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;
 
 141 void display_fingerprint(struct openpgp_publickey *key)
 
 145         unsigned char   fp[20];
 
 147         get_fingerprint(key->publickey, fp, &length);
 
 148         printf("      Key fingerprint =");
 
 149         for (i = 0; i < length; i++) {
 
 150                 if ((length == 16) ||
 
 154                 printf("%02X", fp[i]);
 
 155                 if ((i * 2) == length) {
 
 165  *      key_index - List a set of OpenPGP keys.
 
 166  *      @keys: The keys to display.
 
 167  *      @verbose: Should we list sigs as well?
 
 168  *      @fingerprint: List the fingerprint?
 
 169  *      @html: Should the output be tailored for HTML?
 
 171  *      This function takes a list of OpenPGP public keys and displays an index
 
 172  *      of them. Useful for debugging or the keyserver Index function.
 
 174 int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint,
 
 177         struct openpgp_signedpacket_list        *curuid = NULL;
 
 178         struct tm                               *created = NULL;
 
 179         time_t                                   created_time = 0;
 
 187         puts("Type   bits/keyID    Date       User ID");
 
 188         while (keys != NULL) {
 
 189                 created_time = (keys->publickey->data[1] << 24) +
 
 190                                         (keys->publickey->data[2] << 16) +
 
 191                                         (keys->publickey->data[3] << 8) +
 
 192                                         keys->publickey->data[4];
 
 193                 created = gmtime(&created_time);
 
 195                 switch (keys->publickey->data[0]) {
 
 198                         type = keys->publickey->data[7];
 
 199                         length = (keys->publickey->data[8] << 8) +
 
 200                                         keys->publickey->data[9];
 
 203                         type = keys->publickey->data[5];
 
 204                         length = (keys->publickey->data[6] << 8) +
 
 205                                         keys->publickey->data[7];
 
 208                         fprintf(stderr, "Unknown key type: %d\n",
 
 209                                 keys->publickey->data[0]);
 
 212                 printf("pub  %5d%c/%08X %04d/%02d/%02d ",
 
 214                         (type == 1) ? 'R' : ((type == 16) ? 'g' : 
 
 215                                 ((type == 17) ? 'D' : '?')),
 
 216                         (uint32_t) (get_keyid(keys) & 0xFFFFFFFF),
 
 217                         created->tm_year + 1900,
 
 222                 if (curuid != NULL && curuid->packet->tag == 13) {
 
 223                         snprintf(buf, 1023, "%.*s",
 
 224                                 (int) curuid->packet->length,
 
 225                                 curuid->packet->data);
 
 226                         printf("%s\n", (html) ? txt2html(buf) : buf);
 
 228                                 display_fingerprint(keys);
 
 231                                 list_sigs(curuid->sigs, html);
 
 233                         curuid = curuid->next;
 
 237                                 display_fingerprint(keys);
 
 241                 list_uids(curuid, verbose, html);
 
 242                 list_subkeys(keys->subkeys, verbose, html);