From 1695cf267edf85bc451b59bf012083feb250bf59 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 24 Jun 2024 16:31:24 +0200 Subject: gpg: New option --show-only-session-key * g10/options.h (opt): Add show_only_session_key and turn show_session_key into a bit flag. * g10/gpg.c (oShowOnlySessionKey): New. (opts): Add "show-only-session-key". (main): Set flag. * g10/mainproc.c (proc_encrypted): Handle the new option. * g10/decrypt-data.c (decrypt_data): Ditto. Add compliance error flag to the DECRYPTION_INFO status line. -- This new option is somehow related to GnuPG-bug-id: 1825 --- g10/decrypt-data.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'g10/decrypt-data.c') diff --git a/g10/decrypt-data.c b/g10/decrypt-data.c index ea4d48955..81209f66f 100644 --- a/g10/decrypt-data.c +++ b/g10/decrypt-data.c @@ -263,11 +263,13 @@ decrypt_data (ctrl_t ctrl, void *procctx, PKT_encrypted *ed, DEK *dek, /* Check compliance. */ if (!gnupg_cipher_is_allowed (opt.compliance, 0, dek->algo, ciphermode)) { - log_error (_("cipher algorithm '%s' may not be used in %s mode\n"), + gpgrt_log (opt.show_only_session_key? GPGRT_LOGLVL_INFO + /* */: GPGRT_LOGLVL_ERROR, + _("cipher algorithm '%s' may not be used in %s mode\n"), openpgp_cipher_algo_mode_name (dek->algo,ed->aead_algo), gnupg_compliance_option_string (opt.compliance)); *compliance_error = 1; - if (opt.flags.require_compliance) + if (opt.flags.require_compliance && !opt.show_only_session_key) { /* We fail early in this case because it does not make sense * to first decrypt everything. */ @@ -276,8 +278,9 @@ decrypt_data (ctrl_t ctrl, void *procctx, PKT_encrypted *ed, DEK *dek, } } - write_status_printf (STATUS_DECRYPTION_INFO, "%d %d %d", - ed->mdc_method, dek->algo, ed->aead_algo); + write_status_printf (STATUS_DECRYPTION_INFO, "%d %d %d %d", + ed->mdc_method, dek->algo, ed->aead_algo, + *compliance_error); if (opt.show_session_key) { @@ -297,6 +300,11 @@ decrypt_data (ctrl_t ctrl, void *procctx, PKT_encrypted *ed, DEK *dek, log_info ("session key: '%s%s'\n", numbuf, hexbuf); write_status_strings (STATUS_SESSION_KEY, numbuf, hexbuf, NULL); xfree (hexbuf); + if (opt.show_only_session_key) + { + rc = 0; + goto leave; + } } rc = openpgp_cipher_test_algo (dek->algo); -- cgit v1.2.3