Commit graph

4175 commits

Author SHA1 Message Date
Teodora Sechkova
167e1793d0 Fix Root.add_key() argument's type
After the implementation of a Key class representing
the public portion of a key, the method add_key() should
take an argument of type Key, instead of a dictionary.

Test cases are updated accordingly.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-13 11:23:15 +03:00
Jussi Kukkonen
2ef8546afb
Merge pull request #1370 from MVrachev/delegation-classes
New API: Add DelegationRole and Delegations classes
2021-05-12 08:52:13 +03:00
Martin Vrachev
b2cde9bbbf Don't use Mapping for mutable dicts
Stop using Mapping where we actually mean Dict:
Mapping means "we only need a read-only dict" and most of the time
this is not really the case.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-11 16:04:25 +03:00
Martin Vrachev
42b3269ac1 Remove forgotten debug line from a test
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-11 16:04:25 +03:00
Martin Vrachev
f98f4f750a Add Delegation/DelegatednRole specific tests
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-11 16:04:25 +03:00
Martin Vrachev
8e4d3b9a84 Add DelegatedRole and Delegations
In the top level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.

DelegatedRole shares a couple of fields with the Role class and that's
why it inherits it.
I decided to use a separate Delegations class because I thought it will
make it easier to read, verify and add additional helper functions.
Also, I tried to make sure that I test each level of the delegations
representation for support of storing unrecognized fields.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-11 16:03:56 +03:00
Jussi Kukkonen
a261d49253
Merge pull request #1379 from jku/metadata-minor-fixes
Metadata minor fixes
2021-05-11 15:18:24 +03:00
Jussi Kukkonen
d3a1d43569
Merge pull request #1383 from jku/old-style-logging
Metadata API/pylintrc: Use old style logging
2021-05-11 14:23:25 +03:00
Jussi Kukkonen
efd412aa90 Metadata API/pylintrc: Use old style logging
This is suggested by the Google style guide: the old style logging
(%-format) allows the log strings to be lazily formatted so there's less
need to think about performance when forming debug messages.

No actual code changes are needed because the metadata API does not yet
log anything.

Fixes #1334

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-11 11:47:38 +03:00
Joshua Lock
d5deba2185
Merge pull request #1376 from jku/duplicate-type-property
Metadata API: Provide type as well as _type
2021-05-10 21:27:24 +01:00
Jussi Kukkonen
084df969a4 Metadata API: Fix type hints
* Define missing argument type hints
* Stop using Mapping where we actually mean Dict:
  Mapping means "we only need a read-only dict" and most of the
  time this is not really the case.
* Use List, not list (latter only works from Python 3.9)
* Update Metadata.signatures documentation

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-10 21:27:24 +03:00
Jussi Kukkonen
17121bad28 Metadata API: remove_key() improvements
We should not do multiple lookups through data structures if one is
enough (here we have extra lookups on both roles and keyids).

Also in this case raising on missing key seems like the preferable
alternative so even a try-except is not needed.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-10 17:02:12 +03:00
Jussi Kukkonen
b6558c2070
Merge pull request #1367 from MVrachev/improvements
Make hashes, length and delegations optional + improvements
2021-05-10 16:06:36 +03:00
Martin Vrachev
139bfc0ea9 BREAKING CHANGE: Make delegations optional
According to the spec, delegations in targets are marked as optional:
https://theupdateframework.github.io/specification/latest/#file-formats-targets
and a pr, clarifying that even more, is approved:
https://github.com/theupdateframework/specification/pull/157.

This is a possible breaking change.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-10 15:27:37 +03:00
Martin Vrachev
0604f7026e NEW API: Fix documentation indentation
From the reST/sphinx docs:
https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#literal-blocks

