From nmset@netcourrier.com Fri Feb 20 09:40:28 2009 Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CCA416331AB for ; Fri, 20 Feb 2009 05:40:28 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 01346-07 for ; Fri, 20 Feb 2009 05:40:24 -0400 (AST) X-Greylist: delayed 00:08:33.806289 by SQLgrey-1.7.6 Received: from smtp.nmset.info (cop60-2-88-163-134-117.fbx.proxad.net [88.163.134.117]) by mail.postgresql.org (Postfix) with ESMTP id CB29D6331A6 for ; Fri, 20 Feb 2009 05:40:24 -0400 (AST) Received: by smtp.nmset.info (Postfix, from userid 65534) id 4E68F98390; Fri, 20 Feb 2009 10:31:45 +0100 (CET) Received: from vos.nmset.info (cop60-2-88-163-134-117.fbx.proxad.net [88.163.134.117]) by smtp.nmset.info (Postfix) with ESMTP id BC5209838E for ; Fri, 20 Feb 2009 10:31:41 +0100 (CET) From: "Saleem EDAH-TALLY" To: pgsql-jdbc@postgresql.org Subject: SSL - Providing client certificates Date: Fri, 20 Feb 2009 10:30:32 +0100 User-Agent: KMail/1.11.0 (Linux/2.6.27.7; KDE/4.2.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="Boundary-00=_5gnnJK48M1V9Fz6" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200902201030.33352.nmset@netcourrier.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.218 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001, RCVD_IN_SORBS_WEB=1.117, RDNS_DYNAMIC=0.1 X-Spam-Level: * X-Archive-Number: 200902/33 X-Sequence-Number: 19308 --Boundary-00=_5gnnJK48M1V9Fz6 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Hello, http://jdbc.postgresql.org/documentation/83/ssl-factory.html states : "Specifically it would be nice to be able to provide client certificates to be validated by the server." http://jdbc.postgresql.org/documentation/83/ssl-client.html refers to validating the server's identity only, using javax.net.ssl.trustStore JVM-wide setting. However, if we set javax.net.ssl.keyStore and javax.net.ssl.keyStorePassword, the SSL connection is established and the client certificate is verified. This seems contradictory with the documntation, or I am missing something. I would be happy to read your comments. Thank you. --Boundary-00=_5gnnJK48M1V9Fz6 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit Hello,


http://jdbc.postgresql.org/documentation/83/ssl-factory.html states :


"Specifically it would be nice to be able to provide client certificates to be validated by the server."


http://jdbc.postgresql.org/documentation/83/ssl-client.html refers to validating the server's identity only, using javax.net.ssl.trustStore JVM-wide setting.


However, if we set javax.net.ssl.keyStore and javax.net.ssl.keyStorePassword, the SSL connection is established and the client certificate is verified.


This seems contradictory with the documntation, or I am missing something.


I would be happy to read your comments.


Thank you.

--Boundary-00=_5gnnJK48M1V9Fz6-- From books@ejurka.com Fri Feb 20 17:29:49 2009 Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D01E063862E for ; Fri, 20 Feb 2009 13:29:49 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 01258-03 for ; Fri, 20 Feb 2009 13:29:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail.postgresql.org (Postfix) with ESMTP id C445B63862A for ; Fri, 20 Feb 2009 13:29:42 -0400 (AST) Received: by leary.csoft.net (Postfix, from userid 1112) id 5EE8FACA6; Fri, 20 Feb 2009 12:29:40 -0500 (EST) Date: Fri, 20 Feb 2009 12:29:39 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Saleem EDAH-TALLY cc: pgsql-jdbc@postgresql.org Subject: Re: SSL - Providing client certificates In-Reply-To: <200902201030.33352.nmset@netcourrier.com> Message-ID: References: <200902201030.33352.nmset@netcourrier.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200902/37 X-Sequence-Number: 19312 On Fri, 20 Feb 2009, Saleem EDAH-TALLY wrote: > However, if we set javax.net.ssl.keyStore and javax.net.ssl.keyStorePassword, > the SSL connection is established and the client certificate is verified. > When the code was first written, this wasn't tested and it was just assumed that it wouldn't work. Recently we got a report that it did work, but the documentation was not updated. What I don't understand is how it selects the certificate to send. If you have multiple keys in your keystore, how do you indicate which one to use? Kris Jurka From gc@mnc.ch Mon Feb 23 11:25:50 2009 Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id DC639634346 for ; Mon, 23 Feb 2009 07:25:50 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 01770-03 for ; Mon, 23 Feb 2009 07:25:47 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.mnc.ch (62-2-77-205.static.cablecom.ch [62.2.77.205]) by mail.postgresql.org (Postfix) with ESMTP id 896D063396A for ; Mon, 23 Feb 2009 07:25:43 -0400 (AST) Received: from localhost (mail2.mnc.ch [127.0.0.1]) by mail.mnc.ch (Postfix) with ESMTP id 0CF742307A; Mon, 23 Feb 2009 11:25:40 +0000 (GMT) X-Virus-Scanned: amavisd-new at mnc.ch Received: from mail.mnc.ch ([127.0.0.1]) by localhost (mail2.mnc.ch [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id PNshwPisZv8V; Mon, 23 Feb 2009 11:25:39 +0000 (GMT) Received: from meuh.localdomain (62-2-77-204.static.cablecom.ch [62.2.77.204]) by mail.mnc.ch (Postfix) with ESMTP id 8132023079; Mon, 23 Feb 2009 11:25:39 +0000 (GMT) Received: by meuh.localdomain (Postfix, from userid 1000) id 44CB6DF211; Mon, 23 Feb 2009 12:25:40 +0100 (CET) To: Kris Jurka Cc: Saleem EDAH-TALLY , pgsql-jdbc@postgresql.org Subject: Re: SSL - Providing client certificates References: <200902201030.33352.nmset@netcourrier.com> From: Guillaume Cottenceau X-Hashcash: 1:20:090223:books@ejurka.com::xcPslE9WU4tV2LnZ:04F/o X-Hashcash: 1:20:090223:nmset@netcourrier.com::2hkB2XivKqx7uAPj:00000000000000000000000000000000000000006EKG X-Hashcash: 1:20:090223:pgsql-jdbc@postgresql.org::WIkj8ulsVBR0BMwC:0000000000000000000000000000000000003zIX Date: Mon, 23 Feb 2009 12:25:40 +0100 In-Reply-To: (Kris Jurka's message of "Fri\, 20 Feb 2009 12\:29\:39 -0500 \(EST\)") Message-ID: <87iqn1v1hn.fsf@meuh.mnc.lan> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200902/40 X-Sequence-Number: 19315 Kris Jurka writes: > On Fri, 20 Feb 2009, Saleem EDAH-TALLY wrote: > >> However, if we set javax.net.ssl.keyStore and javax.net.ssl.keyStorePassword, >> the SSL connection is established and the client certificate is verified. >> > > When the code was first written, this wasn't tested and it was just > assumed that it wouldn't work. Recently we got a report that it did > work, but the documentation was not updated. > > What I don't understand is how it selects the certificate to send. If > you have multiple keys in your keystore, how do you indicate which one > to use? My quite limited understanding of the behaviour of SSL client authentication may potentially help a little: You initially send a certificate signing request to the admin/owner of the server (signed with your private key); when you receive the certificate reply (signed with their private key), you can build a chain of trust between you and the server, your keystore will look like: Entry type: PrivateKeyEntry Certificate chain length: 2 Certificate[1]: Owner: Issuer: Certificate[2]: Owner: Issuer: Then at the SSL handshake time, first the server presents his certificate, second it asks for a client certificate, at that time you are able to present the certificate belonging to the chain of trust containing the server certificate on top. -- Guillaume Cottenceau From nmset@netcourrier.com Mon Feb 23 14:54:26 2009 Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1F15463373B for ; Mon, 23 Feb 2009 10:54:26 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 20960-02 for ; Mon, 23 Feb 2009 10:54:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp.nmset.info (cop60-2-88-163-134-117.fbx.proxad.net [88.163.134.117]) by mail.postgresql.org (Postfix) with ESMTP id 58465632214 for ; Mon, 23 Feb 2009 10:54:20 -0400 (AST) Received: by smtp.nmset.info (Postfix, from userid 65534) id 93BD098390; Mon, 23 Feb 2009 15:54:16 +0100 (CET) Received: from vos.nmset.info (cop60-2-88-163-134-117.fbx.proxad.net [88.163.134.117]) by smtp.nmset.info (Postfix) with ESMTP id 6564B9838D; Mon, 23 Feb 2009 15:54:13 +0100 (CET) Resent-From: "Saleem EDAH-TALLY" Resent-To: "Saleem Edah-Tally" Resent-Date: Mon, 23 Feb 2009 15:50:42 +0100 Resent-Message-ID: <200902231550.42914.nmset@netcourrier.com> From: "Saleem EDAH-TALLY" To: pgsql-jdbc@postgresql.org Subject: Re: SSL - Providing client certificates Date: Mon, 23 Feb 2009 15:53:02 +0100 User-Agent: KMail/1.11.0 (Linux/2.6.27.7; KDE/4.2.0; x86_64; ; ) References: <200902201030.33352.nmset@netcourrier.com> <87iqn1v1hn.fsf@meuh.mnc.lan> In-Reply-To: <87iqn1v1hn.fsf@meuh.mnc.lan> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200902231519.29993.nmset@netcourrier.com> Content-Type: multipart/alternative; boundary="Boundary-00=_PhroJDNQIjNXH0g" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.218 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001, RCVD_IN_SORBS_WEB=1.117, RDNS_DYNAMIC=0.1 X-Spam-Level: * X-Archive-Number: 200902/42 X-Sequence-Number: 19317 --Boundary-00=_PhroJDNQIjNXH0g Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Regarding Kris Jurka's question : > > What I don't understand is how it selects the certificate to send. If > > you have multiple keys in your keystore, how do you indicate which one > > to use? http://java.sun.com/javase/6/docs/api/javax/net/ssl/SSLContext.html#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom) states <> Only the first instance of a particular key and/or trust manager implementation type in the array is used... Hence it's not necessary to overload a keystore or a truststore. And who knows how the entries in the keystore are sorted an presented to SSLContext.init. My guess they are sorted in ascending order of the aliases, but it's just a guess. As an add-on to this thread, the following class allows to build a SSLSocketFactory that is not JVM wide but specific to a connection. It can be passed as sslfactory, and a label passed as sslfactoryarg. It may be adapted and included in the jdbc-driver if found useful. ********************************************************************** public class SSLBoth extends javax.net.ssl.SSLSocketFactory{ private String ksFile = null; private String ksType = null; private String ksPwd = null; private String tsFile = null; private String tsType = null; private String tsPwd = null; private javax.net.ssl.SSLSocketFactory ssf = null; public SSLBoth(String label) { setParams(label); javax.net.ssl.KeyManagerFactory kmf = makeKMF(); javax.net.ssl.TrustManagerFactory tmf = makeTMF(); javax.net.ssl.SSLContext sslc = makeSSLContext(kmf.getKeyManagers(), tmf.getTrustManagers()); ssf = sslc.getSocketFactory(); } private void setParams(String label) { ksFile = System.getProperty("KEYSTORE_FILE_" + label); ksType = System.getProperty("KEYSTORE_TYPE_" + label); ksPwd = System.getProperty("KEYSTORE_PWD_" + label); tsFile = System.getProperty("TRUSTSTORE_FILE_" + label); tsType = System.getProperty("TRUSTSTORE_TYPE_" + label); tsPwd = System.getProperty("TRUSTSTORE_PWD_" + label); } private javax.net.ssl.KeyManagerFactory makeKMF() { java.security.KeyStore ks = loadKeyStore(ksFile, ksType, ksPwd); if (ks != null) { try { javax.net.ssl.KeyManagerFactory kmf = javax.net.ssl.KeyManagerFactory.getInstance(javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm()); kmf.init(ks, ksPwd.toCharArray()); return kmf; } catch (java.security.KeyStoreException ex) { ex.printStackTrace(); } catch (java.security.UnrecoverableKeyException ex) { ex.printStackTrace(); } catch (java.security.NoSuchAlgorithmException ex) { ex.printStackTrace(); } } return null; } private javax.net.ssl.TrustManagerFactory makeTMF() { java.security.KeyStore ts = loadKeyStore(tsFile, tsType, tsPwd); if (ts != null) { try { javax.net.ssl.TrustManagerFactory tmf = javax.net.ssl.TrustManagerFactory.getInstance(javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm()); tmf.init(ts); return tmf; } catch (java.security.KeyStoreException ex) { ex.printStackTrace(); } catch (java.security.NoSuchAlgorithmException ex) { ex.printStackTrace(); } } return null; } private javax.net.ssl.SSLContext makeSSLContext(javax.net.ssl.KeyManager[] km, javax.net.ssl.TrustManager[] tm) { try { javax.net.ssl.SSLContext sslc = javax.net.ssl.SSLContext.getInstance("TLS"); sslc.init(km, tm, new java.security.SecureRandom()); return sslc; } catch (java.security.KeyManagementException ex) { ex.printStackTrace(); } catch (java.security.NoSuchAlgorithmException ex) { ex.printStackTrace(); } return null; } public static java.security.KeyStore loadKeyStore(String ksPath, String type, String pwd) { try { java.security.KeyStore ks = java.security.KeyStore.getInstance(type); java.io.FileInputStream fis = new java.io.FileInputStream(ksPath); ks.load(fis, pwd.toCharArray()); fis.close(); return ks; } catch (java.security.KeyStoreException ex) { ex.printStackTrace(); } catch (java.io.FileNotFoundException ex) { ex.printStackTrace(); } catch (java.io.IOException ex) { ex.printStackTrace(); } catch (java.security.NoSuchAlgorithmException ex) { ex.printStackTrace(); } catch (java.security.cert.CertificateException ex) { ex.printStackTrace(); } return null; } @Override public String[] getDefaultCipherSuites() { return ssf.getDefaultCipherSuites(); } @Override public String[] getSupportedCipherSuites() { return ssf.getSupportedCipherSuites(); } @Override public java.net.Socket createSocket(java.net.Socket arg0, String arg1, int arg2, boolean arg3) throws java.io.IOException { return ssf.createSocket(arg0, arg1, arg2, arg3); } @Override public java.net.Socket createSocket(String arg0, int arg1) throws java.io.IOException, java.net.UnknownHostException { return ssf.createSocket(arg0, arg1); } @Override public java.net.Socket createSocket(String arg0, int arg1, java.net.InetAddress arg2, int arg3) throws java.io.IOException, java.net.UnknownHostException { return ssf.createSocket(arg0, arg1, arg2, arg3); } @Override public java.net.Socket createSocket(java.net.InetAddress arg0, int arg1) throws java.io.IOException { return ssf.createSocket(arg0, arg1); } @Override public java.net.Socket createSocket(java.net.InetAddress arg0, int arg1, java.net.InetAddress arg2, int arg3) throws java.io.IOException { return ssf.createSocket(arg0, arg1, arg2, arg3); } } ********************************************************************** --Boundary-00=_PhroJDNQIjNXH0g Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable p, li { white-space: pre-wrap; }Regarding Kris Jurka's question :



