From c8729a02958f7903a7f5e8836e8d9953d0f07ebf Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Fri, 7 Jun 2019 16:04:11 +0200 Subject: [PATCH] Fix serializing GNU stripped-keys --- src/packet/secret_key.js | 7 ++++++- src/type/s2k.js | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index ddde4b15..accb225b 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -224,7 +224,7 @@ SecretKey.prototype.write = function () { // - [Optional] If secret data is encrypted (string-to-key usage octet // not zero), an Initial Vector (IV) of the same length as the // cipher's block size. - if (this.s2k_usage) { + if (this.s2k_usage && this.s2k.type !== 'gnu-dummy') { optionalFieldsArr.push(...this.iv); } @@ -385,6 +385,11 @@ SecretKey.prototype.generate = async function (bits, curve) { * Clear private params, return to initial state */ SecretKey.prototype.clearPrivateParams = function () { + if (this.s2k && this.s2k.type === 'gnu-dummy') { + this.isEncrypted = true; + return; + } + if (!this.keyMaterial) { throw new Error('If secret key is not encrypted, clearing private params is irreversible.'); } diff --git a/src/type/s2k.js b/src/type/s2k.js index 02d86f36..99ea32ca 100644 --- a/src/type/s2k.js +++ b/src/type/s2k.js @@ -117,6 +117,10 @@ S2K.prototype.read = function (bytes) { * @returns {Uint8Array} binary representation of s2k */ S2K.prototype.write = function () { + if (this.type === 'gnu-dummy') { + return new Uint8Array([101, 0, ...util.str_to_Uint8Array('GNU'), 1]); + } + const arr = [new Uint8Array([enums.write(enums.s2k, this.type), enums.write(enums.hash, this.algorithm)])]; switch (this.type) {