From: Bruno Harbulot <bruno@distributedmatter.net>
To: pgsql-jdbc@postgresql.org
Subject: JDBC SSL hostname verification
Date: Sat, 06 Aug 2011 04:00:40 +0100
Message-ID: <j1iaoo$uu$1@dough.gmane.org> (raw)
Hello,
I have noticed that I was able to connect using SSL (with a trusted
certificate) to a server using a name that doesn't match that in the
certificate.
For example, if both "sql.example.com" and "other.example.net" point to
the same IP address, but the certificate is not issued to
"other.example.net" (only "sql.example.com"), the following works when
it shouldn't:
Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "xxxxxxxx");
props.setProperty("ssl", "true");
Connection jdbcConnection =
DriverManager.getConnection("jdbc:postgresql://other.example.net/db", props)
Hostname verification (what 'verify-full' does with psql) is necessary
for ensuring the security of the connection. Verifying that the
certificate is trusted isn't sufficient.
Only this should work:
Connection jdbcConnection =
DriverManager.getConnection("jdbc:postgresql://sql.example.com/db", props)
Did I miss a property to set?
I hope I'm not duplicating an existing feature, but I couldn't find
anything that performed this verification in the existing code base, so
I've implemented a patch to support it. It seems to work well against
versions 8.4 and 9.0 at least.
If this of interest to anyone, I'd be happy to contribute it to the
PostgreSQL community. (Please let me know what the procedure to do so is.)
Best wishes,
Bruno.
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: bruno@distributedmatter.net
Subject: Re: JDBC SSL hostname verification
In-Reply-To: <j1iaoo$uu$1@dough.gmane.org>
References: <j1iaoo$uu$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