Commit graph

1293 commits

Author SHA1 Message Date
Jussi Kukkonen
b67b8c8ad3 Whitespace changes to make new black linter happy
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-06 15:29:28 +02:00
Lukas Pühringer
d2c12f2d14
Merge pull request #2165 from jku/no-key
Move (most of) Key to Securesystemslib
2023-01-31 09:20:44 +01:00
Jussi Kukkonen
f8a7881c87 Make RequestsFetcher public
This is useful for those who want to use the default fetcher
but modify some attributes

The file itself could be moved to tuf/ngclient/ but this is not done yet
as sigstore-python is using this internal module. Move can be done once
sigstore-python 1.0 is no longer relevant.

Fixes #2268

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-25 15:55:11 +02:00
Jussi Kukkonen
41b9b5c60b tests: Remove unnecessary ignores
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 14:31:22 +02:00
Jussi Kukkonen
ed0ec03399 Metadata API: Fix verify_delegate for new Key API
verify_delegate() unfortunately needs an almost complete rewrite
as the Key.verify_signature() API change affects it quite a bit.

Refactoring the role and key lookup into a separate method makes the
code readable again.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 14:31:22 +02:00
Jussi Kukkonen
b55ac25cf5 tests: Fix tests for Key.verify_signature()
Key.verify_signature() API has changed:
* argument is bytes, not metadata
* raised error now comes from securesystemslib

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 14:31:22 +02:00
Jussi Kukkonen
09971aea16 tests, examples: Stop using Key constructors
New Securesystemslib Keys can now be instantiated in two ways:
* deserialize via Key.from_dict() as before
* generate new keys via implementation specific methods

Fix all cases where we call Key() or Key.from_securesystemslib_key()
and use SSlibKey methods instead. Fix related tests.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 14:31:22 +02:00
Lukas Pühringer
216ae641f7
Merge pull request #2193 from jku/repository-lib
Repository module and example
2022-12-19 09:28:05 +01:00
Jussi Kukkonen
4d99f78cf9 Rename manual repository example
I plan to add another repository example as well.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-28 12:13:00 +02:00
Jussi Kukkonen
6450a3a8ff ngclient: Fail gracefully on missing role
If role is delegated but missing from snapshot, we currently raise a
undocumented KeyError: a generic RepositoryError seems better as callers
are expected to handle it (and adding a more specific error seems
useless as this is a repository software bug, not just expired metadata or
something).

The same check is also done later in TrustedMetadataSet but I think
keeping the check in both is clearest.

Fixes #2195

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-28 11:20:31 +02:00
n-dusan
604eef2ffd fix: allow length to be zero
* As per TUF specification, length attribute is a numerical value (which
  can include 0) -
  https://theupdateframework.github.io/specification/latest/#metapath-length

fix: update tests
Signed-off-by: n-dusan <nikolic.dusan.dey@gmail.com>
2022-10-12 13:02:41 +02:00
Martin Vrachev
26e748e0c1 Bump supported spec version to 1.0.31
Bump the supported specification version to 1.0.31 and additionally
update the generated test metadata as it has to be up to date with the
latest changes.

The new changes in the specification version 1.0.31 clarify the
requirement for the new root version as compared to the old root version
in step 5.3.5:
https://theupdateframework.github.io/specification/latest/#update-root

We already do what the specification suggests in the new changes, so
no other changes are required.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-09-26 17:56:15 +03:00
Lukas Pühringer
a773e8f695
Merge pull request #2038 from MVrachev/tap15-example
Add an example script about succinct roles usage
2022-08-12 12:11:42 +02:00
Jussi Kukkonen
01b30ccd2d tests: Improve succinct download test
* move to the test file that contains all the other download tests
* don't write 1000 files: it can be slow in CI
* Compare file content to what was originally written
  (also read the whole file content)
* Remove try-except that seems unused

Signed-off-by: Jussi Kukkonen <jku@goto.fi>
2022-08-08 18:58:37 +03:00
Martin Vrachev
a872eb5b6d Hash bin delegation example: save versioned files
If we have a goal of making metadata that can just be served to clients,
then these (and the parent metadata) should have versioned filenames.
Change the file names of the delegated files in the
hashed_bin_delegation.py to versioned.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-21 22:39:31 +03:00
Martin Vrachev
b8ea2fb9b9 Add an example script about succinct roles usage
Add a basic example script showing all features of the succinct hash bin
delegations and the available API calls of SuccinctRoles.

The explanations are used to promote the usage of succinct hash bin
delegations by explaining it well enough so our users can understand
the API limitations and how to use them and at the same time I tried not
going into too many details of the SuccinctRoles math as its
implementation is inside tuf/api/metadata.py and there there are
explanations about that.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-21 22:39:31 +03:00
Martin Vrachev
7d389f3fcd Downloading from a repository with many targets
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-20 19:09:51 +03:00
Martin Vrachev
e94dca6d1a Tests: download a target with succonct_roles
Add test downloading a target file when succonct_roles is used and as
such test the whole updater downloading workflow.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-20 17:42:47 +03:00
Jussi Kukkonen
b68df2ba65
Merge pull request #2035 from MVrachev/bump-spec-version
Bump supported spec version to 1.0.30
2022-07-04 12:07:11 +03:00
Jussi Kukkonen
8a03abfdeb
Merge pull request #2039 from MVrachev/add-test-case
SuccinctRoles.is_delegated_role() add a test case
2022-06-27 22:14:19 +03:00
Abhisman Sarkar
9f1c86f4a9 Grammar Fix
Fixed a grammatical error in a comment in utils.py

Signed-off-by: Abhisman Sarkar <abhisman.sarkar@gmail.com>
2022-06-27 18:09:43 +05:30
Martin Vrachev
ddbbcce432 SuccinctRoles.is_delegated_role() add test case
Add a test case when there is a bin name with the desired prefix, but
which cannot be cast to a hexadecimal number.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-24 16:48:56 +03:00
Martin Vrachev
773e8f4d3e Bump supported spec version to 1.0.30
Bump the supported specification version to 1.0.30 and additionally
update the generated test metadata as it has to be up to date with the
latest changes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-22 12:41:39 +03:00
Martin Vrachev
5fd3ddccbc ngclient: pick old timestamp if new.ver is equal
In the spec version 1.0.30, a new change has been added considering what
should happen if there is a new timestamp with the same version.
It says the following:
"In case they [versions] are equal, discard the new
timestamp metadata and abort the update cycle.
This is normal and it shouldn't raise any error."

In other words, if there is a new timestamp with the same version, then
stop the update process and use the old timestamp.

Those changes reflect these latest specification modifications.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-21 14:52:31 +03:00
Martin Vrachev
26abdfbbce Test delegation tree with succinct_roles
Test traversing the delegation tree when there is a Targets using a
delegation with succinct roles.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:01 +03:00
Martin Vrachev
4abb826eb5 RepositorySimulator: support succinct_roles
Add support for Targets using delegation with succinct_roles.
For that purpose, we needed a method that can add succinct_roles
information with its all corresponding bins to the target metadata
and self.md_delegates attribute in RepositorySimulator.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:01 +03:00
Martin Vrachev
28b6917739 Root and Targets key API changes
Here is the list of all breaking API changes:
1) The "role" and "key" arguments in "Root.add_key()" are in reverse
order - "key" becomes first and "role" second.
2) "Root.remove_key()" has been renamed to "Root.revoke_key()".
3) The "role" and "keyid" arguments in "Root.revoke_key()" are in
reverse order - "keyid" becomes first and "role" second.
4) The "role" and "key" arguments in "Targets.add_key()" are in reverse
order - "key" becomes first and "role" second.
5) "Targets.remove_key()" has been renamed to "Targets.revoke_key()".
6) The "role" and "keyid" arguments in "Targets.revoke_key()" are in
reverse order - "keyid" becomes first and "role" second.
7) In both methods "Targets.add_key()" and "Targets.revoke_key()" the
"role" argument becomes an optional with a default value of None.

Those changes are made in an effort to make those methods logical
for both cases when standard roles and succinct_roles are used.
The "Root" API change was done in order to preserve naming and argument
order consistency with "Targets" API.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:01 +03:00
Martin Vrachev
15cd42c0d6 Delegations: add support for succinct_roles
This commit contains 2 API changes in "Delegations" class from
tuf/api/metadata.py:
1. roles argment is made optional
2. unrecognized_fields argument becomes the 4-th rather than the 3-rd
as it used to be

In this commit, I add support for succinct_roles roles inside
Delegations class. This change is related to TAP 15 proposal.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:01 +03:00
Martin Vrachev
f80b4ca1d2 Clarifications and simplifications
Clarify explicitly that exactly one of "paths" and "path_hash_prefixes"
must be set inside DelegatedRole.
Also simplify the check for "paths" and "path_hash_prefixes".
Finally, add a test case inside the "test_metadata_serialization.py"
test file about wrong keyids type for "Role" serialization.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:01 +03:00
Martin Vrachev
0a92cb91e3 Add helper methods in SuccinctRoles
Add two helper methods in SuccinctRoles.
Those methods proved useful in the testing code, but I believe they have
a potential value for production code as well.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:00 +03:00
Martin Vrachev
9259ced68a Add SuccinctRole class
Add SuccinctRoles class containing the information from the
succint_roles dict described in TAP 15.
This allows for easy mypy checks on the types, easy enforcement on
TAP 15 restrictions (as for example that "bit_length" must be between 1
and 32) and support for unrecognized fields inside succinct_roles
without much of a hassle.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-09 20:30:30 +03:00
Martin Vrachev
6c2952fc2c Tests: simplify and shorten test_metadata_eq_.py
There is a lot of repetitive code inside test_metadata_eq_.py.
Remove it by using the decorator.

