Commit graph

294 commits

Author SHA1 Message Date
Lukas Pühringer
a871f648e5
Merge pull request #2378 from jku/move-verify-delegate-v2
Move verify_delegate() to Root/Targets
2023-08-21 13:27:01 +02:00
Satvik Vemuganti
ad117d9579 enhancement: Adds from_data() method to MetaFile
Signed-off-by: Satvik Vemuganti <vemugantisesha@iitbhilai.ac.in>
2023-08-16 06:08:34 +05:30
Lukas Puehringer
15dd931609 Metadata API: make new verify_delegate unaware of Metadata
Change new _Delegator.verify_delegate to take payload bytes and
signatures instead of a Metadata object and a payload serializer.

This allows using verify_delegate for payloads that do not come in
a Metadata container, but e.g. in a DSSE envelope (see #2385).

Usage becomes a bit more cumbersome, but still feels reasonable with the
recently added shortcut for default canonical bytes representation of
Metadata.signed.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2023-08-01 15:31:59 +02:00
Lukas Puehringer
fc6c91a711 Metadata API: add Metadata.signed_bytes property
- Add shortcut to canonical json representation of self.signed
- Use in tests and Metadata.sign
- Do not use in _Delegator.verify_delegate (will be updated in subsequent
  commit).

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2023-08-01 15:28:12 +02:00
Jussi Kukkonen
635a2870bd Metadata API: Bump deprecation version to next likely candidate
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-08-01 13:08:13 +02:00
Jussi Kukkonen
ca6434b081 Metadata API: Improve docstrings
Remove duplicate docstrings: these are already documented in
_DelegatorMixin and sphinx will find them there.

Tweak a few other strings to remove duplication in the sentence.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>

Metadata API: Improve dosctrings

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-08-01 13:08:13 +02:00
Jussi Kukkonen
0184edcab1 Metadata API: Annotation syntax tweak
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-08-01 13:08:13 +02:00
Jussi Kukkonen
2ace345afe metadata: Rename _Delegator to _DelegatorMixin
Make it clearer that this is not part of the main inheritance path.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-08-01 13:08:13 +02:00
Jussi Kukkonen
55f6824c24 Move verify_delegate() to Root/Targets
This makes logical sense and makes a lot of code using
verify_delegate() a little easier since there is no need to keep a
reference to the containing metadata anymore.

The implementation is in practice in a new class but that's an
implementation detail that allows sharing between Targets and Root.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-08-01 13:08:13 +02:00
ryanchen99
98d0460cbd
change Root.roles to Dict [Issue #2410]
Signed-off-by: ryanchen99 <60233822+ryanchen99@users.noreply.github.com>
2023-06-16 16:50:01 -07:00
Jussi Kukkonen
cddae3b892 Updates to TargetFile.get_prefixed_paths()
* Use the same solution for producing the paths as we already do in ngclient
* Fix linting issues
* Modify the test results according to new code (I believe these are
  correct, although some cases are so edge cases that disagreement may
  exist. Most importantly I think the method should always return as
  many paths as there are hashes listed

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-03-20 16:12:00 +02:00
Kamui
0eef15ad28 fix: parse manually and handle url edge cases
Signed-off-by: Kamui <fin-kamui@pm.me>
2023-03-20 15:48:51 +02:00
Kamui
1e47e390fb docs: add docstring for method
Signed-off-by: Kamui <fin-kamui@pm.me>
2023-03-20 15:48:51 +02:00
Kamui
24b1db6781 feat: generate hash-prefixed path names for target
Signed-off-by: Kamui <fin-kamui@pm.me>
2023-03-20 15:48:51 +02:00
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
Fridolin Pokorny
074778e08f
Fix pydocstyle D209
D209: Multi-line docstring closing quotes should be on a separate line

Signed-off-by: Fridolin Pokorny <fridolin.pokorny@datadoghq.com>
2023-02-06 13:23:33 +01:00
Jussi Kukkonen
d61dbabc78
Merge pull request #2281 from fridex/pydocstyle-d209
Fix pydocstyle D209
2023-02-02 14:33:41 +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
Fridolin Pokorny
744f75c1e7
Fix pydocstyle D209
Fix multi-line docstring closing quotes should be on a separate line

Signed-off-by: Fridolin Pokorny <fridolin.pokorny@datadoghq.com>
2023-01-26 16:36:13 +01:00
Fridolin Pokorny
5d347b8707
Fix pydocstyle D400: first line should end with a period
Signed-off-by: Fridolin Pokorny <fridolin.pokorny@datadoghq.com>
2023-01-26 15:33:09 +01:00
Jussi Kukkonen
361bbe40f3 metadata: Refactor delegators key and role lookup
Simplify the lookup of delegated keys and roles by moving it to
Targets and Root: this follows the examples set by add_key() and
remove_key().

Most of the methods are trivial but they make sense because this way
the calling code does not have to care if the object is a Targets or a
Root: the same methods work on both.

The new methods are public since they are useful to applications as
well.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 15:26:51 +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
6dbadaa7b1 Metadata API: Remove Key, import it from Seuresystemslib
Key has been moved to Securesystemslib: use it from there.

This still fails tests as Key API has changed a bit: issues are fixed
in followup commits.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 14:31:22 +02:00
Jussi Kukkonen
7f85da53b7 metadata API: Refactor exception imports
tuf.exceptions should IMO be seen as the "default exception source".

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 14:31:22 +02:00
Jussi Kukkonen
ba9ea5b88c
Merge pull request #2230 from fridex/pydocstyle-imperative-mood
Fix pydocstyle D401: first line should be in imperative mood
2022-12-27 11:47:46 +02:00
William Woodruff
7b89dd9532
api/metadata: third time's the charm
Signed-off-by: William Woodruff <william@trailofbits.com>
2022-12-22 09:56:35 -05:00
William Woodruff
d44fe52ce1
api/metadata: use debug logging
Signed-off-by: William Woodruff <william@trailofbits.com>
2022-12-21 10:34:32 -05:00
William Woodruff
408bf9ba20
api/metadata: blacken
Signed-off-by: William Woodruff <william@trailofbits.com>
2022-12-20 16:44:21 -05:00
William Woodruff
2876bfd764
tuf: move INFO logs to DEBUG or WARNING
Signed-off-by: William Woodruff <william@trailofbits.com>
2022-12-20 16:36:04 -05:00
Fridolin Pokorny
c4e1479003
Fix pydocstyle D401: first line should be in imperative mood
Signed-off-by: Fridolin Pokorny <fridolin.pokorny@datadoghq.com>
2022-12-18 13:13:35 +01:00
Jussi Kukkonen
87502b0f38 Metadata API: set default version for MetaFile()
This makes sense to me: if you create a new MetaFile, logically it
is version 1). This does not change serialization in any way.

Practical code becomes slightly nicer as
    metafiles = defaultdict(MetaFile)
now works without lambdas.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-07 15:07:19 +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
Martin Vrachev
addb199100 Fix comment about SuccinctRoles zero-padding
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-21 22:39:31 +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
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
d8808fbdcc SuccinctRoles: add zero padding to bins
Add zero padding to bin names inside SuccinctRoles.
Zero padding ensures that the bin names always have the same length.

This characteristic is implied in the example given by TAP 15 where
the third bin is named "alice.hbd-03". For context read TAP 15:
https://github.com/theupdateframework/taps/blob/master/tap15.md

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-14 18:26:08 +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
Abhisman Sarkar
79d924a4df Metadata API: Checking for None instead of falsyness
Fixes #1937

Initialization of unrecognized_fields acts surprisingly when the input
container is empty. Hence, We're checking for None instead of falsyness.

Signed-off-by: Abhisman Sarkar <abhisman.sarkar@gmail.com>
2022-04-29 22:39:48 +05:30
Marina Moore
9c5c5f7a73 Update supported spec version
Signed-off-by: Marina Moore <mnm678@gmail.com>
2022-04-19 10:22:43 -04:00
Abhisman Sarkar
944a540f97 Metadata API: Annotate 'unrecognized_fields' as Dict
Fixes #1938

Description of the changes being introduced by the pull request:

Annotating as Mapping seems wrong as further changes to the content might
be added in the code base. Hence, annotation changed to Dict.

Signed-off-by: Abhisman Sarkar <abhisman.sarkar@gmail.com>
2022-04-12 22:25:33 +05:30
Jussi Kukkonen
0d3bb682dd Metadata API: Document constructor default arguments
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-04-04 13:49:06 +03:00
Jussi Kukkonen
96b2cd46b5 Metadata API: Set default expires to utcnow()
This means the metadata is by default expired: this seems like a fine
default since we only allow a default value for practical reasons (not
allowing it would mean backwards incompatible API change).

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-24 15:43:06 +02:00
Jussi Kukkonen
d8c0f3b3f3 Metadata API: Be more careful with container args
If argument is an empty container, we want to use the given empty
container. Only create a new container if argument is None.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-24 15:38:53 +02:00
Jussi Kukkonen
d2f8c99c19 Metadata API: Add default constructor arguments
This allows creating new metadata with less boilerplate:
    root = Metadata(Root())
    targets = Metadata(Targets())

Set reasonable default values for all the arguments -- version to
1, spec_version to current supported version, etc.

Expires does not have a good default value and my original plan was
to require expires argument to be set. That would mean an
incompatible API change though as arguments before expires would be
now optional... So expires now defaults to an arbitrary value of 1
day from moment of creation.

One noteworthy special case is consistent_snapshot where the default
value is True (since that's what we want people to use for new
metadata) but None is also used to imply that metadata does not contain
the field at all.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-23 17:25:40 +02:00
Jussi Kukkonen
1d166f0b4e
Merge pull request #1876 from jku/more-details-on-verify-failure
Logging and error message improvements
2022-03-21 14:21:44 +02:00