Repository: Azure/azure-cli-extensions

Issue:
storage blob directory download throwing exception "Could not deserialize key data. The data may be in an incorrect format, or it may be encrypted with an unsupported algorithm"
### Extension name (the extension in question)
Storage Preview, v0.7.3

### Description of the issue (in as much detail as possible)
storage blob directory download throwing exception "Could not deserialize key data. The data may be in an incorrect format, or it may be encrypted with an unsupported algorithm"

From the exception seems like the token is not encrypted in RS256 and decoding is failing?

-----
Detailed Log:

CMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:24,677 | INFO | az_command_data_logger | command args: storage blob directory download -d {} -s {} -c {} --account-name {} --auth-mode {} --recursive -o {} --debug
CMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,234 | INFO | az_command_data_logger | extension name: storage-preview
CMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,234 | INFO | az_command_data_logger | extension version: 0.7.3
CMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,662 | ERROR | az_command_data_logger | The command failed with an unexpected error. Here is the traceback:
CMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,667 | ERROR | az_command_data_logger | Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\jwt/algorithms.py", line 256, in prepare_key
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/primitives/serialization/base.py", line 18, in load_pem_private_key
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/backends/openssl/backend.py", line 1244, in load_pem_private_key
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/backends/openssl/backend.py", line 1475, in _load_key
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/backends/openssl/backend.py", line 1517, in _handle_key_loading_error
ValueError: Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 657, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 712, in _run_job
  File "C:\Users\someuserwhomyoudontknow\.azure\cliextensions\storage-preview\azext_storage_preview\__init__.py", line 252, in new_handler
    handler(ex)
  File "C:\Users\someuserwhomyoudontknow\.azure\cliextensions\storage-preview\azext_storage_preview\__init__.py", line 194, in handler
    raise ex
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 691, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 328, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "C:\Users\someuserwhomyoudontknow\.azure\cliextensions\storage-preview\azext_storage_preview\operations\azcopy.py", line 24, in storage_blob_download
    azcopy = _azcopy_blob_client(cmd, client)
  File "C:\Users\someuserwhomyoudontknow\.azure\cliextensions\storage-preview\azext_storage_preview\operations\azcopy.py", line 65, in _azcopy_blob_client
    return AzCopy(creds=blob_client_auth_for_azcopy(cmd, client))
  File "C:\Users\someuserwhomyoudontknow\.azure\cliextensions\storage-preview\azext_storage_preview\azcopy\util.py", line 81, in blob_client_auth_for_azcopy
    token_info = _unserialize_non_msi_token_payload(token_info)
  File "C:\Users\someuserwhomyoudontknow\.azure\cliextensions\storage-preview\azext_storage_preview\azcopy\util.py", line 105, in _unserialize_non_msi_token_payload
    decode = jwt.decode(token_info['accessToken'], verify=False, algorithms=['RS256'])
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\jwt/api_jwt.py", line 119, in decode
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\jwt/api_jwt.py", line 90, in decode_complete
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\jwt/api_jws.py", line 149, in decode_complete
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\jwt/api_jws.py", line 233, in _verify_signature
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\jwt/algorithms.py", line 258, in prepare_key
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/primitives/serialization/base.py", line 23, in load_pem_public_key
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/backends/openssl/backend.py", line 1274, in load_pem_public_key
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\cryptography/hazmat/backends/openssl/backend.py", line 1517, in _handle_key_loading_error
ValueError: Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.
CMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,669 | INFO | az_command_data_logger | exit code: 1




Discussion:
storage

Resolving patch:
diff --git a/src/storage-preview/azext_storage_preview/azcopy/util.py b/src/storage-preview/azext_storage_preview/azcopy/util.py
--- a/src/storage-preview/azext_storage_preview/azcopy/util.py
+++ b/src/storage-preview/azext_storage_preview/azcopy/util.py
@@ -102,7 +102,7 @@ def _unserialize_non_msi_token_payload(token_info):
     import jwt  # pylint: disable=import-error
 
     parsed_authority = urlparse(token_info['_authority'])
-    decode = jwt.decode(token_info['accessToken'], verify=False, algorithms=['RS256'])
+    decode = jwt.decode(token_info['accessToken'], algorithms=['RS256'], options={"verify_signature": False})
     return {
         'access_token': token_info['accessToken'],
         'refresh_token': token_info['refreshToken'],
diff --git a/src/storage-preview/setup.py b/src/storage-preview/setup.py
--- a/src/storage-preview/setup.py
+++ b/src/storage-preview/setup.py
@@ -8,7 +8,7 @@
 from codecs import open
 from setuptools import setup, find_packages
 
-VERSION = "0.7.3"
+VERSION = "0.7.4"
 
 CLASSIFIERS = [
     'Development Status :: 4 - Beta',


Test patch: