Built motion from commit 97f2f211.|2.6.31
[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 _0x04e6=['algorithm','join','error','test','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','data','update','binary','final','end','unlink','decryptFile','createDecipher','write','close','encryptString','createCipher','utf8','base64','decryptString','crypto','bluebird','../../config/environment','../../config/logger','app','session','aes-256-ctr','aes192','encrypt'];(function(_0x50a0c2,_0x4befab){var _0x5ebadd=function(_0x3a3342){while(--_0x3a3342){_0x50a0c2['push'](_0x50a0c2['shift']());}};_0x5ebadd(++_0x4befab);}(_0x04e6,0x1b1));var _0x604e=function(_0x287a47,_0x2f731c){_0x287a47=_0x287a47-0x0;var _0x3fb726=_0x04e6[_0x287a47];return _0x3fb726;};'use strict';var crypto=require(_0x604e('0x0'));var fs=require('fs');var BPromise=require(_0x604e('0x1'));var _=require('lodash');var config=require(_0x604e('0x2'));var logger=require(_0x604e('0x3'))(_0x604e('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0x604e('0x5')],'algorithm':_0x604e('0x6')};const fileOptions={'algorithm':_0x604e('0x7')};if(config[_0x604e('0x8')]&&config[_0x604e('0x8')]['algorithm']){var isSupported=isAlgorithmSupported(config[_0x604e('0x8')]['algorithm']);if(isSupported){fileOptions[_0x604e('0x9')]=config[_0x604e('0x8')]['algorithm'];}else{var supportedAlgorithms=getSupportedCiphers()[_0x604e('0xa')](',\x20');logger[_0x604e('0xb')](config[_0x604e('0x8')][_0x604e('0x9')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x222112){return AES_SUPPORTED_RX[_0x604e('0xc')](_0x222112);}function getSupportedCiphers(){return crypto['getCiphers']()[_0x604e('0xd')](isASupportedCipher);}function isAlgorithmSupported(_0x4d3a1f){return getSupportedCiphers()[_0x604e('0xe')](_0x4d3a1f)>-0x1;}function combineOptions(_0x145521){var _0x30a4c7={};for(var _0x15c5b9 in fileOptions){if(fileOptions[_0x604e('0xf')](_0x15c5b9)){_0x30a4c7[_0x15c5b9]=fileOptions[_0x15c5b9];}}if(_0x145521){for(var _0x918c19 in _0x145521){if(_0x145521[_0x604e('0xf')](_0x918c19)){_0x30a4c7[_0x918c19]=_0x145521[_0x918c19];}}}return _0x30a4c7;}exports[_0x604e('0x10')]=function(_0x5b3295,_0x2163c7,_0x264379,_0x4564c5){return new BPromise(function(_0x421547,_0x150d04){_0x4564c5=combineOptions(_0x4564c5);var _0x919a1a=new Buffer(_0x264379);var _0x1fe9ea=fs[_0x604e('0x11')](_0x5b3295);var _0x1b75d5=fs[_0x604e('0x12')](_0x2163c7);var _0x1fa43a=crypto['createCipher'](_0x4564c5[_0x604e('0x9')],_0x919a1a);_0x1fe9ea['on'](_0x604e('0x13'),function(_0x12bf39){var _0xca4c6e=new Buffer(_0x1fa43a[_0x604e('0x14')](_0x12bf39),_0x604e('0x15'));_0x1b75d5['write'](_0xca4c6e);});_0x1fe9ea['on']('end',function(){try{var _0x4bb807=new Buffer(_0x1fa43a[_0x604e('0x16')](_0x604e('0x15')),_0x604e('0x15'));_0x1b75d5['write'](_0x4bb807);_0x1b75d5[_0x604e('0x17')]();_0x1b75d5['on']('close',function(){return _0x421547(_0x2163c7);});}catch(_0x572493){fs[_0x604e('0x18')](_0x2163c7);return _0x150d04(_0x572493);}});});};exports[_0x604e('0x19')]=function(_0x5c1985,_0x3c34d7,_0x3dd52b,_0x5c3770){return new BPromise(function(_0x23947a,_0x4b1cc0){_0x5c3770=combineOptions(_0x5c3770);var _0x383c7c=new Buffer(_0x3dd52b);var _0x47ca29=fs['createReadStream'](_0x5c1985);var _0xc18f2=fs[_0x604e('0x12')](_0x3c34d7);var _0x577433=crypto[_0x604e('0x1a')](_0x5c3770['algorithm'],_0x383c7c);_0x47ca29['on'](_0x604e('0x13'),function(_0x5550b8){var _0x319998=new Buffer(_0x577433['update'](_0x5550b8),_0x604e('0x15'));_0xc18f2[_0x604e('0x1b')](_0x319998);});_0x47ca29['on'](_0x604e('0x17'),function(){try{var _0x2724fd=new Buffer(_0x577433[_0x604e('0x16')](_0x604e('0x15')),'binary');_0xc18f2['write'](_0x2724fd);_0xc18f2[_0x604e('0x17')]();_0xc18f2['on'](_0x604e('0x1c'),function(){return _0x23947a(_0x3c34d7);});}catch(_0x4322d8){fs['unlink'](_0x3c34d7);return _0x4b1cc0(_0x4322d8);}});});};exports[_0x604e('0x1d')]=function(_0x518593,_0x3fc0ac,_0x48e00e){var _0x53972d=_0x48e00e||stringOptions[_0x604e('0x9')];var _0x9601ff=_0x3fc0ac||stringOptions['secret'];var _0x34e02b=crypto[_0x604e('0x1e')](_0x53972d,_0x9601ff);var _0xf38f27=_0x34e02b[_0x604e('0x14')](_0x518593,_0x604e('0x1f'),_0x604e('0x20'));_0xf38f27+=_0x34e02b[_0x604e('0x16')]('base64');return _0xf38f27;};exports[_0x604e('0x21')]=function(_0x510c1c,_0xbadf2f,_0x3df1bf){var _0x589d3d=_0x3df1bf||stringOptions[_0x604e('0x9')];var _0x274a4c=_0xbadf2f||stringOptions['secret'];var _0x4c001f=crypto['createDecipher'](_0x589d3d,_0x274a4c);var _0x4ba238=_0x4c001f[_0x604e('0x14')](_0x510c1c,_0x604e('0x20'),_0x604e('0x1f'));_0x4ba238+=_0x4c001f[_0x604e('0x16')](_0x604e('0x1f'));return _0x4ba238;};