@@ -16,126 +16,150 @@ See [PKCS11.md](./PKCS11.md) in this folder.
1616
17171 . Change to source code directory of SoftHSM version 2
1818
19- This tool can be found here: https://github.com/opendnssec/SoftHSMv2
19+ This tool can be found here: https://github.com/opendnssec/SoftHSMv2
2020
21- ```
22- ./autogen.sh
23- ./configure --disable-gost
24- sudo make install
25- ```
21+ ```
22+ ./autogen.sh
23+ ./configure --disable-gost
24+ sudo make install
25+ ```
2626
27- * Note: May need to install pkg-config and libssl-dev*
27+ *Note: May need to install pkg-config and libssl-dev*
2828
29292. Change to wolfssl directory
3030
31- ```
32- ./autogen.sh
33- ./configure --enable-pkcs11
34- make
35- sudo make install
36- ```
31+ ```
32+ ./autogen.sh
33+ ./configure --enable-pkcs11
34+ make
35+ sudo make install
36+ ```
3737
38383. Change to wolfssl-examples/pkcs11 directory
3939
40- ```
41- ./mksofthsm2_conf.sh
42- export SOFTHSM2_CONF=$PWD/softhsm2.conf
43- ```
40+ ```
41+ ./mksofthsm2_conf.sh
42+ export SOFTHSM2_CONF=$PWD/softhsm2.conf
43+ ```
4444
45454. Running tests
4646
47- `softhsm2-util --init-token --slot 0 --label SoftToken`
47+ `softhsm2-util --init-token --slot 0 --label SoftToken`
4848
49- * Use PIN: cryptoki
50- * Use User PIN: cryptoki
49+ * Use PIN: cryptoki
50+ * Use User PIN: cryptoki
5151
52- Use the slot id from the output:
53-
54- `export SOFTHSM2_SLOTID=<slotid>`
52+ Use the slot id from the output:
5553
56- Run the examples:
54+ `export SOFTHSM2_SLOTID=<slotid>`
5755
58- `./softhsm2.sh`
56+ Run the examples:
57+
58+ `./softhsm2.sh`
5959
6060
6161## Setting up and testing openCryptoki
6262
6363
64641. Change to source code directory of openCryptoki
6565
66- This tool can be found here: https://github.com/opencryptoki/opencryptoki
66+ This tool can be found here: https://github.com/opencryptoki/opencryptoki
6767
68- ```
69- ./bootstrap.sh
70- ./configure
71- make
72- ```
68+ ```
69+ ./bootstrap.sh
70+ ./configure
71+ make
72+ ```
7373
74- *Note: May need to install flex, bison and openldap-devel [or libldap2-dev]*
74+ *Note: May need to install flex, bison and openldap-devel [or libldap2-dev]*
7575
76762. Setup pkcs11 group and put current user into it
7777
78- ```
79- sudo groupadd pkcs11
80- sudo usermod -a -G pkcs11 $USER
81- ```
78+ ```
79+ sudo groupadd pkcs11
80+ sudo usermod -a -G pkcs11 $USER
81+ ```
8282
83833. Install library
8484
85- ```
86- sudo make install
87- sudo ldconfig /usr/local/lib
88- ```
85+ ```
86+ sudo make install
87+ sudo ldconfig /usr/local/lib
88+ ```
8989
90904. Start the daemon
9191
92- `sudo /usr/local/sbin/pkcsslotd`
93-
94- *Note: May need to logout and login to be able to use pkcsconf.*
92+ `sudo /usr/local/sbin/pkcsslotd`
93+
94+ *Note: May need to logout and login to be able to use pkcsconf.*
9595
96965. Setup token
97-
98- ```
99- echo "87654321
100- SoftToken" | pkcsconf -I -c 3
101- ```
102-
103- ```
104- echo "87654321
105- cryptoki
106- cryptoki" | pkcsconf -P -c 3
107- ```
108-
109- ```
110- echo "cryptoki
111- cryptoki
112- cryptoki" | pkcsconf -u -c 3
113- ```
114-
97+
98+ ```
99+ echo "87654321
100+ SoftToken" | pkcsconf -I -c 3
101+ ```
102+
103+ ```
104+ echo "87654321
105+ cryptoki
106+ cryptoki" | pkcsconf -P -c 3
107+ ```
108+
109+ ```
110+ echo "cryptoki
111+ cryptoki
112+ cryptoki" | pkcsconf -u -c 3
113+ ```
114+
1151156. Start daemon if not running already:
116-
117- `sudo /usr/local/sbin/pkcsslotd`
116+
117+ `sudo /usr/local/sbin/pkcsslotd`
118118
1191197. Build and install wolfSSL
120120
121- Change to wolfssl directory and run:
121+ Change to wolfssl directory and run:
122122
123- ```
124- ./autogen.sh
125- ./configure --enable-pkcs11
126- make
127- sudo make install
128- ```
123+ ```
124+ ./autogen.sh
125+ ./configure --enable-pkcs11
126+ make
127+ sudo make install
128+ ```
129129
130130
1311318. Running tests
132132
133- Change to wolfssl-examples/pkcs11 directory:
134-
135- `./opencryptoki.sh`
133+ Change to wolfssl-examples/pkcs11 directory:
134+
135+ `./opencryptoki.sh`
136+
137+ ## Setting up and testing wolfPKCS11
138+
139+ 1. Change to source code directory of wolfPKCS11
140+
141+ This tool can be found here: https://github.com/wolfSSL/wolfPKCS11
142+
143+ ```
144+ ./autogen.sh
145+ ./configure
146+ make && sudo make install
147+ ./examples/init_token
148+ export WOLFPKCS11_DIR=.
149+ ```
150+
151+ 2. Change to wolfssl directory
152+
153+ ```
154+ ./autogen.sh
155+ ./configure --enable-aescfb --enable-cryptocb --enable-rsapss --enable-keygen --enable-pwdbased --enable-scrypt --enable-pkcs11 --enable-debug 'C_EXTRA_FLAGS=-DWOLFSSL_PUBLIC_MP -DWC_RSA_DIRECT -DWOLFSSL_PKCS11_RW_TOKENS'
156+ make
157+ sudo make install
158+ ```
159+ It should be noted WOLFSSL_PKCS11_RW_TOKENS is only needed for adding the keys and certs to the store. Once already in the store this is not longer needed.
136160
137161
138- ## TLS Server Example with PKCS # 11 (RSA)
162+ ## TLS Server Example with SoftHSM (RSA)
139163
140164The example `server-tls-pkcs11` is a server that uses a private key that has been stored on the PKCS #11 device.
141165
@@ -145,41 +169,58 @@ Change this to be the id that you set when importing the key.
145169
1461701. SoftHSM version 2
147171
148- Import private key:
149-
150- `softhsm2-util --import ../certs/server-keyPkcs8.pem --slot $SOFTHSM2_SLOTID --id 0001 --label rsa2048`
172+ Import private key:
151173
152- Enter PIN: cryptoki
174+ `softhsm2-util --import ../certs/server-keyPkcs8.pem --slot $SOFTHSM2_SLOTID --id 0001 --label rsa2048`
175+
176+ Enter PIN: cryptoki
153177
1541782. Run server and client
155179
156- `./server-tls-pkcs11 /usr/local/lib/softhsm/libsofthsm2.so $SOFTHSM2_SLOTID SoftToken cryptoki`
180+ `./server-tls-pkcs11 -lib /usr/local/lib/softhsm/libsofthsm2.so -slot $SOFTHSM2_SLOTID -tokenName SoftToken -userPin cryptoki`
157181
158- From wolfssl root:
159- `./examples/client/client`
182+ From wolfssl root:
183+ `./examples/client/client`
160184
161- ## TLS Server Example with PKCS # 11 (ECC)
185+ ## TLS Server Example with SoftHSM (ECC)
162186
163187The example `server-tls-pkcs11-ecc` is a server that uses a private key that has been stored on the PKCS #11 device.
164188
165- The id of the private key is two hex bytes: ` 0x00, 0x01 `
189+ The id of the private key is two hex bytes: `0x00, 0x02 `
166190
167191Change this to be the id that you set when importing the key.
168192
1691931. SoftHSM version 2
170194
171- Import private key:
172-
173- `softhsm2-util --import ../certs/ecc-keyPkcs8.pem --slot $SOFTHSM2_SLOTID --id 0002 --label ecp256`
195+ Import private key:
196+
197+ `softhsm2-util --import ../certs/ecc-keyPkcs8.pem --slot $SOFTHSM2_SLOTID --id 0002 --label ecp256`
174198
175- Enter PIN: cryptoki
199+ Enter PIN: cryptoki
176200
1772012. Run server and client
178202
179- `./server-tls-pkcs11-ecc /usr/local/lib/softhsm/libsofthsm2.so $SOFTHSM2_SLOTID SoftToken cryptoki`
203+ `./server-tls-pkcs11-ecc -lib /usr/local/lib/softhsm/libsofthsm2.so -slot $SOFTHSM2_SLOTID -tokenName SoftToken -userPin cryptoki`
204+
205+ From wolfssl root:
206+ `./examples/client/client -A ./certs/ca-ecc-cert.pem`
207+
208+ ## TLS Server Example with wolfPKCS11 (RSA)
209+
210+ The example `server-tls-pkcs11` is a server that uses a private key and optionally a certificate that has been stored on the PKCS #11 device.
211+
212+ 1. Import Private Key and Certificate
213+ ```
214+ cd $WOLFPKCS11_DIR
215+ ./examples/add_rsa_key_file -privId "server-rsa2048" -rsa ../certs/server-key.der
216+ ./examples/add_cert_file -privId "server-rsa2048-id" -label "server-rsa2048-label" -cert ../certs/server-cert.der
217+ ```
218+
219+ 2. Run server and client
220+ `WOLFPKCS11_TOKEN_PATH=$WOLFPKCS11_DIR ./server-tls-pkcs11 -lib $WOLFPKCS11_DIR/src/.libs/libwolfpkcs11.so -tokenName wolfpkcs11 -userPin wolfpkcs11-test -privKeyId server-rsa2048 -certId server-rsa2048-id`
180221
181- From wolfssl root:
182- `./examples/client/client -A ./certs/ca-ecc-cert.pem `
222+ From wolfssl root:
223+ `./examples/client/client`
183224
184225
185226## Support
0 commit comments