> > What I don't understand is how it selects the certificate to send= =2E If
> > you have multiple keys in your keystore, how do you = indicate which one
> > to use?



http://java.sun.com/javase/6/docs/api/javax/net/ssl/SSLContext.html#init(ja= vax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.Secur= eRandom)



states



<>
Only the first instance of a particular key and/or trust mana= ger implementation type in the array is used...
</>



Hence it's not necessary to overload a keystore or a truststore.



And who knows how the entries in the keystore are sorted an presented to SS= LContext.init. My guess they are sorted in ascending order of the aliases, = but it's just a guess.



As an add-on to this thread, the following class allows to build a SSLSocke= tFactory that is not JVM wide but specific to a connection. It can be passe= d as sslfactory, and a label passed as sslfactoryarg.
It may be adapte= d and included in the jdbc-driver if found useful.



**********************************************************************
public class SSLBoth extends javax.net.ssl.SSLSocketFactory{
priv= ate String ksFile =3D null;
private String ksType =3D null;
= private String ksPwd =3D null;
private String tsFile =3D null;<= br /> private String tsType =3D null;
private String tsPwd =3D = null;
private javax.net.ssl.SSLSocketFactory ssf =3D null;
=
public SSLBoth(String label) {
setParams(label); javax.net.ssl.KeyManagerFactory kmf =3D makeKMF();
= javax.net.ssl.TrustManagerFactory tmf =3D makeTMF();
javax.ne= t.ssl.SSLContext sslc =3D makeSSLContext(kmf.getKeyManagers(), tmf.getTrust= Managers());
ssf =3D sslc.getSocketFactory();
}
=
private void setParams(String label) {
ksFile = =3D System.getProperty("KEYSTORE_FILE_" + label);
ksType =3D S= ystem.getProperty("KEYSTORE_TYPE_" + label);
ksPwd =3D System.= getProperty("KEYSTORE_PWD_" + label);
tsFile =3D System.getPro= perty("TRUSTSTORE_FILE_" + label);
tsType =3D System.getProper= ty("TRUSTSTORE_TYPE_" + label);
tsPwd =3D System.getProperty("= TRUSTSTORE_PWD_" + label);
}
private javax.net.ssl.KeyMan= agerFactory makeKMF() {
java.security.KeyStore ks =3D loadKeyS= tore(ksFile, ksType, ksPwd);
if (ks !=3D null) {
= try {
javax.net.ssl.KeyManagerFactory kmf =3D java= x.net.ssl.KeyManagerFactory.getInstance(javax.net.ssl.KeyManagerFactory.get= DefaultAlgorithm());
kmf.init(ks, ksPwd.toCharArray())= ;
return kmf;
} catch (java.security.= KeyStoreException ex) {
ex.printStackTrace();
= } catch (java.security.UnrecoverableKeyException ex) {
= ex.printStackTrace();
} catch (java.security.NoS= uchAlgorithmException ex) {
ex.printStackTrace();
}
}
return null;
}
= private javax.net.ssl.TrustManagerFactory makeTMF() {
java.se= curity.KeyStore ts =3D loadKeyStore(tsFile, tsType, tsPwd);
if= (ts !=3D null) {
try {
javax.net.ssl= =2ETrustManagerFactory tmf =3D javax.net.ssl.TrustManagerFactory.getInstanc= e(javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm());
= tmf.init(ts);
return tmf;
} cat= ch (java.security.KeyStoreException ex) {
ex.printStac= kTrace();
} catch (java.security.NoSuchAlgorithmException = ex) {
ex.printStackTrace();
}
= }
return null;
}
private javax.net.ssl= =2ESSLContext makeSSLContext(javax.net.ssl.KeyManager[] km, javax.net.ssl.T= rustManager[] tm) {
try {
javax.net.ssl.SSLCo= ntext sslc =3D javax.net.ssl.SSLContext.getInstance("TLS");
= sslc.init(km, tm, new java.security.SecureRandom());
ret= urn sslc;
} catch (java.security.KeyManagementException ex) {<= br /> ex.printStackTrace();
} catch (java.security.= NoSuchAlgorithmException ex) {
ex.printStackTrace();
= }
return null;
}
public static java.= security.KeyStore loadKeyStore(String ksPath, String type, String pwd) { try {
java.security.KeyStore ks =3D java.securi= ty.KeyStore.getInstance(type);
java.io.FileInputStream fis= =3D new java.io.FileInputStream(ksPath);
ks.load(fis, pwd= =2EtoCharArray());
fis.close();
return ks= ;
}

catch (java.security.KeySto= reException ex) {
ex.printStackTrace();
}
catch (java.io.FileNotFoundException ex) {
ex.pr= intStackTrace();
}
catch (java.io.IOException ex)= {
ex.printStackTrace();
}
catch= (java.security.NoSuchAlgorithmException ex) {
ex.printSta= ckTrace();
}
catch (java.security.cert.Certificat= eException ex) {
ex.printStackTrace();
}
return null;
}



@Override
public String[] getDefaultCipherSuites() {
= return ssf.getDefaultCipherSuites();
}



@Override
public String[] getSupportedCipherSuites() {
= return ssf.getSupportedCipherSuites();
}



@Override
public java.net.Socket createSocket(java.net.Socket = arg0, String arg1, int arg2, boolean arg3) throws java.io.IOException {
return ssf.createSocket(arg0, arg1, arg2, arg3);
}
=


@Override
public java.net.Socket createSocket(String arg0, int= arg1) throws java.io.IOException, java.net.UnknownHostException {
= return ssf.createSocket(arg0, arg1);
}



@Override
public java.net.Socket createSocket(String arg0, int= arg1, java.net.InetAddress arg2, int arg3) throws java.io.IOException, jav= a.net.UnknownHostException {
return ssf.createSocket(arg0, arg= 1, arg2, arg3);
}



@Override
public java.net.Socket createSocket(java.net.InetAdd= ress arg0, int arg1) throws java.io.IOException {
return ssf.c= reateSocket(arg0, arg1);
}



@Override
public java.net.Socket createSocket(java.net.InetAdd= ress arg0, int arg1, java.net.InetAddress arg2, int arg3) throws java.io.IO= Exception {
return ssf.createSocket(arg0, arg1, arg2, arg3); }



}



**********************************************************************





--Boundary-00=_PhroJDNQIjNXH0g--