java1.8jdbc_Java 1.8.0 enable TLS1.2 in JDBC connection

本文介绍了一个使用 Java JDBC 驱动连接 SQL Server 2014 时遇到的问题,当仅启用 TLS 1.2 协议时,连接失败并抛出安全连接异常。文中提供了使用的 Java 代码示例及 JVM 启动参数。

I have an SQL Server 2014 updated to the latest fixpack (12.0.5207). In the environment, the only protocol enabled is TLS1.2 (the registry keys has been set for the purpose). I can connect to the SQL server using the SA account both locally and remotely using Management Studio.

However when I try establishing a connection to the SQL server using java code and the JDBC driver sqljdbc42.jar the following exception is thrown: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed.

The java code is the following: public static void main(String[] args) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { System.out.println( e.toString() ); } String connectionUrl = "jdbc:sqlserver://localhost:1433;" + "databaseName=TRCDB;user=sa;password=**********;"; try { Connection con = DriverManager.getConnection(connectionUrl); } catch (SQLException e) { System.out.println( e.toString() ); } }

When the JVM is launched the following option are passed: -Djavax.net.debug=all -Djdk.tls.client.protocols="TLSv1.2" -Dhttps.protocols="TLSv1.2"

So although only TLSv1.2 is enabled the "Client Hello" is done using TLSv1: jdk.tls.client.protocols is defined as TLSv1.2 SSLv3 protocol was requested but was not enabled SUPPORTED: [TLSv1, TLSv1.1, TLSv1.2] SERVER_DEFAULT: [TLSv1, TLSv1.1, TLSv1.2] CLIENT_DEFAULT: [TLSv1.2] ... *** ClientHello, TLSv1 ... main, WRITE: TLSv1 Handshake ... main, called close() main, called closeInternal(true) main, SEND TLSv1.2 ALERT: warning, description = close_notify main, WRITE: TLSv1.2 Alert, length = 2

Is it the TLS version the root cause of the problem? How can I force TLSv1.2?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值