Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / components / encryptor / index.js
index 5e47817..7b8e4b2 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x276c=['update','encryptString','secret','utf8','base64','decryptString','crypto','lodash','app','secrets','session','aes192','encrypt','algorithm','join','filter','indexOf','hasOwnProperty','encryptFile','createWriteStream','createCipher','binary','write','end','final','close','unlink','decryptFile','createReadStream','createDecipher','data'];(function(_0x53e937,_0x5d671b){var _0x35efed=function(_0x1c4bf8){while(--_0x1c4bf8){_0x53e937['push'](_0x53e937['shift']());}};_0x35efed(++_0x5d671b);}(_0x276c,0x17a));var _0xc276=function(_0x14499f,_0x16a1c1){_0x14499f=_0x14499f-0x0;var _0x26aa9e=_0x276c[_0x14499f];return _0x26aa9e;};'use strict';var crypto=require(_0xc276('0x0'));var fs=require('fs');var BPromise=require('bluebird');var _=require(_0xc276('0x1'));var config=require('../../config/environment');var logger=require('../../config/logger')(_0xc276('0x2'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0xc276('0x3')][_0xc276('0x4')],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0xc276('0x5')};if(config['encrypt']&&config[_0xc276('0x6')][_0xc276('0x7')]){var isSupported=isAlgorithmSupported(config[_0xc276('0x6')][_0xc276('0x7')]);if(isSupported){fileOptions[_0xc276('0x7')]=config['encrypt'][_0xc276('0x7')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xc276('0x8')](',\x20');logger['error'](config['encrypt'][_0xc276('0x7')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0x15f1bb){return AES_SUPPORTED_RX['test'](_0x15f1bb);}function getSupportedCiphers(){return crypto['getCiphers']()[_0xc276('0x9')](isASupportedCipher);}function isAlgorithmSupported(_0x92ec89){return getSupportedCiphers()[_0xc276('0xa')](_0x92ec89)>-0x1;}function combineOptions(_0x42ce36){var _0x50feac={};for(var _0xedffda in fileOptions){if(fileOptions[_0xc276('0xb')](_0xedffda)){_0x50feac[_0xedffda]=fileOptions[_0xedffda];}}if(_0x42ce36){for(var _0x574bd3 in _0x42ce36){if(_0x42ce36[_0xc276('0xb')](_0x574bd3)){_0x50feac[_0x574bd3]=_0x42ce36[_0x574bd3];}}}return _0x50feac;}exports[_0xc276('0xc')]=function(_0x4f5ee0,_0x14a90c,_0x5c248e,_0x1600e5){return new BPromise(function(_0x311131,_0x236fdd){_0x1600e5=combineOptions(_0x1600e5);var _0x12d2b5=new Buffer(_0x5c248e);var _0xe99c7e=fs['createReadStream'](_0x4f5ee0);var _0xc1d8fd=fs[_0xc276('0xd')](_0x14a90c);var _0x16796a=crypto[_0xc276('0xe')](_0x1600e5['algorithm'],_0x12d2b5);_0xe99c7e['on']('data',function(_0x351520){var _0x26a2d3=new Buffer(_0x16796a['update'](_0x351520),_0xc276('0xf'));_0xc1d8fd[_0xc276('0x10')](_0x26a2d3);});_0xe99c7e['on'](_0xc276('0x11'),function(){try{var _0x199dff=new Buffer(_0x16796a[_0xc276('0x12')](_0xc276('0xf')),_0xc276('0xf'));_0xc1d8fd['write'](_0x199dff);_0xc1d8fd['end']();_0xc1d8fd['on'](_0xc276('0x13'),function(){return _0x311131(_0x14a90c);});}catch(_0x150d05){fs[_0xc276('0x14')](_0x14a90c);return _0x236fdd(_0x150d05);}});});};exports[_0xc276('0x15')]=function(_0x3d3eeb,_0x1bef59,_0x5e5114,_0x2ba16f){return new BPromise(function(_0xd8d4ad,_0x9e9afa){_0x2ba16f=combineOptions(_0x2ba16f);var _0x45c4a4=new Buffer(_0x5e5114);var _0x3ba3bc=fs[_0xc276('0x16')](_0x3d3eeb);var _0x547071=fs[_0xc276('0xd')](_0x1bef59);var _0x3aa312=crypto[_0xc276('0x17')](_0x2ba16f['algorithm'],_0x45c4a4);_0x3ba3bc['on'](_0xc276('0x18'),function(_0x1f156e){var _0x106aef=new Buffer(_0x3aa312[_0xc276('0x19')](_0x1f156e),'binary');_0x547071[_0xc276('0x10')](_0x106aef);});_0x3ba3bc['on'](_0xc276('0x11'),function(){try{var _0x394dbc=new Buffer(_0x3aa312[_0xc276('0x12')](_0xc276('0xf')),_0xc276('0xf'));_0x547071[_0xc276('0x10')](_0x394dbc);_0x547071[_0xc276('0x11')]();_0x547071['on'](_0xc276('0x13'),function(){return _0xd8d4ad(_0x1bef59);});}catch(_0x5412c8){fs['unlink'](_0x1bef59);return _0x9e9afa(_0x5412c8);}});});};exports[_0xc276('0x1a')]=function(_0xccae4a,_0x59b144,_0x2329d5){var _0x4afa4e=_0x2329d5||stringOptions['algorithm'];var _0x2215d1=_0x59b144||stringOptions[_0xc276('0x1b')];var _0x57470e=crypto['createCipher'](_0x4afa4e,_0x2215d1);var _0x11d5d0=_0x57470e['update'](_0xccae4a,_0xc276('0x1c'),_0xc276('0x1d'));_0x11d5d0+=_0x57470e[_0xc276('0x12')]('base64');return _0x11d5d0;};exports[_0xc276('0x1e')]=function(_0x2aea44,_0x5e86b7,_0x516ade){var _0x38c915=_0x516ade||stringOptions[_0xc276('0x7')];var _0xff2235=_0x5e86b7||stringOptions['secret'];var _0x15d502=crypto[_0xc276('0x17')](_0x38c915,_0xff2235);var _0x10f8a7=_0x15d502[_0xc276('0x19')](_0x2aea44,_0xc276('0x1d'),_0xc276('0x1c'));_0x10f8a7+=_0x15d502[_0xc276('0x12')](_0xc276('0x1c'));return _0x10f8a7;};
\ No newline at end of file
+var _0x1b6d=['createDecipher','update','final','end','close','encryptString','utf8','base64','decryptString','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:','getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createCipher','data','binary','write','unlink','createWriteStream'];(function(_0x2da39b,_0x3faa2f){var _0x4d30dd=function(_0x1cebb8){while(--_0x1cebb8){_0x2da39b['push'](_0x2da39b['shift']());}};_0x4d30dd(++_0x3faa2f);}(_0x1b6d,0x1f3));var _0xd1b6=function(_0x4e676e,_0x2a7c6d){_0x4e676e=_0x4e676e-0x0;var _0x336a3c=_0x1b6d[_0x4e676e];return _0x336a3c;};'use strict';var crypto=require(_0xd1b6('0x0'));var fs=require('fs');var BPromise=require(_0xd1b6('0x1'));var _=require(_0xd1b6('0x2'));var config=require(_0xd1b6('0x3'));var logger=require('../../config/logger')(_0xd1b6('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config[_0xd1b6('0x5')][_0xd1b6('0x6')],'algorithm':_0xd1b6('0x7')};const fileOptions={'algorithm':_0xd1b6('0x8')};if(config[_0xd1b6('0x9')]&&config[_0xd1b6('0x9')][_0xd1b6('0xa')]){var isSupported=isAlgorithmSupported(config[_0xd1b6('0x9')][_0xd1b6('0xa')]);if(isSupported){fileOptions['algorithm']=config['encrypt'][_0xd1b6('0xa')];}else{var supportedAlgorithms=getSupportedCiphers()[_0xd1b6('0xb')](',\x20');logger[_0xd1b6('0xc')](config[_0xd1b6('0x9')][_0xd1b6('0xa')],_0xd1b6('0xd'),supportedAlgorithms);}}function isASupportedCipher(_0x545f51){return AES_SUPPORTED_RX['test'](_0x545f51);}function getSupportedCiphers(){return crypto[_0xd1b6('0xe')]()[_0xd1b6('0xf')](isASupportedCipher);}function isAlgorithmSupported(_0x529db8){return getSupportedCiphers()[_0xd1b6('0x10')](_0x529db8)>-0x1;}function combineOptions(_0x21ec3b){var _0x56f0ca={};for(var _0x3d8e53 in fileOptions){if(fileOptions[_0xd1b6('0x11')](_0x3d8e53)){_0x56f0ca[_0x3d8e53]=fileOptions[_0x3d8e53];}}if(_0x21ec3b){for(var _0x350d91 in _0x21ec3b){if(_0x21ec3b[_0xd1b6('0x11')](_0x350d91)){_0x56f0ca[_0x350d91]=_0x21ec3b[_0x350d91];}}}return _0x56f0ca;}exports[_0xd1b6('0x12')]=function(_0x392837,_0x483106,_0x4b8381,_0x12ebe0){return new BPromise(function(_0x417ad3,_0x360008){_0x12ebe0=combineOptions(_0x12ebe0);var _0x25eed1=new Buffer(_0x4b8381);var _0x424de9=fs[_0xd1b6('0x13')](_0x392837);var _0x348242=fs['createWriteStream'](_0x483106);var _0x1a5195=crypto[_0xd1b6('0x14')](_0x12ebe0[_0xd1b6('0xa')],_0x25eed1);_0x424de9['on'](_0xd1b6('0x15'),function(_0x2460cf){var _0x55bdc3=new Buffer(_0x1a5195['update'](_0x2460cf),_0xd1b6('0x16'));_0x348242[_0xd1b6('0x17')](_0x55bdc3);});_0x424de9['on']('end',function(){try{var _0x35b298=new Buffer(_0x1a5195['final'](_0xd1b6('0x16')),_0xd1b6('0x16'));_0x348242['write'](_0x35b298);_0x348242['end']();_0x348242['on']('close',function(){return _0x417ad3(_0x483106);});}catch(_0x436056){fs[_0xd1b6('0x18')](_0x483106);return _0x360008(_0x436056);}});});};exports['decryptFile']=function(_0x22c7df,_0x27d6ad,_0x43c3c4,_0x13552c){return new BPromise(function(_0x3b89a4,_0x1753a3){_0x13552c=combineOptions(_0x13552c);var _0x46a193=new Buffer(_0x43c3c4);var _0x4e1623=fs[_0xd1b6('0x13')](_0x22c7df);var _0x154cec=fs[_0xd1b6('0x19')](_0x27d6ad);var _0x1bfa67=crypto[_0xd1b6('0x1a')](_0x13552c[_0xd1b6('0xa')],_0x46a193);_0x4e1623['on'](_0xd1b6('0x15'),function(_0xe1735d){var _0x245067=new Buffer(_0x1bfa67[_0xd1b6('0x1b')](_0xe1735d),_0xd1b6('0x16'));_0x154cec[_0xd1b6('0x17')](_0x245067);});_0x4e1623['on']('end',function(){try{var _0x47a18f=new Buffer(_0x1bfa67[_0xd1b6('0x1c')](_0xd1b6('0x16')),_0xd1b6('0x16'));_0x154cec[_0xd1b6('0x17')](_0x47a18f);_0x154cec[_0xd1b6('0x1d')]();_0x154cec['on'](_0xd1b6('0x1e'),function(){return _0x3b89a4(_0x27d6ad);});}catch(_0x4ec1ca){fs[_0xd1b6('0x18')](_0x27d6ad);return _0x1753a3(_0x4ec1ca);}});});};exports[_0xd1b6('0x1f')]=function(_0x58b0f0,_0x504609,_0x24cf16){var _0x582311=_0x24cf16||stringOptions[_0xd1b6('0xa')];var _0x3dffdc=_0x504609||stringOptions['secret'];var _0x683740=crypto[_0xd1b6('0x14')](_0x582311,_0x3dffdc);var _0x30dcfc=_0x683740[_0xd1b6('0x1b')](_0x58b0f0,_0xd1b6('0x20'),_0xd1b6('0x21'));_0x30dcfc+=_0x683740[_0xd1b6('0x1c')](_0xd1b6('0x21'));return _0x30dcfc;};exports[_0xd1b6('0x22')]=function(_0x3a6293,_0x40592f,_0x3c20ba){var _0x3bec16=_0x3c20ba||stringOptions[_0xd1b6('0xa')];var _0xb1e094=_0x40592f||stringOptions['secret'];var _0x8d7525=crypto[_0xd1b6('0x1a')](_0x3bec16,_0xb1e094);var _0x4471f6=_0x8d7525['update'](_0x3a6293,_0xd1b6('0x21'),_0xd1b6('0x20'));_0x4471f6+=_0x8d7525[_0xd1b6('0x1c')](_0xd1b6('0x20'));return _0x4471f6;};
\ No newline at end of file