diff options
author | Werner Koch <wk@gnupg.org> | 1999-07-12 14:57:54 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1999-07-12 14:57:54 +0200 |
commit | 8be0d60594153ee058acbfae91efc0d4d1b17e12 (patch) | |
tree | 07e7e5f3b397c351bca6931578cc19498be60e73 /g10 | |
parent | See ChangeLog: Thu Jul 8 16:21:27 CEST 1999 Werner Koch (diff) | |
download | gnupg2-8be0d60594153ee058acbfae91efc0d4d1b17e12.tar.xz gnupg2-8be0d60594153ee058acbfae91efc0d4d1b17e12.zip |
See ChangeLog: Mon Jul 12 14:55:34 CEST 1999 Werner Koch
Diffstat (limited to 'g10')
-rw-r--r-- | g10/ChangeLog | 16 | ||||
-rw-r--r-- | g10/g10.c | 46 | ||||
-rw-r--r-- | g10/mainproc.c | 82 | ||||
-rw-r--r-- | g10/openfile.c | 2 | ||||
-rw-r--r-- | g10/passphrase.c | 4 | ||||
-rw-r--r-- | g10/seckey-cert.c | 2 |
6 files changed, 127 insertions, 25 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index fcc2a97eb..480aa1f98 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,19 @@ +Mon Jul 12 14:55:34 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> + + + * mainproc.c (kidlist_item): New. + (release_list): Release failed pk-enc-list. + (print_failed_pkenc): New + (proc_encrypted): Print info about failed PK enc. + + * openfile.c (make_outfile_name): s/error/info/ + + * passphrase.c (passphrase_to_dek): Return an empty passphrase when + in batch mode and don't make the warbing message fatal + * seckey-cert.c (check_secret_key): Try only once when in batch mode. + + * g10.c (make_username): New. + Thu Jul 8 16:21:27 CEST 1999 Werner Koch <wk@isil.d.shuttle.de> @@ -442,6 +442,19 @@ wrong_args( const char *text) g10_exit(2); } + +static char * +make_username( const char *string ) +{ + char *p; + if( utf8_strings ) + p = native_to_utf8( string ); + else + p = m_strdup(string); + return p; +} + + static void set_debug(void) { @@ -494,6 +507,7 @@ main( int argc, char **argv ) int orig_argc; char **orig_argv; const char *fname; + char *username; STRLIST sl, remusr= NULL, locusr=NULL; STRLIST nrings=NULL, sec_nrings=NULL; armor_filter_context_t afx; @@ -1050,10 +1064,10 @@ main( int argc, char **argv ) case aDeleteKey: if( argc != 1 ) wrong_args(_("--delete-key username")); - /* note: fname is the user id! */ - /* fixme: do utf8 conversion */ - if( (rc = delete_key(fname, cmd==aDeleteSecretKey)) ) - log_error("%s: delete key failed: %s\n", print_fname_stdin(fname), g10_errstr(rc) ); + username = make_username( fname ); + if( (rc = delete_key(username, cmd==aDeleteSecretKey)) ) + log_error("%s: delete key failed: %s\n", username, g10_errstr(rc) ); + m_free(username); break; @@ -1068,7 +1082,7 @@ main( int argc, char **argv ) secret_key_list( argc, argv ); break; - case aKMode: /* list keyring */ + case aKMode: /* list keyring -- NOTE: This will be removed soon */ if( argc < 2 ) /* -kv [userid] */ public_key_list( (argc && **argv)? 1:0, argv ); else if( argc == 2 ) { /* -kv userid keyring */ @@ -1114,7 +1128,7 @@ main( int argc, char **argv ) case aRecvKeys: sl = NULL; for( ; argc; argc--, argv++ ) - add_to_strlist( &sl, *argv ); + add_to_strlist2( &sl, *argv, utf8_strings ); if( cmd == aSendKeys ) hkp_export( sl ); else if( cmd == aRecvKeys ) @@ -1127,7 +1141,7 @@ main( int argc, char **argv ) case aExportSecret: sl = NULL; for( ; argc; argc--, argv++ ) - add_to_strlist( &sl, *argv ); + add_to_strlist2( &sl, *argv, utf8_strings ); export_seckeys( sl ); free_strlist(sl); break; @@ -1135,7 +1149,9 @@ main( int argc, char **argv ) case aGenRevoke: if( argc != 1 ) wrong_args("--gen-revoke user-id"); - gen_revoke( *argv ); + username = make_username(*argv); + gen_revoke( username ); + m_free( username ); break; case aDeArmor: @@ -1258,8 +1274,11 @@ main( int argc, char **argv ) if( !argc ) check_trustdb(NULL); else { - for( ; argc; argc--, argv++ ) - check_trustdb( *argv ); + for( ; argc; argc--, argv++ ) { + username = make_username( *argv ); + check_trustdb( username ); + m_free(username); + } } break; @@ -1272,8 +1291,11 @@ main( int argc, char **argv ) case aListTrustPath: if( !argc ) wrong_args("--list-trust-path <usernames>"); - for( ; argc; argc--, argv++ ) - list_trust_path( *argv ); + for( ; argc; argc--, argv++ ) { + username = make_username( *argv ); + list_trust_path( username ); + m_free(username); + } break; case aExportOwnerTrust: diff --git a/g10/mainproc.c b/g10/mainproc.c index edd393a1e..1e06a78c8 100644 --- a/g10/mainproc.c +++ b/g10/mainproc.c @@ -39,6 +39,16 @@ #include "trustdb.h" #include "hkp.h" + +struct kidlist_item { + struct kidlist_item *next; + u32 kid[2]; + int pubkey_algo; + int reason; +}; + + + /**************** * Structure to hold the context */ @@ -60,6 +70,8 @@ struct mainproc_context { IOBUF iobuf; /* used to get the filename etc. */ int trustletter; /* temp usage in list_node */ ulong local_id; /* ditto */ + struct kidlist_item *failed_pkenc; /* list of packets for which + we do not have a secret key */ }; @@ -76,6 +88,12 @@ release_list( CTX c ) return; proc_tree(c, c->list ); release_kbnode( c->list ); + while( c->failed_pkenc ) { + struct kidlist_item *tmp = c->failed_pkenc->next; + m_free( c->failed_pkenc ); + c->failed_pkenc = tmp; + } + c->failed_pkenc = NULL; c->list = NULL; } @@ -213,6 +231,8 @@ proc_pubkey_enc( CTX c, PACKET *pkt ) m_free(c->dek); c->dek = NULL; } } + else + result = G10ERR_NO_SECKEY; } else result = G10ERR_PUBKEY_ALGO; @@ -223,22 +243,66 @@ proc_pubkey_enc( CTX c, PACKET *pkt ) if( opt.verbose > 1 ) log_info( _("public key encrypted data: good DEK\n") ); } - else { - /* fixme: defer this message until we have parsed all packets of - * this type - do this by building a list of keys with their stati - * and store it with the context. do_proc_packets can then use - * this list to display some information */ - log_error(_("public key decryption failed: %s\n"), g10_errstr(result)); + else { /* store it for later display */ + struct kidlist_item *x = m_alloc( sizeof *x ); + x->kid[0] = enc->keyid[0]; + x->kid[1] = enc->keyid[1]; + x->pubkey_algo = enc->pubkey_algo; + x->reason = result; + x->next = c->failed_pkenc; + c->failed_pkenc = x; } free_packet(pkt); } + +/**************** + * Print the list of public key encrypted packets which we could + * not decrypt. + */ +static void +print_failed_pkenc( struct kidlist_item *list ) +{ + for( ; list; list = list->next ) { + PKT_public_key *pk = m_alloc_clear( sizeof *pk ); + const char *algstr = pubkey_algo_to_string( list->pubkey_algo ); + + pk->pubkey_algo = list->pubkey_algo; + if( !get_pubkey( pk, list->kid ) ) { + size_t n; + char *p; + log_info( _("encrypted with %u-bit %s key, ID %08lX, created %s\n"), + nbits_from_pk( pk ), algstr, (ulong)list->kid[1], + strtimestamp(pk->timestamp) ); + fputs(" \"", log_stream() ); + p = get_user_id( list->kid, &n ); + print_string( log_stream(), p, n, '"' ); + m_free(p); + fputs("\"\n", log_stream() ); + } + else { + log_info(_("encrypted with %s key, ID %08lX\n"), + algstr, (ulong) list->kid[1] ); + } + free_public_key( pk ); + + if( list->reason == G10ERR_NO_SECKEY ) + log_info(_("no secret key for decryption available\n")); + else + log_error(_("public key decryption failed: %s\n"), + g10_errstr(list->reason)); + } +} + + static void proc_encrypted( CTX c, PACKET *pkt ) { int result = 0; + print_failed_pkenc( c->failed_pkenc ); + /*log_debug("dat: %sencrypted data\n", c->dek?"":"conventional ");*/ if( !c->dek && !c->last_was_session_key ) { /* assume this is old conventional encrypted data */ @@ -267,8 +331,8 @@ proc_encrypted( CTX c, PACKET *pkt ) else { write_status( STATUS_DECRYPTION_FAILED ); log_error(_("decryption failed: %s\n"), g10_errstr(result)); - /* FIXME: if this is secret key not available, try with - * other keys */ + /* Hmmm: does this work when we have encrypted using a multiple + * ways to specify the session key (symmmetric and PK)*/ } free_packet(pkt); c->last_was_session_key = 0; @@ -452,7 +516,6 @@ do_check_sig( CTX c, KBNODE node, int *is_selfsig ) } - static void print_userid( PACKET *pkt ) { @@ -544,6 +607,7 @@ print_notation_data( PKT_signature *sig ) /* TODO */ } + /**************** * List the certificate in a user friendly way */ diff --git a/g10/openfile.c b/g10/openfile.c index ebf954843..4d16db500 100644 --- a/g10/openfile.c +++ b/g10/openfile.c @@ -94,7 +94,7 @@ make_outfile_name( const char *iname ) return buf; } - log_error(_("%s: unknown suffix\n"), iname ); + log_info(_("%s: unknown suffix\n"), iname ); return NULL; } diff --git a/g10/passphrase.c b/g10/passphrase.c index 80c6fa33f..6026ff7f9 100644 --- a/g10/passphrase.c +++ b/g10/passphrase.c @@ -187,8 +187,8 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo, strcpy( pw, fd_passwd ); } else if( opt.batch ) { - write_status( STATUS_MISSING_PASSPHRASE ); - log_fatal("Can't query password in batchmode\n"); + log_error(_("can't query password in batchmode\n")); + pw = m_strdup( "" ); /* return an empty passphrase */ } else { pw = cpr_get_hidden("passphrase.enter", _("Enter passphrase: ") ); diff --git a/g10/seckey-cert.c b/g10/seckey-cert.c index 95af40b78..a8fae04d6 100644 --- a/g10/seckey-cert.c +++ b/g10/seckey-cert.c @@ -164,7 +164,7 @@ check_secret_key( PKT_secret_key *sk, int n ) int i; if( n < 1 ) - n = 3; /* use the default value */ + n = opt.batch? 1 : 3; /* use the default value */ for(i=0; i < n && rc == G10ERR_BAD_PASS; i++ ) { if( i ) |