Skip to content
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

[Key Vault] Add new encryption algorithms for 7.2-preview #16566

Merged
merged 28 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8191ceb
Generate from latest swagger
mccoyp Feb 3, 2021
cff7cc7
Add new EncryptionAlgorithm values
mccoyp Feb 4, 2021
a4802fd
Add 7.2-preview enum value
mccoyp Feb 4, 2021
f85c322
Specify local-capable encrypt algs in crypto tests
mccoyp Feb 4, 2021
bd69135
Regenerate 7.2-preview without arm setting
mccoyp Feb 4, 2021
dc6b387
EncryptionAlgorithm and KeyWrapAlgorithm match .NET
mccoyp Feb 5, 2021
012961a
Add kwarg support for iv, tag, aad
mccoyp Feb 5, 2021
c275520
NotImplementedError -> ValueError in generated client
mccoyp Feb 5, 2021
d161861
Raise ValueError for incompatible parameters
mccoyp Feb 5, 2021
07e8191
optional arguments -> kwargs
mccoyp Feb 5, 2021
83e1f8b
wip; local crypto testing
mccoyp Feb 5, 2021
3e82b1a
Address feedback
mccoyp Feb 5, 2021
88c492a
Consolidate argument checks in helper
mccoyp Feb 5, 2021
6d63b71
Clean up argument validation
mccoyp Feb 5, 2021
cc29c95
Update async crypto client
mccoyp Feb 6, 2021
4860a26
Update tests, re-record
mccoyp Feb 6, 2021
b05acac
Share argument validation method between clients
mccoyp Feb 6, 2021
0fba28d
Record tests with URL missing trailing /
mccoyp Feb 6, 2021
79db935
Add async multiapi generated classes/update client base
mccoyp Feb 6, 2021
e7e94e7
Record tests with correct async API version
mccoyp Feb 6, 2021
cf6e9a2
Update administration recordings
mccoyp Feb 8, 2021
0f75c8d
Update async administration recordings
mccoyp Feb 9, 2021
8033832
Pop kwargs before initialization
mccoyp Feb 9, 2021
5ca469d
Add oct-HSM support
mccoyp Feb 9, 2021
2052aae
Test AES encryption and key wrapping algs
mccoyp Feb 9, 2021
553dfff
Module-level encrypt parameter validation tests
mccoyp Feb 9, 2021
741616d
Address feedback
mccoyp Feb 9, 2021
4fc96e7
bytes.fromhex -> codecs.decode
mccoyp Feb 9, 2021
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ class KeyType(str, Enum):
rsa = "RSA"
rsa_hsm = "RSA-HSM" #: RSA with a private key which is not exportable from the HSM
oct = "oct" #: Octet sequence (used to represent symmetric keys)
oct_hsm = "oct-HSM" #: Octet sequence with a private key which is not exportable from the HSM
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _validate_arguments(operation, algorithm, **kwargs):
# type: (KeyOperation, EncryptionAlgorithm, **Any) -> None
"""Validates the arguments passed to perform an operation with a provided algorithm.

:param KeyOperation operation: the type of operation being requested. Can be "encrypt" or "decrypt"
:param KeyOperation operation: the type of operation being requested
:param EncyptionAlgorithm algorithm: the encryption algorithm to use for the operation
:keyword bytes iv: initialization vector
:keyword bytes authentication_tag: authentication tag returned from an encryption
Expand All @@ -45,9 +45,9 @@ def _validate_arguments(operation, algorithm, **kwargs):
raise ValueError(
"iv should only be provided with AES-CBC algorithms; {} does not accept an iv".format(algorithm)
)
if aad and "GCM" not in algorithm:
if aad and not ("CBC" in algorithm or "GCM" in algorithm):
raise ValueError(
"additional_authenticated_data should only be provided with AES-GCM algorithms; {} does not accept an "
"additional_authenticated_data should only be provided with AES algorithms; {} does not accept an "
"aad".format(algorithm)
mccoyp marked this conversation as resolved.
Show resolved Hide resolved
)

Expand All @@ -62,9 +62,9 @@ def _validate_arguments(operation, algorithm, **kwargs):
algorithm
)
)
if aad and "GCM" not in algorithm:
if aad and not ("CBC" in algorithm or "GCM" in algorithm):
raise ValueError(
"additional_authenticated_data should only be provided with AES-GCM algorithms; {} does not accept an "
"additional_authenticated_data should only be provided with AES algorithms; {} does not accept an "
"aad".format(algorithm)
)

Expand Down Expand Up @@ -175,10 +175,10 @@ def encrypt(self, algorithm, plaintext, **kwargs):
:language: python
:dedent: 8
"""
self._initialize(**kwargs)
iv = kwargs.pop("iv", None)
aad = kwargs.pop("additional_authenticated_data", None)
_validate_arguments(operation=KeyOperation.encrypt, algorithm=algorithm, iv=iv, aad=aad)
self._initialize(**kwargs)

if self._local_provider.supports(KeyOperation.encrypt, algorithm):
raise_if_time_invalid(self._key)
Expand Down Expand Up @@ -229,11 +229,11 @@ def decrypt(self, algorithm, ciphertext, **kwargs):
:language: python
:dedent: 8
"""
self._initialize(**kwargs)
iv = kwargs.pop("iv", None)
tag = kwargs.pop("authentication_tag", None)
aad = kwargs.pop("additional_authenticated_data", None)
_validate_arguments(operation=KeyOperation.decrypt, algorithm=algorithm, iv=iv, tag=tag, aad=aad)
self._initialize(**kwargs)

if self._local_provider.supports(KeyOperation.decrypt, algorithm):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_local_cryptography_provider(key):
return EllipticCurveCryptographyProvider(key)
if key.key_type in (KeyType.rsa, KeyType.rsa_hsm):
return RsaCryptographyProvider(key)
if key.key_type == KeyType.oct:
if key.key_type in (KeyType.oct, KeyType.oct_hsm):
return SymmetricCryptographyProvider(key)

raise ValueError('Unsupported key type "{}"'.format(key.key_type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
class SymmetricCryptographyProvider(LocalCryptographyProvider):
def _get_internal_key(self, key):
# type: (KeyVaultKey) -> Key
if key.key_type != KeyType.oct:
raise ValueError('"key" must be an oct (symmetric) key')
if key.key_type not in (KeyType.oct, KeyType.oct_hsm):
raise ValueError('"key" must be an oct or oct-HSM (symmetric) key')
return SymmetricKey.from_jwk(key.key)

def supports(self, operation, algorithm):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ async def encrypt(self, algorithm: "EncryptionAlgorithm", plaintext: bytes, **kw
:language: python
:dedent: 8
"""
await self._initialize(**kwargs)
iv = kwargs.pop("iv", None)
aad = kwargs.pop("additional_authenticated_data", None)
_validate_arguments(operation=KeyOperation.encrypt, algorithm=algorithm, iv=iv, aad=aad)
await self._initialize(**kwargs)

if self._local_provider.supports(KeyOperation.encrypt, algorithm):
raise_if_time_invalid(self._key)
Expand Down Expand Up @@ -180,11 +180,11 @@ async def decrypt(self, algorithm: "EncryptionAlgorithm", ciphertext: bytes, **k
:language: python
:dedent: 8
"""
await self._initialize(**kwargs)
iv = kwargs.pop("iv", None)
tag = kwargs.pop("authentication_tag", None)
aad = kwargs.pop("additional_authenticated_data", None)
_validate_arguments(operation=KeyOperation.decrypt, algorithm=algorithm, iv=iv, tag=tag, aad=aad)
await self._initialize(**kwargs)

if self._local_provider.supports(KeyOperation.decrypt, algorithm):
try:
Expand Down

This file was deleted.

This file was deleted.

Loading