Skip to content

Raw keyrings #165

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 123 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
0d29631
Adding Keyring API
mmegs-amzn Jun 18, 2019
237a2af
Added docstring to public class
mmegs-amzn Jun 18, 2019
9bbdf83
Delete __init__.py
MeghaShetty Jun 18, 2019
1a14a3b
Delete raw_keyring.py
MeghaShetty Jun 18, 2019
c1a1c77
Edited docstring
mmegs-amzn Jun 18, 2019
66b348f
Edited docstring again
mmegs-amzn Jun 18, 2019
4a0a1c6
Changes in docstring statements
mmegs-amzn Jun 19, 2019
5f6fcb9
Docstring changes
mmegs-amzn Jun 19, 2019
9d8d964
Changes in docstring
mmegs-amzn Jun 20, 2019
83ccdd3
Raw keyring initial
mmegs-amzn Jun 20, 2019
aed1ed7
Raw keyring encrypt commit
mmegs-amzn Jun 20, 2019
dc9352c
Encrypt functions for Raw RSA and AES
mmegs-amzn Jun 20, 2019
b9c22b9
Raw RSA and AES initial
mmegs-amzn Jun 20, 2019
745c9ed
Changes in raw keyrings according to new keyring materials
mmegs-amzn Jun 27, 2019
bb163bc
Updated with autoformat
mmegs-amzn Jun 27, 2019
27fe8d9
Modified base
mmegs-amzn Jun 28, 2019
e8286ac
Corrected tox and flake errors
mmegs-amzn Jun 28, 2019
eef26e7
Docstring error correction
mmegs-amzn Jul 1, 2019
900a064
Added docstrings and corrected errors
mmegs-amzn Jul 1, 2019
c500970
Some more changes in docstrings
mmegs-amzn Jul 1, 2019
8a00e15
Updating base API
mmegs-amzn Jul 1, 2019
250f554
Made all suggested changes
mmegs-amzn Jul 2, 2019
d8a8389
Corrected tox and flake8 errors
mmegs-amzn Jul 3, 2019
8f9f737
Minor change in raw-keyrings
mmegs-amzn Jul 8, 2019
9cd81ea
Adding Keyring API
mmegs-amzn Jun 18, 2019
e3d0757
Added docstring to public class
mmegs-amzn Jun 18, 2019
fcb03c2
Delete __init__.py
MeghaShetty Jun 18, 2019
ae78331
Delete raw_keyring.py
MeghaShetty Jun 18, 2019
f668ca4
Edited docstring
mmegs-amzn Jun 18, 2019
c06b1fa
Edited docstring again
mmegs-amzn Jun 18, 2019
1e2a672
Changes in docstring statements
mmegs-amzn Jun 19, 2019
82feb00
Docstring changes
mmegs-amzn Jun 19, 2019
11f9ce6
Changes in docstring
mmegs-amzn Jun 20, 2019
7a345a5
Raw keyring initial
mmegs-amzn Jun 20, 2019
6ef9ea7
Raw keyring encrypt commit
mmegs-amzn Jun 20, 2019
6576731
Encrypt functions for Raw RSA and AES
mmegs-amzn Jun 20, 2019
5a87c0e
Raw RSA and AES initial
mmegs-amzn Jun 20, 2019
dd01e6b
bump attrs to 19.1.0
mattsb42-aws Jun 21, 2019
82429fe
add keyring trace and integrate into updated encrytion/decryption mat…
mattsb42-aws Jun 21, 2019
0dc48a2
s/KeyRing/Keyring/g
mattsb42-aws Jun 21, 2019
ea0b09d
align cryptographic materials and add write-only interface
mattsb42-aws Jun 27, 2019
9b3d4e2
encrypted_data_keys must only contain EncryptedDataKey
mattsb42-aws Jun 27, 2019
ac67a6f
fix test to be Python 2 compatible
mattsb42-aws Jun 27, 2019
0921eff
Changes in raw keyrings according to new keyring materials
mmegs-amzn Jun 27, 2019
8399fea
Updated with autoformat
mmegs-amzn Jun 27, 2019
38c756b
Modified base
mmegs-amzn Jun 28, 2019
5005cfb
data encryption key must be set before encrypted data keys can be add…
mattsb42-aws Jun 28, 2019
242a3a3
Corrected tox and flake errors
mmegs-amzn Jun 28, 2019
2672567
Docstring error correction
mmegs-amzn Jul 1, 2019
2696183
Added docstrings and corrected errors
mmegs-amzn Jul 1, 2019
f1d1977
Some more changes in docstrings
mmegs-amzn Jul 1, 2019
f08239c
Updating base API
mmegs-amzn Jul 1, 2019
881cf5e
add signing/verification key checks to Encryption/DecryptionMaterials
mattsb42-aws Jul 2, 2019
5769efa
DecryptionMaterials.algorithm must be set before DecryptionMaterials.…
mattsb42-aws Jul 2, 2019
00a7678
update materials docs and typehints
mattsb42-aws Jul 2, 2019
36edf5b
Made all suggested changes
mmegs-amzn Jul 2, 2019
98cf791
EncryptionMaterials must not be initialized with encrypted_data_keys …
mattsb42-aws Jul 3, 2019
e03f38b
add is_complete properties to EncryptionMaterials and DecryptionMater…
mattsb42-aws Jul 3, 2019
f99ac6c
Corrected tox and flake8 errors
mmegs-amzn Jul 3, 2019
b928fd2
Minor change in raw-keyrings
mmegs-amzn Jul 8, 2019
e92db76
change KeyringTraceFlag values to bitshifted ints to match other impl…
mattsb42-aws Jul 9, 2019
bcd4cfe
normalize EncryptionMaterials._encrypted_data_keys to list and encryp…
mattsb42-aws Jul 9, 2019
be3a391
temporarily pin pydocstyle at <4.0.0 to avoid issue breaking flake8-d…
mattsb42-aws Jul 9, 2019
402af2c
temporarily cap pydocstyle at <4.0.0 for decrypt oracle
mattsb42-aws Jul 10, 2019
be4f74c
Changes to keyring trace in raw keyrings
mmegs-amzn Jul 12, 2019
f165e22
Merge branch 'keyring' of github.com:aws/aws-encryption-sdk-python in…
mmegs-amzn Jul 12, 2019
b921715
Changes to raw keyrings after rebase
mmegs-amzn Jul 12, 2019
c01fb90
Adding test files
mmegs-amzn Jul 12, 2019
85a0149
Adding tests
mmegs-amzn Jul 12, 2019
af239f6
Changed data encryption key type to RawDataKey
mmegs-amzn Jul 12, 2019
1a49427
Added keyring trace to pytest encryption materials
mmegs-amzn Jul 14, 2019
ec1d8b5
Changed value of keyring_trace.wrapping_key
mmegs-amzn Jul 15, 2019
5ff39d6
Few changes to match new API
mmegs-amzn Jul 15, 2019
64298a7
Tox errors
mmegs-amzn Jul 15, 2019
cc5aa44
Functional tests pass
mmegs-amzn Jul 16, 2019
7d896d1
Formatting errors corrected and functional tests pass
mmegs-amzn Jul 16, 2019
3eb4536
Corrected too broad exception error and deleted empty return statemen…
mmegs-amzn Jul 16, 2019
b1ad3ed
Changed Exeception to BaseException to solve broad exception error
mmegs-amzn Jul 16, 2019
03aeae3
Added suppress broad exception
mmegs-amzn Jul 17, 2019
2a248f5
Added pylint disable broad exception
mmegs-amzn Jul 17, 2019
92f419c
Changed wrapping keys for RSA keyrings from WrappingKey to cryptograp…
mmegs-amzn Jul 18, 2019
66b56b7
Fixed tox errors
mmegs-amzn Jul 18, 2019
0295db5
More tox errors
mmegs-amzn Jul 18, 2019
4adec20
Moved code for generation of plaintext to be before the check for key…
mmegs-amzn Jul 18, 2019
22243dc
Tox errors
mmegs-amzn Jul 18, 2019
07d05f7
Added metaclass to base API and unit tests for base API
mmegs-amzn Jul 18, 2019
6df10d5
Changed metaclass to six.add_metaclass in base API
mmegs-amzn Jul 18, 2019
8e47bad
Fixed pylint errors
mmegs-amzn Jul 18, 2019
4aae643
Fixed more pylint errors
mmegs-amzn Jul 18, 2019
ede165a
Removed RawAESKeyring instance
mmegs-amzn Jul 18, 2019
39dbfd3
Changed on_encrypt_helper to generate_data_key and removed on_decrypt…
mmegs-amzn Jul 19, 2019
61e8fe5
Changed docstring for generate_data_key
mmegs-amzn Jul 19, 2019
e61f4a2
Changed decryption_materials.data_key to decryption_materials.data_en…
mmegs-amzn Jul 19, 2019
89f8a2c
Fixed pylint errors
mmegs-amzn Jul 19, 2019
fbf351f
Changed raw keyrings to have class methods for PEM and DER encoded keys
mmegs-amzn Jul 20, 2019
fb8b7b8
Unit tests for raw keyrings
mmegs-amzn Jul 22, 2019
41dd140
Changes for PEM encoding
mmegs-amzn Jul 22, 2019
9fa50cf
Made suggested changes to raw keyrings
mmegs-amzn Jul 23, 2019
3b28bea
partial commit for raw keyrings
mmegs-amzn Jul 23, 2019
8f65947
Made suggested changes
mmegs-amzn Jul 23, 2019
40eb8cc
Changed wrapping_key_id in deserialize_wrapped_key() back to self.key…
mmegs-amzn Jul 23, 2019
96979b1
Decryption and PEM input now works
mmegs-amzn Jul 24, 2019
f592956
Adding sample
mmegs-amzn Jul 24, 2019
dbbb840
Removed test comments
mmegs-amzn Jul 24, 2019
b71e09c
Unit tests for raw aes and rsa
mmegs-amzn Jul 26, 2019
866755d
All unit tests working
mmegs-amzn Jul 26, 2019
dae98c3
All unit tests done. Functional tests - key_info_prefix_vectors for A…
mmegs-amzn Jul 27, 2019
00a7dad
Delete sample_aes.py
MeghaShetty Jul 27, 2019
29f69e0
Corrected tox and pylint errors
mmegs-amzn Jul 27, 2019
2e43c1e
Removed print statements used while debugging
mmegs-amzn Jul 27, 2019
8ce5cc6
Partial commit for changes to tests
mmegs-amzn Aug 1, 2019
9fcf529
Partial commit for tests for raw keyrings
mmegs-amzn Aug 1, 2019
d5d186e
All tests except compatibility of raw rsa with mkp and key info prefi…
mmegs-amzn Aug 2, 2019
69acc1a
Pulled from keyring branch
mmegs-amzn Aug 2, 2019
d89bc61
Merge branch 'keyring' into raw-keyrings
MeghaShetty Aug 2, 2019
7ea1bd6
Updated base API
mmegs-amzn Aug 2, 2019
f4ee7f0
Merge branch 'raw-keyrings' of github.com:MeghaShetty/aws-encryption-…
mmegs-amzn Aug 2, 2019
acbd5b4
Added test for key info prefix
mmegs-amzn Aug 2, 2019
8374130
Changed unittest.mock to mock
mmegs-amzn Aug 2, 2019
1dc5a77
Raw keyrings test partial commit
mmegs-amzn Aug 2, 2019
5a7e4b2
All tests for raw keyrings work
mmegs-amzn Aug 2, 2019
ced07c4
Removed unused imports
mmegs-amzn Aug 2, 2019
88cd097
Removed unused imports
mmegs-amzn Aug 2, 2019
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
436 changes: 436 additions & 0 deletions src/aws_encryption_sdk/keyring/raw_keyring.py

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions test/functional/test_f_keyring_raw_aes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Functional tests for Raw AES keyring encryption decryption path."""

import pytest

from aws_encryption_sdk.identifiers import (
Algorithm,
EncryptionKeyType,
EncryptionType,
KeyringTraceFlag,
WrappingAlgorithm,
)
from aws_encryption_sdk.internal.crypto import WrappingKey
from aws_encryption_sdk.internal.formatting.serialize import serialize_raw_master_key_prefix
from aws_encryption_sdk.key_providers.raw import RawMasterKey
from aws_encryption_sdk.keyring.raw_keyring import RawAESKeyring
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
from aws_encryption_sdk.structures import KeyringTrace, MasterKeyInfo, RawDataKey

pytestmark = [pytest.mark.functional, pytest.mark.local]

_ENCRYPTION_CONTEXT = {"encryption": "context", "values": "here"}
_PROVIDER_ID = "Random Raw Keys"
_KEY_ID = b"5325b043-5843-4629-869c-64794af77ada"
_WRAPPING_KEY = b"12345678901234567890123456789012"
_SIGNING_KEY = b"aws-crypto-public-key"

_WRAPPING_ALGORITHM = [alg for alg in WrappingAlgorithm if alg.encryption_type is EncryptionType.SYMMETRIC]


def sample_encryption_materials():
return [
EncryptionMaterials(
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384,
encryption_context=_ENCRYPTION_CONTEXT,
signing_key=_SIGNING_KEY,
),
EncryptionMaterials(
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384,
data_encryption_key=RawDataKey(
key_provider=MasterKeyInfo(provider_id=_PROVIDER_ID, key_info=_KEY_ID),
data_key=b'*!\xa1"^-(\xf3\x105\x05i@B\xc2\xa2\xb7\xdd\xd5\xd5\xa9\xddm\xfae\xa8\\$\xf9d\x1e(',
),
encryption_context=_ENCRYPTION_CONTEXT,
signing_key=_SIGNING_KEY,
keyring_trace=[
KeyringTrace(
wrapping_key=MasterKeyInfo(provider_id=_PROVIDER_ID, key_info=_KEY_ID),
flags={KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY},
)
],
),
]


@pytest.mark.parametrize("encryption_materials_samples", sample_encryption_materials())
@pytest.mark.parametrize("wrapping_algorithm_samples", _WRAPPING_ALGORITHM)
def test_raw_aes_encryption_decryption(encryption_materials_samples, wrapping_algorithm_samples):

# Initializing attributes
key_namespace = _PROVIDER_ID
key_name = _KEY_ID
_wrapping_algorithm = wrapping_algorithm_samples

# Creating an instance of a raw AES keyring
test_raw_aes_keyring = RawAESKeyring(
key_namespace=key_namespace,
key_name=key_name,
wrapping_key=_WRAPPING_KEY,
wrapping_algorithm=_wrapping_algorithm,
)

# Call on_encrypt function for the keyring
encryption_materials = test_raw_aes_keyring.on_encrypt(encryption_materials=encryption_materials_samples)

# Generate decryption materials
decryption_materials = DecryptionMaterials(
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384,
verification_key=b"ex_verification_key",
encryption_context=_ENCRYPTION_CONTEXT,
)

# Call on_decrypt function for the keyring
decryption_materials = test_raw_aes_keyring.on_decrypt(
decryption_materials=decryption_materials, encrypted_data_keys=encryption_materials.encrypted_data_keys
)

# Check if the data keys match
assert encryption_materials.data_encryption_key.data_key == decryption_materials.data_encryption_key.data_key


@pytest.mark.parametrize("encryption_materials_samples", sample_encryption_materials())
@pytest.mark.parametrize("wrapping_algorithm_samples", _WRAPPING_ALGORITHM)
def test_raw_master_key_decrypts_what_raw_keyring_encrypts(encryption_materials_samples, wrapping_algorithm_samples):

# Initializing attributes
key_namespace = _PROVIDER_ID
key_name = _KEY_ID
_wrapping_algorithm = wrapping_algorithm_samples

# Creating an instance of a raw AES keyring
test_raw_aes_keyring = RawAESKeyring(
key_namespace=key_namespace,
key_name=key_name,
wrapping_key=_WRAPPING_KEY,
wrapping_algorithm=_wrapping_algorithm,
)

# Creating an instance of a raw master key
test_raw_master_key = RawMasterKey(
key_id=test_raw_aes_keyring.key_name,
provider_id=test_raw_aes_keyring.key_namespace,
wrapping_key=test_raw_aes_keyring._wrapping_key_structure,
)

# Encrypt using raw AES keyring
encryption_materials = test_raw_aes_keyring.on_encrypt(encryption_materials=encryption_materials_samples)

# Check if plaintext data key encrypted by raw keyring is decrypted by raw master key

raw_mkp_decrypted_data_key = test_raw_master_key.decrypt_data_key_from_list(
encrypted_data_keys=encryption_materials._encrypted_data_keys,
algorithm=encryption_materials.algorithm,
encryption_context=encryption_materials.encryption_context,
).data_key

assert encryption_materials.data_encryption_key.data_key == raw_mkp_decrypted_data_key


@pytest.mark.parametrize("encryption_materials_samples", sample_encryption_materials())
@pytest.mark.parametrize("wrapping_algorithm_samples", _WRAPPING_ALGORITHM)
def test_raw_keyring_decrypts_what_raw_master_key_encrypts(encryption_materials_samples, wrapping_algorithm_samples):

# Initializing attributes
key_namespace = _PROVIDER_ID
key_name = _KEY_ID
_wrapping_algorithm = wrapping_algorithm_samples

# Creating an instance of a raw AES keyring
test_raw_aes_keyring = RawAESKeyring(
key_namespace=key_namespace,
key_name=key_name,
wrapping_key=_WRAPPING_KEY,
wrapping_algorithm=_wrapping_algorithm,
)

# Creating an instance of a raw master key
test_raw_master_key = RawMasterKey(
key_id=test_raw_aes_keyring.key_name,
provider_id=test_raw_aes_keyring.key_namespace,
wrapping_key=test_raw_aes_keyring._wrapping_key_structure,
)

if encryption_materials_samples.data_encryption_key is None:
return
raw_master_key_encrypted_data_key = test_raw_master_key.encrypt_data_key(
data_key=encryption_materials_samples.data_encryption_key,
algorithm=encryption_materials_samples.algorithm,
encryption_context=encryption_materials_samples.encryption_context,
)

# Check if plaintext data key encrypted by raw master key is decrypted by raw keyring

raw_aes_keyring_decrypted_data_key = test_raw_aes_keyring.on_decrypt(
decryption_materials=DecryptionMaterials(
algorithm=encryption_materials_samples.algorithm,
encryption_context=encryption_materials_samples.encryption_context,
verification_key=b"ex_verification_key",
),
encrypted_data_keys=[raw_master_key_encrypted_data_key],
).data_encryption_key.data_key

assert encryption_materials_samples.data_encryption_key.data_key == raw_aes_keyring_decrypted_data_key


@pytest.mark.parametrize("wrapping_algorithm", _WRAPPING_ALGORITHM)
def test_key_info_prefix_vectors(wrapping_algorithm):
assert (
serialize_raw_master_key_prefix(
raw_master_key=RawMasterKey(
provider_id=_PROVIDER_ID,
key_id=_KEY_ID,
wrapping_key=WrappingKey(
wrapping_algorithm=wrapping_algorithm,
wrapping_key=_WRAPPING_KEY,
wrapping_key_type=EncryptionKeyType.SYMMETRIC,
),
)
)
== _KEY_ID + b"\x00\x00\x00\x80\x00\x00\x00\x0c"
)
Loading