4
votes

I am trying to store password in an Oracle Wallet file which I will retrieve from the code and use.

I tried to create a wallet and save a credential there:-

$ mkstore -wrl <wallet_location> -createCredential sid scott tiger

Oracle Secret Store Tool : Version 12.1.0.2
Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.

Enter wallet password:   
Create credential oracle.security.client.connect_string1

The creation does not give any error but when I try to list the credential, I don’t get anything.

$ mkstore -wrl -listCredential

Oracle Secret Store Tool : Version 12.1.0.2
Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved

Also, how to retrieve this password using java?

2
I found the answer to the first part :-user2507962

2 Answers

9
votes

For connecting the Oracle DB using wallet requires the following changes.

  1. you need to create a wallet store, you need to also choose a password for the wallet and you need to use this password while modifying the wallet

    • OracleClientHome/bin/mkstore -wrl Where you want to store your wallet -create

    e.g. C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet

  2. you need to add the tns entries in tnsnames.ora (OracleClientHome/network/admin/tnsnames.ora) and same tns entry name will be used us wallet connect string

    • TNS_Entry_Name=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=Hostname)(PORT=Port_Number))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=Service_Name)))

    e.g. C:\Oracle_11.2.0\product\client_1\network\admin\tnsnames.ora

    • SAMPLEDB_RO=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=HostName)(PORT=PortNumber))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=samplesrv)))
  3. you need to create wallet entry for the above tns entry with credentials, you also need to provide the wallet password which you have given while creating the wallet.

    • OracleClientHome/bin/mkstore -wrl Where you want to store your wallet -createCredential TNS_Entry_Name/Wallet_Entry_name DB_Username DB_Password

    e.g. C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet -createCredential SAMPLEDB_RO sample sample

  4. you need to add the sqlnet.ora file to update the wallet location and wallet override flag to true

    • WALLET_LOCATION =(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=Where you want to store your wallet)))
    • SQLNET.WALLET_OVERRIDE = TRUE

    e.g.

    • WALLET_LOCATION =(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=C:\Users\sample\app\wallet)))
    • SQLNET.WALLET_OVERRIDE = TRUE
  5. test the db connection using wallet and oracle client to make sure the wallet configurations are correct

    • OracleClientHome/bin/sqlplus /nolog

    • connect DB_Username/DB_Password@TNS_Entry_Name

    • connect /@TNS_Entry_Name

    e.g.

    • connect sample/sample@SAMPLEDB_RO
    • connect /@SAMPLEDB_RO
  6. you need to make the java application ready to use the wallet and run the java program with the below JVM Parameters

    • Add the following jars to the application classpath.
    • OracleClientHome/jdbc/lib/ojdbc.jar
    • OracleClientHome/jlib/oraclepki.jar
    • OracleClientHome/jlib/osdt_cert.jar
    • OracleClientHome/jlib/osdt_core.jar

    • e.g.

    • C:\Oracle_11.2.0\product\client_1\jdbc\lib\ojdbc.jar
    • C:\Oracle_11.2.0\product\client_1\jlib\oraclepki.jar
    • C:\Oracle_11.2.0\product\client_1\jlib\osdt_cert.jar
    • C:\Oracle_11.2.0\product\client_1\jlib\osdt_core.jar

    • Change application configuration thin url to use the wallet

    • jdbc:oracle:thin:/@TNS_Entry_Name/Wallet_Entry_name

    • e.g.

    • jdbc:oracle:thin:/@SAMPLEDB_RO

    • Also add the following properties as JVM Parameters, this help the library to find the oracle wallet

    • -Doracle.net.tns_admin=OracleClientHome/network/admin -Doracle.net.wallet_location=Where you want to store your wallet

    • e.g. -Doracle.net.tns_admin=C:\Oracle_11.2.0\product\client_1\network\admin -Doracle.net.wallet_location=C:\Users\sample\app\wallet

    You are all set!!

    • For listing the existing credentials in the wallet you can use the below command, but you need to provide the wallet password which you have given while creating the wallet.
    • OracleClientHome/bin/mkstore -wrl Where you want to store your wallet -listCredential

    • e.g. C:\Oracle_11.2.0\product\client_1\bin\mkstore -wrl C:\Users\sample\app\wallet -listCredential

0
votes

One important thing you must have in mind is, that the alias you choose for the createCredential command must be identical to the URL you are using for the connection.

When your JDBC connection string looks like jdbc:oracle:thin:/@dbsrv:1521/orcl you must use the command

mkstore -wlr /foobar -createCredential dbsrv:1521/orcl USER PASSWORD