Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 69656B5DBE7 for ; Wed, 18 May 2011 10:19:31 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 15192-08 for ; Wed, 18 May 2011 13:19:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id 81C6BB5DBD4 for ; Wed, 18 May 2011 10:19:24 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id 72A60EB; Wed, 18 May 2011 09:19:23 -0400 (EDT) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1qgRNou19yAH; Wed, 18 May 2011 09:19:22 -0400 (EDT) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id 13CED27; Wed, 18 May 2011 09:19:22 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id C6233AE6FC; Wed, 18 May 2011 21:19:20 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 44NJw5w+YygE; Wed, 18 May 2011 21:19:15 +0800 (WST) Received: from [10.1.1.5] (124-169-254-58.dyn.iinet.net.au [124.169.254.58]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 4DA09AE6EA; Wed, 18 May 2011 21:19:15 +0800 (WST) Message-ID: <4DD3C751.5080908@postnewspapers.com.au> Date: Wed, 18 May 2011 21:19:13 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Thunderbird/3.1.10 MIME-Version: 1.0 To: =?windows-1252?Q?Marc-Andr=E9_Laverdi=E8re?= CC: pgsql-jdbc@postgresql.org Subject: Re: Support for cert auth in JDBC 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> In-Reply-To: <4DD379C5.1030703@atc.tcs.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/51 X-Sequence-Number: 21881 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