Commit graph

4247 commits

Author SHA1 Message Date
Marina Moore
f5d08bb0e8 Remove license from Thandy files that are no longer present
There are no longer any files in TUF that came from Thandy, and
so the dual license is no longer required.

Signed-off-by: Marina Moore <mnm678@gmail.com>
2021-06-29 12:15:07 -04:00
Joshua Lock
ef9a0081b8
Merge pull request #1442 from jku/fix-sign-return-value
Metadata API: Fix Metadata.sign() return value annotation
2021-06-29 14:09:45 +01:00
Jussi Kukkonen
505b82a82c Metadata API: Fix Metadata.sign() return value
We've been returning Signature objects since 49aa0fc167.

Also add a test case that does something with the returned signature.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-23 14:35:36 +03:00
Jussi Kukkonen
f458e9230a
Merge pull request #1456 from jku/tighten-comments
Metadata API: Rewrite comments
2021-06-23 10:20:12 +03:00
Jussi Kukkonen
7108ea2e0e
Merge pull request #1454 from sechkova/hashes-handle-sslib-errors
BaseFile._verify_hashes: handle sslib errors
2021-06-23 10:19:14 +03:00
Jussi Kukkonen
97da5ab991
Merge pull request #1416 from MVrachev/comprehensive-testing
New API: Comprehensive serialization testing
2021-06-23 10:17:50 +03:00
Jussi Kukkonen
b860ad813f
Merge pull request #1453 from avelichka/develop
Add 'ecdsa' to the list of supported key types
2021-06-23 10:17:19 +03:00
Jussi Kukkonen
79f4f41979 Metadata: Improve DelegatedRole docstring
Explain the ways a delegation can happen: Do not try to cover the
complete process (specification should do that) but offer enough
details that the complexity is not completely hidden from the viewer.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-22 15:33:26 +03:00
Jussi Kukkonen
38b6d440c0 Metadata API: Rewrite comments
Try to keep dostrings and comments to the point, avoid mentioning
details if they are not necessary or are likely to become outdated
and try to minimize number of comment lines.

Co-authored-by: Joshua Lock <jlock@vmware.com>
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-22 15:33:07 +03:00
Martin Vrachev
d0828bd81b New API: Comprehensive serialization testing
The idea of this commit is to separate (de)serialization testing outside
test_api.py and make sure we are testing from_dict/to_dict for all
possible valid data for all classes.

Jussi in his comment here:
https://github.com/theupdateframework/tuf/issues/1391#issuecomment-849390669
proposed using decorators when creating comprehensive testing
for metadata serialization.
The main problems he pointed out is that:
1) there is a lot of code needed to generate the data for each case
2) the test implementation scales badly when you want to add new
cases for your tests, then you would have to add code as well
3) the dictionary format is not visible - we are loading external files
and assuming they are not changed and valid

In this change, I am using a decorator with an argument that complicates
the implementation of the decorator and requires three nested functions,
but the advantages are that we are resolving the above three problems:
1) we don't need new code when adding a new test case
2) a small amount of hardcoded data is required for each new test
3) the dictionaries are all in the test module without the need of
creating new directories and copying data.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-06-22 12:51:40 +03:00
Teodora Sechkova
752a741d3a
Handle sslib exceptions in BaseFile._verify_hashes
Securesystemslib digest() and digest_fileobject()
calls raise sslib specific exceptions that need to be
handled and re-raised as TUF exceptions.

Updated tests in test_api.py accordingly.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-06-22 11:35:00 +03:00
Jussi Kukkonen
e6f743bbe3
Merge pull request #1435 from jku/handle-exceptions-in-verify
Handle exceptions in verify
2021-06-22 09:55:07 +03:00
Jussi Kukkonen
cfc7638ebe
Merge pull request #1451 from sechkova/hash-validation
api/metadata input validation: length and hashes
2021-06-22 09:54:09 +03:00
Velichka Atanasova
06c8fb8cd3 Add a test for the 'ecdsa' key type
Changes tests/repository_data/keystore/root_key3* to be an ecdsa key,
created and encrypted with the generate_ecdsa_key and
encrypt_key methods of securesystemslib.keys.
The test_updater_root_rotation_integration.py test
tests both repotool and updater.

