Commit graph

48 commits

Author SHA1 Message Date
Jussi Kukkonen
0785c78b33 Make linter happy after python upgrade
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-01-08 13:08:53 +02:00
Jussi Kukkonen
8513f46c2b Bump minimum Python version to 3.10
We could just stop testing with 3.9... but I think this will lead to
unintentionally breaking 3.9 anyway sooner or later.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-01-08 13:08:47 +02:00
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
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
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
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
dceced7acd tests: Avoid UTC alias
Older Pythons do not have this alias, use timezone.utc

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-02-29 15:45:56 +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
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
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
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
Martin Vrachev
5fd3ddccbc ngclient: pick old timestamp if new.ver is equal
In the spec version 1.0.30, a new change has been added considering what
should happen if there is a new timestamp with the same version.
It says the following:
"In case they [versions] are equal, discard the new
timestamp metadata and abort the update cycle.
This is normal and it shouldn't raise any error."

In other words, if there is a new timestamp with the same version, then
stop the update process and use the old timestamp.

Those changes reflect these latest specification modifications.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-21 14:52:31 +03:00
Jussi Kukkonen
0bd8feccf8 tests: Small refactor of a test
Test was supposed to test a threshold that is higher than number of
signatures, but it actually was just using completely unsigned metadata.

This still doesn't test the case where _trusted_ metadata defines a
threshold that new metadata does not reach: only the case where new
metadata defines threshold that it does not meet (this case is covered
in updater tests though).

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-04-01 10:17:06 +03:00
Martin Vrachev
a17ceda4e5 Add "validation" arg in JSONSerializer
If the "validation" argument is set then when
serializing the metadata object will be validated.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-02-28 14:42:06 +02:00
Lukas Puehringer
7da6a38335 test: define TESTS_DIR constant
Define TESTS_DIR constant in tests/util.py as full path to the
parent directory of the util module. This may be used to reliably
read other files in tests dir, such es "repository_data" or
"simple_server", regardless of cwd.

