public abstract class P11Slot extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
P11Slot.P11KeyUsage |
static class |
P11Slot.P11NewKeyControl |
static class |
P11Slot.P11NewObjectControl |
static class |
P11Slot.P11SlotRefreshResult |
| Modifier and Type | Field and Description |
|---|---|
protected String |
moduleName |
protected P11SlotIdentifier |
slotId |
| Modifier | Constructor and Description |
|---|---|
protected |
P11Slot(String moduleName,
P11SlotIdentifier slotId,
boolean readOnly,
P11ModuleConf.P11MechanismFilter mechanismFilter) |
| Modifier and Type | Method and Description |
|---|---|
P11ObjectIdentifier |
addCert(X509Cert cert,
P11Slot.P11NewObjectControl control)
Adds the certificate to the PKCS#11 token under the given identifier
objectId. |
protected abstract P11ObjectIdentifier |
addCert0(X509Cert cert,
P11Slot.P11NewObjectControl control)
Adds the certificate to the PKCS#11 token under the given identifier
objectId. |
protected void |
addIdentity(P11Identity identity) |
void |
assertMechanismSupported(long mechanism) |
protected void |
assertNoIdentityAndCert(byte[] id,
String label) |
protected void |
assertWritable(String operationName) |
abstract void |
close() |
protected static byte[] |
decodeHex(String hex)
Returns the hex representation of the bytes.
|
protected boolean |
existsCertForId(byte[] id) |
protected boolean |
existsCertForLabel(String label) |
protected boolean |
existsIdentityForId(byte[] id) |
protected boolean |
existsIdentityForLabel(String label) |
X509Cert |
exportCert(P11ObjectIdentifier objectId)
Exports the certificate of the given identifier
objectId. |
P11IdentityId |
generateDSAKeypair(BigInteger p,
BigInteger q,
BigInteger g,
P11Slot.P11NewKeyControl control)
Generates a DSA keypair.
|
P11IdentityId |
generateDSAKeypair(int plength,
int qlength,
P11Slot.P11NewKeyControl control)
Generates a DSA keypair.
|
protected abstract P11Identity |
generateDSAKeypair0(BigInteger p,
BigInteger q,
BigInteger g,
P11Slot.P11NewKeyControl control)
Generates a DSA keypair.
|
P11IdentityId |
generateECEdwardsKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid,
P11Slot.P11NewKeyControl control)
Generates an EC Edwards keypair.
|
protected abstract P11Identity |
generateECEdwardsKeypair0(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId,
P11Slot.P11NewKeyControl control)
Generates an EC Edwards keypair.
|
P11IdentityId |
generateECKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid,
P11Slot.P11NewKeyControl control)
Generates an EC keypair.
|
protected abstract P11Identity |
generateECKeypair0(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId,
P11Slot.P11NewKeyControl control)
Generates an EC keypair.
|
P11IdentityId |
generateECMontgomeryKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid,
P11Slot.P11NewKeyControl control)
Generates an EC Montgomery keypair.
|
protected abstract P11Identity |
generateECMontgomeryKeypair0(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId,
P11Slot.P11NewKeyControl control)
Generates an EC Montgomery keypair.
|
protected String |
generateLabel(String label) |
P11IdentityId |
generateRSAKeypair(int keysize,
BigInteger publicExponent,
P11Slot.P11NewKeyControl control)
Generates an RSA keypair.
|
protected abstract P11Identity |
generateRSAKeypair0(int keysize,
BigInteger publicExponent,
P11Slot.P11NewKeyControl control)
Generates an RSA keypair.
|
P11IdentityId |
generateSecretKey(long keyType,
int keysize,
P11Slot.P11NewKeyControl control)
Generates a secret key in the PKCS#11 token.
|
protected abstract P11Identity |
generateSecretKey0(long keyType,
int keysize,
P11Slot.P11NewKeyControl control)
Generates a secret key in the PKCS#11 token.
|
P11IdentityId |
generateSM2Keypair(P11Slot.P11NewKeyControl control)
Generates an SM2 keypair.
|
protected abstract P11Identity |
generateSM2Keypair0(P11Slot.P11NewKeyControl control)
Generates an SM2p256v1 keypair.
|
X509Cert |
getCert(P11ObjectIdentifier objectId)
Gets certificate with the given identifier
id. |
X509Cert |
getCertForId(byte[] id)
Gets certificate with the given identifier
id. |
Set<P11ObjectIdentifier> |
getCertIds() |
static String |
getDescription(byte[] keyId,
char[] keyLabel) |
static String |
getDescription(byte[] keyId,
String keyLabel) |
P11Identity |
getIdentity(P11ObjectIdentifier keyId) |
P11IdentityId |
getIdentityId(byte[] keyId,
String keyLabel) |
Set<P11ObjectIdentifier> |
getIdentityKeyIds() |
Set<Long> |
getMechanisms() |
String |
getModuleName() |
P11ObjectIdentifier |
getObjectId(byte[] id,
String label) |
P11SlotIdentifier |
getSlotId() |
boolean |
hasIdentity(P11ObjectIdentifier keyId) |
protected static String |
hex(byte[] bytes)
Returns the hex representation of the bytes.
|
P11ObjectIdentifier |
importSecretKey(long keyType,
byte[] keyValue,
P11Slot.P11NewKeyControl control)
Imports secret key object in the PKCS#11 token.
|
protected abstract P11Identity |
importSecretKey0(long keyType,
byte[] keyValue,
P11Slot.P11NewKeyControl control)
Imports secret key object in the PKCS#11 token.
|
boolean |
isReadOnly() |
void |
refresh() |
protected abstract P11Slot.P11SlotRefreshResult |
refresh0() |
void |
removeCerts(P11ObjectIdentifier objectId)
Remove certificates.
|
protected abstract void |
removeCerts0(P11ObjectIdentifier objectId) |
void |
removeIdentity(P11IdentityId identityId)
Removes the key (private key, public key, secret key, and certificates) associated with
the given identifier
objectId. |
protected abstract void |
removeIdentity0(P11IdentityId identityId)
Removes the key (private key, public key, secret key, and certificates) associated with
the given identifier
objectId. |
void |
removeIdentityByKeyId(P11ObjectIdentifier keyId)
Removes the key (private key, public key, secret key, and certificates) associated with
the given identifier
objectId. |
abstract int |
removeObjects(byte[] id,
String label)
Remove objects.
|
void |
showDetails(OutputStream stream,
boolean verbose)
Writes the token details to the given
stream. |
boolean |
supportsMechanism(long mechanism) |
void |
updateCertificate(P11ObjectIdentifier keyId,
X509Cert newCert)
Updates the certificate associated with the given ID
keyId with the given certificate
newCert. |
protected abstract void |
updateCertificate0(P11ObjectIdentifier keyId,
X509Cert newCert)
Updates the certificate associated with the given
objectId with the given certificate
newCert. |
protected final String moduleName
protected final P11SlotIdentifier slotId
protected P11Slot(String moduleName, P11SlotIdentifier slotId, boolean readOnly, P11ModuleConf.P11MechanismFilter mechanismFilter) throws P11TokenException
P11TokenExceptionprotected static String hex(byte[] bytes)
bytes - Data to be encoded. Must not be null.protected static byte[] decodeHex(String hex)
hex - Data to be decoded. Must not be null.public static String getDescription(byte[] keyId, char[] keyLabel)
protected abstract void updateCertificate0(P11ObjectIdentifier keyId, X509Cert newCert) throws P11TokenException, CertificateException
objectId with the given certificate
newCert.keyId - Object identifier of the private key. Must not be null.newCert - Certificate to be added. Must not be null.CertificateException - if process with certificate fails.P11TokenException - if PKCS#11 token exception occurs.protected abstract void removeIdentity0(P11IdentityId identityId) throws P11TokenException
objectId.identityId - Identity identifier. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11ObjectIdentifier addCert0(X509Cert cert, P11Slot.P11NewObjectControl control) throws P11TokenException, CertificateException
objectId.cert - Certificate to be added. Must not be null.control - Control of the object creation process. Must not be null.CertificateException - if process with certificate fails.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity generateSecretKey0(long keyType, int keysize, P11Slot.P11NewKeyControl control) throws P11TokenException
keyType - key typekeysize - key sizecontrol - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity importSecretKey0(long keyType, byte[] keyValue, P11Slot.P11NewKeyControl control) throws P11TokenException
keyType - key type.keyValue - Key value. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity generateDSAKeypair0(BigInteger p, BigInteger q, BigInteger g, P11Slot.P11NewKeyControl control) throws P11TokenException
p - p of DSA. Must not be null.q - q of DSA. Must not be null.g - g of DSA. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity generateECEdwardsKeypair0(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId, P11Slot.P11NewKeyControl control) throws P11TokenException
curveId - Object Identifier of the curve. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity generateECMontgomeryKeypair0(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId, P11Slot.P11NewKeyControl control) throws P11TokenException
curveId - Object Identifier of the curve. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity generateECKeypair0(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId, P11Slot.P11NewKeyControl control) throws P11TokenException
curveId - Object identifier of the EC curve. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity generateSM2Keypair0(P11Slot.P11NewKeyControl control) throws P11TokenException
control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Identity generateRSAKeypair0(int keysize, BigInteger publicExponent, P11Slot.P11NewKeyControl control) throws P11TokenException
keysize - key size in bitpublicExponent - RSA public exponent. Could be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.protected abstract P11Slot.P11SlotRefreshResult refresh0() throws P11TokenException
P11TokenExceptionprotected abstract void removeCerts0(P11ObjectIdentifier objectId) throws P11TokenException
P11TokenExceptionpublic abstract void close()
close in interface Closeableclose in interface AutoCloseablepublic abstract int removeObjects(byte[] id,
String label)
throws P11TokenException
id - Id of the objects to be deleted. At least one of id and label may not be null.label - Label of the objects to be deletedP11TokenException - If PKCS#11 error happens.public X509Cert getCertForId(byte[] id)
id.id - Identifier of the certificate. Must not be null.public X509Cert getCert(P11ObjectIdentifier objectId)
id.objectId - Identifier of the certificate. Must not be null.public void refresh()
throws P11TokenException
P11TokenExceptionprotected void addIdentity(P11Identity identity) throws P11DuplicateEntityException
P11DuplicateEntityExceptionpublic boolean hasIdentity(P11ObjectIdentifier keyId)
public boolean supportsMechanism(long mechanism)
public void assertMechanismSupported(long mechanism)
throws P11UnsupportedMechanismException
P11UnsupportedMechanismExceptionpublic Set<P11ObjectIdentifier> getIdentityKeyIds()
public Set<P11ObjectIdentifier> getCertIds()
public String getModuleName()
public P11SlotIdentifier getSlotId()
public boolean isReadOnly()
public P11Identity getIdentity(P11ObjectIdentifier keyId) throws P11UnknownEntityException
P11UnknownEntityExceptionprotected void assertNoIdentityAndCert(byte[] id,
String label)
throws P11DuplicateEntityException
P11DuplicateEntityExceptionpublic P11ObjectIdentifier getObjectId(byte[] id, String label)
public P11IdentityId getIdentityId(byte[] keyId, String keyLabel)
public X509Cert exportCert(P11ObjectIdentifier objectId) throws P11TokenException
objectId.objectId - Object identifier. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public void removeCerts(P11ObjectIdentifier objectId) throws P11TokenException
objectId - Object identifier. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public void removeIdentity(P11IdentityId identityId) throws P11TokenException
objectId.identityId - Identity identifier. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public void removeIdentityByKeyId(P11ObjectIdentifier keyId) throws P11TokenException
objectId.keyId - Key identifier. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11ObjectIdentifier addCert(X509Cert cert, P11Slot.P11NewObjectControl control) throws P11TokenException, CertificateException
objectId.cert - Certificate to be added. Must not be null.control - Control of the object creation process. Must not be null.CertificateException - if process with certificate fails.P11TokenException - if PKCS#11 token exception occurs.protected String generateLabel(String label) throws P11TokenException
P11TokenExceptionpublic P11IdentityId generateSecretKey(long keyType, int keysize, P11Slot.P11NewKeyControl control) throws P11TokenException
keyType - Key typekeysize - Key size in bitcontrol - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11ObjectIdentifier importSecretKey(long keyType, byte[] keyValue, P11Slot.P11NewKeyControl control) throws P11TokenException
keyType - Key typekeyValue - Key value. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11IdentityId generateRSAKeypair(int keysize, BigInteger publicExponent, P11Slot.P11NewKeyControl control) throws P11TokenException
keysize - key size in bitpublicExponent - RSA public exponent. Could be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11IdentityId generateDSAKeypair(int plength, int qlength, P11Slot.P11NewKeyControl control) throws P11TokenException
plength - bit length of Pqlength - bit length of Qcontrol - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11IdentityId generateDSAKeypair(BigInteger p, BigInteger q, BigInteger g, P11Slot.P11NewKeyControl control) throws P11TokenException
p - p of DSA. Must not be null.q - q of DSA. Must not be null.g - g of DSA. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11IdentityId generateECKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid, P11Slot.P11NewKeyControl control) throws P11TokenException
curveOid - Object identifier of the EC curve. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11IdentityId generateECEdwardsKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid, P11Slot.P11NewKeyControl control) throws P11TokenException
curveOid - Object Identifier of the EdEC curve as defined in RFC 8410. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11IdentityId generateECMontgomeryKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid, P11Slot.P11NewKeyControl control) throws P11TokenException
curveOid - Object Identifier of the EdEC curve as defined in RFC 8410. Must not be null.control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public P11IdentityId generateSM2Keypair(P11Slot.P11NewKeyControl control) throws P11TokenException
control - Control of the key generation process. Must not be null.P11TokenException - if PKCS#11 token exception occurs.public void updateCertificate(P11ObjectIdentifier keyId, X509Cert newCert) throws P11TokenException, CertificateException
keyId with the given certificate
newCert.keyId - Object identifier of the private key. Must not be null.newCert - Certificate to be added. Must not be null.CertificateException - if process with certificate fails.P11TokenException - if PKCS#11 token exception occurs.public void showDetails(OutputStream stream, boolean verbose) throws IOException
stream.stream - Output stream. Must not be null.verbose - Whether to show the details verbosely.IOException - if IO error occurs.protected void assertWritable(String operationName) throws P11PermissionException
P11PermissionExceptionprotected boolean existsIdentityForId(byte[] id)
protected boolean existsIdentityForLabel(String label)
protected boolean existsCertForId(byte[] id)
protected boolean existsCertForLabel(String label)
Copyright © 2020. All rights reserved.