Skip to content

Commit a8094bd

Browse files
author
Lukas Puehringer
committed
Add TUF-specific schemas removed in sslib
Add schemas KEYDB_SCHEMA, SIGNATURESTATUS_SCHEMA and VERSIONINFO_SCHEMA, removed in secure-systems-lab/securesystemslib#165 as TUF specific, and adopt usage accordingly. NOTE: The usefulness of these schemas may be assessed in a different PR. Signed-off-by: Lukas Puehringer <[email protected]>
1 parent d24c37f commit a8094bd

File tree

7 files changed

+40
-15
lines changed

7 files changed

+40
-15
lines changed

tests/test_formats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_schemas(self):
145145
{'keyid': '123abc',
146146
'sig': 'A4582BCF323BCEF'}),
147147

148-
'SIGNATURESTATUS_SCHEMA': (securesystemslib.formats.SIGNATURESTATUS_SCHEMA,
148+
'SIGNATURESTATUS_SCHEMA': (tuf.formats.SIGNATURESTATUS_SCHEMA,
149149
{'threshold': 1,
150150
'good_sigs': ['123abc'],
151151
'bad_sigs': ['123abc'],
@@ -164,7 +164,7 @@ def test_schemas(self):
164164
'keyval': {'public': 'pubkey',
165165
'private': 'privkey'}}}),
166166

