Commit graph

1324 commits

Author SHA1 Message Date
Jussi Kukkonen
c2edd30669 Metadata API: Make sure Signed.expires is UTC
* Most importantly use strftime() to serialize the datetime
* Force the timezone as UTC when deserializing

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-29 15:34: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
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
0f64cf4c91 tests: add basic tests for dsse support
* Add API tests for SimpleEnvelope
  This is not as comprehensive as Metadata API. The latter also includes
  tests for all payload classes, which should cover the same scenarios as
  if used with SimpleEnvelope.

* Add unit test for newly added simple envelope load helper function in
  trusted metadata set.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 17:02:15 +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
5fab6355ab ngclient: support dsse in Updater
* Add `use_dsse` updater config parameter which indicates, if an updater
  instance expects metadata to come in a DSSE envelope.

* Update TrustedMetadataSet to take an Unwrapper instance.

* Update Updater, to pass an EnvelopeUnwrapper to TrustedMetadataSet, if
  configured with `use_dsse`.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:59:41 +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
cd543c9947 add ruff format and format 2 files
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-18 00:38:05 -05:00
Jussi Kukkonen
2aec25e729 tests: Add test for Delegations.get_delegated_role()
This test currently fails for SuccinctRoles.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-11 14:30:24 +02: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
14edf3d044 tests: Add VerificationResult tests
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 15:26:31 +02:00
Jussi Kukkonen
bfea673893 tests: Update the root verification tests
Change tests so the previous root version is what the code expects.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 15:12:44 +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
Jussi Kukkonen
cd0fd5c2ff tests: Add tests for root verification
This does much the same tests as test_signed_get_verification_result()
above it does, just using two root roles.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-01 21:13:29 +02:00
Jussi Kukkonen
506b40d93d tests: Update to new VerificationResult
Changes are
* expected result changes (like the handling of keyids without keys)
* test refactoring to have access to the Key
* Removal of union test
* use the fact that VerificationResult is Truthy in asserts
  (to get 1 more line of coverage)

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-01 21:13:29 +02:00
Lukas Puehringer
438518f68c tests: remove unused and obsolete test metadata
- metadata.staged: related to a removed tutorial and outdated deployment
  recommendation
- project: related to the removed developer_tool (#1790)
- map.json: related to TAP4, which is not supported by python-tuf

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2023-10-11 15:09:09 +02:00
Lukas Pühringer
e24faf213c
Merge pull request #2481 from lukpueh/signing-status
Metadata API: add get_verification_result method
2023-10-04 11:40:54 +02:00
Lukas Puehringer
a55756327b Metadata API: add get_verification_result method
The method returns detailed information about signature verification of
a delegated role metadata.

Its implementation is taken from the verify_delegate method and slightly
updated. verify_delegate now is a thin wrapper on top of
get_verification_result.

fixes #2449

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
Co-authored-by: Jussi Kukkonen <jkukkonen@google.com>
2023-10-03 12:05:39 +02:00
Jussi Kukkonen
e37769e252 Drop support for Python 3.7
* Python 3.7 is EOL.
* Our runtime dependencies are still ok with 3.7
* Testing dependencies have started requiring 3.8

Stop supporting and testing Python 3.7.

We could just stop testing Python 3.7 (while claiming to still support
it) but that seems like it'll lead to trouble: we will inevitably use
some 3.8 feature and then won't notice because we don't test 3.7 any
more.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-09-07 15:52:36 +03:00
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
Jussi Kukkonen
7924f8851d
Merge pull request #2447 from lukpueh/fix-sslibsigner-test
tests: adopt sslib changes in test_sign_failures
2023-08-17 15:51:36 +03:00
Lukas Puehringer
d45d65521b tests: adopt sslib changes in test_sign_failures
fixes #2444

SSlibSigner was changed recently (secure-stystems-lab/securesystemslib#604)
to fail on bad input data (keydict) at init instead of when signing.

The patched test used to trigger expects a Signer.sign error from an
SSlibSigner, which is no longer possible.

To still get the desired error, the test uses a custom signer, which
does raise on sign.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2023-08-16 16:36:27 +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
e51c0beee3 tests: Move lint disable to inside block as intended
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-08-01 13:08:13 +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
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
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
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