Translate CompletionException to GeneralSecurityException in AwsKmsAead - #7
Open
stevenwarejones wants to merge 3 commits into
Open
Translate CompletionException to GeneralSecurityException in AwsKmsAead#7stevenwarejones wants to merge 3 commits into
stevenwarejones wants to merge 3 commits into
Conversation
AwsKmsAead.encrypt/decrypt only catch SdkClientException and KmsException, but the AWS SDK's internal synchronous credential resolution (AwsCredentialsAuthorizationStrategy -> CompletableFutureUtils.joinLikeSync) leaves a failed future's CompletionException wrapped, rather than unwrapping it, whenever its cause is not itself a RuntimeException -- which is exactly what happens when a credentials provider fails with a checked exception. That CompletionException then escapes encrypt/decrypt uncaught, breaking the Aead contract that only GeneralSecurityException is thrown. Fixes tink-crypto#5
stevenwarejones
force-pushed
the
fix-completion-exception-leak
branch
from
August 20, 2026 15:10
6cc7987 to
bc303e3
Compare
Author
Only wrap a CompletionException in GeneralSecurityException when its cause is a checked exception -- the one specific shape AWS SDK v2s internal synchronous credential resolution can leave wrapped (AwsCredentialsAuthorizationStrategy -> CompletableFutureUtils.joinLikeSync only unwraps RuntimeException causes). A null, RuntimeException, or Error cause means this is not that shape, so the CompletionException itself is rethrown unchanged instead of being unwrapped or otherwise guessed at. Adds tests proving a checked cause is translated, and that CompletionException wrapping a RuntimeException, an Error, or nothing all propagate unchanged.
…anslated The existing checked-cause test only used GeneralSecurityException. Adds an IOException case to make explicit that any checked exception is translated, not just GeneralSecurityException specifically.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5.
AwsKmsAead.encrypt/decryptonly catchSdkClientException | KmsException, but the AWS SDK's internal synchronous credential resolution (AwsCredentialsAuthorizationStrategy.resolveCredentials->identityProvider.resolveIdentity()->CompletableFutureUtils.joinLikeSync) leaves a failed future'sCompletionExceptionwrapped -- rather than unwrapping it to the cause -- whenever that cause is not itself aRuntimeException. A credentials provider that legitimately fails credential resolution with a checked exception (e.g. a failed STS call wrapped asGeneralSecurityException) therefore surfaces as a rawCompletionExceptionout ofencrypt/decryptinstead of preserving the declared checked-failure path (GeneralSecurityException) these methods otherwise honor.This adds a
catch (CompletionException e)to both methods that translates a checked-exception cause into a newGeneralSecurityException, consistent with the existingSdkClientException/KmsExceptionhandling. Anull,RuntimeException, orErrorcause means this isn't that shape, so theCompletionExceptionitself is rethrown unchanged rather than being unwrapped or otherwise guessed at.Added regression tests covering both methods: a checked cause (
GeneralSecurityException, and separatelyIOExceptionto confirm this isn't specific to one checked type) is translated; aRuntimeExceptioncause, anErrorcause, and a causelessCompletionExceptionall propagate unchanged. Verified each new case fails without this change and passes with it.Downstream impact: common-jvm#399 wraps this library's client in
CompletionExceptionTranslatingKmsClient, whose only job is to translate this specificCompletionExceptionleak. A release containing this fix will let that wrapper be deleted entirely.