2 * keyindex.c - Routines to list an OpenPGP key.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
16 #include "decodekey.h"
22 #include "keystructs.h"
25 int list_sigs(struct openpgp_packet_list *sigs, bool html)
30 while (sigs != NULL) {
31 sigid = sig_keyid(sigs->packet);
32 uid = keyid2uid(sigid);
33 if (html && uid != NULL) {
34 printf("sig <a href=\"lookup?op=get&"
35 "search=%08llX\">%08llX</a> "
36 "<a href=\"lookup?op=vindex&search=0x%08llX\">"
42 } else if (html && uid == NULL) {
44 "[User id not found]\n",
51 "[User id not found]");
63 int list_uids(uint64_t keyid, struct openpgp_signedpacket_list *uids,
64 bool verbose, bool html)
69 while (uids != NULL) {
70 if (uids->packet->tag == 13) {
71 snprintf(buf, 1023, "%.*s",
72 (int) uids->packet->length,
75 (html) ? txt2html(buf) : buf);
76 } else if (uids->packet->tag == 17) {
79 printf("<img src=\"lookup?op=photo&search=0x%llX&idx=%d\" alt=\"[photo id]\">\n",
84 printf("[photo id]\n");
88 list_sigs(uids->sigs, html);
96 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
99 struct tm *created = NULL;
100 time_t created_time = 0;
104 while (subkeys != NULL) {
105 if (subkeys->packet->tag == 14) {
107 created_time = (subkeys->packet->data[1] << 24) +
108 (subkeys->packet->data[2] << 16) +
109 (subkeys->packet->data[3] << 8) +
110 subkeys->packet->data[4];
111 created = gmtime(&created_time);
113 switch (subkeys->packet->data[0]) {
116 type = subkeys->packet->data[7];
117 length = (subkeys->packet->data[8] << 8) +
118 subkeys->packet->data[9];
121 type = subkeys->packet->data[5];
122 length = (subkeys->packet->data[6] << 8) +
123 subkeys->packet->data[7];
126 logthing(LOGTHING_ERROR,
127 "Unknown key type: %d",
128 subkeys->packet->data[0]);
131 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
133 (type == 1) ? 'R' : ((type == 16) ? 'g' :
134 ((type == 17) ? 'D' : '?')),
135 (uint32_t) (get_packetid(subkeys->packet) &
137 created->tm_year + 1900,
143 list_sigs(subkeys->sigs, html);
145 subkeys = subkeys->next;
151 void display_fingerprint(struct openpgp_publickey *key)
155 unsigned char fp[20];
157 get_fingerprint(key->publickey, fp, &length);
158 printf(" Key fingerprint =");
159 for (i = 0; i < length; i++) {
160 if ((length == 16) ||
164 printf("%02X", fp[i]);
165 if ((i * 2) == length) {
175 * key_index - List a set of OpenPGP keys.
176 * @keys: The keys to display.
177 * @verbose: Should we list sigs as well?
178 * @fingerprint: List the fingerprint?
179 * @html: Should the output be tailored for HTML?
181 * This function takes a list of OpenPGP public keys and displays an index
182 * of them. Useful for debugging or the keyserver Index function.
184 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
187 struct openpgp_signedpacket_list *curuid = NULL;
188 struct tm *created = NULL;
189 time_t created_time = 0;
198 puts("Type bits/keyID Date User ID");
199 while (keys != NULL) {
200 created_time = (keys->publickey->data[1] << 24) +
201 (keys->publickey->data[2] << 16) +
202 (keys->publickey->data[3] << 8) +
203 keys->publickey->data[4];
204 created = gmtime(&created_time);
206 switch (keys->publickey->data[0]) {
209 type = keys->publickey->data[7];
210 length = (keys->publickey->data[8] << 8) +
211 keys->publickey->data[9];
214 type = keys->publickey->data[5];
215 length = (keys->publickey->data[6] << 8) +
216 keys->publickey->data[7];
219 logthing(LOGTHING_ERROR, "Unknown key type: %d",
220 keys->publickey->data[0]);
223 keyid = (get_keyid(keys) & 0xFFFFFFFF);
226 printf("pub %5d%c/<a href=\"lookup?op=get&"
227 "search=%08X\">%08X</a> %04d/%02d/%02d ",
229 (type == 1) ? 'R' : ((type == 16) ? 'g' :
230 ((type == 17) ? 'D' : '?')),
233 created->tm_year + 1900,
237 printf("pub %5d%c/%08X %04d/%02d/%02d ",
239 (type == 1) ? 'R' : ((type == 16) ? 'g' :
240 ((type == 17) ? 'D' : '?')),
242 created->tm_year + 1900,
248 if (curuid != NULL && curuid->packet->tag == 13) {
249 snprintf(buf, 1023, "%.*s",
250 (int) curuid->packet->length,
251 curuid->packet->data);
253 printf("<a href=\"lookup?op=vindex&"
258 (html) ? txt2html(buf) : buf,
259 (html) ? "</a>" : "",
260 (keys->revocations == NULL) ? "" :
263 display_fingerprint(keys);
266 list_sigs(curuid->sigs, html);
268 curuid = curuid->next;
271 (keys->revocations == NULL) ? "" :
274 display_fingerprint(keys);
278 list_uids(keyid, curuid, verbose, html);
280 list_subkeys(keys->subkeys, verbose, html);
294 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
295 * @keys: The keys to display.
297 * This function takes a list of OpenPGP public keys and displays a
298 * machine readable list of them.
300 int mrkey_index(struct openpgp_publickey *keys)
302 struct openpgp_signedpacket_list *curuid = NULL;
303 time_t created_time = 0;
308 unsigned char fp[20];
310 while (keys != NULL) {
311 created_time = (keys->publickey->data[1] << 24) +
312 (keys->publickey->data[2] << 16) +
313 (keys->publickey->data[3] << 8) +
314 keys->publickey->data[4];
318 switch (keys->publickey->data[0]) {
321 printf("%016llX", get_keyid(keys));
322 type = keys->publickey->data[7];
323 length = (keys->publickey->data[8] << 8) +
324 keys->publickey->data[9];
327 (void) get_fingerprint(keys->publickey, fp, &fplength);
329 for (i = 0; i < fplength; i++) {
330 printf("%02X", fp[i]);
333 type = keys->publickey->data[5];
334 length = (keys->publickey->data[6] << 8) +
335 keys->publickey->data[7];
338 logthing(LOGTHING_ERROR, "Unknown key type: %d",
339 keys->publickey->data[0]);
342 printf(":%d:%d:%ld::%s\n",
346 (keys->revocations == NULL) ? "" : "r");
348 for (curuid = keys->uids; curuid != NULL;
349 curuid = curuid->next) {
351 if (curuid->packet->tag == 13) {
353 (int) curuid->packet->length,
354 curuid->packet->data);