Skip to content

Commit f6bd090

Browse files
author
lukpueh
authored
Merge pull request #912 from joshuagl/joshuagl/sslcompat
Use TUF specific formats as they have been removed from securesystemslib
2 parents 824e7db + ecb6d26 commit f6bd090

File tree

11 files changed

+66
-67
lines changed

11 files changed

+66
-67
lines changed

tests/test_formats.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def test_schemas(self):
7171

7272
'SCHEME_SCHEMA': (securesystemslib.formats.SCHEME_SCHEMA, 'rsassa-pss-sha256'),
7373

74-
'RELPATH_SCHEMA': (securesystemslib.formats.RELPATH_SCHEMA, 'metadata/root/'),
74+
'RELPATH_SCHEMA': (tuf.formats.RELPATH_SCHEMA, 'metadata/root/'),
7575

76-
'RELPATHS_SCHEMA': (securesystemslib.formats.RELPATHS_SCHEMA,
76+
'RELPATHS_SCHEMA': (tuf.formats.RELPATHS_SCHEMA,
7777
['targets/role1/', 'targets/role2/']),
7878

7979
'PATH_SCHEMA': (securesystemslib.formats.PATH_SCHEMA, '/home/someuser/'),
@@ -84,16 +84,16 @@ def test_schemas(self):
8484
'URL_SCHEMA': (securesystemslib.formats.URL_SCHEMA,
8585
'https://www.updateframework.com/'),
8686

87-
'VERSION_SCHEMA': (securesystemslib.formats.VERSION_SCHEMA,
87+
'VERSION_SCHEMA': (tuf.formats.VERSION_SCHEMA,
8888
{'major': 1, 'minor': 0, 'fix': 8}),
8989

90-
'LENGTH_SCHEMA': (securesystemslib.formats.LENGTH_SCHEMA, 8),
90+
'LENGTH_SCHEMA': (tuf.formats.LENGTH_SCHEMA, 8),
9191

9292
'NAME_SCHEMA': (securesystemslib.formats.NAME_SCHEMA, 'Marty McFly'),
9393

9494
'BOOLEAN_SCHEMA': (securesystemslib.formats.BOOLEAN_SCHEMA, True),
9595

96-
'THRESHOLD_SCHEMA': (securesystemslib.formats.THRESHOLD_SCHEMA, 1),
96+
'THRESHOLD_SCHEMA': (tuf.formats.THRESHOLD_SCHEMA, 1),
9797

9898
'ROLENAME_SCHEMA': (tuf.formats.ROLENAME_SCHEMA, 'Root'),
9999

tests/test_repository_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_get_target_hash(self):
417417
'/packages/file2.txt': 'c9c4a5cdd84858dd6a23d98d7e6e6b2aec45034946c16b2200bc317c75415e92'
418418
}
419419
for filepath, target_hash in six.iteritems(expected_target_hashes):
420-
self.assertTrue(securesystemslib.formats.RELPATH_SCHEMA.matches(filepath))
420+
self.assertTrue(tuf.formats.RELPATH_SCHEMA.matches(filepath))
421421
self.assertTrue(securesystemslib.formats.HASH_SCHEMA.matches(target_hash))
422422
self.assertEqual(repo_lib.get_target_hash(filepath), target_hash)
423423

tests/test_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ def test_9__get_target_hash(self):
15561556
'/Jalape\xc3\xb1o': '78bfd5c314680545eb48ecad508aceb861f8d6e680f4fe1b791da45c298cda88'
15571557
}
15581558
for filepath, target_hash in six.iteritems(expected_target_hashes):
1559-
self.assertTrue(securesystemslib.formats.RELPATH_SCHEMA.matches(filepath))
1559+
self.assertTrue(tuf.formats.RELPATH_SCHEMA.matches(filepath))
15601560
self.assertTrue(securesystemslib.formats.HASH_SCHEMA.matches(target_hash))
15611561
self.assertEqual(self.repository_updater._get_target_hash(filepath), target_hash)
15621562

tuf/client/updater.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ def targets_of_role(self, rolename='targets'):
26272627

26282628
# Does 'rolename' have the correct format?
26292629
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
2630-
securesystemslib.formats.RELPATH_SCHEMA.check_match(rolename)
2630+
tuf.formats.RELPATH_SCHEMA.check_match(rolename)
26312631

