From 2131fb0978fc01b61b9a90653237cbdd6f5b2950 Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Thu, 20 Feb 2020 15:53:03 +0100 Subject: [PATCH] Fix error message for legacy encrypted private keys --- src/packet/secret_key.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index 899e485e..fade2f2a 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -324,7 +324,7 @@ async function produceEncryptionKey(s2k, passphrase, algorithm) { * @async */ SecretKey.prototype.decrypt = async function (passphrase) { - if (this.s2k.type === 'gnu-dummy') { + if (this.s2k && this.s2k.type === 'gnu-dummy') { this.isEncrypted = false; return false; } @@ -336,8 +336,10 @@ SecretKey.prototype.decrypt = async function (passphrase) { let key; if (this.s2k_usage === 254 || this.s2k_usage === 253) { key = await produceEncryptionKey(this.s2k, passphrase, this.symmetric); + } else if (this.s2k_usage === 255) { + throw new Error('Encrypted private key is authenticated using an insecure two-byte hash'); } else { - throw new Error('Unsupported legacy encrypted key'); + throw new Error('Private key is encrypted using an insecure S2K function: unsalted MD5'); } let cleartext;