Skip to content

Commit 720b3b0

Browse files
feat: Add support for negative test vectors (#340)
Co-authored-by: Robin Salkeld <[email protected]>
1 parent f8cdaed commit 720b3b0

18 files changed

+638
-54508
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test_vector_handlers/test/aws-crypto-tools-test-vector-framework"]
2+
path = test_vector_handlers/test/aws-crypto-tools-test-vector-framework
3+
url = https://github.com/awslabs/aws-crypto-tools-test-vector-framework.git

test_vector_handlers/README.rst

+24-3
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,40 @@ processing of common test manifest types.
2424
Full Message Encrypt
2525
--------------------
2626

27-
Used to process an AWS Encryption SDK Full Message Encrypt manifest and produce
27+
Used to process an AWS Encryption SDK Full Message Encrypt manifest.
28+
29+
.. code::
30+
31+
usage: awses-full-message-encrypt [-h] --input INPUT
32+
33+
Build ciphertexts and decrypt manifest from keys and encrypt manifests
34+
35+
optional arguments:
36+
-h, --help show this help message and exit
37+
--input INPUT Existing full message encrypt manifest
38+
39+
Full Message Decrypt Manifest Generate
40+
----------------------------------------
41+
42+
Used to process an AWS Encryption SDK Full Message Decrypt Generation manifest and produce
2843
a Full Message Decrypt manifest along with all corresponding plaintexts and ciphertexts.
2944

3045
.. code::
3146
32-
usage: awses-full-message-encrypt [-h] --output OUTPUT --input INPUT [--human]
47+
usage: awses-full-message-decrypt-generate [-h] --output OUTPUT --input INPUT [--human]
3348
3449
Build ciphertexts and decrypt manifest from keys and encrypt manifests
3550
3651
optional arguments:
3752
-h, --help show this help message and exit
3853
--output OUTPUT Directory in which to store results
39-
--input INPUT Existing full message encrypt manifest
54+
--input INPUT Existing full message decrypt generation manifest
4055
--human Output human-readable JSON
4156
57+
The output of this command can be used to produce a zip file to be added to the
58+
`shared test vectors repository`_.
59+
Make sure that the individual contents of the output directory are top-level entries in
60+
the zip file; it is easy to add an additional top-level folder by accident!
4261

4362
Full Message Decrypt
4463
--------------------
@@ -55,3 +74,5 @@ decrypt and verify all referenced ciphertexts.
5574
optional arguments:
5675
-h, --help show this help message and exit
5776
--input INPUT Existing full message decrypt manifest
77+
78+
.. _shared test vectors repository: https://github.com/awslabs/aws-encryption-sdk-test-vectors

test_vector_handlers/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
attrs >= 17.4.0
2-
aws-encryption-sdk
2+
aws-encryption-sdk>=2.0.0
3+
pytest>=3.3.1
34
six

test_vector_handlers/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def get_requirements():
5959
entry_points={
6060
"console_scripts": [
6161
"awses-full-message-encrypt=awses_test_vectors.commands.full_message_encrypt:cli",
62+
"awses-full-message-decrypt-generate=awses_test_vectors.commands.full_message_decrypt_generate:cli",
6263
"awses-full-message-decrypt=awses_test_vectors.commands.full_message_decrypt:cli",
6364
]
6465
},

test_vector_handlers/src/awses_test_vectors/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Static test vector handling logic for the AWS Encyrption SDK."""
14-
__version__ = "1.0.0"
14+
__version__ = "2.0.0"

test_vector_handlers/src/awses_test_vectors/commands/full_message_decrypt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""AWS Encryption SDK full message decrypt command."""
13+
"""Command to test AWS Encryption SDK full message decryption vectors."""
1414
import argparse
1515

1616
from awses_test_vectors.manifests.full_message.decrypt import MessageDecryptionManifest
@@ -25,7 +25,7 @@
2525
def cli(args=None):
2626
# type: (Optional[Iterable[str]]) -> None
2727
"""CLI entry point for processing AWS Encryption SDK Decrypt Message manifests."""
28-
parser = argparse.ArgumentParser(description="Decrypt ciphertexts generated by awses-full-message-encrypt")
28+
parser = argparse.ArgumentParser(description="Decrypt ciphertexts from keys and decrypt manifests")
2929
parser.add_argument(
3030
"--input", required=True, type=argparse.FileType("r"), help="Existing full message decrypt manifest"
3131
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Command to generate AWS Encryption SDK full message decryption vectors."""
14+
import argparse
15+
16+
from awses_test_vectors.manifests.full_message.decrypt_generation import MessageDecryptionGenerationManifest
17+
18+
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
19+
from typing import Iterable, Optional # noqa pylint: disable=unused-import
20+
except ImportError: # pragma: no cover
21+
# We only actually need these imports when running the mypy checks
22+
pass
23+
24+
25+
def cli(args=None):
26+
# type: (Optional[Iterable[str]]) -> None
27+
"""CLI entry point for generating AWS Encryption SDK Decrypt Message manifests."""
28+
parser = argparse.ArgumentParser(
29+
description="Build a decrypt manifest from keys and decrypt generation manifests"
30+
)
31+
parser.add_argument("--output", required=True, help="Directory in which to store results")
32+
parser.add_argument(
33+
"--input", required=True, type=argparse.FileType("r"), help="Existing full message decrypt generation manifest"
34+
)
35+
parser.add_argument(
36+
"--human",
37+
required=False,
38+
default=None,
39+
action="store_const",
40+
const=4,
41+
dest="json_indent",
42+
help="Output human-readable JSON",
43+
)
44+
45+
parsed = parser.parse_args(args)
46+
47+
encrypt_manifest = MessageDecryptionGenerationManifest.from_file(parsed.input)
48+
49+
encrypt_manifest.run_and_write_to_dir(target_directory=parsed.output, json_indent=parsed.json_indent)

test_vector_handlers/src/awses_test_vectors/commands/full_message_encrypt.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""AWS Encryption SDK full message encrypt command."""
13+
"""Command to test AWS Encryption SDK full message encryption vectors."""
1414
import argparse
1515

1616
from awses_test_vectors.manifests.full_message.encrypt import MessageEncryptionManifest
@@ -26,24 +26,14 @@ def cli(args=None):
2626
# type: (Optional[Iterable[str]]) -> None
2727
"""CLI entry point for processing AWS Encryption SDK Encrypt Message manifests."""
2828
parser = argparse.ArgumentParser(
29-
description="Build ciphertexts and decrypt manifest from keys and encrypt manifests"
29+
description="Build ciphertexts from keys and encrypt manifests"
3030
)
31-
parser.add_argument("--output", required=True, help="Directory in which to store results")
3231
parser.add_argument(
3332
"--input", required=True, type=argparse.FileType("r"), help="Existing full message encrypt manifest"
3433
)
35-
parser.add_argument(
36-
"--human",
37-
required=False,
38-
default=None,
39-
action="store_const",
40-
const=4,
41-
dest="json_indent",
42-
help="Output human-readable JSON",
43-
)
4434

4535
parsed = parser.parse_args(args)
4636

4737
encrypt_manifest = MessageEncryptionManifest.from_file(parsed.input)
4838

49-
encrypt_manifest.run_and_write_to_dir(target_directory=parsed.output, json_indent=parsed.json_indent)
39+
encrypt_manifest.run()

0 commit comments

Comments
 (0)