Added support to set private-key password. 61/186061/1
authorNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 7 Aug 2018 05:03:59 +0000 (10:33 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 7 Aug 2018 05:03:59 +0000 (10:33 +0530)
Added support to set private-key password and it is valid
for EAP-TLS.
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
Change-Id: I7499655f5237fea0f3fb38f39c36f67a5ee4eb96

include/wifi-config.h
src/wifi-config.c

index 32206a7..86002a0 100755 (executable)
@@ -42,6 +42,7 @@ extern "C" {
 #define WIFI_CONFIG_EAP_CACERT                 "CACertFile"
 #define WIFI_CONFIG_EAP_CLIENTCERT                     "ClientCertFile"
 #define WIFI_CONFIG_EAP_PRIVATEKEY             "PrivateKeyFile"
+#define WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD    "PrivateKeyPassword"
 #define WIFI_CONFIG_EAP_IDENTITY               "Identity"
 #define WIFI_CONFIG_EAP_TYPE           "EapType"
 #define WIFI_CONFIG_EAP_AUTH_TYPE      "EapAuthType"
index aea051b..2d9f5f8 100755 (executable)
@@ -55,6 +55,7 @@ struct wifi_eap_config {
        gchar *ca_cert;
        gchar *client_cert;
        gchar *private_key;
+       gchar *private_key_password;
        gchar *identity;
        gchar *eap_type;
        gchar *eap_auth_type;
@@ -91,6 +92,7 @@ static void __free_wifi_configuration(struct wifi_config *conf)
                g_free(conf->eap_config->ca_cert);
                g_free(conf->eap_config->client_cert);
                g_free(conf->eap_config->private_key);
+               g_free(conf->eap_config->private_key_password);
                g_free(conf->eap_config->identity);
                g_free(conf->eap_config->eap_type);
                g_free(conf->eap_config->eap_auth_type);
@@ -316,6 +318,7 @@ static gboolean _load_configuration(const gchar *config_id, struct wifi_config *
                config->eap_config->ca_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CACERT, NULL);
                config->eap_config->client_cert = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_CLIENTCERT, NULL);
                config->eap_config->private_key = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY, NULL);
+               config->eap_config->private_key_password = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, NULL);
                config->eap_config->identity = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_IDENTITY, NULL);
                config->eap_config->eap_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_TYPE, NULL);
                config->eap_config->eap_auth_type = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_EAP_AUTH_TYPE, NULL);
@@ -329,6 +332,8 @@ static gboolean _load_configuration(const gchar *config_id, struct wifi_config *
                        DBG("client_cert [%s]", config->eap_config->client_cert);
                if (config->eap_config->private_key)
                        DBG("private_key [%s]", config->eap_config->private_key);
+               if (config->eap_config->private_key_password)
+                       DBG("private_key_password [%s]", config->eap_config->private_key_password);
                if (config->eap_config->identity)
                        DBG("identity [%s]", config->eap_config->identity);
                if (config->eap_config->eap_type)
@@ -1181,6 +1186,11 @@ gboolean handle_load_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex
                else
                        g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY, g_variant_new_string("NONE"));
 
+               if (conf->eap_config->private_key_password != NULL)
+                       g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, g_variant_new_string(conf->eap_config->private_key_password));
+               else
+                       g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, g_variant_new_string("NONE"));
+
                if (conf->eap_config->identity != NULL)
                        g_variant_builder_add(b, "{sv}", WIFI_CONFIG_EAP_IDENTITY, g_variant_new_string(conf->eap_config->identity));
                else
@@ -1294,6 +1304,13 @@ gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex
                        } else {
                                conf->eap_config->private_key = NULL;
                        }
+               } else if (g_strcmp0(field, WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD) == 0) {
+                       if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+                               conf->eap_config->private_key_password = g_strdup(g_variant_get_string(value, NULL));
+                               DBG("private_key_password[%s]", conf->eap_config->private_key_password);
+                       } else {
+                               conf->eap_config->private_key_password = NULL;
+                       }
                } else if (g_strcmp0(field, WIFI_CONFIG_EAP_IDENTITY) == 0) {
                        if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
                                conf->eap_config->identity = g_strdup(g_variant_get_string(value, NULL));
@@ -1383,6 +1400,10 @@ gboolean handle_save_eap_configuration(Wifi *wifi, GDBusMethodInvocation *contex
                g_key_file_set_string(keyfile, group_name,
                        WIFI_CONFIG_EAP_PRIVATEKEY, conf->eap_config->private_key);
 
+       if (conf->eap_config->private_key_password != NULL)
+               g_key_file_set_string(keyfile, group_name,
+                       WIFI_CONFIG_EAP_PRIVATEKEY_PASSWORD, conf->eap_config->private_key_password);
+
        if (conf->eap_config->identity != NULL)
                g_key_file_set_string(keyfile, group_name,
                        WIFI_CONFIG_EAP_IDENTITY, conf->eap_config->identity);