mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Avoid interposition cycles with a simple restriction.
This commit is contained in:
parent
7af60c51bb
commit
c034d33a2e
1 changed files with 11 additions and 10 deletions
|
|
@ -42,10 +42,12 @@ def __init__( self, configuration ):
|
|||
@staticmethod
|
||||
def build_updater( configuration ):
|
||||
assert isinstance( configuration, Configuration )
|
||||
assert configuration.network_location not in Updater.__updaters
|
||||
|
||||
Updater.__updaters[ configuration.network_location ] = \
|
||||
Updater( configuration )
|
||||
# Restrict each hostname to correspond to a single updater;
|
||||
# this prevents interposition cycles, amongst other things.
|
||||
assert configuration.hostname not in Updater.__updaters
|
||||
|
||||
Updater.__updaters[ configuration.hostname ] = Updater( configuration )
|
||||
|
||||
def download_target( self, target_filepath ):
|
||||
"""Downloads target with TUF as a side effect."""
|
||||
|
|
@ -132,14 +134,13 @@ def get_updater( url ):
|
|||
parsed_url = urlparse.urlparse( url )
|
||||
hostname = parsed_url.hostname
|
||||
port = parsed_url.port or 80
|
||||
network_location = \
|
||||
"{hostname}:{port}".format( hostname = hostname, port = port )
|
||||
updater = Updater.__updaters.get( hostname )
|
||||
|
||||
updater = Updater.__updaters.get( network_location )
|
||||
# This will raise an exception in case we do not recognize
|
||||
# how to transform this URL for TUF. In that case, there will be
|
||||
# no updater for this URL.
|
||||
if updater is not None:
|
||||
# Ensure that the updater is meant for this (hostname, port).
|
||||
if updater is not None and updater.configuration.port == port:
|
||||
# Raises an exception in case we do not recognize how to
|
||||
# transform this URL for TUF. In that case, there will be no
|
||||
# updater for this URL.
|
||||
target_filepath = updater.get_target_filepath( url )
|
||||
except:
|
||||
Logger.warn( WARNING_MESSAGE.format( url = url ) )
|
||||
|
|
|
|||
Loading…
Reference in a new issue