From 5a5d5eee29cc7e7551a53ab25d3e3cc15528940f Mon Sep 17 00:00:00 2001
From: Pavel Pogodaev
Date: Fri, 15 Nov 2024 13:20:18 +0300
Subject: [PATCH] [#543] Add md5 sse-c S3Tests compatability
Signed-off-by: Pavel Pogodaev
---
api/handler/multipart_upload_test.go | 4 ++++
api/layer/multipart_upload.go | 14 +++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/api/handler/multipart_upload_test.go b/api/handler/multipart_upload_test.go
index 2831b3e..38f0e56 100644
--- a/api/handler/multipart_upload_test.go
+++ b/api/handler/multipart_upload_test.go
@@ -382,6 +382,10 @@ func TestMultipartUploadSize(t *testing.T) {
attr := getObjectAttributes(hc, newBucket, newObjName, objectParts)
require.Equal(t, 1, attr.ObjectParts.PartsCount)
require.Equal(t, srcObjInfo.Headers[layer.AttributeDecryptedSize], strconv.Itoa(attr.ObjectParts.Parts[0].Size))
+
+ result := listVersions(t, hc, bktName)
+ require.Len(t, result.Version, 1)
+ require.EqualValues(t, objLen, result.Version[0].Size)
})
}
diff --git a/api/layer/multipart_upload.go b/api/layer/multipart_upload.go
index ed7612c..f0e78b4 100644
--- a/api/layer/multipart_upload.go
+++ b/api/layer/multipart_upload.go
@@ -224,8 +224,12 @@ func (n *Layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
}
decSize := p.Size
+ md5Hash := md5.New()
if p.Info.Encryption.Enabled() {
- r, encSize, err := encryptionReader(p.Reader, p.Size, p.Info.Encryption.Key())
+ rr := wrapReader(p.Reader, 64*1024, func(buf []byte) {
+ md5Hash.Write(buf)
+ })
+ r, encSize, err := encryptionReader(rr, p.Size, p.Info.Encryption.Key())
if err != nil {
return nil, fmt.Errorf("failed to create ecnrypted reader: %w", err)
}
@@ -246,7 +250,12 @@ func (n *Layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
if err != nil {
return nil, apierr.GetAPIError(apierr.ErrInvalidDigest)
}
- if hex.EncodeToString(hashBytes) != hex.EncodeToString(createdObj.MD5Sum) {
+
+ match := hex.EncodeToString(hashBytes) == hex.EncodeToString(createdObj.MD5Sum)
+ if p.Info.Encryption.Enabled() {
+ match = hex.EncodeToString(hashBytes) == hex.EncodeToString(md5Hash.Sum(nil))
+ }
+ if !match {
prm := frostfs.PrmObjectDelete{
Object: createdObj.ID,
Container: bktInfo.CID,
@@ -449,7 +458,6 @@ func (n *Layer) CompleteMultipartUpload(ctx context.Context, p *CompleteMultipar
initMetadata[AttributeHMACKey] = encInfo.HMACKey
initMetadata[AttributeHMACSalt] = encInfo.HMACSalt
initMetadata[AttributeDecryptedSize] = strconv.FormatUint(multipartObjetSize, 10)
- multipartObjetSize = encMultipartObjectSize
}
partsData, err := json.Marshal(parts)