Configure spring to connect to mysql over ssl

后端 未结 3 1627
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 14:53

I am connecting to MySQL over SSL from my Java application. I have configured MYSQL to support SSL and generated client certificates. I have imported server CA certificate a

3条回答
  •  执念已碎
    2020-12-31 15:52

    It is not necessary to pass keyStore and trustStore to java program or set any system properties as it can be achieved via connection properties per connection!

    So you can use different certificated for different connections (and applications if you are in app server).

    Original answer: https://stackoverflow.com/a/51879119/173149 Relevant part:

    jdbc:mysql://example.com:3306/MYDB?verifyServerCertificate=true&useSSL=true&requireSSL=true&clientCertificateKeyStoreUrl=file:cert/keystore.jks&clientCertificateKeyStorePassword=123456&trustCertificateKeyStoreUrl=file:cert/truststore.jks&trustCertificateKeyStorePassword=123456

    It is documented:

    • https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
    • https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-using-ssl.html

提交回复
热议问题