Skip to content

Fix handling of raw test vector manifests #93

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 5 commits into from
Nov 6, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ __pycache__

# PyCharm
.idea/
venv/

# Tox
.tox
Expand Down
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ matrix:
- python: 2.7
env:
TEST_VECTOR_HANDLERS=1
TOXENV=py27-awses_1.3.0
TOXENV=py27-awses_1.3.3
- python: 2.7
env:
TEST_VECTOR_HANDLERS=1
Expand All @@ -114,7 +114,7 @@ matrix:
- python: 3.4
env:
TEST_VECTOR_HANDLERS=1
TOXENV=py34-awses_1.3.0
TOXENV=py34-awses_1.3.3
- python: 3.4
env:
TEST_VECTOR_HANDLERS=1
Expand All @@ -127,7 +127,7 @@ matrix:
- python: 3.5
env:
TEST_VECTOR_HANDLERS=1
TOXENV=py35-awses_1.3.0
TOXENV=py35-awses_1.3.3
- python: 3.5
env:
TEST_VECTOR_HANDLERS=1
Expand All @@ -140,7 +140,7 @@ matrix:
- python: 3.6
env:
TEST_VECTOR_HANDLERS=1
TOXENV=py36-awses_1.3.0
TOXENV=py36-awses_1.3.3
- python: 3.6
env:
TEST_VECTOR_HANDLERS=1
Expand All @@ -153,7 +153,7 @@ matrix:
- python: 3.7
env:
TEST_VECTOR_HANDLERS=1
TOXENV=py37-awses_1.3.0
TOXENV=py37-awses_1.3.3
dist: xenial
sudo: true
- python: 3.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ def from_file(cls, input_file):
raw_keys_manifest = json.loads(reader(raw_manifest["keys"]).decode(ENCODING))
keys = KeysManifest.from_manifest_spec(raw_keys_manifest)
plaintexts = cls._generate_plaintexts(raw_manifest["plaintexts"])
tests = {
name: MessageEncryptionTestScenario.from_scenario(scenario=scenario, keys=keys, plaintexts=plaintexts)
for name, scenario in raw_manifest["tests"].items()
}
tests = {}
for name, scenario in raw_manifest["tests"].items():
try:
tests[name] = MessageEncryptionTestScenario.from_scenario(
scenario=scenario, keys=keys, plaintexts=plaintexts
)
except NotImplementedError:
continue
return cls(version=raw_manifest["manifest"]["version"], keys=keys, plaintexts=plaintexts, tests=tests)

def run_and_write_to_dir(self, target_directory, json_indent=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
# 'rsa/oaep-mgf1/sha384': WrappingAlgorithm.RSA_OAEP_SHA384_MGF1,
# 'rsa/oaep-mgf1/sha512': WrappingAlgorithm.RSA_OAEP_SHA512_MGF1,
}
_NOT_YET_IMPLEMENTED = {"rsa/oaep-mgf1/sha384", "rsa/oaep-mgf1/sha512"}
_RAW_ENCRYPTION_KEY_TYPE = {
"symmetric": EncryptionKeyType.SYMMETRIC,
"private": EncryptionKeyType.PRIVATE,
Expand Down Expand Up @@ -91,10 +92,11 @@ def __attrs_post_init__(self):
raise NotImplementedError("Gap found between known master key types and available master key loaders.")

if self.type_name == "raw":
if None in (self.provider_id, self.encryption_algorithm, self.padding_algorithm):
raise ValueError(
"Provider ID, encryption algorithm, and padding algorithm are all required for raw keys"
)
if None in (self.provider_id, self.encryption_algorithm):
raise ValueError("Provider ID and encryption algorithm are both required for raw keys")

if self.encryption_algorithm == "rsa" and self.padding_algorithm is None:
raise ValueError("Padding algorithm is required for raw RSA keys")

if self.padding_algorithm == "oaep-mgf1" and self.padding_hash is None:
raise ValueError('Padding hash must be specified if padding algorithm is "oaep-mgf1"')
Expand Down Expand Up @@ -140,7 +142,12 @@ def _wrapping_algorithm(self, key_bits):
if self.padding_hash is not None:
key_spec_values.append(self.padding_hash)

return _RAW_WRAPPING_KEY_ALGORITHMS["/".join(key_spec_values)]
key_spec_name = "/".join(key_spec_values)

if key_spec_name in _NOT_YET_IMPLEMENTED:
raise NotImplementedError('Key spec "{}" is not yet available.')

return _RAW_WRAPPING_KEY_ALGORITHMS[key_spec_name]

def _wrapping_key(self, key_spec):
# type: (KeySpec) -> WrappingKey
Expand Down
Loading