Commit graph

329 commits

Author SHA1 Message Date
h4l0gen
e63ba54906
made variable public
Signed-off-by: h4l0gen <ks3913688@gmail.com>
2024-05-28 17:35:14 +05:30
h4l0gen
35a29bbf1d
fix url link
Signed-off-by: h4l0gen <ks3913688@gmail.com>
2024-05-21 17:09:14 +05:30
Jussi Kukkonen
716cde704b lint: Remove unneeded noqa flags
Re-raising a blind exception is now ok.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-07 11:11:08 +02:00
Jussi Kukkonen
80882dbe7d lint: Enable flake8-annotations
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
Jussi Kukkonen
7e52190bf0 lint: Enable flake8-pyi
"object" is slightly more informative than "Any" as annotation

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
Jussi Kukkonen
981788bca2 lint: Enable flake8-pie
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
Lukas Puehringer
3e549793e4 Remove SSlibSigner mention in docstring
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-03 11:18:27 +02: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
3605eaf2fb Metadata API: Stop using a deprecated method
persist_temp_file() is deprecated, and seemingly not very useful.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-04-12 22:41:12 +03: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
27cc46f61d Metadata API: Refactor strptime call
This makes flake8-datetimez happier but has no effect on the result:

    DTZ007 The use of `datetime.datetime.strptime()` without %z must be
    followed by `.replace(tzinfo=)` or `.astimezone()

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-03-08 14:59:04 +02: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
Jussi Kukkonen
de9633dab7 Metadata API: convenience tweak to expires setter
Practically were changing API if we start requiring that
expires is non-naive because this no longer works:

    metadata.signed.expires = datetime(3000,1,1)

We can make this work without API breaks though:
* it the input is naive, just use UTC
* if the input is not naive or UTC, raise

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-29 15:36:54 +02:00
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
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
4005e766b4 Add LengthOrHashMismatchError back to metadata.
22b2726413 claims to add all names
that were moved to the internal _payload module back to metadata.

LengthOrHashMismatchError was not added back. Now it is.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-22 13:48:21 +01:00
Lukas Puehringer
8544bbd6f1 Envelope API: rename, add docs, add alias
* Rename Envelope to SimpleEnvelope:
  Envelope should be the generic term in this context for something that
  contains a payload and signatures. SimpleEnvelope is the specific
  DSSE implementation (just like Metadata is the specific traditional
  canonical JSON -based TUF envelope implementation).

* Add SimpleEnvelope class and method docstrings.

* Add convenience alias for ``self.signatures`` mapped to keyids for
  compatibility with Metadata.signatures.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:59:55 +01:00
Lukas Puehringer
b422afe0a4 Envelope API: add dsse equivalent for Metadata API
Add Envelope class with basic de/serialization methods, currently
hardcoded to JSON.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:34:53 +01:00
Lukas Puehringer
22b2726413 Metadata API: move inner classes to internal module
Allows to simultanously use those classes in different container /
signature wrapper APIs, e.g. Metadata API and Envelope API (DSSE).

All moved classes are imported into tuf.api.metadata scope for
backwards-compatibility.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-02-21 16:20:55 +01:00
Lukas Pühringer
76f39f52ef
Merge pull request #2558 from NicholasTanz/replaceLintingTools
Replace most linting tools with ruff
2024-02-21 15:59:03 +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
73842c97b8 reformat docstrings and supress small errors inline
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-20 15:19:33 -05:00
Jussi Kukkonen
3b65c2217b metadata API: Tweak exception message on sign failure
I still don't know how we should handle failures in signing
(maybe just let all of the weird exceptions raise instead of wrapping
them) but this makes the wrapping error at least a bit more useful.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-20 14:39:50 +02: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
eb4834d920 Metadata API: Fix role lookup for succinct delegation
get_delegated_role() should not return a Role if the rolename is not
a delegated role. This is already true for "normal" DelegatedRole but
was not actually verified for SuccinctRoles.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-11 14:30:24 +02:00
Jussi Kukkonen
161c3e35ad Metadata API: Add VerificationResult.missing
This is helper to tell how many signatures are still required.
Also change the order of Roots given to RootVerificationResult
(this way first is version N, second is version N+1).

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 15:01:46 +02:00
Jussi Kukkonen
b158c0852d Metadata API: Make sanity checks in root verification
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 14:36:05 +02:00
Jussi Kukkonen
42d3a75787 Metadata API: Improve docs for RootVerificationResult
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-05 13:56:57 +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
26bdbbe20c Metadata API: Simplify verify_delegate()
Now that VerificationResult has threshold, this can be simpler.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-02 11:04:01 +02:00
Jussi Kukkonen
dc11afc62e Metadata API: Workaround for Python <3.9
dict unions are only supported in 3.9.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-02 11:02:27 +02:00
Jussi Kukkonen
368bee8228 Metadata API: Implement RootVerificationResult
This is a thin wrapper over two VerificationResults:
useful when verifying root signatures.

Now the API for getting verification results for root and
the API for getting the results for other metadata is different.

Client use cases can continue using verify_delegate() so should not
be affected.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-01 21:13:29 +02:00
Jussi Kukkonen
03a1caa1a8 Metadata API: Refactor VerificationResult
This is an API break as VerificationResult changes:
 * Now contains threshold
 * Now contains Keys and not just keyids

Note that there is a small edge case functionality change:
 * if the role does not have a key for the keyid, then we no longer
   include that key in "unsigned"

I think that is an acceptable change.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-01 18:26:03 +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
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