Skip to content

Commit 48d7f44

Browse files
committed
libp11 PKCS#11 provider documentation
1 parent 6a2eb0f commit 48d7f44

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
NEWS for Libp11 -- History of user visible changes
22

33
New in 0.4.14; unreleased
4+
* Added support for the "pkcs11prov" provider with OpenSSL 3.0
5+
(Małgorzata Olszówka)
46

57
New in 0.4.13; 2024-12-13; Michał Trojnara
68
* Increased maximum PIN length (Michał Trojnara)

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,128 @@ In systems with p11-kit, if this engine control is not called engine_pkcs11
179179
defaults to loading the p11-kit proxy module.
180180

181181

182+
# PKCS#11 provider configuration
183+
184+
## Copying the provider shared object to the proper location
185+
186+
OpenSSL has a designated location where provider shared objects can be placed
187+
for automatic loading. To simplify usage, it is recommended to copy
188+
provider_pkcs11 to that location as `pkcs11prov.so`. This is handled by the
189+
`make install` process of provider_pkcs11.
190+
191+
## Using the openssl configuration file
192+
193+
OpenSSL 3.x does not automatically load custom providers, so `openssl.cnf` must
194+
explicitly define them. Without this configuration, OpenSSL will not detect or
195+
load `pkcs11prov`.
196+
197+
```
198+
[openssl_init]
199+
providers = provider_sect
200+
201+
[provider_sect]
202+
default = default_sect
203+
pkcs11 = pkcs11_sect
204+
205+
[default_sect]
206+
activate = 1
207+
208+
[pkcs11_sect]
209+
identity = pkcs11prov
210+
module = /usr/lib64/ossl-modules/pkcs11prov.so
211+
pkcs11_module = /usr/lib64/opensc-pkcs11.so
212+
debug_level = 7
213+
force_login = 1
214+
pin = XXXX
215+
activate = 1
216+
```
217+
218+
Some parameters can be overridden using environment variables:
219+
`OPENSSL_MODULES`, `PKCS11_MODULE_PATH`, `PKCS11_DEBUG_LEVEL`,
220+
`PKCS11_FORCE_LOGIN`, `PKCS11_PIN`
221+
222+
## Testing the provider operation
223+
224+
To verify that the provider is functioning correctly, run the following command:
225+
226+
```
227+
$ openssl list -providers -verbose -provider pkcs11prov
228+
Providers:
229+
pkcs11prov
230+
name: libp11 PKCS#11 provider (pkcs11prov)
231+
version: 3.4.1
232+
status: active
233+
build info: 3.4.1
234+
gettable provider parameters:
235+
name: pointer to a UTF8 encoded string (arbitrary size)
236+
version: pointer to a UTF8 encoded string (arbitrary size)
237+
buildinfo: pointer to a UTF8 encoded string (arbitrary size)
238+
status: integer (arbitrary size)
239+
240+
```
241+
242+
## Using OpenSSL with the provider from the command line
243+
244+
To enable automatic provider loading, ensure your `openssl.cnf` includes:
245+
246+
```
247+
openssl_conf = openssl_init
248+
249+
[openssl_init]
250+
providers = provider_sect
251+
252+
[provider_sect]
253+
default = default_sect
254+
pkcs11 = pkcs11_sect
255+
256+
[default_sect]
257+
activate = 1
258+
259+
[pkcs11_sect]
260+
identity = pkcs11prov
261+
pkcs11_module = /usr/lib64/opensc-pkcs11.so
262+
activate = 1
263+
```
264+
265+
To generate a certificate with its key stored in the PKCS#11 module, use:
266+
267+
```
268+
$ openssl req -new -key "pkcs11:object=test-key;type=private;pin-value=XXXX" \
269+
-out req.pem -text -x509 -subj "/CN=Andreas Jellinghaus"
270+
$ openssl x509 -signkey "pkcs11:object=test-key;type=private;pin-value=XXXX" \
271+
-in req.pem -out cert.pem
272+
```
273+
274+
Alternatively, you can use environment variables:
275+
276+
```
277+
$ PKCS11_MODULE_PATH=/usr/lib64/opensc-pkcs11.so PKCS11_PIN=XXXX \
278+
openssl req -new -key "pkcs11:object=test-key;type=private" \
279+
-out req.pem -text -x509 -subj "/CN=Andreas Jellinghaus" \
280+
-provider pkcs11prov -provider default
281+
$ PKCS11_MODULE_PATH=/usr/lib64/opensc-pkcs11.so PKCS11_PIN=XXXX \
282+
openssl x509 -signkey "pkcs11:object=test-key;type=private" \
283+
-in req.pem -out cert.pem \
284+
-provider pkcs11prov -provider default
285+
```
286+
287+
## Provider controls
288+
289+
The following provider controls are supported:
290+
* **pkcs11_module**: Specifies the path to the PKCS#11 module shared library
291+
* **pin**: Specifies the PIN code
292+
* **debug_level**: Sets the debug level: 0=emerg, 1=alert, 2=crit, 3=err, 4=warning, 5=notice (default), 6=info, 7=debug
293+
* **force_login**: Forces login to the PKCS#11 module
294+
* **init_args**: Specifies additional initialization arguments to the PKCS#11 module
295+
296+
Example code snippet for setting a specific module (requires OpenSSL 3.5):
297+
298+
```
299+
OSSL_PROVIDER *provider=OSSL_PROVIDER_load(NULL, "pkcs11prov");
300+
OSSL_PROVIDER_add_conf_parameter(provider, "pkcs11_module",
301+
"/path/to/pkcs11module.so");
302+
```
303+
182304
# Developer information
183305

184306
## Thread safety in libp11

0 commit comments

Comments
 (0)