From 635fe92e11e5f9c62f7164e85820cbb6ecbd21c5 Mon Sep 17 00:00:00 2001 From: xiafu Date: Sun, 13 Dec 2020 23:02:57 -0800 Subject: [PATCH] [Storage]Avoid incorrect padding Error when base64 decode account key --- .../azure/storage/blob/_shared/authentication.py | 3 ++- .../azure/storage/filedatalake/_shared/authentication.py | 3 ++- .../azure/storage/fileshare/_shared/authentication.py | 3 ++- .../azure/storage/queue/_shared/authentication.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/authentication.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/authentication.py index d04c1e4fb539..c78bcbb4de45 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/authentication.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared/authentication.py @@ -115,7 +115,8 @@ def _get_canonicalized_resource_query(request): def _add_authorization_header(self, request, string_to_sign): try: - signature = sign_string(self.account_key, string_to_sign) + padding = '=' * (4 - len(self.account_key) % 4) + signature = sign_string(self.account_key + padding, string_to_sign) auth_string = 'SharedKey ' + self.account_name + ':' + signature request.http_request.headers['Authorization'] = auth_string except Exception as ex: diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/authentication.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/authentication.py index d04c1e4fb539..c78bcbb4de45 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/authentication.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/authentication.py @@ -115,7 +115,8 @@ def _get_canonicalized_resource_query(request): def _add_authorization_header(self, request, string_to_sign): try: - signature = sign_string(self.account_key, string_to_sign) + padding = '=' * (4 - len(self.account_key) % 4) + signature = sign_string(self.account_key + padding, string_to_sign) auth_string = 'SharedKey ' + self.account_name + ':' + signature request.http_request.headers['Authorization'] = auth_string except Exception as ex: diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/authentication.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/authentication.py index d04c1e4fb539..c78bcbb4de45 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/authentication.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/authentication.py @@ -115,7 +115,8 @@ def _get_canonicalized_resource_query(request): def _add_authorization_header(self, request, string_to_sign): try: - signature = sign_string(self.account_key, string_to_sign) + padding = '=' * (4 - len(self.account_key) % 4) + signature = sign_string(self.account_key + padding, string_to_sign) auth_string = 'SharedKey ' + self.account_name + ':' + signature request.http_request.headers['Authorization'] = auth_string except Exception as ex: diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py index d04c1e4fb539..c78bcbb4de45 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared/authentication.py @@ -115,7 +115,8 @@ def _get_canonicalized_resource_query(request): def _add_authorization_header(self, request, string_to_sign): try: - signature = sign_string(self.account_key, string_to_sign) + padding = '=' * (4 - len(self.account_key) % 4) + signature = sign_string(self.account_key + padding, string_to_sign) auth_string = 'SharedKey ' + self.account_name + ':' + signature request.http_request.headers['Authorization'] = auth_string except Exception as ex: