diff --git a/libkeyringctl/keyring.py b/libkeyringctl/keyring.py index c4d929b..efbe858 100644 --- a/libkeyringctl/keyring.py +++ b/libkeyringctl/keyring.py @@ -354,6 +354,10 @@ def convert_certificate( current_packet_fingerprint = None current_packet_uid = Uid(simplify_ascii(packet_dump_field(packet, "Value"))) + if current_packet_uid in uids: + raise Exception( + f"Duplicate User ID {current_packet_uid} used in packet {uids[current_packet_uid]} and {packet}" + ) uids[current_packet_uid] = packet elif packet.name.endswith("UserAttribute"): current_packet_mode = "uattr" diff --git a/tests/test_keyring.py b/tests/test_keyring.py index 52bbfb3..a48b6d2 100644 --- a/tests/test_keyring.py +++ b/tests/test_keyring.py @@ -423,6 +423,22 @@ def test_convert_signature_packet( "bar", does_not_raise(), ), + ( + Path("foo.asc"), + [ + Path("--PublicKey"), + Path("--Signature"), + Path("--UserID"), + Path("--UserID"), + ], + [ + "".join(choice("ABCDEF" + digits) for _ in range(40)), + "foo ", + "foo ", + ], + "bar", + raises(Exception), + ), ( Path("foo.asc"), [