pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <ringerc@ringerc.id.au>
To: Walter Hurry <walterhurry@lavabit.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC with SSL
Date: Mon, 05 Dec 2011 08:28:33 +0800
Message-ID: <4EDC1031.2010607@ringerc.id.au> (raw)
In-Reply-To: <jbgma6$a91$1@dough.gmane.org>
References: <jbg7qf$9mn$1@dough.gmane.org>
	<CAF-4BpMJrya0ioXz4vn61bp2BG0X8YR6VkJ00do02n=gM=G2FA@mail.gmail.com>
	<jbgma6$a91$1@dough.gmane.org>

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<walterhurry@lavabit.com>
>> 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<http://jdbc.postgresql.org/documentation/81/ssl-
>>> 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
> <classname>
>
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



view thread (25+ messages)  latest in thread

Message-ID: <4EDC1031.2010607@ringerc.id.au>
Permalink:  ../4EDC1031.2010607@ringerc.id.au/
Also on:    postgresql.org/message-id/4EDC1031.2010607@ringerc.id.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: ringerc@ringerc.id.au, walterhurry@lavabit.com
  Subject: Re: JDBC with SSL
  In-Reply-To: <4EDC1031.2010607@ringerc.id.au>
  References: <jbg7qf$9mn$1@dough.gmane.org> <CAF-4BpMJrya0ioXz4vn61bp2BG0X8YR6VkJ00do02n=gM=G2FA@mail.gmail.com> <jbgma6$a91$1@dough.gmane.org> <4EDC1031.2010607@ringerc.id.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