Wednesday, July 7, 2010

Java Keytool Keystore Commands

Create Keystore, Keys and Certificate Requests
  • Generate a Java keystore and key pair
    keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -storepass password
  • Generate a certificate signing request (CSR) for an existing Java keystore
    keytool -certreq -alias mydomain -keystore keystore.jks -storepass password -file mydomain.csr
  • Generate a keystore and self-signed certificate
    keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360
Import Certificates
  • Import a root or intermediate CA certificate to an existing Java keystore
    keytool -import -trustcacerts -alias root -file Thawte.crt -keystore keystore.jks -storepass password
  • Import a signed primary certificate to an existing Java keystore
    keytool -import -trustcacerts -alias mydomain -file mydomain.crt -keystore keystore.jks -storepass password
  • Import New CA into Trusted Certs
    keytool -import -trustcacerts -file /path/to/ca/ca.pem -alias CA_ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts
Export Certificates
  • Export a certificate from a keystore
    keytool -export -alias mydomain -file mydomain.crt -keystore keystore.jks -storepass password
Check/List/View
  • Check a stand-alone certificate
    keytool -printcert -v -file mydomain.crt
  • Check which certificates are in a Java keystore
    keytool -list -v -keystore keystore.jks -storepass password
  • Check a particular keystore entry using an alias
    keytool -list -v -keystore keystore.jks -storepass password -alias mydomain
  • List Trusted CA Certs
    keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts
Delete Certificates
  • Delete a certificate from a Java Keytool keystore
    keytool -delete -alias mydomain -keystore keystore.jks -storepass password
Change Passwords
  • Change a Java keystore password
    keytool -storepasswd -new new_storepass -keystore keystore.jks -storepass password
  • Change a private key password
    keytool -keypasswd -alias client -keypass old_password -new new_password -keystore client.jks -storepass password

Friday, June 18, 2010

Ubuntu - Copy Everything Except

If you want to copy everything within a directory, except certain files or directories, you can use the following command.
cp -a `ls | grep -v yourexcludepattern` ../destinationdir/

Assume, you want to copy all files, except *.java within from the current directory to the foo directory. Then, the command would be,
cp -a `ls | grep -v *.java` /home/wageesha/foo

Friday, June 11, 2010

How to copy a file into multiple directories in Ubuntu

Assume that you want to copy a file into multiple directories in the current directory, then all you have to do is, just entering following command in the terminal. Here, file.txt will be copied into all directories in the current directory. In case of a directory coping, replace file.txt with -rf [your dir].
for dir in *; do [ -d "$dir" ] && cp file.txt "$dir" ; done
for dir in *; do [ -d "$dir" ] && cp -rf /home/wageesha/images "$dir" ; done

Sunday, May 23, 2010

WSO2 Mashup Server - Google Maps API Key Mashup

If you are using Google Maps in your web site, you need to get an API key from Google.com. In order to do that, you need to login using an existing Google account, accept their terms and policies and finally you will be able to get the Google Maps API key. Although this is the usual procedure, if they provide a web service for it, it will be much useful in places where you want to get the key at runtime.

As an example, WSO2 Mashup Server has a Twitter Maps Mashup which shows recent tweets in a Google map. In order to have the proper functionality of this mashup independent of the domain where the server is running, it needs to dynamically generate an API key for that domain and use it within the Twitter map mashup. That was the original motivation towards this mashup.

You will need to deploy the following mashup in the WSO2 Mashup Server 2.0.2 or a newer one.
getAPIKey.inputTypes = { "username" : "string", "password" : "string", "url" : "string" };
getAPIKey.output = "string";
function getAPIKey(username, password, url) {
    var client = new HttpClient();
    var code = client.executeMethod("GET", "https://www.google.com/accounts/Login");
    if (code == 200) {
        var galx = client.cookies[0].value;
        var content = [
            { name : "Email", value : username },
            { name : "Passwd", value : password },
            { name : "signIn", value : "Sign in" },
            { name : "GALX", value : String(galx) },
            { name : "dsh", value : "5537526595243201224"},
            { name : "rmShown", value : "1"},
            { name : "PersistentCookie", value : "yes"}
        ];
        code = client.executeMethod("POST", "https://www.google.com/accounts/LoginAuth", content);
        if (code == 302 || code == 200) {
            code = client.executeMethod("GET", "http://code.google.com/apis/maps/signup/createkey", [
                { name : "referer", value : url }
            ]);
            if (code == 200) {
                var response = eval('(' + client.response + ')');
                client.releaseConnection();
                return response.generated_key;
            } else {
                client.releaseConnection();
                return new XML("" + code + "" + client.statusText + "");
            }
        } else {
            client.releaseConnection();
            return new XML("" + code + "" + client.statusText + "");
        }
    } else {
        client.releaseConnection();
        return new XML("" + code + "" + client.statusText + "");
    }
}

Friday, April 23, 2010

Subversion: How to revert to a previous revision

Assume that your current revision is 100 and you want to revert the repository to the revision 90. Then you can use the following command,
$ svn merge -rHEAD:90 .
As you have used . at the end, it will revert your local repository. Once commited you will get a new revision such as 101 which is same as revision 90. You can do this directly to a remote repository as well. In that case, replace . with repository url.

Wednesday, April 7, 2010

GCE O/L, A/L and Grade V Examination Results

Do you want to view O/L, A/L and Grade V results a bit earlier than http://www.doenets.lk lets us. I have tried it when it says, "New Await Results". You can do this using firebug addon on firefox.

www.doenets.lk lets us to check previous result too. These are displayed by the "New Await Results" table. So what you need to do is first select one of those forms and change action url to exam_OL.jsp, exam_AL.jsp or exam_GV.jsp as appropriate. You would also need to change the size/maxLength of the inputput field as well. Otherwise it won't let us to insert our full index number. That's all, fill it with your index number, submit and get your results. You can also do a http POST using your own form as well.

Attention : I am not responsible for the accuracy of results as www.doenets.lk might not have officialy released the results when you use this.

Sunday, March 21, 2010

How to enable mod rewrite on Apache

Tired up trying to enable mode rewrite on apache? Try this link which explains it quite well.
http://drupal.org/node/134439