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"
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(struct openpgp_signedpacket_list *uids, bool verbose, bool html)
67 while (uids != NULL) {
68 if (uids->packet->tag == 13) {
69 snprintf(buf, 1023, "%.*s",
70 (int) uids->packet->length,
73 (html) ? txt2html(buf) : buf);
74 } else if (uids->packet->tag == 17) {
79 list_sigs(uids->sigs, html);
87 int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose,
90 struct tm *created = NULL;
91 time_t created_time = 0;
95 while (subkeys != NULL) {
96 if (subkeys->packet->tag == 14) {
98 created_time = (subkeys->packet->data[1] << 24) +
99 (subkeys->packet->data[2] << 16) +
100 (subkeys->packet->data[3] << 8) +
101 subkeys->packet->data[4];
102 created = gmtime(&created_time);
104 switch (subkeys->packet->data[0]) {
107 type = subkeys->packet->data[7];
108 length = (subkeys->packet->data[8] << 8) +
109 subkeys->packet->data[9];
112 type = subkeys->packet->data[5];
113 length = (subkeys->packet->data[6] << 8) +
114 subkeys->packet->data[7];
117 fprintf(stderr, "Unknown key type: %d\n",
118 subkeys->packet->data[0]);
121 printf("sub %5d%c/%08X %04d/%02d/%02d\n",
123 (type == 1) ? 'R' : ((type == 16) ? 'g' :
124 ((type == 17) ? 'D' : '?')),
125 (uint32_t) (get_packetid(subkeys->packet) &
127 created->tm_year + 1900,
133 list_sigs(subkeys->sigs, html);
135 subkeys = subkeys->next;
142 * key_index - List a set of OpenPGP keys.
143 * @keys: The keys to display.
144 * @verbose: Should we list sigs as well?
145 * @fingerprint: List the fingerprint?
146 * @html: Should the output be tailored for HTML?
148 * This function takes a list of OpenPGP public keys and displays an index
149 * of them. Useful for debugging or the keyserver Index function.
151 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
154 struct openpgp_signedpacket_list *curuid = NULL;
155 struct tm *created = NULL;
156 time_t created_time = 0;
164 puts("Type bits/keyID Date User ID");
165 while (keys != NULL) {
166 created_time = (keys->publickey->data[1] << 24) +
167 (keys->publickey->data[2] << 16) +
168 (keys->publickey->data[3] << 8) +
169 keys->publickey->data[4];
170 created = gmtime(&created_time);
172 switch (keys->publickey->data[0]) {
175 type = keys->publickey->data[7];
176 length = (keys->publickey->data[8] << 8) +
177 keys->publickey->data[9];
180 type = keys->publickey->data[5];
181 length = (keys->publickey->data[6] << 8) +
182 keys->publickey->data[7];
185 fprintf(stderr, "Unknown key type: %d\n",
186 keys->publickey->data[0]);
189 printf("pub %5d%c/%08X %04d/%02d/%02d ",
191 (type == 1) ? 'R' : ((type == 16) ? 'g' :
192 ((type == 17) ? 'D' : '?')),
193 (uint32_t) (get_keyid(keys) & 0xFFFFFFFF),
194 created->tm_year + 1900,
199 if (curuid != NULL && curuid->packet->tag == 13) {
200 snprintf(buf, 1023, "%.*s",
201 (int) curuid->packet->length,
202 curuid->packet->data);
203 printf("%s\n", (html) ? txt2html(buf) : buf);
205 list_sigs(curuid->sigs, html);
207 curuid = curuid->next;
212 list_uids(curuid, verbose, html);
213 list_subkeys(keys->subkeys, verbose, html);