Skip to content

Commit 0050ab1

Browse files
committed
Simplifying TLS error detection
1 parent 4938412 commit 0050ab1

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

driver-core/src/main/com/mongodb/internal/connection/BackpressureErrorLabeler.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,8 @@ private static boolean isTlsConfigurationError(final MongoSocketException t) {
8282
}
8383
if (cause instanceof SSLHandshakeException) {
8484
String message = cause.getMessage();
85-
if (message != null) {
86-
String lowerMessage = message.toLowerCase(Locale.ROOT);
87-
if (lowerMessage.contains("certificate")
88-
|| lowerMessage.contains("verify")
89-
|| lowerMessage.contains("trust")
90-
|| lowerMessage.contains("hostname")
91-
|| lowerMessage.contains("protocol")
92-
|| lowerMessage.contains("cipher")
93-
// PKIX path building/validation failures surface as SSLHandshakeException
94-
// when the underlying CertPath* cause is not in the chain.
95-
|| lowerMessage.contains("pkix")
96-
// Any "Received fatal alert: X" from OpenJDK's JSSE provider means the
97-
// server actively answered with a TLS protocol error — not an overload
98-
// signal. Catches all 25 RFC handshake alert descriptions in one rule.
99-
|| lowerMessage.contains("received fatal alert")) {
100-
return true;
101-
}
85+
if (message != null && message.toLowerCase(Locale.ROOT).contains("received fatal alert")) {
86+
return true;
10287
}
10388
}
10489
cause = cause.getCause();

driver-core/src/test/unit/com/mongodb/internal/connection/BackpressureErrorLabelerTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,16 @@ static Stream<Named<Throwable>> localTlsConfigErrorShouldNotBeLabeled() {
8787
named(new CertPathValidatorException("validation failed")),
8888
named(new SSLPeerUnverifiedException("peer not verified")),
8989
named(new SSLProtocolException("protocol error")),
90-
named(new SSLHandshakeException("PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: "
91-
+ "unable to find valid certification path to requested target"))
90+
named(initCause(
91+
new SSLHandshakeException("SSLHandshakeException invoking https://1.2.3.4:8443/api/methodName: "
92+
+ "sun.security.validator.ValidatorException: PKIX path building failed"),
93+
initCause(
94+
new SSLHandshakeException("sun.security.validator.ValidatorException: "
95+
+ "PKIX path building failed: "
96+
+ "sun.security.provider.certpath.SunCertPathBuilderException: "
97+
+ "unable to find valid certification path to requested target"),
98+
new CertPathBuilderException(
99+
"unable to find valid certification path to requested target"))))
92100
);
93101
}
94102

0 commit comments

Comments
 (0)