-
Notifications
You must be signed in to change notification settings - Fork 10
Migrate to AWS SDK v2 #21
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a backward incompatible change, please also bump up the major version in this file. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ java { | |
| withSourcesJar() | ||
| } | ||
|
|
||
| tasks.withType(JavaCompile) { | ||
| tasks.withType(JavaCompile).configureEach { | ||
| options.encoding = 'UTF-8' | ||
| } | ||
|
|
||
|
|
@@ -32,13 +32,15 @@ dependencies { | |
| api 'com.nimbusds:nimbus-jose-jwt:[9,9.31]' | ||
|
|
||
| // These dependencies is used internally, and not exposed to consumers on their own compile classpath. | ||
| implementation 'com.amazonaws:aws-java-sdk-kms:[1.12, 2)' | ||
| implementation 'commons-cli:commons-cli:[1.4, 2)' | ||
| implementation 'software.amazon.awssdk:kms:2.30.18' | ||
| implementation 'commons-cli:commons-cli:1.9.0' | ||
| implementation 'commons-codec:commons-codec:1.18.0' | ||
|
Comment on lines
+35
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using exact versions, can we use ranges here? |
||
| implementation 'com.google.guava:guava:[32,)' | ||
|
|
||
| // Use JUnit Jupiter for testing. | ||
| testImplementation 'org.junit.jupiter:junit-jupiter:5.+' | ||
| testImplementation 'org.assertj:assertj-core:[3,4)' | ||
| testImplementation 'org.junit.platform:junit-platform-launcher:1.11.4' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? Usually we shouldn't use the junit-platform-* dependencies directly. |
||
|
|
||
| // Mockito | ||
| testImplementation 'org.mockito:mockito-core:[3,4)' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,28 +17,20 @@ | |
| package com.nimbusds.jose.aws.kms.crypto; | ||
|
|
||
|
|
||
| import com.amazonaws.services.kms.AWSKMS; | ||
| import com.amazonaws.services.kms.model.DependencyTimeoutException; | ||
| import com.amazonaws.services.kms.model.DisabledException; | ||
| import com.amazonaws.services.kms.model.InvalidGrantTokenException; | ||
| import com.amazonaws.services.kms.model.InvalidKeyUsageException; | ||
| import com.amazonaws.services.kms.model.KMSInternalException; | ||
| import com.amazonaws.services.kms.model.KMSInvalidStateException; | ||
| import com.amazonaws.services.kms.model.KeyUnavailableException; | ||
| import com.amazonaws.services.kms.model.MessageType; | ||
| import com.amazonaws.services.kms.model.NotFoundException; | ||
| import com.amazonaws.services.kms.model.SignRequest; | ||
| import com.amazonaws.services.kms.model.SignResult; | ||
| import com.nimbusds.jose.JOSEException; | ||
| import com.nimbusds.jose.JWSHeader; | ||
| import com.nimbusds.jose.JWSSigner; | ||
| import com.nimbusds.jose.RemoteKeySourceException; | ||
| import com.nimbusds.jose.aws.kms.crypto.impl.KmsAsymmetricSigningCryptoProvider; | ||
| import com.nimbusds.jose.aws.kms.exceptions.TemporaryJOSEException; | ||
| import com.nimbusds.jose.util.Base64URL; | ||
| import javax.annotation.concurrent.ThreadSafe; | ||
| import lombok.NonNull; | ||
| import lombok.var; | ||
| import software.amazon.awssdk.core.SdkBytes; | ||
| import software.amazon.awssdk.services.kms.KmsClient; | ||
| import software.amazon.awssdk.services.kms.model.*; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid using * imports in source files. |
||
|
|
||
| import javax.annotation.concurrent.ThreadSafe; | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -51,28 +43,29 @@ | |
| public class KmsAsymmetricSigner extends KmsAsymmetricSigningCryptoProvider implements JWSSigner { | ||
|
|
||
| public KmsAsymmetricSigner( | ||
| @NonNull final AWSKMS kms, @NonNull final String privateKeyId, @NonNull final MessageType messageType) { | ||
| @NonNull final KmsClient kms, @NonNull final String privateKeyId, @NonNull final MessageType messageType) { | ||
| super(kms, privateKeyId, messageType); | ||
| } | ||
|
|
||
| @Override | ||
| public Base64URL sign(@NonNull final JWSHeader header, @NonNull final byte[] signingInput) throws JOSEException { | ||
|
|
||
| final var message = getMessage(header, signingInput); | ||
| SignResult signResult; | ||
| SignResponse signResponse; | ||
| try { | ||
| signResult = getKms().sign(new SignRequest() | ||
| .withKeyId(getPrivateKeyId()) | ||
| .withMessageType(getMessageType()) | ||
| .withMessage(message) | ||
| .withSigningAlgorithm(JWS_ALGORITHM_TO_SIGNING_ALGORITHM_SPEC.get(header.getAlgorithm()).toString())); | ||
| signResponse = getKms().sign(SignRequest.builder() | ||
| .keyId(getPrivateKeyId()) | ||
| .messageType(getMessageType()) | ||
| .message(SdkBytes.fromByteBuffer(message)) | ||
| .signingAlgorithm(JWS_ALGORITHM_TO_SIGNING_ALGORITHM_SPEC.get(header.getAlgorithm()).toString()) | ||
| .build()); | ||
| } catch (NotFoundException | DisabledException | KeyUnavailableException | InvalidKeyUsageException | ||
| | KMSInvalidStateException e) { | ||
| | KmsInvalidStateException e) { | ||
| throw new RemoteKeySourceException("An exception was thrown from KMS due to invalid key.", e); | ||
| } catch (DependencyTimeoutException | InvalidGrantTokenException | KMSInternalException e) { | ||
| } catch (DependencyTimeoutException | InvalidGrantTokenException | KmsInternalException e) { | ||
| throw new TemporaryJOSEException("A temporary exception was thrown from KMS.", e); | ||
| } | ||
|
|
||
| return Base64URL.encode(signResult.getSignature().array()); | ||
| return Base64URL.encode(signResponse.signature().asByteArray()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an unnecessary change and should be avoided.