26322632
# If we've been given a delegated targets role, we don't know how to
26332633
# validate it without knowing what the delegating role is -- there could
@@ -2690,7 +2690,7 @@ def get_one_valid_targetinfo(self, target_filepath):
26902690

26912691
# Does 'target_filepath' have the correct format?
26922692
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
2693-
securesystemslib.formats.RELPATH_SCHEMA.check_match(target_filepath)
2693+
tuf.formats.RELPATH_SCHEMA.check_match(target_filepath)
26942694

26952695
target_filepath = target_filepath.replace('\\', '/')
26962696

tuf/developer_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def _save_project_configuration(metadata_directory, targets_directory,
694694
securesystemslib.formats.PATH_SCHEMA.check_match(metadata_directory)
695695
securesystemslib.formats.PATH_SCHEMA.check_match(prefix)
696696
securesystemslib.formats.PATH_SCHEMA.check_match(targets_directory)
697-
securesystemslib.formats.RELPATH_SCHEMA.check_match(project_name)
697+
tuf.formats.RELPATH_SCHEMA.check_match(project_name)
698698

699699
cfg_file_directory = metadata_directory
700700

tuf/download.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def safe_download(url, required_length):
110110
# Do all of the arguments have the appropriate format?
111111
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
112112
securesystemslib.formats.URL_SCHEMA.check_match(url)
113-
securesystemslib.formats.LENGTH_SCHEMA.check_match(required_length)
113+
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
114114

115115
return _download_file(url, required_length, STRICT_REQUIRED_LENGTH=True)
116116

@@ -161,7 +161,7 @@ def unsafe_download(url, required_length):
161161
# Do all of the arguments have the appropriate format?
162162
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
163163
securesystemslib.formats.URL_SCHEMA.check_match(url)
164-
securesystemslib.formats.LENGTH_SCHEMA.check_match(required_length)
164+
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
165165

166166
return _download_file(url, required_length, STRICT_REQUIRED_LENGTH=False)
167167

@@ -216,7 +216,7 @@ def _download_file(url, required_length, STRICT_REQUIRED_LENGTH=True):
216216
# Do all of the arguments have the appropriate format?
217217
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
218218
securesystemslib.formats.URL_SCHEMA.check_match(url)
219-
securesystemslib.formats.LENGTH_SCHEMA.check_match(required_length)
219+
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
220220

221221
# 'url.replace('\\', '/')' is needed for compatibility with Windows-based
222222
# systems, because they might use back-slashes in place of forward-slashes.

tuf/formats.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,43 @@
9595
# Must be 1, or greater.
9696
METADATAVERSION_SCHEMA = SCHEMA.Integer(lo=0)
9797

98+
# A relative file path (e.g., 'metadata/root/').
99+
RELPATH_SCHEMA = SCHEMA.AnyString()
100+
RELPATHS_SCHEMA = SCHEMA.ListOf(RELPATH_SCHEMA)
101+
98102
VERSIONINFO_SCHEMA = SCHEMA.Object(
99103
object_name = 'VERSIONINFO_SCHEMA',
100104
version = METADATAVERSION_SCHEMA)
101105

102-
# A dict holding the version or file information for a particular metadata
103-
# role. The dict keys hold the relative file paths, and the dict values the
104-
# corresponding version numbers and/or file information.
105-
FILEINFODICT_SCHEMA = SCHEMA.DictOf(
106-
key_schema = securesystemslib.formats.RELPATH_SCHEMA,
107-
value_schema = SCHEMA.OneOf([VERSIONINFO_SCHEMA,
108-
securesystemslib.formats.FILEINFO_SCHEMA]))
109-
110106
# A string representing a role's name.
111107
ROLENAME_SCHEMA = SCHEMA.AnyString()
112108

109+
# A role's threshold value (i.e., the minimum number
110+
# of signatures required to sign a metadata file).
111+
# Must be 1 and greater.
112+
THRESHOLD_SCHEMA = SCHEMA.Integer(lo=1)
113+
114+
# A hexadecimal value in '23432df87ab..' format.
115+
HEX_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+')
116+
117+
# A path hash prefix is a hexadecimal string.
118+
PATH_HASH_PREFIX_SCHEMA = HEX_SCHEMA
119+
120+
# A list of path hash prefixes.
121+
PATH_HASH_PREFIXES_SCHEMA = SCHEMA.ListOf(PATH_HASH_PREFIX_SCHEMA)
122+
113123
# Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1,
114124
# 'paths':[filepaths..]} format.
115125
# TODO: This is not a role. In further #660-related PRs, fix it, similar to
116126
# the way I did in Uptane's TUF fork.
117127
ROLE_SCHEMA = SCHEMA.Object(
118128
object_name = 'ROLE_SCHEMA',
119-
name = SCHEMA.Optional(securesystemslib.formats.ROLENAME_SCHEMA),
129+
name = SCHEMA.Optional(ROLENAME_SCHEMA),
120130
keyids = securesystemslib.formats.KEYIDS_SCHEMA,
121-
threshold = securesystemslib.formats.THRESHOLD_SCHEMA,
131+
threshold = THRESHOLD_SCHEMA,
122132
terminating = SCHEMA.Optional(securesystemslib.formats.BOOLEAN_SCHEMA),
123-
paths = SCHEMA.Optional(securesystemslib.formats.RELPATHS_SCHEMA),
124-
path_hash_prefixes = SCHEMA.Optional(securesystemslib.formats.PATH_HASH_PREFIXES_SCHEMA))
133+
paths = SCHEMA.Optional(RELPATHS_SCHEMA),
134+
path_hash_prefixes = SCHEMA.Optional(PATH_HASH_PREFIXES_SCHEMA))
125135

126136
# A dict of roles where the dict keys are role names and the dict values holding
127137
# the role data/information.
@@ -156,17 +166,9 @@
156166
# A string representing a role's name.
157167
ROLENAME_SCHEMA = SCHEMA.AnyString()
158168

159-
# A role's threshold value (i.e., the minimum number
160-
# of signatures required to sign a metadata file).
161-
# Must be 1 and greater.
162-
THRESHOLD_SCHEMA = SCHEMA.Integer(lo=1)
163-
164169
# A hexadecimal value in '23432df87ab..' format.
165170
HASH_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+')
166171

167-
# A hexadecimal value in '23432df87ab..' format.
168-
HEX_SCHEMA = SCHEMA.RegularExpression(r'[a-fA-F0-9]+')
169-
170172
# A key identifier (e.g., a hexadecimal value identifying an RSA key).
171173
KEYID_SCHEMA = HASH_SCHEMA
172174

@@ -214,17 +216,6 @@
214216
unknown_sigs = KEYIDS_SCHEMA,
215217
untrusted_sigs = KEYIDS_SCHEMA)
216218

217-
218-
# A relative file path (e.g., 'metadata/root/').
219-
RELPATH_SCHEMA = SCHEMA.AnyString()
220-
RELPATHS_SCHEMA = SCHEMA.ListOf(RELPATH_SCHEMA)
221-
222-
# A path hash prefix is a hexadecimal string.
223-
PATH_HASH_PREFIX_SCHEMA = HEX_SCHEMA
224-
225-
# A list of path hash prefixes.
226-
PATH_HASH_PREFIXES_SCHEMA = SCHEMA.ListOf(PATH_HASH_PREFIX_SCHEMA)
227-
228219
# Role object in {'keyids': [keydids..], 'name': 'ABC', 'threshold': 1,
229220
# 'paths':[filepaths..]} format.
230221
ROLE_SCHEMA = SCHEMA.Object(
@@ -260,6 +251,14 @@
260251
version = SCHEMA.Optional(METADATAVERSION_SCHEMA),
261252
custom = SCHEMA.Optional(SCHEMA.Object()))
262253

254+
# A dict holding the version or file information for a particular metadata
255+
# role. The dict keys hold the relative file paths, and the dict values the
256+
# corresponding version numbers and/or file information.
257+
FILEINFODICT_SCHEMA = SCHEMA.DictOf(
258+
key_schema = RELPATH_SCHEMA,
259+
value_schema = SCHEMA.OneOf([VERSIONINFO_SCHEMA,
260+
FILEINFO_SCHEMA]))
261+
263262
# A dict holding the information for a particular target / file. The dict keys
264263
# hold the relative file paths, and the dict values the corresponding file
265264
# information.
@@ -369,7 +368,7 @@
369368
SNAPSHOT_SCHEMA = SCHEMA.Object(
370369
object_name = 'SNAPSHOT_SCHEMA',
371370
_type = SCHEMA.String('snapshot'),
372-
version = securesystemslib.formats.METADATAVERSION_SCHEMA,
371+
version = METADATAVERSION_SCHEMA,
373372
expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA,
374373
spec_version = SPECIFICATION_VERSION_SCHEMA,
375374
meta = FILEINFODICT_SCHEMA)
@@ -379,9 +378,9 @@
379378
object_name = 'TIMESTAMP_SCHEMA',
380379
_type = SCHEMA.String('timestamp'),
381380
spec_version = SPECIFICATION_VERSION_SCHEMA,
382-
version = securesystemslib.formats.METADATAVERSION_SCHEMA,
381+
version = METADATAVERSION_SCHEMA,
383382
expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA,
384-
meta = securesystemslib.formats.FILEDICT_SCHEMA)
383+
meta = FILEDICT_SCHEMA)
385384

