java - 找不到 ssl jdbc 连接 keystore

标签 java mysql ssl jdbc

我希望使用 jdbc 连接到最近通过 ssl 保护的远程 mysql 数据库。我找到了一个简单的示例 java 程序来测试连接。连接失败并提示找不到 keystore 文件。我验证 keystore 确实在我在代码中所说的位置。至少我认为是的。测试应用程序如下所示:

import java.io.File;
import java.sql.*;
public class TestMySQLSSL {
    public static void main (String[] args)
    {
        Connection con = null;
        System.getProperties().setProperty("javax.net.debug","all");
        System.getProperties().setProperty("javax.net.ssl.keyStore","c:\\LiferayStuff\\bundles\\liferay-portal-6.0.6\\tomcat-6.0.29\\jrel.6.0_20\\keystore");
        System.getProperties().setProperty("javax.net.ssl.keyStorePassword","####");
        System.getProperties().setProperty("javax.net.ssl.trustStore","c:\\LiferayStuff\\bundles\\liferay-portal-6.0.6\\tomcat-6.0.29\\jrel.6.0_20\\truststore");
        System.getProperties().setProperty("javax.net.ssl.trustStorePassword","####");
        try
        {
            String url = "jdbc:mysql://xxx.xxx.xxx.xxx:3306/isc"+
            "?verifyServerCertificate=true"+
            "&useSSL=true"+
            "&requireSSL=true";
            String user = "*******";
            String password = "******";

            Class dbDriver = Class.forName("com.mysql.jdbc.Driver");
            boolean filelives;
            filelives = new File("c:/LiferayStuff/bundles/liferay-portal-6.0.6/tomcat-6.0.29/jre1.6.0_20/keystore").exists();
            System.out.println("keystore " + filelives);
            con = DriverManager.getConnection(url, user, password);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            if (con != null)
            {
                try
                {
                    con.close();
                }
                catch (Exception e){}
            }
        }
    }
}

我得到的第一位输出看起来像这样:

keystore true
keyStore is : c:/LiferayStuff/bundles/liferay-portal-6.0.6/tomcat-6.0.29/jrel.6.0_20/keystore
keyStore type is : jks
keyStore provider is : 
default context init failed:java.security.PrivilegedActionException:java.io.FileNotFoundException: c:\LiferayStuff\bundles\liferay-portal-6.0.6\tomcat-6.0.29\jrel.6.0_20\keystore (The system cannot find the path specified)
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlyingexception: 

** BEGIN NESTED EXCEPTION ** 

com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

keystore 文件在那里,但我怀疑它可能有问题。我在 Windows 上运行应用程序。该文件可能存在权限问题吗?任何帮助,将不胜感激。

问候, 戴夫塞梅拉罗

最佳答案

事实证明,数据库管理员已经阻止了对服务器的所有访问,只有一个 ip 访问。添加我的 IP 后,我就能使上面的代码正常工作。很抱歉浪费了大家的时间。

关于java - 找不到 ssl jdbc 连接 keystore ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18600249/

相关文章:

c# - .net 中的 java 的 ServerSocket

java - 在 Java 8 中找不到 AnnotationProcessorFactory 类

python - 当字符串包含空格时,Django 过滤器 icontains 不返回结果 - mysql.connector.django

java - 如何在gmail中显示字符串的二维码

java - 将 SOAP 客户端与 Axis 重用

ssl - Google 地球的 HTTPS 网络链接

delphi - 带有 OpenSSL(无证书)的简单 TIdTCPServer 具有 "HandShake Failure"和 "No Shared Cipher"

php - Apache RewriteRule 在 http 下工作,而不是在 https 下工作

php - MySQL 到 MSSQL PHP 查询转换和速度故障排除

php - JqG​​rid 编辑表单不在下拉列表中显示正确的项目