Skip to content

Commit

Permalink
Merge pull request #935 from the-thing/certificate-test
Browse files Browse the repository at this point in the history
Additional SSL test logging
  • Loading branch information
chrjohn authored Jan 25, 2025
2 parents 10ac4c2 + abbb136 commit 4f744f8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -819,8 +820,42 @@ public void start() throws RuntimeError, ConfigError {
}

public void stop() {
try {
logSSLInfo();
} catch (Exception e) {
LOGGER.error("Failed to log SSL info", e);
}

connector.stop();
}

private void logSSLInfo() throws Exception {
List<SessionID> sessionsIDs = connector.getSessions();
LOGGER.info("All session IDs: {}", sessionsIDs);

for (SessionID sessionID : sessionsIDs) {
Session session = findSession(sessionID);

if (session == null) {
LOGGER.info("No session found for ID: {}", sessionID);
continue;
}

SSLSession sslSession = findSSLSession(session);

if (sslSession == null) {
LOGGER.info("No SSL session found for session: {}", session);
continue;
}

Throwable exception = this.exception.get();
String exceptionMessage = exception != null ? exception.getMessage() : null;
Class<?> exceptionType = exception != null ? exception.getClass() : null;

LOGGER.info("SSL session info [sessionID={},isLoggedOn={},sslSession={},peerCertificates={},localCertificates={},peerPrincipal={},exceptionMessage={},exceptionType={}]",
sessionID, session.isLoggedOn(), sslSession, sslSession.getPeerCertificates(), sslSession.getLocalCertificates(), sslSession.getPeerPrincipal(), exceptionMessage, exceptionType);
}
}
}

static class TestAcceptor extends TestConnector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void testLogonWithBadCertificate() throws Exception {
ThreadedSocketInitiator initiator = new ThreadedSocketInitiator(clientApplication,
new MemoryStoreFactory(), settings, new DefaultMessageFactory());
final CountDownLatch exceptionCaught = new CountDownLatch(1);
initiator.setIoFilterChainBuilder(chain -> chain.addLast("ExceptionCatcher", new IoFilterAdapter() {
public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) throws Exception {
initiator.setIoFilterChainBuilder(chain -> chain.addFirst("ExceptionCatcher", new IoFilterAdapter() {
public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
log.info("MINA exception: {}", cause.getMessage());
exceptionCaught.countDown();
nextFilter.exceptionCaught(session, cause);
Expand All @@ -81,7 +81,7 @@ public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable
try {
log.info("Do login");
initiator.start();
assertTrue("no exception thrown", exceptionCaught.await(5, TimeUnit.SECONDS));
assertTrue("no exception thrown", exceptionCaught.await(10, TimeUnit.SECONDS));
} finally {
initiator.stop();
}
Expand Down

0 comments on commit 4f744f8

Please sign in to comment.