public interface HSM
This is the interface that needs to be implemented for an HSM. Authlete loads implementations of this interface dynamically. The way Authlete finds implementations is disclosed only to customers who use on-premises Authlete as necessary.
| Modifier and Type | Method and Description |
|---|---|
Map<String,Object> |
createKey(Hsk hsk)
Create a key on the HSM.
|
byte[] |
decrypt(Hsk hsk,
Map<String,Object> info,
byte[] data)
Decrypt data.
|
void |
deleteKey(Hsk hsk,
Map<String,Object> info)
Delete a key on the HSM.
|
String |
getName()
The name of the HSM.
|
String |
getPublicKey(Hsk hsk,
Map<String,Object> info)
Get the public key that corresponds to the key on the HSM.
|
byte[] |
sign(Hsk hsk,
Map<String,Object> info,
byte[] data)
Sign data and return the signature.
|
boolean |
supportsJweAlg(JWEAlg alg)
Check if the HSM supports the specified encryption algorithm.
|
boolean |
supportsJwsAlg(JWSAlg alg)
Check if the HSM supports the specified signing algorithm.
|
String getName()
The name is used as a value of the hsmName request parameter
of the /api/hsk/create API (cf. HskCreateRequest.getHsmName()).
The name must match the regular expression "^[a-zA-Z][0-9a-zA-Z_]{0,29}".
boolean supportsJwsAlg(JWSAlg alg)
This method is called from within the implementation of the
/api/hsk/create API. If this method returns false,
the API call is rejected.
alg - A signing algorithm.true if the HSM supports the signing algorithm.boolean supportsJweAlg(JWEAlg alg)
This method is called from within the implementation of the
/api/hsk/create API. If this method returns false,
the API call is rejected.
alg - An encryption algorithm.true if the HSM supports the encryption algorithm.Map<String,Object> createKey(Hsk hsk) throws IOException
The argument hsk holds conditions for a key to be created.
All properties of hsk except handle and
publicKey properties have non-null values.
The implementation of this method is required to create a key on the
HSM that meets the conditions. Then, if possible, the implementation
should retrieve the public key that corresponds to the created key,
convert the format of the public key into base64-encoded DER, and set
it back to hsk by calling Hsk.setPublicKey(String).
If the implementation did not set the public key, Authlete will call
getPublicKey(Hsk, Map) after this method finishes.
The implementation of this method may return information associated
with the created key as a Map. It is highly likely that the
HSM returns an identifier of the created key which will be needed
later for signing or decrypting. Such information can be embedded in
the map. For example, like below.
Map<String, Object> info = new HashMap<String, Object>();
info.put("identifier", identifier);
The map returned from createKey() is converted into JSON,
encrypted, and then stored into Authlete's database. The map will be
used later as the info argument of other methods such as
sign(Hsk, Map, byte[]).
hsk - Conditions for a key to be created.IOException - Failed to create a key on the HSM.void deleteKey(Hsk hsk, Map<String,Object> info) throws IOException
In the case where the target key does not exist on the HSM, the implementation of this method does not have to raise an exception.
hsk - Information about the key.info - HSM-specific information associated with the key. This is
the map returned from createKey(Hsk).IOException - Failed to delete the key.String getPublicKey(Hsk hsk, Map<String,Object> info) throws IOException
The format of the returned public key should be base64-encoded DER. See "Illustrated X.509 Certificate" about the format.
hsk - Information about the key.info - HSM-specific information associated with the key. This is
the map returned from createKey(Hsk).IOException - Failed to get the public key.byte[] sign(Hsk hsk, Map<String,Object> info, byte[] data) throws IOException
hsk - Information about the key.info - HSM-specific information associated with the key. This is
the map returned from createKey(Hsk).data - The target data to sign.IOException - Failed to sign the data.byte[] decrypt(Hsk hsk, Map<String,Object> info, byte[] data) throws IOException
hsk - Information about the key.info - HSM-specific information associated with the key. This is
the map returned from createKey(Hsk).data - Data encrypted with the public key that corresponds to the
key on the HSM.IOException - Failed to decrypt the data.Copyright © 2022. All rights reserved.