Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / server / components / encryptor / index.js
index a732482..06a0d43 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe10e=['update','binary','write','end','final','close','unlink','decryptFile','createDecipher','utf8','base64','decryptString','secret','crypto','bluebird','../../config/environment','../../config/logger','app','secrets','session','aes192','algorithm','encrypt','join','error','test','getCiphers','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','data'];(function(_0x5ddb91,_0x50a3c6){var _0x222f31=function(_0x543d54){while(--_0x543d54){_0x5ddb91['push'](_0x5ddb91['shift']());}};_0x222f31(++_0x50a3c6);}(_0xe10e,0x13f));var _0xee10=function(_0x119280,_0x439c3e){_0x119280=_0x119280-0x0;var _0x481797=_0xe10e[_0x119280];return _0x481797;};'use strict';var crypto=require(_0xee10('0x0'));var fs=require('fs');var BPromise=require(_0xee10('0x1'));var _=require('lodash');var config=require(_0xee10('0x2'));var logger=require(_0xee10('0x3'))(_0xee10('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0xee10('0x5')][_0xee10('0x6')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0xee10('0x7')};if(config['encrypt']&&config['encrypt'][_0xee10('0x8')]){var isSupported=isAlgorithmSupported(config[_0xee10('0x9')]['algorithm']);if(isSupported){fileOptions[_0xee10('0x8')]=config[_0xee10('0x9')][_0xee10('0x8')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xee10('0xa')](',\x20');logger[_0xee10('0xb')](config['encrypt']['algorithm'],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x3be4e8){return AES_SUPPORTED_RX[_0xee10('0xc')](_0x3be4e8);}function getSupportedCiphers(){return crypto[_0xee10('0xd')]()['filter'](isASupportedCipher);}function isAlgorithmSupported(_0x48c336){return getSupportedCiphers()[_0xee10('0xe')](_0x48c336)>-0x1;}function combineOptions(_0xaf211){var _0x58663b={};for(var _0x294689 in fileOptions){if(fileOptions['hasOwnProperty'](_0x294689)){_0x58663b[_0x294689]=fileOptions[_0x294689];}}if(_0xaf211){for(var _0x466fc8 in _0xaf211){if(_0xaf211[_0xee10('0xf')](_0x466fc8)){_0x58663b[_0x466fc8]=_0xaf211[_0x466fc8];}}}return _0x58663b;}exports[_0xee10('0x10')]=function(_0x582b80,_0x3d2424,_0x2d431b,_0x5c32b4){return new BPromise(function(_0x1ac021,_0x10d7ac){_0x5c32b4=combineOptions(_0x5c32b4);var _0x59b586=new Buffer(_0x2d431b);var _0x56e107=fs[_0xee10('0x11')](_0x582b80);var _0x30d52e=fs[_0xee10('0x12')](_0x3d2424);var _0xf121ff=crypto[_0xee10('0x13')](_0x5c32b4[_0xee10('0x8')],_0x59b586);_0x56e107['on'](_0xee10('0x14'),function(_0x1aab61){var _0x4f527f=new Buffer(_0xf121ff[_0xee10('0x15')](_0x1aab61),_0xee10('0x16'));_0x30d52e[_0xee10('0x17')](_0x4f527f);});_0x56e107['on'](_0xee10('0x18'),function(){try{var _0x2d1211=new Buffer(_0xf121ff[_0xee10('0x19')]('binary'),'binary');_0x30d52e[_0xee10('0x17')](_0x2d1211);_0x30d52e[_0xee10('0x18')]();_0x30d52e['on'](_0xee10('0x1a'),function(){return _0x1ac021(_0x3d2424);});}catch(_0x55cac1){fs[_0xee10('0x1b')](_0x3d2424);return _0x10d7ac(_0x55cac1);}});});};exports[_0xee10('0x1c')]=function(_0x5dc5a7,_0x314fc8,_0x53277a,_0x3eca68){return new BPromise(function(_0x24a452,_0x52775c){_0x3eca68=combineOptions(_0x3eca68);var _0x59a443=new Buffer(_0x53277a);var _0x574247=fs['createReadStream'](_0x5dc5a7);var _0x1473f6=fs[_0xee10('0x12')](_0x314fc8);var _0x4d85bb=crypto[_0xee10('0x1d')](_0x3eca68[_0xee10('0x8')],_0x59a443);_0x574247['on'](_0xee10('0x14'),function(_0x3f9e8c){var _0x3e4d5b=new Buffer(_0x4d85bb[_0xee10('0x15')](_0x3f9e8c),_0xee10('0x16'));_0x1473f6[_0xee10('0x17')](_0x3e4d5b);});_0x574247['on'](_0xee10('0x18'),function(){try{var _0x2cc7ab=new Buffer(_0x4d85bb['final']('binary'),'binary');_0x1473f6[_0xee10('0x17')](_0x2cc7ab);_0x1473f6[_0xee10('0x18')]();_0x1473f6['on'](_0xee10('0x1a'),function(){return _0x24a452(_0x314fc8);});}catch(_0x1e472b){fs[_0xee10('0x1b')](_0x314fc8);return _0x52775c(_0x1e472b);}});});};exports['encryptString']=function(_0x20494d,_0xe8ba8d,_0x316f91){var _0xb68dd4=_0x316f91||stringOptions['algorithm'];var _0x36d6ec=_0xe8ba8d||stringOptions['secret'];var _0x440bba=crypto[_0xee10('0x13')](_0xb68dd4,_0x36d6ec);var _0x1f4b1c=_0x440bba['update'](_0x20494d,_0xee10('0x1e'),_0xee10('0x1f'));_0x1f4b1c+=_0x440bba[_0xee10('0x19')](_0xee10('0x1f'));return _0x1f4b1c;};exports[_0xee10('0x20')]=function(_0x1fdc02,_0x189a80,_0x2e6051){var _0x497096=_0x2e6051||stringOptions[_0xee10('0x8')];var _0x420e6f=_0x189a80||stringOptions[_0xee10('0x21')];var _0x2cb885=crypto['createDecipher'](_0x497096,_0x420e6f);var _0x47d39e=_0x2cb885[_0xee10('0x15')](_0x1fdc02,'base64',_0xee10('0x1e'));_0x47d39e+=_0x2cb885['final']('utf8');return _0x47d39e;};
\ No newline at end of file
+var _0xe2ad=['base64','crypto','bluebird','lodash','../../config/environment','app','session','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','filter','indexOf','hasOwnProperty','createWriteStream','createCipher','binary','write','end','final','close','unlink','decryptFile','createReadStream','createDecipher','data','secret','update','utf8'];(function(_0x42a562,_0x1e2b54){var _0x340e5a=function(_0x19990e){while(--_0x19990e){_0x42a562['push'](_0x42a562['shift']());}};_0x340e5a(++_0x1e2b54);}(_0xe2ad,0x12a));var _0xde2a=function(_0x13ba21,_0x190d6e){_0x13ba21=_0x13ba21-0x0;var _0x4307f6=_0xe2ad[_0x13ba21];return _0x4307f6;};'use strict';var crypto=require(_0xde2a('0x0'));var fs=require('fs');var BPromise=require(_0xde2a('0x1'));var _=require(_0xde2a('0x2'));var config=require(_0xde2a('0x3'));var logger=require('../../config/logger')(_0xde2a('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0xde2a('0x5')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0xde2a('0x6')};if(config[_0xde2a('0x7')]&&config[_0xde2a('0x7')][_0xde2a('0x8')]){var isSupported=isAlgorithmSupported(config[_0xde2a('0x7')][_0xde2a('0x8')]);if(isSupported){fileOptions[_0xde2a('0x8')]=config['encrypt'][_0xde2a('0x8')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xde2a('0x9')](',\x20');logger[_0xde2a('0xa')](config[_0xde2a('0x7')]['algorithm'],_0xde2a('0xb'),supportedAlgorithms);}}function isASupportedCipher(_0x1dff82){return AES_SUPPORTED_RX[_0xde2a('0xc')](_0x1dff82);}function getSupportedCiphers(){return crypto[_0xde2a('0xd')]()[_0xde2a('0xe')](isASupportedCipher);}function isAlgorithmSupported(_0x30cc8e){return getSupportedCiphers()[_0xde2a('0xf')](_0x30cc8e)>-0x1;}function combineOptions(_0x29cf57){var _0x302ad6={};for(var _0x5de86a in fileOptions){if(fileOptions['hasOwnProperty'](_0x5de86a)){_0x302ad6[_0x5de86a]=fileOptions[_0x5de86a];}}if(_0x29cf57){for(var _0x2f8e14 in _0x29cf57){if(_0x29cf57[_0xde2a('0x10')](_0x2f8e14)){_0x302ad6[_0x2f8e14]=_0x29cf57[_0x2f8e14];}}}return _0x302ad6;}exports['encryptFile']=function(_0x14a4ae,_0x44dddb,_0x219628,_0x2c66d3){return new BPromise(function(_0x281e86,_0x4632aa){_0x2c66d3=combineOptions(_0x2c66d3);var _0x57465c=new Buffer(_0x219628);var _0x2e1e41=fs['createReadStream'](_0x14a4ae);var _0x4102b=fs[_0xde2a('0x11')](_0x44dddb);var _0x585409=crypto[_0xde2a('0x12')](_0x2c66d3[_0xde2a('0x8')],_0x57465c);_0x2e1e41['on']('data',function(_0x9abcce){var _0x4c3c6b=new Buffer(_0x585409['update'](_0x9abcce),_0xde2a('0x13'));_0x4102b[_0xde2a('0x14')](_0x4c3c6b);});_0x2e1e41['on'](_0xde2a('0x15'),function(){try{var _0x13a701=new Buffer(_0x585409[_0xde2a('0x16')](_0xde2a('0x13')),_0xde2a('0x13'));_0x4102b[_0xde2a('0x14')](_0x13a701);_0x4102b['end']();_0x4102b['on'](_0xde2a('0x17'),function(){return _0x281e86(_0x44dddb);});}catch(_0x2ecd10){fs[_0xde2a('0x18')](_0x44dddb);return _0x4632aa(_0x2ecd10);}});});};exports[_0xde2a('0x19')]=function(_0x2740b0,_0x556bb3,_0x17777e,_0x2d5903){return new BPromise(function(_0x4fc088,_0x396358){_0x2d5903=combineOptions(_0x2d5903);var _0x1035bb=new Buffer(_0x17777e);var _0x497b2d=fs[_0xde2a('0x1a')](_0x2740b0);var _0x16fa1a=fs[_0xde2a('0x11')](_0x556bb3);var _0x10f575=crypto[_0xde2a('0x1b')](_0x2d5903[_0xde2a('0x8')],_0x1035bb);_0x497b2d['on'](_0xde2a('0x1c'),function(_0x41bb39){var _0x373d1f=new Buffer(_0x10f575['update'](_0x41bb39),_0xde2a('0x13'));_0x16fa1a[_0xde2a('0x14')](_0x373d1f);});_0x497b2d['on']('end',function(){try{var _0x348e04=new Buffer(_0x10f575[_0xde2a('0x16')](_0xde2a('0x13')),_0xde2a('0x13'));_0x16fa1a[_0xde2a('0x14')](_0x348e04);_0x16fa1a[_0xde2a('0x15')]();_0x16fa1a['on']('close',function(){return _0x4fc088(_0x556bb3);});}catch(_0x21c512){fs[_0xde2a('0x18')](_0x556bb3);return _0x396358(_0x21c512);}});});};exports['encryptString']=function(_0x515bb4,_0x311c56,_0x104c9c){var _0x3ccfbd=_0x104c9c||stringOptions[_0xde2a('0x8')];var _0xc6ec4b=_0x311c56||stringOptions[_0xde2a('0x1d')];var _0x5dc3e6=crypto[_0xde2a('0x12')](_0x3ccfbd,_0xc6ec4b);var _0x474a86=_0x5dc3e6[_0xde2a('0x1e')](_0x515bb4,_0xde2a('0x1f'),'base64');_0x474a86+=_0x5dc3e6['final'](_0xde2a('0x20'));return _0x474a86;};exports['decryptString']=function(_0x94cf6f,_0x5eca71,_0x1ea076){var _0x3b3bee=_0x1ea076||stringOptions['algorithm'];var _0x53c595=_0x5eca71||stringOptions['secret'];var _0x125086=crypto['createDecipher'](_0x3b3bee,_0x53c595);var _0x57b279=_0x125086[_0xde2a('0x1e')](_0x94cf6f,_0xde2a('0x20'),_0xde2a('0x1f'));_0x57b279+=_0x125086['final'](_0xde2a('0x1f'));return _0x57b279;};
\ No newline at end of file