Commit graph

74 commits

Author SHA1 Message Date
Jussi Kukkonen
ba949d950f examples: Keep mypy happy
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-03-08 10:27:43 +02:00
Jussi Kukkonen
75ca67ef44 repository: Add default arg for targets() and edit_targets()
The default value "targets" makes sense because now the top-level
metadata can be accessed in a standard way:
  root(), timestamp(), snapshot() and targets()
and likewise for the edit_X() functions

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-03-08 10:27:43 +02:00
Jussi Kukkonen
79eb91d278 Add getter functions for Signed objects
These are equivalent to the edit_X() context managers but for cases
where user is not interested in creating a new version of the metadata.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-03-08 10:27:43 +02:00
Jussi Kukkonen
c3411dc59e repository: Rename snapshot()/timestamp()
New names:
  do_snapshot()
  do_timestamp()
This is in preparation of using the old names for another purpose.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-03-08 10:27:43 +02:00
Jussi Kukkonen
0262a8ac49 repository: Add typed edit_*() contextmanagers
The advantage here is that code within the context can take advantage
of the correct typing. This is already visible in the example code but
is even more useful in real applications.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-03-08 10:27:43 +02:00
Jussi Kukkonen
1e1a504bb6 examples: Tweak download dir creation
Create target download dir when it's needed, not during "tofu".

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-09 10:34:03 +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
5a944f9ba2 examples: More tweaks to uploader README
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-08 11:01:07 +02:00
Jussi Kukkonen
b6465ddedf examples: Add missing link in repository README
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-08 10:53:59 +02:00
Jussi Kukkonen
26495a5d0a examples: Improve uploader docs/messages
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-08 10:47:34 +02:00
Jussi Kukkonen
46930e56c4 examples: Improve repository README
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-08 10:27:33 +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
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
0998c20731 examples: Explain uploader tool in READMEs
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-02 16:25:47 +02:00
Jussi Kukkonen
92e03d2d20 examples: Implement the upload API
uploader API has two POST endpoints

/api/delegation/<ROLE>
    Accepts new delegation keys for targetpath "<ROLE>/*" to role <ROLE>.
    This data is not signed in any way: In a real service this action would
    require some external authentication.

    POST content:
        { <KEYID>: <TUF KEY> }

/api/role/<ROLE>
    accepts uploads of new versions of <ROLE> metadata. The metadata
    must be correctly signed by the keys assigned to this delegation.

    POST content:
        TUF targets metadata as json

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-02 16:25:43 +02:00
Jussi Kukkonen
69b30ecadc examples: Add uploader tool example
This tool works with the example repository: it can be used to
* Add a delegation (this is an unsafe API corresponding to e.g.
  project creation in PyPI)
* Submit new delegated role version (this requires using signing keys
  already submitted with the delegation)

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-02 16:21:52 +02:00
Jussi Kukkonen
efcb3cfb80 examples: Add further scaffolding for upload API
The API doesn't modify the repository yet but the data flow is there now.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-02 16:21:52 +02:00
Jussi Kukkonen
9ec8459379 examples: Add skeleton API endpoints
Also use ThreadingHTTPServer: Using Chrome utterly breaks the non-threading
server.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-02 16:21:52 +02:00
Jussi Kukkonen
22642ed267 examples: Update one more from_securesystemslib_key() usage
This method is now in SSlibKey

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-01-17 15:27:06 +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
Jussi Kukkonen
fd02226acb repository: Improve dosctrings
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-17 23:09:11 +02: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
c1bb46b6c2 repository: Improve docstrings
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-05 13:45:27 +02:00
Jussi Kukkonen
3e4ef61e46 examples: Tweak client README
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-05 12:34:54 +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
69cb140cb3 examples: Add README for repository example
Tweak comments as well

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-12-02 13:33:14 +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
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
5d831537f3 examples: Update client example
* Support any repository (that serves /targets/ and /metadata/)
  with --url
* Support multiple repositories by aking the local cache
  repository-specific
