'How can I trust a self-signed certificate in an Oracle Wallet from .NET 5/6?

I have a console application that is trying to connect to a remote Oracle database using a wallet for authentication. Here is the code for the connection.

OracleConfiguration.WalletLocation = @"(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=c:\Oracle\wallets\test)))";
OracleConfiguration.SqlNetWalletOverride = true;
OracleConfiguration.TnsAdmin = @"C:\Oracle";
OracleConfiguration.TraceLevel = 7;
OracleConfiguration.TraceFileLocation = @"C:\Oracle\trace";
OracleConfiguration.TraceOption = 7;
    
using (var dbConn = new OracleConnection(connectionString))
{
    dbConn.Open();
    Console.WriteLine("SUCCESS!");
    dbConn.Close();
}

The certificate in the wallet is self-signed by the other party I am trying to connect to. The connection fails with the following error:

Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-00542: Failure during SSL handshake
 ---> OracleInternal.Network.NetworkException (0x80004005): ORA-00542: Failure during SSL handshake
 ---> System.Security.Authentication.AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback.

In other .NET applications, I have been able to assign a callback to handle server certificate validation errors. Is there a way to do so in the context of the Oracle connection?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source