Built motion from commit 1ea47bf4.|2.6.34
[motion2.git] / server / components / encryptor / index.js
index 79a6ec8..e48f27b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5893=['data','update','binary','write','end','close','unlink','decryptFile','createDecipher','final','encryptString','secret','createCipher','base64','decryptString','utf8','bluebird','../../config/logger','session','aes-256-ctr','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','filter','encryptFile','createReadStream','createWriteStream'];(function(_0x224f43,_0x3ac2b1){var _0x39a831=function(_0x330450){while(--_0x330450){_0x224f43['push'](_0x224f43['shift']());}};_0x39a831(++_0x3ac2b1);}(_0x5893,0x146));var _0x3589=function(_0x4565bf,_0x5ad9d6){_0x4565bf=_0x4565bf-0x0;var _0x5610ba=_0x5893[_0x4565bf];return _0x5610ba;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0x3589('0x0'));var _=require('lodash');var config=require('../../config/environment');var logger=require(_0x3589('0x1'))('app');const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0x3589('0x2')],'algorithm':_0x3589('0x3')};const fileOptions={'algorithm':'aes192'};if(config['encrypt']&&config[_0x3589('0x4')][_0x3589('0x5')]){var isSupported=isAlgorithmSupported(config['encrypt']['algorithm']);if(isSupported){fileOptions[_0x3589('0x5')]=config[_0x3589('0x4')][_0x3589('0x5')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x3589('0x6')](',\x20');logger[_0x3589('0x7')](config[_0x3589('0x4')][_0x3589('0x5')],_0x3589('0x8'),supportedAlgorithms);}}function isASupportedCipher(_0x58a70f){return AES_SUPPORTED_RX[_0x3589('0x9')](_0x58a70f);}function getSupportedCiphers(){return crypto[_0x3589('0xa')]()[_0x3589('0xb')](isASupportedCipher);}function isAlgorithmSupported(_0x585d16){return getSupportedCiphers()['indexOf'](_0x585d16)>-0x1;}function combineOptions(_0x5e804e){var _0x3d088e={};for(var _0x3130f0 in fileOptions){if(fileOptions['hasOwnProperty'](_0x3130f0)){_0x3d088e[_0x3130f0]=fileOptions[_0x3130f0];}}if(_0x5e804e){for(var _0x38b26b in _0x5e804e){if(_0x5e804e['hasOwnProperty'](_0x38b26b)){_0x3d088e[_0x38b26b]=_0x5e804e[_0x38b26b];}}}return _0x3d088e;}exports[_0x3589('0xc')]=function(_0x41e8e4,_0x8c0efc,_0x477d59,_0x344904){return new BPromise(function(_0x32df1f,_0x470880){_0x344904=combineOptions(_0x344904);var _0x212958=new Buffer(_0x477d59);var _0x218a38=fs[_0x3589('0xd')](_0x41e8e4);var _0x27b7b7=fs[_0x3589('0xe')](_0x8c0efc);var _0x1cf5be=crypto['createCipher'](_0x344904[_0x3589('0x5')],_0x212958);_0x218a38['on'](_0x3589('0xf'),function(_0x402d12){var _0x258b3c=new Buffer(_0x1cf5be[_0x3589('0x10')](_0x402d12),_0x3589('0x11'));_0x27b7b7[_0x3589('0x12')](_0x258b3c);});_0x218a38['on'](_0x3589('0x13'),function(){try{var _0x22446a=new Buffer(_0x1cf5be['final'](_0x3589('0x11')),_0x3589('0x11'));_0x27b7b7[_0x3589('0x12')](_0x22446a);_0x27b7b7[_0x3589('0x13')]();_0x27b7b7['on'](_0x3589('0x14'),function(){return _0x32df1f(_0x8c0efc);});}catch(_0x2c600d){fs[_0x3589('0x15')](_0x8c0efc);return _0x470880(_0x2c600d);}});});};exports[_0x3589('0x16')]=function(_0x1d0f24,_0x5d564f,_0x14db89,_0xeeb5b2){return new BPromise(function(_0x1a43e7,_0x5330f6){_0xeeb5b2=combineOptions(_0xeeb5b2);var _0xcdbb2b=new Buffer(_0x14db89);var _0x4b5772=fs[_0x3589('0xd')](_0x1d0f24);var _0x3f40cb=fs[_0x3589('0xe')](_0x5d564f);var _0x1cec76=crypto[_0x3589('0x17')](_0xeeb5b2[_0x3589('0x5')],_0xcdbb2b);_0x4b5772['on'](_0x3589('0xf'),function(_0x8e1336){var _0x43c496=new Buffer(_0x1cec76['update'](_0x8e1336),_0x3589('0x11'));_0x3f40cb['write'](_0x43c496);});_0x4b5772['on'](_0x3589('0x13'),function(){try{var _0x20221a=new Buffer(_0x1cec76[_0x3589('0x18')](_0x3589('0x11')),'binary');_0x3f40cb[_0x3589('0x12')](_0x20221a);_0x3f40cb[_0x3589('0x13')]();_0x3f40cb['on'](_0x3589('0x14'),function(){return _0x1a43e7(_0x5d564f);});}catch(_0x5823fd){fs[_0x3589('0x15')](_0x5d564f);return _0x5330f6(_0x5823fd);}});});};exports[_0x3589('0x19')]=function(_0x5a04fb,_0x5eb645,_0x1d4f09){var _0x5c49b4=_0x1d4f09||stringOptions[_0x3589('0x5')];var _0x5ab40c=_0x5eb645||stringOptions[_0x3589('0x1a')];var _0x2e3e38=crypto[_0x3589('0x1b')](_0x5c49b4,_0x5ab40c);var _0x385cbc=_0x2e3e38[_0x3589('0x10')](_0x5a04fb,'utf8',_0x3589('0x1c'));_0x385cbc+=_0x2e3e38[_0x3589('0x18')](_0x3589('0x1c'));return _0x385cbc;};exports[_0x3589('0x1d')]=function(_0x4ec75d,_0x5c63d9,_0x3596cf){var _0xed6f7=_0x3596cf||stringOptions[_0x3589('0x5')];var _0x269037=_0x5c63d9||stringOptions[_0x3589('0x1a')];var _0x231ff7=crypto[_0x3589('0x17')](_0xed6f7,_0x269037);var _0x2fcc70=_0x231ff7[_0x3589('0x10')](_0x4ec75d,'base64',_0x3589('0x1e'));_0x2fcc70+=_0x231ff7['final'](_0x3589('0x1e'));return _0x2fcc70;};
\ No newline at end of file
+var _0x40e8=['encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','update','write','end','final','binary','close','decryptFile','data','unlink','secret','utf8','base64','decryptString','bluebird','lodash','../../config/environment','../../config/logger','app','secrets','session','aes-256-ctr','aes192'];(function(_0x4f712f,_0x595559){var _0x238bce=function(_0x3b3f22){while(--_0x3b3f22){_0x4f712f['push'](_0x4f712f['shift']());}};_0x238bce(++_0x595559);}(_0x40e8,0x183));var _0x840e=function(_0x879e31,_0x139d02){_0x879e31=_0x879e31-0x0;var _0x3467e8=_0x40e8[_0x879e31];return _0x3467e8;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0x840e('0x0'));var _=require(_0x840e('0x1'));var config=require(_0x840e('0x2'));var logger=require(_0x840e('0x3'))(_0x840e('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x840e('0x5')][_0x840e('0x6')],'algorithm':_0x840e('0x7')};const fileOptions={'algorithm':_0x840e('0x8')};if(config['encrypt']&&config[_0x840e('0x9')][_0x840e('0xa')]){var isSupported=isAlgorithmSupported(config[_0x840e('0x9')]['algorithm']);if(isSupported){fileOptions['algorithm']=config['encrypt'][_0x840e('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x840e('0xb')](',\x20');logger[_0x840e('0xc')](config[_0x840e('0x9')][_0x840e('0xa')],_0x840e('0xd'),supportedAlgorithms);}}function isASupportedCipher(_0x58b7f1){return AES_SUPPORTED_RX[_0x840e('0xe')](_0x58b7f1);}function getSupportedCiphers(){return crypto[_0x840e('0xf')]()[_0x840e('0x10')](isASupportedCipher);}function isAlgorithmSupported(_0x168493){return getSupportedCiphers()[_0x840e('0x11')](_0x168493)>-0x1;}function combineOptions(_0x373b26){var _0x2c3393={};for(var _0x192cb6 in fileOptions){if(fileOptions['hasOwnProperty'](_0x192cb6)){_0x2c3393[_0x192cb6]=fileOptions[_0x192cb6];}}if(_0x373b26){for(var _0x4ced7b in _0x373b26){if(_0x373b26[_0x840e('0x12')](_0x4ced7b)){_0x2c3393[_0x4ced7b]=_0x373b26[_0x4ced7b];}}}return _0x2c3393;}exports[_0x840e('0x13')]=function(_0xbe8fa5,_0x2209a8,_0x429033,_0x29bde9){return new BPromise(function(_0x2b9286,_0x53eb86){_0x29bde9=combineOptions(_0x29bde9);var _0x4a9586=new Buffer(_0x429033);var _0x2ea09b=fs[_0x840e('0x14')](_0xbe8fa5);var _0x2b8da1=fs[_0x840e('0x15')](_0x2209a8);var _0x463626=crypto[_0x840e('0x16')](_0x29bde9[_0x840e('0xa')],_0x4a9586);_0x2ea09b['on']('data',function(_0x3265c8){var _0x48b034=new Buffer(_0x463626[_0x840e('0x17')](_0x3265c8),'binary');_0x2b8da1[_0x840e('0x18')](_0x48b034);});_0x2ea09b['on'](_0x840e('0x19'),function(){try{var _0x373a65=new Buffer(_0x463626[_0x840e('0x1a')](_0x840e('0x1b')),_0x840e('0x1b'));_0x2b8da1[_0x840e('0x18')](_0x373a65);_0x2b8da1['end']();_0x2b8da1['on'](_0x840e('0x1c'),function(){return _0x2b9286(_0x2209a8);});}catch(_0x50394c){fs['unlink'](_0x2209a8);return _0x53eb86(_0x50394c);}});});};exports[_0x840e('0x1d')]=function(_0x156e63,_0x5aa0b8,_0x4a16a4,_0xa4a4cf){return new BPromise(function(_0xbae24e,_0x2754fa){_0xa4a4cf=combineOptions(_0xa4a4cf);var _0x4effab=new Buffer(_0x4a16a4);var _0x4bfbe0=fs['createReadStream'](_0x156e63);var _0x243023=fs[_0x840e('0x15')](_0x5aa0b8);var _0x2c0fb6=crypto['createDecipher'](_0xa4a4cf['algorithm'],_0x4effab);_0x4bfbe0['on'](_0x840e('0x1e'),function(_0x219dec){var _0x5e62c1=new Buffer(_0x2c0fb6[_0x840e('0x17')](_0x219dec),_0x840e('0x1b'));_0x243023['write'](_0x5e62c1);});_0x4bfbe0['on'](_0x840e('0x19'),function(){try{var _0x2ad549=new Buffer(_0x2c0fb6[_0x840e('0x1a')](_0x840e('0x1b')),_0x840e('0x1b'));_0x243023['write'](_0x2ad549);_0x243023[_0x840e('0x19')]();_0x243023['on'](_0x840e('0x1c'),function(){return _0xbae24e(_0x5aa0b8);});}catch(_0x25dcff){fs[_0x840e('0x1f')](_0x5aa0b8);return _0x2754fa(_0x25dcff);}});});};exports['encryptString']=function(_0x4cf7a7,_0x5906d6,_0xd51799){var _0x497bd9=_0xd51799||stringOptions[_0x840e('0xa')];var _0x5c2811=_0x5906d6||stringOptions[_0x840e('0x20')];var _0x28444a=crypto[_0x840e('0x16')](_0x497bd9,_0x5c2811);var _0x5c8b20=_0x28444a[_0x840e('0x17')](_0x4cf7a7,_0x840e('0x21'),_0x840e('0x22'));_0x5c8b20+=_0x28444a['final'](_0x840e('0x22'));return _0x5c8b20;};exports[_0x840e('0x23')]=function(_0x3965aa,_0x1c8e8e,_0xfaac97){var _0x12a8f9=_0xfaac97||stringOptions[_0x840e('0xa')];var _0xadc6ab=_0x1c8e8e||stringOptions[_0x840e('0x20')];var _0x1de639=crypto['createDecipher'](_0x12a8f9,_0xadc6ab);var _0x3dff86=_0x1de639[_0x840e('0x17')](_0x3965aa,'base64',_0x840e('0x21'));_0x3dff86+=_0x1de639[_0x840e('0x1a')](_0x840e('0x21'));return _0x3dff86;};
\ No newline at end of file