Skip to content

Commit 59bb8b1

Browse files
authored
Merge pull request #7 from smswz/legacy-modes
Legacy modes support
2 parents 1f3d1d2 + 1c329e0 commit 59bb8b1

38 files changed

+2004
-1087
lines changed

README.md

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It also supports writing objects with non-legacy algorithms.
99
The list of legacy modes and operations will be provided below.
1010

1111
### Examples
12-
#### V2 KMS Materials Provider to V3 KMS w/ Context Materials Manager and Keyring
12+
#### V2 KMS Materials Provider to V3
1313
```java
1414
class Example {
1515
public static void main(String[] args) {
@@ -20,21 +20,14 @@ class Example {
2020
.build();
2121

2222
// V3
23-
Keyring keyring = KmsContextKeyring.builder()
24-
.wrappingKeyId(KMS_WRAPPING_KEY_ID)
25-
.build();
26-
27-
MaterialsManager materialsManager = DefaultMaterialsManager.builder()
28-
.keyring(keyring)
29-
.build();
3023
S3Client v3Client = S3EncryptionClient.builder()
31-
.materialsManager(materialsManager)
24+
.kmsKeyId(KMS_WRAPPING_KEY_ID)
3225
.build();
3326
}
3427
}
3528
```
3629

37-
#### V2 AES Key Materials Provider to V3 AES/GCM Materials Manager and Keyring
30+
#### V2 AES Key Materials Provider to V3
3831
```java
3932
class Example {
4033
public static void main(String[] args) {
@@ -49,21 +42,14 @@ class Example {
4942
.build();
5043

5144
// V3
52-
Keyring keyring = AesGcmKeyring.builder()
53-
.wrappingKey(aesKey)
54-
.build();
55-
56-
MaterialsManager materialsManager = DefaultMaterialsManager.builder()
57-
.keyring(keyring)
58-
.build();
5945
S3Client v3Client = S3EncryptionClient.builder()
60-
.materialsManager(materialsManager)
46+
.aesKey(aesKey)
6147
.build();
6248
}
6349
}
6450
```
6551

66-
#### V2 RSA Key Materials Provider to V3 RSA-OAEP Materials Manager and Keyring
52+
#### V2 RSA Key Materials Provider to V3
6753
```java
6854
class Example {
6955
public static void main(String[] args) {
@@ -78,22 +64,15 @@ class Example {
7864
.build();
7965

8066
// V3
81-
Keyring keyring = RsaOaepKeyring.builder()
82-
.wrappingKeyPair(rsaKey)
83-
.build();
84-
85-
MaterialsManager materialsManager = DefaultMaterialsManager.builder()
86-
.keyring(keyring)
87-
.build();
8867
S3Client v3Client = S3EncryptionClient.builder()
89-
.materialsManager(materialsManager)
68+
.rsaKeyPair(rsaKey)
9069
.build();
9170
}
9271
}
9372
```
9473

95-
#### V1 Key Materials Provider to V3 AES/GCM Materials Manager, Legacy AESWrap Keyring, and Keyring
96-
Since legacy algorithms are supported for decryption only, a non-legacy keyring is required for any writes.
74+
#### V1 Key Materials Provider to V3
75+
To allow legacy modes (for decryption only), you must explicitly allow them
9776
```java
9877
class Example {
9978
public static void main(String[] args) {
@@ -108,20 +87,9 @@ class Example {
10887
.build();
10988

11089
// V3
111-
Keyring keyring = AesGcmKeyring.builder()
112-
.wrappingKey(aesKey)
113-
.build();
114-
115-
Keyring legacyKeyring = AesWrapKeyring.builder()
116-
.wrappingKey(aesKey)
117-
.build();
118-
119-
MaterialsManager materialsManager = LegacyDecryptMaterialsManager.builder()
120-
.keyring(keyring)
121-
.legacyKeyring(legacyKeyring)
122-
.build();
12390
S3Client v3Client = S3EncryptionClient.builder()
124-
.materialsManager(materialsManager)
91+
.aesKey(aesKey)
92+
.enableLegacyModes(true)
12593
.build();
12694
}
12795
}
@@ -131,6 +99,7 @@ class Example {
13199
#### Content Encryption
132100
* AES/CBC
133101
#### Key Wrap Encryption
102+
* AES
134103
* AESWrap
135104
* RSA-OAEP w/MGF-1 and SHA-256
136105
* KMS (without context)

pom.xml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,54 @@
6161

6262
<dependencies>
6363
<dependency>
64-
<groupId>org.bouncycastle</groupId>
65-
<artifactId>bcprov-jdk18on</artifactId>
66-
<version>1.71</version>
64+
<groupId>software.amazon.awssdk</groupId>
65+
<artifactId>s3</artifactId>
66+
<version>2.17.204</version>
6767
<optional>true</optional>
6868
</dependency>
6969

7070
<dependency>
71-
<groupId>com.amazonaws</groupId>
72-
<artifactId>aws-java-sdk-kms</artifactId>
71+
<groupId>software.amazon.awssdk</groupId>
72+
<artifactId>kms</artifactId>
73+
<version>2.17.204</version>
74+
<optional>true</optional>
75+
</dependency>
76+
77+
<!-- Test Dependencies -->
78+
<dependency>
79+
<groupId>org.junit.jupiter</groupId>
80+
<artifactId>junit-jupiter</artifactId>
81+
<version>5.9.0</version>
82+
<scope>test</scope>
7383
</dependency>
7484

7585
<dependency>
7686
<groupId>com.amazonaws</groupId>
77-
<artifactId>aws-java-sdk-s3</artifactId>
87+
<artifactId>aws-java-sdk-kms</artifactId>
88+
<scope>test</scope>
7889
</dependency>
7990

8091
<dependency>
81-
<groupId>software.amazon.awssdk</groupId>
82-
<artifactId>s3</artifactId>
83-
<version>2.17.204</version>
84-
<optional>true</optional>
92+
<groupId>com.amazonaws</groupId>
93+
<artifactId>aws-java-sdk-s3</artifactId>
94+
<scope>test</scope>
8595
</dependency>
8696

8797
<dependency>
88-
<groupId>software.amazon.awssdk</groupId>
89-
<artifactId>kms</artifactId>
90-
<version>2.17.204</version>
91-
<optional>true</optional>
98+
<groupId>org.bouncycastle</groupId>
99+
<artifactId>bcprov-jdk18on</artifactId>
100+
<version>1.71</version>
101+
<scope>test</scope>
92102
</dependency>
93103
</dependencies>
94104

105+
<build>
106+
<plugins>
107+
<plugin>
108+
<artifactId>maven-surefire-plugin</artifactId>
109+
<version>2.22.2</version>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
95114
</project>

0 commit comments

Comments
 (0)