Built motion from commit (unavailable).|2.6.0
[motion2.git] / server / components / encryptor / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xbc65=['binary','write','end','final','close','unlink','decryptFile','createWriteStream','createDecipher','secret','createCipher','base64','decryptString','utf8','crypto','bluebird','lodash','../../config/environment','../../config/logger','app','secrets','session','aes192','encrypt','algorithm','join','error','test','getCiphers','indexOf','hasOwnProperty','encryptFile','createReadStream','data','update'];(function(_0x38f85c,_0x4770db){var _0x5a985c=function(_0x350400){while(--_0x350400){_0x38f85c['push'](_0x38f85c['shift']());}};_0x5a985c(++_0x4770db);}(_0xbc65,0x16c));var _0x5bc6=function(_0x434911,_0x1489ac){_0x434911=_0x434911-0x0;var _0x548d7c=_0xbc65[_0x434911];return _0x548d7c;};'use strict';var crypto=require(_0x5bc6('0x0'));var fs=require('fs');var BPromise=require(_0x5bc6('0x1'));var _=require(_0x5bc6('0x2'));var config=require(_0x5bc6('0x3'));var logger=require(_0x5bc6('0x4'))(_0x5bc6('0x5'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x5bc6('0x6')][_0x5bc6('0x7')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0x5bc6('0x8')};if(config[_0x5bc6('0x9')]&&config[_0x5bc6('0x9')][_0x5bc6('0xa')]){var isSupported=isAlgorithmSupported(config[_0x5bc6('0x9')][_0x5bc6('0xa')]);if(isSupported){fileOptions[_0x5bc6('0xa')]=config[_0x5bc6('0x9')][_0x5bc6('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x5bc6('0xb')](',\x20');logger[_0x5bc6('0xc')](config[_0x5bc6('0x9')][_0x5bc6('0xa')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x340bb0){return AES_SUPPORTED_RX[_0x5bc6('0xd')](_0x340bb0);}function getSupportedCiphers(){return crypto[_0x5bc6('0xe')]()['filter'](isASupportedCipher);}function isAlgorithmSupported(_0x39c830){return getSupportedCiphers()[_0x5bc6('0xf')](_0x39c830)>-0x1;}function combineOptions(_0x4ff507){var _0x20fa76={};for(var _0x3d2eca in fileOptions){if(fileOptions[_0x5bc6('0x10')](_0x3d2eca)){_0x20fa76[_0x3d2eca]=fileOptions[_0x3d2eca];}}if(_0x4ff507){for(var _0x54fa96 in _0x4ff507){if(_0x4ff507[_0x5bc6('0x10')](_0x54fa96)){_0x20fa76[_0x54fa96]=_0x4ff507[_0x54fa96];}}}return _0x20fa76;}exports[_0x5bc6('0x11')]=function(_0x255ac7,_0x357c74,_0x3001f4,_0x274826){return new BPromise(function(_0x30f74b,_0x34e081){_0x274826=combineOptions(_0x274826);var _0x5329da=new Buffer(_0x3001f4);var _0x1b5f76=fs[_0x5bc6('0x12')](_0x255ac7);var _0xd5617f=fs['createWriteStream'](_0x357c74);var _0x2a4ff4=crypto['createCipher'](_0x274826[_0x5bc6('0xa')],_0x5329da);_0x1b5f76['on'](_0x5bc6('0x13'),function(_0x41ea52){var _0x551e06=new Buffer(_0x2a4ff4[_0x5bc6('0x14')](_0x41ea52),_0x5bc6('0x15'));_0xd5617f[_0x5bc6('0x16')](_0x551e06);});_0x1b5f76['on'](_0x5bc6('0x17'),function(){try{var _0x3acaa1=new Buffer(_0x2a4ff4[_0x5bc6('0x18')]('binary'),_0x5bc6('0x15'));_0xd5617f[_0x5bc6('0x16')](_0x3acaa1);_0xd5617f['end']();_0xd5617f['on'](_0x5bc6('0x19'),function(){return _0x30f74b(_0x357c74);});}catch(_0x1453c7){fs[_0x5bc6('0x1a')](_0x357c74);return _0x34e081(_0x1453c7);}});});};exports[_0x5bc6('0x1b')]=function(_0x163f8a,_0x187493,_0x32fb09,_0xa1caae){return new BPromise(function(_0x5eea10,_0x3541f8){_0xa1caae=combineOptions(_0xa1caae);var _0x2c9aa8=new Buffer(_0x32fb09);var _0x3ad156=fs[_0x5bc6('0x12')](_0x163f8a);var _0xb58825=fs[_0x5bc6('0x1c')](_0x187493);var _0x5bf855=crypto[_0x5bc6('0x1d')](_0xa1caae[_0x5bc6('0xa')],_0x2c9aa8);_0x3ad156['on'](_0x5bc6('0x13'),function(_0x3448e4){var _0x593855=new Buffer(_0x5bf855[_0x5bc6('0x14')](_0x3448e4),_0x5bc6('0x15'));_0xb58825[_0x5bc6('0x16')](_0x593855);});_0x3ad156['on'](_0x5bc6('0x17'),function(){try{var _0x1c9fa3=new Buffer(_0x5bf855[_0x5bc6('0x18')]('binary'),_0x5bc6('0x15'));_0xb58825[_0x5bc6('0x16')](_0x1c9fa3);_0xb58825['end']();_0xb58825['on']('close',function(){return _0x5eea10(_0x187493);});}catch(_0x2dce5d){fs[_0x5bc6('0x1a')](_0x187493);return _0x3541f8(_0x2dce5d);}});});};exports['encryptString']=function(_0x1be603,_0xed8aac,_0x146fc2){var _0x216823=_0x146fc2||stringOptions['algorithm'];var _0x2f1828=_0xed8aac||stringOptions[_0x5bc6('0x1e')];var _0x263d26=crypto[_0x5bc6('0x1f')](_0x216823,_0x2f1828);var _0x218a28=_0x263d26[_0x5bc6('0x14')](_0x1be603,'utf8','base64');_0x218a28+=_0x263d26[_0x5bc6('0x18')](_0x5bc6('0x20'));return _0x218a28;};exports[_0x5bc6('0x21')]=function(_0x2fb9d0,_0x2024e1,_0x1ee4fe){var _0x35fc3d=_0x1ee4fe||stringOptions[_0x5bc6('0xa')];var _0x32b039=_0x2024e1||stringOptions['secret'];var _0x1d1141=crypto[_0x5bc6('0x1d')](_0x35fc3d,_0x32b039);var _0x2cf3db=_0x1d1141['update'](_0x2fb9d0,_0x5bc6('0x20'),'utf8');_0x2cf3db+=_0x1d1141[_0x5bc6('0x18')](_0x5bc6('0x22'));return _0x2cf3db;};