我的远程 MySQL 服务器只接受通过 TLS 1.2 的连接。如何在 JDBC (OpenJDK 11) 中选择协议(protocol)版本?
SQL State: 28000
java.sql.SQLException: TLS version used does not meet minimal requirements
for this server. Please use a higher TLS version and retry.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
我试过添加 enabledSslProtocolSuites
到我的连接字符串,但无济于事。jdbc:mysql://{server}.mysql.database.azure.com:3306/{database_name}?
serverTimezone=Australia/Melbourne&useSSL=true&requireSSL=true&enabledSslProtocolSuites=TLSv1.2
添加 -Djdk.tls.client.protocols="TLSv1.2" -Djavax.net.debug=all
启动时mvn exec:java
显示尝试使用 TLS 进行客户端 Hello 1.1 .javax.net.ssl|DEBUG|0C|azuremysqltest.App.main()|
2020-08-31 09:16:34.400 UTC|ClientHello.java:653|
Produced ClientHello handshake message (
"ClientHello": {
"client version" : "TLSv1.1",
"random" : "0D 94 D2 90 A7 C0 ...",
"session id" : "",
"cipher suites" : ...
最佳答案
您可以(显然)通过 enabledTLSProtocols
为 mysql 驱动程序(独立于 java 供应商)选择 TLS 版本。属性(8.0 reference):
- enabledTLSProtocols
If "useSSL" is set to "true", overrides the TLS protocols enabled for use on the underlying SSL sockets. This may be used to restrict connections to specific TLS versions. |Since|Version 8.0.8|
在您的情况下,值
=TLSv1.2
批准工作。抱歉,我找不到有关此属性(确切)值的引用,但我们可以进一步调查/获取支持的 ssl 协议(protocol)版本 like here .
关于java - OpenJDK 11 在 JDBC 连接字符串中使用 TLS 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63667790/