Commit graph

136 commits

Author SHA1 Message Date
vladdd
20d5a6b3e4 Fix self.assertTrue() conditions in test_updater.py
A few test conditions in test_updater.py incorrectly used self.assertTrue() instead of self.assertEqual().
Fix updater.remove_obsolete_targets(), where targets in the destination directory were not being removed because target paths were treated as absolute paths by os.path.join().
2014-07-06 22:25:20 -04:00
vladdd
9cf9a6a8b5 Review and update Pull Request #232.
Fix test conditions for updated_targets(), which incorrectly verified the expected number of updated targets with assertTrue().

Update comment for PR fix to clarify os.path.join() behavior and the expected file paths.
2014-07-04 17:50:22 -04:00
vladdd
7746b3f059 Merge branch 'filepath' of https://github.com/meskio/tuf into meskio-filepath 2014-07-04 16:45:00 -04:00
Ruben Pollan
d437964c42 Fix indentation
Indentation is with 2 spaces
2014-07-04 13:38:16 -05:00
vladdd
48224f7274 Minor edits to basic_client.py. 2014-07-01 22:59:43 -04:00
Ruben Pollan
a74a14186b Remove '/' from target filepath
os.path.join ignore previous parameters if one starts with '/'. All
targets start with '/', making updated_targets to try to open a file in
the root folder in case of a unix system.
2014-06-30 14:13:40 -05:00
Vladimir Diaz
5d766d3d6f Review and update docstrings and README. 2014-06-25 09:45:55 -04:00
Vladimir Diaz
21cbaf8f63 Update README.md
Add example for accessing fileinfo and custom data of target objects.
2014-06-25 09:01:06 -04:00
Vladimir Diaz
e4c98d38ba Add missing test cases for download.py and and updater.py. 2014-06-12 09:33:12 -04:00
vladdd
744be00cbc Initial implementation of authoritative delegations. 2014-06-07 20:29:18 -04:00
Vladimir Diaz
797bab5ddc Fix Python 2 + 3 JSON consistency issue and re-generate repository data.
Explicitly specify the JSON separators for Python 2 + 3 consistency.
2014-06-05 11:17:30 -04:00
vladdd
6b8b2399a2 Finish unit tests for Python2 + 3 support.
All unit tests updated / running for Python 2 + 3.
TODO: Fix non-Python 3 issue with util.py.
2014-05-27 13:55:48 -04:00
Vladimir Diaz
ab95a4b3aa [WIP] Python 2+3 support.
Python 2+3 unicode.
libraries.
The following modules (and their tests) work in PY2.7+3.3:
keydb, hash, formats, mirrors
2014-04-29 14:27:34 -04:00
Vladimir Diaz
e23b4e5eae Merge branch 'develop' of https://github.com/theupdateframework/tuf into develop
Conflicts:
	tuf/__init__.py
	tuf/client/updater.py
2014-04-29 08:31:29 -04:00
Vladimir Diaz
91480c8628 Edit updater.refresh() and install of compressed metadata.
1. Raise an exception for clients that do not wish to automatically fetch a Root file when an expired version is loaded from disk.

2. Properly 'install' compressed metadata downloaded.  The compressed version of the rolename was added to the fileinfo store, which prevented detection of changed metadata and would unintentionally cause compressed metadata to always refresh (only the fileinfo of uncompressed metadata is stored and compared.)

3. Rename unsafely_verify_compressed_metadata_file() variable names, so that they match the other verify functions.
2014-04-29 08:15:18 -04:00
vladdd
1e360846bf Reject expired metadata without loading.
Reject downloaded metadata as early as possible.  The top-level roles were all downloaded as a group and then their
expiration inspected.  All metadata provided by a mirror that has already expired is discarded immediately and the next mirror tried.  The update process stops if a requested role cannot be successfully validated, or one of its parents.

[2014-04-29 02:00:32,308 UTC] [tuf.download] [INFO] [_download_file:745@download.py]
Downloading: http://localhost:8001/metadata/timestamp.json

[2014-04-29 02:00:32,324 UTC] [tuf.download] [INFO] [_check_downloaded_length:676@download.py]
Downloaded 544 bytes out of an upper limit of 16384 bytes.

[2014-04-29 02:00:32,324 UTC] [tuf.client.updater] [INFO] [_get_file:1189@updater.py]
Not decompressing http://localhost:8001/metadata/timestamp.json

