pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: Marc-André Laverdière <marc-andre@atc.tcs.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Support for cert auth in JDBC
Date: Wed, 18 May 2011 21:19:13 +0800
Message-ID: <4DD3C751.5080908@postnewspapers.com.au> (raw)
In-Reply-To: <4DD379C5.1030703@atc.tcs.com>
References: <4DD34FE5.3020609@atc.tcs.com>
	<4DD35BEA.3020902@postnewspapers.com.au>
	<4DD361CA.3070907@atc.tcs.com>
	<4DD36EFC.6070707@postnewspapers.com.au>
	<4DD379C5.1030703@atc.tcs.com>

On 05/18/2011 03:48 PM, Marc-André Laverdière wrote:
> It is true that anyone who knows the right Java APIs can put that
> factory together with little pain. I just think that the average user
> shouldn't have to bother about it.

In that, I agree. Canned factories for simple cases like loading a 
PKCS#12 format cert file, loading an app-specified keystore with a 
callback for a password prompt, etc would make a lot of sense.

> So we end up with 3 different keystores (and maybe trust stores too),
> all of which may have different passwords. It is actually not that much
> of a big deal to use, but the 'defaults' won't help us here too much I
> think.

Quite right, if your different keystores must have different passwords 
then you'd need to implement your own factory.

> P.S. Undocumented detail: we need to put the user's name in the
> connection settings anyway, as it won't work without it.

Interesting. I've only ever used setups where X.509 certs are 
supplementary to traditional password authentication. I'm surprised that 
the username isn't just deduced from the X.509 DN.


A few comments on your code: Overall, it looks pretty sensible at first 
reading. There are a few things I noticed:

- The code doesn't accept arguments for keystore and truststore type, so 
it won't be possible to load (eg) a PKCS#12 certificate file directly. 
Only stores of the default types will work.

- It's not very subclassing-friendly, which could be an issue if it's to 
be shipped in PgJDBC.


Specific subclassing use cases I see are allowing different 
configuration mechanisms (Properties instances in thread-local storage, 
JNDI, BeanManager contexts, blah blah) and accepting pre-configured 
KeyStore & TrustStore instances. I needed to use the latter in my app, 
and the former could become an issue whenever you need to create 
CertAuthFactory instances with different configurations in the same app 
- for example, for different users.

Personally, I dislike the use of system properties for configuration of 
the class. It's totally thread-unsafe and is a real pain in any 
situation where you don't necessarily want exactly the same 
configuration for every instance. There's nothing wrong with having it 
as a convenient default, but it'd be nice to be able to override it with 
another configuration mechanism if this code is to ship with PgJDBC.

Alas the SSLSocketFactory interface doesn't offer any really nice 
options like a way to pass a Properties instance to the ctor, and 
accepting URL-encoded query-string like params as a String isn't 
attractive given their length and the potential password security 
issues. What I'd want to do is allow subclasses to override the 
configuration behaviour by:

- Lazily initializing _internalFactory on first access rather than in 
the ctor, so that:

- a subclass's ctor can do something useful and application-defined with 
the String parameter passed to the one-arg form, like reading a config 
file, looking up a Properties instance from a config service or JNDI, 
etc. This would require that:

- Configuration values are acessed via protected methods rather than 
direct System.getProperty() calls so those can be overridden by a 
subclass to get the information from elsewhere.

Ideally (IMO) also:

- the KeyStore instantiation and loading for ks and trustKs is done in 
protected methods too, so these can be completely overridden to obtain 
instances another way.

--
Craig Ringer



view thread (28+ messages)  latest in thread

Message-ID: <4DD3C751.5080908@postnewspapers.com.au>
Permalink:  ../4DD3C751.5080908@postnewspapers.com.au/
Also on:    postgresql.org/message-id/4DD3C751.5080908@postnewspapers.com.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: craig@postnewspapers.com.au, marc-andre@atc.tcs.com
  Subject: Re: Support for cert auth in JDBC
  In-Reply-To: <4DD3C751.5080908@postnewspapers.com.au>
  References: <4DD34FE5.3020609@atc.tcs.com> <4DD35BEA.3020902@postnewspapers.com.au> <4DD361CA.3070907@atc.tcs.com> <4DD36EFC.6070707@postnewspapers.com.au> <4DD379C5.1030703@atc.tcs.com> <4DD3C751.5080908@postnewspapers.com.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