使用Java创建与Oracle数据库的SSL连接 [英] Creating an ssl connection to oracle db with Java

查看:802
本文介绍了使用Java创建与Oracle数据库的SSL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java和SSL连接到Oracle DB.现在,我在具有数据库的服务器上安装了Java程序.

I'm trying to connect to an Oracle DB using Java and SSL. For now I have the Java program on the server with the database.

当我尝试运行它时出现此错误(注释中出现完整错误):

I'm getting this error when I try to run it (full error in comment):

java.sql.SQLRecoverableException: IO Error: Inbound closed before receiving peer's close_notify: possible truncation attack?, connect lapse 15 ms., Authentication lapse 0 ms.

这是我的Java代码:

This is my java code:

public static void main(String[] args) {
        Security.addProvider(new oracle.security.pki.OraclePKIProvider());
        String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=localhost)(PORT=2484))(CONNECT_DATA=(SERVICE_NAME=ORCL)))"; 
        Properties props = new Properties(); 
        props.setProperty("javax.net.ssl.trustStore", 
                "C:\\app\\Administrator\\virtual\\product\\12.2.0\\dbhome_1\\bin\\wallets\\Administrator\\cwallet.sso"); 
        props.setProperty("javax.net.ssl.trustStoreType","SSO"); 
        props.setProperty("javax.net.ssl.keyStore", 
                "C:\\app\\Administrator\\virtual\\product\\12.2.0\\dbhome_1\\bin\\wallets\\Administrator\\cwallet.sso"); 
        props.setProperty("javax.net.ssl.keyStoreType","SSO"); 
        try {
            Connection conn = DriverManager.getConnection(url, props);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }

我将其添加到listener.ora和tnsnames.ora中(我也尝试了sso文件,只是链接到目录)

I added this to listener.ora and tnsnames.ora (I also tried with the sso file and just linking to the directory)

WALLET_LOCATION=(SOURCE=(METHOD=FILE) (METHOD_DATA=(DIRECTORY=C:\app\Administrator\virtual\product\12.2.0\dbhome_1\bin\wallets\Administrator\ewallet.p12 ))
SSL_CLIENT_AUTHENTICATION=TRUE

我还将其添加到java.security:

I also added this to java.security:

security.provider.11=oracle.security.pki.OraclePKIProvider

edit:我不知道评论的长度限制这么短.这是完整的错误:

edit: I didn't realize the length limit on comments was so short. Here's the full error:

Caused by: java.io.IOException: Inbound closed before receiving peer's close_notify: possible truncation attack?, connect lapse 11 ms., Authentication lapse 0 ms.
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:790)
    ... 6 more
Caused by: java.io.IOException: Inbound closed before receiving peer's close_notify: possible truncation attack?, connect lapse 11 ms.
    at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:138)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:317)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1438)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518)
    ... 6 more
Caused by: javax.net.ssl.SSLException: Inbound closed before receiving peer's close_notify: possible truncation attack?
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.fatal(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.fatal(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.closeInbound(Unknown Source)
    at oracle.net.nt.SSLSocketChannel.fill(SSLSocketChannel.java:534)
    at oracle.net.nt.SSLSocketChannel.unwrap(SSLSocketChannel.java:434)
    at oracle.net.nt.SSLSocketChannel.handshake(SSLSocketChannel.java:350)
    at oracle.net.nt.SSLSocketChannel.write(SSLSocketChannel.java:238)
    at oracle.net.ns.NIOPacket.writeToSocketChannel(NIOPacket.java:211)
    at oracle.net.ns.NIOConnectPacket.writeToSocketChannel(NIOConnectPacket.java:232)
    at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:108)
    ... 9 more

推荐答案

您可以确保在类路径中包含oraclepki.jar,osdt_core.jar和osdt_cert.jar吗?您不需要使用密钥库和信任库属性.使用oracle.net.wallet_location和oracle.net.ssl_server_dn_match = true.查看博客以获取更多详细信息.

Can you make sure to have oraclepki.jar, osdt_core.jar and osdt_cert.jar in the classpath? You don't need to use keystore and truststore properties. Use oracle.net.wallet_location and oracle.net.ssl_server_dn_match=true. Check out the blog for more details.

这篇关于使用Java创建与Oracle数据库的SSL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