Bug #110463 | Add posiblity to supply custom SSLContext for a SSL connection | ||
---|---|---|---|
Submitted: | 22 Mar 2023 10:40 | Modified: | 7 Mar 2024 8:26 |
Reporter: | Hakan Altindag | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | Connector / J | Severity: | S4 (Feature request) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[22 Mar 2023 10:40]
Hakan Altindag
[22 Mar 2023 11:18]
MySQL Verification Team
Hello Hakan Altindag, Thank you for the report and feature request. regards, Umesh
[1 Mar 2024 17:09]
Hakan Altindag
Hi dev team, did you get the chance to work on this topic? Almost one year has passed, and I am curious whether there is a discussion on this topic whether mysql will add the possibility to customize the ssl configuration programatically.
[7 Mar 2024 8:26]
Hakan Altindag
As there is no responds yet from the dev team, I would like to provide my solution to this technical challange. So the limitation is that it is not possible adjust the ssl configuration programatically because it is constructed by the library itself based on a property file. Which is not bad, it is just an api design decision. I have made a solution which makes it possible to override/bypass the ssl configuration with a custom one without the need of adjusting the mysql-connectorj library. Here is a working POC: https://github.com/Hakky54/java-tutorials/tree/main/bypassing-overruling-ssl-configuration I am using the following configuration: https://github.com/Hakky54/sslcontext-kickstart?tab=readme-ov-file#global-ssl-configuratio... The code to get it working looks like: ``` import nl.altindag.ssl.util.ProviderUtils; import java.security.Provider; import java.security.Security; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class App { public static void main(String[] args) { SSLFactory sslFactory = SSLFactory.builder() .withIdentityMaterial(Paths.get("/path/to/your/identity.jks"), "password".toCharArray()) .withTrustMaterial(Paths.get("/path/to/your/truststore.jks"), "password".toCharArray()) .withSwappableIdentityMaterial() .withSwappableTrustMaterial() .build(); Provider provider = ProviderUtils.create(sslFactory); Security.insertProviderAt(provider, 1); String url = "jdbc:mysql://localhost:33060/mysql?verifyServerCertificate=true&useSSL=true&requireSSL=true"; try (Connection connection = DriverManager.getConnection(url, "root", "secret")) { System.out.println("Database connected!"); } catch (SQLException e) { throw new IllegalStateException("Cannot connect the database!", e); } finally { Security.removeProvider("Fenix"); } } } ``` I am not sure whether this feature requests needs to be closed as I think it will still be good to have a solution from mysql dev team, but if there is no plan to add that kind of feature then we can close it and I will continue to use the workaround code snippet above. Looking forward to your responds.