Saturday, May 28, 2011

How to export a private key to be used with ssldump

I used a keystore which is generated using java keytool, where my private key is stored; in order to be used in SSL communication that took place between a service hosted in Apache Tomcat and a sample client.

You can find a step by step guide for creating a keystore using java keytool from here.

Today I had the requirement of viewing the messages passed over SSL, using the ssldump.
Once again you can find a guide on ssl debugging with ssldump from here.

In one of the steps there, you will need to provide the server's private key in order for ssldump to decrypt the symmetric key exchanged between client and server and use it for decrypting the ssl traffic.

As I got to know, java keytool doesn't provide an easy way to export private key out of the keystore.
Out of the several ways I tried, keytool-iui helped me to achieve my requirement in a matter of seconds.

Hence, here I will keep a note on the steps I followed:

Step 1: Download the tool from here.

Step 2: Extract it and execute following command being at the 'ktl241sta' folder. (You can find it in readme file also)
java -jar rc15ktl.jar

Step 3: Then select and provide necessary information as shown in the image below:

  • Select Export -> Keystore's Entry->Private Key from left hand panel.
  • Under 'Source', provide the keystore file and password and the format, in this case, keystore is of jks file format.
  • Provide the relevant file locations where the private key and the certificate to be exported, under 'Target'. And the format required by ssldump is PEM.
That's it!. Now you can use this private key with ssldump to view ssl traffic.

On a side note, I also tried openssl to achieve the same, as I read in several places. But failed with the following error.
Error decrypting key
28838:error:0906D064:PEM routines:PEM_read_bio:bad base64 decode:pem_lib.c:759:

If you have any idea about the reason and if you have successfully achieve this with opensssl, please share with us as well...

Related post:

Saturday, April 23, 2011

How to introduce a custom object class to embedded LDAP of Identity Server

WSO2 Identity Server (IS) 3.2.0 comes with an embedded-apacheds ldap as the default user store. We can introduce new attributes to embedded-ldap through custom object classes, in order to use them when persisting user information in  IS.

I have described how to write a custom object class and introduce it to a stand alone LDAP server in my previous post.

In this post I intend to describe how to import a custom object class to Identity Server's default user store and how to use it when adding users to IS.

Step 1: Write your custom object class with the required additional attributes and save it with .ldif extension. 

Before defining attributes in your custom object class, make sure to check what are the attributes that are already supportted  by LDAP  for creating user entries, so that you can use them without defining new attributes and also can avoid conflicts with existing attribute names.

Following is the custom object class that we will import into embedded-apacheds of IS.
dn: cn=schema
changetype: modify
add: attributeTypes
attributeTypes: ( 2.25.128424792425578037463837247958458780603.6
        NAME 'nicNumber'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
attributeTypes: ( 2.25.128424792425578037463837247958458780603.7
        NAME 'passportNumber'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )
-
add: objectClasses
objectClasses: ( 2.25.128424792425578037463837247958458780603.8
    NAME 'samplePerson'
    DESC 'samplePerson'
    SUP wso2Person
    STRUCTURAL
    MAY  ( nicNumber $ passportNumber)
 )
This object class named: 'samplePerson' defines two new attributes to store NIC No. and Passport No. of a user. 
Note the line 19 which implies that 'samplePerson' inherits the 'wso2Person' which is once again a custom object class that we have already introduced to embedded-ldap of IS.

Step 2: Download the latest IS build from here. [IS 3.2.0 is not released yet and a latest build from trunk is hosted in this location.]

Step 3: Start Identity Server and connect to its embedded-ldap through Apache Directory Studio. If you are not familiar with Apache Directory Studio before, this post describes how to perform this step.

Step 4: Import the ldif file containing the new object class definition into the LDAP instance of IS.
You can do it as follows:
i). Locate the 'LDAP Browser' window in Apache Directory Studio as shown below.
                                                                      figure 1
ii). Right click on the 'ou=schema' context entry, select 'import->LDIF import' and point to the samplePerson ldif file and import it.
If you do not see any errors, that means ldif is successfully imported.

Step 6: Use the new object class for creating users in Identity Server.

To reflect the effect of the new object class in embedded-ldap, we need to restart the the Identity Server and also need to do some configuration level changes.
i).  Shutdown the IS.
ii). Locate 'embedded-ldap.xml' and 'user-mgt.xml' config files in [IS_HOME]/repository/conf folder and do the following changes.
  • Find the 'EmbeddedLDAP' element in embedded-ldap.xml and change its 'AdminEntryObjectClass' property value to 'samplePerson'.
samplePerson
  • Find 'UserStoreManager' element in 'user-mgt.xml' and change its 'UserEntryObjectClass' property to 'samplePerson' so that when adding users in IS, user entries will be created with new objectClass.
samplePerson 
iii). Delete the directory named: 'root' located in the path: [IS_HOME]/repository/data/org.wso2.carbon.directory. - so that default partition will be created again at the restart with admin user entry constructed with new objectClass.

iv). Start Identity Server.

v). Login to the management console with admin, admin credentials and add a new user through 'Users and Roles' tab in left hand panel.

vi). Now view the ldap user entry of the newly added user through 'LDAP Browser' window of Apache Directoy Studio.
                                                          figure 2
As you can see in the above figure 2, new user entry is constructed with the objecClass 'samplePerson'.

Step 7: You can use newly introduced attributes in user's profile of IS through 'Claim Management', which you will find in the left hand panel of  the management console.

VoilĂ , we are done.. :)

Friday, April 22, 2011

Connecting to the user store of Identity Server through Apache Directory Studio

WSO2 Identity Server (IS) 3.2.0 will be shipped with an embedded-apacheds ldap as the default user store.
We may need to connect it to through a UI tool in order to browse the structure and entries, importing ldif files etc..

This simple post describes how to connect to Identity Server's embedded-ldap through Apache Directory Studio tool.

1. Download and install Apache Directory Studio from here.

2. Start Identity Server and connect to its embedded-ldap from Apache Directory Studio as shown below.
step 2.1:
step 2.2:
Fill the following details in the new connection window you get:
step 2.3:
Click Next and fill the authentication details in the next window as follows.
DN of the bind user: uid=admin,ou=system
Bind password: 'admin'.

You may skip the other steps in the wizard and finish creating the connection.
Now you can view the ldap structure of IS's default user store in the LDAP Browser window as shown below.

One tiny tip before we windup- when ever you do an update to the embedded-ldap through IS, make sure to click the 'refresh' button in the LDAP Browser window shown above, in order to observe the changes through ApacheDS Studio UI tool.