|
IAIK PKCS#11 Wrapper version 1.2.18 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.pkcs.pkcs11.Token
Objects of this class represent PKCS#11 tokens. The application can get information on the token, manage sessions and initialize the token. Notice that objects of this class can become valid at any time. This is, the user can remove the token at any time and any subsequent calls to the corresponding object will fail with an exception (e.g. an exception with the error code PKCS11Constants.CKR_DEVICE_REMOVED). First, the application may want to find out what cryptographic algorithms the token supports. Implementations of such algorithms on a token are called mechanisms in the context of PKCS#11. The code for this may look something like this.
List supportedMechanisms = Arrays.asList(token.getMechanismList());
// check, if the token supports the required mechanism
if (!supportedMechanisms.contains(Mechanism.RSA_PKCS)) {
System.out.print("This token does not support the RSA PKCS mechanism!");
System.out.flush();
System.exit(1);
} else {
MechanismInfo rsaMechanismInfo = token.getMechanismInfo(Mechanism.RSA_PKCS);
// check, if the mechanism supports the required operation
if (!rsaMechanismInfo.isDecrypt()) {
System.out.print("This token does not support RSA decryption according to PKCS!");
System.out.flush();
System.exit(1);
}
}
Being sure that the token supports the required mechanism, the application
can open a session. For example, it may call
Session session = token.openSession(Token.SessionType.SERIAL_SESSION, Token.SessionReadWriteBehavior.RO_SESSION, null, null);
to open a simple read-only session.
Mechanism
,
MechanismInfo
,
Session
,
TokenInfo
Inner Class Summary | |
static interface |
Token.SessionReadWriteBehavior
This interface defines constants that specify the read/write behavior of a session. |
static interface |
Token.SessionType
This interface defines constants for the type of session that should be opened upon a call to openSession. |
Field Summary | |
protected Slot |
slot_
The reference to the slot. |
Constructor Summary | |
protected |
Token(Slot slot)
The constructor that takes a reference to the module and the slot ID. |
Method Summary | |
void |
closeAllSessions()
Close all open sessions of this token. |
boolean |
equals(java.lang.Object otherObject)
Compares the slot_ of this object with the other object. |
MechanismInfo |
getMechanismInfo(Mechanism mechanism)
Get mor information about one supported mechanism. |
Mechanism[] |
getMechanismList()
Get the list of mechanisms that this token supports. |
Slot |
getSlot()
Get the slot that created this Token object. |
long |
getTokenID()
Get the ID of this token. |
TokenInfo |
getTokenInfo()
Get information about this token. |
int |
hashCode()
The overriding of this method should ensure that the objects of this class work correctly in a hashtable. |
void |
initToken(char[] pin,
java.lang.String label)
Initialize the token. |
Session |
openSession(boolean serialSession,
boolean rwSession,
java.lang.Object application,
Notify notify)
Open a new session to perfom operations on this token. |
java.lang.String |
toString()
Returns the string representation of this object. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Slot slot_
Constructor Detail |
protected Token(Slot slot)
slot
- The reference to the slot.Method Detail |
public boolean equals(java.lang.Object otherObject)
equals
in class java.lang.Object
otherObject
- The other Token object.public Slot getSlot()
public long getTokenID()
public TokenInfo getTokenInfo() throws TokenException
TokenException
- If reading the information fails.public Mechanism[] getMechanismList() throws TokenException
TokenException
- If reading the list of supported mechansisms
fails.public MechanismInfo getMechanismInfo(Mechanism mechanism) throws TokenException
mechanism
- A mechanism that is supported by this token.TokenException
- If reading the information fails, or if the
mechansim is not supported by this token.public int hashCode()
hashCode
in class java.lang.Object
public void initToken(char[] pin, java.lang.String label) throws TokenException
pin
- If the token is not initialized yet, this PIN becomes the
security officer (admin) PIN. If the token is already
initialized, this PIN must be the correct security officer PIN
of this token. Otherwise the operation will fail. If the
token slot has build-in means to verify the user (e.g. a PIN-pad
on the card reader), this parameter can be null.label
- The label to give to the token. If this string is longer than
32 characters, it will be cut off at the end to be exactly 32
characters in length. If it is shorter than 32 characters, the
label is filled up with the blank character (' ') to be
exactly 32 characters in length.TokenException
- If the initialization fails.public Session openSession(boolean serialSession, boolean rwSession, java.lang.Object application, Notify notify) throws TokenException
serialSession
- Must be SessionType.SERIAL_SESSION. (For the sake of
completeness)rwSession
- Must be either SessionReadWriteBehavior.RO_SESSION for
read-only sessions or SessionReadWriteBehavior.RW_SESSION
for read-write sessions.application
- Object to be supplied upon notify callback. May be null.
(Not implemented yet!).notify
- For notifications via callback. may be null.
(Not implemented yet!)TokenException
- If the session could not be opened.public void closeAllSessions() throws TokenException
TokenException
- If closing all session fails.public java.lang.String toString()
toString
in class java.lang.Object
|
IAIK PKCS#11 Wrapper version 1.2.18 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |