Debian Codegraph @

crt/aws-c-io/PKCS11.md

raw symbols SCIP
1 # PKCS#11 tests
2
3 To run the PKCS#11 tests, configure cmake with: `-DENABLE_PKCS11_TESTS=ON`
4
5 and set the following environment variables:
6
7 ```
8 TEST_PKCS11_LIB = <path-to-shared-lib>
9 TEST_PKCS11_TOKEN_DIR = <path-to-softhsm-token-dir>
10 ```
11 TEST_PKCS11_LIB is used by the tests to peform pkcs11 operations.
12
13 TEST_PKCS11_TOKEN_DIR is used by the tests to clear the softhsm tokens before a test begins. This is achieved by cleaning the token directory <b>NOTE: Any tokens created outside the tests will be cleaned up along with all the objects/keys on it as part of the tests.</b>
14
15
16 ## The suggested way to set up your machine
17 1) Install [SoftHSM2](https://www.opendnssec.org/softhsm/) via brew / apt / apt-get / yum:
18 ```
19 > apt install softhsm
20 ```
21
22 Check that it's working:
23 ```
24 > softhsm2-util --show-slots
25 ```
26
27 If this spits out an error message, create a config file:
28 * Default location: `~/.config/softhsm2/softhsm2.conf`
29 * This file must specify token dir, default value is:
30 ```
31 directories.tokendir = /usr/local/var/lib/softhsm/tokens/
32 ```
33
34 2) Set env vars like so:
35 ```
36 TEST_PKCS11_LIB = <path to libsofthsm2.so>
37 TEST_PKCS11_TOKEN_DIR = /usr/local/var/lib/softhsm/tokens/
38 ```
39
40
41 3) [Example to import your keys, Not used by tests] Create token and private key
42
43 You can use any values for the labels, pin, key, cert, CA etc.
44 Here are copy-paste friendly commands for using files available in this repo.
45 ```
46 > softhsm2-util --init-token --free --label my-test-token --pin 0000 --so-pin 0000
47 ```
48
49 Note which slot the token ended up in
50
51 ```
52 > softhsm2-util --import tests/resources/unittests.p8 --slot <slot-with-token> --label my-test-key --id BEEFCAFE --pin 0000
53 ```
54 <b>WARN: All tokens created outside the tests would be cleaned up as part of the tests, Use a separate token directory for running the tests if you would like to keep your tokens intact.</b>
55