Skip to content

Commit

Permalink
fix: OF-2599 - switch SSLHandshakeException check to a CertificateExc…
Browse files Browse the repository at this point in the history
…eption check
  • Loading branch information
AlexGidman committed Jul 31, 2023
1 parent f591cc9 commit edec92b
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLHandshakeException;
import java.security.cert.CertificateException;

/**
* Outbound (S2S) specific ConnectionHandler that knows which subclass of {@link StanzaHandler} should be created
Expand Down Expand Up @@ -133,7 +133,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
// SSL Handshake has failed
stanzaHandler.setSession(null);

if (isSSLHandshakeException(event) && isCausedByCertificateError(event)){
if (isCertificateException(event)){
if (configRequiresStrictCertificateValidation()) {
Log.warn("Aborting attempt to create outgoing session as TLS handshake failed, and strictCertificateValidation is enabled.");
throw new RuntimeException(event.cause());
Expand Down Expand Up @@ -166,12 +166,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
super.userEventTriggered(ctx, evt);
}

private static boolean isSSLHandshakeException(SslHandshakeCompletionEvent event) {
return event.cause() instanceof SSLHandshakeException;
}

private static boolean isCausedByCertificateError(SslHandshakeCompletionEvent event) {
return event.cause().getMessage().contains("java.security.cert.CertPathBuilderException");
private static boolean isCertificateException(SslHandshakeCompletionEvent event) {
return event.cause().getCause() instanceof CertificateException;
}

private static void abandonSession(RespondingServerStanzaHandler stanzaHandler) {
Expand Down

0 comments on commit edec92b

Please sign in to comment.