Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 4B2C363266D for ; Wed, 2 Jun 2010 23:43:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 31949-03 for ; Thu, 3 Jun 2010 02:43:25 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id BF48C6323FF for ; Wed, 2 Jun 2010 23:43:27 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id D19D9A2AB; Thu, 3 Jun 2010 10:43:16 +0800 (WST) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id DD154AFB18; Thu, 3 Jun 2010 10:41:36 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id CNJLW+iwzWwj; Thu, 3 Jun 2010 10:41:30 +0800 (WST) Received: from [10.1.1.7] (124-148-251-30.dyn.iinet.net.au [124.148.251.30]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 95AC2AE2A1; Thu, 3 Jun 2010 10:41:30 +0800 (WST) Message-ID: <4C0716C1.9070009@postnewspapers.com.au> Date: Thu, 03 Jun 2010 10:43:13 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: Jeffrey Baker CC: pgsql-jdbc@postgresql.org Subject: Re: JDBC SSL with postgresql References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/27 X-Sequence-Number: 20597 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 might help you out. I've been meaning to push it to gitgub. Sources: http://www.postnewspapers.com.au/~craig/PgClientCertDemo.zip Executable: http://www.postnewspapers.com.au/~craig/PgClientCertDemo.jar > 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