2 * keyindex.c - Routines to list an OpenPGP key.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002-2005 Project Purple
16 #include "decodekey.h"
22 #include "keystructs.h"
25 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 (sigs->packet->data[0] == 4 &&
35 sigs->packet->data[1] == 0x30) {
36 /* It's a Type 4 sig revocation */
41 if (html && uid != NULL) {
42 printf("%s <a href=\"lookup?op=get&"
43 "search=%016llX\">%08llX</a> "
44 "<a href=\"lookup?op=vindex&search=0x%016llX\">"
51 } else if (html && uid == NULL) {
53 "[User id not found]\n",
62 "[User id not found]");
74 int list_uids(uint64_t keyid, struct openpgp_signedpacket_list *uids,
75 bool verbose, bool html)
80 while (uids != NULL) {
81 if (uids->packet->tag == 13) {
82 snprintf(buf, 1023, "%.*s",
83 (int) uids->packet->length,
86 (html) ? txt2html(buf) : buf);
87 } else if (uids->packet->tag == 17) {
90 printf("<img src=\"lookup?op=photo&search=0x%llX&idx=%d\" alt=\"[photo id]\">\n",
95 printf("[photo id]\n");
99 list_sigs(uids->sigs, html);
107 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
110 struct tm *created = NULL;
111 time_t created_time = 0;
115 while (subkeys != NULL) {
116 if (subkeys->packet->tag == 14) {
118 created_time = (subkeys->packet->data[1] << 24) +
119 (subkeys->packet->data[2] << 16) +
120 (subkeys->packet->data[3] << 8) +
121 subkeys->packet->data[4];
122 created = gmtime(&created_time);
124 switch (subkeys->packet->data[0]) {
127 type = subkeys->packet->data[7];
128 length = (subkeys->packet->data[8] << 8) +
129 subkeys->packet->data[9];
132 type = subkeys->packet->data[5];
133 length = (subkeys->packet->data[6] << 8) +
134 subkeys->packet->data[7];
137 logthing(LOGTHING_ERROR,
138 "Unknown key type: %d",
139 subkeys->packet->data[0]);
142 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
144 (type == 1) ? 'R' : ((type == 16) ? 'g' :
145 ((type == 17) ? 'D' : '?')),
146 (uint32_t) (get_packetid(subkeys->packet) &
148 created->tm_year + 1900,
154 list_sigs(subkeys->sigs, html);
156 subkeys = subkeys->next;
162 void display_fingerprint(struct openpgp_publickey *key)
166 unsigned char fp[20];
168 get_fingerprint(key->publickey, fp, &length);
169 printf(" Key fingerprint =");
170 for (i = 0; i < length; i++) {
171 if ((length == 16) ||
175 printf("%02X", fp[i]);
176 if ((i * 2) == length) {
186 * key_index - List a set of OpenPGP keys.
187 * @keys: The keys to display.
188 * @verbose: Should we list sigs as well?
189 * @fingerprint: List the fingerprint?
190 * @html: Should the output be tailored for HTML?
192 * This function takes a list of OpenPGP public keys and displays an index
193 * of them. Useful for debugging or the keyserver Index function.
195 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
198 struct openpgp_signedpacket_list *curuid = NULL;
199 struct tm *created = NULL;
200 time_t created_time = 0;
209 puts("Type bits/keyID Date User ID");
210 while (keys != NULL) {
211 created_time = (keys->publickey->data[1] << 24) +
212 (keys->publickey->data[2] << 16) +
213 (keys->publickey->data[3] << 8) +
214 keys->publickey->data[4];
215 created = gmtime(&created_time);
217 switch (keys->publickey->data[0]) {
220 type = keys->publickey->data[7];
221 length = (keys->publickey->data[8] << 8) +
222 keys->publickey->data[9];
225 type = keys->publickey->data[5];
226 length = (keys->publickey->data[6] << 8) +
227 keys->publickey->data[7];
230 logthing(LOGTHING_ERROR, "Unknown key type: %d",
231 keys->publickey->data[0]);
234 keyid = get_keyid(keys);
237 printf("pub %5d%c/<a href=\"lookup?op=get&"
238 "search=%016llX\">%08llX</a> %04d/%02d/%02d ",
240 (type == 1) ? 'R' : ((type == 16) ? 'g' :
241 ((type == 17) ? 'D' : '?')),
244 created->tm_year + 1900,
248 printf("pub %5d%c/%08llX %04d/%02d/%02d ",
250 (type == 1) ? 'R' : ((type == 16) ? 'g' :
251 ((type == 17) ? 'D' : '?')),
253 created->tm_year + 1900,
259 if (curuid != NULL && curuid->packet->tag == 13) {
260 snprintf(buf, 1023, "%.*s",
261 (int) curuid->packet->length,
262 curuid->packet->data);
264 printf("<a href=\"lookup?op=vindex&"
265 "search=0x%016llX\">",
269 (html) ? txt2html(buf) : buf,
270 (html) ? "</a>" : "",
271 (keys->revoked) ? " *** REVOKED ***" : "");
273 display_fingerprint(keys);
276 list_sigs(curuid->sigs, html);
278 curuid = curuid->next;
281 (keys->revoked) ? "*** REVOKED ***": "");
283 display_fingerprint(keys);
287 list_uids(keyid, curuid, verbose, html);
289 list_subkeys(keys->subkeys, verbose, html);
303 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
304 * @keys: The keys to display.
306 * This function takes a list of OpenPGP public keys and displays a
307 * machine readable list of them.
309 int mrkey_index(struct openpgp_publickey *keys)
311 struct openpgp_signedpacket_list *curuid = NULL;
312 time_t created_time = 0;
317 unsigned char fp[20];
319 while (keys != NULL) {
320 created_time = (keys->publickey->data[1] << 24) +
321 (keys->publickey->data[2] << 16) +
322 (keys->publickey->data[3] << 8) +
323 keys->publickey->data[4];
327 switch (keys->publickey->data[0]) {
330 printf("%016llX", get_keyid(keys));
331 type = keys->publickey->data[7];
332 length = (keys->publickey->data[8] << 8) +
333 keys->publickey->data[9];
336 (void) get_fingerprint(keys->publickey, fp, &fplength);
338 for (i = 0; i < fplength; i++) {
339 printf("%02X", fp[i]);
342 type = keys->publickey->data[5];
343 length = (keys->publickey->data[6] << 8) +
344 keys->publickey->data[7];
347 logthing(LOGTHING_ERROR, "Unknown key type: %d",
348 keys->publickey->data[0]);
351 printf(":%d:%d:%ld::%s\n",
355 (keys->revoked) ? "r" : "");
357 for (curuid = keys->uids; curuid != NULL;
358 curuid = curuid->next) {
360 if (curuid->packet->tag == 13) {
362 (int) curuid->packet->length,
363 curuid->packet->data);