From 31095d632ae454f9db20ea4c02a89ead98bca9cc Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Wed, 20 Mar 2024 17:21:16 +0900 Subject: [PATCH] Add dbus method for getting wifi passphrase This is the dbus method only for the internal modules with special privileges. Change-Id: I17bc91d9e4b35eea76e9c2245b37ff1121aba87b Signed-off-by: Jaehyun Kim --- include/wifi-key-encryption.h | 1 + interfaces/netconfig-iface-wifi.xml | 1 + resources/etc/dbus-1/system.d/net-config.conf | 1 + src/wifi-config.c | 11 +++++++++-- src/wifi-key-encryption.c | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/wifi-key-encryption.h b/include/wifi-key-encryption.h index 3b60483..064bc76 100755 --- a/include/wifi-key-encryption.h +++ b/include/wifi-key-encryption.h @@ -33,6 +33,7 @@ gboolean handle_decrypt_conf_obj(Wifi *wifi, GDBusMethodInvocation *context, const gchar *enc_c_sign_key, const gchar *enc_net_access_key); gchar* _netconfig_encrypt_passphrase(const gchar *passphrase); +gchar* _netconfig_decrypt_passphrase(const gchar *enc_data); #ifdef __cplusplus } diff --git a/interfaces/netconfig-iface-wifi.xml b/interfaces/netconfig-iface-wifi.xml index ff272d1..85fc86c 100755 --- a/interfaces/netconfig-iface-wifi.xml +++ b/interfaces/netconfig-iface-wifi.xml @@ -125,6 +125,7 @@ + diff --git a/resources/etc/dbus-1/system.d/net-config.conf b/resources/etc/dbus-1/system.d/net-config.conf index f815a38..bbbca1a 100755 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -71,6 +71,7 @@ + diff --git a/src/wifi-config.c b/src/wifi-config.c index a00ba50..99c6903 100755 --- a/src/wifi-config.c +++ b/src/wifi-config.c @@ -654,7 +654,14 @@ static gboolean _get_field(const gchar *interface_name, if (g_strcmp0(key, WIFI_CONFIG_NAME) == 0) { val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_NAME, NULL); } else if (g_strcmp0(key, WIFI_CONFIG_PASSPHRASE) == 0) { - val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL); + gchar *enc_pass = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PASSPHRASE, NULL); + if (enc_pass) { + val = _netconfig_decrypt_passphrase(enc_pass); + g_free(enc_pass); + + if (!val) + ERR("Failed to decrypt the passphrase"); + } } else if (g_strcmp0(key, WIFI_CONFIG_PROXY_SERVER) == 0) { val = g_key_file_get_string(keyfile, group_name, WIFI_CONFIG_PROXY_SERVER, NULL); } else if (g_strcmp0(key, WIFI_CONFIG_HIDDEN) == 0) { @@ -1967,7 +1974,7 @@ gboolean handle_get_config_passphrase(Wifi *wifi, GDBusMethodInvocation *context gboolean ret = FALSE; gchar *passphrase = NULL; - if ((wifi == NULL) || (config_id == NULL)) { + if ((wifi == NULL) || (ifname == NULL) || (config_id == NULL)) { ERR("Invalid parameter"); netconfig_error_invalid_parameter(context); return TRUE; diff --git a/src/wifi-key-encryption.c b/src/wifi-key-encryption.c index 13391d3..33c8f5a 100755 --- a/src/wifi-key-encryption.c +++ b/src/wifi-key-encryption.c @@ -240,7 +240,7 @@ gchar* _netconfig_encrypt_passphrase(const gchar *passphrase) return encrypted_value; } -static gchar* _netconfig_decrypt_passphrase(const gchar *enc_data) +gchar* _netconfig_decrypt_passphrase(const gchar *enc_data) { gchar *ehexstr = NULL; gchar *encrypted_value = NULL; -- 2.34.1