Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 435E41FDBD2F for ; Sun, 4 Dec 2011 20:28:59 -0400 (AST) Received: from mail-qw0-f53.google.com ([209.85.216.53]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RXMQQ-0000Q9-QG for pgsql-jdbc@postgresql.org; Mon, 05 Dec 2011 00:28:58 +0000 Received: by qadb15 with SMTP id b15so2436040qad.19 for ; Sun, 04 Dec 2011 16:28:41 -0800 (PST) Received: by 10.224.198.10 with SMTP id em10mr5936329qab.44.1323044921587; Sun, 04 Dec 2011 16:28:41 -0800 (PST) Received: from ayaki.localdomain (203-173-33-169.dyn.iinet.net.au. [203.173.33.169]) by mx.google.com with ESMTPS id 8sm21975946qaf.9.2011.12.04.16.28.37 (version=SSLv3 cipher=OTHER); Sun, 04 Dec 2011 16:28:39 -0800 (PST) Message-ID: <4EDC1031.2010607@ringerc.id.au> Date: Mon, 05 Dec 2011 08:28:33 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1 MIME-Version: 1.0 To: Walter Hurry CC: pgsql-jdbc@postgresql.org Subject: Re: JDBC with SSL References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/13 X-Sequence-Number: 22467 On 12/05/2011 04:48 AM, Walter Hurry wrote: > On Sun, 04 Dec 2011 20:09:09 +0100, Florent Guillaume wrote: > >> Hi, >> >> You have to install the certificate in the Java keystore using >> "keytool". See >> http://docs.oracle.com/javase/tutorial/security/toolsign/rstep2.html for >> a quick overview. >> A more detailed doc is at >> http://docs.oracle.com/javaee/1.4/tutorial/doc/Security6.html >> >> Florent >> >> On Sun, Dec 4, 2011 at 5:40 PM, Walter Hurry >> wrote: >>> First of all, I am sorry if this is the wrong place to ask. If it is, >>> perhaps someone could direct me to the right arena. >>> >>> This is PostgreSQL 9.0.1 with PostgreSQL JDBC 9.1.901. >>> >>> I have successfully set up one of my databases to require SSL >>> connections with a certificate, and installed a certificate into >>> $HOME/.postgresql. That directory contains postgresql.crt, >>> postgresql.key and root.crt. >>> >>> I can connect successfully using psql and libpq applications. The >>> connection is also rejected properly if I move the certificate out of >>> the way. >>> >>> Now I am trying to connect using JDBC and SSL from a Java application >>> (JDBC is fine without SSL on another database). However, I am getting >>> the following error: >>> >>> FATAL: connection requires a valid client certificate >>> >>> So it appears that somehow I need to "tell" Java where to find the >>> client certificate. Any pointers as to how I do this please? >>> >>> By the way, since this is a self-signed certificate I have followed the >>> instructions at>> client.html>. These succeeded, but I am still getting the error. >>> >>> Thanks, >>> Walter > Thanks for the reply, Florent. I have followed the instructions yu > mentioned carefully, and am now invoking the class with: > > java -Djava.security.manager -Djava.security.policy=clientpolicy > > You don't need the SecurityManager enabled. You need the java.net.ssl properties for keyStore, keyStorePassword and keyStoreType set to point to your JECKS keystore, and need trustStore, trustStorePassword and trustStoreType set to point to the keystore you imported the database's certificate into, which is probably the same store in your case. Alternately, you can use the custom certificate manager class posted on this mailing list a while ago to manage key and trust store lookup from your own stores at runtime. -- Craig Ringer