Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to the newest version of TUF #561

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
60b8fa9
Update tuf, securesystemslib and cryptography deps
lukpueh Aug 23, 2024
f62907e
Add alternative TUF metadata repo implementation
lukpueh Aug 23, 2024
ad2b58f
Change create and add_keys API to take signers
lukpueh Aug 26, 2024
b46645b
Make sure targets is signed on add key
lukpueh Aug 26, 2024
33750eb
Assert keytype rsa in taf.tuf.keys helper
lukpueh Aug 27, 2024
42fbfac
Add signer implementation for Yubikeys
lukpueh Aug 28, 2024
25371d7
Comment out legacy imports (WIP)
lukpueh Aug 28, 2024
ec294a8
Merge branch 'feature/tuf-repositoty' into tuf-upgrade
renatav Oct 29, 2024
70927b7
Merge pull request #512 from lukpueh/tuf-upgrade
renatav Oct 29, 2024
9bf3fb9
feat: moved get threshold to the new repository class, implement dele…
renatav Oct 29, 2024
c7be3cb
refact: move get expiration date, get all targets and check expiratio…
renatav Oct 30, 2024
7601b9b
refact: move get role paths and all target files to the new repositor…
renatav Oct 30, 2024
b8d247e
refact: work on making the create repository method more flexible
renatav Oct 31, 2024
ade9af1
refact: extend creation of repositories using the new TUF, added supp…
renatav Oct 31, 2024
f1c1b6c
test: add create repository with delegations test
renatav Nov 1, 2024
ea05769
test: use repository created using create in tests
renatav Nov 1, 2024
c9857d0
test, refact: reorganize tests, implement keyid-roles mapping using t…
renatav Nov 1, 2024
b7eb34a
test: re-enabled add target test
renatav Nov 2, 2024
ccb94b8
refact: moved modify targets to the new repository class
renatav Nov 4, 2024
43af588
test: create test repos with target files and custom data
renatav Nov 5, 2024
feb7b53
refac, test: move get_all_target_files_state to the new repository cl…
renatav Nov 5, 2024
3202900
refact: move generate_roles_description to the new repository class
renatav Nov 5, 2024
af59138
test, refact: minor tests refactoring, reimplement is_valid_metadata_key
renatav Nov 6, 2024
51d63c9
refact: test: reimplement add metadata keys, enable keys tests
renatav Nov 6, 2024
e57b8e3
feat, test: implement revoke key
renatav Nov 7, 2024
abeaa2c
test, fix: minor add and revoke key improvements
renatav Nov 7, 2024
f3bc1f7
refact, test: initial work on reworking signing, add set expiration d…
renatav Nov 8, 2024
2681d4a
refact: remeve outdated imports
renatav Nov 8, 2024
0d67dd5
refact: check and set expiration date reimplemented
renatav Nov 8, 2024
ba7d3eb
refact: update key generation
renatav Nov 8, 2024
ea93127
refact: reimplement repository_at_revision
renatav Nov 9, 2024
4122100
refact: update updater and the creation of a new repository
renatav Nov 9, 2024
e21edfd
fix: bare repositories fix
renatav Nov 9, 2024
d9e5cc0
refact: reimplement addition of verification keys when creating a new…
renatav Nov 11, 2024
67fbc2b
fix: minor create repo fix
renatav Nov 11, 2024
c1cd853
refact: remove do_snapshot and timestamp from add/revoke keys
renatav Nov 11, 2024
7fe4d2f
refact: work on initializing repository and signers in api
renatav Nov 14, 2024
e77210b
fix, feat: fix add keys, add revoke key command
renatav Nov 14, 2024
947f1e4
test: add add delegated paths test
renatav Nov 14, 2024
5c56ede
refact: rework create new role
renatav Nov 15, 2024
c92c39b
refact: support adding multiple new roles
renatav Nov 15, 2024
f63a058
refact, fix: fix create delagations when no previouis delgations, rew…
renatav Nov 15, 2024
66a2742
refact: refactored remove paths
renatav Nov 16, 2024
2fe6d72
fix: minor fixes, update update-expiration-dates
renatav Nov 16, 2024
5ddb0c3
refact, test: remove unused code, remove paths test added
renatav Nov 16, 2024
dfbcde6
refact: rework targets update
renatav Nov 16, 2024
c541df8
test: add update targets roles test
renatav Nov 18, 2024
45c8c02
refact: reimplement add target repo
renatav Nov 19, 2024
4917b71
refact: rework remove target repo
renatav Nov 19, 2024
2f817d3
refact: update add/remove dependencies
renatav Nov 19, 2024
de7f5f8
test, refact: refact repository init tests, remove outdated tests
renatav Nov 19, 2024
96c7df1
test: work on refactoring test_create_repository tests
renatav Nov 20, 2024
7a787f4
test, refact: reorganize conftest
renatav Nov 20, 2024
1b7146b
test: rework test dependencies, metadata and roles api tests
renatav Nov 21, 2024
c5de6e1
chore: remove ramaining test repos
renatav Nov 21, 2024
739c014
test: refact test targets
renatav Nov 21, 2024
4fd29db
test, refact: update repositoriesdb tests, some refactoring, remove u…
renatav Nov 21, 2024
fbc0a8a
fix: fix snapshot info length/hash issue
renatav Nov 22, 2024
68fb96e
feat: initial implementation of git storage backed, which can load me…
renatav Nov 22, 2024
84a52f2
fix: bypass storage singleton
renatav Nov 22, 2024
8224179
fix: update root version number when updating snaphost. Work on updat…
renatav Nov 25, 2024
5afeaf5
test: update test_update_invalid
renatav Nov 26, 2024
6573a6a
fix: fix update expiration dates. Snapshot info was not getting updated
renatav Nov 27, 2024
959ab49
test: update remaining updater tests, minor cleanup
renatav Nov 27, 2024
16abe0c
chore: cleanup, formatting, remove unused code and imports
renatav Nov 27, 2024
4f02ce1
chore: bump yubikey-manager version
renatav Nov 27, 2024
62a8cac
chore: fixing mypy issues
renatav Nov 27, 2024
cb5b45a
chore: import and mypy issues
renatav Nov 27, 2024
2070426
chore: mypy issues
renatav Nov 27, 2024
106836c
chore: remove unused import
renatav Nov 27, 2024
896eb73
chore: comment out yubukey tests
renatav Nov 27, 2024
f262d81
test: remove generation of tests
renatav Nov 27, 2024
324e642
chore: formatting
renatav Nov 27, 2024
ea6dbf2
test: fix a number of failing tests
renatav Nov 28, 2024
32b2930
chore: remove unused import
renatav Nov 28, 2024
b37a631
test: rework keys tests
renatav Nov 28, 2024
d3d7263
test: update number of root keys in updater keys description
renatav Nov 29, 2024
3000095
fix: fix failing tests
renatav Nov 29, 2024
65c128b
refact: update yubikey cli functions
renatav Nov 29, 2024
4805128
test: refact yubikey tests
renatav Nov 30, 2024
789b591
refact: refactor creation of repositories using yubikeys
renatav Nov 30, 2024
ff146df
chore: formatting and mypy fixes
renatav Nov 30, 2024
e402196
test: add pytest-mock to test requirements
renatav Nov 30, 2024
de1bd82
Merge branch 'master' into feature/tuf-repositoty
renatav Nov 30, 2024
da5344d
chore: update changelog
renatav Nov 30, 2024
2f16959
chore: merge master
renatav Nov 30, 2024
f22da80
test: tun tests without having ykman installed
renatav Dec 4, 2024
7db3588
chore: ignore unused import
renatav Dec 4, 2024
6410f52
docs: GitStorageBackend docstring
renatav Dec 4, 2024
4ab8c48
feat: add a command for rotating keys
renatav Dec 9, 2024
dc431c5
test: add test revoke signing key test
renatav Dec 9, 2024
5ea21e7
docs: update docs related to repository classes
renatav Dec 10, 2024
bef7f8e
chore: merge master and resolve conflicts
renatav Dec 13, 2024
4490e9b
docs: add/update a number of metadata repository docstrings
renatav Dec 19, 2024
81e0799
docs: add docstrings to metadata repository
renatav Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions taf/repository_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,56 +416,6 @@ def get_all_target_files_state(self):

