2001-11-16 18:56:23 +01:00
|
|
|
|
/* verify.c - Verify a messages signature
|
2002-08-09 20:12:22 +02:00
|
|
|
|
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
2001-11-16 18:56:23 +01:00
|
|
|
|
*
|
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
|
* 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,
|
|
|
|
|
* 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>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
#include <gcrypt.h>
|
|
|
|
|
#include <ksba.h>
|
|
|
|
|
|
|
|
|
|
#include "gpgsm.h"
|
|
|
|
|
#include "keydb.h"
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
2002-02-07 19:43:22 +01:00
|
|
|
|
/* fixme: Move this to jnlib */
|
2001-11-23 18:12:37 +01:00
|
|
|
|
static char *
|
2001-11-19 13:42:01 +01:00
|
|
|
|
strtimestamp (time_t atime)
|
|
|
|
|
{
|
|
|
|
|
char *buffer = xmalloc (15);
|
|
|
|
|
|
|
|
|
|
if (atime < 0)
|
2001-11-27 18:40:09 +01:00
|
|
|
|
strcpy (buffer, "????" "-??" "-??");
|
|
|
|
|
else if (!atime)
|
|
|
|
|
strcpy (buffer, "none");
|
2001-11-19 13:42:01 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct tm *tp;
|
|
|
|
|
|
|
|
|
|
tp = gmtime( &atime );
|
|
|
|
|
sprintf (buffer, "%04d-%02d-%02d",
|
|
|
|
|
1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday);
|
|
|
|
|
}
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-12-20 17:51:06 +01:00
|
|
|
|
/* Hash the data for a detached signature */
|
2001-11-19 11:25:00 +01:00
|
|
|
|
static void
|
|
|
|
|
hash_data (int fd, GCRY_MD_HD md)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char buffer[4096];
|
|
|
|
|
int nread;
|
|
|
|
|
|
|
|
|
|
fp = fdopen ( dup (fd), "rb");
|
|
|
|
|
if (!fp)
|
|
|
|
|
{
|
|
|
|
|
log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
nread = fread (buffer, 1, DIM(buffer), fp);
|
|
|
|
|
gcry_md_write (md, buffer, nread);
|
|
|
|
|
}
|
|
|
|
|
while (nread);
|
|
|
|
|
if (ferror (fp))
|
|
|
|
|
log_error ("read error on fd %d: %s\n", fd, strerror (errno));
|
|
|
|
|
fclose (fp);
|
|
|
|
|
}
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
|
|
|
|
|
2001-12-20 17:51:06 +01:00
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
2001-11-19 11:25:00 +01:00
|
|
|
|
/* Perform a verify operation. To verify detached signatures, data_fd
|
2001-12-20 17:51:06 +01:00
|
|
|
|
must be different than -1. With OUT_FP given and a non-detached
|
|
|
|
|
signature, the signed material is written to that stream. */
|
2001-11-16 18:56:23 +01:00
|
|
|
|
int
|
2001-12-20 17:51:06 +01:00
|
|
|
|
gpgsm_verify (CTRL ctrl, int in_fd, int data_fd, FILE *out_fp)
|
2001-11-16 18:56:23 +01:00
|
|
|
|
{
|
|
|
|
|
int i, rc;
|
2001-11-27 18:40:09 +01:00
|
|
|
|
Base64Context b64reader = NULL;
|
2001-12-20 17:51:06 +01:00
|
|
|
|
Base64Context b64writer = NULL;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
KsbaError err;
|
2001-11-27 18:40:09 +01:00
|
|
|
|
KsbaReader reader;
|
2001-12-20 17:51:06 +01:00
|
|
|
|
KsbaWriter writer = NULL;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
KsbaCMS cms = NULL;
|
|
|
|
|
KsbaStopReason stopreason;
|
|
|
|
|
KsbaCert cert;
|
|
|
|
|
KEYDB_HANDLE kh;
|
|
|
|
|
GCRY_MD_HD data_md = NULL;
|
|
|
|
|
int signer;
|
2001-11-20 19:28:53 +01:00
|
|
|
|
const char *algoid;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
int algo;
|
|
|
|
|
int is_detached;
|
2001-11-27 18:40:09 +01:00
|
|
|
|
FILE *fp = NULL;
|
2002-08-10 11:14:21 +02:00
|
|
|
|
char *p;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
|
|
|
|
kh = keydb_new (0);
|
|
|
|
|
if (!kh)
|
|
|
|
|
{
|
|
|
|
|
log_error (_("failed to allocated keyDB handle\n"));
|
2001-11-24 18:43:43 +01:00
|
|
|
|
rc = GNUPG_General_Error;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-27 18:40:09 +01:00
|
|
|
|
fp = fdopen ( dup (in_fd), "rb");
|
|
|
|
|
if (!fp)
|
2001-11-16 18:56:23 +01:00
|
|
|
|
{
|
|
|
|
|
log_error ("fdopen() failed: %s\n", strerror (errno));
|
|
|
|
|
rc = seterr (IO_Error);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-27 18:40:09 +01:00
|
|
|
|
rc = gpgsm_create_reader (&b64reader, ctrl, fp, &reader);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2001-11-27 18:40:09 +01:00
|
|
|
|
log_error ("can't create reader: %s\n", gnupg_strerror (rc));
|
2001-11-16 18:56:23 +01:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-20 17:51:06 +01:00
|
|
|
|
if (out_fp)
|
|
|
|
|
{
|
|
|
|
|
rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, &writer);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("can't create writer: %s\n", gnupg_strerror (rc));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
cms = ksba_cms_new ();
|
|
|
|
|
if (!cms)
|
|
|
|
|
{
|
|
|
|
|
rc = seterr (Out_Of_Core);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-20 17:51:06 +01:00
|
|
|
|
err = ksba_cms_set_reader_writer (cms, reader, writer);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
2002-05-03 22:18:54 +02:00
|
|
|
|
log_error ("ksba_cms_set_reader_writer failed: %s\n",
|
2001-11-16 18:56:23 +01:00
|
|
|
|
ksba_strerror (err));
|
|
|
|
|
rc = map_ksba_err (err);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data_md = gcry_md_open (0, 0);
|
|
|
|
|
if (!data_md)
|
|
|
|
|
{
|
|
|
|
|
rc = map_gcry_err (gcry_errno());
|
|
|
|
|
log_error ("md_open failed: %s\n", gcry_strerror (-1));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
2001-12-14 20:36:33 +01:00
|
|
|
|
if (DBG_HASHING)
|
|
|
|
|
gcry_md_start_debug (data_md, "vrfy.data");
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
|
|
|
|
is_detached = 0;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
err = ksba_cms_parse (cms, &stopreason);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
2002-05-03 22:18:54 +02:00
|
|
|
|
log_error ("ksba_cms_parse failed: %s\n", ksba_strerror (err));
|
2001-11-16 18:56:23 +01:00
|
|
|
|
rc = map_ksba_err (err);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
2001-12-11 13:31:04 +01:00
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
if (stopreason == KSBA_SR_NEED_HASH)
|
|
|
|
|
{
|
|
|
|
|
is_detached = 1;
|
2002-05-03 22:18:54 +02:00
|
|
|
|
if (opt.verbose)
|
|
|
|
|
log_info ("detached signature\n");
|
2001-11-16 18:56:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stopreason == KSBA_SR_NEED_HASH
|
|
|
|
|
|| stopreason == KSBA_SR_BEGIN_DATA)
|
|
|
|
|
{ /* We are now able to enable the hash algorithms */
|
2001-11-20 19:28:53 +01:00
|
|
|
|
for (i=0; (algoid=ksba_cms_get_digest_algo_list (cms, i)); i++)
|
2001-11-16 18:56:23 +01:00
|
|
|
|
{
|
2001-11-20 19:28:53 +01:00
|
|
|
|
algo = gcry_md_map_name (algoid);
|
|
|
|
|
if (!algo)
|
|
|
|
|
log_error ("unknown hash algorithm `%s'\n",
|
|
|
|
|
algoid? algoid:"?");
|
|
|
|
|
else
|
2001-11-16 18:56:23 +01:00
|
|
|
|
gcry_md_enable (data_md, algo);
|
|
|
|
|
}
|
2001-11-19 11:25:00 +01:00
|
|
|
|
if (is_detached)
|
|
|
|
|
{
|
|
|
|
|
if (data_fd == -1)
|
2002-03-12 14:36:29 +01:00
|
|
|
|
log_info ("detached signature w/o data "
|
|
|
|
|
"- assuming certs-only\n");
|
|
|
|
|
else
|
|
|
|
|
hash_data (data_fd, data_md);
|
2001-11-19 11:25:00 +01:00
|
|
|
|
}
|
2001-12-20 17:51:06 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ksba_cms_set_hash_function (cms, HASH_FNC, data_md);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (stopreason == KSBA_SR_END_DATA)
|
|
|
|
|
{ /* The data bas been hashed */
|
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (stopreason != KSBA_SR_READY);
|
|
|
|
|
|
2001-12-20 17:51:06 +01:00
|
|
|
|
if (b64writer)
|
|
|
|
|
{
|
|
|
|
|
rc = gpgsm_finish_writer (b64writer);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("write failed: %s\n", gnupg_strerror (rc));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-19 11:25:00 +01:00
|
|
|
|
if (data_fd != -1 && !is_detached)
|
|
|
|
|
{
|
2001-12-10 20:18:27 +01:00
|
|
|
|
log_error ("data given for a non-detached signature\n");
|
2001-11-24 18:43:43 +01:00
|
|
|
|
rc = GNUPG_Conflict;
|
2001-11-19 11:25:00 +01:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
for (i=0; (cert=ksba_cms_get_cert (cms, i)); i++)
|
|
|
|
|
{
|
2002-01-15 14:02:47 +01:00
|
|
|
|
/* Fixme: it might be better to check the validity of the
|
|
|
|
|
certificate first before entering it into the DB. This way
|
|
|
|
|
we would avoid cluttering the DB with invalid
|
|
|
|
|
certificates. */
|
2002-07-02 12:40:12 +02:00
|
|
|
|
keydb_store_cert (cert, 0, NULL);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
ksba_cert_release (cert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cert = NULL;
|
|
|
|
|
err = 0;
|
2002-08-09 20:12:22 +02:00
|
|
|
|
for (signer=0; ; signer++)
|
2001-11-16 18:56:23 +01:00
|
|
|
|
{
|
|
|
|
|
char *issuer = NULL;
|
2001-12-18 18:37:48 +01:00
|
|
|
|
KsbaSexp sigval = NULL;
|
2002-05-03 22:18:54 +02:00
|
|
|
|
time_t sigtime, keyexptime;
|
2001-12-18 18:37:48 +01:00
|
|
|
|
KsbaSexp serial;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
char *msgdigest = NULL;
|
|
|
|
|
size_t msgdigestlen;
|
2003-01-09 13:59:25 +01:00
|
|
|
|
char *ctattr;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
|
|
|
|
err = ksba_cms_get_issuer_serial (cms, signer, &issuer, &serial);
|
2002-03-12 14:36:29 +01:00
|
|
|
|
if (!signer && err == KSBA_No_Data && data_fd == -1 && is_detached)
|
|
|
|
|
{
|
|
|
|
|
log_info ("certs-only message accepted\n");
|
|
|
|
|
err = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-11-16 18:56:23 +01:00
|
|
|
|
if (err)
|
2002-08-09 20:12:22 +02:00
|
|
|
|
{
|
|
|
|
|
if (signer && err == -1)
|
|
|
|
|
err = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-05-03 22:18:54 +02:00
|
|
|
|
if (DBG_X509)
|
|
|
|
|
{
|
|
|
|
|
log_debug ("signer %d - issuer: `%s'\n",
|
|
|
|
|
signer, issuer? issuer:"[NONE]");
|
|
|
|
|
log_debug ("signer %d - serial: ", signer);
|
|
|
|
|
gpgsm_dump_serial (serial);
|
|
|
|
|
log_printf ("\n");
|
|
|
|
|
}
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
2001-11-26 14:08:36 +01:00
|
|
|
|
err = ksba_cms_get_signing_time (cms, signer, &sigtime);
|
2002-08-20 15:09:53 +02:00
|
|
|
|
if (err == KSBA_No_Data)
|
|
|
|
|
sigtime = 0;
|
|
|
|
|
else if (err)
|
2001-11-26 14:08:36 +01:00
|
|
|
|
{
|
2002-05-03 22:18:54 +02:00
|
|
|
|
log_error ("error getting signing time: %s\n", ksba_strerror (err));
|
2001-11-26 14:08:36 +01:00
|
|
|
|
sigtime = (time_t)-1;
|
|
|
|
|
}
|
2002-08-10 11:14:21 +02:00
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
err = ksba_cms_get_message_digest (cms, signer,
|
|
|
|
|
&msgdigest, &msgdigestlen);
|
2002-08-20 15:09:53 +02:00
|
|
|
|
if (!err)
|
2001-11-16 18:56:23 +01:00
|
|
|
|
{
|
2002-08-20 15:09:53 +02:00
|
|
|
|
algoid = ksba_cms_get_digest_algo (cms, signer);
|
|
|
|
|
algo = gcry_md_map_name (algoid);
|
|
|
|
|
if (DBG_X509)
|
|
|
|
|
log_debug ("signer %d - digest algo: %d\n", signer, algo);
|
|
|
|
|
if ( !gcry_md_info (data_md, GCRYCTL_IS_ALGO_ENABLED, &algo, NULL) )
|
|
|
|
|
{
|
|
|
|
|
log_error ("digest algo %d has not been enabled\n", algo);
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (err == KSBA_No_Data)
|
|
|
|
|
{
|
|
|
|
|
assert (!msgdigest);
|
|
|
|
|
err = 0;
|
|
|
|
|
algoid = NULL;
|
|
|
|
|
algo = 0;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
}
|
2002-08-20 15:09:53 +02:00
|
|
|
|
else /* real error */
|
|
|
|
|
break;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
2003-01-09 13:59:25 +01:00
|
|
|
|
err = ksba_cms_get_sigattr_oids (cms, signer,
|
|
|
|
|
"1.2.840.113549.1.9.3",&ctattr);
|
|
|
|
|
if (!err)
|
|
|
|
|
{
|
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
if (DBG_X509)
|
|
|
|
|
log_debug ("signer %d - content-type attribute: %s", signer, ctattr);
|
|
|
|
|
s = ksba_cms_get_content_oid (cms, 1);
|
|
|
|
|
if (!s || strcmp (ctattr, s))
|
|
|
|
|
{
|
|
|
|
|
log_error ("content-type attribute does not match "
|
|
|
|
|
"actual content-type\n");
|
|
|
|
|
ksba_free (ctattr);
|
|
|
|
|
ctattr = NULL;
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
ksba_free (ctattr);
|
|
|
|
|
ctattr = NULL;
|
|
|
|
|
}
|
|
|
|
|
else if (err != -1)
|
|
|
|
|
{
|
|
|
|
|
log_error ("error getting content-type attribute: %s\n",
|
|
|
|
|
ksba_strerror (err));
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
sigval = ksba_cms_get_sig_val (cms, signer);
|
2001-11-24 15:26:27 +01:00
|
|
|
|
if (!sigval)
|
|
|
|
|
{
|
|
|
|
|
log_error ("no signature value available\n");
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
2002-05-03 22:18:54 +02:00
|
|
|
|
if (DBG_X509)
|
|
|
|
|
log_debug ("signer %d - signature available", signer);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
|
|
|
|
/* Find the certificate of the signer */
|
|
|
|
|
keydb_search_reset (kh);
|
|
|
|
|
rc = keydb_search_issuer_sn (kh, issuer, serial);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2002-06-12 11:54:57 +02:00
|
|
|
|
if (rc == -1)
|
|
|
|
|
{
|
|
|
|
|
log_error ("certificate not found\n");
|
|
|
|
|
rc = GNUPG_No_Public_Key;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
log_error ("failed to find the certificate: %s\n",
|
|
|
|
|
gnupg_strerror(rc));
|
|
|
|
|
gpgsm_status2 (ctrl, STATUS_ERROR, "verify.findkey",
|
|
|
|
|
gnupg_error_token (rc), NULL);
|
|
|
|
|
/* fixme: we might want to append the issuer and serial
|
|
|
|
|
using our standard notation */
|
2001-11-16 18:56:23 +01:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = keydb_get_cert (kh, &cert);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2002-05-03 22:18:54 +02:00
|
|
|
|
log_error ("failed to get cert: %s\n", gnupg_strerror (rc));
|
2001-11-16 18:56:23 +01:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-10 11:14:21 +02:00
|
|
|
|
log_info (_("Signature made "));
|
|
|
|
|
if (sigtime)
|
|
|
|
|
gpgsm_dump_time (sigtime);
|
|
|
|
|
else
|
|
|
|
|
log_printf (_("[date not given]"));
|
|
|
|
|
log_printf (_(" using certificate ID %08lX\n"),
|
|
|
|
|
gpgsm_get_short_fingerprint (cert));
|
|
|
|
|
|
|
|
|
|
|
2001-11-16 18:56:23 +01:00
|
|
|
|
if (msgdigest)
|
|
|
|
|
{ /* Signed attributes are available. */
|
|
|
|
|
GCRY_MD_HD md;
|
|
|
|
|
unsigned char *s;
|
|
|
|
|
|
|
|
|
|
/* check that the message digest in the signed attributes
|
|
|
|
|
matches the one we calculated on the data */
|
|
|
|
|
s = gcry_md_read (data_md, algo);
|
|
|
|
|
if ( !s || !msgdigestlen
|
|
|
|
|
|| gcry_md_get_algo_dlen (algo) != msgdigestlen
|
|
|
|
|
|| !s || memcmp (s, msgdigest, msgdigestlen) )
|
|
|
|
|
{
|
2002-07-02 21:38:14 +02:00
|
|
|
|
char *fpr;
|
|
|
|
|
|
2002-03-05 16:56:46 +01:00
|
|
|
|
log_error ("invalid signature: message digest attribute "
|
|
|
|
|
"does not match calculated one\n");
|
2002-07-02 21:38:14 +02:00
|
|
|
|
fpr = gpgsm_get_fingerprint_hexstring (cert, GCRY_MD_SHA1);
|
|
|
|
|
gpgsm_status (ctrl, STATUS_BADSIG, fpr);
|
|
|
|
|
xfree (fpr);
|
2001-11-19 11:25:00 +01:00
|
|
|
|
goto next_signer;
|
2001-11-16 18:56:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
md = gcry_md_open (algo, 0);
|
|
|
|
|
if (!md)
|
|
|
|
|
{
|
|
|
|
|
log_error ("md_open failed: %s\n", gcry_strerror (-1));
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
2001-12-14 20:36:33 +01:00
|
|
|
|
if (DBG_HASHING)
|
|
|
|
|
gcry_md_start_debug (md, "vrfy.attr");
|
|
|
|
|
|
2001-11-19 13:42:01 +01:00
|
|
|
|
ksba_cms_set_hash_function (cms, HASH_FNC, md);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
rc = ksba_cms_hash_signed_attrs (cms, signer);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2002-05-03 22:18:54 +02:00
|
|
|
|
log_error ("hashing signed attrs failed: %s\n",
|
2001-11-16 18:56:23 +01:00
|
|
|
|
ksba_strerror (rc));
|
|
|
|
|
gcry_md_close (md);
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
rc = gpgsm_check_cms_signature (cert, sigval, md, algo);
|
|
|
|
|
gcry_md_close (md);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rc = gpgsm_check_cms_signature (cert, sigval, data_md, algo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2002-07-02 21:38:14 +02:00
|
|
|
|
char *fpr;
|
|
|
|
|
|
2001-11-24 18:43:43 +01:00
|
|
|
|
log_error ("invalid signature: %s\n", gnupg_strerror (rc));
|
2002-07-02 21:38:14 +02:00
|
|
|
|
fpr = gpgsm_get_fingerprint_hexstring (cert, GCRY_MD_SHA1);
|
|
|
|
|
gpgsm_status (ctrl, STATUS_BADSIG, fpr);
|
|
|
|
|
xfree (fpr);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
2002-06-20 12:43:02 +02:00
|
|
|
|
rc = gpgsm_cert_use_verify_p (cert); /*(this displays an info message)*/
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
gpgsm_status2 (ctrl, STATUS_ERROR, "verify.keyusage",
|
|
|
|
|
gnupg_error_token (rc), NULL);
|
|
|
|
|
rc = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-03 22:18:54 +02:00
|
|
|
|
if (DBG_X509)
|
|
|
|
|
log_debug ("signature okay - checking certs\n");
|
2002-08-16 15:55:03 +02:00
|
|
|
|
rc = gpgsm_validate_chain (ctrl, cert, &keyexptime);
|
2002-05-03 22:18:54 +02:00
|
|
|
|
if (rc == GNUPG_Certificate_Expired)
|
2002-06-12 11:54:57 +02:00
|
|
|
|
{
|
|
|
|
|
gpgsm_status (ctrl, STATUS_EXPKEYSIG, NULL);
|
|
|
|
|
rc = 0;
|
|
|
|
|
}
|
2002-05-03 22:18:54 +02:00
|
|
|
|
else
|
|
|
|
|
gpgsm_status (ctrl, STATUS_GOODSIG, NULL);
|
|
|
|
|
|
2001-11-19 13:42:01 +01:00
|
|
|
|
{
|
|
|
|
|
char *buf, *fpr, *tstr;
|
|
|
|
|
|
|
|
|
|
fpr = gpgsm_get_fingerprint_hexstring (cert, GCRY_MD_SHA1);
|
2001-11-27 18:40:09 +01:00
|
|
|
|
tstr = strtimestamp (sigtime);
|
2002-05-03 22:18:54 +02:00
|
|
|
|
buf = xmalloc ( strlen(fpr) + strlen (tstr) + 120);
|
|
|
|
|
sprintf (buf, "%s %s %lu %lu", fpr, tstr,
|
|
|
|
|
(unsigned long)sigtime, (unsigned long)keyexptime );
|
2001-11-19 13:42:01 +01:00
|
|
|
|
xfree (tstr);
|
|
|
|
|
xfree (fpr);
|
|
|
|
|
gpgsm_status (ctrl, STATUS_VALIDSIG, buf);
|
|
|
|
|
xfree (buf);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-16 15:55:03 +02:00
|
|
|
|
if (rc) /* of validate_chain */
|
2001-11-16 18:56:23 +01:00
|
|
|
|
{
|
2002-08-16 15:55:03 +02:00
|
|
|
|
log_error ("invalid certification chain: %s\n", gnupg_strerror (rc));
|
2002-08-16 16:31:49 +02:00
|
|
|
|
if (rc == GNUPG_Bad_Certificate_Chain
|
2002-06-12 11:54:57 +02:00
|
|
|
|
|| rc == GNUPG_Bad_Certificate
|
|
|
|
|
|| rc == GNUPG_Bad_CA_Certificate
|
|
|
|
|
|| rc == GNUPG_Certificate_Revoked)
|
|
|
|
|
gpgsm_status (ctrl, STATUS_TRUST_NEVER, gnupg_error_token (rc));
|
2001-11-19 13:42:01 +01:00
|
|
|
|
else
|
2002-06-12 11:54:57 +02:00
|
|
|
|
gpgsm_status (ctrl, STATUS_TRUST_UNDEFINED, gnupg_error_token (rc));
|
2001-11-16 18:56:23 +01:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
2002-08-10 11:14:21 +02:00
|
|
|
|
|
|
|
|
|
for (i=0; (p = ksba_cert_get_subject (cert, i)); i++)
|
|
|
|
|
{
|
|
|
|
|
log_info (!i? _("Good signature from")
|
|
|
|
|
: _(" aka"));
|
|
|
|
|
log_printf (" \"");
|
|
|
|
|
gpgsm_print_name (log_get_stream (), p);
|
|
|
|
|
log_printf ("\"\n");
|
|
|
|
|
ksba_free (p);
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-19 13:42:01 +01:00
|
|
|
|
gpgsm_status (ctrl, STATUS_TRUST_FULLY, NULL);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_signer:
|
|
|
|
|
rc = 0;
|
|
|
|
|
xfree (issuer);
|
|
|
|
|
xfree (serial);
|
|
|
|
|
xfree (sigval);
|
|
|
|
|
xfree (msgdigest);
|
|
|
|
|
ksba_cert_release (cert);
|
|
|
|
|
cert = NULL;
|
|
|
|
|
}
|
|
|
|
|
rc = 0;
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
2002-05-03 22:18:54 +02:00
|
|
|
|
log_error ("ksba error: %s\n", ksba_strerror (err));
|
2001-11-16 18:56:23 +01:00
|
|
|
|
rc = map_ksba_err (rc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
leave:
|
|
|
|
|
ksba_cms_release (cms);
|
2001-11-27 18:40:09 +01:00
|
|
|
|
gpgsm_destroy_reader (b64reader);
|
2001-12-20 17:51:06 +01:00
|
|
|
|
gpgsm_destroy_writer (b64writer);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
keydb_release (kh);
|
|
|
|
|
gcry_md_close (data_md);
|
2001-11-27 18:40:09 +01:00
|
|
|
|
if (fp)
|
|
|
|
|
fclose (fp);
|
2002-06-12 11:54:57 +02:00
|
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
|
gpgsm_status2 (ctrl, STATUS_ERROR, "verify.leave",
|
|
|
|
|
gnupg_error_token (rc), NULL);
|
2001-11-16 18:56:23 +01:00
|
|
|
|
return rc;
|
|
|
|
|
}
|
2002-03-12 14:36:29 +01:00
|
|
|
|
|