public final class PK11Token extends java.lang.Object implements CryptoToken
CryptoManager| Modifier and Type | Class and Description | 
|---|---|
static class  | 
PK11Token.NotInitializedException
Thrown if the operation requires that the token be logged in, and it
 isn't. 
 | 
| Modifier and Type | Field and Description | 
|---|---|
protected PK11Store | 
cryptoStore  | 
protected boolean | 
mIsInternalCryptoToken  | 
protected boolean | 
mIsInternalKeyStorageToken  | 
protected TokenProxy | 
tokenProxy  | 
EVERY_TIME, ONE_TIME, TIMEOUT| Modifier | Constructor and Description | 
|---|---|
protected  | 
PK11Token()  | 
protected  | 
PK11Token(byte[] pointer,
         boolean internal,
         boolean keyStorage)
Creates a new PK11Token. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
protected void | 
changePassword(byte[] oldPIN,
              byte[] newPIN)
Change the password on the token from the old one to the new one. 
 | 
void | 
changePassword(PasswordCallback oldPINcb,
              PasswordCallback newPINcb)
Change password. 
 | 
SymmetricKey | 
cloneKey(SymmetricKey key)
Allows a SymmetricKey to be cloned on a different token. 
 | 
boolean | 
doesAlgorithm(Algorithm alg)
Determines whether this token is capable of performing the given
 algorithm. 
 | 
boolean | 
equals(java.lang.Object obj)
Deep-comparison operator. 
 | 
java.lang.String | 
generateCertRequest(java.lang.String subject,
                   int keysize,
                   java.lang.String keyType,
                   byte[] P,
                   byte[] Q,
                   byte[] G)
Generates a PKCS#10 certificate request including Begin/End brackets 
 | 
protected java.lang.String | 
generatePK10(java.lang.String subject,
            int keysize,
            java.lang.String keyType,
            byte[] P,
            byte[] Q,
            byte[] G)  | 
Cipher | 
getCipherContext(EncryptionAlgorithm algorithm)
Creates a Cipher object, which can be used for encryption and
 decryption. 
 | 
CryptoStore | 
getCryptoStore()
Get the CryptoStore interface to this token's objects. 
 | 
JSSMessageDigest | 
getDigestContext(DigestAlgorithm algorithm)
Creates a Digest object. 
 | 
KeyGenerator | 
getKeyGenerator(KeyGenAlgorithm algorithm)
Creates a KeyGenerator object, which can be used to generate
 symmetric encryption keys. 
 | 
KeyPairGenerator | 
getKeyPairGenerator(KeyPairAlgorithm algorithm)
Creates a KeyPairGenerator object, which can be used to generate
 key pairs. 
 | 
KeyWrapper | 
getKeyWrapper(KeyWrapAlgorithm algorithm)  | 
int | 
getLoginMode()
Returns the login mode of this token: ONE_TIME, TIMEOUT, or
 EVERY_TIME. 
 | 
int | 
getLoginTimeoutMinutes()
Returns the login timeout period. 
 | 
java.lang.String | 
getName()
Obtain the nickname, or label, of this token. 
 | 
java.security.Provider | 
getProvider()  | 
TokenProxy | 
getProxy()  | 
java.security.SecureRandom | 
getRandomGenerator()  | 
Signature | 
getSignatureContext(SignatureAlgorithm algorithm)
Creates a Signature object, which can perform signing and signature
 verification. 
 | 
protected void | 
initPassword(byte[] ssopw,
            byte[] userpw)  | 
void | 
initPassword(PasswordCallback ssopwcb,
            PasswordCallback userpwcb)
Initialize PIN. 
 | 
boolean | 
isInternalCryptoToken()  | 
boolean | 
isInternalKeyStorageToken()  | 
boolean | 
isLoggedIn()
Find out if the token is currently logged in. 
 | 
boolean | 
isPresent()
Determines if the given token is present on the system. 
 | 
boolean | 
isWritable()  | 
void | 
login(PasswordCallback callback)
Log into the token. 
 | 
void | 
logout()
Log out of the token. 
 | 
protected PasswordCallbackInfo | 
makePWCBInfo()  | 
protected void | 
nativeLogin(PasswordCallback callback)  | 
boolean | 
needsLogin()
returns true if this token needs to be logged into before 
 it can be used. 
 | 
boolean | 
passwordIsInitialized()
Determine whether the token has been initialized yet. 
 | 
protected boolean | 
PWInitable()
Make sure the PIN can be initialized. 
 | 
void | 
setLoginMode(int mode)
Sets the login mode of this token. 
 | 
