1998-02-16 21:05:02 +01:00
|
|
|
/* revoke.c
|
2004-03-05 01:01:25 +01:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
|
|
|
|
* 2004 Free Software Foundation, Inc.
|
1998-02-16 21:05:02 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* This file is part of GnuPG.
|
1998-02-16 21:05:02 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1998-02-16 21:05:02 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-10-23 12:48:09 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-02-16 21:05:02 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1998-02-16 21:05:02 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-10-23 12:48:09 +02:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
1998-02-16 21:05:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
2000-07-14 19:34:53 +02:00
|
|
|
#include <ctype.h>
|
1998-02-16 21:05:02 +01:00
|
|
|
|
|
|
|
#include "options.h"
|
|
|
|
#include "packet.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "keydb.h"
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "memory.h"
|
1998-02-16 21:05:02 +01:00
|
|
|
#include "util.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "ttyio.h"
|
1998-08-08 21:27:00 +02:00
|
|
|
#include "status.h"
|
|
|
|
#include "i18n.h"
|
1998-02-16 21:05:02 +01:00
|
|
|
|
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
struct revocation_reason_info {
|
|
|
|
int code;
|
|
|
|
char *desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
revocation_reason_build_cb( PKT_signature *sig, void *opaque )
|
|
|
|
{
|
|
|
|
struct revocation_reason_info *reason = opaque;
|
|
|
|
char *ud = NULL;
|
|
|
|
byte *buffer;
|
|
|
|
size_t buflen = 1;
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if(!reason)
|
|
|
|
return 0;
|
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
if( reason->desc ) {
|
|
|
|
ud = native_to_utf8( reason->desc );
|
|
|
|
buflen += strlen(ud);
|
|
|
|
}
|
2005-07-27 20:10:56 +02:00
|
|
|
buffer = xmalloc( buflen );
|
2000-07-14 19:34:53 +02:00
|
|
|
*buffer = reason->code;
|
|
|
|
if( ud ) {
|
|
|
|
memcpy(buffer+1, ud, strlen(ud) );
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree( ud );
|
2000-07-14 19:34:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build_sig_subpkt( sig, SIGSUBPKT_REVOC_REASON, buffer, buflen );
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree( buffer );
|
2000-07-14 19:34:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-06 18:58:58 +02:00
|
|
|
/* Outputs a minimal pk (as defined by 2440) from a keyblock. A
|
|
|
|
minimal pk consists of the public key packet and a user ID. We try
|
|
|
|
and pick a user ID that has a uid signature, and include it if
|
|
|
|
possible. */
|
|
|
|
static int
|
|
|
|
export_minimal_pk(IOBUF out,KBNODE keyblock,
|
|
|
|
PKT_signature *revsig,PKT_signature *revkey)
|
|
|
|
{
|
|
|
|
KBNODE node;
|
|
|
|
PACKET pkt;
|
|
|
|
PKT_user_id *uid=NULL;
|
|
|
|
PKT_signature *selfsig=NULL;
|
|
|
|
u32 keyid[2];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
node=find_kbnode(keyblock,PKT_PUBLIC_KEY);
|
|
|
|
if(!node)
|
|
|
|
{
|
2004-03-05 01:01:25 +01:00
|
|
|
log_error("key incomplete\n");
|
2002-08-06 18:58:58 +02:00
|
|
|
return G10ERR_GENERAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyid_from_pk(node->pkt->pkt.public_key,keyid);
|
|
|
|
|
|
|
|
pkt=*node->pkt;
|
|
|
|
rc=build_packet(out,&pkt);
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
log_error(_("build_packet failed: %s\n"), g10_errstr(rc) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_packet(&pkt);
|
|
|
|
pkt.pkttype=PKT_SIGNATURE;
|
2000-07-14 19:34:53 +02:00
|
|
|
|
2002-08-06 18:58:58 +02:00
|
|
|
/* the revocation itself, if any. 2440 likes this to come first. */
|
|
|
|
if(revsig)
|
|
|
|
{
|
|
|
|
pkt.pkt.signature=revsig;
|
|
|
|
rc=build_packet(out,&pkt);
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
log_error(_("build_packet failed: %s\n"), g10_errstr(rc) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a revkey in a 1F sig is present, include it too */
|
|
|
|
if(revkey)
|
|
|
|
{
|
|
|
|
pkt.pkt.signature=revkey;
|
|
|
|
rc=build_packet(out,&pkt);
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
log_error(_("build_packet failed: %s\n"), g10_errstr(rc) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!selfsig)
|
|
|
|
{
|
|
|
|
KBNODE signode;
|
|
|
|
|
|
|
|
node=find_next_kbnode(node,PKT_USER_ID);
|
|
|
|
if(!node)
|
|
|
|
{
|
|
|
|
/* We're out of user IDs - none were self-signed. */
|
|
|
|
if(uid)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
{
|
2004-03-05 01:01:25 +01:00
|
|
|
log_error(_("key %s has no user IDs\n"),keystr(keyid));
|
2002-08-06 18:58:58 +02:00
|
|
|
return G10ERR_GENERAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(node->pkt->pkt.user_id->attrib_data)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uid=node->pkt->pkt.user_id;
|
|
|
|
signode=node;
|
|
|
|
|
|
|
|
while((signode=find_next_kbnode(signode,PKT_SIGNATURE)))
|
|
|
|
{
|
|
|
|
if(keyid[0]==signode->pkt->pkt.signature->keyid[0] &&
|
|
|
|
keyid[1]==signode->pkt->pkt.signature->keyid[1] &&
|
|
|
|
IS_UID_SIG(signode->pkt->pkt.signature))
|
|
|
|
{
|
|
|
|
selfsig=signode->pkt->pkt.signature;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt.pkttype=PKT_USER_ID;
|
|
|
|
pkt.pkt.user_id=uid;
|
|
|
|
|
|
|
|
rc=build_packet(out,&pkt);
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
log_error(_("build_packet failed: %s\n"), g10_errstr(rc) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(selfsig)
|
|
|
|
{
|
|
|
|
pkt.pkttype=PKT_SIGNATURE;
|
|
|
|
pkt.pkt.signature=selfsig;
|
|
|
|
|
|
|
|
rc=build_packet(out,&pkt);
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
log_error(_("build_packet failed: %s\n"), g10_errstr(rc) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-14 19:34:53 +02:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/****************
|
|
|
|
* Generate a revocation certificate for UNAME via a designated revoker
|
|
|
|
*/
|
|
|
|
int
|
2005-11-19 06:55:45 +01:00
|
|
|
gen_desig_revoke( const char *uname, STRLIST locusr )
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
armor_filter_context_t afx;
|
|
|
|
PKT_public_key *pk = NULL;
|
|
|
|
PKT_secret_key *sk = NULL;
|
|
|
|
PKT_signature *sig = NULL;
|
|
|
|
IOBUF out = NULL;
|
|
|
|
struct revocation_reason_info *reason = NULL;
|
|
|
|
KEYDB_HANDLE kdbhd;
|
|
|
|
KEYDB_SEARCH_DESC desc;
|
|
|
|
KBNODE keyblock=NULL,node;
|
|
|
|
u32 keyid[2];
|
|
|
|
int i,any=0;
|
2005-11-19 06:55:45 +01:00
|
|
|
SK_LIST sk_list=NULL;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-10-28 05:57:30 +02:00
|
|
|
if( opt.batch )
|
|
|
|
{
|
|
|
|
log_error(_("can't do this in batch mode\n"));
|
2002-06-29 15:46:34 +02:00
|
|
|
return G10ERR_GENERAL;
|
2004-10-28 05:57:30 +02:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
memset( &afx, 0, sizeof afx);
|
|
|
|
|
|
|
|
kdbhd = keydb_new (0);
|
|
|
|
classify_user_id (uname, &desc);
|
|
|
|
rc = desc.mode? keydb_search (kdbhd, &desc, 1) : G10ERR_INV_USER_ID;
|
|
|
|
if (rc) {
|
2004-10-28 03:58:01 +02:00
|
|
|
log_error (_("key \"%s\" not found: %s\n"),uname, g10_errstr (rc));
|
2002-06-29 15:46:34 +02:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = keydb_get_keyblock (kdbhd, &keyblock );
|
|
|
|
if( rc ) {
|
|
|
|
log_error (_("error reading keyblock: %s\n"), g10_errstr(rc) );
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* To parse the revkeys */
|
|
|
|
merge_keys_and_selfsig(keyblock);
|
|
|
|
|
|
|
|
/* get the key from the keyblock */
|
|
|
|
node = find_kbnode( keyblock, PKT_PUBLIC_KEY );
|
|
|
|
if( !node )
|
|
|
|
BUG ();
|
|
|
|
|
|
|
|
pk=node->pkt->pkt.public_key;
|
|
|
|
|
|
|
|
keyid_from_pk(pk,keyid);
|
|
|
|
|
2005-11-19 06:55:45 +01:00
|
|
|
if(locusr)
|
|
|
|
{
|
|
|
|
rc=build_sk_list(locusr,&sk_list,0,PUBKEY_USAGE_CERT);
|
|
|
|
if(rc)
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/* Are we a designated revoker for this key? */
|
|
|
|
|
|
|
|
if(!pk->revkey && pk->numrevkeys)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
for(i=0;i<pk->numrevkeys;i++)
|
|
|
|
{
|
2005-11-19 06:55:45 +01:00
|
|
|
SK_LIST list;
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if(sk)
|
|
|
|
free_secret_key(sk);
|
|
|
|
|
2005-11-19 06:55:45 +01:00
|
|
|
if(sk_list)
|
|
|
|
{
|
|
|
|
for(list=sk_list;list;list=list->next)
|
|
|
|
{
|
|
|
|
byte fpr[MAX_FINGERPRINT_LEN];
|
|
|
|
size_t fprlen;
|
|
|
|
|
|
|
|
fingerprint_from_sk(list->sk,fpr,&fprlen);
|
|
|
|
|
|
|
|
/* Don't get involved with keys that don't have 160
|
|
|
|
bit fingerprints */
|
|
|
|
if(fprlen!=20)
|
|
|
|
continue;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-11-19 06:55:45 +01:00
|
|
|
if(memcmp(fpr,pk->revkey[i].fpr,20)==0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(list)
|
|
|
|
sk=copy_secret_key(NULL,list->sk);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sk=xmalloc_secure_clear(sizeof(*sk));
|
|
|
|
rc=get_seckey_byfprint(sk,pk->revkey[i].fpr,MAX_FINGERPRINT_LEN);
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
/* We have the revocation key */
|
|
|
|
if(!rc)
|
|
|
|
{
|
2002-10-18 17:41:33 +02:00
|
|
|
PKT_signature *revkey = NULL;
|
|
|
|
|
|
|
|
any = 1;
|
|
|
|
|
2003-10-02 12:20:12 +02:00
|
|
|
print_pubkey_info (NULL, pk);
|
2002-10-18 17:41:33 +02:00
|
|
|
tty_printf ("\n");
|
|
|
|
|
|
|
|
tty_printf (_("To be revoked by:\n"));
|
|
|
|
print_seckey_info (sk);
|
|
|
|
|
2002-07-19 07:08:54 +02:00
|
|
|
if(pk->revkey[i].class&0x40)
|
|
|
|
tty_printf(_("(This is a sensitive revocation key)\n"));
|
|
|
|
tty_printf("\n");
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
if( !cpr_get_answer_is_yes("gen_desig_revoke.okay",
|
2004-10-10 17:27:14 +02:00
|
|
|
_("Create a designated revocation certificate for this key? (y/N) ")))
|
2002-06-29 15:46:34 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* get the reason for the revocation (this is always v4) */
|
|
|
|
reason = ask_revocation_reason( 1, 0, 1 );
|
|
|
|
if( !reason )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rc = check_secret_key( sk, 0 );
|
|
|
|
if( rc )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !opt.armor )
|
|
|
|
tty_printf(_("ASCII armored output forced.\n"));
|
|
|
|
|
|
|
|
if( (rc = open_outfile( NULL, 0, &out )) )
|
|
|
|
goto leave;
|
|
|
|
|
|
|
|
afx.what = 1;
|
2005-11-19 06:55:45 +01:00
|
|
|
afx.hdrlines = "Comment: A designated revocation certificate"
|
|
|
|
" should follow\n";
|
2002-06-29 15:46:34 +02:00
|
|
|
iobuf_push_filter( out, armor_filter, &afx );
|
|
|
|
|
|
|
|
/* create it */
|
|
|
|
rc = make_keysig_packet( &sig, pk, NULL, NULL, sk, 0x20, 0,
|
|
|
|
0, 0, 0,
|
|
|
|
revocation_reason_build_cb, reason );
|
|
|
|
if( rc ) {
|
|
|
|
log_error(_("make_keysig_packet failed: %s\n"), g10_errstr(rc));
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Spit out a minimal pk as well, since otherwise there is
|
2002-08-06 18:58:58 +02:00
|
|
|
no way to know which key to attach this revocation to.
|
|
|
|
Also include the direct key signature that contains
|
|
|
|
this revocation key. We're allowed to include
|
|
|
|
sensitive revocation keys along with a revocation, as
|
|
|
|
this may be the only time the recipient has seen it.
|
|
|
|
Note that this means that if we have multiple different
|
|
|
|
sensitive revocation keys in a given direct key
|
|
|
|
signature, we're going to include them all here. This
|
|
|
|
is annoying, but the good outweighs the bad, since
|
|
|
|
without including this a sensitive revoker can't really
|
|
|
|
do their job. People should not include multiple
|
|
|
|
sensitive revocation keys in one signature: 2440 says
|
|
|
|
"Note that it may be appropriate to isolate this
|
|
|
|
subpacket within a separate signature so that it is not
|
|
|
|
combined with other subpackets that need to be
|
|
|
|
exported." -dms */
|
|
|
|
|
|
|
|
while(!revkey)
|
2002-07-19 07:08:54 +02:00
|
|
|
{
|
|
|
|
KBNODE signode;
|
|
|
|
|
|
|
|
signode=find_next_kbnode(node,PKT_SIGNATURE);
|
|
|
|
if(!signode)
|
|
|
|
break;
|
|
|
|
|
|
|
|
node=signode;
|
|
|
|
|
|
|
|
if(keyid[0]==signode->pkt->pkt.signature->keyid[0] &&
|
|
|
|
keyid[1]==signode->pkt->pkt.signature->keyid[1] &&
|
|
|
|
IS_KEY_SIG(signode->pkt->pkt.signature))
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for(j=0;j<signode->pkt->pkt.signature->numrevkeys;j++)
|
|
|
|
{
|
|
|
|
if(pk->revkey[i].class==
|
|
|
|
signode->pkt->pkt.signature->revkey[j]->class &&
|
|
|
|
pk->revkey[i].algid==
|
|
|
|
signode->pkt->pkt.signature->revkey[j]->algid &&
|
|
|
|
memcmp(pk->revkey[i].fpr,
|
|
|
|
signode->pkt->pkt.signature->revkey[j]->fpr,
|
|
|
|
MAX_FINGERPRINT_LEN)==0)
|
|
|
|
{
|
2002-08-06 18:58:58 +02:00
|
|
|
revkey=signode->pkt->pkt.signature;
|
2002-07-19 07:08:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-06 18:58:58 +02:00
|
|
|
if(!revkey)
|
2002-07-19 07:08:54 +02:00
|
|
|
BUG();
|
|
|
|
|
2002-08-06 18:58:58 +02:00
|
|
|
rc=export_minimal_pk(out,keyblock,sig,revkey);
|
|
|
|
if(rc)
|
2002-06-29 15:46:34 +02:00
|
|
|
goto leave;
|
|
|
|
|
|
|
|
/* and issue a usage notice */
|
|
|
|
tty_printf(_("Revocation certificate created.\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!any)
|
2004-10-28 03:58:01 +02:00
|
|
|
log_error(_("no revocation keys found for \"%s\"\n"),uname);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
leave:
|
|
|
|
if( pk )
|
|
|
|
free_public_key( pk );
|
|
|
|
if( sk )
|
|
|
|
free_secret_key( sk );
|
|
|
|
if( sig )
|
|
|
|
free_seckey_enc( sig );
|
|
|
|
|
2005-11-19 06:55:45 +01:00
|
|
|
release_sk_list(sk_list);
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if( rc )
|
|
|
|
iobuf_cancel(out);
|
|
|
|
else
|
|
|
|
iobuf_close(out);
|
|
|
|
release_revocation_reason_info( reason );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-16 21:05:02 +01:00
|
|
|
/****************
|
|
|
|
* Generate a revocation certificate for UNAME
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gen_revoke( const char *uname )
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
armor_filter_context_t afx;
|
|
|
|
PACKET pkt;
|
1998-06-29 14:30:57 +02:00
|
|
|
PKT_secret_key *sk; /* used as pointer into a kbnode */
|
|
|
|
PKT_public_key *pk = NULL;
|
1998-02-16 21:05:02 +01:00
|
|
|
PKT_signature *sig = NULL;
|
1998-06-29 14:30:57 +02:00
|
|
|
u32 sk_keyid[2];
|
1998-02-16 21:05:02 +01:00
|
|
|
IOBUF out = NULL;
|
2002-08-06 18:58:58 +02:00
|
|
|
KBNODE keyblock = NULL, pub_keyblock = NULL;
|
1998-02-16 21:05:02 +01:00
|
|
|
KBNODE node;
|
2002-06-29 15:46:34 +02:00
|
|
|
KEYDB_HANDLE kdbhd;
|
2000-07-14 19:34:53 +02:00
|
|
|
struct revocation_reason_info *reason = NULL;
|
2002-06-29 15:46:34 +02:00
|
|
|
KEYDB_SEARCH_DESC desc;
|
1998-02-16 21:05:02 +01:00
|
|
|
|
2004-10-28 05:57:30 +02:00
|
|
|
if( opt.batch )
|
|
|
|
{
|
|
|
|
log_error(_("can't do this in batch mode\n"));
|
2002-06-29 15:46:34 +02:00
|
|
|
return G10ERR_GENERAL;
|
2004-10-28 05:57:30 +02:00
|
|
|
}
|
1998-02-16 21:05:02 +01:00
|
|
|
|
|
|
|
memset( &afx, 0, sizeof afx);
|
|
|
|
init_packet( &pkt );
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/* search the userid:
|
|
|
|
* We don't want the whole getkey stuff here but the entire keyblock
|
|
|
|
*/
|
|
|
|
kdbhd = keydb_new (1);
|
|
|
|
classify_user_id (uname, &desc);
|
|
|
|
rc = desc.mode? keydb_search (kdbhd, &desc, 1) : G10ERR_INV_USER_ID;
|
2004-10-28 03:58:01 +02:00
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
log_error (_("secret key \"%s\" not found: %s\n"),
|
2002-06-29 15:46:34 +02:00
|
|
|
uname, g10_errstr (rc));
|
|
|
|
goto leave;
|
2004-10-28 03:58:01 +02:00
|
|
|
}
|
1998-02-16 21:05:02 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
rc = keydb_get_keyblock (kdbhd, &keyblock );
|
1998-02-16 21:05:02 +01:00
|
|
|
if( rc ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
log_error (_("error reading keyblock: %s\n"), g10_errstr(rc) );
|
1998-02-16 21:05:02 +01:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the keyid from the keyblock */
|
1998-06-29 14:30:57 +02:00
|
|
|
node = find_kbnode( keyblock, PKT_SECRET_KEY );
|
2002-06-29 15:46:34 +02:00
|
|
|
if( !node )
|
|
|
|
BUG ();
|
1998-02-16 21:05:02 +01:00
|
|
|
|
1998-04-02 12:30:03 +02:00
|
|
|
/* fixme: should make a function out of this stuff,
|
1998-02-16 21:05:02 +01:00
|
|
|
* it's used all over the source */
|
1998-06-29 14:30:57 +02:00
|
|
|
sk = node->pkt->pkt.secret_key;
|
|
|
|
keyid_from_sk( sk, sk_keyid );
|
2002-10-18 17:41:33 +02:00
|
|
|
print_seckey_info (sk);
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/* FIXME: We should get the public key direct from the secret one */
|
2002-08-06 18:58:58 +02:00
|
|
|
|
|
|
|
pub_keyblock=get_pubkeyblock(sk_keyid);
|
|
|
|
if(!pub_keyblock)
|
|
|
|
{
|
2002-06-29 15:46:34 +02:00
|
|
|
log_error(_("no corresponding public key: %s\n"), g10_errstr(rc) );
|
1998-02-16 21:05:02 +01:00
|
|
|
goto leave;
|
2002-08-06 18:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
node=find_kbnode(pub_keyblock,PKT_PUBLIC_KEY);
|
|
|
|
if(!node)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
pk=node->pkt->pkt.public_key;
|
|
|
|
|
1998-06-29 14:30:57 +02:00
|
|
|
if( cmp_public_secret_key( pk, sk ) ) {
|
1998-10-12 22:16:38 +02:00
|
|
|
log_error(_("public key does not match secret key!\n") );
|
2002-06-29 15:46:34 +02:00
|
|
|
rc = G10ERR_GENERAL;
|
1998-02-16 21:05:02 +01:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
tty_printf("\n");
|
1998-11-27 12:42:49 +01:00
|
|
|
if( !cpr_get_answer_is_yes("gen_revoke.okay",
|
2004-10-10 17:27:14 +02:00
|
|
|
_("Create a revocation certificate for this key? (y/N) ")) )
|
|
|
|
{
|
1998-02-16 21:05:02 +01:00
|
|
|
rc = 0;
|
|
|
|
goto leave;
|
2004-10-10 17:27:14 +02:00
|
|
|
}
|
1998-02-16 21:05:02 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if(sk->version>=4 || opt.force_v4_certs) {
|
|
|
|
/* get the reason for the revocation */
|
|
|
|
reason = ask_revocation_reason( 1, 0, 1 );
|
|
|
|
if( !reason ) { /* user decided to cancel */
|
2000-07-14 19:34:53 +02:00
|
|
|
rc = 0;
|
|
|
|
goto leave;
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2000-07-14 19:34:53 +02:00
|
|
|
}
|
|
|
|
|
1998-06-29 14:30:57 +02:00
|
|
|
switch( is_secret_key_protected( sk ) ) {
|
1998-02-16 21:05:02 +01:00
|
|
|
case -1:
|
1998-10-12 22:16:38 +02:00
|
|
|
log_error(_("unknown protection algorithm\n"));
|
2002-06-29 15:46:34 +02:00
|
|
|
rc = G10ERR_PUBKEY_ALGO;
|
1998-02-16 21:05:02 +01:00
|
|
|
break;
|
2005-08-04 11:53:21 +02:00
|
|
|
case -3:
|
|
|
|
tty_printf (_("Secret parts of primary key are not available.\n"));
|
|
|
|
rc = G10ERR_NO_SECKEY;
|
|
|
|
break;
|
1998-02-16 21:05:02 +01:00
|
|
|
case 0:
|
1998-11-10 13:59:59 +01:00
|
|
|
tty_printf(_("NOTE: This key is not protected!\n"));
|
1998-02-16 21:05:02 +01:00
|
|
|
break;
|
|
|
|
default:
|
2005-08-04 11:53:21 +02:00
|
|
|
rc = check_secret_key( sk, 0 );
|
1998-02-16 21:05:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( rc )
|
|
|
|
goto leave;
|
|
|
|
|
|
|
|
|
|
|
|
if( !opt.armor )
|
1998-10-12 22:16:38 +02:00
|
|
|
tty_printf(_("ASCII armored output forced.\n"));
|
1998-02-16 21:05:02 +01:00
|
|
|
|
1998-08-11 19:29:34 +02:00
|
|
|
if( (rc = open_outfile( NULL, 0, &out )) )
|
1998-02-16 21:05:02 +01:00
|
|
|
goto leave;
|
|
|
|
|
|
|
|
afx.what = 1;
|
1998-02-18 14:58:46 +01:00
|
|
|
afx.hdrlines = "Comment: A revocation certificate should follow\n";
|
1998-02-16 21:05:02 +01:00
|
|
|
iobuf_push_filter( out, armor_filter, &afx );
|
|
|
|
|
|
|
|
/* create it */
|
2000-07-14 19:34:53 +02:00
|
|
|
rc = make_keysig_packet( &sig, pk, NULL, NULL, sk, 0x20, 0,
|
2002-06-29 15:46:34 +02:00
|
|
|
opt.force_v4_certs?4:0, 0, 0,
|
|
|
|
revocation_reason_build_cb, reason );
|
1998-02-16 21:05:02 +01:00
|
|
|
if( rc ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
log_error(_("make_keysig_packet failed: %s\n"), g10_errstr(rc));
|
1998-02-16 21:05:02 +01:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
* packet.h, build-packet.c (build_sig_subpkt), export.c
(do_export_stream), import.c (remove_bad_stuff, import), parse-packet.c
(dump_sig_subpkt, parse_one_sig_subpkt): Remove vestigal code for the old
sig cache subpacket. This wasn't completely harmless as it caused
subpacket 101 to disappear on import and export.
* options.h, armor.c, cipher.c, g10.c, keyedit.c, pkclist.c, sign.c,
encode.c, getkey.c, revoke.c: The current flags for different levels of
PGP-ness are massively complex. This is step one in simplifying them. No
functional change yet, just use a macro to check for compliance level.
* sign.c (sign_file): Fix bug that causes spurious compression preference
warning.
* sign.c (clearsign_file): Fix bug that prevents proper warning message
from appearing when clearsigning in --pgp2 mode with a non-v3 RSA key.
* main.h, misc.c (compliance_option_string, compliance_string,
compliance_failure), pkclist.c (build_pk_list), sign.c (sign_file,
clearsign_file), encode.c (encode_crypt, write_pubkey_enc_from_list): New
functions to put the "this message may not be usable...." warning in one
place.
* options.h, g10.c (main): Part two of the simplification. Use a single
enum to indicate what we are compliant to (1991, 2440, PGPx, etc.)
* g10.c (main): Show errors for failure in export, send-keys, recv-keys,
and refresh-keys.
* options.h, g10.c (main): Give algorithm warnings for algorithms chosen
against the --pgpX and --openpgp rules.
* keydb.h, pkclist.c (algo_available): Make TIGER192 invalid in --openpgp
mode.
* sign.c (sign_file), pkclist.c (algo_available): Allow passing a hint of
0.
2003-05-03 06:07:45 +02:00
|
|
|
if(PGP2 || PGP6 || PGP7 || PGP8)
|
2002-08-06 18:58:58 +02:00
|
|
|
{
|
2002-10-03 00:01:29 +02:00
|
|
|
/* Use a minimal pk for PGPx mode, since PGP can't import bare
|
|
|
|
revocation certificates. */
|
|
|
|
rc=export_minimal_pk(out,pub_keyblock,sig,NULL);
|
2002-08-06 18:58:58 +02:00
|
|
|
if(rc)
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
init_packet( &pkt );
|
|
|
|
pkt.pkttype = PKT_SIGNATURE;
|
|
|
|
pkt.pkt.signature = sig;
|
|
|
|
|
|
|
|
rc = build_packet( out, &pkt );
|
|
|
|
if( rc ) {
|
|
|
|
log_error(_("build_packet failed: %s\n"), g10_errstr(rc) );
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
}
|
1998-02-16 21:05:02 +01:00
|
|
|
|
|
|
|
/* and issue a usage notice */
|
1998-10-12 22:16:38 +02:00
|
|
|
tty_printf(_("Revocation certificate created.\n\n"
|
1998-04-14 19:51:16 +02:00
|
|
|
"Please move it to a medium which you can hide away; if Mallory gets\n"
|
1998-02-16 21:05:02 +01:00
|
|
|
"access to this certificate he can use it to make your key unusable.\n"
|
1998-04-14 19:51:16 +02:00
|
|
|
"It is smart to print this certificate and store it away, just in case\n"
|
|
|
|
"your media become unreadable. But have some caution: The print system of\n"
|
1998-10-12 22:16:38 +02:00
|
|
|
"your machine might store the data and make it available to others!\n"));
|
1998-02-16 21:05:02 +01:00
|
|
|
|
|
|
|
leave:
|
|
|
|
if( sig )
|
|
|
|
free_seckey_enc( sig );
|
|
|
|
release_kbnode( keyblock );
|
2002-08-06 18:58:58 +02:00
|
|
|
release_kbnode( pub_keyblock );
|
2002-06-29 15:46:34 +02:00
|
|
|
keydb_release (kdbhd);
|
1998-02-16 21:05:02 +01:00
|
|
|
if( rc )
|
|
|
|
iobuf_cancel(out);
|
|
|
|
else
|
|
|
|
iobuf_close(out);
|
2000-07-14 19:34:53 +02:00
|
|
|
release_revocation_reason_info( reason );
|
1998-02-16 21:05:02 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1999-04-26 17:53:01 +02:00
|
|
|
|
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
struct revocation_reason_info *
|
|
|
|
ask_revocation_reason( int key_rev, int cert_rev, int hint )
|
1999-04-26 17:53:01 +02:00
|
|
|
{
|
2002-06-29 15:46:34 +02:00
|
|
|
int code=-1;
|
2000-07-14 19:34:53 +02:00
|
|
|
char *description = NULL;
|
|
|
|
struct revocation_reason_info *reason;
|
2002-06-29 15:46:34 +02:00
|
|
|
const char *text_0 = _("No reason specified");
|
2000-07-14 19:34:53 +02:00
|
|
|
const char *text_1 = _("Key has been compromised");
|
|
|
|
const char *text_2 = _("Key is superseded");
|
|
|
|
const char *text_3 = _("Key is no longer used");
|
2002-06-29 15:46:34 +02:00
|
|
|
const char *text_4 = _("User ID is no longer valid");
|
2000-07-14 19:34:53 +02:00
|
|
|
const char *code_text = NULL;
|
|
|
|
|
|
|
|
do {
|
* trustdb.h, trustdb.c (is_disabled), gpgv.c (is_disabled): Rename
is_disabled to cache_disabled_value, which now takes a pk and not just the
keyid. This is for speed since there is no need to re-fetch a key when we
already have that key handy. Cache the result of the check so we don't
need to hit the trustdb more than once.
* getkey.c (skip_disabled): New function to get a pk and call is_disabled
on it. (key_byname): Use it here.
* packet.h, getkey.c (skip_disabled), keylist.c (print_capabilities): New
"pk_is_disabled" macro to retrieve the cached disabled value if available,
and fill it in via cache_disabled_value if not available.
* trustdb.c (get_validity): Cache the disabled value since we have it
handy and it might be useful later.
* parse-packet.c (parse_key): Clear disabled flag when parsing a new key.
Just in case someone forgets to clear the whole key.
* getkey.c (merge_selfsigs_main): Add an "if all else fails" path for
setting a single user ID primary when there are multiple set primaries all
at the same second, or no primaries set and the most recent user IDs are
at the same second, or no signed user IDs at all. This is arbitrary, but
deterministic.
* exec.h, photoid.h: Add copyright message.
* keylist.c (list_keyblock_print): Don't dump attribs for
revoked/expired/etc uids for non-colon key listings. This is for
consistency with --show-photos.
* main.h, keylist.c (dump_attribs), mainproc.c (check_sig_and_print): Dump
attribs if --attrib-fd is set when verifying signatures.
* g10.c (main): New --gnupg option to disable the various --openpgp,
--pgpX, etc. options. This is the same as --no-XXXX for those options.
* revoke.c (ask_revocation_reason): Clear old reason if user elects to
repeat question. This is bug 153.
* keyedit.c (sign_uids): Show keyid of the key making the signature.
2003-05-21 18:42:22 +02:00
|
|
|
code=-1;
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(description);
|
2000-07-14 19:34:53 +02:00
|
|
|
description = NULL;
|
|
|
|
|
|
|
|
tty_printf(_("Please select the reason for the revocation:\n"));
|
2002-06-29 15:46:34 +02:00
|
|
|
tty_printf( " 0 = %s\n", text_0 );
|
2000-07-14 19:34:53 +02:00
|
|
|
if( key_rev )
|
|
|
|
tty_printf(" 1 = %s\n", text_1 );
|
|
|
|
if( key_rev )
|
|
|
|
tty_printf(" 2 = %s\n", text_2 );
|
|
|
|
if( key_rev )
|
|
|
|
tty_printf(" 3 = %s\n", text_3 );
|
|
|
|
if( cert_rev )
|
|
|
|
tty_printf(" 4 = %s\n", text_4 );
|
2002-06-29 15:46:34 +02:00
|
|
|
tty_printf( " Q = %s\n", _("Cancel") );
|
2000-07-14 19:34:53 +02:00
|
|
|
if( hint )
|
|
|
|
tty_printf(_("(Probably you want to select %d here)\n"), hint );
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
while(code==-1) {
|
2000-07-14 19:34:53 +02:00
|
|
|
int n;
|
|
|
|
char *answer = cpr_get("ask_revocation_reason.code",
|
|
|
|
_("Your decision? "));
|
|
|
|
trim_spaces( answer );
|
|
|
|
cpr_kill_prompt();
|
2002-06-29 15:46:34 +02:00
|
|
|
if( *answer == 'q' || *answer == 'Q')
|
|
|
|
return NULL; /* cancel */
|
|
|
|
if( hint && !*answer )
|
2000-07-14 19:34:53 +02:00
|
|
|
n = hint;
|
* parse-packet.c (parse_signature): No need to reserve 8 bytes for the
unhashed signature cache any longer.
* misc.c (pct_expando): Add two new expandos - signer's fingerprint (%g),
and signer's primary fingerprint (%p).
* Makefile.am: Include W32LIBS where appropriate.
* g10.c (main): Add --rfc2440 alias for --openpgp since in a few months,
they won't be the same thing.
* keyserver.c (parse_keyserver_uri): Accept "http" as an alias for "hkp",
since it is occasionally written that way. (keyserver_spawn): Use
ascii_isspace to avoid locale issues.
* keygen.c (ask_user_id): Make --allow-freeform-uid apply to the email
field as well as the name field, and allow mixing fields when it is set.
* options.skel: Use subkeys.pgp.net as the default keyserver.
* trustdb.c (validate_one_keyblock): Certifications on revoked or expired
uids do not count in the web of trust.
* signal.c (init_one_signal, pause_on_sigusr, do_block): Only use
sigprocmask() if we have sigset_t, and only use sigaction() if we have
struct sigaction. This is for Forte c89 on Solaris which seems to define
only the function call half of the two pairs by default.
(pause_on_sigusr): Typo. (do_block): If we can't use sigprocmask() and
sigset_t, try to get the number of signals from NSIG as well as MAXSIG,
and if we can't, fail with an explanation.
* signal.c, tdbio.c: Comment out the transaction code. It was not used in
this version, and was causing some build problems on quasi-posix platforms
(Solaris and Forte c89).
* keylist.c (list_keyblock_colon): Don't include validity values when
listing secret keys since they can be incorrect and/or misleading. This
is a temporary kludge, and will be handled properly in 1.9/2.0.
* mainproc.c (check_sig_and_print): Only show the "key available from"
preferred keyserver line if the key is not currently present.
* keyedit.c (sign_uids): Do not sign expired uids without --expert (same
behavior as revoked uids). Do not allow signing a user ID without a
self-signature. --expert overrides. Add additional prompt to the
signature level question. (menu_expire): When changing expiration dates,
don't replace selfsigs on revoked uids since this would effectively
unrevoke them. There is also no point in replacing expired selfsigs.
This is bug #181
* g10.c (add_notation_data): Make sure that only ascii is passed to
iscntrl. Noted by Christian Biere.
* getkey.c (classify_user_id2): Replaced isspace by spacep
* keygen.c (ask_user_id): Ditto. (get_parameter_algo): Ditto.
* keyedit.c (keyedit_menu): Ditto.
* tdbdump.c (import_ownertrust): Ditto. s/isxdigit/hexdigitp/.
* revoke.c (ask_revocation_reason):
* keyserver.c (keyserver_spawn): Dito.
2003-07-10 16:30:07 +02:00
|
|
|
else if(!digitp( answer ) )
|
2002-06-29 15:46:34 +02:00
|
|
|
n = -1;
|
2000-07-14 19:34:53 +02:00
|
|
|
else
|
|
|
|
n = atoi(answer);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(answer);
|
2002-06-29 15:46:34 +02:00
|
|
|
if( n == 0 ) {
|
|
|
|
code = 0x00; /* no particular reason */
|
|
|
|
code_text = text_0;
|
|
|
|
}
|
2000-07-14 19:34:53 +02:00
|
|
|
else if( key_rev && n == 1 ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
code = 0x02; /* key has been compromised */
|
2000-07-14 19:34:53 +02:00
|
|
|
code_text = text_1;
|
|
|
|
}
|
|
|
|
else if( key_rev && n == 2 ) {
|
|
|
|
code = 0x01; /* key is superseded */
|
|
|
|
code_text = text_2;
|
|
|
|
}
|
|
|
|
else if( key_rev && n == 3 ) {
|
|
|
|
code = 0x03; /* key is no longer used */
|
|
|
|
code_text = text_3;
|
|
|
|
}
|
|
|
|
else if( cert_rev && n == 4 ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
code = 0x20; /* uid is no longer valid */
|
2000-07-14 19:34:53 +02:00
|
|
|
code_text = text_4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tty_printf(_("Invalid selection.\n"));
|
|
|
|
}
|
1999-04-26 17:53:01 +02:00
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
tty_printf(_("Enter an optional description; "
|
|
|
|
"end it with an empty line:\n") );
|
|
|
|
for(;;) {
|
|
|
|
char *answer = cpr_get("ask_revocation_reason.text", "> " );
|
|
|
|
trim_trailing_ws( answer, strlen(answer) );
|
|
|
|
cpr_kill_prompt();
|
|
|
|
if( !*answer ) {
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(answer);
|
2000-07-14 19:34:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
char *p = make_printable_string( answer, strlen(answer), 0 );
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(answer);
|
2000-07-14 19:34:53 +02:00
|
|
|
answer = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !description )
|
2005-07-27 20:10:56 +02:00
|
|
|
description = xstrdup(answer);
|
2000-07-14 19:34:53 +02:00
|
|
|
else {
|
2005-07-27 20:10:56 +02:00
|
|
|
char *p = xmalloc( strlen(description) + strlen(answer) + 2 );
|
2000-07-14 19:34:53 +02:00
|
|
|
strcpy(stpcpy(stpcpy( p, description),"\n"),answer);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(description);
|
2000-07-14 19:34:53 +02:00
|
|
|
description = p;
|
|
|
|
}
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(answer);
|
1999-04-26 17:53:01 +02:00
|
|
|
}
|
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
tty_printf(_("Reason for revocation: %s\n"), code_text );
|
|
|
|
if( !description )
|
|
|
|
tty_printf(_("(No description given)\n") );
|
|
|
|
else
|
|
|
|
tty_printf("%s\n", description );
|
1999-04-26 17:53:01 +02:00
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
} while( !cpr_get_answer_is_yes("ask_revocation_reason.okay",
|
2004-10-10 17:27:14 +02:00
|
|
|
_("Is this okay? (y/N) ")) );
|
1999-04-26 17:53:01 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
reason = xmalloc( sizeof *reason );
|
2000-07-14 19:34:53 +02:00
|
|
|
reason->code = code;
|
|
|
|
reason->desc = description;
|
|
|
|
return reason;
|
|
|
|
}
|
1999-04-26 17:53:01 +02:00
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
void
|
|
|
|
release_revocation_reason_info( struct revocation_reason_info *reason )
|
|
|
|
{
|
|
|
|
if( reason ) {
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree( reason->desc );
|
|
|
|
xfree( reason );
|
1999-04-26 17:53:01 +02:00
|
|
|
}
|
|
|
|
}
|