Built motion from commit 10af8726.|2.6.34
[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 _0xb0bb=['secret','utf8','base64','decryptString','crypto','bluebird','lodash','../../config/logger','app','session','aes192','encrypt','algorithm','join','error','test','getCiphers','filter','indexOf','encryptFile','createReadStream','createWriteStream','createCipher','update','binary','write','end','final','close','decryptFile','createDecipher','data','unlink','encryptString'];(function(_0x529019,_0x47c564){var _0x552bd4=function(_0x2dc690){while(--_0x2dc690){_0x529019['push'](_0x529019['shift']());}};_0x552bd4(++_0x47c564);}(_0xb0bb,0x158));var _0xbb0b=function(_0x4fb422,_0x5a1bd7){_0x4fb422=_0x4fb422-0x0;var _0x3c32b5=_0xb0bb[_0x4fb422];return _0x3c32b5;};'use strict';var crypto=require(_0xbb0b('0x0'));var fs=require('fs');var BPromise=require(_0xbb0b('0x1'));var _=require(_0xbb0b('0x2'));var config=require('../../config/environment');var logger=require(_0xbb0b('0x3'))(_0xbb0b('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0xbb0b('0x5')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0xbb0b('0x6')};if(config[_0xbb0b('0x7')]&&config['encrypt'][_0xbb0b('0x8')]){var isSupported=isAlgorithmSupported(config[_0xbb0b('0x7')][_0xbb0b('0x8')]);if(isSupported){fileOptions[_0xbb0b('0x8')]=config[_0xbb0b('0x7')][_0xbb0b('0x8')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xbb0b('0x9')](',\x20');logger[_0xbb0b('0xa')](config[_0xbb0b('0x7')][_0xbb0b('0x8')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x24d8b5){return AES_SUPPORTED_RX[_0xbb0b('0xb')](_0x24d8b5);}function getSupportedCiphers(){return crypto[_0xbb0b('0xc')]()[_0xbb0b('0xd')](isASupportedCipher);}function isAlgorithmSupported(_0x1a2206){return getSupportedCiphers()[_0xbb0b('0xe')](_0x1a2206)>-0x1;}function combineOptions(_0x41bf3a){var _0x4f0d64={};for(var _0x3066b1 in fileOptions){if(fileOptions['hasOwnProperty'](_0x3066b1)){_0x4f0d64[_0x3066b1]=fileOptions[_0x3066b1];}}if(_0x41bf3a){for(var _0x30f61e in _0x41bf3a){if(_0x41bf3a['hasOwnProperty'](_0x30f61e)){_0x4f0d64[_0x30f61e]=_0x41bf3a[_0x30f61e];}}}return _0x4f0d64;}exports[_0xbb0b('0xf')]=function(_0x2efef7,_0x3ef9ca,_0x49de9b,_0x379da3){return new BPromise(function(_0x50e323,_0x51b404){_0x379da3=combineOptions(_0x379da3);var _0x2a8c65=new Buffer(_0x49de9b);var _0x97f436=fs[_0xbb0b('0x10')](_0x2efef7);var _0x40b6c8=fs[_0xbb0b('0x11')](_0x3ef9ca);var _0xb9256=crypto[_0xbb0b('0x12')](_0x379da3[_0xbb0b('0x8')],_0x2a8c65);_0x97f436['on']('data',function(_0x49a942){var _0x4f990a=new Buffer(_0xb9256[_0xbb0b('0x13')](_0x49a942),_0xbb0b('0x14'));_0x40b6c8[_0xbb0b('0x15')](_0x4f990a);});_0x97f436['on'](_0xbb0b('0x16'),function(){try{var _0x18ac01=new Buffer(_0xb9256[_0xbb0b('0x17')]('binary'),'binary');_0x40b6c8[_0xbb0b('0x15')](_0x18ac01);_0x40b6c8['end']();_0x40b6c8['on'](_0xbb0b('0x18'),function(){return _0x50e323(_0x3ef9ca);});}catch(_0x4a6490){fs['unlink'](_0x3ef9ca);return _0x51b404(_0x4a6490);}});});};exports[_0xbb0b('0x19')]=function(_0x32ce56,_0x5d4e14,_0x40347e,_0x37f9f9){return new BPromise(function(_0x2fd0f7,_0x4c3cf3){_0x37f9f9=combineOptions(_0x37f9f9);var _0x316b57=new Buffer(_0x40347e);var _0x4f2f47=fs['createReadStream'](_0x32ce56);var _0x3798ef=fs['createWriteStream'](_0x5d4e14);var _0x10d9f0=crypto[_0xbb0b('0x1a')](_0x37f9f9[_0xbb0b('0x8')],_0x316b57);_0x4f2f47['on'](_0xbb0b('0x1b'),function(_0x36616c){var _0x57154f=new Buffer(_0x10d9f0[_0xbb0b('0x13')](_0x36616c),_0xbb0b('0x14'));_0x3798ef[_0xbb0b('0x15')](_0x57154f);});_0x4f2f47['on'](_0xbb0b('0x16'),function(){try{var _0x518486=new Buffer(_0x10d9f0[_0xbb0b('0x17')](_0xbb0b('0x14')),'binary');_0x3798ef[_0xbb0b('0x15')](_0x518486);_0x3798ef['end']();_0x3798ef['on']('close',function(){return _0x2fd0f7(_0x5d4e14);});}catch(_0x5ac6a8){fs[_0xbb0b('0x1c')](_0x5d4e14);return _0x4c3cf3(_0x5ac6a8);}});});};exports[_0xbb0b('0x1d')]=function(_0x3c75f8,_0x4f15b5,_0x3c3dea){var _0x559b3d=_0x3c3dea||stringOptions[_0xbb0b('0x8')];var _0x58633d=_0x4f15b5||stringOptions[_0xbb0b('0x1e')];var _0x366392=crypto[_0xbb0b('0x12')](_0x559b3d,_0x58633d);var _0x3c37b9=_0x366392[_0xbb0b('0x13')](_0x3c75f8,_0xbb0b('0x1f'),'base64');_0x3c37b9+=_0x366392[_0xbb0b('0x17')](_0xbb0b('0x20'));return _0x3c37b9;};exports[_0xbb0b('0x21')]=function(_0x453ced,_0xd1e351,_0x20cd14){var _0x48c6b5=_0x20cd14||stringOptions[_0xbb0b('0x8')];var _0x3b1615=_0xd1e351||stringOptions[_0xbb0b('0x1e')];var _0x3535d5=crypto[_0xbb0b('0x1a')](_0x48c6b5,_0x3b1615);var _0x9a3a4e=_0x3535d5[_0xbb0b('0x13')](_0x453ced,_0xbb0b('0x20'),_0xbb0b('0x1f'));_0x9a3a4e+=_0x3535d5['final'](_0xbb0b('0x1f'));return _0x9a3a4e;};