Built motion from commit (unavailable).|2.5.30
[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 _0xd3a9=['../../config/environment','../../config/logger','secrets','session','aes-256-ctr','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','filter','hasOwnProperty','createReadStream','createWriteStream','createCipher','data','update','binary','end','final','write','unlink','decryptFile','createDecipher','close','secret','base64','decryptString','utf8','crypto','bluebird'];(function(_0x16b9ed,_0x56517a){var _0x66b1f8=function(_0x1c883){while(--_0x1c883){_0x16b9ed['push'](_0x16b9ed['shift']());}};_0x66b1f8(++_0x56517a);}(_0xd3a9,0x82));var _0x9d3a=function(_0xf5370,_0x17b080){_0xf5370=_0xf5370-0x0;var _0x2bf030=_0xd3a9[_0xf5370];return _0x2bf030;};'use strict';var crypto=require(_0x9d3a('0x0'));var fs=require('fs');var BPromise=require(_0x9d3a('0x1'));var _=require('lodash');var config=require(_0x9d3a('0x2'));var logger=require(_0x9d3a('0x3'))('app');const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x9d3a('0x4')][_0x9d3a('0x5')],'algorithm':_0x9d3a('0x6')};const fileOptions={'algorithm':_0x9d3a('0x7')};if(config[_0x9d3a('0x8')]&&config[_0x9d3a('0x8')]['algorithm']){var isSupported=isAlgorithmSupported(config[_0x9d3a('0x8')][_0x9d3a('0x9')]);if(isSupported){fileOptions['algorithm']=config[_0x9d3a('0x8')][_0x9d3a('0x9')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x9d3a('0xa')](',\x20');logger[_0x9d3a('0xb')](config[_0x9d3a('0x8')][_0x9d3a('0x9')],_0x9d3a('0xc'),supportedAlgorithms);}}function isASupportedCipher(_0x2754fd){return AES_SUPPORTED_RX[_0x9d3a('0xd')](_0x2754fd);}function getSupportedCiphers(){return crypto['getCiphers']()[_0x9d3a('0xe')](isASupportedCipher);}function isAlgorithmSupported(_0x3476f4){return getSupportedCiphers()['indexOf'](_0x3476f4)>-0x1;}function combineOptions(_0x42028d){var _0x5d6728={};for(var _0x4562c3 in fileOptions){if(fileOptions[_0x9d3a('0xf')](_0x4562c3)){_0x5d6728[_0x4562c3]=fileOptions[_0x4562c3];}}if(_0x42028d){for(var _0x2440f9 in _0x42028d){if(_0x42028d[_0x9d3a('0xf')](_0x2440f9)){_0x5d6728[_0x2440f9]=_0x42028d[_0x2440f9];}}}return _0x5d6728;}exports['encryptFile']=function(_0xb8dbaa,_0x2ace78,_0x3d88d6,_0x51468f){return new BPromise(function(_0x2a46d8,_0x31314e){_0x51468f=combineOptions(_0x51468f);var _0x53c7e8=new Buffer(_0x3d88d6);var _0x133111=fs[_0x9d3a('0x10')](_0xb8dbaa);var _0x3b70ab=fs[_0x9d3a('0x11')](_0x2ace78);var _0x540357=crypto[_0x9d3a('0x12')](_0x51468f[_0x9d3a('0x9')],_0x53c7e8);_0x133111['on'](_0x9d3a('0x13'),function(_0x28c693){var _0x3e3a3b=new Buffer(_0x540357[_0x9d3a('0x14')](_0x28c693),_0x9d3a('0x15'));_0x3b70ab['write'](_0x3e3a3b);});_0x133111['on'](_0x9d3a('0x16'),function(){try{var _0x22c89b=new Buffer(_0x540357[_0x9d3a('0x17')](_0x9d3a('0x15')),_0x9d3a('0x15'));_0x3b70ab[_0x9d3a('0x18')](_0x22c89b);_0x3b70ab[_0x9d3a('0x16')]();_0x3b70ab['on']('close',function(){return _0x2a46d8(_0x2ace78);});}catch(_0x572432){fs[_0x9d3a('0x19')](_0x2ace78);return _0x31314e(_0x572432);}});});};exports[_0x9d3a('0x1a')]=function(_0x15adb4,_0x5abf9c,_0x4c92fa,_0x346204){return new BPromise(function(_0xbfc0dd,_0x2d5353){_0x346204=combineOptions(_0x346204);var _0x531bd0=new Buffer(_0x4c92fa);var _0x318839=fs[_0x9d3a('0x10')](_0x15adb4);var _0x2211c2=fs[_0x9d3a('0x11')](_0x5abf9c);var _0x5bfc26=crypto[_0x9d3a('0x1b')](_0x346204[_0x9d3a('0x9')],_0x531bd0);_0x318839['on']('data',function(_0xb3065a){var _0x2366e5=new Buffer(_0x5bfc26[_0x9d3a('0x14')](_0xb3065a),'binary');_0x2211c2[_0x9d3a('0x18')](_0x2366e5);});_0x318839['on'](_0x9d3a('0x16'),function(){try{var _0x59c70f=new Buffer(_0x5bfc26[_0x9d3a('0x17')](_0x9d3a('0x15')),_0x9d3a('0x15'));_0x2211c2[_0x9d3a('0x18')](_0x59c70f);_0x2211c2[_0x9d3a('0x16')]();_0x2211c2['on'](_0x9d3a('0x1c'),function(){return _0xbfc0dd(_0x5abf9c);});}catch(_0x599a2c){fs[_0x9d3a('0x19')](_0x5abf9c);return _0x2d5353(_0x599a2c);}});});};exports['encryptString']=function(_0x1c317c,_0x43b6a6,_0x685a9){var _0x12cab6=_0x685a9||stringOptions[_0x9d3a('0x9')];var _0x3cb39e=_0x43b6a6||stringOptions[_0x9d3a('0x1d')];var _0xedc93a=crypto['createCipher'](_0x12cab6,_0x3cb39e);var _0x107ac6=_0xedc93a[_0x9d3a('0x14')](_0x1c317c,'utf8',_0x9d3a('0x1e'));_0x107ac6+=_0xedc93a[_0x9d3a('0x17')](_0x9d3a('0x1e'));return _0x107ac6;};exports[_0x9d3a('0x1f')]=function(_0xc5250e,_0x8614cb,_0x2a3748){var _0x3ff8db=_0x2a3748||stringOptions['algorithm'];var _0x16d0f7=_0x8614cb||stringOptions[_0x9d3a('0x1d')];var _0x3f57e2=crypto[_0x9d3a('0x1b')](_0x3ff8db,_0x16d0f7);var _0x5046e6=_0x3f57e2[_0x9d3a('0x14')](_0xc5250e,_0x9d3a('0x1e'),_0x9d3a('0x20'));_0x5046e6+=_0x3f57e2['final']('utf8');return _0x5046e6;};