Built motion from commit c738b9ac.|2.6.25
[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 _0x4665=['getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','data','binary','write','end','close','unlink','decryptFile','final','encryptString','base64','decryptString','createDecipher','update','utf8','bluebird','lodash','../../config/environment','../../config/logger','app','secrets','session','aes-256-ctr','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test'];(function(_0x47a2dd,_0x4be0d4){var _0x887969=function(_0x50fff1){while(--_0x50fff1){_0x47a2dd['push'](_0x47a2dd['shift']());}};_0x887969(++_0x4be0d4);}(_0x4665,0xaa));var _0x5466=function(_0x395516,_0x26f41a){_0x395516=_0x395516-0x0;var _0x5af650=_0x4665[_0x395516];return _0x5af650;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0x5466('0x0'));var _=require(_0x5466('0x1'));var config=require(_0x5466('0x2'));var logger=require(_0x5466('0x3'))(_0x5466('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x5466('0x5')][_0x5466('0x6')],'algorithm':_0x5466('0x7')};const fileOptions={'algorithm':_0x5466('0x8')};if(config[_0x5466('0x9')]&&config[_0x5466('0x9')]['algorithm']){var isSupported=isAlgorithmSupported(config[_0x5466('0x9')][_0x5466('0xa')]);if(isSupported){fileOptions[_0x5466('0xa')]=config[_0x5466('0x9')][_0x5466('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x5466('0xb')](',\x20');logger[_0x5466('0xc')](config['encrypt']['algorithm'],_0x5466('0xd'),supportedAlgorithms);}}function isASupportedCipher(_0x11f62e){return AES_SUPPORTED_RX[_0x5466('0xe')](_0x11f62e);}function getSupportedCiphers(){return crypto[_0x5466('0xf')]()[_0x5466('0x10')](isASupportedCipher);}function isAlgorithmSupported(_0x1d9e9c){return getSupportedCiphers()[_0x5466('0x11')](_0x1d9e9c)>-0x1;}function combineOptions(_0x2cd086){var _0x4ed881={};for(var _0x145199 in fileOptions){if(fileOptions['hasOwnProperty'](_0x145199)){_0x4ed881[_0x145199]=fileOptions[_0x145199];}}if(_0x2cd086){for(var _0x544372 in _0x2cd086){if(_0x2cd086[_0x5466('0x12')](_0x544372)){_0x4ed881[_0x544372]=_0x2cd086[_0x544372];}}}return _0x4ed881;}exports[_0x5466('0x13')]=function(_0x31eb30,_0x128589,_0x584e07,_0xd091e8){return new BPromise(function(_0x21aad6,_0x43339f){_0xd091e8=combineOptions(_0xd091e8);var _0x809c69=new Buffer(_0x584e07);var _0x5e680b=fs[_0x5466('0x14')](_0x31eb30);var _0x3aa113=fs[_0x5466('0x15')](_0x128589);var _0x108f43=crypto[_0x5466('0x16')](_0xd091e8[_0x5466('0xa')],_0x809c69);_0x5e680b['on'](_0x5466('0x17'),function(_0x51dfbb){var _0x159584=new Buffer(_0x108f43['update'](_0x51dfbb),_0x5466('0x18'));_0x3aa113[_0x5466('0x19')](_0x159584);});_0x5e680b['on'](_0x5466('0x1a'),function(){try{var _0x23a4ea=new Buffer(_0x108f43['final'](_0x5466('0x18')),_0x5466('0x18'));_0x3aa113[_0x5466('0x19')](_0x23a4ea);_0x3aa113[_0x5466('0x1a')]();_0x3aa113['on'](_0x5466('0x1b'),function(){return _0x21aad6(_0x128589);});}catch(_0x4bbce7){fs[_0x5466('0x1c')](_0x128589);return _0x43339f(_0x4bbce7);}});});};exports[_0x5466('0x1d')]=function(_0xdd8d15,_0x5d1b89,_0x429ee5,_0x270e41){return new BPromise(function(_0x2f8b83,_0x275be0){_0x270e41=combineOptions(_0x270e41);var _0x17e52a=new Buffer(_0x429ee5);var _0x1bfc5b=fs[_0x5466('0x14')](_0xdd8d15);var _0x546b31=fs[_0x5466('0x15')](_0x5d1b89);var _0x316a56=crypto['createDecipher'](_0x270e41[_0x5466('0xa')],_0x17e52a);_0x1bfc5b['on'](_0x5466('0x17'),function(_0x3e0d15){var _0x28c271=new Buffer(_0x316a56['update'](_0x3e0d15),_0x5466('0x18'));_0x546b31[_0x5466('0x19')](_0x28c271);});_0x1bfc5b['on'](_0x5466('0x1a'),function(){try{var _0x459062=new Buffer(_0x316a56[_0x5466('0x1e')]('binary'),_0x5466('0x18'));_0x546b31[_0x5466('0x19')](_0x459062);_0x546b31[_0x5466('0x1a')]();_0x546b31['on'](_0x5466('0x1b'),function(){return _0x2f8b83(_0x5d1b89);});}catch(_0x3c0e49){fs['unlink'](_0x5d1b89);return _0x275be0(_0x3c0e49);}});});};exports[_0x5466('0x1f')]=function(_0x5ae616,_0x54c3d8,_0x3b8af4){var _0x5a6571=_0x3b8af4||stringOptions[_0x5466('0xa')];var _0x16f9fe=_0x54c3d8||stringOptions['secret'];var _0x52ff0f=crypto[_0x5466('0x16')](_0x5a6571,_0x16f9fe);var _0x2d1191=_0x52ff0f['update'](_0x5ae616,'utf8',_0x5466('0x20'));_0x2d1191+=_0x52ff0f[_0x5466('0x1e')]('base64');return _0x2d1191;};exports[_0x5466('0x21')]=function(_0xb7901c,_0x134293,_0x74d92d){var _0x206c13=_0x74d92d||stringOptions['algorithm'];var _0x49079e=_0x134293||stringOptions['secret'];var _0x3c054c=crypto[_0x5466('0x22')](_0x206c13,_0x49079e);var _0x11a49e=_0x3c054c[_0x5466('0x23')](_0xb7901c,_0x5466('0x20'),_0x5466('0x24'));_0x11a49e+=_0x3c054c['final'](_0x5466('0x24'));return _0x11a49e;};