Skip to content

Commit 75effec

Browse files
Merge branch 'lukpueh-update-import-keys'
2 parents 3c67035 + 34992dd commit 75effec

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

securesystemslib/formats.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,13 @@
237237
keyval = KEYVAL_SCHEMA,
238238
expires = SCHEMA.Optional(ISO8601_DATETIME_SCHEMA))
239239

240-
# Like KEY_SCHEMA, but requires keyval's private portion to be not set or empty
240+
# Like KEY_SCHEMA, but requires keyval's private portion to be unset or empty,
241+
# and optionally includes the supported keyid hash algorithms used to generate
242+
# the key's keyid.
241243
PUBLIC_KEY_SCHEMA = SCHEMA.Object(
242-
object_name = 'KEY_SCHEMA',
244+
object_name = 'PUBLIC_KEY_SCHEMA',
243245
keytype = SCHEMA.AnyString(),
246+
keyid_hash_algorithms = SCHEMA.Optional(HASHALGORITHMS_SCHEMA),
244247
keyval = PUBLIC_KEYVAL_SCHEMA,
245248
expires = SCHEMA.Optional(ISO8601_DATETIME_SCHEMA))
246249

securesystemslib/interface.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import random
4343

4444
import securesystemslib.formats
45-
import securesystemslib.formats
45+
import securesystemslib.settings
4646
import securesystemslib.util
4747
import securesystemslib.keys
4848

@@ -525,6 +525,11 @@ def import_ed25519_privatekey_from_file(filepath, password=None):
525525
message = 'Invalid key type loaded: ' + repr(key_object['keytype'])
526526
raise securesystemslib.exceptions.FormatError(message)
527527

528+
# Add "keyid_hash_algorithms" so that equal ed25519 keys with
529+
# different keyids can be associated using supported keyid_hash_algorithms.
530+
key_object['keyid_hash_algorithms'] = \
531+
securesystemslib.settings.HASH_ALGORITHMS
532+
528533
return key_object
529534

530535

@@ -745,6 +750,11 @@ def import_ecdsa_privatekey_from_file(filepath, password=None):
745750
message = 'Invalid key type loaded: ' + repr(key_object['keytype'])
746751
raise securesystemslib.exceptions.FormatError(message)
747752

753+
# Add "keyid_hash_algorithms" so that equal ecdsa keys with different keyids
754+
# can be associated using supported keyid_hash_algorithms.
755+
key_object['keyid_hash_algorithms'] = \
756+
securesystemslib.settings.HASH_ALGORITHMS
757+
748758
return key_object
749759

750760

securesystemslib/keys.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ def generate_ecdsa_key(algorithm='ecdsa-sha2-nistp256'):
358358
ecdsa_key['keyid'] = keyid
359359
ecdsa_key['keyval'] = key_value
360360

361+
# Add "keyid_hash_algorithms" so that equal ECDSA keys with different keyids
362+
# can be associated using supported keyid_hash_algorithms.
363+
ecdsa_key['keyid_hash_algorithms'] = \
364+
securesystemslib.settings.HASH_ALGORITHMS
365+
361366
return ecdsa_key
362367

363368

@@ -1244,6 +1249,11 @@ def import_rsakey_from_public_pem(pem):
12441249
rsakey_dict['keyid'] = keyid
12451250
rsakey_dict['keyval'] = key_value
12461251

1252+
# Add "keyid_hash_algorithms" so that equal RSA keys with different keyids
1253+
# can be associated using supported keyid_hash_algorithms.
1254+
rsakey_dict['keyid_hash_algorithms'] = \
1255+
securesystemslib.settings.HASH_ALGORITHMS
1256+
12471257
return rsakey_dict
12481258

12491259

@@ -1315,6 +1325,11 @@ def import_rsakey_from_pem(pem):
13151325
rsakey_dict['keyid'] = keyid
13161326
rsakey_dict['keyval'] = key_value
13171327

1328+
# Add "keyid_hash_algorithms" so that equal RSA keys with
1329+
# different keyids can be associated using supported keyid_hash_algorithms.
1330+
rsakey_dict['keyid_hash_algorithms'] = \
1331+
securesystemslib.settings.HASH_ALGORITHMS
1332+
13181333
return rsakey_dict
13191334

13201335

@@ -1893,6 +1908,11 @@ def import_ecdsakey_from_private_pem(pem, password=None):
18931908
ecdsakey_dict['keyid'] = keyid
18941909
ecdsakey_dict['keyval'] = key_value
18951910

1911+
# Add "keyid_hash_algorithms" so equal ECDSA keys with
1912+
# different keyids can be associated using supported keyid_hash_algorithms
1913+
ecdsakey_dict['keyid_hash_algorithms'] = \
1914+
securesystemslib.settings.HASH_ALGORITHMS
1915+
18961916
return ecdsakey_dict
18971917

18981918

@@ -1971,6 +1991,11 @@ def import_ecdsakey_from_public_pem(pem):
19711991
ecdsakey_dict['keyid'] = keyid
19721992
ecdsakey_dict['keyval'] = key_value
19731993

1994+
# Add "keyid_hash_algorithms" so that equal ECDSA keys with different keyids
1995+
# can be associated using supported keyid_hash_algorithms.
1996+
ecdsakey_dict['keyid_hash_algorithms'] = \
1997+
securesystemslib.settings.HASH_ALGORITHMS
1998+
19741999
return ecdsakey_dict
19752000

19762001

0 commit comments

Comments
 (0)