2 * keyindex.c - Routines to list an OpenPGP key.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: keyindex.c,v 1.12 2003/06/08 21:11:01 noodles Exp $
19 #include "decodekey.h"
25 #include "keystructs.h"
28 int list_sigs(struct openpgp_packet_list *sigs, bool html)
33 while (sigs != NULL) {
34 sigid = sig_keyid(sigs->packet);
35 uid = keyid2uid(sigid);
36 if (html && uid != NULL) {
37 printf("sig <a href=\"lookup?op=get&"
38 "search=%08llX\">%08llX</a> "
39 "<a href=\"lookup?op=vindex&search=0x%08llX\">"
45 } else if (html && uid == NULL) {
47 "[User id not found]\n",
54 "[User id not found]");
66 int list_uids(struct openpgp_signedpacket_list *uids, bool verbose, bool html)
70 while (uids != NULL) {
71 if (uids->packet->tag == 13) {
72 snprintf(buf, 1023, "%.*s",
73 (int) uids->packet->length,
76 (html) ? txt2html(buf) : buf);
77 } else if (uids->packet->tag == 17) {
82 list_sigs(uids->sigs, html);
90 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
93 struct tm *created = NULL;
94 time_t created_time = 0;
98 while (subkeys != NULL) {
99 if (subkeys->packet->tag == 14) {
101 created_time = (subkeys->packet->data[1] << 24) +
102 (subkeys->packet->data[2] << 16) +
103 (subkeys->packet->data[3] << 8) +
104 subkeys->packet->data[4];
105 created = gmtime(&created_time);
107 switch (subkeys->packet->data[0]) {
110 type = subkeys->packet->data[7];
111 length = (subkeys->packet->data[8] << 8) +
112 subkeys->packet->data[9];
115 type = subkeys->packet->data[5];
116 length = (subkeys->packet->data[6] << 8) +
117 subkeys->packet->data[7];
120 logthing(LOGTHING_ERROR,
121 "Unknown key type: %d",
122 subkeys->packet->data[0]);
125 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
127 (type == 1) ? 'R' : ((type == 16) ? 'g' :
128 ((type == 17) ? 'D' : '?')),
129 (uint32_t) (get_packetid(subkeys->packet) &
131 created->tm_year + 1900,
137 list_sigs(subkeys->sigs, html);
139 subkeys = subkeys->next;
145 void display_fingerprint(struct openpgp_publickey *key)
149 unsigned char fp[20];
151 get_fingerprint(key->publickey, fp, &length);
152 printf(" Key fingerprint =");
153 for (i = 0; i < length; i++) {
154 if ((length == 16) ||
158 printf("%02X", fp[i]);
159 if ((i * 2) == length) {
169 * key_index - List a set of OpenPGP keys.
170 * @keys: The keys to display.
171 * @verbose: Should we list sigs as well?
172 * @fingerprint: List the fingerprint?
173 * @html: Should the output be tailored for HTML?
175 * This function takes a list of OpenPGP public keys and displays an index
176 * of them. Useful for debugging or the keyserver Index function.
178 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
181 struct openpgp_signedpacket_list *curuid = NULL;
182 struct tm *created = NULL;
183 time_t created_time = 0;
191 puts("Type bits/keyID Date User ID");
192 while (keys != NULL) {
193 created_time = (keys->publickey->data[1] << 24) +
194 (keys->publickey->data[2] << 16) +
195 (keys->publickey->data[3] << 8) +
196 keys->publickey->data[4];
197 created = gmtime(&created_time);
199 switch (keys->publickey->data[0]) {
202 type = keys->publickey->data[7];
203 length = (keys->publickey->data[8] << 8) +
204 keys->publickey->data[9];
207 type = keys->publickey->data[5];
208 length = (keys->publickey->data[6] << 8) +
209 keys->publickey->data[7];
212 logthing(LOGTHING_ERROR, "Unknown key type: %d",
213 keys->publickey->data[0]);
216 printf("pub %5d%c/%08X %04d/%02d/%02d ",
218 (type == 1) ? 'R' : ((type == 16) ? 'g' :
219 ((type == 17) ? 'D' : '?')),
220 (uint32_t) (get_keyid(keys) & 0xFFFFFFFF),
221 created->tm_year + 1900,
226 if (curuid != NULL && curuid->packet->tag == 13) {
227 snprintf(buf, 1023, "%.*s",
228 (int) curuid->packet->length,
229 curuid->packet->data);
231 (html) ? txt2html(buf) : buf,
232 (keys->revocations == NULL) ? "" :
235 display_fingerprint(keys);
238 list_sigs(curuid->sigs, html);
240 curuid = curuid->next;
243 (keys->revocations == NULL) ? "" :
246 display_fingerprint(keys);
250 list_uids(curuid, verbose, html);
251 list_subkeys(keys->subkeys, verbose, html);
264 * mrkey_index - List a set of OpenPGP keys in the MRHKP format.
265 * @keys: The keys to display.
267 * This function takes a list of OpenPGP public keys and displays a
268 * machine readable list of them.
270 int mrkey_index(struct openpgp_publickey *keys)
272 struct openpgp_signedpacket_list *curuid = NULL;
273 time_t created_time = 0;
278 unsigned char fp[20];
280 while (keys != NULL) {
281 created_time = (keys->publickey->data[1] << 24) +
282 (keys->publickey->data[2] << 16) +
283 (keys->publickey->data[3] << 8) +
284 keys->publickey->data[4];
288 switch (keys->publickey->data[0]) {
291 printf("%016llX", get_keyid(keys));
292 type = keys->publickey->data[7];
293 length = (keys->publickey->data[8] << 8) +
294 keys->publickey->data[9];
297 get_fingerprint(keys->publickey, fp, &fplength);
299 for (i = 0; i < fplength; i++) {
300 printf("%02X", fp[i]);
303 type = keys->publickey->data[5];
304 length = (keys->publickey->data[6] << 8) +
305 keys->publickey->data[7];
308 logthing(LOGTHING_ERROR, "Unknown key type: %d",
309 keys->publickey->data[0]);
312 printf(":%d:%d:%ld::%s\n",
316 (keys->revocations == NULL) ? "" : "r");
318 for (curuid = keys->uids; curuid != NULL;
319 curuid = curuid->next) {
321 if (curuid->packet->tag == 13) {
323 (int) curuid->packet->length,
324 curuid->packet->data);