This commit also replaces a couple of `getcwd() + "filename"` with
`TESTS_DIR + filename`, so that in the future (post #1790) we
should be able to invoke the tests from anywhere, not only from
within the tests directory as is now the case.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-01-24 13:54:07 +01:00
Martin Vrachev
0cbe2a2034 Remove ReplayedMetadataError
ReplayedMetadataError is a subset of
BadVersionNumberError and in a discussion with
Jussi we realized that ReplayedMetadataError can
be replaced by BadVersionNumberError with a
good message.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-01-19 16:52:19 +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
Jussi Kukkonen
80d3fcf56b Metadata API: Make Role.keyids ordered
keyids are ordered in the data we deserialize: Not preserving that order
breaks canonicalization. Set does not preserve order.

Change Role.keyids type from Set to List. This is strictly speaking
an API change but a minor one: keyids are supposed to be changed
via add_key()/remove_key().

Add tests for this for both Role and DelegatedRole. Shorten a related
exception message.

Fix #1752

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-01-05 14:28:17 +02:00
Martin Vrachev
a728717eda Fix more black warnings on test files
The changes are automatic linting fixes from black.
The target files are only those who test the new code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-09 15:52:40 +02:00
Ivana Atanasova
00589f08e3 Apply top-level rolenames constants in tests
This applies the use of constants of top-level rolenames in the
tests instead of the previously hardcoded strings.
Fixes #1648

Signed-off-by: Ivana Atanasova <iyovcheva@iyovcheva-a02.vmware.com>
2021-12-02 12:25:48 +02:00
Martin Vrachev
e2deff3148 Address mypy warnings
This commit includes manual fixes for a lot of mypy warnings.
When there were warnings that we are calling non-annotated function
in annotated context I decided to add annotations instead of ignoring
those warnings.
That's how I end up adding annotations in the whole tests/utils.py
module.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-11-24 20:50:10 +02:00
Ivana Atanasova
9c2bf6e784 Update ngclient to return loaded metadata
This changes `TrustedMetadataSet` to return new trusted Metadata
on successful calls of the `update_<role>` functions and also
changes `Updater._load_targets` to return loaded metadata as well

Signed-off-by: Ivana Atanasova <iyovcheva@iyovcheva-a02.vmware.com>
2021-11-22 14:36:12 +02:00
Martin Vrachev
d4187f3186 Address pylint warnings on tests for the new code
Address or disable pylint warnings raised on all test files inside
the "tests/" directory testing the code of the new implementation.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-11-11 15:39:56 +02:00
Martin Vrachev
2e9ef79762 Apply isort on the tests of the new code
All of the changes included are a result of applying isort
on our tests on the new code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-11-02 19:31:25 +02:00
Martin Vrachev
c98b429643 Apply black on the tests of the new code
All of the changes included are a result of applying black
on our tests on the new code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-11-02 19:30:35 +02:00
Martin Vrachev
1a5912aa7c Remove some unused imports
We can remove the conditional imports from tests as now we support
python versions 3.6+.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-09-21 12:20:09 +03:00
Martin Vrachev
bf12e7565f Metadata API: change meta type in Timestamp
In Timestamp, the only valid "meta" value is the dictionary representing
meta information for the snapshot file. This makes the API unnecessarily
complicated and requires validation that only information about snapshot
is available inside "meta".
Together with the python-tuf maintainers, we decided that snapshot meta
information will not be represented by a "meta" dictionary but instead
by a MetaFile instance and with this it will diverge from the
specification.
Additionally, to prevent confusion, I will rename the "meta" attribute
to "snapshot_meta" as this attribute will be related only to meta
information about snapshot.

This decision is coherent with ADR9 and the rationale
behind it is to provide easier, safer, and direct access to the
snapshot meta information.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-09-20 14:09:38 +03:00
Jussi Kukkonen
d018279e21 ngclient: Fix rollback checks
The rollback checks themselves work, but they create a situation
where Updater does not realize that it needs to download e.g. a new
snapshot because the local snapshot is valid as _intermediate_ snapshot
(that can be used for rollback protection but nothing else), but is not
valid as final snapshot.

Raise in the end of update_snapshot and update_timestamp if the files
are not valid final metadata: this way the intermediate metadata does
get loaded but Updater also knows it is not the final metadata.

This modifies the existing tests but does not yet test the situation
described in the first paragraph.

Fixes #1563

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-09-10 09:59:03 +03:00
Teodora Sechkova
61e8f40346
Update tests/test_trusted_metadata_set.py
Modify root tests to cover both loading inital
root metadata and updating it.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-09-07 14:41:08 +03:00
Jussi Kukkonen
c8696d905e tests: Remove unhelpful helper
Doing the work inline is less code and easier to understand.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:22:01 +03:00
Jussi Kukkonen
e3b789c306 ngclient: allow limited use of wrong snapshot version
Spec does not explicitly say so but the intent is that a snapshot
metadata can be trusted for rollback protection checks of newer
snapshots even if current snapshot version does not match the version
in current timestamp meta.

Only do the snapshot version check for the "final" snapshot by doing it
when targets is updated.

Improve test names and comments.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:22:01 +03:00
Jussi Kukkonen
b515997701 ngclient: Allow limited use of expired timestamp/snapshot
While this is not explicitly said in the spec, the intention is that
expired timestamp and snapshot should be used for rollback protection
checks on newer timestamp/snapshot (but not for anything else).

Move the expiry checks to the "next" metadata update: timestamp expiry
is checked when snapshot is loaded, and snapshot expiry is checked
when targets is loaded.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:22:01 +03:00
Jussi Kukkonen
091197288f ngclient: Remove root_update_finished()
The usefulness was debatable to begin with, and now that it has become
clear that rollback protection requires a second "final verification"
step for all three root, timestamp and snapshot it is clear that
root_update_finished() is not good design.

update_root() still accepts expired root metadata but now the final
root expiry is checked when the "next" metadata (timestamp) is loaded.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:09:12 +03:00
Jussi Kukkonen
f02fed2502 tests: Test TrustedMetadataSet iteration
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-17 15:50:01 +03:00
Jussi Kukkonen
85656a56eb tests: Add missing test to TrustedMetadataSet
Test failing length/hash test for snapshot

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-17 15:40:13 +03:00
Jussi Kukkonen
efb5653016 tests: Improve TrustedSet coverage
* test for succesful root update
* fix test for snapshot version rollback in timestamp update

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-17 13:54:18 +03:00
Martin Vrachev
617e87eb26 Annotations and use extensively modify_metadata
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-08-16 18:13:01 +03:00
Martin Vrachev
11531caf42 Embed modification function helpers
Instead of using general abstract modification functions embed smaller
modification functions inside each test where it's needed and
create modify_metadata function that does all of the common stuff like:
- instantiating a metadata object
- calling the modification function
- signing the modified object
- serializing back to bytes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-21 17:34:23 +03:00
Martin Vrachev
71838562dc ngcl. tests: remove modification on internal state
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-21 16:40:39 +03:00
Martin Vrachev
c7c9d0f321 TrustedMetadataSet testing: use Metadata.to_bytes
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-16 16:57:28 +03:00
Martin Vrachev
6a942889ff ngclient TrustedMetadataSet: improve unit testing
The current situation with the TrustedMetadataSet testing is that
we don't have a mnimimal amount of unit tests testing the different
branches in the various API functionality in the class.

This commit proposes simple unit tests covering almost all of the
branches in the API functions and increasing the unit test coverage
(as reported from the "coverage" tool) from 74 % to 97 %.

The code could be complicated at places, because the different
branches in the update_* functions depend on other metadata classes
as well.
Still, I hope we can find a way and simplify the code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-16 16:57:23 +03:00
Martin Vrachev
726af73256 ng client metadata set: organize common test code
Move the shared code between tests into the "setupClass" function.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-16 15:49:00 +03:00
Jussi Kukkonen
4811e880c0 Rename MetadataBundle to TrustedMetadataSet
TrustedMetadataSet is a long name but
 * it better describes the main feature
 * the name isn't used in too many places

Change the variable names "bundle" -> "trusted_set"

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-07-05 10:45:19 +03:00
Renamed from tests/test_metadata_bundle.py (Browse further)