1
votes

I am trying to access the db using SSL listener port using the code listed below.

import java.security.Security;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class SSLTester
{
public static void main(String[] args)
throws Exception
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Security.insertProviderAt(new oracle.security.pki.OraclePKIProvider(), 3);
String url = "jdbc:oracle:thin:@(DESCRIPTION = " +
"(ADDRESS_LIST = " +
"(ADDRESS = " +
"(PROTOCOL = TCPS)" +
"(HOST = <hostname>)" +
"(PORT = <port>)" +
")" +
") " +
"(CONNECT_DATA = (SERVICE_NAME = <servicename>))" +
")";

java.util.Properties info = new java.util.Properties();
info.setProperty("oracle.net.authentication_services", "(TCPS)");
info.setProperty("javax.net.ssl.trustStore", "YOUR_WALLET_LOCATION/cwallet.sso");
info.setProperty("javax.net.ssl.trustStoreType", "SSO");
info.setProperty("javax.net.ssl.keyStore", "YOUR_WALLET_LOCATON/cwallet.sso");
info.setProperty("javax.net.ssl.keyStoreType", "SSO");

Connection conn = DriverManager.getConnection(url, info);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select user from dual");

while (rset.next())
System.out.println(rset.getString(1));

rset.close();
stmt.close();
conn.close();
}
}

But I am seeing the error below. I tried updating the user id and passowrd using "setProperty" as well but still see the same error.

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673) at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:715) at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:385) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:208) at TestOracleSSLConnection.main(TestOracleSSLConnection.java:22) Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:445) at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464) at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594) at oracle.net.ns.NSProtocol.connect(NSProtocol.java:229) at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486) ... 7 more Caused by: oracle.net.ns.NetException: Unable to initialize ssl context. at oracle.net.nt.CustomSSLSocketFactory.getSSLSocketFactory(CustomSSLSocketFactory.java:325) at oracle.net.nt.TcpsNTAdapter.connect(TcpsNTAdapter.java:115) at oracle.net.nt.ConnOption.connect(ConnOption.java:133) at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411) ... 12 more Caused by: oracle.net.ns.NetException: Unable to initialize the trust store. at oracle.net.nt.CustomSSLSocketFactory.getTrustManagerArray(CustomSSLSocketFactory.java:413) at oracle.net.nt.CustomSSLSocketFactory.getSSLSocketFactory(CustomSSLSocketFactory.java:309) ... 15 more Caused by: oracle.security.crypto.asn1.ASN1FormatException: oracle.security.crypto.core.CipherException: Invalid padding string (or incorrect password) at oracle.security.crypto.cert.PKCS12Safe.input(PKCS12Safe.java:226) at oracle.security.crypto.cert.PKCS12Safe.(PKCS12Safe.java:120) at oracle.security.crypto.cert.PKCS12.input(PKCS12.java:179) at oracle.security.crypto.cert.PKCS12.(PKCS12.java:119) at oracle.security.pki.OracleKeyStoreSpi.engineLoad(Unknown Source) at oracle.security.pki.OracleSSOKeyStoreSpi.engineLoad(Unknown Source) at java.security.KeyStore.load(KeyStore.java:1445) at oracle.net.nt.CustomSSLSocketFactory.getTrustManagerArray(CustomSSLSocketFactory.java:404) ... 16 more

1

1 Answers

0
votes

Can you check out the blog for more details ? Oracle Wallets require oraclepki.jar, osdt_core.jar, and osdt_cert.jar.