python-pgpdump icon indicating copy to clipboard operation
python-pgpdump copied to clipboard

V4 Secret key id and fingerprint not calculated correctly

Open arwyersfs opened this issue 6 years ago • 1 comments

Don't think this is actively maintained, but figured I could spare someone some pain if they need to use this in the future. The fingerprint(and subsequently key_id) for version 4 key packets is calculated incorrectly. According to the RFC 4880 only the public key packets are supposed to be used in SHA1 to get the fingerprint, but the code uses the entire packet content(including the secret key material).

arwyersfs avatar Oct 25 '19 12:10 arwyersfs

Adding this segment of code after line 481 should do the trick public_len = offset if self.pubkey_version == 4: sha1 = hashlib.sha1() seed_bytes = (0x99, (public_len >> 8) & 0xff, public_len & 0xff) sha1.update(pack_data(bytearray(seed_bytes))) sha1.update(pack_data(self.data[:public_len])) self.fingerprint = sha1.hexdigest().upper().encode('ascii') self.key_id = self.fingerprint[24:]

arwyersfs avatar Oct 25 '19 12:10 arwyersfs