X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=decodekey.c;h=705b827d43ef7a7e69197a9a4dd9af537e81d542;hb=23f086c85c5d2db35e9ce76cf0bbf72200b4dc42;hp=606b091f941237ec173cedf64b10b0c6aa1eb29f;hpb=348e7d134e9243fd72cf8fbe366c77c1571faec1;p=onak.git diff --git a/decodekey.c b/decodekey.c index 606b091..705b827 100644 --- a/decodekey.c +++ b/decodekey.c @@ -2,6 +2,19 @@ * decodekey.c - Routines to further decode an OpenPGP key. * * Copyright 2002-2008 Jonathan McDowell + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include @@ -16,6 +29,7 @@ #include "keystructs.h" #include "ll.h" #include "log.h" +#include "openpgp.h" /* * parse_subpackets - Parse the subpackets of a Type 4 signature. @@ -47,14 +61,14 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation) } else if (packetlen == 255) { packetlen = data[offset++]; packetlen <<= 8; - packetlen = data[offset++]; + packetlen |= data[offset++]; packetlen <<= 8; - packetlen = data[offset++]; + packetlen |= data[offset++]; packetlen <<= 8; - packetlen = data[offset++]; + packetlen |= data[offset++]; } switch (data[offset] & 0x7F) { - case 2: + case OPENPGP_SIGSUB_CREATION: /* * Signature creation time. */ @@ -68,17 +82,11 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation) *creation = data[offset + packetlen - 1]; } break; - case 3: /* * Signature expiration time. Might want to output this? */ break; - case 6: - /* - * Regular expression for UIDs this sig is over. - */ - break; - case 16: + case OPENPGP_SIGSUB_ISSUER: if (keyid != NULL) { *keyid = data[offset+packetlen - 8]; *keyid <<= 8; @@ -97,25 +105,23 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation) *keyid += data[offset+packetlen - 1]; } break; - case 20: + case OPENPGP_SIGSUB_EXPIRY: + case OPENPGP_SIGSUB_EXPORTABLE: + case OPENPGP_SIGSUB_TRUSTSIG: + case OPENPGP_SIGSUB_REGEX: + case OPENPGP_SIGSUB_KEYEXPIRY: + case OPENPGP_SIGSUB_PREFSYM: + case OPENPGP_SIGSUB_NOTATION: + case OPENPGP_SIGSUB_PREFHASH: + case OPENPGP_SIGSUB_PREFCOMPRESS: + case OPENPGP_SIGSUB_KEYSERVER: + case OPENPGP_SIGSUB_PRIMARYUID: + case OPENPGP_SIGSUB_POLICYURI: + case OPENPGP_SIGSUB_KEYFLAGS: /* - * Annotation data. - */ - break; - - case 23: - /* - * Key server preferences. Including no-modify. - */ - break; - case 25: - /* - * Primary UID. - */ - break; - case 26: - /* - * Policy URI. + * Various subpacket types we know about, but don't + * currently handle. Some are candidates for being + * supported if we add signature checking support. */ break; default: @@ -276,7 +282,7 @@ char **keyuids(struct openpgp_publickey *key, char **primary) curuid = key->uids; while (curuid != NULL) { buf[0] = 0; - if (curuid->packet->tag == 13) { + if (curuid->packet->tag == OPENPGP_PACKET_UID) { snprintf(buf, 1023, "%.*s", (int) curuid->packet->length, curuid->packet->data); @@ -304,21 +310,21 @@ char **keyuids(struct openpgp_publickey *key, char **primary) * keysubkeys takes a public key structure and returns an array of the * subkey keyids for that key. */ -uint64_t *keysubkeys(struct openpgp_publickey *key) +struct openpgp_fingerprint *keysubkeys(struct openpgp_publickey *key) { struct openpgp_signedpacket_list *cursubkey = NULL; - uint64_t *subkeys = NULL; + struct openpgp_fingerprint *subkeys = NULL; int count = 0; - + if (key != NULL && key->subkeys != NULL) { subkeys = malloc((spsize(key->subkeys) + 1) * - sizeof (uint64_t)); + sizeof (struct openpgp_fingerprint)); cursubkey = key->subkeys; while (cursubkey != NULL) { - subkeys[count++] = get_packetid(cursubkey->packet); + get_fingerprint(cursubkey->packet, &subkeys[count++]); cursubkey = cursubkey -> next; } - subkeys[count] = 0; + subkeys[count].length = 0; } return subkeys;