[2014-04-29 02:00:32,331 UTC] [tuf.download] [INFO] [_download_file:745@download.py]
Downloading: http://localhost:8001/metadata/snapshot.json

[2014-04-29 02:00:32,333 UTC] [tuf.download] [INFO] [_check_downloaded_length:654@download.py]
Downloaded 1003 bytes out of the expected 1003 bytes.

[2014-04-29 02:00:32,334 UTC] [tuf.client.updater] [INFO] [_get_file:1189@updater.py]
Not decompressing http://localhost:8001/metadata/snapshot.json

[2014-04-29 02:00:32,334 UTC] [tuf.client.updater] [INFO] [_check_hashes:696@updater.py]
The file's sha256 hash is correct: 5b3aec7cf295a25e4b39d875c7474511da9645bc6d27f9e86fb7e439c82e0ec7

[2014-04-29 02:00:32,335 UTC] [tuf.client.updater] [ERROR] [_ensure_not_expired:1789@updater.py]
Metadata 'snapshot' expired on Tue Apr 29 01:59:01 2014 (UTC).

Do not request, download, and install top-level roles if the root of trust has already expired after the inital load. If requested, update an expired root role:

[2014-04-29 01:18:02,457 UTC] [tuf.client.updater] [ERROR] [_ensure_not_expired:1789@updater.py]
Metadata 'root' expired on Mon Apr 28 23:23:57 2014 (UTC).

[2014-04-29 01:18:02,458 UTC] [tuf.client.updater] [INFO] [refresh:628@updater.py]
Expired Root metadata was loaded from disk.  Try to update it now.

[2014-04-29 01:18:02,458 UTC] [tuf.download] [INFO] [_download_file:745@download.py]
Downloading: http://localhost:8001/metadata/root.json

[2014-04-29 01:18:02,461 UTC] [tuf.download] [INFO] [_check_downloaded_length:676@download.py]
Downloaded 1198 bytes out of an upper limit of 512000 bytes.

[2014-04-29 01:18:02,461 UTC] [tuf.client.updater] [INFO] [_get_file:1189@updater.py]
Not decompressing http://localhost:8001/metadata/root.json

[2014-04-29 01:18:02,462 UTC] [tuf.client.updater] [ERROR] [_ensure_not_expired:1789@updater.py]
Metadata 'root' expired on Mon Apr 28 23:23:57 2014 (UTC).

Note: An expired 'root' was provided by the server.  The requested root must also be signed by keys trusted by the client.
2014-04-28 22:31:42 -04:00
Vladimir Diaz
a7f28b9af4 [WIP] Python 2+3 support.
Add six, convert PY <=2.5 exception handling, dictionary iteration, libraries, 1/2 the tests.
2014-04-22 15:03:42 -04:00
vladdd
5f94d5be0d Support ISO 8601, vendor iso8601, clean codebase. 2014-04-19 14:27:53 -04:00
Vladimir Diaz
919fb0ff8f Log warning if top-level metadata expires soon. 2014-04-17 12:27:28 -04:00
Vladimir Diaz
1935b1de2b Update TUF modules affected by the change to the 'expires' format. 2014-04-15 12:52:35 -04:00
vladdd
ef9922ebe9 Finish refactor of test_updater.py.
test_updater.py now uses repository_tool.py to update the remote repository as needed, and no longer depends on mocking and repository_setup.py.
2014-03-18 12:59:03 -04:00
vladdd
9109589f34 Merge branch 'develop' of https://github.com/vladimir-v-diaz/tuf into develop 2014-03-15 14:10:41 -04:00
Vladimir Diaz
eaee52e14e [WIP] Refactor test_updater.py
Continue refactoring the test cases of test_updater.py.
Fix issue where repository_tool.py was not writing new compressed metadata.
Minor edits to TUF modules.
2014-03-13 12:31:36 -04:00
JustinCappos
846fd7c4d1 Update README.md 2014-03-11 16:33:02 -04:00
JustinCappos
57343e51d4 Update README.md 2014-03-11 16:31:57 -04:00
Vladimir Diaz
5e7713a93f [WIP] Refactor test_updater.py and repository_setup.py.
Add generate.py script and pre-generated repository files used by Unit tests (replacing repository_setup.py).
Refactor test_updater.py (10 test cases remaining).
2014-03-11 09:08:53 -04:00
vladdd
845b98fda1 Modify installation setup.
Support the following installation setup:
# Minimal install intended for clients (pure Python, only ed25519 signatures).
pip install tuf

