pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Walter Hurry <walterhurry@lavabit.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: JDBC with SSL
Date: Wed, 7 Dec 2011 18:00:00 +0000 (UTC)
Message-ID: <jbo9j0$ntf$1@dough.gmane.org> (raw)
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>
	<jbj3ii$9ab$1@dough.gmane.org>
	<4EDD65BC.4010605@ringerc.id.au>
	<jblr8s$inm$1@dough.gmane.org>
	<4EDEF445.10006@ringerc.id.au>
	<4EDF9403.9060400@distributedmatter.net>

On Wed, 07 Dec 2011 16:27:47 +0000, Bruno Harbulot wrote:

> On 07/12/2011 05:06, Craig Ringer wrote:
>> On 07/12/11 03:43, Walter Hurry wrote:
>>> On Tue, 06 Dec 2011 08:45:48 +0800, Craig Ringer wrote:
>>>
>>>> On 12/06/2011 02:46 AM, Walter Hurry wrote:
>>>>> ------------------------------------------------------------- $ java
>>>>> -Djavax.net.ssl.keyStore=$HOME/.postgresql/clientstore \
>>>>>          -Djavax.net.ssl.keyStorePassword=changeit \
>>>>>          -Djavax.net.ssl.keyStoreType="jks" \
>>>>>
>>>> I thought you could only use a JECKS store when including private
>>>> keys?
>>> Sorry, I'm pretty new to all this. What is a JECKS store? Does it mean
>>> I have the keyStoreType wrong?
>>
>> JKS and JECKS are two different key store formats. Keytool understands
>> both. If my memory serves, JECKS is the encrypted keystore format,
>> intended for storing private key data. I think you can use JECKS for
>> both certificate and key data, but you can use JKS only for certificate
>> data, NOT  for key data.
> 
> You can store certificates and/or private keys in both JKS and JECKS.
> 
> PKCS12 is somewhat different in that, to store a certificate (or a
> certificate chain), it requires there to be a private key associated
> with this certificate. Java isn't the only implementation with this
> limitation, but I must admit I can't remember what the PKCS#12
> specification itself says about it.
> 
> 
> More details on JKS/JECKS, from:
> http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/
CryptoSpec.html#KeystoreImplementation
> 
>> jceks" is an alternate proprietary keystore format to "jks" that uses
>> much stronger encryption in the form of Password-Based Encryption with
>> Triple-DES.
> 
> 
> 
> The default keystore type with the Oracle security provider is JKS; you
> can check this using KeyStore.getDefaultType().
> 
> 
> If your initial key and certs where in PEM format (as used by psql), it
> might be easier to build a PKCS#12 store with OpenSSL:
> 
>     openssl pkcs12 -export -in usercert.pem -inkey userkey.pem -out
> usercreds.p12
> 
> 
> You can then use it with KeyStore type "PKCS12" (no #) from Java
> directly.
> You could also convert this PKCS#12 file into a JKS/JECKS keystore using
> keytool and its -importstore options (only in Java 6+).

Eureka! That nailed it (I used the pkcs12 file as it was, and didn't 
bother to convert it). Very many thanks Bruno, and to everyone who 
offered help. It is deeply appreciated.

$ java -Djavax.net.ssl.keyStore=$HOME/.postgresql/postgresql.p12 \
>        -Djavax.net.ssl.keyStorePassword=changeit \
>        -Djavax.net.ssl.keyStoreType=PKCS12 \
>        -Djavax.net.ssl.trustStore=$HOME/.postgresql/server.jceks \
>        -Djavax.net.ssl.trustStorePassword=changeit \
>        -Djavax.net.ssl.trustStoreType=jceks \
>        JDBCExample neptune misc
-------- PostgreSQL JDBC Connection Testing ------------
PostgreSQL JDBC driver registered
Getting connection to jdbc:postgresql://neptune/misc
Connection successful
$ 

Thanks again,
Walter





view thread (25+ messages)

Message-ID: <jbo9j0$ntf$1@dough.gmane.org>
Permalink:  ../jbo9j0$ntf$1@dough.gmane.org/
Also on:    postgresql.org/message-id/jbo9j0$ntf$1@dough.gmane.org

 · 

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: walterhurry@lavabit.com
  Subject: Re: JDBC with SSL
  In-Reply-To: <jbo9j0$ntf$1@dough.gmane.org>
  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> <jbj3ii$9ab$1@dough.gmane.org> <4EDD65BC.4010605@ringerc.id.au> <jblr8s$inm$1@dough.gmane.org> <4EDEF445.10006@ringerc.id.au> <4EDF9403.9060400@distributedmatter.net> <jbo9j0$ntf$1@dough.gmane.org>

* 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