core: Extend gpgme_subkey_t to carry the keygrip.

* src/gpgme.h.in (struct _gpgme_subkey): Add file 'keygrip'.
* src/key.c (gpgme_key_unref): Free KEYGRIP.
* src/keylist.c (keylist_colon_handler): Parse GRP records.
* src/engine-gpg.c (gpg_keylist_build_options): Do not use
--with-fingerprint options for gpg versions >= 2.1.15.

* tests/run-keylist.c (main): Print subkeys and keygrips.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-08-04 16:17:01 +02:00
parent 56e26b54da
commit 6f3dc66634
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
6 changed files with 76 additions and 10 deletions

1
NEWS
View File

@ -11,6 +11,7 @@ Noteworthy changes in version 1.7.0 (unreleased) [C25/A14/R_]
GPGME_PK_EDDSA NEW.
gpgme_set_ctx_flag NEW.
gpgme_signature_t EXTENDED: New field tofu.
gpgme_subkey_t EXTENDED: New field keygrip.
gpgme_tofu_policy_t NEW.
gpgme_tofu_info_t NEW.
GPGME_STATUS_KEY_CONSIDERED NEW.

View File

@ -2283,12 +2283,19 @@ gpg_keylist_build_options (engine_gpg_t gpg, int secret_only,
gpg_error_t err;
err = add_arg (gpg, "--with-colons");
if (!err)
err = add_arg (gpg, "--fixed-list-mode");
if (!err)
err = add_arg (gpg, "--with-fingerprint");
if (!err)
err = add_arg (gpg, "--with-fingerprint");
/* Since gpg 2.1.15 fingerprints are always printed, thus there is
* no more need to explictly reqeust them. */
if (!have_gpg_version (gpg, "2.1.15"))
{
if (!err)
err = add_arg (gpg, "--fixed-list-mode");
if (!err)
err = add_arg (gpg, "--with-fingerprint");
if (!err)
err = add_arg (gpg, "--with-fingerprint");
}
if (!err && (mode & GPGME_KEYLIST_MODE_WITH_SECRET))
err = add_arg (gpg, "--with-secret");
if (!err

View File

@ -691,6 +691,9 @@ struct _gpgme_subkey
/* The name of the curve for ECC algorithms or NULL. */
char *curve;
/* The keygrip of the subkey in hex digit form or NULL if not availabale. */
char *keygrip;
};
typedef struct _gpgme_subkey *gpgme_subkey_t;

View File

@ -333,6 +333,8 @@ gpgme_key_unref (gpgme_key_t key)
free (subkey->fpr);
if (subkey->curve)
free (subkey->curve);
if (subkey->keygrip)
free (subkey->keygrip);
if (subkey->card_number)
free (subkey->card_number);
free (subkey);

View File

@ -426,7 +426,7 @@ keylist_colon_handler (void *priv, char *line)
gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
enum
{
RT_NONE, RT_SIG, RT_UID, RT_SUB, RT_PUB, RT_FPR,
RT_NONE, RT_SIG, RT_UID, RT_SUB, RT_PUB, RT_FPR, RT_GRP,
RT_SSB, RT_SEC, RT_CRT, RT_CRS, RT_REV, RT_SPK
}
rectype = RT_NONE;
@ -479,6 +479,8 @@ keylist_colon_handler (void *priv, char *line)
rectype = RT_CRS;
else if (!strcmp (field[0], "fpr") && key)
rectype = RT_FPR;
else if (!strcmp (field[0], "grp") && key)
rectype = RT_GRP;
else if (!strcmp (field[0], "uid") && key)
rectype = RT_UID;
else if (!strcmp (field[0], "sub") && key)
@ -717,6 +719,22 @@ keylist_colon_handler (void *priv, char *line)
}
break;
case RT_GRP:
/* Field 10 has the keygrip. */
if (fields >= 10 && field[9] && *field[9])
{
/* Need to apply it to the last subkey because all subkeys
have a keygrip. */
subkey = key->_last_subkey;
if (!subkey->keygrip)
{
subkey->keygrip = strdup (field[9]);
if (!subkey->keygrip)
return gpg_error_from_syserror ();
}
}
break;
case RT_SIG:
case RT_REV:
if (!opd->tmp_uid)

View File

@ -67,6 +67,7 @@ main (int argc, char **argv)
gpgme_ctx_t ctx;
gpgme_keylist_mode_t mode = 0;
gpgme_key_t key;
gpgme_subkey_t subkey;
gpgme_keylist_result_t result;
int import = 0;
gpgme_key_t keyarray[100];
@ -173,22 +174,54 @@ main (int argc, char **argv)
{
gpgme_user_id_t uid;
int nuids;
int nsub;
printf ("keyid : %s\n", key->subkeys?nonnull (key->subkeys->keyid):"?");
printf ("fpr : %s\n", key->subkeys?nonnull (key->subkeys->fpr):"?");
if (key->subkeys && key->subkeys->keygrip)
printf ("grip : %s\n", key->subkeys->keygrip);
if (key->subkeys && key->subkeys->curve)
printf ("curve : %s\n", key->subkeys->curve);
printf ("caps : %s%s%s%s\n",
key->can_encrypt? "e":"",
key->can_sign? "s":"",
key->can_certify? "c":"",
key->can_authenticate? "a":"");
printf ("flags :%s%s%s%s%s%s\n",
printf ("flags :%s%s%s%s%s%s%s\n",
key->secret? " secret":"",
key->revoked? " revoked":"",
key->expired? " expired":"",
key->disabled? " disabled":"",
key->invalid? " invalid":"",
key->is_qualified? " qualifid":"");
key->is_qualified? " qualifid":"",
key->subkeys && key->subkeys->is_cardkey? " cardkey":"");
subkey = key->subkeys;
if (subkey)
subkey = subkey->next;
for (nsub=1; subkey; subkey = subkey->next, nsub++)
{
printf ("fpr %2d: %s\n", nsub, nonnull (subkey->fpr));
if (subkey->keygrip)
printf ("grip %2d: %s\n", nsub, subkey->keygrip);
if (subkey->curve)
printf ("curve %2d: %s\n", nsub, subkey->curve);
printf ("caps %2d: %s%s%s%s\n",
nsub,
subkey->can_encrypt? "e":"",
subkey->can_sign? "s":"",
subkey->can_certify? "c":"",
subkey->can_authenticate? "a":"");
printf ("flags %2d:%s%s%s%s%s%s%s\n",
nsub,
subkey->secret? " secret":"",
subkey->revoked? " revoked":"",
subkey->expired? " expired":"",
subkey->disabled? " disabled":"",
subkey->invalid? " invalid":"",
subkey->is_qualified? " qualifid":"",
subkey->is_cardkey? " cardkey":"");
}
for (nuids=0, uid=key->uids; uid; uid = uid->next, nuids++)
{
printf ("userid %d: %s\n", nuids, nonnull(uid->uid));
@ -201,6 +234,8 @@ main (int argc, char **argv)
uid->validity == GPGME_VALIDITY_ULTIMATE? "ultimate": "[?]");
}
putchar ('\n');
if (import)