|
| 1 | +PKCS#11 Token |
| 2 | +============= |
| 3 | + |
| 4 | +The PKCS#11 Token device implementation allows HWI to interact with PKCS#11-compliant Hardware Security Modules (HSMs) that support the secp256k1 curve. |
| 5 | + |
| 6 | +Requirements |
| 7 | +------------ |
| 8 | + |
| 9 | +- A PKCS#11-compliant HSM with secp256k1 curve support |
| 10 | +- The PKCS#11 library for your HSM |
| 11 | +- The ``python-pkcs11`` Python package |
| 12 | + |
| 13 | +Windows-specific Requirements |
| 14 | +--------------------------- |
| 15 | + |
| 16 | +On Windows, you'll need: |
| 17 | + |
| 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 |
| 22 | + |
| 23 | +2. OpenSSL development headers |
| 24 | + - Download from: https://slproweb.com/products/Win32OpenSSL.html |
| 25 | + - Choose the "Win64 OpenSSL" version |
| 26 | + - During installation, select "Copy OpenSSL DLLs to Windows system directory" |
| 27 | + |
| 28 | +3. The PKCS#11 library for your HSM (usually a .dll file) |
| 29 | + - Place the .dll file in a system path (e.g., C:\Windows\System32) |
| 30 | + - Or specify its path using the PKCS11_LIB_PATH environment variable |
| 31 | + |
| 32 | +Installation Steps for Windows: |
| 33 | + |
| 34 | +1. Install the prerequisites in the order listed above |
| 35 | + |
| 36 | +2. Install python-pkcs11: |
| 37 | + .. code-block:: powershell |
| 38 | + pip install python-pkcs11 |
| 39 | + If you get a "Failed building wheel" error: |
| 40 | + - Make sure Visual Studio Build Tools are installed |
| 41 | + - Ensure OpenSSL is installed and in your PATH |
| 42 | + - Try running the command in a new terminal after installing the prerequisites |
| 43 | + |
| 44 | +Configuration |
| 45 | +------------ |
| 46 | + |
| 47 | +The following environment variables can be used to configure the PKCS#11 device: |
| 48 | + |
| 49 | +- ``PKCS11_LIB_PATH``: Path to the PKCS#11 library (required) |
| 50 | +- ``PKCS11_TOKEN_LABEL``: Label of the token to use (default: "Bitcoin") |
| 51 | + |
| 52 | +Usage |
| 53 | +----- |
| 54 | + |
| 55 | +1. Set up your environment variables: |
| 56 | + |
| 57 | + .. code-block:: powershell |
| 58 | + # On Windows (PowerShell): |
| 59 | + $env:PKCS11_LIB_PATH = "C:\path\to\your\pkcs11\library.dll" |
| 60 | + $env:PKCS11_TOKEN_LABEL = "YourTokenLabel" |
| 61 | + # On Linux/macOS: |
| 62 | + export PKCS11_LIB_PATH=/path/to/your/pkcs11/library.so |
| 63 | + export PKCS11_TOKEN_LABEL=YourTokenLabel |
| 64 | +2. Initialize your HSM with a master key: |
| 65 | + |
| 66 | + - Create a master key with label "MASTER_KEY" |
| 67 | + - Ensure the key uses the secp256k1 curve |
| 68 | + - Set appropriate access controls |
| 69 | + |
| 70 | +3. Use HWI with your PKCS#11 token: |
| 71 | + |
| 72 | + .. code-block:: bash |
| 73 | + hwi enumerate # List available devices |
| 74 | + hwi --device-type pkcs11 --path /path/to/library.so getmasterxpub |
| 75 | +Security Considerations |
| 76 | +--------------------- |
| 77 | + |
| 78 | +- The PKCS#11 token must be properly configured with appropriate access controls |
| 79 | +- The master key should be protected with a strong PIN/password |
| 80 | +- The PKCS#11 library should be from a trusted source |
| 81 | +- The token should be physically secured |
| 82 | + |
| 83 | +Limitations |
| 84 | +---------- |
| 85 | + |
| 86 | +- Only supports secp256k1 curve |
| 87 | +- Requires the token to be pre-initialized with a master key |
| 88 | +- May not support all HWI features depending on the token's capabilities |
| 89 | + |
| 90 | +Troubleshooting |
| 91 | +-------------- |
| 92 | + |
| 93 | +If you encounter issues: |
| 94 | + |
| 95 | +1. Verify your PKCS#11 library is properly installed |
| 96 | +2. Check that your token supports the secp256k1 curve |
| 97 | +3. Ensure the master key exists and is accessible |
| 98 | +4. Check the token's logs for any error messages |
| 99 | +5. Verify the environment variables are set correctly |
| 100 | + |
| 101 | +Windows-specific Troubleshooting: |
| 102 | + |
| 103 | +1. If you get a "Failed building wheel" error: |
| 104 | + - Make sure Visual Studio Build Tools are installed |
| 105 | + - Ensure OpenSSL is installed and in your PATH |
| 106 | + - Try running the command in a new terminal after installing the prerequisites |
| 107 | + |
| 108 | +2. If the library is not found: |
| 109 | + - Check if the .dll file is in a system path |
| 110 | + - Verify the PKCS11_LIB_PATH environment variable is set correctly |
| 111 | + - Try running as Administrator |
| 112 | + |
| 113 | +3. If you get a "DLL load failed" error: |
| 114 | + - Check if all required dependencies are installed |
| 115 | + - Verify the architecture matches (32-bit vs 64-bit) |
| 116 | + - Try installing the Visual C++ Redistributable |
| 117 | + - Make sure OpenSSL DLLs are in your system PATH |
0 commit comments