diff --git a/resources/openpgp.js b/resources/openpgp.js index a01e0103..f7f44d0c 100644 --- a/resources/openpgp.js +++ b/resources/openpgp.js @@ -1026,12 +1026,12 @@ function openpgp_packet_encryptedintegrityprotecteddata() { var tohash = data; tohash += String.fromCharCode(0xD3); tohash += String.fromCharCode(0x14); - util.print_debug("data to be hashed:" - + util.hexstrdump(prefix + tohash)); + util.print_debug_hexstr_dump("data to be hashed:" + , prefix + tohash); tohash += str_sha1(prefix + tohash); - util.print_debug("hash:" - + util.hexstrdump(tohash.substring(tohash.length - 20, - tohash.length))); + util.print_debug_hexstr_dump("hash:" + , tohash.substring(tohash.length - 20, + tohash.length)); var result = openpgp_crypto_symmetricEncrypt(prefixrandom, symmetric_algorithm, key, tohash, false).substring(0, prefix.length + tohash.length); @@ -1061,7 +1061,7 @@ function openpgp_packet_encryptedintegrityprotecteddata() { symmetric_algorithm_type, key, this.encryptedData) + this.decryptedData.substring(0, this.decryptedData.length - 20)); - util.print_debug("calc hash = " + util.hexstrdump(this.hash)); + util.print_debug_hexstr_dump("calc hash = ", this.hash); if (this.hash == this.decryptedData.substring( this.decryptedData.length - 20, this.decryptedData.length)) return this.decryptedData; @@ -1087,7 +1087,8 @@ function openpgp_packet_encryptedintegrityprotecteddata() { this.read_packet = read_packet; this.toString = toString; this.decrypt = decrypt; -};// GPG4Browsers - An OpenPGP implementation in javascript +}; +// GPG4Browsers - An OpenPGP implementation in javascript // Copyright (C) 2011 Recurity Labs GmbH // // This library is free software; you can redistribute it and/or @@ -8958,7 +8959,6 @@ function openpgp_cfb_encrypt(prefixrandom, blockcipherencryptfn, plaintext, bloc // This produces C11-C18, the next 8 octets of ciphertext. for (var i = 2; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i)); var tempCiphertext = ciphertext.substring(0,2*block_size).split(''); - //var tempCiphertextHeader = ciphertext.substring(0,block_size); var tempCiphertextString = ciphertext.substring(block_size); for(n=block_size; n' + * Different than print_debug because will call hexstrdump iff necessary. + * @param str [String] string of the debug message + * @return [String] an HTML tt entity containing a paragraph with a style attribute where the debug message is HTMLencoded in. + */ + this.print_debug_hexstr_dump = function(str,strToHex) { + if (openpgp.config.debug) { + str = str + this.hexstrdump(strToHex); + str = openpgp_encoding_html_encode(str); + showMessages("

"+str.replace(/\n/g,"
")+"

