Built motion from commit c116dc8b.|2.6.30
[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 _0xadce=['createWriteStream','createCipher','update','binary','write','final','end','close','unlink','decryptFile','encryptString','secret','utf8','base64','decryptString','createDecipher','crypto','bluebird','lodash','../../config/environment','../../config/logger','app','session','aes-256-ctr','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','filter','indexOf','hasOwnProperty','createReadStream'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xadce,0xa0));var _0xeadc=function(_0x4a747d,_0x3b747f){_0x4a747d=_0x4a747d-0x0;var _0x3a5b5c=_0xadce[_0x4a747d];return _0x3a5b5c;};'use strict';var crypto=require(_0xeadc('0x0'));var fs=require('fs');var BPromise=require(_0xeadc('0x1'));var _=require(_0xeadc('0x2'));var config=require(_0xeadc('0x3'));var logger=require(_0xeadc('0x4'))(_0xeadc('0x5'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0xeadc('0x6')],'algorithm':_0xeadc('0x7')};const fileOptions={'algorithm':_0xeadc('0x8')};if(config[_0xeadc('0x9')]&&config['encrypt'][_0xeadc('0xa')]){var isSupported=isAlgorithmSupported(config['encrypt'][_0xeadc('0xa')]);if(isSupported){fileOptions[_0xeadc('0xa')]=config['encrypt'][_0xeadc('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xeadc('0xb')](',\x20');logger[_0xeadc('0xc')](config['encrypt'][_0xeadc('0xa')],_0xeadc('0xd'),supportedAlgorithms);}}function isASupportedCipher(_0x4ee55e){return AES_SUPPORTED_RX[_0xeadc('0xe')](_0x4ee55e);}function getSupportedCiphers(){return crypto[_0xeadc('0xf')]()[_0xeadc('0x10')](isASupportedCipher);}function isAlgorithmSupported(_0x1b9689){return getSupportedCiphers()[_0xeadc('0x11')](_0x1b9689)>-0x1;}function combineOptions(_0x5b7a11){var _0x7ebaa6={};for(var _0xb6bcb5 in fileOptions){if(fileOptions[_0xeadc('0x12')](_0xb6bcb5)){_0x7ebaa6[_0xb6bcb5]=fileOptions[_0xb6bcb5];}}if(_0x5b7a11){for(var _0x4b46cb in _0x5b7a11){if(_0x5b7a11[_0xeadc('0x12')](_0x4b46cb)){_0x7ebaa6[_0x4b46cb]=_0x5b7a11[_0x4b46cb];}}}return _0x7ebaa6;}exports['encryptFile']=function(_0x1c18e7,_0x391aa2,_0x5119ca,_0x249f5b){return new BPromise(function(_0x4b6148,_0x5decb3){_0x249f5b=combineOptions(_0x249f5b);var _0x284c12=new Buffer(_0x5119ca);var _0x82b630=fs[_0xeadc('0x13')](_0x1c18e7);var _0x53fbcf=fs[_0xeadc('0x14')](_0x391aa2);var _0x363fbe=crypto[_0xeadc('0x15')](_0x249f5b['algorithm'],_0x284c12);_0x82b630['on']('data',function(_0x379be3){var _0x49b347=new Buffer(_0x363fbe[_0xeadc('0x16')](_0x379be3),_0xeadc('0x17'));_0x53fbcf[_0xeadc('0x18')](_0x49b347);});_0x82b630['on']('end',function(){try{var _0x3f9100=new Buffer(_0x363fbe[_0xeadc('0x19')](_0xeadc('0x17')),'binary');_0x53fbcf[_0xeadc('0x18')](_0x3f9100);_0x53fbcf[_0xeadc('0x1a')]();_0x53fbcf['on'](_0xeadc('0x1b'),function(){return _0x4b6148(_0x391aa2);});}catch(_0x4eb1f2){fs[_0xeadc('0x1c')](_0x391aa2);return _0x5decb3(_0x4eb1f2);}});});};exports[_0xeadc('0x1d')]=function(_0x9a0e09,_0x4e7d11,_0x28098c,_0x1c131f){return new BPromise(function(_0x7ded63,_0x7edcf1){_0x1c131f=combineOptions(_0x1c131f);var _0x5a0f6e=new Buffer(_0x28098c);var _0x2095db=fs['createReadStream'](_0x9a0e09);var _0x1a45b5=fs['createWriteStream'](_0x4e7d11);var _0x368a3f=crypto['createDecipher'](_0x1c131f['algorithm'],_0x5a0f6e);_0x2095db['on']('data',function(_0x20477f){var _0x3976f7=new Buffer(_0x368a3f['update'](_0x20477f),'binary');_0x1a45b5[_0xeadc('0x18')](_0x3976f7);});_0x2095db['on']('end',function(){try{var _0x46cdb9=new Buffer(_0x368a3f[_0xeadc('0x19')]('binary'),_0xeadc('0x17'));_0x1a45b5[_0xeadc('0x18')](_0x46cdb9);_0x1a45b5[_0xeadc('0x1a')]();_0x1a45b5['on']('close',function(){return _0x7ded63(_0x4e7d11);});}catch(_0x3eca3b){fs[_0xeadc('0x1c')](_0x4e7d11);return _0x7edcf1(_0x3eca3b);}});});};exports[_0xeadc('0x1e')]=function(_0x287b22,_0x4838cb,_0x289161){var _0x2ccdfb=_0x289161||stringOptions['algorithm'];var _0x2b25cb=_0x4838cb||stringOptions[_0xeadc('0x1f')];var _0x4a3209=crypto[_0xeadc('0x15')](_0x2ccdfb,_0x2b25cb);var _0x3733b3=_0x4a3209[_0xeadc('0x16')](_0x287b22,_0xeadc('0x20'),_0xeadc('0x21'));_0x3733b3+=_0x4a3209[_0xeadc('0x19')](_0xeadc('0x21'));return _0x3733b3;};exports[_0xeadc('0x22')]=function(_0xa21c9f,_0x51db85,_0x585c59){var _0x1a4d38=_0x585c59||stringOptions['algorithm'];var _0x1cb200=_0x51db85||stringOptions[_0xeadc('0x1f')];var _0x5652c1=crypto[_0xeadc('0x23')](_0x1a4d38,_0x1cb200);var _0x21b6c9=_0x5652c1['update'](_0xa21c9f,_0xeadc('0x21'),_0xeadc('0x20'));_0x21b6c9+=_0x5652c1[_0xeadc('0x19')]('utf8');return _0x21b6c9;};