Commit graph

108 commits

Author SHA1 Message Date
Dimitri Papadopoulos
4a28307270
Fix typos
Signed-off-by: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com>
2025-03-10 22:06:30 +01:00
Jussi Kukkonen
15933a93b6
ngclient: Create directories as needed (#2808) 2025-03-09 06:56:37 +00:00
Jussi Kukkonen
38e4eaba1f updater: Improve comments on bootstrap arg
This includes some minor example improvements

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-02-20 11:11:28 +02:00
Jussi Kukkonen
cea1745cef Implement root bootstrapping
Application may have a "more secure" data store than the metadata cache
is: Allow application to bootstrap the Updater with this more secure
root. This means the Updater must also cache the subsequent root versions
(and not just the last one).

* Store versioned root metadata in local cache
* maintain a non versioned symlink to last known good root
* When loading root metadata, look in local cache too
* Add a 'bootstrap' argument to Updater: this allows
  initializing the Updater with known good root metadata
  instead of trusting the root.json in cache

Additional changes to current functionality:
* when using bootstrap argument, the initial root is written to cache.
  This write happens every time Updater is initialized with bootstrap
* The "root.json" symlink is recreated at the end of every refresh()

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-02-20 11:09:54 +02:00
Jussi Kukkonen
73273813f3
Merge pull request #2773 from jku/no-requests
More porting from  requests to urllib3
2025-02-20 08:51:42 +00:00
pakagronglb
acd7ed08d1 Update Python shebangs to explicitly use python3
Signed-off-by: pakagronglb <pakagronglebel@gmail.com>
2025-02-19 19:44:21 +07:00
Jussi Kukkonen
cfee40aa96 More porting from from requests to urllib3
This is related to #2762 (that replaces RequestsFetcher with
Urllib3Fetcher) and takes care of the remaining requests use cases in
the code base.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-02-14 17:41:50 +02:00
Jussi Kukkonen
1d81a04707 Use __future.annotations module
This allows using some more nice annotations from 3.10
while still being compatible with even Python 3.8.

These are all annotation changes, should not modify any functionality.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-11-29 12:41:09 +02:00
NicholasTanz
5c71f4f062 update python annotations
Signed-off-by: NicholasTanz <nicholastanzillo@gmail.com>
2024-11-03 23:21:23 -05:00
Kapil Sharma
adc0a26020
Update basic_repo.py
Signed-off-by: Kapil Sharma <ks3913688@gmail.com>
2024-05-29 13:03:25 +05:30
h4l0gen
033a231c92
change_target_file_path
Signed-off-by: h4l0gen <ks3913688@gmail.com>
2024-05-29 10:48:08 +05:30
Jussi Kukkonen
dc5194e9e9 lint: Enable flake8-self
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
Jussi Kukkonen
3d1b16cdfa examples: Use Cryptosigner.private_bytes
private_bytes was just added to CryptoSigner, use it.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-04-25 14:44:18 +03:00
Jussi Kukkonen
38f309bbbf WIP: Update to new securesystemslib API
* API changes covered:
  * keys and interface modules removed
  * SSlibSigner removed
  * CryptoSigner added: this replaces the removed functionality
  * DSSE "signatures" container type changed
* Currently pins a securesystemslib main branch commit:
  this shoudl be reverted before merging, when securesystemslib
  has made a release
* tests/generated_data/generate_md.py was simplified
* Encrypted test keys in tests/repository_data/keystore were replaced
  with the unencrypted PEM versions of the same keys