void | 
setLoginTimeoutMinutes(int timeoutMinutes)
Sets the timeout period for logging in. 
 | 
protected boolean | 
SSOPasswordIsCorrect(byte[] ssopw)  | 
protected boolean | 
userPasswordIsCorrect(byte[] pw)
Check the given password, return true if it's right, false if it's
 wrong. 
 | 
protected boolean mIsInternalCryptoToken
protected boolean mIsInternalKeyStorageToken
protected TokenProxy tokenProxy
protected PK11Store cryptoStore
protected PK11Token()
protected PK11Token(byte[] pointer,
         boolean internal,
         boolean keyStorage)
pointer - A byte array containing a pointer to a PKCS #11 slot.public Signature getSignatureContext(SignatureAlgorithm algorithm) throws java.security.NoSuchAlgorithmException, TokenException
CryptoTokengetSignatureContext in interface CryptoTokenalgorithm - The algorithm used for the signing/verification.java.security.NoSuchAlgorithmException - If the given
      algorithm is not supported by this provider.TokenExceptionpublic JSSMessageDigest getDigestContext(DigestAlgorithm algorithm) throws java.security.NoSuchAlgorithmException, java.security.DigestException
CryptoTokengetDigestContext in interface CryptoTokenalgorithm - The algorithm used for digesting.java.security.NoSuchAlgorithmException - If this provider
  does not support the given algorithm.java.security.DigestExceptionpublic Cipher getCipherContext(EncryptionAlgorithm algorithm) throws java.security.NoSuchAlgorithmException, TokenException
CryptoTokengetCipherContext in interface CryptoTokenalgorithm - The algorithm used for encryption/decryption.java.security.NoSuchAlgorithmException - If this provider
      does not support the given algorithm.TokenExceptionpublic KeyGenerator getKeyGenerator(KeyGenAlgorithm algorithm) throws java.security.NoSuchAlgorithmException, TokenException
CryptoTokengetKeyGenerator in interface CryptoTokenalgorithm - The algorithm that the keys will be used with.java.security.NoSuchAlgorithmException - If this token does not
      support the given algorithm.TokenExceptionpublic SymmetricKey cloneKey(SymmetricKey key) throws SymmetricKey.NotExtractableException, java.security.InvalidKeyException, TokenException
cloneKey in interface CryptoTokenSymmetricKey.NotExtractableException - If the key material
      cannot be extracted from the current token.java.security.InvalidKeyException - If the owning token cannot process
      the key to be cloned.TokenExceptionpublic KeyWrapper getKeyWrapper(KeyWrapAlgorithm algorithm) throws java.security.NoSuchAlgorithmException, TokenException
getKeyWrapper in interface CryptoTokenjava.security.NoSuchAlgorithmExceptionTokenExceptionpublic java.security.SecureRandom getRandomGenerator()
                                              throws NotImplementedException,
                                                     TokenException
public KeyPairGenerator getKeyPairGenerator(KeyPairAlgorithm algorithm) throws java.security.NoSuchAlgorithmException, TokenException
CryptoTokengetKeyPairGenerator in interface CryptoTokenalgorithm - The algorithm that the keys will be used with (RSA,
      DSA, EC, etc.)java.security.NoSuchAlgorithmException - If this token does
      not support the given algorithm.TokenExceptionpublic boolean isLoggedIn()
                   throws TokenException
CryptoTokenisLoggedIn in interface CryptoTokenTokenExceptionCryptoToken.login(org.mozilla.jss.util.PasswordCallback), 
CryptoToken.logout()public boolean needsLogin()
                   throws TokenException
CryptoTokenneedsLogin in interface CryptoTokenTokenExceptionCryptoToken.login(org.mozilla.jss.util.PasswordCallback), 
CryptoToken.logout()public void login(PasswordCallback callback) throws PK11Token.NotInitializedException, IncorrectPasswordException, TokenException
login in interface CryptoTokencallback - A callback to use to obtain the password, or a 
      Password object.PK11Token.NotInitializedException - The token has not yet been
  initialized.IncorrectPasswordException - The specified password
      was incorrect.TokenExceptionCryptoToken.setLoginMode(int), 
CryptoManager.setPasswordCallback(org.mozilla.jss.util.PasswordCallback)protected void nativeLogin(PasswordCallback callback) throws PK11Token.NotInitializedException, IncorrectPasswordException, TokenException
public boolean isWritable()
public boolean isPresent()
isPresent in interface CryptoTokenpublic void logout()
            throws TokenException
logout in interface CryptoTokenTokenException - If you are already logged in, or an
  unspecified error occurs.public int getLoginMode()
                 throws TokenException
