Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2978F1337B50 for ; Tue, 14 Sep 2010 19: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 33566-05 for ; Tue, 14 Sep 2010 22:05:10 +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 2F0391337B6C for ; Tue, 14 Sep 2010 19:05:08 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Ovdcd-0003dt-Kq for pgsql-jdbc@postgresql.org; Wed, 15 Sep 2010 00:05:03 +0200 Received: from p54a67122.dip.t-dialin.net ([84.166.113.34]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 15 Sep 2010 00:05:03 +0200 Received: from chris by p54a67122.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 15 Sep 2010 00:05:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Christian Ullrich Subject: Patch: SSPI authentication support Date: Wed, 15 Sep 2010 00:03:44 +0200 Lines: 102 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040102070400080607070301" X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: p54a67122.dip.t-dialin.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 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: 201009/26 X-Sequence-Number: 20896 This is a multi-part message in MIME format. --------------040102070400080607070301 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Hello all, the attached patches provide support for the (Windows-only) SSPI authentication method in the JDBC driver. They will need more testing; I hope to find some volunteers here. Please note that these patches support SSPI authentication by using the existing GSSAPI code, they do _not_ require the underlying system to know anything about SSPI. The patches are based on CVS HEAD. The resulting driver works on both Windows 7 and Windows XP SP3 clients in a domain with a Windows 2008 DC, accessing PostgreSQL 8.4.4 on a (different) Windows 2008 server. I have not tested any other combination of clients and servers, if you have the opportunity, please test it on your systems. It would be nice to find out if non-Windows systems can log on to Windows servers configured for SSPI if they are in the same Kerberos realm. The first patch, "1-sspi-ConnectionFactoryImpl.patch", adds client-side SSPI support in the simplest possible way: by acting as if it was the same as GSSAPI. This works, probably because the Negotiate SSP that is used by the server for SSPI authentication is clever enough to also handle incoming GSSAPI tokens (without SPNEGO encapsulation). Although this patch leads to successful authentication, it is therefore not a complete solution, because it relies on the Negotiate SSP violating its own protocol. I have only tested the combination of clients and server I described above; if you have the opportunity, please test it on your systems. The second patch, "2-sspi-MakeGSS.patch", improves on the first one by adding the OID for the SPNEGO mechanism to the authenticator. This works only on Sun Java 1.6 and later; SPNEGO support is not available in earlier releases. With this change, the SPNEGO negotiation is actually performed on the wire. In my environment, this works even with "sun.security.spnego.msinterop=false". Even though this change resulted in perfect authentication in my environment, I keep thinking, "it was too easy". If you agree, please let me know what I failed to consider. -- Christian --------------040102070400080607070301 Content-Type: text/plain; name="1-sspi-ConnectionFactoryImpl.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="1-sspi-ConnectionFactoryImpl.patch" --- a/org/postgresql/core/v3/ConnectionFactoryImpl.java Tue Sep 14 23:09:00 2010 +0200 +++ b/org/postgresql/core/v3/ConnectionFactoryImpl.java Tue Sep 14 23:09:53 2010 +0200 @@ -375,6 +375,7 @@ } case AUTH_REQ_GSS: + case AUTH_REQ_SSPI: org.postgresql.gss.MakeGSS.authenticate(pgStream, host, user, password, info.getProperty("jaasApplicationName"), @@ -382,12 +383,6 @@ logger); break; - case AUTH_REQ_SSPI: - if (logger.logDebug()) - logger.debug(" <=BE AuthenticationReqSSPI"); - - throw new PSQLException(GT.tr("SSPI authentication is not supported because it is not portable. Try configuring the server to use GSSAPI instead."), PSQLState.CONNECTION_REJECTED); - case AUTH_REQ_OK: if (logger.logDebug()) logger.debug(" <=BE AuthenticationOk"); --------------040102070400080607070301 Content-Type: text/plain; name="2-sspi-MakeGSS.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="2-sspi-MakeGSS.patch" --- a/org/postgresql/gss/MakeGSS.java Tue Sep 14 23:09:53 2010 +0200 +++ b/org/postgresql/gss/MakeGSS.java Tue Sep 14 23:11:11 2010 +0200 @@ -83,8 +83,9 @@ try { - org.ietf.jgss.Oid desiredMechs[] = new org.ietf.jgss.Oid[1]; - desiredMechs[0] = new org.ietf.jgss.Oid("1.2.840.113554.1.2.2"); + org.ietf.jgss.Oid desiredMechs[] = new org.ietf.jgss.Oid[2]; + desiredMechs[0] = new org.ietf.jgss.Oid("1.3.6.1.5.5.2"); + desiredMechs[1] = new org.ietf.jgss.Oid("1.2.840.113554.1.2.2"); GSSManager manager = GSSManager.getInstance(); --------------040102070400080607070301--