Skip to content

Vendoring-compatible imports #1261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8dc07cc
imports: Make 'download' imports vendoring-compatible
Jan 11, 2021
4b078b0
imports: Make 'exceptions' imports vendoring-compatible
Jan 11, 2021
4575637
imports: Make 'formats' imports vendoring-compatible
Jan 11, 2021
07b3aed
imports: Make 'log' imports vendoring-compatible
Jan 11, 2021
696b929
updater: rename mirrors variables
Jan 11, 2021
02046c0
imports: Make 'mirrors' imports vendoring compatible
Jan 11, 2021
9550b14
imports: Make 'roledb' imports vendoring-compatible
Jan 11, 2021
c66c61f
imports: Make 'settings' imports vendoring-compatible
Jan 11, 2021
9d7047f
imports: Make 'sig' imports vendoring-compatible
Jan 11, 2021
6faed27
imports: Fix securesystemslib.exceptions imports
Jan 11, 2021
fe3dacc
imports: Make 'updater' import vendoring-compatible
Jan 11, 2021
79385cc
imports: Fix securesystemslib.formats imports
Jan 12, 2021
f702fdf
imports: Fix securesystemslib.keys imports
Jan 12, 2021
a7c2b8d
imports: Fix securesystemslib.interface imports
Jan 12, 2021
46ebfd0
imports: Fix securesystemslib.util imports
Jan 12, 2021
4b66c17
imports: Fix securesystemslib.storage imports
Jan 12, 2021
dd134a4
imports: Fix securesystemslib.hash imports
Jan 12, 2021
996b2a0
imports: Fix securesystemslib.settings imports
Jan 12, 2021
538623b
imports: Make 'keydb' imports vendoring-compatible
Jan 11, 2021
0aabb82
imports: Move six imports to 3rd party section
Jan 12, 2021
d5b6f91
imports: Remove unused imports
Jan 12, 2021
d0e5bd2
imports: Fix urllib3 exception import
Mar 1, 2021
7dcfb12
requests_fetcher: Move 'tuf' import from download
Mar 1, 2021
30ab838
Make requests_fetcher import vendoring compatible
Mar 19, 2021
ab56344
metadata: Make isort happy and bundle imports
Mar 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from securesystemslib.storage import FilesystemBackend, StorageBackendInterface
from securesystemslib.util import persist_temp_file

