diff --git a/resources/openpgp.js b/resources/openpgp.js index 3325e757..35136f9b 100644 --- a/resources/openpgp.js +++ b/resources/openpgp.js @@ -12109,19 +12109,25 @@ function openpgp_packet_signature() { if (this.version == 4) { this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, this.MPIs, key.obj.publicKeyPacket.MPIs, data+this.signatureData+trailer); + } else if (this.version == 3) { + this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, + this.MPIs, key.obj.publicKeyPacket.MPIs, data+this.signatureData); } else { this.verified = false; } break; case 1: // 0x01: Signature of a canonical text document. + var tohash = data + .replace(/\r\n/g,"\n") + .replace(/[\t ]+\n/g, "\n") + .replace(/\n/g,"\r\n"); if (this.version == 4) { - var tohash = data - .replace(/\r\n/g,"\n") - .replace(/[\t ]+\n/g, "\n") - .replace(/\n/g,"\r\n"); this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, this.MPIs, key.obj.publicKeyPacket.MPIs, tohash+this.signatureData+trailer); + } else if (this.version == 3) { + this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, + this.MPIs, key.obj.publicKeyPacket.MPIs, tohash+this.signatureData); } else { this.verified = false; } @@ -12132,13 +12138,12 @@ function openpgp_packet_signature() { // It is calculated identically to a signature over a zero-length // binary document. Note that it doesn't make sense to have a V3 // standalone signature. - if (this.version == 3) { - this.verified = false; - break; - } - - this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, + if (this.version == 4) { + this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, this.MPIs, key.obj.publicKeyPacket.MPIs, this.signatureData+trailer); + } else { + this.verified = false; + } break; case 16: // 0x10: Generic certification of a User ID and Public-Key packet. diff --git a/resources/openpgp.min.js b/resources/openpgp.min.js index 06e4961a..4dbb7e3f 100644 --- a/resources/openpgp.min.js +++ b/resources/openpgp.min.js @@ -430,19 +430,19 @@ g+" @:"+e+" subplen:"+f+" len:"+d),f+1;default:return util.print_error("openpgp. this.keyId:null};this.write_message_signature=function(a,c,d){var e=d.privateKeyPacket.publicKey,f=d.getPreferredSignatureHashAlgorithm(),g=String.fromCharCode(4),g=g+String.fromCharCode(a),g=g+String.fromCharCode(e.publicKeyAlgorithm),g=g+String.fromCharCode(f),a=Math.round((new Date).getTime()/1E3),a=b(2,""+String.fromCharCode(a>>24&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255)),h=b(16,d.getKeyId()),g=g+String.fromCharCode(a.length+h.length>>8&255), g=g+String.fromCharCode(a.length+h.length&255),g=g+a+h,a=""+String.fromCharCode(4),a=a+String.fromCharCode(255),a=a+String.fromCharCode(g.length>>24),a=a+String.fromCharCode(g.length>>16&255),a=a+String.fromCharCode(g.length>>8&255),a=a+String.fromCharCode(g.length&255),h=String.fromCharCode(0),h=h+String.fromCharCode(0),j=openpgp_crypto_hashData(f,c+g+a);util.print_debug("DSA Signature is calculated with:|"+c+g+a+"|\n"+util.hexstrdump(c+g+a)+"\n hash:"+util.hexstrdump(j));h+=j.charAt(0);h+=j.charAt(1); h+=openpgp_crypto_signData(f,d.privateKeyPacket.publicKey.publicKeyAlgorithm,e.MPIs,d.privateKeyPacket.secMPIs,c+g+a);return{openpgp:openpgp_packet.write_packet_header(2,(g+h).length)+g+h,hash:util.get_hashAlgorithmString(f)}};this.verify=function(a,b){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);switch(this.signatureType){case 0:this.verified=4==this.version?openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,a+this.signatureData+d):!1;break;case 1:if(4==this.version){var e=a.replace(/\r\n/g,"\n").replace(/[\t ]+\n/g,"\n").replace(/\n/g,"\r\n");this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,e+this.signatureData+d)}else this.verified=!1;break;case 2:if(3== -this.version){this.verified=!1;break}this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.obj.publicKeyPacket.MPIs,this.signatureData+d);break;case 16:case 17:case 18:case 19:case 48:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;case 24:if(3==this.version){this.verified=!1;break}this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm, -this.MPIs,b.MPIs,a+this.signatureData+d);break;case 25:case 31:case 32:case 40:this.verified=openpgp_crypto_verifySignature(this.publicKeyAlgorithm,this.hashAlgorithm,this.MPIs,b.MPIs,a+this.signatureData+d);break;default:util.print_error("openpgp.packet.signature.js\nsignature verification for type"+this.signatureType+" not implemented"),this.verified=!1}return this.verified};this.read_packet=function(a,b,d){this.data=a.substring(b,b+d);if(0>d)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+ -b),null;var e=b;this.packetLength=d;this.version=a.charCodeAt(e++);switch(this.version){case 3:5!=a.charCodeAt(e++)&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));this.signatureType=a.charCodeAt(e++);this.creationTime=new Date(1E3*(a.charCodeAt(e++)<<24|a.charCodeAt(e++)<<16|a.charCodeAt(e++)<<8|a.charCodeAt(e++)));this.signatureData=a.substring(b,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm=a.charCodeAt(e++); -this.hashAlgorithm=a.charCodeAt(e++);this.signedHashValue=a.charCodeAt(e++)<<8|a.charCodeAt(e++);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;fd)return util.print_debug("openpgp.packet.signature.js\nopenpgp_packet_signature read_packet length < 0 @:"+b),null;var e=b;this.packetLength=d;this.version=a.charCodeAt(e++);switch(this.version){case 3:5!=a.charCodeAt(e++)&&util.print_debug("openpgp.packet.signature.js\ninvalid One-octet length of following hashed material. MUST be 5. @:"+(e-1));this.signatureType= +a.charCodeAt(e++);this.creationTime=new Date(1E3*(a.charCodeAt(e++)<<24|a.charCodeAt(e++)<<16|a.charCodeAt(e++)<<8|a.charCodeAt(e++)));this.signatureData=a.substring(b,e);this.keyId=a.substring(e,e+8);e+=8;this.publicKeyAlgorithm=a.charCodeAt(e++);this.hashAlgorithm=a.charCodeAt(e++);this.signedHashValue=a.charCodeAt(e++)<<8|a.charCodeAt(e++);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;fb.charCodeAt(e)?(packet_length=b.charCodeAt(e++),f=1):192<=b.charCodeAt(e)&&224>b.charCodeAt(e)?(packet_length=(b.charCodeAt(e++)-192<<8)+b.charCodeAt(e++)+192,f=2):223b.charCodeAt(e)? (packet_length=1<<(b.charCodeAt(e++)&31),f=1):(f=5,e++,packet_length=b.charCodeAt(e++)<<24|b.charCodeAt(e++)<<16|b.charCodeAt(e++)<<8|b.charCodeAt(e++));b.charCodeAt(e++);packet_length--;f++;this.userattributes[0]=[];this.userattributes[0]=b.substring(e,e+packet_length);e+=packet_length;d+=f+packet_length}this.packetLength=e-a;return this};this.read_nodes=function(b,a,c,d){this.parentNode=b;for(var e=c,f=d;a.length!=e;){var g=openpgp_packet.read_packet(a,e,f);if(null==g){util.print_error("openpgp.packet.userattribute.js\n[user_attr] parsing ends here @:"+ e+" l:"+f);break}else switch(g.tagType){case 2:15g.signatureType?this.certificationSignatures[this.certificationSignatures.length]=g:32==g.signatureType&&(this.certificationRevocationSignatures[this.certificationRevocationSignatures.length]=g);e+=g.packetLength+g.headerLength;f=d-(e-c);break;default:return this.data=a,this.position=c-b.packetLength,this.len=e-c}}this.data=a;this.position=c-b.packetLength;return this.len=e-c};this.toString=function(){for(var b="5.12. User Attribute Packet (Tag 17)\n AttributePackets: (count = "+ diff --git a/src/packet/openpgp.packet.signature.js b/src/packet/openpgp.packet.signature.js index c91ad8fe..3529709f 100644 --- a/src/packet/openpgp.packet.signature.js +++ b/src/packet/openpgp.packet.signature.js @@ -497,19 +497,25 @@ function openpgp_packet_signature() { if (this.version == 4) { this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, this.MPIs, key.obj.publicKeyPacket.MPIs, data+this.signatureData+trailer); + } else if (this.version == 3) { + this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, + this.MPIs, key.obj.publicKeyPacket.MPIs, data+this.signatureData); } else { this.verified = false; } break; case 1: // 0x01: Signature of a canonical text document. + var tohash = data + .replace(/\r\n/g,"\n") + .replace(/[\t ]+\n/g, "\n") + .replace(/\n/g,"\r\n"); if (this.version == 4) { - var tohash = data - .replace(/\r\n/g,"\n") - .replace(/[\t ]+\n/g, "\n") - .replace(/\n/g,"\r\n"); this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, this.MPIs, key.obj.publicKeyPacket.MPIs, tohash+this.signatureData+trailer); + } else if (this.version == 3) { + this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, + this.MPIs, key.obj.publicKeyPacket.MPIs, tohash+this.signatureData); } else { this.verified = false; } @@ -520,13 +526,12 @@ function openpgp_packet_signature() { // It is calculated identically to a signature over a zero-length // binary document. Note that it doesn't make sense to have a V3 // standalone signature. - if (this.version == 3) { - this.verified = false; - break; - } - - this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, + if (this.version == 4) { + this.verified = openpgp_crypto_verifySignature(this.publicKeyAlgorithm, this.hashAlgorithm, this.MPIs, key.obj.publicKeyPacket.MPIs, this.signatureData+trailer); + } else { + this.verified = false; + } break; case 16: // 0x10: Generic certification of a User ID and Public-Key packet.