org.opensc.pkcs11.wrap
Class PKCS11Session

java.lang.Object
  extended by org.opensc.util.DestroyableChild
      extended by org.opensc.util.DestroyableHolder
          extended by org.opensc.pkcs11.wrap.PKCS11Session
All Implemented Interfaces:
Destroyable, DestroyableParent

public class PKCS11Session
extends DestroyableHolder

Author:
wglas This class represents an open session on a token.

Field Summary
protected  long handle
          The C handle of the session.
static int OPEN_MODE_READ_ONLY
           
static int OPEN_MODE_READ_WRITE
           
protected  long pvh
          The C handle of the provider.
protected  long shandle
          The C handle of the slot.
 
Constructor Summary
protected PKCS11Session(PKCS11Slot slot, long handle)
          Contruct a session from a given handle-
 
Method Summary
 void destroy()
           
protected  long getHandle()
           
protected  long getPvh()
           
protected  long getSlotHandle()
           
 boolean isSOLoggedIn()
           
 boolean isUserLoggedIn()
           
 void loginSO(char[] pin)
          Presents the security officer PIN to the token.
 void loginUser(char[] pin)
          Presents the user PIN to the token.
 void logout()
          Logs out from the token.
static PKCS11Session open(PKCS11Slot slot, int mode)
          Opens a session on the given slot.
 
Methods inherited from class org.opensc.util.DestroyableHolder
deregister, register
 
Methods inherited from class org.opensc.util.DestroyableChild
getParent, isDestroyed, unlink
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pvh

protected long pvh
The C handle of the provider.


shandle

protected long shandle
The C handle of the slot.


handle

protected long handle
The C handle of the session.


OPEN_MODE_READ_ONLY

public static final int OPEN_MODE_READ_ONLY
See Also:
Constant Field Values

OPEN_MODE_READ_WRITE

public static final int OPEN_MODE_READ_WRITE
See Also:
Constant Field Values
Constructor Detail

PKCS11Session

protected PKCS11Session(PKCS11Slot slot,
                        long handle)
Contruct a session from a given handle-

Method Detail

open

public static PKCS11Session open(PKCS11Slot slot,
                                 int mode)
                          throws PKCS11Exception
Opens a session on the given slot.

Parameters:
slot - The slot on which we open the session.
mode - Either OPEN_MODE_READ_ONLY or OPEN_MODE_READ_WRITE
Returns:
The open session.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

loginUser

public void loginUser(char[] pin)
               throws PKCS11Exception
Presents the user PIN to the token. Should only be called after open().

Parameters:
pin - The user pin. This paremeter may be null, if the token has a protected authentication path.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 engine.
See Also:
PKCS11Slot.hasTokenProtectedAuthPath()

loginSO

public void loginSO(char[] pin)
             throws PKCS11Exception
Presents the security officer PIN to the token. Should only be called after open().

Parameters:
pin - The SO pin. This paremeter may be null, if the token has a protected authentication path.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 engine.
See Also:
PKCS11Slot.hasTokenProtectedAuthPath()

isSOLoggedIn

public boolean isSOLoggedIn()
Returns:
Returns, whether the security officer has successfully logged in through loginSO().

isUserLoggedIn

public boolean isUserLoggedIn()
Returns:
Returns, whether the user has successfully logged in through loginUser().

logout

public void logout()
            throws PKCS11Exception
Logs out from the token.

Throws:
PKCS11Exception

destroy

public void destroy()
             throws DestroyFailedException
Specified by:
destroy in interface Destroyable
Overrides:
destroy in class DestroyableHolder
Throws:
DestroyFailedException

getPvh

protected long getPvh()
Returns:
Returns the C handle of the underlying provider.

getSlotHandle

protected long getSlotHandle()
Returns:
Returns the C handle of the slot.

getHandle

protected long getHandle()
Returns:
Returns the C handle of the session.