2 * keyindex.c - Routines to list an OpenPGP key.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "decodekey.h"
23 #include "keystructs.h"
26 int list_sigs(struct openpgp_packet_list *sigs, bool html)
31 while (sigs != NULL) {
32 sigid = sig_keyid(sigs->packet);
33 uid = keyid2uid(sigid);
34 if (html && uid != NULL) {
35 printf("sig <a href=\"lookup?op=get&"
36 "search=%08llX\">%08llX</a> "
37 "<a href=\"lookup?op=vindex&search=0x%08llX\">"
43 } else if (html && uid == NULL) {
45 "[User id not found]\n",
52 "[User id not found]");
64 int list_uids(uint64_t keyid, struct openpgp_signedpacket_list *uids,
65 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) {
80 printf("<img src=\"lookup?op=photo&search=0x%llX&idx=%d\" alt=\"[photo id]\">\n",
85 printf("[photo id]\n");
89 list_sigs(uids->sigs, html);
97 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
100 struct tm *created = NULL;
101 time_t created_time = 0;
105 while (subkeys != NULL) {
106 if (subkeys->packet->tag == 14) {
108 created_time = (subkeys->packet->data[1] << 24) +
109 (subkeys->packet->data[2] << 16) +
110 (subkeys->packet->data[3] << 8) +
111 subkeys->packet->data[4];
112 created = gmtime(&created_time);
114 switch (subkeys->packet->data[0]) {
117 type = subkeys->packet->data[7];
118 length = (subkeys->packet->data[8] << 8) +
119 subkeys->packet->data[9];
122 type = subkeys->packet->data[5];
123 length = (subkeys->packet->data[6] << 8) +
124 subkeys->packet->data[7];
127 logthing(LOGTHING_ERROR,
128 "Unknown key type: %d",
129 subkeys->packet->data[0]);
132 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
134 (type == 1) ? 'R' : ((type == 16) ? 'g' :
135 ((type == 17) ? 'D' : '?')),
136 (uint32_t) (get_packetid(subkeys->packet) &
138 created->tm_year + 1900,
144 list_sigs(subkeys->sigs, html);
146 subkeys = subkeys->next;
152 void display_fingerprint(struct openpgp_publickey *key)
156 unsigned char fp[20];
158 get_fingerprint(key->publickey, fp, &length);
159 printf(" Key fingerprint =");
160 for (i = 0; i < length; i++) {
161 if ((length == 16) ||
165 printf("%02X", fp[i]);
166 if ((i * 2) == length) {
176 * key_index - List a set of OpenPGP keys.
177 * @keys: The keys to display.
178 * @verbose: Should we list sigs as well?
179 * @fingerprint: List the fingerprint?
180 * @html: Should the output be tailored for HTML?
182 * This function takes a list of OpenPGP public keys and displays an index
183 * of them. Useful for debugging or the keyserver Index function.
185 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
188 struct openpgp_signedpacket_list *curuid = NULL;
189 struct tm *created = NULL;
190 time_t created_time = 0;
199 puts("Type bits/keyID Date User ID");
200 while (keys != NULL) {
201 created_time = (keys->publickey->data[1] << 24) +
202 (keys->publickey->data[2] << 16) +
203 (keys->publickey->data[3] << 8) +
204 keys->publickey->data[4];
205 created = gmtime(&created_time);
207 switch (keys->publickey->data[0]) {
210 type = keys->publickey->data[7];
211 length = (keys->publickey->data[8] << 8) +
212 keys->publickey->data[9];
215 type = keys->publickey->data[5];
216 length = (keys->publickey->data[6] << 8) +
217 keys->publickey->data[7];
220 logthing(LOGTHING_ERROR, "Unknown key type: %d",
221 keys->publickey->data[0]);
224 keyid = (get_keyid(keys) & 0xFFFFFFFF),
225 printf("pub %5d%c/%08X %04d/%02d/%02d ",
227 (type == 1) ? 'R' : ((type == 16) ? 'g' :
228 ((type == 17) ? 'D' : '?')),
230 created->tm_year + 1900,
235 if (curuid != NULL && curuid->packet->tag == 13) {
236 snprintf(buf, 1023, "%.*s",
237 (int) curuid->packet->length,
238 curuid->packet->data);
240 (html) ? txt2html(buf) : buf,
241 (keys->revocations == NULL) ? "" :
244 display_fingerprint(keys);
247 list_sigs(curuid->sigs, html);
249 curuid = curuid->next;
252 (keys->revocations == NULL) ? "" :
255 display_fingerprint(keys);
259 list_uids(keyid, curuid, verbose, html);
261 list_subkeys(keys->subkeys, verbose, html);
275 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
276 * @keys: The keys to display.
278 * This function takes a list of OpenPGP public keys and displays a
279 * machine readable list of them.
281 int mrkey_index(struct openpgp_publickey *keys)
283 struct openpgp_signedpacket_list *curuid = NULL;
284 time_t created_time = 0;
289 unsigned char fp[20];
291 while (keys != NULL) {
292 created_time = (keys->publickey->data[1] << 24) +
293 (keys->publickey->data[2] << 16) +
294 (keys->publickey->data[3] << 8) +
295 keys->publickey->data[4];
299 switch (keys->publickey->data[0]) {
302 printf("%016llX", get_keyid(keys));
303 type = keys->publickey->data[7];
304 length = (keys->publickey->data[8] << 8) +
305 keys->publickey->data[9];
308 (void) get_fingerprint(keys->publickey, fp, &fplength);
310 for (i = 0; i < fplength; i++) {
311 printf("%02X", fp[i]);
314 type = keys->publickey->data[5];
315 length = (keys->publickey->data[6] << 8) +
316 keys->publickey->data[7];
319 logthing(LOGTHING_ERROR, "Unknown key type: %d",
320 keys->publickey->data[0]);
323 printf(":%d:%d:%ld::%s\n",
327 (keys->revocations == NULL) ? "" : "r");
329 for (curuid = keys->uids; curuid != NULL;
330 curuid = curuid->next) {
332 if (curuid->packet->tag == 13) {
334 (int) curuid->packet->length,
335 curuid->packet->data);