return added_target_files, removed_target_files

def get_signed_target_files(self):
"""Return all target files signed by all roles.

Args:
- None

Returns:
- Set of all target paths relative to targets directory
"""
all_roles = self.get_all_targets_roles()
return self.get_singed_target_files_of_roles(all_roles)

def get_singed_target_files_of_roles(self, roles):
"""Return all target files signed by the specified roles

Args:
- roles whose target files will be returned

Returns:
- Set of paths of target files of a role relative to targets directory
"""
if roles is None:
roles = self.get_all_targets_roles()
return set(
reduce(
operator.iconcat,
[self._role_obj(role).target_files for role in roles],
[],
)
)

def get_signed_targets_with_custom_data(self, roles):
"""Return all target files signed by the specified roles and and their custom data
as specified in the metadata files

Args:
- roles whose target files will be returned

Returns:
- A dictionary whose keys are parts of target files relative to the targets directory
and values are custom data dictionaries.
"""
if roles is None:
roles = self.get_all_targets_roles()
target_files = {}
for role in roles:
roles_targets = self._role_obj(role).target_files
for target_file, custom_data in roles_targets.items():
target_files.setdefault(target_file, {}).update(custom_data)
return target_files

def modify_targets(self, added_data=None, removed_data=None):
"""Creates a target.json file containing a repository's commit for each repository.
Expand Down
45 changes: 20 additions & 25 deletions taf/tests/tuf/conftest.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
from collections import defaultdict
import json
import re

import pytest
from taf.models.types import RolesKeysData
from taf.tests.test_api.conftest import REPOSITORY_DESCRIPTION_INPUT_DIR
from taf.tuf.keys import load_public_key_from_file, load_signer_from_file
from taf.tests.test_repository.test_repo import MetadataRepository
from taf.models.converter import from_dict
from taf.tuf.keys import load_signer_from_file

from taf.tests.tuf import TEST_DATA_PATH
NO_YUBIKEYS_INPUT = REPOSITORY_DESCRIPTION_INPUT_DIR / "no_yubikeys.json"
WITH_DELEGATIONS = REPOSITORY_DESCRIPTION_INPUT_DIR / "with_delegations_no_yubikeys.json"


@pytest.fixture

@pytest.fixture(scope="module")
def keystore():
"""Create signer from some rsa test key."""
return TEST_DATA_PATH / "keystores" / "keystore"

@pytest.fixture

@pytest.fixture(scope="module")
def keystore_delegations():
"""Create signer from some rsa test key."""
return TEST_DATA_PATH / "keystores" / "keystore_no_delegations"


@pytest.fixture
@pytest.fixture(scope="module")
def no_yubikeys_input():
return json.loads(NO_YUBIKEYS_INPUT.read_text())


@pytest.fixture
@pytest.fixture(scope="module")
def with_delegations_no_yubikeys_input():
return json.loads(WITH_DELEGATIONS.read_text())


@pytest.fixture
@pytest.fixture(scope="module")
def signers(keystore):
return _load_signers_from_keystore(keystore)


@pytest.fixture
@pytest.fixture(scope="module")
def signers_with_delegations(keystore_delegations):
return _load_signers_from_keystore(keystore_delegations)


@pytest.fixture
def tuf_repo(tmp_path, signers, no_yubikeys_input):
# Create new metadata repository
tuf_repo = MetadataRepository(tmp_path)
roles_keys_data = from_dict(no_yubikeys_input, RolesKeysData)
tuf_repo.create(roles_keys_data, signers)
yield tuf_repo
@pytest.fixture(scope="module")
def public_keys(signers):
return {
role_name: [signer.public_key for signer in signers] for role_name, signers in signers.items()
}


@pytest.fixture
def tuf_repo_with_delegations(tmp_path, signers_with_delegations, with_delegations_no_yubikeys_input):
# Create new metadata repository
tuf_repo = MetadataRepository(tmp_path)
roles_keys_data = from_dict(with_delegations_no_yubikeys_input, RolesKeysData)
tuf_repo.create(roles_keys_data, signers_with_delegations)
yield tuf_repo
@pytest.fixture(scope="module")
def public_keys_with_delegations(signers_with_delegations):
return {
role_name: [signer.public_key for signer in signers] for role_name, signers in signers_with_delegations.items()
}


def _load_signers_from_keystore(keystore):
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from taf.tests.test_repository.test_repo import MetadataRepository
from taf.models.converter import from_dict
from taf.tuf.keys import _get_legacy_keyid
from tuf.api.metadata import Targets


def test_create_without_delegations(tmp_path, signers, no_yubikeys_input):
Expand Down Expand Up @@ -96,3 +95,4 @@ def _get_pub_key_ids(role):
# assert repo cannot be created twice
with pytest.raises(FileExistsError):
tuf_repo.create(roles_keys_data, signers_with_delegations)

70 changes: 70 additions & 0 deletions taf/tests/tuf/test_create_edit_repo/test_targets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# def test_add_target_files(self, tmp_path, test_signers):
# """Edit metadata repository.

