Built motion from commit a8c4dd89.|2.6.33
[motion2.git] / server / components / encryptor / index.js
index a117afe..ad39971 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7a2b=['unlink','secret','utf8','base64','final','createDecipher','crypto','bluebird','lodash','../../config/logger','app','session','aes-256-ctr','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','indexOf','encryptFile','createReadStream','createWriteStream','createCipher','data','update','binary','write','end','close'];(function(_0x356184,_0x42ee78){var _0x36d3b6=function(_0x1b4004){while(--_0x1b4004){_0x356184['push'](_0x356184['shift']());}};_0x36d3b6(++_0x42ee78);}(_0x7a2b,0x1c8));var _0xb7a2=function(_0x618414,_0x1a7a60){_0x618414=_0x618414-0x0;var _0x21c19a=_0x7a2b[_0x618414];return _0x21c19a;};'use strict';var crypto=require(_0xb7a2('0x0'));var fs=require('fs');var BPromise=require(_0xb7a2('0x1'));var _=require(_0xb7a2('0x2'));var config=require('../../config/environment');var logger=require(_0xb7a2('0x3'))(_0xb7a2('0x4'));const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0xb7a2('0x5')],'algorithm':_0xb7a2('0x6')};const fileOptions={'algorithm':'aes192'};if(config[_0xb7a2('0x7')]&&config[_0xb7a2('0x7')][_0xb7a2('0x8')]){var isSupported=isAlgorithmSupported(config[_0xb7a2('0x7')][_0xb7a2('0x8')]);if(isSupported){fileOptions[_0xb7a2('0x8')]=config[_0xb7a2('0x7')]['algorithm'];}else{var supportedAlgorithms=getSupportedCiphers()[_0xb7a2('0x9')](',\x20');logger[_0xb7a2('0xa')](config[_0xb7a2('0x7')]['algorithm'],_0xb7a2('0xb'),supportedAlgorithms);}}function isASupportedCipher(_0x2c79eb){return AES_SUPPORTED_RX[_0xb7a2('0xc')](_0x2c79eb);}function getSupportedCiphers(){return crypto['getCiphers']()['filter'](isASupportedCipher);}function isAlgorithmSupported(_0x4f11c9){return getSupportedCiphers()[_0xb7a2('0xd')](_0x4f11c9)>-0x1;}function combineOptions(_0x4f0ec4){var _0x250349={};for(var _0x39ac1f in fileOptions){if(fileOptions['hasOwnProperty'](_0x39ac1f)){_0x250349[_0x39ac1f]=fileOptions[_0x39ac1f];}}if(_0x4f0ec4){for(var _0x59a299 in _0x4f0ec4){if(_0x4f0ec4['hasOwnProperty'](_0x59a299)){_0x250349[_0x59a299]=_0x4f0ec4[_0x59a299];}}}return _0x250349;}exports[_0xb7a2('0xe')]=function(_0x21eb67,_0x6f8de0,_0x2c5e2a,_0x5c2618){return new BPromise(function(_0x3942ea,_0x1ccf44){_0x5c2618=combineOptions(_0x5c2618);var _0xf848a7=new Buffer(_0x2c5e2a);var _0x543467=fs[_0xb7a2('0xf')](_0x21eb67);var _0x335dfc=fs[_0xb7a2('0x10')](_0x6f8de0);var _0x333120=crypto[_0xb7a2('0x11')](_0x5c2618[_0xb7a2('0x8')],_0xf848a7);_0x543467['on'](_0xb7a2('0x12'),function(_0x42872c){var _0x37d8a6=new Buffer(_0x333120[_0xb7a2('0x13')](_0x42872c),_0xb7a2('0x14'));_0x335dfc[_0xb7a2('0x15')](_0x37d8a6);});_0x543467['on'](_0xb7a2('0x16'),function(){try{var _0x447781=new Buffer(_0x333120['final'](_0xb7a2('0x14')),'binary');_0x335dfc['write'](_0x447781);_0x335dfc[_0xb7a2('0x16')]();_0x335dfc['on'](_0xb7a2('0x17'),function(){return _0x3942ea(_0x6f8de0);});}catch(_0x508c2e){fs[_0xb7a2('0x18')](_0x6f8de0);return _0x1ccf44(_0x508c2e);}});});};exports['decryptFile']=function(_0x49eaa7,_0x4cbe3c,_0x5d8dac,_0x3f3c10){return new BPromise(function(_0x1906d7,_0x18673e){_0x3f3c10=combineOptions(_0x3f3c10);var _0x1047e7=new Buffer(_0x5d8dac);var _0x5bc6df=fs['createReadStream'](_0x49eaa7);var _0x1577a7=fs['createWriteStream'](_0x4cbe3c);var _0x1c9859=crypto['createDecipher'](_0x3f3c10[_0xb7a2('0x8')],_0x1047e7);_0x5bc6df['on'](_0xb7a2('0x12'),function(_0x4f1701){var _0x34f212=new Buffer(_0x1c9859[_0xb7a2('0x13')](_0x4f1701),'binary');_0x1577a7[_0xb7a2('0x15')](_0x34f212);});_0x5bc6df['on']('end',function(){try{var _0x87bdc=new Buffer(_0x1c9859['final'](_0xb7a2('0x14')),'binary');_0x1577a7[_0xb7a2('0x15')](_0x87bdc);_0x1577a7[_0xb7a2('0x16')]();_0x1577a7['on'](_0xb7a2('0x17'),function(){return _0x1906d7(_0x4cbe3c);});}catch(_0x542012){fs[_0xb7a2('0x18')](_0x4cbe3c);return _0x18673e(_0x542012);}});});};exports['encryptString']=function(_0x360010,_0x180f2d,_0x54ec29){var _0x259141=_0x54ec29||stringOptions[_0xb7a2('0x8')];var _0x27ffef=_0x180f2d||stringOptions[_0xb7a2('0x19')];var _0x434e3b=crypto[_0xb7a2('0x11')](_0x259141,_0x27ffef);var _0x50ccf6=_0x434e3b[_0xb7a2('0x13')](_0x360010,_0xb7a2('0x1a'),_0xb7a2('0x1b'));_0x50ccf6+=_0x434e3b[_0xb7a2('0x1c')](_0xb7a2('0x1b'));return _0x50ccf6;};exports['decryptString']=function(_0x43aecb,_0x8cc3fa,_0x32c78c){var _0x3164ce=_0x32c78c||stringOptions[_0xb7a2('0x8')];var _0x2e364f=_0x8cc3fa||stringOptions[_0xb7a2('0x19')];var _0x208f3b=crypto[_0xb7a2('0x1d')](_0x3164ce,_0x2e364f);var _0x4d34df=_0x208f3b[_0xb7a2('0x13')](_0x43aecb,_0xb7a2('0x1b'),_0xb7a2('0x1a'));_0x4d34df+=_0x208f3b[_0xb7a2('0x1c')]('utf8');return _0x4d34df;};
\ No newline at end of file
+var _0x4886=['final','encryptString','secret','update','utf8','base64','decryptString','createDecipher','crypto','../../config/environment','session','aes-256-ctr','aes192','encrypt','algorithm','join','error','is\x20not\x20a\x20supported\x20algorithm.\x20Your\x20system\x20supports\x20the\x20following\x20algorithms:','test','getCiphers','filter','indexOf','hasOwnProperty','encryptFile','createReadStream','createWriteStream','createCipher','data','binary','write','end','close','unlink','decryptFile'];(function(_0x4877bc,_0x24b542){var _0x296c34=function(_0x45e2b0){while(--_0x45e2b0){_0x4877bc['push'](_0x4877bc['shift']());}};_0x296c34(++_0x24b542);}(_0x4886,0x1e4));var _0x6488=function(_0xeef6af,_0x3ce84c){_0xeef6af=_0xeef6af-0x0;var _0x3061d7=_0x4886[_0xeef6af];return _0x3061d7;};'use strict';var crypto=require(_0x6488('0x0'));var fs=require('fs');var BPromise=require('bluebird');var _=require('lodash');var config=require(_0x6488('0x1'));var logger=require('../../config/logger')('app');const AES_SUPPORTED_RX=/^aes(-)?\d{3}(-(cbc|cfb|ctr)(1|8)?){0,1}$/;const stringOptions={'secret':config['secrets'][_0x6488('0x2')],'algorithm':_0x6488('0x3')};const fileOptions={'algorithm':_0x6488('0x4')};if(config['encrypt']&&config[_0x6488('0x5')][_0x6488('0x6')]){var isSupported=isAlgorithmSupported(config['encrypt'][_0x6488('0x6')]);if(isSupported){fileOptions[_0x6488('0x6')]=config[_0x6488('0x5')][_0x6488('0x6')];}else{var supportedAlgorithms=getSupportedCiphers()[_0x6488('0x7')](',\x20');logger[_0x6488('0x8')](config[_0x6488('0x5')][_0x6488('0x6')],_0x6488('0x9'),supportedAlgorithms);}}function isASupportedCipher(_0xaea69f){return AES_SUPPORTED_RX[_0x6488('0xa')](_0xaea69f);}function getSupportedCiphers(){return crypto[_0x6488('0xb')]()[_0x6488('0xc')](isASupportedCipher);}function isAlgorithmSupported(_0x469c47){return getSupportedCiphers()[_0x6488('0xd')](_0x469c47)>-0x1;}function combineOptions(_0x2ca5c7){var _0x2934f0={};for(var _0x215a4a in fileOptions){if(fileOptions[_0x6488('0xe')](_0x215a4a)){_0x2934f0[_0x215a4a]=fileOptions[_0x215a4a];}}if(_0x2ca5c7){for(var _0x36c39 in _0x2ca5c7){if(_0x2ca5c7[_0x6488('0xe')](_0x36c39)){_0x2934f0[_0x36c39]=_0x2ca5c7[_0x36c39];}}}return _0x2934f0;}exports[_0x6488('0xf')]=function(_0x4cdf08,_0x3ae701,_0x167083,_0x45a16e){return new BPromise(function(_0x6b74b7,_0xae8859){_0x45a16e=combineOptions(_0x45a16e);var _0xaa0faf=new Buffer(_0x167083);var _0x597b48=fs[_0x6488('0x10')](_0x4cdf08);var _0x22d1e0=fs[_0x6488('0x11')](_0x3ae701);var _0x1fcaea=crypto[_0x6488('0x12')](_0x45a16e[_0x6488('0x6')],_0xaa0faf);_0x597b48['on'](_0x6488('0x13'),function(_0x4aa306){var _0x42575a=new Buffer(_0x1fcaea['update'](_0x4aa306),_0x6488('0x14'));_0x22d1e0[_0x6488('0x15')](_0x42575a);});_0x597b48['on'](_0x6488('0x16'),function(){try{var _0x1cede5=new Buffer(_0x1fcaea['final'](_0x6488('0x14')),'binary');_0x22d1e0[_0x6488('0x15')](_0x1cede5);_0x22d1e0[_0x6488('0x16')]();_0x22d1e0['on'](_0x6488('0x17'),function(){return _0x6b74b7(_0x3ae701);});}catch(_0x3e2d00){fs[_0x6488('0x18')](_0x3ae701);return _0xae8859(_0x3e2d00);}});});};exports[_0x6488('0x19')]=function(_0x1f58ad,_0x5d018c,_0x1f1b48,_0xa0223e){return new BPromise(function(_0x165b75,_0xf2bd43){_0xa0223e=combineOptions(_0xa0223e);var _0x400202=new Buffer(_0x1f1b48);var _0x5cf781=fs[_0x6488('0x10')](_0x1f58ad);var _0x3ac869=fs['createWriteStream'](_0x5d018c);var _0x37df9f=crypto['createDecipher'](_0xa0223e[_0x6488('0x6')],_0x400202);_0x5cf781['on']('data',function(_0x1cf74f){var _0x546d3c=new Buffer(_0x37df9f['update'](_0x1cf74f),_0x6488('0x14'));_0x3ac869[_0x6488('0x15')](_0x546d3c);});_0x5cf781['on'](_0x6488('0x16'),function(){try{var _0x1df87b=new Buffer(_0x37df9f[_0x6488('0x1a')](_0x6488('0x14')),_0x6488('0x14'));_0x3ac869['write'](_0x1df87b);_0x3ac869['end']();_0x3ac869['on'](_0x6488('0x17'),function(){return _0x165b75(_0x5d018c);});}catch(_0x3cf2f8){fs[_0x6488('0x18')](_0x5d018c);return _0xf2bd43(_0x3cf2f8);}});});};exports[_0x6488('0x1b')]=function(_0x5027c7,_0x119543,_0xe4c30){var _0x53eeb=_0xe4c30||stringOptions[_0x6488('0x6')];var _0x58eea5=_0x119543||stringOptions[_0x6488('0x1c')];var _0x36900b=crypto[_0x6488('0x12')](_0x53eeb,_0x58eea5);var _0x4a7d2e=_0x36900b[_0x6488('0x1d')](_0x5027c7,_0x6488('0x1e'),_0x6488('0x1f'));_0x4a7d2e+=_0x36900b[_0x6488('0x1a')](_0x6488('0x1f'));return _0x4a7d2e;};exports[_0x6488('0x20')]=function(_0x197220,_0x30fa71,_0x38e2a4){var _0x1148c3=_0x38e2a4||stringOptions[_0x6488('0x6')];var _0x446243=_0x30fa71||stringOptions[_0x6488('0x1c')];var _0x29af61=crypto[_0x6488('0x21')](_0x1148c3,_0x446243);var _0x26800f=_0x29af61[_0x6488('0x1d')](_0x197220,_0x6488('0x1f'),'utf8');_0x26800f+=_0x29af61['final']('utf8');return _0x26800f;};
\ No newline at end of file