|
3 | 3 | package software.amazon.encryption.s3.materials;
|
4 | 4 |
|
5 | 5 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
| 6 | +import software.amazon.encryption.s3.S3EncryptionClient; |
6 | 7 | import software.amazon.encryption.s3.S3EncryptionClientException;
|
7 | 8 |
|
8 | 9 | import java.nio.charset.StandardCharsets;
|
|
13 | 14 | import java.util.Map;
|
14 | 15 | import javax.crypto.SecretKey;
|
15 | 16 |
|
| 17 | +import org.apache.commons.logging.LogFactory; |
| 18 | + |
16 | 19 | /**
|
17 | 20 | * This serves as the base class for all the keyrings in the S3 encryption client.
|
18 | 21 | * Shared functionality is all performed here.
|
@@ -124,6 +127,24 @@ public DecryptionMaterials onDecrypt(final DecryptionMaterials materials, List<E
|
124 | 127 |
|
125 | 128 | abstract protected Map<String, DecryptDataKeyStrategy> decryptDataKeyStrategies();
|
126 | 129 |
|
| 130 | + /** |
| 131 | + * Checks if an encryption context is present in the EncryptionMaterials and issues a warning |
| 132 | + * if an encryption context is found. |
| 133 | + * <p> |
| 134 | + * Encryption context is not recommended for use with |
| 135 | + * non-KMS keyrings as it may not provide additional security benefits. |
| 136 | + * |
| 137 | + * @param materials EncryptionMaterials |
| 138 | + */ |
| 139 | + public void warnIfEncryptionContextIsPresent(EncryptionMaterials materials) { |
| 140 | + materials.s3Request().overrideConfiguration() |
| 141 | + .flatMap(overrideConfiguration -> |
| 142 | + overrideConfiguration.executionAttributes() |
| 143 | + .getOptionalAttribute(S3EncryptionClient.ENCRYPTION_CONTEXT)) |
| 144 | + .ifPresent(ctx -> LogFactory.getLog(getClass()).warn("Usage of Encryption Context provides no security benefit in " + getClass().getSimpleName())); |
| 145 | + |
| 146 | + } |
| 147 | + |
127 | 148 | abstract public static class Builder<KeyringT extends S3Keyring, BuilderT extends Builder<KeyringT, BuilderT>> {
|
128 | 149 | private boolean _enableLegacyWrappingAlgorithms = false;
|
129 | 150 | private SecureRandom _secureRandom;
|
|
0 commit comments