1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-10-31 20:08:43 +01:00
gnupg/g10/mainproc.c

1293 lines
34 KiB
C
Raw Normal View History

/* mainproc.c - handle packets
* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
1997-11-18 15:06:00 +01:00
*
* This file is part of GnuPG.
1997-11-18 15:06:00 +01:00
*
* GnuPG is free software; you can redistribute it and/or modify
1997-11-18 15:06:00 +01:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GnuPG is distributed in the hope that it will be useful,
1997-11-18 15:06:00 +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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
1998-03-09 22:44:06 +01:00
#include <string.h>
1997-12-01 11:33:23 +01:00
#include <assert.h>
1998-05-29 13:53:54 +02:00
#include <time.h>
1997-11-18 15:06:00 +01:00
#include <gcrypt.h>
1997-11-18 15:06:00 +01:00
#include "packet.h"
#include "iobuf.h"
#include "options.h"
#include "util.h"
#include "keydb.h"
1997-11-24 12:04:11 +01:00
#include "filter.h"
1997-11-24 23:24:04 +01:00
#include "main.h"
1998-01-30 17:23:16 +01:00
#include "status.h"
1998-05-29 13:53:54 +02:00
#include "i18n.h"
#include "trustdb.h"
#include "hkp.h"
1997-11-27 12:44:13 +01:00
struct kidlist_item {
struct kidlist_item *next;
u32 kid[2];
int pubkey_algo;
int reason;
};
1997-12-01 11:33:23 +01:00
/****************
* Structure to hold the context
*/
typedef struct mainproc_context *CTX;
struct mainproc_context {
struct mainproc_context *anchor; /* may be useful in the future */
1998-06-29 14:30:57 +02:00
PKT_public_key *last_pubkey;
PKT_secret_key *last_seckey;
1997-11-27 12:44:13 +01:00
PKT_user_id *last_user_id;
md_filter_context_t mfx;
1998-03-09 22:44:06 +01:00
int sigs_only; /* process only signatures and reject all other stuff */
1998-04-14 19:51:16 +02:00
int encrypt_only; /* process only encrytion messages */
1998-03-09 22:44:06 +01:00
STRLIST signed_data;
1998-07-14 19:10:28 +02:00
const char *sigfilename;
1997-11-27 12:44:13 +01:00
DEK *dek;
1998-05-03 17:42:08 +02:00
int last_was_session_key;
1998-02-17 21:48:52 +01:00
KBNODE list; /* the current list of packets */
1997-12-03 11:20:03 +01:00
int have_data;
IOBUF iobuf; /* used to get the filename etc. */
1998-05-29 13:53:54 +02:00
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 */
};
1997-11-27 12:44:13 +01:00
1998-03-09 22:44:06 +01:00
static int do_proc_packets( CTX c, IOBUF a );
1997-11-27 12:44:13 +01:00
1997-12-12 13:03:58 +01:00
static void list_node( CTX c, KBNODE node );
static void proc_tree( CTX c, KBNODE node );
1997-12-01 11:33:23 +01:00
1997-11-26 23:02:28 +01:00
static void
1998-02-17 21:48:52 +01:00
release_list( CTX c )
1997-11-26 23:02:28 +01:00
{
1998-02-17 21:48:52 +01:00
if( !c->list )
1997-12-01 11:33:23 +01:00
return;
1998-02-17 21:48:52 +01:00
proc_tree(c, c->list );
release_kbnode( c->list );
while( c->failed_pkenc ) {
struct kidlist_item *tmp = c->failed_pkenc->next;
gcry_free( c->failed_pkenc );
c->failed_pkenc = tmp;
}
c->failed_pkenc = NULL;
1998-02-17 21:48:52 +01:00
c->list = NULL;
1997-11-26 23:02:28 +01:00
}
1997-12-02 20:36:53 +01:00
static int
add_onepass_sig( CTX c, PACKET *pkt )
{
1997-12-12 13:03:58 +01:00
KBNODE node;
1997-12-03 11:20:03 +01:00
1998-02-17 21:48:52 +01:00
if( c->list ) { /* add another packet */
if( c->list->pkt->pkttype != PKT_ONEPASS_SIG ) {
1997-12-02 20:36:53 +01:00
log_error("add_onepass_sig: another packet is in the way\n");
1998-02-17 21:48:52 +01:00
release_list( c );
1998-09-28 21:25:31 +02:00
c->list = new_kbnode( pkt );
1997-12-02 20:36:53 +01:00
}
1998-09-28 21:25:31 +02:00
else
add_kbnode( c->list, new_kbnode( pkt ));
1997-12-02 20:36:53 +01:00
}
else /* insert the first one */
1998-02-17 21:48:52 +01:00
c->list = node = new_kbnode( pkt );
1997-12-03 11:20:03 +01:00
1997-12-02 20:36:53 +01:00
return 1;
}
1997-12-01 11:33:23 +01:00
static int
1998-04-02 12:30:03 +02:00
add_user_id( CTX c, PACKET *pkt )
1997-12-01 11:33:23 +01:00
{
1998-04-02 12:30:03 +02:00
if( !c->list ) {
log_error("orphaned user ID\n" );
1998-04-02 12:30:03 +02:00
return 0;
}
add_kbnode( c->list, new_kbnode( pkt ) );
1997-12-01 11:33:23 +01:00
return 1;
}
static int
1998-04-02 12:30:03 +02:00
add_subkey( CTX c, PACKET *pkt )
1997-11-27 12:44:13 +01:00
{
1998-02-17 21:48:52 +01:00
if( !c->list ) {
1998-04-02 12:30:03 +02:00
log_error("subkey w/o mainkey\n" );
1997-12-01 11:33:23 +01:00
return 0;
1997-11-27 12:44:13 +01:00
}
1998-02-17 21:48:52 +01:00
add_kbnode( c->list, new_kbnode( pkt ) );
1997-12-01 11:33:23 +01:00
return 1;
1997-11-27 12:44:13 +01:00
}
static int
add_ring_trust( CTX c, PACKET *pkt )
{
if( !c->list ) {
log_error("ring trust w/o key\n" );
return 0;
}
add_kbnode( c->list, new_kbnode( pkt ) );
return 1;
}
1997-11-27 12:44:13 +01:00
1997-12-01 11:33:23 +01:00
static int
add_signature( CTX c, PACKET *pkt )
1997-11-27 12:44:13 +01:00
{
1998-02-12 00:22:09 +01:00
KBNODE node;
1997-11-27 12:44:13 +01:00
1998-02-17 21:48:52 +01:00
if( pkt->pkttype == PKT_SIGNATURE && !c->list ) {
1998-04-14 19:51:16 +02:00
/* This is the first signature for the following datafile.
* GPG does not write such packets; instead it always uses
1998-01-30 17:23:16 +01:00
* onepass-sig packets. The drawback of PGP's method
1998-04-14 19:51:16 +02:00
* of prepending the signature to the data is
* that it is not possible to make a signature from data read
* from stdin. (GPG is able to read PGP stuff anyway.) */
1998-01-30 17:23:16 +01:00
node = new_kbnode( pkt );
1998-02-17 21:48:52 +01:00
c->list = node;
1998-01-30 17:23:16 +01:00
return 1;
1997-11-27 12:44:13 +01:00
}
1998-02-17 21:48:52 +01:00
else if( !c->list )
1998-02-12 00:22:09 +01:00
return 0; /* oops (invalid packet sequence)*/
1998-02-17 21:48:52 +01:00
else if( !c->list->pkt )
1998-02-12 00:22:09 +01:00
BUG(); /* so nicht */
1998-01-30 17:23:16 +01:00
1998-02-12 00:22:09 +01:00
/* add a new signature node id at the end */
1997-12-12 13:03:58 +01:00
node = new_kbnode( pkt );
1998-02-17 21:48:52 +01:00
add_kbnode( c->list, node );
1997-12-01 11:33:23 +01:00
return 1;
1997-11-27 12:44:13 +01:00
}
1998-05-03 17:42:08 +02:00
static void
proc_symkey_enc( CTX c, PACKET *pkt )
{
PKT_symkey_enc *enc;
enc = pkt->pkt.symkey_enc;
1998-05-04 20:49:26 +02:00
if( enc->seskeylen )
log_error( "symkey_enc packet with session keys are not supported!\n");
else {
c->last_was_session_key = 2;
c->dek = passphrase_to_dek( NULL, 0, enc->cipher_algo, &enc->s2k, 0 );
1998-05-03 17:42:08 +02:00
}
free_packet(pkt);
}
1997-11-27 12:44:13 +01:00
static void
proc_pubkey_enc( CTX c, PACKET *pkt )
{
PKT_pubkey_enc *enc;
int result = 0;
1998-08-05 18:51:59 +02:00
/* check whether the secret key is available and store in this case */
1998-05-03 17:42:08 +02:00
c->last_was_session_key = 1;
1997-11-27 12:44:13 +01:00
enc = pkt->pkt.pubkey_enc;
1998-01-02 21:40:10 +01:00
/*printf("enc: encrypted by a pubkey with keyid %08lX\n", enc->keyid[1] );*/
/* Hmmm: why do I have this algo check here - anyway there is
* function to check it. */
if( opt.verbose )
log_info(_("public key is %08lX\n"), (ulong)enc->keyid[1] );
if( is_status_enabled() ) {
char buf[50];
sprintf(buf, "%08lX%08lX %d 0",
(ulong)enc->keyid[0], (ulong)enc->keyid[1], enc->pubkey_algo );
write_status_text( STATUS_ENC_TO, buf );
}
1998-05-04 20:49:26 +02:00
if( is_ELGAMAL(enc->pubkey_algo)
|| enc->pubkey_algo == GCRY_PK_DSA
1998-05-04 20:49:26 +02:00
|| is_RSA(enc->pubkey_algo) ) {
if ( !c->dek && ((!enc->keyid[0] && !enc->keyid[1])
|| !seckey_available( enc->keyid )) ) {
if( opt.list_only )
result = -1;
else {
c->dek = gcry_xmalloc_secure( sizeof *c->dek );
if( (result = get_session_key( enc, c->dek )) ) {
/* error: delete the DEK */
gcry_free(c->dek); c->dek = NULL;
}
1998-10-25 20:00:01 +01:00
}
1997-11-27 12:44:13 +01:00
}
else
result = GPGERR_NO_SECKEY;
1997-11-27 12:44:13 +01:00
}
else
result = GPGERR_PUBKEY_ALGO;
1997-11-27 12:44:13 +01:00
if( result == -1 )
;
1998-01-02 21:40:10 +01:00
else if( !result ) {
if( opt.verbose > 1 )
log_info( _("public key encrypted data: good DEK\n") );
1998-01-02 21:40:10 +01:00
}
else { /* store it for later display */
struct kidlist_item *x = gcry_xmalloc( 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;
1998-05-29 13:53:54 +02:00
}
1997-11-27 12:44:13 +01:00
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 = gcry_xcalloc( 1, sizeof *pk );
const char *algstr = gcry_pk_algo_name( list->pubkey_algo );
if( !algstr )
algstr = "[?]";
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, '"' );
gcry_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 == GPGERR_NO_SECKEY ) {
log_info(_("no secret key for decryption available\n"));
if( is_status_enabled() ) {
char buf[20];
sprintf(buf,"%08lX%08lX", (ulong)list->kid[0],
(ulong)list->kid[1] );
write_status_text( STATUS_NO_SECKEY, buf );
}
}
else
log_error(_("public key decryption failed: %s\n"),
gpg_errstr(list->reason));
}
}
1997-11-27 12:44:13 +01:00
static void
1997-12-01 11:33:23 +01:00
proc_encrypted( CTX c, PACKET *pkt )
1997-11-27 12:44:13 +01:00
{
int result = 0;
print_failed_pkenc( c->failed_pkenc );
write_status( STATUS_BEGIN_DECRYPTION );
/*log_debug("dat: %sencrypted data\n", c->dek?"":"conventional ");*/
if( opt.list_only )
result = -1;
else if( !c->dek && !c->last_was_session_key ) {
/* assume this is old conventional encrypted data
* Actually we should use IDEA and MD5 in this case, but because
* IDEA is patented we can't do so */
c->dek = passphrase_to_dek( NULL, 0,
1998-08-05 18:51:59 +02:00
opt.def_cipher_algo ? opt.def_cipher_algo
: DEFAULT_CIPHER_ALGO, NULL, 0 );
1997-11-27 12:44:13 +01:00
}
else if( !c->dek )
result = GPGERR_NO_SECKEY;
1997-11-27 12:44:13 +01:00
if( !result )
result = decrypt_data( c, pkt->pkt.encrypted, c->dek );
gcry_free(c->dek); c->dek = NULL;
1997-11-27 12:44:13 +01:00
if( result == -1 )
;
1998-01-02 21:40:10 +01:00
else if( !result ) {
write_status( STATUS_DECRYPTION_OKAY );
1998-01-02 21:40:10 +01:00
if( opt.verbose > 1 )
1998-11-10 13:59:59 +01:00
log_info(_("decryption okay\n"));
if( pkt->pkt.encrypted->mdc_method )
write_status( STATUS_GOODMDC );
}
else if( result == GPGERR_BAD_SIGN ) {
log_error(_("WARNING: encrypted message has been manipulated!\n"));
write_status( STATUS_BADMDC );
1998-01-02 21:40:10 +01:00
}
else {
write_status( STATUS_DECRYPTION_FAILED );
log_error(_("decryption failed: %s\n"), gpg_errstr(result));
/* Hmmm: does this work when we have encrypted using multiple
* ways to specify the session key (symmmetric and PK)*/
1998-01-02 21:40:10 +01:00
}
1997-11-27 12:44:13 +01:00
free_packet(pkt);
1998-05-03 17:42:08 +02:00
c->last_was_session_key = 0;
write_status( STATUS_END_DECRYPTION );
1997-11-27 12:44:13 +01:00
}
1997-11-27 12:44:13 +01:00
static void
proc_plaintext( CTX c, PACKET *pkt )
{
PKT_plaintext *pt = pkt->pkt.plaintext;
int any, clearsig, only_md5, rc;
1998-06-25 12:19:08 +02:00
KBNODE n;
1997-11-27 12:44:13 +01:00
1998-09-29 18:15:15 +02:00
if( pt->namelen == 8 && !memcmp( pt->name, "_CONSOLE", 8 ) )
1998-11-10 13:59:59 +01:00
log_info(_("NOTE: sender requested \"for-your-eyes-only\"\n"));
1998-09-29 18:15:15 +02:00
else if( opt.verbose )
1998-11-10 13:59:59 +01:00
log_info(_("original file name='%.*s'\n"), pt->namelen, pt->name);
1997-11-27 12:44:13 +01:00
free_md_filter_context( &c->mfx );
c->mfx.md = gcry_md_open( 0, 0);
if( !c->mfx.md )
BUG();
1998-07-08 11:29:43 +02:00
/* fixme: we may need to push the textfilter if we have sigclass 1
* and no armoring - Not yet tested
* Hmmm, why don't we need it at all if we have sigclass 1
* Should we assume that plaintext in mode 't' has always sigclass 1??
* See: Russ Allbery's mail 1999-02-09
*/
any = clearsig = only_md5 = 0;
1998-06-25 12:19:08 +02:00
for(n=c->list; n; n = n->next ) {
1998-07-08 11:29:43 +02:00
if( n->pkt->pkttype == PKT_ONEPASS_SIG ) {
if( n->pkt->pkt.onepass_sig->digest_algo ) {
gcry_md_enable( c->mfx.md, n->pkt->pkt.onepass_sig->digest_algo );
if( !any && n->pkt->pkt.onepass_sig->digest_algo
== GCRY_MD_MD5 )
only_md5 = 1;
else
only_md5 = 0;
1998-07-08 11:29:43 +02:00
any = 1;
}
if( n->pkt->pkt.onepass_sig->sig_class != 0x01 )
only_md5 = 0;
1998-07-08 11:29:43 +02:00
/* Check whether this is a cleartext signature. We assume that
* we have one if the sig_class is 1 and the keyid is 0, that
* are the faked packets produced by armor.c. There is a
* possibility that this fails, but there is no other easy way
* to do it. (We could use a special packet type to indicate
* this, but this may also be faked - it simply can't be verified
* and is _no_ security issue)
*/
if( n->pkt->pkt.onepass_sig->sig_class == 0x01
&& !n->pkt->pkt.onepass_sig->keyid[0]
&& !n->pkt->pkt.onepass_sig->keyid[1] )
1998-07-08 11:29:43 +02:00
clearsig = 1;
1998-06-25 12:19:08 +02:00
}
}
if( !any && !opt.skip_verify ) {
/* no onepass sig packet: enable all standard algos */
gcry_md_enable( c->mfx.md, GCRY_MD_RMD160 );
gcry_md_enable( c->mfx.md, GCRY_MD_SHA1 );
gcry_md_enable( c->mfx.md, GCRY_MD_MD5 );
1998-06-25 12:19:08 +02:00
}
if( opt.pgp2_workarounds && only_md5 && !opt.skip_verify ) {
/* This is a kludge to work around a bug in pgp2. It does only
* catch those mails which are armored. To catch the non-armored
* pgp mails we could see whether there is the signature packet
* in front of the plaintext. If someone needs this, send me a patch.
*/
c->mfx.md2 = gcry_md_open( GCRY_MD_MD5, 0);
if( !c->mfx.md2 )
BUG();
}
if ( DBG_HASHING ) {
gcry_md_start_debug( c->mfx.md, "verify" );
if ( c->mfx.md2 )
gcry_md_start_debug( c->mfx.md2, "verify2" );
}
1998-07-08 11:29:43 +02:00
rc = handle_plaintext( pt, &c->mfx, c->sigs_only, clearsig );
if( rc == GPGERR_CREATE_FILE && !c->sigs_only) {
1998-07-14 19:10:28 +02:00
/* can't write output but we hash it anyway to
* check the signature */
rc = handle_plaintext( pt, &c->mfx, 1, clearsig );
}
1998-01-02 21:40:10 +01:00
if( rc )
log_error( "handle plaintext failed: %s\n", gpg_errstr(rc));
1997-11-27 12:44:13 +01:00
free_packet(pkt);
1998-05-03 17:42:08 +02:00
c->last_was_session_key = 0;
1997-11-27 12:44:13 +01:00
}
1998-03-09 22:44:06 +01:00
static int
proc_compressed_cb( IOBUF a, void *info )
{
return proc_signature_packets( info, a, ((CTX)info)->signed_data,
((CTX)info)->sigfilename );
1998-03-09 22:44:06 +01:00
}
static int
proc_encrypt_cb( IOBUF a, void *info )
{
return proc_encryption_packets( info, a );
1998-03-09 22:44:06 +01:00
}
1997-11-27 12:44:13 +01:00
static void
1997-12-01 11:33:23 +01:00
proc_compressed( CTX c, PACKET *pkt )
1997-11-27 12:44:13 +01:00
{
PKT_compressed *zd = pkt->pkt.compressed;
1998-01-02 21:40:10 +01:00
int rc;
1997-11-27 12:44:13 +01:00
1998-01-02 21:40:10 +01:00
/*printf("zip: compressed data packet\n");*/
1998-03-09 22:44:06 +01:00
if( c->sigs_only )
rc = handle_compressed( c, zd, proc_compressed_cb, c );
1998-03-09 22:44:06 +01:00
else if( c->encrypt_only )
rc = handle_compressed( c, zd, proc_encrypt_cb, c );
1998-03-09 22:44:06 +01:00
else
rc = handle_compressed( c, zd, NULL, NULL );
1998-01-02 21:40:10 +01:00
if( rc )
log_error("uncompressing failed: %s\n", gpg_errstr(rc));
1997-11-27 12:44:13 +01:00
free_packet(pkt);
1998-05-03 17:42:08 +02:00
c->last_was_session_key = 0;
1997-11-27 12:44:13 +01:00
}
1997-11-26 23:02:28 +01:00
1997-12-01 11:33:23 +01:00
/****************
* check the signature
* Returns: 0 = valid signature or an error code
*/
static int
1998-05-29 13:53:54 +02:00
do_check_sig( CTX c, KBNODE node, int *is_selfsig )
1997-12-01 11:33:23 +01:00
{
PKT_signature *sig;
GCRY_MD_HD md = NULL, md2 = NULL;
1997-12-01 11:33:23 +01:00
int algo, rc;
assert( node->pkt->pkttype == PKT_SIGNATURE );
1998-05-29 13:53:54 +02:00
if( is_selfsig )
*is_selfsig = 0;
1997-12-01 11:33:23 +01:00
sig = node->pkt->pkt.signature;
1998-05-04 20:49:26 +02:00
algo = sig->digest_algo;
if( (rc=openpgp_md_test_algo(algo)) )
1997-12-01 11:33:23 +01:00
return rc;
1997-12-03 11:20:03 +01:00
if( sig->sig_class == 0x00 ) {
1998-02-27 18:51:28 +01:00
if( c->mfx.md )
md = gcry_md_copy( c->mfx.md );
1998-02-27 18:51:28 +01:00
else /* detached signature */
md = gcry_md_open( 0, 0 ); /* signature_check() will enable the md*/
if( !md )
BUG();
1997-12-03 11:20:03 +01:00
}
1998-02-04 19:54:31 +01:00
else if( sig->sig_class == 0x01 ) {
/* how do we know that we have to hash the (already hashed) text
* in canonical mode ??? (calculating both modes???) */
if( c->mfx.md ) {
md = gcry_md_copy( c->mfx.md );
if( !md )
BUG();
if( c->mfx.md2 ) {
md2 = gcry_md_copy( c->mfx.md2 );
if( !md2 )
BUG();
}
}
else { /* detached signature */
log_debug("Do we really need this here?");
md = gcry_md_open( 0, 0 ); /* signature_check() will enable the md*/
md2 = gcry_md_open( 0, 0 );
if( !md || !md2 )
BUG();
}
1998-02-04 19:54:31 +01:00
}
else if( (sig->sig_class&~3) == 0x10
1998-04-02 12:30:03 +02:00
|| sig->sig_class == 0x18
|| sig->sig_class == 0x20
1998-04-25 10:08:35 +02:00
|| sig->sig_class == 0x30 ) { /* classes 0x10..0x17,0x20,0x30 */
1998-06-29 14:30:57 +02:00
if( c->list->pkt->pkttype == PKT_PUBLIC_KEY
|| c->list->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
1998-05-29 13:53:54 +02:00
return check_key_signature( c->list, node, is_selfsig );
1997-12-01 11:33:23 +01:00
}
else if( sig->sig_class == 0x20 ) {
log_info(_("standalone revocation - "
"use \"gpg --import\" to apply\n"));
return GPGERR_NOT_PROCESSED;
}
1997-12-01 11:33:23 +01:00
else {
log_error("invalid root packet for sigclass %02x\n",
sig->sig_class);
return GPGERR_SIG_CLASS;
1997-12-01 11:33:23 +01:00
}
}
else
return GPGERR_SIG_CLASS;
rc = signature_check( sig, md );
if( rc == GPGERR_BAD_SIGN && md2 )
rc = signature_check( sig, md2 );
gcry_md_close(md);
gcry_md_close(md2);
1997-12-01 11:33:23 +01:00
return rc;
}
static void
print_userid( PACKET *pkt )
{
if( !pkt )
1998-01-16 22:15:24 +01:00
BUG();
1997-12-01 11:33:23 +01:00
if( pkt->pkttype != PKT_USER_ID ) {
printf("ERROR: unexpected packet type %d", pkt->pkttype );
return;
}
if( opt.with_colons )
print_string( stdout, pkt->pkt.user_id->name,
pkt->pkt.user_id->len, ':');
else
print_utf8_string( stdout, pkt->pkt.user_id->name,
pkt->pkt.user_id->len );
1997-12-01 11:33:23 +01:00
}
1997-12-09 13:46:23 +01:00
static void
1998-06-29 14:30:57 +02:00
print_fingerprint( PKT_public_key *pk, PKT_secret_key *sk )
1997-12-09 13:46:23 +01:00
{
1998-10-12 22:16:38 +02:00
byte array[MAX_FINGERPRINT_LEN], *p;
1997-12-09 13:46:23 +01:00
size_t i, n;
1998-10-12 22:16:38 +02:00
if( sk )
fingerprint_from_sk( sk, array, &n );
else
fingerprint_from_pk( pk, array, &n );
p = array;
1998-03-09 22:44:06 +01:00
if( opt.with_colons ) {
1998-04-02 12:30:03 +02:00
printf("fpr:::::::::");
1998-03-09 22:44:06 +01:00
for(i=0; i < n ; i++, p++ )
printf("%02X", *p );
putchar(':');
1997-12-09 13:46:23 +01:00
}
else {
1998-03-09 22:44:06 +01:00
printf(" Key fingerprint =");
if( n == 20 ) {
for(i=0; i < n ; i++, i++, p += 2 ) {
if( i == 10 )
putchar(' ');
printf(" %02X%02X", *p, p[1] );
}
}
else {
for(i=0; i < n ; i++, p++ ) {
if( i && !(i%8) )
putchar(' ');
printf(" %02X", *p );
}
1997-12-09 13:46:23 +01:00
}
}
putchar('\n');
}
static void
print_notation_data( PKT_signature *sig )
{
size_t n, n1, n2;
const byte *p;
int seq = 0;
while( (p = enum_sig_subpkt( sig->hashed_data, SIGSUBPKT_NOTATION,
&n, &seq )) ) {
if( n < 8 ) {
log_info(_("WARNING: invalid notation data found\n"));
return;
}
if( !(*p & 0x80) )
return; /* not human readable */
n1 = (p[4] << 8) | p[5];
n2 = (p[6] << 8) | p[7];
p += 8;
if( 8+n1+n2 != n ) {
log_info(_("WARNING: invalid notation data found\n"));
return;
}
log_info(_("Notation: ") );
print_string( log_stream(), p, n1, 0 );
putc( '=', log_stream() );
print_string( log_stream(), p+n1, n2, 0 );
putc( '\n', log_stream() );
}
if( (p = parse_sig_subpkt( sig->hashed_data, SIGSUBPKT_POLICY, &n ) )) {
log_info(_("Policy: ") );
print_string( log_stream(), p, n, 0 );
putc( '\n', log_stream() );
}
/* Now check wheter the key of this signature has some
* notation data */
/* TODO */
}
1997-12-09 13:46:23 +01:00
1997-12-01 11:33:23 +01:00
/****************
* List the certificate in a user friendly way
*/
static void
1997-12-12 13:03:58 +01:00
list_node( CTX c, KBNODE node )
1997-12-01 11:33:23 +01:00
{
int any=0;
1998-04-02 12:30:03 +02:00
int mainkey;
1997-12-01 11:33:23 +01:00
if( !node )
;
1998-06-29 14:30:57 +02:00
else if( (mainkey = (node->pkt->pkttype == PKT_PUBLIC_KEY) )
|| node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
PKT_public_key *pk = node->pkt->pkt.public_key;
1997-12-01 11:33:23 +01:00
1998-03-09 22:44:06 +01:00
if( opt.with_colons ) {
u32 keyid[2];
1998-06-29 14:30:57 +02:00
keyid_from_pk( pk, keyid );
1998-05-29 13:53:54 +02:00
if( mainkey ) {
1998-06-29 14:30:57 +02:00
c->local_id = pk->local_id;
c->trustletter = opt.fast_list_mode?
0 : query_trust_info( pk, NULL );
1998-05-29 13:53:54 +02:00
}
printf("%s:", mainkey? "pub":"sub" );
if( c->trustletter )
putchar( c->trustletter );
printf(":%u:%d:%08lX%08lX:%s:%s:",
1998-06-29 14:30:57 +02:00
nbits_from_pk( pk ),
pk->pubkey_algo,
1998-03-09 22:44:06 +01:00
(ulong)keyid[0],(ulong)keyid[1],
1998-06-29 14:30:57 +02:00
datestr_from_pk( pk ),
1998-10-16 18:00:17 +02:00
pk->expiredate? strtimestamp(pk->expiredate):"" );
1998-05-29 13:53:54 +02:00
if( c->local_id )
printf("%lu", c->local_id );
putchar(':');
if( c->local_id && !opt.fast_list_mode )
putchar( get_ownertrust_info( c->local_id ) );
1998-05-29 13:53:54 +02:00
putchar(':');
if( node->next && node->next->pkt->pkttype == PKT_RING_TRUST) {
putchar('\n'); any=1;
if( opt.fingerprint )
print_fingerprint( pk, NULL );
printf("rtv:1:%u:\n",
node->next->pkt->pkt.ring_trust->trustval );
}
1998-03-09 22:44:06 +01:00
}
else
1998-04-02 12:30:03 +02:00
printf("%s %4u%c/%08lX %s ",
mainkey? "pub":"sub",
1998-06-29 14:30:57 +02:00
nbits_from_pk( pk ),
pubkey_letter( pk->pubkey_algo ),
(ulong)keyid_from_pk( pk, NULL ),
datestr_from_pk( pk ) );
1998-05-29 13:53:54 +02:00
if( mainkey ) {
/* and now list all userids with their signatures */
for( node = node->next; node; node = node->next ) {
if( node->pkt->pkttype == PKT_SIGNATURE ) {
if( !any ) {
if( node->pkt->pkt.signature->sig_class == 0x20 )
puts("[revoked]");
else
putchar('\n');
any = 1;
}
list_node(c, node );
1998-03-09 22:44:06 +01:00
}
1998-05-29 13:53:54 +02:00
else if( node->pkt->pkttype == PKT_USER_ID ) {
if( any ) {
if( opt.with_colons )
printf("uid:::::::::");
else
printf( "uid%*s", 28, "" );
}
print_userid( node->pkt );
1998-03-09 22:44:06 +01:00
if( opt.with_colons )
1998-05-29 13:53:54 +02:00
putchar(':');
1998-04-02 12:30:03 +02:00
putchar('\n');
1998-05-29 13:53:54 +02:00
if( opt.fingerprint && !any )
1998-06-29 14:30:57 +02:00
print_fingerprint( pk, NULL );
if( node->next
&& node->next->pkt->pkttype == PKT_RING_TRUST ) {
printf("rtv:2:%u:\n",
node->next->pkt->pkt.ring_trust->trustval );
}
1998-05-29 13:53:54 +02:00
any=1;
}
1998-06-29 14:30:57 +02:00
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
1998-05-29 13:53:54 +02:00
if( !any ) {
putchar('\n');
any = 1;
}
list_node(c, node );
1998-04-02 12:30:03 +02:00
}
}
1997-12-01 11:33:23 +01:00
}
else if( pk->expiredate ) { /* of subkey */
printf(_(" [expires: %s]"), expirestr_from_pk( pk ) );
}
1998-05-29 13:53:54 +02:00
if( !any )
1998-04-02 12:30:03 +02:00
putchar('\n');
1998-07-29 21:35:05 +02:00
if( !mainkey && opt.fingerprint > 1 )
print_fingerprint( pk, NULL );
1997-12-01 11:33:23 +01:00
}
1998-06-29 14:30:57 +02:00
else if( (mainkey = (node->pkt->pkttype == PKT_SECRET_KEY) )
|| node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
PKT_secret_key *sk = node->pkt->pkt.secret_key;
1997-12-01 11:33:23 +01:00
1998-05-29 13:53:54 +02:00
if( opt.with_colons ) {
u32 keyid[2];
1998-06-29 14:30:57 +02:00
keyid_from_sk( sk, keyid );
1998-10-16 18:00:17 +02:00
printf("%s::%u:%d:%08lX%08lX:%s:%s:::",
1998-05-29 13:53:54 +02:00
mainkey? "sec":"ssb",
1998-06-29 14:30:57 +02:00
nbits_from_sk( sk ),
sk->pubkey_algo,
1998-05-29 13:53:54 +02:00
(ulong)keyid[0],(ulong)keyid[1],
1998-06-29 14:30:57 +02:00
datestr_from_sk( sk ),
1998-10-16 18:00:17 +02:00
sk->expiredate? strtimestamp(sk->expiredate):""
1998-05-29 13:53:54 +02:00
/* fixme: add LID */ );
}
else
printf("%s %4u%c/%08lX %s ",
1998-04-02 12:30:03 +02:00
mainkey? "sec":"ssb",
1998-06-29 14:30:57 +02:00
nbits_from_sk( sk ),
pubkey_letter( sk->pubkey_algo ),
(ulong)keyid_from_sk( sk, NULL ),
datestr_from_sk( sk ) );
1998-05-29 13:53:54 +02:00
if( mainkey ) {
/* and now list all userids with their signatures */
for( node = node->next; node; node = node->next ) {
if( node->pkt->pkttype == PKT_SIGNATURE ) {
if( !any ) {
if( node->pkt->pkt.signature->sig_class == 0x20 )
puts("[revoked]");
else
putchar('\n');
any = 1;
}
list_node(c, node );
}
else if( node->pkt->pkttype == PKT_USER_ID ) {
if( any ) {
if( opt.with_colons )
printf("uid:::::::::");
else
printf( "uid%*s", 28, "" );
}
print_userid( node->pkt );
if( opt.with_colons )
putchar(':');
putchar('\n');
if( opt.fingerprint && !any )
1998-06-29 14:30:57 +02:00
print_fingerprint( NULL, sk );
1998-05-29 13:53:54 +02:00
any=1;
}
1998-06-29 14:30:57 +02:00
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
1998-05-29 13:53:54 +02:00
if( !any ) {
putchar('\n');
any = 1;
}
list_node(c, node );
}
}
1997-12-01 11:33:23 +01:00
}
1998-05-29 13:53:54 +02:00
if( !any )
1998-04-02 12:30:03 +02:00
putchar('\n');
1998-07-29 21:35:05 +02:00
if( !mainkey && opt.fingerprint > 1 )
print_fingerprint( NULL, sk );
1997-12-01 11:33:23 +01:00
}
1997-12-09 13:46:23 +01:00
else if( node->pkt->pkttype == PKT_SIGNATURE ) {
1997-12-01 11:33:23 +01:00
PKT_signature *sig = node->pkt->pkt.signature;
1998-05-29 13:53:54 +02:00
int is_selfsig = 0;
1998-02-17 21:48:52 +01:00
int rc2=0;
1997-12-01 11:33:23 +01:00
size_t n;
char *p;
int sigrc = ' ';
1997-12-09 13:46:23 +01:00
if( !opt.list_sigs )
return;
if( sig->sig_class == 0x20 || sig->sig_class == 0x30 )
fputs("rev", stdout);
else
fputs("sig", stdout);
1997-12-01 11:33:23 +01:00
if( opt.check_sigs ) {
fflush(stdout);
1998-05-29 13:53:54 +02:00
switch( (rc2=do_check_sig( c, node, &is_selfsig )) ) {
1997-12-01 11:33:23 +01:00
case 0: sigrc = '!'; break;
case GPGERR_BAD_SIGN: sigrc = '-'; break;
case GPGERR_NO_PUBKEY: sigrc = '?'; break;
1997-12-01 11:33:23 +01:00
default: sigrc = '%'; break;
}
}
1998-05-29 13:53:54 +02:00
else { /* check whether this is a self signature */
u32 keyid[2];
1998-06-29 14:30:57 +02:00
if( c->list->pkt->pkttype == PKT_PUBLIC_KEY
|| c->list->pkt->pkttype == PKT_SECRET_KEY ) {
if( c->list->pkt->pkttype == PKT_PUBLIC_KEY )
keyid_from_pk( c->list->pkt->pkt.public_key, keyid );
1998-05-29 13:53:54 +02:00
else
1998-06-29 14:30:57 +02:00
keyid_from_sk( c->list->pkt->pkt.secret_key, keyid );
1998-05-29 13:53:54 +02:00
if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] )
is_selfsig = 1;
}
}
1998-03-09 22:44:06 +01:00
if( opt.with_colons ) {
putchar(':');
if( sigrc != ' ' )
putchar(sigrc);
printf("::%d:%08lX%08lX:%s::::", sig->pubkey_algo,
(ulong)sig->keyid[0],
1998-03-09 22:44:06 +01:00
(ulong)sig->keyid[1], datestr_from_sig(sig));
}
else
printf("%c %08lX %s ",
sigrc, (ulong)sig->keyid[1], datestr_from_sig(sig));
1997-12-01 11:33:23 +01:00
if( sigrc == '%' )
printf("[%s] ", gpg_errstr(rc2) );
1997-12-01 11:33:23 +01:00
else if( sigrc == '?' )
;
1998-05-29 13:53:54 +02:00
else if( is_selfsig ) {
if( opt.with_colons )
putchar(':');
fputs( sig->sig_class == 0x18? "[keybind]":"[selfsig]", stdout);
if( opt.with_colons )
putchar(':');
}
else if( !opt.fast_list_mode ) {
1997-12-01 11:33:23 +01:00
p = get_user_id( sig->keyid, &n );
1998-03-09 22:44:06 +01:00
print_string( stdout, p, n, opt.with_colons );
gcry_free(p);
1997-12-01 11:33:23 +01:00
}
1998-03-09 22:44:06 +01:00
if( opt.with_colons )
printf(":%02x:", sig->sig_class );
1997-12-01 11:33:23 +01:00
putchar('\n');
}
else
log_error("invalid node with packet of type %d\n", node->pkt->pkttype);
}
1997-11-26 23:02:28 +01:00
int
proc_packets( void *anchor, IOBUF a )
1997-11-26 23:02:28 +01:00
{
int rc;
CTX c = gcry_xcalloc( 1, sizeof *c );
c->anchor = anchor;
rc = do_proc_packets( c, a );
gcry_free( c );
1998-03-09 22:44:06 +01:00
return rc;
}
1998-03-09 22:44:06 +01:00
int
proc_signature_packets( void *anchor, IOBUF a,
STRLIST signedfiles, const char *sigfilename )
1998-03-09 22:44:06 +01:00
{
CTX c = gcry_xcalloc( 1, sizeof *c );
1998-01-16 22:15:24 +01:00
int rc;
c->anchor = anchor;
1998-03-09 22:44:06 +01:00
c->sigs_only = 1;
c->signed_data = signedfiles;
1998-07-14 19:10:28 +02:00
c->sigfilename = sigfilename;
1998-03-09 22:44:06 +01:00
rc = do_proc_packets( c, a );
gcry_free( c );
1998-03-09 22:44:06 +01:00
return rc;
}
int
proc_encryption_packets( void *anchor, IOBUF a )
1998-03-09 22:44:06 +01:00
{
CTX c = gcry_xcalloc( 1, sizeof *c );
1998-03-09 22:44:06 +01:00
int rc;
c->anchor = anchor;
1998-03-09 22:44:06 +01:00
c->encrypt_only = 1;
rc = do_proc_packets( c, a );
gcry_free( c );
1998-03-09 22:44:06 +01:00
return rc;
}
int
do_proc_packets( CTX c, IOBUF a )
{
PACKET *pkt = gcry_xmalloc( sizeof *pkt );
1998-03-09 22:44:06 +01:00
int rc=0;
int any_data=0;
1997-12-01 11:33:23 +01:00
int newpkt;
1997-11-26 23:02:28 +01:00
c->iobuf = a;
1997-11-26 23:02:28 +01:00
init_packet(pkt);
while( (rc=parse_packet(a, pkt, NULL)) != -1 ) {
any_data = 1;
1997-11-26 23:02:28 +01:00
if( rc ) {
free_packet(pkt);
if( rc == GPGERR_INVALID_PACKET )
break;
1997-11-26 23:02:28 +01:00
continue;
}
1997-12-01 11:33:23 +01:00
newpkt = -1;
1998-01-02 21:40:10 +01:00
if( opt.list_packets ) {
switch( pkt->pkttype ) {
case PKT_PUBKEY_ENC: proc_pubkey_enc( c, pkt ); break;
case PKT_SYMKEY_ENC: proc_symkey_enc( c, pkt ); break;
case PKT_ENCRYPTED:
case PKT_ENCRYPTED_MDC: proc_encrypted( c, pkt ); break;
1998-01-02 21:40:10 +01:00
case PKT_COMPRESSED: proc_compressed( c, pkt ); break;
default: newpkt = 0; break;
}
}
1998-03-09 22:44:06 +01:00
else if( c->sigs_only ) {
switch( pkt->pkttype ) {
1998-06-29 14:30:57 +02:00
case PKT_PUBLIC_KEY:
case PKT_SECRET_KEY:
1998-03-09 22:44:06 +01:00
case PKT_USER_ID:
1998-05-03 17:42:08 +02:00
case PKT_SYMKEY_ENC:
1998-03-09 22:44:06 +01:00
case PKT_PUBKEY_ENC:
case PKT_ENCRYPTED:
case PKT_ENCRYPTED_MDC:
rc = GPGERR_UNEXPECTED;
1998-03-09 22:44:06 +01:00
goto leave;
case PKT_SIGNATURE: newpkt = add_signature( c, pkt ); break;
case PKT_PLAINTEXT: proc_plaintext( c, pkt ); break;
case PKT_COMPRESSED: proc_compressed( c, pkt ); break;
case PKT_ONEPASS_SIG: newpkt = add_onepass_sig( c, pkt ); break;
default: newpkt = 0; break;
}
}
else if( c->encrypt_only ) {
switch( pkt->pkttype ) {
1998-06-29 14:30:57 +02:00
case PKT_PUBLIC_KEY:
case PKT_SECRET_KEY:
1998-03-09 22:44:06 +01:00
case PKT_USER_ID:
rc = GPGERR_UNEXPECTED;
1998-03-09 22:44:06 +01:00
goto leave;
case PKT_SIGNATURE: newpkt = add_signature( c, pkt ); break;
1998-05-03 17:42:08 +02:00
case PKT_SYMKEY_ENC: proc_symkey_enc( c, pkt ); break;
1998-03-09 22:44:06 +01:00
case PKT_PUBKEY_ENC: proc_pubkey_enc( c, pkt ); break;
case PKT_ENCRYPTED:
case PKT_ENCRYPTED_MDC: proc_encrypted( c, pkt ); break;
1998-03-09 22:44:06 +01:00
case PKT_PLAINTEXT: proc_plaintext( c, pkt ); break;
case PKT_COMPRESSED: proc_compressed( c, pkt ); break;
case PKT_ONEPASS_SIG: newpkt = add_onepass_sig( c, pkt ); break;
default: newpkt = 0; break;
}
}
1998-01-02 21:40:10 +01:00
else {
switch( pkt->pkttype ) {
1998-06-29 14:30:57 +02:00
case PKT_PUBLIC_KEY:
case PKT_SECRET_KEY:
1998-04-02 12:30:03 +02:00
release_list( c );
c->list = new_kbnode( pkt );
newpkt = 1;
break;
1998-06-29 14:30:57 +02:00
case PKT_PUBLIC_SUBKEY:
case PKT_SECRET_SUBKEY:
1998-04-02 12:30:03 +02:00
newpkt = add_subkey( c, pkt );
break;
1998-01-02 21:40:10 +01:00
case PKT_USER_ID: newpkt = add_user_id( c, pkt ); break;
case PKT_SIGNATURE: newpkt = add_signature( c, pkt ); break;
case PKT_PUBKEY_ENC: proc_pubkey_enc( c, pkt ); break;
1998-05-03 17:42:08 +02:00
case PKT_SYMKEY_ENC: proc_symkey_enc( c, pkt ); break;
case PKT_ENCRYPTED:
case PKT_ENCRYPTED_MDC: proc_encrypted( c, pkt ); break;
1998-01-02 21:40:10 +01:00
case PKT_PLAINTEXT: proc_plaintext( c, pkt ); break;
case PKT_COMPRESSED: proc_compressed( c, pkt ); break;
case PKT_ONEPASS_SIG: newpkt = add_onepass_sig( c, pkt ); break;
case PKT_RING_TRUST: newpkt = add_ring_trust( c, pkt ); break;
1998-01-02 21:40:10 +01:00
default: newpkt = 0; break;
}
1997-12-01 11:33:23 +01:00
}
1997-12-03 11:20:03 +01:00
if( pkt->pkttype != PKT_SIGNATURE )
c->have_data = pkt->pkttype == PKT_PLAINTEXT;
1997-12-01 11:33:23 +01:00
if( newpkt == -1 )
;
else if( newpkt ) {
pkt = gcry_xmalloc( sizeof *pkt );
1997-12-01 11:33:23 +01:00
init_packet(pkt);
1997-11-26 23:02:28 +01:00
}
1997-12-01 11:33:23 +01:00
else
free_packet(pkt);
1997-11-26 23:02:28 +01:00
}
if( rc == GPGERR_INVALID_PACKET )
write_status_text( STATUS_NODATA, "3" );
if( any_data )
rc = 0;
else if( rc == -1 )
write_status_text( STATUS_NODATA, "2" );
1997-11-26 23:02:28 +01:00
1998-03-09 22:44:06 +01:00
leave:
1998-02-17 21:48:52 +01:00
release_list( c );
gcry_free(c->dek);
1997-11-26 23:02:28 +01:00
free_packet( pkt );
gcry_free( pkt );
1997-11-27 12:44:13 +01:00
free_md_filter_context( &c->mfx );
1998-03-09 22:44:06 +01:00
return rc;
1997-11-26 23:02:28 +01:00
}
1997-11-18 15:06:00 +01:00
1998-01-30 17:23:16 +01:00
static int
check_sig_and_print( CTX c, KBNODE node )
{
PKT_signature *sig = node->pkt->pkt.signature;
const char *astr, *tstr;
1998-01-30 17:23:16 +01:00
int rc;
if( opt.skip_verify ) {
1998-11-10 13:59:59 +01:00
log_info(_("signature verification suppressed\n"));
1998-04-30 16:06:01 +02:00
return 0;
}
tstr = asctimestamp(sig->timestamp);
astr = gcry_pk_algo_name( sig->pubkey_algo );
log_info(_("Signature made %.*s using %s key ID %08lX\n"),
(int)strlen(tstr), tstr, astr? astr: "?", (ulong)sig->keyid[1] );
1998-05-29 13:53:54 +02:00
rc = do_check_sig(c, node, NULL );
if( rc == GPGERR_NO_PUBKEY && opt.keyserver_name && opt.auto_key_retrieve) {
if( !hkp_ask_import( sig->keyid ) )
rc = do_check_sig(c, node, NULL );
}
if( !rc || rc == GPGERR_BAD_SIGN ) {
KBNODE un, keyblock;
char *us;
int count=0;
keyblock = get_pubkeyblock( sig->keyid );
us = get_long_user_id_string( sig->keyid );
1998-10-06 14:10:02 +02:00
write_status_text( rc? STATUS_BADSIG : STATUS_GOODSIG, us );
gcry_free(us);
/* fixme: list only user ids which are valid and add information
* about the trustworthiness of each user id, sort them.
* Integrate this with check_signatures_trust(). */
for( un=keyblock; un; un = un->next ) {
if( un->pkt->pkttype != PKT_USER_ID )
continue;
if( !count++ )
log_info(rc? _("BAD signature from \"")
: _("Good signature from \""));
else
log_info( _(" aka \""));
print_utf8_string( log_stream(), un->pkt->pkt.user_id->name,
un->pkt->pkt.user_id->len );
fputs("\"\n", log_stream() );
if( rc )
break; /* print only one id in this case */
}
if( !count ) { /* just in case that we have no userid */
log_info(rc? _("BAD signature from \"")
: _("Good signature from \""));
fputs("[?]\"\n", log_stream() );
}
release_kbnode( keyblock );
if( !rc )
print_notation_data( sig );
if( !rc && is_status_enabled() ) {
/* print a status response with the fingerprint */
PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
if( !get_pubkey( pk, sig->keyid ) ) {
byte array[MAX_FINGERPRINT_LEN], *p;
char buf[MAX_FINGERPRINT_LEN*2+61];
size_t i, n;
fingerprint_from_pk( pk, array, &n );
p = array;
for(i=0; i < n ; i++, p++ )
sprintf(buf+2*i, "%02X", *p );
sprintf(buf+strlen(buf), " %s %lu",
strtimestamp( sig->timestamp ),
(ulong)sig->timestamp );
write_status_text( STATUS_VALIDSIG, buf );
}
free_public_key( pk );
}
1998-07-09 15:37:17 +02:00
if( !rc )
rc = check_signatures_trust( sig );
1998-11-10 13:59:59 +01:00
if( rc )
gpg_errors_seen = 1;
1998-03-19 16:27:29 +01:00
if( opt.batch && rc )
gpg_exit(1);
1998-01-30 17:23:16 +01:00
}
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 == GPGERR_NO_PUBKEY ) {
buf[16] = 0;
write_status_text( STATUS_NO_PUBKEY, buf );
}
if( rc != GPGERR_NOT_PROCESSED )
log_error(_("Can't check signature: %s\n"), gpg_errstr(rc) );
1998-01-30 17:23:16 +01:00
}
return rc;
}
1997-12-02 20:36:53 +01:00
/****************
* Process the tree which starts at node
1997-12-02 20:36:53 +01:00
*/
static void
1997-12-12 13:03:58 +01:00
proc_tree( CTX c, KBNODE node )
1997-12-02 20:36:53 +01:00
{
1997-12-12 13:03:58 +01:00
KBNODE n1;
1997-12-02 20:36:53 +01:00
int rc;
if( opt.list_packets || opt.list_only )
1998-01-02 21:40:10 +01:00
return;
1998-05-29 13:53:54 +02:00
c->local_id = 0;
c->trustletter = ' ';
1998-06-29 14:30:57 +02:00
if( node->pkt->pkttype == PKT_PUBLIC_KEY
1998-10-21 19:34:36 +02:00
|| node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
merge_keys_and_selfsig( node );
1997-12-02 20:36:53 +01:00
list_node( c, node );
1998-10-21 19:34:36 +02:00
}
else if( node->pkt->pkttype == PKT_SECRET_KEY ) {
merge_keys_and_selfsig( node );
1997-12-02 20:36:53 +01:00
list_node( c, node );
1998-10-21 19:34:36 +02:00
}
1997-12-02 20:36:53 +01:00
else if( node->pkt->pkttype == PKT_ONEPASS_SIG ) {
/* check all signatures */
if( !c->have_data ) {
free_md_filter_context( &c->mfx );
/* prepare to create all requested message digests */
if ( !(c->mfx.md = gcry_md_open(0, 0)) )
BUG();
1998-03-09 22:44:06 +01:00
/* fixme: why looking for the signature packet and not 1passpacket*/
for( n1 = node; (n1 = find_next_kbnode(n1, PKT_SIGNATURE )); ) {
gcry_md_enable( c->mfx.md, n1->pkt->pkt.signature->digest_algo);
}
/* ask for file and hash it */
if( c->sigs_only ) {
rc = hash_datafiles( c->mfx.md, NULL,
c->signed_data, c->sigfilename,
1998-08-05 18:51:59 +02:00
n1? (n1->pkt->pkt.onepass_sig->sig_class == 0x01):0 );
}
else {
rc = ask_for_detached_datafile( c->mfx.md, c->mfx.md2,
iobuf_get_fname(c->iobuf),
n1? (n1->pkt->pkt.onepass_sig->sig_class == 0x01):0 );
}
if( rc ) {
log_error("can't hash datafile: %s\n", gpg_errstr(rc));
return;
1997-12-03 11:20:03 +01:00
}
1997-12-02 20:36:53 +01:00
}
for( n1 = node; (n1 = find_next_kbnode(n1, PKT_SIGNATURE )); )
check_sig_and_print( c, n1 );
1997-12-02 20:36:53 +01:00
}
else if( node->pkt->pkttype == PKT_SIGNATURE ) {
1998-01-30 17:23:16 +01:00
PKT_signature *sig = node->pkt->pkt.signature;
if( sig->sig_class != 0x00 && sig->sig_class != 0x01 )
log_info(_("standalone signature of class 0x%02x\n"),
sig->sig_class);
else if( !c->have_data ) {
/* detached signature */
1998-02-27 18:51:28 +01:00
free_md_filter_context( &c->mfx );
c->mfx.md = gcry_md_open(sig->digest_algo, 0);
if ( !c->mfx.md )
BUG();
if( !opt.pgp2_workarounds )
;
else if( sig->digest_algo == GCRY_MD_MD5
&& is_RSA( sig->pubkey_algo ) ) {
/* enable a workaround for a pgp2 bug */
c->mfx.md2 = gcry_md_open( GCRY_MD_MD5, 0 );
if ( !c->mfx.md2 )
BUG();
}
else if( sig->digest_algo == GCRY_MD_SHA1
&& sig->pubkey_algo == GCRY_PK_DSA
&& sig->sig_class == 0x01 ) {
/* enable the workaround also for pgp5 when the detached
* signature has been created in textmode */
c->mfx.md2 = gcry_md_open( sig->digest_algo, 0 );
if ( !c->mfx.md2 )
BUG();
}
#if 0 /* workaround disabled */
/* Here we have another hack to work around a pgp 2 bug
* It works by not using the textmode for detached signatures;
* this will let the first signature check (on md) fail
* but the second one (on md2) which adds an extra CR should
* then produce the "correct" hash. This is very, very ugly
* hack but it may help in some cases (and break others)
*/
/* c->mfx.md2? 0 :(sig->sig_class == 0x01) */
#endif
if( c->sigs_only ) {
rc = hash_datafiles( c->mfx.md, c->mfx.md2,
c->signed_data, c->sigfilename,
(sig->sig_class == 0x01) );
}
else {
rc = ask_for_detached_datafile( c->mfx.md, c->mfx.md2,
iobuf_get_fname(c->iobuf),
(sig->sig_class == 0x01) );
}
1998-02-27 18:51:28 +01:00
if( rc ) {
log_error("can't hash datafile: %s\n", gpg_errstr(rc));
1998-02-27 18:51:28 +01:00
return;
1998-01-30 17:23:16 +01:00
}
}
1998-02-27 18:51:28 +01:00
else
1998-11-10 13:59:59 +01:00
log_info(_("old style (PGP 2.x) signature\n"));
1998-01-30 17:23:16 +01:00
check_sig_and_print( c, node );
1997-12-02 20:36:53 +01:00
}
else
1998-11-10 13:59:59 +01:00
log_error(_("invalid root packet detected in proc_tree()\n"));
1997-12-02 20:36:53 +01:00
}