Skip to content

Commit 8864c08

Browse files
author
Alex Cioc
committed
Revert "Merge pull request aws#189 from mattsb42-aws/revert"
This reverts commit bd4da5b, reversing changes made to d88fe8b.
1 parent 8f5f69e commit 8864c08

File tree

131 files changed

+11290
-1152
lines changed

Some content is hidden

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

131 files changed

+11290
-1152
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# Changelog
22

3+
## 1.7.0 -- unreleased
4+
5+
### Deprecation Warnings
6+
* Deprecated `MasterKey` and `MasterKeyProvider`. Replace your usage of these classes with `Keyring`. See `StandardKeyrings`
7+
for the built-in keyrings that replace `KmsMasterKeyProvider`, `JceMasterKey`, and `MultiProviderFactory`.
8+
We still support using master key providers and are not removing them yet.
9+
When we decide to remove them, we will communicate that as defined in our versioning policy.
10+
* Deprecated `encryptData`, `decryptData` and related methods in `AwsCrypto`. Replace your calls to these methods with
11+
calls to `AwsCrypto.encrypt(EncryptRequest)` and `AwsCrypto.decrypt(DecryptRequest)`.
12+
13+
### Major Changes
14+
* Introduce `Keyring` interface, built in Keyring implementations, and
15+
methods in AwsCrypto that use keyrings [PR #173](https://github.com/aws/aws-encryption-sdk-java/pull/173)
16+
17+
### Patches
18+
* Validate final frame length does not exceed the frame size in the message header [PR #166](https://github.com/aws/aws-encryption-sdk-java/pull/166)
19+
20+
### Maintenance
21+
* Update AWS Java SDK version from 1.11.561 to 1.11.677. [PR #147](https://github.com/aws/aws-encryption-sdk-java/pull/147)
22+
* Upgrade JUnit from 4.12 to 5.5.2 [PR #151](https://github.com/aws/aws-encryption-sdk-java/pull/151)
23+
* Upgrade Mockito from 2.28.1 to 3.1.0 [PR #142](https://github.com/aws/aws-encryption-sdk-java/pull/142)
24+
* Upgrade Bouncy Castle from 1.61 to 1.65 [PR #179](https://github.com/aws/aws-encryption-sdk-java/pull/179)
25+
26+
### Documentation
27+
* Added new examples demonstrating how to use
28+
APIs, keyrings, cryptographic materials managers, and master key providers. PRs
29+
[#165](https://github.com/aws/aws-encryption-sdk-java/pull/165),
30+
[#168](https://github.com/aws/aws-encryption-sdk-java/pull/168),
31+
and [#170](https://github.com/aws/aws-encryption-sdk-java/pull/170).
32+
333
## 1.6.2 -- 2020-05-26
434

535
### Patches

README.md

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# AWS Encryption SDK for Java
22

3-
The AWS Encryption SDK enables secure client-side encryption. It uses cryptography best practices to protect your data and the encryption keys used to protect that data. Each data object is protected with a unique data encryption key (DEK), and the DEK is protected with a key encryption key (KEK) called a *master key*. The encrypted DEK is combined with the encrypted data into a single [encrypted message](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html), so you don't need to keep track of the DEKs for your data. The SDK supports master keys in [AWS Key Management Service](https://aws.amazon.com/kms/) (KMS), and it also provides APIs to define and use other master key providers. The SDK provides methods for encrypting and decrypting strings, byte arrays, and byte streams. For details, see the [example code][examples] and the [Javadoc](https://aws.github.io/aws-encryption-sdk-java/javadoc/).
3+
The AWS Encryption SDK is a client-side encryption library designed to make it easy for everyone to encrypt and decrypt data using industry standards and best practices. It enables you to focus on the core functionality of your application, rather than on how to best encrypt and decrypt your data.
44

5-
For more details about the design and architecture of the SDK, see the [official documentation](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/).
5+
For details about the design, architecture and usage of the SDK, see the [official documentation](https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/), [example code][examples] and the [Javadoc](https://aws.github.io/aws-encryption-sdk-java/javadoc/).
66

77
[Security issue notifications](./CONTRIBUTING.md#security-issue-notifications)
88

@@ -60,75 +60,9 @@ You can get the latest release from Maven:
6060
</dependency>
6161
```
6262

63-
### Get Started
64-
65-
The following code sample demonstrates how to get started:
66-
67-
1. Instantiate the SDK.
68-
2. Define the master key provider.
69-
3. Encrypt and decrypt data.
70-
71-
```java
72-
// This sample code encrypts and then decrypts a string using a KMS CMK.
73-
// You provide the KMS key ARN and plaintext string as arguments.
74-
package com.amazonaws.crypto.examples;
75-
76-
import java.util.Collections;
77-
import java.util.Map;
78-
79-
import com.amazonaws.encryptionsdk.AwsCrypto;
80-
import com.amazonaws.encryptionsdk.CryptoResult;
81-
import com.amazonaws.encryptionsdk.kms.KmsMasterKey;
82-
import com.amazonaws.encryptionsdk.kms.KmsMasterKeyProvider;
83-
84-
public class StringExample {
85-
private static String keyArn;
86-
private static String data;
87-
88-
public static void main(final String[] args) {
89-
keyArn = args[0];
90-
data = args[1];
91-
92-
// Instantiate the SDK
93-
final AwsCrypto crypto = new AwsCrypto();
94-
95-
// Set up the master key provider
96-
final KmsMasterKeyProvider prov = new KmsMasterKeyProvider(keyArn);
97-
98-
// Encrypt the data
99-
//
100-
// NOTE: Encrypted data should have associated encryption context
101-
// to protect integrity. For this example, just use a placeholder
102-
// value. For more information about encryption context, see
103-
// https://amzn.to/1nSbe9X (blogs.aws.amazon.com)
104-
final Map<String, String> context = Collections.singletonMap("Example", "String");
105-
106-
final String ciphertext = crypto.encryptString(prov, data, context).getResult();
107-
System.out.println("Ciphertext: " + ciphertext);
108-
109-
// Decrypt the data
110-
final CryptoResult<String, KmsMasterKey> decryptResult = crypto.decryptString(prov, ciphertext);
111-
// Check the encryption context (and ideally the master key) to
112-
// ensure this is the expected ciphertext
113-
if (!decryptResult.getMasterKeyIds().get(0).equals(keyArn)) {
114-
throw new IllegalStateException("Wrong key id!");
115-
}
116-
117-
// The SDK may add information to the encryption context, so check to
118-
// ensure all of the values are present
119-
for (final Map.Entry<String, String> e : context.entrySet()) {
120-
if (!e.getValue().equals(decryptResult.getEncryptionContext().get(e.getKey()))) {
121-
throw new IllegalStateException("Wrong Encryption Context!");
122-
}
123-
}
124-
125-
// The data is correct, so output it.
126-
System.out.println("Decrypted: " + decryptResult.getResult());
127-
}
128-
}
129-
```
63+
### Sample Code
13064

131-
You can find more examples in the [examples directory][examples].
65+
You can find sample code in the [examples directory][examples].
13266

13367
## Public API
13468

pom.xml

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,23 @@
5353
</dependency>
5454

5555
<dependency>
56-
<groupId>org.mockito</groupId>
57-
<artifactId>mockito-core</artifactId>
58-
<version>2.28.1</version>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter</artifactId>
58+
<version>5.5.2</version>
59+
<scope>test</scope>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.junit.vintage</groupId>
64+
<artifactId>junit-vintage-engine</artifactId>
65+
<version>5.5.2</version>
5966
<scope>test</scope>
6067
</dependency>
6168

6269
<dependency>
63-
<groupId>junit</groupId>
64-
<artifactId>junit</artifactId>
65-
<version>4.12</version>
70+
<groupId>org.mockito</groupId>
71+
<artifactId>mockito-junit-jupiter</artifactId>
72+
<version>3.1.0</version>
6673
<scope>test</scope>
6774
</dependency>
6875

@@ -73,6 +80,19 @@
7380
<scope>test</scope>
7481
</dependency>
7582

83+
<dependency>
84+
<groupId>com.amazonaws</groupId>
85+
<artifactId>aws-lambda-java-core</artifactId>
86+
<version>1.2.0</version>
87+
<scope>test</scope>
88+
</dependency>
89+
90+
<dependency>
91+
<groupId>com.amazonaws</groupId>
92+
<artifactId>aws-lambda-java-events</artifactId>
93+
<version>2.2.7</version>
94+
<scope>test</scope>
95+
</dependency>
7696

7797
<dependency>
7898
<groupId>com.google.code.findbugs</groupId>
@@ -190,7 +210,7 @@
190210
</profile>
191211

192212
<profile>
193-
<id>full-test-suite</id>
213+
<id>test-suite</id>
194214
<activation>
195215
<activeByDefault>true</activeByDefault>
196216
</activation>
@@ -201,30 +221,50 @@
201221
<artifactId>maven-surefire-plugin</artifactId>
202222
<version>2.22.0</version>
203223
<configuration>
204-
<includes>
205-
<include>**/AllTestsSuite.java</include>
206-
</includes>
224+
<excludedGroups>ad_hoc</excludedGroups>
207225
</configuration>
208226
</plugin>
209227
</plugins>
210228
</build>
211229
</profile>
212230

231+
<!-- This test profile is intended to assist in rapid development; it filters out some of the slower,
232+
more exhaustive tests in the overall test suite to allow for a rapid edit-test cycle. -->
213233
<profile>
214234
<id>fast-tests-only</id>
215-
<activation>
216-
<activeByDefault>false</activeByDefault>
217-
</activation>
218235
<build>
219236
<plugins>
220237
<plugin>
221238
<groupId>org.apache.maven.plugins</groupId>
222239
<artifactId>maven-surefire-plugin</artifactId>
223240
<version>2.22.0</version>
224241
<configuration>
225-
<includes>
226-
<include>**/FastTestsOnlySuite.java</include>
227-
</includes>
242+
<excludedGroups>ad_hoc, integration</excludedGroups>
243+
<systemPropertyVariables>
244+
<fastTestsOnly>true</fastTestsOnly>
245+
</systemPropertyVariables>
246+
<!-- Require that this fast suite completes relatively quickly. If you're seeing
247+
this timeout get hit, it's time to pare down tests some more. As a general rule of
248+
thumb, we should avoid any single test taking more than 10s, and try to keep the
249+
number of such slow tests to a minimum. -->
250+
<forkedProcessTimeoutInSeconds>120</forkedProcessTimeoutInSeconds>
251+
</configuration>
252+
</plugin>
253+
</plugins>
254+
</build>
255+
</profile>
256+
257+
<!-- This test profile will run only the integration tests. -->
258+
<profile>
259+
<id>integration</id>
260+
<build>
261+
<plugins>
262+
<plugin>
263+
<groupId>org.apache.maven.plugins</groupId>
264+
<artifactId>maven-surefire-plugin</artifactId>
265+
<version>2.22.0</version>
266+
<configuration>
267+
<groups>integration</groups>
228268
</configuration>
229269
</plugin>
230270
</plugins>

src/examples/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# AWS Encryption SDK Examples
2+
3+
This section features examples that show you
4+
how to use the AWS Encryption SDK.
5+
We demonstrate how to use the encryption and decryption APIs
6+
and how to set up some common configuration patterns.
7+
8+
## APIs
9+
10+
The AWS Encryption SDK provides two high-level APIs:
11+
one-step APIs that process the entire operation in memory
12+
and streaming APIs.
13+
14+
You can find examples that demonstrate these APIs
15+
in the [`examples`](./java/com/amazonaws/crypto/examples) directory.
16+
17+
## Configuration
18+
19+
To use the encryption and decryption APIs,
20+
you need to describe how you want the library to protect your data keys.
21+
You can do this by configuring
22+
[keyrings](#keyrings) or [cryptographic materials managers](#cryptographic-materials-managers),
23+
or by configuring [master key providers](#master-key-providers).
24+
These examples will show you how to use the configuration tools that we include for you
25+
and how to create some of your own.
26+
We start with AWS KMS examples, then show how to use other wrapping keys.
27+
28+
* Using AWS Key Management Service (AWS KMS)
29+
* How to use one AWS KMS CMK
30+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/SingleCmk.java)
31+
* [with master key providers](./java/com/amazonaws/crypto/examples/masterkeyprovider/awskms/SingleCmk.java)
32+
* How to use multiple AWS KMS CMKs in different regions
33+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/MultipleRegions.java)
34+
* [with master key providers](./java/com/amazonaws/crypto/examples/masterkeyprovider/awskms/MultipleRegions.java)
35+
* How to decrypt when you don't know the CMK
36+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecrypt.java)
37+
* [with master key providers](./java/com/amazonaws/crypto/examples/masterkeyprovider/awskms/DiscoveryDecrypt.java)
38+
* How to decrypt within a region
39+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecryptInRegionOnly.java)
40+
* How to decrypt with a preferred region but failover to others
41+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecryptWithPreferredRegions.java)
42+
* How to reproduce the behavior of an AWS KMS master key provider
43+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/ActLikeAwsKmsMasterKeyProvider.java)
44+
* How to use AWS KMS clients with custom configuration
45+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/CustomKmsClientConfig.java)
46+
* How to use different AWS KMS client for different regions
47+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/CustomClientSupplier.java)
48+
* Using raw wrapping keys
49+
* How to use a raw AES wrapping key
50+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/rawaes/RawAes.java)
51+
* [with master key providers](./java/com/amazonaws/crypto/examples/masterkeyprovider/rawaes/RawAes.java)
52+
* How to use a raw RSA wrapping key
53+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/rawrsa/RawRsa.java)
54+
* [with master key providers](./java/com/amazonaws/crypto/examples/masterkeyprovider/rawrsa/RawRsa.java)
55+
* How to encrypt with a raw RSA public key wrapping key without access to the private key
56+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/rawrsa/PublicPrivateKeySeparate.java)
57+
* How to use a raw RSA wrapping key when the key is DER encoded
58+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/rawrsa/RawRsaDerEncoded.java)
59+
* Combining wrapping keys
60+
* How to combine AWS KMS with an offline escrow key
61+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/multi/AwsKmsWithEscrow.java)
62+
* [with master key providers](./java/com/amazonaws/crypto/examples/masterkeyprovider/multi/AwsKmsWithEscrow.java)
63+
* How to reuse data keys across multiple messages
64+
* [with the caching cryptographic materials manager](./java/com/amazonaws/crypto/examples/cryptomaterialsmanager/caching/SimpleCache.java)
65+
* How to restrict algorithm suites
66+
* [with a custom cryptographic materials manager](./java/com/amazonaws/crypto/examples/cryptomaterialsmanager/custom/AlgorithmSuiteEnforcement.java)
67+
* How to require encryption context fields
68+
* [with a custom cryptographic materials manager](./java/com/amazonaws/crypto/examples/cryptomaterialsmanager/custom/RequiringEncryptionContextFields.java)
69+
70+
### Keyrings
71+
72+
Keyrings are the most common way for you to configure the AWS Encryption SDK.
73+
They determine how the AWS Encryption SDK protects your data.
74+
You can find these examples in ['examples/keyring`](./java/com/amazonaws/crypto/examples/keyring).
75+
76+
### Cryptographic Materials Managers
77+
78+
Keyrings define how your data keys are protected,
79+
but there is more going on here than just protecting data keys.
80+
81+
Cryptographic materials managers give you higher-level controls
82+
over how the AWS Encryption SDK protects your data.
83+
This can include things like
84+
enforcing the use of certain algorithm suites or encryption context settings,
85+
reusing data keys across messages,
86+
or changing how you interact with keyrings.
87+
You can find these examples in
88+
[`examples/crypto_materials_manager`](./java/com/amazonaws/crypto/examples/cryptomaterialsmanager).
89+
90+
### Master Key Providers
91+
92+
Before there were keyrings, there were master key providers.
93+
Master key providers were the original configuration structure
94+
that we provided for defining how you want to protect your data keys.
95+
Keyrings provide a simpler experience and often more powerful configuration options,
96+
but if you need to use master key providers,
97+
need help migrating from master key providers to keyrings,
98+
or simply want to see the difference between these configuration experiences,
99+
you can find these examples in [`examples/masterkeyprovider`](./java/com/amazonaws/crypto/examples/masterkeyprovider).
100+
101+
## Legacy
102+
103+
This section includes older examples,
104+
including examples of using master keys and master key providers.
105+
You can use them as a reference,
106+
but we recommend looking at the newer examples, which explain the preferred ways of using this library.
107+
You can find these examples in [`examples/legacy`](./java/com/amazonaws/crypto/examples/legacy).
108+
109+
# Writing Examples
110+
111+
If you want to contribute a new example, that's awesome!
112+
To make sure that your example is tested in our CI,
113+
please make sure that it meets the following requirements:
114+
115+
1. The example MUST be a distinct class in the [`examples`](./java/com/amazonaws/crypto/examples) directory.
116+
1. Each example file MUST contain exactly one example.
117+
1. Each example file MUST contain a static method called `run` that runs the example.
118+
1. If your `run` method needs any of the following inputs,
119+
the parameters MUST have the following types:
120+
* `com.amazonaws.encryptionsdk.kms.AwsKmsCmkId` : A single AWS KMS CMK ARN.
121+
* NOTE: You can assume that automatically discovered credentials have
122+
`kms:GenerateDataKey`, `kms:Encrypt`, and `kms:Decrypt` permissions on this CMK.
123+
* `List<com.amazonaws.encryptionsdk.kms.AwsKmsCmkId>` :
124+
A list of AWS KMS CMK ARNs to use for encrypting and decrypting data keys.
125+
* NOTE: You can assume that automatically discovered credentials have
126+
`kms:Encrypt` and `kms:Decrypt` permissions on these CMKs.
127+
* `byte[]` : Plaintext data to encrypt.
128+
* `java.io.File` : A path to a file containing plaintext to encrypt.
129+
* NOTE: You can assume that you have write access to the parent directory
130+
and that anything you do in that directory will be cleaned up
131+
by our test runners.
132+
1. Any additional parameters MUST be optional and nullable and not of the same type as the above parameters.

0 commit comments

Comments
 (0)