PostgreSQL Source Code: contrib/pgcrypto/pgp-info.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
32
35#include "px.h"
36
37static int
39{
40 int res;
42
44 if (res < 0)
46
47
49 if (res < 0)
51
52
53 switch (pk->algo)
54 {
58 memcpy(keyid_buf, pk->key_id, 8);
59 res = 1;
60 break;
61 default:
62 res = 0;
63 }
64
67 return res;
68}
69
70static int
72{
74 int res;
75
77 if (ver != 3)
78 return -1;
79
81 if (res < 0)
82 return res;
83
85}
86
87static const char hextbl[] = "0123456789ABCDEF";
88
89static int
91{
92 int i;
93 unsigned c;
94
96 {
98 *dst++ = hextbl[(c >> 4) & 0x0F];
100 }
101 *dst = 0;
102 return 8 * 2;
103}
104
106{0, 0, 0, 0, 0, 0, 0, 0};
107
108
109
110
111int
113{
114 int res;
119 int got_pub_key = 0,
120 got_symenc_key = 0,
121 got_pubenc_key = 0;
122 int got_data = 0;
123 uint8 keyid_buf[8];
124 int got_main_key = 0;
125
126
128 if (res < 0)
129 return res;
130
131 while (1)
132 {
134 if (res <= 0)
135 break;
137 if (res < 0)
138 break;
139
140 switch (tag)
141 {
144
145 if (!got_main_key)
146 {
147 got_main_key = 1;
149 }
150 else
152 break;
156 if (res < 0)
157 break;
158 if (res > 0)
159 got_pub_key++;
160 break;
162 got_pubenc_key++;
164 break;
167
168 got_data = 1;
169 break;
171 got_symenc_key++;
172
180 break;
181 default:
183 }
184
185 if (pkt)
187 pkt = NULL;
188
189 if (res < 0 || got_data)
190 break;
191 }
192
194 if (pkt)
196
197 if (res < 0)
198 return res;
199
200
201 if (got_pub_key && got_pubenc_key)
203
204 if (got_pub_key > 1)
206
207 if (got_pubenc_key > 1)
209
210
211
212
213 if (res >= 0)
214 {
215 if (got_pubenc_key || got_pub_key)
216 {
217 if (memcmp(keyid_buf, any_key, 8) == 0)
218 {
219 memcpy(dst, "ANYKEY", 7);
220 res = 6;
221 }
222 else
224 }
225 else if (got_symenc_key)
226 {
227 memcpy(dst, "SYMKEY", 7);
228 res = 6;
229 }
230 else
232 }
233
234 return res;
235}
void err(int eval, const char *fmt,...)
int pullf_read_fixed(PullFilter *src, int len, uint8 *dst)
int pullf_create_mbuf_reader(PullFilter **mp_p, MBuf *src)
void pullf_free(PullFilter *pf)
int pgp_parse_pkt_hdr(PullFilter *src, uint8 *tag, int *len_p, int allow_ctx)
int pgp_skip_packet(PullFilter *pkt)
int pgp_create_pkt_reader(PullFilter **pf_p, PullFilter *src, int len, int pkttype, PGP_Context *ctx)
static const uint8 any_key[]
static int read_pubkey_keyid(PullFilter *pkt, uint8 *keyid_buf)
static const char hextbl[]
static int print_key(uint8 *keyid, char *dst)
static int read_pubenc_keyid(PullFilter *pkt, uint8 *keyid_buf)
int pgp_get_keyid(MBuf *pgp_data, char *dst)
void pgp_key_free(PGP_PubKey *pk)
int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p)
@ PGP_PKT_SYMENCRYPTED_DATA
@ PGP_PKT_SYMENCRYPTED_SESSKEY
@ PGP_PKT_SYMENCRYPTED_DATA_MDC
@ PGP_PKT_PUBENCRYPTED_SESSKEY
@ PGP_PUB_RSA_ENCRYPT_SIGN
#define PXE_PGP_MULTIPLE_KEYS
#define PXE_PGP_NO_USABLE_KEY
#define PXE_PGP_CORRUPT_DATA