JDBC报错之--java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not all

忙活了半小时的王师傅Run以下代码又双叒叕报错了…

报错信息:

java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not all

在url的后边加上allowPublicKeyRetrieval=true即可

文档中(https://mysql-net.github.io/MySqlConnector/connection-options/)
加粗样式*

If the user account uses sha256_password authentication, the password must be protected during transmission; TLS is the preferred mechanism for this, but if it is not available then RSA public key encryption will be used. To specify the server’s RSA public key, use the ServerRSAPublicKeyFile connection string setting, or set AllowPublicKeyRetrieval=True to allow the client to automatically request the public key from the server. Note that AllowPublicKeyRetrieval=True could allow a malicious proxy to perform a MITM attack to get the plaintext password, so it is False by default and must be explicitly enabled.

如果用户使用了 sha256_password 认证,密码在传输过程中必须使用 TLS 协议保护,但是如果 RSA 公钥不可用,可以使用服务器提供的公钥;可以在连接中通过 ServerRSAPublicKeyFile 指定服务器的 RSA 公钥,或者AllowPublicKeyRetrieval=True参数以允许客户端从服务器获取公钥;但是需要注意的是 AllowPublicKeyRetrieval=True可能会导致恶意的代理通过中间人攻击(MITM)获取到明文密码,所以默认是关闭的,必须显式开启。

但是奇怪第一次运行出现错误,之后问题重现删除AllowPublicKeyRetrieval=True 却直接运行通过。


版权声明:本文为weixin_44034837原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。