-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(GHW): Run Java Examples for PR CI (#749)
- Loading branch information
Showing
11 changed files
with
293 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved." | ||
# "SPDX-License-Identifier: CC-BY-SA-4.0" | ||
# This workflow runs any examples. | ||
name: Library Examples | ||
on: | ||
workflow_call: | ||
inputs: | ||
dafny: | ||
description: "The Dafny version to run" | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
java: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Support longpaths on Git checkout | ||
run: | | ||
git config --global core.longpaths true | ||
- name: Configure AWS Credentials for Tests | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-region: us-west-2 | ||
role-to-assume: arn:aws:iam::370957321024:role/GitHub-CI-MPL-Dafny-Role-us-west-2 | ||
role-session-name: JavaExampleTests | ||
|
||
- uses: actions/checkout@v4 | ||
- run: git submodule update --init libraries | ||
- run: git submodule update --init smithy-dafny | ||
|
||
- name: Setup Dafny | ||
uses: dafny-lang/[email protected] | ||
with: | ||
dafny-version: ${{ inputs.dafny }} | ||
|
||
- name: Setup Java 8 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: "corretto" | ||
java-version: 8 | ||
|
||
- name: Build AwsCryptographicMaterialProviders Java implementation | ||
working-directory: ./AwsCryptographicMaterialProviders | ||
run: | | ||
# This works because `node` is installed by default on GHA runners | ||
CORES=$(node -e 'console.log(os.cpus().length)') | ||
make build_java CORES=$CORES | ||
- name: Test AwsCryptographicMaterialProviders Java Examples | ||
working-directory: ./AwsCryptographicMaterialProviders | ||
run: | | ||
make test_example_java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
AwsCryptographicMaterialProviders/runtimes/java/src/examples/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved." | ||
[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0" | ||
|
||
## Examples (Java) | ||
|
||
This project contains examples demonstrating how to use the | ||
AWS Cryptographic Material Providers Library (MPL) in Java. | ||
|
||
``` | ||
├── .. | ||
└── Hierarchy: Examples for manging the Hierarchical Keyring's Key Store | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...a/src/examples/java/software/amazon/cryptography/example/hierarchy/VersionKeyExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package software.amazon.cryptography.example.hierarchy; | ||
|
||
import javax.annotation.Nullable; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
import software.amazon.cryptography.keystoreadmin.KeyStoreAdmin; | ||
import software.amazon.cryptography.keystoreadmin.model.KMSIdentifier; | ||
import software.amazon.cryptography.keystoreadmin.model.VersionKeyInput; | ||
|
||
/* | ||
There can only be one active version for each branch key at a time. | ||
The Hierarchical keyring typically uses each active branch key version | ||
to satisfy multiple requests. | ||
But you control the extent to which active branch keys are reused | ||
and determine how often the active branch key is rotated. | ||
Branch keys are not used to encrypt plaintext data keys. | ||
They are used to derive the unique wrapping keys | ||
that encrypt plaintext data keys. | ||
The wrapping key derivation process produces a | ||
unique 32 byte wrapping key with 28 bytes of randomness. | ||
This means that a branch key can derive more than 79 octillion, or 296, | ||
unique wrapping keys before cryptographic wear-out occurs. | ||
Despite this very low exhaustion risk, | ||
you might be required to rotate your active branch keys more often. | ||
The active version of the branch key remains active until you rotate it. | ||
Previous versions of the active branch key will not | ||
be used to perform encrypt operations and | ||
cannot be used to derive new wrapping keys. | ||
But they can still be queried and provide wrapping keys | ||
to decrypt the data keys that they encrypted while active. | ||
Use the Key Store Admin's VersionKey operation to | ||
rotate your active branch key. | ||
When you rotate the active branch key, | ||
a new branch key is created to replace the previous version. | ||
The branch-key-id does not change when you rotate the active branch key. | ||
You must specify the branch-key-id that identifies | ||
the current active branch key when you call VersionKey. | ||
*/ | ||
public class VersionKeyExample { | ||
|
||
public static String VersionKey( | ||
String keyStoreTableName, | ||
String logicalKeyStoreName, | ||
String kmsKeyArn, | ||
String branchKeyId, | ||
@Nullable DynamoDbClient dynamoDbClient | ||
) { | ||
// 1. Configure your Key Store Admin resource. | ||
KeyStoreAdmin admin = AdminProvider.admin( | ||
keyStoreTableName, | ||
logicalKeyStoreName, | ||
dynamoDbClient | ||
); | ||
|
||
// 2. Version the Branch Key | ||
admin.VersionKey( | ||
VersionKeyInput | ||
.builder() | ||
// This is the KMS ARN that will be used to protect the Branch Key. | ||
// It is a required argument. | ||
// This ARN MUST match the ARN that protects the Branch Key. | ||
.kmsArn(KMSIdentifier.builder().kmsKeyArn(kmsKeyArn).build()) | ||
// This the Identifier for the Branch Key that is being rotated/versioned. | ||
.branchKeyIdentifier(branchKeyId) | ||
.build() | ||
); | ||
|
||
return branchKeyId; | ||
} | ||
|
||
public static void main(final String[] args) { | ||
if (args.length <= 1) { | ||
throw new IllegalArgumentException( | ||
"To run this example, include the keyStoreTableName, logicalKeyStoreName, and kmsKeyArn in args" | ||
); | ||
} | ||
final String keyStoreTableName = args[0]; | ||
final String logicalKeyStoreName = args[1]; | ||
final String kmsKeyArn = args[2]; | ||
final String branchKeyId = args[3]; | ||
VersionKey( | ||
keyStoreTableName, | ||
logicalKeyStoreName, | ||
kmsKeyArn, | ||
branchKeyId, | ||
null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.