service: Store agent provided credentials separately
authorHenri Bragge <henri.bragge@ixonos.com>
Thu, 28 Jul 2011 14:20:30 +0000 (17:20 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 29 Jul 2011 16:04:40 +0000 (18:04 +0200)
Add new fields for agent provided identity/passphrase in service struct
(agent_identity/agent_passphrase) and network ("WiFi.AgentIdentity" and
"WiFi.AgentPassphrase").

Preparing these values in prepare_8021x() is left out because the same
thing is done in request_input_cb(), which is where the values always
come from.

src/connman.h
src/network.c
src/service.c

index 681b29f..1dc6e51 100644 (file)
@@ -542,8 +542,12 @@ void __connman_service_set_proxy_autoconfig(struct connman_service *service,
 
 void __connman_service_set_identity(struct connman_service *service,
                                        const char *identity);
+void __connman_service_set_agent_identity(struct connman_service *service,
+                                               const char *agent_identity);
 void __connman_service_set_passphrase(struct connman_service *service,
                                        const char* passphrase);
+void __connman_service_set_agent_passphrase(struct connman_service *service,
+                                               const char *agent_passphrase);
 
 void __connman_service_notify(struct connman_service *service,
                        unsigned int rx_packets, unsigned int tx_packets,
index 41f9188..b2177db 100644 (file)
@@ -63,8 +63,10 @@ struct connman_network {
                unsigned short channel;
                char *security;
                char *passphrase;
+               char *agent_passphrase;
                char *eap;
                char *identity;
+               char *agent_identity;
                char *ca_cert_path;
                char *client_cert_path;
                char *private_key_path;
@@ -317,8 +319,10 @@ static void network_destruct(struct connman_network *network)
        g_free(network->wifi.mode);
        g_free(network->wifi.security);
        g_free(network->wifi.passphrase);
+       g_free(network->wifi.agent_passphrase);
        g_free(network->wifi.eap);
        g_free(network->wifi.identity);
+       g_free(network->wifi.agent_identity);
        g_free(network->wifi.ca_cert_path);
        g_free(network->wifi.client_cert_path);
        g_free(network->wifi.private_key_path);
@@ -1550,12 +1554,18 @@ int connman_network_set_string(struct connman_network *network,
        } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
                g_free(network->wifi.passphrase);
                network->wifi.passphrase = g_strdup(value);
+       } else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE) {
+               g_free(network->wifi.agent_passphrase);
+               network->wifi.agent_passphrase = g_strdup(value);
        } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
                g_free(network->wifi.eap);
                network->wifi.eap = g_strdup(value);
        } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
                g_free(network->wifi.identity);
                network->wifi.identity = g_strdup(value);
+       } else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE) {
+               g_free(network->wifi.agent_identity);
+               network->wifi.agent_identity = g_strdup(value);
        } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
                g_free(network->wifi.ca_cert_path);
                network->wifi.ca_cert_path = g_strdup(value);
@@ -1605,10 +1615,14 @@ const char *connman_network_get_string(struct connman_network *network,
                return network->wifi.security;
        else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
                return network->wifi.passphrase;
+       else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE)
+               return network->wifi.agent_passphrase;
        else if (g_str_equal(key, "WiFi.EAP") == TRUE)
                return network->wifi.eap;
        else if (g_str_equal(key, "WiFi.Identity") == TRUE)
                return network->wifi.identity;
+       else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE)
+               return network->wifi.agent_identity;
        else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
                return network->wifi.ca_cert_path;
        else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
index e1ebec3..2249863 100644 (file)
@@ -75,6 +75,7 @@ struct connman_service {
        unsigned int order;
        char *name;
        char *passphrase;
+       char *agent_passphrase;
        char *profile;
        connman_bool_t roaming;
        connman_bool_t login_required;
@@ -91,6 +92,7 @@ struct connman_service {
        /* 802.1x settings from the config files */
        char *eap;
        char *identity;
+       char *agent_identity;
        char *ca_cert_file;
        char *client_cert_file;
        char *private_key_file;
@@ -2047,6 +2049,18 @@ void __connman_service_set_identity(struct connman_service *service,
                                        service->identity);
 }
 
+void __connman_service_set_agent_identity(struct connman_service *service,
+                                               const char *agent_identity)
+{
+       g_free(service->agent_identity);
+       service->agent_identity = g_strdup(agent_identity);
+
+       if (service->network != NULL)
+               connman_network_set_string(service->network,
+                                       "WiFi.AgentIdentity",
+                                       service->agent_identity);
+}
+
 void __connman_service_set_passphrase(struct connman_service *service,
                                        const char* passphrase)
 {
@@ -2066,6 +2080,18 @@ void __connman_service_set_passphrase(struct connman_service *service,
        __connman_storage_save_service(service);
 }
 
+void __connman_service_set_agent_passphrase(struct connman_service *service,
+                                               const char *agent_passphrase)
+{
+       g_free(service->agent_passphrase);
+       service->agent_passphrase = g_strdup(agent_passphrase);
+
+       if (service->network != NULL)
+               connman_network_set_string(service->network,
+                                       "WiFi.AgentPassphrase",
+                                       service->agent_passphrase);
+}
+
 static DBusMessage *get_properties(DBusConnection *conn,
                                        DBusMessage *msg, void *user_data)
 {
@@ -2725,12 +2751,16 @@ static void request_input_cb (struct connman_service *service,
                return;
 
        if (identity != NULL)
-               __connman_service_set_identity(service, identity);
+               __connman_service_set_agent_identity(service, identity);
 
        if (passphrase != NULL)
-               __connman_service_set_passphrase(service, passphrase);
+               __connman_service_set_agent_passphrase(service, passphrase);
 
        __connman_service_connect(service);
+
+       /* Never cache agent provided credentials */
+       __connman_service_set_agent_identity(service, NULL);
+       __connman_service_set_agent_passphrase(service, NULL);
 }
 
 static DBusMessage *connect_service(DBusConnection *conn,
@@ -2995,9 +3025,11 @@ static void service_free(gpointer user_data)
        g_free(service->profile);
        g_free(service->name);
        g_free(service->passphrase);
+       g_free(service->agent_passphrase);
        g_free(service->identifier);
        g_free(service->eap);
        g_free(service->identity);
+       g_free(service->agent_identity);
        g_free(service->ca_cert_file);
        g_free(service->client_cert_file);
        g_free(service->private_key_file);
@@ -3846,7 +3878,15 @@ static int service_connect(struct connman_service *service)
                        if (g_str_equal(service->eap, "tls") == TRUE)
                                break;
 
-                       if (service->immutable != TRUE)
+                       /*
+                        * Return -ENOKEY if either identity or passphrase is
+                        * missing. Agent provided credentials can be used as
+                        * fallback if needed.
+                        */
+                       if ((service->identity == NULL &&
+                                       service->agent_identity == NULL) ||
+                                       (service->passphrase == NULL &&
+                                       service->agent_passphrase == NULL))
                                return -ENOKEY;
 
                        break;