Skip to main content

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 tests/test_root_ca.py

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 pycodestyle
mypy --strict --namespace-packages --ignore-missing-imports tests/*.py
pylint tests/*.py
pycodestyle tests/*.py
python3 -m unittest tests/*.py

Project details


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.7.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

python_x509_pkcs11-0.1.7-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file python_x509_pkcs11-0.1.7.tar.gz.

File metadata

  • Download URL: python_x509_pkcs11-0.1.7.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for python_x509_pkcs11-0.1.7.tar.gz
Algorithm Hash digest
SHA256 35fe2215a03d534247b3aa0ad4a431eb7e6e10d7c26d42a9fcb2f8e7497666be
MD5 b6c4932d199eb1070749ab793c868dd7
BLAKE2b-256 a6d5fbcd813d2c6f7a23f23b47bc4e5175e833a6c711ea840a8aee5517b6b992

See more details on using hashes here.

File details

Details for the file python_x509_pkcs11-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for python_x509_pkcs11-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fb4dba582a652d51678e907c13b81f99107700355870e3a0c9de63c0fac515b6
MD5 53ce8633c3783a5c5ece6836ae1aa166
BLAKE2b-256 82bc6f829e4c6bc199838ecb8b99d0989af1903ad335f4e364726fcea6f3c2b6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page