Skip to content

Commit 1fda798

Browse files
committed
ASN.1: deal with empty private values in public key dicts
by removing them. This is potentially problematic as it might change the keyid when converting to ASN.1 and back, but it'll have to do for now, and we shouldn't have these things in there in the first place. It's an edge case, and this is a compromise. Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
1 parent da726fe commit 1fda798

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tuf/encoding/asn1_convert.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,16 @@ def public_key_to_pyasn1(public_key_dict):
180180
# whether it replaces the previous one or is a second check_match on the same
181181
# arg.
182182
if 'private' in public_key_dict['keyval']:
183-
raise tuf.exceptions.FormatError('Expected public key, received key dict '
184-
'containing a private key entry!')
183+
184+
# TODO: Clean this conditional up! Removing an empty 'private' value is
185+
# not ideal, and might change the keyid based on how we currently calculate
186+
# keyids.... Empty strings don't seem to be OK as OctetStrings, though, so
187+
# for now, we're doing this....
188+
if not public_key_dict['keyval']['private']:
189+
del public_key_dict['keyval']['private']
190+
else:
191+
raise tuf.exceptions.FormatError('Expected public key, received key dict '
192+
'containing a private key entry!')
185193

186194
# TODO: Intelligently handle PEM-style RSA keys, which have value set to an
187195
# ASCII-prefixed Base64 string like:

0 commit comments

Comments
 (0)