17
17
18
18
import static software .amazon .awssdk .http .HttpMetric .HTTP_CLIENT_NAME ;
19
19
import static software .amazon .awssdk .http .SdkHttpConfigurationOption .PROTOCOL ;
20
+ import static software .amazon .awssdk .http .crt .internal .AwsCrtConfigurationUtils .buildProxyOptions ;
21
+ import static software .amazon .awssdk .http .crt .internal .AwsCrtConfigurationUtils .buildSocketOptions ;
22
+ import static software .amazon .awssdk .http .crt .internal .AwsCrtConfigurationUtils .resolveCipherPreference ;
23
+ import static software .amazon .awssdk .http .crt .internal .AwsCrtConfigurationUtils .resolveHttpMonitoringOptions ;
20
24
import static software .amazon .awssdk .utils .FunctionalUtils .invokeSafely ;
21
25
import static software .amazon .awssdk .utils .Validate .paramNotNull ;
22
26
36
40
import software .amazon .awssdk .crt .http .HttpProxyOptions ;
37
41
import software .amazon .awssdk .crt .io .ClientBootstrap ;
38
42
import software .amazon .awssdk .crt .io .SocketOptions ;
39
- import software .amazon .awssdk .crt .io .TlsCipherPreference ;
40
43
import software .amazon .awssdk .crt .io .TlsContext ;
41
44
import software .amazon .awssdk .crt .io .TlsContextOptions ;
42
45
import software .amazon .awssdk .http .Protocol ;
@@ -97,10 +100,11 @@ private AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) {
97
100
}
98
101
99
102
try (ClientBootstrap clientBootstrap = new ClientBootstrap (null , null );
100
- SocketOptions clientSocketOptions = buildSocketOptions (builder , config );
103
+ SocketOptions clientSocketOptions = buildSocketOptions (builder .tcpKeepAliveConfiguration ,
104
+ config .get (SdkHttpConfigurationOption .CONNECTION_TIMEOUT ));
101
105
TlsContextOptions clientTlsContextOptions =
102
106
TlsContextOptions .createDefaultClient ()
103
- .withCipherPreference (TlsCipherPreference . TLS_CIPHER_SYSTEM_DEFAULT )
107
+ .withCipherPreference (resolveCipherPreference ( builder . postQuantumTlsEnabled ) )
104
108
.withVerifyPeer (!config .get (SdkHttpConfigurationOption .TRUST_ALL_CERTIFICATES ));
105
109
TlsContext clientTlsContext = new TlsContext (clientTlsContextOptions )) {
106
110
@@ -109,69 +113,12 @@ private AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) {
109
113
this .tlsContext = registerOwnedResource (clientTlsContext );
110
114
this .readBufferSize = builder .readBufferSize == null ? DEFAULT_STREAM_WINDOW_SIZE : builder .readBufferSize ;
111
115
this .maxConnectionsPerEndpoint = config .get (SdkHttpConfigurationOption .MAX_CONNECTIONS );
112
- this .monitoringOptions = revolveHttpMonitoringOptions (builder .connectionHealthConfiguration );
116
+ this .monitoringOptions = resolveHttpMonitoringOptions (builder .connectionHealthConfiguration );
113
117
this .maxConnectionIdleInMilliseconds = config .get (SdkHttpConfigurationOption .CONNECTION_MAX_IDLE_TIMEOUT ).toMillis ();
114
- this .proxyOptions = buildProxyOptions (builder .proxyConfiguration );
118
+ this .proxyOptions = buildProxyOptions (builder .proxyConfiguration , tlsContext );
115
119
}
116
120
}
117
121
118
- private HttpMonitoringOptions revolveHttpMonitoringOptions (ConnectionHealthConfiguration config ) {
119
- if (config == null ) {
120
- return null ;
121
- }
122
-
123
- HttpMonitoringOptions httpMonitoringOptions = new HttpMonitoringOptions ();
124
- httpMonitoringOptions .setMinThroughputBytesPerSecond (config .minimumThroughputInBps ());
125
- int seconds = (int ) config .minimumThroughputTimeout ().getSeconds ();
126
- httpMonitoringOptions .setAllowableThroughputFailureIntervalSeconds (seconds );
127
- return httpMonitoringOptions ;
128
- }
129
-
130
- private HttpProxyOptions buildProxyOptions (ProxyConfiguration proxyConfiguration ) {
131
- if (proxyConfiguration == null ) {
132
- return null ;
133
- }
134
-
135
- HttpProxyOptions clientProxyOptions = new HttpProxyOptions ();
136
-
137
- clientProxyOptions .setHost (proxyConfiguration .host ());
138
- clientProxyOptions .setPort (proxyConfiguration .port ());
139
-
140
- if ("https" .equalsIgnoreCase (proxyConfiguration .scheme ())) {
141
- clientProxyOptions .setTlsContext (tlsContext );
142
- }
143
-
144
- if (proxyConfiguration .username () != null && proxyConfiguration .password () != null ) {
145
- clientProxyOptions .setAuthorizationUsername (proxyConfiguration .username ());
146
- clientProxyOptions .setAuthorizationPassword (proxyConfiguration .password ());
147
- clientProxyOptions .setAuthorizationType (HttpProxyOptions .HttpProxyAuthorizationType .Basic );
148
- } else {
149
- clientProxyOptions .setAuthorizationType (HttpProxyOptions .HttpProxyAuthorizationType .None );
150
- }
151
-
152
- return clientProxyOptions ;
153
- }
154
-
155
- private SocketOptions buildSocketOptions (DefaultBuilder builder , AttributeMap config ) {
156
- SocketOptions clientSocketOptions = new SocketOptions ();
157
-
158
- Duration connectionTimeout = config .get (SdkHttpConfigurationOption .CONNECTION_TIMEOUT );
159
- if (connectionTimeout != null ) {
160
- clientSocketOptions .connectTimeoutMs = NumericUtils .saturatedCast (connectionTimeout .toMillis ());
161
- }
162
-
163
- TcpKeepAliveConfiguration tcpKeepAliveConfiguration = builder .tcpKeepAliveConfiguration ;
164
- if (tcpKeepAliveConfiguration != null ) {
165
- clientSocketOptions .keepAliveIntervalSecs =
166
- NumericUtils .saturatedCast (tcpKeepAliveConfiguration .keepAliveInterval ().getSeconds ());
167
- clientSocketOptions .keepAliveTimeoutSecs =
168
- NumericUtils .saturatedCast (tcpKeepAliveConfiguration .keepAliveTimeout ().getSeconds ());
169
-
170
- }
171
-
172
- return clientSocketOptions ;
173
- }
174
-
175
122
/**
176
123
* Marks a Native CrtResource as owned by the current Java Object.
177
124
*
@@ -418,6 +365,22 @@ Builder connectionHealthConfiguration(Consumer<ConnectionHealthConfiguration.Bui
418
365
*/
419
366
Builder tcpKeepAliveConfiguration (Consumer <TcpKeepAliveConfiguration .Builder >
420
367
tcpKeepAliveConfigurationBuilder );
368
+
369
+ /**
370
+ * Configure whether to enable a hybrid post-quantum key exchange option for the Transport Layer Security (TLS) network
371
+ * encryption protocol when communicating with services that support Post Quantum TLS. If Post Quantum cipher suites are
372
+ * not supported on the platform, the SDK will use the default TLS cipher suites.
373
+ *
374
+ * <p>
375
+ * See <a href="https://docs.aws.amazon.com/kms/latest/developerguide/pqtls.html">Using hybrid post-quantum TLS with AWS KMS</a>
376
+ *
377
+ * <p>
378
+ * It's disabled by default.
379
+ *
380
+ * @param postQuantumTlsEnabled whether to prefer Post Quantum TLS
381
+ * @return The builder of the method chaining.
382
+ */
383
+ Builder postQuantumTlsEnabled (Boolean postQuantumTlsEnabled );
421
384
}
422
385
423
386
/**
@@ -430,6 +393,7 @@ private static final class DefaultBuilder implements Builder {
430
393
private ProxyConfiguration proxyConfiguration ;
431
394
private ConnectionHealthConfiguration connectionHealthConfiguration ;
432
395
private TcpKeepAliveConfiguration tcpKeepAliveConfiguration ;
396
+ private Boolean postQuantumTlsEnabled ;
433
397
434
398
private DefaultBuilder () {
435
399
}
@@ -509,6 +473,12 @@ public Builder tcpKeepAliveConfiguration(Consumer<TcpKeepAliveConfiguration.Buil
509
473
return tcpKeepAliveConfiguration (builder .build ());
510
474
}
511
475
476
+ @ Override
477
+ public Builder postQuantumTlsEnabled (Boolean postQuantumTlsEnabled ) {
478
+ this .postQuantumTlsEnabled = postQuantumTlsEnabled ;
479
+ return this ;
480
+ }
481
+
512
482
@ Override
513
483
public Builder proxyConfiguration (Consumer <ProxyConfiguration .Builder > proxyConfigurationBuilderConsumer ) {
514
484
ProxyConfiguration .Builder builder = ProxyConfiguration .builder ();
0 commit comments