Skip to content

Commit 2eacabc

Browse files
committed
Update PKCS#11 docs and requirements
1 parent feb1c18 commit 2eacabc

File tree

2 files changed

+73
-83
lines changed

2 files changed

+73
-83
lines changed

docs/devices/pkcs11.rst

Lines changed: 69 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -6,109 +6,96 @@ The PKCS#11 Token device implementation allows HWI to interact with PKCS#11-comp
66
Requirements
77
------------
88

9-
- A PKCS#11-compliant HSM with secp256k1 curve support
10-
- The PKCS#11 library for your HSM
11-
- The ``python-pkcs11`` Python package
9+
- A PKCS#11-compliant HSM with secp256k1 curve support.
10+
- The PKCS#11 library for your HSM.
11+
- The ``python-pkcs11`` Python package.
1212

1313
Windows-specific Requirements
14-
---------------------------
14+
-----------------------------
1515

1616
On Windows, you'll need:
1717

18-
1. Visual Studio Build Tools with C++ support
19-
- Download from: https://visualstudio.microsoft.com/visual-cpp-build-tools/
20-
- Select "Desktop development with C++"
21-
- Make sure to include the Windows 10 SDK
18+
1. **Visual Studio Build Tools with C++ support**
19+
- Download from: https://visualstudio.microsoft.com/visual-cpp-build-tools/
20+
- Select "Desktop development with C++".
21+
- Make sure to include the Windows 10 SDK.
2222

23-
2. OpenSSL development headers
24-
- Download from: https://slproweb.com/products/Win32OpenSSL.html
25-
- Choose the "Win64 OpenSSL" version
26-
- Ensure the OpenSSL bin directory is on PATH (avoid copying DLLs into Windows system directories)3. The PKCS#11 library for your HSM (usually a .dll file)
27-
- Prefer specifying its absolute path via PKCS11_LIB_PATH or placing it alongside the application.
28-
- Avoid copying into C:\Windows\System32 to reduce DLL hijack and servicing risk.Installation Steps for Windows:
23+
2. **OpenSSL development headers**
24+
- Download from: https://slproweb.com/products/Win32OpenSSL.html
25+
- Choose the "Win64 OpenSSL" version.
26+
- Ensure the OpenSSL bin directory is on PATH.
2927

30-
1. Install the prerequisites in the order listed above
28+
3. **The PKCS#11 library for your HSM** (usually a ``.dll`` file)
29+
- Prefer specifying its absolute path via ``PKCS11_LIB_PATH`` or placing it alongside the application.
30+
- Avoid copying into ``C:\Windows\System32`` to reduce DLL hijacking risks.
3131

32-
2. Install python-pkcs11:
33-
.. code-block:: powershell
34-
pip install python-pkcs11
35-
If you get a "Failed building wheel" error:
36-
- Make sure Visual Studio Build Tools are installed
37-
- Ensure OpenSSL is installed and in your PATH
38-
- Try running the command in a new terminal after installing the prerequisites
32+
Installation Steps for Windows:
33+
34+
1. Install the prerequisites in the order listed above.
35+
2. Install ``python-pkcs11``:
36+
37+
.. code-block:: shell
38+
39+
pip install python-pkcs11
40+
41+
If you get a "Failed building wheel" error, ensure prerequisites are installed correctly and try running the command in a new terminal.
3942

4043
Configuration
41-
------------
44+
-------------
45+
46+
The device can be configured using environment variables. Command-line flags will override these variables if provided.
47+
48+
- ``PKCS11_LIB_PATH``: **(Required)** Path to the PKCS#11 library.
49+
- ``PKCS11_TOKEN_LABEL``: Label of the token to use (default: "Bitcoin").
50+
- ``PKCS11_PIN``: User PIN for token login. For security, it is better to rely on the interactive prompt than to set this variable.
51+
52+
Example environment variable setup:
4253

43-
The following environment variables can be used to configure the PKCS#11 device:
54+
.. code-block:: powershell
4455
45-
- ``PKCS11_LIB_PATH``: Path to the PKCS#11 library (required)
46-
- ``PKCS11_TOKEN_LABEL``: Label of the token to use (default: "Bitcoin")
56+
# On Windows (PowerShell)
57+
$env:PKCS11_LIB_PATH = "C:\path\to\your\pkcs11\library.dll"
58+
$env:PKCS11_TOKEN_LABEL = "YourTokenLabel"
59+
60+
.. code-block:: shell
61+
62+
# On Linux/macOS
63+
export PKCS11_LIB_PATH=/path/to/your/pkcs11/library.so
64+
export PKCS11_TOKEN_LABEL=YourTokenLabel
4765
4866
Usage
49-
- ``PKCS11_LIB_PATH``: Path to the PKCS#11 library (required)
50-
- ``PKCS11_TOKEN_LABEL``: Label of the token to use (default: "Bitcoin")
51-
- ``PKCS11_PIN``: User PIN for token login (optional; prefer interactive prompt over env for security)
52-
53-
CLI flags, when provided, should take precedence over environment variables.
54-
.. code-block:: powershell
55-
# On Windows (PowerShell):
56-
$env:PKCS11_LIB_PATH = "C:\path\to\your\pkcs11\library.dll"
57-
$env:PKCS11_TOKEN_LABEL = "YourTokenLabel"
58-
# On Linux/macOS:
59-
export PKCS11_LIB_PATH=/path/to/your/pkcs11/library.so
60-
export PKCS11_TOKEN_LABEL=YourTokenLabel
61-
2. Initialize your HSM with a master key:
62-
63-
- Create a master key with label "MASTER_KEY"
64-
- Ensure the key uses the secp256k1 curve
65-
- Set appropriate access controls
66-
67-
3. Use HWI with your PKCS#11 token:
68-
69-
.. code-block:: bash
70-
hwi enumerate # List available devices
71-
hwi --device-type pkcs11 --path /path/to/library.so getmasterxpub
72-
Security Considerations
73-
---------------------
67+
-----
7468

75-
- The PKCS#11 token must be properly configured with appropriate access controls
76-
- The master key should be protected with a strong PIN/password
77-
- The PKCS#11 library should be from a trusted source
78-
- The token should be physically secured
69+
1. **Initialize your HSM** with a master key labeled ``MASTER_KEY`` using the secp256k1 curve.
70+
2. **Use HWI** with your PKCS#11 token:
7971

80-
Limitations
81-
----------
72+
.. code-block:: shell
8273
83-
- Only supports secp256k1 curve
84-
- Requires the token to be pre-initialized with a master key
85-
- May not support all HWI features depending on the token's capabilities
74+
# List available devices
75+
hwi enumerate
8676
87-
Troubleshooting
88-
--------------
77+
# Get the master public key
78+
hwi --device-type pkcs11 --path /path/to/library.so getmasterxpub
8979
90-
If you encounter issues:
80+
Security Considerations
81+
-----------------------
9182

92-
1. Verify your PKCS#11 library is properly installed
93-
2. Check that your token supports the secp256k1 curve
94-
3. Ensure the master key exists and is accessible
95-
4. Check the token's logs for any error messages
96-
5. Verify the environment variables are set correctly
83+
- The PKCS#11 token must be properly configured with appropriate access controls.
84+
- The master key should be protected with a strong PIN/password.
85+
- The PKCS#11 library should be from a trusted source.
86+
- The token should be physically secured.
9787

98-
Windows-specific Troubleshooting:
88+
Limitations
89+
-----------
9990

100-
1. If you get a "Failed building wheel" error:
101-
- Make sure Visual Studio Build Tools are installed
102-
- Ensure OpenSSL is installed and in your PATH
103-
- Try running the command in a new terminal after installing the prerequisites
91+
- Only supports the secp256k1 curve.
92+
- Requires the token to be pre-initialized with a master key.
93+
- May not support all HWI features depending on the token's capabilities.
10494

105-
2. If the library is not found:
106-
- Check if the .dll file is in a system path
107-
- Verify the PKCS11_LIB_PATH environment variable is set correctly
108-
- Try running as Administrator
95+
Troubleshooting
96+
---------------
10997

110-
3. If you get a "DLL load failed" error:
111-
- Check if all required dependencies are installed
112-
- Verify the architecture matches (32-bit vs 64-bit)
113-
- Try installing the Visual C++ Redistributable
114-
- Make sure OpenSSL DLLs are in your system PATH
98+
- Verify your PKCS#11 library is properly installed and the path is correct.
99+
- Check that your token supports the secp256k1 curve.
100+
- Ensure the ``MASTER_KEY`` exists and is accessible.
101+
- Check the token's logs for any error messages.

docs/requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
sphinxcontrib-autoprogram>=0.1.5
22
sphinx>=3.2.1
33
sphinx_rtd_theme>=1.0.0
4-
python-pkcs11>=0.7.0
4+
python-pkcs11>=0.7.0
5+
cbor2>=5.4.6,<6.0.0
6+
pyserial>=3.5
7+
semver>=2.13.0,<3.0.0

0 commit comments

Comments
 (0)