Skip to content

Commit b76ae36

Browse files
committed
Update PKCS11 server examples for using a certificate stored with PKCS11, add instructions to readme showing how to use wolfPKCS11 for TLS
1 parent bee7a18 commit b76ae36

3 files changed

Lines changed: 419 additions & 138 deletions

File tree

pkcs11/README.md

Lines changed: 131 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -16,126 +16,150 @@ See [PKCS11.md](./PKCS11.md) in this folder.
1616

1717
1. 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
2929
2. 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
3838
3. 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
4545
4. 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
6464
1. 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
7676
2. 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
8383
3. 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
9090
4. 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
9696
5. 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+
115115
6. Start daemon if not running already:
116-
117-
`sudo /usr/local/sbin/pkcsslotd`
116+
117+
`sudo /usr/local/sbin/pkcsslotd`
118118
119119
7. 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
131131
8. 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
140164
The 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
146170
1. 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
154178
2. 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
163187
The 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
167191
Change this to be the id that you set when importing the key.
168192
169193
1. 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
177201
2. 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

Comments
 (0)