Skip to content

Commit 004ea5d

Browse files
MeghaShettymattsb42-aws
authored andcommitted
Add keyring base class (#176)
* Adding Keyring API * Delete __init__.py * Delete raw_keyring.py * Added docstring to public class * Edited docstring * Edited docstring again * Changes in docstring statements * Docstring changes * Changes in docstring * Raw keyring initial * Raw keyring encrypt commit * Encrypt functions for Raw RSA and AES * Raw RSA and AES initial * Changes in raw keyrings according to new keyring materials * Updated with autoformat * Modified base * Corrected tox and flake errors * Docstring error correction * Added docstrings and corrected errors * Some more changes in docstrings * Updating base API * Made all suggested changes * Corrected tox and flake8 errors * Minor change in raw-keyrings * Adding Keyring API * Delete __init__.py * Delete raw_keyring.py * Added docstring to public class * Edited docstring * Edited docstring again * Changes in docstring statements * Docstring changes * Changes in docstring * Raw keyring initial * Raw keyring encrypt commit * Encrypt functions for Raw RSA and AES * Raw RSA and AES initial * bump attrs to 19.1.0 * add keyring trace and integrate into updated encrytion/decryption materials * s/KeyRing/Keyring/g * align cryptographic materials and add write-only interface * encrypted_data_keys must only contain EncryptedDataKey * fix test to be Python 2 compatible * Changes in raw keyrings according to new keyring materials * Updated with autoformat * Modified base * data encryption key must be set before encrypted data keys can be added to EncryptionMaterials * Corrected tox and flake errors * Docstring error correction * Added docstrings and corrected errors * Some more changes in docstrings * Updating base API * add signing/verification key checks to Encryption/DecryptionMaterials * DecryptionMaterials.algorithm must be set before DecryptionMaterials.add_data_encryption_key can be called * update materials docs and typehints * Made all suggested changes * EncryptionMaterials must not be initialized with encrypted_data_keys but no data_encryption_key * add is_complete properties to EncryptionMaterials and DecryptionMaterials * Corrected tox and flake8 errors * Minor change in raw-keyrings * change KeyringTraceFlag values to bitshifted ints to match other implementations * normalize EncryptionMaterials._encrypted_data_keys to list and encrypted_data_keys to tuple * temporarily pin pydocstyle at <4.0.0 to avoid issue breaking flake8-docstrings * temporarily cap pydocstyle at <4.0.0 for decrypt oracle * Changes to keyring trace in raw keyrings * Adding test files * Adding tests * Changed data encryption key type to RawDataKey * Added keyring trace to pytest encryption materials * Changed value of keyring_trace.wrapping_key * Few changes to match new API * Tox errors * Functional tests pass * Formatting errors corrected and functional tests pass * Corrected too broad exception error and deleted empty return statement from tests * Changed Exeception to BaseException to solve broad exception error * Added suppress broad exception * Added pylint disable broad exception * Changed wrapping keys for RSA keyrings from WrappingKey to cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey/RSAPublicKey * Fixed tox errors * More tox errors * Moved code for generation of plaintext to be before the check for key being private or public * Tox errors * Added metaclass to base API and unit tests for base API * Changed metaclass to six.add_metaclass in base API * Fixed pylint errors * Fixed more pylint errors * Removed RawAESKeyring instance * Changed on_encrypt_helper to generate_data_key and removed on_decrypt_helper. Renamed base API unit test file * Changed docstring for generate_data_key * Changed decryption_materials.data_key to decryption_materials.data_encryption_key and fixed pylint errors * Fixed pylint errors * Changed raw keyrings to have class methods for PEM and DER encoded keys * Unit tests for raw keyrings * Changes for PEM encoding * Changed base API to remove metaclass and modified tests * Delete raw_keyring.py * Delete test_f_keyring_raw_aes.py * Delete test_f_keyring_raw_rsa.py * Delete test_keyring_raw_aes.py * Delete test_keyring_raw_rsa.py * Suggested changes * Made suggested changes to base API and tests * Made suggested changes to base API tests * Ignore commit * Corrected tox and pylint errors in base API unit tests * Removed try except for Iterable * Removed try except for Iterable from test_utils * Added try except for Iterable in base API * Resolved isort errors
1 parent 1615d63 commit 004ea5d

File tree

5 files changed

+110
-2
lines changed

5 files changed

+110
-2
lines changed

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
six
12
boto3>=1.4.4
23
cryptography>=1.8.1
34
attrs>=19.1.0
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2017 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+
"""All provided Keyrings."""

src/aws_encryption_sdk/materials_managers/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class EncryptionMaterials(CryptographicMaterials):
191191
Most parameters are now optional.
192192
193193
:param Algorithm algorithm: Algorithm to use for encrypting message
194-
:param DataKey data_encryption_key: Plaintext data key to use for encrypting message (optional)
194+
:param RawDataKey data_encryption_key: Plaintext data key to use for encrypting message (optional)
195195
:param encrypted_data_keys: List of encrypted data keys (optional)
196196
:type encrypted_data_keys: list of :class:`EncryptedDataKey`
197197
:param dict encryption_context: Encryption context tied to `encrypted_data_keys`
@@ -370,7 +370,7 @@ class DecryptionMaterials(CryptographicMaterials):
370370
All parameters are now optional.
371371
372372
:param Algorithm algorithm: Algorithm to use for encrypting message (optional)
373-
:param DataKey data_encryption_key: Plaintext data key to use for encrypting message (optional)
373+
:param RawDataKey data_encryption_key: Plaintext data key to use for encrypting message (optional)
374374
:param dict encryption_context: Encryption context tied to `encrypted_data_keys` (optional)
375375
:param bytes verification_key: Raw signature verification key (optional)
376376
:param keyring_trace: Any KeyRing trace entries (optional)

test/unit/test_keyring_base.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2019 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+
"""Unit tests for base keyring."""
14+
15+
import pytest
16+
17+
from aws_encryption_sdk.identifiers import Algorithm
18+
from aws_encryption_sdk.keyring.base import Keyring
19+
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
20+
21+
pytestmark = [pytest.mark.unit, pytest.mark.local]
22+
23+
_encryption_materials = EncryptionMaterials(
24+
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384,
25+
encryption_context={"encryption": "context", "values": "here"},
26+
signing_key=b"aws-crypto-public-key",
27+
)
28+
29+
_decryption_materials = DecryptionMaterials(
30+
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, verification_key=b"ex_verification_key"
31+
)
32+
33+
_encrypted_data_keys = []
34+
35+
36+
def test_keyring_no_encrypt():
37+
with pytest.raises(NotImplementedError) as exc_info:
38+
Keyring().on_encrypt(encryption_materials=_encryption_materials)
39+
assert exc_info.match("Keyring does not implement on_encrypt function")
40+
41+
42+
def test_keyring_no_decrypt():
43+
with pytest.raises(NotImplementedError) as exc_info:
44+
Keyring().on_decrypt(decryption_materials=_decryption_materials, encrypted_data_keys=_encrypted_data_keys)
45+
assert exc_info.match("Keyring does not implement on_decrypt function")

test/unit/test_values.py

+49
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,55 @@ def array_byte(source):
187187
"\xff\x8fn\x95\xf0\xf0E\x91Uj\xb0E3=\x0e\x1a\xf1'4\xf6"
188188
),
189189
"signature_len": b"\x00h",
190+
"private_rsa_key_bytes": [
191+
(
192+
b"-----BEGIN RSA PRIVATE KEY-----"
193+
b"MIICXgIBAAKBgQCUjhI8YRPXV8Gfofbg/"
194+
b"PLjWw2AzowQTPErLU2z3+xGqElMdzdiC4Ta43DFWZg34Eg0X8kQPAeoe8h3cRSMo"
195+
b"77eSOHt2dPo7OfTfZqsH8766fivHIKVxBYPX8SZYIUhMtRnlg3uqch9BksfRop+h"
196+
b"f8h/H3lfervJoevS2CXYB9/iwIDAQABAoGBAIqeGzQOHbaGI51yQ2zjez1dPDdiB"
197+
b"F49fZide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JQUTxYGzsY+ZemlNm\n"
231+
b"fGdQo7a8kePMRuKY2MkcnXPaqTg49YgRmjq4z8CtHokRcWjJUWnPOTs8rmEZUshk\n"
232+
b"0KJ0mbQdCFt/Uv0mtXgpFTkEZ3DPkDTGcV4oR4CRfOCl0/EU/A5VvL/U4i/mRo7h\n"
233+
b"ye+xgQKBgD58b+9z+PR5LAJm1tZHIwb4tnyczP28PzwknxFd2qylR4ZNgvAUqGtU\n"
234+
b"xvpUDpzMioz6zUH9YV43YNtt+5Xnzkqj+u9Mr27/H2v9XPwORGfwQ5XPwRJz/2oC\n"
235+
b"EnPmP1SZoY9lXKUpQXHXSpDZ2rE2Klt3RHMUMHt8Zpy36E8Vwx8o\n"
236+
b"-----END RSA PRIVATE KEY-----\n"
237+
),
238+
],
190239
}
191240
VALUES["updated_encryption_context"] = copy.deepcopy(VALUES["encryption_context"])
192241
VALUES["updated_encryption_context"]["aws-crypto-public-key"] = VALUES["encoded_curve_point"]

0 commit comments

Comments
 (0)