Built motion from commit f74363e9.|2.6.34
[motion2.git] / server / components / encryptor / index.js
index c3f3ebc..797ee41 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5b95=['write','end','close','unlink','decryptFile','createReadStream','createWriteStream','createDecipher','final','encryptString','secret','base64','decryptString','utf8','bluebird','lodash','../../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','getCiphers','filter','indexOf','encryptFile','createCipher','data','update','binary'];(function(_0x35e1b3,_0x464aa6){var _0x472a30=function(_0x53b1c5){while(--_0x53b1c5){_0x35e1b3['push'](_0x35e1b3['shift']());}};_0x472a30(++_0x464aa6);}(_0x5b95,0xe6));var _0x55b9=function(_0x47aa64,_0xfb8a07){_0x47aa64=_0x47aa64-0x0;var _0x549c7a=_0x5b95[_0x47aa64];return _0x549c7a;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0x55b9('0x0'));var _=require(_0x55b9('0x1'));var config=require(_0x55b9('0x2'));var logger=require(_0x55b9('0x3'))('app');const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x55b9('0x4')][_0x55b9('0x5')],'algorithm':_0x55b9('0x6')};const fileOptions={'algorithm':_0x55b9('0x7')};if(config[_0x55b9('0x8')]&&config[_0x55b9('0x8')][_0x55b9('0x9')]){var isSupported=isAlgorithmSupported(config['encrypt'][_0x55b9('0x9')]);if(isSupported){fileOptions[_0x55b9('0x9')]=config['encrypt'][_0x55b9('0x9')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x55b9('0xa')](',\x20');logger[_0x55b9('0xb')](config[_0x55b9('0x8')][_0x55b9('0x9')],_0x55b9('0xc'),supportedAlgorithms);}}function isASupportedCipher(_0x3b2f4e){return AES_SUPPORTED_RX[_0x55b9('0xd')](_0x3b2f4e);}function getSupportedCiphers(){return crypto[_0x55b9('0xe')]()[_0x55b9('0xf')](isASupportedCipher);}function isAlgorithmSupported(_0x2673ee){return getSupportedCiphers()[_0x55b9('0x10')](_0x2673ee)>-0x1;}function combineOptions(_0x3f7a5c){var _0x4cc59c={};for(var _0x4436ea in fileOptions){if(fileOptions['hasOwnProperty'](_0x4436ea)){_0x4cc59c[_0x4436ea]=fileOptions[_0x4436ea];}}if(_0x3f7a5c){for(var _0x411047 in _0x3f7a5c){if(_0x3f7a5c['hasOwnProperty'](_0x411047)){_0x4cc59c[_0x411047]=_0x3f7a5c[_0x411047];}}}return _0x4cc59c;}exports[_0x55b9('0x11')]=function(_0x2bb327,_0x4a0fa6,_0x2a782e,_0x231ea1){return new BPromise(function(_0x51f260,_0x369e15){_0x231ea1=combineOptions(_0x231ea1);var _0x3284fd=new Buffer(_0x2a782e);var _0x170ab7=fs['createReadStream'](_0x2bb327);var _0x3b70f9=fs['createWriteStream'](_0x4a0fa6);var _0xa9a0a7=crypto[_0x55b9('0x12')](_0x231ea1[_0x55b9('0x9')],_0x3284fd);_0x170ab7['on'](_0x55b9('0x13'),function(_0x49e6ef){var _0x58f626=new Buffer(_0xa9a0a7[_0x55b9('0x14')](_0x49e6ef),_0x55b9('0x15'));_0x3b70f9[_0x55b9('0x16')](_0x58f626);});_0x170ab7['on'](_0x55b9('0x17'),function(){try{var _0x3088d2=new Buffer(_0xa9a0a7['final'](_0x55b9('0x15')),_0x55b9('0x15'));_0x3b70f9[_0x55b9('0x16')](_0x3088d2);_0x3b70f9[_0x55b9('0x17')]();_0x3b70f9['on'](_0x55b9('0x18'),function(){return _0x51f260(_0x4a0fa6);});}catch(_0xf3400b){fs[_0x55b9('0x19')](_0x4a0fa6);return _0x369e15(_0xf3400b);}});});};exports[_0x55b9('0x1a')]=function(_0x48522d,_0x2084df,_0x4e5be6,_0x4af354){return new BPromise(function(_0x1d962d,_0x17732e){_0x4af354=combineOptions(_0x4af354);var _0x1d11f6=new Buffer(_0x4e5be6);var _0x2c22c4=fs[_0x55b9('0x1b')](_0x48522d);var _0x541bb1=fs[_0x55b9('0x1c')](_0x2084df);var _0x5f5d43=crypto[_0x55b9('0x1d')](_0x4af354[_0x55b9('0x9')],_0x1d11f6);_0x2c22c4['on'](_0x55b9('0x13'),function(_0x44419f){var _0x5f5af5=new Buffer(_0x5f5d43[_0x55b9('0x14')](_0x44419f),_0x55b9('0x15'));_0x541bb1['write'](_0x5f5af5);});_0x2c22c4['on'](_0x55b9('0x17'),function(){try{var _0x4ab293=new Buffer(_0x5f5d43[_0x55b9('0x1e')](_0x55b9('0x15')),_0x55b9('0x15'));_0x541bb1['write'](_0x4ab293);_0x541bb1[_0x55b9('0x17')]();_0x541bb1['on'](_0x55b9('0x18'),function(){return _0x1d962d(_0x2084df);});}catch(_0x14c0b4){fs['unlink'](_0x2084df);return _0x17732e(_0x14c0b4);}});});};exports[_0x55b9('0x1f')]=function(_0x45e2a6,_0xb2178d,_0x1ab658){var _0x171571=_0x1ab658||stringOptions[_0x55b9('0x9')];var _0x4e246a=_0xb2178d||stringOptions[_0x55b9('0x20')];var _0x3b2490=crypto['createCipher'](_0x171571,_0x4e246a);var _0x3e33fe=_0x3b2490['update'](_0x45e2a6,'utf8','base64');_0x3e33fe+=_0x3b2490['final'](_0x55b9('0x21'));return _0x3e33fe;};exports[_0x55b9('0x22')]=function(_0x39e7c8,_0x85b3b4,_0x224142){var _0x5ac434=_0x224142||stringOptions[_0x55b9('0x9')];var _0x53c94b=_0x85b3b4||stringOptions['secret'];var _0x2586cd=crypto[_0x55b9('0x1d')](_0x5ac434,_0x53c94b);var _0x2c5680=_0x2586cd[_0x55b9('0x14')](_0x39e7c8,_0x55b9('0x21'),_0x55b9('0x23'));_0x2c5680+=_0x2586cd['final'](_0x55b9('0x23'));return _0x2c5680;};
\ No newline at end of file
+var _0xd796=['write','final','end','close','unlink','createReadStream','createWriteStream','secret','base64','decryptString','utf8','bluebird','lodash','../../config/environment','secrets','session','aes192','encrypt','algorithm','join','getCiphers','filter','indexOf','createCipher','data','update','binary'];(function(_0x3ba527,_0x446a5e){var _0x5ee6ad=function(_0x5978c7){while(--_0x5978c7){_0x3ba527['push'](_0x3ba527['shift']());}};_0x5ee6ad(++_0x446a5e);}(_0xd796,0xfe));var _0x6d79=function(_0x3e5fd7,_0x5e5033){_0x3e5fd7=_0x3e5fd7-0x0;var _0x5b05b2=_0xd796[_0x3e5fd7];return _0x5b05b2;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0x6d79('0x0'));var _=require(_0x6d79('0x1'));var config=require(_0x6d79('0x2'));var logger=require('../../config/logger')('app');const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0x6d79('0x3')][_0x6d79('0x4')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0x6d79('0x5')};if(config[_0x6d79('0x6')]&&config['encrypt'][_0x6d79('0x7')]){var isSupported=isAlgorithmSupported(config[_0x6d79('0x6')][_0x6d79('0x7')]);if(isSupported){fileOptions[_0x6d79('0x7')]=config[_0x6d79('0x6')]['algorithm'];}else{var supportedAlgorithms=getSupportedCiphers()[_0x6d79('0x8')](',\x20');logger['error'](config[_0x6d79('0x6')][_0x6d79('0x7')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x486e5a){return AES_SUPPORTED_RX['test'](_0x486e5a);}function getSupportedCiphers(){return crypto[_0x6d79('0x9')]()[_0x6d79('0xa')](isASupportedCipher);}function isAlgorithmSupported(_0x452e91){return getSupportedCiphers()[_0x6d79('0xb')](_0x452e91)>-0x1;}function combineOptions(_0x3a6ce2){var _0x3d4fb6={};for(var _0x4f10a6 in fileOptions){if(fileOptions['hasOwnProperty'](_0x4f10a6)){_0x3d4fb6[_0x4f10a6]=fileOptions[_0x4f10a6];}}if(_0x3a6ce2){for(var _0x5d412b in _0x3a6ce2){if(_0x3a6ce2['hasOwnProperty'](_0x5d412b)){_0x3d4fb6[_0x5d412b]=_0x3a6ce2[_0x5d412b];}}}return _0x3d4fb6;}exports['encryptFile']=function(_0x4adae1,_0x3b2aac,_0xbc1573,_0x591838){return new BPromise(function(_0x42a807,_0x2de2df){_0x591838=combineOptions(_0x591838);var _0xa4f8f4=new Buffer(_0xbc1573);var _0x162052=fs['createReadStream'](_0x4adae1);var _0x1eb62a=fs['createWriteStream'](_0x3b2aac);var _0x413ba3=crypto[_0x6d79('0xc')](_0x591838[_0x6d79('0x7')],_0xa4f8f4);_0x162052['on'](_0x6d79('0xd'),function(_0x1333a0){var _0xeda108=new Buffer(_0x413ba3[_0x6d79('0xe')](_0x1333a0),_0x6d79('0xf'));_0x1eb62a[_0x6d79('0x10')](_0xeda108);});_0x162052['on']('end',function(){try{var _0x51097c=new Buffer(_0x413ba3[_0x6d79('0x11')]('binary'),_0x6d79('0xf'));_0x1eb62a[_0x6d79('0x10')](_0x51097c);_0x1eb62a[_0x6d79('0x12')]();_0x1eb62a['on'](_0x6d79('0x13'),function(){return _0x42a807(_0x3b2aac);});}catch(_0xb89a1d){fs[_0x6d79('0x14')](_0x3b2aac);return _0x2de2df(_0xb89a1d);}});});};exports['decryptFile']=function(_0x5b1896,_0x4a339b,_0x51b44a,_0x25c82c){return new BPromise(function(_0x593a97,_0x530b6f){_0x25c82c=combineOptions(_0x25c82c);var _0x56ca2c=new Buffer(_0x51b44a);var _0x1c4165=fs[_0x6d79('0x15')](_0x5b1896);var _0x23e598=fs[_0x6d79('0x16')](_0x4a339b);var _0x51b22f=crypto['createDecipher'](_0x25c82c[_0x6d79('0x7')],_0x56ca2c);_0x1c4165['on']('data',function(_0x4d4f88){var _0x553ec=new Buffer(_0x51b22f['update'](_0x4d4f88),_0x6d79('0xf'));_0x23e598[_0x6d79('0x10')](_0x553ec);});_0x1c4165['on'](_0x6d79('0x12'),function(){try{var _0x52a543=new Buffer(_0x51b22f[_0x6d79('0x11')](_0x6d79('0xf')),'binary');_0x23e598[_0x6d79('0x10')](_0x52a543);_0x23e598[_0x6d79('0x12')]();_0x23e598['on'](_0x6d79('0x13'),function(){return _0x593a97(_0x4a339b);});}catch(_0x35c2f9){fs['unlink'](_0x4a339b);return _0x530b6f(_0x35c2f9);}});});};exports['encryptString']=function(_0x2a12ea,_0xa89641,_0x4d1b23){var _0x37cfae=_0x4d1b23||stringOptions[_0x6d79('0x7')];var _0x5ba88f=_0xa89641||stringOptions[_0x6d79('0x17')];var _0x3fb283=crypto[_0x6d79('0xc')](_0x37cfae,_0x5ba88f);var _0x374e25=_0x3fb283['update'](_0x2a12ea,'utf8',_0x6d79('0x18'));_0x374e25+=_0x3fb283['final'](_0x6d79('0x18'));return _0x374e25;};exports[_0x6d79('0x19')]=function(_0x1b560f,_0x4bb630,_0x5b8714){var _0x4dd00a=_0x5b8714||stringOptions[_0x6d79('0x7')];var _0x426a19=_0x4bb630||stringOptions[_0x6d79('0x17')];var _0x5005a8=crypto['createDecipher'](_0x4dd00a,_0x426a19);var _0x545d56=_0x5005a8[_0x6d79('0xe')](_0x1b560f,_0x6d79('0x18'),_0x6d79('0x1a'));_0x545d56+=_0x5005a8[_0x6d79('0x11')](_0x6d79('0x1a'));return _0x545d56;};
\ No newline at end of file