Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.56k stars 2.79k forks source link

Unexpected Exception in CryptographyClient #15608

Closed bcaradec closed 3 years ago

bcaradec commented 3 years ago

Describe the bug After instantiating an azure.keyvault.keys.crypto.CryptographyClient object using a key as URL of a Key Vault Key, the call to wrap_key() conducts to the following exception:

File "/home/bcaradec/.virtualenvs/b-id_386_env/lib/python3.8/site-packages/azure/core/tracing/decorator.py", line 83, in wrapper_use_tracer return func(args, kwargs) File "/home/bcaradec/.virtualenvs/b-id_386_env/lib/python3.8/site-packages/azure/keyvault/keys/crypto/_client.py", line 196, in wrap_key self._initialize(kwargs) File "/home/bcaradec/.virtualenvs/b-id_386_env/lib/python3.8/site-packages/azure/core/tracing/decorator.py", line 83, in wrapper_use_tracer return func(args, kwargs) File "/home/bcaradec/.virtualenvs/b-id_386_env/lib/python3.8/site-packages/azure/keyvault/keys/crypto/_client.py", line 100, in _initialize self._local_provider = get_local_cryptography_provider(self._key) File "/home/bcaradec/.virtualenvs/b-id_386_env/lib/python3.8/site-packages/azure/keyvault/keys/crypto/_providers/init.py", line 19, in get_local_cryptography_provider if key.key_type in (KeyType.ec, KeyType.ec_hsm): AttributeError: 'KeyBundle' object has no attribute 'key_type'**

To Reproduce Steps to reproduce the behavior: my_crypto_client=CryptographyClient(key="https://mykv.vault.azure.net/keys/mykeyname/myversionnr

", credential=DefaultAzureCredential( exclude_visual_studio_code_credential=True, exclude_interactive_browser_credential=True, logging_enable=True, ))

my_CustomerProvidedEncryptionKey = CpkGenerator.random_cpk() #code generating a CPK

wrap_result = my_crypto_client.wrap_key(algorithm = KeyWrapAlgorithm.rsa_oaep,
                key = base64.b64decode(my_CustomerProvidedEncryptionKey.key_value),)

Expected behavior Succesful wrapping

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

chlowell commented 3 years ago

Thank you for opening this issue! I have a fix and am working on a patch release. In the meantime, I think the best workaround is to use the prior version (4.2.0). The only new feature in 4.3.0 is that CryptographyClient can decrypt and sign locally.

chlowell commented 3 years ago

azure-keyvault-keys 4.3.1 is available now with a fix for this. Thanks again for opening this issue. Please open another if you encounter other problems, and feel free to reopen this issue if you see this error again with version 4.3.1.

bcaradec commented 3 years ago

Thanks Charles for the quick fix, much appreciated! Fix has been successfully tested. Greatings from Germany Bertrand