We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/storage-preview/setup.py`
Content:
```
1 #!/usr/bin/env python
2 
3 # --------------------------------------------------------------------------------------------
4 # Copyright (c) Microsoft Corporation. All rights reserved.
5 # Licensed under the MIT License. See License.txt in the project root for license information.
6 # --------------------------------------------------------------------------------------------
7 
8 from codecs import open
9 from setuptools import setup, find_packages
10 
11 VERSION = "0.7.3"
12 
13 CLASSIFIERS = [
14     'Development Status :: 4 - Beta',
15     'Intended Audience :: Developers',
16     'Intended Audience :: System Administrators',
17     'Programming Language :: Python',
18     'Programming Language :: Python :: 2',
19     'Programming Language :: Python :: 2.7',
20     'Programming Language :: Python :: 3',
21     'Programming Language :: Python :: 3.4',
22     'Programming Language :: Python :: 3.5',
23     'Programming Language :: Python :: 3.6',
24     'License :: OSI Approved :: MIT License',
25 ]
26 
27 DEPENDENCIES = ['azure-core']
28 
29 setup(
30     name='storage-preview',
31     version=VERSION,
32     description='Provides a preview for upcoming storage features.',
33     long_description='An Azure CLI Extension for storage preview features. This will replace the full storage module.',
34     license='MIT',
35     author='Microsoft Corporation',
36     author_email='azpycli@microsoft.com',
37     url='https://github.com/Azure/azure-cli-extensions/tree/master/src/storage-preview',
38     classifiers=CLASSIFIERS,
39     package_data={
40         'azext_storage_preview': ['azext_metadata.json', 'azcopy/*/*']
41     },
42     packages=find_packages(exclude=["tests"]),
43     install_requires=DEPENDENCIES
44 )
45
```

Path: `src/storage-preview/azext_storage_preview/azcopy/util.py`
Content:
```
1 # --------------------------------------------------------------------------------------------
2 # Copyright (c) Microsoft Corporation. All rights reserved.
3 # Licensed under the MIT License. See License.txt in the project root for license information.
4 # --------------------------------------------------------------------------------------------
5 
6 
7 import os
8 import json
9 import platform
10 import subprocess
11 import datetime
12 from six.moves.urllib.parse import urlparse
13 from azure.cli.core._profile import Profile
14 from knack.log import get_logger
15 
16 logger = get_logger(__name__)
17 
18 
19 STORAGE_RESOURCE_ENDPOINT = "https://storage.azure.com"
20 SERVICES = {'blob', 'file'}
21 AZCOPY_VERSION = '10.5.0'
22 
23 
24 class AzCopy(object):
25     system_executable_path = {
26         'Darwin': ['azcopy_darwin_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],
27         'Linux': ['azcopy_linux_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],
28         'Windows': ['azcopy_windows_amd64_{}'.format(AZCOPY_VERSION), 'azcopy.exe']
29     }
30 
31     def __init__(self, creds=None):
32         self.system = platform.system()
33         curr_path = os.path.dirname(os.path.realpath(__file__))
34         self.executable = os.path.join(curr_path, *AzCopy.system_executable_path[self.system])
35         self.creds = creds
36 
37     def run_command(self, args):
38         command = [self.executable] + args
39         logger.warning("Azcopy command: %s", command)
40         env_kwargs = {}
41         if self.creds and self.creds.token_info:
42             env_kwargs = {'AZCOPY_OAUTH_TOKEN_INFO': json.dumps(self.creds.token_info)}
43         subprocess.call(command, env=dict(os.environ, **env_kwargs))
44 
45     def copy(self, source, destination, flags=None):
46         flags = flags or []
47         self.run_command(['copy', source, destination] + flags)
48 
49     def remove(self, target, flags=None):
50         flags = flags or []
51         self.run_command(['remove', target] + flags)
52 
53     def sync(self, source, destination, flags=None):
54         flags = flags or []
55         self.run_command(['sync', source, destination] + flags)
56 
57 
58 class AzCopyCredentials(object):  # pylint: disable=too-few-public-methods
59     def __init__(self, sas_token=None, token_info=None):
60         self.sas_token = sas_token
61         self.token_info = token_info
62 
63 
64 def login_auth_for_azcopy(cmd):
65     token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token(resource=STORAGE_RESOURCE_ENDPOINT)[0][2]
66     try:
67         token_info = _unserialize_non_msi_token_payload(token_info)
68     except KeyError:  # unserialized MSI token payload
69         raise Exception('MSI auth not yet supported.')
70     return AzCopyCredentials(token_info=token_info)
71 
72 
73 def blob_client_auth_for_azcopy(cmd, blob_client):
74     azcopy_creds = storage_client_auth_for_azcopy(cmd, blob_client, 'blob')
75     if azcopy_creds is not None:
76         return azcopy_creds
77 
78     # oauth mode
79     token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token(resource=STORAGE_RESOURCE_ENDPOINT)[0][2]
80     try:
81         token_info = _unserialize_non_msi_token_payload(token_info)
82     except KeyError:  # unserialized MSI token payload
83         raise Exception('MSI auth not yet supported.')
84     return AzCopyCredentials(token_info=token_info)
85 
86 
87 def storage_client_auth_for_azcopy(cmd, client, service):
88     if service not in SERVICES:
89         raise Exception('{} not one of: {}'.format(service, str(SERVICES)))
90 
91     if client.sas_token:
92         return AzCopyCredentials(sas_token=client.sas_token)
93 
94     # if account key provided, generate a sas token
95     if client.account_key:
96         sas_token = _generate_sas_token(cmd, client.account_name, client.account_key, service)
97         return AzCopyCredentials(sas_token=sas_token)
98     return None
99 
100 
101 def _unserialize_non_msi_token_payload(token_info):
102     import jwt  # pylint: disable=import-error
103 
104     parsed_authority = urlparse(token_info['_authority'])
105     decode = jwt.decode(token_info['accessToken'], verify=False, algorithms=['RS256'])
106     return {
107         'access_token': token_info['accessToken'],
108         'refresh_token': token_info['refreshToken'],
109         'expires_in': str(token_info['expiresIn']),
110         'not_before': str(decode['nbf']),
111         'expires_on': str(int((datetime.datetime.strptime(
112             token_info['expiresOn'], "%Y-%m-%d %H:%M:%S.%f")).timestamp())),
113         'resource': STORAGE_RESOURCE_ENDPOINT,
114         'token_type': token_info['tokenType'],
115         '_tenant': parsed_authority.path.strip('/'),
116         '_client_id': token_info['_clientId'],
117         '_ad_endpoint': '{uri.scheme}://{uri.netloc}'.format(uri=parsed_authority)
118     }
119 
120 
121 def _generate_sas_token(cmd, account_name, account_key, service):
122     from .._client_factory import cloud_storage_account_service_factory
123     from .._validators import resource_type_type, services_type
124 
125     kwargs = {
126         'account_name': account_name,
127         'account_key': account_key
128     }
129     cloud_storage_client = cloud_storage_account_service_factory(cmd.cli_ctx, kwargs)
130     t_account_permissions = cmd.loader.get_sdk('common.models#AccountPermissions')
131 
132     return cloud_storage_client.generate_shared_access_signature(
133         services_type(cmd.loader)(service[0]),
134         resource_type_type(cmd.loader)('sco'),
135         t_account_permissions(_str='rwdlacup'),
136         datetime.datetime.utcnow() + datetime.timedelta(days=1)
137     )
138
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
     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',

{"golden_diff": "diff --git a/src/storage-preview/azext_storage_preview/azcopy/util.py b/src/storage-preview/azext_storage_preview/azcopy/util.py\n--- a/src/storage-preview/azext_storage_preview/azcopy/util.py\n+++ b/src/storage-preview/azext_storage_preview/azcopy/util.py\n@@ -102,7 +102,7 @@\n     import jwt  # pylint: disable=import-error\n \n     parsed_authority = urlparse(token_info['_authority'])\n-    decode = jwt.decode(token_info['accessToken'], verify=False, algorithms=['RS256'])\n+    decode = jwt.decode(token_info['accessToken'], algorithms=['RS256'], options={\"verify_signature\": False})\n     return {\n         'access_token': token_info['accessToken'],\n         'refresh_token': token_info['refreshToken'],\ndiff --git a/src/storage-preview/setup.py b/src/storage-preview/setup.py\n--- a/src/storage-preview/setup.py\n+++ b/src/storage-preview/setup.py\n@@ -8,7 +8,7 @@\n from codecs import open\n from setuptools import setup, find_packages\n \n-VERSION = \"0.7.3\"\n+VERSION = \"0.7.4\"\n \n CLASSIFIERS = [\n     'Development Status :: 4 - Beta',\n", "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\"\n### Extension name (the extension in question)\r\nStorage Preview, v0.7.3\r\n\r\n### Description of the issue (in as much detail as possible)\r\nstorage 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\"\r\n\r\nFrom the exception seems like the token is not encrypted in RS256 and decoding is failing?\r\n\r\n-----\r\nDetailed Log:\r\n\r\nCMD-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\r\nCMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,234 | INFO | az_command_data_logger | extension name: storage-preview\r\nCMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,234 | INFO | az_command_data_logger | extension version: 0.7.3\r\nCMD-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:\r\nCMD-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.\r\nTraceback (most recent call last):\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\jwt/algorithms.py\", line 256, in prepare_key\r\n  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\r\n  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\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\cryptography/hazmat/backends/openssl/backend.py\", line 1475, in _load_key\r\n  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\r\nValueError: Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\knack/cli.py\", line 231, in invoke\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\azure/cli/core/commands/__init__.py\", line 657, in execute\r\n  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\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\azure/cli/core/commands/__init__.py\", line 712, in _run_job\r\n  File \"C:\\Users\\someuserwhomyoudontknow\\.azure\\cliextensions\\storage-preview\\azext_storage_preview\\__init__.py\", line 252, in new_handler\r\n    handler(ex)\r\n  File \"C:\\Users\\someuserwhomyoudontknow\\.azure\\cliextensions\\storage-preview\\azext_storage_preview\\__init__.py\", line 194, in handler\r\n    raise ex\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\azure/cli/core/commands/__init__.py\", line 691, in _run_job\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\azure/cli/core/commands/__init__.py\", line 328, in __call__\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\azure/cli/core/commands/command_operation.py\", line 121, in handler\r\n  File \"C:\\Users\\someuserwhomyoudontknow\\.azure\\cliextensions\\storage-preview\\azext_storage_preview\\operations\\azcopy.py\", line 24, in storage_blob_download\r\n    azcopy = _azcopy_blob_client(cmd, client)\r\n  File \"C:\\Users\\someuserwhomyoudontknow\\.azure\\cliextensions\\storage-preview\\azext_storage_preview\\operations\\azcopy.py\", line 65, in _azcopy_blob_client\r\n    return AzCopy(creds=blob_client_auth_for_azcopy(cmd, client))\r\n  File \"C:\\Users\\someuserwhomyoudontknow\\.azure\\cliextensions\\storage-preview\\azext_storage_preview\\azcopy\\util.py\", line 81, in blob_client_auth_for_azcopy\r\n    token_info = _unserialize_non_msi_token_payload(token_info)\r\n  File \"C:\\Users\\someuserwhomyoudontknow\\.azure\\cliextensions\\storage-preview\\azext_storage_preview\\azcopy\\util.py\", line 105, in _unserialize_non_msi_token_payload\r\n    decode = jwt.decode(token_info['accessToken'], verify=False, algorithms=['RS256'])\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\jwt/api_jwt.py\", line 119, in decode\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\jwt/api_jwt.py\", line 90, in decode_complete\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\jwt/api_jws.py\", line 149, in decode_complete\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\jwt/api_jws.py\", line 233, in _verify_signature\r\n  File \"D:\\a\\1\\s\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\jwt/algorithms.py\", line 258, in prepare_key\r\n  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\r\n  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\r\n  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\r\nValueError: Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.\r\nCMD-LOG-LINE-BEGIN 5728 | 2021-07-09 16:36:25,669 | INFO | az_command_data_logger | exit code: 1\r\n\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\n# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom codecs import open\nfrom setuptools import setup, find_packages\n\nVERSION = \"0.7.3\"\n\nCLASSIFIERS = [\n    'Development Status :: 4 - Beta',\n    'Intended Audience :: Developers',\n    'Intended Audience :: System Administrators',\n    'Programming Language :: Python',\n    'Programming Language :: Python :: 2',\n    'Programming Language :: Python :: 2.7',\n    'Programming Language :: Python :: 3',\n    'Programming Language :: Python :: 3.4',\n    'Programming Language :: Python :: 3.5',\n    'Programming Language :: Python :: 3.6',\n    'License :: OSI Approved :: MIT License',\n]\n\nDEPENDENCIES = ['azure-core']\n\nsetup(\n    name='storage-preview',\n    version=VERSION,\n    description='Provides a preview for upcoming storage features.',\n    long_description='An Azure CLI Extension for storage preview features. This will replace the full storage module.',\n    license='MIT',\n    author='Microsoft Corporation',\n    author_email='azpycli@microsoft.com',\n    url='https://github.com/Azure/azure-cli-extensions/tree/master/src/storage-preview',\n    classifiers=CLASSIFIERS,\n    package_data={\n        'azext_storage_preview': ['azext_metadata.json', 'azcopy/*/*']\n    },\n    packages=find_packages(exclude=[\"tests\"]),\n    install_requires=DEPENDENCIES\n)\n", "path": "src/storage-preview/setup.py"}, {"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\n\nimport os\nimport json\nimport platform\nimport subprocess\nimport datetime\nfrom six.moves.urllib.parse import urlparse\nfrom azure.cli.core._profile import Profile\nfrom knack.log import get_logger\n\nlogger = get_logger(__name__)\n\n\nSTORAGE_RESOURCE_ENDPOINT = \"https://storage.azure.com\"\nSERVICES = {'blob', 'file'}\nAZCOPY_VERSION = '10.5.0'\n\n\nclass AzCopy(object):\n    system_executable_path = {\n        'Darwin': ['azcopy_darwin_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],\n        'Linux': ['azcopy_linux_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],\n        'Windows': ['azcopy_windows_amd64_{}'.format(AZCOPY_VERSION), 'azcopy.exe']\n    }\n\n    def __init__(self, creds=None):\n        self.system = platform.system()\n        curr_path = os.path.dirname(os.path.realpath(__file__))\n        self.executable = os.path.join(curr_path, *AzCopy.system_executable_path[self.system])\n        self.creds = creds\n\n    def run_command(self, args):\n        command = [self.executable] + args\n        logger.warning(\"Azcopy command: %s\", command)\n        env_kwargs = {}\n        if self.creds and self.creds.token_info:\n            env_kwargs = {'AZCOPY_OAUTH_TOKEN_INFO': json.dumps(self.creds.token_info)}\n        subprocess.call(command, env=dict(os.environ, **env_kwargs))\n\n    def copy(self, source, destination, flags=None):\n        flags = flags or []\n        self.run_command(['copy', source, destination] + flags)\n\n    def remove(self, target, flags=None):\n        flags = flags or []\n        self.run_command(['remove', target] + flags)\n\n    def sync(self, source, destination, flags=None):\n        flags = flags or []\n        self.run_command(['sync', source, destination] + flags)\n\n\nclass AzCopyCredentials(object):  # pylint: disable=too-few-public-methods\n    def __init__(self, sas_token=None, token_info=None):\n        self.sas_token = sas_token\n        self.token_info = token_info\n\n\ndef login_auth_for_azcopy(cmd):\n    token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token(resource=STORAGE_RESOURCE_ENDPOINT)[0][2]\n    try:\n        token_info = _unserialize_non_msi_token_payload(token_info)\n    except KeyError:  # unserialized MSI token payload\n        raise Exception('MSI auth not yet supported.')\n    return AzCopyCredentials(token_info=token_info)\n\n\ndef blob_client_auth_for_azcopy(cmd, blob_client):\n    azcopy_creds = storage_client_auth_for_azcopy(cmd, blob_client, 'blob')\n    if azcopy_creds is not None:\n        return azcopy_creds\n\n    # oauth mode\n    token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token(resource=STORAGE_RESOURCE_ENDPOINT)[0][2]\n    try:\n        token_info = _unserialize_non_msi_token_payload(token_info)\n    except KeyError:  # unserialized MSI token payload\n        raise Exception('MSI auth not yet supported.')\n    return AzCopyCredentials(token_info=token_info)\n\n\ndef storage_client_auth_for_azcopy(cmd, client, service):\n    if service not in SERVICES:\n        raise Exception('{} not one of: {}'.format(service, str(SERVICES)))\n\n    if client.sas_token:\n        return AzCopyCredentials(sas_token=client.sas_token)\n\n    # if account key provided, generate a sas token\n    if client.account_key:\n        sas_token = _generate_sas_token(cmd, client.account_name, client.account_key, service)\n        return AzCopyCredentials(sas_token=sas_token)\n    return None\n\n\ndef _unserialize_non_msi_token_payload(token_info):\n    import jwt  # pylint: disable=import-error\n\n    parsed_authority = urlparse(token_info['_authority'])\n    decode = jwt.decode(token_info['accessToken'], verify=False, algorithms=['RS256'])\n    return {\n        'access_token': token_info['accessToken'],\n        'refresh_token': token_info['refreshToken'],\n        'expires_in': str(token_info['expiresIn']),\n        'not_before': str(decode['nbf']),\n        'expires_on': str(int((datetime.datetime.strptime(\n            token_info['expiresOn'], \"%Y-%m-%d %H:%M:%S.%f\")).timestamp())),\n        'resource': STORAGE_RESOURCE_ENDPOINT,\n        'token_type': token_info['tokenType'],\n        '_tenant': parsed_authority.path.strip('/'),\n        '_client_id': token_info['_clientId'],\n        '_ad_endpoint': '{uri.scheme}://{uri.netloc}'.format(uri=parsed_authority)\n    }\n\n\ndef _generate_sas_token(cmd, account_name, account_key, service):\n    from .._client_factory import cloud_storage_account_service_factory\n    from .._validators import resource_type_type, services_type\n\n    kwargs = {\n        'account_name': account_name,\n        'account_key': account_key\n    }\n    cloud_storage_client = cloud_storage_account_service_factory(cmd.cli_ctx, kwargs)\n    t_account_permissions = cmd.loader.get_sdk('common.models#AccountPermissions')\n\n    return cloud_storage_client.generate_shared_access_signature(\n        services_type(cmd.loader)(service[0]),\n        resource_type_type(cmd.loader)('sco'),\n        t_account_permissions(_str='rwdlacup'),\n        datetime.datetime.utcnow() + datetime.timedelta(days=1)\n    )\n", "path": "src/storage-preview/azext_storage_preview/azcopy/util.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom codecs import open\nfrom setuptools import setup, find_packages\n\nVERSION = \"0.7.4\"\n\nCLASSIFIERS = [\n    'Development Status :: 4 - Beta',\n    'Intended Audience :: Developers',\n    'Intended Audience :: System Administrators',\n    'Programming Language :: Python',\n    'Programming Language :: Python :: 2',\n    'Programming Language :: Python :: 2.7',\n    'Programming Language :: Python :: 3',\n    'Programming Language :: Python :: 3.4',\n    'Programming Language :: Python :: 3.5',\n    'Programming Language :: Python :: 3.6',\n    'License :: OSI Approved :: MIT License',\n]\n\nDEPENDENCIES = ['azure-core']\n\nsetup(\n    name='storage-preview',\n    version=VERSION,\n    description='Provides a preview for upcoming storage features.',\n    long_description='An Azure CLI Extension for storage preview features. This will replace the full storage module.',\n    license='MIT',\n    author='Microsoft Corporation',\n    author_email='azpycli@microsoft.com',\n    url='https://github.com/Azure/azure-cli-extensions/tree/master/src/storage-preview',\n    classifiers=CLASSIFIERS,\n    package_data={\n        'azext_storage_preview': ['azext_metadata.json', 'azcopy/*/*']\n    },\n    packages=find_packages(exclude=[\"tests\"]),\n    install_requires=DEPENDENCIES\n)\n", "path": "src/storage-preview/setup.py"}, {"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\n\nimport os\nimport json\nimport platform\nimport subprocess\nimport datetime\nfrom six.moves.urllib.parse import urlparse\nfrom azure.cli.core._profile import Profile\nfrom knack.log import get_logger\n\nlogger = get_logger(__name__)\n\n\nSTORAGE_RESOURCE_ENDPOINT = \"https://storage.azure.com\"\nSERVICES = {'blob', 'file'}\nAZCOPY_VERSION = '10.5.0'\n\n\nclass AzCopy(object):\n    system_executable_path = {\n        'Darwin': ['azcopy_darwin_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],\n        'Linux': ['azcopy_linux_amd64_{}'.format(AZCOPY_VERSION), 'azcopy'],\n        'Windows': ['azcopy_windows_amd64_{}'.format(AZCOPY_VERSION), 'azcopy.exe']\n    }\n\n    def __init__(self, creds=None):\n        self.system = platform.system()\n        curr_path = os.path.dirname(os.path.realpath(__file__))\n        self.executable = os.path.join(curr_path, *AzCopy.system_executable_path[self.system])\n        self.creds = creds\n\n    def run_command(self, args):\n        command = [self.executable] + args\n        logger.warning(\"Azcopy command: %s\", command)\n        env_kwargs = {}\n        if self.creds and self.creds.token_info:\n            env_kwargs = {'AZCOPY_OAUTH_TOKEN_INFO': json.dumps(self.creds.token_info)}\n        subprocess.call(command, env=dict(os.environ, **env_kwargs))\n\n    def copy(self, source, destination, flags=None):\n        flags = flags or []\n        self.run_command(['copy', source, destination] + flags)\n\n    def remove(self, target, flags=None):\n        flags = flags or []\n        self.run_command(['remove', target] + flags)\n\n    def sync(self, source, destination, flags=None):\n        flags = flags or []\n        self.run_command(['sync', source, destination] + flags)\n\n\nclass AzCopyCredentials(object):  # pylint: disable=too-few-public-methods\n    def __init__(self, sas_token=None, token_info=None):\n        self.sas_token = sas_token\n        self.token_info = token_info\n\n\ndef login_auth_for_azcopy(cmd):\n    token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token(resource=STORAGE_RESOURCE_ENDPOINT)[0][2]\n    try:\n        token_info = _unserialize_non_msi_token_payload(token_info)\n    except KeyError:  # unserialized MSI token payload\n        raise Exception('MSI auth not yet supported.')\n    return AzCopyCredentials(token_info=token_info)\n\n\ndef blob_client_auth_for_azcopy(cmd, blob_client):\n    azcopy_creds = storage_client_auth_for_azcopy(cmd, blob_client, 'blob')\n    if azcopy_creds is not None:\n        return azcopy_creds\n\n    # oauth mode\n    token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token(resource=STORAGE_RESOURCE_ENDPOINT)[0][2]\n    try:\n        token_info = _unserialize_non_msi_token_payload(token_info)\n    except KeyError:  # unserialized MSI token payload\n        raise Exception('MSI auth not yet supported.')\n    return AzCopyCredentials(token_info=token_info)\n\n\ndef storage_client_auth_for_azcopy(cmd, client, service):\n    if service not in SERVICES:\n        raise Exception('{} not one of: {}'.format(service, str(SERVICES)))\n\n    if client.sas_token:\n        return AzCopyCredentials(sas_token=client.sas_token)\n\n    # if account key provided, generate a sas token\n    if client.account_key:\n        sas_token = _generate_sas_token(cmd, client.account_name, client.account_key, service)\n        return AzCopyCredentials(sas_token=sas_token)\n    return None\n\n\ndef _unserialize_non_msi_token_payload(token_info):\n    import jwt  # pylint: disable=import-error\n\n    parsed_authority = urlparse(token_info['_authority'])\n    decode = jwt.decode(token_info['accessToken'], algorithms=['RS256'], options={\"verify_signature\": False})\n    return {\n        'access_token': token_info['accessToken'],\n        'refresh_token': token_info['refreshToken'],\n        'expires_in': str(token_info['expiresIn']),\n        'not_before': str(decode['nbf']),\n        'expires_on': str(int((datetime.datetime.strptime(\n            token_info['expiresOn'], \"%Y-%m-%d %H:%M:%S.%f\")).timestamp())),\n        'resource': STORAGE_RESOURCE_ENDPOINT,\n        'token_type': token_info['tokenType'],\n        '_tenant': parsed_authority.path.strip('/'),\n        '_client_id': token_info['_clientId'],\n        '_ad_endpoint': '{uri.scheme}://{uri.netloc}'.format(uri=parsed_authority)\n    }\n\n\ndef _generate_sas_token(cmd, account_name, account_key, service):\n    from .._client_factory import cloud_storage_account_service_factory\n    from .._validators import resource_type_type, services_type\n\n    kwargs = {\n        'account_name': account_name,\n        'account_key': account_key\n    }\n    cloud_storage_client = cloud_storage_account_service_factory(cmd.cli_ctx, kwargs)\n    t_account_permissions = cmd.loader.get_sdk('common.models#AccountPermissions')\n\n    return cloud_storage_client.generate_shared_access_signature(\n        services_type(cmd.loader)(service[0]),\n        resource_type_type(cmd.loader)('sco'),\n        t_account_permissions(_str='rwdlacup'),\n        datetime.datetime.utcnow() + datetime.timedelta(days=1)\n    )\n", "path": "src/storage-preview/azext_storage_preview/azcopy/util.py"}]}