Commit graph

3578 commits

Author SHA1 Message Date
Sebastien Awwad
82fe71a570 minor: fix bug in test_developer_tool
which failed to fail the test if an expected exception was raised.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2020-03-17 09:56:47 +01:00
lukpueh
c63b7f3bdc
Merge pull request #1001 from lukpueh/rm-obsolete-client-doc
Remove obsolete client documentation
2020-03-16 13:03:32 +01:00
Lukas Puehringer
7816000abc Remove incomplete and outdated client doc
An up-to-date version of the minimal client usage instructions
from client_setup_and_repository_example.md can be found in
the main TUF tutorial.

More comprehensive documentation of the tuf client can be found in
tuf/client/README.md, which also needs a revision.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-03-16 10:33:57 +01:00
Lukas Puehringer
6f94aa1653 Remove link to outdated client docs in tutorial
Remove link to incomplete and severely outdated
client_setup_and_repository_example.md in client section of
TUTORIAL.md.

Instead we should link (or move the entire client tutorial part) to
tuf/client/README.md, which is more comprehensive and less outdated
than above document (see #808).

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-03-16 10:31:14 +01:00
lukpueh
45a82945be
Merge pull request #997 from joshuagl/joshuagl/maint
Update MAINTAINERS
2020-03-11 16:12:41 +01:00
Joshua Lock
ca953c3335 Update MAINTAINERS
Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 14:58:51 +00:00
lukpueh
1cf085a360
Merge pull request #988 from joshuagl/joshuagl/issue-933
Remove root from snapshot
2020-03-11 14:34:09 +01:00
lukpueh
256aef8695
Merge pull request #989 from joshuagl/logger
Use __name__ for loggers, per convention
2020-03-11 14:33:35 +01:00
Joshua Lock
99ba904cbb Remove redundant code branch in Updater
Remove logic for handling of root metadata in _update_metadata_if_changed()
as root metadata is no longer fetched with this function, instead
_update_root_metadata() serves this purpose.

Additionally remove redundant mention of root metadata in a TODO comment.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 12:55:16 +00:00
Joshua Lock
3720b2358e Re-generate repository and client test metadata
Re-generate metadata to adopt the change that root.json is no longer
listed in snapshot.json

```
 # Remove repository and client data
cd tests/repository_data && rm -rf repository client
 # Generate metadata
python generate.py
 # Duplicate metadata files
cp -r client/test_repository1 client/test_repository2
 # Recover non-signed file
git checkout client/map.json
```

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:35:37 +00:00
Joshua Lock
4bd9b5ef6b Improve determinism of test repository generator
One of the created target files has its file permissions encoded in the
targets metadata via the custom attribute of the add_target() function.
On Linux-based OS the umask value of the environment the script is run
in can result in different octal permissions for the created file, i.e.
on Fedora the default umask is 0002 (default permissions 664) whereas
on Debian/Ubuntu the default umask is 0022 (default permissions 644).

Explicitly chown 'file1' to octal permissions 644 so that the generated
data has the same custom attributes for targets regardless of which
Linux host they are generated on.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:35:37 +00:00
Joshua Lock
a134db0a43 Update test repository data generator
* Fix the path referenced in the Purpose
* Change add_target() calls to pass file paths relative to targets dir

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:35:37 +00:00
Joshua Lock
8dafe6018d Update docstrings and comments for the Updater object
The workflow for downloading metadata for top-level roles has changed.

Root is now updated and verified by stepping through a chain of trust
based on the currently available root metadata. For that reason
root.json is no longer needed in snapshot and has been dropped from
there per theupdateframework/specification#40

Update docstrings and comments in the Updater object to reflect the
correct flow of metadata updates:
root (if necessary) -> timestamp -> snapshot -> targets

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:35:37 +00:00
Joshua Lock
8dfee1a106 Update docs/METADATA.md to reflect recent spec change
The specification was updated in PR #40 to remove root.json from
snapshot.json

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:35:37 +00:00
Joshua Lock
8f13fe5add Update tests for removal of root.json from snapshot.json
Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:15:06 +00:00
Joshua Lock
0c972717d0 Remove root from snapshot
In PR #40 aginst the specification "root.json" has been removed from
the meta dictionary in "snapshot.json".

Update generate_snapshot_metadata() to no longer add an entry for
root.json to root.json

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:15:06 +00:00
lukpueh
ba57da0bb8
Merge pull request #993 from joshuagl/joshuagl/quickblake
Support blake algorithms for file hashing
2020-03-10 17:33:30 +01:00
lukpueh
4fe29d138d
Merge pull request #992 from lukpueh/fix-tutorial-typo
Quickfix critical tutorial typo
2020-03-06 11:41:46 +01:00
Lukas Puehringer
c490a8daee Quickfix critical tutorial typo
In tutorial code snippet fix a call to repository.mark_dirty that
passes a non-existing bin role name raising:
"tuf.exceptions.UnknownRoleError: Role name does not exist: 90-7"

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-03-06 10:47:52 +01:00
Joshua Lock
930d832f87 Don't hard-code hash algo used in timestamp for snapshot
Timestamp.json includes a METAFILES entry for snapshot.json. METAFILES
includes HASHES:
"HASHES is the dictionary that specifies one or more hashes, including the
cryptographic hash function. For example: { "sha256": HASH, ... }."

We've been hard-coding this to a single sha256 hash, as that's the default
algorithms argument of securesystemlib.util.get_file_details() -- this
feels wrong. Change to using the new tuf.settings.FILE_HASH_ALGORITHMS
setting.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-05 17:55:38 +00:00
Joshua Lock
1f0cb9cd52 Add new setting for file hashing algorithms
Using securesystemslib.settings.HASH_ALGORITHMS is undersirable, because
it binds tuf to an implementation detail of the underlying library.
In this specific instance of file hashing algorithms it's even more
undesirable because it's overloading the intended use of the setting
which is "algorithm(s) [...] used to generate key IDs".

Add a new setting tuf.settings.FILE_HASH_ALGORITHMS, with a default
value of ['sha256', 'sha512'] (that matches the current value of
securesystemslib.settings.HASH_ALGORITHMS), to be used for file
hashing operations in tuf.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-05 17:55:38 +00:00
lukpueh
679348ffcf
Merge pull request #990 from theupdateframework/dependabot/pip/pycparser-2.20
build(deps): bump pycparser from 2.19 to 2.20
2020-03-05 14:43:14 +01:00
dependabot-preview[bot]
fe7c852293
build(deps): bump pycparser from 2.19 to 2.20
Bumps [pycparser](https://github.com/eliben/pycparser) from 2.19 to 2.20.
- [Release notes](https://github.com/eliben/pycparser/releases)
- [Changelog](https://github.com/eliben/pycparser/blob/master/CHANGES)
- [Commits](https://github.com/eliben/pycparser/compare/release_v2.19...release_v2.20)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-05 10:34:58 +00:00
lukpueh
bb94304eb8
Merge pull request #985 from lukpueh/quickfix-win-py27-tests
Fix failing AppVeyor Python2.7 tests
2020-03-03 12:04:53 +01:00
Joshua Lock
292b18926b Use __name__ for loggers, per convention
Replace hard-coded logger names with __name__. For the most part this just uses
the standard conventions to create the same logger hierarchy as existed before.
The only real difference is that loggers created for printing during tests are
no longer part of the 'tuf' hierarchy.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-03 10:36:39 +00:00
lukpueh
83d6ded134
Merge pull request #987 from theupdateframework/dependabot/pip/securesystemslib-colorscryptopynacl--0.14.2
build(deps): bump securesystemslib[colors,crypto,pynacl] from 0.14.0 to 0.14.2
2020-02-28 14:03:50 +01:00
dependabot-preview[bot]
797ccf0ac4
build(deps): bump securesystemslib[colors,crypto,pynacl]
Bumps [securesystemslib[colors,crypto,pynacl]](https://github.com/secure-systems-lab/securesystemslib) from 0.14.0 to 0.14.2.
- [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.14.0...v0.14.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-27 10:52:32 +00:00
Lukas Puehringer
842f843210 Remove duplicate testing simple_server.py
tests/simple_server.py was copied to tuf/scripts/ to "make testing
easier" (cf84d3f51f), although with
the current test setup the original (and recently patched to fix an
Windows/Py2 test issue) test simple_server.py can be used just as
well.

This commit:
- removes tuf/scripts/simple_server.py
  Note: that version slightly differed from the original test
  server, probably due to demands by the linter that is only executed
  on the tuf core code and not on the tests. However, for the testing
  purposes of simple_server.py these changes (i.e., `SystemRandom()`,
  `if __name__ =='__main__':`) are not necessary.
- updates the tests that used tuf.scripts.simple_server to instead
  use tests.simple_server,
- updates setup.py to not install the simple_server module as
  script, when installing tuf, as it is only a testing script and
  not meant for end-user usage.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-25 14:55:36 +01:00
Lukas Puehringer
7dbb30ae10 Fix failing AppVeyor Python2.7 tests
Since #885 the tests in TestUpdater and TestKeyRevocation fail on
Appveyor Python 2.7 builds. After some live debugging, it turns out
that the tests fail due to the extra amount of http requests to
the simple http server (see tests/simple_server.py) that were
added in #885.

The simple server runs in a subprocess and is re-used for the
entire TestCase. After a certain amount of requests it becomes
unresponsive. Note that neither the subprocess exits (ps -W), nor
does the port get closed (netstat -a). It just doesn't serve the
request, making it time out and fail the test.

The following script can be used to reproduce the issue (run in
tests directory):

```python
import subprocess
import requests
import random

counter = 0

port = random.randint(30000, 45000)
command = ['python', 'simple_server.py', str(port)]
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
url = 'http://localhost:'+str(port) + '/'

sess = requests.Session()

try:
  while True:
    sess.get(url, timeout=3)
    counter +=1

finally:
  print(counter)
  server_process.kill()
```

It fails repeatedly on the 69th request, but only if
`stderr=subprocess.PIPE` is passed to Popen. Given that for each
request the simple server writes about ~60 characters to stderr,
e.g. ...
```
127.0.0.1 - - [24/Feb/2020 12:01:23] "GET / HTTP/1.1" 200 -
```
... it looks a lot like a full pipe buffer of size 4096. Note that the
`bufsize` argument to Popen does not change anything.

As a simple work around we silence the test server on
Windows/Python2 to not fill the buffer.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-24 16:32:26 +01:00
lukpueh
a044d23eef
Merge pull request #984 from theupdateframework/dependabot/pip/requests-2.23.0
build(deps): bump requests from 2.22.0 to 2.23.0
2020-02-24 09:32:22 +01:00
lukpueh
c20888407e
Merge pull request #980 from theupdateframework/dependabot/pip/idna-2.9
build(deps): bump idna from 2.8 to 2.9
2020-02-24 09:31:21 +01:00
dependabot-preview[bot]
9c8e4ff609
build(deps): bump requests from 2.22.0 to 2.23.0
Bumps [requests](https://github.com/psf/requests) from 2.22.0 to 2.23.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.22.0...v2.23.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-20 10:37:20 +00:00
dependabot-preview[bot]
d055487ef2
build(deps): bump idna from 2.8 to 2.9
Bumps [idna](https://github.com/kjd/idna) from 2.8 to 2.9.
- [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/v2.8...v2.9)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-19 10:50:05 +00:00
lukpueh
42f4c3f7a9
Merge pull request #982 from lukpueh/revise-requirements
Revise requirements files again
2020-02-19 11:48:46 +01:00
lukpueh
4254482e32
Merge pull request #981 from joshuagl/joshuagl/tweak
Add colorama to dependencies installed in the tutorial
2020-02-19 10:38:08 +01:00
Lukas Puehringer
730e4d8b97 Revise requirements files again
Follows up on #978, which had the following problems:
- too many requirements files (cc @trishankatdatadog ;)
- used extra tooling around pip-compile that
  - didn't take into account requirement markers (see comments
    in requirements.txt in this commit), and
  - confused Dependabot, which expects the hashed requirements
    file in a certain format, as pip-compile would generate it
    without custom tooling (see #979).

This commit restructures the requirements files as follows:

- Merges requirements-tox.txt and requirements-test.txt. The
  separation was semantically correct but operationally irrelevant.
- Removes the hashed requirements file, which doesn't add much
  security, especially with PEP 458 on the way (see python/peps#1306),
  but extra maintenance (see notes about requirements.txt in #978
  and about Dependabot above)
- Manually adds environment markers to requirements-pinned.txt (see
  comments in requirements.txt in this commit).

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-18 16:11:31 +01:00
Joshua Lock
eaefbd9fda Add securesystemslib[color] to packages installed in the tutorial
colorama is now an optional dependency for securesystemslib, and so isn't
installed by default. However, the repo script uses colorama and doesn't
handle its absence - add securesystemslib[colors] to ensure colorama is
installed.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-02-18 15:05:13 +00:00
lukpueh
797d55600b
Merge pull request #978 from lukpueh/revise-requirements
Revise requirements files and remove pyup
2020-02-11 13:32:09 +01:00
Lukas Puehringer
1844295a39 Update requirements files comments
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
Co-Authored-By: Joshua Lock <jlock@vmware.com>
2020-02-07 16:21:44 +01:00
Lukas Puehringer
6186e075d4 Add Dependabot status badge
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-07 12:45:34 +01:00
Lukas Puehringer
1a826cb4b0 Fix tests that use non-public sslib module
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-06 17:40:29 +01:00
Lukas Puehringer
08f50ab075 Remove pyup config and badges
The PyUp GitHub integration for TUF stopped working a few days
ago. Instead of troubleshooting, I'm seizing the opportunity to
replace it with Dependabot, which has shown to work well in the
in-toto org.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-06 17:35:59 +01:00
Lukas Puehringer
15d1e933a0 Restructure requirements files
* Use suffixed instead of prefixed sub-requirements files to group
  them alphabetically in the file tree.
* Layer requirements files akin to the in-toto project
  (see in-toto/in-toto#294). The hierarchy is:

  - *requirements.in*
    tuf runtime requirements, including optional requirements
    (pynacl and cyrptography)

  - *requirements-pinned.txt*
    pinned tuf runtime requirements, including optional
    and transitive (1 level deep) requirements and their hashes.

    The file is generated semi-automatically using pip-compile
    and a bash script (see document header), based off of
    requirements.in, combining requirements from all supported
    Python versions.

    This file should be auto-updated, by e.g. dependabot, and be used
    for ci/cd tests, to catch issues with new dependencies.

  - *requirements-test.txt*
    additional test runtime requirements

  - *requirements-tox.txt*
    combines requirements.txt, requirements-test.txt and additional
    test tools (for linting and coverage), i.e. everything that is
    needed in each tox environment to run the tests.

  - *requirements-dev.txt*
    lists tox for local development and testing, and also
    requirements-tox.txt and tuf in editable mode to run
    the test suite or individual tests directly.

  - *requirements.txt*
    requirements-pinned.txt with the hashes of the dependencies
    as reported by pip at the time of creating the file.
    NOTE: this is not used for testing or  dev-install because pip
    doesn't allow mixed (with and without hashes) installations.

    This file should also be auto-updated, by e.g. dependabot.

* Removes an obsolete version constraint on coverage

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-06 17:35:51 +01:00
Justin Cappos
15414c6735
Merge pull request #975 from theupdateframework/bump0.12.2
release: 0.12.2
2020-01-10 16:08:05 -05:00
Santiago Torres
bea6496dc2
release: 0.12.2
Signed-off-by: Santiago Torres <santiago@archlinux.org>
2020-01-10 15:43:44 -05:00
Santiago Torres
2977188139
Merge pull request #974 from lukpueh/fix-signature-threshold
Fix signature threshold
2020-01-10 15:19:16 -05:00
Lukas Puehringer
67a3a7ab92 Update docs and comments in sig.py and test_sig.py
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-01-10 11:26:07 +01:00
Lukas Puehringer
a0397c7c82 Fix signature threshold verification
Prior to this commit metadadata signature verification as provided
by `tuf.sig.verify()` and used e.g. in `tuf.client.updater` counted
multiple signatures with identical authorized keyids each
separately towards the threshold. This behavior practically
subverts the signature thresholds check.

This commit fixes the issue by counting identical authorized keyids
only once towards the threshold.

The commit further clarifies the behavior of the relevant functions
in the `sig` module, i.e. `get_signature_status` and `verify` in
their respective docstrings. And adds tests for those functions and
also for the client updater.

---

NOTE: With this commit signatures with different authorized keyids
still each count separately towards the threshold, even if the
keyids identify the same key. If this behavior is not desired, I
propose the following fix instead. It verifies uniqueness of keys
(and not keyids):

```
diff --git a/tuf/sig.py b/tuf/sig.py
index ae9bae15..5392e596 100755
--- a/tuf/sig.py
+++ b/tuf/sig.py
@@ -303,7 +303,14 @@ def verify(signable, role, repository_name='default', threshold=None,
   if threshold is None or threshold <= 0: #pragma: no cover
     raise securesystemslib.exceptions.Error("Invalid threshold: " + repr(threshold))

-  return len(good_sigs) >= threshold
+  # Different keyids might point to the same key
+  # To be safe, check against unique public key values
+  unique_good_sig_keys = set()
+  for keyid in good_sigs:
+    key = tuf.keydb.get_key(keyid, repository_name)
+    unique_good_sig_keys.add(key["keyval"]["public"])
+
+  return len(unique_good_sig_keys) >= threshold

```

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-01-09 18:54:47 +01:00
mnm678
b913d88ad4
Merge pull request #972 from mnm678/thread-safety
Explain concurrency limitation
2020-01-07 18:18:17 -05:00
marinamoore
9e5a7c6905 Clarified location
Signed-off-by: marinamoore <mmoore32@calpoly.edu>
2020-01-07 10:40:46 -08:00