Built motion from commit 1fd437e9.|2.6.19
[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 _0x69bc=['close','decryptFile','createReadStream','createDecipher','final','unlink','encryptString','secret','utf8','base64','decryptString','bluebird','lodash','../../config/environment','../../config/logger','app','secrets','session','aes-256-ctr','encrypt','algorithm','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','filter','indexOf','hasOwnProperty','encryptFile','data','update','write','end','binary'];(function(_0x1b4bdc,_0x11f92c){var _0x246255=function(_0x52ca0b){while(--_0x52ca0b){_0x1b4bdc['push'](_0x1b4bdc['shift']());}};_0x246255(++_0x11f92c);}(_0x69bc,0x71));var _0xc69b=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0x69bc[_0x14add3];return _0x4a174f;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0xc69b('0x0'));var _=require(_0xc69b('0x1'));var config=require(_0xc69b('0x2'));var logger=require(_0xc69b('0x3'))(_0xc69b('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0xc69b('0x5')][_0xc69b('0x6')],'algorithm':_0xc69b('0x7')};const fileOptions={'algorithm':'aes192'};if(config[_0xc69b('0x8')]&&config[_0xc69b('0x8')]['algorithm']){var isSupported=isAlgorithmSupported(config['encrypt'][_0xc69b('0x9')]);if(isSupported){fileOptions['algorithm']=config[_0xc69b('0x8')][_0xc69b('0x9')];}else{var supportedAlgorithms=getSupportedCiphers()['join'](',\x20');logger[_0xc69b('0xa')](config[_0xc69b('0x8')][_0xc69b('0x9')],_0xc69b('0xb'),supportedAlgorithms);}}function isASupportedCipher(_0x5037d8){return AES_SUPPORTED_RX[_0xc69b('0xc')](_0x5037d8);}function getSupportedCiphers(){return crypto[_0xc69b('0xd')]()[_0xc69b('0xe')](isASupportedCipher);}function isAlgorithmSupported(_0x31e561){return getSupportedCiphers()[_0xc69b('0xf')](_0x31e561)>-0x1;}function combineOptions(_0x2fc545){var _0x3d1d89={};for(var _0x37fa03 in fileOptions){if(fileOptions[_0xc69b('0x10')](_0x37fa03)){_0x3d1d89[_0x37fa03]=fileOptions[_0x37fa03];}}if(_0x2fc545){for(var _0x3fe9bc in _0x2fc545){if(_0x2fc545[_0xc69b('0x10')](_0x3fe9bc)){_0x3d1d89[_0x3fe9bc]=_0x2fc545[_0x3fe9bc];}}}return _0x3d1d89;}exports[_0xc69b('0x11')]=function(_0x34355a,_0x13b421,_0x56141f,_0x274087){return new BPromise(function(_0x5ad270,_0x22eff3){_0x274087=combineOptions(_0x274087);var _0x3ad2d3=new Buffer(_0x56141f);var _0x10173a=fs['createReadStream'](_0x34355a);var _0x50c6dc=fs['createWriteStream'](_0x13b421);var _0xb06534=crypto['createCipher'](_0x274087['algorithm'],_0x3ad2d3);_0x10173a['on'](_0xc69b('0x12'),function(_0x17708a){var _0x3e56ad=new Buffer(_0xb06534[_0xc69b('0x13')](_0x17708a),'binary');_0x50c6dc[_0xc69b('0x14')](_0x3e56ad);});_0x10173a['on'](_0xc69b('0x15'),function(){try{var _0x4d0c93=new Buffer(_0xb06534['final'](_0xc69b('0x16')),_0xc69b('0x16'));_0x50c6dc[_0xc69b('0x14')](_0x4d0c93);_0x50c6dc['end']();_0x50c6dc['on'](_0xc69b('0x17'),function(){return _0x5ad270(_0x13b421);});}catch(_0x5fda9){fs['unlink'](_0x13b421);return _0x22eff3(_0x5fda9);}});});};exports[_0xc69b('0x18')]=function(_0x363a19,_0x4a8b4d,_0x54cc0c,_0xc66306){return new BPromise(function(_0x5e2ba8,_0x692b88){_0xc66306=combineOptions(_0xc66306);var _0x2389fd=new Buffer(_0x54cc0c);var _0x17d6d6=fs[_0xc69b('0x19')](_0x363a19);var _0x597ad5=fs['createWriteStream'](_0x4a8b4d);var _0x511f55=crypto[_0xc69b('0x1a')](_0xc66306[_0xc69b('0x9')],_0x2389fd);_0x17d6d6['on'](_0xc69b('0x12'),function(_0x20570c){var _0x140564=new Buffer(_0x511f55['update'](_0x20570c),_0xc69b('0x16'));_0x597ad5[_0xc69b('0x14')](_0x140564);});_0x17d6d6['on'](_0xc69b('0x15'),function(){try{var _0x30fa65=new Buffer(_0x511f55[_0xc69b('0x1b')]('binary'),_0xc69b('0x16'));_0x597ad5[_0xc69b('0x14')](_0x30fa65);_0x597ad5[_0xc69b('0x15')]();_0x597ad5['on'](_0xc69b('0x17'),function(){return _0x5e2ba8(_0x4a8b4d);});}catch(_0x5ddf93){fs[_0xc69b('0x1c')](_0x4a8b4d);return _0x692b88(_0x5ddf93);}});});};exports[_0xc69b('0x1d')]=function(_0x4399e4,_0x5bb9ff,_0x528c57){var _0x2099c7=_0x528c57||stringOptions['algorithm'];var _0x42f835=_0x5bb9ff||stringOptions[_0xc69b('0x1e')];var _0x1960b5=crypto['createCipher'](_0x2099c7,_0x42f835);var _0x2300d0=_0x1960b5[_0xc69b('0x13')](_0x4399e4,_0xc69b('0x1f'),_0xc69b('0x20'));_0x2300d0+=_0x1960b5[_0xc69b('0x1b')]('base64');return _0x2300d0;};exports[_0xc69b('0x21')]=function(_0x236da4,_0x371f7d,_0x58f403){var _0x34f5ed=_0x58f403||stringOptions['algorithm'];var _0x277091=_0x371f7d||stringOptions[_0xc69b('0x1e')];var _0x5dfe9b=crypto[_0xc69b('0x1a')](_0x34f5ed,_0x277091);var _0x149634=_0x5dfe9b[_0xc69b('0x13')](_0x236da4,'base64','utf8');_0x149634+=_0x5dfe9b[_0xc69b('0x1b')]('utf8');return _0x149634;};