From 15bf0e144c0d9905c74d7c4bd8c9dd9b9969b7fe Mon Sep 17 00:00:00 2001 From: Sean Colyer Date: Mon, 16 Jan 2012 21:31:46 -0500 Subject: [PATCH] Few bugfixes. Testing for key generation has revealed is currently broken. Investigating. --- resources/openpgp.js | 21 ++++++----- resources/openpgp.min.js | 69 ++++++++++++++++++------------------ src/openpgp.js | 3 +- src/openpgp.keyring.js | 4 +-- src/openpgp.msg.publickey.js | 4 +-- 5 files changed, 52 insertions(+), 49 deletions(-) diff --git a/resources/openpgp.js b/resources/openpgp.js index 4d7d68ba..01e7e453 100644 --- a/resources/openpgp.js +++ b/resources/openpgp.js @@ -635,8 +635,8 @@ function openpgp_packet_signature() { case 108: // Private or experimental case 109: // Private or experimental case 110: // Private or experimental - return subplen+1; util.print_error("openpgp.packet.signature.js\n"+'private or experimental signature subpacket type '+type+" @:"+mypos+" subplen:"+subplen+" len:"+len); + return subplen+1; break; case 0: // Reserved case 1: // Reserved @@ -932,7 +932,8 @@ function openpgp_packet_signature() { this.verify = verify; this.read_packet = read_packet; this.toString = toString; -}// 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 @@ -3323,6 +3324,7 @@ function openpgp_packet_keymaterial() { * @return {body: [string]OpenPGP packet body contents, header: [string] OpenPGP packet header, string: [string] header+body} */ function write_private_key(keyType, key){ + debugger; var tag = 5; var body = String.fromCharCode(4); //TODO make the date into a util function @@ -7310,6 +7312,7 @@ function RSA() { // Generate a new random private key B bits long, using public expt E function generate(B,E) { + debugger; var key = new keyObject(); var rng = new SecureRandom(); var qs = B>>1; @@ -9676,7 +9679,7 @@ function _openpgp () { mypos += publicKeys[publicKeyCount].publicKeyPacket.packetLength; mypos += publicKeys[publicKeyCount].read_nodes(publicKeys[publicKeyCount].publicKeyPacket, input, mypos, (input.length - mypos)); } else { - publicKeys[publicKeys.length] = new openpgp_msg_publickey(); + publicKeys[publicKeyCount] = new openpgp_msg_publickey(); publicKeys[publicKeyCount].publicKeyPacket = first_packet; mypos += first_packet.headerLength+first_packet.packetLength; mypos += publicKeys[publicKeyCount].read_nodes(first_packet, input, mypos, input.length -mypos); @@ -9688,7 +9691,6 @@ function _openpgp () { publicKeys[publicKeyCount].data = input.substring(0,mypos); publicKeyCount++; } - debugger; return publicKeys; } @@ -10056,7 +10058,7 @@ function openpgp_msg_publickey() { case 2: // public key revocation signature if (result.signatureType == 32) this.revocationSignatures[this.revocationSignatures.length] = result; - else if (result.signatureType == 19) + else if (result.signatureType == 16 || result.signatureType == 17 || result.signatureType == 18 || result.signatureType == 19) this.certificationSignature = result; else if (result.signatureType == 25) { this.bindingSignature = result; @@ -10258,7 +10260,8 @@ function openpgp_msg_publickey() { this.getFingerprint = getFingerprint; this.getKeyId = getKeyId; this.verifyBasicSignatures = verifyBasicSignatures; -}// 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 @@ -10304,7 +10307,7 @@ function openpgp_config() { keyserver: "keyserver.linux.it" // "pgp.mit.edu:11371" }; - this.versionstring ="GPG4Browsers 0.1"; + this.versionstring ="OpenPGP.js v0.1"; this.commentstring ="http://openpgpjs.org"; /** * reads the config out of the HTML5 local storage @@ -11506,7 +11509,7 @@ function openpgp_keyring() { function importPublicKey (armored_text) { var result = openpgp.read_publicKey(armored_text); for (var i = 0; i < result.length; i++) { - this.publicKeys[this.publicKeys.length] = {armored: armored_text, obj: result[i]}; + this.publicKeys[this.publicKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()}; } } @@ -11518,7 +11521,7 @@ function openpgp_keyring() { function importPrivateKey (armored_text) { var result = openpgp.read_privateKey(armored_text); for (var i = 0; i < result.length; i++) { - this.privateKeys[this.privateKeys.length] = {armored: armored_text, obj: result[i]}; + this.privateKeys[this.privateKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()}; } } diff --git a/resources/openpgp.min.js b/resources/openpgp.min.js index c6e8fe3b..c6cf1983 100644 --- a/resources/openpgp.min.js +++ b/resources/openpgp.min.js @@ -10,25 +10,26 @@ this.revocationKeyAlgorithm=a[e++].charCodeAt();this.revocationKeyFingerprint=[] for(g=0;g>24&255)+String.fromCharCode(b>>16&255)+String.fromCharCode(b>> -8&255)+String.fromCharCode(b&255)),h=a(16,d.getKeyId()),g=g+String.fromCharCode(b.length+h.length>>8&255),g=g+String.fromCharCode(b.length+h.length&255),g=g+b+h,b=""+String.fromCharCode(4),b=b+String.fromCharCode(255),b=b+String.fromCharCode(g.length>>24),b=b+String.fromCharCode(g.length>>16&255),b=b+String.fromCharCode(g.length>>8&255),b=b+String.fromCharCode(g.length&255),h=String.fromCharCode(0),h=h+String.fromCharCode(0),k=openpgp_crypto_hashData(f,c+g+b);util.print_debug("DSA Signature is calculated with:|"+ -c+g+b+"|\n"+util.hexstrdump(c+g+b)+"\n hash:"+util.hexstrdump(k));h+=k.charAt(0);h+=k.charAt(1);h+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,c+g+b);return{openpgp:openpgp_packet.write_packet_header(2,(g+h).length)+g+h,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,c){switch(this.signatureType){case 0:if(4==this.version){var d;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>> -24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,a.substring(i)+this.signatureData+d)}if(3==this.version)return!1;case 1:if(4==this.version)return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>> -24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,a+this.signatureData+d);if(3==this.version)return!1;case 2:if(3==this.version)return!1;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>> -16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,this.signatureData+d);case 16:case 17:case 18:case 19:case 48:return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>> -8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);case 24:if(3==this.version)return!1;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255); -return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);case 25:case 31:case 32:case 40:return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm, -this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented")}};this.read_packet=function(a,c,d){this.data=a.substring(c,c+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+c),null;var e=c;this.packetLength=d;this.version=a[e++].charCodeAt();switch(this.version){case 3:5!=a[e++].charCodeAt()&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+ -(e-1));this.signatureType=a[e++].charCodeAt();this.creationTime=new Date(1E3*(a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt()));this.signatureData=a.substring(c,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm=a[e++].charCodeAt();this.hashAlgorithm=a[e++].charCodeAt();this.signedHashValue=a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=0;0this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(var f= -0;fthis.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(f=0;f>24&255)+String.fromCharCode(b>>16&255)+String.fromCharCode(b>>8&255)+String.fromCharCode(b&255)),h=a(16,d.getKeyId()),g=g+String.fromCharCode(b.length+h.length>>8&255),g=g+String.fromCharCode(b.length+h.length&255),g=g+b+h,b=""+String.fromCharCode(4),b=b+String.fromCharCode(255),b=b+String.fromCharCode(g.length>>24),b=b+String.fromCharCode(g.length>>16&255),b=b+String.fromCharCode(g.length>>8&255),b=b+String.fromCharCode(g.length&255),h=String.fromCharCode(0), +h=h+String.fromCharCode(0),k=openpgp_crypto_hashData(f,c+g+b);util.print_debug("DSA Signature is calculated with:|"+c+g+b+"|\n"+util.hexstrdump(c+g+b)+"\n hash:"+util.hexstrdump(k));h+=k.charAt(0);h+=k.charAt(1);h+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,c+g+b);return{openpgp:openpgp_packet.write_packet_header(2,(g+h).length)+g+h,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,c){switch(this.signatureType){case 0:if(4== +this.version){var d;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,a.substring(i)+this.signatureData+d)}if(3==this.version)return!1;case 1:if(4== +this.version)return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,a+this.signatureData+d);if(3==this.version)return!1;case 2:if(3==this.version)return!1; +d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>>24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.obj.publicKeyPacket.MPIs,this.signatureData+d);case 16:case 17:case 18:case 19:case 48:return d=""+String.fromCharCode(this.version), +d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>>16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);case 24:if(3==this.version)return!1;d=""+String.fromCharCode(this.version);d+=String.fromCharCode(255);d+=String.fromCharCode(this.signatureData.length>> +24);d+=String.fromCharCode(this.signatureData.length>>16&255);d+=String.fromCharCode(this.signatureData.length>>8&255);d+=String.fromCharCode(this.signatureData.length&255);return openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);case 25:case 31:case 32:case 40:return d=""+String.fromCharCode(this.version),d+=String.fromCharCode(255),d+=String.fromCharCode(this.signatureData.length>>24),d+=String.fromCharCode(this.signatureData.length>> +16&255),d+=String.fromCharCode(this.signatureData.length>>8&255),d+=String.fromCharCode(this.signatureData.length&255),openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,c.MPIs,a+this.signatureData+d);default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented")}};this.read_packet=function(a,c,d){this.data=a.substring(c,c+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+ +c),null;var e=c;this.packetLength=d;this.version=a[e++].charCodeAt();switch(this.version){case 3:5!=a[e++].charCodeAt()&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));this.signatureType=a[e++].charCodeAt();this.creationTime=new Date(1E3*(a[e++].charCodeAt()<<24|a[e++].charCodeAt()<<16|a[e++].charCodeAt()<<8|a[e++].charCodeAt()));this.signatureData=a.substring(c,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm= +a[e++].charCodeAt();this.hashAlgorithm=a[e++].charCodeAt();this.signedHashValue=a[e++].charCodeAt()<<8|a[e++].charCodeAt();d=0;0this.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(var f=0;fthis.publicKeyAlgorithm?d=1:17==this.publicKeyAlgorithm&&(d=2);this.MPIs=[];for(f=0;fthis.publicKeyAlgorithm){var a=this.MPIs[0].substring(this.MPIs[0].mpiByteLength-8);util.print_debug("openpgp.msg.publickey read_nodes:\nV3 key ID: "+a);return a}};this.getFingerprint=function(){if(4==this.version)return tohash=String.fromCharCode(153)+ -String.fromCharCode(this.packetdata.length>>8&255)+String.fromCharCode(this.packetdata.length&255)+this.packetdata,util.print_debug("openpgp.msg.publickey creating subkey fingerprint by hashing:"+util.hexstrdump(tohash)+"\npublickeyalgorithm: "+this.publicKeyAlgorithm),str_sha1(tohash,tohash.length);if(3==this.version&&0this.publicKeyAlgorithm)return MD5(this.MPIs[0].MPI)};this.write_private_key=function(a,b){var c=String.fromCharCode(4),d=new Date,d=d.getTime()/1E3,c= -c+(String.fromCharCode(Math.floor(d/16777216%256))+String.fromCharCode(Math.floor(d/65536%256))+String.fromCharCode(Math.floor(d/256%256))+String.fromCharCode(Math.floor(d%256)));switch(a){case 1:var c=c+String.fromCharCode(1),c=c+b.n.toMPI(),c=c+b.ee.toMPI(),e=6,c=c+String.fromCharCode(0),c=c+b.d.toMPI(),c=c+b.p.toMPI(),c=c+b.q.toMPI(),c=c+b.coeff.toMPI();break;default:c="",util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+a)}c+=util.calc_checksum(c.substr(e)); +String.fromCharCode(this.packetdata.length>>8&255)+String.fromCharCode(this.packetdata.length&255)+this.packetdata,util.print_debug("openpgp.msg.publickey creating subkey fingerprint by hashing:"+util.hexstrdump(tohash)+"\npublickeyalgorithm: "+this.publicKeyAlgorithm),str_sha1(tohash,tohash.length);if(3==this.version&&0this.publicKeyAlgorithm)return MD5(this.MPIs[0].MPI)};this.write_private_key=function(a,b){debugger;var c=String.fromCharCode(4),d=new Date,d=d.getTime()/ +1E3,c=c+(String.fromCharCode(Math.floor(d/16777216%256))+String.fromCharCode(Math.floor(d/65536%256))+String.fromCharCode(Math.floor(d/256%256))+String.fromCharCode(Math.floor(d%256)));switch(a){case 1:var c=c+String.fromCharCode(1),c=c+b.n.toMPI(),c=c+b.ee.toMPI(),e=6,c=c+String.fromCharCode(0),c=c+b.d.toMPI(),c=c+b.p.toMPI(),c=c+b.q.toMPI(),c=c+b.coeff.toMPI();break;default:c="",util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+a)}c+=util.calc_checksum(c.substr(e)); d=openpgp_packet.write_packet_header(5,c.length);return{string:d+c,header:d,body:c}};this.write_public_key=function(a,b){var c=String.fromCharCode(4),d=new Date,d=d.getTime()/1E3,c=c+(String.fromCharCode(Math.floor(d/16777216%256))+String.fromCharCode(Math.floor(d/65536%256))+String.fromCharCode(Math.floor(d/256%256))+String.fromCharCode(Math.floor(d%256)));switch(a){case 1:c+=String.fromCharCode(1);c+=b.n.toMPI();c+=b.ee.toMPI();break;default:util.print_error("openpgp.packet.keymaterial.js\nerror writing private key, unknown type :"+ a)}d=openpgp_packet.write_packet_header(6,c.length);return{string:d+c,header:d,body:c}}} function MD5(a){function b(a){for(i=0;i>b)+(1073741824>>b-1):a>>b}function e(a,b){for(var a=c(a),b=c(b),d=0;da;a+=2)o=16843009*a,r f[4]);setW(d,e+4,l[3]^f[5]);setW(d,e+8,l[0]^f[6]);setW(d,e+12,l[1]^f[7]);e+=16;return d},decrypt:function(c,g){d=c;e=g;for(var l=[getW(d,e)^f[4],getW(d,e+4)^f[5],getW(d,e+8)^f[6],getW(d,e+12)^f[7]],m=7;0<=m;m--){var o=m,r=l,q=a(r[0]),s=b(r[1]);r[2]=rotw(r[2],1)^q+s+f[4*o+10]&MAXINT;r[3]=rotw(r[3]^q+2*s+f[4*o+11]&MAXINT,31);q=a(r[2]);s=b(r[3]);r[0]=rotw(r[0],1)^q+s+f[4*o+8]&MAXINT;r[1]=rotw(r[1]^q+2*s+f[4*o+9]&MAXINT,31)}setW(d,e,l[2]^f[0]);setW(d,e+4,l[3]^f[1]);setW(d,e+8,l[0]^f[2]);setW(d,e+12,l[1]^ f[3]);e+=16},finalize:function(){return d}}}function SecureRandom(){this.nextBytes=function(a){for(var b=0;b>1;d.e=parseInt(c,16);for(d.ee=new BigInteger(c,16);;){for(;!(d.p=new BigInteger(b-f,1,e),0==d.p.subtract(BigInteger.ONE).gcd(d.ee).compareTo(BigInteger.ONE)&&d.p.isProbablePrime(10)););for(;!(d.q=new BigInteger(f,1,e),0==d.q.subtract(BigInteger.ONE).gcd(d.ee).compareTo(BigInteger.ONE)&& +c.multiply(f).mod(e);return c.multiply(d).add(g)};this.verify=function(a,c,d){return a.modPowInt(c,d)};this.sign=function(a,c,d){return a.modPow(c,d)};this.generate=function(b,c){debugger;var d=new a,e=new SecureRandom,f=b>>1;d.e=parseInt(c,16);for(d.ee=new BigInteger(c,16);;){for(;!(d.p=new BigInteger(b-f,1,e),0==d.p.subtract(BigInteger.ONE).gcd(d.ee).compareTo(BigInteger.ONE)&&d.p.isProbablePrime(10)););for(;!(d.q=new BigInteger(f,1,e),0==d.q.subtract(BigInteger.ONE).gcd(d.ee).compareTo(BigInteger.ONE)&& d.q.isProbablePrime(10)););if(0>=d.p.compareTo(d.q)){var g=d.p;d.p=d.q;d.q=g}var g=d.p.subtract(BigInteger.ONE),h=d.q.subtract(BigInteger.ONE),k=g.multiply(h);if(0==k.gcd(d.ee).compareTo(BigInteger.ONE)){d.n=d.p.multiply(d.q);d.d=d.ee.modInverse(k);d.dmp1=d.d.mod(g);d.dmq1=d.d.mod(h);d.coeff=d.q.modInverse(d.p);break}}return d};this.keyObject=a} function DSA(){this.select_hash_algorithm=function(a){var b=openpgp.config.config.prefer_hash_algorithm;switch(Math.round(a.bitLength()/8)){case 20:return 2!=b&&11b?2:b;case 28:return 11b?11:b;case 32:return 10b?8:b;default:return util.print_debug("DSA select hash algorithm: returning null for an unknown length of q"),null}};this.sign=function(a,b,c,d,e,f){a=util.getLeftNBits(openpgp_crypto_hashData(a,b),e.bitLength());a=new BigInteger(util.hexstrdump(a),16);b=openpgp_crypto_getRandomBigIntegerInRange(BigInteger.ONE.add(BigInteger.ONE), e.subtract(BigInteger.ONE));c=c.modPow(b,d).mod(e);e=b.modInverse(e).multiply(a.add(f.multiply(c))).mod(e);f=[];f[0]=c.toMPI();f[1]=e.toMPI();return f};this.verify=function(a,b,c,d,e,f,g,h){a=util.getLeftNBits(openpgp_crypto_hashData(a,d),f.bitLength());a=new BigInteger(util.hexstrdump(a),16);if(0h.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[c.length]=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++}debugger;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; +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;b")[0]: a.trim(),a=0;a")[0]:a.trim(),a=0;ae.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'+ diff --git a/src/openpgp.js b/src/openpgp.js index 7b026056..1b886e30 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -66,7 +66,7 @@ function _openpgp () { mypos += publicKeys[publicKeyCount].publicKeyPacket.packetLength; mypos += publicKeys[publicKeyCount].read_nodes(publicKeys[publicKeyCount].publicKeyPacket, input, mypos, (input.length - mypos)); } else { - publicKeys[publicKeys.length] = new openpgp_msg_publickey(); + publicKeys[publicKeyCount] = new openpgp_msg_publickey(); publicKeys[publicKeyCount].publicKeyPacket = first_packet; mypos += first_packet.headerLength+first_packet.packetLength; mypos += publicKeys[publicKeyCount].read_nodes(first_packet, input, mypos, input.length -mypos); @@ -78,7 +78,6 @@ function _openpgp () { publicKeys[publicKeyCount].data = input.substring(0,mypos); publicKeyCount++; } - debugger; return publicKeys; } diff --git a/src/openpgp.keyring.js b/src/openpgp.keyring.js index cd782c5a..c45c4f28 100644 --- a/src/openpgp.keyring.js +++ b/src/openpgp.keyring.js @@ -174,7 +174,7 @@ function openpgp_keyring() { function importPublicKey (armored_text) { var result = openpgp.read_publicKey(armored_text); for (var i = 0; i < result.length; i++) { - this.publicKeys[this.publicKeys.length] = {armored: armored_text, obj: result[i]}; + this.publicKeys[this.publicKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()}; } } @@ -186,7 +186,7 @@ function openpgp_keyring() { function importPrivateKey (armored_text) { var result = openpgp.read_privateKey(armored_text); for (var i = 0; i < result.length; i++) { - this.privateKeys[this.privateKeys.length] = {armored: armored_text, obj: result[i]}; + this.privateKeys[this.privateKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()}; } } diff --git a/src/openpgp.msg.publickey.js b/src/openpgp.msg.publickey.js index b24924bf..87fbb7ac 100644 --- a/src/openpgp.msg.publickey.js +++ b/src/openpgp.msg.publickey.js @@ -47,7 +47,7 @@ function openpgp_msg_publickey() { case 2: // public key revocation signature if (result.signatureType == 32) this.revocationSignatures[this.revocationSignatures.length] = result; - else if (result.signatureType == 19) + else if (result.signatureType == 16 || result.signatureType == 17 || result.signatureType == 18 || result.signatureType == 19) this.certificationSignature = result; else if (result.signatureType == 25) { this.bindingSignature = result; @@ -249,4 +249,4 @@ function openpgp_msg_publickey() { this.getFingerprint = getFingerprint; this.getKeyId = getKeyId; this.verifyBasicSignatures = verifyBasicSignatures; -} \ No newline at end of file +}