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:
parent
56e26b54da
commit
6f3dc66634
1
NEWS
1
NEWS
@ -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.
|
||||
|
@ -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");
|
||||
|
||||
/* 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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user