Commit graph

3960 commits

Author SHA1 Message Date
Lukas Puehringer
b5252fed65 ADR0005: Decide on python code style guide
Use Google style guide with refinements, because the Google style
guide is a comprehensive, well-established style guide that is
mostly based on PEP-8 and was accepted by everyone on the TUF team.

There is no need to replicate these recommendations. However, we do
provide a very slim document with additional refinements, in order
to emphasize on items the we consider especially important, want to
be handled differently, or in one specific way, where the Google
guide would allow multiple.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
Co-authored-by: Joshua Lock <jlock@vmware.com>
2020-12-04 10:39:24 +01:00
lukpueh
d3cd0cd0cd
Merge pull request #1229 from lukpueh/adr0004
ADR0004: Justify extent of OOP in metadata model
2020-12-01 08:56:01 +01:00
Lukas Puehringer
229e9df630 ADR0004: Justify extent of OOP in metadata model
Add MADR that justifies why we want to add custom classes for
complex tuf metadata attributes.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-11-30 14:59:56 +01:00
lukpueh
2a376ae7a7
Merge pull request #1228 from MVrachev/fix-ci
TOX: Install securesystemslib in non-editable mode
2020-11-27 16:20:29 +01:00
Martin Vrachev
0b0e5c3aab TOX: Install securesystemslib in non-editable mode
Installing securesystemslib in editable mode leads to a problem
in sys.path where we have two "tests" packages.
By not installing securesystemslib in an editable mode we are not
adding the securesystemslib tests to sys.path.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-27 16:39:30 +02:00
lukpueh
fc4b77f92c
Merge pull request #1226 from jku/updater-close-file-object
Updater: close file object
2020-11-27 12:29:08 +01:00
lukpueh
901496dd46
Merge pull request #1220 from sechkova/adr0003
ADR0003: where to develop TUF 1.0.0
2020-11-27 12:05:58 +01:00
Teodora Sechkova
3370005e7d
ADR003: Add pros and cons of the options
Describe pros of developing TUF 1.0.0 in a subdirectory
of the current implementation against the rest of the options.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-11-27 12:26:52 +02:00
Teodora Sechkova
1e24977677
ADR003: describe transition to stand-alone TUF
Describe the steps for transitioning from TUF 1.0.0
in a subdirectory to stand-alone TUF 1.0.0

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-11-27 12:26:52 +02:00
Teodora Sechkova
3a1ec87d52
ADR0003: where to develop TUF 1.0.0
Document the outcome of #1126 to develop TUF 1.0.0
in a subdirectory of the current TUF implementation.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-11-27 12:26:48 +02:00
Jussi Kukkonen
6101817b4c Updater: Close temp file in exception cases
If during updater.download_target() the download succeeds but a later
check fails (e.g. BadHashError), remember to close the tempfile.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-11-27 12:19:01 +02:00
Jussi Kukkonen
e54869c98c Tests: Fix first line of test server output
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-11-27 12:18:44 +02:00
Joshua Lock
2302f0dc57
Merge pull request #1225 from joshuagl/joshuagl/release-0.16
Prepare 0.16.0 release
2020-11-26 13:42:57 +00:00
Joshua Lock
7ff26717a1 Prepare 0.16.0 release
Update docs/CHANGELOG.md and bump version number for a 0.16.0 release

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-11-26 13:15:14 +00:00
lukpueh
e061bc6ebb
Merge pull request #1202 from joshuagl/joshuagl/updater-simplify
Simplify updater logic for downloading and verifying target files
2020-11-26 13:48:35 +01:00
Joshua Lock
372e2184e0 client: simplify loop exit logic
Simplify the loop exit logic in _get_target_file() to simply return a
verified file_object, once we have it, rather than breaking from the loop
and then returning the file_object.

