Skip to content

Commit 8199e0a

Browse files
committed
Add some contextual comments
1 parent 3c3f648 commit 8199e0a

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424
import software.amazon.encryption.s3.materials.KmsKeyring;
2525
import software.amazon.encryption.s3.materials.RsaKeyring;
2626

27+
/**
28+
* This client is a drop-in replacement for the S3 client. It will automatically encrypt objects
29+
* on putObject and decrypt objects on getObject using the provided encryption key(s).
30+
*/
2731
public class S3EncryptionClient implements S3Client {
2832

33+
// Used for request-scoped encryption contexts for supporting keys
2934
public static final ExecutionAttribute<Map<String,String>> ENCRYPTION_CONTEXT = new ExecutionAttribute<>("EncryptionContext");
3035

3136
private final S3Client _wrappedClient;
@@ -42,6 +47,7 @@ public static Builder builder() {
4247
return new Builder();
4348
}
4449

50+
// Helper function to attach encryption contexts to a request
4551
public static Consumer<AwsRequestOverrideConfiguration.Builder> withAdditionalEncryptionContext(Map<String, String> encryptionContext) {
4652
return builder ->
4753
builder.putExecutionAttribute(S3EncryptionClient.ENCRYPTION_CONTEXT, encryptionContext);

src/main/java/software/amazon/encryption/s3/internal/GetEncryptedObjectPipeline.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
import software.amazon.encryption.s3.materials.DecryptionMaterials;
2121
import software.amazon.encryption.s3.materials.EncryptedDataKey;
2222

23+
/**
24+
* This class will determine the necessary mechanisms to decrypt objects returned from S3.
25+
* Due to supporting various legacy modes, this is not a predefined pipeline like
26+
* PutEncryptedObjectPipeline. There are several branches in this graph that are determined as more
27+
* information is available from the returned object.
28+
*/
2329
public class GetEncryptedObjectPipeline {
2430

2531
private final S3Client _s3Client;

src/main/java/software/amazon/encryption/s3/internal/PutEncryptedObjectPipeline.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public PutObjectResponse putObject(PutObjectRequest request, RequestBody request
3636

3737
byte[] input;
3838
try {
39+
// TODO: this needs to be a stream and not a byte[]
3940
input = IoUtils.toByteArray(requestBody.contentStreamProvider().newStream());
4041
} catch (IOException e) {
4142
throw new S3EncryptionClientException("Cannot read input.", e);
@@ -50,6 +51,7 @@ public PutObjectResponse putObject(PutObjectRequest request, RequestBody request
5051
public static class Builder {
5152
private S3Client _s3Client;
5253
private CryptographicMaterialsManager _cryptoMaterialsManager;
54+
// Default to AesGcm since it is the only active (non-legacy) content encryption strategy
5355
private ContentEncryptionStrategy _contentEncryptionStrategy =
5456
AesGcmContentStrategy
5557
.builder()

src/main/java/software/amazon/encryption/s3/materials/KmsKeyring.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.HashMap;
55
import java.util.Map;
66
import java.util.Optional;
7-
import java.util.TreeMap;
87
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
98
import software.amazon.awssdk.core.ApiName;
109
import software.amazon.awssdk.core.SdkBytes;
@@ -100,8 +99,7 @@ public EncryptionMaterials modifyMaterials(EncryptionMaterials materials) {
10099

101100
@Override
102101
public byte[] encryptDataKey(SecureRandom secureRandom, EncryptionMaterials materials) {
103-
// Convert to TreeMap for sorting of keys
104-
TreeMap<String, String> encryptionContext = new TreeMap<>(materials.encryptionContext());
102+
HashMap<String, String> encryptionContext = new HashMap<>(materials.encryptionContext());
105103
EncryptRequest request = EncryptRequest.builder()
106104
.keyId(_wrappingKeyId)
107105
.encryptionContext(encryptionContext)

src/test/java/S3EncryptionClientTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,7 @@ public void KmsContextV3toV2() throws IOException {
536536
.overrideConfiguration(withAdditionalEncryptionContext(encryptionContext)),
537537
RequestBody.fromString(input));
538538

539-
EncryptedGetObjectRequest getObjectRequest = new EncryptedGetObjectRequest(
540-
BUCKET,
541-
BUCKET_KEY
542-
).withExtraMaterialsDescription(encryptionContext);
543-
String output = IOUtils.toString(v2Client.getObject(getObjectRequest).getObjectContent());
539+
String output = v2Client.getObjectAsString(BUCKET, BUCKET_KEY);
544540
assertEquals(input, output);
545541
}
546542

0 commit comments

Comments
 (0)