Skip to content

Commit 721cf44

Browse files
zoewanggbsmelo
andauthored
Only log SSL Certificate verification being disabled warrning when it's actually disabled (#6766)
* Fix: Warn about SSL Certificate verification being disabled only when it's actually disabled Only Boolean.TRUE disables SSL Certificate Validation, so both Boolean.FALSE and null should skip the warning message * Add tests and changelog entry * Address feedback --------- Co-authored-by: Bruno Melo <bsilva.melo@gmail.com>
1 parent 81f7973 commit 721cf44

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS CRT-based S3 Client",
4+
"contributor": "bsmelo",
5+
"description": "Only log `SSL Certificate verification is disabled` warning if trustAllCertificatesEnabled is set to true."
6+
}

services/s3/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@
129129
<version>${awsjavasdk.version}</version>
130130
</dependency>
131131
<!-- Test Dependencies -->
132+
<dependency>
133+
<groupId>software.amazon.awssdk</groupId>
134+
<artifactId>test-utils</artifactId>
135+
<version>${awsjavasdk.version}</version>
136+
<scope>test</scope>
137+
</dependency>
132138
<dependency>
133139
<artifactId>commons-io</artifactId>
134140
<groupId>commons-io</groupId>

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ public S3NativeClientConfiguration(Builder builder) {
7676
TlsContextOptions.createDefaultClient()
7777
.withCipherPreference(TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT);
7878

79-
if (builder.httpConfiguration != null
80-
&& builder.httpConfiguration.trustAllCertificatesEnabled() != null) {
81-
log.warn(() -> "SSL Certificate verification is disabled. "
82-
+ "This is not a safe setting and should only be used for testing.");
83-
clientTlsContextOptions.withVerifyPeer(!builder.httpConfiguration.trustAllCertificatesEnabled());
79+
if (builder.httpConfiguration != null &&
80+
builder.httpConfiguration.trustAllCertificatesEnabled() != null) {
81+
Boolean trustAllCertificatesEnabled = builder.httpConfiguration.trustAllCertificatesEnabled();
82+
if (Boolean.TRUE.equals(trustAllCertificatesEnabled)) {
83+
log.warn(() -> "SSL Certificate verification is disabled. "
84+
+ "This is not a safe setting and should only be used for testing.");
85+
}
86+
clientTlsContextOptions.withVerifyPeer(!trustAllCertificatesEnabled);
8487
}
8588
this.tlsContext = new TlsContext(clientTlsContextOptions);
8689
this.credentialProviderAdapter = new CrtCredentialsProviderAdapter(
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.internal.crt;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import java.util.stream.Stream;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.Arguments;
24+
import org.junit.jupiter.params.provider.MethodSource;
25+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
26+
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
27+
import software.amazon.awssdk.services.s3.crt.S3CrtHttpConfiguration;
28+
import software.amazon.awssdk.testutils.LogCaptor;
29+
30+
class S3NativeClientConfigurationTest {
31+
32+
private static final String SSL_WARNING = "SSL Certificate verification is disabled.";
33+
34+
@Test
35+
void build_whenTrustAllCertificatesTrue_shouldLogWarning() {
36+
try (LogCaptor logCaptor = LogCaptor.create();
37+
S3NativeClientConfiguration config = buildConfig(
38+
S3CrtHttpConfiguration.builder().trustAllCertificatesEnabled(true).build())) {
39+
40+
assertThat(logCaptor.loggedEvents())
41+
.anySatisfy(event -> assertThat(event.getMessage().getFormattedMessage()).contains(SSL_WARNING));
42+
}
43+
}
44+
45+
@ParameterizedTest
46+
@MethodSource("noWarningConfigurations")
47+
void build_whenTrustAllCertificatesNotTrue_shouldNotLogWarning(S3CrtHttpConfiguration httpConfig) {
48+
try (LogCaptor logCaptor = LogCaptor.create();
49+
S3NativeClientConfiguration config = buildConfig(httpConfig)) {
50+
51+
assertThat(logCaptor.loggedEvents())
52+
.noneSatisfy(event -> assertThat(event.getMessage().getFormattedMessage()).contains(SSL_WARNING));
53+
}
54+
}
55+
56+
private static Stream<Arguments> noWarningConfigurations() {
57+
return Stream.of(
58+
Arguments.of(S3CrtHttpConfiguration.builder().trustAllCertificatesEnabled(false).build()),
59+
Arguments.of(S3CrtHttpConfiguration.builder().build()),
60+
Arguments.of((S3CrtHttpConfiguration) null)
61+
);
62+
}
63+
64+
private S3NativeClientConfiguration buildConfig(S3CrtHttpConfiguration httpConfig) {
65+
S3NativeClientConfiguration.Builder builder =
66+
S3NativeClientConfiguration.builder()
67+
.signingRegion("us-east-1")
68+
.credentialsProvider(
69+
StaticCredentialsProvider.create(
70+
AwsBasicCredentials.create("foo", "bar")));
71+
if (httpConfig != null) {
72+
builder.httpConfiguration(httpConfig);
73+
}
74+
return builder.build();
75+
}
76+
}

0 commit comments

Comments
 (0)