Built motion from commit 13c3002c.|2.6.9
[motion2.git] / server / components / encryptor / index.js
index 6a86e7a..7bcf405 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5fe6=['final','close','unlink','decryptFile','createDecipher','data','secret','base64','decryptString','crypto','lodash','../../config/environment','../../config/logger','app','session','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','filter','hasOwnProperty','createReadStream','createWriteStream','createCipher','update','binary','write','end'];(function(_0x456f31,_0x5d5e19){var _0x271ba1=function(_0x6cec4f){while(--_0x6cec4f){_0x456f31['push'](_0x456f31['shift']());}};_0x271ba1(++_0x5d5e19);}(_0x5fe6,0xc3));var _0x65fe=function(_0x45b050,_0xe2cb0a){_0x45b050=_0x45b050-0x0;var _0xcf1cd5=_0x5fe6[_0x45b050];return _0xcf1cd5;};'use strict';var crypto=require(_0x65fe('0x0'));var fs=require('fs');var BPromise=require('bluebird');var _=require(_0x65fe('0x1'));var config=require(_0x65fe('0x2'));var logger=require(_0x65fe('0x3'))(_0x65fe('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0x65fe('0x5')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0x65fe('0x6')};if(config[_0x65fe('0x7')]&&config['encrypt'][_0x65fe('0x8')]){var isSupported=isAlgorithmSupported(config[_0x65fe('0x7')]['algorithm']);if(isSupported){fileOptions[_0x65fe('0x8')]=config[_0x65fe('0x7')]['algorithm'];}else{var supportedAlgorithms=getSupportedCiphers()[_0x65fe('0x9')](',\x20');logger[_0x65fe('0xa')](config[_0x65fe('0x7')][_0x65fe('0x8')],_0x65fe('0xb'),supportedAlgorithms);}}function isASupportedCipher(_0x12aa16){return AES_SUPPORTED_RX[_0x65fe('0xc')](_0x12aa16);}function getSupportedCiphers(){return crypto['getCiphers']()[_0x65fe('0xd')](isASupportedCipher);}function isAlgorithmSupported(_0x11d90a){return getSupportedCiphers()['indexOf'](_0x11d90a)>-0x1;}function combineOptions(_0x966f6){var _0x37ca87={};for(var _0x4321c5 in fileOptions){if(fileOptions[_0x65fe('0xe')](_0x4321c5)){_0x37ca87[_0x4321c5]=fileOptions[_0x4321c5];}}if(_0x966f6){for(var _0xd4ec92 in _0x966f6){if(_0x966f6['hasOwnProperty'](_0xd4ec92)){_0x37ca87[_0xd4ec92]=_0x966f6[_0xd4ec92];}}}return _0x37ca87;}exports['encryptFile']=function(_0x26f7cc,_0x16a9ad,_0x476e7c,_0x29168a){return new BPromise(function(_0x43ec62,_0x52e7db){_0x29168a=combineOptions(_0x29168a);var _0x30a320=new Buffer(_0x476e7c);var _0x4ae8fb=fs[_0x65fe('0xf')](_0x26f7cc);var _0x7e00c0=fs[_0x65fe('0x10')](_0x16a9ad);var _0x42f940=crypto[_0x65fe('0x11')](_0x29168a[_0x65fe('0x8')],_0x30a320);_0x4ae8fb['on']('data',function(_0x4b555a){var _0x585b96=new Buffer(_0x42f940[_0x65fe('0x12')](_0x4b555a),_0x65fe('0x13'));_0x7e00c0[_0x65fe('0x14')](_0x585b96);});_0x4ae8fb['on'](_0x65fe('0x15'),function(){try{var _0x41989d=new Buffer(_0x42f940[_0x65fe('0x16')](_0x65fe('0x13')),'binary');_0x7e00c0[_0x65fe('0x14')](_0x41989d);_0x7e00c0[_0x65fe('0x15')]();_0x7e00c0['on'](_0x65fe('0x17'),function(){return _0x43ec62(_0x16a9ad);});}catch(_0x2c619b){fs[_0x65fe('0x18')](_0x16a9ad);return _0x52e7db(_0x2c619b);}});});};exports[_0x65fe('0x19')]=function(_0x112f72,_0x567e74,_0x449cf2,_0x45a10a){return new BPromise(function(_0x2b0b83,_0x7cf20){_0x45a10a=combineOptions(_0x45a10a);var _0x797048=new Buffer(_0x449cf2);var _0xea0ed0=fs[_0x65fe('0xf')](_0x112f72);var _0x1f9d72=fs[_0x65fe('0x10')](_0x567e74);var _0x48c138=crypto[_0x65fe('0x1a')](_0x45a10a[_0x65fe('0x8')],_0x797048);_0xea0ed0['on'](_0x65fe('0x1b'),function(_0x34a7d4){var _0x364e1f=new Buffer(_0x48c138['update'](_0x34a7d4),_0x65fe('0x13'));_0x1f9d72[_0x65fe('0x14')](_0x364e1f);});_0xea0ed0['on'](_0x65fe('0x15'),function(){try{var _0x4b9a6e=new Buffer(_0x48c138['final']('binary'),_0x65fe('0x13'));_0x1f9d72[_0x65fe('0x14')](_0x4b9a6e);_0x1f9d72[_0x65fe('0x15')]();_0x1f9d72['on']('close',function(){return _0x2b0b83(_0x567e74);});}catch(_0x208368){fs[_0x65fe('0x18')](_0x567e74);return _0x7cf20(_0x208368);}});});};exports['encryptString']=function(_0x2a3024,_0xad9a53,_0x29a6c5){var _0x45c3c3=_0x29a6c5||stringOptions[_0x65fe('0x8')];var _0x3b80a5=_0xad9a53||stringOptions[_0x65fe('0x1c')];var _0x1ef9ba=crypto[_0x65fe('0x11')](_0x45c3c3,_0x3b80a5);var _0x4285bb=_0x1ef9ba[_0x65fe('0x12')](_0x2a3024,'utf8',_0x65fe('0x1d'));_0x4285bb+=_0x1ef9ba[_0x65fe('0x16')](_0x65fe('0x1d'));return _0x4285bb;};exports[_0x65fe('0x1e')]=function(_0x3cc8f0,_0x121b47,_0x1d993a){var _0x4c30f8=_0x1d993a||stringOptions[_0x65fe('0x8')];var _0x3a7335=_0x121b47||stringOptions[_0x65fe('0x1c')];var _0x403b68=crypto[_0x65fe('0x1a')](_0x4c30f8,_0x3a7335);var _0x3abea7=_0x403b68['update'](_0x3cc8f0,_0x65fe('0x1d'),'utf8');_0x3abea7+=_0x403b68['final']('utf8');return _0x3abea7;};
\ No newline at end of file
+var _0x4bd2=['app','session','aes-256-ctr','aes192','encrypt','algorithm','test','getCiphers','hasOwnProperty','createReadStream','createCipher','update','binary','end','final','write','unlink','decryptFile','createWriteStream','createDecipher','data','close','encryptString','secret','utf8','base64','decryptString','lodash','../../config/environment'];(function(_0x46a422,_0x14ace5){var _0x56a5dc=function(_0x21107f){while(--_0x21107f){_0x46a422['push'](_0x46a422['shift']());}};_0x56a5dc(++_0x14ace5);}(_0x4bd2,0x177));var _0x24bd=function(_0x537184,_0x5b536e){_0x537184=_0x537184-0x0;var _0x56a947=_0x4bd2[_0x537184];return _0x56a947;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require('bluebird');var _=require(_0x24bd('0x0'));var config=require(_0x24bd('0x1'));var logger=require('../../config/logger')(_0x24bd('0x2'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0x24bd('0x3')],'algorithm':_0x24bd('0x4')};const fileOptions={'algorithm':_0x24bd('0x5')};if(config[_0x24bd('0x6')]&&config[_0x24bd('0x6')][_0x24bd('0x7')]){var isSupported=isAlgorithmSupported(config[_0x24bd('0x6')][_0x24bd('0x7')]);if(isSupported){fileOptions[_0x24bd('0x7')]=config['encrypt'][_0x24bd('0x7')];}else{var supportedAlgorithms=getSupportedCiphers()['join'](',\x20');logger['error'](config[_0x24bd('0x6')]['algorithm'],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x19760a){return AES_SUPPORTED_RX[_0x24bd('0x8')](_0x19760a);}function getSupportedCiphers(){return crypto[_0x24bd('0x9')]()['filter'](isASupportedCipher);}function isAlgorithmSupported(_0x4921c3){return getSupportedCiphers()['indexOf'](_0x4921c3)>-0x1;}function combineOptions(_0x28a186){var _0x280ed6={};for(var _0xab9408 in fileOptions){if(fileOptions['hasOwnProperty'](_0xab9408)){_0x280ed6[_0xab9408]=fileOptions[_0xab9408];}}if(_0x28a186){for(var _0x112b44 in _0x28a186){if(_0x28a186[_0x24bd('0xa')](_0x112b44)){_0x280ed6[_0x112b44]=_0x28a186[_0x112b44];}}}return _0x280ed6;}exports['encryptFile']=function(_0x54c2eb,_0x4d7d9c,_0x3f58b7,_0x31944a){return new BPromise(function(_0x2a2551,_0x1fa203){_0x31944a=combineOptions(_0x31944a);var _0x1f9e19=new Buffer(_0x3f58b7);var _0x4130ef=fs[_0x24bd('0xb')](_0x54c2eb);var _0x5e930c=fs['createWriteStream'](_0x4d7d9c);var _0x42e685=crypto[_0x24bd('0xc')](_0x31944a['algorithm'],_0x1f9e19);_0x4130ef['on']('data',function(_0x462745){var _0x563780=new Buffer(_0x42e685[_0x24bd('0xd')](_0x462745),_0x24bd('0xe'));_0x5e930c['write'](_0x563780);});_0x4130ef['on'](_0x24bd('0xf'),function(){try{var _0x468962=new Buffer(_0x42e685[_0x24bd('0x10')](_0x24bd('0xe')),_0x24bd('0xe'));_0x5e930c[_0x24bd('0x11')](_0x468962);_0x5e930c['end']();_0x5e930c['on']('close',function(){return _0x2a2551(_0x4d7d9c);});}catch(_0x52a2c7){fs[_0x24bd('0x12')](_0x4d7d9c);return _0x1fa203(_0x52a2c7);}});});};exports[_0x24bd('0x13')]=function(_0x4e1f6e,_0x1ca30f,_0x161be9,_0x110b73){return new BPromise(function(_0x4ec083,_0x3e2e30){_0x110b73=combineOptions(_0x110b73);var _0x44317e=new Buffer(_0x161be9);var _0x4e5e46=fs['createReadStream'](_0x4e1f6e);var _0xd2aa9a=fs[_0x24bd('0x14')](_0x1ca30f);var _0x382188=crypto[_0x24bd('0x15')](_0x110b73[_0x24bd('0x7')],_0x44317e);_0x4e5e46['on'](_0x24bd('0x16'),function(_0x408d42){var _0xa295b2=new Buffer(_0x382188[_0x24bd('0xd')](_0x408d42),'binary');_0xd2aa9a['write'](_0xa295b2);});_0x4e5e46['on']('end',function(){try{var _0x464104=new Buffer(_0x382188[_0x24bd('0x10')](_0x24bd('0xe')),'binary');_0xd2aa9a['write'](_0x464104);_0xd2aa9a['end']();_0xd2aa9a['on'](_0x24bd('0x17'),function(){return _0x4ec083(_0x1ca30f);});}catch(_0x75bb02){fs['unlink'](_0x1ca30f);return _0x3e2e30(_0x75bb02);}});});};exports[_0x24bd('0x18')]=function(_0x2c614f,_0x528960,_0xf55ca6){var _0x2e2ebc=_0xf55ca6||stringOptions[_0x24bd('0x7')];var _0x4816f6=_0x528960||stringOptions[_0x24bd('0x19')];var _0x2dd912=crypto[_0x24bd('0xc')](_0x2e2ebc,_0x4816f6);var _0x1bedb4=_0x2dd912['update'](_0x2c614f,_0x24bd('0x1a'),'base64');_0x1bedb4+=_0x2dd912[_0x24bd('0x10')](_0x24bd('0x1b'));return _0x1bedb4;};exports[_0x24bd('0x1c')]=function(_0x45e204,_0x4c6b61,_0x1d0a54){var _0x78de5c=_0x1d0a54||stringOptions[_0x24bd('0x7')];var _0x533800=_0x4c6b61||stringOptions['secret'];var _0x106be2=crypto[_0x24bd('0x15')](_0x78de5c,_0x533800);var _0x5c2a35=_0x106be2[_0x24bd('0xd')](_0x45e204,'base64',_0x24bd('0x1a'));_0x5c2a35+=_0x106be2[_0x24bd('0x10')](_0x24bd('0x1a'));return _0x5c2a35;};
\ No newline at end of file