[Openvpn-devel,v2] pkcs11: Initialize pkcs11-helper early
Commit Message
From: Selva Nair <selva.nair@gmail.com>
Initializing before open_management() is required for
management interface directives such as pkcs11-id-count to
not error out if used during the first management-hold,
for example.
Github: fixes OpenVPN/openvpn#1166
Change-Id: Ibd33f20108d3ca8ddc17f145502d21d2f6e6d91a
Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2388
---
This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2388
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
@@ -747,20 +747,6 @@
do_link_socket_addr_new(c);
-#if defined(ENABLE_PKCS11)
- if (c->first_time)
- {
- int i;
- pkcs11_initialize(true, c->options.pkcs11_pin_cache_period);
- for (i = 0; i < MAX_PARMS && c->options.pkcs11_providers[i] != NULL; i++)
- {
- pkcs11_addProvider(
- c->options.pkcs11_providers[i], c->options.pkcs11_protected_authentication[i],
- c->options.pkcs11_private_mode[i], c->options.pkcs11_cert_private[i]);
- }
- }
-#endif
-
#if 0 /* test get_user_pass with GET_USER_PASS_NEED_OK flag */
{
/*
@@ -786,6 +772,26 @@
}
void
+init_pkcs11(const struct context *c)
+{
+#if defined(ENABLE_PKCS11)
+ if (c->first_time)
+ {
+ if (!pkcs11_initialize(true, c->options.pkcs11_pin_cache_period))
+ {
+ msg(M_FATAL, "ERROR: pkcs11-helper initialization failed.");
+ }
+ for (int i = 0; i < MAX_PARMS && c->options.pkcs11_providers[i] != NULL; i++)
+ {
+ pkcs11_addProvider(
+ c->options.pkcs11_providers[i], c->options.pkcs11_protected_authentication[i],
+ c->options.pkcs11_private_mode[i], c->options.pkcs11_cert_private[i]);
+ }
+ }
+#endif
+}
+
+void
context_gc_free(struct context *c)
{
gc_free(&c->c2.gc);
@@ -34,6 +34,7 @@
void context_clear_2(struct context *c);
void context_init_1(struct context *c);
+void init_pkcs11(const struct context *c);
void context_clear_all_except_first_time(struct context *c);
@@ -280,6 +280,8 @@
write_pid_file(c.options.writepid, c.options.chroot_dir);
}
+ init_pkcs11(&c);
+
#ifdef ENABLE_MANAGEMENT
/* open management subsystem */
if (!open_management(&c))