Python library for signing x509 using keys in an pkcs11 device such as a HSM
Project description
python_x509_pkcs11
Seamless signing x509 using PKCS11 device for key storage
Currently supports
- Creating a root CA and generating its RSA key in the PKCS11 device
- Using the key in the PKCS11 device to sign certificates (or Intermediate CAs)
- Creating CRLs with the PKCS11 device key
- Store multiple keys in the PKCS11 device enabling a full PKI infrastructure
- 'Advanced' handling of fragile persistent PKCS11 sessions, including recreating the session if PKCS11 operation timeout
This package is pretty much a wrapper around python-pkcs11 and asn1crypto
Setup
# Install this package
pip install python_x509_pkcs11
# Install deps and add your user to the softhsm group
sudo apt-get install opensc softhsm2
sudo usermod -a -G softhsm $USER
sudo reboot # Yeah seem to not update your groups without a reboot
# export env values the code will use
export PKCS11_MODULE="/usr/lib/softhsm/libsofthsm2.so"
export PKCS11_PIN="1234"
export PKCS11_TOKEN="my_test_token_1"
# Initialize the token
softhsm2-util --init-token --slot 0 --label $PKCS11_TOKEN --pin $PKCS11_PIN --so-pin $PKCS11_PIN
Usage
Look at the documentation
The tests are also a good starting point
Tests
# Install the package
pip install python_x509_pkcs11
# Export env vars
export PKCS11_MODULE="/usr/lib/softhsm/libsofthsm2.so"
export PKCS11_TOKEN='my_test_token_1'
export PKCS11_PIN='1234'
# Delete and init a token
softhsm2-util --delete-token --token my_test_token_1
softhsm2-util --init-token --slot 0 --label $PKCS11_TOKEN --pin $PKCS11_PIN --so-pin $PKCS11_PIN
# Run unittest with mypy, pylint and pycodestyle
mypy --strict --namespace-packages --ignore-missing-imports tests/*.py \
&& pylint tests/*.py \
&& pycodestyle tests/*.py \
&& python3 -m unittest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python_x509_pkcs11-0.1.81.tar.gz
(10.8 kB
view details)
Built Distribution
File details
Details for the file python_x509_pkcs11-0.1.81.tar.gz
.
File metadata
- Download URL: python_x509_pkcs11-0.1.81.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcb4cbe018f166e921ea40401abb020411a33b31c5a7d9ece2590180c6f77105 |
|
MD5 | c43185a7c43c07572b326bf401d3ff75 |
|
BLAKE2b-256 | 83e23927d82722ac516def3b700c1d9f380bc3eab5df176216548f1dac75bf00 |
File details
Details for the file python_x509_pkcs11-0.1.81-py3-none-any.whl
.
File metadata
- Download URL: python_x509_pkcs11-0.1.81-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 054d99fbee0da699d4d68f077a7928b214ccea343d94d8d92137139d68941284 |
|
MD5 | 98e110da19e69c5537c98e71ddb61ed2 |
|
BLAKE2b-256 | de4260b221d0a4bc2b684861fc5cd82ba60f773a127d6d64afe08eab2faab5f6 |