From 87c7fb3e01c6770e1112ec83fd9984c6a031989a Mon Sep 17 00:00:00 2001 From: Jiri Suchan Date: Tue, 26 Sep 2023 22:15:49 +0200 Subject: [PATCH 1/5] fix missing file_info.sse_c_key_id for large file --- b2sdk/raw_api.py | 3 +++ test/integration/test_upload.py | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/b2sdk/raw_api.py b/b2sdk/raw_api.py index 5f2202f36..ee9cd6c98 100644 --- a/b2sdk/raw_api.py +++ b/b2sdk/raw_api.py @@ -758,6 +758,9 @@ def start_large_file( ) kwargs['serverSideEncryption'] = server_side_encryption.serialize_to_json_for_request() + if server_side_encryption.mode == EncryptionMode.SSE_C: + file_info = server_side_encryption.add_key_id_to_file_info(file_info) + if legal_hold is not None: kwargs['legalHold'] = legal_hold.to_server() diff --git a/test/integration/test_upload.py b/test/integration/test_upload.py index 479047e49..d9ae6a5c3 100644 --- a/test/integration/test_upload.py +++ b/test/integration/test_upload.py @@ -11,8 +11,13 @@ import io +from b2sdk.b2http import B2Http +from b2sdk.encryption.setting import EncryptionSetting, EncryptionKey +from b2sdk.encryption.types import EncryptionMode, EncryptionAlgorithm +from b2sdk.v2 import B2RawHTTPApi from .base import IntegrationTestBase from .fixtures import b2_auth_data # noqa +from .test_raw_api import authorize_raw_api class TestUnboundStreamUpload(IntegrationTestBase): @@ -38,3 +43,38 @@ def test_streamed_large_buffer_small_part_size(self): data = b'a large data content' * 512 * 1024 # 5mb, the smallest allowed part size self.assert_data_uploaded_via_stream(data, part_size=5 * 1024 * 1024) + + +class TestUploadLargeFile(IntegrationTestBase): + def test_ssec_key_id(self): + sse_c = EncryptionSetting( + mode=EncryptionMode.SSE_C, + algorithm=EncryptionAlgorithm.AES256, + key=EncryptionKey(secret=b'********************************', key_id='some-id'), + ) + + raw_api = B2RawHTTPApi(B2Http()) + + auth_dict = authorize_raw_api(raw_api) + account_auth_token = auth_dict['authorizationToken'] + api_url = auth_dict['apiUrl'] + bucket = self.create_bucket() + + large_info = raw_api.start_large_file( + api_url, + account_auth_token, + bucket.id_, + 'test_largefile_sse_c.txt', + 'text/plain', + None, + server_side_encryption=sse_c, + ) + + assert large_info['fileInfo'] == { + 'sse_c_key_id': sse_c.key.key_id, + } + assert large_info['serverSideEncryption'] == { + 'algorithm': 'AES256', + 'customerKeyMd5': 'SaaDheEjzuynJH8eW6AEpQ==', + 'mode': 'SSE-C', + } From 6c410f3502e824b5ed145a9ea6f22aa52be81d6b Mon Sep 17 00:00:00 2001 From: Jiri Suchan Date: Tue, 26 Sep 2023 22:21:03 +0200 Subject: [PATCH 2/5] fix error message concating when unauthorized.message is None --- b2sdk/session.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/b2sdk/session.py b/b2sdk/session.py index 09fc23e17..95bb790a0 100644 --- a/b2sdk/session.py +++ b/b2sdk/session.py @@ -508,9 +508,7 @@ def _add_app_key_info_to_unauthorized(self, unauthorized): key_messages.append('with no restrictions') # Make a new message - new_message = unauthorized.message - if new_message == '': - new_message = 'unauthorized' + new_message = unauthorized.message or 'unauthorized' new_message += ' for application key ' + ', '.join(key_messages) return Unauthorized(new_message, unauthorized.code) From bece804fde80d9d4a106d32af6a3e7a2dd22a863 Mon Sep 17 00:00:00 2001 From: Jiri Suchan Date: Tue, 26 Sep 2023 22:30:31 +0200 Subject: [PATCH 3/5] fix lint --- test/integration/test_upload.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/integration/test_upload.py b/test/integration/test_upload.py index d9ae6a5c3..3bd8621e4 100644 --- a/test/integration/test_upload.py +++ b/test/integration/test_upload.py @@ -12,9 +12,10 @@ import io from b2sdk.b2http import B2Http -from b2sdk.encryption.setting import EncryptionSetting, EncryptionKey -from b2sdk.encryption.types import EncryptionMode, EncryptionAlgorithm +from b2sdk.encryption.setting import EncryptionKey, EncryptionSetting +from b2sdk.encryption.types import EncryptionAlgorithm, EncryptionMode from b2sdk.v2 import B2RawHTTPApi + from .base import IntegrationTestBase from .fixtures import b2_auth_data # noqa from .test_raw_api import authorize_raw_api From 5c0dee08572cb325f3d88ad79964641a1a556437 Mon Sep 17 00:00:00 2001 From: Jiri Suchan Date: Tue, 26 Sep 2023 22:34:36 +0200 Subject: [PATCH 4/5] add changelog notes --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33683196e..f9ae687c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +* Fix missing key ID for large file encrypted with SSE-C +* Fix concatenating error message when message is None + ## [1.24.0] - 2023-08-31 From 0fe4f5914f995baffd9e52dfa26ef12eb3e28fb2 Mon Sep 17 00:00:00 2001 From: Jiri Suchan Date: Tue, 26 Sep 2023 22:38:53 +0200 Subject: [PATCH 5/5] fix changelog format --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9ae687c9..392a11e32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + ### Fixed * Fix missing key ID for large file encrypted with SSE-C * Fix concatenating error message when message is None