]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
D-Bus: Add support to set pkcs11_{engine,module}_path
authorMichael Schaller <misch@google.com>
Sat, 23 Nov 2013 08:38:07 +0000 (10:38 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 23 Nov 2013 08:48:27 +0000 (10:48 +0200)
Add SetPKCS11EngineAndModulePath D-Bus method. Add PKCS11EnginePath
and PKCS11ModulePath D-Bus property getters.

Signed-hostap: Michael Schaller <misch@google.com>

doc/dbus.doxygen
wpa_supplicant/dbus/dbus_new.c
wpa_supplicant/dbus/dbus_new_handlers.c
wpa_supplicant/dbus/dbus_new_handlers.h
wpa_supplicant/wpa_supplicant.c
wpa_supplicant/wpa_supplicant_i.h

index 87093ed2ddb59648f4346171f70cdace362e0986..2aa874de7c9259d5c734422bbcb2b1953b03379d 100644 (file)
@@ -408,6 +408,25 @@ fi.w1.wpa_supplicant1.CreateInterface.
        <h3>EAPLogon ( ) --> nothing</h3>
        <p>IEEE 802.1X EAPOL state machine logon.</p>
       </li>
+
+      <li>
+       <h3>SetPKCS11EngineAndModulePath ( s : pkcs11_engine_path, s : pkcs11_module_path ) --> nothing</h3>
+       <p>Set PKCS #11 engine and module path.</p>
+       <h4>Arguments</h4>
+       <dl>
+         <dt>s : pkcs11_engine_path</dt>
+         <dd>PKCS #11 engine path.</dd>
+         <dt>s : pkcs11_module_path</dt>
+         <dd>PKCS #11 module path.</dd>
+       </dl>
+       <h4>Possible errors</h4>
+       <dl>
+         <dt>org.freedesktop.DBus.Error.Failed.InvalidArgs</dt>
+         <dd>Invalid PKCS #11 engine or module path.</dd>
+         <dt>org.freedesktop.DBus.Error.Failed</dt>
+         <dd>Reinit of the EAPOL state machine with the new PKCS #11 engine and module path failed.</dd>
+       </dl>
+      </li>
     </ul>
 
 \subsection dbus_interface_properties Properties
@@ -507,6 +526,16 @@ fi.w1.wpa_supplicant1.CreateInterface.
        <h3>ScanInterval - i - (read/write)</h3>
        <p>Time (in seconds) between scans for a suitable AP. Must be >= 0.</p>
       </li>
+
+      <li>
+       <h3>PKCS11EnginePath - s - (read)</h3>
+       <p>PKCS #11 engine path.</p>
+      </li>
+
+      <li>
+       <h3>PKCS11ModulePath - s - (read)</h3>
+       <p>PKCS #11 module path.</p>
+      </li>
     </ul>
 
 \subsection dbus_interface_signals Signals
index 9736e8f0a7ef326538ac9862f4f5d73761dd0485..f40d4219e5685d729ca27622ec609971f9bf3a4a 100644 (file)
@@ -2516,6 +2516,15 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
          }
        },
 #endif /* CONFIG_NO_CONFIG_BLOBS */
