From 96e36c32f0852bafa2a9f005a78e3f028dc2a8ed Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Fri, 19 Feb 2010 17:42:09 +0900 Subject: [PATCH] * parse_subpacket() are split into parse_signature_subpacket() and parse_userattr_subpacket(). A bug of length calculation is fixed. * The critical bit of the signature subpackets are supported. Peter Palfrader --- CHANGES | 7 +++++ packet.c | 84 +++++++++++++++++++++++++++++++++++------------------ pgpdump.c | 2 +- pgpdump.h | 3 +- signature.c | 4 +-- tagfuncs.c | 2 +- uatfunc.c | 2 +- 7 files changed, 70 insertions(+), 34 deletions(-) diff --git a/CHANGES b/CHANGES index 613d265..f415041 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,12 @@ Change Log +0.22 2004/01/23 + +* parse_subpacket() are split into parse_signature_subpacket() and + parse_userattr_subpacket(). A bug of length calculation is fixed. +* The critical bit of the signature subpackets are supported. + Peter Palfrader + 0.21 2004/01/13 * Removing compiler warnings. diff --git a/packet.c b/packet.c index dac1783..8fe20c7 100644 --- a/packet.c +++ b/packet.c @@ -18,6 +18,9 @@ private int is_partial(int); #define OLD_TAG_SHIFT 2 #define OLD_LEN_MASK 0x03 +#define CRITICAL_BIT 0x80 +#define CRITICAL_MASK 0x7f + private char * TAG[] = { "Reserved", @@ -366,33 +369,57 @@ parse_packet(void) } public void -parse_subpacket(char *prefix, int tlen, int type) +parse_signature_subpacket(char *prefix, int tlen) { - int len, sub, slen; - char **exptbl; - funcptr *sw; + int len, subtype, critical; - switch (type) { - case 1: - slen = SIGSUB_NUM; - exptbl = SIGSUB; - sw = sigsub_func; - break; - case 2: - slen = UATSUB_NUM; - exptbl = UATSUB; - sw = uatsub_func; - break; - default: - warn_exit("unknown type (%d) for subpacket.", type); - break; + while (tlen > 0) { + len = Getc(); + if (len < 192) + tlen--; + else if (len < 255) { + len = ((len - 192) << 8) + Getc() + 192; + tlen -= 2; + } else if (len == 255) { + len = Getc() << 24; + len |= Getc() << 16; + len |= Getc() << 8; + len |= Getc(); + tlen -= 5; + } + tlen -= len; + subtype = Getc(); /* len includes this field byte */ + len--; + + /* Handle critical bit of subpacket type */ + critical = NO; + if (subtype & CRITICAL_BIT) { + critical = YES; + subtype &= CRITICAL_MASK; + } + + if (subtype < SIGSUB_NUM) + printf("\t%s: %s%s", prefix, SIGSUB[subtype], critical ? "(critical)" : ""); + else + printf("\t%s: unknown(sub %d%s)", prefix, subtype, critical ? ", critical" : ""); + printf("(%d bytes)\n", len); + if (subtype < SIGSUB_NUM && sigsub_func[subtype] != NULL) + (*sigsub_func[subtype])(len); + else + skip(len); } - +} + +public void +parse_userattr_subpacket(char *prefix, int tlen) +{ + int len, subtype; + while (tlen > 0) { len = Getc(); if (len < 192) - tlen --; - else if (len < 223) { + tlen--; + else if (len < 255) { len = ((len - 192) << 8) + Getc() + 192; tlen -= 2; } else if (len == 255) { @@ -403,15 +430,16 @@ parse_subpacket(char *prefix, int tlen, int type) tlen -= 5; } tlen -= len; - sub = Getc(); /* len includes this field byte */ - len --; - if (sub < slen) - printf("\t%s: %s", prefix, exptbl[sub]); + subtype = Getc(); + len--; /* len includes this field byte */ + + if (subtype < UATSUB_NUM) + printf("\t%s: %s", prefix, UATSUB[subtype]); else - printf("\t%s: unknown(sub %d)", prefix, sub); + printf("\t%s: unknown(sub %d)", prefix, subtype); printf("(%d bytes)\n", len); - if (sub < slen && sw[sub] != NULL) - (*sw[sub])(len); + if (subtype < UATSUB_NUM && uatsub_func[subtype] != NULL) + (*uatsub_func[subtype])(len); else skip(len); } diff --git a/pgpdump.c b/pgpdump.c index fd772e0..49a1cc0 100644 --- a/pgpdump.c +++ b/pgpdump.c @@ -13,7 +13,7 @@ int mflag; int pflag; int uflag; -private char *pgpdump_version = "0.21, Copyright (C) 1998-2004 Kazu Yamamoto"; +private char *pgpdump_version = "0.22, Copyright (C) 1998-2004 Kazu Yamamoto"; private char *prog; private char *getprog(void); diff --git a/pgpdump.h b/pgpdump.h index e1ec8bd..dbbe2e2 100644 --- a/pgpdump.h +++ b/pgpdump.h @@ -66,7 +66,8 @@ public void Getc_resetlen(void); */ public void parse_packet(void); -public void parse_subpacket(char *, int, int); +public void parse_signature_subpacket(char *, int); +public void parse_userattr_subpacket(char *, int); /* * types.c diff --git a/signature.c b/signature.c index 8794e75..2d66d5a 100644 --- a/signature.c +++ b/signature.c @@ -168,10 +168,10 @@ new_Signature_Packet(int len) hash_algs(Getc()); hsplen = Getc() * 256; hsplen += Getc(); - parse_subpacket("Hashed Sub", hsplen, 1); + parse_signature_subpacket("Hashed Sub", hsplen); usplen = Getc() * 256; usplen += Getc(); - parse_subpacket("Sub", usplen, 1); + parse_signature_subpacket("Sub", usplen); hash2(); signature_multi_precision_integer(pub, len - 9 - hsplen - usplen); } diff --git a/tagfuncs.c b/tagfuncs.c index eae8052..6c098ee 100644 --- a/tagfuncs.c +++ b/tagfuncs.c @@ -178,7 +178,7 @@ User_ID_Packet(int len) public void User_Attribute_Packet(int len) { - parse_subpacket("Sub", len, 2); + parse_userattr_subpacket("Sub", len); } public void diff --git a/uatfunc.c b/uatfunc.c index 4b7e7af..fff9e16 100644 --- a/uatfunc.c +++ b/uatfunc.c @@ -15,7 +15,7 @@ image_attribute(int len) if (hver == 1) { int enc = Getc(); printf("\t\tImage encoding - %s(enc %d)\n", - enc==1 ? "JPEG" : "Unknown", + enc == 1 ? "JPEG" : "Unknown", enc); printf("\t\tImage data(%d bytes)\n", len - hlen); skip(len - 4);