Signed-off-by: Velichka Atanasova <avelichka@vmware.com>
2021-06-21 16:32:49 +03:00
Teodora Sechkova
328f637264
Remove trailing comma from test data
A trailing comma makes any element a one-item tuple.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-06-17 14:38:02 +03:00
Teodora Sechkova
e30faa89be
Remove empty hash dict check from MetaFile
The check for an empty hash dictionary is now part
of the hash validation function.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-06-17 14:38:02 +03:00
Teodora Sechkova
03f39b01e7
Add hash and length validation
- valid length: greater than zero
- valid hashes: a non-empty dictionary of type Dict[str, str]

Checking the validity of hash algorithms is not part
of the metadata input validation and is done by
securesystemslib during  hash verification.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-06-17 14:38:01 +03:00
Velichka Atanasova
0fa6c6f2ca Add 'ecdsa' to the list of supported key types
Signed-off-by: Velichka Atanasova <avelichka@vmware.com>
2021-06-17 11:48:30 +03:00
Jussi Kukkonen
70aff4c1a0 tests: Improve verify_signature tests
Test unknown signature algorithm/scheme.

Also shorten the incorrect (but syntactically valid) signature a bit.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-17 10:50:06 +03:00
Jussi Kukkonen
743c4408d4 Metadata API: Clean up verify_signature() exceptions
Aim to only raise UnsignedMetadataError from verify_signature().

Some of the situations could be things like UnsupportedAlgorithmError
-- where the underlying reason may be a missing dependency -- but it
seems impossible for a client to know whether it's that or whether it
is broken or malicious server side.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-17 10:48:40 +03:00
Jussi Kukkonen
4952b987a5 tests: Test verify_signature with explicit serializer
This is just a tiny bit more test coverage.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-17 10:48:09 +03:00
Jussi Kukkonen
39ed706d72
Merge pull request #1437 from sechkova/hash-verification
Add hash and length verification to MetaFile and TargetFile
2021-06-16 22:18:03 +03:00
Jussi Kukkonen
51c26b7b7a
Merge pull request #1428 from theupdateframework/dependabot/pip/certifi-2021.5.30
build(deps): bump certifi from 2020.12.5 to 2021.5.30
2021-06-16 20:30:22 +03:00
Jussi Kukkonen
6c4e2be196
Merge pull request #1450 from MVrachev/threshold-validation
Metadata API: Add simple threshold validation
2021-06-16 19:56:26 +03:00
Jussi Kukkonen
fa2268df5a
Merge pull request #1449 from MVrachev/key-validation
Metadata API: Add Key attributes types validation
2021-06-16 19:55:34 +03:00
Jussi Kukkonen
25e5f304ee
Merge pull request #1430 from MVrachev/spec_version-validation
New metadata API: spec_version attribute validation
2021-06-16 19:54:36 +03:00
Martin Vrachev
a9dc24adea Metadata API: Add a comment for Key validation
Clarify that we don't semantically validate "Key" instances during
initialization and that this is a responsibility of securesystemslib.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-06-16 16:37:48 +03:00
Martin Vrachev
6c5d970799 Metadata API: Add simple threshold validation
Probably there could be future API calls that modify "threshold"
to a new value, but the problem is we don't have a clear idea
if they would exist and what exactly they will do.
That's why it makes sense to validate against the potential problems
we can imagine - in this case, is passing a threshold below 1.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-06-15 18:06:31 +03:00
Martin Vrachev
f20664d2fc Metadata API: Add Key attributes types validation
In our discussion with Jussi we come to the conclusion that we want
to verify that all Key attributes contain values in the expected types,
but at the same time, we don't want to focus on validating the semantics
behind them.
The reason is that having a Key instance with invalid attributes is
possible and supported by the spec.
That's why we have a "threshold" for the roles meaning we can have up to
a certain number of invalid Keys until we satisfy
the required threshold.

Also, for deeper semantic validation it's better to be done in
securesystemslib which does the actual work with keys.

