Tuesday, August 04, 2009

Setting up Tortoise CVS with CollabNet

We recently moved from Sourceforge to CollabNet and had to make changes to our CVS client setup. Sourceforge uses "pserver", whereas Collabnet uses "ext ssh". This is how you can get Tortoise CVS to connect to CollabNet, without prompting you for passwords every time.

1. Create a pair of public/private keys
You can create a pair of keys using PuTTY Key Generator (PUTTYGEN.EXE). Simply press the Generate button and move your mouse to generate randomness. This will create a public key for pasting into an authorized_keys file. Press the Save public key and Save private key buttons to save the keys as files. I have saved mine as:

  • C:\Documents and Settings\[xpid]\ssh\id_dsa (private)
  • C:\Documents and Settings\[xpid]\ssh\id_dsa.pub (public)
Alternatively, you can use the UNIX utility "ssh-keygen", as explained in one of my previous posts here.

2. Store your public key on CollabNet

  • Log onto CollabNet
  • Click on My Workspace
  • Click on Authorization Keys
  • Paste the public key, generated in Step 1, into the Authorized Keys text area and press Update
3. Update Tortoise SSH Settings
  • Open TortoiseCVS Preferences
  • Go to the Tools tab
  • Add your private key to your SSH parameters, so that it becomes:
-i "C:\Documents and Settings\[xpid]\ssh\id_dsa" -l "%u" "%h"
Now, whenever you perform a CVS operation through Tortoise, it will not prompt you for a password.

Your CVSROOT should look something like this:

:ext:fahd_shariff@cvs-collabnet.server.com:/cvsroot/module
References:
Tortoise FAQs
CollabNet Help

Monday, July 27, 2009

Howto: Import Certificates into a Keystore

One night, our Java application, which connects to a webservice, started failing with the following error:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
This error meant that our application did not have a valid certificate, but since our application had been working fine for the past few months, the only plausible explanation was that the webservice that we were trying to connect to, had changed their certificate without telling us!

I then had to go about getting hold of the new certificate and importing it into my truststore, in order to get my application up and running again. This is how:

1) Save the SSL Certificate to a File
In Firefox 3.5 (it's easier):

  • Open the webservice url
  • Double-click the padlock icon (or right-click on page and select Page Info)
  • Click on the Security tab (the padlock icon)
  • Press View Certificate
  • Click on the Details tab
  • Press Export...
  • Choose a file to save to - I like to save as type: X.509 Certification (DER)
In Internet Explorer (IE 8):
  • Open the webservice url
  • Click the padlock icon and then on View Certificates
  • Click on Install Certificate, click Next
  • Choose Place all certificates in the following store and Browse to Personal
  • Click Next and run through the rest of the screens
  • Go to Start > Run > certmgr.msc
  • Select Personal
  • Right click on certificate, go to All Tasks > Export...
Once saved, you can view the certificate using Java Keytool as follows:
keytool -printcert -file mycert.cer

2) Import Certificate to Keystore
Now that we have saved the website certificate to a local file, we can use Java Keytool to import it into our keystore using the following command:

keytool -import -alias myalias -file mycert.cer \
        -keystore mytruststore
You can also display the contents of the keystore using the following command:
keytool -list -v -keystore mytruststore

Thursday, July 16, 2009

Enabling Desktop SSO in Firefox

This is how you can configure Firefox to use Desktop Single Sign On (SSO) / Kerberos authentication:
  • Go to about:config
  • Change your preference network.negotiate-auth.delegation-uris
  • to the domain you want to authenticate against, for example ".domain.com".
  • Change your preference network.negotiate-auth.trusted-uris
  • to the domain as above.
Now try going to a URL and you should be able to login automatically. This has been tried and tested with Firefox 3.5.

Friday, June 26, 2009

Fibonacci Shell Script

Here is a quick unix shell script which prints out the Fibonacci sequence:

0,1,1,2,3,5,8,13,21,34,55,89,144,...

The first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two.

#!/bin/sh
prev=0
next=1

echo $prev

while(true)
do
 echo $next

 #add the two numbers
 sum=$(($prev+$next))

 #swap
 prev=$next
 next=$sum
 sleep 1
done

Monday, June 01, 2009

Using XPath in Java

Given the following xml document:
<hosts>
  <host name="starship" port="8080"/>
  <host name="firefly" port="8180"/>
</hosts>
this is how you can use the javax.xml.xpath library to run an XPath query in order to obtain a list of host names:
//create a document
DocumentBuilderFactory domFactory = 
                     DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse("file.xml");

//create the xpath expression
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//host/@name");

//run the xpath query
Object result = expr.evaluate(doc, XPathConstants.NODESET);

//read results
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
    System.out.println(nodes.item(i).getNodeValue());
}