WebAssembly host adapter for PKCS#11 cryptographic token interface standard.
This project provides a WebAssembly Component Model adapter that bridges WebAssembly guest modules to native PKCS#11 providers (hardware tokens, HSMs, software tokens like SoftHSM).
host-adapter/- Rust implementation that wraps native PKCS#11 librariesguest-smoke/- Example WebAssembly guest component for testingdocs/- Design documentation and implementation noteswit/- WIT interface definitions (git submodule)
The WIT interface definitions are maintained in a separate repository: pkcs11-wit
After cloning this repository, initialize the WIT submodule:
git submodule update --init --recursiveFor local development before pushing pkcs11-wit to remote:
If you haven't pushed pkcs11-wit to a remote repository yet, create a symlink:
ln -s ~/git/pkcs11-wit witOnce pkcs11-wit is pushed to a remote repository, add it as a proper submodule:
rm wit # Remove symlink
git submodule add https://github.com/your-org/pkcs11-wit.git wit- wasmtime - WebAssembly runtime with Component Model support
- libloading - Dynamic loading of native PKCS#11 provider libraries
- wit-bindgen - Generate Rust bindings from WIT definitions
- SoftHSM2
- Hardware HSMs (YubiHSM, Luna, etc.)
- Any PKCS#11 2.x compliant provider
cd host-adapter
cargo buildThe host adapter includes integration tests that can run against a real PKCS#11 provider:
# Point to your PKCS#11 module
export PKCS11_MODULE_PATH="/opt/homebrew/lib/softhsm/libsofthsm2.so"
# Optional: provide a PIN for testing authenticated operations
export PKCS11_USER_PIN="1234"
cargo testThe adapter can be packaged as a wasmtime host bundle for easy distribution:
# Build host bundle
cd host-adapter
cargo build --release
# Run component with PKCS#11
wasmtime component run \
--host-bundle ./pkcs11_host_bundle \
--env PKCS11_MODULE_PATH=/usr/local/lib/softhsm/libsofthsm2.so \
your_component.wasmSee WASMTIME_INTEGRATION.md for complete integration guide.
use pkcs11_host_adapter::AdapterContext;
// Initialize with a PKCS#11 provider
let ctx = AdapterContext::default();
ctx.ensure_initialized("/usr/local/lib/softhsm/libsofthsm2.so")?;
// Use the PKCS#11 interface through WebAssembly componentsThis adapter is designed to work with:
- Wasmtime CLI: Via host bundles (see WASMTIME_INTEGRATION.md)
- Custom Runtimes: Link directly as a Rust library
- Component Orchestration: Compatible with webassembly-component-orchestration patterns
- wasmtime: WebAssembly runtime with component model support
- pkcs11-wit: WIT interface definitions (submodule)
- webassembly-component-orchestration: Component composition system
Apache-2.0