commit 2c14e73f8271ec9cd8071667638940006d91934a
parent 8be98d6149101e6ffd04debedcb6ecdcc238cbfe
Author: James Prestwood <prestwoj@gmail.com>
Date: Tue, 17 Sep 2019 13:23:15 -0700
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.
Diffstat:
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git 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
@@ -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);