You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by da...@apache.org on 2023/06/26 15:39:10 UTC

[jackrabbit-oak] branch OAK-10093 created (now 9a19284522)

This is an automated email from the ASF dual-hosted git repository.

daim pushed a change to branch OAK-10093
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


      at 9a19284522 Merge pull request #960 from apache/OAK-10093

This branch includes the following new commits:

     new 9a19284522 Merge pull request #960 from apache/OAK-10093

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[jackrabbit-oak] 01/01: Merge pull request #960 from apache/OAK-10093

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

daim pushed a commit to branch OAK-10093
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 9a19284522e65c4c1b73dcfcd8e7db74f15cb982
Author: Rishabh Kumar <ri...@gmail.com>
AuthorDate: Mon Jun 26 20:53:53 2023 +0530

    Merge pull request #960 from apache/OAK-10093
    
    OAK-10093 : provided support for SSE Customer Keys for AWS
---
 .../jackrabbit/oak/blob/cloud/s3/S3Backend.java    | 41 +++++------
 .../jackrabbit/oak/blob/cloud/s3/S3Constants.java  | 12 +++
 .../oak/blob/cloud/s3/S3RequestDecorator.java      | 86 +++++++++++++++++++---
 .../blob/cloud/s3/TestS3DSWithSSECustomerKey.java  | 54 ++++++++++++++
 .../jackrabbit/oak/blob/cloud/s3/TestS3Ds.java     | 63 ++++++++++++----
 oak-blob-cloud/src/test/resources/aws.properties   |  4 +
 .../site/markdown/features/direct-binary-access.md |  2 +
 7 files changed, 213 insertions(+), 49 deletions(-)

diff --git a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java
index 0da9adf9cc..7db96e16da 100644
--- a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java
+++ b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java
@@ -39,6 +39,8 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import com.amazonaws.services.s3.model.GetObjectMetadataRequest;
+import com.amazonaws.services.s3.model.GetObjectRequest;
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataRecord;
@@ -325,7 +327,7 @@ public class S3Backend extends AbstractSharedBackend {
                 getClass().getClassLoader());
             // check if the same record already exists
             try {
-                objectMetaData = s3service.getObjectMetadata(bucket, key);
+                objectMetaData = s3service.getObjectMetadata(s3ReqDecorator.decorate(new GetObjectMetadataRequest(bucket, key)));
             } catch (AmazonServiceException ase) {
                 if (!(ase.getStatusCode() == 404 || ase.getStatusCode() == 403)) {
                     throw ase;
@@ -386,8 +388,7 @@ public class S3Backend extends AbstractSharedBackend {
         ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
         try {
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-            ObjectMetadata objectMetaData = s3service.getObjectMetadata(bucket,
-                key);
+            ObjectMetadata objectMetaData = s3service.getObjectMetadata(s3ReqDecorator.decorate(new GetObjectMetadataRequest(bucket, key)));
             if (objectMetaData != null) {
                 LOG.trace("exists [{}]: [true] took [{}] ms.",
                     identifier, (System.currentTimeMillis() - start) );
@@ -552,7 +553,7 @@ public class S3Backend extends AbstractSharedBackend {
                 getClass().getClassLoader());
             ObjectMetadata meta = s3service.getObjectMetadata(bucket, addMetaKeyPrefix(name));
             return new S3DataRecord(this, s3service, bucket, new DataIdentifier(name),
-                meta.getLastModified().getTime(), meta.getContentLength(), true);
+                meta.getLastModified().getTime(), meta.getContentLength(), true, s3ReqDecorator);
         } catch(Exception e) {
             LOG.error("Error getting metadata record for {}", name, e);
         }
@@ -579,7 +580,7 @@ public class S3Backend extends AbstractSharedBackend {
             for (final S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
                 metadataList.add(new S3DataRecord(this, s3service, bucket,
                     new DataIdentifier(stripMetaKeyPrefix(s3ObjSumm.getKey())),
-                    s3ObjSumm.getLastModified().getTime(), s3ObjSumm.getSize(), true));
+                    s3ObjSumm.getLastModified().getTime(), s3ObjSumm.getSize(), true, s3ReqDecorator));
             }
         } finally {
             if (contextClassLoader != null) {
@@ -643,7 +644,7 @@ public class S3Backend extends AbstractSharedBackend {
                 public DataRecord apply(S3ObjectSummary input) {
                     return new S3DataRecord(backend, s3service, bucket,
                         new DataIdentifier(getIdentifierName(input.getKey())),
-                        input.getLastModified().getTime(), input.getSize());
+                        input.getLastModified().getTime(), input.getSize(), s3ReqDecorator);
                 }
             });
     }
