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