diff --git a/NEWS b/NEWS index 1a342b18..7b6fdd9c 100644 --- a/NEWS +++ b/NEWS @@ -3,9 +3,10 @@ Noteworthy changes in version 1.10.1 (unreleased) * Interface changes relative to the 1.10.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + gpgme_import_result_t EXTENDED: New field 'skipped_v3_keys' cpp: Key::locate NEW. cpp: Data::toString NEW. - + cpp: ImportResult::numV3KeysSkipped NEW. Noteworthy changes in version 1.10.0 (2017-12-12) ------------------------------------------------- diff --git a/doc/gpgme.texi b/doc/gpgme.texi index cd7bb4ba..37cf16ac 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -4811,6 +4811,12 @@ The number of keys not imported. @item gpgme_import_status_t imports A list of gpgme_import_status_t objects which contain more information about the keys for which an import was attempted. + +@item int skipped_v3_keys +For security reasons modern versions of GnuPG do not anymore support +v3 keys (created with PGP 2.x) and ignores them on import. This +counter provides the number of such skipped v3 keys. + @end table @end deftp diff --git a/lang/cpp/src/importresult.cpp b/lang/cpp/src/importresult.cpp index 8c35f9cc..dbb31d05 100644 --- a/lang/cpp/src/importresult.cpp +++ b/lang/cpp/src/importresult.cpp @@ -154,6 +154,11 @@ int GpgME::ImportResult::notImported() const return d ? d->res.not_imported : 0 ; } +int GpgME::ImportResult::numV3KeysSkipped() const +{ + return d ? d->res.skipped_v3_keys : 0 ; +} + GpgME::Import GpgME::ImportResult::import(unsigned int idx) const { return Import(d, idx); diff --git a/lang/cpp/src/importresult.h b/lang/cpp/src/importresult.h index 2f0e7f20..05476796 100644 --- a/lang/cpp/src/importresult.h +++ b/lang/cpp/src/importresult.h @@ -78,6 +78,7 @@ public: int numSecretKeysUnchanged() const; int notImported() const; + int numV3KeysSkipped() const; Import import(unsigned int idx) const; std::vector imports() const; diff --git a/src/gpgme.h.in b/src/gpgme.h.in index ff80023e..e3198798 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -1639,6 +1639,9 @@ struct _gpgme_op_import_result /* List of keys for which an import was attempted. */ gpgme_import_status_t imports; + + /* Number of v3 keys skipped. */ + int skipped_v3_keys; }; typedef struct _gpgme_op_import_result *gpgme_import_result_t; diff --git a/src/import.c b/src/import.c index 386ca722..f0d9d9fa 100644 --- a/src/import.c +++ b/src/import.c @@ -94,8 +94,9 @@ gpgme_op_import_result (gpgme_ctx_t ctx) TRACE_LOG3 ("%i secret keys, %i imported, %i unchanged", opd->result.secret_read, opd->result.secret_imported, opd->result.secret_unchanged); - TRACE_LOG2 ("%i skipped new keys, %i not imported", - opd->result.skipped_new_keys, opd->result.not_imported); + TRACE_LOG3 ("%i skipped new keys, %i not imported, %i v3 skipped", + opd->result.skipped_new_keys, opd->result.not_imported, + opd->result.skipped_v3_keys); impstat = opd->result.imports; i = 0; @@ -212,6 +213,10 @@ parse_import_res (char *args, gpgme_import_result_t result) PARSE_NEXT (result->secret_unchanged); PARSE_NEXT (result->skipped_new_keys); PARSE_NEXT (result->not_imported); + if (args && *args) + { + PARSE_NEXT (result->skipped_v3_keys); + } return 0; } diff --git a/src/keylist.c b/src/keylist.c index 24a9b0b3..7956935b 100644 --- a/src/keylist.c +++ b/src/keylist.c @@ -1261,7 +1261,7 @@ gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, gpgme_key_t *r_key, { gpgme_ctx_t listctx; gpgme_error_t err; - gpgme_key_t key; + gpgme_key_t result, key; TRACE_BEG2 (DEBUG_CTX, "gpgme_get_key", ctx, "fpr=%s, secret=%i", fpr, secret); @@ -1295,7 +1295,7 @@ gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, gpgme_key_t *r_key, err = gpgme_op_keylist_start (listctx, fpr, secret); if (!err) - err = gpgme_op_keylist_next (listctx, r_key); + err = gpgme_op_keylist_next (listctx, &result); if (!err) { try_next_key: @@ -1305,9 +1305,9 @@ gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, gpgme_key_t *r_key, else { if (!err - && *r_key && (*r_key)->subkeys && (*r_key)->subkeys->fpr + && result && result->subkeys && result->subkeys->fpr && key && key->subkeys && key->subkeys->fpr - && !strcmp ((*r_key)->subkeys->fpr, key->subkeys->fpr)) + && !strcmp (result->subkeys->fpr, key->subkeys->fpr)) { /* The fingerprint is identical. We assume that this is the same key and don't mark it as an ambiguous. This @@ -1323,12 +1323,14 @@ gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, gpgme_key_t *r_key, gpgme_key_unref (key); err = gpg_error (GPG_ERR_AMBIGUOUS_NAME); } - gpgme_key_unref (*r_key); + gpgme_key_unref (result); + result = NULL; } } gpgme_release (listctx); if (! err) { + *r_key = result; TRACE_LOG2 ("key=%p (%s)", *r_key, ((*r_key)->subkeys && (*r_key)->subkeys->fpr) ? (*r_key)->subkeys->fpr : "invalid"); diff --git a/tests/gpg/t-support.h b/tests/gpg/t-support.h index f6dec682..ef5766a3 100644 --- a/tests/gpg/t-support.h +++ b/tests/gpg/t-support.h @@ -196,7 +196,8 @@ print_import_result (gpgme_import_result_t r) " secret imported: %d\n" " secret unchanged: %d\n" " skipped new keys: %d\n" - " not imported: %d\n", + " not imported: %d\n" + " skipped v3 keys: %d\n", r->considered, r->no_user_id, r->imported, @@ -210,6 +211,7 @@ print_import_result (gpgme_import_result_t r) r->secret_imported, r->secret_unchanged, r->skipped_new_keys, - r->not_imported); + r->not_imported, + r->skipped_v3_keys); } diff --git a/tests/run-support.h b/tests/run-support.h index 6a2170b0..6c713a9a 100644 --- a/tests/run-support.h +++ b/tests/run-support.h @@ -177,7 +177,8 @@ print_import_result (gpgme_import_result_t r) " secret imported: %d\n" " secret unchanged: %d\n" " skipped new keys: %d\n" - " not imported: %d\n", + " not imported: %d\n" + " skipped v3 keys: %d\n", r->considered, r->no_user_id, r->imported, @@ -191,6 +192,7 @@ print_import_result (gpgme_import_result_t r) r->secret_imported, r->secret_unchanged, r->skipped_new_keys, - r->not_imported); + r->not_imported, + r->skipped_v3_keys); }