Download the PHP package gamringer/pkcs11 without Composer
On this page you can find all versions of the php package gamringer/pkcs11. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pkcs11
PKCS11 bindings for PHP
Tested with the following HSMs:
- SafeNET Luna SA 4
- SoftHSM 2.6
- Nitrokey HSM 2
- AWS CloudHSM
Supports PHP version >= 7.4
Compile
Running tests
To make tests, ensure that SoftHSM2 is installed, configured and initialized.
Install SoftHSM2
From Source
- Get the source
- Extract Archive
cd /path/to/extracted/archive./configuremakemake install
Module will be located in /usr/local/lib/softhsm/libsofthsm2.so
From Ubuntu package repository
As of this writing, Ubuntu 20.04 provides v2.2 of SoftHSM2 in which not all mechanisms will be available
sudo apt install softhsm2
Module will be located in /usr/lib/softhsm/libsofthsm2.so
Configure and initialize SoftHSM2
- Create a directory where HSM files will be stored
/home/user/.softhsm - Create a configuration file in your home directory
~/.config/softhsm2/softhsm2.conf - Initialize token
softhsm2-util --init-token --slot 0 --label "My token 1" --pin 123456 --so-pin 12345678 - Grab the resulting slot ID
softhsm2-util --show-slots
Example configuration file
Run tests
How to use
All examples assume the use of a locally compiled installation of SoftHSM, but it will work with other modules as well.
Loading a module
To load a PKCS11 module, create a new PKCS11\Module object.
From the PKCS11\Module object, you can call most PKCS11 methods.
To get information the module:
Slot Information
There are 2 methods to retrieve slots information. getSlotList can be used to retrieve a simple list of slots like C_GetSlotList would, while getSlots returns de result of C_GetSlotInfo for each available slot.
Token Information
Mechanisms
All mechanisms declared in PKCS11 version 3 are available under the Pkcs11 namespace.
Initializing a token
This extension supports initializing simple tokens via the C_InitToken function.
Opening a session
You can open a session and login as either a Security Officer or user. From the returned Pkcs11\Session object, more methods are available.
PIN Management
As a Security Officer, the user PIN can be set to any value.
As either user, the current user PIN can be changed.
Generating Keys
You can generate symmetric keys for any available mechanism.
Encrypt/Decrypt
Given a symmetric key, you can encrypt something. Certain encryption mechanisms require a special Parameters object. Currently, the following are available:
- Pkcs11\GcmParams
- Pkcs11\Salsa20Params
- Pkcs11\ChaCha20Params
- Pkcs11\Salsa20Chacha20Poly1305Params
AWS CloudHSM does things in a particular way. The initialization vector is generated by the HSM for you and returned prepended to the ciphertext.
Given an RSA public key, you can encrypt a symmetric key. Similarly to symmetric mechanisms, some asymmetric encryption mechanisms require a special Parameters object. Currently, the following are available:
- Pkcs11\RsaOaepParams
Derivation
Given an EC public key, you can derive a shared secret.
Retrieving object by URI
You have the ability to retrieve object using RFC7512 URIs.
Note: Currently, only the following path attributes are supported:
- id
- object
- type
Retrieve object attributes
Given an Object, you can retrieve it's readable attributes.
Note: the following attributes are not implemented and retrieving them throws an exception:
- CKA_WRAP_TEMPLATE
- CKA_UNWRAP_TEMPLATE
- CKA_DERIVE_TEMPLATE
Note: the following attributes internally provide a struct describing the date, but are here returned as a string:
- CKA_START_DATE
- CKA_END_DATE