2 * keyindex.c - Routines to list an OpenPGP key.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "decodekey.h"
23 #include "keystructs.h"
26 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 (html && uid != NULL) {
35 printf("sig <a href=\"lookup?op=get&"
36 "search=%08llX\">%08llX</a> "
37 "<a href=\"lookup?op=vindex&search=0x%08llX\">"
43 } else if (html && uid == NULL) {
45 "[User id not found]\n",
52 "[User id not found]");
64 int list_uids(struct openpgp_signedpacket_list *uids, bool verbose, bool html)
68 while (uids != NULL) {
69 if (uids->packet->tag == 13) {
70 snprintf(buf, 1023, "%.*s",
71 (int) uids->packet->length,
74 (html) ? txt2html(buf) : buf);
75 } else if (uids->packet->tag == 17) {
80 list_sigs(uids->sigs, html);
88 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
91 struct tm *created = NULL;
92 time_t created_time = 0;
96 while (subkeys != NULL) {
97 if (subkeys->packet->tag == 14) {
99 created_time = (subkeys->packet->data[1] << 24) +
100 (subkeys->packet->data[2] << 16) +
101 (subkeys->packet->data[3] << 8) +
102 subkeys->packet->data[4];
103 created = gmtime(&created_time);
105 switch (subkeys->packet->data[0]) {
108 type = subkeys->packet->data[7];
109 length = (subkeys->packet->data[8] << 8) +
110 subkeys->packet->data[9];
113 type = subkeys->packet->data[5];
114 length = (subkeys->packet->data[6] << 8) +
115 subkeys->packet->data[7];
118 logthing(LOGTHING_ERROR,
119 "Unknown key type: %d",
120 subkeys->packet->data[0]);
123 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
125 (type == 1) ? 'R' : ((type == 16) ? 'g' :
126 ((type == 17) ? 'D' : '?')),
127 (uint32_t) (get_packetid(subkeys->packet) &
129 created->tm_year + 1900,
135 list_sigs(subkeys->sigs, html);
137 subkeys = subkeys->next;
143 void display_fingerprint(struct openpgp_publickey *key)
147 unsigned char fp[20];
149 get_fingerprint(key->publickey, fp, &length);
150 printf(" Key fingerprint =");
151 for (i = 0; i < length; i++) {
152 if ((length == 16) ||
156 printf("%02X", fp[i]);
157 if ((i * 2) == length) {
167 * key_index - List a set of OpenPGP keys.
168 * @keys: The keys to display.
169 * @verbose: Should we list sigs as well?
170 * @fingerprint: List the fingerprint?
171 * @html: Should the output be tailored for HTML?
173 * This function takes a list of OpenPGP public keys and displays an index
174 * of them. Useful for debugging or the keyserver Index function.
176 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
179 struct openpgp_signedpacket_list *curuid = NULL;
180 struct tm *created = NULL;
181 time_t created_time = 0;
189 puts("Type bits/keyID Date User ID");
190 while (keys != NULL) {
191 created_time = (keys->publickey->data[1] << 24) +
192 (keys->publickey->data[2] << 16) +
193 (keys->publickey->data[3] << 8) +
194 keys->publickey->data[4];
195 created = gmtime(&created_time);
197 switch (keys->publickey->data[0]) {
200 type = keys->publickey->data[7];
201 length = (keys->publickey->data[8] << 8) +
202 keys->publickey->data[9];
205 type = keys->publickey->data[5];
206 length = (keys->publickey->data[6] << 8) +
207 keys->publickey->data[7];
210 logthing(LOGTHING_ERROR, "Unknown key type: %d",
211 keys->publickey->data[0]);
214 printf("pub %5d%c/%08X %04d/%02d/%02d ",
216 (type == 1) ? 'R' : ((type == 16) ? 'g' :
217 ((type == 17) ? 'D' : '?')),
218 (uint32_t) (get_keyid(keys) & 0xFFFFFFFF),
219 created->tm_year + 1900,
224 if (curuid != NULL && curuid->packet->tag == 13) {
225 snprintf(buf, 1023, "%.*s",
226 (int) curuid->packet->length,
227 curuid->packet->data);
228 printf("%s\n", (html) ? txt2html(buf) : buf);
230 display_fingerprint(keys);
233 list_sigs(curuid->sigs, html);
235 curuid = curuid->next;
239 display_fingerprint(keys);
243 list_uids(curuid, verbose, html);
244 list_subkeys(keys->subkeys, verbose, html);