2003-08-05 19:11:04 +02:00
|
|
|
|
/* verify.c - Verify a messages signature
|
2011-02-04 12:57:53 +01:00
|
|
|
|
* Copyright (C) 2001, 2002, 2003, 2007,
|
2010-03-08 13:22:18 +01:00
|
|
|
|
* 2010 Free Software Foundation, Inc.
|
2020-07-03 15:47:55 +02:00
|
|
|
|
* Copyright (C) 2001-2019 Werner Koch
|
|
|
|
|
* Copyright (C) 2015-2020 g10 Code GmbH
|
2003-08-05 19:11:04 +02: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
|
2007-07-04 21:49:40 +02:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-08-05 19:11:04 +02:00
|
|
|
|
* (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
|
2016-11-05 12:02:19 +01:00
|
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2020-07-03 15:47:55 +02:00
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2003-08-05 19:11:04 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
2011-02-04 12:57:53 +01:00
|
|
|
|
#include <unistd.h>
|
2003-08-05 19:11:04 +02:00
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "gpgsm.h"
|
|
|
|
|
#include <gcrypt.h>
|
|
|
|
|
#include <ksba.h>
|
|
|
|
|
|
|
|
|
|
#include "keydb.h"
|
2017-03-07 12:21:23 +01:00
|
|
|
|
#include "../common/i18n.h"
|
2017-05-30 14:30:24 +02:00
|
|
|
|
#include "../common/compliance.h"
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
static char *
|
2003-10-31 13:12:47 +01:00
|
|
|
|
strtimestamp_r (ksba_isotime_t atime)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
char *buffer = xmalloc (15);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-10-31 13:12:47 +01:00
|
|
|
|
if (!atime || !*atime)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
strcpy (buffer, "none");
|
|
|
|
|
else
|
2003-10-31 13:12:47 +01:00
|
|
|
|
sprintf (buffer, "%.4s-%.2s-%.2s", atime, atime+4, atime+6);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-19 17:03:50 +01:00
|
|
|
|
/* Hash the data for a detached signature. Returns 0 on success. */
|
|
|
|
|
static gpg_error_t
|
2023-07-25 03:04:18 +02:00
|
|
|
|
hash_data (estream_t fp, gcry_md_hd_t md)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2007-11-19 17:03:50 +01:00
|
|
|
|
gpg_error_t err = 0;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
char buffer[4096];
|
|
|
|
|
int nread;
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
do
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2010-03-08 13:22:18 +01:00
|
|
|
|
nread = es_fread (buffer, 1, DIM(buffer), fp);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gcry_md_write (md, buffer, nread);
|
|
|
|
|
}
|
|
|
|
|
while (nread);
|
2010-03-08 13:22:18 +01:00
|
|
|
|
if (es_ferror (fp))
|
2007-11-19 17:03:50 +01:00
|
|
|
|
{
|
|
|
|
|
err = gpg_error_from_syserror ();
|
2023-07-25 03:04:18 +02:00
|
|
|
|
log_error ("read error on fp %p: %s\n", fp, gpg_strerror (err));
|
2007-11-19 17:03:50 +01:00
|
|
|
|
}
|
|
|
|
|
return err;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-25 03:04:18 +02:00
|
|
|
|
/* Perform a verify operation. To verify detached signatures, DATA_FP
|
|
|
|
|
must be different than NULL. With OUT_FP given and a non-detached
|
2010-03-08 13:22:18 +01:00
|
|
|
|
signature, the signed material is written to that stream. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
int
|
2023-07-25 03:04:18 +02:00
|
|
|
|
gpgsm_verify (ctrl_t ctrl, estream_t in_fp, estream_t data_fp,
|
|
|
|
|
estream_t out_fp)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
int i, rc;
|
2017-02-16 17:11:38 +01:00
|
|
|
|
gnupg_ksba_io_t b64reader = NULL;
|
|
|
|
|
gnupg_ksba_io_t b64writer = NULL;
|
2003-12-17 13:28:24 +01:00
|
|
|
|
ksba_reader_t reader;
|
|
|
|
|
ksba_writer_t writer = NULL;
|
|
|
|
|
ksba_cms_t cms = NULL;
|
|
|
|
|
ksba_stop_reason_t stopreason;
|
|
|
|
|
ksba_cert_t cert;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
KEYDB_HANDLE kh;
|
|
|
|
|
gcry_md_hd_t data_md = NULL;
|
|
|
|
|
int signer;
|
|
|
|
|
const char *algoid;
|
|
|
|
|
int algo;
|
2023-03-08 10:57:25 +01:00
|
|
|
|
int is_detached, maybe_detached;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
char *p;
|
|
|
|
|
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_set_type (ctrl->audit, AUDIT_TYPE_VERIFY);
|
|
|
|
|
|
2023-03-08 10:57:25 +01:00
|
|
|
|
/* Although we detect detached signatures during the parsing phase,
|
|
|
|
|
* we need to know it earlier and thus accept the caller idea of
|
|
|
|
|
* what to verify. */
|
2023-07-25 03:04:18 +02:00
|
|
|
|
maybe_detached = (data_fp != NULL);
|
2023-03-08 10:57:25 +01:00
|
|
|
|
|
2020-09-02 17:27:30 +02:00
|
|
|
|
kh = keydb_new (ctrl);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (!kh)
|
|
|
|
|
{
|
2012-08-22 18:54:38 +02:00
|
|
|
|
log_error (_("failed to allocate keyDB handle\n"));
|
2003-08-05 19:11:04 +02:00
|
|
|
|
rc = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-16 15:16:48 +01:00
|
|
|
|
rc = gnupg_ksba_create_reader
|
|
|
|
|
(&b64reader, ((ctrl->is_pem? GNUPG_KSBA_IO_PEM : 0)
|
|
|
|
|
| (ctrl->is_base64? GNUPG_KSBA_IO_BASE64 : 0)
|
2023-03-08 10:57:25 +01:00
|
|
|
|
| (ctrl->autodetect_encoding? GNUPG_KSBA_IO_AUTODETECT : 0)
|
|
|
|
|
| (maybe_detached? GNUPG_KSBA_IO_STRIP : 0)),
|
2017-02-16 15:16:48 +01:00
|
|
|
|
in_fp, &reader);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("can't create reader: %s\n", gpg_strerror (rc));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (out_fp)
|
|
|
|
|
{
|
2017-02-16 15:16:48 +01:00
|
|
|
|
rc = gnupg_ksba_create_writer
|
|
|
|
|
(&b64writer, ((ctrl->create_pem? GNUPG_KSBA_IO_PEM : 0)
|
|
|
|
|
| (ctrl->create_base64? GNUPG_KSBA_IO_BASE64 : 0)),
|
|
|
|
|
ctrl->pem_name, out_fp, &writer);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("can't create writer: %s\n", gpg_strerror (rc));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 10:37:07 +02:00
|
|
|
|
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
|
2023-06-15 12:28:55 +02:00
|
|
|
|
if (ctrl->input_size_hint)
|
|
|
|
|
gnupg_ksba_set_total (b64writer, ctrl->input_size_hint);
|
2023-06-15 10:37:07 +02:00
|
|
|
|
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = ksba_cms_new (&cms);
|
|
|
|
|
if (rc)
|
|
|
|
|
goto leave;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = ksba_cms_set_reader_writer (cms, reader, writer);
|
|
|
|
|
if (rc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
log_error ("ksba_cms_set_reader_writer failed: %s\n",
|
2004-06-06 15:00:59 +02:00
|
|
|
|
gpg_strerror (rc));
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = gcry_md_open (&data_md, 0, 0);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("md_open failed: %s\n", gpg_strerror (rc));
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
if (DBG_HASHING)
|
2011-09-20 09:54:27 +02:00
|
|
|
|
gcry_md_debug (data_md, "vrfy.data");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log (ctrl->audit, AUDIT_SETUP_READY);
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
is_detached = 0;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
do
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = ksba_cms_parse (cms, &stopreason);
|
|
|
|
|
if (rc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2004-06-06 15:00:59 +02:00
|
|
|
|
log_error ("ksba_cms_parse failed: %s\n", gpg_strerror (rc));
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stopreason == KSBA_SR_NEED_HASH)
|
|
|
|
|
{
|
|
|
|
|
is_detached = 1;
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log (ctrl->audit, AUDIT_DETACHED_SIGNATURE);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (opt.verbose)
|
|
|
|
|
log_info ("detached signature\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stopreason == KSBA_SR_NEED_HASH
|
|
|
|
|
|| stopreason == KSBA_SR_BEGIN_DATA)
|
2011-02-04 12:57:53 +01:00
|
|
|
|
{
|
2007-12-06 16:55:03 +01:00
|
|
|
|
audit_log (ctrl->audit, AUDIT_GOT_DATA);
|
|
|
|
|
|
|
|
|
|
/* We are now able to enable the hash algorithms */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
for (i=0; (algoid=ksba_cms_get_digest_algo_list (cms, i)); i++)
|
|
|
|
|
{
|
|
|
|
|
algo = gcry_md_map_name (algoid);
|
|
|
|
|
if (!algo)
|
2005-11-13 20:07:06 +01:00
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_error ("unknown hash algorithm '%s'\n",
|
2005-11-13 20:07:06 +01:00
|
|
|
|
algoid? algoid:"?");
|
|
|
|
|
if (algoid
|
|
|
|
|
&& ( !strcmp (algoid, "1.2.840.113549.1.1.2")
|
|
|
|
|
||!strcmp (algoid, "1.2.840.113549.2.2")))
|
|
|
|
|
log_info (_("(this is the MD2 algorithm)\n"));
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_BAD_DATA_HASH_ALGO, algoid);
|
2005-11-13 20:07:06 +01:00
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
else
|
2007-11-19 17:03:50 +01:00
|
|
|
|
{
|
2007-12-13 16:45:40 +01:00
|
|
|
|
if (DBG_X509)
|
|
|
|
|
log_debug ("enabling hash algorithm %d (%s)\n",
|
|
|
|
|
algo, algoid? algoid:"");
|
2007-11-19 17:03:50 +01:00
|
|
|
|
gcry_md_enable (data_md, algo);
|
|
|
|
|
audit_log_i (ctrl->audit, AUDIT_DATA_HASH_ALGO, algo);
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
2007-12-13 16:45:40 +01:00
|
|
|
|
if (opt.extra_digest_algo)
|
|
|
|
|
{
|
|
|
|
|
if (DBG_X509)
|
2011-02-04 12:57:53 +01:00
|
|
|
|
log_debug ("enabling extra hash algorithm %d\n",
|
2007-12-13 16:45:40 +01:00
|
|
|
|
opt.extra_digest_algo);
|
|
|
|
|
gcry_md_enable (data_md, opt.extra_digest_algo);
|
2009-12-02 19:33:59 +01:00
|
|
|
|
audit_log_i (ctrl->audit, AUDIT_DATA_HASH_ALGO,
|
|
|
|
|
opt.extra_digest_algo);
|
2007-12-13 16:45:40 +01:00
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (is_detached)
|
|
|
|
|
{
|
2023-07-25 03:04:18 +02:00
|
|
|
|
if (!data_fp)
|
2007-11-19 17:03:50 +01:00
|
|
|
|
{
|
|
|
|
|
log_info ("detached signature w/o data "
|
|
|
|
|
"- assuming certs-only\n");
|
|
|
|
|
audit_log (ctrl->audit, AUDIT_CERT_ONLY_SIG);
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
else
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_ok (ctrl->audit, AUDIT_DATA_HASHING,
|
2023-07-25 03:04:18 +02:00
|
|
|
|
hash_data (data_fp, data_md));
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ksba_cms_set_hash_function (cms, HASH_FNC, data_md);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (stopreason == KSBA_SR_END_DATA)
|
|
|
|
|
{ /* The data bas been hashed */
|
2009-12-02 19:33:59 +01:00
|
|
|
|
audit_log_ok (ctrl->audit, AUDIT_DATA_HASHING, 0);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
while (stopreason != KSBA_SR_READY);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
if (b64writer)
|
|
|
|
|
{
|
2017-02-16 17:11:38 +01:00
|
|
|
|
rc = gnupg_ksba_finish_writer (b64writer);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
if (rc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
log_error ("write failed: %s\n", gpg_strerror (rc));
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_ok (ctrl->audit, AUDIT_WRITE_ERROR, rc);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 03:04:18 +02:00
|
|
|
|
if (data_fp && !is_detached)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
log_error ("data given for a non-detached signature\n");
|
|
|
|
|
rc = gpg_error (GPG_ERR_CONFLICT);
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log (ctrl->audit, AUDIT_USAGE_ERROR);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0; (cert=ksba_cms_get_cert (cms, i)); i++)
|
|
|
|
|
{
|
|
|
|
|
/* 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. */
|
2011-02-04 12:57:53 +01:00
|
|
|
|
audit_log_cert (ctrl->audit, AUDIT_SAVE_CERT, cert,
|
2016-11-10 17:01:19 +01:00
|
|
|
|
keydb_store_cert (ctrl, cert, 0, NULL));
|
2003-08-05 19:11:04 +02:00
|
|
|
|
ksba_cert_release (cert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cert = NULL;
|
|
|
|
|
for (signer=0; ; signer++)
|
|
|
|
|
{
|
|
|
|
|
char *issuer = NULL;
|
2020-07-03 15:47:55 +02:00
|
|
|
|
gcry_sexp_t sigval = NULL;
|
2003-10-31 13:12:47 +01:00
|
|
|
|
ksba_isotime_t sigtime, keyexptime;
|
2003-12-17 13:28:24 +01:00
|
|
|
|
ksba_sexp_t serial;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
char *msgdigest = NULL;
|
|
|
|
|
size_t msgdigestlen;
|
|
|
|
|
char *ctattr;
|
2007-12-13 16:45:40 +01:00
|
|
|
|
int sigval_hash_algo;
|
2007-08-10 18:52:05 +02:00
|
|
|
|
int info_pkalgo;
|
2020-05-08 13:42:36 +02:00
|
|
|
|
unsigned int nbits;
|
|
|
|
|
int pkalgo;
|
|
|
|
|
char *pkalgostr = NULL;
|
2023-01-12 20:52:27 +01:00
|
|
|
|
char *pkcurve = NULL;
|
2020-05-08 13:42:36 +02:00
|
|
|
|
char *pkfpr = NULL;
|
2020-07-03 15:47:55 +02:00
|
|
|
|
unsigned int pkalgoflags, verifyflags;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = ksba_cms_get_issuer_serial (cms, signer, &issuer, &serial);
|
|
|
|
|
if (!signer && gpg_err_code (rc) == GPG_ERR_NO_DATA
|
2023-07-25 03:04:18 +02:00
|
|
|
|
&& !data_fp && is_detached)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
log_info ("certs-only message accepted\n");
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = 0;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-06-06 15:00:59 +02:00
|
|
|
|
if (rc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2004-06-06 15:00:59 +02:00
|
|
|
|
if (signer && rc == -1)
|
|
|
|
|
rc = 0;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-04-05 19:25:21 +02:00
|
|
|
|
|
|
|
|
|
gpgsm_status (ctrl, STATUS_NEWSIG, NULL);
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_i (ctrl->audit, AUDIT_NEW_SIG, signer);
|
2004-04-05 19:25:21 +02:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (DBG_X509)
|
|
|
|
|
{
|
2012-06-05 19:29:22 +02:00
|
|
|
|
log_debug ("signer %d - issuer: '%s'\n",
|
2003-08-05 19:11:04 +02:00
|
|
|
|
signer, issuer? issuer:"[NONE]");
|
|
|
|
|
log_debug ("signer %d - serial: ", signer);
|
|
|
|
|
gpgsm_dump_serial (serial);
|
|
|
|
|
log_printf ("\n");
|
|
|
|
|
}
|
2007-11-19 17:03:50 +01:00
|
|
|
|
if (ctrl->audit)
|
|
|
|
|
{
|
|
|
|
|
char *tmpstr = gpgsm_format_sn_issuer (serial, issuer);
|
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_NAME, tmpstr);
|
|
|
|
|
xfree (tmpstr);
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = ksba_cms_get_signing_time (cms, signer, sigtime);
|
|
|
|
|
if (gpg_err_code (rc) == GPG_ERR_NO_DATA)
|
2003-10-31 13:12:47 +01:00
|
|
|
|
*sigtime = 0;
|
2004-06-06 15:00:59 +02:00
|
|
|
|
else if (rc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2004-06-06 15:00:59 +02:00
|
|
|
|
log_error ("error getting signing time: %s\n", gpg_strerror (rc));
|
|
|
|
|
*sigtime = 0; /* (we can't encode an error in the time string.) */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = ksba_cms_get_message_digest (cms, signer,
|
|
|
|
|
&msgdigest, &msgdigestlen);
|
|
|
|
|
if (!rc)
|
2003-08-05 19:11:04 +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);
|
2017-05-31 12:51:56 +02:00
|
|
|
|
if (! gcry_md_is_enabled (data_md, algo))
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
|
log_error ("digest algo %d (%s) has not been enabled\n",
|
2007-12-13 16:45:40 +01:00
|
|
|
|
algo, algoid?algoid:"");
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "unsupported");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-06-06 15:00:59 +02:00
|
|
|
|
else if (gpg_err_code (rc) == GPG_ERR_NO_DATA)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2020-07-08 14:40:34 +02:00
|
|
|
|
log_assert (!msgdigest);
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = 0;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
algoid = NULL;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
algo = 0;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
else /* real error */
|
2007-11-19 17:03:50 +01:00
|
|
|
|
{
|
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "error");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = ksba_cms_get_sigattr_oids (cms, signer,
|
|
|
|
|
"1.2.840.113549.1.9.3", &ctattr);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
if (!rc)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
if (DBG_X509)
|
2004-06-06 15:00:59 +02:00
|
|
|
|
log_debug ("signer %d - content-type attribute: %s",
|
|
|
|
|
signer, ctattr);
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
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;
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "bad");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
ksba_free (ctattr);
|
|
|
|
|
ctattr = NULL;
|
|
|
|
|
}
|
2004-06-06 15:00:59 +02:00
|
|
|
|
else if (rc != -1)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
log_error ("error getting content-type attribute: %s\n",
|
2004-06-06 15:00:59 +02:00
|
|
|
|
gpg_strerror (rc));
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "bad");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
2004-06-06 15:00:59 +02:00
|
|
|
|
rc = 0;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
|
2020-07-03 15:47:55 +02:00
|
|
|
|
sigval = gpgsm_ksba_cms_get_sig_val (cms, signer);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (!sigval)
|
|
|
|
|
{
|
|
|
|
|
log_error ("no signature value available\n");
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "bad");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
2020-07-03 15:47:55 +02:00
|
|
|
|
|
|
|
|
|
sigval_hash_algo = gpgsm_get_hash_algo_from_sigval (sigval, &pkalgoflags);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (DBG_X509)
|
2007-12-13 16:45:40 +01:00
|
|
|
|
{
|
2020-07-03 15:47:55 +02:00
|
|
|
|
log_debug ("signer %d - signature available (sigval hash=%d pkaf=%u)",
|
|
|
|
|
signer, sigval_hash_algo, pkalgoflags);
|
2007-12-13 16:45:40 +01:00
|
|
|
|
}
|
|
|
|
|
if (!sigval_hash_algo)
|
|
|
|
|
sigval_hash_algo = algo; /* Fallback used e.g. with old libksba. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
/* Find the certificate of the signer */
|
|
|
|
|
keydb_search_reset (kh);
|
2016-11-10 17:01:19 +01:00
|
|
|
|
rc = keydb_search_issuer_sn (ctrl, kh, issuer, serial);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2021-11-26 09:35:21 +01:00
|
|
|
|
if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND)
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
log_error ("certificate not found\n");
|
|
|
|
|
rc = gpg_error (GPG_ERR_NO_PUBKEY);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
log_error ("failed to find the certificate: %s\n",
|
|
|
|
|
gpg_strerror(rc));
|
|
|
|
|
{
|
|
|
|
|
char numbuf[50];
|
|
|
|
|
sprintf (numbuf, "%d", rc);
|
|
|
|
|
|
|
|
|
|
gpgsm_status2 (ctrl, STATUS_ERROR, "verify.findkey",
|
|
|
|
|
numbuf, NULL);
|
|
|
|
|
}
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "no-cert");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = keydb_get_cert (kh, &cert);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("failed to get cert: %s\n", gpg_strerror (rc));
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "error");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-08 13:42:36 +02:00
|
|
|
|
pkfpr = gpgsm_get_fingerprint_hexstring (cert, GCRY_MD_SHA1);
|
|
|
|
|
pkalgostr = gpgsm_pubkey_algo_string (cert, NULL);
|
2023-10-24 14:51:16 +02:00
|
|
|
|
pkalgo = gpgsm_get_key_algo_info (cert, &nbits, &pkcurve);
|
2020-05-08 14:14:01 +02:00
|
|
|
|
/* Remap the ECC algo to the algo we use. Note that EdDSA has
|
|
|
|
|
* already been mapped. */
|
|
|
|
|
if (pkalgo == GCRY_PK_ECC)
|
|
|
|
|
pkalgo = GCRY_PK_ECDSA;
|
2017-06-06 16:01:40 +02:00
|
|
|
|
|
2020-05-08 13:42:36 +02:00
|
|
|
|
/* Print infos about the signature. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
log_info (_("Signature made "));
|
2003-10-31 13:12:47 +01:00
|
|
|
|
if (*sigtime)
|
2020-05-08 13:42:36 +02:00
|
|
|
|
{
|
|
|
|
|
/* We take the freedom as noted in RFC3339 to use a space
|
2020-05-08 14:14:01 +02:00
|
|
|
|
* instead of the "T" delimiter between date and time. We
|
2020-05-08 13:42:36 +02:00
|
|
|
|
* also append a separate UTC instead of a "Z" or "+00:00"
|
|
|
|
|
* suffix because that makes it clear to everyone what kind
|
|
|
|
|
* of time this is. */
|
|
|
|
|
dump_isotime (sigtime);
|
|
|
|
|
log_printf (" UTC");
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
else
|
|
|
|
|
log_printf (_("[date not given]"));
|
2020-05-08 13:42:36 +02:00
|
|
|
|
log_info (_(" using %s key %s\n"), pkalgostr, pkfpr);
|
|
|
|
|
if (opt.verbose)
|
|
|
|
|
{
|
|
|
|
|
log_info (_("algorithm:"));
|
|
|
|
|
log_printf (" %s + %s",
|
2020-05-08 14:14:01 +02:00
|
|
|
|
pubkey_algo_to_string (pkalgo),
|
2020-05-08 13:42:36 +02:00
|
|
|
|
gcry_md_algo_name (sigval_hash_algo));
|
|
|
|
|
if (algo != sigval_hash_algo)
|
|
|
|
|
log_printf (" (%s)", gcry_md_algo_name (algo));
|
|
|
|
|
log_printf ("\n");
|
|
|
|
|
}
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2009-12-02 19:33:59 +01:00
|
|
|
|
audit_log_i (ctrl->audit, AUDIT_DATA_HASH_ALGO, algo);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2020-05-08 13:42:36 +02:00
|
|
|
|
/* Check compliance. */
|
2023-11-08 17:09:04 +01:00
|
|
|
|
pkalgoflags |= PK_ALGO_FLAG_ECC18;
|
2020-05-08 13:42:36 +02:00
|
|
|
|
if (! gnupg_pk_is_allowed (opt.compliance, PK_USE_VERIFICATION,
|
2023-10-24 14:51:16 +02:00
|
|
|
|
pkalgo, pkalgoflags, NULL, nbits, pkcurve))
|
2020-05-08 13:42:36 +02:00
|
|
|
|
{
|
|
|
|
|
char kidstr[10+1];
|
|
|
|
|
|
|
|
|
|
snprintf (kidstr, sizeof kidstr, "0x%08lX",
|
|
|
|
|
gpgsm_get_short_fingerprint (cert, NULL));
|
|
|
|
|
log_error (_("key %s may not be used for signing in %s mode\n"),
|
|
|
|
|
kidstr,
|
|
|
|
|
gnupg_compliance_option_string (opt.compliance));
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! gnupg_digest_is_allowed (opt.compliance, 0, sigval_hash_algo))
|
|
|
|
|
{
|
|
|
|
|
log_error (_("digest algorithm '%s' may not be used in %s mode\n"),
|
|
|
|
|
gcry_md_algo_name (sigval_hash_algo),
|
|
|
|
|
gnupg_compliance_option_string (opt.compliance));
|
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 20:52:27 +01:00
|
|
|
|
/* Print compliance warning for the key. */
|
|
|
|
|
if (!opt.quiet
|
|
|
|
|
&& !gnupg_pk_is_compliant (opt.compliance, pkalgo, pkalgoflags,
|
|
|
|
|
NULL, nbits, pkcurve))
|
|
|
|
|
{
|
|
|
|
|
log_info (_("WARNING: This key is not suitable for signing"
|
|
|
|
|
" in %s mode\n"),
|
|
|
|
|
gnupg_compliance_option_string (opt.compliance));
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-08 13:42:36 +02:00
|
|
|
|
/* Check compliance with CO_DE_VS. */
|
2020-07-03 15:47:55 +02:00
|
|
|
|
if (gnupg_pk_is_compliant (CO_DE_VS, pkalgo, pkalgoflags,
|
2023-01-12 20:52:27 +01:00
|
|
|
|
NULL, nbits, pkcurve)
|
2021-01-28 15:48:08 +01:00
|
|
|
|
&& gnupg_gcrypt_is_compliant (CO_DE_VS)
|
2020-05-08 13:42:36 +02:00
|
|
|
|
&& gnupg_digest_is_compliant (CO_DE_VS, sigval_hash_algo))
|
|
|
|
|
gpgsm_status (ctrl, STATUS_VERIFICATION_COMPLIANCE_MODE,
|
|
|
|
|
gnupg_status_compliance_flag (CO_DE_VS));
|
2022-03-08 19:06:30 +01:00
|
|
|
|
else if (opt.require_compliance
|
|
|
|
|
&& opt.compliance == CO_DE_VS)
|
|
|
|
|
{
|
|
|
|
|
log_error (_("operation forced to fail due to"
|
|
|
|
|
" unfulfilled compliance rules\n"));
|
|
|
|
|
gpgsm_errors_seen = 1;
|
|
|
|
|
}
|
2020-05-08 13:42:36 +02:00
|
|
|
|
|
|
|
|
|
/* Now we can check the signature. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (msgdigest)
|
|
|
|
|
{ /* Signed attributes are available. */
|
|
|
|
|
gcry_md_hd_t md;
|
|
|
|
|
unsigned char *s;
|
|
|
|
|
|
2007-12-13 16:45:40 +01:00
|
|
|
|
/* Check that the message digest in the signed attributes
|
|
|
|
|
matches the one we calculated on the data. */
|
2003-08-05 19:11:04 +02:00
|
|
|
|
s = gcry_md_read (data_md, algo);
|
|
|
|
|
if ( !s || !msgdigestlen
|
|
|
|
|
|| gcry_md_get_algo_dlen (algo) != msgdigestlen
|
2015-01-23 15:30:03 +01:00
|
|
|
|
|| memcmp (s, msgdigest, msgdigestlen) )
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
|
|
|
|
char *fpr;
|
|
|
|
|
|
2008-04-18 11:20:25 +02:00
|
|
|
|
log_error (_("invalid signature: message digest attribute "
|
|
|
|
|
"does not match computed one\n"));
|
|
|
|
|
if (DBG_X509)
|
|
|
|
|
{
|
|
|
|
|
if (msgdigest)
|
2017-11-27 15:00:25 +01:00
|
|
|
|
log_printhex (msgdigest, msgdigestlen, "message: ");
|
2008-04-18 11:20:25 +02:00
|
|
|
|
if (s)
|
2017-11-27 15:00:25 +01:00
|
|
|
|
log_printhex (s, gcry_md_get_algo_dlen (algo),
|
|
|
|
|
"computed: ");
|
2008-04-18 11:20:25 +02:00
|
|
|
|
}
|
2006-11-14 11:23:21 +01:00
|
|
|
|
fpr = gpgsm_fpr_and_name_for_status (cert);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gpgsm_status (ctrl, STATUS_BADSIG, fpr);
|
|
|
|
|
xfree (fpr);
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "bad");
|
2011-02-04 12:57:53 +01:00
|
|
|
|
goto next_signer;
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2009-12-02 19:33:59 +01:00
|
|
|
|
audit_log_i (ctrl->audit, AUDIT_ATTR_HASH_ALGO, sigval_hash_algo);
|
2007-12-13 16:45:40 +01:00
|
|
|
|
rc = gcry_md_open (&md, sigval_hash_algo, 0);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("md_open failed: %s\n", gpg_strerror (rc));
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "error");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
if (DBG_HASHING)
|
2011-09-20 09:54:27 +02:00
|
|
|
|
gcry_md_debug (md, "vrfy.attr");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
|
|
|
|
ksba_cms_set_hash_function (cms, HASH_FNC, md);
|
|
|
|
|
rc = ksba_cms_hash_signed_attrs (cms, signer);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
log_error ("hashing signed attrs failed: %s\n",
|
2003-11-12 16:17:44 +01:00
|
|
|
|
gpg_strerror (rc));
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gcry_md_close (md);
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "error");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
2020-07-03 15:47:55 +02:00
|
|
|
|
rc = gpgsm_check_cms_signature (cert, sigval, md, sigval_hash_algo,
|
|
|
|
|
pkalgoflags, &info_pkalgo);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gcry_md_close (md);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
|
rc = gpgsm_check_cms_signature (cert, sigval, data_md,
|
2020-07-03 15:47:55 +02:00
|
|
|
|
algo, pkalgoflags, &info_pkalgo);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
char *fpr;
|
|
|
|
|
|
|
|
|
|
log_error ("invalid signature: %s\n", gpg_strerror (rc));
|
2006-11-14 11:23:21 +01:00
|
|
|
|
fpr = gpgsm_fpr_and_name_for_status (cert);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gpgsm_status (ctrl, STATUS_BADSIG, fpr);
|
|
|
|
|
xfree (fpr);
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "bad");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
rc = gpgsm_cert_use_verify_p (cert); /*(this displays an info message)*/
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
gpgsm_status_with_err_code (ctrl, STATUS_ERROR, "verify.keyusage",
|
|
|
|
|
gpg_err_code (rc));
|
|
|
|
|
rc = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DBG_X509)
|
|
|
|
|
log_debug ("signature okay - checking certs\n");
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log (ctrl->audit, AUDIT_VALIDATE_CHAIN);
|
2007-08-10 18:52:05 +02:00
|
|
|
|
rc = gpgsm_validate_chain (ctrl, cert,
|
|
|
|
|
*sigtime? sigtime : "19700101T000000",
|
2011-02-04 12:57:53 +01:00
|
|
|
|
keyexptime, 0,
|
2007-08-10 18:52:05 +02:00
|
|
|
|
NULL, 0, &verifyflags);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
{
|
2006-11-14 11:23:21 +01:00
|
|
|
|
char *fpr, *buf, *tstr;
|
|
|
|
|
|
|
|
|
|
fpr = gpgsm_fpr_and_name_for_status (cert);
|
|
|
|
|
if (gpg_err_code (rc) == GPG_ERR_CERT_EXPIRED)
|
|
|
|
|
{
|
|
|
|
|
gpgsm_status (ctrl, STATUS_EXPKEYSIG, fpr);
|
|
|
|
|
rc = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gpgsm_status (ctrl, STATUS_GOODSIG, fpr);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2006-11-14 11:23:21 +01:00
|
|
|
|
xfree (fpr);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
|
2020-05-08 13:42:36 +02:00
|
|
|
|
/* FIXME: INFO_PKALGO correctly shows ECDSA but PKALGO is then
|
2020-07-03 15:47:55 +02:00
|
|
|
|
* ECC. We should use the ECDSA here and need to find a way to
|
2022-11-25 09:21:58 +01:00
|
|
|
|
* figure this out without using the bogus assumption in
|
|
|
|
|
* gpgsm_check_cms_signature that ECC is always ECDSA. */
|
2020-05-08 13:42:36 +02:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
fpr = gpgsm_get_fingerprint_hexstring (cert, GCRY_MD_SHA1);
|
|
|
|
|
tstr = strtimestamp_r (sigtime);
|
2007-08-10 18:52:05 +02:00
|
|
|
|
buf = xasprintf ("%s %s %s %s 0 0 %d %d 00", fpr, tstr,
|
|
|
|
|
*sigtime? sigtime : "0",
|
|
|
|
|
*keyexptime? keyexptime : "0",
|
|
|
|
|
info_pkalgo, algo);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
xfree (tstr);
|
|
|
|
|
xfree (fpr);
|
|
|
|
|
gpgsm_status (ctrl, STATUS_VALIDSIG, buf);
|
|
|
|
|
xfree (buf);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 16:55:03 +01:00
|
|
|
|
audit_log_ok (ctrl->audit, AUDIT_CHAIN_STATUS, rc);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
if (rc) /* of validate_chain */
|
|
|
|
|
{
|
|
|
|
|
log_error ("invalid certification chain: %s\n", gpg_strerror (rc));
|
|
|
|
|
if (gpg_err_code (rc) == GPG_ERR_BAD_CERT_CHAIN
|
|
|
|
|
|| gpg_err_code (rc) == GPG_ERR_BAD_CERT
|
|
|
|
|
|| gpg_err_code (rc) == GPG_ERR_BAD_CA_CERT
|
|
|
|
|
|| gpg_err_code (rc) == GPG_ERR_CERT_REVOKED)
|
|
|
|
|
gpgsm_status_with_err_code (ctrl, STATUS_TRUST_NEVER, NULL,
|
|
|
|
|
gpg_err_code (rc));
|
|
|
|
|
else
|
2011-02-04 12:57:53 +01:00
|
|
|
|
gpgsm_status_with_err_code (ctrl, STATUS_TRUST_UNDEFINED, NULL,
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gpg_err_code (rc));
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "bad");
|
2003-08-05 19:11:04 +02:00
|
|
|
|
goto next_signer;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-19 17:03:50 +01:00
|
|
|
|
audit_log_s (ctrl->audit, AUDIT_SIG_STATUS, "good");
|
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
for (i=0; (p = ksba_cert_get_subject (cert, i)); i++)
|
|
|
|
|
{
|
|
|
|
|
log_info (!i? _("Good signature from")
|
|
|
|
|
: _(" aka"));
|
|
|
|
|
log_printf (" \"");
|
2010-03-15 12:15:45 +01:00
|
|
|
|
gpgsm_es_print_name (log_get_stream (), p);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
log_printf ("\"\n");
|
|
|
|
|
ksba_free (p);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-08 13:42:36 +02:00
|
|
|
|
|
2007-08-10 18:52:05 +02:00
|
|
|
|
/* Print a note if this is a qualified signature. */
|
|
|
|
|
{
|
|
|
|
|
size_t qualbuflen;
|
|
|
|
|
char qualbuffer[1];
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2007-08-10 18:52:05 +02:00
|
|
|
|
rc = ksba_cert_get_user_data (cert, "is_qualified", &qualbuffer,
|
|
|
|
|
sizeof (qualbuffer), &qualbuflen);
|
|
|
|
|
if (!rc && qualbuflen)
|
|
|
|
|
{
|
|
|
|
|
if (*qualbuffer)
|
|
|
|
|
{
|
|
|
|
|
log_info (_("This is a qualified signature\n"));
|
|
|
|
|
if (!opt.qualsig_approval)
|
2011-02-04 12:57:53 +01:00
|
|
|
|
log_info
|
2007-08-10 18:52:05 +02:00
|
|
|
|
(_("Note, that this software is not officially approved "
|
|
|
|
|
"to create or verify such signatures.\n"));
|
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
}
|
2007-08-10 18:52:05 +02:00
|
|
|
|
else if (gpg_err_code (rc) != GPG_ERR_NOT_FOUND)
|
|
|
|
|
log_error ("get_user_data(is_qualified) failed: %s\n",
|
2011-02-04 12:57:53 +01:00
|
|
|
|
gpg_strerror (rc));
|
2007-08-10 18:52:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
gpgsm_status (ctrl, STATUS_TRUST_FULLY,
|
2011-12-07 16:15:15 +01:00
|
|
|
|
(verifyflags & VALIDATE_FLAG_STEED)?
|
|
|
|
|
"0 steed":
|
2007-08-10 18:52:05 +02:00
|
|
|
|
(verifyflags & VALIDATE_FLAG_CHAIN_MODEL)?
|
|
|
|
|
"0 chain": "0 shell");
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
2003-08-05 19:11:04 +02:00
|
|
|
|
next_signer:
|
|
|
|
|
rc = 0;
|
|
|
|
|
xfree (issuer);
|
|
|
|
|
xfree (serial);
|
2020-07-03 15:47:55 +02:00
|
|
|
|
gcry_sexp_release (sigval);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
xfree (msgdigest);
|
2020-05-08 13:42:36 +02:00
|
|
|
|
xfree (pkalgostr);
|
2023-01-12 20:52:27 +01:00
|
|
|
|
xfree (pkcurve);
|
2020-05-08 13:42:36 +02:00
|
|
|
|
xfree (pkfpr);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
ksba_cert_release (cert);
|
|
|
|
|
cert = NULL;
|
|
|
|
|
}
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
|
|
leave:
|
|
|
|
|
ksba_cms_release (cms);
|
2017-02-16 17:11:38 +01:00
|
|
|
|
gnupg_ksba_destroy_reader (b64reader);
|
|
|
|
|
gnupg_ksba_destroy_writer (b64writer);
|
2011-02-04 12:57:53 +01:00
|
|
|
|
keydb_release (kh);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
gcry_md_close (data_md);
|
|
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
char numbuf[50];
|
|
|
|
|
sprintf (numbuf, "%d", rc );
|
|
|
|
|
gpgsm_status2 (ctrl, STATUS_ERROR, "verify.leave",
|
2024-01-15 09:13:46 +01:00
|
|
|
|
numbuf,
|
|
|
|
|
gpg_err_code (rc) == GPG_ERR_EPIPE?
|
|
|
|
|
"-- (Broken pipe on input or output)":
|
|
|
|
|
gpg_err_code (rc) == GPG_ERR_EOF?
|
|
|
|
|
"-- (End of file)" : NULL,
|
|
|
|
|
NULL);
|
2003-08-05 19:11:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
}
|