Skip to content
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

Restore ImageRepoBadHwIdUptane and fix other HWID tests. #56

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions tuf_vectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def human_message(err: str) -> str:
"hardware id."
elif err == 'BadEcuId':
return "The target had an ECU ID that did not match the client's configured ECU id."
elif err == 'TargetMismatch':
return "The target metadata in image and director do not match."
else:
raise Exception('Unavailable err: {}'.format(err))

Expand Down
13 changes: 8 additions & 5 deletions tuf_vectors/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,17 @@ def __init__(
'sha256': sha256(content, bad_hash=bad_hash),
'sha512': sha512(content, bad_hash=bad_hash),
},
'custom': {
'hardwareId': hardware_id,
},
'custom': {},
}

if ecu_identifier is not None:
if ecu_identifier is None:
# Only used by Image repo metadata.
self.meta['custom'] = {
'hardwareIds': [ hardware_id + ('-XXX' if bad_hw_id else ''), ],
}
else:
# Only used by Director metadata.
ecu_identifier = ecu_identifier + ('-XXX' if bad_ecu_id else '')
self.meta['custom']['ecuIdentifier'] = ecu_identifier
self.meta['custom']['ecuIdentifiers'] = {
ecu_identifier: {
'hardwareId': hardware_id + ('-XXX' if bad_hw_id else ''),
Expand Down
72 changes: 66 additions & 6 deletions tuf_vectors/uptane.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class ImageStep(Step):
class DirectorStep(Step):

TARGET_ERRORS = {
DEFAULT_TARGET_NAME: 'TargetHashMismatch',
DEFAULT_TARGET_NAME: 'TargetMismatch',
}

TARGETS_KEYS_IDX = [5]
Expand Down Expand Up @@ -769,7 +769,7 @@ class ImageRepoTargetHashMismatchUptane(Uptane):
class ImageStep(Step):

TARGET_ERRORS = {
DEFAULT_TARGET_NAME: 'TargetHashMismatch',
DEFAULT_TARGET_NAME: 'TargetMismatch',
}

TARGETS_KEYS_IDX = [1]
Expand Down Expand Up @@ -2574,6 +2574,66 @@ def __targets(hardware_id: str, ecu_identifier: str=None) -> list:
(DirectorStep, ImageStep),
]


class ImageRepoBadHwIdUptane(Uptane):

'''The image repo targets metadata has a bad hardware ID'''

class ImageStep(Step):

TARGET_ERRORS = {
DEFAULT_TARGET_NAME: 'TargetMismatch',
}

TARGETS_KEYS_IDX = [1]
SNAPSHOT_KEYS_IDX = [2]
TIMESTAMP_KEYS_IDX = [3]

ROOT_KWARGS = {
'root_keys_idx': [0],
'targets_keys_idx': TARGETS_KEYS_IDX,
'snapshot_keys_idx': SNAPSHOT_KEYS_IDX,
'timestamp_keys_idx': TIMESTAMP_KEYS_IDX,
}

def __targets(hardware_id: str, ecu_identifier: str=None) -> list:
return [Target(name=DEFAULT_TARGET_NAME,
content=DEFAULT_TARGET_CONTENT,
hardware_id=hardware_id,
ecu_identifier=ecu_identifier,
alteration='bad-hw-id')]

TARGETS_KWARGS = {
'targets_keys_idx': TARGETS_KEYS_IDX,
'targets': __targets,
}

SNAPSHOT_KWARGS = {
'snapshot_keys_idx': SNAPSHOT_KEYS_IDX,
}

TIMESTAMP_KWARGS = {
'timestamp_keys_idx': TIMESTAMP_KEYS_IDX,
}

class DirectorStep(Step):

TARGETS_KEYS_IDX = [5]

ROOT_KWARGS = {
'root_keys_idx': [4],
'targets_keys_idx': TARGETS_KEYS_IDX,
}

TARGETS_KWARGS = {
'targets_keys_idx': TARGETS_KEYS_IDX,
}

STEPS = [
(DirectorStep, ImageStep),
]


class BadHwIdUptane(Uptane):

'''Both targets metadata have a bad hardware ID'''
Expand Down Expand Up @@ -2931,7 +2991,7 @@ def __delegations(delegations_keys_idx: list=None, **kwargs) -> list:
class DirectorStep(Step):

TARGET_ERRORS = {
DEFAULT_TARGET_NAME: 'TargetHashMismatch',
DEFAULT_TARGET_NAME: 'TargetMismatch',
}

TARGETS_KEYS_IDX = [5]
Expand Down Expand Up @@ -3251,7 +3311,7 @@ class DirectorStep(Step):
# the target is missing, but that doesn't work. The error could also be
# more accurate.
TARGET_ERRORS = {
DEFAULT_TARGET_NAME: 'TargetHashMismatch',
DEFAULT_TARGET_NAME: 'TargetMismatch',
}

TARGETS_KEYS_IDX = [5]
Expand Down Expand Up @@ -3322,7 +3382,7 @@ class DirectorStep(Step):
# Should be a failure in the images repo, since that is where the
# target is missing, but that doesn't work.
TARGET_ERRORS = {
DEFAULT_TARGET_NAME: 'TargetHashMismatch',
DEFAULT_TARGET_NAME: 'TargetMismatch',
}

TARGETS_KEYS_IDX = [5]
Expand Down Expand Up @@ -3387,7 +3447,7 @@ class DirectorStep(Step):
# target is missing, but that doesn't work. The error could also be
# more accurate.
TARGET_ERRORS = {
DEFAULT_TARGET_NAME: 'TargetHashMismatch',
DEFAULT_TARGET_NAME: 'TargetMismatch',
}

TARGETS_KEYS_IDX = [5]
Expand Down