We will use an Oracle Wallet to securely store and retrieve credentials such as certificates, certificate requests, and private keys. The wallet will be created in a directory of your choice on your database server. In examples that follow, we use the placeholder <server_wallet_directory> to represent that directory name.
The use of PKI (orapki) encryption with Transparent Data Encryption is deprecated.
Use the ADMINISTER KEY MANAGEMENT SQL statement.
We create the wallet using the Oracle Public Key Infrastructure (orapki) utility. The wallet will be created with two additional options.
The auto_login_local option allows the database to read the values of the wallet without requiring interactive password authentication. Additionally, it enforces that the wallet may only be opened by the user that created the wallet on the machine where the wallet was created. Because of this security requirement you will need to create the wallet as the same user that your database executes as.
The wallet also requires that a password be specified for it. We will use the placeholder <server_wallet_password> in the examples to represent that value.
Connections use SSL or TLS depending on the cipher suites selected. Place the ciphers in the strongest-to-weakest order in the list.
_____________________________________________
Wallet Configuration Steps
___________________________________________
1)
Set the parameters common_user_prefix, os_authent_prefix and remote_os_authent to NULL in the database.
alter system set common_user_prefix='' scope=spfile;
alter system set os_authent_prefix='' scope=spfile;
alter system set remote_os_authent=FALSE scope=spfile;
2) Update server sqlnet.ora settings:
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA = (DIRECTORY = /u01/app/oracle/pki/server_wallet) )
)
SQLNET.AUTHENTICATION_SERVICES= (TCPS,IPC,BEQ)
SSL_CLIENT_AUTHENTICATION = TRUE ( or false )
SSL_CIPHER_SUITES = (SSL_RSA_WITH_AES_256_GCM_SHA384,SSL_RSA_WITH_AES_128_CBC_SHA256,SSL_RSA_WITH_AES_256_CBC_SHA256,SSL_RSA_WITH_AES_128_CBC_SHA256,SSL_RSA_WITH_AES_128_CBC_SHA256,SSL_RSA_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_RC4_128_MD5)
SSL_VERSION = 1.2 or 1.1
sqlnet.crypto_checksum_client = ACCEPTED ( or requested )
sqlnet.crypto_checksum_server = ACCEPTED ( or requested )
sqlnet.crypto_checksum_types_server=(SHA356, SHA1)
3) Update server listener.ora settings:
WALLET_LOCATION =( SOURCE=(METHOD=FILE) ( EMOTHOD_DATA=(DIRECTORY= /u01/app/oracle/pki/server_wallet )))
SSL_CLIENT_AUTHENTICATION=FALSE
SSL_VERSION=1.2
4) Create the Server Wallet and Certificate Signing Request (CSR). In this example we are using this password: Welcome1234.
mkdir /u01/app/oracle/pki/server_wallet
cd /u01/app/oracle/pki/server_wallet
orapki wallet create -wallet /u01/app/oracle/pki/server_wallet -auto_login -pwd Welcome123
orapki wallet display -wallet /u01/app/oracle/pki/server_wallet/
5) Create a self-signed certificate and load it into the wallet.
orapki wallet add -wallet /u01/app/oracle/pki/server_wallet -dn "CN=oracle12c.eem.com" -keysize 2048 -sign_alg sha256 -pwd Welcome1234
parameter value
dn A user specified distinguished name. For example: "CN=ORCLCDB,O=testsecurity,C=US"
keysize The certificates keysize must be one of the 3 values, either (512|1024|2048)
validity The number of days the certificate should be valid for
self_signed Self-sign the certification
6) Export the CSR into a file.
Finally we will export the server certificate from the wallet to a file to use later with the client wallet.
orapki wallet export -wallet /u01/app/oracle/pki/server_wallet -dn "CN=oracle12c.eem.com" -request devserver.txt
orapki wallet export -wallet <server_wallet_directory> -pwd <server_wallet_password> -dn "CN=ORCLCDB,O=testsecurity,C=US" -cert /tmp/oracle-db-certificate.crt
$ cat /tmp/oracle-db-certificate.crt
7) If the Certificate Authority (CA) is unable to process a CSR with MD5 algorithm then the below commands need to be run (Oracle MOS Note 1448161.1).
openssl pkcs12 -in ewallet.p12 -nodes -out nonoracle_wallet.pem
openssl req -new -key nonoracle_wallet.pem -out devserver.csr
8) (LOAD TRUESTED CERT) Submit the CSR to the CA for them to generate a certificate.Once the CA provides the server certificate, upload the certificate chain to the wallet.
orapki wallet add -wallet /u01/app/oracle/pki/server_wallet -trusted_cert -cert /u01/app/oracle/pki/server_wallet/ca_cert.crt -pwd Welcome1234
orapki wallet add -wallet /u01/app/oracle/pki/server_wallet -trusted_cert -cert /u01/app/oracle/pki/server_wallet/chain.crt -pwd Welcome1234
orapki wallet add -wallet /u01/app/oracle/pki/server_wallet -user_cert -cert /u01/app/oracle/pki/server_wallet/devserver.crt -pwd Welcome1234
orapki wallet display -wallet /var/opt//oracle/wallets/
orapki cert display -cert /var/opt//oracle/wallets/ -summary
9) Modify endpoints in scan listener and restart listeners
[oracle@myserver ~]$ crsctl stat res -p |grep ENDPOINTS
[oracle@myserver ~]$ srvctl modify listener -p "TCP:1521/TCPS:2484"
[oracle@myserver ~]$ srvctl modify scan_listener -p "TCP:1521/TCPS:2484"
[oracle@myserver ~]$ crsctl stat res -p |grep -B20 ENDPOINTS | grep -e ENDPOINTS -e "^NAME="
New TCPS listener should be added to the list of listeners in the LOCAL_LISTENER database parameter
– Static registration can be used for single instances instead
ALTER SYSTEM SET LOCAL_LISTENER='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)...) (ADDRESS=(PROTOCOL=TCPS)...)))' scope=both;
$ srvctl stop scan_listener ; srvctl start scan_listener ; srvctl status scan_listener
$ srvctl stop listener ; srvctl start listener ; srvctl status listener
For Rac :
1. Update the listener.ora at $GRID_HOME/network/admin (WALLET_LOCATION parameter is the location of the server wallet. In the examples below, we are using the shared server wallet location for Oracle RAC.)
The file listener.ora must be updated to enable a port for secure communication and specify the location of the Oracle wallet.
Please note, when specifying the value for the DIRECTORY parameter make sure to use a fully qualified path to the <server_wallet_directory> location.
For now, we are going to continue to use username/password authentication, so we will disable SSL client authentication on the server by setting the SSL_CLIENT_AUTHENTICATION property to FALSE.
Next, we will add the key SECURE_PROTOCOL_LISTENER and set it to use the more secure Oracle IPC (which only allows communication with other processes on the system) rather than the TCP protocol. By setting this we are instructing the listener to only accept administration and registration requests from the IPC protocol.
Lastly, update the listener entry to enable support for TCPS traffic by changing the protocol from TCP to TCPS and the PORT to 2484.
SSL_CLIENT_AUTHENTICATION = FALSE
SECURE_PROTOCOL_LISTENER=(IPC)
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /acfs/oracle/pki_wallet/server_wallet)
)
)
2. Update sqlnet.ora at $GRID_HOME/network/admin
The file sqlnet.ora must also be updated to enable secure communications. Like the changes we made to the listener.ora file, the SSL_CLIENT_AUTHENTICATION and WALLET_LOCATION need to be set.
Once again, when specifying the value for DIRECTORY, make sure to use a fully qualified path to the <server_wallet_directory> location you specified.
Lastly, we need to specify the property SSL_CIPHER_SUITES to define which encryption algorithms the server should use/require to encrypt network traffic.
SQLNET.ENCRYPTION_SERVER = required
The parameter ENCRYPTION_SERVER has the following options:
REQUESTED – to enable the security service if the client allows it
REQUIRED – to enable the security service and disallow the connection if the client is not enabled for the security service
ACCEPTED – to enable the security service if required or requested by the client
REJECTED – to disable the security service, even if required by the client
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /acfs/oracle/pki_wallet/server_wallet)
)
)
SQLNET.ENCRYPTION_TYPES_SERVER = (AES256,AES192)
SQLNET.ENCRYPTION_TYPES_CLIENT = (AES256,AES192)
SQLNET.CRYPTO_CHECKSUM_CLIENT = ACCEPTED
SQLNET.CRYPTO_CHECKSUM_SERVER = ACCEPTED
SQLNET.CRYPTO_CHECKSUM_TYPES_SERVER = (SHA256,SHA1,SHA384)
SQLNET.CRYPTO_CHECKSUM_TYPES_CLIENT = (SHA256,SHA1,SHA384)
############### SSL ########################
SQLNET.AUTHENTICATION_SERVICES= (TCPS, BEQ, IPC)
SSL_CLIENT_AUTHENTICATION = TRUE
SSL_CIPHER_SUITES = (SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA)
SSL_VERSION = 1.2 or 1.1
3. Update sqlnet.ora at $ORACLE_HOME/network/admin
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /acfs/oracle/pki_wallet/server_wallet)
)
)
SQLNET.ENCRYPTION_TYPES_SERVER = (AES256,AES192)
SQLNET.ENCRYPTION_TYPES_CLIENT = (AES256,AES192)
SQLNET.CRYPTO_CHECKSUM_CLIENT = ACCEPTED
SQLNET.CRYPTO_CHECKSUM_SERVER = ACCEPTED
SQLNET.CRYPTO_CHECKSUM_TYPES_SERVER = (SHA256,SHA1,SHA384)
SQLNET.CRYPTO_CHECKSUM_TYPES_CLIENT = (SHA256,SHA1,SHA384)
4. Restart the database(s) and all listeners so that the new settings take effect.
5. Connect via sqlplus using the TCPS tnsnames entry.
6. Toad: the username should be EXTERNAL and the password field is left blank.
7. SQL Developer: Requires version 17 of SQL Developer and perform the following steps:
a. Select Tools-> Preferences-> Database-> Advanced
b. Check – ‘Use Oracle Client’ and ‘Use OCI/Thick Driver’
c. Set Oracle Homes and TNS Names Directory
d. Create New Connection (Select the TCPS TNS Names Entry)
e. Select OS Authentication
f. Once connected, run the below queries to verify the connection.
Select user from dual;
SELECT SYS_CONTEXT ('USERENV', 'AUTHENTICATED_IDENTITY') FROM DUAL;
SELECT SYS_CONTEXT ('USERENV', 'AUTHENTICATION_METHOD') FROM DUAL;
SELECT SYS_CONTEXT ('USERENV', 'NETWORK_PROTOCOL') FROM DUAL;
Client Side TLS Wallet Configuration
Now that we have the server set up for encrypted communication, we also need to set up encryption in the client as well. The client will also use an Oracle Wallet to store the server security certificate to encode and decode communication with the server.
As noted in the assumptions section, this article assumes you have a machine with the Oracle database client installed. We will create another Oracle Wallet (this time on the client) with the following command, again setting the wallet to enable the auto_login_local option and setting a password. As above we will use a placeholder <client_wallet_directory> in examples that follow to represent the directory name you have chosen.
orapki wallet create -wallet <client_wallet_directory> -auto_login_local -pwd <client_wallet_password>
1) Create a new auto-login wallet.
orapki wallet create -wallet "c:\app\oracle\wallet" -pwd WalletPasswd123 -auto_login_local
2) Create a self-signed certificate and load it into the wallet.
orapki wallet add -wallet "c:\app\oracle\wallet" -pwd WalletPasswd123 -dn "CN=%computername%" -keysize 1024 -self_signed -validity 3650
3) Now we need to add the server security certificate (the file oracle-db-certificate.crt we generated from the database server) to the client wallet to facilitate encrypted communication. For example
orapki wallet add -wallet <client_wallet_directory> -pwd <client_wallet_password> -trusted_cert -cert oracle-db-certificate.crt
orapki wallet add -wallet "c:\app\oracle\wallet" -pwd WalletPasswd123 -trusted_cert -cert c:\ol7-121.localdomain-certificate.crt
orapki wallet display -wallet "c:\app\oracle\wallet" -pwd WalletPasswd1234
4) Update the client side sqlnet.ora
SQLNET.AUTHENTICATION_SERVICES=(TCPS,BEQ)
NAMES.DIRECTORY_PATH= (TNSNAMES)
SSL_CLIENT_AUTHENTICATION = TRUE
SSL_VERSION = 1.1
SSL_CIPHER_SUITES = (SSL_RSA_WITH_AES_256_GCM_SHA384,SSL_RSA_WITH_AES_128_CBC_SHA256,SSL_RSA_WITH_AES_256_CBC_SHA256,SSL_RSA_WITH_AES_128_CBC_SHA256,SSL_RSA_WITH_AES_128_CBC_SHA256,SSL_RSA_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_RC4_128_MD5)
WALLET_LOCATION = (SOURCE = (METHOD=MCS))
Or
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = <server_wallet_directory>)
)
)
4) Update the client tnsnames.ora file to include an entry for the TCPS connection.
First, we will need to update the file tnsnames.orain your client to register the new TCPS listener on your database server. You should replace SERVER_ADDRESS with the IP Address or FQDN of the server hosting your database.
Update the net_service_name entry (in this example named SERVER) to enable support for TCPS traffic by changing the protocol from TCP to TCPS and the PORT to 2484.
testdb_TCPS=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCPS)
(HOST=oracle12c.aem.com)
(PORT=1522)
)
(CONNECT_DATA=
(SERVER=dedicated)
(SERVICE_NAME=testdb.aem.com)
)
)
6) Update the database user account to be identified by the certificate (this will be different for every user based on Distinguished Name of their certificate).
alter user ggarrison identified externally as 'CN=lastname.firstname.middlename,OU=PKI,C=US';
To check that encryption is effectively taking place, execute the following SQL query on the database server side:
SQL> select network_service_banner from v$session_connect_info
where sid in (select distinct sid from v$mystat);
7) Exchange Cert: Export client cert and import in server ( This is not needed for OU class Cert )
Export the certificate so we can load it into the server later.
c:\>orapki wallet export -wallet "c:\app\oracle\wallet" -pwd WalletPasswd123 -dn "CN=%computername%" -cert c:\%computername%-certificate.crt
Load the client certificate into the server wallet.
$ orapki wallet add -wallet "/u01/app/oracle/wallet" -pwd WalletPasswd123 -trusted_cert -cert /tmp/my-computer-certificate.crt
orapki wallet display -wallet "/u01/app/oracle/wallet" -pwd WalletPasswd123
SSL Troubleshooting Guide (Doc ID 166492.1)
• ORA-12560: TNS:protocol adapter error
• ORA-28862: SSL connection failed
– 28759, 00000, "Failed to open file"
– 28859, 00000, "SSL negotiation failure"
– ntzCreateConnection: failed with error 549
• ORA-29024:Certificate Validation Failure
• ORA-29143: Message 29143 not found
• ORA-29106: Can not import PKCS # 12 wallet
• ORA-28860: Fatal SSL error
• ORA-29263: HTTP protocol error
• ORA-28868: certificate chain check failed • ORA-28750: unknown error
• ORA-28865: SSL connection closed
• ORA-01004: Default username feature not supported; log denied
• ORA-28864: SSL connection closed gracefully
• ORA-01017: invalid username/password; logon denied
• alert.log: "SSL Client: Server DN doesn't contain expected SID name"
• ORA-29113: Cannot access attributes from a PKCS #12 key bag.
• ORA-29002: SSL transport detected invalid or obsolete server certificate
• ORA-29003: SSL transport detected mismatched server certificate
• ORA-28857: Unknown SSL Error
Reference :
https://docs.oracle.com/en/cloud/paas/data-safe/admds/create-wallet-or-certificates-tls-connection.html#TASK_QZ2_XRQ_ZHB
https://2019.hroug.hr/eng/content/download/20367/433976/file/Nelson+Calero+-+SSL+certificates+in+the+Oracle+Database+without+surprises.pdf