import tuf.exceptions
import tuf.formats
from tuf import exceptions, formats
from tuf.api.serialization import (
MetadataDeserializer,
MetadataSerializer,
Expand Down Expand Up @@ -266,10 +265,10 @@ def verify(
)

if not signatures_for_keyid:
raise tuf.exceptions.Error(f"no signature for key {key['keyid']}.")
raise exceptions.Error(f"no signature for key {key['keyid']}.")

if len(signatures_for_keyid) > 1:
raise tuf.exceptions.Error(
raise exceptions.Error(
f"{len(signatures_for_keyid)} signatures for key "
f"{key['keyid']}, not sure which one to verify."
)
Expand Down Expand Up @@ -337,7 +336,7 @@ def _common_fields_from_dict(signed_dict: Mapping[str, Any]) -> list:
# Convert 'expires' TUF metadata string to a datetime object, which is
# what the constructor expects and what we store. The inverse operation
# is implemented in '_common_fields_to_dict'.
expires = tuf.formats.expiry_string_to_datetime(expires_str)
expires = formats.expiry_string_to_datetime(expires_str)
return [_type, version, spec_version, expires]

def _common_fields_to_dict(self) -> Dict[str, Any]:
Expand Down
261 changes: 131 additions & 130 deletions tuf/client/updater.py

Large diffs are not rendered by default.

142 changes: 72 additions & 70 deletions tuf/developer_tool.py

Large diffs are not rendered by default.

45 changes: 22 additions & 23 deletions tuf/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
from __future__ import unicode_literals

import logging
import six
import timeit
import tempfile

import securesystemslib
import securesystemslib.util
import six
import securesystemslib # pylint: disable=unused-import
from securesystemslib import formats as sslib_formats

import tuf
import tuf.exceptions
import tuf.formats
from tuf import exceptions
from tuf import formats
from tuf import settings

# See 'log.py' to learn how logging is handled in TUF.
logger = logging.getLogger(__name__)
Expand All @@ -53,7 +53,7 @@ def safe_download(url, required_length, fetcher):
Given the 'url' and 'required_length' of the desired file, open a connection
to 'url', download it, and return the contents of the file. Also ensure
the length of the downloaded file matches 'required_length' exactly.
tuf.download.unsafe_download() may be called if an upper download limit is
download.unsafe_download() may be called if an upper download limit is
preferred.

<Arguments>
Expand Down Expand Up @@ -86,8 +86,8 @@ def safe_download(url, required_length, fetcher):

# Do all of the arguments have the appropriate format?
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
securesystemslib.formats.URL_SCHEMA.check_match(url)
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
sslib_formats.URL_SCHEMA.check_match(url)
formats.LENGTH_SCHEMA.check_match(required_length)

return _download_file(url, required_length, fetcher, STRICT_REQUIRED_LENGTH=True)

Expand All @@ -101,7 +101,7 @@ def unsafe_download(url, required_length, fetcher):
Given the 'url' and 'required_length' of the desired file, open a connection
to 'url', download it, and return the contents of the file. Also ensure
the length of the downloaded file is up to 'required_length', and no larger.
tuf.download.safe_download() may be called if an exact download limit is
download.safe_download() may be called if an exact download limit is
preferred.

<Arguments>
Expand Down Expand Up @@ -134,8 +134,8 @@ def unsafe_download(url, required_length, fetcher):

# Do all of the arguments have the appropriate format?
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
securesystemslib.formats.URL_SCHEMA.check_match(url)
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
sslib_formats.URL_SCHEMA.check_match(url)
formats.LENGTH_SCHEMA.check_match(required_length)

return _download_file(url, required_length, fetcher, STRICT_REQUIRED_LENGTH=False)

Expand Down Expand Up @@ -208,15 +208,14 @@ def _download_file(url, required_length, fetcher, STRICT_REQUIRED_LENGTH=True):
seconds_spent_receiving = stop_time - start_time
average_download_speed = number_of_bytes_received / seconds_spent_receiving

if average_download_speed < tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED:
if average_download_speed < settings.MIN_AVERAGE_DOWNLOAD_SPEED:
logger.debug('The average download speed dropped below the minimum'
' average download speed set in tuf.settings.py. Stopping the'
' download!')
' average download speed set in settings. Stopping the download!.')
break

else:
logger.debug('The average download speed has not dipped below the'
' minimum average download speed set in tuf.settings.py.')
' minimum average download speed set in settings.')

# Does the total number of downloaded bytes match the required length?
_check_downloaded_length(number_of_bytes_received, required_length,
Expand Down Expand Up @@ -273,7 +272,7 @@ def _check_downloaded_length(total_downloaded, required_length,

tuf.exceptions.SlowRetrievalError, if the total downloaded was
done in less than the acceptable download speed (as set in
tuf.settings.py).
tuf.settings).

<Returns>
None.
Expand All @@ -296,24 +295,24 @@ def _check_downloaded_length(total_downloaded, required_length,
# If the average download speed is below a certain threshold, we flag
# this as a possible slow-retrieval attack.
logger.debug('Average download speed: ' + repr(average_download_speed))
logger.debug('Minimum average download speed: ' + repr(tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED))
logger.debug('Minimum average download speed: ' + repr(settings.MIN_AVERAGE_DOWNLOAD_SPEED))

if average_download_speed < tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED:
raise tuf.exceptions.SlowRetrievalError(average_download_speed)
if average_download_speed < settings.MIN_AVERAGE_DOWNLOAD_SPEED:
raise exceptions.SlowRetrievalError(average_download_speed)

else:
logger.debug('Good average download speed: ' +
repr(average_download_speed) + ' bytes per second')

raise tuf.exceptions.DownloadLengthMismatchError(required_length, total_downloaded)
raise exceptions.DownloadLengthMismatchError(required_length, total_downloaded)

else:
# We specifically disabled strict checking of required length, but we
# will log a warning anyway. This is useful when we wish to download the
# Timestamp or Root metadata, for which we have no signed metadata; so,
# we must guess a reasonable required_length for it.
if average_download_speed < tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED:
raise tuf.exceptions.SlowRetrievalError(average_download_speed)
if average_download_speed < settings.MIN_AVERAGE_DOWNLOAD_SPEED:
raise exceptions.SlowRetrievalError(average_download_speed)

else:
logger.debug('Good average download speed: ' +
Expand Down
Loading