Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C26B3B5DBD5 for ; Sat, 6 Aug 2011 09:02:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 73356-07 for ; Sat, 6 Aug 2011 12:02:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f42.google.com (mail-pz0-f42.google.com [209.85.210.42]) by mail.postgresql.org (Postfix) with ESMTP id A9B88B5DBD0 for ; Sat, 6 Aug 2011 09:02:14 -0300 (ADT) Received: by pzk37 with SMTP id 37so8572019pzk.15 for ; Sat, 06 Aug 2011 05:02:14 -0700 (PDT) Received: by 10.142.209.1 with SMTP id h1mr3252194wfg.142.1312632134737; Sat, 06 Aug 2011 05:02:14 -0700 (PDT) Received: from [10.1.1.8] (124-169-181-228.dyn.iinet.net.au [124.169.181.228]) by mx.google.com with ESMTPS id i5sm1402700wff.6.2011.08.06.05.02.12 (version=SSLv3 cipher=OTHER); Sat, 06 Aug 2011 05:02:14 -0700 (PDT) Message-ID: <4E3D2D40.3000405@ringerc.id.au> Date: Sat, 06 Aug 2011 20:02:08 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Bruno Harbulot CC: pgsql-jdbc@postgresql.org Subject: Re: JDBC SSL hostname verification References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201108/23 X-Sequence-Number: 22055 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