Skip to content

Commit c1d2b7f

Browse files
committed
Initial release for AWS Java SDK v2
1 parent 0c9785f commit c1d2b7f

File tree

59 files changed

+10137
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+10137
-2
lines changed

ddej-build-tools/src/main/resources/software/amazon/cryptools/ddej-build-tools/checkstyle/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<property name="fileExtensions" value="java"/>
99
<module name="RegexpHeader">
1010
<property name="header"
11-
value="^/*\n * Copyright \d{4} Amazon\.com, Inc\. or its affiliates\. All Rights Reserved\.$"/>
11+
value="^/*\n * Copyright \d{4}([-]\d{4})? Amazon\.com, Inc\. or its affiliates\. All Rights Reserved\.$"/>
1212
</module>
1313
</module>

sdk2/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>software.amazon.awssdk</groupId>
2424
<artifactId>bom</artifactId>
25-
<version>2.4.11</version>
25+
<version>2.5.47</version>
2626
<type>pom</type>
2727
<scope>import</scope>
2828
</dependency>
@@ -44,5 +44,12 @@
4444
<artifactId>dynamodbencryptionclient-common</artifactId>
4545
<version>0.1.0-SNAPSHOT</version>
4646
</dependency>
47+
48+
<dependency>
49+
<groupId>org.mockito</groupId>
50+
<artifactId>mockito-junit-jupiter</artifactId>
51+
<version>2.27.0</version>
52+
<scope>test</scope>
53+
</dependency>
4754
</dependencies>
4855
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.cryptools.dynamodbencryptionclientsdk2;
16+
17+
import java.util.Collections;
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
21+
import software.amazon.cryptools.dynamodbencryptionclientsdk2.encryption.EncryptionContext;
22+
23+
public class BasicDynamoDbEncryptionConfiguration implements DynamoDbEncryptionConfiguration {
24+
private final EncryptionAction defaultEncryptionAction;
25+
private final Map<String, EncryptionAction> encryptionActionOverrides;
26+
private final EncryptionContext encryptionContext;
27+
28+
private BasicDynamoDbEncryptionConfiguration(Builder builder) {
29+
this.defaultEncryptionAction = builder.defaultEncryptionAction;
30+
this.encryptionActionOverrides = Collections.unmodifiableMap(builder.encryptionActionOverrides);
31+
this.encryptionContext = builder.encryptionContext;
32+
}
33+
34+
@Override
35+
public EncryptionAction getDefaultEncryptionAction() {
36+
return this.defaultEncryptionAction;
37+
}
38+
39+
@Override
40+
public Map<String, EncryptionAction> getEncryptionActionOverrides() {
41+
return this.encryptionActionOverrides;
42+
}
43+
44+
@Override
45+
public EncryptionContext getEncryptionContext() {
46+
return this.encryptionContext;
47+
}
48+
49+
/**
50+
* Builder for an immutable implementation of {@link DynamoDbEncryptionConfiguration}.
51+
*/
52+
public static class Builder {
53+
private EncryptionAction defaultEncryptionAction;
54+
private Map<String, EncryptionAction> encryptionActionOverrides = new HashMap<>();
55+
private EncryptionContext encryptionContext;
56+
57+
/**
58+
* Set the default {@link EncryptionAction} that should be applied to any attribute that is found in the
59+
* record and does not have a specific override associated with it.
60+
* @param defaultEncryptionAction The default encryption action that should be applied to attributes.
61+
* @return a mutated instance of this builder.
62+
*/
63+
public Builder defaultEncryptionAction(EncryptionAction defaultEncryptionAction) {
64+
this.defaultEncryptionAction = defaultEncryptionAction;
65+
return this;
66+
}
67+
68+
/**
69+
* Add a map of encryption action overrides for specific attributes. Will be merged into any existing overrides
70+
* the builder already has and will overwrite existing values with the same key.
71+
* @param encryptionActionOverrides A map of encryption action overrides.
72+
* @return a mutated instance of this builder.
73+
*/
74+
public Builder addEncryptionActionOverrides(Map<String, EncryptionAction> encryptionActionOverrides) {
75+
this.encryptionActionOverrides.putAll(encryptionActionOverrides);
76+
return this;
77+
}
78+
79+
/**
80+
* Add a single encryption action override for a specific attribute. Will be merged into any existing overrides
81+
* ths builder already has and will overwrite existing values with the same key.
82+
* @param attributeKey The name of the attribute.
83+
* @param encryptionAction The encryption action to apply to that attribute.
84+
* @return a mutated instance of this builder.
85+
*/
86+
public Builder addEncryptionActionOverride(String attributeKey, EncryptionAction encryptionAction) {
87+
this.encryptionActionOverrides.put(attributeKey, encryptionAction);
88+
return this;
89+
}
90+
91+
/**
92+
* Sets the encryption context to be used by the encryption client when encrypting or decrypting records. At
93+
* a minimum the following fields should be set on the context: tableName, hashKeyName, rangeKeyName.
94+
* @param encryptionContext An {@link EncryptionContext} object to associate with this configuration.
95+
* @return a mutated instance of this builder.
96+
*/
97+
public Builder encryptionContext(EncryptionContext encryptionContext) {
98+
this.encryptionContext = encryptionContext;
99+
return this;
100+
}
101+
102+
/**
103+
* Construct an immutable {@link DynamoDbEncryptionConfiguration} from the information provided to the builder.
104+
* @return an initialized {@link BasicDynamoDbEncryptionConfiguration} object.
105+
*/
106+
public BasicDynamoDbEncryptionConfiguration build() {
107+
return new BasicDynamoDbEncryptionConfiguration(this);
108+
}
109+
}
110+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.cryptools.dynamodbencryptionclientsdk2;
16+
17+
import java.util.Map;
18+
19+
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
20+
import software.amazon.cryptools.dynamodbencryptionclientsdk2.encryption.DynamoDbEncryptor;
21+
22+
/**
23+
* General interface for a class that is capable of encrypting and decrypting DynamoDB records as well as signing and
24+
* verifying signatures.
25+
*/
26+
public interface DynamoDbEncryptionClient {
27+
/**
28+
* Encrypt and sign a record.
29+
* @param itemAttributes The map of AttributeValues that make up the record.
30+
* @param configuration A {@link DynamoDbEncryptionConfiguration} object that configures the behavior and scope
31+
* of encryption and signing on the record.
32+
* @return A map of AttributeValues that has been encrypted and signed as directed.
33+
*/
34+
Map<String, AttributeValue> encryptRecord(Map<String, AttributeValue> itemAttributes,
35+
DynamoDbEncryptionConfiguration configuration);
36+
37+
/**
38+
* Decrypt and verify signature on a record.
39+
* @param itemAttributes The map of AttributeValues that make up the encrypted/signed record.
40+
* @param configuration A {@link DynamoDbEncryptionConfiguration} object that configures the behavior and scope
41+
* of decryption and signature verification on the record.
42+
* @return A map of AttributeValues that have been decrypted and verified as directed.
43+
*/
44+
Map<String, AttributeValue> decryptRecord(Map<String, AttributeValue> itemAttributes,
45+
DynamoDbEncryptionConfiguration configuration);
46+
47+
/**
48+
* Convenience method to return a builder for the default approved implementation of this interface, a
49+
* {@link DynamoDbEncryptor}.
50+
* @return A builder object for the default implementation of this interface.
51+
*/
52+
static DynamoDbEncryptor.Builder builder() {
53+
return DynamoDbEncryptor.builder();
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.cryptools.dynamodbencryptionclientsdk2;
16+
17+
import java.util.Map;
18+
19+
import software.amazon.cryptools.dynamodbencryptionclientsdk2.encryption.EncryptionContext;
20+
21+
/**
22+
* An interface to an object that supplies configuration and context to the {@link DynamoDbEncryptionClient}.
23+
*/
24+
public interface DynamoDbEncryptionConfiguration {
25+
/**
26+
* Get the default {@link EncryptionAction} that should be applied to any attribute that is found in the record and
27+
* does not have a specific override associated with it.
28+
* @return The default {@link EncryptionAction}.
29+
*/
30+
EncryptionAction getDefaultEncryptionAction();
31+
32+
/**
33+
* Gets a map of specific attribute {@link EncryptionAction} overrides.
34+
* @return A map of {@link EncryptionAction} overrides, keyed by attribute name.
35+
*/
36+
Map<String, EncryptionAction> getEncryptionActionOverrides();
37+
38+
/**
39+
* Returns an {@link EncryptionContext} to be used by the encryption client. Has information about the table
40+
* name, the names of the primary indices etc.
41+
* @return An {@link EncryptionContext} object.
42+
*/
43+
EncryptionContext getEncryptionContext();
44+
45+
/**
46+
* Default builder for an immutable implementation of {@link DynamoDbEncryptionConfiguration}.
47+
* @return A newly initialized {@link BasicDynamoDbEncryptionConfiguration.Builder}.
48+
*/
49+
static BasicDynamoDbEncryptionConfiguration.Builder builder() {
50+
return new BasicDynamoDbEncryptionConfiguration.Builder();
51+
}
52+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.cryptools.dynamodbencryptionclientsdk2;
16+
17+
/**
18+
* When configuring the {@link DynamoDbEncryptionClient} you may specify a default behavior for how attributes should
19+
* be treated when encrypting and decrypting, and also you may include overrides to change the behavior for specific
20+
* attributes. The following enumeration are the different valid behaviors for how a single attribute should be treated.
21+
*/
22+
public enum EncryptionAction {
23+
/**
24+
* DO_NOTHING : This instructs the encryption client to completely ignore the attribute. The attribute will not be
25+
* encrypted and it will not be included in the signature calculation of the record.
26+
*/
27+
DO_NOTHING,
28+
29+
/**
30+
* SIGN_ONLY : This instructs the encryption client to include the attribute in the signature calculation of the
31+
* record, but not to encrypt its value.
32+
*/
33+
SIGN_ONLY,
34+
35+
/**
36+
* ENCRYPT_AND_SIGN : This instructs the encryption client to include the attribute in the signature calculation of
37+
* the record and to encrypt its value.
38+
*/
39+
ENCRYPT_AND_SIGN
40+
}

0 commit comments

Comments
 (0)