org.ourgrid.common.security
Class KeyToolWrapper

java.lang.Object
  extended by org.ourgrid.common.security.KeyToolWrapper

public class KeyToolWrapper
extends java.lang.Object

This class provides an abstraction to use the KeyTool features. The idea is to generate self-signed certificates, as well import and export signatures to the user KeyStore file. The keystore file is located at the $MGROOT/var/$USER.keys by deafult.


Field Summary
protected static java.lang.String ALIAS
          This option is used to specify an alias to identfy the certificate
protected static java.lang.String DNAME
          Option to specify personal information of the certificate
protected  Executor executor
          To execute the KeyTool application
static java.lang.String EXPORT
          Export certificates from a KeyStore
protected static java.lang.String FILE
          Exported certificate file specification option
static java.lang.String GENKEY
          Generation a key entry option
static java.lang.String IMPORT
          Import certificates to the KeyStore option
protected static java.lang.String KEYPASS
          This option is used to specify a password associated to the generated Key
protected static java.lang.String KEYSIZE
          the keysize option that determines the size in bits of the generated key
protected static java.lang.String KEYSTORE
          Keystore file specification option
protected static java.lang.String KEYTOOL
          The keytool command line
protected static java.lang.String LIST
          This option is used to list KEYSTORE content
protected static int MAXSIZE
          Determine the maximum keysize supported by the KeyTool
protected  ExecutorResult result
          Store the result of the execution of the KeyTool
protected static java.lang.String STOREPASS
          This option is used to specify a password associated to the KeyStore
protected static java.lang.String VALIDITY
          This option determines the validity of the certificate
 
Constructor Summary
KeyToolWrapper()
          This method constructs a new instance of the
 
Method Summary
protected  boolean aliasExists(java.lang.String alias, java.lang.String keystoreName)
          This method verifies the existence of the alias into the keystore.
protected  boolean execute(java.lang.String commandLine)
          This method executes the key tool command that is determined by the public methods.
 boolean generateKey(java.lang.String alias, java.lang.String commonName, java.lang.String keystoreName, int keysize, int validity)
          This method provides an interface to the key entry generation into the Keystore specified.
 boolean transportCertificate(java.lang.String alias, java.lang.String keystoreName, java.lang.String certificateFilename, java.lang.String operation)
          This method perform the key importation and exportation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXSIZE

protected static final int MAXSIZE
Determine the maximum keysize supported by the KeyTool

See Also:
Constant Field Values

KEYTOOL

protected static final java.lang.String KEYTOOL
The keytool command line

See Also:
Constant Field Values

GENKEY

public static final java.lang.String GENKEY
Generation a key entry option

See Also:
Constant Field Values

IMPORT

public static final java.lang.String IMPORT
Import certificates to the KeyStore option

See Also:
Constant Field Values

EXPORT

public static final java.lang.String EXPORT
Export certificates from a KeyStore

See Also:
Constant Field Values

KEYSTORE

protected static final java.lang.String KEYSTORE
Keystore file specification option

See Also:
Constant Field Values

FILE

protected static final java.lang.String FILE
Exported certificate file specification option

See Also:
Constant Field Values

KEYSIZE

protected static final java.lang.String KEYSIZE
the keysize option that determines the size in bits of the generated key

See Also:
Constant Field Values

VALIDITY

protected static final java.lang.String VALIDITY
This option determines the validity of the certificate

See Also:
Constant Field Values

DNAME

protected static final java.lang.String DNAME
Option to specify personal information of the certificate

See Also:
Constant Field Values

STOREPASS

protected static final java.lang.String STOREPASS
This option is used to specify a password associated to the KeyStore

See Also:
Constant Field Values

KEYPASS

protected static final java.lang.String KEYPASS
This option is used to specify a password associated to the generated Key

See Also:
Constant Field Values

ALIAS

protected static final java.lang.String ALIAS
This option is used to specify an alias to identfy the certificate

See Also:
Constant Field Values

LIST

protected static final java.lang.String LIST
This option is used to list KEYSTORE content

See Also:
Constant Field Values

executor

protected Executor executor
To execute the KeyTool application


result

protected ExecutorResult result
Store the result of the execution of the KeyTool

Constructor Detail

KeyToolWrapper

public KeyToolWrapper()
This method constructs a new instance of the

Method Detail

generateKey

public boolean generateKey(java.lang.String alias,
                           java.lang.String commonName,
                           java.lang.String keystoreName,
                           int keysize,
                           int validity)
This method provides an interface to the key entry generation into the Keystore specified.

Parameters:
alias - an alias to identify the certificate
commonName - the CN field that is used to identify the key entry.
keystoreName - the filename where the key entries are stored.
keysize - the size of generated key in bytes
validity - how many days the key will be a valid key
Returns:
true if the execution has been sucessfull. false otherwise.

transportCertificate

public boolean transportCertificate(java.lang.String alias,
                                    java.lang.String keystoreName,
                                    java.lang.String certificateFilename,
                                    java.lang.String operation)
This method perform the key importation and exportation. The operation is defined by the parameter and the fields KeyToolWrapper.IMPORT and KeyToolWrapper.EXPORT must be used.

Parameters:
alias - the identificator of the key that must be transported
keystoreName - the name of the file that store the certificates
certificateFilename - the name of the file to/from the certificate goes/comes
operation - the operation that must be performed. KeyToolWrapper.IMPORT and KeyToolWrapper.EXPORT
Returns:
true if the operation was successfully executed false otherwise.

aliasExists

protected boolean aliasExists(java.lang.String alias,
                              java.lang.String keystoreName)
This method verifies the existence of the alias into the keystore.

Parameters:
alias - The alias name
keystoreName - The name of the file that stores the certificates
Returns:
true if alias already exists. false otherwise.

execute

protected boolean execute(java.lang.String commandLine)
This method executes the key tool command that is determined by the public methods.

Parameters:
commandLine - the command line that represents a key generation, certificate importation or exportation.
Returns:
true if the execution has been successfull. false otherwise.