@@ -656,9 +657,9 @@ public class S3Backend extends AbstractSharedBackend {
         try {
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
 
-            ObjectMetadata object = s3service.getObjectMetadata(bucket, key);
+            ObjectMetadata object = s3service.getObjectMetadata(s3ReqDecorator.decorate(new GetObjectMetadataRequest(bucket, key)));
             S3DataRecord record = new S3DataRecord(this, s3service, bucket, identifier,
-                object.getLastModified().getTime(), object.getContentLength());
+                object.getLastModified().getTime(), object.getContentLength(), s3ReqDecorator);
             LOG.debug("Identifier [{}]'s getRecord = [{}] took [{}]ms.",
                 identifier, record, (System.currentTimeMillis() - start));
 
@@ -991,7 +992,8 @@ public class S3Backend extends AbstractSharedBackend {
                         bucket,
                         blobId,
                         lastModified.getTime(),
-                        size
+                        size,
+                        s3ReqDecorator
                 );
             }
             else {
@@ -1023,13 +1025,9 @@ public class S3Backend extends AbstractSharedBackend {
             final Date expiration = new Date();
             expiration.setTime(expiration.getTime() + expirySeconds * 1000);
 
-            GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, key)
+            GeneratePresignedUrlRequest request = s3ReqDecorator.decorate(new GeneratePresignedUrlRequest(bucket, key)
                     .withMethod(method)
-                    .withExpiration(expiration);
-
-            if (method != HttpMethod.GET) {
-               request = s3ReqDecorator.decorate(request);
-            }
+                    .withExpiration(expiration));
 
             for (Map.Entry<String, String> e : reqParams.entrySet()) {
                 request.addRequestParameter(e.getKey(), e.getValue());
@@ -1166,22 +1164,22 @@ public class S3Backend extends AbstractSharedBackend {
         private long lastModified;
         private String bucket;
         private boolean isMeta;
+        private final S3RequestDecorator s3ReqDecorator;
 
         public S3DataRecord(AbstractSharedBackend backend, AmazonS3Client s3service, String bucket,
-            DataIdentifier key, long lastModified,
-            long length) {
-            this(backend, s3service, bucket, key, lastModified, length, false);
+            DataIdentifier key, long lastModified, long length, final S3RequestDecorator s3ReqDecorator) {
+            this(backend, s3service, bucket, key, lastModified, length, false, s3ReqDecorator);
         }
 
         public S3DataRecord(AbstractSharedBackend backend, AmazonS3Client s3service, String bucket,
-            DataIdentifier key, long lastModified,
-            long length, boolean isMeta) {
+            DataIdentifier key, long lastModified, long length, boolean isMeta, final S3RequestDecorator s3ReqDecorator) {
             super(backend, key);
             this.s3service = s3service;
             this.lastModified = lastModified;
             this.length = length;
             this.bucket = bucket;
             this.isMeta = isMeta;
+            this.s3ReqDecorator = s3ReqDecorator;
         }
 
         @Override
@@ -1194,6 +1192,7 @@ public class S3Backend extends AbstractSharedBackend {
             String id = getKeyName(getIdentifier());
             if (isMeta) {
                 id = addMetaKeyPrefix(getIdentifier().toString());
+                return s3service.getObject(bucket, id).getObjectContent();
             }
             else {
                 // Don't worry about stream logging for metadata records
@@ -1202,7 +1201,7 @@ public class S3Backend extends AbstractSharedBackend {
                     LOG_STREAMS_DOWNLOAD.debug("Binary downloaded from S3 - identifier={}", id, new Exception());
                 }
             }
-            return s3service.getObject(bucket, id).getObjectContent();
+            return s3service.getObject(s3ReqDecorator.decorate(new GetObjectRequest(bucket, id))).getObjectContent();
         }
 
         @Override
diff --git a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Constants.java b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Constants.java
index e8ed6f00b0..3852e35b2f 100644
--- a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Constants.java
+++ b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Constants.java
@@ -107,11 +107,23 @@ public final class S3Constants {
      */
     public static final String S3_ENCRYPTION_SSE_KMS = "SSE_KMS";
 
+    /**
+     *  Constant to set SSE_C encryption.
+     */
+    public static final String S3_ENCRYPTION_SSE_C = "SSE_C";
+
     /**
      *  Constant to set keyID for SSE_KMS encryption.
      */
     public static final String S3_SSE_KMS_KEYID = "kmsKeyId";
 
+    /**
+     *  Constant to set base64 encoded key for SSE_C encryption.
+     */
+    // please use  'openssl rand -base64 -out ssec.key 32' command to
+    // generate base64 encoded 32 bytes string customer key for SSE_C
+    public static final String S3_SSE_C_KEY = "sseCustomerKey";
+
     /**
      *  Constant to set S3 signature for SSE_KMS encryption.
      */
diff --git a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3RequestDecorator.java b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3RequestDecorator.java
index 3d136795c5..a99e8b67ef 100644
--- a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3RequestDecorator.java
+++ b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3RequestDecorator.java
@@ -17,16 +17,28 @@
 
 package org.apache.jackrabbit.oak.blob.cloud.s3;
 
-import java.util.Properties;
-
 import com.amazonaws.services.s3.model.CopyObjectRequest;
 import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
+import com.amazonaws.services.s3.model.GetObjectMetadataRequest;
+import com.amazonaws.services.s3.model.GetObjectRequest;
 import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
 import com.amazonaws.services.s3.model.ObjectMetadata;
 import com.amazonaws.services.s3.model.PutObjectRequest;
 import com.amazonaws.services.s3.model.SSEAlgorithm;
 import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams;
-import com.amazonaws.util.StringUtils;
+import com.amazonaws.services.s3.model.SSECustomerKey;
+
+import java.util.Properties;
+
+import static com.amazonaws.HttpMethod.GET;
+import static com.amazonaws.services.s3.model.SSEAlgorithm.AES256;
+import static com.amazonaws.util.StringUtils.hasValue;
+import static java.util.Objects.requireNonNull;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION_SSE_C;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION_SSE_KMS;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_SSE_C_KEY;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_SSE_KMS_KEYID;
 
 /**
  * This class to sets encrption mode in S3 request.
@@ -34,24 +46,57 @@ import com.amazonaws.util.StringUtils;
  */
 public class S3RequestDecorator {
     DataEncryption dataEncryption = DataEncryption.NONE;
-    Properties props;
     SSEAwsKeyManagementParams sseParams;
 
+    SSECustomerKey sseCustomerKey;
+
     public S3RequestDecorator(Properties props) {
-        String encryptionType = props.getProperty(S3Constants.S3_ENCRYPTION);
+        final String encryptionType = props.getProperty(S3_ENCRYPTION);
         if (encryptionType != null) {
-            this.dataEncryption = dataEncryption.valueOf(encryptionType);
+            this.dataEncryption = DataEncryption.valueOf(encryptionType);
 
-            if (encryptionType.equals(S3Constants.S3_ENCRYPTION_SSE_KMS)) {
-                String keyId = props.getProperty(S3Constants.S3_SSE_KMS_KEYID);
-                sseParams = new SSEAwsKeyManagementParams();
-                if (!StringUtils.isNullOrEmpty(keyId)) {
-                    sseParams.withAwsKmsKeyId(keyId);
+            switch (encryptionType) {
+                case S3_ENCRYPTION_SSE_KMS: {
+                    final String keyId = props.getProperty(S3_SSE_KMS_KEYID);
+                    sseParams = new SSEAwsKeyManagementParams();
+                    if (hasValue(keyId)) {
+                        sseParams.withAwsKmsKeyId(keyId);
+                    }
+                    break;
                 }
+                case S3_ENCRYPTION_SSE_C: {
+                    final String keyId = props.getProperty(S3_SSE_C_KEY);
+                    if (hasValue(keyId)) {
+                        sseCustomerKey = new SSECustomerKey(keyId);
+                    }
+                    break;
+                }
+                default:
+                    break;
             }
         }
     }
 
+    /**
+     * Set encryption in {@link GetObjectMetadataRequest}
+     */
+    public GetObjectMetadataRequest decorate(final GetObjectMetadataRequest request) {
+        if (requireNonNull(getDataEncryption()) == DataEncryption.SSE_C) {
+            request.withSSECustomerKey(sseCustomerKey);
+        }
+        return request;
+    }
+
+    /**
+     * Set encryption in {@link GetObjectRequest}
+     */
+    public GetObjectRequest decorate(final GetObjectRequest request) {
+        if (requireNonNull(getDataEncryption()) == DataEncryption.SSE_C) {
+            request.withSSECustomerKey(sseCustomerKey);
+        }
+        return request;
+    }
+
     /**
      * Set encryption in {@link PutObjectRequest}
      */
@@ -68,6 +113,9 @@ public class S3RequestDecorator {
                 /*Set*/
                 request.withSSEAwsKeyManagementParams(sseParams);
                 break;
+            case SSE_C:
+                request.withSSECustomerKey(sseCustomerKey);
+                break;
             case NONE:
                 break;
         }
@@ -90,6 +138,10 @@ public class S3RequestDecorator {
                 metadata.setSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm());
                 request.withSSEAwsKeyManagementParams(sseParams);
                 break;
+            case SSE_C:
+                metadata.setSSEAlgorithm(AES256.getAlgorithm());
+                request.withSourceSSECustomerKey(sseCustomerKey).withDestinationSSECustomerKey(sseCustomerKey);
+                break;
             case NONE:
                 break;
         }
@@ -109,6 +161,9 @@ public class S3RequestDecorator {
                 metadata.setSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm());
                 request.withSSEAwsKeyManagementParams(sseParams);
                 break;
+            case SSE_C:
+                request.withSSECustomerKey(sseCustomerKey);
+                break;
             case NONE:
                 break;
         }
@@ -119,11 +174,18 @@ public class S3RequestDecorator {
     public GeneratePresignedUrlRequest decorate(GeneratePresignedUrlRequest request) {
         switch (getDataEncryption()) {
           case SSE_KMS:
+              if (request.getMethod() == GET) break; // KMS is not valid for GET Requests
               String keyId = getSSEParams().getAwsKmsKeyId();
               request = request.withSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm());
               if (keyId != null) {
                   request = request.withKmsCmkId(keyId);
               }
+              break;
+          case SSE_C:
+              request = request.withSSECustomerKey(sseCustomerKey);
+              break;
+          default:
+              break;
         }
         return request;
     }
@@ -141,7 +203,7 @@ public class S3RequestDecorator {
      *
      */
     private enum DataEncryption {
-        SSE_S3, SSE_KMS, NONE;
+        SSE_S3, SSE_KMS, SSE_C, NONE;
     }
 
 }
diff --git a/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/TestS3DSWithSSECustomerKey.java b/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/TestS3DSWithSSECustomerKey.java
new file mode 100644
index 0000000000..c8d1b20e64
--- /dev/null
+++ b/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/TestS3DSWithSSECustomerKey.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.blob.cloud.s3;
+
+import org.junit.AssumptionViolatedException;
+import org.junit.Before;
+import org.slf4j.Logger;
+
+import static com.amazonaws.util.StringUtils.hasValue;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION_SSE_C;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_SSE_C_KEY;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Test S3DataStore operation with SSE_C encryption.
+ * It requires to pass aws config file via system property  or system properties by prefixing with 'ds.'.
+ * See details @ {@link S3DataStoreUtils}.
+ * For e.g. -Dconfig=/opt/cq/aws.properties. Sample aws properties located at
+ * src/test/resources/aws.properties
+ *
+ */
+public class TestS3DSWithSSECustomerKey extends TestS3Ds {
+
+        protected static final Logger LOG = getLogger(TestS3DSWithSSECustomerKey.class);
+
+        @Override
+        @Before
+        public void setUp() throws Exception {
+            super.setUp();
+            String keyId = props.getProperty(S3_SSE_C_KEY);
+            if (hasValue(keyId)) {
+                props.setProperty(S3_ENCRYPTION, S3_ENCRYPTION_SSE_C);
+                props.setProperty(S3_SSE_C_KEY, keyId);
+            } else {
+                LOG.info("SSE Customer Key ID not configured so ignoring test");
+                throw new AssumptionViolatedException("SSE Customer key Id not configured");
+            }
+        }
+}
diff --git a/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/TestS3Ds.java b/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/TestS3Ds.java
index 59b9458bb6..166c2d44c4 100644
--- a/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/TestS3Ds.java
+++ b/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/TestS3Ds.java
@@ -22,12 +22,11 @@ import java.io.InputStream;
 import java.net.URI;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.Properties;
 
 import javax.jcr.RepositoryException;
 
-import com.amazonaws.services.s3.Headers;
-import com.amazonaws.services.s3.model.SSEAlgorithm;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.time.DateUtils;
 import org.apache.http.HttpEntity;
@@ -60,6 +59,20 @@ import org.junit.runners.Parameterized;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static com.amazonaws.services.s3.Headers.SERVER_SIDE_ENCRYPTION;
+import static com.amazonaws.services.s3.Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID;
+import static com.amazonaws.services.s3.Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM;
+import static com.amazonaws.services.s3.Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY;
+import static com.amazonaws.services.s3.Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5;
+import static com.amazonaws.services.s3.model.SSEAlgorithm.AES256;
+import static com.amazonaws.services.s3.model.SSEAlgorithm.KMS;
+import static com.amazonaws.util.Base64.decode;
+import static com.amazonaws.util.Md5Utils.md5AsBase64;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION_SSE_C;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_ENCRYPTION_SSE_KMS;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_SSE_C_KEY;
+import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Constants.S3_SSE_KMS_KEYID;
 import static org.apache.jackrabbit.oak.blob.cloud.s3.S3DataStoreUtils.getFixtures;
 import static org.apache.jackrabbit.oak.blob.cloud.s3.S3DataStoreUtils.getS3Config;
 import static org.apache.jackrabbit.oak.blob.cloud.s3.S3DataStoreUtils.getS3DataStore;
@@ -125,7 +138,7 @@ public class TestS3Ds extends AbstractDataStoreTest {
         props.setProperty(S3Constants.PRESIGNED_HTTP_UPLOAD_URI_EXPIRY_SECONDS, "60");
         props.setProperty(S3Constants.PRESIGNED_URI_ENABLE_ACCELERATION, "60");
         props.setProperty(S3Constants.PRESIGNED_HTTP_DOWNLOAD_URI_CACHE_MAX_SIZE, "60");
-        props.setProperty(S3Constants.S3_ENCRYPTION, S3Constants.S3_ENCRYPTION_NONE);
+        props.setProperty(S3_ENCRYPTION, S3Constants.S3_ENCRYPTION_NONE);
         super.setUp();
     }
 
@@ -175,11 +188,11 @@ public class TestS3Ds extends AbstractDataStoreTest {
     @Test
     public void testDataMigration() {
         try {
-            String encryption = props.getProperty(S3Constants.S3_ENCRYPTION);
+            String encryption = props.getProperty(S3_ENCRYPTION);
 
             //manually close the setup ds and remove encryption
             ds.close();
-            props.remove(S3Constants.S3_ENCRYPTION);
+            props.remove(S3_ENCRYPTION);
             ds = createDataStore();
 
             byte[] data = new byte[dataLength];
@@ -190,7 +203,7 @@ public class TestS3Ds extends AbstractDataStoreTest {
             ds.close();
 
             // turn encryption now anc recreate datastore instance
-            props.setProperty(S3Constants.S3_ENCRYPTION, encryption);
+            props.setProperty(S3_ENCRYPTION, encryption);
             props.setProperty(S3Constants.S3_RENAME_KEYS, "true");
             ds = createDataStore();
 
@@ -252,16 +265,24 @@ public class TestS3Ds extends AbstractDataStoreTest {
         HttpPut putreq = new HttpPut(puturl);
 
         String keyId = null;
-        String encryptionType = props.getProperty(S3Constants.S3_ENCRYPTION);
-
-        if (encryptionType.equals(S3Constants.S3_ENCRYPTION_SSE_KMS)) {
-             keyId = props.getProperty(S3Constants.S3_SSE_KMS_KEYID);
-             putreq.addHeader(new BasicHeader(Headers.SERVER_SIDE_ENCRYPTION,
-                     SSEAlgorithm.KMS.getAlgorithm()));
-             if(keyId != null) {
-                 putreq.addHeader(new BasicHeader(Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID,
-                         keyId));
-             }
+        String encryptionType = props.getProperty(S3_ENCRYPTION);
+
+        switch (encryptionType) {
+            case S3_ENCRYPTION_SSE_KMS:
+                keyId = props.getProperty(S3_SSE_KMS_KEYID);
+                putreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION, KMS.getAlgorithm()));
+                if (keyId != null) {
+                    putreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID, keyId));
+                }
+                break;
+            case S3_ENCRYPTION_SSE_C:
+                keyId = props.getProperty(S3_SSE_C_KEY);
+                putreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM, AES256.getAlgorithm()));
+                putreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY, keyId));
+                putreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5, md5AsBase64(decode(keyId))));
+                break;
+            default:
+                break;
         }
 
         putreq.setEntity(new InputStreamEntity(inputstream , length));
@@ -273,6 +294,16 @@ public class TestS3Ds extends AbstractDataStoreTest {
 
     private HttpEntity httpGet(URI uri) throws IOException {
         HttpGet getreq = new HttpGet(uri);
+
+        final String encryptionType = props.getProperty(S3_ENCRYPTION);
+
+        if (Objects.equals(S3_ENCRYPTION_SSE_C, encryptionType)) {
+            String keyId = props.getProperty(S3_SSE_C_KEY);
+            getreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM, AES256.getAlgorithm()));
+            getreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY, keyId));
+            getreq.addHeader(new BasicHeader(SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5, md5AsBase64(decode(keyId))));
+        }
+
         CloseableHttpClient httpclient = HttpClients.createDefault();
         CloseableHttpResponse res = httpclient.execute(getreq);
         Assert.assertEquals(200, res.getStatusLine().getStatusCode());
