singpolyma / OpenPGP-Python

A port of OpenPGP-PHP to Python
ISC License
34 stars 8 forks source link

Bare UID name is parsed incorrectly #18

Closed fincham closed 6 years ago

fincham commented 7 years ago

When a UserIDPacket is created using a bare string (e.g. no e-mail or comment) as the UID only the 2nd character from this ends up in the packet. Abbreviated example:

private_key = Crypto.PublicKey.RSA.generate(2048)
ggp_private_key = OpenPGP.SecretKeyPacket((
        Crypto.Util.number.long_to_bytes(private_key.n),
        Crypto.Util.number.long_to_bytes(private_key.e),
        Crypto.Util.number.long_to_bytes(private_key.d),
        Crypto.Util.number.long_to_bytes(private_key.p),
        Crypto.Util.number.long_to_bytes(private_key.q),
        Crypto.Util.number.long_to_bytes(private_key.u)
))
pgp_uid = OpenPGP.UserIDPacket('Test')

Once signed etc the resulting UID packet ends up with an 'e' as the UID:

# python test_uid.py  | gpg2 --list-packets
:secret key packet:
    version 4, algo 1, created 1486694962, expires 0
    skey[0]: [2048 bits]
    skey[1]: [17 bits]
    skey[2]: [2047 bits]
    skey[3]: [1024 bits]
    skey[4]: [1024 bits]
    skey[5]: [1024 bits]
    checksum: 4877
    keyid: B99C600A629B4C38
:user ID packet: "e"
:signature packet: algo 1, keyid B99C600A629B4C38
    version 4, created 1486694963, md5len 0, sigclass 0x13
    digest algo 8, begin of digest a1 29
    hashed subpkt 2 len 4 (sig created 2017-02-10)
    hashed subpkt 27 len 1 (key flags: 20)
    hashed subpkt 16 len 8 (issuer key ID B99C600A629B4C38)
    data: [2048 bits]
fincham commented 6 years ago

Thanks!