2003-06-05 09:14:21 +02:00
|
|
|
|
/* keyid.c - key ID and fingerprint handling
|
2006-04-19 13:26:11 +02:00
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2003,
|
2010-04-20 19:57:50 +02:00
|
|
|
|
* 2004, 2006, 2010 Free Software Foundation, Inc.
|
2014-02-05 10:37:59 +01:00
|
|
|
|
* Copyright (C) 2014 Werner Koch
|
2016-02-19 14:48:56 +01:00
|
|
|
|
* Copyright (C) 2016 g10 Code GmbH
|
2003-06-05 09:14:21 +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-06-05 09:14:21 +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/>.
|
2003-06-05 09:14:21 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <time.h>
|
2003-06-18 21:56:13 +02:00
|
|
|
|
|
|
|
|
|
#include "gpg.h"
|
2017-03-07 12:21:23 +01:00
|
|
|
|
#include "../common/util.h"
|
2003-06-05 09:14:21 +02:00
|
|
|
|
#include "main.h"
|
|
|
|
|
#include "packet.h"
|
|
|
|
|
#include "options.h"
|
|
|
|
|
#include "keydb.h"
|
2017-03-07 12:21:23 +01:00
|
|
|
|
#include "../common/i18n.h"
|
2008-12-11 18:44:52 +01:00
|
|
|
|
#include "rmd160.h"
|
2017-03-07 12:21:23 +01:00
|
|
|
|
#include "../common/host2net.h"
|
2015-02-11 10:27:57 +01:00
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2010-08-31 17:58:39 +02:00
|
|
|
|
#define KEYID_STR_SIZE 19
|
|
|
|
|
|
2010-10-27 13:26:53 +02:00
|
|
|
|
#ifdef HAVE_UNSIGNED_TIME_T
|
|
|
|
|
# define IS_INVALID_TIME_T(a) ((a) == (time_t)(-1))
|
2011-02-02 15:48:54 +01:00
|
|
|
|
#else
|
2010-10-27 13:26:53 +02:00
|
|
|
|
/* Error or 32 bit time_t and value after 2038-01-19. */
|
|
|
|
|
# define IS_INVALID_TIME_T(a) ((a) < 0)
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-08-31 17:58:39 +02:00
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
/* Return a letter describing the public key algorithms. */
|
2003-06-05 09:14:21 +02:00
|
|
|
|
int
|
|
|
|
|
pubkey_letter( int algo )
|
|
|
|
|
{
|
2010-09-06 21:57:42 +02:00
|
|
|
|
switch (algo)
|
|
|
|
|
{
|
|
|
|
|
case PUBKEY_ALGO_RSA: return 'R' ;
|
|
|
|
|
case PUBKEY_ALGO_RSA_E: return 'r' ;
|
|
|
|
|
case PUBKEY_ALGO_RSA_S: return 's' ;
|
2011-01-21 12:00:57 +01:00
|
|
|
|
case PUBKEY_ALGO_ELGAMAL_E: return 'g' ;
|
2010-09-06 21:57:42 +02:00
|
|
|
|
case PUBKEY_ALGO_ELGAMAL: return 'G' ;
|
|
|
|
|
case PUBKEY_ALGO_DSA: return 'D' ;
|
2011-01-21 12:00:57 +01:00
|
|
|
|
case PUBKEY_ALGO_ECDH: return 'e' ; /* ECC DH (encrypt only) */
|
2014-02-05 10:37:59 +01:00
|
|
|
|
case PUBKEY_ALGO_ECDSA: return 'E' ; /* ECC DSA (sign only) */
|
|
|
|
|
case PUBKEY_ALGO_EDDSA: return 'E' ; /* ECC EdDSA (sign only) */
|
2010-09-06 21:57:42 +02:00
|
|
|
|
default: return '?';
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 10:37:59 +01:00
|
|
|
|
/* Return a string describing the public key algorithm and the
|
2019-04-03 09:04:49 +02:00
|
|
|
|
keysize. For elliptic curves the function prints the name of the
|
2014-02-05 10:37:59 +01:00
|
|
|
|
curve because the keysize is a property of the curve. The string
|
|
|
|
|
is copied to the supplied buffer up a length of BUFSIZE-1.
|
|
|
|
|
Examples for the output are:
|
|
|
|
|
|
2017-09-08 00:41:10 +02:00
|
|
|
|
"rsa3072" - RSA with 3072 bit
|
2014-02-05 10:37:59 +01:00
|
|
|
|
"elg1024" - Elgamal with 1024 bit
|
|
|
|
|
"ed25519" - ECC using the curve Ed25519.
|
|
|
|
|
"E_1.2.3.4" - ECC using the unsupported curve with OID "1.2.3.4".
|
|
|
|
|
"E_1.3.6.1.4.1.11591.2.12242973" ECC with a bogus OID.
|
|
|
|
|
"unknown_N" - Unknown OpenPGP algorithm N.
|
|
|
|
|
|
|
|
|
|
If the option --legacy-list-mode is active, the output use the
|
|
|
|
|
legacy format:
|
|
|
|
|
|
2017-09-08 00:41:10 +02:00
|
|
|
|
"3072R" - RSA with 3072 bit
|
2014-02-05 10:37:59 +01:00
|
|
|
|
"1024g" - Elgamal with 1024 bit
|
|
|
|
|
"256E" - ECDSA using a curve with 256 bit
|
|
|
|
|
|
|
|
|
|
The macro PUBKEY_STRING_SIZE may be used to allocate a buffer with
|
2020-02-09 21:20:48 +01:00
|
|
|
|
a suitable size. Note that a more general version of this function
|
|
|
|
|
exists as get_keyalgo_string. However, that has no special
|
|
|
|
|
treatment for the old and unsupported Elgamal which we here print as
|
|
|
|
|
xxxNNNN. */
|
2014-02-05 10:37:59 +01:00
|
|
|
|
char *
|
|
|
|
|
pubkey_string (PKT_public_key *pk, char *buffer, size_t bufsize)
|
|
|
|
|
{
|
|
|
|
|
const char *prefix = NULL;
|
|
|
|
|
|
|
|
|
|
if (opt.legacy_list_mode)
|
|
|
|
|
{
|
|
|
|
|
snprintf (buffer, bufsize, "%4u%c",
|
|
|
|
|
nbits_from_pk (pk), pubkey_letter (pk->pubkey_algo));
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (pk->pubkey_algo)
|
|
|
|
|
{
|
|
|
|
|
case PUBKEY_ALGO_RSA:
|
|
|
|
|
case PUBKEY_ALGO_RSA_E:
|
|
|
|
|
case PUBKEY_ALGO_RSA_S: prefix = "rsa"; break;
|
|
|
|
|
case PUBKEY_ALGO_ELGAMAL_E: prefix = "elg"; break;
|
|
|
|
|
case PUBKEY_ALGO_DSA: prefix = "dsa"; break;
|
|
|
|
|
case PUBKEY_ALGO_ELGAMAL: prefix = "xxx"; break;
|
|
|
|
|
case PUBKEY_ALGO_ECDH:
|
|
|
|
|
case PUBKEY_ALGO_ECDSA:
|
|
|
|
|
case PUBKEY_ALGO_EDDSA: prefix = ""; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prefix && *prefix)
|
|
|
|
|
snprintf (buffer, bufsize, "%s%u", prefix, nbits_from_pk (pk));
|
|
|
|
|
else if (prefix)
|
|
|
|
|
{
|
|
|
|
|
char *curve = openpgp_oid_to_str (pk->pkey[0]);
|
2015-08-06 09:44:03 +02:00
|
|
|
|
const char *name = openpgp_oid_to_curve (curve, 0);
|
2014-02-05 10:37:59 +01:00
|
|
|
|
|
2015-07-08 08:05:06 +02:00
|
|
|
|
if (name)
|
2014-02-05 10:37:59 +01:00
|
|
|
|
snprintf (buffer, bufsize, "%s", name);
|
|
|
|
|
else if (curve)
|
|
|
|
|
snprintf (buffer, bufsize, "E_%s", curve);
|
|
|
|
|
else
|
|
|
|
|
snprintf (buffer, bufsize, "E_error");
|
|
|
|
|
xfree (curve);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
snprintf (buffer, bufsize, "unknown_%u", (unsigned int)pk->pubkey_algo);
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
|
2019-03-14 11:20:07 +01:00
|
|
|
|
/* Hash a public key. This function is useful for v4 and v5
|
|
|
|
|
* fingerprints and for v3 or v4 key signing. */
|
2006-04-19 13:26:11 +02:00
|
|
|
|
void
|
2010-09-06 21:57:42 +02:00
|
|
|
|
hash_public_key (gcry_md_hd_t md, PKT_public_key *pk)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2019-03-14 11:20:07 +01:00
|
|
|
|
unsigned int n;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
unsigned int nn[PUBKEY_MAX_NPKEY];
|
|
|
|
|
byte *pp[PUBKEY_MAX_NPKEY];
|
|
|
|
|
int i;
|
2006-11-21 12:00:14 +01:00
|
|
|
|
unsigned int nbits;
|
|
|
|
|
size_t nbytes;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
int npkey = pubkey_get_npkey (pk->pubkey_algo);
|
2019-03-14 11:20:07 +01:00
|
|
|
|
int is_v5 = pk->version == 5;
|
2003-07-23 09:11:06 +02:00
|
|
|
|
|
2019-03-14 11:20:07 +01:00
|
|
|
|
n = is_v5? 10 : 6;
|
2011-02-02 15:48:54 +01:00
|
|
|
|
/* FIXME: We can avoid the extra malloc by calling only the first
|
|
|
|
|
mpi_print here which computes the required length and calling the
|
|
|
|
|
real mpi_print only at the end. The speed advantage would only be
|
|
|
|
|
for ECC (opaque MPIs) or if we could implement an mpi_print
|
|
|
|
|
variant with a callback handler to do the hashing. */
|
2006-04-19 13:26:11 +02:00
|
|
|
|
if (npkey==0 && pk->pkey[0]
|
|
|
|
|
&& gcry_mpi_get_flag (pk->pkey[0], GCRYMPI_FLAG_OPAQUE))
|
|
|
|
|
{
|
|
|
|
|
pp[0] = gcry_mpi_get_opaque (pk->pkey[0], &nbits);
|
|
|
|
|
nn[0] = (nbits+7)/8;
|
|
|
|
|
n+=nn[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
2010-09-06 21:57:42 +02:00
|
|
|
|
{
|
2011-01-21 12:00:57 +01:00
|
|
|
|
for (i=0; i < npkey; i++ )
|
2010-09-06 21:57:42 +02:00
|
|
|
|
{
|
2014-06-02 19:51:23 +02:00
|
|
|
|
if (!pk->pkey[i])
|
|
|
|
|
{
|
|
|
|
|
/* This case may only happen if the parsing of the MPI
|
|
|
|
|
failed but the key was anyway created. May happen
|
|
|
|
|
during "gpg KEYFILE". */
|
|
|
|
|
pp[i] = NULL;
|
|
|
|
|
nn[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (gcry_mpi_get_flag (pk->pkey[i], GCRYMPI_FLAG_OPAQUE))
|
2011-02-02 15:48:54 +01:00
|
|
|
|
{
|
2021-03-12 08:15:04 +01:00
|
|
|
|
const char *p;
|
2020-06-09 03:32:47 +02:00
|
|
|
|
int is_sos = 0;
|
|
|
|
|
|
|
|
|
|
if (gcry_mpi_get_flag (pk->pkey[i], GCRYMPI_FLAG_USER2))
|
|
|
|
|
is_sos = 2;
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
|
|
|
|
p = gcry_mpi_get_opaque (pk->pkey[i], &nbits);
|
2020-06-09 03:32:47 +02:00
|
|
|
|
pp[i] = xmalloc ((nbits+7)/8 + is_sos);
|
2015-02-19 16:29:58 +01:00
|
|
|
|
if (p)
|
2020-06-09 03:32:47 +02:00
|
|
|
|
memcpy (pp[i] + is_sos, p, (nbits+7)/8);
|
2015-02-19 16:29:58 +01:00
|
|
|
|
else
|
|
|
|
|
pp[i] = NULL;
|
2020-06-09 03:32:47 +02:00
|
|
|
|
if (is_sos)
|
|
|
|
|
{
|
2021-03-12 08:15:04 +01:00
|
|
|
|
if (*p)
|
|
|
|
|
{
|
|
|
|
|
nbits = ((nbits + 7) / 8) * 8;
|
|
|
|
|
|
|
|
|
|
if (nbits >= 8 && !(*p & 0x80))
|
|
|
|
|
if (--nbits >= 7 && !(*p & 0x40))
|
|
|
|
|
if (--nbits >= 6 && !(*p & 0x20))
|
|
|
|
|
if (--nbits >= 5 && !(*p & 0x10))
|
|
|
|
|
if (--nbits >= 4 && !(*p & 0x08))
|
|
|
|
|
if (--nbits >= 3 && !(*p & 0x04))
|
|
|
|
|
if (--nbits >= 2 && !(*p & 0x02))
|
|
|
|
|
if (--nbits >= 1 && !(*p & 0x01))
|
|
|
|
|
--nbits;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 03:32:47 +02:00
|
|
|
|
pp[i][0] = (nbits >> 8);
|
|
|
|
|
pp[i][1] = nbits;
|
|
|
|
|
}
|
|
|
|
|
nn[i] = (nbits+7)/8 + is_sos;
|
2011-02-02 15:48:54 +01:00
|
|
|
|
n += nn[i];
|
|
|
|
|
}
|
2011-01-21 12:00:57 +01:00
|
|
|
|
else
|
2011-02-02 15:48:54 +01:00
|
|
|
|
{
|
|
|
|
|
if (gcry_mpi_print (GCRYMPI_FMT_PGP, NULL, 0,
|
|
|
|
|
&nbytes, pk->pkey[i]))
|
|
|
|
|
BUG ();
|
|
|
|
|
pp[i] = xmalloc (nbytes);
|
|
|
|
|
if (gcry_mpi_print (GCRYMPI_FMT_PGP, pp[i], nbytes,
|
|
|
|
|
&nbytes, pk->pkey[i]))
|
|
|
|
|
BUG ();
|
|
|
|
|
nn[i] = nbytes;
|
|
|
|
|
n += nn[i];
|
|
|
|
|
}
|
2010-09-06 21:57:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2019-03-14 11:20:07 +01:00
|
|
|
|
if (is_v5)
|
|
|
|
|
{
|
|
|
|
|
gcry_md_putc ( md, 0x9a ); /* ctb */
|
|
|
|
|
gcry_md_putc ( md, n >> 24 ); /* 4 byte length header */
|
|
|
|
|
gcry_md_putc ( md, n >> 16 );
|
|
|
|
|
gcry_md_putc ( md, n >> 8 );
|
|
|
|
|
gcry_md_putc ( md, n );
|
|
|
|
|
gcry_md_putc ( md, pk->version );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gcry_md_putc ( md, 0x99 ); /* ctb */
|
|
|
|
|
gcry_md_putc ( md, n >> 8 ); /* 2 byte length header */
|
|
|
|
|
gcry_md_putc ( md, n );
|
|
|
|
|
gcry_md_putc ( md, pk->version );
|
|
|
|
|
}
|
2006-04-19 13:26:11 +02:00
|
|
|
|
gcry_md_putc ( md, pk->timestamp >> 24 );
|
|
|
|
|
gcry_md_putc ( md, pk->timestamp >> 16 );
|
|
|
|
|
gcry_md_putc ( md, pk->timestamp >> 8 );
|
|
|
|
|
gcry_md_putc ( md, pk->timestamp );
|
|
|
|
|
|
|
|
|
|
gcry_md_putc ( md, pk->pubkey_algo );
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2019-03-14 11:20:07 +01:00
|
|
|
|
if (is_v5)
|
|
|
|
|
{
|
|
|
|
|
n -= 10;
|
|
|
|
|
gcry_md_putc ( md, n >> 24 );
|
|
|
|
|
gcry_md_putc ( md, n >> 16 );
|
|
|
|
|
gcry_md_putc ( md, n >> 8 );
|
|
|
|
|
gcry_md_putc ( md, n );
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
if(npkey==0 && pk->pkey[0]
|
|
|
|
|
&& gcry_mpi_get_flag (pk->pkey[0], GCRYMPI_FLAG_OPAQUE))
|
|
|
|
|
{
|
2015-02-19 16:29:58 +01:00
|
|
|
|
if (pp[0])
|
|
|
|
|
gcry_md_write (md, pp[0], nn[0]);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
2006-04-19 13:26:11 +02:00
|
|
|
|
else
|
2015-02-19 16:29:58 +01:00
|
|
|
|
{
|
|
|
|
|
for(i=0; i < npkey; i++ )
|
|
|
|
|
{
|
|
|
|
|
if (pp[i])
|
|
|
|
|
gcry_md_write ( md, pp[i], nn[i] );
|
|
|
|
|
xfree(pp[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-04-19 13:26:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
|
|
|
|
|
/* fixme: Check whether we can replace this function or if not
|
|
|
|
|
describe why we need it. */
|
2003-06-18 21:56:13 +02:00
|
|
|
|
u32
|
|
|
|
|
v3_keyid (gcry_mpi_t a, u32 *ki)
|
|
|
|
|
{
|
2006-10-18 17:34:54 +02:00
|
|
|
|
byte *buffer, *p;
|
2003-06-18 21:56:13 +02:00
|
|
|
|
size_t nbytes;
|
|
|
|
|
|
2003-07-28 10:59:18 +02:00
|
|
|
|
if (gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &nbytes, a ))
|
2003-06-18 21:56:13 +02:00
|
|
|
|
BUG ();
|
|
|
|
|
/* fixme: allocate it on the stack */
|
|
|
|
|
buffer = xmalloc (nbytes);
|
2003-07-28 10:59:18 +02:00
|
|
|
|
if (gcry_mpi_print( GCRYMPI_FMT_USG, buffer, nbytes, NULL, a ))
|
2003-06-18 21:56:13 +02:00
|
|
|
|
BUG ();
|
|
|
|
|
if (nbytes < 8) /* oops */
|
|
|
|
|
ki[0] = ki[1] = 0;
|
2011-02-02 15:48:54 +01:00
|
|
|
|
else
|
2003-06-18 21:56:13 +02:00
|
|
|
|
{
|
2006-10-18 17:34:54 +02:00
|
|
|
|
p = buffer + nbytes - 8;
|
2015-02-11 10:27:57 +01:00
|
|
|
|
ki[0] = buf32_to_u32 (p);
|
2006-10-18 17:34:54 +02:00
|
|
|
|
p += 4;
|
2015-02-11 10:27:57 +01:00
|
|
|
|
ki[1] = buf32_to_u32 (p);
|
2003-06-18 21:56:13 +02:00
|
|
|
|
}
|
|
|
|
|
xfree (buffer);
|
|
|
|
|
return ki[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-19 14:48:56 +01:00
|
|
|
|
/* Return PK's keyid. The memory is owned by PK. */
|
|
|
|
|
u32 *
|
|
|
|
|
pk_keyid (PKT_public_key *pk)
|
|
|
|
|
{
|
|
|
|
|
keyid_from_pk (pk, NULL);
|
|
|
|
|
|
|
|
|
|
/* Uncomment this for help tracking down bugs related to keyid or
|
|
|
|
|
main_keyid not being set correctly. */
|
|
|
|
|
#if 0
|
|
|
|
|
if (! (pk->main_keyid[0] || pk->main_keyid[1]))
|
|
|
|
|
log_bug ("pk->main_keyid not set!\n");
|
|
|
|
|
if (keyid_cmp (pk->keyid, pk->main_keyid) == 0
|
|
|
|
|
&& ! pk->flags.primary)
|
|
|
|
|
log_bug ("keyid and main_keyid are the same, but primary flag not set!\n");
|
|
|
|
|
if (keyid_cmp (pk->keyid, pk->main_keyid) != 0
|
|
|
|
|
&& pk->flags.primary)
|
|
|
|
|
log_bug ("keyid and main_keyid are different, but primary flag set!\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return pk->keyid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the keyid of the primary key associated with PK. The memory
|
|
|
|
|
is owned by PK. */
|
|
|
|
|
u32 *
|
|
|
|
|
pk_main_keyid (PKT_public_key *pk)
|
|
|
|
|
{
|
|
|
|
|
/* Uncomment this for help tracking down bugs related to keyid or
|
|
|
|
|
main_keyid not being set correctly. */
|
|
|
|
|
#if 0
|
|
|
|
|
if (! (pk->main_keyid[0] || pk->main_keyid[1]))
|
|
|
|
|
log_bug ("pk->main_keyid not set!\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return pk->main_keyid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy the keyid in SRC to DEST and return DEST. */
|
|
|
|
|
u32 *
|
|
|
|
|
keyid_copy (u32 *dest, const u32 *src)
|
|
|
|
|
{
|
|
|
|
|
dest[0] = src[0];
|
|
|
|
|
dest[1] = src[1];
|
|
|
|
|
return dest;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 00:31:35 +01:00
|
|
|
|
char *
|
2015-11-17 11:47:43 +01:00
|
|
|
|
format_keyid (u32 *keyid, int format, char *buffer, int len)
|
2006-04-19 13:26:11 +02:00
|
|
|
|
{
|
2015-11-17 11:47:43 +01:00
|
|
|
|
if (! buffer)
|
2016-02-08 00:31:35 +01:00
|
|
|
|
{
|
2021-11-24 02:43:38 +01:00
|
|
|
|
len = KEYID_STR_SIZE;
|
|
|
|
|
buffer = xtrymalloc (len);
|
|
|
|
|
if (!buffer)
|
|
|
|
|
return NULL;
|
2016-02-08 00:31:35 +01:00
|
|
|
|
}
|
2015-11-17 11:47:43 +01:00
|
|
|
|
|
|
|
|
|
if (format == KF_DEFAULT)
|
|
|
|
|
format = opt.keyid_format;
|
|
|
|
|
if (format == KF_DEFAULT)
|
2016-06-06 17:03:47 +02:00
|
|
|
|
format = KF_NONE;
|
2015-11-17 11:47:43 +01:00
|
|
|
|
|
|
|
|
|
switch (format)
|
2006-04-19 13:26:11 +02:00
|
|
|
|
{
|
2016-06-06 16:00:50 +02:00
|
|
|
|
case KF_NONE:
|
|
|
|
|
if (len)
|
|
|
|
|
*buffer = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
case KF_SHORT:
|
2015-11-17 11:47:43 +01:00
|
|
|
|
snprintf (buffer, len, "%08lX", (ulong)keyid[1]);
|
|
|
|
|
break;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
|
|
case KF_LONG:
|
2016-07-13 17:19:56 +02:00
|
|
|
|
snprintf (buffer, len, "%08lX%08lX", (ulong)keyid[0], (ulong)keyid[1]);
|
2015-11-17 11:47:43 +01:00
|
|
|
|
break;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
|
|
case KF_0xSHORT:
|
2015-11-17 11:47:43 +01:00
|
|
|
|
snprintf (buffer, len, "0x%08lX", (ulong)keyid[1]);
|
|
|
|
|
break;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
|
|
case KF_0xLONG:
|
2016-07-13 17:19:56 +02:00
|
|
|
|
snprintf (buffer, len, "0x%08lX%08lX", (ulong)keyid[0],(ulong)keyid[1]);
|
2015-11-17 11:47:43 +01:00
|
|
|
|
break;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
BUG();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 11:47:43 +01:00
|
|
|
|
return buffer;
|
|
|
|
|
}
|
2010-08-31 17:58:39 +02:00
|
|
|
|
|
2015-11-17 11:47:43 +01:00
|
|
|
|
size_t
|
|
|
|
|
keystrlen(void)
|
2011-02-02 15:48:54 +01:00
|
|
|
|
{
|
2015-12-09 19:01:04 +01:00
|
|
|
|
int format = opt.keyid_format;
|
|
|
|
|
if (format == KF_DEFAULT)
|
2016-06-06 17:03:47 +02:00
|
|
|
|
format = KF_NONE;
|
2015-12-09 19:01:04 +01:00
|
|
|
|
|
|
|
|
|
switch(format)
|
2006-04-19 13:26:11 +02:00
|
|
|
|
{
|
2016-06-06 16:55:03 +02:00
|
|
|
|
case KF_NONE:
|
|
|
|
|
return 0;
|
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
case KF_SHORT:
|
2015-11-17 11:47:43 +01:00
|
|
|
|
return 8;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
|
|
case KF_LONG:
|
2015-11-17 11:47:43 +01:00
|
|
|
|
return 16;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
|
|
case KF_0xSHORT:
|
2015-11-17 11:47:43 +01:00
|
|
|
|
return 10;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
|
|
|
|
case KF_0xLONG:
|
2015-11-17 11:47:43 +01:00
|
|
|
|
return 18;
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
default:
|
|
|
|
|
BUG();
|
|
|
|
|
}
|
2015-11-17 11:47:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
2015-11-17 11:47:43 +01:00
|
|
|
|
const char *
|
|
|
|
|
keystr (u32 *keyid)
|
|
|
|
|
{
|
|
|
|
|
static char keyid_str[KEYID_STR_SIZE];
|
2016-06-06 16:00:50 +02:00
|
|
|
|
int format = opt.keyid_format;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
2016-08-31 08:37:51 +02:00
|
|
|
|
if (format == KF_DEFAULT)
|
|
|
|
|
format = KF_NONE;
|
2016-06-06 16:00:50 +02:00
|
|
|
|
if (format == KF_NONE)
|
|
|
|
|
format = KF_LONG;
|
2010-08-31 17:58:39 +02:00
|
|
|
|
|
2016-06-06 16:00:50 +02:00
|
|
|
|
return format_keyid (keyid, format, keyid_str, sizeof (keyid_str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This function returns the key id of the main and possible the
|
|
|
|
|
* subkey as one string. It is used by error messages. */
|
2010-08-31 17:58:39 +02:00
|
|
|
|
const char *
|
|
|
|
|
keystr_with_sub (u32 *main_kid, u32 *sub_kid)
|
2011-02-02 15:48:54 +01:00
|
|
|
|
{
|
2010-08-31 17:58:39 +02:00
|
|
|
|
static char buffer[KEYID_STR_SIZE+1+KEYID_STR_SIZE];
|
|
|
|
|
char *p;
|
2016-06-06 16:00:50 +02:00
|
|
|
|
int format = opt.keyid_format;
|
|
|
|
|
|
|
|
|
|
if (format == KF_NONE)
|
|
|
|
|
format = KF_LONG;
|
2010-08-31 17:58:39 +02:00
|
|
|
|
|
2016-06-06 16:00:50 +02:00
|
|
|
|
format_keyid (main_kid, format, buffer, KEYID_STR_SIZE);
|
2010-10-01 22:33:53 +02:00
|
|
|
|
if (sub_kid)
|
|
|
|
|
{
|
|
|
|
|
p = buffer + strlen (buffer);
|
|
|
|
|
*p++ = '/';
|
2016-06-06 16:00:50 +02:00
|
|
|
|
format_keyid (sub_kid, format, p, KEYID_STR_SIZE);
|
2010-10-01 22:33:53 +02:00
|
|
|
|
}
|
2010-08-31 17:58:39 +02:00
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
const char *
|
|
|
|
|
keystr_from_pk(PKT_public_key *pk)
|
|
|
|
|
{
|
|
|
|
|
keyid_from_pk(pk,NULL);
|
|
|
|
|
|
|
|
|
|
return keystr(pk->keyid);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 17:58:39 +02:00
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
keystr_from_pk_with_sub (PKT_public_key *main_pk, PKT_public_key *sub_pk)
|
|
|
|
|
{
|
|
|
|
|
keyid_from_pk (main_pk, NULL);
|
2010-10-01 22:33:53 +02:00
|
|
|
|
if (sub_pk)
|
|
|
|
|
keyid_from_pk (sub_pk, NULL);
|
2010-08-31 17:58:39 +02:00
|
|
|
|
|
2010-10-01 22:33:53 +02:00
|
|
|
|
return keystr_with_sub (main_pk->keyid, sub_pk? sub_pk->keyid:NULL);
|
2010-08-31 17:58:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-19 14:48:56 +01:00
|
|
|
|
/* Return PK's key id as a string using the default format. PK owns
|
|
|
|
|
the storage. */
|
|
|
|
|
const char *
|
|
|
|
|
pk_keyid_str (PKT_public_key *pk)
|
|
|
|
|
{
|
|
|
|
|
return keystr (pk_keyid (pk));
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 17:58:39 +02:00
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
const char *
|
|
|
|
|
keystr_from_desc(KEYDB_SEARCH_DESC *desc)
|
|
|
|
|
{
|
|
|
|
|
switch(desc->mode)
|
|
|
|
|
{
|
|
|
|
|
case KEYDB_SEARCH_MODE_LONG_KID:
|
|
|
|
|
case KEYDB_SEARCH_MODE_SHORT_KID:
|
|
|
|
|
return keystr(desc->u.kid);
|
|
|
|
|
|
2019-03-14 08:54:59 +01:00
|
|
|
|
case KEYDB_SEARCH_MODE_FPR:
|
|
|
|
|
{
|
|
|
|
|
u32 keyid[2];
|
|
|
|
|
|
|
|
|
|
if (desc->fprlen == 32)
|
|
|
|
|
{
|
|
|
|
|
keyid[0] = buf32_to_u32 (desc->u.fpr);
|
|
|
|
|
keyid[1] = buf32_to_u32 (desc->u.fpr+4);
|
|
|
|
|
}
|
2019-03-14 14:55:06 +01:00
|
|
|
|
else if (desc->fprlen == 20)
|
2019-03-14 08:54:59 +01:00
|
|
|
|
{
|
|
|
|
|
keyid[0] = buf32_to_u32 (desc->u.fpr+12);
|
|
|
|
|
keyid[1] = buf32_to_u32 (desc->u.fpr+16);
|
|
|
|
|
}
|
2019-03-14 14:55:06 +01:00
|
|
|
|
else if (desc->fprlen == 16)
|
|
|
|
|
return "?v3 fpr?";
|
|
|
|
|
else /* oops */
|
|
|
|
|
return "?vx fpr?";
|
2019-03-14 08:54:59 +01:00
|
|
|
|
return keystr(keyid);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
default:
|
|
|
|
|
BUG();
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-06-18 21:56:13 +02:00
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2019-04-12 11:11:09 +02:00
|
|
|
|
/* Compute the fingerprint and keyid and store it in PK. */
|
|
|
|
|
static void
|
|
|
|
|
compute_fingerprint (PKT_public_key *pk)
|
|
|
|
|
{
|
|
|
|
|
const byte *dp;
|
|
|
|
|
gcry_md_hd_t md;
|
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
|
|
if (gcry_md_open (&md, pk->version == 5 ? GCRY_MD_SHA256 : GCRY_MD_SHA1, 0))
|
|
|
|
|
BUG ();
|
|
|
|
|
hash_public_key (md, pk);
|
|
|
|
|
gcry_md_final (md);
|
|
|
|
|
dp = gcry_md_read (md, 0);
|
|
|
|
|
len = gcry_md_get_algo_dlen (gcry_md_get_algo (md));
|
|
|
|
|
log_assert (len <= MAX_FINGERPRINT_LEN);
|
|
|
|
|
memcpy (pk->fpr, dp, len);
|
|
|
|
|
pk->fprlen = len;
|
|
|
|
|
if (pk->version == 5)
|
|
|
|
|
{
|
|
|
|
|
pk->keyid[0] = buf32_to_u32 (dp);
|
|
|
|
|
pk->keyid[1] = buf32_to_u32 (dp+4);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pk->keyid[0] = buf32_to_u32 (dp+12);
|
|
|
|
|
pk->keyid[1] = buf32_to_u32 (dp+16);
|
|
|
|
|
}
|
|
|
|
|
gcry_md_close( md);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
/*
|
2019-03-14 11:20:07 +01:00
|
|
|
|
* Get the keyid from the public key PK and store it at KEYID unless
|
|
|
|
|
* this is NULL. Returns the 32 bit short keyid.
|
2003-06-05 09:14:21 +02:00
|
|
|
|
*/
|
|
|
|
|
u32
|
2010-09-06 21:57:42 +02:00
|
|
|
|
keyid_from_pk (PKT_public_key *pk, u32 *keyid)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2006-04-19 13:26:11 +02:00
|
|
|
|
u32 dummy_keyid[2];
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
if (!keyid)
|
2006-04-19 13:26:11 +02:00
|
|
|
|
keyid = dummy_keyid;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2019-04-12 11:11:09 +02:00
|
|
|
|
if (!pk->fprlen)
|
|
|
|
|
compute_fingerprint (pk);
|
|
|
|
|
|
|
|
|
|
keyid[0] = pk->keyid[0];
|
|
|
|
|
keyid[1] = pk->keyid[1];
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2020-08-07 05:41:47 +02:00
|
|
|
|
if (pk->fprlen == 32)
|
|
|
|
|
return keyid[0];
|
|
|
|
|
else
|
|
|
|
|
return keyid[1];
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
/*
|
2018-12-04 15:43:19 +01:00
|
|
|
|
* Get the keyid from the fingerprint. This function is simple for
|
|
|
|
|
* most keys, but has to do a key lookup for old v3 keys where the
|
|
|
|
|
* keyid is not part of the fingerprint.
|
2003-06-05 09:14:21 +02:00
|
|
|
|
*/
|
|
|
|
|
u32
|
2017-03-31 20:03:52 +02:00
|
|
|
|
keyid_from_fingerprint (ctrl_t ctrl, const byte *fprint,
|
|
|
|
|
size_t fprint_len, u32 *keyid)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2010-09-06 21:57:42 +02:00
|
|
|
|
u32 dummy_keyid[2];
|
|
|
|
|
|
|
|
|
|
if( !keyid )
|
|
|
|
|
keyid = dummy_keyid;
|
|
|
|
|
|
2018-12-04 15:43:19 +01:00
|
|
|
|
if (fprint_len != 20 && fprint_len != 32)
|
2010-09-06 21:57:42 +02:00
|
|
|
|
{
|
|
|
|
|
/* This is special as we have to lookup the key first. */
|
|
|
|
|
PKT_public_key pk;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
memset (&pk, 0, sizeof pk);
|
2017-03-31 20:03:52 +02:00
|
|
|
|
rc = get_pubkey_byfprint (ctrl, &pk, NULL, fprint, fprint_len);
|
2010-09-06 21:57:42 +02:00
|
|
|
|
if( rc )
|
|
|
|
|
{
|
2018-12-04 15:43:19 +01:00
|
|
|
|
log_printhex (fprint, fprint_len,
|
|
|
|
|
"Oops: keyid_from_fingerprint: no pubkey; fpr:");
|
2010-09-06 21:57:42 +02:00
|
|
|
|
keyid[0] = 0;
|
|
|
|
|
keyid[1] = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
keyid_from_pk (&pk, keyid);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
2011-02-02 15:48:54 +01:00
|
|
|
|
else
|
2010-09-06 21:57:42 +02:00
|
|
|
|
{
|
|
|
|
|
const byte *dp = fprint;
|
2019-03-14 11:20:07 +01:00
|
|
|
|
if (fprint_len == 20) /* v4 key */
|
|
|
|
|
{
|
|
|
|
|
keyid[0] = buf32_to_u32 (dp+12);
|
|
|
|
|
keyid[1] = buf32_to_u32 (dp+16);
|
|
|
|
|
}
|
|
|
|
|
else /* v5 key */
|
|
|
|
|
{
|
|
|
|
|
keyid[0] = buf32_to_u32 (dp);
|
|
|
|
|
keyid[1] = buf32_to_u32 (dp+4);
|
|
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
return keyid[1];
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u32
|
2010-09-06 21:57:42 +02:00
|
|
|
|
keyid_from_sig (PKT_signature *sig, u32 *keyid)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2011-02-02 15:48:54 +01:00
|
|
|
|
if( keyid )
|
2010-09-06 21:57:42 +02:00
|
|
|
|
{
|
|
|
|
|
keyid[0] = sig->keyid[0];
|
|
|
|
|
keyid[1] = sig->keyid[1];
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
2019-03-14 11:20:07 +01:00
|
|
|
|
return sig->keyid[1]; /*FIXME:shortkeyid*/
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
byte *
|
2010-09-06 21:57:42 +02:00
|
|
|
|
namehash_from_uid (PKT_user_id *uid)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2008-12-11 18:44:52 +01:00
|
|
|
|
if (!uid->namehash)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2008-12-11 18:44:52 +01:00
|
|
|
|
uid->namehash = xmalloc (20);
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
if (uid->attrib_data)
|
2008-12-11 18:44:52 +01:00
|
|
|
|
rmd160_hash_buffer (uid->namehash, uid->attrib_data, uid->attrib_len);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
else
|
2008-12-11 18:44:52 +01:00
|
|
|
|
rmd160_hash_buffer (uid->namehash, uid->name, uid->len);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
return uid->namehash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
/*
|
|
|
|
|
* Return the number of bits used in PK.
|
2003-06-05 09:14:21 +02:00
|
|
|
|
*/
|
2010-09-06 21:57:42 +02:00
|
|
|
|
unsigned int
|
|
|
|
|
nbits_from_pk (PKT_public_key *pk)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2010-09-06 21:57:42 +02:00
|
|
|
|
return pubkey_nbits (pk->pubkey_algo, pk->pkey);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
|
2017-07-20 13:36:44 +02:00
|
|
|
|
/* Convert an UTC TIMESTAMP into an UTC yyyy-mm-dd string. Return
|
|
|
|
|
* that string. The caller should pass a buffer with at least a size
|
|
|
|
|
* of MK_DATESTR_SIZE. */
|
|
|
|
|
char *
|
|
|
|
|
mk_datestr (char *buffer, size_t bufsize, u32 timestamp)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2017-07-20 13:36:44 +02:00
|
|
|
|
time_t atime = timestamp;
|
2010-09-06 21:57:42 +02:00
|
|
|
|
struct tm *tp;
|
|
|
|
|
|
2010-10-27 13:26:53 +02:00
|
|
|
|
if (IS_INVALID_TIME_T (atime))
|
|
|
|
|
strcpy (buffer, "????" "-??" "-??"); /* Mark this as invalid. */
|
2011-02-02 15:48:54 +01:00
|
|
|
|
else
|
2010-09-06 21:57:42 +02:00
|
|
|
|
{
|
|
|
|
|
tp = gmtime (&atime);
|
2017-07-20 13:36:44 +02:00
|
|
|
|
snprintf (buffer, bufsize, "%04d-%02d-%02d",
|
|
|
|
|
1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday );
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
2010-09-06 21:57:42 +02:00
|
|
|
|
return buffer;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
|
|
|
|
|
/*
|
2003-06-05 09:14:21 +02:00
|
|
|
|
* return a string with the creation date of the pk
|
|
|
|
|
* Note: this is alloced in a static buffer.
|
|
|
|
|
* Format is: yyyy-mm-dd
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
2020-02-13 14:01:07 +01:00
|
|
|
|
dateonlystr_from_pk (PKT_public_key *pk)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2017-07-20 13:36:44 +02:00
|
|
|
|
static char buffer[MK_DATESTR_SIZE];
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2017-07-20 13:36:44 +02:00
|
|
|
|
return mk_datestr (buffer, sizeof buffer, pk->timestamp);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-02-13 14:01:07 +01:00
|
|
|
|
/* Same as dateonlystr_from_pk but with a global option a full iso
|
|
|
|
|
* timestamp is returned. In this case it shares a static buffer with
|
|
|
|
|
* isotimestamp(). */
|
2003-06-05 09:14:21 +02:00
|
|
|
|
const char *
|
2020-02-13 14:01:07 +01:00
|
|
|
|
datestr_from_pk (PKT_public_key *pk)
|
|
|
|
|
{
|
|
|
|
|
if (opt.flags.full_timestrings)
|
|
|
|
|
return isotimestamp (pk->timestamp);
|
|
|
|
|
else
|
|
|
|
|
return dateonlystr_from_pk (pk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
dateonlystr_from_sig (PKT_signature *sig )
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2017-07-20 13:36:44 +02:00
|
|
|
|
static char buffer[MK_DATESTR_SIZE];
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2017-07-20 13:36:44 +02:00
|
|
|
|
return mk_datestr (buffer, sizeof buffer, sig->timestamp);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-13 14:01:07 +01:00
|
|
|
|
const char *
|
|
|
|
|
datestr_from_sig (PKT_signature *sig )
|
|
|
|
|
{
|
|
|
|
|
if (opt.flags.full_timestrings)
|
|
|
|
|
return isotimestamp (sig->timestamp);
|
|
|
|
|
else
|
|
|
|
|
return dateonlystr_from_sig (sig);
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
|
|
const char *
|
2010-09-06 21:57:42 +02:00
|
|
|
|
expirestr_from_pk (PKT_public_key *pk)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2017-07-20 13:36:44 +02:00
|
|
|
|
static char buffer[MK_DATESTR_SIZE];
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
if (!pk->expiredate)
|
|
|
|
|
return _("never ");
|
2020-02-13 14:01:07 +01:00
|
|
|
|
|
|
|
|
|
if (opt.flags.full_timestrings)
|
|
|
|
|
return isotimestamp (pk->expiredate);
|
|
|
|
|
|
2017-07-20 13:36:44 +02:00
|
|
|
|
return mk_datestr (buffer, sizeof buffer, pk->expiredate);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
const char *
|
2010-09-06 21:57:42 +02:00
|
|
|
|
expirestr_from_sig (PKT_signature *sig)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2017-07-20 13:36:44 +02:00
|
|
|
|
static char buffer[MK_DATESTR_SIZE];
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
if (!sig->expiredate)
|
|
|
|
|
return _("never ");
|
2020-02-13 14:01:07 +01:00
|
|
|
|
|
|
|
|
|
if (opt.flags.full_timestrings)
|
|
|
|
|
return isotimestamp (sig->expiredate);
|
|
|
|
|
|
2017-07-20 13:36:44 +02:00
|
|
|
|
return mk_datestr (buffer, sizeof buffer, sig->expiredate);
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
|
2006-04-19 13:26:11 +02:00
|
|
|
|
const char *
|
|
|
|
|
revokestr_from_pk( PKT_public_key *pk )
|
|
|
|
|
{
|
2017-07-20 13:36:44 +02:00
|
|
|
|
static char buffer[MK_DATESTR_SIZE];
|
2006-04-19 13:26:11 +02:00
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
if(!pk->revoked.date)
|
|
|
|
|
return _("never ");
|
2020-02-13 14:01:07 +01:00
|
|
|
|
|
|
|
|
|
if (opt.flags.full_timestrings)
|
|
|
|
|
return isotimestamp (pk->revoked.date);
|
|
|
|
|
|
2017-07-20 13:36:44 +02:00
|
|
|
|
return mk_datestr (buffer, sizeof buffer, pk->revoked.date);
|
2006-04-19 13:26:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
2014-08-12 10:36:30 +02:00
|
|
|
|
usagestr_from_pk (PKT_public_key *pk, int fill)
|
2006-04-19 13:26:11 +02:00
|
|
|
|
{
|
|
|
|
|
static char buffer[10];
|
|
|
|
|
int i = 0;
|
|
|
|
|
unsigned int use = pk->pubkey_usage;
|
|
|
|
|
|
|
|
|
|
if ( use & PUBKEY_USAGE_SIG )
|
|
|
|
|
buffer[i++] = 'S';
|
|
|
|
|
|
|
|
|
|
if ( use & PUBKEY_USAGE_CERT )
|
|
|
|
|
buffer[i++] = 'C';
|
|
|
|
|
|
|
|
|
|
if ( use & PUBKEY_USAGE_ENC )
|
|
|
|
|
buffer[i++] = 'E';
|
|
|
|
|
|
|
|
|
|
if ( (use & PUBKEY_USAGE_AUTH) )
|
|
|
|
|
buffer[i++] = 'A';
|
|
|
|
|
|
2022-09-07 10:34:05 +02:00
|
|
|
|
if ( (use & PUBKEY_USAGE_RENC) )
|
|
|
|
|
buffer[i++] = 'R';
|
|
|
|
|
if ( (use & PUBKEY_USAGE_TIME) )
|
|
|
|
|
buffer[i++] = 'T';
|
|
|
|
|
if ( (use & PUBKEY_USAGE_GROUP) )
|
|
|
|
|
buffer[i++] = 'G';
|
|
|
|
|
|
2014-08-12 10:36:30 +02:00
|
|
|
|
while (fill && i < 4)
|
2006-04-19 13:26:11 +02:00
|
|
|
|
buffer[i++] = ' ';
|
|
|
|
|
|
|
|
|
|
buffer[i] = 0;
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
const char *
|
|
|
|
|
colon_strtime (u32 t)
|
|
|
|
|
{
|
2008-06-11 10:07:54 +02:00
|
|
|
|
static char buf[20];
|
|
|
|
|
|
|
|
|
|
if (!t)
|
|
|
|
|
return "";
|
|
|
|
|
snprintf (buf, sizeof buf, "%lu", (ulong)t);
|
|
|
|
|
return buf;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
colon_datestr_from_pk (PKT_public_key *pk)
|
|
|
|
|
{
|
2008-06-11 10:07:54 +02:00
|
|
|
|
static char buf[20];
|
|
|
|
|
|
|
|
|
|
snprintf (buf, sizeof buf, "%lu", (ulong)pk->timestamp);
|
|
|
|
|
return buf;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
colon_datestr_from_sig (PKT_signature *sig)
|
|
|
|
|
{
|
2008-06-11 10:07:54 +02:00
|
|
|
|
static char buf[20];
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2008-06-11 10:07:54 +02:00
|
|
|
|
snprintf (buf, sizeof buf, "%lu", (ulong)sig->timestamp);
|
|
|
|
|
return buf;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
colon_expirestr_from_sig (PKT_signature *sig)
|
|
|
|
|
{
|
2008-06-11 10:07:54 +02:00
|
|
|
|
static char buf[20];
|
|
|
|
|
|
|
|
|
|
if (!sig->expiredate)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
snprintf (buf, sizeof buf,"%lu", (ulong)sig->expiredate);
|
|
|
|
|
return buf;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-04-12 11:11:09 +02:00
|
|
|
|
|
2010-09-06 21:57:42 +02:00
|
|
|
|
/*
|
2003-06-05 09:14:21 +02:00
|
|
|
|
* Return a byte array with the fingerprint for the given PK/SK
|
|
|
|
|
* The length of the array is returned in ret_len. Caller must free
|
|
|
|
|
* the array or provide an array of length MAX_FINGERPRINT_LEN.
|
|
|
|
|
*/
|
|
|
|
|
byte *
|
2010-09-06 21:57:42 +02:00
|
|
|
|
fingerprint_from_pk (PKT_public_key *pk, byte *array, size_t *ret_len)
|
2003-06-05 09:14:21 +02:00
|
|
|
|
{
|
2019-04-12 11:11:09 +02:00
|
|
|
|
if (!pk->fprlen)
|
|
|
|
|
compute_fingerprint (pk);
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2014-10-12 20:07:12 +02:00
|
|
|
|
if (!array)
|
2019-04-12 11:11:09 +02:00
|
|
|
|
array = xmalloc (pk->fprlen);
|
|
|
|
|
memcpy (array, pk->fpr, pk->fprlen);
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2014-10-13 14:54:26 +02:00
|
|
|
|
if (ret_len)
|
2019-04-12 11:11:09 +02:00
|
|
|
|
*ret_len = pk->fprlen;
|
2006-04-19 13:26:11 +02:00
|
|
|
|
return array;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2006-08-16 12:47:53 +02:00
|
|
|
|
|
2020-08-07 05:46:09 +02:00
|
|
|
|
/*
|
|
|
|
|
* Get FPR20 for the given PK/SK into ARRAY.
|
|
|
|
|
*
|
|
|
|
|
* FPR20 is special form of fingerprint of length 20 for the record of
|
|
|
|
|
* trustdb. For v4key, having fingerprint with SHA-1, FPR20 is the
|
|
|
|
|
* same one. For v5key, FPR20 is constructed from its fingerprint
|
|
|
|
|
* with SHA-2, so that its kid of last 8-byte can be as same as
|
|
|
|
|
* kid of v5key fingerprint.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
fpr20_from_pk (PKT_public_key *pk, byte array[20])
|
|
|
|
|
{
|
|
|
|
|
if (!pk->fprlen)
|
|
|
|
|
compute_fingerprint (pk);
|
|
|
|
|
|
|
|
|
|
if (!array)
|
|
|
|
|
array = xmalloc (pk->fprlen);
|
|
|
|
|
|
|
|
|
|
if (pk->fprlen == 32) /* v5 fingerprint */
|
|
|
|
|
{
|
|
|
|
|
memcpy (array + 0, pk->fpr + 20, 4);
|
|
|
|
|
memcpy (array + 4, pk->fpr + 24, 4);
|
|
|
|
|
memcpy (array + 8, pk->fpr + 28, 4);
|
|
|
|
|
memcpy (array + 12, pk->fpr + 0, 4); /* kid[0] */
|
|
|
|
|
memcpy (array + 16, pk->fpr + 4, 4); /* kid[1] */
|
|
|
|
|
}
|
|
|
|
|
else /* v4 fingerprint */
|
|
|
|
|
memcpy (array, pk->fpr, 20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-06-25 20:25:28 +02:00
|
|
|
|
/* Return an allocated buffer with the fingerprint of PK formatted as
|
2017-12-13 10:52:34 +01:00
|
|
|
|
* a plain hexstring. If BUFFER is NULL the result is a malloc'd
|
|
|
|
|
* string. If BUFFER is not NULL the result will be copied into this
|
|
|
|
|
* buffer. In the latter case BUFLEN describes the length of the
|
|
|
|
|
* buffer; if this is too short the function terminates the process.
|
|
|
|
|
* Returns a malloc'ed string or BUFFER. A suitable length for BUFFER
|
|
|
|
|
* is (2*MAX_FINGERPRINT_LEN + 1). */
|
2014-06-25 20:25:28 +02:00
|
|
|
|
char *
|
2015-11-14 09:13:02 +01:00
|
|
|
|
hexfingerprint (PKT_public_key *pk, char *buffer, size_t buflen)
|
2014-06-25 20:25:28 +02:00
|
|
|
|
{
|
2019-04-12 11:11:09 +02:00
|
|
|
|
if (!pk->fprlen)
|
|
|
|
|
compute_fingerprint (pk);
|
2014-06-25 20:25:28 +02:00
|
|
|
|
|
2015-11-14 09:13:02 +01:00
|
|
|
|
if (!buffer)
|
2017-12-13 10:52:34 +01:00
|
|
|
|
{
|
2019-04-12 11:11:09 +02:00
|
|
|
|
buffer = xtrymalloc (2 * pk->fprlen + 1);
|
2017-12-13 10:52:34 +01:00
|
|
|
|
if (!buffer)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-04-12 11:11:09 +02:00
|
|
|
|
else if (buflen < 2 * pk->fprlen + 1)
|
2015-11-14 09:13:02 +01:00
|
|
|
|
log_fatal ("%s: buffer too short (%zu)\n", __func__, buflen);
|
2019-04-12 11:11:09 +02:00
|
|
|
|
|
|
|
|
|
bin2hex (pk->fpr, pk->fprlen, buffer);
|
2015-11-14 09:13:02 +01:00
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Pretty print a hex fingerprint. If BUFFER is NULL the result is a
|
|
|
|
|
malloc'd string. If BUFFER is not NULL the result will be copied
|
|
|
|
|
into this buffer. In the latter case BUFLEN describes the length
|
|
|
|
|
of the buffer; if this is too short the function terminates the
|
|
|
|
|
process. Returns a malloc'ed string or BUFFER. A suitable length
|
|
|
|
|
for BUFFER is (MAX_FORMATTED_FINGERPRINT_LEN + 1). */
|
|
|
|
|
char *
|
|
|
|
|
format_hexfingerprint (const char *fingerprint, char *buffer, size_t buflen)
|
|
|
|
|
{
|
|
|
|
|
int hexlen = strlen (fingerprint);
|
|
|
|
|
int space;
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
if (hexlen == 40) /* v4 fingerprint */
|
|
|
|
|
{
|
|
|
|
|
space = (/* The characters and the NUL. */
|
|
|
|
|
40 + 1
|
|
|
|
|
/* After every fourth character, we add a space (except
|
|
|
|
|
the last). */
|
|
|
|
|
+ 40 / 4 - 1
|
|
|
|
|
/* Half way through we add a second space. */
|
|
|
|
|
+ 1);
|
|
|
|
|
}
|
2017-09-27 09:42:13 +02:00
|
|
|
|
else if (hexlen == 64 || hexlen == 50) /* v5 fingerprint */
|
|
|
|
|
{
|
|
|
|
|
/* The v5 fingerprint is commonly printed truncated to 25
|
|
|
|
|
* octets. We accept the truncated as well as the full hex
|
|
|
|
|
* version here and format it like this:
|
2019-11-28 12:02:41 +01:00
|
|
|
|
* 19347 BC987 24640 25F99 DF3EC 2E000 0ED98 84892 E1F7B 3EA4C
|
2017-09-27 09:42:13 +02:00
|
|
|
|
*/
|
|
|
|
|
hexlen = 50;
|
2019-11-28 12:02:41 +01:00
|
|
|
|
space = 10 * 5 + 9 + 1;
|
2017-09-27 09:42:13 +02:00
|
|
|
|
}
|
2015-11-14 09:13:02 +01:00
|
|
|
|
else /* Other fingerprint versions - print as is. */
|
|
|
|
|
{
|
2017-09-27 09:42:13 +02:00
|
|
|
|
/* We truncated here so that we do not need to provide a buffer
|
|
|
|
|
* of a length which is in reality never used. */
|
|
|
|
|
if (hexlen > MAX_FORMATTED_FINGERPRINT_LEN - 1)
|
|
|
|
|
hexlen = MAX_FORMATTED_FINGERPRINT_LEN - 1;
|
2015-11-14 09:13:02 +01:00
|
|
|
|
space = hexlen + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
|
buffer = xmalloc (space);
|
|
|
|
|
else if (buflen < space)
|
|
|
|
|
log_fatal ("%s: buffer too short (%zu)\n", __func__, buflen);
|
|
|
|
|
|
|
|
|
|
if (hexlen == 40) /* v4 fingerprint */
|
|
|
|
|
{
|
|
|
|
|
for (i = 0, j = 0; i < 40; i ++)
|
|
|
|
|
{
|
2017-09-27 09:42:13 +02:00
|
|
|
|
if (i && !(i % 4))
|
2015-11-14 09:13:02 +01:00
|
|
|
|
buffer[j ++] = ' ';
|
|
|
|
|
if (i == 40 / 2)
|
|
|
|
|
buffer[j ++] = ' ';
|
|
|
|
|
|
|
|
|
|
buffer[j ++] = fingerprint[i];
|
|
|
|
|
}
|
|
|
|
|
buffer[j ++] = 0;
|
2016-04-29 11:05:24 +02:00
|
|
|
|
log_assert (j == space);
|
2015-11-14 09:13:02 +01:00
|
|
|
|
}
|
2017-09-27 09:42:13 +02:00
|
|
|
|
else if (hexlen == 50) /* v5 fingerprint */
|
|
|
|
|
{
|
2019-11-28 12:02:41 +01:00
|
|
|
|
for (i=j=0; i < 50; i++)
|
2017-09-27 09:42:13 +02:00
|
|
|
|
{
|
2019-11-28 12:02:41 +01:00
|
|
|
|
if (i && !(i % 5))
|
2017-09-27 09:42:13 +02:00
|
|
|
|
buffer[j++] = ' ';
|
|
|
|
|
buffer[j++] = fingerprint[i];
|
|
|
|
|
}
|
|
|
|
|
buffer[j++] = 0;
|
|
|
|
|
log_assert (j == space);
|
|
|
|
|
}
|
2015-11-14 09:13:02 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-09-27 09:42:13 +02:00
|
|
|
|
mem2str (buffer, fingerprint, space);
|
2015-11-14 09:13:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffer;
|
2014-06-25 20:25:28 +02:00
|
|
|
|
}
|
2006-08-16 12:47:53 +02:00
|
|
|
|
|
2010-04-20 19:57:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the so called KEYGRIP which is the SHA-1 hash of the public
|
Spelling cleanup.
No functional changes, just fixing minor spelling issues.
---
Most of these were identified from the command line by running:
codespell \
--ignore-words-list fpr,stati,keyserver,keyservers,asign,cas,iff,ifset \
--skip '*.po,ChangeLog*,help.*.txt,*.jpg,*.eps,*.pdf,*.png,*.gpg,*.asc' \
doc g13 g10 kbx agent artwork scd tests tools am common dirmngr sm \
NEWS README README.maint TODO
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2020-02-18 15:34:42 +01:00
|
|
|
|
key parameters expressed as an canonical encoded S-Exp. ARRAY must
|
2015-11-16 12:41:46 +01:00
|
|
|
|
be 20 bytes long. Returns 0 on success or an error code. */
|
2010-04-20 19:57:50 +02:00
|
|
|
|
gpg_error_t
|
|
|
|
|
keygrip_from_pk (PKT_public_key *pk, unsigned char *array)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
|
|
|
|
gcry_sexp_t s_pkey;
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2010-04-20 19:57:50 +02:00
|
|
|
|
if (DBG_PACKET)
|
|
|
|
|
log_debug ("get_keygrip for public key\n");
|
|
|
|
|
|
|
|
|
|
switch (pk->pubkey_algo)
|
|
|
|
|
{
|
|
|
|
|
case GCRY_PK_DSA:
|
|
|
|
|
err = gcry_sexp_build (&s_pkey, NULL,
|
|
|
|
|
"(public-key(dsa(p%m)(q%m)(g%m)(y%m)))",
|
|
|
|
|
pk->pkey[0], pk->pkey[1],
|
|
|
|
|
pk->pkey[2], pk->pkey[3]);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GCRY_PK_ELG:
|
|
|
|
|
case GCRY_PK_ELG_E:
|
|
|
|
|
err = gcry_sexp_build (&s_pkey, NULL,
|
|
|
|
|
"(public-key(elg(p%m)(g%m)(y%m)))",
|
|
|
|
|
pk->pkey[0], pk->pkey[1], pk->pkey[2]);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GCRY_PK_RSA:
|
|
|
|
|
case GCRY_PK_RSA_S:
|
|
|
|
|
case GCRY_PK_RSA_E:
|
|
|
|
|
err = gcry_sexp_build (&s_pkey, NULL,
|
|
|
|
|
"(public-key(rsa(n%m)(e%m)))",
|
|
|
|
|
pk->pkey[0], pk->pkey[1]);
|
|
|
|
|
break;
|
|
|
|
|
|
gpg: Use only OpenPGP public key algo ids and add the EdDSA algo id.
* common/sexputil.c (get_pk_algo_from_canon_sexp): Change to return a
string.
* g10/keygen.c (check_keygrip): Adjust for change.
* sm/certreqgen-ui.c (check_keygrip): Likewise.
* agent/pksign.c (do_encode_dsa): Remove bogus map_pk_openpgp_to_gcry.
* g10/misc.c (map_pk_openpgp_to_gcry): Remove.
(openpgp_pk_test_algo): Change to a wrapper for openpgp_pk_test_algo2.
(openpgp_pk_test_algo2): Rewrite.
(openpgp_pk_algo_usage, pubkey_nbits): Add support for EdDSA.
(openpgp_pk_algo_name): Rewrite to remove need for gcry calls.
(pubkey_get_npkey, pubkey_get_nskey): Ditto.
(pubkey_get_nsig, pubkey_get_nenc): Ditto.
* g10/keygen.c(do_create_from_keygrip): Support EdDSA.
(common_gen, gen_ecc, ask_keysize, generate_keypair): Ditto.
* g10/build-packet.c (do_key): Ditto.
* g10/export.c (transfer_format_to_openpgp): Ditto.
* g10/getkey.c (cache_public_key): Ditto.
* g10/import.c (transfer_secret_keys): Ditto.
* g10/keylist.c (list_keyblock_print, list_keyblock_colon): Ditto.
* g10/mainproc.c (proc_pubkey_enc): Ditto.
* g10/parse-packet.c (parse_key): Ditto,
* g10/sign.c (hash_for, sign_file, make_keysig_packet): Ditto.
* g10/keyserver.c (print_keyrec): Use openpgp_pk_algo_name.
* g10/pkglue.c (pk_verify, pk_encrypt, pk_check_secret_key): Use only
OpenPGP algo ids and support EdDSA.
* g10/pubkey-enc.c (get_it): Use only OpenPGP algo ids.
* g10/seskey.c (encode_md_value): Ditto.
--
This patch separates Libgcrypt and OpenPGP public key algorithms ids
and in most cases completely removes the Libgcrypt ones. This is
useful because for Libgcrypt we specify the algorithm in the
S-expressions and the public key ids are not anymore needed.
This patch also adds some support for PUBKEY_ALGO_EDDSA which will
eventually be used instead of merging EdDSA with ECDSA. As of now an
experimental algorithm id is used but the plan is to write an I-D so
that we can get a new id from the IETF. Note that EdDSA (Ed25519)
does not yet work and that more changes are required.
The ECC support is still broken right now. Needs to be fixed.
Signed-off-by: Werner Koch <wk@gnupg.org>
2014-01-30 18:48:37 +01:00
|
|
|
|
case PUBKEY_ALGO_EDDSA:
|
2011-01-06 02:33:17 +01:00
|
|
|
|
case PUBKEY_ALGO_ECDSA:
|
|
|
|
|
case PUBKEY_ALGO_ECDH:
|
2011-01-31 09:27:06 +01:00
|
|
|
|
{
|
|
|
|
|
char *curve = openpgp_oid_to_str (pk->pkey[0]);
|
|
|
|
|
if (!curve)
|
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
err = gcry_sexp_build (&s_pkey, NULL,
|
2015-08-06 10:00:41 +02:00
|
|
|
|
pk->pubkey_algo == PUBKEY_ALGO_EDDSA?
|
|
|
|
|
"(public-key(ecc(curve%s)(flags eddsa)(q%m)))":
|
|
|
|
|
(pk->pubkey_algo == PUBKEY_ALGO_ECDH
|
2016-08-25 15:16:32 +02:00
|
|
|
|
&& openpgp_oid_is_cv25519 (pk->pkey[0]))?
|
2015-08-06 10:00:41 +02:00
|
|
|
|
"(public-key(ecc(curve%s)(flags djb-tweak)(q%m)))":
|
|
|
|
|
"(public-key(ecc(curve%s)(q%m)))",
|
2011-01-31 09:27:06 +01:00
|
|
|
|
curve, pk->pkey[1]);
|
|
|
|
|
xfree (curve);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-06 02:33:17 +01:00
|
|
|
|
break;
|
2011-01-21 12:00:57 +01:00
|
|
|
|
|
2010-04-20 19:57:50 +02:00
|
|
|
|
default:
|
|
|
|
|
err = gpg_error (GPG_ERR_PUBKEY_ALGO);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2010-04-20 19:57:50 +02:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
if (!gcry_pk_get_keygrip (s_pkey, array))
|
|
|
|
|
{
|
2018-11-30 12:35:37 +01:00
|
|
|
|
char *hexfpr;
|
|
|
|
|
|
|
|
|
|
hexfpr = hexfingerprint (pk, NULL, 0);
|
|
|
|
|
log_info ("error computing keygrip (fpr=%s)\n", hexfpr);
|
|
|
|
|
xfree (hexfpr);
|
|
|
|
|
|
2014-10-08 21:40:34 +02:00
|
|
|
|
memset (array, 0, 20);
|
2010-04-20 19:57:50 +02:00
|
|
|
|
err = gpg_error (GPG_ERR_GENERAL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (DBG_PACKET)
|
2017-11-27 15:00:25 +01:00
|
|
|
|
log_printhex (array, 20, "keygrip=");
|
2010-04-20 19:57:50 +02:00
|
|
|
|
/* FIXME: Save the keygrip in PK. */
|
|
|
|
|
}
|
|
|
|
|
gcry_sexp_release (s_pkey);
|
2011-02-02 15:48:54 +01:00
|
|
|
|
|
2016-01-07 19:07:59 +01:00
|
|
|
|
return err;
|
2010-04-20 19:57:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Store an allocated buffer with the keygrip of PK encoded as a
|
|
|
|
|
hexstring at r_GRIP. Returns 0 on success. */
|
|
|
|
|
gpg_error_t
|
|
|
|
|
hexkeygrip_from_pk (PKT_public_key *pk, char **r_grip)
|
|
|
|
|
{
|
|
|
|
|
gpg_error_t err;
|
2017-09-27 09:33:14 +02:00
|
|
|
|
unsigned char grip[KEYGRIP_LEN];
|
2010-04-20 19:57:50 +02:00
|
|
|
|
|
|
|
|
|
*r_grip = NULL;
|
|
|
|
|
err = keygrip_from_pk (pk, grip);
|
|
|
|
|
if (!err)
|
|
|
|
|
{
|
2017-09-27 09:33:14 +02:00
|
|
|
|
char * buf = xtrymalloc (KEYGRIP_LEN * 2 + 1);
|
2010-04-20 19:57:50 +02:00
|
|
|
|
if (!buf)
|
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-09-27 09:33:14 +02:00
|
|
|
|
bin2hex (grip, KEYGRIP_LEN, buf);
|
2010-04-20 19:57:50 +02:00
|
|
|
|
*r_grip = buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return err;
|
|
|
|
|
}
|