"); + } + }; + /** * Helper function to print an error message. * The calling Javascript context MUST define diff --git a/resources/openpgp.min.js b/resources/openpgp.min.js index d1e1d341..f38a510b 100644 --- a/resources/openpgp.min.js +++ b/resources/openpgp.min.js @@ -30,10 +30,10 @@ this.toString=function(){for(var a=3==this.version?"5.2. Signature Packet (Tag 2 " "+this.keyNeverExpires+"\nPreferred Symmetric Algorithms :"+this.preferredSymmetricAlgorithms+"\nRevocation Key\n ( 1 octet of class, :"+this.revocationKeyClass+"\n 1 octet of public-key ID, :"+this.revocationKeyAlgorithm+"\n 20 octets of fingerprint) :"+this.revocationKeyFingerprint+"\nIssuer :"+util.hexstrdump(this.issuerKeyId)+"\nPreferred Hash Algorithms :"+this.preferredHashAlgorithms+"\nPreferred Compression Alg. :"+ this.preferredCompressionAlgorithms+"\nKey Server Preferences :"+this.keyServerPreferences+"\nPreferred Key Server :"+this.preferredKeyServer+"\nPrimary User ID :"+this.isPrimaryUserID+"\nPolicy URI :"+this.policyURI+"\nKey Flags :"+this.keyFlags+"\nSigner's User ID :"+this.signersUserId+"\nNotation :"+this.notationName+" = "+this.notationValue+"\nReason for Revocation\n Flag :"+ this.reasonForRevocationFlag+"\n Reason :"+this.reasonForRevocationString+"\nMPI:\n",c=0;c> 8&255)+String.fromCharCode(f.length&255)+f+String.fromCharCode(180)+String.fromCharCode(c.length>>24)+String.fromCharCode(c.length>>16&255)+String.fromCharCode(c.length>>8&255)+String.fromCharCode(c.length&255)+c;c=new openpgp_packet_signature;c=c.write_message_signature(16,f,a);e=openpgp_encoding_armor(4,e.publicKey.string+d+c.openpgp);d=openpgp_encoding_armor(5,b.string+d+c.openpgp);return{privateKey:a,privateKeyArmored:d,publicKeyArmored:e}};this.write_signed_message=function(a,b){var c=(new openpgp_packet_signature).write_message_signature(1, -b.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"),a),c={text:b.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"),openpgp:c.openpgp,hash:c.hash};return openpgp_encoding_armor(2,c,null,null)};this.write_signed_and_encrypted_message=function(a,b,c){var d="",e=(new openpgp_packet_literaldata).write_packet(c.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));util.print_debug("literal_packet: |"+e+"|\n"+util.hexstrdump(e));for(var f=0;fh.signatureType||3==h.tagType||8==h.tagType||9==h.tagType||10==h.tagType||11==h.tagType||18==h.tagType||19==h.tagType)if(d[d.length]=new openpgp_msg_message,d[e].messagePacket=h,d[e].type=b.type,9==h.tagType||1==h.tagType||3==h.tagType||18==h.tagType)if(9==h.tagType){util.print_error("unexpected openpgp packet");break}else if(1==h.tagType){util.print_debug("session key found:\n "+ -h.toString());var k=!0;d[e].sessionKeys=[];for(var l=0;k;)d[e].sessionKeys[l]=h,f+=h.packetLength+h.headerLength,g-=h.packetLength+h.headerLength,h=openpgp_packet.read_packet(a,f,g),1!=h.tagType&&3!=h.tagType&&(k=!1),l++;18==h.tagType||9==h.tagType?(util.print_debug("encrypted data found:\n "+h.toString()),d[e].encryptedData=h,f+=h.packetLength+h.headerLength,g-=h.packetLength+h.headerLength,e++):util.print_debug("something is wrong: "+h.tagType)}else{if(18==h.tagType){util.print_debug("symmetric encrypted data"); -break}}else if(2==h.tagType&&3>h.signatureType){d[e].text=b.text;d[e].signature=h;break}else if(8==h.tagType){util.print_error("A directly compressed message is currently not supported");break}else{if(11==h.tagType){util.print_error("A direct literal message is currently not supported.");break}}else return util.print_error("no message found!"),null}return d};this.read_publicKey=function(a){for(var b=0,c=[],d=0,a=openpgp_encoding_deArmor(a.replace(/\r/g,"")).openpgp,e=a.length;b!=a.length;){var f= -openpgp_packet.read_packet(a,b,e);if(153==a[b].charCodeAt()||6==f.tagType)c[d]=new openpgp_msg_publickey,c[d].header=a.substring(b,b+3),153==a[b].charCodeAt()?(b++,e=a[b++].charCodeAt()<<8|a[b++].charCodeAt(),c[d].publicKeyPacket=new openpgp_packet_keymaterial,c[d].publicKeyPacket.header=c[d].header,c[d].publicKeyPacket.read_tag6(a,b,e),b+=c[d].publicKeyPacket.packetLength,b+=c[d].read_nodes(c[d].publicKeyPacket,a,b,a.length-b)):(c[d]=new openpgp_msg_publickey,c[d].publicKeyPacket=f,b+=f.headerLength+ -f.packetLength,b+=c[d].read_nodes(f,a,b,a.length-b));else return util.print_error("no public key found!"),null;c[d].data=a.substring(0,b);d++}return c};this.read_privateKey=function(a){for(var b=[],c=0,d=0,a=openpgp_encoding_deArmor(a.replace(/\r/g,"")).openpgp,e=a.length;d!=a.length;){var f=openpgp_packet.read_packet(a,d,e);if(5==f.tagType)b[b.length]=new openpgp_msg_privatekey,d+=f.headerLength+f.packetLength,d+=b[c].read_nodes(f,a,d,e);else return util.print_error("no block packet found!"),null; -b[c].data=a.substring(0,d);c++}return b};this.init=function(){this.config=new openpgp_config;this.config.read();this.keyring=new openpgp_keyring;this.keyring.init()}}var openpgp=new _openpgp; +b.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"),a),c={text:b.replace(/\r\n/g,"\n").replace(/\n/,"\r\n"),openpgp:c.openpgp,hash:c.hash};return openpgp_encoding_armor(2,c,null,null)};this.write_signed_and_encrypted_message=function(a,b,c){var d="",e=(new openpgp_packet_literaldata).write_packet(c.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"));util.print_debug_hexstr_dump("literal_packet: |"+e+"|\n",e);for(var f=0;fh.signatureType||3==h.tagType||8==h.tagType||9==h.tagType||10==h.tagType||11==h.tagType||18==h.tagType||19==h.tagType)if(d[d.length]=new openpgp_msg_message,d[e].messagePacket=h,d[e].type=b.type,9==h.tagType||1==h.tagType||3==h.tagType||18==h.tagType)if(9==h.tagType){util.print_error("unexpected openpgp packet");break}else if(1==h.tagType){util.print_debug("session key found:\n "+h.toString());var k=!0;d[e].sessionKeys=[];for(var l= +0;k;)d[e].sessionKeys[l]=h,f+=h.packetLength+h.headerLength,g-=h.packetLength+h.headerLength,h=openpgp_packet.read_packet(a,f,g),1!=h.tagType&&3!=h.tagType&&(k=!1),l++;18==h.tagType||9==h.tagType?(util.print_debug("encrypted data found:\n "+h.toString()),d[e].encryptedData=h,f+=h.packetLength+h.headerLength,g-=h.packetLength+h.headerLength,e++):util.print_debug("something is wrong: "+h.tagType)}else{if(18==h.tagType){util.print_debug("symmetric encrypted data");break}}else if(2==h.tagType&&3>h.signatureType){d[e].text= +b.text;d[e].signature=h;break}else if(8==h.tagType){util.print_error("A directly compressed message is currently not supported");break}else{if(11==h.tagType){util.print_error("A direct literal message is currently not supported.");break}}else return util.print_error("no message found!"),null}return d};this.read_publicKey=function(a){for(var b=0,c=[],d=0,a=openpgp_encoding_deArmor(a.replace(/\r/g,"")).openpgp,e=a.length;b!=a.length;){var f=openpgp_packet.read_packet(a,b,e);if(153==a[b].charCodeAt()|| +6==f.tagType)c[d]=new openpgp_msg_publickey,c[d].header=a.substring(b,b+3),153==a[b].charCodeAt()?(b++,e=a[b++].charCodeAt()<<8|a[b++].charCodeAt(),c[d].publicKeyPacket=new openpgp_packet_keymaterial,c[d].publicKeyPacket.header=c[d].header,c[d].publicKeyPacket.read_tag6(a,b,e),b+=c[d].publicKeyPacket.packetLength,b+=c[d].read_nodes(c[d].publicKeyPacket,a,b,a.length-b)):(c[d]=new openpgp_msg_publickey,c[d].publicKeyPacket=f,b+=f.headerLength+f.packetLength,b+=c[d].read_nodes(f,a,b,a.length-b));else return util.print_error("no public key found!"), +null;c[d].data=a.substring(0,b);d++}return c};this.read_privateKey=function(a){for(var b=[],c=0,d=0,a=openpgp_encoding_deArmor(a.replace(/\r/g,"")).openpgp,e=a.length;d!=a.length;){var f=openpgp_packet.read_packet(a,d,e);if(5==f.tagType)b[b.length]=new openpgp_msg_privatekey,d+=f.headerLength+f.packetLength,d+=b[c].read_nodes(f,a,d,e);else return util.print_error("no block packet found!"),null;b[c].data=a.substring(0,d);c++}return b};this.init=function(){this.config=new openpgp_config;this.config.read(); +this.keyring=new openpgp_keyring;this.keyring.init()}}var openpgp=new _openpgp; function openpgp_msg_publickey(){this.tostring="OPENPGP PUBLIC KEY\n";this.publicKeyPacket=this.bindingSignature=null;this.userIds=[];this.userAttributes=[];this.revocationSignatures=[];this.subKeys=[];this.arbitraryPacket=[];this.directSignatures=[];this.verifyCertificationSignatures=function(){for(var a=[],b=0;be.length;)e="0"+e;b+=" "+e;f++;0==f%32&&(b+="\n ")}return b};this.hexstrdump=function(a){if(null==a)return"";for(var b="",c=a.length,d=0,e;de.length;)e="0"+e;b+=""+e}return b};this.hexidump=function(a){for(var b="",c=a.length,d=0,e;de.length;)e="0"+e;b+=""+e}return b};this.str2bin=function(a){for(var b= [],c=0;c

'+ -a.replace(/\n/g,"
")+"

"))};this.print_error=function(a){a=openpgp_encoding_html_encode(a);showMessages('

ERROR:\t'+a.replace(/\n/g,"
")+"

")};this.print_info=function(a){a=openpgp_encoding_html_encode(a);showMessages('

INFO:\t'+ -a.replace(/\n/g,"
")+"

")};this.print_warning=function(a){a=openpgp_encoding_html_encode(a);showMessages('

WARNING:\t'+a.replace(/\n/g,"
")+"

")};this.getLeftNBits=function(a,b){var c=b%8;return 0==c?a.substring(0,b/8):this.shiftRight(a.substring(0,(b-c)/8+1),8-c)};this.shiftRight=function(a,b){var c= -util.str2bin(a);if(0!=b%8)for(var d=c.length-1;0<=d;d--)c[d]>>=b%8,0")+"

"))};this.print_debug_hexstr_dump=function(a,b){openpgp.config.debug&&(a+=this.hexstrdump(b),a=openpgp_encoding_html_encode(a),showMessages('

'+a.replace(/\n/g,"
")+"

"))};this.print_error=function(a){a=openpgp_encoding_html_encode(a);showMessages('

ERROR:\t'+ +a.replace(/\n/g,"
")+"

")};this.print_info=function(a){a=openpgp_encoding_html_encode(a);showMessages('

INFO:\t'+a.replace(/\n/g,"
")+"

")};this.print_warning=function(a){a=openpgp_encoding_html_encode(a);showMessages('

WARNING:\t'+ +a.replace(/\n/g,"
")+"

")};this.getLeftNBits=function(a,b){var c=b%8;return 0==c?a.substring(0,b/8):this.shiftRight(a.substring(0,(b-c)/8+1),8-c)};this.shiftRight=function(a,b){var c=util.str2bin(a);if(0!=b%8)for(var d=c.length-1;0<=d;d--)c[d]>>=b%8,0' + * Different than print_debug because will call hexstrdump iff necessary. + * @param str [String] string of the debug message + * @return [String] an HTML tt entity containing a paragraph with a style attribute where the debug message is HTMLencoded in. + */ + this.print_debug_hexstr_dump = function(str,strToHex) { + if (openpgp.config.debug) { + str = str + this.hexstrdump(strToHex); + str = openpgp_encoding_html_encode(str); + showMessages("

"+str.replace(/\n/g,"
")+"

"); + } + }; + /** * Helper function to print an error message. * The calling Javascript context MUST define