summaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
Diffstat (limited to 'g10')
-rw-r--r--g10/ChangeLog14
-rw-r--r--g10/encode.c4
-rw-r--r--g10/getkey.c17
-rw-r--r--g10/import.c31
-rw-r--r--g10/keydb.h4
-rw-r--r--g10/keyedit.c68
-rw-r--r--g10/keylist.c5
-rw-r--r--g10/main.h1
-rw-r--r--g10/passphrase.c2
-rw-r--r--g10/sign.c4
-rw-r--r--g10/status.c8
11 files changed, 120 insertions, 38 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 1857317cc..c0cd820f6 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,6 +1,18 @@
+2002-08-19 Werner Koch <wk@gnupg.org>
+
+ * getkey.c (get_user_id_native): Renamed to ..
+ (get_user_id_printable): this. Filter out all dangerous
+ characters. Checked all usages.
+ (get_user_id_string_native): Renamed to..
+ (get_user_id_string_printable): this. Filter out all dangerous
+ characters. Checked all usages.
+ * keyedit.c (show_basic_key_info): New.
+ * keylist.c (print_fingerprint): New mode 3.
+ * import.c (import_one): Use new function to display the user ID.
+
2002-08-16 Timo Schulz <ts@winpt.org>
- * g10.c (main): enable opt.interactive.
+ * g10.c (main): Enable opt.interactive.
* import.c (import_one): Ask the user if the key shall be
imported when the interactive mode is used. Useful to extract
diff --git a/g10/encode.c b/g10/encode.c
index 417685f12..4811e4e88 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -719,8 +719,8 @@ write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out )
log_error("pubkey_encrypt failed: %s\n", g10_errstr(rc) );
else {
if( opt.verbose ) {
- char *ustr = get_user_id_string_native( enc->keyid );
- log_info(_("%s/%s encrypted for: %s\n"),
+ char *ustr = get_user_id_string_printable (enc->keyid);
+ log_info(_("%s/%s encrypted for: \"%s\"\n"),
pubkey_algo_to_string(enc->pubkey_algo),
cipher_algo_to_string(dek->algo), ustr );
m_free(ustr);
diff --git a/g10/getkey.c b/g10/getkey.c
index 87680502a..1f13dcacf 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -2323,13 +2323,14 @@ get_user_id_string( u32 *keyid )
char*
-get_user_id_string_native( u32 *keyid )
+get_user_id_string_printable ( u32 *keyid )
{
char *p = get_user_id_string( keyid );
char *p2 = utf8_to_native( p, strlen(p), 0 );
-
m_free(p);
- return p2;
+ p = make_printable_string (p2, strlen (p2), 0);
+ m_free (p2);
+ return p;
}
@@ -2386,17 +2387,19 @@ get_user_id( u32 *keyid, size_t *rn )
}
char*
-get_user_id_native( u32 *keyid )
+get_user_id_printable( u32 *keyid )
{
size_t rn;
-
char *p = get_user_id( keyid, &rn );
char *p2 = utf8_to_native( p, rn, 0 );
-
m_free(p);
- return p2;
+ p = make_printable_string (p2, strlen (p2), 0);
+ m_free (p2);
+ return p;
}
+
+
KEYDB_HANDLE
get_ctx_handle(GETKEY_CTX ctx)
{
diff --git a/g10/import.c b/g10/import.c
index ec9ada602..6d524b4da 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -34,6 +34,7 @@
#include "trustdb.h"
#include "main.h"
#include "i18n.h"
+#include "ttyio.h"
#include "status.h"
#include "keyserver-internal.h"
@@ -642,21 +643,13 @@ import_one( const char *fname, KBNODE keyblock, int fast,
return 0;
}
- if( opt.interactive ) {
- char *prompt, *p;
- size_t n = 0;
-
- p = get_user_id( pk->keyid, &n );
- prompt = m_alloc( n + 16 + 128 + 1 );
- snprintf( prompt, n + 16 + 128,
- "Do you want to import %08lX \"%s\" ? (y/n) ",
- (ulong)keyid[1], p );
- m_free( p );
- if( !cpr_get_answer_is_yes( "import.okay", prompt ) ) {
- m_free( prompt );
+ if (opt.interactive) {
+ tty_printf ("\n");
+ show_basic_key_info (keyblock);
+ tty_printf ("\n");
+ if (!cpr_get_answer_is_yes ("import.okay",
+ "Do you want to import this key? (y/N) "))
return 0;
- }
- m_free( prompt );
}
clear_kbnode_flags( keyblock );
@@ -728,7 +721,7 @@ import_one( const char *fname, KBNODE keyblock, int fast,
/* we are ready */
if( !opt.quiet ) {
- char *p=get_user_id_native(keyid);
+ char *p=get_user_id_printable (keyid);
log_info( _("key %08lX: public key \"%s\" imported\n"),
(ulong)keyid[1],p);
m_free(p);
@@ -804,7 +797,7 @@ import_one( const char *fname, KBNODE keyblock, int fast,
/* we are ready */
if( !opt.quiet ) {
- char *p=get_user_id_native(keyid);
+ char *p=get_user_id_printable(keyid);
if( n_uids == 1 )
log_info( _("key %08lX: \"%s\" 1 new user ID\n"),
(ulong)keyid[1], p);
@@ -832,7 +825,7 @@ import_one( const char *fname, KBNODE keyblock, int fast,
}
else {
if( !opt.quiet ) {
- char *p=get_user_id_native(keyid);
+ char *p=get_user_id_printable(keyid);
log_info( _("key %08lX: \"%s\" not changed\n"),
(ulong)keyid[1],p);
m_free(p);
@@ -1023,7 +1016,7 @@ import_revoke_cert( const char *fname, KBNODE node, struct stats_s *stats )
keydb_release (hd); hd = NULL;
/* we are ready */
if( !opt.quiet ) {
- char *p=get_user_id_native(keyid);
+ char *p=get_user_id_printable (keyid);
log_info( _("key %08lX: \"%s\" revocation certificate imported\n"),
(ulong)keyid[1],p);
m_free(p);
@@ -1445,7 +1438,7 @@ merge_blocks( const char *fname, KBNODE keyblock_orig, KBNODE keyblock,
}
}
if( !found ) {
- char *p=get_user_id_native(keyid);
+ char *p=get_user_id_printable (keyid);
KBNODE n2 = clone_kbnode(node);
insert_kbnode( keyblock_orig, n2, 0 );
n2->flag |= 1;
diff --git a/g10/keydb.h b/g10/keydb.h
index 34d02d702..ea9e48e6d 100644
--- a/g10/keydb.h
+++ b/g10/keydb.h
@@ -215,10 +215,10 @@ void get_seckey_end( GETKEY_CTX ctx );
int enum_secret_keys( void **context, PKT_secret_key *sk, int with_subkeys );
void merge_keys_and_selfsig( KBNODE keyblock );
char*get_user_id_string( u32 *keyid );
-char*get_user_id_string_native( u32 *keyid );
+char*get_user_id_string_printable( u32 *keyid );
char*get_long_user_id_string( u32 *keyid );
char*get_user_id( u32 *keyid, size_t *rn );
-char*get_user_id_native( u32 *keyid );
+char*get_user_id_printable( u32 *keyid );
KEYDB_HANDLE get_ctx_handle(GETKEY_CTX ctx);
/*-- keyid.c --*/
diff --git a/g10/keyedit.c b/g10/keyedit.c
index d9c3df09f..19da4256c 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -1845,6 +1845,74 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
}
+
+/* Display basic key information. This fucntion is suitable to show
+ information on the key without any dependencies on the trustdb or
+ any other internal GnuPG stuff. KEYBLOCK may either be a public or
+ a secret key.*/
+void
+show_basic_key_info ( KBNODE keyblock )
+{
+ KBNODE node;
+ int i;
+
+ /* The primary key */
+ for (node = keyblock; node; node = node->next)
+ {
+ if (node->pkt->pkttype == PKT_PUBLIC_KEY)
+ {
+ PKT_public_key *pk = node->pkt->pkt.public_key;
+
+ /* Note, we use the same format string as in other show
+ functions to make the translation job easier. */
+ tty_printf (_("%s%c %4u%c/%08lX created: %s expires: %s"),
+ node->pkt->pkttype == PKT_PUBLIC_KEY? "pub":"sub",
+ ' ',
+ nbits_from_pk( pk ),
+ pubkey_letter( pk->pubkey_algo ),
+ (ulong)keyid_from_pk(pk,NULL),
+ datestr_from_pk(pk),
+ expirestr_from_pk(pk) );
+ tty_printf("\n");
+ print_fingerprint ( pk, NULL, 3 );
+ tty_printf("\n");
+ }
+ else if (node->pkt->pkttype == PKT_SECRET_KEY)
+ {
+ PKT_secret_key *sk = node->pkt->pkt.secret_key;
+ tty_printf(_("%s%c %4u%c/%08lX created: %s expires: %s"),
+ node->pkt->pkttype == PKT_SECRET_KEY? "sec":"ssb",
+ ' ',
+ nbits_from_sk( sk ),
+ pubkey_letter( sk->pubkey_algo ),
+ (ulong)keyid_from_sk(sk,NULL),
+ datestr_from_sk(sk),
+ expirestr_from_sk(sk) );
+ tty_printf("\n");
+ print_fingerprint (NULL, sk, 3 );
+ tty_printf("\n");
+ }
+ }
+
+ /* The user IDs. */
+ for (i=0, node = keyblock; node; node = node->next)
+ {
+ if (node->pkt->pkttype == PKT_USER_ID)
+ {
+ PKT_user_id *uid = node->pkt->pkt.user_id;
+ ++i;
+
+ tty_printf (" ");
+ if (uid->is_revoked)
+ tty_printf ("[revoked] ");
+ if ( uid->is_expired )
+ tty_printf ("[expired] ");
+ tty_print_utf8_string (uid->name, uid->len);
+ tty_printf ("\n");
+ }
+ }
+}
+
static void
show_key_and_fingerprint( KBNODE keyblock )
{
diff --git a/g10/keylist.c b/g10/keylist.c
index cc26b0bc3..cca574ef9 100644
--- a/g10/keylist.c
+++ b/g10/keylist.c
@@ -940,6 +940,7 @@ list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque )
* mode 0: as used in key listings, opt.with_colons is honored
* 1: print using log_info ()
* 2: direct use of tty
+ * 3: direct use of tty but only primary key.
* modes 1 and 2 will try and print both subkey and primary key fingerprints
*/
void
@@ -1005,6 +1006,10 @@ print_fingerprint (PKT_public_key *pk, PKT_secret_key *sk, int mode )
else
text = _(" Subkey fingerprint:");
}
+ else if (mode == 3) {
+ fp = NULL; /* use tty */
+ text = _(" Key fingerprint =");
+ }
else {
fp = stdout;
text = _(" Key fingerprint =");
diff --git a/g10/main.h b/g10/main.h
index 09d4a93d8..efb528aed 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -117,6 +117,7 @@ int delete_keys( STRLIST names, int secret, int allow_both );
/*-- keyedit.c --*/
void keyedit_menu( const char *username, STRLIST locusr, STRLIST cmds,
int sign_mode );
+void show_basic_key_info (KBNODE keyblock);
/*-- keygen.c --*/
u32 ask_expire_interval(int object);
diff --git a/g10/passphrase.c b/g10/passphrase.c
index c8ebad620..7c4f78f68 100644
--- a/g10/passphrase.c
+++ b/g10/passphrase.c
@@ -636,7 +636,7 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *tryagain_text )
else
*maink = 0;
- uid = get_user_id( keyid, &uidlen );
+ uid = get_user_id ( keyid, &uidlen );
timestr = strtimestamp (pk->timestamp);
fmtstr = _("You need a passphrase to unlock the"
" secret key for user:\n"
diff --git a/g10/sign.c b/g10/sign.c
index ac6f077d6..e4fcc5f34 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -308,8 +308,8 @@ do_sign( PKT_secret_key *sk, PKT_signature *sig,
log_error(_("signing failed: %s\n"), g10_errstr(rc) );
else {
if( opt.verbose ) {
- char *ustr = get_user_id_string( sig->keyid );
- log_info(_("%s signature from: %s\n"),
+ char *ustr = get_user_id_string_printable (sig->keyid);
+ log_info(_("%s signature from: \"%s\"\n"),
pubkey_algo_to_string(sk->pubkey_algo), ustr );
m_free(ustr);
}
diff --git a/g10/status.c b/g10/status.c
index e0b126b78..515be0c6e 100644
--- a/g10/status.c
+++ b/g10/status.c
@@ -642,10 +642,10 @@ cpr_get_answer_is_yes( const char *keyword, const char *prompt )
if( opt.command_fd != -1 )
return !!do_get_from_fd ( keyword, 0, 1 );
- #ifdef USE_SHM_COPROCESSING
+#ifdef USE_SHM_COPROCESSING
if( opt.shm_coprocess )
return !!do_shm_get( keyword, 0, 1 );
- #endif
+#endif
for(;;) {
p = tty_get( prompt );
trim_spaces(p); /* it is okay to do this here */
@@ -670,10 +670,10 @@ cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt )
if( opt.command_fd != -1 )
return !!do_get_from_fd ( keyword, 0, 1 );
- #ifdef USE_SHM_COPROCESSING
+#ifdef USE_SHM_COPROCESSING
if( opt.shm_coprocess )
return !!do_shm_get( keyword, 0, 1 );
- #endif
+#endif
for(;;) {
p = tty_get( prompt );
trim_spaces(p); /* it is okay to do this here */