From: Craig Ringer <craig@2ndquadrant.com>
To: "Gabriel E. Sánchez Martínez" <gabrielesanchez@gmail.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: Client Certificate Authentication
Date: Tue, 19 Mar 2013 19:46:48 +0800
Message-ID: <51485028.80008@2ndquadrant.com> (raw)
In-Reply-To: <514358B4.7030109@gmail.com>
References: <514358B4.7030109@gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
On 03/16/2013 01:21 AM, "Gabriel E. Sánchez Martínez" wrote:
> I have a PostgreSQL database on a server. For security reasons, all
> client access from outside the server is restricted to certificate
> mode, i.e. the client sends SSL certificates rather than a password.
> Connecting with pgAdmin works well. Is there a way of creating a Java
> application that connects to this database with certificates? Any
> how-to guides, examples, or pointers on how to achieve this?
In most cases you can set the JSEE keystore and truststore properties to
get Java to use an existing keystore and truststore with your private
key and the server's public certificate installed. In particular, see:
http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingSto...
The keystore must be in JECKS format. You can create it with keytool.
Import the user's client certificate into it; you'll most likely have a
pkcs#12 format cert (.p12 file) but you might instead have separate PEM
format key and certs.
The truststore is optional and may be in JKS format if provided. If you
don't provide a truststore the system wide SSL root certificate trust
store for Java is used. That's fine unless your server is using a
self-signed cert for the server, in which case you'll want to either add
your private CA cert to the system truststore or specify your own
truststore as a jvm system property.
If you cannot use the system properties for whatever reason then you
need to provide your own SSLSocketFactory that uses the JSSE APIs to
load a keystore and truststore.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
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@2ndquadrant.com, gabrielesanchez@gmail.com
Subject: Re: Client Certificate Authentication
In-Reply-To: <51485028.80008@2ndquadrant.com>
References: <514358B4.7030109@gmail.com> <51485028.80008@2ndquadrant.com>
* 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