386385

387386
# project.cfg file: stores information about the project in a json dictionary
@@ -401,9 +400,9 @@
401400
MIRROR_SCHEMA = SCHEMA.Object(
402401
object_name = 'MIRROR_SCHEMA',
403402
url_prefix = securesystemslib.formats.URL_SCHEMA,
404-
metadata_path = securesystemslib.formats.RELPATH_SCHEMA,
405-
targets_path = securesystemslib.formats.RELPATH_SCHEMA,
406-
confined_target_dirs = securesystemslib.formats.RELPATHS_SCHEMA,
403+
metadata_path = RELPATH_SCHEMA,
404+
targets_path = RELPATH_SCHEMA,
405+
confined_target_dirs = RELPATHS_SCHEMA,
407406
custom = SCHEMA.Optional(SCHEMA.Object()))
408407

409408
# A dictionary of mirrors where the dict keys hold the mirror's name and
@@ -807,7 +806,7 @@ def make_fileinfo(length, hashes, version=None, custom=None):
807806
fileinfo['custom'] = custom
808807

809808
# Raise 'securesystemslib.exceptions.FormatError' if the check fails.
810-
securesystemslib.formats.FILEINFO_SCHEMA.check_match(fileinfo)
809+
FILEINFO_SCHEMA.check_match(fileinfo)
811810

812811
return fileinfo
813812

tuf/mirrors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_list_of_mirrors(file_type, file_path, mirrors_dict):
8484
"""
8585

8686
# Checking if all the arguments have appropriate format.
87-
securesystemslib.formats.RELPATH_SCHEMA.check_match(file_path)
87+
tuf.formats.RELPATH_SCHEMA.check_match(file_path)
8888
tuf.formats.MIRRORDICT_SCHEMA.check_match(mirrors_dict)
8989
securesystemslib.formats.NAME_SCHEMA.check_match(file_type)
9090

tuf/repository_lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ def get_target_hash(target_filepath):
12031203
The hash of 'target_filepath'.
12041204
12051205
"""
1206-
securesystemslib.formats.RELPATH_SCHEMA.check_match(target_filepath)
1206+
tuf.formats.RELPATH_SCHEMA.check_match(target_filepath)
12071207

