how to access the server certs on sun one directory server 5.2 from java

I need the sample java code to download server certs on sun one directory server 5.2
[91 byte] By [bkrsa] at [2007-11-27 0:49:24]
# 1
What for exactly? If you use SSL you will get them during the handshake and you can access them via the SSLSession or a HandshakeCompletedListener.
ejpa at 2007-7-11 23:18:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2

I enabled SSL in SUN ONE Directory Server 5.2, I use the following code to download the server certs,

Hashtable env = new Hashtable(11);

env.put(Context.INITIAL_CONTEXT_FACTORY,

"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, "ldaps://bharatkumar.webm.webmethods.com:636/o=in");

env.put(Context.SECURITY_AUTHENTICATION, "EXTERNAL");

env.put(Context.SECURITY_PROTOCOL, "ssl");

try {

// Create initial context

DirContext ctx = new InitialDirContext(env);

System.out.println(ctx.lookup("ou=web"));

ctx.close();

} catch (NamingException e) {

e.printStackTrace();

}

But it throws the following error:

javax.naming.CommunicationException: SASL bind failed: bharat.com:636 [Root exception is javax.net.ssl.SSLHandshakeException: sun.security.

validator.ValidatorException: PKIX path building failed: sun.security.provider.c

ertpath.SunCertPathBuilderException: unable to find valid certification path to

requested target]

at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:220)

at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2637)

at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:283)

at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)

at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193

How to rectify the above error?

Kindly Help me.

Thanks,

Bharat

bkrsa at 2007-7-11 23:18:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3
That code doesn't download server certificates except implicitly via SSL - is that what you mean?The issue here is that the server's certificate isn't trusted by the client's truststore. See http://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html.
ejpa at 2007-7-11 23:18:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 4

server certs installed in sun one directory server is not trusted.

Verisign - Trail SSL Certificate is installed into server certs. But it is not trusted. How can I explicitly trusted that certificate. (OR) where can i get the trusted certificate and installed into server cert.

Kindly Help me,

Thanks,

Bharat

bkrsa at 2007-7-11 23:18:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...