如何使用JDBC驱动程序和SSL连接连接到Sybase ASE [英] How to connect to Sybase ASE using JDBC driver and SSL connection
问题描述
我正在尝试使用JDBC驱动程序与Sybase ASE 15.7建立SSL连接,但没有成功. 我尝试了以下选项:
I'm trying to establish an SSL connection to a Sybase ASE 15.7 using JDBC driver with no luck. I tried the following options:
-
使用JTDS 1.25驱动程序(jtds-1.2.5.jar)
Using JTDS 1.25 driver (jtds-1.2.5.jar)
具有以下连接字符串:jdbc:jtds:sybase://host:port;databaseName=dbname;ssl=request
With the following connection string: jdbc:jtds:sybase://host:port;databaseName=dbname;ssl=request
我得到了Network error IOException: Connection refused
使用Jconnect 4(jconn4.jar)
Using Jconnect 4 (jconn4.jar)
具有以下连接字符串:
jdbc:sybase:Tds:host:port/dbname?ENABLE_SSL = true
jdbc:sybase:Tds:host:port/dbname?ENABLE_SSL=true
我得到了java.sql.SQLException: JZ00L: Login failed. Examine the SQLWarnings chained to this exception for the reason(s)
...
java.sql.SQLException: I/O Error: DB server closed connection.
I got java.sql.SQLException: JZ00L: Login failed. Examine the SQLWarnings chained to this exception for the reason(s)
...
java.sql.SQLException: I/O Error: DB server closed connection.
我检查了Sybase日志,看到以下错误:
I checked the Sybase log see the following error:
kernel SSL or Crypto Error Message: 'The SSL handshake failed. Root error: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol'.
看起来Sybase服务器需要SSL连接,但Java客户端仍未使用SSL(尽管连接字符串属性标记ssl = true).
it looks like the Sybase server expects SSL connection but the java client still not using SSL (although connection string property marks ssl=true).
尝试搜索Sybase文档时运气不佳,无论是针对该错误还是JConnect的SSL.
tried searching Sybase documentation with not much luck, neither for this error nor for SSL with JConnect.
任何答案都将不胜感激-我对驱动程序的类型和配置很灵活.
Any answer will be much appreciated - i'm flexible with the type of driver and the configuration.
谢谢
推荐答案
经过大量调查,我找到了解决方案.实际上是2个.
After much investigation, I found a solution. 2 actually.
- 使用信任所有证书的JDBC连接字符串参数:
如果您不介意信任所有证书(仅当您完全信任您正在使用的网络,尤其是不公用网络上的任何网络时,才执行此操作),则可以添加一个连接字符串,该字符串指示SSLSocketFactory创建要信任的连接所有证书.连接字符串如下所示:
jdbc:sybase:Tds:host:port/dbname?ENABLE_SSL=true&SSL_TRUST_ALL_CERTS=true
- 使用sybase证书:
证书需要导入到Java应用程序信任库中.
如果您不使用指定的信任库,则可以将其导入到
$JAVA_HOME\jreX\lib\security\cacerts
下的Java默认信任库中.可以按照此处中所述使用密钥工具导入证书. li>
- Using trust all certificate JDBC connection string parameter:
if you don't mind to trust all certificates (do this only if you entirely trust the network you're working in, especially not anything going on the public internet), you may add a connection string indicating the SSLSocketFactory creating the connection to trust all certificates. The connection string will look as follows:
jdbc:sybase:Tds:host:port/dbname?ENABLE_SSL=true&SSL_TRUST_ALL_CERTS=true
- Using the sybase certificate:
the certificate needs to be imported to the java application trust store.
in case you're not working with a designated trust store, it may be imported to the Java default trust store found under
$JAVA_HOME\jreX\lib\security\cacerts
. The certificate may be imported using keytool as explained here.
这篇关于如何使用JDBC驱动程序和SSL连接连接到Sybase ASE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!