Skip to content

Commit ccf94cb

Browse files
committed
Add ability to handle sse-c with add-header
This will suppress md5-sum checks for sse-c uploaded and downloaded files. And use extra-headers also for get requests to download sse-c enrypted files again.
1 parent bd7b87f commit ccf94cb

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

S3/S3.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,13 @@ def object_put(self, filename, uri, extra_headers = None, extra_label = ""):
706706
response = self.send_file(request, src_stream, labels)
707707
return response
708708

709-
def object_get(self, uri, stream, dest_name, start_position = 0, extra_label = ""):
709+
def object_get(self, uri, stream, dest_name, start_position = 0, extra_headers = None, extra_label = ""):
710+
headers = SortedDict(ignore_case = True)
711+
if extra_headers:
712+
headers.update(extra_headers)
710713
if uri.type != "s3":
711714
raise ValueError("Expected URI type 's3', got '%s'" % uri.type)
712-
request = self.create_request("OBJECT_GET", uri = uri)
715+
request = self.create_request("OBJECT_GET", uri = uri, headers = headers)
713716
labels = { 'source' : uri.uri(), 'destination' : dest_name, 'extra' : extra_label }
714717
response = self.recv_file(request, stream, labels, start_position)
715718
return response
@@ -1583,7 +1586,10 @@ def send_file(self, request, stream, labels, buffer = '', throttle = 0,
15831586
debug("MD5 sums: computed=%s, received=%s" % (md5_computed, response["headers"].get('etag', '').strip('"\'')))
15841587
## when using KMS encryption, MD5 etag value will not match
15851588
md5_from_s3 = response["headers"].get("etag", "").strip('"\'')
1586-
if ('-' not in md5_from_s3) and (md5_from_s3 != md5_hash.hexdigest()) and response["headers"].get("x-amz-server-side-encryption") != 'aws:kms':
1589+
if (('-' not in md5_from_s3) and
1590+
(md5_from_s3 != md5_hash.hexdigest()) and
1591+
response["headers"].get("x-amz-server-side-encryption") != 'aws:kms' and
1592+
response["headers"].get("x-amz-server-side​-encryption​-customer-key-md5") == ""):
15871593
warning("MD5 Sums don't match!")
15881594
if retries:
15891595
warning("Retrying upload of %s" % (filename))
@@ -1821,7 +1827,9 @@ def recv_file(self, request, stream, labels, start_position = 0, retries = _max_
18211827
start_position + int(response["headers"]["content-length"]), response["size"]))
18221828
debug("ReceiveFile: Computed MD5 = %s" % response.get("md5"))
18231829
# avoid ETags from multipart uploads that aren't the real md5
1824-
if ('-' not in md5_from_s3 and not response["md5match"]) and (response["headers"].get("x-amz-server-side-encryption") != 'aws:kms'):
1830+
if (('-' not in md5_from_s3 and not response["md5match"]) and
1831+
response["headers"].get("x-amz-server-side-encryption") != 'aws:kms' and
1832+
response["headers"].get("x-amz-server-side​-encryption​-customer-key-md5") == ""):
18251833
warning("MD5 signatures do not match: computed=%s, received=%s" % (
18261834
response.get("md5"), md5_from_s3))
18271835
return response

s3cmd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ def cmd_object_get(args):
548548
warning(u"Exiting now because of --dry-run")
549549
return EX_OK
550550

551+
extra_headers = copy(cfg.extra_headers)
552+
551553
seq = 0
552554
ret = EX_OK
553555
for key in remote_list:
@@ -599,7 +601,10 @@ def cmd_object_get(args):
599601
continue
600602
try:
601603
try:
602-
response = s3.object_get(uri, dst_stream, destination, start_position = start_position, extra_label = seq_label)
604+
response = s3.object_get(uri, dst_stream, destination,
605+
start_position=start_position,
606+
extra_headers=extra_headers,
607+
extra_label=seq_label)
603608
finally:
604609
dst_stream.close()
605610
except S3DownloadError as e:

0 commit comments

Comments
 (0)