Commit graph

2432 commits

Author SHA1 Message Date
Jussi Kukkonen
c9c36934f2 repository: Make snapshot/timetamp helpers non-abstract
targets_infos() and snapshot_info() are helpers used by snapshot and
timestamp. Some Repository implementations do not need
snapshot/timestamp (think e.g. a signing tool that never modifies online
roles), so the helpers should not be required.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-26 11:35:02 +02:00
Lukas Pühringer
dd855b1fca
Merge pull request #2241 from jku/repository-lib-uploader
Examples: Add repository uploader
2023-02-08 10:30:52 +01: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
d36c0cfa02 examples: Rename client example directory
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-02 16:25:47 +02: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
Lukas Pühringer
93b8fb6377
Merge pull request #2279 from fridex/export-targetfile-ngclient
Export TUF TargetFile in ngclient
2023-01-31 09:19:41 +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
Lukas Puehringer
9811ac3568 python-tuf 2.1.0
* update changelog
* bump version

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2023-01-26 16:26:38 +01:00
Fridolin Pokorny
524a6b848f
Export TUF TargetFile in ngclient
Signed-off-by: Fridolin Pokorny <fridolin.pokorny@datadoghq.com>
2023-01-26 15:54:44 +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
889b218e7a Add comment explaining public status to the module itself
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-26 09:33:44 +02: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
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
e1d15887a8 ngclient: Remove "Optional" from helper props
The properties in TrustedMetadataSet are a bit difficult to use
with static typing since they return Optional but in many cases
we know the "None"-case is impossible.

Remove None from annotation: the idea is that calling the property
getter too early is a programming error: it will result in KeyError
which is consistent:
 * trusted_set["timestamp"] raises KeyError if timestamp is not set
 * trusted_set.timestamp raises KeyError if timestamp is not set

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-27 16:56:32 +02:00
Aditya Shrivastav
42cb50b15b
Merge branch 'theupdateframework:develop' into metaclass-fix 2022-12-27 16:28:43 +05:30
adityashrivastav1
086216f7cc unused variable removed, inheritance fixed
Signed-off-by: adityashrivastav1 <aditya.shri9981@gmail.com>
2022-12-27 16:27:17 +05:30
adityashrivastav1
2c15c75e50 class FetcherInterface() changed to FetchterInterface(abc.ABC)
Signed-off-by: adityashrivastav1 <aditya.shri9981@gmail.com>
signed off
Signed-off-by: adityashrivastav1 <aditya.shri9981@gmail.com>
2022-12-27 15:44:54 +05:30
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
Jussi Kukkonen
e5856f7c91
Merge pull request #2233 from fridex/tuf-ngclient-api
Provide __all__ for tuf.ngclient module
2022-12-27 11:28:33 +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
9ffb4a4474
Provide __all__ for tuf.ngclient module
Signed-off-by: Fridolin Pokorny <fridolin.pokorny@datadoghq.com>
2022-12-20 00:17:31 +01: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
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
fd02226acb repository: Improve dosctrings
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-17 23:09:11 +02:00
Lukas Pühringer
c6f8b5817b
Merge pull request #2197 from jku/client-robustness
ngclient: Fail gracefully on missing role
2022-12-16 10:23:08 +01:00
Jussi Kukkonen
48865aede9 repository: Remove sign_only argument from close()
This is only needed for threshold signing and not even used in the
example: leave it to the implementations to handle for now.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-14 20:05:56 +02:00
Jussi Kukkonen
9e9c156288 repository: remove init argument from open()
This no longer seems needed: if the metadata store does not contain
a single version of role, then open() can assume it is initializing.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-14 19:53:43 +02: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
Martin Vrachev
c8d79a323c
Updater: add missing config docstring
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-12-06 17:50:13 +02:00
Jussi Kukkonen
c1bb46b6c2 repository: Improve docstrings
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-05 13:45:27 +02:00
Jussi Kukkonen
fdf0affcad repository: Address review comments
This is a collection of comment, documentation and logging fixes.

The noteworthy part is making it clear that repository is not stable
API yet: I think this is a good idea.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-03 11:34:21 +02:00
Jussi Kukkonen
0f94c03756 repository: Handle linting issues
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-02 13:40:58 +02:00
Jussi Kukkonen
87c74a83bc examples: Maintain a meta info cache
This is not required for the demo but is more realistic: we keep
a cache of targets versions so that we can produce a new snapshot
whenever one is needed, without accessing all of the targets metadata
to do so.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-30 21:19:43 +02:00
Jussi Kukkonen
dd36b73ca9 repository: insert copies of MetaFile into metadata
Otherwise the metafile cache and the metadata object end up
pointing to same instances which starts breaking later.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-30 21:05:57 +02:00
Jussi Kukkonen
df6b044c5a repository: Make snapshot/targets info required properties
This does not make the examples simpler now, but it will when
there are multiple locations where snapshot/timestamp are called.

* This way the snapshot/timestamp input material is an internal detail
  of Repository and the call sites will be simpler.
* Both methods now have a "force" argument that can be used to create a
  new version regardless of meta info changes
* but implementations are now required to implement snapshot_info
  and targets_infos properties that represent the current snapshot and
  targets versions in the repository

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-30 18:44:16 +02:00
Jussi Kukkonen
5e17617fc5 Add repository module
Plan for tuf.repository is:
* provides useful functionality for TUF repository-side implementations
  (repository applications, developer tools, etc)
* is minimalistic: only features that most implementations will use
  should be icluded
* Only example implementations will be provided in python-tuf
* As more repository implementations are built using tuf.repository
  we can evaluate what extended functionality is useful

In this PR, a single abstract class is added that provides a framework
for building repository-modifying tools. In subsequent commits
some examples will be added that demonstrate how to use the class.

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
Jussi Kukkonen
f56d5267ed README: Remove limitations
There may be ways to unsafely use the client library but situation
should be significantly better now with ngclient:
  * metadata writing is safer, more atomic
  * non-root cached metadata is never trusted (so inconsistent
    cached repository is not a security issue)
  * the cache locations are now clearly application
    decisions (they are required Updater constructor args)

Move the notice to Updater module documentation.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-18 13:16:41 +02:00
Jussi Kukkonen
35a7dd58c5 RequestsFetcher: satisfy mypy with small fix
The typeshed annotations for requests say that the hostname could be None:
I think this is untrue but let's keep mypy happy.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-10-31 21:25:02 +03:00
KOLANICH
0c9c494261 Supported schemes without netloc.
Signed-off-by: KOLANICH <KOLANICH@users.noreply.github.com>
2022-10-31 21:23:56 +03: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