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->revocations == NULL) ? "" :
274 display_fingerprint(keys);
277 list_sigs(curuid->sigs, html);
279 curuid = curuid->next;
282 (keys->revocations == NULL) ? "" :
285 display_fingerprint(keys);
289 list_uids(keyid, curuid, verbose, html);
291 list_subkeys(keys->subkeys, verbose, html);
305 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
306 * @keys: The keys to display.
308 * This function takes a list of OpenPGP public keys and displays a
309 * machine readable list of them.
311 int mrkey_index(struct openpgp_publickey *keys)
313 struct openpgp_signedpacket_list *curuid = NULL;
314 time_t created_time = 0;
319 unsigned char fp[20];
321 while (keys != NULL) {
322 created_time = (keys->publickey->data[1] << 24) +
323 (keys->publickey->data[2] << 16) +
324 (keys->publickey->data[3] << 8) +
325 keys->publickey->data[4];
329 switch (keys->publickey->data[0]) {
332 printf("%016llX", get_keyid(keys));
333 type = keys->publickey->data[7];
334 length = (keys->publickey->data[8] << 8) +
335 keys->publickey->data[9];
338 (void) get_fingerprint(keys->publickey, fp, &fplength);
340 for (i = 0; i < fplength; i++) {
341 printf("%02X", fp[i]);
344 type = keys->publickey->data[5];
345 length = (keys->publickey->data[6] << 8) +
346 keys->publickey->data[7];
349 logthing(LOGTHING_ERROR, "Unknown key type: %d",
350 keys->publickey->data[0]);
353 printf(":%d:%d:%ld::%s\n",
357 (keys->revocations == NULL) ? "" : "r");
359 for (curuid = keys->uids; curuid != NULL;
360 curuid = curuid->next) {
362 if (curuid->packet->tag == 13) {
364 (int) curuid->packet->length,
365 curuid->packet->data);