You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by Milinda Lakmal <mi...@yahoo.com> on 2006/07/01 04:41:40 UTC

LDAP & Private key

Is anyone know how to store private key in LDAP.
And I have problem when trying to retrieve X.509 using this method. 

LDAPCertStoreParameters lcsp = new
LDAPCertStoreParameters("localhost", 389);
      CertStore cs = CertStore.getInstance("LDAP",lcsp);
      X509CertSelector xcs = new X509CertSelector();
      xcs.setSubject(newContext);
      Collection certs = cs.getCertificates(xcs);


But I succeeded when I use searching method.

        try {
            DirContext ctx = new InitialDirContext(env);
            SearchControls constraints = new SearchControls();
            constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration results = ctx.search(newContext, who, constraints);
            if (results.hasMore()) {
                SearchResult sr = (SearchResult) results.next();
                javax.naming.directory.Attributes xanswer = sr.getAttributes();
                javax.naming.directory.Attribute attribute = xanswer.get("userCertificate;binary");
                // check if userCertificate attribute missing
                if (attribute != null) {
                    // retrieve cert as binary object
                    Object bin = attribute.get();
                    // convert to byte array
                    byte[] buf = (byte[]) bin;
                    // convert to X.509 class
                    X509Certificate cert = null;
                    CertificateFactory cf =
                            CertificateFactory.getInstance("X.509");
                    ByteArrayInputStream bais = new
                            ByteArrayInputStream(buf);
                    while (bais.available() > 0) {
                        cert = (X509Certificate) cf.generateCertificate(bais);
                        System.out.println(cert.getIssuerUniqueID());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();

        }



 		
---------------------------------
Do you Yahoo!?
 Get on board. You're invited to try the new Yahoo! Mail Beta.