Feature: Mutual TLS (mTLS) support with client certificate authentication#62
Open
crazyrokr wants to merge 7 commits intoJavaSaBr:developfrom
Open
Feature: Mutual TLS (mTLS) support with client certificate authentication#62crazyrokr wants to merge 7 commits intoJavaSaBr:developfrom
crazyrokr wants to merge 7 commits intoJavaSaBr:developfrom
Conversation
JavaSaBr
reviewed
Apr 22, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds mutual TLS (mTLS) support to rlib-network by introducing an mTLS-capable server connection type, updating SSL connection initialization to allow SSLEngine configuration before the handshake, and fixing an SSL handshake writer state issue that could stall the network executor.
Changes:
- Introduces
StringDataMtlsServerConnectionto require client certificate authentication (setNeedClientAuth(true)). - Refactors SSL connection initialization so handshakes are started explicitly via
beginHandshake()after construction. - Fixes
AbstractSslNetworkPacketWriter.doHandshake()behavior forNEED_UNWRAPto avoid executor stalls; adds integration tests and a client certificate keystore.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| rlib-network/src/test/resources/ssl/rlib_test_client_cert.p12 | Adds a PKCS12 client cert keystore used by mTLS integration tests. |
| rlib-network/src/test/java/javasabr/rlib/network/SslMutualTlsTest.java | Adds integration/regression tests covering mTLS acceptance/rejection scenarios. |
| rlib-network/src/main/java/javasabr/rlib/network/packet/impl/AbstractSslNetworkPacketWriter.java | Fixes handshake handling for NEED_UNWRAP to prevent stalling. |
| rlib-network/src/main/java/javasabr/rlib/network/impl/StringDataMtlsServerConnection.java | New server connection type that enforces client cert authentication. |
| rlib-network/src/main/java/javasabr/rlib/network/impl/AbstractSslConnection.java | Moves beginHandshake() out of the constructor into an explicit method. |
| rlib-network/src/main/java/javasabr/rlib/network/NetworkFactory.java | Updates SSL connection factories to call beginHandshake() explicitly; adds mTLS server factory method. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
StringDataMtlsServerConnectionthat enforces client certificate authentication, along with tests and fixes for the SSL handshake state machine.Changes
StringDataMtlsServerConnection- new connection type that callssslEngine.setNeedClientAuth(true)before the handshake starts.AbstractSslConnection- removedbeginHandshake()from the constructor and exposed it as a public method, so subclasses can configure the SSLEngine (e.g.setNeedClientAuth) before the handshake begins.NetworkFactory- addedstringDataMtlsServerNetworkfactory method; all SSL connections now callconnection.beginHandshake()explicitly after construction.AbstractSslNetworkPacketWriter.doHandshake()- fixed an infinite loop: theNEED_UNWRAPbranch had break instead of returnEMPTY_BUFFER, which blocked the single-threaded network executor during the mTLS handshake.rlib_test_client_cert.p12- added test client certificate (PKCS12, password testpw), used as both the client keystore and the server-side trust store.Problem
The issue was identified in
AbstractSslNetworkPacketReaderduring the SSL/TLS handshake process. This occurs when a single network packet contains both the final handshake data and the initial encrypted application data.Previously, if
sslEngine.unwrap()resulted in aNEED_WRAPstatus (indicating the engine needs to send a handshake response), the reader would immediately request a wrap and then clear the remaining data in the buffer. This caused any application data that arrived in the same packet to be discarded, leading to protocol desynchronization or connection hangs.Fix
In
AbstractSslNetworkPacketReader.doHandshake(), a check was added within theNEED_WRAPcase. Before cleaning the buffer and returning, the reader now checks ifnetworkBufferstill has remaining bytes. If it does, these bytes are immediately passed todecryptAndRead()to be decrypted and processed as application packets.