]> the.earth.li Git - onak.git/blob - keystructs.h
Add ability to drop overly large packets
[onak.git] / keystructs.h
1 /**
2  * @file keystructs.h
3  * @brief Structures for OpenPGP keys
4  *
5  * Copyright 2002 Jonathan McDowell <noodles@earth.li>
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19
20 #ifndef __KEYSTRUCTS_H__
21 #define __KEYSTRUCTS_H__
22
23 #include <inttypes.h>
24 #include <stdbool.h>
25 #include <stdlib.h>
26
27 #include "ll.h"
28
29 /* v3 MD5 fingerprint is 16 characters, v4 SHA-1 fingerprint is 20 */
30 #define MAX_FINGERPRINT_LEN 20
31
32 /**
33  * @brief Stores the fingerprint of an OpenPGP key
34  */
35 struct openpgp_fingerprint {
36         /** Length of fingerprint. 16 bytes for v3, 20 for v4 */
37         size_t length;
38         /** Fingerprint data. Only the first length bytes are valid */
39         uint8_t fp[MAX_FINGERPRINT_LEN];
40 };
41
42 /**
43  * @brief Stores an OpenPGP packet.
44  *
45  * This structure holds any form of OpenPGP packet with minimum common
46  * details decoded out.
47  */
48 struct openpgp_packet {
49         /** The packet tag (i.e. type). */
50         unsigned int tag;
51         /** Indicates if this is a new format packet. */
52         bool newformat;
53         /** The length of the packet. */
54         size_t length;
55         /** The actual packet data. */
56         unsigned char *data;
57 };
58
59 /**
60  * @brief A linked list of OpenPGP packets.
61  *
62  * This structure is used to hold a linked list of packets, for example
63  * all the signatures of a public key's UID.
64  */
65 struct openpgp_packet_list {
66         /** The actual packet structure. */
67         struct openpgp_packet *packet;
68         /** A pointer to the next packet in the list. */
69         struct openpgp_packet_list *next;
70 };
71
72 /**
73  * @brief A packet with signatures.
74  *
75  * This structure holds an OpenPGP packet along with signatures that are
76  * over this packet. It also links to the next signed packet. It's usually
77  * used to hold a UID or subkey with their associated signatures.
78  */
79 struct openpgp_signedpacket_list {
80         /** The OpenPGP packet that's signed. */
81         struct openpgp_packet *packet;
82         /** A linked list of sigs for the packet. */
83         struct openpgp_packet_list *sigs;
84         /** Pointer to the last sig in the sigs linked list */
85         struct openpgp_packet_list *last_sig;
86         /** A pointer to the next packet with signatures. */
87         struct openpgp_signedpacket_list *next;
88 };
89
90 /**
91  * @brief An OpenPGP public key complete with sigs.
92  */
93 struct openpgp_publickey {
94         /** The OpenPGP packet for the public key. */
95         struct openpgp_packet                   *publickey;
96         /** True if the key is revoked. */
97         bool                                     revoked;
98         /** Any signatures directly on the @a publickey packet. */
99         struct openpgp_packet_list              *sigs;
100         /** Pointer to the end of the @a sigs list */
101         struct openpgp_packet_list              *last_sig;
102         /** The list of UIDs with signatures for this key. */
103         struct openpgp_signedpacket_list        *uids;
104         /** Pointer to the end of the @a uids list */
105         struct openpgp_signedpacket_list        *last_uid;
106         /** The list of subkeys with signatures for this key. */
107         struct openpgp_signedpacket_list        *subkeys;
108         /** Pointer to the end of the @a subkey list */
109         struct openpgp_signedpacket_list        *last_subkey;
110         /** The next public key. */
111         struct openpgp_publickey                *next;
112 };
113
114 /**
115  * @brief Holds an SKS key hash (md5 over sorted packet list)
116  */
117 struct skshash {
118         /** The 128 bit MD5 hash of the sorted packet list from the key */
119         uint8_t hash[16];
120 };
121
122 #endif /* __KEYSTRUCTS_H__ */