From 2c14e73f8271ec9cd8071667638940006d91934a Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Tue, 17 Sep 2019 13:23:15 -0700 Subject: [PATCH] network: add network_set_passphrase This lets other modules (like WSC) to set a plain text passphrase as opposed to only allowing a PSK to be set. network_get_psk was also updated to generate a PSK on-the-fly if required. Since WPA3 requires the raw passphrase to work, it makes sense to just store the passphrase if we have it. --- src/network.c | 26 ++++++++++++++++++++++++++ src/network.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/network.c b/src/network.c index 2148f0aa..723b166d 100644 --- a/src/network.c +++ b/src/network.c @@ -250,6 +250,18 @@ enum security network_get_security(const struct network *network) const uint8_t *network_get_psk(struct network *network) { + if (network->psk) + return network->psk; + + if (!network->passphrase) + return NULL; + + network->psk = l_malloc(32); + + crypto_psk_from_passphrase(network->passphrase, + (unsigned char *)network->ssid, + strlen(network->ssid), network->psk); + return network->psk; } @@ -258,6 +270,20 @@ const char *network_get_passphrase(const struct network *network) return network->passphrase; } +bool network_set_passphrase(struct network *network, const char *passphrase) +{ + if (network_get_security(network) != SECURITY_PSK) + return false; + + if (!network_settings_load(network)) + network->settings = l_settings_new(); + + network_reset_passphrase(network); + network->passphrase = l_strdup(passphrase); + + return true; +} + struct l_queue *network_get_secrets(const struct network *network) { return network->secrets; diff --git a/src/network.h b/src/network.h index 92ddeb6e..4b569726 100644 --- a/src/network.h +++ b/src/network.h @@ -41,6 +41,7 @@ const char *network_get_path(const struct network *network); enum security network_get_security(const struct network *network); const uint8_t *network_get_psk(struct network *network); const char *network_get_passphrase(const struct network *network); +bool network_set_passphrase(struct network *network, const char *passphrase); 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);