Built motion from commit d69f4380.|2.6.29
[motion2.git] / server / components / encryptor / index.js
index 726416b..11fc418 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x065c=['crypto','bluebird','../../config/environment','app','session','aes-256-ctr','aes192','encrypt','algorithm','join','error','test','getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createCipher','data','update','end','final','binary','write','close','decryptFile','createReadStream','createWriteStream','createDecipher','unlink','encryptString','secret','utf8','base64','decryptString'];(function(_0x1d1407,_0x1850c8){var _0x3034ff=function(_0x340962){while(--_0x340962){_0x1d1407['push'](_0x1d1407['shift']());}};_0x3034ff(++_0x1850c8);}(_0x065c,0x181));var _0xc065=function(_0x16b9ed,_0x56517a){_0x16b9ed=_0x16b9ed-0x0;var _0x66b1f8=_0x065c[_0x16b9ed];return _0x66b1f8;};'use strict';var crypto=require(_0xc065('0x0'));var fs=require('fs');var BPromise=require(_0xc065('0x1'));var _=require('lodash');var config=require(_0xc065('0x2'));var logger=require('../../config/logger')(_0xc065('0x3'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0xc065('0x4')],'algorithm':_0xc065('0x5')};const fileOptions={'algorithm':_0xc065('0x6')};if(config[_0xc065('0x7')]&&config[_0xc065('0x7')][_0xc065('0x8')]){var isSupported=isAlgorithmSupported(config['encrypt'][_0xc065('0x8')]);if(isSupported){fileOptions[_0xc065('0x8')]=config[_0xc065('0x7')]['algorithm'];}else{var supportedAlgorithms=getSupportedCiphers()[_0xc065('0x9')](',\x20');logger[_0xc065('0xa')](config[_0xc065('0x7')][_0xc065('0x8')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x72bd2b){return AES_SUPPORTED_RX[_0xc065('0xb')](_0x72bd2b);}function getSupportedCiphers(){return crypto[_0xc065('0xc')]()[_0xc065('0xd')](isASupportedCipher);}function isAlgorithmSupported(_0x24a68e){return getSupportedCiphers()[_0xc065('0xe')](_0x24a68e)>-0x1;}function combineOptions(_0x439943){var _0x4af87f={};for(var _0x4228e2 in fileOptions){if(fileOptions[_0xc065('0xf')](_0x4228e2)){_0x4af87f[_0x4228e2]=fileOptions[_0x4228e2];}}if(_0x439943){for(var _0x13000a in _0x439943){if(_0x439943['hasOwnProperty'](_0x13000a)){_0x4af87f[_0x13000a]=_0x439943[_0x13000a];}}}return _0x4af87f;}exports[_0xc065('0x10')]=function(_0x9a0ad4,_0x691ec7,_0x2e748e,_0x19689f){return new BPromise(function(_0x28a19d,_0x57431b){_0x19689f=combineOptions(_0x19689f);var _0x4faa8d=new Buffer(_0x2e748e);var _0x4322c7=fs['createReadStream'](_0x9a0ad4);var _0x4dae20=fs['createWriteStream'](_0x691ec7);var _0x1dc161=crypto[_0xc065('0x11')](_0x19689f[_0xc065('0x8')],_0x4faa8d);_0x4322c7['on'](_0xc065('0x12'),function(_0x5ede5b){var _0x29445e=new Buffer(_0x1dc161[_0xc065('0x13')](_0x5ede5b),'binary');_0x4dae20['write'](_0x29445e);});_0x4322c7['on'](_0xc065('0x14'),function(){try{var _0x183fcd=new Buffer(_0x1dc161[_0xc065('0x15')](_0xc065('0x16')),_0xc065('0x16'));_0x4dae20[_0xc065('0x17')](_0x183fcd);_0x4dae20[_0xc065('0x14')]();_0x4dae20['on'](_0xc065('0x18'),function(){return _0x28a19d(_0x691ec7);});}catch(_0x4184ea){fs['unlink'](_0x691ec7);return _0x57431b(_0x4184ea);}});});};exports[_0xc065('0x19')]=function(_0xad346d,_0x3f9274,_0x3053d0,_0x313154){return new BPromise(function(_0x5c97da,_0x33d41a){_0x313154=combineOptions(_0x313154);var _0x3dc2e9=new Buffer(_0x3053d0);var _0x599739=fs[_0xc065('0x1a')](_0xad346d);var _0x294f2f=fs[_0xc065('0x1b')](_0x3f9274);var _0x3bc1fc=crypto[_0xc065('0x1c')](_0x313154[_0xc065('0x8')],_0x3dc2e9);_0x599739['on'](_0xc065('0x12'),function(_0x3c9055){var _0x3a0fd3=new Buffer(_0x3bc1fc['update'](_0x3c9055),_0xc065('0x16'));_0x294f2f[_0xc065('0x17')](_0x3a0fd3);});_0x599739['on'](_0xc065('0x14'),function(){try{var _0x5a07f0=new Buffer(_0x3bc1fc[_0xc065('0x15')](_0xc065('0x16')),_0xc065('0x16'));_0x294f2f['write'](_0x5a07f0);_0x294f2f['end']();_0x294f2f['on']('close',function(){return _0x5c97da(_0x3f9274);});}catch(_0x26c64e){fs[_0xc065('0x1d')](_0x3f9274);return _0x33d41a(_0x26c64e);}});});};exports[_0xc065('0x1e')]=function(_0xd1b3d6,_0x2e7d1b,_0x7aa29a){var _0x525f43=_0x7aa29a||stringOptions[_0xc065('0x8')];var _0xea2a=_0x2e7d1b||stringOptions[_0xc065('0x1f')];var _0x457211=crypto['createCipher'](_0x525f43,_0xea2a);var _0x2df6df=_0x457211[_0xc065('0x13')](_0xd1b3d6,_0xc065('0x20'),_0xc065('0x21'));_0x2df6df+=_0x457211['final'](_0xc065('0x21'));return _0x2df6df;};exports[_0xc065('0x22')]=function(_0x1e8963,_0x4c3437,_0x25f7b6){var _0x4933f2=_0x25f7b6||stringOptions['algorithm'];var _0x1feecf=_0x4c3437||stringOptions['secret'];var _0x13c3b9=crypto[_0xc065('0x1c')](_0x4933f2,_0x1feecf);var _0x57f523=_0x13c3b9[_0xc065('0x13')](_0x1e8963,_0xc065('0x21'),_0xc065('0x20'));_0x57f523+=_0x13c3b9[_0xc065('0x15')](_0xc065('0x20'));return _0x57f523;};
\ No newline at end of file
+var _0x1911=['final','end','close','decryptFile','unlink','secret','base64','createDecipher','utf8','crypto','bluebird','../../config/environment','../../config/logger','app','session','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','indexOf','encryptFile','createReadStream','createWriteStream','createCipher','data','update','binary','write'];(function(_0x1ae439,_0x4280bc){var _0x3a395e=function(_0x17951d){while(--_0x17951d){_0x1ae439['push'](_0x1ae439['shift']());}};_0x3a395e(++_0x4280bc);}(_0x1911,0x109));var _0x1191=function(_0xc83c6f,_0x246dea){_0xc83c6f=_0xc83c6f-0x0;var _0x1cc09c=_0x1911[_0xc83c6f];return _0x1cc09c;};'use strict';var crypto=require(_0x1191('0x0'));var fs=require('fs');var BPromise=require(_0x1191('0x1'));var _=require('lodash');var config=require(_0x1191('0x2'));var logger=require(_0x1191('0x3'))(_0x1191('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0x1191('0x5')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0x1191('0x6')};if(config[_0x1191('0x7')]&&config[_0x1191('0x7')][_0x1191('0x8')]){var isSupported=isAlgorithmSupported(config['encrypt'][_0x1191('0x8')]);if(isSupported){fileOptions['algorithm']=config[_0x1191('0x7')]['algorithm'];}else{var supportedAlgorithms=getSupportedCiphers()[_0x1191('0x9')](',\x20');logger[_0x1191('0xa')](config[_0x1191('0x7')]['algorithm'],_0x1191('0xb'),supportedAlgorithms);}}function isASupportedCipher(_0x3aaed4){return AES_SUPPORTED_RX[_0x1191('0xc')](_0x3aaed4);}function getSupportedCiphers(){return crypto[_0x1191('0xd')]()['filter'](isASupportedCipher);}function isAlgorithmSupported(_0x2e0e22){return getSupportedCiphers()[_0x1191('0xe')](_0x2e0e22)>-0x1;}function combineOptions(_0x3a4139){var _0x1ae0fc={};for(var _0xa59caf in fileOptions){if(fileOptions['hasOwnProperty'](_0xa59caf)){_0x1ae0fc[_0xa59caf]=fileOptions[_0xa59caf];}}if(_0x3a4139){for(var _0x3a8763 in _0x3a4139){if(_0x3a4139['hasOwnProperty'](_0x3a8763)){_0x1ae0fc[_0x3a8763]=_0x3a4139[_0x3a8763];}}}return _0x1ae0fc;}exports[_0x1191('0xf')]=function(_0x173d88,_0x25ab4e,_0x5463c8,_0x9fbb31){return new BPromise(function(_0x2608fc,_0xf8122f){_0x9fbb31=combineOptions(_0x9fbb31);var _0x3dc6e1=new Buffer(_0x5463c8);var _0x1b5604=fs[_0x1191('0x10')](_0x173d88);var _0x248c1f=fs[_0x1191('0x11')](_0x25ab4e);var _0x30fed7=crypto[_0x1191('0x12')](_0x9fbb31[_0x1191('0x8')],_0x3dc6e1);_0x1b5604['on'](_0x1191('0x13'),function(_0x4b6ae7){var _0x4873e6=new Buffer(_0x30fed7[_0x1191('0x14')](_0x4b6ae7),_0x1191('0x15'));_0x248c1f[_0x1191('0x16')](_0x4873e6);});_0x1b5604['on']('end',function(){try{var _0x2069c7=new Buffer(_0x30fed7[_0x1191('0x17')]('binary'),'binary');_0x248c1f[_0x1191('0x16')](_0x2069c7);_0x248c1f[_0x1191('0x18')]();_0x248c1f['on'](_0x1191('0x19'),function(){return _0x2608fc(_0x25ab4e);});}catch(_0xac8067){fs['unlink'](_0x25ab4e);return _0xf8122f(_0xac8067);}});});};exports[_0x1191('0x1a')]=function(_0x375fc0,_0x46676f,_0x1a6fe2,_0x1d575e){return new BPromise(function(_0x129a44,_0x286b04){_0x1d575e=combineOptions(_0x1d575e);var _0x583d1b=new Buffer(_0x1a6fe2);var _0x5b66b2=fs['createReadStream'](_0x375fc0);var _0x44cc03=fs[_0x1191('0x11')](_0x46676f);var _0x17bc51=crypto['createDecipher'](_0x1d575e['algorithm'],_0x583d1b);_0x5b66b2['on'](_0x1191('0x13'),function(_0x403598){var _0x259e02=new Buffer(_0x17bc51[_0x1191('0x14')](_0x403598),_0x1191('0x15'));_0x44cc03[_0x1191('0x16')](_0x259e02);});_0x5b66b2['on']('end',function(){try{var _0x5e5b8b=new Buffer(_0x17bc51[_0x1191('0x17')]('binary'),_0x1191('0x15'));_0x44cc03[_0x1191('0x16')](_0x5e5b8b);_0x44cc03[_0x1191('0x18')]();_0x44cc03['on']('close',function(){return _0x129a44(_0x46676f);});}catch(_0x2991e5){fs[_0x1191('0x1b')](_0x46676f);return _0x286b04(_0x2991e5);}});});};exports['encryptString']=function(_0x5bda85,_0xe341ff,_0x2e8433){var _0x4f1f71=_0x2e8433||stringOptions['algorithm'];var _0xce5da1=_0xe341ff||stringOptions[_0x1191('0x1c')];var _0x5c88ae=crypto[_0x1191('0x12')](_0x4f1f71,_0xce5da1);var _0x527f28=_0x5c88ae[_0x1191('0x14')](_0x5bda85,'utf8',_0x1191('0x1d'));_0x527f28+=_0x5c88ae[_0x1191('0x17')](_0x1191('0x1d'));return _0x527f28;};exports['decryptString']=function(_0xa2f50,_0x1cce2b,_0x3067f9){var _0x32c8ff=_0x3067f9||stringOptions[_0x1191('0x8')];var _0x390b99=_0x1cce2b||stringOptions[_0x1191('0x1c')];var _0x5cccb8=crypto[_0x1191('0x1e')](_0x32c8ff,_0x390b99);var _0x148a17=_0x5cccb8[_0x1191('0x14')](_0xa2f50,_0x1191('0x1d'),'utf8');_0x148a17+=_0x5cccb8[_0x1191('0x17')](_0x1191('0x1f'));return _0x148a17;};
\ No newline at end of file