1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

* trustdb.c (uid_trust_string_fixed): Show uids as revoked if the key is

revoked.

* keyedit.c (show_key_with_all_names): Don't show validity for secret key
UIDs.

* keyedit.c (parse_sign_type): New.  Figure out the flags (local,
nonrevoke, trust) for a signature. (keyedit_menu): Call it here so we can
mix and match flags, and don't need "nrltsign", "ltsign", "tnrsign", etc,
etc, etc.
This commit is contained in:
David Shaw 2004-12-14 14:42:41 +00:00
parent 3a6e319232
commit 7dd3fe2a79
3 changed files with 196 additions and 119 deletions

View File

@ -1,3 +1,16 @@
2004-12-14 David Shaw <dshaw@jabberwocky.com>
* trustdb.c (uid_trust_string_fixed): Show uids as revoked if the
key is revoked.
* keyedit.c (show_key_with_all_names): Don't show validity for
secret key UIDs.
* keyedit.c (parse_sign_type): New. Figure out the flags (local,
nonrevoke, trust) for a signature.
(keyedit_menu): Call it here so we can mix and match flags, and
don't need "nrltsign", "ltsign", "tnrsign", etc, etc, etc.
2004-12-14 Werner Koch <wk@g10code.com> 2004-12-14 Werner Koch <wk@g10code.com>
* passphrase.c (agent_get_passphrase): Removed debug output * passphrase.c (agent_get_passphrase): Removed debug output

View File

