toofishes / python-pgpdump

PGP packet parser library
Other
55 stars 26 forks source link

Error parsing OpenPGP Data TypeError: Odd-length string #6

Closed muelli closed 12 years ago

muelli commented 12 years ago

<PublicKeyPacket: 0xB415F52BF49191B6, DSA Digital Signature Algorithm, length 418> Reading from byte 97826 <UserIDPacket: u'Satoshi Nishimura' (u'snishimura1@earthlink.net'), length 45> Reading from byte 97871 <SignaturePacket: DSA Digital Signature Algorithm, SHA1, length 78> Reading from byte 97949 <PublicSubkeyPacket: 0x58850DA6EFFBF762, ElGamal Encrypt-Only, length 525> Reading from byte 98474 <SignaturePacket: DSA Digital Signature Algorithm, SHA1, length 70> Traceback (most recent call last): File "/home/muelli/hg/openpgp-things/mypgpdump.py", line 38, in sys.exit(main(sys.argv)) File "/home/muelli/hg/openpgp-things/mypgpdump.py", line 23, in main for packet in data.packets(): File "/home/muelli/git/python-pgpdump/pgpdump/data.py", line 30, in packets total_length, packet = construct_packet(self.data, offset) File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 562, in construct_packet packet = PacketType(tag, name, new, packet_data) File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 303, in init super(PublicKeyPacket, self).init(_args, *_kwargs) File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 21, in init self.parse() File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 333, in parse md5.update(get_bytes(self.exponent)) File "/home/muelli/git/python-pgpdump/pgpdump/packet.py", line 331, in get_bytes = lambda x: binascii.unhexlify(('%X' % x).encode('ascii')) TypeError: Odd-length string

This is what pgpdump writes:

Old: Public Key Packet(tag 6)(418 bytes) Ver 4 - new Public key creation time - Fri Feb 18 18:58:58 CET 2000 Pub alg - DSA Digital Signature Algorithm(pub 17) DSA p(1024 bits) - ... DSA q(160 bits) - ... DSA g(1022 bits) - ... DSA y(1022 bits) - ... Old: User ID Packet(tag 13)(45 bytes) User ID - Satoshi Nishimura snishimura1@earthlink.net Old: Signature Packet(tag 2)(78 bytes) Ver 4 - new Sig type - Generic certification of a User ID and Public Key packet(0x10 ). Pub alg - DSA Digital Signature Algorithm(pub 17) Hash alg - SHA1(hash 2) Hashed Sub: signature creation time(sub 2)(4 bytes) Time - Fri Feb 18 18:58:58 CET 2000 Hashed Sub: preferred symmetric algorithms(sub 11)(3 bytes) Sym alg - CAST5(sym 3) Sym alg - Triple-DES(sym 2) Sym alg - IDEA(sym 1) Hashed Sub: primary User ID(sub 25)(1 bytes) Primary - Yes Sub: issuer key ID(sub 16)(8 bytes) Key ID - 0xB415F52BF49191B6 Hash left 2 bytes - b6 de DSA r(160 bits) - ... DSA s(160 bits) - ... -> hash(DSA q bits)

Old: Public Subkey Packet(tag 14)(525 bytes) Ver 4 - new Public key creation time - Fri Feb 18 18:58:58 CET 2000 Pub alg - ElGamal Encrypt-Only(pub 16) ElGamal p(2048 bits) - ... ElGamal g(2 bits) - ... ElGamal y(2048 bits) - ... Old: Signature Packet(tag 2)(70 bytes) Ver 4 - new Sig type - Subkey Binding Signature(0x18). Pub alg - DSA Digital Signature Algorithm(pub 17) Hash alg - SHA1(hash 2) Hashed Sub: signature creation time(sub 2)(4 bytes) Time - Fri Feb 18 18:58:58 CET 2000 Sub: issuer key ID(sub 16)(8 bytes) Key ID - 0xB415F52BF49191B6 Hash left 2 bytes - 52 14 DSA r(160 bits) - ... DSA s(159 bits) - ... -> hash(DSA q bits)

toofishes commented 12 years ago

I can't reproduce this with current git version. I see the exact same output from pgpdump, and the python code also successfully prints out the summary of the same packets. Note that you shouldn't even be in the version 3 public key code that involves the md5.update() call with this key, as all parts are version 4 public keys.

muelli commented 12 years ago

Well, then try this data:

https://muelli.cryptobitch.de/tmp/2012-04-08-openpgp-keys.pgp

It fails for me on the very recent git version.

toofishes commented 12 years ago

This is now fixed in git, but that file has some crazy data in it. The overall parsing of it still fails, but pgpdump also eats it on the same packet due to some malformed lengths or something it is finding inside.

muelli commented 12 years ago

Yep. true. GnuPG fails, too:

gpg: key D76B9A41: "Michael Nunemacher ksnune@southwind.net" not changed gpg: key 46D6FF9D: "Glenn L. Smith III RIVER_KID@PRODIGY.NET" not changed gpg: key C1611324: "zamitsos zamitsos@lavabit.com" not changed gpg: key 07BDB6A6: "Michael Mertel mmertel@bwc.de" not changed gpg: mpi too large for this implementation (51694 bits) gpg: mpi too large for this implementation (20621 bits) gpg: read_block: read error: invalid packet gpg: import from `sks-dump-0001.pgp' failed: invalid keyring gpg: Total number processed: 187 gpg: w/o user IDs: 5 gpg: unchanged: 182

Thanks for having that fixed.