Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / components / encryptor / index.js
index 3c080f6..42e7518 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4659=['unlink','decryptFile','createWriteStream','final','secret','base64','decryptString','createDecipher','utf8','crypto','bluebird','../../config/environment','../../config/logger','app','secrets','session','aes-256-ctr','encrypt','algorithm','join','error','getCiphers','filter','indexOf','encryptFile','createReadStream','createCipher','data','update','binary','end','write','close'];(function(_0x3bdd55,_0x58eade){var _0x4659f1=function(_0xe0a951){while(--_0xe0a951){_0x3bdd55['push'](_0x3bdd55['shift']());}};_0x4659f1(++_0x58eade);}(_0x4659,0x6c));var _0x9465=function(_0x2797de,_0x44e5df){_0x2797de=_0x2797de-0x0;var _0x42ede0=_0x4659[_0x2797de];return _0x42ede0;};'use strict';var crypto=require(_0x9465('0x0'));var fs=require('fs');var BPromise=require(_0x9465('0x1'));var _=require('lodash');var config=require(_0x9465('0x2'));var logger=require(_0x9465('0x3'))(_0x9465('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x9465('0x5')][_0x9465('0x6')],'algorithm':_0x9465('0x7')};const fileOptions={'algorithm':'aes192'};if(config[_0x9465('0x8')]&&config[_0x9465('0x8')][_0x9465('0x9')]){var isSupported=isAlgorithmSupported(config[_0x9465('0x8')]['algorithm']);if(isSupported){fileOptions[_0x9465('0x9')]=config[_0x9465('0x8')][_0x9465('0x9')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x9465('0xa')](',\x20');logger[_0x9465('0xb')](config[_0x9465('0x8')][_0x9465('0x9')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x1ae96f){return AES_SUPPORTED_RX['test'](_0x1ae96f);}function getSupportedCiphers(){return crypto[_0x9465('0xc')]()[_0x9465('0xd')](isASupportedCipher);}function isAlgorithmSupported(_0x110726){return getSupportedCiphers()[_0x9465('0xe')](_0x110726)>-0x1;}function combineOptions(_0x25d2c5){var _0x8f7cbb={};for(var _0x250f89 in fileOptions){if(fileOptions['hasOwnProperty'](_0x250f89)){_0x8f7cbb[_0x250f89]=fileOptions[_0x250f89];}}if(_0x25d2c5){for(var _0x433f7c in _0x25d2c5){if(_0x25d2c5['hasOwnProperty'](_0x433f7c)){_0x8f7cbb[_0x433f7c]=_0x25d2c5[_0x433f7c];}}}return _0x8f7cbb;}exports[_0x9465('0xf')]=function(_0x240274,_0x3524c6,_0x4ba45b,_0x13f9d1){return new BPromise(function(_0x484cc5,_0x42097c){_0x13f9d1=combineOptions(_0x13f9d1);var _0x56fc88=new Buffer(_0x4ba45b);var _0x3c10ee=fs[_0x9465('0x10')](_0x240274);var _0x24ac4e=fs['createWriteStream'](_0x3524c6);var _0x5f297d=crypto[_0x9465('0x11')](_0x13f9d1['algorithm'],_0x56fc88);_0x3c10ee['on'](_0x9465('0x12'),function(_0x415684){var _0x47e1b4=new Buffer(_0x5f297d[_0x9465('0x13')](_0x415684),_0x9465('0x14'));_0x24ac4e['write'](_0x47e1b4);});_0x3c10ee['on'](_0x9465('0x15'),function(){try{var _0x343d49=new Buffer(_0x5f297d['final']('binary'),_0x9465('0x14'));_0x24ac4e[_0x9465('0x16')](_0x343d49);_0x24ac4e[_0x9465('0x15')]();_0x24ac4e['on'](_0x9465('0x17'),function(){return _0x484cc5(_0x3524c6);});}catch(_0x2d6f96){fs[_0x9465('0x18')](_0x3524c6);return _0x42097c(_0x2d6f96);}});});};exports[_0x9465('0x19')]=function(_0x42c58d,_0x388b53,_0x4151a1,_0x74a427){return new BPromise(function(_0x135481,_0xa914ed){_0x74a427=combineOptions(_0x74a427);var _0x474cf8=new Buffer(_0x4151a1);var _0x2554ef=fs[_0x9465('0x10')](_0x42c58d);var _0x2674a4=fs[_0x9465('0x1a')](_0x388b53);var _0x4f6394=crypto['createDecipher'](_0x74a427[_0x9465('0x9')],_0x474cf8);_0x2554ef['on'](_0x9465('0x12'),function(_0x1756c9){var _0x4ee94a=new Buffer(_0x4f6394[_0x9465('0x13')](_0x1756c9),_0x9465('0x14'));_0x2674a4[_0x9465('0x16')](_0x4ee94a);});_0x2554ef['on'](_0x9465('0x15'),function(){try{var _0x6cf99=new Buffer(_0x4f6394[_0x9465('0x1b')](_0x9465('0x14')),_0x9465('0x14'));_0x2674a4[_0x9465('0x16')](_0x6cf99);_0x2674a4[_0x9465('0x15')]();_0x2674a4['on'](_0x9465('0x17'),function(){return _0x135481(_0x388b53);});}catch(_0x224287){fs[_0x9465('0x18')](_0x388b53);return _0xa914ed(_0x224287);}});});};exports['encryptString']=function(_0x2d2177,_0x5e3620,_0x3a20b1){var _0x451dc1=_0x3a20b1||stringOptions[_0x9465('0x9')];var _0x3b469a=_0x5e3620||stringOptions[_0x9465('0x1c')];var _0x36a900=crypto[_0x9465('0x11')](_0x451dc1,_0x3b469a);var _0x2843cb=_0x36a900[_0x9465('0x13')](_0x2d2177,'utf8',_0x9465('0x1d'));_0x2843cb+=_0x36a900[_0x9465('0x1b')](_0x9465('0x1d'));return _0x2843cb;};exports[_0x9465('0x1e')]=function(_0x4d0328,_0x568c3c,_0x427ff7){var _0x5de284=_0x427ff7||stringOptions[_0x9465('0x9')];var _0x3f77ae=_0x568c3c||stringOptions[_0x9465('0x1c')];var _0x4b5fb1=crypto[_0x9465('0x1f')](_0x5de284,_0x3f77ae);var _0x595f31=_0x4b5fb1[_0x9465('0x13')](_0x4d0328,_0x9465('0x1d'),_0x9465('0x20'));_0x595f31+=_0x4b5fb1['final'](_0x9465('0x20'));return _0x595f31;};
\ No newline at end of file
+var _0x2abb=['is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','indexOf','hasOwnProperty','encryptFile','createCipher','data','update','write','end','final','binary','unlink','createReadStream','createWriteStream','createDecipher','secret','utf8','base64','decryptString','crypto','bluebird','lodash','../../config/environment','../../config/logger','app','secrets','session','aes-256-ctr','aes192','encrypt','algorithm','join','error'];(function(_0x25f743,_0x765664){var _0x2ba165=function(_0xf13c61){while(--_0xf13c61){_0x25f743['push'](_0x25f743['shift']());}};_0x2ba165(++_0x765664);}(_0x2abb,0x7e));var _0xb2ab=function(_0x1f0159,_0x1939a9){_0x1f0159=_0x1f0159-0x0;var _0x3e145f=_0x2abb[_0x1f0159];return _0x3e145f;};'use strict';var crypto=require(_0xb2ab('0x0'));var fs=require('fs');var BPromise=require(_0xb2ab('0x1'));var _=require(_0xb2ab('0x2'));var config=require(_0xb2ab('0x3'));var logger=require(_0xb2ab('0x4'))(_0xb2ab('0x5'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0xb2ab('0x6')][_0xb2ab('0x7')],'algorithm':_0xb2ab('0x8')};const fileOptions={'algorithm':_0xb2ab('0x9')};if(config[_0xb2ab('0xa')]&&config[_0xb2ab('0xa')][_0xb2ab('0xb')]){var isSupported=isAlgorithmSupported(config[_0xb2ab('0xa')][_0xb2ab('0xb')]);if(isSupported){fileOptions[_0xb2ab('0xb')]=config[_0xb2ab('0xa')][_0xb2ab('0xb')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xb2ab('0xc')](',\x20');logger[_0xb2ab('0xd')](config[_0xb2ab('0xa')][_0xb2ab('0xb')],_0xb2ab('0xe'),supportedAlgorithms);}}function isASupportedCipher(_0x8d4530){return AES_SUPPORTED_RX[_0xb2ab('0xf')](_0x8d4530);}function getSupportedCiphers(){return crypto[_0xb2ab('0x10')]()['filter'](isASupportedCipher);}function isAlgorithmSupported(_0x2a606b){return getSupportedCiphers()[_0xb2ab('0x11')](_0x2a606b)>-0x1;}function combineOptions(_0x510e35){var _0x1c6845={};for(var _0x16fde7 in fileOptions){if(fileOptions[_0xb2ab('0x12')](_0x16fde7)){_0x1c6845[_0x16fde7]=fileOptions[_0x16fde7];}}if(_0x510e35){for(var _0x14f13c in _0x510e35){if(_0x510e35[_0xb2ab('0x12')](_0x14f13c)){_0x1c6845[_0x14f13c]=_0x510e35[_0x14f13c];}}}return _0x1c6845;}exports[_0xb2ab('0x13')]=function(_0x95fb07,_0x1ebeaa,_0x308ee9,_0x38adfc){return new BPromise(function(_0x312784,_0xaebb08){_0x38adfc=combineOptions(_0x38adfc);var _0x5bb070=new Buffer(_0x308ee9);var _0x539dfd=fs['createReadStream'](_0x95fb07);var _0x9224ca=fs['createWriteStream'](_0x1ebeaa);var _0x2756a4=crypto[_0xb2ab('0x14')](_0x38adfc[_0xb2ab('0xb')],_0x5bb070);_0x539dfd['on'](_0xb2ab('0x15'),function(_0x1a1f84){var _0x3432ed=new Buffer(_0x2756a4[_0xb2ab('0x16')](_0x1a1f84),'binary');_0x9224ca[_0xb2ab('0x17')](_0x3432ed);});_0x539dfd['on'](_0xb2ab('0x18'),function(){try{var _0x41b200=new Buffer(_0x2756a4[_0xb2ab('0x19')](_0xb2ab('0x1a')),'binary');_0x9224ca[_0xb2ab('0x17')](_0x41b200);_0x9224ca[_0xb2ab('0x18')]();_0x9224ca['on']('close',function(){return _0x312784(_0x1ebeaa);});}catch(_0x435606){fs[_0xb2ab('0x1b')](_0x1ebeaa);return _0xaebb08(_0x435606);}});});};exports['decryptFile']=function(_0x1e8df8,_0x149417,_0x28d3a1,_0x1fe137){return new BPromise(function(_0x33e6be,_0x479cd7){_0x1fe137=combineOptions(_0x1fe137);var _0x277e37=new Buffer(_0x28d3a1);var _0x293281=fs[_0xb2ab('0x1c')](_0x1e8df8);var _0x47eb9e=fs[_0xb2ab('0x1d')](_0x149417);var _0x2c0241=crypto[_0xb2ab('0x1e')](_0x1fe137[_0xb2ab('0xb')],_0x277e37);_0x293281['on'](_0xb2ab('0x15'),function(_0x5d1c6f){var _0x2905f1=new Buffer(_0x2c0241[_0xb2ab('0x16')](_0x5d1c6f),_0xb2ab('0x1a'));_0x47eb9e[_0xb2ab('0x17')](_0x2905f1);});_0x293281['on'](_0xb2ab('0x18'),function(){try{var _0x2ee6d6=new Buffer(_0x2c0241['final']('binary'),_0xb2ab('0x1a'));_0x47eb9e['write'](_0x2ee6d6);_0x47eb9e[_0xb2ab('0x18')]();_0x47eb9e['on']('close',function(){return _0x33e6be(_0x149417);});}catch(_0x5aac88){fs[_0xb2ab('0x1b')](_0x149417);return _0x479cd7(_0x5aac88);}});});};exports['encryptString']=function(_0x4d5474,_0x24a69a,_0x187c83){var _0x1f95d6=_0x187c83||stringOptions['algorithm'];var _0x453ea1=_0x24a69a||stringOptions[_0xb2ab('0x1f')];var _0x3e2262=crypto['createCipher'](_0x1f95d6,_0x453ea1);var _0xe32594=_0x3e2262['update'](_0x4d5474,_0xb2ab('0x20'),_0xb2ab('0x21'));_0xe32594+=_0x3e2262['final'](_0xb2ab('0x21'));return _0xe32594;};exports[_0xb2ab('0x22')]=function(_0x571ee8,_0x5baeb1,_0x47848b){var _0x43d187=_0x47848b||stringOptions[_0xb2ab('0xb')];var _0x3b37ab=_0x5baeb1||stringOptions['secret'];var _0x519139=crypto['createDecipher'](_0x43d187,_0x3b37ab);var _0x4c2c0c=_0x519139[_0xb2ab('0x16')](_0x571ee8,_0xb2ab('0x21'),_0xb2ab('0x20'));_0x4c2c0c+=_0x519139[_0xb2ab('0x19')](_0xb2ab('0x20'));return _0x4c2c0c;};
\ No newline at end of file