CryptoTokengetLoginMode in interface CryptoTokenTokenException - If an error occurs on the token.CryptoToken.getLoginTimeoutMinutes()public void setLoginMode(int mode)
                  throws TokenException
CryptoTokensetLoginMode in interface CryptoTokenmode - ONE_TIME, TIMEOUT, or EVERY_TIMETokenException - If this mode is not supported by this token,
  or an error occurs on the token.CryptoToken.login(org.mozilla.jss.util.PasswordCallback), 
CryptoToken.setLoginTimeoutMinutes(int)public int getLoginTimeoutMinutes()
                           throws TokenException
CryptoTokengetLoginTimeoutMinutes in interface CryptoTokenTokenException - If an error occurs on the token.CryptoToken.getLoginMode()public void setLoginTimeoutMinutes(int timeoutMinutes)
                            throws TokenException
CryptoTokensetLoginTimeoutMinutes in interface CryptoTokenTokenException - If timeouts are not supported by this
      token, or an error occurs on the token.CryptoToken.setLoginMode(int)public void initPassword(PasswordCallback ssopwcb, PasswordCallback userpwcb) throws IncorrectPasswordException, AlreadyInitializedException, TokenException
initPassword in interface CryptoTokenssopwcb - The security officer's current password callback.userpwcb - The user's new password callback.IncorrectPinException - If the security officer PIN is
  incorrect.TokenException - If the PIN was already initialized,
  or there was an unspecified error in the token.IncorrectPasswordException - If the supplied security officer
                password is incorrect.AlreadyInitializedException - If the token only allows one
                password initialization, and it has already occurred.protected boolean PWInitable()
                      throws TokenException
TokenExceptionprotected boolean SSOPasswordIsCorrect(byte[] ssopw)
                                throws TokenException,
                                       AlreadyInitializedException
protected void initPassword(byte[] ssopw,
                byte[] userpw)
                     throws IncorrectPasswordException,
                            AlreadyInitializedException,
                            TokenException
public boolean passwordIsInitialized()
                              throws TokenException
passwordIsInitialized in interface CryptoTokenTokenException - If an error occurs on the token.public void changePassword(PasswordCallback oldPINcb, PasswordCallback newPINcb) throws IncorrectPasswordException, TokenException
changePassword in interface CryptoTokenoldPINcb - The user's old PIN callback.newPINcb - The new PIN callback.IncorrectPasswordException - If the old PIN is incorrect.TokenException - If some other error occurs on the token.protected PasswordCallbackInfo makePWCBInfo()
protected boolean userPasswordIsCorrect(byte[] pw)
                                 throws TokenException
TokenExceptionprotected void changePassword(byte[] oldPIN,
                  byte[] newPIN)
                       throws IncorrectPasswordException,
                              TokenException
public java.lang.String getName()
CryptoTokengetName in interface CryptoTokenpublic java.security.Provider getProvider()
public CryptoStore getCryptoStore()
CryptoTokengetCryptoStore in interface CryptoTokenpublic boolean equals(java.lang.Object obj)
equals in interface CryptoTokenequals in class java.lang.Objectcompare is null.public boolean doesAlgorithm(Algorithm alg)
doesAlgorithm in interface CryptoTokenalg - A JSS algorithm.  Note that for Signature, a token may 
      fail to support a specific SignatureAlgorithm (such as
      RSASignatureWithMD5Digest) even though it does support the
      generic algorithm (RSASignature). In this case, the signature
      operation will be performed on that token, but the digest
      operation will be performed on the internal token.public java.lang.String generateCertRequest(java.lang.String subject,
                                   int keysize,
                                   java.lang.String keyType,
                                   byte[] P,
                                   byte[] Q,
                                   byte[] G)
                                     throws TokenException,
                                            java.security.InvalidParameterException,
                                            PQGParamGenException
generateCertRequest in interface CryptoTokensubject - subject dn of the certificatekeysize - size of the keykeyType - "rsa" or "dsa"P - The DSA prime parameterQ - The DSA sub-prime parameterG - The DSA base parameterTokenExceptionjava.security.InvalidParameterExceptionPQGParamGenExceptionprotected java.lang.String generatePK10(java.lang.String subject,
                            int keysize,
                            java.lang.String keyType,
                            byte[] P,
                            byte[] Q,
                            byte[] G)
                                 throws TokenException,
                                        java.security.InvalidParameterException
TokenExceptionjava.security.InvalidParameterExceptionpublic TokenProxy getProxy()
public boolean isInternalCryptoToken()
public boolean isInternalKeyStorageToken()