From: Craig Ringer <ringerc@ringerc.id.au>
To: Bruno Harbulot <bruno@distributedmatter.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC SSL hostname verification
Date: Sat, 06 Aug 2011 20:02:08 +0800
Message-ID: <4E3D2D40.3000405@ringerc.id.au> (raw)
In-Reply-To: <j1iaoo$uu$1@dough.gmane.org>
References: <j1iaoo$uu$1@dough.gmane.org>
On 6/08/2011 11:00 AM, Bruno Harbulot wrote:
> 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.
JSSE doesn't verify the hostname automatically. Quoting the JSSE
reference guide for Java 6:
"When using raw SSLSockets/SSLEngines you should always check the peer's
credentials before sending any data. The SSLSocket and SSLEngine classes
do not automatically verify that the hostname in a URL matches the
hostname in the peer's credentials. An application could be exploited
with URL spoofing if the hostname is not verified."
I was under the impression that PgJDBC verified the hostname its self
unless verification was disabled, but it seems not. Hmm. I guess you can
use a custom SSLSocketFactory to do the verification, but it really
should be something done by the stock JDBC driver. Patch?
--
Craig Ringer
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: ringerc@ringerc.id.au, bruno@distributedmatter.net
Subject: Re: JDBC SSL hostname verification
In-Reply-To: <4E3D2D40.3000405@ringerc.id.au>
References: <j1iaoo$uu$1@dough.gmane.org> <4E3D2D40.3000405@ringerc.id.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