Re: Trust intermediate CA for client certificates

From: Ian Pilcher <arequipeno(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, stellr(at)vt(dot)edu, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Trust intermediate CA for client certificates
Date: 2013-03-09 08:52:43
Message-ID: 513AF85B.6080202@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 03/07/2013 12:42 PM, Ray Stell wrote:
> What Tom said works for me. Here is a page that gives an example and I think it demonstrates that the root CA does not allow everybody in the gate, the chain has to be in place:
> http://stackoverflow.com/questions/1456034/trouble-understanding-ssl-certificate-chain-verification

That page doesn't even mention PostgreSQL.

> You can use the "openssl verify" command to test that the root is not wide open on it's own.

The issue is the behavior of the PostgreSQL server. "openssl verify" is
germane only in that it points to the source of the problem -- OpenSSL's
insistence on ultimately validating all certificates against a self-
signed root CA. This requires that the root CA certificate be present
in root.crt, which causes the server to accept connections from all
clients that can present a certificate chain leading to that root CA.

If you don't believe me, test with the attached files, which implement
the following hierarchy.

+---------+
| Root CA |
+---------+
/\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
+-----------+ +-----------+
| Server CA | | Client CA |
+-----------+ +-----------+
/\ \
/ \ \
/ \ \
/ \ \
/ \ \
/ \ \
/ \ \
/ \ \
+----------+ +--------+ +--------+
| postgres | | "Bad" | | "Good" |
| (server) | | client | | client |
+----------+ +--------+ +--------+

The goal is to configure the server such that the "good" client will
be allowed to connect (because its certificate is signed by the Client
CA), but the "bad" client will not be allowed to connect (because its
certificate is not signed by the Client CA).

You will find the following:

1. You cannot simply use client-ca,crt as $PGDATA/root.crt. OpenSSL
will not validate a client certificate without access to the root CA
certificate.

2. To enable client connections, you must add the root CA certificate
to $PGDATA/root.crt -- "cat client-ca.crt root-ca.crt > root.crt".

3. Once the root CA certificate is trusted, however, the "bad" client
can also connect by using a certificate chain that includes the
Server CA certificate --"cat bad-client.crt server-ca.crt >
~/.postgresql/postgresql.crt".

After looking at be-secure.c and investigating the way that OpenSSL
validates certificates, I do not believe that there is any way of
achieving the desired behavior with the current codebase.

Adding pgsql-hackers to see if there is any interest in a patch to add
this functionality.

--
========================================================================
Ian Pilcher arequipeno(at)gmail(dot)com
Sometimes there's nothing left to do but crash and burn...or die trying.
========================================================================

Attachment Content-Type Size
root-ca.crt application/pkix-cert 1.3 KB
server-ca.crt application/pkix-cert 1.3 KB
client-ca.crt application/pkix-cert 1.3 KB
bad-client.crt application/pkix-cert 1.3 KB
bad-client.key text/plain 1.6 KB
good-client.crt application/pkix-cert 1.3 KB
good-client.key text/plain 1.6 KB
postgres.crt application/pkix-cert 1.3 KB
postgres.key text/plain 1.6 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message akp geek 2013-03-09 14:51:21 postgres 9.0.2 replicated database is crashing
Previous Message akp geek 2013-03-09 07:06:31 Re: Replication stopped on 9.0.2 after making change to conf file

Browse pgsql-hackers by date

  From Date Subject
Next Message Dann Corbit 2013-03-09 10:32:57 Re: Why do we still perform a check for pre-sorted input within qsort variants?
Previous Message Satoshi Nagayasu 2013-03-09 06:23:01 Re: Fix pgstattuple/pgstatindex to use regclass-type as the argument