gpt4 book ai didi

mysql - JDBC 到 mysql 5.7.21 和 java 1.8.0_162;不支持的记录版本 Unknown-0.0

转载 作者:行者123 更新时间:2023-11-29 03:18:50 37 4
gpt4 key购买 nike

我正在尝试使用 JDBC 连接到 mysql。我在 Windows 10 上按如下方式生成了 key :

winpty openssl pkcs12 -export -inkey ssl_cert/client-key.pem -in ssl_cert/client-cert.pem -out client.packet

keytool -importkeystore -deststorepass <password> -destkeypass <password> -destkeystore mysqldb.jks -srckeystore client.packet -srcstoretype PKCS12 -srcstorepass <password> -alias 1

keytool -importcert -alias mysqlCA -trustcacerts -file ssl_cert/ca.pem -keystore mysqldb.jks

我的 JDBC 代码如下所示:

System.setProperty("javax.net.ssl.trustStore", "ks-production-mysqldb.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "<password> ");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");

System.setProperty("javax.net.ssl.keyStore", "mysqldb.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "<password> ");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");

String dbURL = "jdbc:mysql://localhost:1234/sb?"
+ "verifyServerCertificate=true&useSSL=true&requireSSL=true";
conn = DriverManager.getConnection(dbURL, dbUser, dbPass);

我收到以下错误:

Caused by: javax.net.ssl.SSLException: Unsupported record version Unknown-0.0 at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552) at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:565) at sun.security.ssl.InputRecord.read(InputRecord.java:529) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397) at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:444) ... 7 more

我在谷歌上搜索了一下,发现这可能是由于服务器和 java 之间的 SSL 协议(protocol)不同,他们说这必须在 java 7 或更高版本中解决。但我仍然收到错误?我错过了什么?

连接到 localhost:1234 之前的端口转发:

try {
JSch jsch = new JSch();
jsch.addIdentity(privateKey);
logger.info("Establishing connection to " + sshHost + " by user " + sshUser);
session = jsch.getSession(sshUser, sshHost, 22);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
int assignedPort = session.setPortForwardingL(localPort, remoteHost, remotePort);
logger.info("assigned Port = " + assignedPort);
} catch (JSchException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return session;

openssl 命令输出:

 $ openssl s_client -connect localhost:1234
CONNECTED(00000003)
140108247099296:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:s23_lib.c:177:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 289 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
Krb5 Principal: None
PSK identity: None
PSK identity hint: None
Start Time: 1519473350
Timeout : 300 (sec)
Verify return code: 0 (ok)
---

最佳答案

没有发布解决方案,因此对于面临此问题的任何人:

我们使用 MariaDB 并一直面临这个问题,在尝试了所有方法之后,将 mariaDB java 客户端驱动程序版本升级到最新版本解决了这个问题。希望对您有所帮助。

关于mysql - JDBC 到 mysql 5.7.21 和 java 1.8.0_162;不支持的记录版本 Unknown-0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48947926/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com