Commit graph

3676 commits

Author SHA1 Message Date
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
Lukas Puehringer
17f08ad200 Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.

The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)

The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.

Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).

This commits also adds tests.

**TODO: See doc header TODO list**

**Additional design considerations**
(also in regards to prior sketches of this module)

 - Aims at simplicity, brevity and recognizability of the wireline metadata
   format.

 - All attributes that correspond to fields in TUF JSON metadata are public.
   There doesn't seem to be a good reason to protect them with leading
   underscores and use setters/getters instead, it just adds more code, and
   impedes recognizability of the wireline metadata format.

 - Although, it might be convenient to have short-cuts on the Metadata class
   that point to methods and attributes that are common to all subclasses of
   the contained Signed class (e.g. Metadata.version instead of
   Metadata.signed.version, etc.), this also conflicts with goal of
   recognizability of the wireline metadata. Thus we won't add such short-cuts
   for now. See:
   https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629

 - Signing keys and a 'consistent_snapshot' boolean are not on the targets
   metadata class. They are a better fit for management code. See:
   https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
   and #660.

 - Does not use sslib schema checks (see TODO notes about validation in
   doc header)

 - Does not use existing tuf utils, such as make_metadata_fileinfo,
   build_dict_conforming_to_schema, if it is easy and more explicit to
   just re-implement the desired behavior on the metadata classes.

 - All datetime's are treated as UTC. Since timezone info is not captured in
   the wireline metadata format it should not be captured in the internal
   representation either.

 - Does not use 3rd-party dateutil package, in order to minimize dependency
   footprint, which is especially important for update clients which often have
   to vendor their dependencies.
   However, compatibility between the more advanced dateutil.relativedelta (e.g
   handles leap years automatically) and timedelta is tested.

 - Uses PEP8 indentation (4 space) and Google-style doc string instead of
   sslab-style. See
   https://github.com/secure-systems-lab/code-style-guidelines/issues/20

 - Does not support Python =< 3.5

Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-20 12:14:40 +02:00
lukpueh
5d16f91ca7
Merge pull request #1054 from jku/update-docs-on-crypto-details
Update docs on crypto details
2020-06-23 12:00:31 +02:00
Jussi Kukkonen
dc78d89f4f Update Tutorial on dependency installation
* Remove reference to deprecated settings
* Mention that the tutorial expects the dependencies and link to
  instructions

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-06-23 11:02:31 +03:00
lukpueh
017a5ff33b
Merge pull request #1056 from theupdateframework/dependabot/pip/certifi-2020.6.20
build(deps): bump certifi from 2020.4.5.2 to 2020.6.20
2020-06-23 09:47:08 +02:00
lukpueh
116e66e604
Merge pull request #1055 from theupdateframework/dependabot/pip/requests-2.24.0
build(deps): bump requests from 2.23.0 to 2.24.0
2020-06-22 19:02:08 +02:00
dependabot-preview[bot]
bc75c8c08c
build(deps): bump certifi from 2020.4.5.2 to 2020.6.20
Bumps [certifi](https://github.com/certifi/python-certifi) from 2020.4.5.2 to 2020.6.20.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2020.04.05.2...2020.06.20)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-22 11:38:01 +00:00
dependabot-preview[bot]
943ed41ada
build(deps): bump requests from 2.23.0 to 2.24.0
Bumps [requests](https://github.com/psf/requests) from 2.23.0 to 2.24.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.23.0...v2.24.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-18 10:32:51 +00:00
Jussi Kukkonen
179892c1e9 Update Tutorial on cryptographic keys
Lot of changes in 7 lines:
* PyCrypto is no longer an option: remove mention of it
* RSA-PSS wiki page now redirects to a fairly useless stub: replace it
  with the RFC (it's not light reading but better than nothing)
* Mention ECDSA
* Remove mention of json for RSA keys: that does not seem to be true

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-06-17 18:01:45 +03:00
Jussi Kukkonen
5a8f93529b Update comments about optional crypto dependencies
tools-extra does not exist in tuf anymore: mention the securesystemslib
extras instead.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-06-17 17:33:58 +03:00
lukpueh
8e6ca67f31
Merge pull request #1047 from theupdateframework/dependabot/pip/certifi-2020.4.5.2
build(deps): bump certifi from 2020.4.5.1 to 2020.4.5.2
2020-06-12 10:08:24 +02:00
lukpueh
d875dd4bd3
Merge pull request #1051 from jcstr/patch2-docs
Add python 3 use case
2020-06-11 10:07:32 +02:00
Jesús Castro
9badf8a51e
Add python 3 use case
This indication can be found on other documents.

Signed-off-by: Jesús Castro <x51v4n@gmail.com>
2020-06-10 06:30:23 -05:00
lukpueh
ff5afe441a
Merge pull request #1049 from sechkova/issue-1046
Load full target file info for delegated targets metadata
2020-06-09 16:34:31 +02:00
Teodora Sechkova
2553dff276
Update test_load_repository
Extend test_load_repository to check if targets file info is loaded
correctly.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-06-09 16:48:53 +03:00
Teodora Sechkova
88f6755153
Load full target file info for delegated targets
Fix load_repository to actually load the full targets file info from
file system for delegated targets.

Update _load_top_level_metadata to load targets and delegated targets
metadata in a consistent way.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-06-09 16:48:42 +03:00
dependabot-preview[bot]
a5e015f8f7
build(deps): bump certifi from 2020.4.5.1 to 2020.4.5.2
Bumps [certifi](https://github.com/certifi/python-certifi) from 2020.4.5.1 to 2020.4.5.2.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2020.04.05.1...2020.04.05.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-08 10:59:00 +00:00
Joshua Lock
5d40ffa3c4
Merge pull request #1034 from joshuagl/joshuagl/abstract-files-fixes
Fix and better test abstract files and directories support
2020-06-05 13:40:21 +01:00
lukpueh
95d08cc5b4
Merge pull request #1044 from jcstr/patch1
Remove unused imports
2020-06-05 09:42:53 +02:00
Jesús Castro
f4121e8f75
Remove unused imports
Those imports are marked as a non used libraries.

Signed-off-by: Jesús Castro <x51v4n@gmail.com>
2020-06-04 19:18:33 -05:00
Joshua Lock
5e5c598769 Support abstract storage for timestamp metadata
This was erroneously absent in PR 1024, which added support for abstract
files and directories. Resolve by adding a storage_backend argument to
generate_timestamp_metadata() and using it so that the fileinfo (hashes
and length) for the snapshot file can be generated for a snapshot
metadata file on any supported storage.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-06-03 14:16:47 +01:00
Joshua Lock
d9ec10e894 Test abstract storage backend support
Add a class implementing StorageBackendInterface for testhing which
mutates filenames on put()/get(), such that trying to read the expected
file paths for TUF metadata from the local filesystem doesn't find the
files.

Use this class when creating a repository and writing metadata to test
abstract files and directories support for metadata writing.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-06-03 14:16:47 +01:00
Joshua Lock
05d5639502 Better document generate_targets_metadata()
Clarify, through the docstrings and code comments, the expected behaviour
of generate_targets_metadata() and the interactions of the
use_existing_fileinfo and write_consistent_targets parameters.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-06-03 14:16:47 +01:00
Marina Moore
a354fc01c0
Merge pull request #1040 from trailofbits/ww/return-bin-name-when-delegating
tuf/repository_tool: Return delegated bin_name during modifications
2020-06-01 15:59:45 -07:00
William Woodruff
1e532e825a
tests: Fill in more returned role name use
Signed-off-by: William Woodruff <william@trailofbits.com>
2020-06-01 14:22:29 -04:00
William Woodruff
4327a980cd
tests: Use newly returned role name
Signed-off-by: William Woodruff <william@trailofbits.com>
2020-06-01 14:01:46 -04:00
William Woodruff
65fd02c4ab
tuf/repository_tool: Return delegated bin_name during modifications
This makes it easier for consumers of repository_tool to mark the
appropriate delegated bin as dirty when using delegated targets.

Signed-off-by: William Woodruff <william@trailofbits.com>
2020-06-01 13:46:43 -04:00
lukpueh
a4b52e7e0d
Merge pull request #1036 from theupdateframework/dependabot/pip/pynacl-1.4.0
build(deps): bump pynacl from 1.3.0 to 1.4.0
2020-06-01 14:05:00 +02:00
dependabot-preview[bot]
f01a31f2f9
build(deps): bump pynacl from 1.3.0 to 1.4.0
Bumps [pynacl](https://github.com/pyca/pynacl) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/pyca/pynacl/releases)
- [Changelog](https://github.com/pyca/pynacl/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pyca/pynacl/compare/1.3.0...1.4.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-28 09:37:12 +00:00
lukpueh
e36080e673
Merge pull request #1035 from theupdateframework/dependabot/pip/six-1.15.0
build(deps): bump six from 1.14.0 to 1.15.0
2020-05-28 11:34:26 +02:00
lukpueh
580334e707
Merge pull request #1021 from MVrachev/patch-1
Fix typo in comment
2020-05-27 14:16:30 +02:00
dependabot-preview[bot]
bb94dcfff6
build(deps): bump six from 1.14.0 to 1.15.0
Bumps [six](https://github.com/benjaminp/six) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/benjaminp/six/releases)
- [Changelog](https://github.com/benjaminp/six/blob/master/CHANGES)
- [Commits](https://github.com/benjaminp/six/compare/1.14.0...1.15.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-22 10:37:20 +00:00
Marina Moore
540377eb8e
Merge pull request #1024 from joshuagl/joshuagl/abstract-filesystem
Port to securesystemslib with abstract files and directories (securesystemslib PR 232)
2020-05-19 16:53:33 -07:00
Joshua Lock
be3c541a8a Update securesystemslib dependency
We need the recently released securesystemslib 0.15.0 or newer for
abstract storage support.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-19 22:36:17 +01:00
Joshua Lock
4e7b7b40ea Allow generating targets metadata for non-local storage
Utilise the abstract files and directories support to enable generating
targets metadata for files which aren't necessarily locally accessible,
rather than requiring that metadata for non-local files be provided via
existing fileinfo structures.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-19 22:36:17 +01:00
Joshua Lock
a187377533 Make absence of fundamental roles fatal
The specification lists four fundamental roles: root, targets, snapshot
and timestamp. Loading a repository where those roles are not present
should not be supported, therefore convert debug messages on the absence
of metadata files for these fundamental roles into a RepositoryError
exception.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-19 22:36:17 +01:00
Joshua Lock
7384412b3d Remove file existence checks in repository_lib
Rather than check for the existence of metadata files before trying to
load them in _load_top_level_metadata, we should just try and load them.

This is more idiomatic Python through employing EAFP (Easier to Ask
Forgiveness than Permission) principles.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-12 22:16:50 +01:00
Joshua Lock
0c0aaa97eb Port to new securesystemslib w abstract filesystem
Switch to using the new abstract files and directories support in
securesystemslib by taking an object which implements
securesystemslib.storage.StorageBackendInterface in the Repository
constructor, passed in by tuf.repository_tool.create_new_repository() and
tuf.repository_tool.load_repository()

The Updater class in tuf.client.updater does not specify a storage backend
and instead allows the functions in securesystemslib to perform the
default action of instantiating a LocalFilesystemBackend, that is the
updater does not currently support abstract filesystem backends and always
defaults to using local storage.

Finally we drop support for tuf.settings.CONSISTENT_METHOD as it's not as
clear how different copying modes should work when the details of the
underlying storage are abstracted away.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-12 22:16:50 +01:00
Joshua Lock
431b808a18 Remove outdated comments
tuf removed support for compressed metadata in v0.10.x, therefore it is
confusing to carry comments referring to compressed versions of metadata.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-12 22:16:38 +01:00
Joshua Lock
4487a98020 Remove redundant test logic
Support for compressed files was removed in tuf v0.10.x leaving behind
some vestiges like the test logic in test_repository_lib, which is
duplicated below and carries a redundant comment, and setting compression
on in generate_project_data.py

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-12 22:16:38 +01:00
Joshua Lock
d7aec6a5f9
Merge pull request #1029 from MVrachev/fix-1010
Fix error "[Errno 111] Connection refused" and make logs more usable
2020-05-11 22:58:40 +01:00
Martin Vrachev
c7f878b2dc Remove six.PY2 and platform checks and add warning
After a discussion with Joshua Lock, we agreed that for
Windows users it would be good to provide the option to use
SimpleHTTPRequestHandler, but still leave a warning about it,
knowing that this caused an error before.
See: 7dbb30ae10

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-05-07 18:06:09 +03:00
Martin Vrachev
b42ca297e5 Remove PIPE arg and make QuiteHandler the default
Passing a pipe to the subprocess, but not reading from it
conceals helpful error messages.
As the code redirects all of the stderr from the subprocess
to nowhere, the error output of the process is never read.
If we remove the PIPEs from the tests we should see some
error messages on the console/logger that can
help us understand what went wrong.

On another hand, when we stop passing stderr=subprocess.PIPE arg
to the subprocess.Popen function call there are a lot of
HTTP messages together with the helpful error messages.
One decision is to make QuietHTTPRequestHandler
the default. That way we receive the helpful error messages
without the HTTP messages.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-05-07 15:53:01 +03:00
Martin Vrachev
dae1a1ba66 Fix [Errno 111] Connection refused
Fixes issue: https://github.com/theupdateframework/tuf/issues/1010

When running the tests this error appears
"[Errno 111] Connection refused". After some digging Lukas
found another error "No module named tests.simple_server"
which is the root case for error 111.

With the help of Joshua Lock, we found out that the simple_server.py
was not being found because subprocess.Popen was being passed
a cwd kwarg which moved the current working directory
away from tuf/tests.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-05-07 15:35:33 +03:00
Trishank Karthik Kuppusamy
3851f38ca1
Merge pull request #1028 from joshuagl/joshuagl/maint
Add my PGP fingerprint
2020-05-05 16:47:36 -04:00
Joshua Lock
165cdfb3ee Update MAINTAINERS
Add Joshua's PGP fingerprint

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-05 21:30:28 +01:00
Santiago Torres
808ac0c6fc
Merge pull request #1027 from joshuagl/joshuagl/custom
Improve error message and docstring for custom parameter in `add_target()`
2020-05-05 10:06:31 -04:00
Joshua Lock
8d4511a11e Update add_target docstring
Update the docstring to make it clear that 'custom' and 'fileinfo' are
mutually exclusive, and further that the 'custom' parameter will be
dropped in a future release.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-05 12:34:47 +01:00
Joshua Lock
dcd0a9bc05 Improve accuracy of CUSTOM_SCHEMA definition
Change CUSTOM_SCHEMA to a dictionary mapping AnyString to Any value. This
makes error reporting more indicative of what the expected value is, by
reporting something like:
  FormatError: Expected a dict but got ‘meta’

instead of:
  FormatError: Expected a object but got 'meta'

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-30 22:17:31 +01:00