Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
13d4ee7
I created the MaterialsDescription class to help identify AES + RSA k…
Jun 17, 2025
8e438d3
Added S3Keyring class
Jun 17, 2025
c11f832
Added Materials Description class
Jun 17, 2025
1e2553a
Added class description for MaterialsDescription
Jun 17, 2025
575627e
added _reEncryptInstructionFile boolean field to builder in AES + RSA…
Jun 18, 2025
239d286
Fixed changes from first PR review
Jun 18, 2025
f182706
removed unused import
Jun 18, 2025
3bd8556
removed unused import
Jun 18, 2025
20ed743
Created an abstract class with an abstract builder method that AES + …
Jun 19, 2025
18f21e0
AESKeyring class is now extending RawKeyring and the builder is also …
Jun 19, 2025
dfa7b4f
RsaKeyring class is now extending RawKeyring and also extending the a…
Jun 19, 2025
cd3ac2c
removed warnIfEncryptionContextIsPresent() method from this class and…
Jun 19, 2025
3ae4b9c
removed getMaterialsDescription() since it will be inherited from Raw…
Jun 19, 2025
7db7d6b
removed things that aren't neccessary due to inheritance
Jun 19, 2025
0bd11ab
added modifyMaterials() method to RawKeyring since common functionali…
Jun 19, 2025
20a8364
removed the modifyMaterials method from AES + RSA Keyrings since it w…
Jun 19, 2025
cfe9e33
re-named getter functions
Jun 19, 2025
674053d
Modified the ContentMetadataEncodingStrategy class to take into accou…
Jun 20, 2025
81215b1
Added MaterialsDescription to Encryption Materials (note: encryption …
Jun 20, 2025
edc1cac
removed materials description from this class and renamed _encryption…
Jun 20, 2025
3ee7571
rennamed variables + moving things around
Jun 20, 2025
541132e
fixed issue where materials description wasn't being passed to Encryp…
Jun 20, 2025
97ff17a
Added test cases for testing if material description was placed in ob…
Jun 20, 2025
241889d
modified the materialsDescription builder setter method to take into …
Jun 20, 2025
db3b701
modified test cases to now include the new field name: encryptionCont…
Jun 20, 2025
09c734d
added test cases for materials description in instruction file
Jun 20, 2025
f62afd6
fixed naming of variable
Jun 20, 2025
5847f8d
added class-level definition for abstract class RawKeyring
Jun 20, 2025
c4fc099
removed unused imports
Jun 20, 2025
ae7e20d
Fixed second round of PR comments
Jun 24, 2025
5b0cbce
modified object_key + input values to match description of test funct…
Jun 24, 2025
5cd05db
correctly using encryption context via overrideConfiguration
Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class ContentMetadata {

private final EncryptedDataKey _encryptedDataKey;
private final String _encryptedDataKeyAlgorithm;

/**
* This field stores either encryption context or material description.
* We use a single field to store both in order to maintain backwards
* compatibility with V2, which treated both as the same.
*/
private final Map<String, String> _encryptionContextOrMatDesc;
Comment thread
kessplas marked this conversation as resolved.

private final byte[] _contentIv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public boolean isLegacy() {

@Override
public EncryptionMaterials modifyMaterials(EncryptionMaterials materials) {
return modifyMaterialHelper(materials);
return modifyMaterialsForRawKeyring(materials);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import software.amazon.awssdk.services.s3.model.S3Request;
import software.amazon.encryption.s3.S3EncryptionClientException;
import software.amazon.encryption.s3.algorithms.AlgorithmSuite;
import software.amazon.encryption.s3.internal.CipherMode;
import software.amazon.encryption.s3.internal.CipherProvider;
Expand Down Expand Up @@ -187,6 +188,9 @@ public Builder plaintextLength(long plaintextLength) {
}

public EncryptionMaterials build() {
if (!_materialsDescription.isEmpty() && !_encryptionContext.isEmpty()) {
throw new S3EncryptionClientException("MaterialsDescription and EncryptionContext cannot both be set!");
}
return new EncryptionMaterials(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String get(Object key) {

@Override
public String put(String key, String value) {
return materialsDescription.put(key, value);
throw new UnsupportedOperationException("This map is immutable");
}

@Override
Expand All @@ -64,7 +64,7 @@ public String remove(Object key) {

@Override
public void putAll(Map<? extends String, ? extends String> m) {
materialsDescription.putAll(m);
throw new UnsupportedOperationException("This map is immutable");
}

@Override
Expand Down Expand Up @@ -101,9 +101,7 @@ public Builder putAll(Map<String, String> description) {
if (description == null) {
throw new IllegalArgumentException("Description must not be null");
}
for (Map.Entry<String, String> entry : description.entrySet()) {
put(entry.getKey(), entry.getValue());
}
materialsDescription.putAll(description);
return this;
}
public MaterialsDescription build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,46 @@
*/
public abstract class RawKeyring extends S3Keyring {
protected final MaterialsDescription _materialsDescription;
protected final boolean _reEncryptInstructionFile;

protected RawKeyring(Builder<?, ?> builder) {
super(builder);
_materialsDescription = builder._materialsDescription;
_reEncryptInstructionFile = builder._reEncryptInstructionFile;
}
public MaterialsDescription getMaterialsDescription() {
return _materialsDescription;
}
public boolean getReEncryptInstructionFile() {
return _reEncryptInstructionFile;
}
public EncryptionMaterials modifyMaterialHelper(EncryptionMaterials materials) {

public EncryptionMaterials modifyMaterialsForRawKeyring(EncryptionMaterials materials) {
warnIfEncryptionContextIsPresent(materials);
if (_materialsDescription != null && !_materialsDescription.isEmpty()) {
materials = materials.toBuilder()
.materialsDescription(_materialsDescription)
.build();
return materials;
}

return materials;
}

/**
* Checks if an encryption context is present in the EncryptionMaterials and issues a warning
* if an encryption context is found.
* <p>
* Encryption context is not recommended for use with
* non-KMS keyrings as it does not provide additional security benefits and is not stored.
*
* @param materials EncryptionMaterials
*/

public void warnIfEncryptionContextIsPresent(EncryptionMaterials materials) {
Comment thread
kessplas marked this conversation as resolved.
materials.s3Request().overrideConfiguration()
.flatMap(overrideConfiguration ->
overrideConfiguration.executionAttributes()
.getOptionalAttribute(S3EncryptionClient.ENCRYPTION_CONTEXT))
.ifPresent(ctx -> LogFactory.getLog(getClass()).warn("Usage of Encryption Context provides no security benefit in " + getClass().getSimpleName()));
.ifPresent(ctx -> LogFactory.getLog(getClass()).warn("Usage of Encryption Context provides no " +
"security benefit in " + getClass().getSimpleName() + ".Additionally, this Encryption Context WILL NOT be " +
"stored in the material description. Provide a MaterialDescription in the Keyring's builder instead."));
}

public static abstract class Builder<KeyringT extends RawKeyring, BuilderT extends Builder<KeyringT, BuilderT>>
extends S3Keyring.Builder<KeyringT, BuilderT> {

protected MaterialsDescription _materialsDescription;
protected boolean _reEncryptInstructionFile = false;

protected Builder() {
super();
Expand All @@ -55,10 +59,5 @@ public BuilderT materialsDescription(MaterialsDescription materialsDescription)
_materialsDescription = materialsDescription;
return builder();
}

public BuilderT reEncryptInstructionFile(boolean reEncryptInstructionFile) {
_reEncryptInstructionFile = reEncryptInstructionFile;
return builder();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public boolean isLegacy() {

@Override
public EncryptionMaterials modifyMaterials(EncryptionMaterials materials) {
return modifyMaterialHelper(materials);
return modifyMaterialsForRawKeyring(materials);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ abstract public class S3Keyring implements Keyring {
protected final DataKeyGenerator _dataKeyGenerator;
private final boolean _enableLegacyWrappingAlgorithms;
private final SecureRandom _secureRandom;
protected final MaterialsDescription _materialsDescription;

protected S3Keyring(Builder<?, ?> builder) {
_enableLegacyWrappingAlgorithms = builder._enableLegacyWrappingAlgorithms;
_secureRandom = builder._secureRandom;
_dataKeyGenerator = builder._dataKeyGenerator;
_materialsDescription = builder._materialsDescription;
}

/**
Expand Down Expand Up @@ -130,8 +128,6 @@ abstract public static class Builder<KeyringT extends S3Keyring, BuilderT extend
private boolean _enableLegacyWrappingAlgorithms = false;
private SecureRandom _secureRandom;
private DataKeyGenerator _dataKeyGenerator = new DefaultDataKeyGenerator();
protected MaterialsDescription _materialsDescription;


protected Builder() {}

Expand Down Expand Up @@ -162,11 +158,6 @@ public BuilderT dataKeyGenerator(final DataKeyGenerator dataKeyGenerator) {
_dataKeyGenerator = dataKeyGenerator;
return builder();
}
public BuilderT materialsDescription(final MaterialsDescription materialsDescription) {
_materialsDescription = materialsDescription;
return builder();
}

abstract public KeyringT build();
}
}
Loading