Commit graph

3827 commits

Author SHA1 Message Date
Joshua Lock
fdccb8dc0b
Merge pull request #1149 from theupdateframework/dependabot/pip/cryptography-3.1.1
build(deps): bump cryptography from 3.1 to 3.1.1
2020-09-23 13:00:55 +01:00
dependabot-preview[bot]
ec90e1cd75
build(deps): bump cryptography from 3.1 to 3.1.1
Bumps [cryptography](https://github.com/pyca/cryptography) from 3.1 to 3.1.1.
- [Release notes](https://github.com/pyca/cryptography/releases)
- [Changelog](https://github.com/pyca/cryptography/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pyca/cryptography/compare/3.1...3.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-09-23 10:30:35 +00:00
Joshua Lock
505f3545d5
Merge pull request #1145 from jku/silence-errors-to-be-raised
Silence errors to be raised
2020-09-22 13:42:27 +01:00
Joshua Lock
687506fa61
Merge pull request #1147 from jku/close-all-the-things
Close file objects, requests.Responses
2020-09-22 13:03:21 +01:00
Jussi Kukkonen
fb9d8e7d64 Download: Fix documentation
* Remove dead urls: trust reader to find Requests documentation on
  their own
* Mention that "stream" means that downloading the body is deferred

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-22 14:22:46 +03:00
Jussi Kukkonen
26f45858d7 Download: Don't leak requests.Responses
Use 'with' to avoid leaking responses when response.raise_for_status()
is used.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-22 14:22:46 +03:00
Jussi Kukkonen
b5a3c705db Avoid leaving unclosed file objects
* move code to only create objects after potential raises
* Use 'with' when possible
* close manually if those did not help

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-22 14:22:46 +03:00
Jussi Kukkonen
1e7ca5fb42 tests: Set root logger level too
We want the tests own log output visible as well, and they are not
under the "tuf" logger. Set root level to the same value as "tuf".

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-16 14:38:10 +03:00
Jussi Kukkonen
1e0a2a3103 docs: Mention how to run individual tests
Fixes #1076.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-15 22:34:12 +03:00
Jussi Kukkonen
03b15fb4be tests: Configure logging for all test files
all test_*.py files now accept zero or more '-v' to increase tuf
logging level. The default is now ERROR.

default: ERROR
"-v":    ERROR, but unittest prints test names
"-vv":   WARNING
"-vvv":  INFO
"-vvvv": DEBUG

Example to run a single test with DEBUG level:
  python3 test_updater.py -vvvv TestUpdater.test_4_refresh

Also make test_log.py restore the log level it modifies during test.

Fixes #1093

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-15 21:36:50 +03:00
Jussi Kukkonen
aad3bd49eb tests: remove test_init and test_exceptions
All of these tests create an exception and log it. They do not
actually test anything.

The alternative would be to change the log level to something that is
not error to prevent verbose error output on successful test runs --
but that still wouldn't make them actual tests.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-15 19:49:04 +03:00
Jussi Kukkonen
69a45946e6 Updater: Don't log errors that will be raised
Don't use log level ERROR when we are only raising an exception for user
to handle (the issue is not a bug in TUF: TUF is working as expected in
all of these cases). Don't log at all if all the info is included in the
raised exception.

Also definitely don't log at error level when we don't know if this will
even be raised (e.g. a 404 is expected at least once on every
Updater.refresh()).

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-15 19:49:04 +03:00
Joshua Lock
87e92d589f
Merge pull request #1146 from theupdateframework/dependabot/pip/cffi-1.14.3
build(deps): bump cffi from 1.14.2 to 1.14.3
2020-09-15 16:56:31 +01:00
dependabot-preview[bot]
549222a414
build(deps): bump cffi from 1.14.2 to 1.14.3
Bumps [cffi](https://github.com/python-cffi/release-doc) from 1.14.2 to 1.14.3.
- [Release notes](https://github.com/python-cffi/release-doc/releases)
- [Commits](https://github.com/python-cffi/release-doc/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-09-15 10:42:28 +00:00
Joshua Lock
74dd43bac8
Merge pull request #1144 from theupdateframework/dependabot/pip/iso8601-0.1.13
build(deps): bump iso8601 from 0.1.12 to 0.1.13
2020-09-15 11:36:01 +01:00
Jussi Kukkonen
4bcf761f35 Download: Do not log unnecessary errors
A mismatched length will lead to DownloadLengthMismatchError that will
be handled by user. There is no need to log Errors or Criticals on the
way.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-15 10:58:32 +03:00
dependabot-preview[bot]
ccfee2cf50
build(deps): bump iso8601 from 0.1.12 to 0.1.13
Bumps [iso8601](https://github.com/micktwomey/pyiso8601) from 0.1.12 to 0.1.13.
- [Release notes](https://github.com/micktwomey/pyiso8601/releases)
- [Commits](https://github.com/micktwomey/pyiso8601/compare/0.1.12...0.1.13)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-09-14 10:22:36 +00:00
lukpueh
eda46e11da
Merge pull request #1112 from lukpueh/simple-tuf-api
Add simple TUF role metadata model
2020-09-10 17:07:35 +02:00
Lukas Puehringer
f106435aa5 Remove iso8601 dependency from simple metadata api
Use builtin datetime instead of external iso6801 for simple
datetime string parsing. Also see
https://github.com/theupdateframework/tuf/issues/1065

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
228a4c72e0 Ticketize doc header todo items
See:
Add root metadata class to new TUF metadata model #1137
Add classes for complex metadata fields #1139
Add input validation to simple metadata api #1140

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
73dd72d54d Raise on bad signature count in Metadata.verify
Change Metadata.verify(key) behavior to raise an exception if
none or multiple signatures for the passed key are found on the
Metadata object.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
f9a4ebe1ea Re-order metadata methods logically and add vspace
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
387169fc11 Add from_json metadata convenience wrapper
Add convenience wrapper that takes a json string and passes it
to from_dict to create a Metadata object.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
f63dce6ddd Refactor metadata constructors and add factory
This commit better separates the Metadata class model from the
Metadata wireline format, by tailoring the constructors
towards class-based parameters and adding an additional
factory classmethod that creates Metadata objects based on the
wireline json/dictionary metadata representation. (pythonic
way of constructor overloading).

This 'from_dict' factory method recurses into the 'from_dict'
methods of each contained complex field/attribute that is also
represented by a class. Currently 'signed' is the only such
attribute.

This commit further:
- Changes optional constructor keyword arguments to mandatory
positional arguments: Reduces code and simplifies usage by
restricting it. For now, users are unlikely to call
constructor directly anyway, but the 'from_dict' factory (or
its 'from_json_file' wrapper) instead.

- Removes Signed.__expiration (datetime) vs. Signed.expires
(datestring) dichotomy: Keeping only one representation of the
same attribute in memory makes the interface simpler and less
ambiguous. We choose the datetime object, because it is more
convenient to modify. Transformation from and to the string
format required by the tuf wireline format is performed in the
corresponding metadata de/serialization methods, i.e.
('to_dict' and 'from_dict').

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
f738ea0273 Rename tuf metadata interface methods
Consistenly rename de/serialization interface methods, using
a 'from_' and 'to_' prefix.

read_from_json -> from_json_file
write_to_json  -> to_json_file
as_json        -> to_json
as_dict        -> to_dict
signed_bytes   -> to_canonical_bytes

The latter is also changed from a property to a method for
consistency with the other serialization methods.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
e61ae1bea3 Remove Signed.read_from_json metadata method
Remove metadata factory on Signed class, for the sake of API
simplicity/non-ambiguity, i.e. it's enough to have one
way of loading any Metadata, that is:
Metadata.read_from_json

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
21de660b66 Remove comments and unify quotes in api tests
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:28 +02:00
Lukas Puehringer
08bdc171e4 Add simple sign + verify Metadata methods (+tests)
Add simple methods to create or verify signatures of the
canonical_signed property of a Metadata object.

See corresponding docstrings for behavior and design
considerations.

The commit also adds tests and updates the test setup to load
some test keys into memory.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:18:19 +02:00
Lukas Puehringer
5cc73353fa Add metadata model class and method docstrings
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 16:09:22 +02:00
Lukas Puehringer
0d7e2680f2 Simplifies Timestamp.update method
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 15:59:10 +02:00
Lukas Puehringer
088e94055f Replace _get_written_metadata with as_json method.
Add simple as_json Metadata method and use it instead of repository
lib's internal _get_written_metadata function in write_to_json.

This commit further adds code documentation and the possibility to
write compact json by excluding whitespace to write_to_json, and
also removes a call to the sign method from write_to_json.

The commit also adds tests.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 15:59:10 +02:00
Lukas Puehringer
e997097d1c Add generic Metadata.read_from_json class method
Add generic read from json class method that returns a Metadata
object with a signed field that contains the appropriate Signed
subclass, based on the signed._type field of the read metadata.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 15:59:10 +02:00
Lukas Puehringer
b1dd3d6787 Skip api tests on Python < 3.6
The new metadata module uses constructs that are only available
on Python >= 3.6 (typing, f-format strings, etc.).

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-09-10 15:59:01 +02:00
Joshua Lock
7cc41c6fee
Merge pull request #1122 from joshuagl/joshuagl/release-0.14.0
Prepare 0.14.0 release
2020-09-10 09:51:37 +01:00
Joshua Lock
37b5d404c8
Merge pull request #1121 from joshuagl/joshuagl/rm-keyid-hash-algorithms
Remove accidentally introduced uses of keyid_hash_algorithms
2020-09-10 09:51:15 +01:00
Joshua Lock
3e68b3a07e Prepare 0.14.0 release
Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-09-09 11:11:48 +01:00
Joshua Lock
fcc6841247 More consistent formatting in RELEASE.md
Consistently enclose filenames referred to througout the release process in
backticks to ensure they are rendered in the code style.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-09-09 11:07:25 +01:00
Joshua Lock
7c18cbbbfb Remove uses of keyid_hash_algorithms
PR #1014 removed uses of keyid_hash_algorithms in favour of using the calculated
keyid values from the metadata. A few instances of this removal were
unintentionally reintroduced in PR #1016, when changing to explicitly passing
a list of hash algorithms rather than changing securesystemslib settings
values.

This change removes uneccessary uses of keyid_hash_algorithms.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-09-09 10:51:46 +01:00
Joshua Lock
c4617ff55f
Merge pull request #1102 from MVrachev/1080
Add a way to disable hash prefix when using consistent_snapshot
2020-09-02 16:28:31 +01:00
lukpueh
11a743c7fa
Merge pull request #1117 from theupdateframework/dependabot/pip/cryptography-3.1
build(deps): bump cryptography from 3.0 to 3.1
2020-09-02 13:11:13 +02:00
dependabot-preview[bot]
598e7a181b
build(deps): bump cryptography from 3.0 to 3.1
Bumps [cryptography](https://github.com/pyca/cryptography) from 3.0 to 3.1.
- [Release notes](https://github.com/pyca/cryptography/releases)
- [Changelog](https://github.com/pyca/cryptography/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pyca/cryptography/compare/3.0...3.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-27 10:26:19 +00:00
Joshua Lock
7b7a14ab42
Merge pull request #1074 from sechkova/delegations-update
Update targets delegations in generate_targets_metadata
2020-08-26 15:54:45 +01:00
Joshua Lock
28f0b676a1
Merge pull request #1016 from MVrachev/refactor-format-metadata-to-key
Refactor to use changed format metadata to key
2020-08-26 15:05:36 +01:00
Teodora Sechkova
b6307ddf6d
Fix typo in comment section
Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:52 +03:00
Teodora Sechkova
b3b0c041fe
Add test for delegations update
Add a new test case in test_generate_targets_metadata
to check if targets metadata is up-to-date with its delegated
roles.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:51 +03:00
Teodora Sechkova
05a70085b2
Update failing tests for generate_targets_metadata
Tests logic is modified to accommodate for the update of the
delegations during generate_targets_metadata().

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:51 +03:00
Teodora Sechkova
8f05420e68
Load delegated roles 'keyids' and 'threshold'
Use the delegation graph traversal during load_repository()
to load delegated roles' 'keyids' and 'threshold' by reading it
from the delegating role metadata.

If more than one delegation to the same role exists, only the first
one is loaded in roledb for this role.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:50 +03:00
Teodora Sechkova
f7c9fcb460
Update delegations in generate_targets_metadata()
Collect keys and threshold of delegated roles and update
delegations in generate_targets_metadata in a similar manner
as generate_root_metadata() does for top-level roles.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:50 +03:00
Teodora Sechkova
8f396a70eb
Move _keys_to_keydict() to repository_lib
Use _keys_to_keydict() for the  key dictionary generation in
generate_root_metadata().
Rename it as a public function keys_to_keydict().

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:46 +03:00
lukpueh
f54bbf5bd0
Merge pull request #1116 from sechkova/raise-missing-from
Re-raise exceptions explicitly using the 'from' keyword
2020-08-24 14:49:45 +02:00