# If we edit manually, we need to make sure to create a valid snapshot.
# """
# # Create new metadata repository
# repo = MetadataRepository(tmp_path)
# repo.create(test_signers)

# target_file = TargetFile.from_data("foo.txt", b"foo", ["sha256", "sha512"])

# # assert add target file and correct version bumps
# repo.add_target_files([target_file])
# assert repo.targets().targets[target_file.path] == target_file
# assert repo.root().version == 1
# assert repo.timestamp().version == 2
# assert repo.snapshot().version == 2
# assert repo.targets().version == 2
# assert repo.timestamp().snapshot_meta.version == 2
# assert repo.snapshot().meta["root.json"].version == 1
# assert repo.snapshot().meta["targets.json"].version == 2

# def test_add_keys(self, tmp_path, test_signers, test_signer2):
# repo = MetadataRepository(tmp_path)
# repo.create(test_signers)

# # assert add new root key and version bumps (all but targets)
# repo.add_keys([test_signer2], "root")
# assert test_signer2.public_key.keyid in repo.root().keys
# assert test_signer2.public_key.keyid in repo.root().roles["root"].keyids
# assert repo.root().version == 2
# assert repo.timestamp().version == 2
# assert repo.snapshot().version == 2
# assert repo.targets().version == 1
# assert repo.timestamp().snapshot_meta.version == 2
# assert repo.snapshot().meta["root.json"].version == 2
# assert repo.snapshot().meta["targets.json"].version == 1

