Skip to content

Commit 234f08c

Browse files
authored
Add TrustAllCertificates in CRT S3 Client options (#3903)
* Add TrustAllCertificates in CRT S3 Client options * Handled PR comments
1 parent c6c9d6a commit 234f08c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "API to Add TrustAllCertificates in CRT S3 Client options for test purposes"
6+
}

services/s3/src/main/java/software/amazon/awssdk/services/s3/crt/S3CrtHttpConfiguration.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public final class S3CrtHttpConfiguration implements ToCopyableBuilder<S3CrtHttp
3838
private final Duration connectionTimeout;
3939
private final S3CrtProxyConfiguration proxyConfiguration;
4040
private final S3CrtConnectionHealthConfiguration healthConfiguration;
41+
private final Boolean trustAllCertificatesEnabled;
4142

4243
private S3CrtHttpConfiguration(DefaultBuilder builder) {
4344
this.connectionTimeout = builder.connectionTimeout;
4445
this.proxyConfiguration = builder.proxyConfiguration;
4546
this.healthConfiguration = builder.healthConfiguration;
47+
this.trustAllCertificatesEnabled = builder.trustAllCertificatesEnabled;
4648
}
4749

4850
/**
@@ -73,6 +75,13 @@ public S3CrtConnectionHealthConfiguration healthConfiguration() {
7375
return healthConfiguration;
7476
}
7577

78+
/**
79+
* Return the configured {@link Builder#trustAllCertificatesEnabled}.
80+
*/
81+
public Boolean trustAllCertificatesEnabled() {
82+
return trustAllCertificatesEnabled;
83+
}
84+
7685
@Override
7786
public boolean equals(Object o) {
7887
if (this == o) {
@@ -90,14 +99,18 @@ public boolean equals(Object o) {
9099
if (!Objects.equals(proxyConfiguration, that.proxyConfiguration)) {
91100
return false;
92101
}
93-
return Objects.equals(healthConfiguration, that.healthConfiguration);
102+
if (!Objects.equals(healthConfiguration, that.healthConfiguration)) {
103+
return false;
104+
}
105+
return Objects.equals(trustAllCertificatesEnabled, that.trustAllCertificatesEnabled);
94106
}
95107

96108
@Override
97109
public int hashCode() {
98110
int result = connectionTimeout != null ? connectionTimeout.hashCode() : 0;
99111
result = 31 * result + (proxyConfiguration != null ? proxyConfiguration.hashCode() : 0);
100112
result = 31 * result + (healthConfiguration != null ? healthConfiguration.hashCode() : 0);
113+
result = 31 * result + (trustAllCertificatesEnabled != null ? trustAllCertificatesEnabled.hashCode() : 0);
101114
return result;
102115
}
103116

@@ -115,6 +128,18 @@ public interface Builder extends CopyableBuilder<S3CrtHttpConfiguration.Builder,
115128
*/
116129
Builder connectionTimeout(Duration connectionTimeout);
117130

131+
132+
/**
133+
* <p>
134+
* Option to disable SSL cert validation and SSL host name verification.
135+
* This turns off x.509 validation.
136+
* By default, this option is off.
137+
* Only enable this option for testing purposes.
138+
* @param trustAllCertificatesEnabled True if SSL cert validation is disabled.
139+
* @return The builder of the method chaining.
140+
*/
141+
Builder trustAllCertificatesEnabled(Boolean trustAllCertificatesEnabled);
142+
118143
/**
119144
* Sets the http proxy configuration to use for this client.
120145
*
@@ -165,6 +190,7 @@ Builder connectionHealthConfiguration(Consumer<S3CrtConnectionHealthConfiguratio
165190
private static final class DefaultBuilder implements Builder {
166191
private S3CrtConnectionHealthConfiguration healthConfiguration;
167192
private Duration connectionTimeout;
193+
private Boolean trustAllCertificatesEnabled;
168194
private S3CrtProxyConfiguration proxyConfiguration;
169195

170196
private DefaultBuilder() {
@@ -174,6 +200,7 @@ private DefaultBuilder(S3CrtHttpConfiguration httpConfiguration) {
174200
this.healthConfiguration = httpConfiguration.healthConfiguration;
175201
this.connectionTimeout = httpConfiguration.connectionTimeout;
176202
this.proxyConfiguration = httpConfiguration.proxyConfiguration;
203+
this.trustAllCertificatesEnabled = httpConfiguration.trustAllCertificatesEnabled;
177204
}
178205

179206
@Override
@@ -182,6 +209,12 @@ public Builder connectionTimeout(Duration connectionTimeout) {
182209
return this;
183210
}
184211

212+
@Override
213+
public Builder trustAllCertificatesEnabled(Boolean trustAllCertificatesEnabled) {
214+
this.trustAllCertificatesEnabled = trustAllCertificatesEnabled;
215+
return this;
216+
}
217+
185218
@Override
186219
public Builder proxyConfiguration(S3CrtProxyConfiguration proxyConfiguration) {
187220
this.proxyConfiguration = proxyConfiguration;

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/S3NativeClientConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import software.amazon.awssdk.crt.io.TlsContextOptions;
3434
import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain;
3535
import software.amazon.awssdk.services.s3.crt.S3CrtHttpConfiguration;
36+
import software.amazon.awssdk.utils.Logger;
3637
import software.amazon.awssdk.utils.SdkAutoCloseable;
3738

3839
/**
@@ -41,6 +42,7 @@
4142
@SdkInternalApi
4243
public class S3NativeClientConfiguration implements SdkAutoCloseable {
4344
static final long DEFAULT_PART_SIZE_IN_BYTES = 8L * 1024 * 1024;
45+
private static final Logger log = Logger.loggerFor(S3NativeClientConfiguration.class);
4446
private static final long DEFAULT_TARGET_THROUGHPUT_IN_GBPS = 10;
4547

4648
private final String signingRegion;
@@ -67,6 +69,13 @@ public S3NativeClientConfiguration(Builder builder) {
6769
TlsContextOptions clientTlsContextOptions =
6870
TlsContextOptions.createDefaultClient()
6971
.withCipherPreference(TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT);
72+
73+
if (builder.httpConfiguration != null
74+
&& builder.httpConfiguration.trustAllCertificatesEnabled() != null) {
75+
log.warn(() -> "SSL Certificate verification is disabled. "
76+
+ "This is not a safe setting and should only be used for testing.");
77+
clientTlsContextOptions.withVerifyPeer(!builder.httpConfiguration.trustAllCertificatesEnabled());
78+
}
7079
this.tlsContext = new TlsContext(clientTlsContextOptions);
7180
this.credentialProviderAdapter =
7281
builder.credentialsProvider == null ?
@@ -175,6 +184,7 @@ public static final class Builder {
175184
private Integer maxConcurrency;
176185
private URI endpointOverride;
177186
private Boolean checksumValidationEnabled;
187+
178188
private S3CrtHttpConfiguration httpConfiguration;
179189
private StandardRetryOptions standardRetryOptions;
180190

0 commit comments

Comments
 (0)