167-
'KEYDB_SCHEMA': (securesystemslib.formats.KEYDB_SCHEMA,
167+
'KEYDB_SCHEMA': (tuf.formats.KEYDB_SCHEMA,
168168
{'123abc': {'keytype': 'rsa',
169169
'scheme': 'rsassa-pss-sha256',
170170
'keyid': '123456789abcdef',
@@ -738,7 +738,7 @@ def test_make_versioninfo(self):
738738
version_number = 8
739739
versioninfo = {'version': version_number}
740740

741-
VERSIONINFO_SCHEMA = securesystemslib.formats.VERSIONINFO_SCHEMA
741+
VERSIONINFO_SCHEMA = tuf.formats.VERSIONINFO_SCHEMA
742742
make_versioninfo = tuf.formats.make_versioninfo
743743
self.assertTrue(VERSIONINFO_SCHEMA.matches(make_versioninfo(version_number)))
744744

tests/test_sig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_get_signature_status_no_role(self):
6666

6767
# A valid, but empty signature status.
6868
sig_status = tuf.sig.get_signature_status(signable)
69-
self.assertTrue(securesystemslib.formats.SIGNATURESTATUS_SCHEMA.matches(sig_status))
69+
self.assertTrue(tuf.formats.SIGNATURESTATUS_SCHEMA.matches(sig_status))
7070

7171
self.assertEqual(0, sig_status['threshold'])
7272
self.assertEqual([], sig_status['good_sigs'])

tuf/client/updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ def _versioninfo_has_been_updated(self, metadata_filename, new_versioninfo):
19731973
A dict object representing the new file information for
19741974
'metadata_filename'. 'new_versioninfo' may be 'None' when
19751975
updating 'root' without having 'snapshot' available. This
1976-
dict conforms to 'securesystemslib.formats.VERSIONINFO_SCHEMA' and has
1976+
dict conforms to 'tuf.formats.VERSIONINFO_SCHEMA' and has
19771977
the form:
19781978
19791979
{'version': 288}

tuf/formats.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import securesystemslib.schema as SCHEMA
7474

7575
import tuf
76+
import tuf.formats
7677

7778
import six
7879

@@ -85,12 +86,20 @@
8586
# check, and an ISO8601 string should be fully verified when it is parsed.
8687
ISO8601_DATETIME_SCHEMA = SCHEMA.RegularExpression(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z')
8788

89+
# An integer representing the numbered version of a metadata file.
90+
# Must be 1, or greater.
91+
METADATAVERSION_SCHEMA = SCHEMA.Integer(lo=0)
92+
93+
VERSIONINFO_SCHEMA = SCHEMA.Object(
94+
object_name = 'VERSIONINFO_SCHEMA',
95+
version = METADATAVERSION_SCHEMA)
96+
8897
# A dict holding the version or file information for a particular metadata
8998
# role. The dict keys hold the relative file paths, and the dict values the
9099
# corresponding version numbers and/or file information.
91100
FILEINFODICT_SCHEMA = SCHEMA.DictOf(
92101
key_schema = securesystemslib.formats.RELPATH_SCHEMA,
93-
value_schema = SCHEMA.OneOf([securesystemslib.formats.VERSIONINFO_SCHEMA,
102+
value_schema = SCHEMA.OneOf([VERSIONINFO_SCHEMA,
94103
securesystemslib.formats.FILEINFO_SCHEMA]))
95104

96105
# A string representing a role's name.
@@ -136,10 +145,6 @@
136145
minor = SCHEMA.Integer(lo=0),
137146
fix = SCHEMA.Integer(lo=0))
138147

139-
# An integer representing the numbered version of a metadata file.
140-
# Must be 1, or greater.
141-
METADATAVERSION_SCHEMA = SCHEMA.Integer(lo=0)
142-
143148
# A value that is either True or False, on or off, etc.
144149
BOOLEAN_SCHEMA = SCHEMA.Boolean()
145150

@@ -184,6 +189,26 @@
184189
key_schema = KEYID_SCHEMA,
185190
value_schema = KEY_SCHEMA)
186191

192+
# The format used by the key database to store keys. The dict keys hold a key
193+
# identifier and the dict values any object. The key database should store
194+
# key objects in the values (e.g., 'RSAKEY_SCHEMA', 'DSAKEY_SCHEMA').
195+
KEYDB_SCHEMA = SCHEMA.DictOf(
196+
key_schema = KEYID_SCHEMA,
197+
value_schema = SCHEMA.Any())
198+
199+
# A schema holding the result of checking the signatures of a particular
200+
# 'SIGNABLE_SCHEMA' role.
201+
# For example, how many of the signatures for the 'Target' role are
202+
# valid? This SCHEMA holds this information. See 'sig.py' for
203+
# more information.
204+
SIGNATURESTATUS_SCHEMA = SCHEMA.Object(
205+
object_name = 'SIGNATURESTATUS_SCHEMA',
206+
threshold = SCHEMA.Integer(),
207+
good_sigs = KEYIDS_SCHEMA,
208+
bad_sigs = KEYIDS_SCHEMA,
209+
unknown_sigs = KEYIDS_SCHEMA,
210+
untrusted_sigs = KEYIDS_SCHEMA)
211+
187212

188213
# A relative file path (e.g., 'metadata/root/').
189214
RELPATH_SCHEMA = SCHEMA.AnyString()
@@ -811,7 +836,7 @@ def make_versioninfo(version_number):
811836

812837
# Raise 'securesystemslib.exceptions.FormatError' if 'versioninfo' is
813838
# improperly formatted.
814-
securesystemslib.formats.VERSIONINFO_SCHEMA.check_match(versioninfo)
839+
VERSIONINFO_SCHEMA.check_match(versioninfo)
815840

816841
return versioninfo
817842

tuf/keydb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def create_keydb_from_root_metadata(root_metadata, repository_name='default'):
6565
<Purpose>
6666
Populate the key database with the unique keys found in 'root_metadata'.
6767
The database dictionary will conform to
68-
'securesystemslib.formats.KEYDB_SCHEMA' and have the form: {keyid: key,
68+
'tuf.formats.KEYDB_SCHEMA' and have the form: {keyid: key,
6969
...}. The 'keyid' conforms to 'securesystemslib.formats.KEYID_SCHEMA' and
7070
'key' to its respective type. In the case of RSA keys, this object would
7171
match 'RSAKEY_SCHEMA'.

tuf/repository_lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ def get_metadata_versioninfo(rolename, repository_name):
11311131
"""
11321132
<Purpose>
11331133
Retrieve the version information of 'rolename'. The object returned
1134-
conforms to 'securesystemslib.VERSIONINFO_SCHEMA'. The information
1134+
conforms to 'tuf.formats.VERSIONINFO_SCHEMA'. The information
11351135
generated for 'rolename' is stored in 'snapshot.json'.
11361136
The versioninfo object returned has the form:
11371137
@@ -1156,7 +1156,7 @@ def get_metadata_versioninfo(rolename, repository_name):
11561156
None.
11571157
11581158
<Returns>
1159-
A dictionary conformant to 'securesystemslib.VERSIONINFO_SCHEMA'.
1159+
A dictionary conformant to 'tuf.formats.VERSIONINFO_SCHEMA'.
11601160
This dictionary contains the version number of 'rolename'.
11611161
"""
11621162

tuf/sig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def may_need_new_keys(signature_status):
336336
# This check will ensure 'signature_status' has the appropriate number
337337
# of objects and object types, and that all dict keys are properly named.
338338
# Raise 'securesystemslib.exceptions.FormatError' if the check fails.
339-
securesystemslib.formats.SIGNATURESTATUS_SCHEMA.check_match(signature_status)
339+
tuf.formats.SIGNATURESTATUS_SCHEMA.check_match(signature_status)
340340

341341
unknown = signature_status['unknown_sigs']
342342
untrusted = signature_status['untrusted_sigs']

0 commit comments

Comments
 (0)