065358b2a88896e2106eb603fea7aa707a3c7529
[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 _0x576c=['decryptFile','createDecipher','close','encryptString','secret','utf8','base64','decryptString','crypto','bluebird','lodash','../../config/environment','../../config/logger','app','secrets','aes-256-ctr','aes192','encrypt','algorithm','join','error','test','getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','data','update','binary','write','end','final','unlink'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x576c,0x130));var _0xc576=function(_0x2818a7,_0xb38d51){_0x2818a7=_0x2818a7-0x0;var _0x3d7a89=_0x576c[_0x2818a7];return _0x3d7a89;};'use strict';var crypto=require(_0xc576('0x0'));var fs=require('fs');var BPromise=require(_0xc576('0x1'));var _=require(_0xc576('0x2'));var config=require(_0xc576('0x3'));var logger=require(_0xc576('0x4'))(_0xc576('0x5'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0xc576('0x6')]['session'],'algorithm':_0xc576('0x7')};const fileOptions={'algorithm':_0xc576('0x8')};if(config[_0xc576('0x9')]&&config[_0xc576('0x9')]['algorithm']){var isSupported=isAlgorithmSupported(config['encrypt'][_0xc576('0xa')]);if(isSupported){fileOptions[_0xc576('0xa')]=config[_0xc576('0x9')][_0xc576('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xc576('0xb')](',\x20');logger[_0xc576('0xc')](config['encrypt']['algorithm'],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x4d98e5){return AES_SUPPORTED_RX[_0xc576('0xd')](_0x4d98e5);}function getSupportedCiphers(){return crypto[_0xc576('0xe')]()[_0xc576('0xf')](isASupportedCipher);}function isAlgorithmSupported(_0xebbe23){return getSupportedCiphers()[_0xc576('0x10')](_0xebbe23)>-0x1;}function combineOptions(_0x423528){var _0x1e9ea1={};for(var _0x579c79 in fileOptions){if(fileOptions[_0xc576('0x11')](_0x579c79)){_0x1e9ea1[_0x579c79]=fileOptions[_0x579c79];}}if(_0x423528){for(var _0x20d2b8 in _0x423528){if(_0x423528[_0xc576('0x11')](_0x20d2b8)){_0x1e9ea1[_0x20d2b8]=_0x423528[_0x20d2b8];}}}return _0x1e9ea1;}exports[_0xc576('0x12')]=function(_0x2768e9,_0x354f53,_0x4f72cc,_0x3c566e){return new BPromise(function(_0x8177e7,_0x4f27f7){_0x3c566e=combineOptions(_0x3c566e);var _0x17624f=new Buffer(_0x4f72cc);var _0x1b8939=fs[_0xc576('0x13')](_0x2768e9);var _0x2e1c7b=fs[_0xc576('0x14')](_0x354f53);var _0x2ede60=crypto[_0xc576('0x15')](_0x3c566e[_0xc576('0xa')],_0x17624f);_0x1b8939['on'](_0xc576('0x16'),function(_0x2e7fd3){var _0x517614=new Buffer(_0x2ede60[_0xc576('0x17')](_0x2e7fd3),_0xc576('0x18'));_0x2e1c7b[_0xc576('0x19')](_0x517614);});_0x1b8939['on'](_0xc576('0x1a'),function(){try{var _0x10b7cc=new Buffer(_0x2ede60[_0xc576('0x1b')](_0xc576('0x18')),_0xc576('0x18'));_0x2e1c7b[_0xc576('0x19')](_0x10b7cc);_0x2e1c7b[_0xc576('0x1a')]();_0x2e1c7b['on']('close',function(){return _0x8177e7(_0x354f53);});}catch(_0x227717){fs[_0xc576('0x1c')](_0x354f53);return _0x4f27f7(_0x227717);}});});};exports[_0xc576('0x1d')]=function(_0x29874b,_0x294411,_0x33383a,_0x1b214b){return new BPromise(function(_0x3e864e,_0x3eb5c7){_0x1b214b=combineOptions(_0x1b214b);var _0x2c7af6=new Buffer(_0x33383a);var _0x3cd72a=fs['createReadStream'](_0x29874b);var _0x1bb8b2=fs[_0xc576('0x14')](_0x294411);var _0x17d11d=crypto[_0xc576('0x1e')](_0x1b214b['algorithm'],_0x2c7af6);_0x3cd72a['on'](_0xc576('0x16'),function(_0x4ecd74){var _0xa7f2d1=new Buffer(_0x17d11d[_0xc576('0x17')](_0x4ecd74),'binary');_0x1bb8b2[_0xc576('0x19')](_0xa7f2d1);});_0x3cd72a['on'](_0xc576('0x1a'),function(){try{var _0x5dbde7=new Buffer(_0x17d11d[_0xc576('0x1b')](_0xc576('0x18')),_0xc576('0x18'));_0x1bb8b2[_0xc576('0x19')](_0x5dbde7);_0x1bb8b2['end']();_0x1bb8b2['on'](_0xc576('0x1f'),function(){return _0x3e864e(_0x294411);});}catch(_0x48e221){fs[_0xc576('0x1c')](_0x294411);return _0x3eb5c7(_0x48e221);}});});};exports[_0xc576('0x20')]=function(_0x12256b,_0x2ce9e8,_0x176084){var _0xf302=_0x176084||stringOptions[_0xc576('0xa')];var _0x1c51d4=_0x2ce9e8||stringOptions[_0xc576('0x21')];var _0x10e9b1=crypto[_0xc576('0x15')](_0xf302,_0x1c51d4);var _0x5ded4f=_0x10e9b1[_0xc576('0x17')](_0x12256b,_0xc576('0x22'),'base64');_0x5ded4f+=_0x10e9b1[_0xc576('0x1b')](_0xc576('0x23'));return _0x5ded4f;};exports[_0xc576('0x24')]=function(_0x562bb0,_0x3e0c24,_0x429ae0){var _0x502ea6=_0x429ae0||stringOptions[_0xc576('0xa')];var _0x42fb26=_0x3e0c24||stringOptions[_0xc576('0x21')];var _0x52670a=crypto['createDecipher'](_0x502ea6,_0x42fb26);var _0x5ebf78=_0x52670a[_0xc576('0x17')](_0x562bb0,_0xc576('0x23'),_0xc576('0x22'));_0x5ebf78+=_0x52670a[_0xc576('0x1b')](_0xc576('0x22'));return _0x5ebf78;};