@ -1214,6 +1214,35 @@ fix_keyblock( KBNODE keyblock )
return fixed; return fixed;
} }
static int
parse_sign_type(const char *str,int *localsig,int *nonrevokesig,int *trustsig)
{
const char *p=str;
while(*p)
{
if(ascii_strncasecmp(p,"l",1)==0)
{
*localsig=1;
p++;
}
else if(ascii_strncasecmp(p,"nr",2)==0)
{
*nonrevokesig=1;
p+=2;
}
else if(ascii_strncasecmp(p,"t",1)==0)
{
*trustsig=1;
p++;
}
else
return 0;
}
return 1;
}
/**************** /****************
* Menu driven key editor. If seckey_check is true, then a secret key * Menu driven key editor. If seckey_check is true, then a secret key
* that matches username will be looked for. If it is false, not all * that matches username will be looked for. If it is false, not all
@ -1222,78 +1251,87 @@ fix_keyblock( KBNODE keyblock )
* Note: to keep track of some selection we use node->mark MARKBIT_xxxx. * Note: to keep track of some selection we use node->mark MARKBIT_xxxx.
*/ */
/* Need an SK for this command */
#define KEYEDIT_NEED_SK 1
/* Cannot be viewing the SK for this command */
#define KEYEDIT_NOT_SK 2
/* Must be viewing the SK for this command */
#define KEYEDIT_ONLY_SK 4
/* Match the tail of the string */
#define KEYEDIT_TAIL_MATCH 8
void void
keyedit_menu( const char *username, STRLIST locusr, keyedit_menu( const char *username, STRLIST locusr,
STRLIST commands, int quiet, int seckey_check ) STRLIST commands, int quiet, int seckey_check )
{ {
enum cmdids { cmdNONE = 0, enum cmdids
cmdQUIT, cmdHELP, cmdFPR, cmdLIST, cmdSELUID, cmdCHECK, cmdSIGN, { cmdNONE = 0,
cmdTSIGN, cmdLSIGN, cmdNRSIGN, cmdNRLSIGN, cmdREVSIG, cmdREVKEY, cmdQUIT, cmdHELP, cmdFPR, cmdLIST, cmdSELUID, cmdCHECK, cmdSIGN,
cmdREVUID, cmdDELSIG, cmdPRIMARY, cmdDEBUG, cmdSAVE, cmdADDUID, cmdREVSIG, cmdREVKEY, cmdREVUID, cmdDELSIG, cmdPRIMARY, cmdDEBUG,
cmdADDPHOTO, cmdDELUID, cmdADDKEY, cmdDELKEY, cmdADDREVOKER, cmdSAVE, cmdADDUID, cmdADDPHOTO, cmdDELUID, cmdADDKEY, cmdDELKEY,
cmdTOGGLE, cmdSELKEY, cmdPASSWD, cmdTRUST, cmdPREF, cmdEXPIRE, cmdADDREVOKER, cmdTOGGLE, cmdSELKEY, cmdPASSWD, cmdTRUST, cmdPREF,
cmdENABLEKEY, cmdDISABLEKEY, cmdSHOWPREF, cmdSETPREF, cmdUPDPREF, cmdEXPIRE, cmdENABLEKEY, cmdDISABLEKEY, cmdSHOWPREF, cmdSETPREF,
cmdPREFKS, cmdINVCMD, cmdSHOWPHOTO, cmdUPDTRUST, cmdCHKTRUST, cmdUPDPREF, cmdPREFKS, cmdINVCMD, cmdSHOWPHOTO, cmdUPDTRUST,
cmdADDCARDKEY, cmdKEYTOCARD, cmdCHKTRUST, cmdADDCARDKEY, cmdKEYTOCARD,
cmdNOP }; cmdNOP };
static struct { const char *name; static struct
enum cmdids id; {
int need_sk; const char *name;
int not_with_sk; /* but 2 == must use SK */ enum cmdids id;
const char *desc; int flags;
} cmds[] = { const char *desc;
{ "quit" , cmdQUIT , 0,0, N_("quit this menu") }, } cmds[] =
{ "q" , cmdQUIT , 0,0, NULL }, {
{ "save" , cmdSAVE , 0,0, N_("save and quit") }, { N_("quit") , cmdQUIT , 0, N_("quit this menu") },
{ "help" , cmdHELP , 0,0, N_("show this help") }, { N_("q") , cmdQUIT , 0, NULL },
{ "?" , cmdHELP , 0,0, NULL }, { N_("save") , cmdSAVE , 0, N_("save and quit") },
{ "fpr" , cmdFPR , 0,0, N_("show fingerprint") }, { N_("help") , cmdHELP , 0, N_("show this help") },
{ "list" , cmdLIST , 0,0, N_("list key and user IDs") }, { "?" , cmdHELP , 0, NULL },
{ "l" , cmdLIST , 0,0, NULL }, { N_("fpr") , cmdFPR , 0, N_("show fingerprint") },
{ "uid" , cmdSELUID , 0,0, N_("select user ID N") }, { N_("list") , cmdLIST , 0, N_("list key and user IDs") },
{ "key" , cmdSELKEY , 0,0, N_("select secondary key N") }, { N_("l") , cmdLIST , 0, NULL },
{ "check" , cmdCHECK , 0,0, N_("list signatures") }, { N_("uid") , cmdSELUID , 0, N_("select user ID N") },
{ "c" , cmdCHECK , 0,0, NULL }, { N_("key") , cmdSELKEY , 0, N_("select secondary key N") },
{ "sign" , cmdSIGN , 0,1, N_("sign the key") }, { N_("check") , cmdCHECK , 0, N_("list signatures") },
{ "s" , cmdSIGN , 0,1, NULL }, { N_("c") , cmdCHECK , 0, NULL },
{ "tsign" , cmdTSIGN , 0,1, N_("make a trust signature")}, { N_("sign") , cmdSIGN , KEYEDIT_NOT_SK|KEYEDIT_TAIL_MATCH, N_("sign the key") },
{ "lsign" , cmdLSIGN , 0,1, N_("sign the key locally") }, { N_("s") , cmdSIGN , KEYEDIT_NOT_SK, NULL },
{ "nrsign" , cmdNRSIGN , 0,1, N_("sign the key non-revocably") }, /* "lsign" will never match since "sign" comes first and it is a
{ "nrlsign" , cmdNRLSIGN , 0,1, N_("sign the key locally " tail match. It is here so it shows up in the help menu. */
"and non-revocably") }, { N_("lsign") , cmdNOP , 0, N_("sign the key locally") },
{ "debug" , cmdDEBUG , 0,0, NULL }, { N_("debug") , cmdDEBUG , 0, NULL },
{ "adduid" , cmdADDUID , 1,1, N_("add a user ID") }, { N_("adduid") , cmdADDUID , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a user ID") },
{ "addphoto" , cmdADDPHOTO , 1,1, N_("add a photo ID") }, { N_("addphoto"), cmdADDPHOTO , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a photo ID") },
{ "deluid" , cmdDELUID , 0,1, N_("delete user ID") }, { N_("deluid") , cmdDELUID , KEYEDIT_NOT_SK, N_("delete user ID") },
/* delphoto is really deluid in disguise */ /* delphoto is really deluid in disguise */
{ "delphoto" , cmdDELUID , 0,1, NULL }, { N_("delphoto"), cmdDELUID , KEYEDIT_NOT_SK, NULL },
{ "addkey" , cmdADDKEY , 1,1, N_("add a secondary key") }, { N_("addkey") , cmdADDKEY , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a secondary key") },
#ifdef ENABLE_CARD_SUPPORT #ifdef ENABLE_CARD_SUPPORT
{ "addcardkey", cmdADDCARDKEY , 1,1, N_("add a key to a smartcard") }, { N_("addcardkey"), cmdADDCARDKEY , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a key to a smartcard") },
{ "keytocard", cmdKEYTOCARD , 1,2, N_("move a key to a smartcard")}, { N_("keytocard"), cmdKEYTOCARD , KEYEDIT_NEED_SK|KEYEDIT_ONLY_SK, N_("move a key to a smartcard")},
#endif /*ENABLE_CARD_SUPPORT*/ #endif /*ENABLE_CARD_SUPPORT*/
{ "delkey" , cmdDELKEY , 0,1, N_("delete a secondary key") }, { N_("delkey") , cmdDELKEY , KEYEDIT_NOT_SK, N_("delete a secondary key") },
{ "addrevoker",cmdADDREVOKER,1,1, N_("add a revocation key") }, { N_("addrevoker"),cmdADDREVOKER,KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a revocation key") },
{ "delsig" , cmdDELSIG , 0,1, N_("delete signatures") }, { N_("delsig") , cmdDELSIG , KEYEDIT_NOT_SK, N_("delete signatures") },
{ "expire" , cmdEXPIRE , 1,1, N_("change the expire date") }, { N_("expire") , cmdEXPIRE , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("change the expire date") },
{ "primary" , cmdPRIMARY , 1,1, N_("flag user ID as primary")}, { N_("primary") , cmdPRIMARY , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("flag user ID as primary")},
{ "toggle" , cmdTOGGLE , 1,0, N_("toggle between secret " { N_("toggle") , cmdTOGGLE , KEYEDIT_NEED_SK, N_("toggle between secret and public key listing") },
"and public key listing") }, { N_("t" ) , cmdTOGGLE , KEYEDIT_NEED_SK, NULL },
{ "t" , cmdTOGGLE , 1,0, NULL }, { N_("pref") , cmdPREF , KEYEDIT_NOT_SK, N_("list preferences (expert)")},
{ "pref" , cmdPREF , 0,1, N_("list preferences (expert)")}, { N_("showpref"), cmdSHOWPREF , KEYEDIT_NOT_SK, N_("list preferences (verbose)") },
{ "showpref" , cmdSHOWPREF , 0,1, N_("list preferences (verbose)") }, { N_("setpref") , cmdSETPREF , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("set preference list") },
{ "setpref" , cmdSETPREF , 1,1, N_("set preference list") }, { N_("updpref") , cmdUPDPREF , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("updated preferences") },
{ "updpref" , cmdUPDPREF , 1,1, N_("updated preferences") }, { N_("keyserver"),cmdPREFKS , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("set preferred keyserver URL")},
{ "keyserver",cmdPREFKS , 1,1, N_("set preferred keyserver URL")}, { N_("passwd") , cmdPASSWD , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("change the passphrase") },
{ "passwd" , cmdPASSWD , 1,1, N_("change the passphrase") }, { N_("trust") , cmdTRUST , KEYEDIT_NOT_SK, N_("change the ownertrust") },
{ "trust" , cmdTRUST , 0,1, N_("change the ownertrust") }, { N_("revsig") , cmdREVSIG , KEYEDIT_NOT_SK, N_("revoke signatures") },
{ "revsig" , cmdREVSIG , 0,1, N_("revoke signatures") }, { N_("revuid") , cmdREVUID , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("revoke a user ID") },
{ "revuid" , cmdREVUID , 1,1, N_("revoke a user ID") }, { N_("revkey") , cmdREVKEY , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("revoke a secondary key") },
{ "revkey" , cmdREVKEY , 1,1, N_("revoke a secondary key") }, { N_("disable") , cmdDISABLEKEY, KEYEDIT_NOT_SK, N_("disable a key") },
{ "disable" , cmdDISABLEKEY, 0,1, N_("disable a key") }, { N_("enable") , cmdENABLEKEY , KEYEDIT_NOT_SK, N_("enable a key") },
{ "enable" , cmdENABLEKEY , 0,1, N_("enable a key") }, { N_("showphoto"),cmdSHOWPHOTO , 0, N_("show photo ID") },
{ "showphoto",cmdSHOWPHOTO , 0,0, N_("show photo ID") }, { NULL, cmdNONE, 0, NULL }
{ NULL, cmdNONE, 0, 0, NULL } }; };
enum cmdids cmd = 0; enum cmdids cmd = 0;
int rc = 0; int rc = 0;
KBNODE keyblock = NULL; KBNODE keyblock = NULL;
@ -1420,30 +1458,49 @@ keyedit_menu( const char *username, STRLIST locusr,
arg_string = p; arg_string = p;
} }
for(i=0; cmds[i].name; i++ ) { for(i=0; cmds[i].name; i++ )
if( !ascii_strcasecmp( answer, cmds[i].name ) ) {
break; if(cmds[i].flags & KEYEDIT_TAIL_MATCH)
} {
if( cmds[i].need_sk && !sec_keyblock ) { size_t l=strlen(cmds[i].name);
size_t a=strlen(answer);
if(a>=l)
{
if(ascii_strcasecmp(&answer[a-l],cmds[i].name)==0)
{
answer[a-l]='\0';
break;
}
}
}
else if( !ascii_strcasecmp( answer, cmds[i].name ) )
break;
}
if((cmds[i].flags & KEYEDIT_NEED_SK) && !sec_keyblock )
{
tty_printf(_("Need the secret key to do this.\n")); tty_printf(_("Need the secret key to do this.\n"));
cmd = cmdNOP; cmd = cmdNOP;
} }
else if( (cmds[i].not_with_sk == 1 && sec_keyblock && toggle) else if(((cmds[i].flags & KEYEDIT_NOT_SK) && sec_keyblock
||(cmds[i].not_with_sk == 2 && sec_keyblock && !toggle)) { && toggle)
||((cmds[i].flags & KEYEDIT_ONLY_SK) && sec_keyblock
&& !toggle))
{
tty_printf(_("Please use the command \"toggle\" first.\n")); tty_printf(_("Please use the command \"toggle\" first.\n"));
cmd = cmdNOP; cmd = cmdNOP;
} }
else else
cmd = cmds[i].id; cmd = cmds[i].id;
} }
switch( cmd ) { switch( cmd ) {
case cmdHELP: case cmdHELP:
for(i=0; cmds[i].name; i++ ) { for(i=0; cmds[i].name; i++ )
if( cmds[i].need_sk && !sec_keyblock ) {
; /* skip if we do not have the secret key */ if((cmds[i].flags & KEYEDIT_NEED_SK) && !sec_keyblock )
else if( cmds[i].desc ) ; /* skip if we do not have the secret key */
tty_printf("%-10s %s\n", cmds[i].name, _(cmds[i].desc) ); else if( cmds[i].desc )
} tty_printf("%-10s %s\n", cmds[i].name, _(cmds[i].desc) );
}
break; break;
case cmdLIST: case cmdLIST:
@ -1472,43 +1529,49 @@ keyedit_menu( const char *username, STRLIST locusr,
break; break;
case cmdSIGN: /* sign (only the public key) */ case cmdSIGN: /* sign (only the public key) */
case cmdLSIGN: /* sign (only the public key) */ {
case cmdNRSIGN: /* sign (only the public key) */ int localsig=0,nonrevokesig=0,trustsig=0;
case cmdNRLSIGN: /* sign (only the public key) */
case cmdTSIGN:
if( pk->is_revoked )
{
tty_printf(_("Key is revoked."));
if(opt.expert) if( pk->is_revoked )
{ {
tty_printf(" "); tty_printf(_("Key is revoked."));
if(!cpr_get_answer_is_yes("keyedit.sign_revoked.okay",
_("Are you sure you still want " if(opt.expert)
"to sign it? (y/N) "))) {
tty_printf(" ");
if(!cpr_get_answer_is_yes("keyedit.sign_revoked.okay",
_("Are you sure you still want"
" to sign it? (y/N) ")))
break;
}
else
{
tty_printf(_(" Unable to sign.\n"));
break; break;
} }
else }
{
tty_printf(_(" Unable to sign.\n"));
break;
}
}
if( count_uids(keyblock) > 1 && !count_selected_uids(keyblock) ) if( count_uids(keyblock) > 1 && !count_selected_uids(keyblock) )
{ {
if( !cpr_get_answer_is_yes("keyedit.sign_all.okay", if( !cpr_get_answer_is_yes("keyedit.sign_all.okay",
_("Really sign all user IDs? (y/N) "))) _("Really sign all user IDs?"
{ " (y/N) ")))
tty_printf(_("Hint: Select the user IDs to sign\n")); {
break; tty_printf(_("Hint: Select the user IDs to sign\n"));
} break;
} }
}
sign_uids( keyblock, locusr, &modified, /* What sort of signing are we doing? */
(cmd == cmdLSIGN) || (cmd == cmdNRLSIGN), if(!parse_sign_type(answer,&localsig,&nonrevokesig,&trustsig))
(cmd == cmdNRSIGN) || (cmd==cmdNRLSIGN), {
(cmd == cmdTSIGN)); tty_printf(_("Unknown signature type `%s'\n"),answer);
break;
}
sign_uids(keyblock, locusr, &modified,
localsig, nonrevokesig, trustsig);
}
break; break;
case cmdDEBUG: case cmdDEBUG:
@ -2360,7 +2423,7 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
++i; ++i;
if( !only_marked || (only_marked && (node->flag & NODFLG_MARK_A))) if( !only_marked || (only_marked && (node->flag & NODFLG_MARK_A)))
{ {
if(!only_marked) if(!only_marked && primary)
tty_printf("%s ",uid_trust_string_fixed(primary,uid)); tty_printf("%s ",uid_trust_string_fixed(primary,uid));
if( only_marked ) if( only_marked )

View File

@ -495,17 +495,18 @@ trust_letter (unsigned int value)
properly. The value "10" should be the length of the strings you properly. The value "10" should be the length of the strings you
choose to translate to. This is the length in printable columns. choose to translate to. This is the length in printable columns.
It gets passed to atoi() so everything after the number is It gets passed to atoi() so everything after the number is
essentially a comment and need not be translated. */ essentially a comment and need not be translated. Either key and
uid are both NULL, or neither are NULL. */
const char * const char *
uid_trust_string_fixed(PKT_public_key *key,PKT_user_id *uid) uid_trust_string_fixed(PKT_public_key *key,PKT_user_id *uid)
{ {
if(!key && !uid) if(!key && !uid)
return _("10 translator see trustdb.c:uid_trust_string_fixed"); return _("10 translator see trustdb.c:uid_trust_string_fixed");
else if(uid->is_revoked) else if(uid->is_revoked || key->is_revoked)
return _("[ revoked]"); return _("[ revoked]");
else if(uid->is_expired) else if(uid->is_expired)
return _("[ expired]"); return _("[ expired]");
else if(key) else
switch(get_validity(key,uid)&TRUST_MASK) switch(get_validity(key,uid)&TRUST_MASK)
{ {
case TRUST_UNKNOWN: return _("[ unknown]"); case TRUST_UNKNOWN: return _("[ unknown]");