aboutsummaryrefslogtreecommitdiffstats
path: root/src/decrypt.c
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2022-04-25 10:14:42 +0000
committerIngo Klöcker <[email protected]>2022-04-25 10:14:42 +0000
commite21c3b559dfb59c61f789572071e72e31bb089bf (patch)
tree0bfbbdb6f934ae82e2f729ced8e7e1f79674e2aa /src/decrypt.c
parentqt: Report better error if decryption failed because of bad passphrase (diff)
downloadgpgme-e21c3b559dfb59c61f789572071e72e31bb089bf.tar.gz
gpgme-e21c3b559dfb59c61f789572071e72e31bb089bf.zip
core: Return BAD_PASSPHRASE error code on symmetric decryption.
* src/decrypt.c (op_data_t): Add field symdecrypt_failed. (parse_status_error): Handle BAD_PASSPHRASE error code. (_gpgme_decrypt_status_handler): Consult new field. -- Return a bad passphrase error if the failure during symmetric decryption is likely caused by the user entering a wrong passphrase. The special error code of a failed public key decryption takes precedence. GnuPG-bug-id: 5939
Diffstat (limited to 'src/decrypt.c')
-rw-r--r--src/decrypt.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/decrypt.c b/src/decrypt.c
index f8847996..896a873f 100644
--- a/src/decrypt.c
+++ b/src/decrypt.c
@@ -44,10 +44,12 @@ typedef struct
int okay;
- /* A flag telling that the a decryption failed and an optional error
- * code to further specify the failure. */
+ /* A flag telling that the a decryption failed and two optional error
+ * codes to further specify the failure for public key decryption and
+ * symmetric decryption. */
int failed;
gpg_error_t pkdecrypt_failed;
+ gpg_error_t symdecrypt_failed;
/* At least one secret key is not available. gpg issues NO_SECKEY
* status lines for each key the message has been encrypted to but
@@ -228,7 +230,22 @@ parse_status_error (char *args, op_data_t opd)
opd->result.legacy_cipher_nomdc = 1;
opd->not_integrity_protected = 1;
}
+ else if (!strcmp (field[0], "symkey_decrypt.maybe_error"))
+ {
+ switch (gpg_err_code (err))
+ {
+ case GPG_ERR_BAD_PASSPHRASE:
+ /* A bad passphrase is severe enough that we return this
+ * error code. */
+ opd->symdecrypt_failed = err;
+ break;
+ default:
+ /* For now all other error codes are ignored and the
+ * standard DECRYPT_FAILED is returned. */
+ break;
+ }
+ }
/* Record the first error code. */
if (err && !opd->first_status_error)
opd->first_status_error = err;
@@ -376,6 +393,8 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
/* This comes from a specialized ERROR status line. */
if (opd->pkdecrypt_failed)
return opd->pkdecrypt_failed;
+ if (opd->symdecrypt_failed)
+ return opd->symdecrypt_failed;
/* For an integrity failure return just DECRYPTION_FAILED;
* the actual cause can be taken from an already set