From: Seonah Moon Date: Thu, 10 Dec 2015 02:45:27 +0000 (+0900) Subject: Modified get/set passphrase functions X-Git-Tag: accepted/tizen/mobile/20151210.083544~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F53872%2F1;p=platform%2Fcore%2Fapi%2Ftethering.git Modified get/set passphrase functions Change-Id: Ie59bb38d7606c703d8302d35e5e5ade36dc22c0d Signed-off-by: Seonah Moon --- diff --git a/packaging/capi-network-tethering.spec b/packaging/capi-network-tethering.spec index 7a10dd1..5ef0810 100644 --- a/packaging/capi-network-tethering.spec +++ b/packaging/capi-network-tethering.spec @@ -1,6 +1,6 @@ Name: capi-network-tethering Summary: Tethering Framework -Version: 1.0.22 +Version: 1.0.23 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/tethering.c b/src/tethering.c index 8c178ab..9a38d8a 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -95,7 +95,7 @@ static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data); -static void __get_key_manager_alias(char* alias, size_t buff_len); +static char *__get_key_manager_alias(const char* alias); static __tethering_sig_t sigs[] = { {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed}, @@ -257,7 +257,7 @@ static tethering_error_e __set_passphrase(const char *passphrase, const unsigned return TETHERING_ERROR_INVALID_PARAMETER; int ret = -1; - char alias[MAX_ALIAS_LEN] = {0, }; + char *alias; ckmc_raw_buffer_s ckmc_buf; ckmc_policy_s ckmc_policy; @@ -265,23 +265,42 @@ static tethering_error_e __set_passphrase(const char *passphrase, const unsigned ckmc_policy.extractable = true; ckmc_buf.data = (unsigned char *) passphrase; - ckmc_buf.size = strlen(passphrase); + ckmc_buf.size = strlen(passphrase) + 1; + + alias = __get_key_manager_alias(TETHERING_WIFI_PASSPHRASE_STORE_KEY); + + ret = ckmc_remove_data(alias); + if (ret != CKMC_ERROR_NONE) { + ERR("Fail to remove old data : %d", ret); + return TETHERING_ERROR_OPERATION_FAILED; + } - __get_key_manager_alias(alias, sizeof(alias)); ret = ckmc_save_data(alias, ckmc_buf, ckmc_policy); if (ret != CKMC_ERROR_NONE) { - ERR("Fail to save the passphrase : %d\n", ret); + ERR("Fail to save the passphrase : %d", ret); return TETHERING_ERROR_OPERATION_FAILED; } + if (alias) + free(alias); + return TETHERING_ERROR_NONE; } -static void __get_key_manager_alias(char* alias, size_t buff_len) +static char *__get_key_manager_alias(const char* name) { - snprintf(alias, buff_len, "%s%s%s", ckmc_owner_id_system, - ckmc_owner_id_separator, - TETHERING_WIFI_PASSPHRASE_STORE_KEY); + size_t alias_len = strlen(name) + strlen(ckmc_owner_id_system) + strlen(ckmc_owner_id_separator); + char *ckm_alias = (char *)malloc(alias_len + 1); + if (!ckm_alias) { + ERR("Fail to allocate memory\n"); + return NULL; + } + memset(ckm_alias, 0, alias_len); + strncat(ckm_alias, ckmc_owner_id_system, strlen(ckmc_owner_id_system)); + strncat(ckm_alias, ckmc_owner_id_separator, strlen(ckmc_owner_id_separator)); + strncat(ckm_alias, name, strlen(name)); + + return ckm_alias; } static tethering_error_e __get_passphrase(char *passphrase, @@ -293,12 +312,13 @@ static tethering_error_e __get_passphrase(char *passphrase, } int ret = 0; - char tmp[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; - char alias[MAX_ALIAS_LEN] = {0, }; + char *alias = NULL; + char *passwd = NULL; + char tmp[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; ckmc_raw_buffer_s *ckmc_buf; - __get_key_manager_alias(alias, sizeof(alias)); - ret = ckmc_get_data(alias, NULL, &ckmc_buf); + alias = __get_key_manager_alias(TETHERING_WIFI_PASSPHRASE_STORE_KEY); + ret = ckmc_get_data(alias, passwd, &ckmc_buf); if (ret < 0) { DBG("Create new password\n"); ret = __generate_initial_passphrase(tmp, sizeof(tmp)); @@ -320,7 +340,8 @@ static tethering_error_e __get_passphrase(char *passphrase, g_strlcpy(passphrase, (char *)ckmc_buf->data, (*passphrase_len) + 1); } - g_free(alias); + if (alias) + free(alias); return TETHERING_ERROR_NONE; }