# # assert add new timestamp key and version bumps (all but targets)
# repo.add_keys([test_signer2], "timestamp")
# assert test_signer2.public_key.keyid in repo.root().roles["timestamp"].keyids
# assert repo.root().version == 3
# assert repo.timestamp().version == 3
# assert repo.snapshot().version == 3
# assert repo.targets().version == 1
# assert repo.timestamp().snapshot_meta.version == 3
# assert repo.snapshot().meta["root.json"].version == 3
# assert repo.snapshot().meta["targets.json"].version == 1

# # assert add new snapshot key and version bumps (all but targets)
# repo.add_keys([test_signer2], "snapshot")
# assert test_signer2.public_key.keyid in repo.root().roles["snapshot"].keyids
# assert repo.root().version == 4
# assert repo.timestamp().version == 4
# assert repo.snapshot().version == 4
# assert repo.targets().version == 1
# assert repo.timestamp().snapshot_meta.version == 4
# assert repo.snapshot().meta["root.json"].version == 4
# assert repo.snapshot().meta["targets.json"].version == 1

# # assert add new targets key and version bumps (all)
# repo.add_keys([test_signer2], "targets")
# assert test_signer2.public_key.keyid in repo.root().roles["targets"].keyids
# assert repo.root().version == 5
# assert repo.timestamp().version == 5
# assert repo.snapshot().version == 5
# assert repo.targets().version == 2
# assert repo.timestamp().snapshot_meta.version == 5
# assert repo.snapshot().meta["root.json"].version == 5
# assert repo.snapshot().meta["targets.json"].version == 2
37 changes: 37 additions & 0 deletions taf/tests/tuf/test_query_repo/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

