Skip to content

Commit

Permalink
Handle key decryption errors
Browse files Browse the repository at this point in the history
  • Loading branch information
twiss committed Jul 5, 2024
1 parent aad40cd commit 3f196f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/commands/decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const openpgp = require('../initOpenpgp');
const fs = require('fs');
const process = require('process');
const utils = require('../utils');
const { CANNOT_DECRYPT, BAD_DATA } = require('../errorCodes');
const { CANNOT_DECRYPT, BAD_DATA, KEY_IS_PROTECTED } = require('../errorCodes');

const decrypt = async (withPassword, sessionKeyOut, withSessionKey, verifyWith, verificationsOut, keyfiles, withKeyPassword) => {
const encrypted = await utils.read_stdin();
Expand Down Expand Up @@ -63,7 +63,12 @@ const decrypt = async (withPassword, sessionKeyOut, withSessionKey, verifyWith,
decryptionKeys = await Promise.all(decryptionKeys.map(privateKey => openpgp.decryptKey({
privateKey,
passphrase: [keyPassword, keyPassword.trimEnd()]
})));
}))).catch((e) => {
// TODO: Only error on key decryption failure if we can't decrypt
// the message with another key (or password or session key).
console.error(e.message);
process.exit(KEY_IS_PROTECTED);
});
}

const decryptedSessionKeys = await openpgp.decryptSessionKeys({
Expand Down
1 change: 1 addition & 0 deletions src/errorCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
CERT_CANNOT_ENCRYPT: 17,
CANNOT_DECRYPT: 29,
BAD_DATA: 41,
KEY_IS_PROTECTED: 67,
KEY_CANNOT_SIGN: 79,
UNSUPPORTED_PROFILE: 89
};

0 comments on commit 3f196f9

Please sign in to comment.