From e20d727d76bd97d1d2e843ca23c4859b7b4b19cb Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Mon, 18 Nov 2019 13:40:40 +0100 Subject: [PATCH] Always encrypt keys using AES Even if they were previously encrypted using another algorithm. --- 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 ea7edc84..8ac73133 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -68,12 +68,12 @@ function SecretKey(date = new Date()) { * Symmetric algorithm * @type {String} */ - this.symmetric = 'aes256'; + this.symmetric = null; /** * AEAD algorithm * @type {String} */ - this.aead = 'eax'; + this.aead = null; } SecretKey.prototype = new PublicKey(); @@ -287,12 +287,14 @@ SecretKey.prototype.encrypt = async function (passphrase) { this.s2k = new type_s2k(); this.s2k.salt = await crypto.random.getRandomBytes(8); const cleartext = write_cleartext_params(this.params, this.algorithm); + this.symmetric = 'aes256'; const key = await produceEncryptionKey(this.s2k, passphrase, this.symmetric); const blockLen = crypto.cipher[this.symmetric].blockSize; this.iv = await crypto.random.getRandomBytes(blockLen); if (this.version === 5) { this.s2k_usage = 253; + this.aead = 'eax'; const mode = crypto[this.aead]; const modeInstance = await mode(this.symmetric, key); this.keyMaterial = await modeInstance.encrypt(cleartext, this.iv.subarray(0, mode.ivLength), new Uint8Array());