Store SoftAP passphrase to key-manager DB 36/187336/2
authorSeonah Moon <seonah1.moon@samsung.com>
Wed, 22 Aug 2018 05:56:42 +0000 (14:56 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 22 Aug 2018 05:58:14 +0000 (14:58 +0900)
Change-Id: I30a6ab9bc00036c608d1826ac28067a039100392

include/mobileap_wifi.h
include/softap-dbus-interface.xml
src/mobileap.c
src/mobileap_wifi.c

index bfc661a..051dd4c 100644 (file)
@@ -138,6 +138,9 @@ gboolean softap_disable(Softap *obj,
 gboolean softap_reload_settings(Softap *obj,
                GDBusMethodInvocation *context, GVariant *settings);
 
+gboolean softap_get_passphrase(Softap *obj,
+               GDBusMethodInvocation *context);
+
 gboolean softap_set_wps_pin(Softap *obj,
                GDBusMethodInvocation *context, gchar *wps_pin);
 
index fd53f11..0c9b143 100644 (file)
                        <arg type="u" name="result" direction="out"/>
                </method>
 
+               <method name="get_passphrase">
+                       <arg type="s" name="passphrase" direction="out"/>
+                       <arg type="u" name="result" direction="out"/>
+               </method>
+
                <method name="get_station_info">
                <arg type="a(a{sv})" name="station" direction="out"/>
                </method>
index 7d58a4a..cdc040f 100755 (executable)
@@ -541,6 +541,8 @@ static void on_bus_acquired_cb(GDBusConnection *connection, const gchar *name,
                        G_CALLBACK(softap_disable), NULL);
        g_signal_connect(softap_obj, "handle-reload-settings",
                        G_CALLBACK(softap_reload_settings), NULL);
+       g_signal_connect(softap_obj, "handle-get-passphrase",
+                       G_CALLBACK(softap_get_passphrase), NULL);
        g_signal_connect(softap_obj, "handle-get-station-info",
                        G_CALLBACK(softap_get_station_info), NULL);
        g_signal_connect(softap_obj, "handle-set-wps-pin",
index a9028bb..a0df274 100755 (executable)
 #define MOBILE_AP_WIFI_KEY_MAX_LEN     64      /**< Maximum length of wifi key */
 
 #define MOBILE_AP_WIFI_PASSPHRASE_STORE_KEY "tethering_wifi_passphrase"
+#define MOBILE_AP_SOFTAP_PASSPHRASE_STORE_KEY "softap_passphrase"
 
 static mobile_ap_error_code_e __update_softap_settings(softap_settings_t *dst, softap_settings_t *src);
-static mobile_ap_error_code_e __get_passphrase(char *passphrase,
-       unsigned int passphrase_size, unsigned int *passphrase_len);
-static mobile_ap_error_code_e __set_passphrase(const char *passphrase, const unsigned int size);
+static mobile_ap_error_code_e __get_passphrase(const char *key, char *passphrase,
+               unsigned int passphrase_size, unsigned int *passphrase_len);
+static mobile_ap_error_code_e __set_passphrase(const char *key, const char *passphrase,
+               const unsigned int size);
 static char *__get_key_manager_alias(const char* name);
 static int __turn_off_wifi(void *obj);
 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size);
@@ -719,6 +721,10 @@ mobile_ap_error_code_e _enable_soft_ap(Softap *obj, softap_settings_t *settings)
                return ret;
        }
 
+       if (__set_passphrase(MOBILE_AP_SOFTAP_PASSPHRASE_STORE_KEY,
+                               obj_softap_settings.key, strlen(obj_softap_settings.key)) != MOBILE_AP_ERROR_NONE)
+               ERR("__set_passphrase is failed"); //LCOV_EXCL_LINE
+
        if (vconf_set_str(VCONFKEY_SOFTAP_SSID, obj_softap_settings.ssid) < 0)
                ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE
 
@@ -728,9 +734,6 @@ mobile_ap_error_code_e _enable_soft_ap(Softap *obj, softap_settings_t *settings)
        if (vconf_set_int(VCONFKEY_SOFTAP_SECURITY, obj_softap_settings.security_type) < 0)
                ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE
 
-       if (vconf_set_str(VCONFKEY_SOFTAP_KEY, obj_softap_settings.key) < 0)
-               ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE
-
        if (vconf_set_int(VCONFKEY_SOFTAP_CHANNEL, obj_softap_settings.channel) < 0)
                ERR("vconf_set_str is failed"); //LCOV_EXCL_LINE
 
@@ -1212,7 +1215,8 @@ static char *__get_key_manager_alias(const char* name)
        return ckmc_alias;
 }
 
