X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=decodekey.c;h=28f8ceef39f90dd7151bc1f4692ac520d6487493;hb=2039724ebd70536ad567630725f6b75b7868e486;hp=57a1e660754b1a7adf79284d028f248d23416b6d;hpb=df44563877c4ae07ac62a65c9dee79250a3a779a;p=onak.git
diff --git a/decodekey.c b/decodekey.c
index 57a1e66..28f8cee 100644
--- a/decodekey.c
+++ b/decodekey.c
@@ -13,11 +13,10 @@
* 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.
+ * this program. If not, see .
*/
-#include
+#include
#include
#include
#include
@@ -28,12 +27,13 @@
#include "keyid.h"
#include "keystructs.h"
#include "ll.h"
-#include "log.h"
#include "openpgp.h"
/*
* parse_subpackets - Parse the subpackets of a Type 4 signature.
* @data: The subpacket data.
+ * @len: The amount of data available to read.
+ * @parselen: The amount of data that was actually parsed.
* @keyid: A pointer to where we should return the keyid.
* @creationtime: A pointer to where we should return the creation time.
*
@@ -42,16 +42,31 @@
* processed. If the value of any piece of data is not desired a NULL
* can be passed instead of a pointer to a storage area for that value.
*/
-int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation)
+onak_status_t parse_subpackets(unsigned char *data, size_t len,
+ size_t *parselen, uint64_t *keyid, time_t *creation)
{
int offset = 0;
int length = 0;
int packetlen = 0;
+ struct openpgp_fingerprint fp;
+ int i;
- log_assert(data != NULL);
+ assert(data != NULL);
+
+ /* Make sure we actually have the 2 byte length field */
+ if (len < 2) {
+ return ONAK_E_INVALID_PKT;
+ }
length = (data[0] << 8) + data[1] + 2;
+ /* If the length is off the end of the data available, it's bogus */
+ if (len < length) {
+ return ONAK_E_INVALID_PKT;
+ }
+
+ *parselen = length;
+
offset = 2;
while (offset < length) {
packetlen = data[offset++];
@@ -67,6 +82,10 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation)
packetlen <<= 8;
packetlen |= data[offset++];
}
+ /* Check the supplied length is within the remaining data */
+ if (packetlen == 0 || (packetlen + offset) > length) {
+ return ONAK_E_INVALID_PKT;
+ }
switch (data[offset] & 0x7F) {
case OPENPGP_SIGSUB_CREATION:
/*
@@ -105,6 +124,16 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation)
*keyid += data[offset+packetlen - 1];
}
break;
+ case OPENPGP_SIGSUB_ISSUER_FINGER:
+ if ((packetlen - 2) <= MAX_FINGERPRINT_LEN &&
+ keyid != NULL) {
+ fp.length = packetlen - 2;
+ for (i = 0; i < fp.length; i++) {
+ fp.fp[i] = data[offset + i + 2];
+ }
+ *keyid = fingerprint2keyid(&fp);
+ }
+ break;
case OPENPGP_SIGSUB_EXPIRY:
case OPENPGP_SIGSUB_EXPORTABLE:
case OPENPGP_SIGSUB_TRUSTSIG:
@@ -117,7 +146,7 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation)
case OPENPGP_SIGSUB_REVOCATION_KEY:
case OPENPGP_SIGSUB_ISSUER_UID:
case OPENPGP_SIGSUB_URL:
- case OPENPGP_SIGSUB_ISSUER_FINGER:
+ case OPENPGP_SIGSUB_X_ISSUER_FINGER:
case OPENPGP_SIGSUB_NOTATION:
case OPENPGP_SIGSUB_PREFHASH:
case OPENPGP_SIGSUB_PREFCOMPRESS:
@@ -143,38 +172,13 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation)
* 7 is set in which case we log a major error.
*/
if (data[offset] & 0x80) {
- logthing(LOGTHING_CRITICAL,
- "Critical subpacket type not parsed: 0x%X",
- data[offset]);
+ return ONAK_E_UNSUPPORTED_FEATURE;
}
-
}
offset += packetlen;
}
- return length;
-}
-
-/**
- * keysigs - Return the sigs on a given OpenPGP signature list.
- * @curll: The current linked list. Can be NULL to create a new list.
- * @sigs: The signature list we want the sigs on.
- *
- * Returns a linked list of stats_key elements containing the sigs on the
- * supplied OpenPGP packet list.
- */
-struct ll *keysigs(struct ll *curll,
- struct openpgp_packet_list *sigs)
-{
- uint64_t keyid = 0;
-
- while (sigs != NULL) {
- keyid = sig_keyid(sigs->packet);
- sigs = sigs->next;
- curll = lladd(curll, createandaddtohash(keyid));
- }
-
- return curll;
+ return ONAK_E_OK;
}
/**
@@ -187,10 +191,12 @@ struct ll *keysigs(struct ll *curll,
* key or pulls the data directly from v2/3. NULL can be passed for any
* values which aren't cared about.
*/
-void sig_info(struct openpgp_packet *packet, uint64_t *keyid, time_t *creation)
+onak_status_t sig_info(struct openpgp_packet *packet, uint64_t *keyid,
+ time_t *creation)
{
- int length = 0;
-
+ size_t length = 0;
+ onak_status_t res;
+
if (packet != NULL) {
switch (packet->data[0]) {
case 2:
@@ -223,20 +229,26 @@ void sig_info(struct openpgp_packet *packet, uint64_t *keyid, time_t *creation)
}
break;
case 4:
- length = parse_subpackets(&packet->data[4],
- keyid, creation);
- parse_subpackets(&packet->data[length + 4],
- keyid, creation);
- /*
- * Don't bother to look at the unsigned packets.
- */
+ case 5:
+ res = parse_subpackets(&packet->data[4],
+ packet->length - 4,
+ &length, keyid, creation);
+ if (res != ONAK_E_OK) {
+ return res;
+ }
+ res = parse_subpackets(&packet->data[length + 4],
+ packet->length - (4 + length),
+ &length, keyid, creation);
+ if (res != ONAK_E_OK) {
+ return res;
+ }
break;
default:
break;
}
}
- return;
+ return ONAK_E_OK;
}
/**