Commit dc373fe016 for strongswan.org
commit dc373fe0164a2625e7cdd329dd9fb8b001ccbe1f
Author: Tobias Brunner <tobias@strongswan.org>
Date: Thu Nov 26 15:52:34 2026 +0100
Use new wipe helpers where appropriate
diff --git a/src/charon-cmd/cmd/cmd_creds.c b/src/charon-cmd/cmd/cmd_creds.c
index 6ad6783a2f..4746e0ebfd 100644
--- a/src/charon-cmd/cmd/cmd_creds.c
+++ b/src/charon-cmd/cmd/cmd_creds.c
@@ -112,7 +112,7 @@ static shared_key_t* callback_shared(private_cmd_creds_t *this,
*match_other = ID_MATCH_PERFECT;
}
shared = shared_key_create(type, chunk_clone(chunk_from_str(pwd)));
- memwipe(pwd, strlen(pwd));
+ strwipe(pwd);
/* cache password in case it is required more than once */
owners = linked_list_create();
if (me)
diff --git a/src/charon-nm/nm/nm_creds.c b/src/charon-nm/nm/nm_creds.c
index 52d5226b05..0c5b0d7713 100644
--- a/src/charon-nm/nm/nm_creds.c
+++ b/src/charon-nm/nm/nm_creds.c
@@ -355,25 +355,13 @@ 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);
- wipe_and_free(this->pass);
+ strwipe_free(this->pass);
this->pass = strdupnull(password);
this->lock->unlock(this->lock);
}
@@ -382,7 +370,7 @@ METHOD(nm_creds_t, set_key_password, void,
private_nm_creds_t *this, char *password)
{
this->lock->write_lock(this->lock);
- wipe_and_free(this->keypass);
+ strwipe_free(this->keypass);
this->keypass = strdupnull(password);
this->lock->unlock(this->lock);
}
@@ -391,7 +379,7 @@ METHOD(nm_creds_t, set_pin, void,
private_nm_creds_t *this, chunk_t keyid, char *pin)
{
this->lock->write_lock(this->lock);
- wipe_and_free(this->keypass);
+ strwipe_free(this->keypass);
free(this->keyid.ptr);
this->keypass = strdupnull(pin);
this->keyid = chunk_clone(keyid);
@@ -420,8 +408,8 @@ METHOD(nm_creds_t, clear, void,
cert->destroy(cert);
}
DESTROY_IF(this->user);
- wipe_and_free(this->pass);
- wipe_and_free(this->keypass);
+ strwipe_free(this->pass);
+ strwipe_free(this->keypass);
free(this->keyid.ptr);
DESTROY_IF(this->usercert);
DESTROY_IF(this->key);
diff --git a/src/libcharon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c b/src/libcharon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
index b4eb2b5fb9..ca66ddb4c5 100644
--- a/src/libcharon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
+++ b/src/libcharon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
@@ -1991,8 +1991,7 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
failed:
memwipe(&request, sizeof(request));
- memwipe(out, len);
- free(out);
+ memwipe_free(out, len);
return status;
}
@@ -2151,8 +2150,7 @@ METHOD(kernel_ipsec_t, update_sa, status_t,
}
#endif /*SADB_X_EXT_NEW_ADDRESS_SRC*/
- memwipe(out, len);
- free(out);
+ memwipe_free(out, len);
out = NULL;
if (pfkey_send(this, msg, &out, &len) != SUCCESS)
@@ -2171,8 +2169,7 @@ METHOD(kernel_ipsec_t, update_sa, status_t,
status = SUCCESS;
failed:
memwipe(&request, sizeof(request));
- memwipe(out, len);
- free(out);
+ memwipe_free(out, len);
return status;
}
@@ -2253,8 +2250,7 @@ METHOD(kernel_ipsec_t, query_sa, status_t,
status = SUCCESS;
failed:
- memwipe(out, len);
- free(out);
+ memwipe_free(out, len);
return status;
}
diff --git a/src/libcharon/plugins/stroke/stroke_config.c b/src/libcharon/plugins/stroke/stroke_config.c
index ebbde9da91..15df0b4d53 100644
--- a/src/libcharon/plugins/stroke/stroke_config.c
+++ b/src/libcharon/plugins/stroke/stroke_config.c
@@ -1361,8 +1361,8 @@ METHOD(stroke_config_t, set_user_credentials, void,
char *pass;
pass = msg->user_creds.password;
- password = chunk_clone(chunk_create(pass, strlen(pass)));
- memwipe(pass, strlen(pass));
+ password = chunk_clone(chunk_from_str(pass));
+ strwipe(pass);
}
else
{ /* prompt the user for the password */
diff --git a/src/libcharon/plugins/vici/vici_message.c b/src/libcharon/plugins/vici/vici_message.c
index 58b1d8fffa..e12df5cb9e 100644
--- a/src/libcharon/plugins/vici/vici_message.c
+++ b/src/libcharon/plugins/vici/vici_message.c
@@ -645,13 +645,6 @@ METHOD(vici_message_t, dump, bool,
return FALSE;
}
-CALLBACK(clear_strings, void,
- char *str)
-{
- memwipe(str, strlen(str));
- free(str);
-}
-
METHOD(vici_message_t, destroy, void,
private_vici_message_t *this)
{
@@ -659,7 +652,7 @@ METHOD(vici_message_t, destroy, void,
{
chunk_clear(&this->encoding);
}
- this->strings->destroy_function(this->strings, clear_strings);
+ this->strings->destroy_function(this->strings, (void*)strwipe_free);
free(this);
}
diff --git a/src/libstrongswan/plugins/aes/aes_crypter.c b/src/libstrongswan/plugins/aes/aes_crypter.c
index 5bb31d5ec0..68b086f0cf 100644
--- a/src/libstrongswan/plugins/aes/aes_crypter.c
+++ b/src/libstrongswan/plugins/aes/aes_crypter.c
@@ -991,8 +991,7 @@ METHOD(crypter_t, set_key, bool,
METHOD(crypter_t, destroy, void,
private_aes_crypter_t *this)
{
- memwipe(this, sizeof(*this));
- free(this);
+ memwipe_free(this, sizeof(*this));
}
/*
diff --git a/src/libstrongswan/plugins/cmac/cmac.c b/src/libstrongswan/plugins/cmac/cmac.c
index b0a779628f..437c8eb5de 100644
--- a/src/libstrongswan/plugins/cmac/cmac.c
+++ b/src/libstrongswan/plugins/cmac/cmac.c
@@ -301,10 +301,8 @@ METHOD(mac_t, destroy, void,
private_mac_t *this)
{
this->k->destroy(this->k);
- memwipe(this->k1, this->b);
- free(this->k1);
- memwipe(this->k2, this->b);
- free(this->k2);
+ memwipe_free(this->k1, this->b);
+ memwipe_free(this->k2, this->b);
free(this->t);
free(this->remaining);
free(this);
diff --git a/src/libstrongswan/plugins/des/des_crypter.c b/src/libstrongswan/plugins/des/des_crypter.c
index 6a564aa13b..10405ff1bf 100644
--- a/src/libstrongswan/plugins/des/des_crypter.c
+++ b/src/libstrongswan/plugins/des/des_crypter.c
@@ -1570,8 +1570,7 @@ METHOD(crypter_t, set_key3, bool,
METHOD(crypter_t, destroy, void,
private_des_crypter_t *this)
{
- memwipe(this, sizeof(*this));
- free(this);
+ memwipe_free(this, sizeof(*this));
}
/*
diff --git a/src/libstrongswan/plugins/mysql/mysql_database.c b/src/libstrongswan/plugins/mysql/mysql_database.c
index 1b0b0be7b9..84ba83ed8d 100644
--- a/src/libstrongswan/plugins/mysql/mysql_database.c
+++ b/src/libstrongswan/plugins/mysql/mysql_database.c
@@ -754,8 +754,7 @@ METHOD(database_t, destroy, void,
this->mutex->destroy(this->mutex);
free(this->host);
free(this->username);
- memwipe(this->password, this->password ? strlen(this->password) : 0);
- free(this->password);
+ strwipe_free(this->password);
free(this->database);
free(this);
}
@@ -800,8 +799,7 @@ static bool parse_uri(private_mysql_database_t *this, char *uri)
this->password = strdup(password);
this->database = strdup(database);
this->port = atoi(port);
- memwipe(username, strlen(uri) - scheme_len);
- free(username);
+ memwipe_free(username, strlen(uri) - scheme_len);
return TRUE;
}
DBG1(DBG_LIB, "parsing MySQL database uri 'mysql://%s:***@%s' "
@@ -818,8 +816,7 @@ static bool parse_uri(private_mysql_database_t *this, char *uri)
DBG1(DBG_LIB, "parsing MySQL database uri of the form "
"'mysql://username:[password]@host[:port]/database' failed");
}
- memwipe(username, strlen(uri) - scheme_len);
- free(username);
+ memwipe_free(username, strlen(uri) - scheme_len);
return FALSE;
}
diff --git a/src/libstrongswan/plugins/openssl/openssl_pkcs12.c b/src/libstrongswan/plugins/openssl/openssl_pkcs12.c
index cba968b91a..2714e546fb 100644
--- a/src/libstrongswan/plugins/openssl/openssl_pkcs12.c
+++ b/src/libstrongswan/plugins/openssl/openssl_pkcs12.c
@@ -175,8 +175,7 @@ static bool decrypt_and_unpack(private_pkcs12_t *this)
{
case PARSE_ERROR:
/* password was incorrect, try another */
- memwipe(password, strlen(password));
- free(password);
+ strwipe_free(password);
continue;
case SUCCESS:
success = TRUE;
@@ -185,8 +184,7 @@ static bool decrypt_and_unpack(private_pkcs12_t *this)
/* password was correct but we were unable to unpack anything */
break;
}
- memwipe(password, strlen(password));
- free(password);
+ strwipe_free(password);
break;
}
enumerator->destroy(enumerator);
diff --git a/src/libstrongswan/plugins/xcbc/xcbc.c b/src/libstrongswan/plugins/xcbc/xcbc.c
index 826b9bd7c8..774ce103a0 100644
--- a/src/libstrongswan/plugins/xcbc/xcbc.c
+++ b/src/libstrongswan/plugins/xcbc/xcbc.c
@@ -279,10 +279,8 @@ METHOD(mac_t, destroy, void,
private_mac_t *this)
{
this->k1->destroy(this->k1);
- memwipe(this->k2, this->b);
- free(this->k2);
- memwipe(this->k3, this->b);
- free(this->k3);
+ memwipe_free(this->k2, this->b);
+ memwipe_free(this->k3, this->b);
free(this->e);
free(this->remaining);
free(this);
diff --git a/src/libstrongswan/settings/settings.c b/src/libstrongswan/settings/settings.c
index afbfe63617..6e7282f522 100644
--- a/src/libstrongswan/settings/settings.c
+++ b/src/libstrongswan/settings/settings.c
@@ -1084,7 +1084,7 @@ CALLBACK(clear_content, void,
{
if (*(bool*)clear)
{
- memwipe(str, strlen(str));
+ strwipe(str);
}
free(str);
}
diff --git a/src/pki/pki.c b/src/pki/pki.c
index c50d44a6af..9e2dcaa3bf 100644
--- a/src/pki/pki.c
+++ b/src/pki/pki.c
@@ -449,7 +449,7 @@ static shared_key_t* cb(void *data, shared_key_type_t type,
*match_other = ID_MATCH_NONE;
}
shared = shared_key_create(type, chunk_clone(chunk_from_str(secret)));
- memwipe(secret, strlen(secret));
+ strwipe(secret);
/* cache password in case it is required more than once */
cb_creds->add_shared(cb_creds, shared, NULL);
return shared->get_ref(shared);
diff --git a/src/stroke/stroke.c b/src/stroke/stroke.c
index 17df73f491..a77c83a843 100644
--- a/src/stroke/stroke.c
+++ b/src/stroke/stroke.c
@@ -130,7 +130,7 @@ static int send_stroke_msg(stroke_msg_t *msg)
if (pass)
{
stream->write_all(stream, pass, strlen(pass));
- memwipe(pass, strlen(pass));
+ strwipe(pass);
stream->write_all(stream, "\n", 1);
}
}
diff --git a/src/swanctl/commands/load_creds.c b/src/swanctl/commands/load_creds.c
index 1feeaa44e9..9405972e6d 100644
--- a/src/swanctl/commands/load_creds.c
+++ b/src/swanctl/commands/load_creds.c
@@ -318,7 +318,7 @@ CALLBACK(password_cb, shared_key_t*,
*match_other = ID_MATCH_PERFECT;
}
shared = shared_key_create(type, chunk_clone(chunk_from_str(pwd)));
- memwipe(pwd, strlen(pwd));
+ strwipe(pwd);
/* cache secret if it is required more than once (PKCS#12) */
data->cache->add_shared(data->cache, shared, NULL);
return shared->get_ref(shared);
@@ -701,7 +701,7 @@ static void load_tokens(load_ctx_t *ctx)
load_token(ctx, section, pin);
if (pin)
{
- memwipe(pin, strlen(pin));
+ strwipe(pin);
pin = NULL;
}
}