Skip to content

Commit 3a02cb6

Browse files
authored
Merge pull request #93 from mattsb42-aws/vectors
Fix handling of raw test vector manifests
2 parents c609316 + 4e742c6 commit 3a02cb6

File tree

6 files changed

+50827
-2350
lines changed

6 files changed

+50827
-2350
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ __pycache__
3333

3434
# PyCharm
3535
.idea/
36+
venv/
3637

3738
# Tox
3839
.tox

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ matrix:
101101
- python: 2.7
102102
env:
103103
TEST_VECTOR_HANDLERS=1
104-
TOXENV=py27-awses_1.3.0
104+
TOXENV=py27-awses_1.3.3
105105
- python: 2.7
106106
env:
107107
TEST_VECTOR_HANDLERS=1
@@ -114,7 +114,7 @@ matrix:
114114
- python: 3.4
115115
env:
116116
TEST_VECTOR_HANDLERS=1
117-
TOXENV=py34-awses_1.3.0
117+
TOXENV=py34-awses_1.3.3
118118
- python: 3.4
119119
env:
120120
TEST_VECTOR_HANDLERS=1
@@ -127,7 +127,7 @@ matrix:
127127
- python: 3.5
128128
env:
129129
TEST_VECTOR_HANDLERS=1
130-
TOXENV=py35-awses_1.3.0
130+
TOXENV=py35-awses_1.3.3
131131
- python: 3.5
132132
env:
133133
TEST_VECTOR_HANDLERS=1
@@ -140,7 +140,7 @@ matrix:
140140
- python: 3.6
141141
env:
142142
TEST_VECTOR_HANDLERS=1
143-
TOXENV=py36-awses_1.3.0
143+
TOXENV=py36-awses_1.3.3
144144
- python: 3.6
145145
env:
146146
TEST_VECTOR_HANDLERS=1
@@ -153,7 +153,7 @@ matrix:
153153
- python: 3.7
154154
env:
155155
TEST_VECTOR_HANDLERS=1
156-
TOXENV=py37-awses_1.3.0
156+
TOXENV=py37-awses_1.3.3
157157
dist: xenial
158158
sudo: true
159159
- python: 3.7

test_vector_handlers/src/awses_test_vectors/manifests/full_message/encrypt.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,14 @@ def from_file(cls, input_file):
202202
raw_keys_manifest = json.loads(reader(raw_manifest["keys"]).decode(ENCODING))
203203
keys = KeysManifest.from_manifest_spec(raw_keys_manifest)
204204
plaintexts = cls._generate_plaintexts(raw_manifest["plaintexts"])
205-
tests = {
206-
name: MessageEncryptionTestScenario.from_scenario(scenario=scenario, keys=keys, plaintexts=plaintexts)
207-
for name, scenario in raw_manifest["tests"].items()
208-
}
205+
tests = {}
206+
for name, scenario in raw_manifest["tests"].items():
207+
try:
208+
tests[name] = MessageEncryptionTestScenario.from_scenario(
209+
scenario=scenario, keys=keys, plaintexts=plaintexts
210+
)
211+
except NotImplementedError:
212+
continue
209213
return cls(version=raw_manifest["manifest"]["version"], keys=keys, plaintexts=plaintexts, tests=tests)
210214

211215
def run_and_write_to_dir(self, target_directory, json_indent=None):

test_vector_handlers/src/awses_test_vectors/manifests/master_key.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
# 'rsa/oaep-mgf1/sha384': WrappingAlgorithm.RSA_OAEP_SHA384_MGF1,
5555
# 'rsa/oaep-mgf1/sha512': WrappingAlgorithm.RSA_OAEP_SHA512_MGF1,
5656
}
57+
_NOT_YET_IMPLEMENTED = {"rsa/oaep-mgf1/sha384", "rsa/oaep-mgf1/sha512"}
5758
_RAW_ENCRYPTION_KEY_TYPE = {
5859
"symmetric": EncryptionKeyType.SYMMETRIC,
5960
"private": EncryptionKeyType.PRIVATE,
@@ -91,10 +92,11 @@ def __attrs_post_init__(self):
9192
raise NotImplementedError("Gap found between known master key types and available master key loaders.")
9293

9394
if self.type_name == "raw":
94-
if None in (self.provider_id, self.encryption_algorithm, self.padding_algorithm):
95-
raise ValueError(
96-
"Provider ID, encryption algorithm, and padding algorithm are all required for raw keys"
97-
)
95+
if None in (self.provider_id, self.encryption_algorithm):
96+
raise ValueError("Provider ID and encryption algorithm are both required for raw keys")
97+
98+
if self.encryption_algorithm == "rsa" and self.padding_algorithm is None:
99+
raise ValueError("Padding algorithm is required for raw RSA keys")
98100

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

143-
return _RAW_WRAPPING_KEY_ALGORITHMS["/".join(key_spec_values)]
145+
key_spec_name = "/".join(key_spec_values)
146+
147+
if key_spec_name in _NOT_YET_IMPLEMENTED:
148+
raise NotImplementedError('Key spec "{}" is not yet available.')
149+
150+
return _RAW_WRAPPING_KEY_ALGORITHMS[key_spec_name]
144151

145152
def _wrapping_key(self, key_spec):
146153
# type: (KeySpec) -> WrappingKey

0 commit comments

Comments
 (0)