bca1c405fed142ac1c0d21eb28d99c4db4db11f1
[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 _0xc78e=['write','decryptFile','createDecipher','close','encryptString','secret','createCipher','utf8','base64','decryptString','bluebird','lodash','../../config/environment','../../config/logger','app','secrets','session','aes-256-ctr','aes192','encrypt','algorithm','join','error','test','getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','data','update','end','final','binary'];(function(_0x32c25a,_0x5dad37){var _0x24eccf=function(_0xaab7fb){while(--_0xaab7fb){_0x32c25a['push'](_0x32c25a['shift']());}};_0x24eccf(++_0x5dad37);}(_0xc78e,0x76));var _0xec78=function(_0x33a5a5,_0x8c62a){_0x33a5a5=_0x33a5a5-0x0;var _0x33993a=_0xc78e[_0x33a5a5];return _0x33993a;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0xec78('0x0'));var _=require(_0xec78('0x1'));var config=require(_0xec78('0x2'));var logger=require(_0xec78('0x3'))(_0xec78('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0xec78('0x5')][_0xec78('0x6')],'algorithm':_0xec78('0x7')};const fileOptions={'algorithm':_0xec78('0x8')};if(config[_0xec78('0x9')]&&config[_0xec78('0x9')][_0xec78('0xa')]){var isSupported=isAlgorithmSupported(config[_0xec78('0x9')]['algorithm']);if(isSupported){fileOptions[_0xec78('0xa')]=config[_0xec78('0x9')][_0xec78('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xec78('0xb')](',\x20');logger[_0xec78('0xc')](config[_0xec78('0x9')]['algorithm'],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x933ba9){return AES_SUPPORTED_RX[_0xec78('0xd')](_0x933ba9);}function getSupportedCiphers(){return crypto[_0xec78('0xe')]()[_0xec78('0xf')](isASupportedCipher);}function isAlgorithmSupported(_0x3a301c){return getSupportedCiphers()[_0xec78('0x10')](_0x3a301c)>-0x1;}function combineOptions(_0xe85d17){var _0x370796={};for(var _0x461f16 in fileOptions){if(fileOptions[_0xec78('0x11')](_0x461f16)){_0x370796[_0x461f16]=fileOptions[_0x461f16];}}if(_0xe85d17){for(var _0x12b0b1 in _0xe85d17){if(_0xe85d17['hasOwnProperty'](_0x12b0b1)){_0x370796[_0x12b0b1]=_0xe85d17[_0x12b0b1];}}}return _0x370796;}exports[_0xec78('0x12')]=function(_0xe68b32,_0x405367,_0x13be53,_0x3c8607){return new BPromise(function(_0x4928c3,_0x4bfadc){_0x3c8607=combineOptions(_0x3c8607);var _0x591e63=new Buffer(_0x13be53);var _0x2d1ad1=fs[_0xec78('0x13')](_0xe68b32);var _0x31c1e1=fs[_0xec78('0x14')](_0x405367);var _0x2a0a5e=crypto['createCipher'](_0x3c8607[_0xec78('0xa')],_0x591e63);_0x2d1ad1['on'](_0xec78('0x15'),function(_0x32da8c){var _0x574874=new Buffer(_0x2a0a5e[_0xec78('0x16')](_0x32da8c),'binary');_0x31c1e1['write'](_0x574874);});_0x2d1ad1['on'](_0xec78('0x17'),function(){try{var _0x5ad625=new Buffer(_0x2a0a5e[_0xec78('0x18')](_0xec78('0x19')),_0xec78('0x19'));_0x31c1e1[_0xec78('0x1a')](_0x5ad625);_0x31c1e1['end']();_0x31c1e1['on']('close',function(){return _0x4928c3(_0x405367);});}catch(_0x1d88bf){fs['unlink'](_0x405367);return _0x4bfadc(_0x1d88bf);}});});};exports[_0xec78('0x1b')]=function(_0x46245f,_0x5c33de,_0x87c4ec,_0x7ac178){return new BPromise(function(_0x29ebe2,_0x2a6011){_0x7ac178=combineOptions(_0x7ac178);var _0x519ae9=new Buffer(_0x87c4ec);var _0x5b5216=fs[_0xec78('0x13')](_0x46245f);var _0x55c32d=fs[_0xec78('0x14')](_0x5c33de);var _0x25c071=crypto[_0xec78('0x1c')](_0x7ac178[_0xec78('0xa')],_0x519ae9);_0x5b5216['on'](_0xec78('0x15'),function(_0x5c2fde){var _0x4c89de=new Buffer(_0x25c071[_0xec78('0x16')](_0x5c2fde),_0xec78('0x19'));_0x55c32d['write'](_0x4c89de);});_0x5b5216['on'](_0xec78('0x17'),function(){try{var _0x45e69f=new Buffer(_0x25c071['final']('binary'),_0xec78('0x19'));_0x55c32d[_0xec78('0x1a')](_0x45e69f);_0x55c32d[_0xec78('0x17')]();_0x55c32d['on'](_0xec78('0x1d'),function(){return _0x29ebe2(_0x5c33de);});}catch(_0x55528d){fs['unlink'](_0x5c33de);return _0x2a6011(_0x55528d);}});});};exports[_0xec78('0x1e')]=function(_0x1898af,_0x148a53,_0x1e6ac8){var _0x424623=_0x1e6ac8||stringOptions[_0xec78('0xa')];var _0x5116d4=_0x148a53||stringOptions[_0xec78('0x1f')];var _0x43882a=crypto[_0xec78('0x20')](_0x424623,_0x5116d4);var _0x17b905=_0x43882a[_0xec78('0x16')](_0x1898af,_0xec78('0x21'),_0xec78('0x22'));_0x17b905+=_0x43882a[_0xec78('0x18')]('base64');return _0x17b905;};exports[_0xec78('0x23')]=function(_0x13117b,_0x35290f,_0x33aa81){var _0x18e839=_0x33aa81||stringOptions[_0xec78('0xa')];var _0x42aa58=_0x35290f||stringOptions['secret'];var _0x6ef6a6=crypto[_0xec78('0x1c')](_0x18e839,_0x42aa58);var _0x19b86f=_0x6ef6a6['update'](_0x13117b,_0xec78('0x22'),_0xec78('0x21'));_0x19b86f+=_0x6ef6a6[_0xec78('0x18')](_0xec78('0x21'));return _0x19b86f;};