diff --git a/g10/ChangeLog b/g10/ChangeLog index 1ff227fdc..b4db7b5f0 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,23 @@ +2003-06-23 Werner Koch + + * keyid.c (do_fingerprint_md): Made it work again. + +2003-06-19 Werner Koch + + Fixed all "==" comparisons against error code constants to use + gpg_err_code(). + + * import.c (import_secret_one): + (import_revoke_cert): + (chk_self_sigs): + + * misc.c (openpgp_md_map_name): Check also for the Hx format. + (openpgp_cipher_map_name): Check also for the Sx format. + (pubkey_get_npkey): Adjusted for changed gcrypt API. + (pubkey_get_nskey): Ditto. + (pubkey_get_nsig): Ditto. + (pubkey_get_nenc): Ditto. + 2003-06-18 Werner Koch Finished the bulk of changes for gnupg 1.9. This included diff --git a/g10/import.c b/g10/import.c index 94e8914ec..84d60a1b3 100644 --- a/g10/import.c +++ b/g10/import.c @@ -906,7 +906,8 @@ import_secret_one( const char *fname, KBNODE keyblock, /* do we have this key already in one of our secrings ? */ rc = seckey_available( keyid ); - if( rc == GPG_ERR_NO_SECKEY && !opt.merge_only ) { /* simply insert this key */ + if( gpg_err_code (rc) == GPG_ERR_NO_SECKEY && !opt.merge_only ) { + /* simply insert this key */ KEYDB_HANDLE hd = keydb_new (1); /* get default resource */ @@ -977,7 +978,7 @@ import_revoke_cert( const char *fname, KBNODE node, struct stats_s *stats ) pk = xcalloc (1, sizeof *pk ); rc = get_pubkey( pk, keyid ); - if( rc == GPG_ERR_NO_PUBKEY ) { + if( gpg_err_code (rc) == GPG_ERR_NO_PUBKEY ) { log_info( _("key %08lX: no public key - " "can't apply revocation certificate\n"), (ulong)keyid[1]); rc = 0; @@ -1126,7 +1127,7 @@ chk_self_sigs( const char *fname, KBNODE keyblock, { char *p=utf8_to_native(unode->pkt->pkt.user_id->name, strlen(unode->pkt->pkt.user_id->name),0); - log_info( rc == GPG_ERR_PUBKEY_ALGO ? + log_info( gpg_err_code (rc) == GPG_ERR_PUBKEY_ALGO ? _("key %08lX: unsupported public key " "algorithm on user id \"%s\"\n"): _("key %08lX: invalid self-signature " @@ -1151,7 +1152,7 @@ chk_self_sigs( const char *fname, KBNODE keyblock, else { rc = check_key_signature( keyblock, n, NULL); if( rc ) { - log_info( rc == GPG_ERR_PUBKEY_ALGO ? + log_info( gpg_err_code (rc) == GPG_ERR_PUBKEY_ALGO ? _("key %08lX: unsupported public key algorithm\n"): _("key %08lX: invalid subkey binding\n"), (ulong)keyid[1]); @@ -1192,7 +1193,7 @@ chk_self_sigs( const char *fname, KBNODE keyblock, else { rc = check_key_signature( keyblock, n, NULL); if( rc ) { - log_info( rc == GPG_ERR_PUBKEY_ALGO ? + log_info( gpg_err_code (rc) == GPG_ERR_PUBKEY_ALGO ? _("key %08lX: unsupported public key algorithm\n"): _("key %08lX: invalid subkey revocation\n"), (ulong)keyid[1]); diff --git a/g10/keyid.c b/g10/keyid.c index 78b637481..49a316db5 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -54,15 +54,15 @@ static gcry_md_hd_t do_fingerprint_md( PKT_public_key *pk ) { gcry_md_hd_t md; - unsigned n; - unsigned nb[PUBKEY_MAX_NPKEY]; - unsigned nn[PUBKEY_MAX_NPKEY]; + unsigned int n; + unsigned int nn[PUBKEY_MAX_NPKEY]; byte *pp[PUBKEY_MAX_NPKEY]; int i; int npkey = pubkey_get_npkey( pk->pubkey_algo ); gcry_md_open (&md, pk->version < 4 ? DIGEST_ALGO_RMD160 : DIGEST_ALGO_SHA1, 0); + gcry_md_start_debug (md,"keyid"); n = pk->version < 4 ? 8 : 6; for(i=0; i < npkey; i++ ) { size_t nbytes; @@ -74,7 +74,7 @@ do_fingerprint_md( PKT_public_key *pk ) if (gcry_mpi_print ( GCRYMPI_FMT_PGP, pp[i], &nbytes, pk->pkey[i] )) BUG (); nn[i] = nbytes; - n += 2 + nn[i]; + n += nn[i]; } gcry_md_putc ( md, 0x99 ); /* ctb */ @@ -103,8 +103,6 @@ do_fingerprint_md( PKT_public_key *pk ) } gcry_md_putc ( md, pk->pubkey_algo ); for(i=0; i < npkey; i++ ) { - gcry_md_putc ( md, nb[i]>>8); - gcry_md_putc ( md, nb[i] ); gcry_md_write( md, pp[i], nn[i] ); xfree (pp[i]); } diff --git a/g10/keyring.c b/g10/keyring.c index cc1150065..4639e9462 100644 --- a/g10/keyring.c +++ b/g10/keyring.c @@ -125,7 +125,7 @@ new_offset_hash_table (void) { struct off_item **tbl; - tbl = xcalloc (1,2048 * sizeof *tbl); + tbl = xcalloc (2048, sizeof *tbl); return tbl; } @@ -387,7 +387,7 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb) save_mode = set_packet_list_mode(0); while ((rc=parse_packet (a, pkt)) != -1) { hd->found.n_packets++; - if (rc == GPG_ERR_UNKNOWN_PACKET) { + if (gpg_err_code (rc) == GPG_ERR_UNKNOWN_PACKET) { free_packet (pkt); init_packet (pkt); continue; @@ -478,7 +478,7 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb) /* Make sure that future search operations fail immediately when * we know that we are working on a invalid keyring */ - if (rc == GPG_ERR_INV_KEYRING) + if (gpg_err_code (rc) == GPG_ERR_INV_KEYRING) hd->current.error = rc; return rc; diff --git a/g10/mainproc.c b/g10/mainproc.c index e9b7a4b66..969c65066 100644 --- a/g10/mainproc.c +++ b/g10/mainproc.c @@ -428,7 +428,7 @@ print_pkenc_list( struct kidlist_item *list, int failed ) } free_public_key( pk ); - if( list->reason == GPG_ERR_NO_SECKEY ) { + if( gpg_err_code (list->reason) == GPG_ERR_NO_SECKEY ) { if( is_status_enabled() ) { char buf[20]; sprintf(buf,"%08lX%08lX", (ulong)list->kid[0], @@ -1189,7 +1189,7 @@ do_proc_packets( CTX c, iobuf_t a ) break; } } - if( rc == GPG_ERR_INV_PACKET ) + if( gpg_err_code (rc) == GPG_ERR_INV_PACKET ) write_status_text( STATUS_NODATA, "3" ); if( any_data ) rc = 0; @@ -1280,7 +1280,8 @@ check_sig_and_print( CTX c, KBNODE node ) (int)strlen(tstr), tstr, astr? astr: "?", (ulong)sig->keyid[1] ); rc = do_check_sig(c, node, NULL, &is_expkey ); - if( rc == GPG_ERR_NO_PUBKEY && opt.keyserver_scheme && opt.keyserver_options.auto_key_retrieve) { + if( gpg_err_code (rc) == GPG_ERR_NO_PUBKEY + && opt.keyserver_scheme && opt.keyserver_options.auto_key_retrieve) { if( keyserver_import_keyid ( sig->keyid )==0 ) rc = do_check_sig(c, node, NULL, &is_expkey ); } @@ -1482,14 +1483,14 @@ check_sig_and_print( CTX c, KBNODE node ) if( opt.batch && rc ) g10_exit(1); } - else { + else { char buf[50]; sprintf(buf, "%08lX%08lX %d %d %02x %lu %d", (ulong)sig->keyid[0], (ulong)sig->keyid[1], sig->pubkey_algo, sig->digest_algo, sig->sig_class, (ulong)sig->timestamp, rc ); write_status_text( STATUS_ERRSIG, buf ); - if( rc == GPG_ERR_NO_PUBKEY ) { + if( gpg_err_code (rc) == GPG_ERR_NO_PUBKEY ) { buf[16] = 0; write_status_text( STATUS_NO_PUBKEY, buf ); } diff --git a/g10/misc.c b/g10/misc.c index 19586624f..5cdad1598 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -244,6 +244,9 @@ openpgp_pk_test_algo( int algo, unsigned int usage_flags ) { size_t value = usage_flags; + if (algo == GCRY_PK_ELG_E) + algo = GCRY_PK_ELG; +#warning need to handle the usage here? if (algo < 0 || algo > 110) return GPG_ERR_PUBKEY_ALGO; return gcry_pk_algo_info (algo, GCRYCTL_TEST_ALGO, NULL, &value); @@ -292,6 +295,18 @@ int openpgp_md_map_name (const char *string) { int i = gcry_md_map_name (string); + + if (!i && (string[0]=='H' || string[0]=='h')) + { /* Didn't find it, so try the Hx format */ + long val; + char *endptr; + + string++; + + val=strtol(string,&endptr,10); + if (*string!='\0' && *endptr=='\0' && !openpgp_md_test_algo(val)) + i = val; + } return i < 0 || i > 110? 0 : i; } @@ -299,6 +314,18 @@ int openpgp_cipher_map_name (const char *string) { int i = gcry_cipher_map_name (string); + + if (!i && (string[0]=='S' || string[0]=='s')) + { /* Didn't find it, so try the Sx format */ + long val; + char *endptr; + + string++; + + val=strtol(string,&endptr,10); + if (*string!='\0' && *endptr=='\0' && !openpgp_cipher_test_algo(val)) + i = val; + } return i < 0 || i > 110? 0 : i; } @@ -703,32 +730,52 @@ parse_options(char *str,unsigned int *options,struct parse_options *opts) int pubkey_get_npkey( int algo ) { - int n = gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NPKEY, NULL, 0 ); - return n > 0? n : 0; + size_t n; + + if (algo == GCRY_PK_ELG_E) + algo = GCRY_PK_ELG; + if (gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NPKEY, NULL, &n)) + n = 0; + return n; } /* Temporary helper. */ int pubkey_get_nskey( int algo ) { - int n = gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NSKEY, NULL, 0 ); - return n > 0? n : 0; + size_t n; + + if (algo == GCRY_PK_ELG_E) + algo = GCRY_PK_ELG; + if (gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NSKEY, NULL, &n )) + n = 0; + return n; } /* Temporary helper. */ int pubkey_get_nsig( int algo ) { - int n = gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NSIGN, NULL, 0 ); - return n > 0? n : 0; + size_t n; + + if (algo == GCRY_PK_ELG_E) + algo = GCRY_PK_ELG; + if (gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NSIGN, NULL, &n)) + n = 0; + return n; } /* Temporary helper. */ int pubkey_get_nenc( int algo ) { - int n = gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NENCR, NULL, 0 ); - return n > 0? n : 0; + size_t n; + + if (algo == GCRY_PK_ELG_E) + algo = GCRY_PK_ELG; + if (gcry_pk_algo_info( algo, GCRYCTL_GET_ALGO_NENCR, NULL, &n )) + n = 0; + return n; } @@ -788,7 +835,7 @@ mpi_write( iobuf_t out, gcry_mpi_t a ) } /**************** - * Writye a MPI to out, but in this case it is an opaque one, + * Writyeg a MPI to out, but in this case it is an opaque one, * s used vor v3 protected keys. */ int diff --git a/g10/pubkey-enc.c b/g10/pubkey-enc.c index b5837b24e..b08394e4a 100644 --- a/g10/pubkey-enc.c +++ b/g10/pubkey-enc.c @@ -190,7 +190,7 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid ) write_status(STATUS_RSA_OR_IDEA); rc = openpgp_cipher_test_algo (dek->algo); if( rc ) { - if( !opt.quiet && rc == GPG_ERR_CIPHER_ALGO ) { + if( !opt.quiet && gpg_err_code (rc) == GPG_ERR_CIPHER_ALGO ) { log_info(_("cipher algorithm %d%s is unknown or disabled\n"), dek->algo, dek->algo == CIPHER_ALGO_IDEA? " (IDEA)":""); if(dek->algo==CIPHER_ALGO_IDEA)