Skip to content

Commit 1e0d3f1

Browse files
committed
Add initial poc for RSA Accumulator snapshots: repo side
This commit uses a custom python implementation of Miller-Rabin that we will want to replace with a well-maintained library. It does not include efficient updates to the RSA Accumulator Signed-off-by: Marina Moore <mnm678@gmail.com>
1 parent 2045e6a commit 1e0d3f1

5 files changed

Lines changed: 133 additions & 211 deletions

File tree

tests/test_repository_lib.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -467,62 +467,36 @@ def test_generate_targets_metadata(self):
467467
False, use_existing_fileinfo=True)
468468

469469

470-
def test_build_merkle_tree(self):
470+
def test_build_rsa_acc(self):
471471
temporary_directory = tempfile.mkdtemp(dir=self.temporary_directory)
472472
storage_backend = securesystemslib.storage.FilesystemBackend()
473473
version = 1
474474

475-
# Test building the tree one node at a time to verify the hashes
475+
# Test an rsa accumulator with a few nodes to verify the output
476476

477477
test_nodes = {}
478478
test_nodes['file1'] = tuf.formats.make_metadata_fileinfo(5, None, None)
479479

480-
root_1, leaves = repo_lib._build_merkle_tree(test_nodes)
481-
repo_lib._write_merkle_paths(root_1, leaves, storage_backend,
482-
temporary_directory, version)
483-
484-
file_path = os.path.join(temporary_directory, 'file1-snapshot.json')
485-
self.assertTrue(os.path.exists(file_path))
486-
487-
file_path = os.path.join(temporary_directory, '1.file1-snapshot.json')
488-
self.assertTrue(os.path.exists(file_path))
489-
490-
test_nodes['file2'] = tuf.formats.make_metadata_fileinfo(5, None, None)
491-
root_2, leaves = repo_lib._build_merkle_tree(test_nodes)
492-
493-
self.assertEqual(root_2.left.digest, root_1.digest)
494480

495-
test_nodes['file3'] = tuf.formats.make_metadata_fileinfo(5, None, None)
496-
test_nodes['file4'] = tuf.formats.make_metadata_fileinfo(5, None, None)
497-
498-
root_3, leaves = repo_lib._build_merkle_tree(test_nodes)
499-
500-
self.assertEqual(root_3.left.digest, root_2.digest)
501-
502-
test_nodes['file5'] = tuf.formats.make_metadata_fileinfo(5, None, None)
503-
504-
root_4, leaves = repo_lib._build_merkle_tree(test_nodes)
505-
506-
repo_lib._write_merkle_paths(root_4, leaves, storage_backend,
507-
temporary_directory, version + 1)
508-
509-
self.assertEqual(root_4.left.digest, root_3.digest)
481+
root_1, leaves = repo_lib._build_rsa_acc(test_nodes)
482+
repo_lib._write_rsa_leaves(root_1, leaves, storage_backend,
483+
temporary_directory, version)
510484

511485
# Ensure that the paths are written to the directory
512486
file_path = os.path.join(temporary_directory, 'file1-snapshot.json')
513487
self.assertTrue(os.path.exists(file_path))
514488

515-
file_path = os.path.join(temporary_directory, '2.file1-snapshot.json')
489+
file_path = os.path.join(temporary_directory, '1.file1-snapshot.json')
516490
self.assertTrue(os.path.exists(file_path))
517491

518-
# repo_lib.print_merkle_tree(root_4)
492+
self.assertEqual(root_1, 5)
519493

520494
test_nodes = {}
521495
test_nodes['targets'] = tuf.formats.make_metadata_fileinfo(1, None, None)
522496
test_nodes['role1'] = tuf.formats.make_metadata_fileinfo(1, None, None)
523497
test_nodes['role2'] = tuf.formats.make_metadata_fileinfo(1, None, None)
524498

525-
root, leaves = repo_lib._build_merkle_tree(test_nodes)
499+
root, leaves = repo_lib._build_rsa_acc(test_nodes)
526500

527501

528502

tests/test_repository_tool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,20 @@ def test_writeall(self):
255255
# Verify that status() does not raise an exception.
256256
repository.status()
257257

258-
# Test writeall with generating a snapshot merkle tree
258+
# Test writeall with generating a snapshot RSA accumulator
259259
repository.mark_dirty(['role1', 'targets', 'root', 'snapshot', 'timestamp'])
260-
repository.writeall(snapshot_merkle=True)
260+
repository.writeall(rsa_acc=True)
261261

262-
# Were the merkle snapshots written?
262+
# Were the RSA proof snapshots written?
263263
targets_snapshot_filepath = os.path.join(metadata_directory,
264264
'targets-snapshot.json')
265265
targets_snapshot = securesystemslib.util.load_json_file(targets_snapshot_filepath)
266-
tuf.formats.SNAPSHOT_MERKLE_SCHEMA.check_match(targets_snapshot)
266+
tuf.formats.SNAPSHOT_RSA_ACC_SCHEMA.check_match(targets_snapshot)
267267

268268
# Does timestamp have the root hash?
269269
timestamp_filepath = os.path.join(metadata_directory, 'timestamp.json')
270270
timestamp = securesystemslib.util.load_json_file(timestamp_filepath)
271-
timestamp['signed']['merkle_root']
271+
timestamp['signed']['rsa_acc']
272272

273273
# Verify that status() does not raise
274274
# 'tuf.exceptions.InsufficientKeysError' if a top-level role
@@ -512,7 +512,7 @@ def test_get_filepaths_in_directory(self):
512512
expected_files = []
513513
for filepath in ['1.root.json', 'root.json', 'targets.json',
514514
'snapshot.json', 'timestamp.json', 'role1.json', 'role2.json',
515-
'targets-snapshot.json', 'timestamp-merkle.json',
515+
'targets-snapshot.json', 'timestamp-rsa.json',
516516
'role1-snapshot.json', 'role2-snapshot.json']:
517517
expected_files.append(os.path.abspath(os.path.join(
518518
'repository_data', 'repository', 'metadata', filepath)))

tuf/formats.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,10 @@
366366
targets = FILEDICT_SCHEMA,
367367
delegations = SCHEMA.Optional(DELEGATIONS_SCHEMA))
368368

369-
SNAPSHOT_MERKLE_SCHEMA = SCHEMA.Object(
369+
SNAPSHOT_RSA_ACC_SCHEMA = SCHEMA.Object(
370370
leaf_contents = SCHEMA.OneOf([VERSIONINFO_SCHEMA,
371371
METADATA_FILEINFO_SCHEMA]),
372-
merkle_path = SCHEMA.DictOf(key_schema=SCHEMA.AnyString(), value_schema=HASH_SCHEMA),
373-
path_directions = SCHEMA.DictOf(key_schema=SCHEMA.AnyString(), value_schema=SCHEMA.Integer()))
372+
rsa_acc_proof = SCHEMA.AnyString())
374373

375374
# Snapshot role: indicates the latest versions of all metadata (except
376375
# timestamp).
@@ -390,7 +389,7 @@
390389
version = METADATAVERSION_SCHEMA,
391390
expires = securesystemslib.formats.ISO8601_DATETIME_SCHEMA,
392391
meta = FILEINFODICT_SCHEMA,
393-
merkle_root = SCHEMA.Optional(HASH_SCHEMA))
392+
rsa_acc = SCHEMA.Optional(HASH_SCHEMA))
394393

395394

396395
# project.cfg file: stores information about the project in a json dictionary

0 commit comments

Comments
 (0)