There may be another option.
I re-read the configuration reference for Connector/J and there is a URL property that can be specified for connections: socketFactory
. This must be the fully-qualified name of a class which implements Connector/J's interface called SocketFactory
(note that this is similar but unrelated to the standard library class javax.net.SocketFactory
).
This interface is pretty small:
public interface SocketFaactory {
Socket afterHandshake() throws SocketException, IOException;
Socket beforeHandshake() throws SocketException, IOException;
Socket connect(String host, int portNumber, Properties props) throws SocketException, IOException;
}
Later versions of the driver add a fourth int loginTimeout
parameter to the connect
method.
At any rate, it looks like this might be the basis for a solution.
Unfortunately, MySQL does not use vanilla TLS connections so it might not be as simple as returning a Socket from a standard customized javax.net.ssl.SSLSocketFactory
.
UPDATE
The SSL/TLS magic happens after connection due to the way MySQL manages its protocol (it's not just plain-TLS).
In the 5.1-era drivers, it's done in a class called ExportControlled
in a method called getSSLSocketFactoryDefaultOrConfigured
. In later versions (I have 8.0-era source in front of me), it's done in the same class but in a different method called performTlsHandshake
.
Without significant hacking of the driver source or re-implementation of a ton of code, I suspect that the better solution is to implement the URL-based keystore-loading from this answer.