-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: Preserve error cause in CRT http client TLS and socket timeout failures #7157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+401
−4
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0952ae3
fix: Preserve error cause in CRT http client TLS and socket timeout f…
joviegas 93ce8b0
Updated test cases
joviegas 7ec98b9
handle checkstyle failure
joviegas 40d7174
handle PR comments
joviegas 33389ad
Merge branch 'master' into joviegas/tls-ssl-cause-preserve
joviegas b43a527
Merge branch 'master' into joviegas/tls-ssl-cause-preserve
joviegas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "type": "bugfix", | ||
| "category": "AWS CRT HTTP Client", | ||
| "contributor": "", | ||
| "description": "Preserve the underlying CRT HttpException (including the CRT error code) as the cause of the SSLHandshakeException and ConnectException surfaced for TLS negotiation failures and socket timeouts, so callers can differentiate transient failures from persistent ones by inspecting the exception cause chain." | ||
| } |
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
26 changes: 26 additions & 0 deletions
26
...ient/src/test/java/software/amazon/awssdk/http/apache/ApacheSslHandshakeBehaviorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.http.apache; | ||
|
|
||
| import software.amazon.awssdk.http.SdkHttpClient; | ||
| import software.amazon.awssdk.http.SdkHttpClientSslHandshakeBehaviorTestSuite; | ||
|
|
||
| public class ApacheSslHandshakeBehaviorTest extends SdkHttpClientSslHandshakeBehaviorTestSuite { | ||
| @Override | ||
| protected SdkHttpClient createSdkHttpClient() { | ||
| return ApacheHttpClient.builder().build(); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...nt/src/test/java/software/amazon/awssdk/http/apache5/Apache5SslHandshakeBehaviorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.http.apache5; | ||
|
|
||
| import software.amazon.awssdk.http.SdkHttpClient; | ||
| import software.amazon.awssdk.http.SdkHttpClientSslHandshakeBehaviorTestSuite; | ||
|
|
||
| public class Apache5SslHandshakeBehaviorTest extends SdkHttpClientSslHandshakeBehaviorTestSuite { | ||
| @Override | ||
| protected SdkHttpClient createSdkHttpClient() { | ||
| return Apache5HttpClient.builder().build(); | ||
| } | ||
| } |
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
31 changes: 31 additions & 0 deletions
31
...lient/src/test/java/software/amazon/awssdk/http/crt/CrtAsyncSslHandshakeBehaviorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.http.crt; | ||
|
|
||
| import java.time.Duration; | ||
| import software.amazon.awssdk.http.SdkAsyncHttpClientSslHandshakeBehaviorTestSuite; | ||
| import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
|
|
||
| public class CrtAsyncSslHandshakeBehaviorTest extends SdkAsyncHttpClientSslHandshakeBehaviorTestSuite { | ||
| @Override | ||
| protected SdkAsyncHttpClient createSdkAsyncHttpClient() { | ||
| // CRT negotiates TLS during connection acquisition; the default 10s acquisition timeout can | ||
| // expire first and surface an acquisition-timeout exception instead of SSLHandshakeException. | ||
| return AwsCrtAsyncHttpClient.builder() | ||
| .connectionAcquisitionTimeout(Duration.ofSeconds(30)) | ||
| .build(); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...crt-client/src/test/java/software/amazon/awssdk/http/crt/CrtSslHandshakeBehaviorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.http.crt; | ||
|
|
||
| import java.time.Duration; | ||
| import software.amazon.awssdk.http.SdkHttpClient; | ||
| import software.amazon.awssdk.http.SdkHttpClientSslHandshakeBehaviorTestSuite; | ||
|
|
||
| public class CrtSslHandshakeBehaviorTest extends SdkHttpClientSslHandshakeBehaviorTestSuite { | ||
| @Override | ||
| protected SdkHttpClient createSdkHttpClient() { | ||
| // CRT negotiates TLS during connection acquisition; the default 10s acquisition timeout can | ||
| // expire first and surface an acquisition-timeout exception instead of SSLHandshakeException. | ||
| return AwsCrtHttpClient.builder() | ||
| .connectionAcquisitionTimeout(Duration.ofSeconds(30)) | ||
| .build(); | ||
| } | ||
| } |
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
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
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
26 changes: 26 additions & 0 deletions
26
...nt/src/test/java/software/amazon/awssdk/http/nio/netty/NettySslHandshakeBehaviorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.http.nio.netty; | ||
|
|
||
| import software.amazon.awssdk.http.SdkAsyncHttpClientSslHandshakeBehaviorTestSuite; | ||
| import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
|
|
||
| public class NettySslHandshakeBehaviorTest extends SdkAsyncHttpClientSslHandshakeBehaviorTestSuite { | ||
| @Override | ||
| protected SdkAsyncHttpClient createSdkAsyncHttpClient() { | ||
| return NettyNioAsyncHttpClient.builder().build(); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...java/software/amazon/awssdk/http/urlconnection/UrlConnectionSslHandshakeBehaviorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.http.urlconnection; | ||
|
|
||
| import software.amazon.awssdk.http.SdkHttpClient; | ||
| import software.amazon.awssdk.http.SdkHttpClientSslHandshakeBehaviorTestSuite; | ||
|
|
||
| public class UrlConnectionSslHandshakeBehaviorTest extends SdkHttpClientSslHandshakeBehaviorTestSuite { | ||
| @Override | ||
| protected SdkHttpClient createSdkHttpClient() { | ||
| return UrlConnectionHttpClient.builder().build(); | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
...ain/java/software/amazon/awssdk/http/SdkAsyncHttpClientSslHandshakeBehaviorTestSuite.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.http; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.catchThrowable; | ||
|
|
||
| import com.github.tomakehurst.wiremock.WireMockServer; | ||
| import java.util.concurrent.CompletionException; | ||
| import javax.net.ssl.SSLHandshakeException; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
|
|
||
| /** | ||
| * Validates that a TLS handshake failure against an untrusted (self-signed) certificate surfaces as | ||
| * {@link SSLHandshakeException} with a cause chain, so callers can differentiate transient | ||
| * interruptions from persistent certificate failures. | ||
| */ | ||
| public abstract class SdkAsyncHttpClientSslHandshakeBehaviorTestSuite { | ||
| private WireMockServer selfSignedServer; | ||
|
|
||
| protected abstract SdkAsyncHttpClient createSdkAsyncHttpClient(); | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| selfSignedServer = HttpTestUtils.createSelfSignedServer(); | ||
| selfSignedServer.start(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void teardown() { | ||
| if (selfSignedServer != null) { | ||
| selfSignedServer.stop(); | ||
| selfSignedServer = null; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void sslHandshakeFailure_surfacesAsSslHandshakeException() { | ||
| Throwable thrown = executeRequestAgainstUntrustedServer(); | ||
|
|
||
| assertThat(thrown).isInstanceOf(SSLHandshakeException.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void sslHandshakeFailure_exceptionCarriesDiagnosableCause() { | ||
| Throwable thrown = executeRequestAgainstUntrustedServer(); | ||
|
|
||
| assertThat(thrown).isInstanceOf(SSLHandshakeException.class); | ||
| assertThat(thrown.getCause()) | ||
| .withFailMessage("SSLHandshakeException must chain the underlying failure as its cause " | ||
| + "so callers can differentiate transient from persistent TLS failures. Was: %s", thrown) | ||
| .isNotNull(); | ||
| } | ||
|
|
||
| private Throwable executeRequestAgainstUntrustedServer() { | ||
| try (SdkAsyncHttpClient client = createSdkAsyncHttpClient()) { | ||
| Throwable thrown = catchThrowable( | ||
| () -> HttpTestUtils.sendGetRequest(selfSignedServer.httpsPort(), client, true).join()); | ||
| return thrown instanceof CompletionException ? thrown.getCause() : thrown; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.