# Optional installation required by the TUF repository tools (RSA keys and rsassa-pss
# signatures, faster ed25519 cryptographic computations, general-purpose cryptography, etc.)
pip install tuf[tools]

Re-implement the fix for issue #167.

Update comments and docstrings related to the fixes above.
2014-03-08 17:56:40 -05:00
vladdd
57e42f0072 Fix updater.py typo. 2014-02-05 09:47:32 -05:00
vladdd
a22099699e Resolve remaining unit test failures.
Update the remaining unit tests following the many design changes.  The unit tests should next be factored to use repository_tool.py, avoid pseudo repositories and repository objects, monkey patching, etc.
2014-01-31 14:47:48 -05:00
Vladimir Diaz
009ddd9f37 Rename top-level role and functions of repository_tool.py. Update documentation and diagram.
add_key() -> add_verification_key()
remove_key() -> remove_verification_key()
release.json -> snapshot.json
Update repository_tool-diagram.png
Update README following the renamed functions and release role changes.
Minor edits, such as removing lint left over from a previous merge conflict.
2014-01-29 11:26:56 -05:00
Vladimir Diaz
2c55b94a8b Modify the extension of rolename files.
rolename.txt -> rolename.json.
2014-01-27 11:35:38 -05:00
Vladimir Diaz
8712099953 Verify delegated target paths in repository_tool.py.
repository_tool.py verified that valid metadata was written, properly signed, hashes all matched, and required roles created.  The only check missing was verification of delegated target paths according the parent's delegations.  Now, target paths are validated before write() is called for both 'path' and 'path_hash_prefixes'.  updater.py has always properly verified paths, only repository_tool.py needed the support.  If any of the delegated paths are not allowed, write()
raises the following exception:
tuf.ForbiddenTargetError: Role 'targets/unclaimed' specifies target '/simple/bad_file.txt', which is not an allowed path according to the delegations set by its parent role.
2014-01-27 10:55:14 -05:00
vladdd
298f52ddb8 Modify format of paths in metadata and minor fixes.
Allow leading os.sep for target and restricted paths listed in metadata.  Previously, '{repository directory}/targets/file.txt' was listed as 'file.txt' and unsuccessfully compared against '/', or the root-most targets directory.  Now, '/file.txt' & '/' and similar examples may be compared and verified.

Fix issue where a hashed bin with empty targets was flagged as invalid because its targets did not produce a path hash prefix that matched any of those listed in the parent role.  Uncovered with _ensure_all_targets_allowed().

Minor edits to code that compared paths and and used path separators.
2014-01-25 16:40:53 -05:00
Vladimir Diaz
973d3a23a3 Address Issue #137 and update repository_tool.py.
Add the add_restricted_paths() method.
Rename libtuf.py
Update README.
Update delegate_hashed_bins() docstring.
More testing of hashed bins and consistent snapshots.
Remove old scripts from setup.py.
2014-01-23 12:03:31 -05:00
vladdd
52fdb2ea5f Adjust logger level for compressed and uncompressed metadata. 2014-01-18 20:45:21 -05:00
vladdd
fbd7b147e8 Address Issues #151 and #156.
Adjust logger messages and levels.
Update use of tuf.conf variable so that it can be updated in code.
Update updater.py comments.
2014-01-18 18:37:27 -05:00
Vladimir Diaz
a9d90e7ce0 Finish initial implementation of Issue #151 and reading consistent snapshots.
Support multiple hash algorithms, where the generated digests of metadata and
target files is included in metadata (and filenames if 'consistent_snapshots'
is True).  Previously, only a single hash algorithm was supported, and it was
set by default to 'sha256' in code.  Repository maintainers may now choose any,
and/or multiple, hash algorithms from those supported by TUF.  By default,
'sha256' is used when generating digests.

Support the recent change to the TUF specification, where writing consistent
snapshots may include N versions of identical metadata and targets, if N hash
algorithms is used by the repository when generating metadata.

Update code affected by the recent changes to the specification, such as
targets that may include digests in their filename.

Support consistent snapshots of compressed metadata, including repositories
that provide multiple versions of metadata with different digests included
in their filenames.

The repository tools can now load repositories that include consistent snapshots
of metadata and targets, including those with multiple (i.e., multiple digests
prepended to filenames) consistent snapshots of files.