This converts a use of a try/except/else to a try/except and is a little
easier to read.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-11-26 10:01:14 +00:00
Joshua Lock
e005801891
Merge pull request #1216 from MVrachev/fix-imports-and-default
Fix imports and default value for function arg
2020-11-25 16:19:09 +00:00
Joshua Lock
481496ca6d
Merge pull request #1201 from theupdateframework/dependabot/pip/certifi-2020.11.8
build(deps): bump certifi from 2020.6.20 to 2020.11.8
2020-11-25 14:37:11 +00:00
Joshua Lock
60dcb95656
Merge pull request #1219 from jku/avoid-reading-target-in-memory
Avoid reading target in memory
2020-11-25 12:07:19 +00:00
dependabot-preview[bot]
0f6a275b11
build(deps): bump certifi from 2020.6.20 to 2020.11.8
Bumps [certifi](https://github.com/certifi/python-certifi) from 2020.6.20 to 2020.11.8.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2020.06.20...2020.11.08)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-25 12:03:09 +00:00
Joshua Lock
fdb74bb0a1
Merge pull request #1222 from theupdateframework/dependabot/pip/cffi-1.14.4
build(deps): bump cffi from 1.14.3 to 1.14.4
2020-11-25 12:01:57 +00:00
dependabot-preview[bot]
8e4383d140
build(deps): bump cffi from 1.14.3 to 1.14.4
Bumps [cffi](https://github.com/python-cffi/release-doc) from 1.14.3 to 1.14.4.
- [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-11-25 10:41:29 +00:00
lukpueh
3050252554
Merge pull request #1203 from joshuagl/joshuagl/adr2
ADR0002: document deprecation strategy for current release series post 1.0
2020-11-24 16:49:50 +01:00
Joshua Lock
35177fbe9c ADR0002: document deprecation strategy post 1.0
Per the discussion in #1127 opt to support the old release on a best-effort
basis.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-11-24 15:26:51 +00:00
lukpueh
9f8979b7c1
Merge pull request #1218 from joshuagl/joshuagl/root-self-verify-two
Fix root self verification to only count a keyid once towards the threshold
2020-11-24 15:16:36 +01:00
Joshua Lock
83ac7be525 client: new root sigs only counted once per keyid
When verifying newly downloaded root metadata with the keys listed in the
root metadata being verified, multiple signatures with the same keyid
should not be counted towards the threshold. A keyid should only count
once towards the threshold.

This fixes the _verify_root_self_signed() method introduced in PR #1101 to
ensure that keyids are only counted once when verifying a threshold of new
root signatures.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-11-24 13:22:47 +00:00
Joshua Lock
71cb00478e tests: test that new root sigs only count once
When the updater is verifying that the new root metadata is signed by a
threshold of keys defined by the new root metadata itself, multiple
signatures with the same keyid should not be counted more than once
towards the threshold.

Implement a test for this, which currently fails.

Reported-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-11-24 13:22:47 +00:00
Martin Vrachev
028d1bc9f7 Make "utils" import more definite
Currently, we are importing the "utils" module in tests/utils
with "import utils".
This could become a problem when there is another module with
the same general name "utils" and could lead to import mistakes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-23 22:17:31 +02:00
Martin Vrachev
cf4902131e Fix empty list as a default value for function arg
This quote from the Google Python style guide made me realize
why empty list as a default value for an argument could be
dangerous:

"Default arguments are evaluated once at module load time.
This may cause problems if the argument is a mutable object
such as a list or a dictionary. If the function modifies the object
(e.g., by appending an item to a list), the default value is modified."

Read more here:
https://google.github.io/styleguide/pyguide.html#2123-cons

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-23 21:55:51 +02:00
Jussi Kukkonen
fcdae97b8a Updater: clean up _check_hashes() comments
Remove duplicate/obvious comments, tighten other comments and a logline

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-11-23 20:37:11 +02:00
Jussi Kukkonen
e86520a667 Updater: Avoid reading whole target file in memory
We don't want to read the whole file in memory as it can be huge. Use
digest_fileobject() instead: This way Securesystemslib will read the
file in chunks.

Securesystemslib already takes care of seeking to beginning of file.

Fixes #1215

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-11-23 20:37:11 +02:00
Joshua Lock
9d3ef85192
Merge pull request #1193 from sechkova/metadata-root
Add root metadata class to new TUF metadata model
2020-11-23 16:58:17 +00:00
Joshua Lock
2aae0bad69
Merge pull request #1198 from MVrachev/threads-port-generation
Tests: Use Queue for process communication which replaces tmp files and use OS for port creation
2020-11-23 15:40:19 +00:00
lukpueh
6333a4ec7a
Merge pull request #1217 from lukpueh/sort-metadata-sigs
Make metadata signatures ordered by keyid
2020-11-23 10:40:58 +01:00
Lukas Puehringer
846604a259 Make metadata signatures ordered by keyid
In 'repository_lib._generate_and_write_metadata' sort the set of
signing key keyids alphabetically before passing them on to signing
functions, to make the order in which signatures are added
deterministic.

This is above all beneficial for testing.

This commit also adds an exemplary test for signatures on root
metadata using the repository_tool interface to setup all the state
that required to test _generate_and_write_metadata.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-11-19 17:42:27 +01:00
Martin Vrachev
ad9c82409d Tests: Remove "temp file" from comments
Update the comments to not mention the usage of temp file
for logging regarding the instances of the TestServerProcess class.

Also, remove one unused import.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Martin Vrachev
ea20e86380 Make "bind successful" the first server message
The current implementation for server startup in TestServerProcess
relies on the fact that "bind successful..." is the first message
sent by the server process.
Make sure that this is true and leave a comment about this.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Martin Vrachev
2104dab897 Add tests for tests/utils.py
We want to make sure that server are successfully started in
the common use cases and that the new port generation works.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Martin Vrachev
6462779230 Remove sleep from test_slow_retrieval_attack.py
Now, after we can use wait_for_server and the retry mechanism
of TestServerProcess in utils.py we no longer need to use
sleep in this test file.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Martin Vrachev
54c837f654 Remove unused random module imports
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Martin Vrachev
5d9a6f6598 Tests: Queue replace tmp files, OS port creation
These changes can be summarized with the following bullets:
- Delegate generation of ports used for the tests to the OS
- Use thread-safe Queue for processes communication
instead of temporary files
- Remove all instances of port generation or hardcoded ports
- Make test_slow_retrieval.py fully conform with TestServerProcess

Delegate generation of ports used for the tests to the OS is much
better than if we manually generate them, because there is always
a chance that the port we have randomly pick turns out to be taken.
By giving 0 to the port argument we ask the OS to give us
an arbitrary unused port.

Use thread-safe Queue for processes communication instead of temporary
files became a necessity because of findings made by Jussi Kukkonen.
With the latest changes made in pr 1192 we were rapidly reading
from the temporary files and Jussi found that it happened rarely
the successful message "bind succeded..." to be corrupted.
It seems, this is a thread issue related to the thread redirecting
the subprocess stdout to the temp file and our thread rapidly
reading from the file.
By using a thread-safe Queue we eliminate this possibility.
For reference read:
https://github.com/theupdateframework/tuf/issues/1196

Lastly, test_slow_retrieval.py and slow_retrieval.py were refactored.
Until now, slow_retrieval.py couldn't use the TestServerProcess class
from utils.py for a port generation because of a bug related to
httpd.handle_request().
Now, when we use httpd.serve_forever() we can refactor both of those
files and fully conform with TestServerProcess.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Martin Vrachev
592a94726d Remove test_slow_retrieval expected failure test
Remove the test with mode 2 ('mode_2': During the download process,
the server blocks the download by sending just several characters
every few seconds.) from test_slow_retrieval.

This test is marked as "expected failure" with the purpose of
rewriting it one day, but slow retrievals have been removed from
the specification and soon it will be removed from the tuf
reference implementation as a whole.
That means that the chances of making this test useful are close
to 0 if not none.

The other test (with mode 1) in test_slow_retrieval is not removed.

For reference:
- https://github.com/theupdateframework/specification/pull/111
- https://github.com/theupdateframework/tuf/pull/1156

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
lukpueh
549b899a85
Merge pull request #1210 from theupdateframework/dependabot/pip/requests-2.25.0
build(deps): bump requests from 2.24.0 to 2.25.0
2020-11-13 12:25:42 +01:00
lukpueh
65d5987fcb
Merge pull request #1212 from theupdateframework/dependabot/pip/urllib3-1.26.2
build(deps): bump urllib3 from 1.25.11 to 1.26.2
2020-11-13 12:25:23 +01:00
dependabot-preview[bot]
d2f51d6cde
build(deps): bump urllib3 from 1.25.11 to 1.26.2
Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.25.11 to 1.26.2.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/master/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/1.25.11...1.26.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-13 10:23:47 +00:00
lukpueh
af18e75413
Merge pull request #1208 from lukpueh/migrate-travis
Update Travis CI build badge/docs after migration
2020-11-12 15:57:00 +01:00
dependabot-preview[bot]
0c0e1146a3
build(deps): bump requests from 2.24.0 to 2.25.0
Bumps [requests](https://github.com/psf/requests) from 2.24.0 to 2.25.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.24.0...v2.25.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-12 10:22:52 +00:00
Lukas Puehringer
d46ebd016e Update Travis CI build badge/docs after migration
Update badge URL in readme after migrating from travis-ci.org to
travis-ci.com, due to brownout on the former.

Migration was performed via Travis Web UI:
https://docs.travis-ci.com/user/migrate/open-source-repository-migration

NOTE: This is a quick fix to speed up Travis builds until we switch
to GitHub Actions (#1195)

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-11-12 10:07:53 +01:00
Joshua Lock
02416e3376 updater: more optimal file length checking
Rather than read to the end of the file in order to determin its size, use
the whence value of seek() to move the file object's position to the end
of the file, then the tell() method of the file object to read the current
position in bytes.

Co-authored-by: Jussi Kukkonen <jkukkonen@vmware.com>
Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-11-11 15:53:07 +00:00
lukpueh
11e2f4ca48
Merge pull request #1191 from lukpueh/adopt-sslib-interface-changes
Adopt sslib keygen interface encryption changes
2020-11-11 11:31:35 +01:00