File "class-udrpc.min.js"
Full Path: /home/rfaztorb/public_html/wordpress/search/file/pomo/updraft/plugins-old/updraftcentral/js/class-udrpc.min.js
File size: 11.82 KB
MIME-type: text/plain
Charset: utf-8
var UpdraftPlus_Remote_Communications=function(e,t){return this.version="0.3.3 (27/July/2016)",this.key_name_indicator="",this.key_remote=!1,this.key_local=!1,this.can_generate=!1,this.destination_url=!1,this.maximum_replay_time_difference=300,this.extra_replay_protection=!1,this.debug_level=0,this.seen_hashes={},this.cors_headers_wanted=1,this.format=2,this.time_correction_sec=0,this.http_credentials={},this.auth_method="jquery",this.message_wrapper=!1,this.message_unwrapper=!1,this.message_random_number=!1,e=void 0!==e?e:"default",this.time_now=function(){return Math.floor(Date.now()/1e3)+this.time_correction_sec},this.register_time=function(e){var t,s;void 0!==e&&(s=e-(t=Math.floor(Date.now()/1e3)),120<Math.abs(s))&&(console.log("UDRPC: Time difference detected; time_now="+t+", server_time="+e+", store_diff="+s),this.time_correction_sec=s)},this.paddingleft=function(e,t){return String(e+t).slice(-e.length)},this.set_key_name_indicator=function(e){this.key_name_indicator=e},this.set_cors_headers_wanted=function(e){this.cors_headers_wanted=e=void 0===e||e},this.set_can_generate=function(e){this.can_generate=void 0===e||e},this.set_maximum_replay_time_difference=function(e){this.maximum_replay_time_difference=parseInt(e)},this.set_debug_level=function(e){this.debug_level=void 0!==e?e:1,this.debug_level&&console.log("UDRPC: Debug mode activated (level: "+e+")")},this.ensure_crypto_loaded=function(){if("undefined"==typeof forge)throw console.log("UDRPC JS: No loaded forge library found (you should make sure it has loaded before calling UDRPC functions)"),"No loaded forge library found (you should make sure it has loaded before calling UDRPC functions)"},this.set_destination_url=function(e){this.destination_url=e},this.set_message_wrapper=function(e){this.message_wrapper=e},this.set_message_unwrapper=function(e){this.message_unwrapper=e},this.set_option_name=function(e){console.log("UDRPC: set_option_name() called - which is wrong/unnecessary in the JavaScript port")},this.get_key_remote=function(){return!this.key_remote&&this.can_generate&&this.generate_new_keypair(),this.key_remote||!1},this.set_key_remote=function(e){this.key_remote=e},this.get_key_local=function(){return!this.key_local&&this.can_generate&&this.generate_new_keypair(),this.key_local||!1},this.decode_portable_bundle=function(e,t){return this.unimplemented_function("decode_portable_bundle"),!1},this.get_portable_bundle=function(e){return this.unimplemented_function("get_portable_bundle"),!1},this.set_key_local=function(e){this.key_local=e},this.unimplemented_function=function(e){console.log("UDRPC: Unimplemented function in JavaScript port called: "+e)},this.generate_new_keypair=function(){return this.unimplemented_function("generate_new_keypair"),!1},this.encrypt_message=function(e,t,s){if(!(t=void 0!==t&&t)&&!this.key_remote)throw"No encryption key has been set";t=t||this.key_remote,this.ensure_crypto_loaded();var t=forge.pki.publicKeyFromPem(t),s=(void 0===s&&(s=Math.ceil(t.n.bitLength()/8)<65?16:32),forge.random.getBytesSync(s)),o=(1<this.debug_level&&console.log("Generated symmetric key, in hex: "+forge.util.bytesToHex(s)),forge.cipher.createCipher("AES-CBC",s)),e=(o.start({iv:""}),o.update(forge.util.createBuffer(forge.util.encodeUtf8(e))),o.finish(),o.output),o=(1<this.debug_level&&console.log("Ciphertext, in hex (PHP equiv: bin2hex): "+forge.util.bytesToHex(e)),e=forge.util.encode64(e.bytes()),1<this.debug_level&&console.log("Ciphertext, in base64: "+e),s=t.encrypt(s,"RSA-OAEP"),1<this.debug_level&&console.log("Symmetric key, after being encrypted with the assymetric key, in hex: "+forge.util.bytesToHex(s)),s=forge.util.encode64(s),1<this.debug_level&&console.log("Encrypted symmetric key, in base 64: "+s),s.length),t=(1<this.debug_level&&console.log("Key length (decimal): "+o),o=o.toString(16),o=this.paddingleft("000",o),e.length);return 1<this.debug_level&&console.log("Cipher length (decimal): "+t),t=t.toString(16),t=this.paddingleft("0000000000000000",t),1<this.debug_level&&(console.log("Length, hexed + padded (3): "+o),console.log("Cipherlength, hexed + padded (16): "+t)),o+s+t+e},this.decrypt_message=function(e){if(!this.key_local)throw new Exception("No decryption key has been set");this.ensure_crypto_loaded();var t=e.substr(0,3),s=(1<this.debug_level&&console.log("Key length (hex + passed): "+t),t=parseInt(t,16),1<this.debug_level&&console.log("Key length (decimal): "+t),e.substr(3,t)),o=(1<this.debug_level&&console.log("Encrypted symmetric key, base64-encoded: "+s),s=forge.util.decode64(s),1<this.debug_level&&console.log("Encrypted symmetric key, in hex: "+forge.util.bytesToHex(s)),e.substr(t+3,16)),e=(1<this.debug_level&&console.log("Ciphertext length (hex + passed): "+o),o=parseInt(o,16),1<this.debug_level&&console.log("Ciphertext length (decimal): "+o),e.substr(t+19,o)),t=(1<this.debug_level&&console.log("Ciphertext (base64): "+e),e=forge.util.decode64(e),1<this.debug_level&&console.log("Ciphertext, in hex (PHP equiv: bin2hex): "+forge.util.bytesToHex(e)),forge.pki.privateKeyFromPem(this.key_local)),s=(1<this.debug_level&&console.log("Attempting to decrypt symmetric key"),t.decrypt(s,"RSA-OAEP")),o=(1<this.debug_level&&console.log("Generated symmetric key, after being decrypted, in hex: "+forge.util.bytesToHex(s)),forge.cipher.createDecipher("AES-CBC",s));return o.start({iv:""}),o.update(forge.util.createBuffer(e)),o.finish(),forge.util.decodeUtf8(o.output)},this.create_message=function(e,t,s,o,r){o=void 0!==o&&o,r=void 0!==r&&r,t=void 0!==t?t:null;var i={},s=((s=void 0!==s&&s)?i.response=e:i.command=e,this.cors_headers_wanted&&(i.cors_headers_wanted=1),i.time=this.time_now(),i.key_name=this.key_name_indicator,this.message_random_number=Math.round(2147483647*Math.random()),i.rand=this.message_random_number,null!==t&&(i.data=t),this.encrypt_message(JSON.stringify(i),o)),e={format:this.format,key_name:this.key_name_indicator,udrpc_message:s,signature:this.signature_for_message(s,r)},t=e;return!1!==this.message_wrapper&&((t=this.message_wrapper).wrapped_message=e),t},this.signature_for_message=function(e,t){if(!(t=void 0!==t&&t)&&!this.key_local)throw"No encryption key (local) has been set";t=t||this.key_local,this.ensure_crypto_loaded();var s=forge.md.sha256.create();s.update(e,"utf8");e=forge.pki.privateKeyFromPem(t).sign(s,"RSASSA-PKCS1-V1_5"),t=forge.util.encode64(e);return 0<this.debug_level&&(console.log("Hash (sha256) (follows)"),console.log(s),1<this.debug_level)&&(console.log("Signature (raw): "+e),console.log("Signature (base64-ed): "+t)),t},this.verify_signature=function(e,t,s,o){this.ensure_crypto_loaded();var r=forge.md.sha256.create(),e=(r.update(e,"utf8"),r.digest().bytes()),r=forge.pki.publicKeyFromPem(s),s=(1<this.debug_level&&(console.log("UDRPC: verify_signature: message hash (hex): "+forge.util.bytesToHex(e)),console.log("UDRPC: verify_signature: signature (len="+t.length+") (existing base64): "+t)),r.verify(e,forge.util.decode64(t)));return 0<this.debug_level&&console.log("UDRPC: verify signature: result: "+s),s},this.activate_replay_protection=function(e){this.extra_replay_protection=void 0===e||e},this.set_http_credentials=function(e){this.http_credentials=e},this.set_auth_method=function(e){this.auth_method=e},this.send_post=function(r,i,e,n,t){t=void 0!==t?t:30,i&&jQuery(i).addClass("updraftcentral_spinner");try{0<this.debug_level&&console.log("send_post: "+r);var s,o={type:"POST",url:r,data:e,dataType:"text",headers:{"X-Secondary-User-Agent":"class-udrpc.js/"+this.version},timeout:1e3*t,success:function(e){i&&jQuery(i).removeClass("updraftcentral_spinner"),n.call(this,e)},error:function(e,t,s){if(UpdraftCentral.reloaded||(console.log("UDRPC: Error in send_post (url="+r+")"),console.log(e),console.log(t),console.log(s)),i&&jQuery(i).removeClass("updraftcentral_spinner"),"function"==typeof(s=(s=""==s?"http_post_fail":s).hasOwnProperty("statusText")?s.statusText.toString():s).toLowerCase)s=s.toLowerCase();else try{var o=s.toString().toLowerCase();o&&(s=o)}catch(e){}n.call(this,e,"error",s)}};this.http_credentials.hasOwnProperty("username")&&(s=this.http_credentials.hasOwnProperty("password")?this.http_credentials.password:"","manual"==this.auth_method?o.headers.Authorization="Basic "+forge.util.encode64(this.http_credentials.username+":"+s):(o.xhrFields={withCredentials:!0},o.username=this.http_credentials.username,this.http_credentials.hasOwnProperty("password")&&(o.password=this.http_credentials.password))),1<this.debug_level&&(console.log("UDPRC: jQuery POST: options follow:"),console.log(o)),jQuery.ajax(o)}catch(e){throw console.log("UDRPC: Exception in send_post (url="+r+")"),console.log(e),e}},this.send_message=function(e,t,s,l){if(t=void 0!==t?t:null,s=void 0!==s?s:30,!this.destination_url)throw console.log("UDRPC: send_message: no destination URL has been initialised"),"RPC error: destination URL not initialised";message=this.create_message(e,t,!1);var h=this.message_random_number,c=this;this.send_post(this.destination_url,!1,message,function(t,e,s){if("error"==e)l.call(this,t,"error",s);else if(""===t)console.log("UDRPC: the response from the remote site was empty"),l.call(this,t,"error","response_empty");else{try{var o=JSON.parse(t)}catch(e){return console.log(e),void l.call(this,t,"error","json_parse_fail")}try{if(!o)return console.log("UDRPC: the response from the remote site was empty"),console.log(t),void l.call(this,t,"error","parsed_response_not_understood");if(!1!==c.message_unwrapper){var r=c.message_unwrapper.call(this,o);if(!1===r)return void l.call(this,o,"error","unwrapper_failure");o=r}if(!o.hasOwnProperty("udrpc_message"))return console.log("UDRPC: the response from the remote site could not be understood (follows)"),console.log(t),void l.call(this,t,"error","parsed_response_not_understood");if(!o.hasOwnProperty("signature")||!o.signature)return console.log("UDRPC: No signature found on response from remote site - message dropped"),void l.call(this,o,"error","response_no_signature");try{if(!c.verify_signature(o.udrpc_message,o.signature,c.key_remote))return console.log("UDRPC: Verify signature on response: failed - message dropped"),void l.call(this,o,"error","response_signature_invalid");c.debug&&console.log("UDRPC: Verify signature on response: OK")}catch(e){return console.log(e),void l.call(this,o,"error","signature_verify_exception")}try{var i=c.decrypt_message(o.udrpc_message)}catch(e){return console.log(e),void l.call(this,e,"error","decryption_error")}var n=JSON.parse(i);if(!n.hasOwnProperty("response")||!n.hasOwnProperty("time"))return console.log("response_corrupt: Response from remote site was not in the expected format (follows)"),console.log(o),console.log(n),void l.call(this,i,"error","parsed_response_bad_format");if(c.extra_replay_protection&&(message_hash=c.calculate_message_hash(t),c.message_hash_seen(message_hash)))return console.log("Message refused: replay detected"),console.log(message_hash),void l.call(this,n.response,"error","response_replay_detected");var a=c.time_now();if((time_difference=a-n.time)>c.maximum_replay_time_difference)return console.log("UDRPC: Message refused: too late - diff="+time_difference+", maximum_difference="+c.maximum_replay_time_difference),void l.call(this,n.response,"error","response_refused_too_late");if(n.hasOwnProperty("incoming_rand")&&h&&n.incoming_rand!=h)return console.log("UDRPC: Message mismatch (possibly MITM) (sent_rand="+h+", returned_rand="+n.incoming_rand+"): dropping"),void l.call(this,n.response,"error","response_mismatch")}catch(e){return console.log(e),void l.call(this,o,"error","js_exception")}l.call(this,n,"ok")}},s)},this.create_listener=function(){return this.unimplemented_function("create_listener"),!1},this.calculate_message_hash=function(e){this.ensure_crypto_loaded();var t=forge.md.sha256.create();return t.update(e),t.digest().toHex()},this.message_hash_seen=function(s){var o=this.seen_hashes,r=this.time_now(),i=!1;return jQuery.each(o,function(e,t){o.hash<r-this.maximum_replay_time_difference?delete o.hash:t==s&&(i=!0,o.hash=r)}),i},this.set_key_name_indicator(e),this};