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);
224 printf("pub %5d%c/%08X %04d/%02d/%02d ",
226 (type == 1) ? 'R' : ((type == 16) ? 'g' :
227 ((type == 17) ? 'D' : '?')),
229 created->tm_year + 1900,
234 if (curuid != NULL && curuid->packet->tag == 13) {
235 snprintf(buf, 1023, "%.*s",
236 (int) curuid->packet->length,
237 curuid->packet->data);
239 (html) ? txt2html(buf) : buf,
240 (keys->revocations == NULL) ? "" :
243 display_fingerprint(keys);
246 list_sigs(curuid->sigs, html);
248 curuid = curuid->next;
251 (keys->revocations == NULL) ? "" :
254 display_fingerprint(keys);
258 list_uids(keyid, curuid, verbose, html);
260 list_subkeys(keys->subkeys, verbose, html);
274 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
275 * @keys: The keys to display.
277 * This function takes a list of OpenPGP public keys and displays a
278 * machine readable list of them.
280 int mrkey_index(struct openpgp_publickey *keys)
282 struct openpgp_signedpacket_list *curuid = NULL;
283 time_t created_time = 0;
288 unsigned char fp[20];
290 while (keys != NULL) {
291 created_time = (keys->publickey->data[1] << 24) +
292 (keys->publickey->data[2] << 16) +
293 (keys->publickey->data[3] << 8) +
294 keys->publickey->data[4];
298 switch (keys->publickey->data[0]) {
301 printf("%016llX", get_keyid(keys));
302 type = keys->publickey->data[7];
303 length = (keys->publickey->data[8] << 8) +
304 keys->publickey->data[9];
307 (void) get_fingerprint(keys->publickey, fp, &fplength);
309 for (i = 0; i < fplength; i++) {
310 printf("%02X", fp[i]);
313 type = keys->publickey->data[5];
314 length = (keys->publickey->data[6] << 8) +
315 keys->publickey->data[7];
318 logthing(LOGTHING_ERROR, "Unknown key type: %d",
319 keys->publickey->data[0]);
322 printf(":%d:%d:%ld::%s\n",
326 (keys->revocations == NULL) ? "" : "r");
328 for (curuid = keys->uids; curuid != NULL;
329 curuid = curuid->next) {
331 if (curuid->packet->tag == 13) {
333 (int) curuid->packet->length,
334 curuid->packet->data);