[Date Prev][Date Next] [Chronological] [Thread] [Top]

[JLDAP] Store X509 object programmatically



Hello everybody,

first post!
Hope this is not OT.


I'm trying to use Novell JLDAP API (June 04, 2003 release) to interface
to OpenLDAP 2.1.10 on a RH 8.0 linux box.

Standard operations seem to work, but I could not get to store a
X509Certificate object, based on the AddEntry.java example.
I can add the entry (used userCertificate and userSMIMECertificate) but
the value shown is '0'.
I'm _quite_ sure I passed the X509 as DER...
I tried both the constructor, LDAPAttribute(Object,byte[]) and the
method addValue(byte[]).


Looks like it's not converted to BINARY...

Oddly, the password object is marked as binary (used LDAP browser/editor
to check)


Can anyone help?


Here's my code snippet:
/****************************************************************/

/*
Get the certificate, connection, etc...
Then...
*/

 LDAPConnection lc = new LDAPConnection();
	 LDAPAttribute  attribute = null;
	 LDAPAttributeSet attributeSet = new LDAPAttributeSet();

     
      	 attributeSet.add( new LDAPAttribute( 
						  "objectclass", new String("inetOrgPerson")));                
	 attributeSet.add( new LDAPAttribute("cn", 
			 new String[]{"JamesWilson  Smith", "Jim W. Smith", "Jimmy W.
Smith"}));               
	 attributeSet.add( new LDAPAttribute("givenname",
							  new String[]{"James", "Jim", "Jimmy" }));        
	 attributeSet.add( new LDAPAttribute("sn", new
String("Smith")));        
	 attributeSet.add( new LDAPAttribute("telephonenumber",
										 new String("1 801 555
1212")));                                                     
	 attributeSet.add( new LDAPAttribute("mail", 
										new String("JSmith@Acme.com")));
										
			LDAPAttribute pwd = null;							
	 attributeSet.add( pwd = new LDAPAttribute("userpassword", 
											new String("newpassword")));     //This one becomes BINARY
when stored, //but it's a normal string in the constructor.
                                      

	LDAPAttribute cert = null;
	
	
 try {
	byte[] crtBytes = certif.getEncoded(); // gets the DER version of the
X509 - IAIK JCE library

	
	cert = new LDAPAttribute("userCertificate",crtBytes);
	// or userSMIMECertificate
	
     //cert.addValue(crtBytes);
	boolean added = attributeSet.add(cert);
	    
	System.out.println("Certificate:\n" + "added=" +added + "\n" +
cert.toString() +"\n\npwd=" + pwd.toString());
	
	                                            
                                               
	 String  dn  = "cn=JSmith Wilson 13," + containerName;      
	 LDAPEntry newEntry = new LDAPEntry( dn, attributeSet );

	 try {
		 // connect to the server
		 lc.connect( ldapHost, ldapPort );
		 // authenticate to the server
		 lc.bind( ldapVersion, loginDN, password );

		 lc.add( newEntry );
		 System.out.println( "\nAdded object: " + dn + " successfully." );

		 // disconnect with the server
		 lc.disconnect();
	 }
	 catch( LDAPException e ) {
		 System.out.println( "Error:  " + e.toString());
	 }                                   
	 System.exit(0);
 }