* The public test keys in tests/repository_data/keystore were removed
  as they were not used anymore

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-04-25 14:27:54 +03:00
E3E
52601e2bd8 add RUF and BLE rulesets; ignore some broad exceptions (BLE001) and RUF012
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-04-21 01:37:40 -04:00
Jussi Kukkonen
009e1ddbf4 lint: Enable more ruff ulesets
Minor fixes were needed, the only possibly interesting one is
the one in RequestsFetcher (use "yield from").

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-04-02 11:02:48 +03:00
Jussi Kukkonen
1512653995 linter: Enable more rules
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-03-19 16:30:52 +02:00
Lukas Pühringer
e1b52e7fd8
Merge pull request #2580 from theupdateframework/dependabot/pip/test-and-lint-dependencies-c17666fe2e
build(deps): bump the test-and-lint-dependencies group with 1 update
2024-03-12 09:40:40 +01:00
Jussi Kukkonen
884cae9660 lint: Update formatting for ruff 3.x
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-03-07 10:05:36 +02:00
Nurgaleev_Mansur_908
048d3b343b fix lint
Signed-off-by: Nurgaleev_Mansur_908 <mansur0158@gmail.com>
2024-02-28 15:29:44 +03:00
Nurgaleev_Mansur_908
93d9f8fa2d fix lint
Signed-off-by: Nurgaleev_Mansur_908 <mansur0158@gmail.com>
2024-02-27 22:13:17 +03:00
Nurgaleev_Mansur_908
53ac05d5d3 change utcnow() to now(timezone.utc)
Signed-off-by: Nurgaleev_Mansur_908 <mansur0158@gmail.com>
2024-02-27 21:57:46 +03:00
Lukas Puehringer
b6fa05b01f Revert "examples: support dsse in example client"
This reverts commit b279745886.

... plus related changes from:
 "ngclient: change envelope type config to flag".

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 17:26:02 +01:00
Lukas Puehringer
1897f9a652 ngclient: change envelope type config to flag
The flag allows adding other envelope types in the future (unlikely),
or parallel support (`METADATA & SIMPLE`) without breaking the API.

Internally, the flag is now just passed on to TrustedMetadataSet as
mandatory parameter. (Optional parameters make less sense when we
control all the invocations.)

This change requires updating all invocations of TrustedMetadataSet,
including the duplication of a test function.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:59:55 +01:00
Lukas Puehringer
b279745886 examples: support dsse in example client
Add `--use-dsse` flag to `download` subcommand of example client, which
can be used to indicate that all metadata is expected to come in a DSSE
envelope.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:59:55 +01:00
Lukas Puehringer
cb9aa4a362 ngclient: use Unwrapper in TrustedMetadataSet
Change TrustedMetadataSet to load and verify metadata using a
MetadataUnwrapper instance.

IMPORTANT NOTES:
* Requires changing the TrustedMetadataSet to store payloads only, which
  is okay, because signatures are no longer needed, after being verified
  at load time.

* Includes a minor re-ordering of validation steps.  That is, the
  version increment for root metadata is now checked after signature
  verification. Preserving the order would require including the check in
  the Unwrapper interface, which is feasible but does not seem correct wrt
  separation of responsibility.

Changes are adopted in updater, tests and _localrepo.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:24:29 +01:00
E3E
f156e21537 remove pylint and suppressed inline errors from pylint
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-20 22:57:53 -05:00
E3E
206c9424f1 Add to linting Configuration:
- adpot changes in dependabot.yml and remove --diff from ruff check.
- select pydocstyle, isort, pyflakes, pep8-naming, pycodestyle for ruff and ignore some small issues / add inline comments.
- adjust docstring length to 80 in various files

Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-20 00:34:47 -05:00
Jussi Kukkonen
be55b871da
Merge pull request #2551 from jku/improve-verification-result
Improve verification results
2024-02-05 20:08:39 +02:00
Jussi Kukkonen
f60fb4abc8 Metadata API: Tweak get_root_verification_result args
Change the "other" argument to optional "previous" and
handle the None case in code.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 13:51:28 +02:00
Jussi Kukkonen
b8dbe307db examples: Use verification results in repo example
This is an example of using the verification resutls in a repository.

The only remaining tricky part is in _get_verification_result():
* has to figure out the delegating metadata (something we currently
  cannot provide in repository.Repository for the general case)
* Needs a special case for first root

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-03 17:10:12 +02:00
Jussi Kukkonen
f72edc54bc Linter fixes from new black
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-01 22:10:31 +02:00
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
Jussi Kukkonen
a69ddf1f04 ngclient,tests,examples: Use new verify_delegate()
Avoid Metadata.verify_delegate() now that it's deprecated.

Note that this commit does not try to make any code cleanups
that are now possible: this is the minimal change to use the new
API.

Future improvements can make code in TrustedMetadataSet and
Updater slightly easier to read: as an example there's no need for
TrustedMetadataSet to actually store or expose actual Metadata in its
cache -- Signed is all that's needed.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-08-01 13:08:13 +02:00
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