From f772757ea1b10b34e418f6a3ed672b0dc05f779c Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 31 Jan 2012 15:14:20 +0100 Subject: [PATCH] gpg: Add a DECRYPTION_INFO status. * common/status.h (STATUS_DECRYPTION_INFO): New. * g10/encr-data.c: Include status.h. (decrypt_data): Emit STATUS_DECRYPTION_INFO line. -- DECRYPTION_INFO Print information about the symmetric encryption algorithm and the MDC method. This will be emitted even if the decryption fails. --- common/status.h | 1 + doc/DETAILS | 52 +++++++++++++++++++++++++++---------------------- g10/encr-data.c | 51 ++++++++++++++++++++++++++++-------------------- 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/common/status.h b/common/status.h index 8df64defa..cfb64ca1b 100644 --- a/common/status.h +++ b/common/status.h @@ -49,6 +49,7 @@ enum STATUS_NO_PUBKEY, STATUS_NO_SECKEY, STATUS_NEED_PASSPHRASE_SYM, + STATUS_DECRYPTION_INFO, STATUS_DECRYPTION_FAILED, STATUS_DECRYPTION_OKAY, STATUS_MISSING_PASSPHRASE, diff --git a/doc/DETAILS b/doc/DETAILS index 2e1d92bb7..423eea9d2 100644 --- a/doc/DETAILS +++ b/doc/DETAILS @@ -57,7 +57,7 @@ record; gpg2 does this by default and the option is a dummy. f = The key is fully valid u = The key is ultimately valid. This often means that the secret key is available, but any key may - be marked as ultimately valid. + be marked as ultimately valid. If the validity information is given for a UID or UAT record, it describes the validity calculated based on this @@ -97,7 +97,7 @@ record; gpg2 does this by default and the option is a dummy. This is a single letter, but be prepared that additional information may follow in some future versions. For trust signatures with a regular expression, this is the regular - expression value, quoted as in field 10. + expression value, quoted as in field 10. 10. Field: User-ID. The value is quoted like a C string to avoid control characters (the colon is quoted "\x3a"). @@ -134,7 +134,7 @@ record; gpg2 does this by default and the option is a dummy. this is the same string as the fingerprint. The advantage of using this value is that it is guaranteed to have been been build by the same lookup algorithm as gpgsm uses. - For "uid" records this lists the preferences in the same + For "uid" records this lists the preferences in the same way the gpg's --edit-key menu does. For "sig" records, this is the fingerprint of the key that issued the signature. Note that this is only filled in if @@ -190,7 +190,7 @@ Example for a "tru" trust base record: (gpg's option --marginals-needed) 7: Number of completely trusted users to introduce a new key signer. (gpg's option --completes-needed) - 8: Maximum depth of a certification chain. + 8: Maximum depth of a certification chain. *gpg's option --max-cert-depth) The "spk" signature subpacket records have the fields: @@ -236,7 +236,7 @@ more arguments in future versions. keyid if it is available. This is the case with CMS and might eventually also be available for OpenPGP. - EXPKEYSIG + EXPKEYSIG The signature with the keyid is good, but the signature was made by an expired key. The username is the primary one encoded in UTF-8 and %XX escaped. The fingerprint may be used @@ -328,13 +328,13 @@ more arguments in future versions. UNEXPECTED Unexpected data has been encountered - 0 - not further specified 1 - + 0 - not further specified 1 + TRUST_UNDEFINED TRUST_NEVER TRUST_MARGINAL [0 []] - TRUST_FULLY [0 []] + TRUST_FULLY [0 []] TRUST_ULTIMATE [0 []] For good signatures one of these status lines are emitted to indicate the validity of the key used to create the signature. @@ -355,7 +355,7 @@ more arguments in future versions. PKA_TRUST_BAD Depending on the outcome of the PKA check one of the above status codes is emitted in addition to a TRUST_* status. - Without PKA info available or + Without PKA info available or SIGEXPIRED This is deprecated in favor of KEYEXPIRED. @@ -452,7 +452,7 @@ more arguments in future versions. 1 := Entirely new key. 2 := New user IDs 4 := New signatures - 8 := New subkeys + 8 := New subkeys 16 := Contains private key. The flags may be ORed. @@ -474,7 +474,7 @@ more arguments in future versions. operation: 1 - verify 2 - encrypt - 3 - decrypt + 3 - decrypt FILE_DONE Marks the end of a file processing which has been started @@ -505,7 +505,7 @@ more arguments in future versions. "char" is the character displayed with no --status-fd enabled, with the linefeed replaced by an 'X'. "cur" is the current amount done and "total" is amount to be done; a "total" of 0 indicates that - the total amount is not known. The condition + the total amount is not known. The condition TOATL && CUR == TOTAL may be used to detect the end of an operation. Well known values for WHAT: @@ -524,7 +524,7 @@ more arguments in future versions. "learncard" Send by the agent and gpgsm while learing the data of a smartcard. "card_busy" A smartcard is still working - + SIG_CREATED A signature has been created using these parameters. type: 'D' = detached @@ -536,7 +536,7 @@ more arguments in future versions. Note, that TIMESTAMP may either be a number with seconds since epoch or an ISO 8601 string which can be detected by the presence of the letter 'T' inside. - + KEY_CREATED [] A key has been created type: 'B' = primary and subkey @@ -557,13 +557,13 @@ more arguments in future versions. is used. The format is suitable to be passed to the option --override-session-key - NOTATION_NAME + NOTATION_NAME NOTATION_DATA name and string are %XX escaped; the data may be split among several NOTATION_DATA lines. USERID_HINT - Give a hint about the user ID for a certain keyID. + Give a hint about the user ID for a certain keyID. POLICY_URL string is %XX escaped @@ -587,7 +587,7 @@ more arguments in future versions. 8 := "Policy mismatch" 9 := "Not a secret key" 10 := "Key not trusted" - 11 := "Missing certificate" + 11 := "Missing certificate" 12 := "Missing issuer certificate" Note that for historical reasons the INV_RECP status is also @@ -621,9 +621,9 @@ more arguments in future versions. SUCCESS [] Postive confirimation that an operation succeeded. - is optional but if given should not contain spaces. + is optional but if given should not contain spaces. Used only with a few commands. - + ATTRIBUTE @@ -650,7 +650,7 @@ more arguments in future versions. 3 = Card with serialnumber detected 4 = No card available. 5 = No card reader available - 6 = No card support available + 6 = No card support available PLAINTEXT This indicates the format of the plaintext that is about to be @@ -695,6 +695,12 @@ more arguments in future versions. may either be the specified mountpoint or one randomly choosen by g13. + DECRYPTION_INFO + Print information about the symmetric encryption algorithm and + the MDC method. This will be emitted even if the decryption + fails. + + Format of the "--attribute-fd" output ===================================== @@ -827,7 +833,7 @@ The format of this file is as follows: relinquishes the GUI from implementing its own passphrase entry code. This is a global option. %no-ask-passphrase - Disable the ask-passphrase mode. + Disable the ask-passphrase mode. %no-protection With GnuPG 2.1 it is not anymore possible to specify a passphrase for unattended key generation. The passphrase @@ -898,7 +904,7 @@ The format of this file is as follows: information and which is also part of the fingerprint calculation. Either a date like "1986-04-26" or a full timestamp like "19860426T042640" may be used. The time is - considered to be UTC. If it is not given the current time + considered to be UTC. If it is not given the current time is used. Preferences: Set the cipher, hash, and compression preference values for @@ -1207,7 +1213,7 @@ Other Notes OIDs below the GnuPG arc: ========================= - 1.3.6.1.4.1.11591.2 GnuPG + 1.3.6.1.4.1.11591.2 GnuPG 1.3.6.1.4.1.11591.2.1 notation 1.3.6.1.4.1.11591.2.1.1 pkaAddress 1.3.6.1.4.1.11591.2.12242973 invalid encoded OID diff --git a/g10/encr-data.c b/g10/encr-data.c index c559299ff..602ae55aa 100644 --- a/g10/encr-data.c +++ b/g10/encr-data.c @@ -1,6 +1,6 @@ /* encr-data.c - process an encrypted data packet * Copyright (C) 1998, 1999, 2000, 2001, 2005, - * 2006, 2009 Free Software Foundation, Inc. + * 2006, 2009, 2012 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -30,6 +30,7 @@ #include "cipher.h" #include "options.h" #include "i18n.h" +#include "status.h" static int mdc_decode_filter ( void *opaque, int control, IOBUF a, @@ -80,7 +81,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) byte temp[32]; unsigned blocksize; unsigned nprefix; - + dfx = xtrycalloc (1, sizeof *dfx); if (!dfx) return gpg_error_from_syserror (); @@ -89,12 +90,20 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( opt.verbose && !dek->algo_info_printed ) { if (!openpgp_cipher_test_algo (dek->algo)) - log_info (_("%s encrypted data\n"), + log_info (_("%s encrypted data\n"), openpgp_cipher_algo_name (dek->algo)); else log_info (_("encrypted with unknown algorithm %d\n"), dek->algo ); dek->algo_info_printed = 1; } + + { + char buf[20]; + + snprintf (buf, sizeof buf, "%d %d", ed->mdc_method, dek->algo); + write_status_text (STATUS_DECRYPTION_INFO, buf); + } + rc = openpgp_cipher_test_algo (dek->algo); if (rc) goto leave; @@ -105,7 +114,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( ed->len && ed->len < (nprefix+2) ) BUG(); - if ( ed->mdc_method ) + if ( ed->mdc_method ) { if (gcry_md_open (&dfx->mdc_hash, ed->mdc_method, 0 )) BUG (); @@ -140,7 +149,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) goto leave; } - if (!ed->buf) + if (!ed->buf) { log_error(_("problem handling encrypted packet\n")); goto leave; @@ -150,7 +159,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( ed->len ) { - for (i=0; i < (nprefix+2) && ed->len; i++, ed->len-- ) + for (i=0; i < (nprefix+2) && ed->len; i++, ed->len-- ) { if ( (c=iobuf_get(ed->buf)) == -1 ) break; @@ -158,7 +167,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) temp[i] = c; } } - else + else { for (i=0; i < (nprefix+2); i++ ) if ( (c=iobuf_get(ed->buf)) == -1 ) @@ -166,7 +175,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) else temp[i] = c; } - + gcry_cipher_decrypt (dfx->cipher_hd, temp, nprefix+2, NULL, 0); gcry_cipher_sync (dfx->cipher_hd); p = temp; @@ -177,7 +186,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) rc = gpg_error (GPG_ERR_BAD_KEY); goto leave; } - + if ( dfx->mdc_hash ) gcry_md_write (dfx->mdc_hash, temp, nprefix+2); @@ -192,7 +201,7 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) if ( ed->mdc_method && dfx->eof_seen == 2 ) rc = gpg_error (GPG_ERR_INV_PACKET); else if ( ed->mdc_method ) - { + { /* We used to let parse-packet.c handle the MDC packet but this turned out to be a problem with compressed packets: With old style packets there is no length information available and @@ -226,8 +235,8 @@ decrypt_data( void *procctx, PKT_encrypted *ed, DEK *dek ) /* log_printhex("MDC message:", dfx->defer, 22); */ /* log_printhex("MDC calc:", gcry_md_read (dfx->mdc_hash,0), datalen); */ } - - + + leave: release_dfx_context (dfx); return rc; @@ -244,7 +253,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, size_t n, size = *ret_len; int rc = 0; int c; - + if ( control == IOBUFCTRL_UNDERFLOW && dfx->eof_seen ) { *ret_len = 0; @@ -254,7 +263,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, { assert (a); assert ( size > 44 ); - + /* Get at least 22 bytes and put it somewhere ahead in the buffer. */ for (n=22; n < 44 ; n++ ) { @@ -262,7 +271,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, break; buf[n] = c; } - if ( n == 44 ) + if ( n == 44 ) { /* We have enough stuff - flush the deferred stuff. */ /* (we asserted that the buffer is large enough) */ @@ -276,7 +285,7 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, memcpy (buf, dfx->defer, 22 ); } /* Now fill up. */ - for (; n < size; n++ ) + for (; n < size; n++ ) { if ( (c = iobuf_get(a)) == -1 ) break; @@ -317,11 +326,11 @@ mdc_decode_filter (void *opaque, int control, IOBUF a, } *ret_len = n; } - else if ( control == IOBUFCTRL_FREE ) + else if ( control == IOBUFCTRL_FREE ) { release_dfx_context (dfx); } - else if ( control == IOBUFCTRL_DESC ) + else if ( control == IOBUFCTRL_DESC ) { *(char**)buf = "mdc_decode_filter"; } @@ -335,8 +344,8 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len) decode_filter_ctx_t fc = opaque; size_t n, size = *ret_len; int rc = 0; - - if ( control == IOBUFCTRL_UNDERFLOW ) + + if ( control == IOBUFCTRL_UNDERFLOW ) { assert(a); n = iobuf_read ( a, buf, size ); @@ -351,7 +360,7 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len) rc = -1; /* EOF */ *ret_len = n; } - else if ( control == IOBUFCTRL_FREE ) + else if ( control == IOBUFCTRL_FREE ) { release_dfx_context (fc); }