2 * keyindex.c - Routines to list an OpenPGP key.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: keyindex.c,v 1.10 2003/06/04 22:11:40 noodles Exp $
19 #include "decodekey.h"
25 #include "keystructs.h"
28 int list_sigs(struct openpgp_packet_list *sigs, bool html)
33 while (sigs != NULL) {
34 sigid = sig_keyid(sigs->packet);
35 uid = keyid2uid(sigid);
36 if (html && uid != NULL) {
37 printf("sig <a href=\"lookup?op=get&"
38 "search=%08llX\">%08llX</a> "
39 "<a href=\"lookup?op=vindex&search=0x%08llX\">"
45 } else if (html && uid == NULL) {
47 "[User id not found]\n",
54 "[User id not found]");
66 int list_uids(struct openpgp_signedpacket_list *uids, bool verbose, bool html)
70 while (uids != NULL) {
71 if (uids->packet->tag == 13) {
72 snprintf(buf, 1023, "%.*s",
73 (int) uids->packet->length,
76 (html) ? txt2html(buf) : buf);
77 } else if (uids->packet->tag == 17) {
82 list_sigs(uids->sigs, html);
90 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
93 struct tm *created = NULL;
94 time_t created_time = 0;
98 while (subkeys != NULL) {
99 if (subkeys->packet->tag == 14) {
101 created_time = (subkeys->packet->data[1] << 24) +
102 (subkeys->packet->data[2] << 16) +
103 (subkeys->packet->data[3] << 8) +
104 subkeys->packet->data[4];
105 created = gmtime(&created_time);
107 switch (subkeys->packet->data[0]) {
110 type = subkeys->packet->data[7];
111 length = (subkeys->packet->data[8] << 8) +
112 subkeys->packet->data[9];
115 type = subkeys->packet->data[5];
116 length = (subkeys->packet->data[6] << 8) +
117 subkeys->packet->data[7];
120 logthing(LOGTHING_ERROR,
121 "Unknown key type: %d",
122 subkeys->packet->data[0]);
125 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
127 (type == 1) ? 'R' : ((type == 16) ? 'g' :
128 ((type == 17) ? 'D' : '?')),
129 (uint32_t) (get_packetid(subkeys->packet) &
131 created->tm_year + 1900,
137 list_sigs(subkeys->sigs, html);
139 subkeys = subkeys->next;
145 void display_fingerprint(struct openpgp_publickey *key)
149 unsigned char fp[20];
151 get_fingerprint(key->publickey, fp, &length);
152 printf(" Key fingerprint =");
153 for (i = 0; i < length; i++) {
154 if ((length == 16) ||
158 printf("%02X", fp[i]);
159 if ((i * 2) == length) {
169 * key_index - List a set of OpenPGP keys.
170 * @keys: The keys to display.
171 * @verbose: Should we list sigs as well?
172 * @fingerprint: List the fingerprint?
173 * @html: Should the output be tailored for HTML?
175 * This function takes a list of OpenPGP public keys and displays an index
176 * of them. Useful for debugging or the keyserver Index function.
178 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
181 struct openpgp_signedpacket_list *curuid = NULL;
182 struct tm *created = NULL;
183 time_t created_time = 0;
191 puts("Type bits/keyID Date User ID");
192 while (keys != NULL) {
193 created_time = (keys->publickey->data[1] << 24) +
194 (keys->publickey->data[2] << 16) +
195 (keys->publickey->data[3] << 8) +
196 keys->publickey->data[4];
197 created = gmtime(&created_time);
199 switch (keys->publickey->data[0]) {
202 type = keys->publickey->data[7];
203 length = (keys->publickey->data[8] << 8) +
204 keys->publickey->data[9];
207 type = keys->publickey->data[5];
208 length = (keys->publickey->data[6] << 8) +
209 keys->publickey->data[7];
212 logthing(LOGTHING_ERROR, "Unknown key type: %d",
213 keys->publickey->data[0]);
216 printf("pub %5d%c/%08X %04d/%02d/%02d ",
218 (type == 1) ? 'R' : ((type == 16) ? 'g' :
219 ((type == 17) ? 'D' : '?')),
220 (uint32_t) (get_keyid(keys) & 0xFFFFFFFF),
221 created->tm_year + 1900,
226 if (curuid != NULL && curuid->packet->tag == 13) {
227 snprintf(buf, 1023, "%.*s",
228 (int) curuid->packet->length,
229 curuid->packet->data);
230 printf("%s\n", (html) ? txt2html(buf) : buf);
232 display_fingerprint(keys);
235 list_sigs(curuid->sigs, html);
237 curuid = curuid->next;
241 display_fingerprint(keys);
245 list_uids(curuid, verbose, html);
246 list_subkeys(keys->subkeys, verbose, html);
259 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
260 * @keys: The keys to display.
262 * This function takes a list of OpenPGP public keys and displays a
263 * machine readable list of them.
265 int mrkey_index(struct openpgp_publickey *keys)
267 struct openpgp_signedpacket_list *curuid = NULL;
268 time_t created_time = 0;
273 unsigned char fp[20];
277 while (keys != NULL) {
278 created_time = (keys->publickey->data[1] << 24) +
279 (keys->publickey->data[2] << 16) +
280 (keys->publickey->data[3] << 8) +
281 keys->publickey->data[4];
285 switch (keys->publickey->data[0]) {
288 printf("%016llX", get_keyid(keys));
289 type = keys->publickey->data[7];
290 length = (keys->publickey->data[8] << 8) +
291 keys->publickey->data[9];
294 get_fingerprint(keys->publickey, fp, &fplength);
296 for (i = 0; i < fplength; i++) {
297 printf("%02X", fp[i]);
300 type = keys->publickey->data[5];
301 length = (keys->publickey->data[6] << 8) +
302 keys->publickey->data[7];
305 logthing(LOGTHING_ERROR, "Unknown key type: %d",
306 keys->publickey->data[0]);
309 printf(":%d:%d:%d::\n",
314 for (curuid = keys->uids; curuid != NULL;
315 curuid = curuid->next) {
317 if (curuid->packet->tag == 13) {
319 (int) curuid->packet->length,
320 curuid->packet->data);