-static mobile_ap_error_code_e __set_passphrase(const char *passphrase, const unsigned int size)
+static mobile_ap_error_code_e __set_passphrase(const char *key,
+               const char *passphrase, const unsigned int size)
 {
        if (passphrase == NULL || size == 0)
                return MOBILE_AP_ERROR_INVALID_PARAM;
@@ -1228,7 +1232,7 @@ static mobile_ap_error_code_e __set_passphrase(const char *passphrase, const uns
        ckmc_buf.data = (unsigned char *) passphrase;
        ckmc_buf.size = strlen(passphrase) + 1;
 
-       alias = __get_key_manager_alias(MOBILE_AP_WIFI_PASSPHRASE_STORE_KEY);
+       alias = __get_key_manager_alias(key);
 
        ret = ckmc_remove_alias(alias);
        if (ret != CKMC_ERROR_NONE && ret != CKMC_ERROR_DB_ALIAS_UNKNOWN) {
@@ -1271,10 +1275,10 @@ static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int
        return index;
 }
 
-static mobile_ap_error_code_e __get_passphrase(char *passphrase,
-               unsigned int passphrase_size, unsigned int *passphrase_len)
+static mobile_ap_error_code_e __get_passphrase(const char *key,
+               char *passphrase, unsigned int passphrase_size, unsigned int *passphrase_len)
 {
-       if (passphrase == NULL || passphrase_size == 0) {
+       if (key == NULL || passphrase == NULL || passphrase_size == 0) {
                ERR("Invalid parameter\n"); //LCOV_EXCL_LINE
                return MOBILE_AP_ERROR_INVALID_PARAM;
        }
@@ -1285,7 +1289,7 @@ static mobile_ap_error_code_e __get_passphrase(char *passphrase,
        char tmp[MOBILE_AP_WIFI_KEY_MAX_LEN + 1] = {0, };
        ckmc_raw_buffer_s *ckmc_buf = NULL;
 
-       alias = __get_key_manager_alias(MOBILE_AP_WIFI_PASSPHRASE_STORE_KEY);
+       alias = __get_key_manager_alias(key);
        ret = ckmc_get_data(alias, passwd, &ckmc_buf);
        if (ret < 0) {
                DBG("Create new password\n");
@@ -1301,7 +1305,7 @@ static mobile_ap_error_code_e __get_passphrase(char *passphrase,
                        *passphrase_len = ret;
                        g_strlcpy(passphrase, tmp, (*passphrase_len)+1);
 
-                       if (__set_passphrase(passphrase, *passphrase_len) != MOBILE_AP_ERROR_NONE) {
+                       if (__set_passphrase(key, passphrase, *passphrase_len) != MOBILE_AP_ERROR_NONE) {
                                DBG("set_passphrase is failed : %s, %d", passphrase, *passphrase_len); //LCOV_EXCL_LINE
                                if (alias)
                                        free(alias);
@@ -1357,7 +1361,8 @@ gboolean tethering_get_wifi_tethering_passphrase(Tethering *obj,
        char passphrase_buf[MOBILE_AP_WIFI_KEY_MAX_LEN + 1] = {0, };
        unsigned int len = 0;
 
-       ret = __get_passphrase(passphrase_buf, sizeof(passphrase_buf), &len);
+       ret = __get_passphrase(MOBILE_AP_WIFI_PASSPHRASE_STORE_KEY,
+                       passphrase_buf, sizeof(passphrase_buf), &len);
        if (ret != MOBILE_AP_ERROR_NONE) {
                ERR("__get_passphrase is failed"); //LCOV_EXCL_LINE
                len = 0;
@@ -1379,13 +1384,15 @@ gboolean tethering_set_wifi_tethering_passphrase(Tethering *obj,
        unsigned int passphrase_len = strlen(passphrase);
        mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
 
-       ret = __get_passphrase(old_passphrase, sizeof(old_passphrase), &old_len);
+       ret = __get_passphrase(MOBILE_AP_WIFI_PASSPHRASE_STORE_KEY,
+                       old_passphrase, sizeof(old_passphrase), &old_len);
        if (ret == MOBILE_AP_ERROR_NONE &&
                        old_len == passphrase_len &&
                        !g_strcmp0(old_passphrase, passphrase))
                goto DONE;
 
-       ret = __set_passphrase(passphrase, passphrase_len);
+       ret = __set_passphrase(MOBILE_AP_WIFI_PASSPHRASE_STORE_KEY,
+                       passphrase, passphrase_len);
 
 DONE:
 #ifndef TIZEN_FEATURE_UNITTEST
@@ -1553,6 +1560,28 @@ DONE:
        return TRUE;
 }
 
+gboolean softap_get_passphrase(Softap *obj,
+               GDBusMethodInvocation *context)
+{
+       mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
+       char passphrase_buf[MOBILE_AP_WIFI_KEY_MAX_LEN + 1] = {0, };
+       unsigned int len = 0;
+
+       ret = __get_passphrase(MOBILE_AP_SOFTAP_PASSPHRASE_STORE_KEY,
+                       passphrase_buf, sizeof(passphrase_buf), &len);
+       if (ret != MOBILE_AP_ERROR_NONE) {
+               ERR("__get_passphrase is failed"); //LCOV_EXCL_LINE
+               len = 0;
+       }
+
+#ifndef TIZEN_FEATURE_UNITTEST
+       softap_complete_get_passphrase(obj, context,
+                       (len > 0 ? passphrase_buf : NULL), ret);
+#endif
+
+       return TRUE;
+}
+
 gboolean softap_set_wps_pin(Softap *obj,
                GDBusMethodInvocation *context, gchar *wps_pin)
 {