58526652e8082e0f65801962343e756913d4d877
[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 _0x471b=['getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','data','update','write','end','binary','unlink','decryptFile','createDecipher','close','encryptString','secret','base64','final','decryptString','utf8','crypto','bluebird','lodash','../../config/logger','app','aes-256-ctr','aes192','encrypt','algorithm','join','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test'];(function(_0x2397d7,_0x8ee99e){var _0x44c78b=function(_0x3ef385){while(--_0x3ef385){_0x2397d7['push'](_0x2397d7['shift']());}};_0x44c78b(++_0x8ee99e);}(_0x471b,0xa3));var _0xb471=function(_0x52a83e,_0x5db18b){_0x52a83e=_0x52a83e-0x0;var _0xa39db9=_0x471b[_0x52a83e];return _0xa39db9;};'use strict';var crypto=require(_0xb471('0x0'));var fs=require('fs');var BPromise=require(_0xb471('0x1'));var _=require(_0xb471('0x2'));var config=require('../../config/environment');var logger=require(_0xb471('0x3'))(_0xb471('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets']['session'],'algorithm':_0xb471('0x5')};const fileOptions={'algorithm':_0xb471('0x6')};if(config[_0xb471('0x7')]&&config[_0xb471('0x7')][_0xb471('0x8')]){var isSupported=isAlgorithmSupported(config['encrypt'][_0xb471('0x8')]);if(isSupported){fileOptions[_0xb471('0x8')]=config[_0xb471('0x7')][_0xb471('0x8')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xb471('0x9')](',\x20');logger['error'](config[_0xb471('0x7')][_0xb471('0x8')],_0xb471('0xa'),supportedAlgorithms);}}function isASupportedCipher(_0x11d2a1){return AES_SUPPORTED_RX[_0xb471('0xb')](_0x11d2a1);}function getSupportedCiphers(){return crypto[_0xb471('0xc')]()[_0xb471('0xd')](isASupportedCipher);}function isAlgorithmSupported(_0x161379){return getSupportedCiphers()[_0xb471('0xe')](_0x161379)>-0x1;}function combineOptions(_0x1e9253){var _0x1e775={};for(var _0x363177 in fileOptions){if(fileOptions[_0xb471('0xf')](_0x363177)){_0x1e775[_0x363177]=fileOptions[_0x363177];}}if(_0x1e9253){for(var _0x569e77 in _0x1e9253){if(_0x1e9253['hasOwnProperty'](_0x569e77)){_0x1e775[_0x569e77]=_0x1e9253[_0x569e77];}}}return _0x1e775;}exports[_0xb471('0x10')]=function(_0x4cc720,_0x5d7468,_0x3d94c3,_0x37d145){return new BPromise(function(_0x1b717b,_0x2900b4){_0x37d145=combineOptions(_0x37d145);var _0x5b27c8=new Buffer(_0x3d94c3);var _0x24cbce=fs[_0xb471('0x11')](_0x4cc720);var _0x38d9c8=fs[_0xb471('0x12')](_0x5d7468);var _0x3f0bb1=crypto[_0xb471('0x13')](_0x37d145[_0xb471('0x8')],_0x5b27c8);_0x24cbce['on'](_0xb471('0x14'),function(_0x383e88){var _0x463651=new Buffer(_0x3f0bb1[_0xb471('0x15')](_0x383e88),'binary');_0x38d9c8[_0xb471('0x16')](_0x463651);});_0x24cbce['on'](_0xb471('0x17'),function(){try{var _0x3ea352=new Buffer(_0x3f0bb1['final'](_0xb471('0x18')),_0xb471('0x18'));_0x38d9c8['write'](_0x3ea352);_0x38d9c8[_0xb471('0x17')]();_0x38d9c8['on']('close',function(){return _0x1b717b(_0x5d7468);});}catch(_0x2462a9){fs[_0xb471('0x19')](_0x5d7468);return _0x2900b4(_0x2462a9);}});});};exports[_0xb471('0x1a')]=function(_0x4b86c9,_0xb5df97,_0x3d5516,_0x416e74){return new BPromise(function(_0x2130ce,_0x5f5217){_0x416e74=combineOptions(_0x416e74);var _0x3ff60f=new Buffer(_0x3d5516);var _0x3e6191=fs['createReadStream'](_0x4b86c9);var _0x5908d7=fs[_0xb471('0x12')](_0xb5df97);var _0x3b2ea5=crypto[_0xb471('0x1b')](_0x416e74[_0xb471('0x8')],_0x3ff60f);_0x3e6191['on'](_0xb471('0x14'),function(_0x591a06){var _0x343bef=new Buffer(_0x3b2ea5['update'](_0x591a06),_0xb471('0x18'));_0x5908d7['write'](_0x343bef);});_0x3e6191['on']('end',function(){try{var _0x497730=new Buffer(_0x3b2ea5['final']('binary'),'binary');_0x5908d7[_0xb471('0x16')](_0x497730);_0x5908d7[_0xb471('0x17')]();_0x5908d7['on'](_0xb471('0x1c'),function(){return _0x2130ce(_0xb5df97);});}catch(_0x22d2bf){fs[_0xb471('0x19')](_0xb5df97);return _0x5f5217(_0x22d2bf);}});});};exports[_0xb471('0x1d')]=function(_0x29fc81,_0x13a654,_0x3811b8){var _0x36ec33=_0x3811b8||stringOptions[_0xb471('0x8')];var _0x37e534=_0x13a654||stringOptions[_0xb471('0x1e')];var _0x39d831=crypto[_0xb471('0x13')](_0x36ec33,_0x37e534);var _0x12ec6f=_0x39d831[_0xb471('0x15')](_0x29fc81,'utf8',_0xb471('0x1f'));_0x12ec6f+=_0x39d831[_0xb471('0x20')](_0xb471('0x1f'));return _0x12ec6f;};exports[_0xb471('0x21')]=function(_0x31df05,_0x1cbe99,_0x1fa707){var _0x1c3643=_0x1fa707||stringOptions[_0xb471('0x8')];var _0x3a1583=_0x1cbe99||stringOptions[_0xb471('0x1e')];var _0x30669c=crypto[_0xb471('0x1b')](_0x1c3643,_0x3a1583);var _0x56ffb9=_0x30669c[_0xb471('0x15')](_0x31df05,'base64',_0xb471('0x22'));_0x56ffb9+=_0x30669c[_0xb471('0x20')]('utf8');return _0x56ffb9;};