The client code may now read repositories with 'consistent_snapshots': true in
Root metadata, and properly request and update files with digests included.
2014-01-17 11:05:40 -05:00
Vladimir Diaz
b73393c214 Resolve issues #149 and #155.
Move 'tuf.client.updater.Updater.refresh()' call in interposition to its updater's __init__().  The refresh() was previously executed on every target request.

Add tuf.interposition.refresh() for integrations that may require a manual refresh of top-level metadata (rare).
2014-01-09 09:48:37 -05:00
Vladimir Diaz
bdef3756ef Update README.md
Update sections affected by Issue #100 changes.
2014-01-05 14:44:30 -05:00
vladdd
c39abf9e6c Update, test, and complete Issue #100 target methods.
Improve targets_of_role(rolename) behavior.  It now updates the minimum metadata needed for 'rolename'.
Ensure all_targets() adds targets in the expected order, where parent role targets come before children.
Minor updates to comments and docstrings.
2014-01-05 14:40:45 -05:00
vladdd
a2db039cf0 Update conf.py header and comments 2014-01-04 15:42:34 -05:00
vladdd
b5c640c128 Minor edits to previous commit.
Add docstring documentation for newly-added 'unsafely_update_root_if_necessary' argument.

Update comments.
2014-01-04 15:21:44 -05:00
vladdd
f866da7cb8 Address Issues #165, #158, and #147.
Issue 147: Finalize conversion of all written metadata behavior.  This commit ensures that compressed and uncompressed metadata is also written as outlined in the issue.

Issue 158: As requested, updater.refresh() may now unsafely fetch (i.e., unknown file size and hash) Root metadata if valid top-level metadata cannot be downloaded successfully (e.g., top-level keys may have been revoked).  The repository must also sign the new Root file (at least until all clients have updated) with any revoked keys so that clients may successfully update.  After unsafely updating Root, the top-level metadata is updated again as normal (and only once to avoid an infinite loop).  By default, refresh() unsafely updates Root if only invalid top-level metadata can be downloaded, although this behavior may be overriden by the caller if they wish.  Changed default behavior: refresh(self, unsafely_update_root_if_necessary=True)

Issue 165: Delegated roles are no longer added as attributes of a Targets object by libtuf.py (e.g., repository.targets.delegated_role).  The previous bahavior restricted rolenames to Python identifiers (i.e., can only include letters, numbers, the underscore character, and must start with a nonnumeric character).  Now, delegated roles may be referenced as strings (e.g., repository.targets('recently-claimed')) and include characters other than '_'.  In addition, methods have been added to return all the delegated rolesnames of a target (e.g., repository.targets.get_delegated_rolenames()) and the immediate delegated Target objects of a role.  Previous behavior: repository.targets.unclaimed.django.version = 8
Current behavior: repository.targets('unclaimed')('django').version = 8.
2014-01-02 12:18:44 -05:00
Vladimir Diaz
4647d4a01d Address Issue #120 2013-12-18 14:57:17 -05:00
Vladimir Diaz
8199033207 Merge branch 'repository-tools' of https://github.com/theupdateframework/tuf into repository-tools 2013-12-16 13:40:13 -05:00
Vladimir Diaz
182368e973 Update README.md
Minor updated to comments.
2013-12-16 13:39:54 -05:00
Vladimir Diaz
d22c48fcb2 Add missing docstring to updater.py
Add missing docstring for refresh_targets_metadata_chain().
Minor updates to comments.
2013-12-16 13:38:38 -05:00
Vladimir Diaz
ac2192f228 Update README.md
Lines: Add simple integration example and its output.

Minor updates to comments.
2013-12-16 11:59:42 -05:00
Vladimir Diaz
026daacb7d Update README.md
Line 18:  Fix heading.
Lines 76-78: Expand comment on refresh().
Lines 81-83: Expand comment on all_targets().
Lines 103: Fix heading.
Lines 111-113: Add refresh_targets_metadata_chain() example.
115-116: Expand comment on refreshing target files and determining
the ones that have changed.
128: Add refresh() comment.
2013-12-16 10:48:03 -05:00
Vladimir Diaz
bf1c319f4a Update README.md
Line 41: Add sub-heading.
Lines 100-110: Add targets of role example.
Lines 113-123: Add downloading specific target file example.
2013-12-16 10:15:11 -05:00