Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 09474B5D803 for ; Sat, 6 Aug 2011 00:05:16 -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 87943-01-2 for ; Sat, 6 Aug 2011 03:05:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 2598EB5DC03 for ; Sat, 6 Aug 2011 00:05:08 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QpXCB-0006R8-H9 for pgsql-jdbc@postgresql.org; Sat, 06 Aug 2011 05:05:03 +0200 Received: from cpc10-with5-2-0-cust74.1-4.cable.virginmedia.com ([86.26.85.75]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 06 Aug 2011 05:05:03 +0200 Received: from bruno by cpc10-with5-2-0-cust74.1-4.cable.virginmedia.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 06 Aug 2011 05:05:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Bruno Harbulot Subject: JDBC SSL hostname verification Date: Sat, 06 Aug 2011 04:00:40 +0100 Lines: 42 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: cpc10-with5-2-0-cust74.1-4.cable.virginmedia.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.831 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.931 X-Spam-Level: X-Archive-Number: 201108/22 X-Sequence-Number: 22054 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.