Built motion from commit efa66e19.|2.6.22
[motion2.git] / server / components / encryptor / index.js
index 075dcd3..3b3a44d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1905=['end','final','close','unlink','decryptFile','createDecipher','encryptString','secret','base64','utf8','crypto','bluebird','lodash','../../config/logger','secrets','aes-256-ctr','algorithm','encrypt','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','data','update','binary','write'];(function(_0x39519d,_0x3345e1){var _0x483149=function(_0xad7083){while(--_0xad7083){_0x39519d['push'](_0x39519d['shift']());}};_0x483149(++_0x3345e1);}(_0x1905,0xaf));var _0x5190=function(_0x2424ca,_0x120f28){_0x2424ca=_0x2424ca-0x0;var _0x7d577a=_0x1905[_0x2424ca];return _0x7d577a;};'use strict';var crypto=require(_0x5190('0x0'));var fs=require('fs');var BPromise=require(_0x5190('0x1'));var _=require(_0x5190('0x2'));var config=require('../../config/environment');var logger=require(_0x5190('0x3'))('app');const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x5190('0x4')]['session'],'algorithm':_0x5190('0x5')};const fileOptions={'algorithm':'aes192'};if(config['encrypt']&&config['encrypt'][_0x5190('0x6')]){var isSupported=isAlgorithmSupported(config[_0x5190('0x7')][_0x5190('0x6')]);if(isSupported){fileOptions[_0x5190('0x6')]=config['encrypt'][_0x5190('0x6')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x5190('0x8')](',\x20');logger[_0x5190('0x9')](config['encrypt']['algorithm'],_0x5190('0xa'),supportedAlgorithms);}}function isASupportedCipher(_0x1f6179){return AES_SUPPORTED_RX[_0x5190('0xb')](_0x1f6179);}function getSupportedCiphers(){return crypto[_0x5190('0xc')]()['filter'](isASupportedCipher);}function isAlgorithmSupported(_0x3fbd97){return getSupportedCiphers()[_0x5190('0xd')](_0x3fbd97)>-0x1;}function combineOptions(_0x4d5aa2){var _0x3779d4={};for(var _0x5b6efb in fileOptions){if(fileOptions[_0x5190('0xe')](_0x5b6efb)){_0x3779d4[_0x5b6efb]=fileOptions[_0x5b6efb];}}if(_0x4d5aa2){for(var _0x2b70f8 in _0x4d5aa2){if(_0x4d5aa2[_0x5190('0xe')](_0x2b70f8)){_0x3779d4[_0x2b70f8]=_0x4d5aa2[_0x2b70f8];}}}return _0x3779d4;}exports[_0x5190('0xf')]=function(_0x1e6803,_0x54353e,_0x4bb526,_0x334bc5){return new BPromise(function(_0xfb2faa,_0x1b590c){_0x334bc5=combineOptions(_0x334bc5);var _0x3bc522=new Buffer(_0x4bb526);var _0x2115c1=fs[_0x5190('0x10')](_0x1e6803);var _0x47ef92=fs[_0x5190('0x11')](_0x54353e);var _0x5e7850=crypto[_0x5190('0x12')](_0x334bc5['algorithm'],_0x3bc522);_0x2115c1['on'](_0x5190('0x13'),function(_0x4a02f3){var _0x2ea3c9=new Buffer(_0x5e7850[_0x5190('0x14')](_0x4a02f3),_0x5190('0x15'));_0x47ef92[_0x5190('0x16')](_0x2ea3c9);});_0x2115c1['on'](_0x5190('0x17'),function(){try{var _0x44ec25=new Buffer(_0x5e7850[_0x5190('0x18')](_0x5190('0x15')),_0x5190('0x15'));_0x47ef92[_0x5190('0x16')](_0x44ec25);_0x47ef92[_0x5190('0x17')]();_0x47ef92['on'](_0x5190('0x19'),function(){return _0xfb2faa(_0x54353e);});}catch(_0x143f86){fs[_0x5190('0x1a')](_0x54353e);return _0x1b590c(_0x143f86);}});});};exports[_0x5190('0x1b')]=function(_0x3f269a,_0x43dee3,_0x5f7426,_0x217742){return new BPromise(function(_0x4bbe37,_0x3adca8){_0x217742=combineOptions(_0x217742);var _0x1d8095=new Buffer(_0x5f7426);var _0x33659a=fs[_0x5190('0x10')](_0x3f269a);var _0x566422=fs[_0x5190('0x11')](_0x43dee3);var _0x3cd849=crypto[_0x5190('0x1c')](_0x217742[_0x5190('0x6')],_0x1d8095);_0x33659a['on'](_0x5190('0x13'),function(_0x5b5ee9){var _0x4cbbd0=new Buffer(_0x3cd849['update'](_0x5b5ee9),_0x5190('0x15'));_0x566422['write'](_0x4cbbd0);});_0x33659a['on'](_0x5190('0x17'),function(){try{var _0x219a98=new Buffer(_0x3cd849['final'](_0x5190('0x15')),_0x5190('0x15'));_0x566422['write'](_0x219a98);_0x566422[_0x5190('0x17')]();_0x566422['on'](_0x5190('0x19'),function(){return _0x4bbe37(_0x43dee3);});}catch(_0x190fad){fs[_0x5190('0x1a')](_0x43dee3);return _0x3adca8(_0x190fad);}});});};exports[_0x5190('0x1d')]=function(_0x40088e,_0x3369f7,_0x5811a6){var _0x49ac94=_0x5811a6||stringOptions['algorithm'];var _0x3fb333=_0x3369f7||stringOptions[_0x5190('0x1e')];var _0x2cdaa4=crypto['createCipher'](_0x49ac94,_0x3fb333);var _0xc74fcb=_0x2cdaa4['update'](_0x40088e,'utf8','base64');_0xc74fcb+=_0x2cdaa4['final'](_0x5190('0x1f'));return _0xc74fcb;};exports['decryptString']=function(_0x653016,_0x15665b,_0x1ac0d7){var _0x111896=_0x1ac0d7||stringOptions[_0x5190('0x6')];var _0x4c858c=_0x15665b||stringOptions[_0x5190('0x1e')];var _0x46a3f3=crypto[_0x5190('0x1c')](_0x111896,_0x4c858c);var _0x349f78=_0x46a3f3[_0x5190('0x14')](_0x653016,_0x5190('0x1f'),_0x5190('0x20'));_0x349f78+=_0x46a3f3[_0x5190('0x18')](_0x5190('0x20'));return _0x349f78;};
\ No newline at end of file
+var _0x9c38=['data','update','binary','write','close','unlink','decryptFile','createReadStream','createDecipher','end','encryptString','secret','utf8','final','decryptString','base64','crypto','bluebird','lodash','../../config/environment','app','secrets','session','aes-256-ctr','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','filter','indexOf','hasOwnProperty','encryptFile','createWriteStream','createCipher'];(function(_0x325abf,_0x42ee54){var _0xe95e47=function(_0x3e2b70){while(--_0x3e2b70){_0x325abf['push'](_0x325abf['shift']());}};_0xe95e47(++_0x42ee54);}(_0x9c38,0xe8));var _0x89c3=function(_0x358981,_0x5ec73e){_0x358981=_0x358981-0x0;var _0x401f07=_0x9c38[_0x358981];return _0x401f07;};'use strict';var crypto=require(_0x89c3('0x0'));var fs=require('fs');var BPromise=require(_0x89c3('0x1'));var _=require(_0x89c3('0x2'));var config=require(_0x89c3('0x3'));var logger=require('../../config/logger')(_0x89c3('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x89c3('0x5')][_0x89c3('0x6')],'algorithm':_0x89c3('0x7')};const fileOptions={'algorithm':_0x89c3('0x8')};if(config[_0x89c3('0x9')]&&config[_0x89c3('0x9')][_0x89c3('0xa')]){var isSupported=isAlgorithmSupported(config[_0x89c3('0x9')][_0x89c3('0xa')]);if(isSupported){fileOptions['algorithm']=config['encrypt'][_0x89c3('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x89c3('0xb')](',\x20');logger[_0x89c3('0xc')](config[_0x89c3('0x9')][_0x89c3('0xa')],_0x89c3('0xd'),supportedAlgorithms);}}function isASupportedCipher(_0x3ff481){return AES_SUPPORTED_RX['test'](_0x3ff481);}function getSupportedCiphers(){return crypto['getCiphers']()[_0x89c3('0xe')](isASupportedCipher);}function isAlgorithmSupported(_0x5d46c5){return getSupportedCiphers()[_0x89c3('0xf')](_0x5d46c5)>-0x1;}function combineOptions(_0x5284f6){var _0x2178b2={};for(var _0xe85867 in fileOptions){if(fileOptions[_0x89c3('0x10')](_0xe85867)){_0x2178b2[_0xe85867]=fileOptions[_0xe85867];}}if(_0x5284f6){for(var _0x7a9dce in _0x5284f6){if(_0x5284f6[_0x89c3('0x10')](_0x7a9dce)){_0x2178b2[_0x7a9dce]=_0x5284f6[_0x7a9dce];}}}return _0x2178b2;}exports[_0x89c3('0x11')]=function(_0x3c4140,_0x232db0,_0x58eaac,_0x480f62){return new BPromise(function(_0x2e50e6,_0x236ccb){_0x480f62=combineOptions(_0x480f62);var _0x18c214=new Buffer(_0x58eaac);var _0x198dde=fs['createReadStream'](_0x3c4140);var _0x1c4509=fs[_0x89c3('0x12')](_0x232db0);var _0x12935c=crypto[_0x89c3('0x13')](_0x480f62[_0x89c3('0xa')],_0x18c214);_0x198dde['on'](_0x89c3('0x14'),function(_0x178774){var _0x15b8fd=new Buffer(_0x12935c[_0x89c3('0x15')](_0x178774),_0x89c3('0x16'));_0x1c4509[_0x89c3('0x17')](_0x15b8fd);});_0x198dde['on']('end',function(){try{var _0x3be70b=new Buffer(_0x12935c['final'](_0x89c3('0x16')),'binary');_0x1c4509[_0x89c3('0x17')](_0x3be70b);_0x1c4509['end']();_0x1c4509['on'](_0x89c3('0x18'),function(){return _0x2e50e6(_0x232db0);});}catch(_0x239979){fs[_0x89c3('0x19')](_0x232db0);return _0x236ccb(_0x239979);}});});};exports[_0x89c3('0x1a')]=function(_0x5144cc,_0x2abc82,_0x4de838,_0x2249f4){return new BPromise(function(_0x2cec2e,_0x79b9dc){_0x2249f4=combineOptions(_0x2249f4);var _0x1f4b2e=new Buffer(_0x4de838);var _0x5dbcc1=fs[_0x89c3('0x1b')](_0x5144cc);var _0x3540f5=fs[_0x89c3('0x12')](_0x2abc82);var _0x113a90=crypto[_0x89c3('0x1c')](_0x2249f4[_0x89c3('0xa')],_0x1f4b2e);_0x5dbcc1['on'](_0x89c3('0x14'),function(_0x161668){var _0x561ddd=new Buffer(_0x113a90[_0x89c3('0x15')](_0x161668),'binary');_0x3540f5[_0x89c3('0x17')](_0x561ddd);});_0x5dbcc1['on'](_0x89c3('0x1d'),function(){try{var _0xada8f1=new Buffer(_0x113a90['final'](_0x89c3('0x16')),_0x89c3('0x16'));_0x3540f5['write'](_0xada8f1);_0x3540f5[_0x89c3('0x1d')]();_0x3540f5['on'](_0x89c3('0x18'),function(){return _0x2cec2e(_0x2abc82);});}catch(_0x3aef1e){fs[_0x89c3('0x19')](_0x2abc82);return _0x79b9dc(_0x3aef1e);}});});};exports[_0x89c3('0x1e')]=function(_0x110714,_0x1e84be,_0x48b6b5){var _0x3327f2=_0x48b6b5||stringOptions[_0x89c3('0xa')];var _0x1cf4ba=_0x1e84be||stringOptions[_0x89c3('0x1f')];var _0x5484d6=crypto[_0x89c3('0x13')](_0x3327f2,_0x1cf4ba);var _0x155be7=_0x5484d6[_0x89c3('0x15')](_0x110714,_0x89c3('0x20'),'base64');_0x155be7+=_0x5484d6[_0x89c3('0x21')]('base64');return _0x155be7;};exports[_0x89c3('0x22')]=function(_0x1f46d8,_0x30156d,_0x5bb6f5){var _0x3c03a2=_0x5bb6f5||stringOptions[_0x89c3('0xa')];var _0x3e55f5=_0x30156d||stringOptions[_0x89c3('0x1f')];var _0x48e85a=crypto[_0x89c3('0x1c')](_0x3c03a2,_0x3e55f5);var _0x3e1d2f=_0x48e85a[_0x89c3('0x15')](_0x1f46d8,_0x89c3('0x23'),'utf8');_0x3e1d2f+=_0x48e85a[_0x89c3('0x21')](_0x89c3('0x20'));return _0x3e1d2f;};
\ No newline at end of file