Built motion from commit f0a64034.|2.6.11
[motion2.git] / server / components / encryptor / index.js
index 5fa21dc..6c78941 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x55ec=['getCiphers','filter','hasOwnProperty','createReadStream','data','update','binary','end','final','write','close','decryptFile','createWriteStream','createDecipher','unlink','encryptString','secret','createCipher','utf8','base64','crypto','bluebird','lodash','../../config/environment','../../config/logger','app','aes192','encrypt','algorithm','join','error'];(function(_0x20845e,_0x211e78){var _0x28cf2b=function(_0x31d613){while(--_0x31d613){_0x20845e['push'](_0x20845e['shift']());}};_0x28cf2b(++_0x211e78);}(_0x55ec,0x188));var _0xc55e=function(_0x576e2b,_0x328953){_0x576e2b=_0x576e2b-0x0;var _0x46461a=_0x55ec[_0x576e2b];return _0x46461a;};'use strict';var crypto=require(_0xc55e('0x0'));var fs=require('fs');var BPromise=require(_0xc55e('0x1'));var _=require(_0xc55e('0x2'));var config=require(_0xc55e('0x3'));var logger=require(_0xc55e('0x4'))(_0xc55e('0x5'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets']['session'],'algorithm':'aes-256-ctr'};const fileOptions={'algorithm':_0xc55e('0x6')};if(config[_0xc55e('0x7')]&&config[_0xc55e('0x7')]['algorithm']){var isSupported=isAlgorithmSupported(config[_0xc55e('0x7')][_0xc55e('0x8')]);if(isSupported){fileOptions['algorithm']=config[_0xc55e('0x7')]['algorithm'];}else{var supportedAlgorithms=getSupportedCiphers()[_0xc55e('0x9')](',\x20');logger[_0xc55e('0xa')](config['encrypt'][_0xc55e('0x8')],'is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:',supportedAlgorithms);}}function isASupportedCipher(_0xcb05ff){return AES_SUPPORTED_RX['test'](_0xcb05ff);}function getSupportedCiphers(){return crypto[_0xc55e('0xb')]()[_0xc55e('0xc')](isASupportedCipher);}function isAlgorithmSupported(_0x52b134){return getSupportedCiphers()['indexOf'](_0x52b134)>-0x1;}function combineOptions(_0x5f3048){var _0x517f1a={};for(var _0x468778 in fileOptions){if(fileOptions[_0xc55e('0xd')](_0x468778)){_0x517f1a[_0x468778]=fileOptions[_0x468778];}}if(_0x5f3048){for(var _0x142071 in _0x5f3048){if(_0x5f3048[_0xc55e('0xd')](_0x142071)){_0x517f1a[_0x142071]=_0x5f3048[_0x142071];}}}return _0x517f1a;}exports['encryptFile']=function(_0x1bc6fa,_0x14b3f8,_0x3fb959,_0x50c399){return new BPromise(function(_0x1a62e8,_0x10df3c){_0x50c399=combineOptions(_0x50c399);var _0x48064f=new Buffer(_0x3fb959);var _0x24353b=fs[_0xc55e('0xe')](_0x1bc6fa);var _0x12e948=fs['createWriteStream'](_0x14b3f8);var _0xfc7d42=crypto['createCipher'](_0x50c399[_0xc55e('0x8')],_0x48064f);_0x24353b['on'](_0xc55e('0xf'),function(_0x3d44b4){var _0x9e11e5=new Buffer(_0xfc7d42[_0xc55e('0x10')](_0x3d44b4),_0xc55e('0x11'));_0x12e948['write'](_0x9e11e5);});_0x24353b['on'](_0xc55e('0x12'),function(){try{var _0x147c1d=new Buffer(_0xfc7d42[_0xc55e('0x13')](_0xc55e('0x11')),_0xc55e('0x11'));_0x12e948[_0xc55e('0x14')](_0x147c1d);_0x12e948[_0xc55e('0x12')]();_0x12e948['on'](_0xc55e('0x15'),function(){return _0x1a62e8(_0x14b3f8);});}catch(_0x4a3889){fs['unlink'](_0x14b3f8);return _0x10df3c(_0x4a3889);}});});};exports[_0xc55e('0x16')]=function(_0x218642,_0x1b1092,_0x472255,_0x5bf97f){return new BPromise(function(_0x3dd6ed,_0x3ba8a5){_0x5bf97f=combineOptions(_0x5bf97f);var _0x1def55=new Buffer(_0x472255);var _0x1c8f49=fs[_0xc55e('0xe')](_0x218642);var _0x251845=fs[_0xc55e('0x17')](_0x1b1092);var _0x5a5371=crypto[_0xc55e('0x18')](_0x5bf97f[_0xc55e('0x8')],_0x1def55);_0x1c8f49['on'](_0xc55e('0xf'),function(_0xaadaf0){var _0x366e40=new Buffer(_0x5a5371[_0xc55e('0x10')](_0xaadaf0),_0xc55e('0x11'));_0x251845[_0xc55e('0x14')](_0x366e40);});_0x1c8f49['on']('end',function(){try{var _0x5287ae=new Buffer(_0x5a5371[_0xc55e('0x13')]('binary'),_0xc55e('0x11'));_0x251845[_0xc55e('0x14')](_0x5287ae);_0x251845[_0xc55e('0x12')]();_0x251845['on'](_0xc55e('0x15'),function(){return _0x3dd6ed(_0x1b1092);});}catch(_0x1627c7){fs[_0xc55e('0x19')](_0x1b1092);return _0x3ba8a5(_0x1627c7);}});});};exports[_0xc55e('0x1a')]=function(_0x5533dd,_0x1c3b2d,_0x3ba04f){var _0x318707=_0x3ba04f||stringOptions['algorithm'];var _0x653a78=_0x1c3b2d||stringOptions[_0xc55e('0x1b')];var _0x2f15e0=crypto[_0xc55e('0x1c')](_0x318707,_0x653a78);var _0x10de00=_0x2f15e0[_0xc55e('0x10')](_0x5533dd,_0xc55e('0x1d'),_0xc55e('0x1e'));_0x10de00+=_0x2f15e0[_0xc55e('0x13')]('base64');return _0x10de00;};exports['decryptString']=function(_0x298f38,_0x147a29,_0xf227d9){var _0x21e6e1=_0xf227d9||stringOptions[_0xc55e('0x8')];var _0x182664=_0x147a29||stringOptions['secret'];var _0x2fed31=crypto[_0xc55e('0x18')](_0x21e6e1,_0x182664);var _0x51c283=_0x2fed31['update'](_0x298f38,_0xc55e('0x1e'),_0xc55e('0x1d'));_0x51c283+=_0x2fed31[_0xc55e('0x13')]('utf8');return _0x51c283;};
\ No newline at end of file
+var _0x5485=['test','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','data','update','binary','write','end','final','close','decryptFile','createDecipher','unlink','secret','utf8','decryptString','base64','crypto','../../config/environment','app','aes-256-ctr','encrypt','algorithm','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:'];(function(_0x461669,_0x24285c){var _0x576a71=function(_0xd97887){while(--_0xd97887){_0x461669['push'](_0x461669['shift']());}};_0x576a71(++_0x24285c);}(_0x5485,0x1d8));var _0x5548=function(_0x7ff50b,_0x399dc0){_0x7ff50b=_0x7ff50b-0x0;var _0x43e570=_0x5485[_0x7ff50b];return _0x43e570;};'use strict';var crypto=require(_0x5548('0x0'));var fs=require('fs');var BPromise=require('bluebird');var _=require('lodash');var config=require(_0x5548('0x1'));var logger=require('../../config/logger')(_0x5548('0x2'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets']['session'],'algorithm':_0x5548('0x3')};const fileOptions={'algorithm':'aes192'};if(config[_0x5548('0x4')]&&config['encrypt']['algorithm']){var isSupported=isAlgorithmSupported(config[_0x5548('0x4')]['algorithm']);if(isSupported){fileOptions[_0x5548('0x5')]=config['encrypt'][_0x5548('0x5')];}else{var supportedAlgorithms=getSupportedCiphers()['join'](',\x20');logger[_0x5548('0x6')](config['encrypt'][_0x5548('0x5')],_0x5548('0x7'),supportedAlgorithms);}}function isASupportedCipher(_0x20618f){return AES_SUPPORTED_RX[_0x5548('0x8')](_0x20618f);}function getSupportedCiphers(){return crypto['getCiphers']()[_0x5548('0x9')](isASupportedCipher);}function isAlgorithmSupported(_0x458540){return getSupportedCiphers()[_0x5548('0xa')](_0x458540)>-0x1;}function combineOptions(_0x12c3d9){var _0x4d6f2c={};for(var _0x1550a4 in fileOptions){if(fileOptions['hasOwnProperty'](_0x1550a4)){_0x4d6f2c[_0x1550a4]=fileOptions[_0x1550a4];}}if(_0x12c3d9){for(var _0x203d23 in _0x12c3d9){if(_0x12c3d9[_0x5548('0xb')](_0x203d23)){_0x4d6f2c[_0x203d23]=_0x12c3d9[_0x203d23];}}}return _0x4d6f2c;}exports[_0x5548('0xc')]=function(_0x5e348d,_0x322b27,_0x12c843,_0x324988){return new BPromise(function(_0x284345,_0x2ae304){_0x324988=combineOptions(_0x324988);var _0x1cf10c=new Buffer(_0x12c843);var _0xb3e828=fs[_0x5548('0xd')](_0x5e348d);var _0x3caef6=fs[_0x5548('0xe')](_0x322b27);var _0xe3a57e=crypto[_0x5548('0xf')](_0x324988[_0x5548('0x5')],_0x1cf10c);_0xb3e828['on'](_0x5548('0x10'),function(_0x1f8f17){var _0x5fffdc=new Buffer(_0xe3a57e[_0x5548('0x11')](_0x1f8f17),_0x5548('0x12'));_0x3caef6[_0x5548('0x13')](_0x5fffdc);});_0xb3e828['on'](_0x5548('0x14'),function(){try{var _0x1f1e07=new Buffer(_0xe3a57e[_0x5548('0x15')](_0x5548('0x12')),'binary');_0x3caef6['write'](_0x1f1e07);_0x3caef6[_0x5548('0x14')]();_0x3caef6['on'](_0x5548('0x16'),function(){return _0x284345(_0x322b27);});}catch(_0x34225a){fs['unlink'](_0x322b27);return _0x2ae304(_0x34225a);}});});};exports[_0x5548('0x17')]=function(_0x2b465a,_0x14db45,_0x3616f1,_0x37955f){return new BPromise(function(_0xdebe31,_0x289869){_0x37955f=combineOptions(_0x37955f);var _0x4cbbb6=new Buffer(_0x3616f1);var _0x5f5964=fs['createReadStream'](_0x2b465a);var _0x4b48c3=fs['createWriteStream'](_0x14db45);var _0x3a8960=crypto[_0x5548('0x18')](_0x37955f['algorithm'],_0x4cbbb6);_0x5f5964['on'](_0x5548('0x10'),function(_0x5f7cbf){var _0x267a03=new Buffer(_0x3a8960['update'](_0x5f7cbf),_0x5548('0x12'));_0x4b48c3[_0x5548('0x13')](_0x267a03);});_0x5f5964['on'](_0x5548('0x14'),function(){try{var _0x1149ed=new Buffer(_0x3a8960[_0x5548('0x15')](_0x5548('0x12')),_0x5548('0x12'));_0x4b48c3[_0x5548('0x13')](_0x1149ed);_0x4b48c3['end']();_0x4b48c3['on'](_0x5548('0x16'),function(){return _0xdebe31(_0x14db45);});}catch(_0x36b07b){fs[_0x5548('0x19')](_0x14db45);return _0x289869(_0x36b07b);}});});};exports['encryptString']=function(_0x231c75,_0xee742e,_0x12022c){var _0xd014b9=_0x12022c||stringOptions[_0x5548('0x5')];var _0x5c6901=_0xee742e||stringOptions[_0x5548('0x1a')];var _0x5c1d49=crypto[_0x5548('0xf')](_0xd014b9,_0x5c6901);var _0x574056=_0x5c1d49[_0x5548('0x11')](_0x231c75,_0x5548('0x1b'),'base64');_0x574056+=_0x5c1d49[_0x5548('0x15')]('base64');return _0x574056;};exports[_0x5548('0x1c')]=function(_0x29d6b9,_0x17f982,_0x2e617b){var _0x5a152e=_0x2e617b||stringOptions[_0x5548('0x5')];var _0x512bce=_0x17f982||stringOptions['secret'];var _0x1f80b9=crypto['createDecipher'](_0x5a152e,_0x512bce);var _0x42e8be=_0x1f80b9['update'](_0x29d6b9,_0x5548('0x1d'),'utf8');_0x42e8be+=_0x1f80b9[_0x5548('0x15')]('utf8');return _0x42e8be;};
\ No newline at end of file