3

I am facing a problem connecting my java application to an oracle database using oracle wallet as password store.

To isolate the problem I made a small Main class as follow:

public static void main(String[] args) {
Connection conn;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
System.setProperty("oracle.net.tns_admin", "c:\\tns");
OracleDataSource ds = new OracleDataSource();
Properties props = new Properties();
System.setProperty("oracle.net.wallet_location", "c:/wallet2");

ds.setConnectionProperties(props);
ds.setURL("jdbc:oracle:thin:/@XE2");
Provider p;
p = new OraclePKIProvider();
Security.insertProviderAt(p, 3);
conn = ds.getConnection();

} catch (SQLException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);

} catch (ClassNotFoundException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
}

in the directory c:\tns I've the following files:

sqlnet.ora
tnsnames.ora

this is the listing for sqlnet.ora

SQLNET.AUTHENTICATION_SERVICES = (NTS)
names.directory_path = TNSNAMES
SQLNET.WALLET_OVERRIDE = TRUE
#WALLET_LOCATION = (SOURCE=(METHOD=FILE)METHOD_DATA=(DIRECTORY=c:\wallet))
WALLET_LOCATION = (SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=c:/wallet)))

that for the tnsnames

...
XE2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

In c:\wallet2 there are the following files:

cwallet.sso
ewallet.p12

the file was previously generated with orapki and there is my entry named XE2 with the correct credential. When I run the code I get the following exception

Could not open wallet. java.io.IOException: Could not open wallet. Check password

enabling the oracle trace I can see these lines:

mar 02, 2017 3:57:00 PM oracle.jdbc.driver.DatabaseError findMessage
TRACE_30:          Enter: "ORA-17168", java.io.IOException: Could not open wallet. java.io.IOException: Could not open wallet. Check password
mar 02, 2017 3:57:00 PM oracle.jdbc.driver.Message11 msg
TRACE_30: 72B6CBCC Enter: "ORA-17168", java.io.IOException: Could not open wallet. java.io.IOException: Could not open wallet. Check password
mar 02, 2017 3:57:00 PM oracle.jdbc.driver.Message11 msg
TRACE_30: 72B6CBCC Exit [0.066509ms]

and

mar 02, 2017 3:57:00 PM oracle.jdbc.driver.PhysicalConnection getSecretStoreCredentials
GRAVE:          Throwing SQLException: 168java.io.IOException: Could not open wallet. java.io.IOException: Could not open wallet. Check password

Anyone can help me? Thanks for reading. r.

Dherik
  • 17,757
  • 11
  • 115
  • 164
  • Looks like wallet location issue as ORA-17168 means encountered a problem with the Secret Store. Check the wallet location for the presence of an open wallet (cwallet.sso) and ensure that this wallet contains the correct credentials using the mkstore utility. Check if you are pointing to right location. – Atul Mar 02 '17 at 17:14
  • the path are correct, and cwallet.sso is in there. Moreover I test he contets of the keystore using mkstore utility and the entry for XE is present – Roberto Benazzato Mar 02 '17 at 17:16

3 Answers3

0

This is very old topic . -TNS_ADMIN should point to the wallet location ( C:\wallet2 ) -in tnsnames.ora wallet_location is C:\wallet2 not c:/walet as you have

Mihai
  • 1
0

I think that your ewallet.p12 file is protected by password.

You need do setup the oracle.net.wallet_password property with the password:

System.setProperty("oracle.net.wallet_password", "PASSWORD");

If the password is specified, the driver looks for the p12 file, otherwise it uses the sso file.

Dherik
  • 17,757
  • 11
  • 115
  • 164
-4

SQLNET.AUTHENTICATION_SERVICES = (NTS)

That should that be TNS instead of NTS.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140