Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect to Postgresql with SSL

Tags:

c#

postgresql

ssl

I am attempting to connect to a postgresql database which uses SSL via my c# application. But I'm unable to work out what the correct connection string would be. Is anyone able to help?

        NpgsqlConnection postgresConn;
        public PostgreManager()
        {
            openConnection();
        }

        private void openConnection()
        {
            postgresConn = new NpgsqlConnection("Server=10.153.8.4;Port=5432;Database=au_wa_jpc;User Id=readonly;Password=myPass;");
            postgresConn.Open();

        }

Edit:

I have attempted to use Ssl Mode=Require; in the connection string, however it throws the following exception.

An unhandled exception of type 'System.IO.IOException' occurred in Npgsql.dll

Additional information: TlsClientStream.ClientAlertException: CertificateUnknown: Server certificate was not accepted. Chain status: A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.

. The specified hostname was not present in the certificate.

like image 966
illusion466 Avatar asked Aug 18 '16 02:08

illusion466


People also ask

How do I connect to PostgreSQL with SSL?

With SSL support compiled in, the PostgreSQL server can be started with SSL enabled by setting the parameter ssl to on in postgresql. conf. The server will listen for both normal and SSL connections on the same TCP port, and will negotiate with any connecting client on whether to use SSL .

What is SSL in Postgres?

SSL (Secured Sockets Layer) also known as TLS (Transport Layer Security) is a standard security technology for establishing encrypted connection between a server and a client.

How can I tell if Postgres is SSL?

Verify SSL is Enabled Verify the configuration file for Postgres has the ca file configured cat /db/postgresql/*/data/postgresql. conf | grep 'ssl' . If the configuration file shows SSL is on and the server indicated it was off you'll need to Restart PostgreSQL.

How do I enable SSL in RDS Postgres?

You can set the rds. force_ssl parameter to 1 (on) to require SSL for connections to your DB instance. To change the value of this parameter, you need to create a custom DB parameter group. You then change the value for rds.


1 Answers

As described in the documentation here and here, you'll have to use SSL Mode=Require;Trust Server Certificate=true in your connection string.

like image 54
Laurenz Albe Avatar answered Sep 20 '22 05:09

Laurenz Albe