import shutil
from taf.tests.conftest import CLIENT_DIR_PATH
from taf.utils import on_rm_error
import pytest
from taf.models.types import RolesKeysData
from taf.tests.test_repository.test_repo import MetadataRepository
from taf.models.converter import from_dict


@pytest.fixture(scope="module", autouse=True)
def repo_dir():
path = CLIENT_DIR_PATH / "tuf"
path.mkdir()
yield path
shutil.rmtree(path, onerror=on_rm_error)

@pytest.fixture(scope="module")
def tuf_repo(repo_dir, signers, no_yubikeys_input):
# Create new metadata repository
path = repo_dir / "repository_without_delegations"
path.mkdir()
tuf_repo = MetadataRepository(path)
roles_keys_data = from_dict(no_yubikeys_input, RolesKeysData)
tuf_repo.create(roles_keys_data, signers)
yield tuf_repo


@pytest.fixture(scope="module")
def tuf_repo_with_delegations(repo_dir, signers_with_delegations, with_delegations_no_yubikeys_input):
# Create new metadata repository
path = repo_dir / "repository_with_delegations"
path.mkdir()
tuf_repo = MetadataRepository(path)
roles_keys_data = from_dict(with_delegations_no_yubikeys_input, RolesKeysData)
tuf_repo.create(roles_keys_data, signers_with_delegations)
yield tuf_repo
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,21 @@ def test_signing_roles(tuf_repo_with_delegations):
def test_get_role_from_target_paths(tuf_repo_with_delegations):
assert tuf_repo_with_delegations.get_role_from_target_paths(["dir1/file1.txt", "dir1/file2.txt"]) == "delegated_role"

# def test_find_keys_roles(targets_key):
# test_group_dir = TEST_DATA_REPOS_PATH / "test-repository-tool/test-delegated-roles-pkcs1v15" / "taf"
# tuf_repo = MetadataRepository(test_group_dir)
# tuf_repo.find_keys_roles([targets_key])
def test_find_keys_roles(tuf_repo_with_delegations, public_keys_with_delegations):
target_keys = public_keys_with_delegations["targets"]
delegated_role_keys = public_keys_with_delegations["delegated_role"]
actual = tuf_repo_with_delegations.find_keys_roles(target_keys + delegated_role_keys)
assert actual == ["targets", "delegated_role"]
actual = tuf_repo_with_delegations.find_keys_roles(target_keys[2:] + delegated_role_keys)
assert actual == ["delegated_role"]
root_keys = public_keys_with_delegations["root"]
actual = tuf_repo_with_delegations.find_keys_roles(root_keys)
assert actual == ["root"]

def test_find_associated_roles_of_key(tuf_repo_with_delegations, public_keys_with_delegations):
for role in ("root", "targets", "snapshot", "timestamp", "delegated_role", "inner_role"):
key = public_keys_with_delegations[role][0]
assert tuf_repo_with_delegations.find_associated_roles_of_key(key) == [role]


# def test_all_target_files():
Expand Down
82 changes: 0 additions & 82 deletions taf/tests/tuf/test_repository.py

This file was deleted.

Loading
Loading