diff options
author | Werner Koch <[email protected]> | 2017-03-30 07:07:02 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2017-03-30 07:07:02 +0000 |
commit | a8895c99a7d0750132477d80cd66caaf3a709113 (patch) | |
tree | e36d1f640132ecc4723fe204de452ea95eaf7074 /g10/packet.h | |
parent | gpg: Extend free_packet to handle a packet parser context. (diff) | |
download | gnupg-a8895c99a7d0750132477d80cd66caaf3a709113.tar.gz gnupg-a8895c99a7d0750132477d80cd66caaf3a709113.zip |
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 <[email protected]>
Diffstat (limited to 'g10/packet.h')
-rw-r--r-- | g10/packet.h | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/g10/packet.h b/g10/packet.h index ad6f317e7..b23298aac 100644 --- a/g10/packet.h +++ b/g10/packet.h @@ -283,20 +283,25 @@ typedef struct 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 */ + u32 keyupdate; /* From the ring trust packet. */ + char *updateurl; /* NULL or the URL of the last update origin. */ + byte keysrc; /* From the ring trust packet. */ byte selfsigversion; struct { unsigned int mdc:1; unsigned int ks_modify:1; unsigned int compacted:1; - unsigned int primary:2; /* 2 if set via the primary flag, 1 if calculated */ + unsigned int primary:2; /* 2 if set via the primary flag, 1 if calculated */ unsigned int revoked:1; unsigned int expired:1; } flags; + char *mbox; /* NULL or the result of mailbox_from_userid. */ + /* The text contained in the user id packet, which is normally the - name and email address of the key holder (See RFC 4880 5.11). - (Serialized.). For convenience an extra Nul is always appended. */ + * name and email address of the key holder (See RFC 4880 5.11). + * (Serialized.). For convenience an extra Nul is always appended. */ char name[1]; } PKT_user_id; @@ -402,6 +407,9 @@ typedef struct u32 trust_timestamp; byte trust_depth; byte trust_value; + byte keysrc; /* From the ring trust packet. */ + u32 keyupdate; /* From the ring trust packet. */ + char *updateurl; /* NULL or the URL of the last update origin. */ const byte *trust_regexp; char *serialno; /* Malloced hex string or NULL if it is likely not on a card. See also @@ -474,11 +482,28 @@ typedef struct { byte hash[20]; } PKT_mdc; + +/* Subtypes for the ring trust packet. */ +#define RING_TRUST_SIG 0 /* The classical signature cache. */ +#define RING_TRUST_KEY 1 /* A KEYSRC on a primary key. */ +#define RING_TRUST_UID 2 /* A KEYSRC on a user id. */ + +/* 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 + * struct packet_struct becuase we use it only local in the packet + * parser and builder. */ typedef struct { - unsigned int trustval; - unsigned int sigcache; + unsigned int trustval; + unsigned int sigcache; + unsigned char subtype; /* The subtype of this ring trust packet. */ + unsigned char keysrc; /* The origin of the key (KEYSRC_*). */ + u32 keyupdate; /* The wall time the key was last updated. */ + char *url; /* NULL or the URL of the source. */ } PKT_ring_trust; + /* A plaintext packet (see RFC 4880, 5.9). */ typedef struct { /* The length of data in BUF or 0 if unknown. */ @@ -519,7 +544,6 @@ struct packet_struct { PKT_compressed *compressed; /* PKT_COMPRESSED */ PKT_encrypted *encrypted; /* PKT_ENCRYPTED[_MDC] */ PKT_mdc *mdc; /* PKT_MDC */ - PKT_ring_trust *ring_trust; /* PKT_RING_TRUST */ PKT_plaintext *plaintext; /* PKT_PLAINTEXT */ PKT_gpg_control *gpg_control; /* PKT_GPG_CONTROL */ } pkt; @@ -599,6 +623,7 @@ struct parse_packet_ctx_s iobuf_t inp; /* The input stream with the packets. */ PACKET *last_pkt; /* The last parsed packet. */ int free_last_pkt; /* Indicates that LAST_PKT must be freed. */ + int skip_meta; /* Skip right trust packets. */ }; typedef struct parse_packet_ctx_s *parse_packet_ctx_t; @@ -606,6 +631,7 @@ typedef struct parse_packet_ctx_s *parse_packet_ctx_t; (a)->inp = (i); \ (a)->last_pkt = NULL; \ (a)->free_last_pkt = 0; \ + (a)->skip_meta = 0; \ } while (0) #define deinit_parse_packet(a) do { \ @@ -786,7 +812,8 @@ PACKET *create_gpg_control ( ctrlpkttype_t type, size_t datalen ); /*-- build-packet.c --*/ -int build_packet( iobuf_t inp, PACKET *pkt ); +int build_packet (iobuf_t out, PACKET *pkt); +gpg_error_t build_packet_and_meta (iobuf_t out, PACKET *pkt); gpg_error_t gpg_mpi_write (iobuf_t out, gcry_mpi_t a); gpg_error_t gpg_mpi_write_nohdr (iobuf_t out, gcry_mpi_t a); u32 calc_packet_length( PACKET *pkt ); |