* Add "tofu" command to initialize with Trust-On-First-Use
* Update README so it uses the new repository application example

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-28 12:19:54 +02:00
Jussi Kukkonen
314efaf3da Examples: Add repository application example
This uses the repository module to create an app that
* generates everything from scratch
* serves metadata and targets from memory
* simulates a live repository by adding new targets every few seconds

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2022-11-28 12:13:00 +02: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
ameypd
fc0d53aae2 Fixes #1862, added way to see full stack trace on error situations
Signed-off-by: ameypd <h20220013@goa.bits-pilani.ac.in>
2022-11-25 19:41:49 +05:30
Lukas Puehringer
e9ef5b60b9 Minor restructure in TAP 15 example
Generate keys for all roles in one place and rename to
better distinguish delegating targets key from bins key.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-08-11 16:57:29 +02:00
Lukas Pühringer
50960c4076 Minor rewords in TAP 15 example
Apply minor rewording suggestions from code review.

Co-authored-by: Lois Anne DeLong <lad278@nyu.edu>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-08-11 16:54:31 +02: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
bfcd3a54a2 Simplifications on hashed_bin_delegatio example
We no longer need or use SPEC_VERSION variable defined in the
begging of the script.

Additionally, I decided to add a small addition to the "roles"
type annotation as that gives better context to the syntax highlighter
of VS code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-21 22:33:46 +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
Jussi Kukkonen
8071806e04 examples: Use the constructor default arguments
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-24 10:37:30 +02:00
Martin Vrachev
06118843ca Use spec version from tuf/api/metadata in examples
Replace the hardcoded specification version with the one defined inside
tuf/api/metadata.py

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-03-17 15:41:05 +02:00
lukpueh
31fd8d4f03
Merge pull request #1790 from lukpueh/rm-all
Rm all legacy
2022-02-04 14:01:53 +01:00
Jussi Kukkonen
4efd9496dc ngclient: Make DownloadErrors consistent
Fetcher interface should only raise DownloadErrors,
regardless of the implementation.
 * Make sure fetch() wraps non-DownloadError errors in a DownloadError
 * Make the abstract function private _fetch()
 * Try to be more consistent in doscstrings

This now makes the example client more sensible (when server does not
respond):
    $ ./client_example.py download qwerty
    ...
    Failed to download target qwerty: Failed to download url http://127.0.0.1:8000/metadata/2.root.json

(here the latter part of the error string comes from DownloadError
raised by FetcherInterface.fetch())

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-04 11:03:12 +02:00
Lukas Puehringer
9816c40d77 doc: update deprecation info in repo_example docs
Rephrase deprecation info in repo_example modules doc headers
to reflect that the deprecation has happened.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-02-03 10:00:22 +01:00
Martin Vrachev
a2f7b4588f Fix new space warning by black
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-02-01 12:29:50 +02:00
lukpueh
b2704a56a8
Merge pull request #1783 from MVrachev/drop-python3.6
Drop python3.6 and remove the usage of OrderedDict
2022-01-20 14:46:52 +01:00
Martin Vrachev
e3b267e2e0 Remove OrderedDict in favor of python3.7+ dict
After we drop support for python3.6 we can relly that dictionaries
preserve the insertion order:
https://docs.python.org/3.7/whatsnew/3.7.html

This means we can replace the usage of OrderedDict with a standard
dictionaries.

Something we have to keep in mind is that even thought the insertion
order is preserved the equality comparison for normal dicts is
insensitive for normal dicts compared to OrderedDict

For example:
>>> OrderedDict([(1,1), (2,2)]) == OrderedDict([(2,2), (1,1)])
False
>>> dict([(1,1), (2,2)]) == dict([(2,2), (1,1)])
True

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-01-19 18:19:56 +02:00
Martin Vrachev
4b61be9cf7 Add tuf/api/exceptions.py
Add tuf/api/exceptions.py for exceptions in the new code.
I copied the exceptions from tuf/exceptions.py with a few important
decisions:
1. I only added the exceptions that are used in the new code
2. I removed the general "Error" class as we can directly inherit
Exceptions
3. I tried grouping the exceptions by relevance
4. I removed the second argument "UnsignedMetadataError" as it's only
kept for backward compatibility and is not used
5. I tried following the new code style guidelines and linted the file
with our linters.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-01-19 16:52:19 +02:00