Skip to content

Commit d4937d4

Browse files
committed
Be defensive about key structure
A public key packet needs to be before any other packets
1 parent 564f754 commit d4937d4

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

pulpcore/app/openpgp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def read_public_key(data):
2828
signed_content = public_key
2929

3030
elif tag == Tag.PublicSubkey:
31+
if public_key is None:
32+
raise ValueError("Not a public key.")
3133
public_subkey = {
3234
"raw_data": body,
3335
"fingerprint": packet.fingerprint,
@@ -38,6 +40,8 @@ def read_public_key(data):
3840
public_key["public_subkeys"].append(public_subkey)
3941

4042
elif tag == Tag.UserID:
43+
if public_key is None:
44+
raise ValueError("Not a public key.")
4145
user_id = {
4246
"raw_data": body,
4347
"user_id": packet.user_id,
@@ -47,6 +51,8 @@ def read_public_key(data):
4751
public_key["user_ids"].append(user_id)
4852

4953
elif tag == Tag.UserAttribute:
54+
if public_key is None:
55+
raise ValueError("Not a public key.")
5056
user_attribute = {
5157
"raw_data": body,
5258
"sha256": hashlib.sha256(body).hexdigest(),
@@ -56,6 +62,8 @@ def read_public_key(data):
5662
public_key["user_attributes"].append(user_attribute)
5763

5864
elif tag == Tag.Signature:
65+
if signed_content is None:
66+
raise ValueError("Not a public key.")
5967
sig_attrs = {
6068
"sha256": hashlib.sha256(body).hexdigest(),
6169
"signature_type": body[1],

0 commit comments

Comments
 (0)