From 6d755a83b48c889cb648bd593a55d3790c4f1d1a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 23 Jul 2009 08:00:39 +0000 Subject: [PATCH] Parse EXTCAP lines from the card. Change messages for a corrupt trustdb. --- g10/ChangeLog | 12 ++++++++++++ g10/cardglue.c | 33 ++++++++++++++++++++++++++++++--- g10/cardglue.h | 4 ++++ g10/gpg.c | 6 ++---- g10/tdbio.c | 6 +++--- g10/trustdb.c | 21 +++++++++++++++++++++ g10/trustdb.h | 1 + 7 files changed, 73 insertions(+), 10 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index b5ed29a6e..dec5a9187 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,15 @@ +2009-07-23 Werner Koch + + * trustdb.c (how_to_fix_the_trustdb): New. + * tdbio.c (tdbio_invalid): Print hints on how to fix the trustdb. + * gpg.c (main) : Print hints. + +2009-07-22 Werner Koch + + * cardglue.h (struct agent_card_info_s): Add field EXTCAP. + * cardglue.c (agent_learn): Read KEY-ATTR. + (learn_status_cb): Parse EXTCAP. + 2009-07-21 Werner Koch * app-common.h, app-openpgp.c, iso7816.c, iso7816.h, apdu.c, diff --git a/g10/cardglue.c b/g10/cardglue.c index 0833d6050..43f46dcd1 100644 --- a/g10/cardglue.c +++ b/g10/cardglue.c @@ -1,5 +1,5 @@ /* cardglue.c - mainly dispatcher for card related functions. - * Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -382,7 +382,7 @@ open_card_via_agent (int *scd_available) if (!ctx) return NULL; - /* Request the serialbnumber of the card. If we get + /* Request the serialnumber of the card. If we get NOT_SUPPORTED or NO_SCDAEMON back, the gpg-agent either has disabled scdaemon or it can't be used. We close the connection in this case and use our own code. This may happen if just the @@ -438,7 +438,7 @@ open_card (void) if (app) goto ready; /* Yes, there is a agent with a usable card, go that way. */ if (scd_available) - return NULL; /* agent avilabale but card problem. */ + return NULL; /* Agent available but card problem. */ } @@ -770,6 +770,30 @@ learn_status_cb (void *opaque, const char *line) xfree (buf); } } + else if (keywordlen == 6 && !memcmp (keyword, "EXTCAP", keywordlen)) + { + char *p, *p2, *buf; + int abool; + + buf = p = unescape_status_string (line); + if (buf) + { + for (p = strtok (buf, " "); p; p = strtok (NULL, " ")) + { + p2 = strchr (p, '='); + if (p2) + { + *p2++ = 0; + abool = (*p2 == '1'); + if (!strcmp (p, "ki")) + parm->extcap.ki = abool; + else if (!strcmp (p, "aac")) + parm->extcap.aac = abool; + } + } + xfree (buf); + } + } else if (keywordlen == 7 && !memcmp (keyword, "KEY-FPR", keywordlen)) { int no = atoi (line); @@ -876,6 +900,9 @@ agent_learn (struct agent_card_info_s *info) } } + if (!rc) + agent_scd_getattr ("KEY-ATTR", info); + return rc; } diff --git a/g10/cardglue.h b/g10/cardglue.h index f1b51c88b..dc114aa69 100644 --- a/g10/cardglue.h +++ b/g10/cardglue.h @@ -69,6 +69,10 @@ struct agent_card_info_s { int algo; /* Algorithm identifier. */ unsigned int nbits; /* Supported keysize. */ } key_attr[3]; + struct { + unsigned int ki:1; /* Key import available. */ + unsigned int aac:1; /* Algorithm attributes are changeable. */ + } extcap; }; struct agent_card_genkey_s { diff --git a/g10/gpg.c b/g10/gpg.c index 0d9122ff2..5e6283ac4 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -3343,8 +3343,8 @@ main (int argc, char **argv ) case aGenRandom: case aDeArmor: case aEnArmor: - case aFixTrustDB: break; + case aFixTrustDB: case aExportOwnerTrust: rc = setup_trustdb( 0, trustdb_name ); break; case aListTrustDB: rc = setup_trustdb( argc? 1:0, trustdb_name ); break; default: rc = setup_trustdb(1, trustdb_name ); break; @@ -3874,9 +3874,7 @@ main (int argc, char **argv ) break; case aFixTrustDB: - log_error("this command is not yet implemented.\n"); - log_error("A workaround is to use \"--export-ownertrust\", remove\n"); - log_error("the trustdb file and do an \"--import-ownertrust\".\n" ); + how_to_fix_the_trustdb (); break; case aListTrustPath: diff --git a/g10/tdbio.c b/g10/tdbio.c index cdfc27a6b..606194f53 100644 --- a/g10/tdbio.c +++ b/g10/tdbio.c @@ -1499,9 +1499,9 @@ tdbio_search_trust_bypk (PKT_public_key *pk, TRUSTREC *rec) void tdbio_invalid(void) { - log_error(_( - "the trustdb is corrupted; please run \"gpg --fix-trustdb\".\n") ); - g10_exit(2); + log_error (_("Error: The trustdb is corrupted.\n")); + how_to_fix_the_trustdb (); + g10_exit (2); } /* diff --git a/g10/trustdb.c b/g10/trustdb.c index 57684590a..d435ce676 100644 --- a/g10/trustdb.c +++ b/g10/trustdb.c @@ -411,6 +411,27 @@ setup_trustdb( int level, const char *dbname ) return 0; } +void +how_to_fix_the_trustdb () +{ + const char *name = trustdb_args.dbname; + + if (!name) + name = "trustdb.gpg"; + + log_info (_("You may try to re-create the trustdb using the commands:\n")); + log_info (" cd %s\n", default_homedir ()); + log_info (" gpg2 --export-ownertrust > otrust.tmp\n"); +#ifdef HAVE_W32_SYSTEM + log_info (" del %s\n", name); +#else + log_info (" rm %s\n", name); +#endif + log_info (" gpg2 --import-ownertrust < otrust.tmp\n"); + log_info (_("If that does not work, please consult the manual\n")); +} + + void init_trustdb() { diff --git a/g10/trustdb.h b/g10/trustdb.h index 8c6721532..9eca2c0c5 100644 --- a/g10/trustdb.h +++ b/g10/trustdb.h @@ -45,6 +45,7 @@ void register_trusted_key( const char *string ); void check_trustdb (void); void update_trustdb (void); int setup_trustdb( int level, const char *dbname ); +void how_to_fix_the_trustdb (void); void init_trustdb( void ); void check_trustdb_stale(void); void sync_trustdb( void );