Commit graph

4544 commits

Author SHA1 Message Date
Joshua Lock
6d18d53ec0
Merge pull request #1626 from joshuagl/joshuagl/build
Modernise packaging configuration
2021-10-21 20:01:55 +01:00
Joshua Lock
de1a3af019 build: more intentional about what's included in sdist
Our sdist has typically included everything from git apart from the CI
related files (.github/*, .fossa.yml, .readthedocs.yaml). Update our
MANIFEST.in and the check-manifest section of setup.cfg to be explicit
about this.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:30:46 +01:00
Joshua Lock
352f6c2c56 Add vscode project directory to gitignore
Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:30:46 +01:00
Joshua Lock
ada35c9e8f build: add pyproject.toml to list build tools
Per PEP 517 the pyproject.toml file lists tools required when building the
project with build: https://pypa-build.readthedocs.io/en/stable/index.html

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:30:46 +01:00
Joshua Lock
52ad17a710 build: update check-manifest options
Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:30:46 +01:00
Joshua Lock
ac0ea24ca9 Remove references to setup.py
We now use a static setup.cfg instead, update __init__.py and
docs/RELEASE.md to point there.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:30:46 +01:00
Joshua Lock
38ea974674 build: convert to static setuptools metadata
This is preferred and removes the crutch of invoking setup.py as a CLI
tool for building dists.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:30:46 +01:00
Joshua Lock
d3e34acd98 build: add docs to project_urls
Add a 'Documentation' entry to project_urls pointing to our stable docs
on readthedocs.io. This will result in a 'Documentation' entry under the
'Project links' section on PyPI.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:28:08 +01:00
Joshua Lock
36242adc74 build: recommend using build, not setup.py
Invoking setup.py directly is deprecated, see:
https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html

Therefore:
* remove the executable bit from setup.py's permissions
* remove the shebang entry from setup.py
* update the comments in setup.py to recommend using build to create dists
  and pip to install them

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:28:08 +01:00
Joshua Lock
4fd35434bd build: update MANIFEST.in to match sdist
Update the MANIFEST.in to be explicit about what we choose to ship in our
sdist. This _does not_ result in any additional files being included in
our sdist, but does remove warnings from build.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:28:08 +01:00
Joshua Lock
08decea2d0 Remove unused .gitmodules directory
Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:28:07 +01:00
Joshua Lock
2ab518b3f0 build: cleanup setup.cfg
* List license files in a new metadata section
* Remove .travis.yml from check-manifest section's ignore entry

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:28:07 +01:00
Joshua Lock
2ed51167f6 build: add build and release deps to requirements-dev
build, twine and wheel packages should all be installed in order to be
able to build and release python-tuf -- add those dependencies to
requirements-dev.txt

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:28:07 +01:00
Joshua Lock
9e113d6135 docs/RELEASE: use build for building dists
This is the PyPA recommend tool for building Python packages:
https://packaging.python.org/guides/distributing-packages-using-setuptools/

Furthermore, direct invocation of setup.py is long ago deprecated:
https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html

Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-10-21 13:28:07 +01:00
Jussi Kukkonen
69eb29fc80
Merge pull request #1628 from MVrachev/add-python3.10
Add python3.10 and fix test failures on python3.10
2021-10-21 14:40:43 +03:00
Martin Vrachev
2e94e39275 Use quotes for python version for github workflows
Fix GitHub workflow failures by using quotes for python versions.
It seems that adding `3.10` as a number is transformed then to `3.1`
which as a result is translated to Python version 3.1 instead of Python
version 3.10.
This seems to work for other projects as well:
https://github.com/MasoniteFramework/masonite4/blob/master/.github/workflows/pythontest.yml
https://github.com/python-pillow/Pillow/blob/main/.github/workflows/test-windows.yml
https://github.com/PyGithub/PyGithub/blob/master/.github/workflows/ci.yml

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-21 14:32:05 +03:00
Martin Vrachev
6ff852ad0f Add support for python 3.10
Python 3.10 is released on October 4-th 2021 and it seems
logical to add support for it as it doesn't require any major effort
from the project.

For reference read:
https://www.python.org/downloads/release/python-3100/

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-21 14:32:04 +03:00
Martin Vrachev
4c81340610 Replace depricated ssl function and fix CI errors
When I tried adding support for Python3.10 we had CI errors due to
test failures: https://github.com/theupdateframework/python-tuf/pull/1610/checks?check_run_id=3861875325
The problem comes from the fact that we start a subprocess
executing simple_https_server.py, but then we fail to communicate the
message we expect from the server process to the main process actually
running the test. We expect our custom message to be the first line
printed from the server process, but instead, a deprecation warning is
printed first about the usage of ssl.wrap_socket(). Our custom message
is printed second.
As of Python 3.7 this function has been deprecated:
https://docs.python.org/3/library/ssl.html#ssl.wrap_socket and for
whatever the reason we didn't get a warning when using it before.

My fix does what is suggested in the warning and replaces the usage of
ssl.wrap_socket() by instantiating a ssl.SSLContext object and then
calling SSLContext.wrap_socket().
This removes the warning.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-21 14:15:29 +03:00
lukpueh
0cf6ba2258
Merge pull request #1620 from lukpueh/misc-metadata-api-docs
Add missing method args docs in metadata API
2021-10-20 15:51:07 +02:00
Jussi Kukkonen
4aef2b2ae6
Merge pull request #1611 from theupdateframework/dependabot/pip/charset-normalizer-2.0.7
build(deps): bump charset-normalizer from 2.0.6 to 2.0.7
2021-10-20 12:04:39 +03:00
dependabot[bot]
9864e8ef5e
build(deps): bump charset-normalizer from 2.0.6 to 2.0.7
Bumps [charset-normalizer](https://github.com/ousret/charset_normalizer) from 2.0.6 to 2.0.7.
- [Release notes](https://github.com/ousret/charset_normalizer/releases)
- [Commits](https://github.com/ousret/charset_normalizer/compare/2.0.6...2.0.7)

---
updated-dependencies:
- dependency-name: charset-normalizer
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-20 08:40:11 +00:00
Jussi Kukkonen
6839e81edc
Merge pull request #1609 from theupdateframework/dependabot/pip/certifi-2021.10.8
build(deps): bump certifi from 2021.5.30 to 2021.10.8
2021-10-20 11:39:43 +03:00
dependabot[bot]
b642a44ce1
build(deps): bump certifi from 2021.5.30 to 2021.10.8
Bumps [certifi](https://github.com/certifi/python-certifi) from 2021.5.30 to 2021.10.8.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2021.05.30...2021.10.08)

---
updated-dependencies:
- dependency-name: certifi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-20 08:25:45 +00:00
Jussi Kukkonen
761349919b
Merge pull request #1621 from theupdateframework/dependabot/pip/cffi-1.15.0
build(deps): bump cffi from 1.14.6 to 1.15.0
2021-10-20 11:23:45 +03:00
Jussi Kukkonen
d19d40353d
Merge pull request #1616 from theupdateframework/dependabot/pip/idna-3.3
build(deps): bump idna from 3.2 to 3.3
2021-10-20 11:23:33 +03:00
Jussi Kukkonen
e86a61571c
Merge pull request #1625 from jku/release-0.19
Release 0.19.0
2021-10-19 17:21:41 +03:00
Jussi Kukkonen
f2f7f9df53 Release 0.19.0
For users of legacy client (tuf/client/) this is purely a security fix
release with no API or functionality changes. For ngclient and Metadata
API, some API changes are included.

All users are advised to upgrade.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-19 17:17:49 +03:00
Joshua Lock
4ad7ae48fd
Merge pull request from GHSA-wjw6-2cqr-j4qr
Fix client issue with rolenames as filenames
2021-10-19 14:21:29 +01:00
dependabot[bot]
0b9317a8a9
build(deps): bump cffi from 1.14.6 to 1.15.0
Bumps [cffi](http://cffi.readthedocs.org) from 1.14.6 to 1.15.0.

---
updated-dependencies:
- dependency-name: cffi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-14 10:06:30 +00:00
Lukas Puehringer
86d4b35a98 Add missing method args docs in metadata API
Affected methods are:

- Root.add_key()
- Root.remove_key()
- Targets.add_key()
- Targets.remove_key()
- DelegatedRole.is_delegated_path()
- Key.from_securesystemslib_key()

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-10-14 11:12:05 +02:00
Jussi Kukkonen
677377899e tests: Use spec version from Metadata API
When constructing new metadata from scratch, use the spec version
the API supports.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-13 15:59:56 +03:00
Jussi Kukkonen
7da1f1e41b legacy client: Remove dead code
_fileinfo_has_changed() and _update_fileinfo() have been unused internal
methods since 2016. Remove them.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-13 15:59:56 +03:00
Jussi Kukkonen
98e97e31d9 legacy client: Do local filename encoding in all places
The original commit 051b8229 handled the loading and saving metadata
cases but the legacy client actually checks for the files existence
in various other places:
 * _update_versioninfo() never reads the file but operates differently
   depending on whether the file exists or not
 * _move_current_to_previous() that copies files around
 * MultiRepoUpdater initialization: this only handle root.json so
   is still correct
 * _update_fileinfo() which is dead code

Fix the first two of these cases.
2021-10-13 15:59:56 +03:00
Jussi Kukkonen
f569754f5e tests: Fix a bug in RepoSimulator signer lookup 2021-10-13 15:59:56 +03:00
Jussi Kukkonen
b2b2f21f99 tests: Make sure legacy client copes with unusual rolenames
Make sure rolenames like "../a" won't trick ngclient into creating the
metadata file outside the metadata cache.

The test data was semi-manually created with RepositorySimulator:
this test code could use RepositorySimulator directly instead (like the
ngclient tests do) but that would require some more infrastructural
work.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-13 15:59:56 +03:00
Jussi Kukkonen
81e5862be9 legacy client: Encode rolenames when using as filenames
If an attacker manages to create arbitrary rolenames they could trick
the client into writing metadata files into unexpected locations:
To avoid directory traversal and writing files into unexpected
locations, encode the rolename before using it as filename.

If a client has delegated targets metadata with rolenames that have
percent-encoded characters in them, these metadata will now not be
found in local metadata cache and must be re-downloaded.

Note that this does not mean using rolenames that get encoded is
advisable (as forming the download URLs still has issues with them),
this just means the client will not do unsafe writes when it encounters
rolenames like this.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-13 15:59:56 +03:00
Jussi Kukkonen
1846e28ca3 tests: Test ngclient with unusual rolenames
Add support for adding delegated targets into RepositorySimulator.
Make the metadata URL parsing in RepositorySimulator more robust.

Add a test to make sure "../a" won't trick ngclient into creating the
metadata file outside the metadata cache.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-13 15:59:01 +03:00
Jussi Kukkonen
94ed456b05 ngclient: Encode rolenames when using as filenames
If an attacker manages to create arbitrary rolenames they could trick
the client into writing metadata files into unexpected locations:
To avoid directory traversal and writing files into unexpected
locations, encode the rolename before using it as filename.

If a client has delegated targets metadata with rolenames that have
percent-encoded characters in them, these metadata will now not be
found in local metadata cache and must be re-downloaded.

Note that this does not mean using rolenames that get encoded is
advisable (as forming the download URLs still has issues with them),
this just means the client will not do unsafe writes when it encounters
rolenames like this.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-13 15:47:58 +03:00
Jussi Kukkonen
a0cb100cd8 ngclient: Do not use urljoin to form metadata URL
urljoin considers the second URL to override the base URL if the second
one contains e.g. hostname: this could lead to ngclient downloading
from the wrong host entirely. Doing that would not compromise the
security of the system as the metadata would still need to be verified,
but would definitely be unexpected and a bug.

Note that we're still not encoding the rolename, it's just inserted into
the URL as is.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-10-13 15:47:58 +03:00
Jussi Kukkonen
4d8cbc7010
Merge pull request #1605 from MVrachev/snapshot-hashes-length-check
Introduce the idea of trusted/untrusted snapshot
2021-10-13 15:44:07 +03:00
dependabot[bot]
1351184028
build(deps): bump idna from 3.2 to 3.3
Bumps [idna](https://github.com/kjd/idna) from 3.2 to 3.3.
- [Release notes](https://github.com/kjd/idna/releases)
- [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst)
- [Commits](https://github.com/kjd/idna/compare/v3.2...v3.3)

---
updated-dependencies:
- dependency-name: idna
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-13 10:05:27 +00:00
Martin Vrachev
717eef9bb5 Repo simulator: make delegates() to all_targets()
Modify RepositorySimulator function delegates() to all_targets(), so
that all targets can be traversed and updated with one cycle when
calling update_snapshot() (which is the only use case for now for
delegates()).

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-13 10:40:29 +03:00
Martin Vrachev
f1f76d259f Repository_simulator: add a flag to compute hashes
Add an option to calculate the hashes and length for timestamp/snapshot
meta.
This will help to cover more use cases with the repository simulator.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-13 10:40:29 +03:00
Martin Vrachev
a30425c20d Introduce the idea of trusted/untrusted snapshot
If you do the following steps:
1. call Updater.refresh() and load, verify and cache all metadata files
2. modify timestamp snapshot meta information:
(One or more of hashes or length for snapshot changes here)
3. call Updater.refresh() again
4. root and timestamp will be updated to their latest versions
5. local snapshot will be loaded, but hashes/length will be different
than the ones in timestamp.snapshot_meta and that will prevent loading
6. remote snapshot is loaded and verification starts
then when executing step 6 the rollback checks will not be done because
the old snapshot was not loaded on step 5.

In order to resolve this issue, we are introducing the idea of trusted and
untrusted snapshot.
Trusted snapshot is the locally available cached version. This version has
been verified at least once meaning hashes and length were already checked
against timestamp.snapshot_meta hashes and length.
That's why we can allow loading a trusted snapshot version even if there is a
mismatch between the current timestamp.snapshot_meta hashes/length and
hashes/length inside the trusted snapshot.
Untrusted snapshot is the one downloaded from the web. It hasn't been verified
before and that's why we mandate that timestamp.snapshot_meta hashes and length
should match the hashes and legth calculated on this untrusted version of
snapshot.

As the TrustedMetadataSet doesn't have information which snapshot is trusted or
not, so possibly the best solution is to add a new argument "trusted"
to update_snapshot.
Even though this is ugly as the rest of the update functions doesn't
have such an argument, it seems the best solution as it seems to work
in all cases:
- when loading a local snapshot, we know the data has at some point been
trusted (signatures have been checked): it doesn't need to match hashes
now
- if there is no local snapshot and we're updating from remote, the
remote data must match meta hashes in timestamp
- if there is a local snapshot and we're updating from remote, the remote
data must match meta hashes in timestamp

Lastly, I want to point out that  hash checks for metadata files are not
essential to TUF security guarantees: they are just an additional layer of
security that allows us to avoid even parsing json that could be malicious -
we already know the malicious metadata would be stopped at metadata
verification after the parsing.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-13 10:40:28 +03:00
Jussi Kukkonen
cb94504ba5
Merge pull request #1596 from theupdateframework/dependabot/pip/cryptography-35.0.0
build(deps): bump cryptography from 3.4.8 to 35.0.0
2021-10-12 15:43:13 +03:00
Teodora Sechkova
88245f15dd
Merge pull request #1591 from MVrachev/consistent-targets
Fix handling consistent targets same as legacy updater
2021-10-12 12:52:56 +03:00
Jussi Kukkonen
5cdc7dc616
Merge pull request #1608 from sechkova/sleep-before-round
ngclient: remove sleep_before_round
2021-10-11 11:40:59 +03:00
Teodora Sechkova
a5096a88b1
ngclient: remove sleep_before_round
The purpose of this config was to ensure blocking
inside the download loop and releasing CPU resources.

To our best knowledge the network stack currently used
in RequestsFetcher will always block inside the loop
and the issue cannot be reproduced.

'chunk_size' and 'socket_timeout' are currently the
settings provided by RequestsFetcher to tweak
CPU usage and download granularity.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-10-07 15:32:20 +03:00
Martin Vrachev
c3e746a096 Tests: assert that test_targets use hash prefixes
Make sure that hash prefixes are added when downloading a target
through the repository simulator.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-07 15:28:21 +03:00
Martin Vrachev
0d73220dff Use decorator in test_updater_with_simulator
Reuse the decorator defined in tests/utils.py in order
to receive more helpful messages when an assertion
fails in test_tragets().

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-07 15:28:20 +03:00