The PKCS #11 standard defines a platform-independent API to cryptographic tokens, such as hardware security modules (HSM), smart cards, and names the API itself "Cryptoki" (from "cryptographic token interface" and pronounced as "crypto-key" - but "PKCS #11" is often used to refer to the API as well as the standard that defines it).
The API defines most commonly used cryptographic object types (RSAX.509 keys, DES/Triple DES Certificates/keys, etc.) and all the functions needed to use, create/generate, modify and delete those objects.
This container relies on a PKCS#11 a library which handles the communication with the token/card. This can be a vendor specific library or an opensource one, please select the correct one depending on the type of token/card you are using.
Interface Summary
The Abstract PKCS #11 smartcard interface is summarized in the following snippet:
Each interface will be covered on this wiki, accompanied with example code and response objects.
Get the PKCS #11 container object
For more information on how to configure the T1C-JS client library see Client Configuration.
To set the locations of the PCKS#11 library, pass a ModuleConfig object when initializing the client:
Then grab a reference to the pkcs11 container:
Call a function for the PKCS #11 container:
Reading data
Info
This methods returns more information about the PKCS #11 library you are using.
An example response:
Slots
This methods returns the available slots on the system.
An example response:
The flags value gives more information about the slot, possible values are
Value
Description
0
Empty
1
Token present
2
Removable device
3
Token present + removable device
4
Hardware slot
5
Token present + hardware slot
6
Removable device + hardware slot
7
Token present + removable device + hardware slot
32
Unknown
Slots with tokens present
This method is similar the the slots endpoint but only returns a list of slots where a token is present.
An example response:
Token
This methods returns the token information for a slot.
An example response:
Certificates
This methods allows you to retrieve the certificates from the PKCS #11 token.
An example callback:
Response:
Signing data
To successfully sign data, we need the following parameters:
Slot ID of the token to use
Certificate ID of the signing certificate
PIN code
Hashed data to sign
Hashing algorithm used
The slot id can be found using either a call to slots, slotsWithTokenPresent. Once the slot id is found, the certificates can be retrieved with a call to certificates. This then returns the certificate id. Now we can combine this with the PIN code and hashed data + hashing algorithm (SHA1, SHA256, SHA384, SHA512) to create the final signData call:
signData call
Returns signed data for provided input data.
An example response:
verifySignedData call
This call can be used to verify if the signed data is correct. The request is similar to signData, but we also pass in the signed hash:
An example response:
Error Handling
Error Object
The functions specified are asynchronous and always need a callback function.
The callback function will reply with a data object in case of success, or with an error object in case of an error. An example callback:
The error object returned:
For the error codes and description, see Status codes.