pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: Jeffrey Baker <jwbaker@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC SSL with postgresql
Date: Thu, 03 Jun 2010 10:26:46 +0800
Message-ID: <4C0712E6.1050002@postnewspapers.com.au> (raw)
In-Reply-To: <AANLkTikptvIa8hE5J_9lzqIwZYuQ7AMHLQIiZh8uAFEn@mail.gmail.com>
References: <AANLkTikptvIa8hE5J_9lzqIwZYuQ7AMHLQIiZh8uAFEn@mail.gmail.com>

On 3/06/2010 8:46 AM, Jeffrey Baker wrote:
> I was interested in this[1] work on SSL client certs for JDBC, but I
> see the author stopped working on your project.  I hope the list can
> give me a quick clue, because i've been banging my head against this
> all day.
>
> 1: http://github.com/ringerc/pkcs12provider

I stopped working on it because it's unnecessary if Java is configured 
correctly using the standard, built-in SSLSocketFactory and the system 
properties controlling it, as documented in the README in that directory.

Unfortunately, that's only true with current Pg server versions if the 
same root signed the server and client certificates, or if you have only 
one client cert installed in your KeyStore. Otherwise, Java doesn't know 
which client cert to send.

> truststore has only my self-signed root CA cert.  keystore has the
> root CA cert and my signed client certificate.  Using a trivial JDBC
> test class and this command line:
>
> java -cp /usr/share/java/postgresql.jar:.
> -Djavax.net.ssl.keyStore=./keystore
> -Djavax.net.ssl.trustStore=./truststore TestJdbc
>
> I get this exception:
>
> Exception in thread "main" org.postgresql.util.PSQLException: FATAL:
> connection requires a valid client certificate

This code (attached) might help you out. I've been meaning to push it to 
gitgub.

> Which is half good, because I know that it's validating the trust
> chain from the server to the root CA, but half bad because it's not
> sending the client cert.  I know it's opening the keystore with my
> client cert in it, because I verified it with strace.
>
> Do I need to use a SSL socket factory class to make this work, or is
> it supposed to work out of the box and if so how?

You'll need a custom SSLSocketFactory (like the one included in 
PgClientCertDemo) if you want to target current 8.x versions reliably. 
Make it configurable, though, because with 9.x Pg versions you won't 
need it, and using a custom SSLSocketFactory makes it practically 
impossible for the user to use PKCS#11 hardware keys and the like.

--
Craig Ringer

Attachments:

  PgClientCertDemo.zip (application/x-zip-compressed, 10.3K) download

view thread (7+ messages)  latest in thread

Message-ID: <4C0712E6.1050002@postnewspapers.com.au>
Permalink:  ../4C0712E6.1050002@postnewspapers.com.au/
Also on:    postgresql.org/message-id/4C0712E6.1050002@postnewspapers.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: craig@postnewspapers.com.au, jwbaker@gmail.com
  Subject: Re: JDBC SSL with postgresql
  In-Reply-To: <4C0712E6.1050002@postnewspapers.com.au>
  References: <AANLkTikptvIa8hE5J_9lzqIwZYuQ7AMHLQIiZh8uAFEn@mail.gmail.com> <4C0712E6.1050002@postnewspapers.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox