SafeJDBC v2.00

com.safejdbc.api
Class SafeJdbcSetter

java.lang.Object
  extended by com.safejdbc.api.SafeJdbcSetter

public final class SafeJdbcSetter
extends Object

Main API for SafeJDBC Driver loading & setting cryptography elements.

1) Driver loading parameters

The first step is to set the parameters of the SafeJDBC Driver:

2) Cryptography elements & parameters

The second step is to choose a Provider, a symmetric Algorithm and to set a 128 bit encryption Key or Passphrase.
SafeJDBC comes with a default Provider and a default Algorithm:
The triplet (Provider, Algorithm, encryption Key) is linked to a SafeJDBC User.

3) SafeJDBC driver loading & final getConnection()

When all parameters are set, load the driver using:
Class.forName("com.safejdbc.api.Driver").newInstance();

and get a "Cipher" Connection to the application database using the DriverManager.getConnection() method.

Example:

// This is the native wrapped Driver name
String sNativeDriver = "org.gjt.mm.mysql.Driver";

// This is the application database url
String sDbUrl = "jdbc:mysql://localhost:3306/sj_clients";

// These are the username & password for the application database
Properties propsApp = new Properties();
propsApp.put("user", "safelogic");
propsApp.put("password", "safelogic*$");

// This is the SafeJdbc Catalog database url
String sJdbcUrl = "jdbc:mysql://localhost:3306/safejdbc_catalog";

// These are the username & password for SafeJdbc Catalog database
Properties propsSjdbc = new Properties();
propsSjdbc.put("user", "safelogic");
propsSjdbc.put("password", "safelogic*$");

// Create a SafeJDBC instance
SafeJdbcSetter sjSetter = SafeJdbcSetter.getInstance();

// Set the Wrapped Driver
sjSetter.setWrappedDriverName(sNativeDriver);

// sjSetter.setSafeJdbcDbUrl(sJdbcUrl, "safelogic", new String(caPassword));
sjSetter.setSafeJdbcDbUrl(sJdbcUrl, propsSjdbc);

// set the encryption key for encrypting and decrypting
String sUserId = "safejdbc_userid";
sjSetter.setKey(sUserId, "safejdbc_passphrase".toCharArray());

// load the SafeJDBC Driver and get a secure Connection to the database
Class.forName("com.safejdbc.api.Driver").newInstance();

Connection connection = DriverManager.getConnection(sDbUrl);

// Verify that the Connection is a Cipher one!
if (!(connection instanceof CipherConnection))
{
    System.out.println(sjSetter.getStatus());
    throw new SQLException("SafeJDBC Driver not loaded!");
}

System.out.println("Good! Cipher Connection loaded using SafeJdbcSetter! ");


Constructor Summary
protected SafeJdbcSetter()
          Constructor
 
Method Summary
 Object clone()
          This class cannot be clonned for security reasons
static SafeJdbcSetter getInstance()
          Creates a new SafeJdbcSetter instance.
 int getStatus()
          Returns the Status value after an attempt to load the SafeJDBC Driver.
 void setAlgorithm(String sAlgorithm)
          Sets the symmetric algorithm to be used, with the mode and the padding.
 void setKey(String sUserId, char[] caPassphrase)
          Sets the 128 bit symmetric PBE (Passphrase Based encryption Key) key to be used.
 void setKey(String sUserId, Key key)
          Sets the 128 bit symmetric Key to be used.
 void setProvider(String sProvider)
          Sets the cryptographic Provider to use.
 void setSafeJdbcDbUrl(String safeJdbcDbUrl)
          Sets the SafeJDBC Db URL.
 void setSafeJdbcDbUrl(String safeJdbcDbUrl, Properties props)
          Sets the SafeJDBC Db URL with Properties.
 void setSafeJdbcDbUrl(String safeJdbcDbUrl, String sUser, String sPassword)
          Sets the SafeJDBC Db URL with Db User and Db Password.
 void setSafeJdbcLogFile(String sSafeJdbcLogFile)
          Sets the Log file.
 void setWrappedDriverName(String wrappedDriverName)
          Sets the Wrapped JDBC Driver Name.
 String toString()
          Returns a human readable String containing detailed info about the status of SafeJdbcSetter.