For context see: https://github.com/theupdateframework/tuf/issues/1438

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-06-15 17:35:02 +03:00
Martin Vrachev
41afb1e134 Validate spec_version during initialization
According to point 2 in the semver specification:
"A normal version number MUST take the form X.Y.Z where X, Y, and Z are
non-negative integers...". See: https://semver.org/#spec-item-2
Also, even though version strings like "2.0.0-rc.2" or "1.0.0-beta" are
valid strings in semantic versioning format, in TUF we never needed
to add letters for our specification number.
That's why I validate that: spec_version is a . separated string
and when split it has a length of 3 and that each of the
three elements is a number.

The modules under the tuf/api folder in TUF are an alternative TUF
implementation. That's why they should use their own constant for
SPECIFICATION_VERSION in tuf/metadata/api.

This time, I used a list for the SPECIFICATION_VERSION constant in order
to retrieve major and minor versions easier.

I use the SPECIFICATION_VERSION to check that the given spec_version is
supported against the tuf code spec version.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-06-14 17:54:14 +03:00
Jussi Kukkonen
2a5bfb9cac
Merge pull request #1424 from jku/enforce-unique-sigs
Metadata API: Store signatures as dict
2021-06-11 13:55:20 +03:00
Teodora Sechkova
dcdd33287c
Add basic input validation to {Meta,Target}File
Add basic checks for allowed input values during
objects' serialization.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-06-11 11:59:13 +03:00
Teodora Sechkova
22facb7753
Update test_api
Add tests for hash and length verification.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-06-11 11:59:09 +03:00
Teodora Sechkova
8710f8d71a
Add hash and length verification
Extend MetaFile and TargetFile classes with methods
for length and hash verification.  The common functionality
is implemented as static methods of the base class while
MetaFile and TargetFile implement the user API based on it.

Define LengthOrHasheMismathError.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-06-11 11:52:54 +03:00
Jussi Kukkonen
146eb105c1 Metadata API: Be more explicit when appending sigs
Clearing the OrderedDict makes it easier to see what happens and
avoids having to call OrderedDict() again.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-11 10:47:18 +03:00
Martin Vrachev
15eb0d93c4 Remove question about version validation place
In issue #1418 in this comment:
https://github.com/theupdateframework/tuf/issues/1418#issuecomment-852147689
I summarized the discussion we had with the participants in this issue.
In summary: no additional changes are needed for "version" validation
considering there is "bump_version()" function for that.

If we won't be adding "version" validation elsewhere we can keep it
the way it is.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-06-09 13:53:17 +03:00
Jussi Kukkonen
1ce36d0cd6 Metadata API: Use OrderedDict for signatures
Dict ordering is part of regular Dict from Python 3.7: Use OrderedDict
for signatures to make sure signatures are serialized in a reproducible
order even on 3.6.

The added benefit is that reader will immediately understand that the
order has some significance.

The actual type annotations are a bit convoluted because:
* typing does not include OrderedDict before 3.7 so can't use that
* Annotating inner types does not work for collections.OrderedDict
  in older pythons (so have to use the "stringified annotations")

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-09 11:21:38 +03:00
Jussi Kukkonen
e3190fca9d Metadata API: Store signatures as dict
store signatures in a Dict of keyid to Signature. This ensures
signature uniqueness. Raise in from_dict() if input contains multiple
different signatures for a keyid.