I am initializing the object instances in setUpClass instead of doing it
inside the test function in order to escape the need for
reinitialization of the instances on each attribute.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-08 14:31:41 +03:00
Jussi Kukkonen
3a7fad7854
Merge pull request #1960 from mnm678/spec-version
Update supported spec version
2022-04-20 09:57:24 +03:00
Jussi Kukkonen
b8acf5512d
Merge pull request #1953 from MVrachev/fix-eq-tests
Tests: restore objects to initial state after test
2022-04-20 09:57:12 +03:00
Marina Moore
70b27b0ef8 Regenerate tests with new spec version
Signed-off-by: Marina Moore <mnm678@gmail.com>
2022-04-19 10:31:07 -04:00
Lukas Pühringer
c2087b39e1
Merge pull request #1955 from jku/test-client-metadata-length-limits
tests: Test client max metadata length config
2022-04-19 15:47:47 +02:00
Ari
0708fb4a3b Reverted URL construction back to f-strings
Signed-off-by: Ari <aribasch@umich.edu>
2022-04-18 12:21:44 -04:00
Ari
d867debb77 Replaced manual path construction with os.path.join
Signed-off-by: Ari <aribasch@umich.edu>
2022-04-18 12:21:44 -04:00
Jussi Kukkonen
17ec875cd8 tests: Test client max metadata length config
Fixes #1730

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-04-14 10:22:17 +03:00
Martin Vrachev
ce11102dee Tests: restore objects to initial state after test
Inside test_metadata_eq_.py we test the __eq__ implementations of all
classes. In order to do this, we change the attribute of the object and
then compare them to the unchanged version of those objects.
Usually, we do it in the following steps:
1. create an initial version "a"
2. create a copy of "a" called "b"
3. iterate all attributes inside "b" and change them to a given value
4. check that "a" and "b" are different

We do however forget to restore the object `b` to its initial state
which means we don't check the `__eq__` correctly as we stop on the
first, the found difference which could be of an older attribute changed
in one of the past iterations.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-04-13 16:28:31 +03:00
Lukas Pühringer
b3508471dc
Merge pull request #1922 from jku/constructor-defaults
Add default args to Signed constructors
2022-04-04 13:18:21 +02:00
Jussi Kukkonen
b17ae3fd8f
Merge pull request #1808 from ivanayov/delegated_hash_bins_tests
Add test coverage for delegated hash bins
2022-04-04 12:22:54 +03:00
Jussi Kukkonen
0bd8feccf8 tests: Small refactor of a test
Test was supposed to test a threshold that is higher than number of
signatures, but it actually was just using completely unsigned metadata.

This still doesn't test the case where _trusted_ metadata defines a
threshold that new metadata does not reach: only the case where new
metadata defines threshold that it does not meet (this case is covered
in updater tests though).

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-04-01 10:17:06 +03:00
Ivana Atanasova
59245a2c2e Add test coverage for delegated hash bins
This change adds tests coverage for `path_hash_prefixes` and
verifies that role names matching specific prefixed successfully
find and download the corresponding metadata files

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-31 15:28:47 +03:00
Jussi Kukkonen
4392574ddf tests: Remove unused variables from generate_md
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-24 14:20:03 +02:00
Jussi Kukkonen
220e854c8e tests: Use the default Metadata constructor args
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-23 17:32:04 +02:00
Jussi Kukkonen
b7b035aea1
Merge pull request #1758 from ivanayov/updater_api_input_validation
Add tests for Updater input validation
2022-03-23 15:17:48 +02:00
Martin Vrachev
384772efc3 Provide a way to generate a simple repository
I created a new script called "generate_md.py" which can be used
to easily generate a repository. Additionally, I created a new
test file making sure that the locally stored metadata files and
the newly generated metadata roles are the same.
This will allow us to test that we are not changing the metadata
file structure when making changes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-03-22 18:13:54 +02:00
Ivana Atanasova
8d4d9af70b Update expired metadata tests logic
This change improves the logic of expired metadata tests, so that
it is explicitly visible what the expiry time and the versions are
and when update/refresh is called in that period

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 22:01:33 +02:00
Ivana Atanasova
d8d0486514 Fix expired metadata tests
This change fixes the expired metadata tests to mock `datetime`
as previously they mocked `time` incorrectly, which did not affect
update methods, as they use `datetime.datetime.utcnow()` to
calculate now

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 19:53:50 +02:00