SSL Problem? Npgsql.NpgsqlException: 'Exception while performing SSL

In my connection string i setthe trustcertificate to true, in my windows pc i am able to connect. However when connecting to my android i get this error →

Npgsql.NpgsqlException: 'Exception while performing SSL

Any ideas what is happening and how to fix that?

1 Like

Hi @TheUninvited !

This could come for several reasons.

Make sure that the SSL certificate of your PostgreSQL server is trusted by the Android system. You can manually install the certificate on the Android device.

  1. Export the certificate
  2. Transfer to Android (email / cloud storage / direct USB)
  3. Install the certificate. It might depend on your version/flavour of Android, but if you search for “certificate” in Settings, you should find it (I found it on mine).
  4. After installation, it should appear in “User certificates” or “Trusted Credentials” (in the User tab).

To do it inside your app, maybe this would be of help: Network security configuration  |  Android Developers

If that still does not solve the issue, check your logs (adb logcat) for more info.

Good luck!

1 Like

i did that but nothing has changed.

Hmmm, okay.

And did you find any more information with adb logcat -s "SSL" ?

You can also try checking Npgsql logs. You can enable logging to get details on what Npgsql is doing behind the scenes during the connection phase, which can help you diagnose SSL issues. For example:

using Microsoft.Extensions.Logging;

// Create a new LoggerFactory
var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddConsole().SetMinimumLevel(LogLevel.Debug);
});

// Attach the logger factory to Npgsql
NpgsqlLogManager.Provider = new ExtensionsLoggingProvider(loggerFactory);

// Your Npgsql connection code here

This will output Npgsql logs to the console, including the steps taken during the SSL handshake. You’ll get more details about what Npgsql is doing, which could hint at why the SSL operation is failing.

You can also have a look at the “Logs” menu in the left panel of the Aiven Console. Maybe you’ll gain more information as to why the connection was refused.

As a rule of thumb, you should try identifying if the issue is specific to Npgsql or a more general SSL issue.

A last idea would be to check that there is no Android Network Policy (VPN, firewall rules, a custom network security config…) blocking the connection.

Good luck!

Samuel

I didn’t even went to fix that issue yet, just tried today to log in and I got this error:
Failed to connect to 13.49.64.124:16711’

SocketException: No connection could be made because the target machine actively refused it.