diff --git a/oak-blob-cloud/src/test/resources/aws.properties b/oak-blob-cloud/src/test/resources/aws.properties
index e23ed0c3fd..fb5623d4bb 100644
--- a/oak-blob-cloud/src/test/resources/aws.properties
+++ b/oak-blob-cloud/src/test/resources/aws.properties
@@ -35,6 +35,10 @@ s3Region=
 # and has a higher precedence over endpoint derived
 # via S3 region.
 kmsKeyId=
+# base64 encoded 32 bytes customer key to be used for SSE_C
+# Please use 'openssl rand -base64 -out ssec.key 32' command
+# to generate customer key
+sseCustomerKey=
 connectionTimeout=120000
 socketTimeout=120000
 maxConnections=20
diff --git a/oak-doc/src/site/markdown/features/direct-binary-access.md b/oak-doc/src/site/markdown/features/direct-binary-access.md
index a65d37abc3..b66106ecdc 100644
--- a/oak-doc/src/site/markdown/features/direct-binary-access.md
+++ b/oak-doc/src/site/markdown/features/direct-binary-access.md
@@ -42,6 +42,8 @@ Currently these Blob/DataStores are supported:
 * [S3DataStore](../osgi_config.html#Jackrabbit_2_-_S3DataStore)
 * AzureDataStore
 
+Please note that `Direct Binary Access` doesn't work with Customer provided keys. For more info, please refer to AWS documentation on [SSE-C keys](https://docs.aws.amazon.com/AmazonS3/latest/userguide/ServerSideEncryptionCustomerKeys.html#ssec-and-presignedurl)
+
 ## Configuration
 
 The feature has to be explicitly enabled by setting properties on the DataStore. In the table, "S3" refers to `S3DataStore`, "Azure" to `AzureDataStore`.