Re-Establishing a Connection Between Your Java Application and SafeNet Luna Network HSM

The following snippet of java code re-establishes a connection between a Java Application and SafeNet Luna Network HSM in the event of a disconnect (for example, firewall rules, network issues).

NOTE   Stop all existing crypto operations before performing the reconnect.

public void reconnectHsmServer() {
     LunaSlotManager lsm = LunaSlotManager.getInstance();
     lsm.reinitialize();
     lsm.login(“<HSM partition password>”);
}
 

NOTE   The reinitialize() call is a disruptive call. It unloads and reloads the dll, in order to perform a cleanup and refresh. When reinitialize() is called, there are no safe API methods that may be called and any calls in progress will result in undefined behaviour, leading, most-likely, to a JVM crash. Before calling reinitialize(), ensure that all threads making use of the API are halted or stopped, and that no other calls are made until reinitialize() has completed.