From 35278ae108cefa58801b9e313282e1dd91bde6bb Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Tue, 7 Aug 2018 14:29:06 -0700 Subject: [PATCH] network: save passphrase in network SAE needs access to the raw passphrase, not the PSK which network saves. This changes saves the passphrase in network and handshake objects, as well as adds getters to both objects so SAE can retrieve the passphrase. --- src/handshake.c | 7 +++++++ src/handshake.h | 3 +++ src/network.c | 11 +++++++++++ src/network.h | 1 + 4 files changed, 22 insertions(+) diff --git a/src/handshake.c b/src/handshake.c index fe225c94..87cf93db 100644 --- a/src/handshake.c +++ b/src/handshake.c @@ -78,6 +78,7 @@ void handshake_state_free(struct handshake_state *s) l_free(s->own_ie); l_free(s->mde); l_free(s->fte); + l_free(s->passphrase); memset(s, 0, sizeof(*s)); @@ -228,6 +229,12 @@ void handshake_state_set_event_func(struct handshake_state *s, s->user_data = user_data; } +void handshake_state_set_passphrase(struct handshake_state *s, + const char *passphrase) +{ + s->passphrase = l_strdup(passphrase); +} + void handshake_state_new_snonce(struct handshake_state *s) { get_nonce(s->snonce); diff --git a/src/handshake.h b/src/handshake.h index 93c675ec..9bfb636d 100644 --- a/src/handshake.h +++ b/src/handshake.h @@ -102,6 +102,7 @@ struct handshake_state { bool have_anonce : 1; uint8_t ssid[32]; size_t ssid_len; + char *passphrase; uint8_t r0khid[48]; size_t r0khid_len; uint8_t r1khid[6]; @@ -144,6 +145,8 @@ void handshake_state_set_kh_ids(struct handshake_state *s, void handshake_state_set_event_func(struct handshake_state *s, handshake_event_func_t func, void *user_data); +void handshake_state_set_passphrase(struct handshake_state *s, + const char *passphrase); void handshake_state_new_snonce(struct handshake_state *s); void handshake_state_new_anonce(struct handshake_state *s); diff --git a/src/network.c b/src/network.c index ecb5c3a4..aa6d511c 100644 --- a/src/network.c +++ b/src/network.c @@ -51,6 +51,7 @@ struct network { struct device *device; struct network_info *info; unsigned char *psk; + char *passphrase; unsigned int agent_request; struct l_queue *bss_list; struct l_settings *settings; @@ -81,6 +82,9 @@ static void network_settings_close(struct network *network) l_free(network->psk); network->psk = NULL; + l_free(network->passphrase); + network->passphrase = NULL; + l_settings_free(network->settings); network->settings = NULL; } @@ -317,6 +321,11 @@ const uint8_t *network_get_psk(const struct network *network) return network->psk; } +const char *network_get_passphrase(const struct network *network) +{ + return network->passphrase; +} + struct l_queue *network_get_secrets(const struct network *network) { return network->secrets; @@ -625,6 +634,8 @@ static void passphrase_callback(enum agent_result result, l_free(network->psk); network->psk = l_malloc(32); + l_free(network->passphrase); + network->passphrase = l_strdup(passphrase); if (crypto_psk_from_passphrase(passphrase, (uint8_t *) network->info->ssid, diff --git a/src/network.h b/src/network.h index a7cdbff0..88e4dc6d 100644 --- a/src/network.h +++ b/src/network.h @@ -40,6 +40,7 @@ struct device *network_get_device(const struct network *network); const char *network_get_path(const struct network *network); enum security network_get_security(const struct network *network); const uint8_t *network_get_psk(const struct network *network); +const char *network_get_passphrase(const struct network *network); struct l_queue *network_get_secrets(const struct network *network); int network_get_signal_strength(const struct network *network); struct l_settings *network_get_settings(const struct network *network);