I added new lines and an identation where it was missed.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-10 15:27:37 +03:00
Martin Vrachev
71c4992cea Make length and hashes optional in Timestamp
As per the specification (v1.0.1) length and hashes fields
in timestamp and snapshot metadata are optional.
We have implement this in the older API
(see https://github.com/theupdateframework/tuf/pull/1031) and we should
implement it in the new API.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-10 15:27:37 +03:00
Martin Vrachev
c0d72d460c New API: Add root use case in couple of tests
Add a use case for the root class to be tested in test_generic_read
and test_read_write_read_compare tests in test_apy.py

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-10 15:27:37 +03:00
Jussi Kukkonen
85971beaee Metadata API: Provide type as well as _type
Using Metadata APIs '_type' attribute (from outside metadata.py) currently
results in linter errors.

Add a duplicate 'type': this way the API users can avoid linter errors
but '_type' is still available in case the strict file format
compatibility is needed.

Fixes #1375

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-10 14:12:06 +03:00
Jussi Kukkonen
f736028480
Merge pull request #1381 from jku/bump-sslib
build(deps): bump securesystemslib
2021-05-10 14:08:58 +03:00
Jussi Kukkonen
6d927a8e84 build(deps): bump securesystemslib
Bumps [securesystemslib[crypto,pynacl]](https://github.com/secure-systems-lab/securesystemslib) from 0.20.0 to 0.20.1
- [Release notes](https://github.com/secure-systems-lab/securesystemslib/releases)
- [Changelog](https://github.com/secure-systems-lab/securesystemslib/blob/master/CHANGELOG.md)
- [Commits](https://github.com/secure-systems-lab/securesystemslib/compare/v0.20.0...v0.20.1)

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-10 13:46:13 +03:00
Jussi Kukkonen
5c1b12fec7
Merge pull request #1372 from jku/read-only-type
API: Make _type read-only
2021-05-06 15:26:07 +03:00
Jussi Kukkonen
28e420bf21
Merge pull request #1364 from jku/no-pre-release-tools 2021-05-05 09:01:18 +03:00
Jussi Kukkonen
b22659e25d
Merge pull request #1369 from sechkova/coveralls-publish
CI: Allow failure when publishing on coveralls
2021-05-04 10:22:45 +03:00
Jussi Kukkonen
57bd9af7c2 API: Make _type read-only
Also remove _type from Signed constructor arguments: the value is in a
class atttribute. This way _type never needs to be validated (except
in the dispatcher in Metadata). There is a double-check in
_common_fields_from_dict() just to be sure.

This makes the API easier to use correctly as the public property is
immutable.

This is an API break as all Signed constructors change -- this could be
avoided but seems like the correct choice.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-04 09:36:53 +03:00
Teodora Sechkova
785350b28e CI: Allow failure when publishing on coveralls
A failure during publishing of the coverage results
on coveralls should not fail the whole build job.
Allow the step to fail.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-04-29 15:31:56 +03:00
Jussi Kukkonen
765caf5a77
Merge pull request #1360 from MVrachev/key-role-classes
New API: Add Key and Role classes
2021-04-29 13:01:59 +03:00
Martin Vrachev
1ce94b95cb keyid: verify adding an existing key is ignored
Verify that adding an already existing key to keyid for a particular
role in Root won't create duplicate key.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-29 12:26:40 +03:00
Jussi Kukkonen
aaca8ecc35 tox: Don't use pre-release tools
Keep using newest versions of build tools, but don't use pre-releases:
* less downloading (with chances of failures) happens in the CI because
  versions change less often
* tools are less likely to break the build (or at least it happens less
  often)

This change should not affect the software under test as we install
pinned versions of those.

Note that this also doesn't affect black: tox still ends up with a
pre-release version of black because that project has never made an
actual release.

Fixes #1350

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-04-27 15:28:47 +03:00
Martin Vrachev
54a535e4c3 New API: Add Key/Role specific tests
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-27 15:26:41 +03:00
Martin Vrachev
0c9dc0ea36 Check the format of keyval in Root
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-27 15:26:39 +03:00
Martin Vrachev
0c3131b4a2 Make keyids in Role a set
From the specification:
"Clients MUST ensure that for any KEYID represented in this key list
and in other files, only one unique key has that KEYID."

The “only one unique key has that KEYID” is a requirement which can’t
be achieved if two keyids are the same.
So, in order to mandate that requirement it makes sense to use a set
which will guarantee us the keyid’s uniqueness.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-27 15:26:13 +03:00
Martin Vrachev
ef71c2df76 Add from_dict methods in Key and Role classes
The from_dict() method simplifies the object creation.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-27 15:19:03 +03:00
Martin Vrachev
eab8c318f0 Add a Role class and integrate it into Root
In the top level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-27 15:13:40 +03:00
Martin Vrachev
11e0a87bde Add Key class and integrate it into Root
In the top level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-27 15:09:48 +03:00
Jussi Kukkonen
878c8c6beb
Merge pull request #1363 from MVrachev/black-identation
Fix black docstring indentation errors
2021-04-27 15:04:37 +03:00
Martin Vrachev
1712b71b55 Fix black docstring indentation errors
Black was updated from 20.8b1 to 21.4b0 requiring that one-line
docstring don't add additional space before the closing quotes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-27 14:08:24 +03:00
Jussi Kukkonen
ec7173f03e
Merge pull request #1359 from sechkova/metadata-version
Fix api/metadata version check
2021-04-26 14:34:47 +03:00
Jussi Kukkonen
feb340f8da
Merge pull request #1345 from MVrachev/implement-adr-8
New metadata API: add support for ADR 0008
2021-04-22 21:54:32 +03:00
Martin Vrachev
79391f1d85 New API: accept metadata with unrecognized fields
In order to support ADR 0008 we would want to accept unrecognized
fields in all metadata classes.
Input that contains unknown fields in the 'signed' dictionary should
successfully deserialize into a Metadata object, and that object should
successfully serialize with the unknown fields intact.

Also, we should test that we support unrecognized fields when adding
new classes or modifying existing ones to make sure we support
ADR 0008.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-22 17:11:05 +03:00
Teodora Sechkova
92257a84c3
Fix metadata version check
VERSION is an integer that is greater than 0.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-04-21 16:35:20 +03:00
Jussi Kukkonen
41f7e809fe
Merge pull request #1354 from jku/metadata-from-string
api: Add Metadata.from_bytes()
2021-04-21 11:57:02 +03:00
Jussi Kukkonen
4e8738ffa5 api: Add Metadata.from_bytes()
This is essentially short-hand for
    JSONDeserializer().deserialize(data)
but seems much easier for the API user so may be worth it.

Metadata.from_file() now uses Metadata.from_bytes() internally.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-04-21 09:36:34 +03:00
Jussi Kukkonen
30ba6e9f9a
Merge pull request #1353 from MVrachev/patch-1
Add ADR8 to the ADR's index file
2021-04-19 10:27:55 +03:00
Martin Vrachev
f695bfd24e
Add ADR8 to the ADR's index file
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-16 12:26:42 +03:00
Jussi Kukkonen
ed3d00eb99
Merge pull request #1343 from MVrachev/adr8
Document ADR 0008 about unrecognized fields
2021-04-16 11:36:22 +03:00
Jussi Kukkonen
7bf41c953e
Merge pull request #1347 from avelichka/develop
Add a method of Signed metadata class returning information about metadata expiration
2021-04-16 08:49:58 +03:00
Martin Vrachev
d0fa8fc8ca Document ADR 0008 about unrecognized fields
Even though, this ADR documents something already implied in the TUF
spec in [document formats](https://theupdateframework.github.io/specification/latest/#document-formats)
it seems better to document this decision clearly so that it could be
referenced and give an explanation why someone can load a metadata file
with additional unrecognized fields.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-04-14 13:51:55 +03:00
Velichka Atanasova
1eaef0093b Add is_expired method to the Signed class
Checks metadata expiration against a reference time (a naive datetime in UTC).
If not provided, checks against the current UTC date and time.
Returns True if expiration time is less than the reference time.

Signed-off-by: Velichka Atanasova <avelichka@vmware.com>
2021-04-14 13:28:36 +03:00
Jussi Kukkonen
7074d6a718
Merge pull request #1337 from CrossStream/sandbox/rzr/review/master
tests: Use current python interpreter for sub tests
2021-04-13 11:25:51 +03:00
Philippe Coval
f00f89328e tests: Use current python interpreter for sub tests
Can be useful to run tests using distro runtimes,
(like python3 on Debian).

Relate-to: https://github.com/theupdateframework/tuf/issues/263
Origin: https://salsa.debian.org/rzr/python-tuf/-/tree/debian/review/master
Forwarded: https://github.com/theupdateframework/tuf/pull/1337
Signed-off-by: Philippe Coval <rzr@users.sf.net>
2021-04-12 23:34:31 +02:00