This changes Metadata object API, and makes it slightly different from
the file format: this is justified by making the API safer to use and
easier to validate.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-09 11:21:38 +03:00
Jussi Kukkonen
de78251b00
Merge pull request #1423 from jku/verify-in-key
Metadata API: implement sig verification in Key, store id in key
2021-06-09 10:14:45 +03:00
Jussi Kukkonen
414dfc829f Metadata API: Move signature verification to Key
This is likely not needed by users of the API (as they are interested
in the higher level functionality "verify delegate metadata with
threshold of signatures").

Moving verify to Key makes the API cleaner because including both
"verify myself" and "verify a delegate with threshold" can look awkward
in Metadata, and because the ugly Securesystemslib integration is now
Key class implementation detail (see Key.to_securesystemslib_key()).

Also raise on verify failure instead of returning false: this was found
to confuse API users (and was arguably not a pythonic way to handle it).

* Name the function verify_signature() to make it clear what is being
  verified.
* Assume only one signature per keyid exists: see #1422
* Raise only UnsignedMetadataError (when no signatures or verify failure),
  the remaining lower level errors will be handled in #1351
* Stop using a "keystore" in tests for the public keys: everything we
  need is in metadata already

This changes API, but also should not be something API users want to
call in the future when "verify a delegate with threshold" exists.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-07 13:20:26 +03:00
Jussi Kukkonen
41a6daca75 Metadata API: Add id to Key
This simplifies life for API users as usually a key needs its
identifier: this is already visible in how update() becomes simpler
in the API.

The downside is that 'from_dict()' now has two arguments (so arguably
the name is not great anymore but it still does _mostly_ the same job
as other from_dicts).

This is an API change, if a minor one.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-06-07 13:20:22 +03:00
Jussi Kukkonen
7f3b15e125
Merge pull request #1432 from avelichka/develop
Stop using formats.py in metadata.py
2021-06-04 09:43:44 +03:00
Velichka Atanasova
4e8a0fe140 Stop using formats.py in metadata.py
Currently we have one use of tuf/formats.py in tuf/api/metadata.py.
If we do the conversion of the expires string in metadata.py,
we can keep the two implementations separate.

Signed-off-by: Velichka Atanasova <avelichka@vmware.com>
2021-06-03 13:26:35 +03:00
Jussi Kukkonen
0b54cafa94
Merge pull request #1415 from MVrachev/targets-optional
new API: make sure targets in Targets can be empty
2021-06-02 11:19:43 +03:00
Jussi Kukkonen
d9a928e626
Merge pull request #1395 from jku/initial-mypy-integration
Build: Initial mypy integration
2021-06-01 14:33:47 +03:00
dependabot[bot]
8cfbfa5626
build(deps): bump certifi from 2020.12.5 to 2021.5.30
Bumps [certifi](https://github.com/certifi/python-certifi) from 2020.12.5 to 2021.5.30.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2020.12.05...2021.05.30)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-31 10:05:24 +00:00
Philippe Coval
f496c83e78 docs: Remove academics files
Duplication is not needed since files are hosted in website project:

https://github.com/theupdateframework/theupdateframework.io/tree/master/static/papers

Those generated files are not explicitly under Apache-2.0 licence
and AFAIK they can not be regenerated from missing (latex?) sources.

To avoid licence mixup.
It would help to have those files published elsewhere.
Meanwhile online (Github) links are used.

Debian had to repack the source package to make tarball compliant with DFSG
despite debian tools are known to be trustworthy,
this extra step would add weakess in the chain of trust

Cleanup done upstream would make distribution safer.

Bug: https://github.com/theupdateframework/tuf/issues/1161
Bug-Debian: https://salsa.debian.org/python-team/packages/tuf/-/merge_requests/11
Relate-to: https://github.com/theupdateframework/tuf/issues/263#issuecomment-835239415
Forwarded: https://github.com/theupdateframework/tuf/pull/1380
Relate-to: https://github.com/theupdateframework/specification/pull/160
Signed-off-by: Philippe Coval <rzr@users.sf.net>
2021-05-28 17:07:14 -04:00
Jussi Kukkonen
edeb8afaa7
Merge pull request #1421 from theupdateframework/dependabot/pip/urllib3-1.26.5
build(deps): bump urllib3 from 1.26.4 to 1.26.5
2021-05-27 19:58:47 +03:00
dependabot[bot]
85ca1da00e
build(deps): bump urllib3 from 1.26.4 to 1.26.5
Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.4 to 1.26.5.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/1.26.4...1.26.5)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-27 10:04:16 +00:00
Martin Vrachev
737c249067 new API: make sure targets in Targets can be empty
This change is relevant to the new metadata class Targets.

In the specification, when describing the Targets metadata file format
and more precisely "TARGETPATH" (or targets containing the actual
target files) it's said:
"It is allowed to have a TARGETS object with no TARGETPATH elements.
This can be used to indicate that no target files are available."

If there is no "TARGETPATH" keys for the dictionary "targets", this
would mean that "Targets.targets" is {}.
Make sure we test for that.

See: https://theupdateframework.github.io/specification/latest/#targetpath

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-25 13:15:00 +03:00