无法使用javax.net.ssl.keyStore set连接到MariaDB

时间:2018-01-25 19:11:23

标签: java ssl mariadb

我的应用程序必须与Maria数据库实例建立SSL连接。

这是我的连接字符串

jdbc:mariadb://<serverName>:3306/<dbName>?serverSslCert=<path to server cert>&jdbcCompliantTruncation=false&verifyServerCertificate=true&useSSL=true&enabledSslProtocolSuites=TLSv1.1&autoReconnect=true

这工作正常,但现在我的应用程序需要创建一个https连接并提供客户端证书。

        HttpClientBuilder hcb = HttpClients.custom();
        hcb.useSystemProperties();
        hcb.setUserAgent(AGENT);
        hcb.setDefaultCookieStore(new BasicCookieStore());

        SSLContext sslContext = SSLContexts.createSystemDefault();
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
        hcb.setSSLSocketFactory(sslsf);
        client = hcb.build();

当我使用 javax.net.ssl.keyStore 设置启动我的应用程序时,我收到以下异常

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not connect to <serverName>:3306: Unsupported record version Unknown-0.0)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:718)
    at gov.dni.search.intelsync.common.dao.MySQLDAO.getSyncRecords(MySQLDAO.java:71)
    at gov.dni.search.intelsync.common.client.SyncClient.getSyncRecords(SyncClient.java:283)
    at gov.dni.search.intelsync.common.ExporterUpdater.call(ExporterUpdater.java:53)
    at gov.dni.search.intelsync.common.ExporterUpdater.call(ExporterUpdater.java:22)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not connect to <serverName>:3306: Unsupported record version Unknown-0.0)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    ... 15 more
Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to <serverName>:3306: Unsupported record version Unknown-0.0
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:156)
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:118)
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.throwException(ExceptionMapper.java:92)
    at org.mariadb.jdbc.Driver.connect(Driver.java:111)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
    ... 19 more
Caused by: java.sql.SQLException: Could not connect to <serverName>:3306: Unsupported record version Unknown-0.0
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.handleConnectionPhases(AbstractConnectProtocol.java:712)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connect(AbstractConnectProtocol.java:405)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1028)
    at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:483)
    at org.mariadb.jdbc.Driver.connect(Driver.java:106)
    ... 23 more
Caused by: javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
    at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:524)
    at sun.security.ssl.InputRecord.read(InputRecord.java:509)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.handleConnectionPhases(AbstractConnectProtocol.java:686)
    ... 27 more

因此,应用程序似乎可以建立安全的数据库连接(必需)或将自身标识为http服务器(也是必需的)。

我正在使用 mariadb-java-client-1.6.2.jar 但是已经尝试了与Java 7(1.7.1)兼容的最新版本,但仍然会遇到同样的错误。

我的主要问题是,我做错了什么,或者在设置 javax.net.ssl.keyStore 时是否无法使用与mariadb的安全连接?我是否需要将(mariadb)服务器证书放入密钥库?

除此之外,还有其他一些方法可以让我的 HttpClient 使用密钥库而不通过 javax.net.ssl.keyStore 提供吗?

0 个答案:

没有答案