2006-04-19 11:26:11 +00:00
|
|
|
/* packet.h - OpenPGP packet definitions
|
2007-05-03 04:44:12 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
|
|
|
* 2007 Free Software Foundation, Inc.
|
2015-08-19 13:36:13 +02:00
|
|
|
* Copyright (C) 2015 g10 Code GmbH
|
2003-06-05 07:14:21 +00: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 19:49:40 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-05 07:14:21 +00: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 07:14:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef G10_PACKET_H
|
|
|
|
#define G10_PACKET_H
|
|
|
|
|
2017-03-07 20:21:23 +09:00
|
|
|
#include "../common/types.h"
|
2003-06-18 19:56:13 +00:00
|
|
|
#include "../common/iobuf.h"
|
2010-03-10 12:24:58 +00:00
|
|
|
#include "../common/strlist.h"
|
gpg: Remove cipher.h and put algo ids into a common file.
* common/openpgpdefs.h (cipher_algo_t, pubkey_algo_t, digest_algo_t)
(compress_algo_t): New.
* agent/gpg-agent.c: Remove ../g10/cipher.h. Add openpgpdefs.h.
* g10/cipher.h (DEK): Move to ...
* g10/dek.h: new file.
* g10/cipher.h (is_RSA, is_ELGAMAL, is_DSA)
(PUBKEY_MAX_NPKEY, PUBKEY_MAX_NSKEY, PUBKEY_MAX_NSIG, PUBKEY_MAX_NENC)
(PUBKEY_USAGE_SIG, PUBKEY_USAGE_ENC, PUBKEY_USAGE_CERT)
(PUBKEY_USAGE_AUTH, PUBKEY_USAGE_NONE): Move to
* g10/packet.h: here.
* g10/cipher.h: Remove. Remove from all files.
* g10/filter.h, g10/packet.h: Include dek.h.
* g10/Makefile.am (common_source): Remove cipher.h. Add dek.h.
Signed-off-by: Werner Koch <wk@gnupg.org>
2014-01-29 20:35:05 +01:00
|
|
|
#include "dek.h"
|
2003-06-05 07:14:21 +00:00
|
|
|
#include "filter.h"
|
2006-08-21 20:20:23 +00:00
|
|
|
#include "../common/openpgpdefs.h"
|
2009-12-08 16:30:33 +00:00
|
|
|
#include "../common/userids.h"
|
2017-03-07 20:21:23 +09:00
|
|
|
#include "../common/util.h"
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
#define DEBUG_PARSE_PACKET 1
|
|
|
|
|
2019-05-21 16:25:56 +02:00
|
|
|
/* Maximum length of packets to avoid excessive memory allocation. */
|
|
|
|
#define MAX_KEY_PACKET_LENGTH (256 * 1024)
|
|
|
|
#define MAX_UID_PACKET_LENGTH ( 2 * 1024)
|
|
|
|
#define MAX_COMMENT_PACKET_LENGTH ( 64 * 1024)
|
|
|
|
#define MAX_ATTR_PACKET_LENGTH ( 16 * 1024*1024)
|
2003-06-05 07:14:21 +00:00
|
|
|
|
2019-01-29 18:20:34 +01:00
|
|
|
/* Constants to allocate static MPI arrays. */
|
|
|
|
#define PUBKEY_MAX_NPKEY OPENPGP_MAX_NPKEY
|
|
|
|
#define PUBKEY_MAX_NSKEY OPENPGP_MAX_NSKEY
|
|
|
|
#define PUBKEY_MAX_NSIG OPENPGP_MAX_NSIG
|
|
|
|
#define PUBKEY_MAX_NENC OPENPGP_MAX_NENC
|
gpg: Remove cipher.h and put algo ids into a common file.
* common/openpgpdefs.h (cipher_algo_t, pubkey_algo_t, digest_algo_t)
(compress_algo_t): New.
* agent/gpg-agent.c: Remove ../g10/cipher.h. Add openpgpdefs.h.
* g10/cipher.h (DEK): Move to ...
* g10/dek.h: new file.
* g10/cipher.h (is_RSA, is_ELGAMAL, is_DSA)
(PUBKEY_MAX_NPKEY, PUBKEY_MAX_NSKEY, PUBKEY_MAX_NSIG, PUBKEY_MAX_NENC)
(PUBKEY_USAGE_SIG, PUBKEY_USAGE_ENC, PUBKEY_USAGE_CERT)
(PUBKEY_USAGE_AUTH, PUBKEY_USAGE_NONE): Move to
* g10/packet.h: here.
* g10/cipher.h: Remove. Remove from all files.
* g10/filter.h, g10/packet.h: Include dek.h.
* g10/Makefile.am (common_source): Remove cipher.h. Add dek.h.
Signed-off-by: Werner Koch <wk@gnupg.org>
2014-01-29 20:35:05 +01:00
|
|
|
|
|
|
|
/* Usage flags */
|
|
|
|
#define PUBKEY_USAGE_SIG GCRY_PK_USAGE_SIGN /* Good for signatures. */
|
|
|
|
#define PUBKEY_USAGE_ENC GCRY_PK_USAGE_ENCR /* Good for encryption. */
|
|
|
|
#define PUBKEY_USAGE_CERT GCRY_PK_USAGE_CERT /* Also good to certify keys.*/
|
|
|
|
#define PUBKEY_USAGE_AUTH GCRY_PK_USAGE_AUTH /* Good for authentication. */
|
|
|
|
#define PUBKEY_USAGE_UNKNOWN GCRY_PK_USAGE_UNKN /* Unknown usage flag. */
|
|
|
|
#define PUBKEY_USAGE_NONE 256 /* No usage given. */
|
|
|
|
#if (GCRY_PK_USAGE_SIGN | GCRY_PK_USAGE_ENCR | GCRY_PK_USAGE_CERT \
|
|
|
|
| GCRY_PK_USAGE_AUTH | GCRY_PK_USAGE_UNKN) >= 256
|
|
|
|
# error Please choose another value for PUBKEY_USAGE_NONE
|
|
|
|
#endif
|
2022-09-07 10:34:05 +02:00
|
|
|
#define PUBKEY_USAGE_GROUP 512 /* Group flag. */
|
2023-03-01 17:22:20 +01:00
|
|
|
#define PUBKEY_USAGE_RENC 1024 /* Restricted encryption. */
|
|
|
|
#define PUBKEY_USAGE_TIME 2048 /* Timestamp use. */
|
|
|
|
|
2024-08-12 14:50:08 +02:00
|
|
|
|
2024-06-05 10:00:05 +02:00
|
|
|
/* The usage bits which can be derived from the algo. */
|
|
|
|
#define PUBKEY_USAGE_BASIC_MASK (PUBKEY_USAGE_SIG|PUBKEY_USAGE_ENC\
|
|
|
|
|PUBKEY_USAGE_CERT|PUBKEY_USAGE_AUTH)
|
|
|
|
|
2024-08-12 14:50:08 +02:00
|
|
|
/* The usage bits which define encryption. */
|
|
|
|
#define PUBKEY_USAGE_XENC_MASK (PUBKEY_USAGE_ENC | PUBKEY_USAGE_RENC)
|
|
|
|
|
2023-03-01 17:22:20 +01:00
|
|
|
/* Bitflags to convey hints on what kind of signature is created. */
|
|
|
|
#define SIGNHINT_KEYSIG 1
|
|
|
|
#define SIGNHINT_SELFSIG 2
|
|
|
|
#define SIGNHINT_ADSK 4
|
|
|
|
|
gpg: Remove cipher.h and put algo ids into a common file.
* common/openpgpdefs.h (cipher_algo_t, pubkey_algo_t, digest_algo_t)
(compress_algo_t): New.
* agent/gpg-agent.c: Remove ../g10/cipher.h. Add openpgpdefs.h.
* g10/cipher.h (DEK): Move to ...
* g10/dek.h: new file.
* g10/cipher.h (is_RSA, is_ELGAMAL, is_DSA)
(PUBKEY_MAX_NPKEY, PUBKEY_MAX_NSKEY, PUBKEY_MAX_NSIG, PUBKEY_MAX_NENC)
(PUBKEY_USAGE_SIG, PUBKEY_USAGE_ENC, PUBKEY_USAGE_CERT)
(PUBKEY_USAGE_AUTH, PUBKEY_USAGE_NONE): Move to
* g10/packet.h: here.
* g10/cipher.h: Remove. Remove from all files.
* g10/filter.h, g10/packet.h: Include dek.h.
* g10/Makefile.am (common_source): Remove cipher.h. Add dek.h.
Signed-off-by: Werner Koch <wk@gnupg.org>
2014-01-29 20:35:05 +01:00
|
|
|
|
|
|
|
/* Helper macros. */
|
|
|
|
#define is_RSA(a) ((a)==PUBKEY_ALGO_RSA || (a)==PUBKEY_ALGO_RSA_E \
|
|
|
|
|| (a)==PUBKEY_ALGO_RSA_S )
|
|
|
|
#define is_ELGAMAL(a) ((a)==PUBKEY_ALGO_ELGAMAL_E)
|
|
|
|
#define is_DSA(a) ((a)==PUBKEY_ALGO_DSA)
|
|
|
|
|
|
|
|
/* A pointer to the packet object. */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct packet_struct PACKET;
|
|
|
|
|
|
|
|
/* PKT_GPG_CONTROL types */
|
|
|
|
typedef enum {
|
|
|
|
CTRLPKT_CLEARSIGN_START = 1,
|
|
|
|
CTRLPKT_PIPEMODE = 2,
|
|
|
|
CTRLPKT_PLAINTEXT_MARK =3
|
|
|
|
} ctrlpkttype_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PREFTYPE_NONE = 0,
|
|
|
|
PREFTYPE_SYM = 1,
|
|
|
|
PREFTYPE_HASH = 2,
|
2018-01-10 11:42:38 +01:00
|
|
|
PREFTYPE_ZIP = 3,
|
|
|
|
PREFTYPE_AEAD = 4
|
2003-06-05 07:14:21 +00:00
|
|
|
} preftype_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2011-02-04 12:57:53 +01:00
|
|
|
byte type;
|
2003-06-05 07:14:21 +00:00
|
|
|
byte value;
|
|
|
|
} prefitem_t;
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A string-to-key specifier as defined in RFC 4880, Section 3.7. */
|
2011-02-04 12:57:53 +01:00
|
|
|
typedef struct
|
2010-09-06 19:57:42 +00:00
|
|
|
{
|
|
|
|
int mode; /* Must be an integer due to the GNU modes 1001 et al. */
|
|
|
|
byte hash_algo;
|
|
|
|
byte salt[8];
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The *coded* (i.e., the serialized version) iteration count. */
|
2010-09-06 19:57:42 +00:00
|
|
|
u32 count;
|
2003-06-05 07:14:21 +00:00
|
|
|
} STRING2KEY;
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A symmetric-key encrypted session key packet as defined in RFC
|
|
|
|
4880, Section 5.3. All fields are serialized. */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
2018-01-23 12:07:25 +01:00
|
|
|
/* We support version 4 (rfc4880) and 5 (rfc4880bis). */
|
2016-02-25 21:08:56 +01:00
|
|
|
byte version;
|
2018-01-23 12:07:25 +01:00
|
|
|
/* The cipher algorithm used to encrypt the session key. Note that
|
|
|
|
* this may be different from the algorithm that is used to encrypt
|
|
|
|
* bulk data. */
|
2016-02-25 21:08:56 +01:00
|
|
|
byte cipher_algo;
|
2018-01-23 12:07:25 +01:00
|
|
|
/* The AEAD algorithm or 0 for CFB encryption. */
|
|
|
|
byte aead_algo;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The string-to-key specifier. */
|
|
|
|
STRING2KEY s2k;
|
|
|
|
/* The length of SESKEY in bytes or 0 if this packet does not
|
|
|
|
encrypt a session key. (In the latter case, the results of the
|
|
|
|
S2K function on the password is the session key. See RFC 4880,
|
|
|
|
Section 5.3.) */
|
|
|
|
byte seskeylen;
|
2018-01-23 12:07:25 +01:00
|
|
|
/* The session key as encrypted by the S2K specifier. For AEAD this
|
|
|
|
* includes the nonce and the authentication tag. */
|
2016-02-25 21:08:56 +01:00
|
|
|
byte seskey[1];
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_symkey_enc;
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A public-key encrypted session key packet as defined in RFC 4880,
|
|
|
|
Section 5.1. All fields are serialized. */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The 64-bit keyid. */
|
|
|
|
u32 keyid[2];
|
|
|
|
/* The packet's version. Currently, only version 3 is defined. */
|
|
|
|
byte version;
|
|
|
|
/* The algorithm used for the public key encryption scheme. */
|
|
|
|
byte pubkey_algo;
|
|
|
|
/* Whether to hide the key id. This value is not directly
|
|
|
|
serialized. */
|
|
|
|
byte throw_keyid;
|
|
|
|
/* The session key. */
|
|
|
|
gcry_mpi_t data[PUBKEY_MAX_NENC];
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_pubkey_enc;
|
|
|
|
|
|
|
|
|
2018-08-27 13:12:31 +09:00
|
|
|
/* An object to build a list of public-key encrypted session key. */
|
|
|
|
struct pubkey_enc_list
|
|
|
|
{
|
|
|
|
struct pubkey_enc_list *next;
|
|
|
|
u32 keyid[2];
|
|
|
|
int pubkey_algo;
|
2019-01-16 10:27:21 +09:00
|
|
|
int result;
|
2018-08-27 13:12:31 +09:00
|
|
|
gcry_mpi_t data[PUBKEY_MAX_NENC];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A one-pass signature packet as defined in RFC 4880, Section
|
|
|
|
5.4. All fields are serialized. */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
2016-02-25 21:08:56 +01:00
|
|
|
u32 keyid[2]; /* The 64-bit keyid */
|
|
|
|
/* The signature's classification (RFC 4880, Section 5.2.1). */
|
|
|
|
byte sig_class;
|
2003-06-05 07:14:21 +00:00
|
|
|
byte digest_algo; /* algorithm used for digest */
|
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A message can be signed by multiple keys. In this case, there
|
|
|
|
are n one-pass signature packets before the message to sign and
|
|
|
|
n signatures packets after the message. It is conceivable that
|
|
|
|
someone wants to not only sign the message, but all of the
|
|
|
|
signatures. Now we need to distinguish between signing the
|
|
|
|
message and signing the message plus the surrounding
|
|
|
|
signatures. This is the point of this flag. If set, it means:
|
|
|
|
I sign all of the data starting at the next packet. */
|
|
|
|
byte last;
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_onepass_sig;
|
|
|
|
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A v4 OpenPGP signature has a hashed and unhashed area containing
|
|
|
|
co-called signature subpackets (RFC 4880, Section 5.2.3). These
|
|
|
|
areas are described by this data structure. Use enum_sig_subpkt to
|
|
|
|
parse this area. */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
|
|
|
size_t size; /* allocated */
|
2016-02-25 21:08:56 +01:00
|
|
|
size_t len; /* used (serialized) */
|
|
|
|
byte data[1]; /* the serialized subpackes (serialized) */
|
2003-06-05 07:14:21 +00:00
|
|
|
} subpktarea_t;
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The in-memory representation of a designated revoker signature
|
|
|
|
subpacket (RFC 4880, Section 5.2.3.15). */
|
2003-06-05 07:14:21 +00:00
|
|
|
struct revocation_key {
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A bit field. 0x80 must be set. 0x40 means this information is
|
|
|
|
sensitive (and should not be uploaded to a keyserver by
|
|
|
|
default). */
|
2003-06-05 07:14:21 +00:00
|
|
|
byte class;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The public-key algorithm ID. */
|
2003-06-05 07:14:21 +00:00
|
|
|
byte algid;
|
2018-12-04 15:43:19 +01:00
|
|
|
/* The length of the fingerprint. */
|
|
|
|
byte fprlen;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The fingerprint of the authorized key. */
|
2003-06-05 07:14:21 +00:00
|
|
|
byte fpr[MAX_FINGERPRINT_LEN];
|
|
|
|
};
|
|
|
|
|
2006-04-19 11:26:11 +00:00
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A signature packet (RFC 4880, Section 5.2). Only a subset of these
|
|
|
|
fields are directly serialized (these are marked as such); the rest
|
|
|
|
are read from the subpackets, which are not synthesized when
|
|
|
|
serializing this data structure (i.e., when using build_packet()).
|
|
|
|
Instead, the subpackets must be created by hand. */
|
2011-02-04 12:57:53 +01:00
|
|
|
typedef struct
|
2006-04-19 11:26:11 +00:00
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
struct
|
2006-04-19 11:26:11 +00:00
|
|
|
{
|
|
|
|
unsigned checked:1; /* Signature has been checked. */
|
|
|
|
unsigned valid:1; /* Signature is good (if checked is set). */
|
|
|
|
unsigned chosen_selfsig:1; /* A selfsig that is the chosen one. */
|
|
|
|
unsigned unknown_critical:1;
|
|
|
|
unsigned exportable:1;
|
|
|
|
unsigned revocable:1;
|
|
|
|
unsigned policy_url:1; /* At least one policy URL is present */
|
|
|
|
unsigned notation:1; /* At least one notation is present */
|
|
|
|
unsigned pref_ks:1; /* At least one preferred keyserver is present */
|
2020-03-13 17:14:34 +01:00
|
|
|
unsigned key_block:1; /* A key block subpacket is present. */
|
2006-04-19 11:26:11 +00:00
|
|
|
unsigned expired:1;
|
|
|
|
} flags;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The key that allegedly generated this signature. (Directly
|
|
|
|
serialized in v3 sigs; for v4 sigs, this must be explicitly added
|
|
|
|
as an issuer subpacket (5.2.3.5.) */
|
|
|
|
u32 keyid[2];
|
|
|
|
/* When the signature was made (seconds since the Epoch). (Directly
|
|
|
|
serialized in v3 sigs; for v4 sigs, this must be explicitly added
|
|
|
|
as a signature creation time subpacket (5.2.3.4).) */
|
|
|
|
u32 timestamp;
|
2006-04-19 11:26:11 +00:00
|
|
|
u32 expiredate; /* Expires at this date or 0 if not at all. */
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The serialization format used / to use. If 0, then defaults to
|
|
|
|
version 3. (Serialized.) */
|
2006-04-19 11:26:11 +00:00
|
|
|
byte version;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The signature type. (See RFC 4880, Section 5.2.1.) */
|
|
|
|
byte sig_class;
|
|
|
|
/* Algorithm used for public key scheme (e.g., PUBKEY_ALGO_RSA).
|
|
|
|
(Serialized.) */
|
|
|
|
byte pubkey_algo;
|
|
|
|
/* Algorithm used for digest (e.g., DIGEST_ALGO_SHA1).
|
|
|
|
(Serialized.) */
|
|
|
|
byte digest_algo;
|
2006-04-19 11:26:11 +00:00
|
|
|
byte trust_depth;
|
|
|
|
byte trust_value;
|
|
|
|
const byte *trust_regexp;
|
2015-08-21 10:38:41 +02:00
|
|
|
struct revocation_key *revkey;
|
2006-04-19 11:26:11 +00:00
|
|
|
int numrevkeys;
|
2018-10-25 09:46:23 -04:00
|
|
|
int help_counter; /* Used internally bu some functions. */
|
2016-06-13 10:40:34 +02:00
|
|
|
char *signers_uid; /* Malloced value of the SIGNERS_UID
|
2016-08-10 19:51:54 +02:00
|
|
|
* subpacket or NULL. This string has
|
|
|
|
* already been sanitized. */
|
2006-04-19 11:26:11 +00:00
|
|
|
subpktarea_t *hashed; /* All subpackets with hashed data (v4 only). */
|
|
|
|
subpktarea_t *unhashed; /* Ditto for unhashed data. */
|
2016-02-25 21:08:56 +01:00
|
|
|
/* First 2 bytes of the digest. (Serialized. Note: this is not
|
|
|
|
automatically filled in when serializing a signature!) */
|
|
|
|
byte digest_start[2];
|
|
|
|
/* The signature. (Serialized.) */
|
2006-04-19 11:26:11 +00:00
|
|
|
gcry_mpi_t data[PUBKEY_MAX_NSIG];
|
g10: Add TOFU support.
* configure.ac: Check for sqlite3.
(SQLITE3_CFLAGS): AC_SUBST it.
(SQLITE3_LIBS): Likewise.
* g10/Makefile.am (AM_CFLAGS): Add $(SQLITE3_CFLAGS).
(gpg2_SOURCES): Add tofu.h and tofu.c.
(gpg2_LDADD): Add $(SQLITE3_LIBS).
* g10/tofu.c: New file.
* g10/tofu.h: New file.
* g10/options.h (trust_model): Define TM_TOFU and TM_TOFU_PGP.
(tofu_db_format): Define.
* g10/packet.h (PKT_signature): Add fields digest and digest_len.
* g10/gpg.c: Include "tofu.h".
(cmd_and_opt_values): Declare aTOFUPolicy, oTOFUDefaultPolicy,
oTOFUDBFormat.
(opts): Add them.
(parse_trust_model): Recognize the tofu and tofu+pgp trust models.
(parse_tofu_policy): New function.
(parse_tofu_db_format): New function.
(main): Initialize opt.tofu_default_policy and opt.tofu_db_format.
Handle aTOFUPolicy, oTOFUDefaultPolicy and oTOFUDBFormat.
* g10/mainproc.c (do_check_sig): If the signature is good, copy the
hash to SIG->DIGEST and set SIG->DIGEST_LEN appropriately.
* g10/trustdb.h (get_validity): Add arguments sig and may_ask. Update
callers.
(tdb_get_validity_core): Add arguments sig and may_ask. Update
callers.
* g10/trust.c (get_validity) Add arguments sig and may_ask. Pass them
to tdb_get_validity_core.
* g10/trustdb.c: Include "tofu.h".
(trust_model_string): Handle TM_TOFU and TM_TOFU_PGP.
(tdb_get_validity_core): Add arguments sig and may_ask. If
OPT.TRUST_MODEL is TM_TOFU or TM_TOFU_PGP, compute the TOFU trust
level. Combine it with the computed PGP trust level, if appropriate.
* g10/keyedit.c: Include "tofu.h".
(show_key_with_all_names_colon): If the trust mode is tofu or
tofu+pgp, then show the trust policy.
* g10/keylist.c: Include "tofu.h".
(public_key_list): Also show the PGP stats if the trust model is
TM_TOFU_PGP.
(list_keyblock_colon): If the trust mode is tofu or
tofu+pgp, then show the trust policy.
* g10/pkclist.c: Include "tofu.h".
* g10/gpgv.c (get_validity): Add arguments sig and may_ask.
(enum tofu_policy): Define.
(tofu_get_policy): New stub.
(tofu_policy_str): Likewise.
* g10/test-stubs.c (get_validity): Add arguments sig and may_ask.
(enum tofu_policy): Define.
(tofu_get_policy): New stub.
(tofu_policy_str): Likewise.
* doc/DETAILS: Describe the TOFU Policy field.
* doc/gpg.texi: Document --tofu-set-policy, --trust-model=tofu,
--trust-model=tofu+pgp, --tofu-default-policy and --tofu-db-format.
* tests/openpgp/Makefile.am (TESTS): Add tofu.test.
(TEST_FILES): Add tofu-keys.asc, tofu-keys-secret.asc,
tofu-2183839A-1.txt, tofu-BC15C85A-1.txt and tofu-EE37CF96-1.txt.
(CLEANFILES): Add tofu.db.
(clean-local): Add tofu.d.
* tests/openpgp/tofu.test: New file.
* tests/openpgp/tofu-2183839A-1.txt: New file.
* tests/openpgp/tofu-BC15C85A-1.txt: New file.
* tests/openpgp/tofu-EE37CF96-1.txt: New file.
* tests/openpgp/tofu-keys.asc: New file.
* tests/openpgp/tofu-keys-secret.asc: New file.
--
Signed-off-by: Neal H. Walfield <neal@g10code.com>.
2015-10-18 18:44:05 +02:00
|
|
|
/* The message digest and its length (in bytes). Note the maximum
|
|
|
|
digest length is 512 bits (64 bytes). If DIGEST_LEN is 0, then
|
|
|
|
the digest's value has not been saved here. */
|
|
|
|
byte digest[512 / 8];
|
|
|
|
int digest_len;
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_signature;
|
|
|
|
|
|
|
|
#define ATTRIB_IMAGE 1
|
|
|
|
|
2009-12-08 16:30:33 +00:00
|
|
|
/* This is the cooked form of attributes. */
|
2003-06-05 07:14:21 +00:00
|
|
|
struct user_attribute {
|
|
|
|
byte type;
|
|
|
|
const byte *data;
|
|
|
|
u32 len;
|
|
|
|
};
|
|
|
|
|
2009-12-08 16:30:33 +00:00
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A user id (RFC 4880, Section 5.11) or a user attribute packet (RFC
|
|
|
|
4880, Section 5.12). Only a subset of these fields are directly
|
|
|
|
serialized (these are marked as such); the rest are read from the
|
|
|
|
self-signatures in merge_keys_and_selfsig()). */
|
|
|
|
typedef struct
|
2006-04-19 11:26:11 +00:00
|
|
|
{
|
|
|
|
int ref; /* reference counter */
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The length of NAME. */
|
|
|
|
int len;
|
2006-04-19 11:26:11 +00:00
|
|
|
struct user_attribute *attribs;
|
|
|
|
int numattribs;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* If this is not NULL, the packet is a user attribute rather than a
|
2016-11-29 14:41:22 +01:00
|
|
|
user id (See RFC 4880 5.12). (Serialized.) */
|
2016-02-25 21:08:56 +01:00
|
|
|
byte *attrib_data;
|
|
|
|
/* The length of ATTRIB_DATA. */
|
2006-04-19 11:26:11 +00:00
|
|
|
unsigned long attrib_len;
|
|
|
|
byte *namehash;
|
2023-03-01 17:22:20 +01:00
|
|
|
u16 help_key_usage;
|
2006-04-19 11:26:11 +00:00
|
|
|
u32 help_key_expire;
|
|
|
|
int help_full_count;
|
|
|
|
int help_marginal_count;
|
|
|
|
u32 expiredate; /* expires at this date or 0 if not at all */
|
|
|
|
prefitem_t *prefs; /* list of preferences (may be NULL)*/
|
|
|
|
u32 created; /* according to the self-signature */
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
u32 keyupdate; /* From the ring trust packet. */
|
|
|
|
char *updateurl; /* NULL or the URL of the last update origin. */
|
2017-07-13 17:28:32 +02:00
|
|
|
byte keyorg; /* From the ring trust packet. */
|
2006-04-19 11:26:11 +00:00
|
|
|
byte selfsigversion;
|
|
|
|
struct
|
|
|
|
{
|
2009-12-08 16:30:33 +00:00
|
|
|
unsigned int mdc:1;
|
2018-01-10 11:42:38 +01:00
|
|
|
unsigned int aead:1;
|
2009-12-08 16:30:33 +00:00
|
|
|
unsigned int ks_modify:1;
|
|
|
|
unsigned int compacted:1;
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
unsigned int primary:2; /* 2 if set via the primary flag, 1 if calculated */
|
2020-06-08 15:22:28 +02:00
|
|
|
/* Note that this flag is set in a
|
|
|
|
* keyblock at max for one User ID and for
|
|
|
|
* one User Attribute per keyblock. */
|
2017-03-08 11:01:22 +01:00
|
|
|
unsigned int revoked:1;
|
|
|
|
unsigned int expired:1;
|
2006-04-19 11:26:11 +00:00
|
|
|
} flags;
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
|
2016-07-01 15:40:56 +02:00
|
|
|
char *mbox; /* NULL or the result of mailbox_from_userid. */
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The text contained in the user id packet, which is normally the
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
* name and email address of the key holder (See RFC 4880 5.11).
|
|
|
|
* (Serialized.). For convenience an extra Nul is always appended. */
|
2006-04-19 11:26:11 +00:00
|
|
|
char name[1];
|
2016-02-25 21:08:56 +01:00
|
|
|
} PKT_user_id;
|
2009-12-08 16:30:33 +00:00
|
|
|
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
|
2006-04-19 11:26:11 +00:00
|
|
|
struct revoke_info
|
|
|
|
{
|
|
|
|
/* revoked at this date */
|
|
|
|
u32 date;
|
|
|
|
/* the keyid of the revoking key (selfsig or designated revoker) */
|
|
|
|
u32 keyid[2];
|
|
|
|
/* the algo of the revoking key */
|
|
|
|
byte algo;
|
|
|
|
};
|
2003-06-05 07:14:21 +00:00
|
|
|
|
2010-09-06 19:57:42 +00:00
|
|
|
|
|
|
|
/* Information pertaining to secret keys. */
|
|
|
|
struct seckey_info
|
|
|
|
{
|
|
|
|
int is_protected:1; /* The secret info is protected and must */
|
|
|
|
/* be decrypted before use, the protected */
|
|
|
|
/* MPIs are simply (void*) pointers to memory */
|
|
|
|
/* and should never be passed to a mpi_xxx() */
|
2011-02-04 12:57:53 +01:00
|
|
|
int sha1chk:1; /* SHA1 is used instead of a 16 bit checksum */
|
2010-09-06 19:57:42 +00:00
|
|
|
u16 csum; /* Checksum for old protection modes. */
|
|
|
|
byte algo; /* Cipher used to protect the secret information. */
|
|
|
|
STRING2KEY s2k; /* S2K parameter. */
|
|
|
|
byte ivlen; /* Used length of the IV. */
|
|
|
|
byte iv[16]; /* Initialization vector for CFB mode. */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
/****************
|
2016-02-25 21:08:56 +01:00
|
|
|
* The in-memory representation of a public key (RFC 4880, Section
|
|
|
|
* 5.5). Note: this structure contains significantly more information
|
2016-04-07 13:51:26 +02:00
|
|
|
* than is contained in an OpenPGP public key packet. This
|
2016-02-25 21:08:56 +01:00
|
|
|
* information is derived from the self-signed signatures (by
|
|
|
|
* merge_keys_and_selfsig()) and is ignored when serializing the
|
|
|
|
* packet. The fields that are actually written out when serializing
|
|
|
|
* this packet are marked as accordingly.
|
|
|
|
*
|
2010-09-06 19:57:42 +00:00
|
|
|
* We assume that secret keys have the same number of parameters as
|
|
|
|
* the public key and that the public parameters are the first items
|
|
|
|
* in the PKEY array. Thus NPKEY is always less than NSKEY and it is
|
|
|
|
* possible to compare the secret and public keys by comparing the
|
|
|
|
* first NPKEY elements of the PKEY array. Note that since GnuPG 2.1
|
|
|
|
* we don't use secret keys anymore directly because they are managed
|
|
|
|
* by gpg-agent. However for parsing OpenPGP key files we need a way
|
|
|
|
* to temporary store those secret keys. We do this by putting them
|
|
|
|
* into the public key structure and extending the PKEY field to NSKEY
|
|
|
|
* elements; the extra secret key information are stored in the
|
|
|
|
* SECKEY_INFO field.
|
2003-06-05 07:14:21 +00:00
|
|
|
*/
|
2010-10-20 11:33:50 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2016-02-25 21:08:56 +01:00
|
|
|
/* When the key was created. (Serialized.) */
|
|
|
|
u32 timestamp;
|
2010-10-20 11:33:50 +00:00
|
|
|
u32 expiredate; /* expires at this date or 0 if not at all */
|
|
|
|
u32 max_expiredate; /* must not expire past this date */
|
|
|
|
struct revoke_info revoked;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* An OpenPGP packet consists of a header and a body. This is the
|
|
|
|
size of the header. If this is 0, an appropriate size is
|
|
|
|
automatically chosen based on the size of the body.
|
|
|
|
(Serialized.) */
|
|
|
|
byte hdrbytes;
|
|
|
|
/* The serialization format. If 0, the default version (4) is used
|
|
|
|
when serializing. (Serialized.) */
|
2010-10-20 11:33:50 +00:00
|
|
|
byte version;
|
|
|
|
byte selfsigversion; /* highest version of all of the self-sigs */
|
2019-04-12 11:11:09 +02:00
|
|
|
byte fprlen; /* 0 or length of FPR. */
|
2024-10-31 15:11:55 +01:00
|
|
|
byte pubkey_algo; /* The public key algorithm. (PGP format) */
|
|
|
|
u16 pubkey_usage; /* carries the usage info. */
|
|
|
|
u16 req_usage; /* hack to pass a request to getkey() */
|
2011-02-04 12:57:53 +01:00
|
|
|
u32 has_expired; /* set to the expiration date if expired */
|
2016-02-19 14:48:56 +01:00
|
|
|
/* keyid of the primary key. Never access this value directly.
|
|
|
|
Instead, use pk_main_keyid(). */
|
|
|
|
u32 main_keyid[2];
|
|
|
|
/* keyid of this key. Never access this value directly! Instead,
|
|
|
|
use pk_keyid(). */
|
|
|
|
u32 keyid[2];
|
2019-04-12 11:11:09 +02:00
|
|
|
/* Fingerprint of the key. Only valid if FPRLEN is not 0. */
|
|
|
|
byte fpr[MAX_FINGERPRINT_LEN];
|
2010-10-20 11:33:50 +00:00
|
|
|
prefitem_t *prefs; /* list of preferences (may be NULL) */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int mdc:1; /* MDC feature set. */
|
2018-01-10 11:42:38 +01:00
|
|
|
unsigned int aead:1; /* AEAD feature set. */
|
2010-10-20 11:33:50 +00:00
|
|
|
unsigned int disabled_valid:1;/* The next flag is valid. */
|
|
|
|
unsigned int disabled:1; /* The key has been disabled. */
|
2011-02-04 12:57:53 +01:00
|
|
|
unsigned int primary:1; /* This is a primary key. */
|
2010-10-20 11:33:50 +00:00
|
|
|
unsigned int revoked:2; /* Key has been revoked.
|
|
|
|
1 = revoked by the owner
|
|
|
|
2 = revoked by designated revoker. */
|
|
|
|
unsigned int maybe_revoked:1; /* A designated revocation is
|
|
|
|
present, but without the key to
|
|
|
|
check it. */
|
|
|
|
unsigned int valid:1; /* Key (especially subkey) is valid. */
|
|
|
|
unsigned int dont_cache:1; /* Do not cache this key. */
|
|
|
|
unsigned int backsig:2; /* 0=none, 1=bad, 2=good. */
|
|
|
|
unsigned int serialno_valid:1;/* SERIALNO below is valid. */
|
2016-01-08 15:16:12 +01:00
|
|
|
unsigned int exact:1; /* Found via exact (!) search. */
|
2010-10-20 11:33:50 +00:00
|
|
|
} flags;
|
|
|
|
PKT_user_id *user_id; /* If != NULL: found by that uid. */
|
|
|
|
struct revocation_key *revkey;
|
|
|
|
int numrevkeys;
|
|
|
|
u32 trust_timestamp;
|
|
|
|
byte trust_depth;
|
|
|
|
byte trust_value;
|
2017-07-13 17:28:32 +02:00
|
|
|
byte keyorg; /* From the ring trust packet. */
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
u32 keyupdate; /* From the ring trust packet. */
|
|
|
|
char *updateurl; /* NULL or the URL of the last update origin. */
|
2010-10-20 11:33:50 +00:00
|
|
|
const byte *trust_regexp;
|
|
|
|
char *serialno; /* Malloced hex string or NULL if it is
|
|
|
|
likely not on a card. See also
|
2011-02-04 12:57:53 +01:00
|
|
|
flags.serialno_valid. */
|
2016-02-25 21:08:56 +01:00
|
|
|
/* If not NULL this malloced structure describes a secret key.
|
|
|
|
(Serialized.) */
|
|
|
|
struct seckey_info *seckey_info;
|
|
|
|
/* The public key. Contains pubkey_get_npkey (pubkey_algo) +
|
|
|
|
pubkey_get_nskey (pubkey_algo) MPIs. (If pubkey_get_npkey
|
|
|
|
returns 0, then the algorithm is not understood and the PKEY
|
|
|
|
contains a single opaque MPI.) (Serialized.) */
|
2010-10-20 11:33:50 +00:00
|
|
|
gcry_mpi_t pkey[PUBKEY_MAX_NSKEY]; /* Right, NSKEY elements. */
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_public_key;
|
|
|
|
|
|
|
|
/* Evaluates as true if the pk is disabled, and false if it isn't. If
|
|
|
|
there is no disable value cached, fill one in. */
|
2010-10-20 11:33:50 +00:00
|
|
|
#define pk_is_disabled(a) \
|
|
|
|
(((a)->flags.disabled_valid)? \
|
2017-03-31 20:03:52 +02:00
|
|
|
((a)->flags.disabled):(cache_disabled_value(ctrl,(a))))
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int len; /* length of data */
|
|
|
|
char data[1];
|
|
|
|
} PKT_comment;
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A compression packet (RFC 4880, Section 5.6). */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
2016-02-25 21:08:56 +01:00
|
|
|
/* Not used. */
|
|
|
|
u32 len;
|
|
|
|
/* Whether the serialized version of the packet used / should use
|
|
|
|
the new format. */
|
|
|
|
byte new_ctb;
|
|
|
|
/* The compression algorithm. */
|
|
|
|
byte algorithm;
|
|
|
|
/* An iobuf holding the data to be decompressed. (This is not used
|
|
|
|
for compression!) */
|
|
|
|
iobuf_t buf;
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_compressed;
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A symmetrically encrypted data packet (RFC 4880, Section 5.7) or a
|
|
|
|
symmetrically encrypted integrity protected data packet (Section
|
|
|
|
5.13) */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
2016-02-25 21:08:56 +01:00
|
|
|
/* Remaining length of encrypted data. */
|
|
|
|
u32 len;
|
2018-01-21 16:24:43 +01:00
|
|
|
/* When encrypting in CFB mode, the first block size bytes of data
|
|
|
|
* are random data and the following 2 bytes are copies of the last
|
|
|
|
* two bytes of the random data (RFC 4880, Section 5.7). This
|
|
|
|
* provides a simple check that the key is correct. EXTRALEN is the
|
|
|
|
* size of this extra data or, in AEAD mode, the length of the
|
|
|
|
* headers and the tags. This is used by build_packet when writing
|
|
|
|
* out the packet's header. */
|
2016-02-25 21:08:56 +01:00
|
|
|
int extralen;
|
|
|
|
/* Whether the serialized version of the packet used / should use
|
|
|
|
the new format. */
|
|
|
|
byte new_ctb;
|
|
|
|
/* Whether the packet has an indeterminate length (old format) or
|
|
|
|
was encoded using partial body length headers (new format).
|
|
|
|
Note: this is ignored when encrypting. */
|
|
|
|
byte is_partial;
|
|
|
|
/* If 0, MDC is disabled. Otherwise, the MDC method that was used
|
2018-01-10 11:42:38 +01:00
|
|
|
(only DIGEST_ALGO_SHA1 has ever been defined). */
|
2016-02-25 21:08:56 +01:00
|
|
|
byte mdc_method;
|
2018-01-21 16:24:43 +01:00
|
|
|
/* If 0, AEAD is not used. Otherwise, the used AEAD algorithm.
|
|
|
|
* MDC_METHOD (above) shall be zero if AEAD is used. */
|
|
|
|
byte aead_algo;
|
|
|
|
/* The cipher algo for/from the AEAD packet. 0 for other encryption
|
|
|
|
* packets. */
|
|
|
|
byte cipher_algo;
|
|
|
|
/* The chunk byte from the AEAD packet. */
|
|
|
|
byte chunkbyte;
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* An iobuf holding the data to be decrypted. (This is not used for
|
|
|
|
encryption!) */
|
|
|
|
iobuf_t buf;
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_encrypted;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
byte hash[20];
|
|
|
|
} PKT_mdc;
|
|
|
|
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
|
|
|
|
/* Subtypes for the ring trust packet. */
|
|
|
|
#define RING_TRUST_SIG 0 /* The classical signature cache. */
|
2017-07-20 14:49:07 +02:00
|
|
|
#define RING_TRUST_KEY 1 /* A KEYORG on a primary key. */
|
|
|
|
#define RING_TRUST_UID 2 /* A KEYORG on a user id. */
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
|
|
|
|
/* The local only ring trust packet which OpenPGP declares as
|
|
|
|
* implementation defined. GnuPG uses this to cache signature
|
|
|
|
* verification status and since 2.1.18 also to convey information
|
|
|
|
* about the origin of a key. Note that this packet is not part
|
2017-04-28 10:06:33 +09:00
|
|
|
* struct packet_struct because we use it only local in the packet
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
* parser and builder. */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
unsigned int trustval;
|
|
|
|
unsigned int sigcache;
|
|
|
|
unsigned char subtype; /* The subtype of this ring trust packet. */
|
2017-07-20 14:49:07 +02:00
|
|
|
unsigned char keyorg; /* The origin of the key (KEYORG_*). */
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
u32 keyupdate; /* The wall time the key was last updated. */
|
|
|
|
char *url; /* NULL or the URL of the source. */
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_ring_trust;
|
|
|
|
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A plaintext packet (see RFC 4880, 5.9). */
|
2003-06-05 07:14:21 +00:00
|
|
|
typedef struct {
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The length of data in BUF or 0 if unknown. */
|
|
|
|
u32 len;
|
|
|
|
/* A buffer containing the data stored in the packet's body. */
|
|
|
|
iobuf_t buf;
|
|
|
|
byte new_ctb;
|
|
|
|
byte is_partial; /* partial length encoded */
|
|
|
|
/* The data's formatting. This is either 'b', 't', 'u', 'l' or '1'
|
|
|
|
(however, the last two are deprecated). */
|
|
|
|
int mode;
|
|
|
|
u32 timestamp;
|
|
|
|
/* The name of the file. This can be at most 255 characters long,
|
|
|
|
since namelen is just a byte in the serialized format. */
|
|
|
|
int namelen;
|
|
|
|
char name[1];
|
2003-06-05 07:14:21 +00:00
|
|
|
} PKT_plaintext;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int control;
|
|
|
|
size_t datalen;
|
|
|
|
char data[1];
|
|
|
|
} PKT_gpg_control;
|
|
|
|
|
|
|
|
/* combine all packets into a union */
|
|
|
|
struct packet_struct {
|
|
|
|
pkttype_t pkttype;
|
|
|
|
union {
|
|
|
|
void *generic;
|
|
|
|
PKT_symkey_enc *symkey_enc; /* PKT_SYMKEY_ENC */
|
|
|
|
PKT_pubkey_enc *pubkey_enc; /* PKT_PUBKEY_ENC */
|
|
|
|
PKT_onepass_sig *onepass_sig; /* PKT_ONEPASS_SIG */
|
|
|
|
PKT_signature *signature; /* PKT_SIGNATURE */
|
2015-08-19 13:36:13 +02:00
|
|
|
PKT_public_key *public_key; /* PKT_PUBLIC_[SUB]KEY */
|
2010-09-06 19:57:42 +00:00
|
|
|
PKT_public_key *secret_key; /* PKT_SECRET_[SUB]KEY */
|
2003-06-05 07:14:21 +00:00
|
|
|
PKT_comment *comment; /* PKT_COMMENT */
|
|
|
|
PKT_user_id *user_id; /* PKT_USER_ID */
|
|
|
|
PKT_compressed *compressed; /* PKT_COMPRESSED */
|
|
|
|
PKT_encrypted *encrypted; /* PKT_ENCRYPTED[_MDC] */
|
|
|
|
PKT_mdc *mdc; /* PKT_MDC */
|
|
|
|
PKT_plaintext *plaintext; /* PKT_PLAINTEXT */
|
|
|
|
PKT_gpg_control *gpg_control; /* PKT_GPG_CONTROL */
|
|
|
|
} pkt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define init_packet(a) do { (a)->pkttype = 0; \
|
|
|
|
(a)->pkt.generic = NULL; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
2016-02-25 21:08:56 +01:00
|
|
|
/* A notation. See RFC 4880, Section 5.2.3.16. */
|
2006-04-19 11:26:11 +00:00
|
|
|
struct notation
|
|
|
|
{
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The notation's name. */
|
2006-04-19 11:26:11 +00:00
|
|
|
char *name;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* If the notation is human readable, then the value is stored here
|
2016-05-31 15:43:51 +02:00
|
|
|
as a NUL-terminated string. If it is not human readable a human
|
|
|
|
readable approximation of the binary value _may_ be stored
|
|
|
|
here. */
|
2006-04-19 11:26:11 +00:00
|
|
|
char *value;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* Sometimes we want to %-expand the value. In these cases, we save
|
|
|
|
that transformed value here. */
|
2006-04-19 11:26:11 +00:00
|
|
|
char *altvalue;
|
2016-05-31 15:43:51 +02:00
|
|
|
/* If the notation is not human readable, then the value is stored
|
2016-02-25 21:08:56 +01:00
|
|
|
here. */
|
2006-04-19 11:26:11 +00:00
|
|
|
unsigned char *bdat;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The amount of data stored in BDAT.
|
|
|
|
|
|
|
|
Note: if this is 0 and BDAT is NULL, this does not necessarily
|
|
|
|
mean that the value is human readable. It could be that we have
|
|
|
|
a 0-length value. To determine whether the notation is human
|
|
|
|
readable, always check if VALUE is not NULL. This works, because
|
|
|
|
if a human-readable value has a length of 0, we will still
|
|
|
|
allocate space for the NUL byte. */
|
2006-04-19 11:26:11 +00:00
|
|
|
size_t blen;
|
|
|
|
struct
|
|
|
|
{
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The notation is critical. */
|
2006-04-19 11:26:11 +00:00
|
|
|
unsigned int critical:1;
|
2016-05-31 15:43:51 +02:00
|
|
|
/* The notation is human readable. */
|
|
|
|
unsigned int human:1;
|
2016-02-25 21:08:56 +01:00
|
|
|
/* The notation should be deleted. */
|
2006-04-19 11:26:11 +00:00
|
|
|
unsigned int ignore:1;
|
|
|
|
} flags;
|
2016-02-25 21:08:56 +01:00
|
|
|
|
|
|
|
/* A field to facilitate creating a list of notations. */
|
2006-04-19 11:26:11 +00:00
|
|
|
struct notation *next;
|
|
|
|
};
|
2016-05-31 15:43:51 +02:00
|
|
|
typedef struct notation *notation_t;
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
/*-- mainproc.c --*/
|
2007-05-03 04:44:12 +00:00
|
|
|
void reset_literals_seen(void);
|
2010-10-01 20:33:53 +00:00
|
|
|
int proc_packets (ctrl_t ctrl, void *ctx, iobuf_t a );
|
|
|
|
int proc_signature_packets (ctrl_t ctrl, void *ctx, iobuf_t a,
|
2006-10-02 11:54:35 +00:00
|
|
|
strlist_t signedfiles, const char *sigfile );
|
2010-10-01 20:33:53 +00:00
|
|
|
int proc_signature_packets_by_fd (ctrl_t ctrl,
|
|
|
|
void *anchor, IOBUF a, int signed_data_fd );
|
|
|
|
int proc_encryption_packets (ctrl_t ctrl, void *ctx, iobuf_t a);
|
2003-06-18 19:56:13 +00:00
|
|
|
int list_packets( iobuf_t a );
|
2003-06-05 07:14:21 +00:00
|
|
|
|
2018-07-05 20:55:32 +02:00
|
|
|
const byte *issuer_fpr_raw (PKT_signature *sig, size_t *r_len);
|
2018-04-12 17:53:17 +02:00
|
|
|
char *issuer_fpr_string (PKT_signature *sig);
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
/*-- parse-packet.c --*/
|
2015-08-19 13:36:13 +02:00
|
|
|
|
2018-08-29 09:36:09 +02:00
|
|
|
|
|
|
|
void register_known_notation (const char *string);
|
|
|
|
|
2015-08-19 13:36:13 +02:00
|
|
|
/* Sets the packet list mode to MODE (i.e., whether we are dumping a
|
|
|
|
packet or not). Returns the current mode. This allows for
|
|
|
|
temporarily suspending dumping by doing the following:
|
|
|
|
|
|
|
|
int saved_mode = set_packet_list_mode (0);
|
|
|
|
...
|
|
|
|
set_packet_list_mode (saved_mode);
|
|
|
|
*/
|
2003-06-05 07:14:21 +00:00
|
|
|
int set_packet_list_mode( int mode );
|
|
|
|
|
2017-03-29 10:02:40 +02:00
|
|
|
|
|
|
|
/* A context used with parse_packet. */
|
|
|
|
struct parse_packet_ctx_s
|
|
|
|
{
|
2017-03-29 11:57:40 +02:00
|
|
|
iobuf_t inp; /* The input stream with the packets. */
|
2017-03-30 16:01:52 +02:00
|
|
|
struct packet_struct last_pkt; /* The last parsed packet. */
|
2017-03-29 11:57:40 +02:00
|
|
|
int free_last_pkt; /* Indicates that LAST_PKT must be freed. */
|
2017-05-08 13:52:39 +02:00
|
|
|
int skip_meta; /* Skip ring trust packets. */
|
2017-05-08 14:24:00 +02:00
|
|
|
unsigned int n_parsed_packets; /* Number of parsed packets. */
|
2017-03-29 10:02:40 +02:00
|
|
|
};
|
|
|
|
typedef struct parse_packet_ctx_s *parse_packet_ctx_t;
|
|
|
|
|
2017-03-29 11:57:40 +02:00
|
|
|
#define init_parse_packet(a,i) do { \
|
|
|
|
(a)->inp = (i); \
|
2017-03-30 16:01:52 +02:00
|
|
|
(a)->last_pkt.pkttype = 0; \
|
|
|
|
(a)->last_pkt.pkt.generic= NULL;\
|
2017-03-29 11:57:40 +02:00
|
|
|
(a)->free_last_pkt = 0; \
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
(a)->skip_meta = 0; \
|
2017-05-08 14:24:00 +02:00
|
|
|
(a)->n_parsed_packets = 0; \
|
2017-03-29 11:57:40 +02:00
|
|
|
} while (0)
|
2017-03-29 10:02:40 +02:00
|
|
|
|
2017-03-29 11:57:40 +02:00
|
|
|
#define deinit_parse_packet(a) do { \
|
|
|
|
if ((a)->free_last_pkt) \
|
|
|
|
free_packet (NULL, (a)); \
|
|
|
|
} while (0)
|
2017-03-29 10:02:40 +02:00
|
|
|
|
|
|
|
|
2003-06-05 07:14:21 +00:00
|
|
|
#if DEBUG_PARSE_PACKET
|
2015-08-19 13:36:13 +02:00
|
|
|
/* There are debug functions and should not be used directly. */
|
2017-03-29 10:02:40 +02:00
|
|
|
int dbg_search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
|
|
|
|
off_t *retpos, int with_uid,
|
2003-06-05 07:14:21 +00:00
|
|
|
const char* file, int lineno );
|
2017-03-29 10:02:40 +02:00
|
|
|
int dbg_parse_packet (parse_packet_ctx_t ctx, PACKET *ret_pkt,
|
|
|
|
const char *file, int lineno);
|
2003-06-18 19:56:13 +00:00
|
|
|
int dbg_copy_all_packets( iobuf_t inp, iobuf_t out,
|
2003-06-05 07:14:21 +00:00
|
|
|
const char* file, int lineno );
|
2003-06-18 19:56:13 +00:00
|
|
|
int dbg_copy_some_packets( iobuf_t inp, iobuf_t out, off_t stopoff,
|
2003-06-05 07:14:21 +00:00
|
|
|
const char* file, int lineno );
|
2003-06-18 19:56:13 +00:00
|
|
|
int dbg_skip_some_packets( iobuf_t inp, unsigned n,
|
2003-06-05 07:14:21 +00:00
|
|
|
const char* file, int lineno );
|
|
|
|
#define search_packet( a,b,c,d ) \
|
|
|
|
dbg_search_packet( (a), (b), (c), (d), __FILE__, __LINE__ )
|
|
|
|
#define parse_packet( a, b ) \
|
|
|
|
dbg_parse_packet( (a), (b), __FILE__, __LINE__ )
|
|
|
|
#define copy_all_packets( a,b ) \
|
|
|
|
dbg_copy_all_packets((a),(b), __FILE__, __LINE__ )
|
|
|
|
#define copy_some_packets( a,b,c ) \
|
|
|
|
dbg_copy_some_packets((a),(b),(c), __FILE__, __LINE__ )
|
|
|
|
#define skip_some_packets( a,b ) \
|
|
|
|
dbg_skip_some_packets((a),(b), __FILE__, __LINE__ )
|
|
|
|
#else
|
2015-08-19 13:36:13 +02:00
|
|
|
/* Return the next valid OpenPGP packet in *PKT. (This function will
|
2017-03-29 10:02:40 +02:00
|
|
|
* skip any packets whose type is 0.) CTX must have been setup prior to
|
|
|
|
* calling this function.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 if EOF is reached, and an error code
|
|
|
|
* otherwise. In the case of an error, the packet in *PKT may be
|
|
|
|
* partially constructed. As such, even if there is an error, it is
|
|
|
|
* necessary to free *PKT to avoid a resource leak. To detect what
|
|
|
|
* has been allocated, clear *PKT before calling this function. */
|
|
|
|
int parse_packet (parse_packet_ctx_t ctx, PACKET *pkt);
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Return the first OpenPGP packet in *PKT that contains a key (either
|
2017-03-29 10:02:40 +02:00
|
|
|
* a public subkey, a public key, a secret subkey or a secret key) or,
|
|
|
|
* if WITH_UID is set, a user id.
|
|
|
|
*
|
|
|
|
* Saves the position in the pipeline of the start of the returned
|
|
|
|
* packet (according to iobuf_tell) in RETPOS, if it is not NULL.
|
|
|
|
*
|
|
|
|
* The return semantics are the same as parse_packet. */
|
|
|
|
int search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
|
|
|
|
off_t *retpos, int with_uid);
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Copy all packets (except invalid packets, i.e., those with a type
|
2017-03-29 10:02:40 +02:00
|
|
|
* of 0) from INP to OUT until either an error occurs or EOF is
|
|
|
|
* reached.
|
|
|
|
*
|
|
|
|
* Returns -1 when end of file is reached or an error code, if an
|
|
|
|
* error occurred. (Note: this function never returns 0, because it
|
|
|
|
* effectively keeps going until it gets an EOF.) */
|
|
|
|
int copy_all_packets (iobuf_t inp, iobuf_t out );
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Like copy_all_packets, but stops at the first packet that starts at
|
2017-03-29 10:02:40 +02:00
|
|
|
* or after STOPOFF (as indicated by iobuf_tell).
|
|
|
|
*
|
|
|
|
* Example: if STOPOFF is 100, the first packet in INP goes from
|
|
|
|
* 0 to 110 and the next packet starts at offset 111, then the packet
|
|
|
|
* starting at offset 0 will be completely processed (even though it
|
|
|
|
* extends beyond STOPOFF) and the packet starting at offset 111 will
|
|
|
|
* not be processed at all. */
|
|
|
|
int copy_some_packets (iobuf_t inp, iobuf_t out, off_t stopoff);
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Skips the next N packets from INP.
|
2017-03-29 10:02:40 +02:00
|
|
|
*
|
|
|
|
* If parsing a packet returns an error code, then the function stops
|
|
|
|
* immediately and returns the error code. Note: in the case of an
|
|
|
|
* error, this function does not indicate how many packets were
|
|
|
|
* successfully processed. */
|
|
|
|
int skip_some_packets (iobuf_t inp, unsigned int n);
|
2003-06-05 07:14:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-08-19 13:36:13 +02:00
|
|
|
/* Parse a signature packet and store it in *SIG.
|
|
|
|
|
|
|
|
The signature packet is read from INP. The OpenPGP header (the tag
|
|
|
|
and the packet's length) have already been read; the next byte read
|
|
|
|
from INP should be the first byte of the packet's contents. The
|
|
|
|
packet's type (as extract from the tag) must be passed as PKTTYPE
|
|
|
|
and the packet's length must be passed as PKTLEN. This is used as
|
|
|
|
the upper bound on the amount of data read from INP. If the packet
|
|
|
|
is shorter than PKTLEN, the data at the end will be silently
|
|
|
|
skipped. If an error occurs, an error code will be returned. -1
|
|
|
|
means the EOF was encountered. 0 means parsing was successful. */
|
2006-04-19 11:26:11 +00:00
|
|
|
int parse_signature( iobuf_t inp, int pkttype, unsigned long pktlen,
|
|
|
|
PKT_signature *sig );
|
2015-08-19 13:36:13 +02:00
|
|
|
|
2019-09-05 20:36:38 +02:00
|
|
|
/* Given a signature packet, either:
|
|
|
|
*
|
|
|
|
* - test whether there are any subpackets with the critical bit set
|
|
|
|
* that we don't understand,
|
|
|
|
*
|
|
|
|
* - list the subpackets, or,
|
|
|
|
*
|
|
|
|
* - find a subpacket with a specific type.
|
|
|
|
*
|
|
|
|
* The WANT_HASHED flag indicates that the hashed area shall be
|
|
|
|
* considered.
|
|
|
|
*
|
|
|
|
* REQTYPE indicates the type of operation.
|
|
|
|
*
|
|
|
|
* If REQTYPE is SIGSUBPKT_TEST_CRITICAL, then this function checks
|
|
|
|
* whether there are any subpackets that have the critical bit and
|
|
|
|
* which GnuPG cannot handle. If GnuPG understands all subpackets
|
|
|
|
* whose critical bit is set, then this function returns simply
|
|
|
|
* returns SUBPKTS. If there is a subpacket whose critical bit is set
|
|
|
|
* and which GnuPG does not understand, then this function returns
|
|
|
|
* NULL and, if START is not NULL, sets *START to the 1-based index of
|
|
|
|
* the subpacket that violates the constraint.
|
|
|
|
*
|
|
|
|
* If REQTYPE is SIGSUBPKT_LIST_HASHED or SIGSUBPKT_LIST_UNHASHED, the
|
|
|
|
* packets are dumped. Note: if REQTYPE is SIGSUBPKT_LIST_HASHED,
|
|
|
|
* this function does not check whether the hash is correct; this is
|
|
|
|
* merely an indication of the section that the subpackets came from.
|
|
|
|
*
|
|
|
|
* If REQTYPE is anything else, then this function interprets the
|
|
|
|
* values as a subpacket type and looks for the first subpacket with
|
|
|
|
* that type. If such a packet is found, *CRITICAL (if not NULL) is
|
|
|
|
* set if the critical bit was set, *RET_N is set to the offset of the
|
|
|
|
* subpacket's content within the SUBPKTS buffer, *START is set to the
|
|
|
|
* 1-based index of the subpacket within the buffer, and returns
|
|
|
|
* &SUBPKTS[*RET_N].
|
|
|
|
*
|
|
|
|
* *START is the number of initial subpackets to not consider. Thus,
|
|
|
|
* if *START is 2, then the first 2 subpackets are ignored.
|
|
|
|
*/
|
|
|
|
const byte *enum_sig_subpkt (PKT_signature *sig, int want_hashed,
|
|
|
|
sigsubpkttype_t reqtype,
|
|
|
|
size_t *ret_n, int *start, int *critical );
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Shorthand for:
|
2019-09-05 20:36:38 +02:00
|
|
|
*
|
|
|
|
* enum_sig_subpkt (sig, want_hashed, reqtype, ret_n, NULL, NULL);
|
|
|
|
*/
|
|
|
|
const byte *parse_sig_subpkt (PKT_signature *sig, int want_hashed,
|
|
|
|
sigsubpkttype_t reqtype,
|
|
|
|
size_t *ret_n );
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* This calls parse_sig_subpkt first on the hashed signature area in
|
2019-09-05 20:36:38 +02:00
|
|
|
* SIG and then, if that returns NULL, calls parse_sig_subpkt on the
|
|
|
|
* unhashed subpacket area in SIG. */
|
|
|
|
const byte *parse_sig_subpkt2 (PKT_signature *sig, sigsubpkttype_t reqtype);
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Returns whether the N byte large buffer BUFFER is sufficient to
|
|
|
|
hold a subpacket of type TYPE. Note: the buffer refers to the
|
|
|
|
contents of the subpacket (not the header) and it must already be
|
|
|
|
initialized: for some subpackets, it checks some internal
|
|
|
|
constraints.
|
|
|
|
|
|
|
|
Returns 0 if the size is acceptable. Returns -2 if the buffer is
|
2015-11-16 12:41:46 +01:00
|
|
|
definitely too short. To check for an error, check whether the
|
2015-08-19 13:36:13 +02:00
|
|
|
return value is less than 0. */
|
2003-06-05 07:14:21 +00:00
|
|
|
int parse_one_sig_subpkt( const byte *buffer, size_t n, int type );
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Looks for revocation key subpackets (see RFC 4880 5.2.3.15) in the
|
|
|
|
hashed area of the signature packet. Any that are found are added
|
|
|
|
to SIG->REVKEY and SIG->NUMREVKEYS is updated appropriately. */
|
2003-06-05 07:14:21 +00:00
|
|
|
void parse_revkeys(PKT_signature *sig);
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Extract the attributes from the buffer at UID->ATTRIB_DATA and
|
|
|
|
update UID->ATTRIBS and UID->NUMATTRIBS accordingly. */
|
2003-06-05 07:14:21 +00:00
|
|
|
int parse_attribute_subpkts(PKT_user_id *uid);
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Set the UID->NAME field according to the attributes. MAX_NAMELEN
|
|
|
|
must be at least 71. */
|
2003-06-05 07:14:21 +00:00
|
|
|
void make_attribute_uidname(PKT_user_id *uid, size_t max_namelen);
|
2015-08-19 13:36:13 +02:00
|
|
|
|
|
|
|
/* Allocate and initialize a new GPG control packet. DATA is the data
|
|
|
|
to save in the packet. */
|
2003-06-05 07:14:21 +00:00
|
|
|
PACKET *create_gpg_control ( ctrlpkttype_t type,
|
|
|
|
const byte *data,
|
|
|
|
size_t datalen );
|
|
|
|
|
|
|
|
/*-- build-packet.c --*/
|
2019-11-27 11:58:47 +01:00
|
|
|
gpg_error_t build_keyblock_image (kbnode_t keyblock, iobuf_t *r_iobuf);
|
gpg: Revamp reading and writing of ring trust packets.
* g10/parse-packet.c (parse_trust): Rename to ...
(parse_ring_trust): this. Change args and implement new ring trust
packet format.
(parse): Add special ring trust packet handling.
* g10/packet.h (PKT_user_id): New fields KEYUPDATE, UPDATEURL, and
KEYSRC.
(PKT_public_key): Ditto.
(RING_TRUST_SIG, RING_TRUST_KEY, RING_TRUST_UID): New consts.
(PKT_ring_trust): New.
(struct packet_struct): Remove member RING_TRUST.
(strcu parse_packet_ctx_s): Add field SKIP_META.
(init_parse_packet): Init SKIPT_META.
* g10/free-packet.c (release_public_key_parts): Free UDPATEURL.
(free_user_id): Ditto.
* g10/mainproc.c (list_node): Remove printing of non-documented "rtv"
lines.
* g10/build-packet.c (build_packet_and_meta): New.
(do_ring_trust): New.
* g10/export.c (write_keyblock_to_output): Use build_packet_and_meta
in backup mode.
(do_export_one_keyblock): Ditto.
* g10/import.c (read_block): Add arg WITH_META. Skip ring trust
packets if that ism not set.
(import): Call read_block WITH_META in restore mode.
* g10/keydb.h (KEYSRC_UNKNOWN, KEYSRC_FILE, KEYSRC_KS, KEYSRC_PREF_KS)
(KEYSRC_WKD, KEYSRC_WKD_SD, KEYSRC_DANE): New constants. They are not
yet used, though.
* g10/keydb.c (parse_keyblock_image): Allow ring trust packets.
(build_keyblock_image): Ditto. Use build_packet_and_meta.
* g10/keyring.c (keyring_get_keyblock): Remove specila treatment of
ring trust packets.
(write_keyblock): Use build_packet_and_meta. Remove special treatment
of ring trust packets and initialization of the signature caches.
--
This patch introduced the framework to store meta data for keys and
user ids in the keyrings/keyboxes. Ring trust packets are
implementation defined and have always been used in gpg to cache the
signature verification status.
Ring trust packets are only exported with the export option "backup"
and only imported with the import option "restore".
The new code uses a cleaner way to handle the ring trust packets: When
the parser reads a ring trust packet and the previously read packet
matches the type of that ring trust packet, the information is stored
in that previously read packet (signature, user id, or primary key)
and the next packet is read immediately. Thus only the parser sees
the ring trust packets. Ring trust packets are written by using the
new function build_packet_and_meta instead of build_packet. That
function writes a ring trust packet when the needed information is
available.
As a side-effect of this patch the signature status cache works again
and "gpg --check-sigs" is thus much faster.
Signed-off-by: Werner Koch <wk@gnupg.org>
2017-03-30 09:07:02 +02:00
|
|
|
int build_packet (iobuf_t out, PACKET *pkt);
|
|
|
|
gpg_error_t build_packet_and_meta (iobuf_t out, PACKET *pkt);
|
2019-03-14 11:20:07 +01:00
|
|
|
gpg_error_t gpg_mpi_write (iobuf_t out, gcry_mpi_t a, unsigned int *t_nwritten);
|
2013-11-15 08:59:45 +01:00
|
|
|
gpg_error_t gpg_mpi_write_nohdr (iobuf_t out, gcry_mpi_t a);
|
2003-06-05 07:14:21 +00:00
|
|
|
u32 calc_packet_length( PACKET *pkt );
|
|
|
|
void build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
|
|
|
|
const byte *buffer, size_t buflen );
|
2023-03-01 17:22:20 +01:00
|
|
|
void build_sig_subpkt_from_sig (PKT_signature *sig, PKT_public_key *pksk,
|
|
|
|
unsigned int signhints);
|
2003-06-05 07:14:21 +00:00
|
|
|
int delete_sig_subpkt(subpktarea_t *buffer, sigsubpkttype_t type );
|
|
|
|
void build_attribute_subpkt(PKT_user_id *uid,byte type,
|
|
|
|
const void *buf,u32 buflen,
|
|
|
|
const void *header,u32 headerlen);
|
2006-04-19 11:26:11 +00:00
|
|
|
struct notation *string_to_notation(const char *string,int is_utf8);
|
2016-02-29 14:12:57 +01:00
|
|
|
struct notation *blob_to_notation(const char *name,
|
|
|
|
const char *data, size_t len);
|
2006-04-19 11:26:11 +00:00
|
|
|
struct notation *sig_to_notation(PKT_signature *sig);
|
|
|
|
void free_notation(struct notation *notation);
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
/*-- free-packet.c --*/
|
|
|
|
void free_symkey_enc( PKT_symkey_enc *enc );
|
|
|
|
void free_pubkey_enc( PKT_pubkey_enc *enc );
|
|
|
|
void free_seckey_enc( PKT_signature *enc );
|
|
|
|
void release_public_key_parts( PKT_public_key *pk );
|
|
|
|
void free_public_key( PKT_public_key *key );
|
|
|
|
void free_attributes(PKT_user_id *uid);
|
|
|
|
void free_user_id( PKT_user_id *uid );
|
|
|
|
void free_comment( PKT_comment *rem );
|
2017-03-29 11:57:40 +02:00
|
|
|
void free_packet (PACKET *pkt, parse_packet_ctx_t parsectx);
|
2003-06-05 07:14:21 +00:00
|
|
|
prefitem_t *copy_prefs (const prefitem_t *prefs);
|
2023-03-01 17:22:20 +01:00
|
|
|
PKT_public_key *copy_public_key_basics (PKT_public_key *d, PKT_public_key *s);
|
2003-06-05 07:14:21 +00:00
|
|
|
PKT_public_key *copy_public_key( PKT_public_key *d, PKT_public_key *s );
|
|
|
|
PKT_signature *copy_signature( PKT_signature *d, PKT_signature *s );
|
|
|
|
PKT_user_id *scopy_user_id (PKT_user_id *sd );
|
|
|
|
int cmp_public_keys( PKT_public_key *a, PKT_public_key *b );
|
|
|
|
int cmp_signatures( PKT_signature *a, PKT_signature *b );
|
|
|
|
int cmp_user_ids( PKT_user_id *a, PKT_user_id *b );
|
|
|
|
|
|
|
|
|
|
|
|
/*-- sig-check.c --*/
|
2015-10-19 11:15:00 +02:00
|
|
|
/* Check a signature. This is shorthand for check_signature2 with
|
|
|
|
the unnamed arguments passed as NULL. */
|
2017-03-31 20:03:52 +02:00
|
|
|
int check_signature (ctrl_t ctrl, PKT_signature *sig, gcry_md_hd_t digest);
|
2015-10-19 11:15:00 +02:00
|
|
|
|
|
|
|
/* Check a signature. Looks up the public key from the key db. (If
|
2016-09-01 16:00:06 +02:00
|
|
|
* R_PK is not NULL, it is stored at RET_PK.) DIGEST contains a
|
|
|
|
* valid hash context that already includes the signed data. This
|
|
|
|
* function adds the relevant meta-data to the hash before finalizing
|
2020-03-13 17:14:34 +01:00
|
|
|
* it and verifying the signature. FOCRED_PK is usually NULL. */
|
2017-03-31 20:03:52 +02:00
|
|
|
gpg_error_t check_signature2 (ctrl_t ctrl,
|
|
|
|
PKT_signature *sig, gcry_md_hd_t digest,
|
2019-03-14 11:20:07 +01:00
|
|
|
const void *extrahash, size_t extrahashlen,
|
2020-03-13 17:14:34 +01:00
|
|
|
PKT_public_key *forced_pk,
|
2016-09-01 16:00:06 +02:00
|
|
|
u32 *r_expiredate, int *r_expired, int *r_revoked,
|
|
|
|
PKT_public_key **r_pk);
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-- pubkey-enc.c --*/
|
2018-08-27 13:12:31 +09:00
|
|
|
gpg_error_t get_session_key (ctrl_t ctrl, struct pubkey_enc_list *k, DEK *dek);
|
2010-04-21 17:30:07 +00:00
|
|
|
gpg_error_t get_override_session_key (DEK *dek, const char *string);
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
/*-- compress.c --*/
|
2010-10-01 20:33:53 +00:00
|
|
|
int handle_compressed (ctrl_t ctrl, void *ctx, PKT_compressed *cd,
|
2003-06-18 19:56:13 +00:00
|
|
|
int (*callback)(iobuf_t, void *), void *passthru );
|
2003-06-05 07:14:21 +00:00
|
|
|
|
2022-03-18 11:13:23 +01:00
|
|
|
/*-- decrypt-data.c --*/
|
|
|
|
int decrypt_data (ctrl_t ctrl, void *ctx, PKT_encrypted *ed, DEK *dek,
|
|
|
|
int *compliance_error);
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
/*-- plaintext.c --*/
|
2015-11-05 12:20:42 +01:00
|
|
|
gpg_error_t get_output_file (const byte *embedded_name, int embedded_namelen,
|
|
|
|
iobuf_t data, char **fnamep, estream_t *fpp);
|
2003-06-05 07:14:21 +00:00
|
|
|
int handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
2006-04-19 11:26:11 +00:00
|
|
|
int nooutput, int clearsig );
|
|
|
|
int ask_for_detached_datafile( gcry_md_hd_t md, gcry_md_hd_t md2,
|
2003-06-05 07:14:21 +00:00
|
|
|
const char *inname, int textmode );
|
|
|
|
|
|
|
|
/*-- sign.c --*/
|
2017-03-31 20:03:52 +02:00
|
|
|
int make_keysig_packet (ctrl_t ctrl,
|
|
|
|
PKT_signature **ret_sig, PKT_public_key *pk,
|
2003-06-05 07:14:21 +00:00
|
|
|
PKT_user_id *uid, PKT_public_key *subpk,
|
2019-05-13 12:38:32 +02:00
|
|
|
PKT_public_key *pksk, int sigclass,
|
2014-10-12 20:07:12 +02:00
|
|
|
u32 timestamp, u32 duration,
|
2003-06-05 07:14:21 +00:00
|
|
|
int (*mksubpkt)(PKT_signature *, void *),
|
2010-09-01 12:49:05 +00:00
|
|
|
void *opaque,
|
|
|
|
const char *cache_nonce);
|
2017-03-31 20:03:52 +02:00
|
|
|
gpg_error_t update_keysig_packet (ctrl_t ctrl,
|
|
|
|
PKT_signature **ret_sig,
|
2003-06-05 07:14:21 +00:00
|
|
|
PKT_signature *orig_sig,
|
|
|
|
PKT_public_key *pk,
|
|
|
|
PKT_user_id *uid,
|
|
|
|
PKT_public_key *subpk,
|
2010-02-02 14:06:19 +00:00
|
|
|
PKT_public_key *pksk,
|
2003-06-05 07:14:21 +00:00
|
|
|
int (*mksubpkt)(PKT_signature *, void *),
|
|
|
|
void *opaque );
|
|
|
|
|
|
|
|
/*-- keygen.c --*/
|
2015-05-08 16:08:57 +02:00
|
|
|
PKT_user_id *generate_user_id (kbnode_t keyblock, const char *uidstr);
|
2003-06-05 07:14:21 +00:00
|
|
|
|
|
|
|
#endif /*G10_PACKET_H*/
|