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=%016llX\">%08llX</a> "
45 "<a href=\"lookup?op=vindex&search=0x%016llX\">"
52 } else if (html && uid == NULL) {
54 "[User id not found]\n",
63 "[User id not found]");
75 int list_uids(uint64_t keyid, struct openpgp_signedpacket_list *uids,
76 bool verbose, bool html)
81 while (uids != NULL) {
82 if (uids->packet->tag == 13) {
83 snprintf(buf, 1023, "%.*s",
84 (int) uids->packet->length,
87 (html) ? txt2html(buf) : buf);
88 } else if (uids->packet->tag == 17) {
91 printf("<img src=\"lookup?op=photo&search=0x%llX&idx=%d\" alt=\"[photo id]\">\n",
96 printf("[photo id]\n");
100 list_sigs(uids->sigs, html);
108 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
111 struct tm *created = NULL;
112 time_t created_time = 0;
116 while (subkeys != NULL) {
117 if (subkeys->packet->tag == 14) {
119 created_time = (subkeys->packet->data[1] << 24) +
120 (subkeys->packet->data[2] << 16) +
121 (subkeys->packet->data[3] << 8) +
122 subkeys->packet->data[4];
123 created = gmtime(&created_time);
125 switch (subkeys->packet->data[0]) {
128 type = subkeys->packet->data[7];
129 length = (subkeys->packet->data[8] << 8) +
130 subkeys->packet->data[9];
133 type = subkeys->packet->data[5];
134 length = (subkeys->packet->data[6] << 8) +
135 subkeys->packet->data[7];
138 logthing(LOGTHING_ERROR,
139 "Unknown key type: %d",
140 subkeys->packet->data[0]);
143 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
145 (type == 1) ? 'R' : ((type == 16) ? 'g' :
146 ((type == 17) ? 'D' : '?')),
147 (uint32_t) (get_packetid(subkeys->packet) &
149 created->tm_year + 1900,
155 list_sigs(subkeys->sigs, html);
157 subkeys = subkeys->next;
163 void display_fingerprint(struct openpgp_publickey *key)
167 unsigned char fp[20];
169 get_fingerprint(key->publickey, fp, &length);
170 printf(" Key fingerprint =");
171 for (i = 0; i < length; i++) {
172 if ((length == 16) ||
176 printf("%02X", fp[i]);
177 if ((i * 2) == length) {
187 * key_index - List a set of OpenPGP keys.
188 * @keys: The keys to display.
189 * @verbose: Should we list sigs as well?
190 * @fingerprint: List the fingerprint?
191 * @html: Should the output be tailored for HTML?
193 * This function takes a list of OpenPGP public keys and displays an index
194 * of them. Useful for debugging or the keyserver Index function.
196 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
199 struct openpgp_signedpacket_list *curuid = NULL;
200 struct tm *created = NULL;
201 time_t created_time = 0;
210 puts("Type bits/keyID Date User ID");
211 while (keys != NULL) {
212 created_time = (keys->publickey->data[1] << 24) +
213 (keys->publickey->data[2] << 16) +
214 (keys->publickey->data[3] << 8) +
215 keys->publickey->data[4];
216 created = gmtime(&created_time);
218 switch (keys->publickey->data[0]) {
221 type = keys->publickey->data[7];
222 length = (keys->publickey->data[8] << 8) +
223 keys->publickey->data[9];
226 type = keys->publickey->data[5];
227 length = (keys->publickey->data[6] << 8) +
228 keys->publickey->data[7];
231 logthing(LOGTHING_ERROR, "Unknown key type: %d",
232 keys->publickey->data[0]);
235 keyid = get_keyid(keys);
238 printf("pub %5d%c/<a href=\"lookup?op=get&"
239 "search=%016llX\">%08llX</a> %04d/%02d/%02d ",
241 (type == 1) ? 'R' : ((type == 16) ? 'g' :
242 ((type == 17) ? 'D' : '?')),
245 created->tm_year + 1900,
249 printf("pub %5d%c/%08llX %04d/%02d/%02d ",
251 (type == 1) ? 'R' : ((type == 16) ? 'g' :
252 ((type == 17) ? 'D' : '?')),
254 created->tm_year + 1900,
260 if (curuid != NULL && curuid->packet->tag == 13) {
261 snprintf(buf, 1023, "%.*s",
262 (int) curuid->packet->length,
263 curuid->packet->data);
265 printf("<a href=\"lookup?op=vindex&"
266 "search=0x%016llX\">",
270 (html) ? txt2html(buf) : buf,
271 (html) ? "</a>" : "",
272 (keys->revoked) ? " *** REVOKED ***" : "");
274 display_fingerprint(keys);
277 list_sigs(curuid->sigs, html);
279 curuid = curuid->next;
282 (keys->revoked) ? "*** REVOKED ***": "");
284 display_fingerprint(keys);
288 list_uids(keyid, curuid, verbose, html);
290 list_subkeys(keys->subkeys, verbose, html);
304 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
305 * @keys: The keys to display.
307 * This function takes a list of OpenPGP public keys and displays a
308 * machine readable list of them.
310 int mrkey_index(struct openpgp_publickey *keys)
312 struct openpgp_signedpacket_list *curuid = NULL;
313 time_t created_time = 0;
318 unsigned char fp[20];
320 while (keys != NULL) {
321 created_time = (keys->publickey->data[1] << 24) +
322 (keys->publickey->data[2] << 16) +
323 (keys->publickey->data[3] << 8) +
324 keys->publickey->data[4];
328 switch (keys->publickey->data[0]) {
331 printf("%016llX", get_keyid(keys));
332 type = keys->publickey->data[7];
333 length = (keys->publickey->data[8] << 8) +
334 keys->publickey->data[9];
337 (void) get_fingerprint(keys->publickey, fp, &fplength);
339 for (i = 0; i < fplength; i++) {
340 printf("%02X", fp[i]);
343 type = keys->publickey->data[5];
344 length = (keys->publickey->data[6] << 8) +
345 keys->publickey->data[7];
348 logthing(LOGTHING_ERROR, "Unknown key type: %d",
349 keys->publickey->data[0]);
352 printf(":%d:%d:%ld::%s\n",
356 (keys->revoked) ? "r" : "");
358 for (curuid = keys->uids; curuid != NULL;
359 curuid = curuid->next) {
361 if (curuid->packet->tag == 13) {
363 (int) curuid->packet->length,
364 curuid->packet->data);