Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom SSL truststore only for mysql jdbc

Tags:

java

mysql

ssl

jdbc

I would like to be able to connect to a MySQL server with JDBC through an SSL connection. The MySQL documentation states that we should set system properties:

java System.setProperty("javax.net.ssl.trustStore","path_to_truststore_file"); System.setProperty("javax.net.ssl.trustStorePassword","password");

Indeed, it works... for MySQL. But once I've set those system properties, I cannot make regular HTTPS calls to registered websites. The system trustore has been overriden, and I get an SSLHandshakeException.

I'd like to be able to set the trustore ONLY for the JDBC MySQL connection. Any regular HTTPS call should use the system trust store.
How can it be done ?

I have found this question that may lead to an answer but it looks like it's not working.

like image 365
Salomon BRYS Avatar asked Mar 25 '16 14:03

Salomon BRYS


1 Answers

Turns out the MySQL JDBC driver allows to override those properties as part of the connection URL.

So I need to add &trustCertificateKeyStoreUrl=file://path_to_truststore_file&trustCertificateKeyStorePassword=password to the connection URL.

like image 57
Salomon BRYS Avatar answered Oct 25 '22 14:10

Salomon BRYS