p11ex is an Elixir library that provides access to the PKCS#11 interface for cryptographic tokens such as Hardware Security Modules and smartcards. The library exposes most PKCS#11 functionality to Elixir, though it is not yet feature complete. Available functions include:
C_GetSlotList: List tokensC_GetTokenInfo: Retrieve information about a tokenC_OpenSession: Open a new PKCS#11 sessionC_CloseSession: Close a PKCS#11 sessionC_CloseAllSession: Close all open sessions for a tokenC_GetSessionInfo: Retrieve status information about a sessionC_Login: Authenticate an open sessionC_Logout: Deauthenticate an open sessionC_GenerateKey: Generate a symmetric keyC_FindObjects: Search for objects stored in the tokenC_GetAttributeValue: Retrieve attributes of an objectC_EncryptInit,C_Encrypt,C_EncryptUpdate, andC_EncryptFinal: Encryption in chunks and as a complete blockC_DecryptInit,C_Decrypt,C_DecryptUpdate, andC_DecryptFinal: Decryption in chunks and as a complete blockC_GenerateRandom: Generate random bytes using the tokenC_DestroyObject: Delete objects in the token or sessionC_GetMechanismList: List cryptographic mechanisms supported by tokenC_GetMechanismInfo: Retrieve information about a mechanismC_SignInit,C_Sign,C_SignUpdate,C_SignFinal: Sign data in chunks and as a complete blockC_VerifyInit,C_Verify: Verify a signatureC_DigestInit,C_Digest,C_DigestUpdate,C_DigestFinal: Compute a hash digest in the tokenC_GenKeyPair: Generate asymmetric key pairC_WrapKey: Encrypt an extractable key and make it exportableC_UnwrapKey: Decrypt an exported key into the token
Some PKCS#11 functions require mechanism parameters as arguments. Common parameter types are supported and documented in the Elixir documentation.
The implementation is automatically tested with SoftHSM on Linux (AMD64 and ARM64) and macOS (ARM64). Additional tests are available for the Yubikey PKCS#11 module, though these do not run automatically as part of the build.
The project also includes a CLI program named p11ex_cli for working with cryptographic tokens. This program provides access to key p11ex functions.