Commit 880b5d5160 for strongswan.org
commit 880b5d5160479d4a6f97f17207b9d6f70cdf912b
Author: Gary T. Giesen <ggiesen@giesen.me>
Date: Mon Sep 7 21:11:57 2026 -0400
charon-nm: Wipe secrets before freeing them
The user password and the private key passphrase are freed without being
cleared.
Signed-off-by: Gary T. Giesen <ggiesen@giesen.me>
diff --git a/src/charon-nm/nm/nm_creds.c b/src/charon-nm/nm/nm_creds.c
index fa590e8f3c..52d5226b05 100644
--- a/src/charon-nm/nm/nm_creds.c
+++ b/src/charon-nm/nm/nm_creds.c
@@ -355,13 +355,25 @@ METHOD(nm_creds_t, load_ca_dir, void,
}
}
+/**
+ * Wipe and free a secret string
+ */
+static void wipe_and_free(char *secret)
+{
+ if (secret)
+ {
+ memwipe(secret, strlen(secret));
+ free(secret);
+ }
+}
+
METHOD(nm_creds_t, set_username_password, void,
private_nm_creds_t *this, identification_t *id, char *password)
{
this->lock->write_lock(this->lock);
DESTROY_IF(this->user);
this->user = id->clone(id);
- free(this->pass);
+ wipe_and_free(this->pass);
this->pass = strdupnull(password);
this->lock->unlock(this->lock);
}
@@ -370,7 +382,7 @@ METHOD(nm_creds_t, set_key_password, void,
private_nm_creds_t *this, char *password)
{
this->lock->write_lock(this->lock);
- free(this->keypass);
+ wipe_and_free(this->keypass);
this->keypass = strdupnull(password);
this->lock->unlock(this->lock);
}
@@ -379,7 +391,7 @@ METHOD(nm_creds_t, set_pin, void,
private_nm_creds_t *this, chunk_t keyid, char *pin)
{
this->lock->write_lock(this->lock);
- free(this->keypass);
+ wipe_and_free(this->keypass);
free(this->keyid.ptr);
this->keypass = strdupnull(pin);
this->keyid = chunk_clone(keyid);
@@ -408,8 +420,8 @@ METHOD(nm_creds_t, clear, void,
cert->destroy(cert);
}
DESTROY_IF(this->user);
- free(this->pass);
- free(this->keypass);
+ wipe_and_free(this->pass);
+ wipe_and_free(this->keypass);
free(this->keyid.ptr);
DESTROY_IF(this->usercert);
DESTROY_IF(this->key);