12081208
# Calculate the hash of the filepath to determine which bin to find the
12091209
# target. The client currently assumes the repository uses
@@ -1416,7 +1416,7 @@ def generate_targets_metadata(targets_directory, target_files, version,
14161416
# types, and that all dict keys are properly named.
14171417
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
14181418
securesystemslib.formats.PATH_SCHEMA.check_match(targets_directory)
1419-
securesystemslib.formats.PATH_FILEINFO_SCHEMA.check_match(target_files)
1419+
tuf.formats.PATH_FILEINFO_SCHEMA.check_match(target_files)
14201420
tuf.formats.METADATAVERSION_SCHEMA.check_match(version)
14211421
securesystemslib.formats.ISO8601_DATETIME_SCHEMA.check_match(expiration_date)
14221422
securesystemslib.formats.BOOLEAN_SCHEMA.check_match(write_consistent_targets)

tuf/repository_tool.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def version(self):
10491049
"""
10501050
<Purpose>
10511051
A getter method that returns the role's version number, conformant to
1052-
'securesystemslib.formats.VERSION_SCHEMA'.
1052+
'tuf.formats.VERSION_SCHEMA'.
10531053
10541054
<Arguments>
10551055
None.
@@ -1062,7 +1062,7 @@ def version(self):
10621062
10631063
<Returns>
10641064
The role's version number, conformant to
1065-
'securesystemslib.formats.VERSION_SCHEMA'.
1065+
'tuf.formats.VERSION_SCHEMA'.
10661066
"""
10671067

10681068
roleinfo = tuf.roledb.get_roleinfo(self.rolename, self._repository_name)
@@ -1094,7 +1094,7 @@ def version(self, version):
10941094
<Arguments>
10951095
version:
10961096
The role's version number, conformant to
1097-
'securesystemslib.formats.VERSION_SCHEMA'.
1097+
'tuf.formats.VERSION_SCHEMA'.
10981098
10991099
<Exceptions>
11001100
securesystemslib.exceptions.FormatError, if the 'version' argument is
@@ -1140,7 +1140,7 @@ def threshold(self):
11401140
11411141
<Returns>
11421142
The role's threshold value, conformant to
1143-
'securesystemslib.formats.THRESHOLD_SCHEMA'.
1143+
'tuf.formats.THRESHOLD_SCHEMA'.
11441144
"""
11451145

11461146
roleinfo = tuf.roledb.get_roleinfo(self._rolename, self._repository_name)
@@ -1166,7 +1166,7 @@ def threshold(self, threshold):
11661166
threshold:
11671167
An integer value that sets the role's threshold value, or the minimum
11681168
number of signatures needed for metadata to be considered fully
1169-
signed. Conformant to 'securesystemslib.formats.THRESHOLD_SCHEMA'.
1169+
signed. Conformant to 'tuf.formats.THRESHOLD_SCHEMA'.
11701170
11711171
<Exceptions>
11721172
securesystemslib.exceptions.FormatError, if the 'threshold' argument is
@@ -1184,7 +1184,7 @@ def threshold(self, threshold):
11841184
# Ensure the arguments have the appropriate number of objects and object
11851185
# types, and that all dict keys are properly named. Raise
11861186
# 'securesystemslib.exceptions.FormatError' if any are improperly formatted.
1187-
securesystemslib.formats.THRESHOLD_SCHEMA.check_match(threshold)
1187+
tuf.formats.THRESHOLD_SCHEMA.check_match(threshold)
11881188

11891189
roleinfo = tuf.roledb.get_roleinfo(self._rolename, self._repository_name)
11901190
roleinfo['previous_threshold'] = roleinfo['threshold']
@@ -1983,7 +1983,7 @@ def add_targets(self, list_of_targets):
19831983
# Ensure the arguments have the appropriate number of objects and object
19841984
# types, and that all dict keys are properly named.
19851985
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
1986-
securesystemslib.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
1986+
tuf.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
19871987

19881988
# Update the tuf.roledb entry.
19891989
targets_directory_length = len(self._targets_directory)
@@ -2054,7 +2054,7 @@ def remove_target(self, filepath):
20542054
# Ensure the arguments have the appropriate number of objects and object
20552055
# types, and that all dict keys are properly named. Raise
20562056
# 'securesystemslib.exceptions.FormatError' if there is a mismatch.
2057-
securesystemslib.formats.RELPATH_SCHEMA.check_match(filepath)
2057+
tuf.formats.RELPATH_SCHEMA.check_match(filepath)
20582058

20592059
# Remove 'relative_filepath', if found, and update this Targets roleinfo.
20602060
fileinfo = tuf.roledb.get_roleinfo(self.rolename, self._repository_name)
@@ -2211,15 +2211,15 @@ def delegate(self, rolename, public_keys, paths, threshold=1,
22112211
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
22122212
tuf.formats.ROLENAME_SCHEMA.check_match(rolename)
22132213
securesystemslib.formats.ANYKEYLIST_SCHEMA.check_match(public_keys)
2214-
securesystemslib.formats.RELPATHS_SCHEMA.check_match(paths)
2215-
securesystemslib.formats.THRESHOLD_SCHEMA.check_match(threshold)
2214+
tuf.formats.RELPATHS_SCHEMA.check_match(paths)
2215+
tuf.formats.THRESHOLD_SCHEMA.check_match(threshold)
22162216
securesystemslib.formats.BOOLEAN_SCHEMA.check_match(terminating)
22172217

22182218
if list_of_targets is not None:
2219-
securesystemslib.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
2219+
tuf.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
22202220

22212221
if path_hash_prefixes is not None:
2222-
securesystemslib.formats.PATH_HASH_PREFIXES_SCHEMA.check_match(path_hash_prefixes)
2222+
tuf.formats.PATH_HASH_PREFIXES_SCHEMA.check_match(path_hash_prefixes)
22232223

22242224
# Keep track of the valid keyids (added to the new Targets object) and
22252225
# their keydicts (added to this Targets delegations).

0 commit comments

Comments
 (0)