如何与TLS1.2保护的oracle服务器建立连接?

时间:2019-04-22 10:58:59

标签: java oracle11g tls1.2

我一直在尝试创建与受TLS1.2保护的Oracle数据库服务器的简单JDBC连接。下面是我到目前为止编写的代码:

public static void main(String args[]) throws SQLException { 

 System.setProperty("https.protocols", "TLSv1.2");
 System.setProperty("http.protocols", "TLSv1.2");
 Properties info = new Properties();      
 info.put(OracleConnection.CONNECTION_PROPERTY_USER_NAME, DB_USER); 
 info.put(OracleConnection.CONNECTION_PROPERTY_PASSWORD, DB_PASSWORD);           
 info.put(OracleConnection.CONNECTION_PROPERTY_DEFAULT_ROW_PREFETCH, "20");
 info.put("oracle.net.ssl_version", "1.2");
 info.put("oracle.net.tns_admin", "./lib");
 info.put("oracle.net.ssl_server_dn_match", "true");
 info.put("oracle.net.ssl_cipher_suites", "(TLS_RSA_WITH_AES_256_CBC_SHA256)");
 info.put(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTORE, "C:/Program Files/Java/jdk1.7.0_79/jre/lib/security/cacerts");
 info.put(OracleConnection.CONNECTION_PROPERTY_THIN_JAVAX_NET_SSL_TRUSTSTOREPASSWORD, "*******");
 info.put("oracle.jdbc.ReadTimeout", "180000");






 try {
 OracleDataSource ods = new OracleDataSource(); 
 ods.setURL(DB_URL);     
 ods.setConnectionProperties(info); 


 // With AutoCloseable, the connection is closed automatically. 
 try (OracleConnection connection = (OracleConnection) ods.getConnection()) { 
   // Get the JDBC driver name and version  
   DatabaseMetaData dbmd = connection.getMetaData();        
   System.out.println("Driver Name: " + dbmd.getDriverName()); 
   System.out.println("Driver Version: " + dbmd.getDriverVersion()); 
   // Print some connection properties 
   System.out.println("Default Row Prefetch Value is: " +  
      connection.getDefaultRowPrefetch()); 
   System.out.println("Database Username is: " + connection.getUserName()); 
   System.out.println(); 
   // Perform a database operation  
   printEmployees(connection); 
   dbClose(connection); 
 }  
 } catch (Exception e) {
     e.printStackTrace();
 }

}

我已经使用iKeyman工具将从数据库服务器检索到的证书添加到cacerts中。 当我尝试运行该应用程序时,出现以下错误:

java.sql.SQLRecoverableException: IO Error: Software caused connection abort: recv failed
       at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:752)
       at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
       at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
       at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
       at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:317)
       at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:241)
       at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:184)
       at com.certificateCheck.DataSourceSample.main(DataSourceSample.java:60)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
       at java.net.SocketInputStream.socketRead0(Native Method)
       at java.net.SocketInputStream.read(SocketInputStream.java:152)
       at java.net.SocketInputStream.read(SocketInputStream.java:122)
       at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
       at sun.security.ssl.InputRecord.read(InputRecord.java:480)
       at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
       at sun.security.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1725)
       at sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:122)
       at sun.security.ssl.Handshaker.sendChangeCipherSpec(Handshaker.java:1005)
       at sun.security.ssl.ClientHandshaker.sendChangeCipherAndFinish(ClientHandshaker.java:1161)
       at sun.security.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:1073)
       at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:341)
       at sun.security.ssl.Handshaker.processLoop(Handshaker.java:901)
       at sun.security.ssl.Handshaker.process_record(Handshaker.java:837)
       at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1023)
       at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
       at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:709)
       at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
       at oracle.net.ns.Packet.send(Packet.java:419)
       at oracle.net.ns.ConnectPacket.send(ConnectPacket.java:241)
       at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:158)
       at oracle.net.ns.NSProtocol.connect(NSProtocol.java:264)
       at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452)
       at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496)
       ... 7 more

我被困在这里。连接到受TLS保护的数据库服务器的任何帮助或替代解决方案,将不胜感激。

1 个答案:

答案 0 :(得分:0)

您使用的JDBC驱动程序版本是什么?您可以查看blog以获得更多详细信息吗?