|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | package software.amazon.encryption.s3; |
4 | 4 |
|
5 | | -import ch.qos.logback.classic.Logger; |
6 | | -import ch.qos.logback.classic.spi.ILoggingEvent; |
7 | | -import ch.qos.logback.core.read.ListAppender; |
8 | 5 | import com.amazonaws.services.kms.AWSKMS; |
9 | 6 | import com.amazonaws.services.kms.AWSKMSClientBuilder; |
10 | 7 | import com.amazonaws.services.s3.AmazonS3Encryption; |
|
23 | 20 | import com.amazonaws.services.s3.model.StaticEncryptionMaterialsProvider; |
24 | 21 | import org.junit.jupiter.api.BeforeAll; |
25 | 22 | import org.junit.jupiter.api.Test; |
26 | | -import org.slf4j.LoggerFactory; |
27 | 23 | import software.amazon.awssdk.core.ResponseBytes; |
28 | 24 | import software.amazon.awssdk.core.sync.RequestBody; |
29 | 25 | import software.amazon.awssdk.services.s3.S3Client; |
|
33 | 29 | import software.amazon.awssdk.services.s3.model.PutObjectRequest; |
34 | 30 | import software.amazon.encryption.s3.internal.InstructionFileConfig; |
35 | 31 |
|
36 | | -import software.amazon.encryption.s3.materials.AesKeyring; |
37 | | -import software.amazon.encryption.s3.materials.KmsKeyring; |
38 | | -import software.amazon.encryption.s3.materials.PartialRsaKeyPair; |
39 | | -import software.amazon.encryption.s3.materials.RsaKeyring; |
40 | | - |
41 | 32 | import javax.crypto.KeyGenerator; |
42 | 33 | import javax.crypto.SecretKey; |
43 | 34 | import java.io.ByteArrayInputStream; |
|
50 | 41 | import java.util.Map; |
51 | 42 |
|
52 | 43 | import static org.junit.jupiter.api.Assertions.assertEquals; |
53 | | -import static org.junit.jupiter.api.Assertions.assertFalse; |
54 | 44 | import static org.junit.jupiter.api.Assertions.assertThrows; |
55 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
56 | 45 |
|
57 | 46 | import static software.amazon.encryption.s3.S3EncryptionClient.withAdditionalConfiguration; |
58 | 47 | import static software.amazon.encryption.s3.utils.S3EncryptionClientTestResources.BUCKET; |
@@ -978,159 +967,4 @@ public void nullMaterialDescriptionV3() { |
978 | 967 |
|
979 | 968 | } |
980 | 969 |
|
981 | | - @Test |
982 | | - public void LegacyWrappingEnabledOnClientButNotOnAesKeyring() { |
983 | | - Logger logger = (Logger) LoggerFactory.getLogger(S3EncryptionClient.class); |
984 | | - ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); |
985 | | - listAppender.start(); |
986 | | - logger.addAppender(listAppender); |
987 | | - |
988 | | - AesKeyring aesKeyring = AesKeyring.builder() |
989 | | - .wrappingKey(AES_KEY) |
990 | | - .build(); |
991 | | - |
992 | | - S3Client wrappedClient = S3Client.create(); |
993 | | - S3Client v3Client = S3EncryptionClient.builder() |
994 | | - .keyring(aesKeyring) |
995 | | - .wrappedClient(wrappedClient) |
996 | | - .enableLegacyWrappingAlgorithms(true) |
997 | | - .enableLegacyUnauthenticatedModes(true) |
998 | | - .build(); |
999 | | - |
1000 | | - assertTrue(listAppender.list.stream().anyMatch(event -> event.getMessage().contains("enableLegacyWrappingAlgorithms is set on the client, but is not set on the keyring provided. In order to enable legacy wrapping algorithms, set enableLegacyWrappingAlgorithms to true in the keyring's builder."))); |
1001 | | - logger.detachAppender(listAppender); |
1002 | | - } |
1003 | | - |
1004 | | - @Test |
1005 | | - public void LegacyWrappingEnabledOnClientButNotOnRsaKeyring() { |
1006 | | - Logger logger = (Logger) LoggerFactory.getLogger(S3EncryptionClient.class); |
1007 | | - ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); |
1008 | | - listAppender.start(); |
1009 | | - logger.addAppender(listAppender); |
1010 | | - |
1011 | | - PartialRsaKeyPair partialRsaKeyPair = PartialRsaKeyPair.builder() |
1012 | | - .publicKey(RSA_KEY_PAIR.getPublic()) |
1013 | | - .privateKey(RSA_KEY_PAIR.getPrivate()) |
1014 | | - .build(); |
1015 | | - |
1016 | | - RsaKeyring rsaKeyring = RsaKeyring.builder() |
1017 | | - .wrappingKeyPair(partialRsaKeyPair) |
1018 | | - .build(); |
1019 | | - |
1020 | | - S3Client wrappedClient = S3Client.create(); |
1021 | | - S3Client v3Client = S3EncryptionClient.builder() |
1022 | | - .keyring(rsaKeyring) |
1023 | | - .wrappedClient(wrappedClient) |
1024 | | - .enableLegacyWrappingAlgorithms(true) |
1025 | | - .enableLegacyUnauthenticatedModes(true) |
1026 | | - .build(); |
1027 | | - |
1028 | | - assertTrue(listAppender.list.stream().anyMatch(event -> event.getMessage().contains("enableLegacyWrappingAlgorithms is set on the client, but is not set on the keyring provided. In order to enable legacy wrapping algorithms, set enableLegacyWrappingAlgorithms to true in the keyring's builder."))); |
1029 | | - logger.detachAppender(listAppender); |
1030 | | - |
1031 | | - } |
1032 | | - |
1033 | | - @Test |
1034 | | - public void LegacyWrappingEnabledOnClientButNotOnKmsKeyring() { |
1035 | | - Logger logger = (Logger) LoggerFactory.getLogger(S3EncryptionClient.class); |
1036 | | - ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); |
1037 | | - listAppender.start(); |
1038 | | - logger.addAppender(listAppender); |
1039 | | - |
1040 | | - KmsKeyring kmsKeyring = KmsKeyring.builder() |
1041 | | - .wrappingKeyId(KMS_KEY_ID) |
1042 | | - .build(); |
1043 | | - |
1044 | | - S3Client wrappedClient = S3Client.create(); |
1045 | | - S3Client v3Client = S3EncryptionClient.builder() |
1046 | | - .keyring(kmsKeyring) |
1047 | | - .wrappedClient(wrappedClient) |
1048 | | - .enableLegacyWrappingAlgorithms(true) |
1049 | | - .enableLegacyUnauthenticatedModes(true) |
1050 | | - .build(); |
1051 | | - |
1052 | | - assertTrue(listAppender.list.stream().anyMatch(event -> event.getMessage().contains("enableLegacyWrappingAlgorithms is set on the client, but is not set on the keyring provided. In order to enable legacy wrapping algorithms, set enableLegacyWrappingAlgorithms to true in the keyring's builder."))); |
1053 | | - logger.detachAppender(listAppender); |
1054 | | - |
1055 | | - } |
1056 | | - |
1057 | | - @Test |
1058 | | - public void LegacyWrappingEnabledOnBothClientAndAesKeyring() { |
1059 | | - Logger logger = (Logger) LoggerFactory.getLogger(S3EncryptionClient.class); |
1060 | | - ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); |
1061 | | - listAppender.start(); |
1062 | | - logger.addAppender(listAppender); |
1063 | | - |
1064 | | - AesKeyring aesKeyring = AesKeyring.builder() |
1065 | | - .wrappingKey(AES_KEY) |
1066 | | - .enableLegacyWrappingAlgorithms(true) |
1067 | | - .build(); |
1068 | | - |
1069 | | - S3Client wrappedClient = S3Client.create(); |
1070 | | - S3Client v3Client = S3EncryptionClient.builder() |
1071 | | - .keyring(aesKeyring) |
1072 | | - .wrappedClient(wrappedClient) |
1073 | | - .enableLegacyWrappingAlgorithms(true) |
1074 | | - .enableLegacyUnauthenticatedModes(true) |
1075 | | - .build(); |
1076 | | - |
1077 | | - assertFalse(listAppender.list.stream() |
1078 | | - .anyMatch(event -> event.getMessage().contains("enableLegacyWrappingAlgorithms is set on the client, but is not set on the keyring provided. In order to enable legacy wrapping algorithms, set enableLegacyWrappingAlgorithms to true in the keyring's builder."))); |
1079 | | - logger.detachAppender(listAppender); |
1080 | | - } |
1081 | | - |
1082 | | - @Test |
1083 | | - public void LegacyWrappingEnabledOnBothClientAndRsaKeyring() { |
1084 | | - Logger logger = (Logger) LoggerFactory.getLogger(S3EncryptionClient.class); |
1085 | | - ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); |
1086 | | - listAppender.start(); |
1087 | | - logger.addAppender(listAppender); |
1088 | | - |
1089 | | - PartialRsaKeyPair partialRsaKeyPair = PartialRsaKeyPair.builder() |
1090 | | - .publicKey(RSA_KEY_PAIR.getPublic()) |
1091 | | - .privateKey(RSA_KEY_PAIR.getPrivate()) |
1092 | | - .build(); |
1093 | | - |
1094 | | - RsaKeyring rsaKeyring = RsaKeyring.builder() |
1095 | | - .wrappingKeyPair(partialRsaKeyPair) |
1096 | | - .enableLegacyWrappingAlgorithms(true) |
1097 | | - .build(); |
1098 | | - |
1099 | | - S3Client wrappedClient = S3Client.create(); |
1100 | | - S3Client v3Client = S3EncryptionClient.builder() |
1101 | | - .keyring(rsaKeyring) |
1102 | | - .wrappedClient(wrappedClient) |
1103 | | - .enableLegacyWrappingAlgorithms(true) |
1104 | | - .enableLegacyUnauthenticatedModes(true) |
1105 | | - .build(); |
1106 | | - |
1107 | | - assertFalse(listAppender.list.stream() |
1108 | | - .anyMatch(event -> event.getMessage().contains("enableLegacyWrappingAlgorithms is set on the client, but is not set on the keyring provided. In order to enable legacy wrapping algorithms, set enableLegacyWrappingAlgorithms to true in the keyring's builder."))); |
1109 | | - logger.detachAppender(listAppender); |
1110 | | - } |
1111 | | - |
1112 | | - @Test |
1113 | | - public void LegacyWrappingEnabledOnBothClientAndKmsKeyring() { |
1114 | | - Logger logger = (Logger) LoggerFactory.getLogger(S3EncryptionClient.class); |
1115 | | - ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); |
1116 | | - listAppender.start(); |
1117 | | - logger.addAppender(listAppender); |
1118 | | - |
1119 | | - KmsKeyring kmsKeyring = KmsKeyring.builder() |
1120 | | - .wrappingKeyId(KMS_KEY_ID) |
1121 | | - .enableLegacyWrappingAlgorithms(true) |
1122 | | - .build(); |
1123 | | - |
1124 | | - S3Client wrappedClient = S3Client.create(); |
1125 | | - S3Client v3Client = S3EncryptionClient.builder() |
1126 | | - .keyring(kmsKeyring) |
1127 | | - .wrappedClient(wrappedClient) |
1128 | | - .enableLegacyWrappingAlgorithms(true) |
1129 | | - .enableLegacyUnauthenticatedModes(true) |
1130 | | - .build(); |
1131 | | - |
1132 | | - assertFalse(listAppender.list.stream() |
1133 | | - .anyMatch(event -> event.getMessage().contains("enableLegacyWrappingAlgorithms is set on the client, but is not set on the keyring provided. In order to enable legacy wrapping algorithms, set enableLegacyWrappingAlgorithms to true in the keyring's builder."))); |
1134 | | - logger.detachAppender(listAppender); |
1135 | | - } |
1136 | 970 | } |
0 commit comments