java 无法使用ssl,Java JDBC无法使用SSL连接到Oracle数据库

I have configured a Oracle 11g database server to work with SSL using a wallet and self signed certificate.

Tested it with local client (sqlplus) and it works without any issues.

Now I'm trying to connect the database using Java JDBC.

Currently I'm getting an error:

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to

find valid certification path to requested target

Here is my code:

public static void main(String[] args)

{

Connection connection = null;

String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=192.168.200.191)(PORT=1522))(CONNECT_DATA=(SERVICE_NAME=VDB)))";

Properties props = new Properties();

props.setProperty("user", "dbuser");

props.setProperty("password", "dbpass");

props.setProperty("oracle.net.ssl_cipher_suites","(SSL_RSA_WITH_3DES_EDE_CBC_SHA)");

/* Load the database driver */

try

{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

connection = DriverManager.getConnection(url,props);

if (connection != null) {

System.out.println("You made it, take control your database now!");

} else {

System.out.println("Failed to make connection!");

}

}

catch (SQLException ex) {

ex.printStackTrace();

}

}

I did some more research, and found that if the wallet is configured as 'auto_login', I can try the following:

Connection connection = null;

String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=192.168.200.191)(PORT=1522))(CONNECT_DATA=(SERVICE_NAME=VDB)))";

Properties props = new Properties();

props.setProperty("user", "dbuser");

props.setProperty("password", "dbpass");

props.setProperty("javax.net.ssl.trustStore", "C:\\oracle\\wallet\\cwallet.sso");

props.setProperty("javax.net.ssl.trustStoreType","SSO");

/* Load the database driver */

try

{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

connection = DriverManager.getConnection(url,props);

if (connection != null) {

System.out.println("You made it, take control your database now!");

} else {

System.out.println("Failed to make connection!");

}

}

catch (SQLException ex) {

ex.printStackTrace();

}

In this case, I'm getting:

java.security.NoSuchAlgorithmException: SSO KeyStore not available

I've added 3 Jars: oraclepki.jar, osdt_cert.jar, osdt_core.jar

Attempted to run the last version of the code, getting exception:

java.lang.ClassNotFoundException: com.phaos.crypto.AuthenticationException

Perhaps I should specify the wallet location? as I did in the tnsnames.ora file? or specify the certificate CN?

Please advise, thanks.

解决方案

Found the solution, as I'm using SSO need to specify both keystore and truststore.

Connection connection = null;

String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=192.168.200.191)(PORT=1522))(CONNECT_DATA=(SERVICE_NAME=NNVSDB)))";

Properties props = new Properties();

props.setProperty("user", "dbuser");

props.setProperty("password", "dbpass");

//Single sign on

props.setProperty("javax.net.ssl.trustStore", "C:\\oracle\\wallet\\cwallet.sso");

props.setProperty("javax.net.ssl.trustStoreType","SSO");

props.setProperty("javax.net.ssl.keyStore","C:\\oracle\\wallet\\cwallet.sso");

props.setProperty("javax.net.ssl.keyStoreType","SSO");

props.setProperty("oracle.net.authentication_services","(TCPS)");

/* Load the database driver */

try

{

Security.addProvider(new oracle.security.pki.OraclePKIProvider());

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

connection = DriverManager.getConnection(url,props);

if (connection != null) {

System.out.println("You made it, take control your database now!");

} else {

System.out.println("Failed to make connection!");

}

}

catch (SQLException ex) {

ex.printStackTrace();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值