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"
24 #include "onak-conf.h"
26 int list_sigs(struct openpgp_packet_list *sigs, bool html)
32 while (sigs != NULL) {
33 sigid = sig_keyid(sigs->packet);
34 uid = config.dbbackend->keyid2uid(sigid);
35 if (sigs->packet->data[0] == 4 &&
36 sigs->packet->data[1] == 0x30) {
37 /* It's a Type 4 sig revocation */
42 if (html && uid != NULL) {
43 printf("%s <a href=\"lookup?op=get&"
44 "search=%016" PRIX64 "\">%08" PRIX64
46 "<a href=\"lookup?op=vindex&search=0x%016"
53 } else if (html && uid == NULL) {
54 printf("%s %08" PRIX64 " "
55 "[User id not found]\n",
59 printf("%s %08" PRIX64
64 "[User id not found]");
76 int list_uids(uint64_t keyid, struct openpgp_signedpacket_list *uids,
77 bool verbose, bool html)
82 while (uids != NULL) {
83 if (uids->packet->tag == 13) {
84 snprintf(buf, 1023, "%.*s",
85 (int) uids->packet->length,
88 (html) ? txt2html(buf) : buf);
89 } else if (uids->packet->tag == 17) {
92 printf("<img src=\"lookup?op=photo&search=0x%"
93 PRIX64 "&idx=%d\" alt=\"[photo id]\">"
99 printf("[photo id]\n");
103 list_sigs(uids->sigs, html);
111 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
114 struct tm *created = NULL;
115 time_t created_time = 0;
119 while (subkeys != NULL) {
120 if (subkeys->packet->tag == 14) {
122 created_time = (subkeys->packet->data[1] << 24) +
123 (subkeys->packet->data[2] << 16) +
124 (subkeys->packet->data[3] << 8) +
125 subkeys->packet->data[4];
126 created = gmtime(&created_time);
128 switch (subkeys->packet->data[0]) {
131 type = subkeys->packet->data[7];
132 length = (subkeys->packet->data[8] << 8) +
133 subkeys->packet->data[9];
136 type = subkeys->packet->data[5];
137 length = (subkeys->packet->data[6] << 8) +
138 subkeys->packet->data[7];
141 logthing(LOGTHING_ERROR,
142 "Unknown key type: %d",
143 subkeys->packet->data[0]);
146 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
148 (type == 1) ? 'R' : ((type == 16) ? 'g' :
149 ((type == 17) ? 'D' : '?')),
150 (uint32_t) (get_packetid(subkeys->packet) &
152 created->tm_year + 1900,
158 list_sigs(subkeys->sigs, html);
160 subkeys = subkeys->next;
166 void display_fingerprint(struct openpgp_publickey *key)
170 unsigned char fp[20];
172 get_fingerprint(key->publickey, fp, &length);
173 printf(" Key fingerprint =");
174 for (i = 0; i < length; i++) {
175 if ((length == 16) ||
179 printf("%02X", fp[i]);
180 if ((i * 2) == length) {
190 * key_index - List a set of OpenPGP keys.
191 * @keys: The keys to display.
192 * @verbose: Should we list sigs as well?
193 * @fingerprint: List the fingerprint?
194 * @html: Should the output be tailored for HTML?
196 * This function takes a list of OpenPGP public keys and displays an index
197 * of them. Useful for debugging or the keyserver Index function.
199 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
202 struct openpgp_signedpacket_list *curuid = NULL;
203 struct tm *created = NULL;
204 time_t created_time = 0;
213 puts("Type bits/keyID Date User ID");
214 while (keys != NULL) {
215 created_time = (keys->publickey->data[1] << 24) +
216 (keys->publickey->data[2] << 16) +
217 (keys->publickey->data[3] << 8) +
218 keys->publickey->data[4];
219 created = gmtime(&created_time);
221 switch (keys->publickey->data[0]) {
224 type = keys->publickey->data[7];
225 length = (keys->publickey->data[8] << 8) +
226 keys->publickey->data[9];
229 type = keys->publickey->data[5];
230 length = (keys->publickey->data[6] << 8) +
231 keys->publickey->data[7];
234 logthing(LOGTHING_ERROR, "Unknown key type: %d",
235 keys->publickey->data[0]);
238 keyid = get_keyid(keys);
241 printf("pub %5d%c/<a href=\"lookup?op=get&"
242 "search=%016" PRIX64 "\">%08" PRIX64
243 "</a> %04d/%02d/%02d ",
245 (type == 1) ? 'R' : ((type == 16) ? 'g' :
246 ((type == 17) ? 'D' : '?')),
249 created->tm_year + 1900,
253 printf("pub %5d%c/%08" PRIX64 " %04d/%02d/%02d ",
255 (type == 1) ? 'R' : ((type == 16) ? 'g' :
256 ((type == 17) ? 'D' : '?')),
258 created->tm_year + 1900,
264 if (curuid != NULL && curuid->packet->tag == 13) {
265 snprintf(buf, 1023, "%.*s",
266 (int) curuid->packet->length,
267 curuid->packet->data);
269 printf("<a href=\"lookup?op=vindex&"
270 "search=0x%016" PRIX64 "\">",
274 (html) ? txt2html(buf) : buf,
275 (html) ? "</a>" : "",
276 (keys->revoked) ? " *** REVOKED ***" : "");
278 display_fingerprint(keys);
281 list_sigs(curuid->sigs, html);
283 curuid = curuid->next;
286 (keys->revoked) ? "*** REVOKED ***": "");
288 display_fingerprint(keys);
292 list_uids(keyid, curuid, verbose, html);
294 list_subkeys(keys->subkeys, verbose, html);
308 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
309 * @keys: The keys to display.
311 * This function takes a list of OpenPGP public keys and displays a
312 * machine readable list of them.
314 int mrkey_index(struct openpgp_publickey *keys)
316 struct openpgp_signedpacket_list *curuid = NULL;
317 time_t created_time = 0;
322 unsigned char fp[20];
324 while (keys != NULL) {
325 created_time = (keys->publickey->data[1] << 24) +
326 (keys->publickey->data[2] << 16) +
327 (keys->publickey->data[3] << 8) +
328 keys->publickey->data[4];
332 switch (keys->publickey->data[0]) {
335 printf("%016" PRIX64, get_keyid(keys));
336 type = keys->publickey->data[7];
337 length = (keys->publickey->data[8] << 8) +
338 keys->publickey->data[9];
341 (void) get_fingerprint(keys->publickey, fp, &fplength);
343 for (i = 0; i < fplength; i++) {
344 printf("%02X", fp[i]);
347 type = keys->publickey->data[5];
348 length = (keys->publickey->data[6] << 8) +
349 keys->publickey->data[7];
352 logthing(LOGTHING_ERROR, "Unknown key type: %d",
353 keys->publickey->data[0]);
356 printf(":%d:%d:%ld::%s\n",
360 (keys->revoked) ? "r" : "");
362 for (curuid = keys->uids; curuid != NULL;
363 curuid = curuid->next) {
365 if (curuid->packet->tag == 13) {
367 (int) curuid->packet->length,
368 curuid->packet->data);