-
Notifications
You must be signed in to change notification settings - Fork 910
Add a config option to allow users to enable post quantum TLS support in CRT HTTP client #3727
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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": "feature", | ||
"category": "AWS CRT HTTP Client", | ||
"contributor": "", | ||
"description": "Allow users to enable Post Quantum TLS via `AwsCrtAsyncHttpClient.builder().postQuantumTlsEnabled(true).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
113 changes: 113 additions & 0 deletions
113
...ient/src/main/java/software/amazon/awssdk/http/crt/internal/AwsCrtConfigurationUtils.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,113 @@ | ||
/* | ||
* 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.internal; | ||
|
||
|
||
import java.time.Duration; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
import software.amazon.awssdk.crt.http.HttpMonitoringOptions; | ||
import software.amazon.awssdk.crt.http.HttpProxyOptions; | ||
import software.amazon.awssdk.crt.io.SocketOptions; | ||
import software.amazon.awssdk.crt.io.TlsCipherPreference; | ||
import software.amazon.awssdk.crt.io.TlsContext; | ||
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient; | ||
import software.amazon.awssdk.http.crt.ConnectionHealthConfiguration; | ||
import software.amazon.awssdk.http.crt.ProxyConfiguration; | ||
import software.amazon.awssdk.http.crt.TcpKeepAliveConfiguration; | ||
import software.amazon.awssdk.utils.Logger; | ||
import software.amazon.awssdk.utils.NumericUtils; | ||
|
||
@SdkInternalApi | ||
public final class AwsCrtConfigurationUtils { | ||
private static final Logger log = Logger.loggerFor(AwsCrtAsyncHttpClient.class); | ||
|
||
private AwsCrtConfigurationUtils() { | ||
} | ||
|
||
public static SocketOptions buildSocketOptions(TcpKeepAliveConfiguration tcpKeepAliveConfiguration, | ||
Duration connectionTimeout) { | ||
SocketOptions clientSocketOptions = new SocketOptions(); | ||
|
||
if (connectionTimeout != null) { | ||
clientSocketOptions.connectTimeoutMs = NumericUtils.saturatedCast(connectionTimeout.toMillis()); | ||
} | ||
|
||
if (tcpKeepAliveConfiguration != null) { | ||
clientSocketOptions.keepAliveIntervalSecs = | ||
NumericUtils.saturatedCast(tcpKeepAliveConfiguration.keepAliveInterval().getSeconds()); | ||
clientSocketOptions.keepAliveTimeoutSecs = | ||
NumericUtils.saturatedCast(tcpKeepAliveConfiguration.keepAliveTimeout().getSeconds()); | ||
|
||
} | ||
|
||
return clientSocketOptions; | ||
} | ||
|
||
public static HttpProxyOptions buildProxyOptions(ProxyConfiguration proxyConfiguration, TlsContext tlsContext) { | ||
if (proxyConfiguration == null) { | ||
return null; | ||
} | ||
|
||
HttpProxyOptions clientProxyOptions = new HttpProxyOptions(); | ||
|
||
clientProxyOptions.setHost(proxyConfiguration.host()); | ||
clientProxyOptions.setPort(proxyConfiguration.port()); | ||
|
||
if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) { | ||
clientProxyOptions.setTlsContext(tlsContext); | ||
} | ||
|
||
if (proxyConfiguration.username() != null && proxyConfiguration.password() != null) { | ||
clientProxyOptions.setAuthorizationUsername(proxyConfiguration.username()); | ||
clientProxyOptions.setAuthorizationPassword(proxyConfiguration.password()); | ||
clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic); | ||
} else { | ||
clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.None); | ||
} | ||
|
||
return clientProxyOptions; | ||
} | ||
|
||
public static HttpMonitoringOptions resolveHttpMonitoringOptions(ConnectionHealthConfiguration config) { | ||
if (config == null) { | ||
return null; | ||
} | ||
|
||
HttpMonitoringOptions httpMonitoringOptions = new HttpMonitoringOptions(); | ||
httpMonitoringOptions.setMinThroughputBytesPerSecond(config.minimumThroughputInBps()); | ||
int seconds = (int) config.minimumThroughputTimeout().getSeconds(); | ||
httpMonitoringOptions.setAllowableThroughputFailureIntervalSeconds(seconds); | ||
return httpMonitoringOptions; | ||
} | ||
|
||
public static TlsCipherPreference resolveCipherPreference(Boolean postQuantumTlsEnabled) { | ||
TlsCipherPreference defaultTls = TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT; | ||
if (postQuantumTlsEnabled == null || !postQuantumTlsEnabled) { | ||
return defaultTls; | ||
} | ||
|
||
// TODO: change this to the new PQ TLS Policy that stays up to date when it's ready | ||
TlsCipherPreference pqTls = TlsCipherPreference.TLS_CIPHER_PREF_PQ_TLSv1_0_2021_05; | ||
if (!pqTls.isSupported()) { | ||
log.warn(() -> "Hybrid post-quantum cipher suites are not supported on this platform. The SDK will use the system " | ||
+ "default cipher suites instead"); | ||
return defaultTls; | ||
} | ||
|
||
return pqTls; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
.../src/test/java/software/amazon/awssdk/http/crt/internal/AwsCrtConfigurationUtilsTest.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,54 @@ | ||
/* | ||
* 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.internal; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static software.amazon.awssdk.crt.io.TlsCipherPreference.TLS_CIPHER_PREF_PQ_TLSv1_0_2021_05; | ||
import static software.amazon.awssdk.crt.io.TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import software.amazon.awssdk.crt.io.TlsCipherPreference; | ||
|
||
class AwsCrtConfigurationUtilsTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("cipherPreferences") | ||
void resolveCipherPreference_pqNotSupported_shouldFallbackToSystemDefault(Boolean preferPqTls, | ||
TlsCipherPreference tlsCipherPreference) { | ||
Assumptions.assumeFalse(TLS_CIPHER_PREF_PQ_TLSv1_0_2021_05.isSupported()); | ||
assertThat(AwsCrtConfigurationUtils.resolveCipherPreference(preferPqTls)).isEqualTo(tlsCipherPreference); | ||
} | ||
|
||
@Test | ||
void resolveCipherPreference_pqSupported_shouldHonor() { | ||
Assumptions.assumeTrue(TLS_CIPHER_PREF_PQ_TLSv1_0_2021_05.isSupported()); | ||
assertThat(AwsCrtConfigurationUtils.resolveCipherPreference(true)).isEqualTo(TLS_CIPHER_PREF_PQ_TLSv1_0_2021_05); | ||
} | ||
|
||
private static Stream<Arguments> cipherPreferences() { | ||
return Stream.of( | ||
Arguments.of(null, TLS_CIPHER_SYSTEM_DEFAULT), | ||
Arguments.of(false, TLS_CIPHER_SYSTEM_DEFAULT), | ||
Arguments.of(true, TLS_CIPHER_SYSTEM_DEFAULT) | ||
); | ||
} | ||
|
||
} |
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.
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.
No changes have been made to these methods. I just moved them to the new class.
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.
gotcha