Friday, May 24, 2013

Installation and configuration of Mercurial

Installation

Windows :

The best version of Mercurial for Windows is TortoiseHg, which can be found at http://tortoisehg.bitbucket.org/ . This package has no external dependencies. It “just works.” It provides both command-line and graphical user interfaces.
After installation, you will have a right-click menu in Windows Explorer that gives you access to the graphical tools. After logging out and in again, you will also have a hg and a thg program available in a Command Prompt. You can use the thg program to start the graphical TortoiseHg tools.

Command-line : (figure 1)



GUI : (figure2)


Linux :

You can install Mercurial on Linux using package manager -
yum install *mercurial*
but installing it from package manager not assure you the latest version of mercurial.
So, You can install the latest version(2.6) from source http://mercurial.selenic.com/release , unpack it and run make install to install it.
If you get any issue like “error: command 'gcc' failed with exit status 1 ” then install following thing

            yum install python

Check the correct version of devel and install it :

           yum search python | grep -i devel
           yum install python-devel.x86_64
           yum install python-docutils

To find out whether the Mercurial is installed properly. Check hg version command. If the Mercurial is installed properly, You can see the version information as below (figure 3) :


Configuration

Once your setup is ready, You have to add username in the configuration file.

Linux :

create new file having name “.hgrc” under $HOME directory and
[ui]
username =Firstname Lastname <example@example.org>

(Figure 4)


Windows:

create new file having name “Mercurial.ini” under $HOME directory and add
[ui]
username =Firstname Lastname <example@example.org>

To confirm, You have added username correctly, Run hg debuginstall command. You will get the message “No problem detected.”

What is Mercurial ?

Mercurial is a fast, lightweight Source Control Management system designed for efficient handling of very large distributed projects. It is mainly implemented using the Python programming language. It is supported on Windows and Unix-like systems, such as Mac OS X and Linux.

All of Mercurial's operations are invoked as arguments to its driver program hg, a reference to the chemical symbol of the element mercury.

Mercurial's major design goals include high performance and scalability, decentralized, fully distributed collaborative development, robust handling of both plain text and binary files, and advanced branching and merging capabilities, while remaining conceptually simple. 


How you can benefit from Mercurial

  1. It is fast and powerful, It efficiently handles projects of any size and kind. Every clone contains the whole project history, so most actions are local, fast and convenient.
  2. Mercurial supports a multitude of workflows and you can easily enhance its functionality with extensions.
  3. It is easy to learn and use
  4. It is lightweight.
  5. It scales excellently.

How to read certificates using CertificateFactory class

In my previous blog, I have explained how can you create self signed certificate using bouncy castle API and how to import it into keystore.

This tutorial will explain how to read existing certificate file using java.security.cert.CertificateFactory class.


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyStore;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;

/**
 * Reads the certificate and import into Java keystore.
 *
 * @author abdul
 *
 */
public class ReadCertificateFile {

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        ReadCertificateFile readCertificateFile = new ReadCertificateFile();

        // Path of the certificate file
        FileInputStream fis = new FileInputStream("YOUR_CERTIFICATE.cert");

        /*
         * Returns a CertificateFactory object of the specified certificate
         * type.
         */
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
       
        /*
         * Read the certificate from the specified input stream, and returns it
         * as a Certificate object. It can read certificate in both binary (DER
         * encoded) and printable (RFC standard) formats.
         */
        java.security.cert.Certificate cert = cf.generateCertificate(fis);

        System.out.println();
        System.out.println("Certificate Details: ");
        /*Returns the type of this certificate factory*/
        System.out.println("Type = " + cert.getType());
       
        System.out.println("toString = " + cert.toString());

        PublicKey key = cert.getPublicKey();
        System.out.println();
        System.out.println("PublicKey Object Info: ");
        System.out.println("Algorithm = " + key.getAlgorithm());
        System.out.println("Format = " + key.getFormat());
        System.out.println("toString = " + key.toString());

        // save/import certificate into keystore
        readCertificateFile.saveCert(cert);
    }

    private void saveCert(Certificate cert) throws Exception {
        KeyStore keyStore = KeyStore.getInstance("JKS");
        keyStore.load(null, null);

        // import your certificate into keystore
        keyStore.setCertificateEntry("YOUR_ALIAS_NAME", cert);

        // name of keystore "
        File file = new File(".", "YOUR_KEYSTORE_NAME");
        keyStore.store(new FileOutputStream(file),
                "YOUR_PASSWORD".toCharArray());
    }

}


How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...