From aa20d6a45a1adb03c0529ce8a2ad80d0f4dd1e4f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 28 Mar 2002 17:43:02 +0000 Subject: [PATCH] * gpgme.h (GpgmeAttr): Add values for issuer and chaining. * key.h (gpgme_key_s): Add issuer and chaining elements for X509. * keylist.c (keylist_colon_handler): Store them. * key.c (gpgme_key_release): Free them. (gpgme_key_get_as_xml,gpgme_key_get_string_attr): Print them. --- NEWS | 2 + gpgme/ChangeLog | 8 +++ gpgme/gpgme.h | 5 +- gpgme/key.c | 129 +++++++++++++++++++++++++++--------------------- gpgme/key.h | 3 ++ gpgme/keylist.c | 22 ++++++++- 6 files changed, 110 insertions(+), 59 deletions(-) diff --git a/NEWS b/NEWS index 2f919448..ff2e623c 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ case, symmetric encryption is performed. Note that this requires a passphrase from the user. + * More information is returned for X.509 certificates. + * Interface changes relative to the 0.3.4 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gpgme_op_encrypt EXTENDED: Symmetric encryption possible diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index cf713cdf..e77e3a0a 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,11 @@ +2002-03-28 Werner Koch + + * gpgme.h (GpgmeAttr): Add values for issuer and chaining. + * key.h (gpgme_key_s): Add issuer and chaining elements for X509. + * keylist.c (keylist_colon_handler): Store them. + * key.c (gpgme_key_release): Free them. + (gpgme_key_get_as_xml,gpgme_key_get_string_attr): Print them. + 2002-03-26 Werner Koch * Makefile.am (libgpgme_la_SOURCES): Add mutex.h diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index f45c41f3..5200e935 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -161,7 +161,10 @@ typedef enum GPGME_ATTR_CAN_SIGN = 22, GPGME_ATTR_CAN_CERTIFY = 23, GPGME_ATTR_KEY_EXPIRED = 24, - GPGME_ATTR_KEY_DISABLED = 25 + GPGME_ATTR_KEY_DISABLED = 25, + GPGME_ATTR_SERIAL = 26, + GPGME_ATTR_ISSUER = 27, + GPGME_ATTR_CHAINID = 28 } GpgmeAttr; diff --git a/gpgme/key.c b/gpgme/key.c index 25d6a5db..0443668a 100644 --- a/gpgme/key.c +++ b/gpgme/key.c @@ -352,6 +352,9 @@ gpgme_key_release ( GpgmeKey key ) u2 = u->next; xfree (u); } + xfree (key->issuer_serial); + xfree (key->issuer_name); + xfree (key->chain_id); xfree (key); } @@ -655,66 +658,73 @@ one_uid_as_xml (GpgmeData d, struct user_id_s *u) char * gpgme_key_get_as_xml ( GpgmeKey key ) { - GpgmeData d; - struct user_id_s *u; - struct subkey_s *k; - - if ( !key ) - return NULL; - - if ( gpgme_data_new ( &d ) ) - return NULL; - - _gpgme_data_append_string ( d, "\n" - " \n" ); - if ( key->keys.secret ) + GpgmeData d; + struct user_id_s *u; + struct subkey_s *k; + + if ( !key ) + return NULL; + + if ( gpgme_data_new ( &d ) ) + return NULL; + + _gpgme_data_append_string ( d, "\n" + " \n" ); + if ( key->keys.secret ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.invalid ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.revoked ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.expired ) + _gpgme_data_append_string ( d, " \n"); + if ( key->keys.flags.disabled ) + _gpgme_data_append_string ( d, " \n"); + add_tag_and_string (d, "keyid", key->keys.keyid ); + if (key->keys.fingerprint) + add_tag_and_string (d, "fpr", key->keys.fingerprint ); + add_tag_and_uint (d, "algo", key->keys.key_algo ); + add_tag_and_uint (d, "len", key->keys.key_len ); + add_tag_and_time (d, "created", key->keys.timestamp ); + add_tag_and_time (d, "expire", key->keys.expires_at ); + if (key->issuer_serial) + add_tag_and_string (d, "serial", key->issuer_serial); + if (key->issuer_name) + add_tag_and_string (d, "issuer", key->issuer_name); + if (key->chain_id) + add_tag_and_string (d, "chainid", key->chain_id); + _gpgme_data_append_string (d, " \n"); + + /* Now the user IDs. */ + for (u = key->uids; u; u = u->next) + one_uid_as_xml (d,u); + + /* and now the subkeys */ + for (k=key->keys.next; k; k = k->next ) + { + _gpgme_data_append_string (d, " \n"); + if ( k->secret ) _gpgme_data_append_string ( d, " \n"); - if ( key->keys.flags.invalid ) + if ( k->flags.invalid ) _gpgme_data_append_string ( d, " \n"); - if ( key->keys.flags.revoked ) + if ( k->flags.revoked ) _gpgme_data_append_string ( d, " \n"); - if ( key->keys.flags.expired ) + if ( k->flags.expired ) _gpgme_data_append_string ( d, " \n"); - if ( key->keys.flags.disabled ) + if ( k->flags.disabled ) _gpgme_data_append_string ( d, " \n"); - add_tag_and_string (d, "keyid", key->keys.keyid ); - if (key->keys.fingerprint) - add_tag_and_string (d, "fpr", key->keys.fingerprint ); - add_tag_and_uint (d, "algo", key->keys.key_algo ); - add_tag_and_uint (d, "len", key->keys.key_len ); - add_tag_and_time (d, "created", key->keys.timestamp ); - add_tag_and_time (d, "expire", key->keys.expires_at ); - _gpgme_data_append_string (d, " \n"); - - /* Now the user IDs. */ - for (u = key->uids; u; u = u->next) - one_uid_as_xml (d,u); - - /* and now the subkeys */ - for (k=key->keys.next; k; k = k->next ) { - _gpgme_data_append_string (d, " \n"); - if ( k->secret ) - _gpgme_data_append_string ( d, " \n"); - if ( k->flags.invalid ) - _gpgme_data_append_string ( d, " \n"); - if ( k->flags.revoked ) - _gpgme_data_append_string ( d, " \n"); - if ( k->flags.expired ) - _gpgme_data_append_string ( d, " \n"); - if ( k->flags.disabled ) - _gpgme_data_append_string ( d, " \n"); - add_tag_and_string (d, "keyid", k->keyid ); - if (k->fingerprint) - add_tag_and_string (d, "fpr", k->fingerprint ); - add_tag_and_uint (d, "algo", k->key_algo ); - add_tag_and_uint (d, "len", k->key_len ); - add_tag_and_time (d, "created", k->timestamp ); - add_tag_and_time (d, "expire", k->expires_at ); - _gpgme_data_append_string (d, " \n"); + add_tag_and_string (d, "keyid", k->keyid ); + if (k->fingerprint) + add_tag_and_string (d, "fpr", k->fingerprint ); + add_tag_and_uint (d, "algo", k->key_algo ); + add_tag_and_uint (d, "len", k->key_len ); + add_tag_and_time (d, "created", k->timestamp ); + add_tag_and_time (d, "expire", k->expires_at ); + _gpgme_data_append_string (d, " \n"); } - _gpgme_data_append_string ( d, "\n" ); - - return _gpgme_data_release_and_return_string (d); + _gpgme_data_append_string ( d, "\n" ); + + return _gpgme_data_release_and_return_string (d); } @@ -850,6 +860,15 @@ gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what, if (k) val = capabilities_to_string (k); break; + case GPGME_ATTR_SERIAL: + val = key->issuer_serial; + break; + case GPGME_ATTR_ISSUER: + val = key->issuer_name; + break; + case GPGME_ATTR_CHAINID: + val = key->chain_id; + break; } return val; } @@ -970,5 +989,3 @@ gpgme_key_get_ulong_attr ( GpgmeKey key, GpgmeAttr what, } return val; } - - diff --git a/gpgme/key.h b/gpgme/key.h index 9503d551..bc00f5ff 100644 --- a/gpgme/key.h +++ b/gpgme/key.h @@ -59,6 +59,9 @@ struct gpgme_key_s { unsigned int ref_count; unsigned int secret:1; unsigned int x509:1; + char *issuer_serial; /* malloced string used only with X.509 */ + char *issuer_name; /* ditto */ + char *chain_id; /* ditto */ struct subkey_s keys; struct user_id_s *uids; }; diff --git a/gpgme/keylist.c b/gpgme/keylist.c index 1bcda34e..57a89809 100644 --- a/gpgme/keylist.c +++ b/gpgme/keylist.c @@ -304,13 +304,23 @@ keylist_colon_handler (GpgmeCtx ctx, char *line) key->keys.expires_at = parse_timestamp (p); break; case 8: /* X.509 serial number */ - /* fixme: store it */ + if (rectype == RT_CRT) + { + key->issuer_serial = xtrystrdup (p); + if (!key->issuer_serial) + ctx->error = mk_error (Out_Of_Core); + } break; case 9: /* ownertrust */ break; case 10: /* not used for gpg due to --fixed-list-mode option but gpgsm stores the issuer name */ - /* fixme: store issuer name */ + if (rectype == RT_CRT) + { + key->issuer_name = xtrystrdup (p); + if (!key->issuer_name) + ctx->error = mk_error (Out_Of_Core); + } break; case 11: /* signature class */ break; @@ -394,6 +404,14 @@ keylist_colon_handler (GpgmeCtx ctx, char *line) if (!key->keys.fingerprint) ctx->error = mk_error (Out_Of_Core); } + break; + case 13: /* gpgsm chain ID (take only the first one)*/ + if (!key->chain_id && *p) + { + key->chain_id = xtrystrdup (p); + if (!key->chain_id) + ctx->error = mk_error (Out_Of_Core); + } pend = NULL; /* that is all we want */ break; }