+       { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler)
+         &wpas_dbus_handler_set_pkcs11_engine_and_module_path,
+         {
+                 { "pkcs11_engine_path", "s", ARG_IN },
+                 { "pkcs11_module_path", "s", ARG_IN },
+                 END_ARGS
+         }
+       },
 #ifdef CONFIG_WPS
        { "Start", WPAS_DBUS_NEW_IFACE_WPS,
          (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
@@ -2843,6 +2852,14 @@ static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
          wpas_dbus_getter_scan_interval,
          wpas_dbus_setter_scan_interval
        },
+       { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+         wpas_dbus_getter_pkcs11_engine_path,
+         NULL
+       },
+       { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+         wpas_dbus_getter_pkcs11_module_path,
+         NULL
+       },
 #ifdef CONFIG_WPS
        { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
          wpas_dbus_getter_process_credentials,
index 0a80521229d74a2a92a8e8d2e0e1bf778f647f41..fdf9a0a65d98d2255eea3e40a824df822373a050 100644 (file)
@@ -2161,6 +2161,63 @@ DBusMessage * wpas_dbus_handler_tdls_teardown(DBusMessage *message,
 #endif /* CONFIG_TDLS */
 
 
+/**
+ * wpas_dbus_handler_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: %wpa_supplicant data structure
+ * Returns: A dbus message containing an error on failure or NULL on success
+ *
+ * Sets the PKCS #11 engine and module path.
+ */
+DBusMessage * wpas_dbus_handler_set_pkcs11_engine_and_module_path(
+       DBusMessage *message, struct wpa_supplicant *wpa_s)
+{
+       DBusMessageIter iter;
+       char *value = NULL;
+       char *pkcs11_engine_path = NULL;
+       char *pkcs11_module_path = NULL;
+
+       dbus_message_iter_init(message, &iter);
+       dbus_message_iter_get_basic(&iter, &value);
+       if (value == NULL) {
+               return dbus_message_new_error(
+                       message, DBUS_ERROR_INVALID_ARGS,
+                       "Invalid pkcs11_engine_path argument");
+       }
+       /* Empty path defaults to NULL */
+       if (os_strlen(value))
+               pkcs11_engine_path = value;
+
+       dbus_message_iter_next(&iter);
+       dbus_message_iter_get_basic(&iter, &value);
+       if (value == NULL) {
+               os_free(pkcs11_engine_path);
+               return dbus_message_new_error(
+                       message, DBUS_ERROR_INVALID_ARGS,
+                       "Invalid pkcs11_module_path argument");
+       }
+       /* Empty path defaults to NULL */
+       if (os_strlen(value))
+               pkcs11_module_path = value;
+
+       if (wpas_set_pkcs11_engine_and_module_path(wpa_s, pkcs11_engine_path,
+                                                  pkcs11_module_path))
+               return dbus_message_new_error(
+                       message, DBUS_ERROR_FAILED,
+                       "Reinit of the EAPOL state machine with the new PKCS "
+                       "#11 engine and module path failed.");
+
+       wpa_dbus_mark_property_changed(
+               wpa_s->global->dbus, wpa_s->dbus_new_path,
+               WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11EnginePath");
+       wpa_dbus_mark_property_changed(
+               wpa_s->global->dbus, wpa_s->dbus_new_path,
+               WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11ModulePath");
+
+       return NULL;
+}
+
+
 /**
  * wpas_dbus_getter_capabilities - Return interface capabilities
  * @iter: Pointer to incoming dbus message iter
@@ -3176,6 +3233,76 @@ out:
 }
 
 
+/**
+ * wpas_dbus_getter_pkcs11_engine_path - Get PKCS #11 engine path
+ * @iter: Pointer to incoming dbus message iter
+ * @error: Location to store error on failure
+ * @user_data: Function specific data
+ * Returns: A dbus message containing the PKCS #11 engine path
+ *
+ * Getter for "PKCS11EnginePath" property.
+ */
+dbus_bool_t wpas_dbus_getter_pkcs11_engine_path(DBusMessageIter *iter,
+                                               DBusError *error,
+                                               void *user_data)
+{
+       struct wpa_supplicant *wpa_s = user_data;
+       const char *pkcs11_engine_path;
+
+       if (wpa_s->conf == NULL) {
+               wpa_printf(MSG_ERROR,
+                          "wpas_dbus_getter_pkcs11_engine_path[dbus]: An "
+                          "error occurred getting the PKCS #11 engine path.");
+               dbus_set_error_const(
+                       error, DBUS_ERROR_FAILED,
+                       "An error occured getting the PKCS #11 engine path.");
+               return FALSE;
+       }
+
+       if (wpa_s->conf->pkcs11_engine_path == NULL)
+               pkcs11_engine_path = "";
+       else
+               pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
+       return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
+                                               &pkcs11_engine_path, error);
+}
+
+
+/**
+ * wpas_dbus_getter_pkcs11_module_path - Get PKCS #11 module path
+ * @iter: Pointer to incoming dbus message iter
+ * @error: Location to store error on failure
+ * @user_data: Function specific data
+ * Returns: A dbus message containing the PKCS #11 module path
+ *
+ * Getter for "PKCS11ModulePath" property.
+ */
+dbus_bool_t wpas_dbus_getter_pkcs11_module_path(DBusMessageIter *iter,
+                                               DBusError *error,
+                                               void *user_data)
+{
+       struct wpa_supplicant *wpa_s = user_data;
+       const char *pkcs11_module_path;
+
+       if (wpa_s->conf == NULL) {
+               wpa_printf(MSG_ERROR,
+                          "wpas_dbus_getter_pkcs11_module_path[dbus]: An "
+                          "error occurred getting the PKCS #11 module path.");
+               dbus_set_error_const(
+                       error, DBUS_ERROR_FAILED,
+                       "An error occured getting the PKCS #11 module path.");
+               return FALSE;
+       }
+
+       if (wpa_s->conf->pkcs11_module_path == NULL)
+               pkcs11_module_path = "";
+       else
+               pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
+       return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
+                                               &pkcs11_module_path, error);
+}
+
+
 /**
  * wpas_dbus_getter_blobs - Get all blobs defined for this interface
  * @iter: Pointer to incoming dbus message iter
index aa3316b7da9887fa244eb8d2d3f48a47c7b10bf0..c0669445eb8571f3f371ddb0990e8a242001e3a1 100644 (file)
@@ -122,6 +122,9 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
 DBusMessage * wpas_dbus_handler_remove_blob(DBusMessage *message,
                                            struct wpa_supplicant *wpa_s);
 
+DBusMessage * wpas_dbus_handler_set_pkcs11_engine_and_module_path(
+       DBusMessage *message, struct wpa_supplicant *wpa_s);
+
 DBusMessage * wpas_dbus_handler_flush_bss(DBusMessage *message,
                                          struct wpa_supplicant *wpa_s);
 
@@ -218,6 +221,14 @@ dbus_bool_t wpas_dbus_getter_bsss(DBusMessageIter *iter, DBusError *error,
 dbus_bool_t wpas_dbus_getter_networks(DBusMessageIter *iter, DBusError *error,
                                      void *user_data);
 
+dbus_bool_t wpas_dbus_getter_pkcs11_engine_path(DBusMessageIter *iter,
+                                               DBusError *error,
+                                               void *user_data);
+
+dbus_bool_t wpas_dbus_getter_pkcs11_module_path(DBusMessageIter *iter,
+                                               DBusError *error,
+                                               void *user_data);
+
 dbus_bool_t wpas_dbus_getter_blobs(DBusMessageIter *iter, DBusError *error,
                                   void *user_data);
 
index 55cc3d318554f6e30d7dfaceb8f283ead726af9e..812be003a8129519a47edc14dcddfbfcdfc575c8 100644 (file)
@@ -1957,6 +1957,59 @@ void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
 }
 
 
+/**
+ * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * @pkcs11_engine_path: PKCS #11 engine path or NULL
+ * @pkcs11_module_path: PKCS #11 module path or NULL
+ * Returns: 0 on success; -1 on failure
+ *
+ * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid
+ * path. If resetting the EAPOL state machine with the new PKCS #11 engine and
+ * module path fails the paths will be reset to the default value (NULL).
+ */
+int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s,
+                                          const char *pkcs11_engine_path,
+                                          const char *pkcs11_module_path)
+{
+       char *pkcs11_engine_path_copy = NULL;
+       char *pkcs11_module_path_copy = NULL;
+
+       if (pkcs11_engine_path != NULL) {
+               pkcs11_engine_path_copy = os_strdup(pkcs11_engine_path);
+               if (pkcs11_engine_path_copy == NULL)
+                       return -1;
+       }
+       if (pkcs11_module_path != NULL) {
+               pkcs11_module_path_copy = os_strdup(pkcs11_module_path);
+               if (pkcs11_engine_path_copy == NULL) {
+                       os_free(pkcs11_engine_path_copy);
+                       return -1;
+               }
+       }
+
+       os_free(wpa_s->conf->pkcs11_engine_path);
+       os_free(wpa_s->conf->pkcs11_module_path);
+       wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path_copy;
+       wpa_s->conf->pkcs11_module_path = pkcs11_module_path_copy;
+
+       wpa_sm_set_eapol(wpa_s->wpa, NULL);
+       eapol_sm_deinit(wpa_s->eapol);
+       wpa_s->eapol = NULL;
+       if (wpa_supplicant_init_eapol(wpa_s)) {
+               /* Error -> Reset paths to the default value (NULL) once. */
+               if (pkcs11_engine_path != NULL && pkcs11_module_path != NULL)
+                       wpas_set_pkcs11_engine_and_module_path(wpa_s, NULL,
+                                                              NULL);
+
+               return -1;
+       }
+       wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
+
+       return 0;
+}
+
+
 /**
  * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
  * @wpa_s: wpa_supplicant structure for a network interface
index eed1053ad95f477baa9871a4850bcd16be362539..32cea8bfda2ef94de73b6ca9daabe48d650e4f54 100644 (file)
@@ -772,6 +772,9 @@ void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
                                    struct wpa_ssid *ssid);
 void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
                                   struct wpa_ssid *ssid);
+int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s,
+                                          const char *pkcs11_engine_path,
+                                          const char *pkcs11_module_path);
 int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s,
                               int ap_scan);
 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s,