简体   繁体   English

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

[英]How to establish a connection with TLS1.2 protected oracle server?

I have been trying to create a simple JDBC connection to a TLS1.2 protected Oracle database server. 我一直在尝试创建一个简单的JDBC连接到受TLS1.2保护的Oracle数据库服务器。 Below is the code that I have written so far: 下面是我到目前为止编写的代码:

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();
 }

} }

I have already added the certificate retrieved from the Database server into cacerts using iKeyman tool. 我已经使用iKeyman工具将从数据库服务器检索到的证书添加到cacerts中。 When I try to run the application, I get the following error: 当我尝试运行该应用程序时,出现以下错误:

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

I am stuck here. 我被困在这里。 Any help or an alternative solution to connect to TLS protected database server will be appreciated. 任何帮助或替代解决方案连接到受TLS保护的数据库服务器将不胜感激。

What is the JDBC driver version that you are using? 您使用的JDBC驱动程序版本是什么? Can you review the blog for more details? 您可以查看博客了解更多详情吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM