From 0b11af59c7ce6664bcbdc43f65e3d33fe1a6142b Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 13 Dec 2001 15:05:35 +0000 Subject: [PATCH] * engine-gpgsm.c (_gpgme_gpgsm_op_keylist): Allow NULL for pattern. (gpgsm_assuan_simple_command): Removed underscore from assuan_write_line. (_gpgme_gpgsm_start): Ditto. * keylist.c (keylist_colon_handler): Handle "crt" records * key.h (gpgme_key_s): Add an x509 flag. * key.c (parse_x509_user_id): New. (_gpgme_key_append_name): Handle x.509 names. However, it does not yet work. --- gpgme/ChangeLog | 13 +++++++++++++ gpgme/engine-gpgsm.c | 12 ++++++++---- gpgme/key.c | 24 +++++++++++++++++++++++- gpgme/key.h | 1 + gpgme/keylist.c | 26 +++++++++++++++++++++----- 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 2f6b2f28..d500acae 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,16 @@ +2001-12-13 Werner Koch + + * engine-gpgsm.c (_gpgme_gpgsm_op_keylist): Allow NULL for + pattern. + (gpgsm_assuan_simple_command): Removed underscore from + assuan_write_line. + (_gpgme_gpgsm_start): Ditto. + + * keylist.c (keylist_colon_handler): Handle "crt" records + * key.h (gpgme_key_s): Add an x509 flag. + * key.c (parse_x509_user_id): New. + (_gpgme_key_append_name): Handle x.509 names. + 2001-12-05 Marcus Brinkmann * engine-gpgsm.c (gpgsm_status_handler): Make it work with current diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index 04f32a08..ea3cd0d6 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -86,7 +86,8 @@ struct gpgsm_object_s const char * _gpgme_gpgsm_get_version (void) { - static const char *gpgsm_version; +#warning version check is disabled + static const char *gpgsm_version = "0.0.1"; /* FIXME: Locking. */ if (!gpgsm_version) @@ -98,7 +99,7 @@ _gpgme_gpgsm_get_version (void) GpgmeError _gpgme_gpgsm_check_version (void) { - return _gpgme_compare_versions (_gpgme_gpgsm_get_version (), + return _gpgme_compare_versions (_gpgme_gpgsm_get_version (), NEED_GPGSM_VERSION) ? 0 : mk_error (Invalid_Engine); } @@ -195,7 +196,7 @@ gpgsm_assuan_simple_command (ASSUAN_CONTEXT ctx, char *line) { AssuanError err; - err = _assuan_write_line (ctx, line); + err = assuan_write_line (ctx, line); if (err) return err; @@ -378,6 +379,9 @@ _gpgme_gpgsm_op_keylist (GpgsmObject gpgsm, const char *pattern, { char *line; + if (!pattern) + pattern = ""; + line = xtrymalloc (9 + strlen (pattern) + 1); /* "LISTKEYS " + p + '\0'. */ if (!line) return mk_error (Out_Of_Core); @@ -575,7 +579,7 @@ _gpgme_gpgsm_start (GpgsmObject gpgsm, void *opaque) } if (!err) - err = _assuan_write_line (gpgsm->assuan_ctx, gpgsm->command); + err = assuan_write_line (gpgsm->assuan_ctx, gpgsm->command); return err; } diff --git a/gpgme/key.c b/gpgme/key.c index 51bd66be..9e43bef4 100644 --- a/gpgme/key.c +++ b/gpgme/key.c @@ -459,6 +459,25 @@ parse_user_id ( struct user_id_s *uid, char *tail ) } +static void +parse_x509_user_id ( struct user_id_s *uid, char *tail ) +{ + const char *s; + + s=uid->name; + if (*s == '<' && s[strlen(s)-1] == '>') + uid->email_part = s; + + /* let unused parts point to an EOS */ + tail--; + if (!uid->name_part) + uid->name_part = tail; + if (!uid->email_part) + uid->email_part = tail; + if (!uid->comment_part) + uid->comment_part = tail; +} + /* * Take a name from the --with-colon listing, remove certain escape sequences * sequences and put it into the list of UIDs @@ -531,7 +550,10 @@ _gpgme_key_append_name ( GpgmeKey key, const char *s ) } } *d++ = 0; - parse_user_id ( uid, d ); + if (key->x509) + parse_x509_user_id (uid, d); + else + parse_user_id (uid, d); uid->next = key->uids; key->uids = uid; diff --git a/gpgme/key.h b/gpgme/key.h index 003821a5..597dd0c7 100644 --- a/gpgme/key.h +++ b/gpgme/key.h @@ -57,6 +57,7 @@ struct gpgme_key_s { } gloflags; unsigned int ref_count; unsigned int secret:1; + unsigned int x509:1; struct subkey_s keys; struct user_id_s *uids; }; diff --git a/gpgme/keylist.c b/gpgme/keylist.c index 323d6360..ca0cae09 100644 --- a/gpgme/keylist.c +++ b/gpgme/keylist.c @@ -146,7 +146,7 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) char *p, *pend; int field = 0; enum { - RT_NONE, RT_SIG, RT_UID, RT_SUB, RT_PUB, RT_FPR, RT_SSB, RT_SEC + RT_NONE, RT_SIG, RT_UID, RT_SUB, RT_PUB, RT_FPR, RT_SSB, RT_SEC, RT_CRT } rectype = RT_NONE; GpgmeKey key = ctx->tmp_key; int i; @@ -211,13 +211,26 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) assert ( !ctx->tmp_key ); ctx->tmp_key = key; } + else if ( !strcmp (p, "crt") ) { + /* start a new certificate */ + if ( _gpgme_key_new ( &key ) ) { + ctx->out_of_core=1; /* the only kind of error we can get*/ + return; + } + key->x509 = 1; + rectype = RT_CRT; + finish_key ( ctx ); + assert ( !ctx->tmp_key ); + ctx->tmp_key = key; + } else if ( !strcmp ( p, "fpr" ) && key ) rectype = RT_FPR; else rectype = RT_NONE; } - else if ( rectype == RT_PUB || rectype == RT_SEC ) { + else if ( rectype == RT_PUB || rectype == RT_SEC || rectype == RT_CRT) + { switch (field) { case 2: /* trust info */ trust_info = p; @@ -242,11 +255,14 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) break; case 7: /* valid for n days */ break; - case 8: /* reserved (LID) */ + case 8: /* X.509 serial number */ + /* fixme: store it */ break; case 9: /* ownertrust */ break; - case 10: /* not used due to --fixed-list-mode option */ + case 10: /* not used for gpg due to --fixed-list-mode option + but gpgsm stores the issuer name */ + /* fixme: store issuer name */ break; case 11: /* signature class */ break; @@ -257,7 +273,7 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) pend = NULL; /* we can stop here */ break; } - } + } else if ( (rectype == RT_SUB || rectype== RT_SSB) && sk ) { switch (field) { case 2: /* trust info */