From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:16 +0000 (+0000) Subject: cscvs to tla changeset 41 X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/d5ee45b742e49fa30cc8d0a5a69ee47c8c5b1eb5?ds=sidebyside cscvs to tla changeset 41 Author: noodles Date: 2002/11/16 18:30:01 Added display of subkeys on (v)index. --- diff --git a/keyid.c b/keyid.c index 65a0363..6bb2e19 100644 --- a/keyid.c +++ b/keyid.c @@ -13,11 +13,21 @@ #include "md5.h" #include "sha.h" + /** * get_keyid - Given a public key returns the keyid. - * @publickey: The key to calculate the fingerprint for. + * @publickey: The key to calculate the id for. */ uint64_t get_keyid(struct openpgp_publickey *publickey) +{ + return (get_packetid(publickey->publickey)); +} + +/** + * get_packetid - Given a PGP packet returns the keyid. + * @packet: The packet to calculate the id for. + */ +uint64_t get_packetid(struct openpgp_packet *packet) { SHA1_CONTEXT sha_ctx; uint64_t keyid = 0; @@ -26,9 +36,9 @@ uint64_t get_keyid(struct openpgp_publickey *publickey) unsigned char c; unsigned char *buff = NULL; - assert(publickey != NULL); + assert(packet != NULL); - switch (publickey->publickey->data[0]) { + switch (packet->data[0]) { case 2: case 3: /* @@ -38,14 +48,14 @@ uint64_t get_keyid(struct openpgp_publickey *publickey) * * We need to ensure it's an RSA key. */ - if (publickey->publickey->data[7] == 1) { - offset = (publickey->publickey->data[8] << 8) + - publickey->publickey->data[9]; + if (packet->data[7] == 1) { + offset = (packet->data[8] << 8) + + packet->data[9]; offset = ((offset + 7) / 8) + 2; for (keyid = 0, i = 0; i < 8; i++) { keyid <<= 8; - keyid += publickey->publickey->data[offset++]; + keyid += packet->data[offset++]; } } else { fputs("Type 2 or 3 key, but not RSA.\n", stderr); @@ -65,12 +75,12 @@ uint64_t get_keyid(struct openpgp_publickey *publickey) */ c = 0x99; sha1_write(&sha_ctx, &c, sizeof(c)); - c = publickey->publickey->length >> 8; + c = packet->length >> 8; sha1_write(&sha_ctx, &c, sizeof(c)); - c = publickey->publickey->length & 0xFF; + c = packet->length & 0xFF; sha1_write(&sha_ctx, &c, sizeof(c)); - sha1_write(&sha_ctx, publickey->publickey->data, - publickey->publickey->length); + sha1_write(&sha_ctx, packet->data, + packet->length); sha1_final(&sha_ctx); buff = sha1_read(&sha_ctx); @@ -84,7 +94,7 @@ uint64_t get_keyid(struct openpgp_publickey *publickey) break; default: fprintf(stderr, "Unknown key type: %d\n", - publickey->publickey->data[0]); + packet->data[0]); } return keyid; diff --git a/keyid.h b/keyid.h index 1959a0d..d25447c 100644 --- a/keyid.h +++ b/keyid.h @@ -16,10 +16,18 @@ /** * get_keyid - Given a public key returns the keyid. - * @publickey: The key to calculate the fingerprint for. + * @publickey: The key to calculate the id for. * * This function returns the key id for a given public key. */ uint64_t get_keyid(struct openpgp_publickey *publickey); +/** + * get_packetid - Given a PGP packet returns the keyid. + * @packet: The packet to calculate the id for. + * + * This function returns the key id for a given PGP packet. + */ +uint64_t get_packetid(struct openpgp_packet *packet); + #endif /* __KEYID_H__ */ diff --git a/keyindex.c b/keyindex.c index a7218b2..a8f9193 100644 --- a/keyindex.c +++ b/keyindex.c @@ -25,7 +25,6 @@ int list_sigs(struct openpgp_packet_list *sigs, bool html) { - int length = 0; char *uid = NULL; uint64_t sigid = 0; @@ -86,6 +85,61 @@ int list_uids(struct openpgp_signedpacket_list *uids, bool verbose, bool html) return 0; } +int list_subkeys(struct openpgp_signedpacket_list *subkeys, bool verbose, + bool html) +{ + struct tm *created = NULL; + time_t created_time = 0; + int type = 0; + int length = 0; + + while (subkeys != NULL) { + if (subkeys->packet->tag == 14) { + + created_time = (subkeys->packet->data[1] << 24) + + (subkeys->packet->data[2] << 16) + + (subkeys->packet->data[3] << 8) + + subkeys->packet->data[4]; + created = gmtime(&created_time); + + switch (subkeys->packet->data[0]) { + case 2: + case 3: + type = subkeys->packet->data[7]; + length = (subkeys->packet->data[8] << 8) + + subkeys->packet->data[9]; + break; + case 4: + type = subkeys->packet->data[5]; + length = (subkeys->packet->data[6] << 8) + + subkeys->packet->data[7]; + break; + default: + fprintf(stderr, "Unknown key type: %d\n", + subkeys->packet->data[0]); + } + + printf("sub %5d%c/%08X %04d/%02d/%02d\n", + length, + (type == 1) ? 'R' : ((type == 16) ? 'g' : + ((type == 17) ? 'D' : '?')), + (uint32_t) (get_packetid(subkeys->packet) & + 0xFFFFFFFF), + created->tm_year + 1900, + created->tm_mon + 1, + created->tm_mday); + + } + if (verbose) { + list_sigs(subkeys->sigs, html); + } + subkeys = subkeys->next; + } + + return 0; +} + + /** * key_index - List a set of OpenPGP keys. * @keys: The keys to display. @@ -136,7 +190,8 @@ int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint, printf("pub %5d%c/%08X %04d/%02d/%02d ", length, - (type == 1) ? 'R' : ((type == 17) ? 'D' : '?'), + (type == 1) ? 'R' : ((type == 16) ? 'g' : + ((type == 17) ? 'D' : '?')), (uint32_t) (get_keyid(keys) & 0xFFFFFFFF), created->tm_year + 1900, created->tm_mon + 1, @@ -157,8 +212,7 @@ int key_index(struct openpgp_publickey *keys, bool verbose, bool fingerprint, } list_uids(curuid, verbose, html); - - //TODO: List subkeys. + list_subkeys(keys->subkeys, verbose, html); keys = keys->next; }