Hi,
I have some certificates from SAML metadata XML files and I will need
to use SSL to communicate with the relying party, in order to set up
SSL connection, I would create truststore. However, the standard
truststore will require a keystore backed by a file, and so I will have
to import all certificates found in my XML files to a keystore file
using the keytool. My desire is to simplify the administration so I can
just read and create X509Certificate from my XML file at runtime and
use those certificates as the trusts.
Method 1: I tried to this:
trustStore = KeyStore.getInstance("X509");
trustStore.load(null, pwd.toCharArray());
tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(trustStore);
SSLContext sslctx = SSLContext.getInstance("SSL");
sslctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
null);
// when I need to do SSL
X509Certificate idpCert = ... // find the cert from my
cache
trustStore.setCertificateEntry(idpURL, idpCert );
conn.setSSLSocketFactory(sslctx.getSocketFactory());
But I still keep getting "javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: No trusted certificate
found".
What's wrong here?
Method 2: I would attempt to implement my own X509TrustManager
class MyX509TrustManager implements X509TrustManager {
public void checkServerTrusted(X509Certificate[] x509Certificates,
String authType) ... {
// (a)
}
public X509Certificate[] getAcceptedIssuers() {
// (b)
}
If I go this, what is the algorithm at (a)? Is there any utility
library out there that can help me do chain verification?
At (b), should I just return the certificate I'm expecting, i.e.
idpCert?
Thanks a lot!
Hacking Bear - 14 Nov 2006 23:23 GMT
Hi,
Can anyone help me on this?
I believe at (a), we just need to loop through the certificates and
compare it to the one we are expecting. Correct? or I need something
else?
Thanks in advanced!
> Hi,
>
[quoted text clipped - 47 lines]
>
> Thanks a lot!
Ronny Schuetz - 16 Nov 2006 12:38 GMT
Hi,
> class MyX509TrustManager implements X509TrustManager {
> public void checkServerTrusted(X509Certificate[] x509Certificates,
[quoted text clipped - 8 lines]
> If I go this, what is the algorithm at (a)? Is there any utility
> library out there that can help me do chain verification?
If you don't have the full certificate path, you need to build it first.
Then you need to validate it by checking the certificate extensions
(i.e. to see if the certificate path is correct, if the certificate can
be used for your use case, if the certificate contains the right host
name (for server certificates), etc.), validation dates, revocation
status etc. and check if the CA certificate in the path is in your trust
store.
See
http://java.sun.com/j2se/1.4.2/docs/guide/security/certpath/CertPathProgGuide.html
for a library that would help you.
> At (b), should I just return the certificate I'm expecting, i.e.
> idpCert?
Return the trusted certificates from your trust store.
Best regards,
Ronny
Hacking Bear - 16 Nov 2006 18:38 GMT