From 151694ff07592de3ecf3336bee902fd807f7c249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obernd=C3=B6rfer?= Date: Sun, 23 Feb 2014 20:51:02 +0100 Subject: [PATCH] Write unhashed subpackets. Fix #178. --- src/packet/signature.js | 8 ++++++-- test/general/signature.js | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/packet/signature.js b/src/packet/signature.js index 0f9f7f8b..607a0528 100644 --- a/src/packet/signature.js +++ b/src/packet/signature.js @@ -51,6 +51,7 @@ function Signature() { this.publicKeyAlgorithm = null; this.signatureData = null; + this.unhashedSubpackets = null; this.signedHashValue = null; this.created = new Date(); @@ -166,9 +167,11 @@ Signature.prototype.read = function (bytes) { // hash algorithm, the hashed subpacket length, and the hashed // subpacket body. this.signatureData = bytes.substr(0, i); + var sigDataLength = i; // unhashed subpackets i += subpackets.call(this, bytes.substr(i), false); + this.unhashedSubpackets = bytes.substr(sigDataLength, i - sigDataLength); break; default: @@ -184,7 +187,8 @@ Signature.prototype.read = function (bytes) { Signature.prototype.write = function () { return this.signatureData + - util.writeNumber(0, 2) + // Number of unsigned subpackets. + // unhashed subpackets or two octets for zero + (this.unhashedSubpackets ? this.unhashedSubpackets : util.writeNumber(0, 2)) + this.signedHashValue + this.signature; }; @@ -559,7 +563,7 @@ Signature.prototype.toSign = function (type, data) { case t.key: if (data.key === undefined) - throw new Error('Key packet is required for this sigtature.'); + throw new Error('Key packet is required for this signature.'); return data.key.writeOld(); diff --git a/test/general/signature.js b/test/general/signature.js index df69d0e3..8c0b29a3 100644 --- a/test/general/signature.js +++ b/test/general/signature.js @@ -571,4 +571,12 @@ describe("Signature", function() { expect(verified).to.be.true; done(); }); + + it('Write unhashed subpackets', function() { + var pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; + expect(pubKey.users[0].selfCertifications).to.exist; + pubKey = openpgp.key.readArmored(pubKey.armor()).keys[0] + expect(pubKey.users[0].selfCertifications).to.exist; + }); + });