static void unlock()
          Unlocks SafeJDBC after driver initialization.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SafeJdbcSetter

protected SafeJdbcSetter()
                  throws SQLException
Constructor

Throws:
SQLException
Method Detail

getInstance

public static SafeJdbcSetter getInstance()
                                  throws SQLException
Creates a new SafeJdbcSetter instance.

Throws:
SQLException - if SafeJdbcSetter instance already exists and is locked.

unlock

public static void unlock()
Unlocks SafeJDBC after driver initialization. This should be done each time the SafeJDBC driver is loaded.


getStatus

public int getStatus()
Returns the Status value after an attempt to load the SafeJDBC Driver.

See Also:
Status

setWrappedDriverName

public void setWrappedDriverName(String wrappedDriverName)
Sets the Wrapped JDBC Driver Name.
The Wrapped JDBC Driver is the "native" JDBC Driver in used by the SQL Engine.

Parameters:
wrappedDriverName - The Wrapped Driver Name to be set.

setSafeJdbcDbUrl

public void setSafeJdbcDbUrl(String safeJdbcDbUrl)
Sets the SafeJDBC Db URL.

The SafeJDBC database URL is the URL of The SafeJDBC catalog database, with the syntax for the native Wrapped Driver Name.

Parameters:
safeJdbcDbUrl - The SafeJDBC database URL to be set, with all the parameters (including userid & password).

setSafeJdbcDbUrl

public void setSafeJdbcDbUrl(String safeJdbcDbUrl,
                             String sUser,
                             String sPassword)
Sets the SafeJDBC Db URL with Db User and Db Password.

The SafeJDBC database URL is the URL of The SafeJDBC catalog database, with the syntax for the native Wrapped Driver Name.

Parameters:
safeJdbcDbUrl - The SafeJDBC database URL to be set.
sUser - the database user on whose behalf the connection is being made
sPassword - the user's password for the database.

setSafeJdbcDbUrl

public void setSafeJdbcDbUrl(String safeJdbcDbUrl,
                             Properties props)
Sets the SafeJDBC Db URL with Properties.

The SafeJDBC database URL is the URL of the SafeJDBC catalog database, with the syntax for the native Wrapped Driver Name.

Parameters:
safeJdbcDbUrl - The SafeJDBC database URL to set.
props - a list of arbitrary string tag/value pairs as connection arguments. Generally at least a "user" and "password" property should be included.

setSafeJdbcLogFile

public void setSafeJdbcLogFile(String sSafeJdbcLogFile)
Sets the Log file.

Parameters:
sSafeJdbcLogFile - the Log File name

setAlgorithm

public void setAlgorithm(String sAlgorithm)
                  throws IllegalArgumentException
Sets the symmetric algorithm to be used, with the mode and the padding.

setProvider

public void setProvider(String sProvider)
Sets the cryptographic Provider to use.
The default Provider is Provider.PROVIDER_CRYPTIX.

Parameters:
sProvider - The provider to be used
Throws:
IllegalArgumentException - if the Provider name is invalid

setKey

public void setKey(String sUserId,
                   Key key)
Sets the 128 bit symmetric Key to be used.

Parameters:
sUserId - The SafeJDBC UserId owner of this Key.
key - the Key to be used for cipher operations.
Throws:
IllegalArgumentException - if the sUserId name is null or the key is null

setKey

public void setKey(String sUserId,
                   char[] caPassphrase)
            throws IllegalArgumentException
Sets the 128 bit symmetric PBE (Passphrase Based encryption Key) key to be used. A PBE Key is derived from a passphrase.

Parameters:
sUserId - The UserId who owns this Key.
caPassphrase - the passphrase for the PBE key generation.
Throws:
IllegalArgumentException - if the userid or passphrase is invalid

toString

public String toString()
Returns a human readable String containing detailed info about the status of SafeJdbcSetter.

Overrides:
toString in class Object

clone

public final Object clone()
                   throws CloneNotSupportedException
This class cannot be clonned for security reasons

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

SafeJDBC v2.00

Copyright © SafeLogic 2011