Skip to content

Commit

Permalink
Added x-amz-checksum-sha256 header for Object Lock support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisPPLIN committed Aug 22, 2024
1 parent 22949ba commit d9bae67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions S3/Crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,11 @@ def calculateChecksum(buffer, mfile, offset, chunk_size, send_chunk):

return md5_hash.hexdigest()
__all__.append("calculateChecksum")

def sha256_hash_to_base64(sha256_hash):
# Extract digest from sha256 hash
sha256_hash_digest = sha256_hash.digest()
# Then convert it to base64
sha256_hash_digest_b64 = base64.b64encode(sha256_hash_digest).decode()
return sha256_hash_digest_b64
__all__.append("sha256_hash_to_base64")
7 changes: 6 additions & 1 deletion S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from .ConnMan import ConnMan
from .Crypto import (sign_request_v2, sign_request_v4, checksum_sha256_file,
checksum_sha256_buffer, generate_content_md5,
hash_file_md5, calculateChecksum, format_param_str)
hash_file_md5, calculateChecksum, format_param_str, sha256_hash_to_base64)

try:
from ctypes import ArgumentError
Expand Down Expand Up @@ -1848,6 +1848,11 @@ def send_file(self, request, stream, labels, buffer = '', throttle = 0,
sha256_hash = checksum_sha256_file(stream, offset, size_total)
request.body = sha256_hash

# Provide the checksum with the request. This is important for buckets that have
# Object Lock enabled.

headers['x-amz-checksum-sha256'] = sha256_hash_to_base64(sha256_hash)

if use_expect_continue:
if not size_total:
use_expect_continue = False
Expand Down

0 comments on commit d9bae67

Please sign in to comment.