Commit 8b7c4e00ef for strongswan.org

commit 8b7c4e00efc11681e6df5d6b7a8d216c3820dff7
Author: Tobias Brunner <tobias@strongswan.org>
Date:   Fri Nov 13 14:20:41 2026 +0100

    auth-cfg: Add support for ECDSA curve constraints

    Also updates the documentation and matching of prefixes in vici.  Note
    that the documentation for the legacy ipsec.conf is not updated.

diff --git a/src/libcharon/plugins/stroke/stroke_config.c b/src/libcharon/plugins/stroke/stroke_config.c
index b6e700fa9c..ebbde9da91 100644
--- a/src/libcharon/plugins/stroke/stroke_config.c
+++ b/src/libcharon/plugins/stroke/stroke_config.c
@@ -521,10 +521,7 @@ static auth_cfg_t *build_auth_cfg(private_stroke_config_t *this,
 	}

 	/* authentication method (class, actually) */
-	if (strpfx(auth, "ike:") ||
-		strpfx(auth, "pubkey") ||
-		strpfx(auth, "rsa") ||
-		strpfx(auth, "ecdsa"))
+	if (auth_cfg_is_pubkey_prefix(auth))
 	{
 		cfg->add(cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
 		build_crl_policy(cfg, local, msg->add_conn.crl_policy);
diff --git a/src/libcharon/plugins/vici/vici_config.c b/src/libcharon/plugins/vici/vici_config.c
index 41b7c466f3..6a6ce4684c 100644
--- a/src/libcharon/plugins/vici/vici_config.c
+++ b/src/libcharon/plugins/vici/vici_config.c
@@ -1173,10 +1173,7 @@ CALLBACK(parse_auth, bool,
 	{
 		return FALSE;
 	}
-	if (strpfx(buf, "ike:") ||
-		strpfx(buf, "pubkey") ||
-		strpfx(buf, "rsa") ||
-		strpfx(buf, "ecdsa"))
+	if (auth_cfg_is_pubkey_prefix(buf))
 	{
 		cfg->add(cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
 		cfg->add_pubkey_constraints(cfg, buf, TRUE);
diff --git a/src/libstrongswan/credentials/auth_cfg.c b/src/libstrongswan/credentials/auth_cfg.c
index c057b351d7..3952de02e3 100644
--- a/src/libstrongswan/credentials/auth_cfg.c
+++ b/src/libstrongswan/credentials/auth_cfg.c
@@ -53,6 +53,7 @@ ENUM(auth_rule_names, AUTH_RULE_IDENTITY, AUTH_HELPER_AC_CERT,
 	"RULE_GROUP",
 	"RULE_RSA_STRENGTH",
 	"RULE_ECDSA_STRENGTH",
+	"RULE_ECDSA_CURVE",
 	"RULE_SIGNATURE_SCHEME",
 	"RULE_IKE_SIGNATURE_SCHEME",
 	"RULE_CERT_POLICY",
@@ -84,6 +85,7 @@ ENUM(auth_rule_names_lower, AUTH_RULE_IDENTITY, AUTH_HELPER_AC_CERT,
 	"group",
 	"rsa_strength",
 	"ecdsa_strength",
+	"ecdsa_curve",
 	"signature_scheme",
 	"ike_signature_scheme",
 	"cert_policy",
@@ -126,6 +128,7 @@ static inline bool is_multi_value_rule(auth_rule_t type)
 		case AUTH_RULE_CERT_POLICY:
 		case AUTH_RULE_RSA_STRENGTH:
 		case AUTH_RULE_ECDSA_STRENGTH:
+		case AUTH_RULE_ECDSA_CURVE:
 		case AUTH_RULE_SIGNATURE_SCHEME:
 		case AUTH_RULE_IKE_SIGNATURE_SCHEME:
 		case AUTH_HELPER_IM_CERT:
@@ -262,6 +265,7 @@ static void init_entry(entry_t *this, auth_rule_t type, va_list args)
 		case AUTH_RULE_IM_CERT:
 		case AUTH_RULE_SUBJECT_CERT:
 		case AUTH_RULE_CERT_POLICY:
+		case AUTH_RULE_ECDSA_CURVE:
 		case AUTH_RULE_SIGNATURE_SCHEME:
 		case AUTH_RULE_IKE_SIGNATURE_SCHEME:
 		case AUTH_HELPER_IM_CERT:
@@ -337,6 +341,7 @@ static bool entry_equals(entry_t *e1, entry_t *e2)
 			return signature_params_equal(e1->value, e2->value);
 		}
 		case AUTH_RULE_CERT_POLICY:
+		case AUTH_RULE_ECDSA_CURVE:
 		case AUTH_RULE_XAUTH_BACKEND:
 		case AUTH_HELPER_IM_HASH_URL:
 		case AUTH_HELPER_SUBJECT_HASH_URL:
@@ -380,6 +385,7 @@ static void destroy_entry_value(entry_t *entry)
 			break;
 		}
 		case AUTH_RULE_CERT_POLICY:
+		case AUTH_RULE_ECDSA_CURVE:
 		case AUTH_RULE_XAUTH_BACKEND:
 		case AUTH_HELPER_IM_HASH_URL:
 		case AUTH_HELPER_SUBJECT_HASH_URL:
@@ -447,6 +453,7 @@ static void replace(private_auth_cfg_t *this, entry_enumerator_t *enumerator,
 			case AUTH_RULE_IM_CERT:
 			case AUTH_RULE_SUBJECT_CERT:
 			case AUTH_RULE_CERT_POLICY:
+			case AUTH_RULE_ECDSA_CURVE:
 			case AUTH_RULE_SIGNATURE_SCHEME:
 			case AUTH_RULE_IKE_SIGNATURE_SCHEME:
 			case AUTH_HELPER_IM_CERT:
@@ -527,6 +534,7 @@ METHOD(auth_cfg_t, get, void*,
 		case AUTH_RULE_IM_CERT:
 		case AUTH_RULE_SUBJECT_CERT:
 		case AUTH_RULE_CERT_POLICY:
+		case AUTH_RULE_ECDSA_CURVE:
 		case AUTH_RULE_SIGNATURE_SCHEME:
 		case AUTH_RULE_IKE_SIGNATURE_SCHEME:
 		case AUTH_HELPER_IM_CERT:
@@ -589,6 +597,65 @@ static signature_params_t *create_rsa_pss_constraint(char *token)
 	return params;
 }

+/**
+ * Map of known key types.
+ */
+static struct {
+	char *name;
+	key_type_t type;
+	auth_rule_t strength;
+} known_key_types[] = {
+	{ "pubkey",		KEY_ANY,		AUTH_RULE_MAX,				},
+	{ "rsa",		KEY_RSA,		AUTH_RULE_RSA_STRENGTH,		},
+	{ "rsa/pss",	KEY_RSA,		AUTH_RULE_RSA_STRENGTH,		},
+	{ "ecdsa",		KEY_ECDSA,		AUTH_RULE_ECDSA_STRENGTH,	},
+	{ "ed25519",	KEY_ED25519,	AUTH_RULE_MAX,				},
+	{ "ed448",		KEY_ED448,		AUTH_RULE_MAX,				},
+	{ "mldsa44",	KEY_ML_DSA_44,	AUTH_RULE_MAX,				},
+	{ "mldsa65",	KEY_ML_DSA_65,	AUTH_RULE_MAX,				},
+	{ "mldsa87",	KEY_ML_DSA_87,	AUTH_RULE_MAX,				},
+};
+
+/**
+ * Determine the key type and optional strength rule for the given token.
+ * Optionally, match as prefix.
+ */
+static bool is_known_key_type(const char *str, bool prefix, key_type_t *type,
+							  auth_rule_t *strength)
+{
+	int i;
+
+	if (strpfx(str, "ike:"))
+	{
+		str += 4;
+	}
+	for (i = 0; i < countof(known_key_types); i++)
+	{
+		if ((prefix && strpfx(str, known_key_types[i].name)) ||
+			(!prefix && streq(str, known_key_types[i].name)))
+		{
+			if (type)
+			{
+				*type = known_key_types[i].type;
+			}
+			if (strength)
+			{
+				*strength = known_key_types[i].strength;
+			}
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+/*
+ * Described in header
+ */
+bool auth_cfg_is_pubkey_prefix(const char *str)
+{
+	return is_known_key_type(str, TRUE, NULL, NULL);
+}
+
 METHOD(auth_cfg_t, add_pubkey_constraints, void,
 	private_auth_cfg_t *this, char* constraints, bool ike)
 {
@@ -636,78 +703,45 @@ METHOD(auth_cfg_t, add_pubkey_constraints, void,
 		};

 		if (expected_strength != AUTH_RULE_MAX)
-		{	/* expecting a key strength token */
-			strength = atoi(token);
-			if (strength)
+		{	/* expecting a key strength token, but not a dotted OID */
+			if (!strchr(token, '.'))
 			{
-				add(this, expected_strength, (uintptr_t)strength);
+				strength = atoi(token);
+				if (strength)
+				{
+					add(this, expected_strength, (uintptr_t)strength);
+					expected_strength = AUTH_RULE_MAX;
+					continue;
+				}
 			}
 			expected_strength = AUTH_RULE_MAX;
-			if (strength)
-			{
-				continue;
-			}
-		}
-		if (streq(token, "rsa") || streq(token, "ike:rsa"))
-		{
-			key_token = token;
-			expected_type = KEY_RSA;
-			expected_strength = AUTH_RULE_RSA_STRENGTH;
-			continue;
-		}
-		if (streq(token, "rsa/pss") || streq(token, "ike:rsa/pss"))
-		{
-			key_token = token;
-			expected_type = KEY_RSA;
-			expected_strength = AUTH_RULE_RSA_STRENGTH;
-			continue;
-		}
-		if (streq(token, "ecdsa") || streq(token, "ike:ecdsa"))
-		{
-			key_token = token;
-			expected_type = KEY_ECDSA;
-			expected_strength = AUTH_RULE_ECDSA_STRENGTH;
-			continue;
-		}
-		if (streq(token, "ed25519") || streq(token, "ike:ed25519"))
-		{
-			key_token = token;
-			expected_type = KEY_ED25519;
-			continue;
-		}
-		if (streq(token, "ed448") || streq(token, "ike:ed448"))
-		{
-			key_token = token;
-			expected_type = KEY_ED448;
-			continue;
 		}
-		if (streq(token, "mldsa44") || streq(token, "ike:mldsa44"))
+		if (is_known_key_type(token, FALSE, &expected_type, &expected_strength))
 		{
 			key_token = token;
-			expected_type = KEY_ML_DSA_44;
 			continue;
 		}
-		if (streq(token, "mldsa65") || streq(token, "ike:mldsa65"))
-		{
-			key_token = token;
-			expected_type = KEY_ML_DSA_65;
-			continue;
-		}
-		if (streq(token, "mldsa87") || streq(token, "ike:mldsa87"))
-		{
-			key_token = token;
-			expected_type = KEY_ML_DSA_87;
-			continue;
-		}
-		if (streq(token, "pubkey") || streq(token, "ike:pubkey"))
+		if (key_token && strpfx(key_token, "ike:") && !ike)
 		{
-			key_token = token;
-			expected_type = KEY_ANY;
 			continue;
 		}
-		if (key_token && strpfx(key_token, "ike:") && !ike)
+
+		if (expected_type == KEY_ECDSA)
 		{
-			continue;
+			chunk_t curve;
+
+			curve = ecdsa_curve_from_string(token);
+			if (curve.len)
+			{
+				char *name = ecdsa_curve_to_string(curve);
+
+				chunk_free(&curve);
+				if (name)
+				{
+					add(this, AUTH_RULE_ECDSA_CURVE, name);
+					continue;
+				}
+			}
 		}

 		if (key_token && streq(key_token + strlen(key_token) - 3, "pss"))
@@ -801,6 +835,66 @@ METHOD(auth_cfg_t, add_pubkey_constraints, void,
 	}
 }

+/**
+ * Check if ECDSA curves are compliant
+ */
+static bool complies_curve(private_auth_cfg_t *this, auth_cfg_t *constraints,
+						   bool log_error)
+{
+	enumerator_t *e1, *e2;
+	auth_rule_t t1, t2;
+	char *curve, *allowed;
+	int ecdsa = 0, curves = 0;
+	bool success = TRUE;
+
+	e2 = create_enumerator(this);
+	while (e2->enumerate(e2, &t2, &curve))
+	{
+		if (t2 == AUTH_RULE_ECDSA_STRENGTH)
+		{	/* at least one cert used ECDSA, keep track in case we have no
+			 * information about the curves */
+			ecdsa++;
+			continue;
+		}
+		if (t2 != AUTH_RULE_ECDSA_CURVE)
+		{
+			continue;
+		}
+		curves++;
+		success = FALSE;
+		e1 = constraints->create_enumerator(constraints);
+		while (e1->enumerate(e1, &t1, &allowed))
+		{
+			if (t1 == t2 && streq(curve, allowed))
+			{
+				success = TRUE;
+				break;
+			}
+		}
+		e1->destroy(e1);
+		if (!success)
+		{
+			if (log_error)
+			{
+				DBG1(DBG_CFG, "ECDSA curve %s not acceptable", curve);
+			}
+			break;
+		}
+	}
+	e2->destroy(e2);
+
+	if (success && ecdsa > curves)
+	{
+		success = FALSE;
+		if (log_error)
+		{
+			DBG1(DBG_CFG, "unable to determine ECDSA curve for %d keys",
+				 ecdsa - curves);
+		}
+	}
+	return success;
+}
+
 /**
  * Check if signature schemes of a specific type are compliant
  */
@@ -850,7 +944,7 @@ METHOD(auth_cfg_t, complies, bool,
 {
 	enumerator_t *e1, *e2;
 	bool success = TRUE, group_match = FALSE;
-	bool ca_match = FALSE, cert_match = FALSE;
+	bool ca_match = FALSE, cert_match = FALSE, curves = FALSE;
 	identification_t *require_group = NULL, *require_ca = NULL;
 	certificate_t *require_cert = NULL;
 	signature_params_t *ike_scheme = NULL, *scheme = NULL;
@@ -1102,6 +1196,11 @@ METHOD(auth_cfg_t, complies, bool,
 				scheme = value;
 				break;
 			}
+			case AUTH_RULE_ECDSA_CURVE:
+			{
+				curves = TRUE;
+				break;
+			}
 			case AUTH_RULE_CERT_POLICY:
 			{
 				char *oid1, *oid2;
@@ -1159,6 +1258,10 @@ METHOD(auth_cfg_t, complies, bool,
 		success = complies_scheme(this, constraints,
 								  AUTH_RULE_IKE_SIGNATURE_SCHEME, log_error);
 	}
+	if (success && curves)
+	{
+		success = complies_curve(this, constraints, log_error);
+	}

 	/* Check if we have a matching constraint (or none at all) for used
 	 * public key strength */
@@ -1236,6 +1339,65 @@ METHOD(auth_cfg_t, complies, bool,
 	return success;
 }

+/**
+ * Clone the given value according to the type
+ */
+static void *clone_value(auth_rule_t type, void *value)
+{
+	switch (type)
+	{
+		case AUTH_RULE_IDENTITY:
+		case AUTH_RULE_CA_IDENTITY:
+		case AUTH_RULE_EAP_IDENTITY:
+		case AUTH_RULE_AAA_IDENTITY:
+		case AUTH_RULE_GROUP:
+		case AUTH_RULE_XAUTH_IDENTITY:
+		{
+			identification_t *id = (identification_t*)value;
+			return id->clone(id);
+		}
+		case AUTH_RULE_CA_CERT:
+		case AUTH_RULE_IM_CERT:
+		case AUTH_RULE_SUBJECT_CERT:
+		case AUTH_HELPER_IM_CERT:
+		case AUTH_HELPER_SUBJECT_CERT:
+		case AUTH_HELPER_REVOCATION_CERT:
+		case AUTH_HELPER_AC_CERT:
+		{
+			certificate_t *cert = (certificate_t*)value;
+			return cert->get_ref(cert);
+		}
+		case AUTH_RULE_SIGNATURE_SCHEME:
+		case AUTH_RULE_IKE_SIGNATURE_SCHEME:
+		{
+			return signature_params_clone(value);
+		}
+		case AUTH_RULE_XAUTH_BACKEND:
+		case AUTH_RULE_CERT_POLICY:
+		case AUTH_RULE_ECDSA_CURVE:
+		case AUTH_HELPER_IM_HASH_URL:
+		case AUTH_HELPER_SUBJECT_HASH_URL:
+		{
+			return strdup((char*)value);
+		}
+		case AUTH_RULE_IDENTITY_LOOSE:
+		case AUTH_RULE_AUTH_CLASS:
+		case AUTH_RULE_EAP_TYPE:
+		case AUTH_RULE_EAP_VENDOR:
+		case AUTH_RULE_CRL_VALIDATION:
+		case AUTH_RULE_OCSP_VALIDATION:
+		case AUTH_RULE_RSA_STRENGTH:
+		case AUTH_RULE_ECDSA_STRENGTH:
+		case AUTH_RULE_CERT_VALIDATION_SUSPENDED:
+		{
+			return value;
+		}
+		case AUTH_RULE_MAX:
+			break;
+	}
+	return NULL;
+}
+
 /**
  * Implementation of auth_cfg_t.merge.
  */
@@ -1255,8 +1417,15 @@ static void merge(private_auth_cfg_t *this, private_auth_cfg_t *other, bool copy
 		enumerator = create_enumerator(other);
 		while (enumerator->enumerate(enumerator, &type, &value))
 		{
+			value = clone_value(type, value);
 			switch (type)
 			{
+				case AUTH_RULE_IDENTITY:
+				case AUTH_RULE_CA_IDENTITY:
+				case AUTH_RULE_EAP_IDENTITY:
+				case AUTH_RULE_AAA_IDENTITY:
+				case AUTH_RULE_GROUP:
+				case AUTH_RULE_XAUTH_IDENTITY:
 				case AUTH_RULE_CA_CERT:
 				case AUTH_RULE_IM_CERT:
 				case AUTH_RULE_SUBJECT_CERT:
@@ -1264,51 +1433,26 @@ static void merge(private_auth_cfg_t *this, private_auth_cfg_t *other, bool copy
 				case AUTH_HELPER_SUBJECT_CERT:
 				case AUTH_HELPER_REVOCATION_CERT:
 				case AUTH_HELPER_AC_CERT:
-				{
-					certificate_t *cert = (certificate_t*)value;
-
-					add(this, type, cert->get_ref(cert));
+				case AUTH_RULE_SIGNATURE_SCHEME:
+				case AUTH_RULE_IKE_SIGNATURE_SCHEME:
+				case AUTH_RULE_XAUTH_BACKEND:
+				case AUTH_RULE_CERT_POLICY:
+				case AUTH_RULE_ECDSA_CURVE:
+				case AUTH_HELPER_IM_HASH_URL:
+				case AUTH_HELPER_SUBJECT_HASH_URL:
+					add(this, type, value);
 					break;
-				}
 				case AUTH_RULE_IDENTITY_LOOSE:
-				case AUTH_RULE_CRL_VALIDATION:
-				case AUTH_RULE_OCSP_VALIDATION:
 				case AUTH_RULE_AUTH_CLASS:
 				case AUTH_RULE_EAP_TYPE:
 				case AUTH_RULE_EAP_VENDOR:
+				case AUTH_RULE_CRL_VALIDATION:
+				case AUTH_RULE_OCSP_VALIDATION:
 				case AUTH_RULE_RSA_STRENGTH:
 				case AUTH_RULE_ECDSA_STRENGTH:
 				case AUTH_RULE_CERT_VALIDATION_SUSPENDED:
-				{
 					add(this, type, (uintptr_t)value);
 					break;
-				}
-				case AUTH_RULE_IDENTITY:
-				case AUTH_RULE_CA_IDENTITY:
-				case AUTH_RULE_EAP_IDENTITY:
-				case AUTH_RULE_AAA_IDENTITY:
-				case AUTH_RULE_GROUP:
-				case AUTH_RULE_XAUTH_IDENTITY:
-				{
-					identification_t *id = (identification_t*)value;
-
-					add(this, type, id->clone(id));
-					break;
-				}
-				case AUTH_RULE_SIGNATURE_SCHEME:
-				case AUTH_RULE_IKE_SIGNATURE_SCHEME:
-				{
-					add(this, type, signature_params_clone(value));
-					break;
-				}
-				case AUTH_RULE_XAUTH_BACKEND:
-				case AUTH_RULE_CERT_POLICY:
-				case AUTH_HELPER_IM_HASH_URL:
-				case AUTH_HELPER_SUBJECT_HASH_URL:
-				{
-					add(this, type, strdup((char*)value));
-					break;
-				}
 				case AUTH_RULE_MAX:
 					break;
 			}
@@ -1414,6 +1558,7 @@ METHOD(auth_cfg_t, clone_, auth_cfg_t*,
 	enumerator = create_enumerator(this);
 	while (enumerator->enumerate(enumerator, &type, &value))
 	{
+		value = clone_value(type, value);
 		switch (type)
 		{
 			case AUTH_RULE_IDENTITY:
@@ -1422,11 +1567,6 @@ METHOD(auth_cfg_t, clone_, auth_cfg_t*,
 			case AUTH_RULE_AAA_IDENTITY:
 			case AUTH_RULE_GROUP:
 			case AUTH_RULE_XAUTH_IDENTITY:
-			{
-				identification_t *id = (identification_t*)value;
-				clone->add(clone, type, id->clone(id));
-				break;
-			}
 			case AUTH_RULE_CA_CERT:
 			case AUTH_RULE_IM_CERT:
 			case AUTH_RULE_SUBJECT_CERT:
@@ -1434,19 +1574,15 @@ METHOD(auth_cfg_t, clone_, auth_cfg_t*,
 			case AUTH_HELPER_SUBJECT_CERT:
 			case AUTH_HELPER_REVOCATION_CERT:
 			case AUTH_HELPER_AC_CERT:
-			{
-				certificate_t *cert = (certificate_t*)value;
-				clone->add(clone, type, cert->get_ref(cert));
-				break;
-			}
+			case AUTH_RULE_SIGNATURE_SCHEME:
+			case AUTH_RULE_IKE_SIGNATURE_SCHEME:
 			case AUTH_RULE_XAUTH_BACKEND:
 			case AUTH_RULE_CERT_POLICY:
+			case AUTH_RULE_ECDSA_CURVE:
 			case AUTH_HELPER_IM_HASH_URL:
 			case AUTH_HELPER_SUBJECT_HASH_URL:
-			{
-				clone->add(clone, type, strdup(value));
+				clone->add(clone, type, value);
 				break;
-			}
 			case AUTH_RULE_IDENTITY_LOOSE:
 			case AUTH_RULE_AUTH_CLASS:
 			case AUTH_RULE_EAP_TYPE:
@@ -1458,12 +1594,6 @@ METHOD(auth_cfg_t, clone_, auth_cfg_t*,
 			case AUTH_RULE_CERT_VALIDATION_SUSPENDED:
 				clone->add(clone, type, (uintptr_t)value);
 				break;
-			case AUTH_RULE_SIGNATURE_SCHEME:
-			case AUTH_RULE_IKE_SIGNATURE_SCHEME:
-			{
-				clone->add(clone, type, signature_params_clone(value));
-				break;
-			}
 			case AUTH_RULE_MAX:
 				break;
 		}
diff --git a/src/libstrongswan/credentials/auth_cfg.h b/src/libstrongswan/credentials/auth_cfg.h
index bb15453474..7384a05adc 100644
--- a/src/libstrongswan/credentials/auth_cfg.h
+++ b/src/libstrongswan/credentials/auth_cfg.h
@@ -107,6 +107,8 @@ enum auth_rule_t {
 	AUTH_RULE_RSA_STRENGTH,
 	/** required ECDSA public key strength, u_int in bits */
 	AUTH_RULE_ECDSA_STRENGTH,
+	/** required ECDSA curve, name/OID (via ecdsa_curve_to_string()) as char* */
+	AUTH_RULE_ECDSA_CURVE,
 	/** required signature scheme, signature_params_t* */
 	AUTH_RULE_SIGNATURE_SCHEME,
 	/** required signature scheme for IKE authentication, signature_params_t* */
@@ -282,4 +284,12 @@ struct auth_cfg_t {
  */
 auth_cfg_t *auth_cfg_create();

+/**
+ * Check if the given string starts with a known public key constraint prefix.
+ *
+ * @param str			string to check
+ * @return				TRUE if prefix matched
+ */
+bool auth_cfg_is_pubkey_prefix(const char *str);
+
 #endif /** AUTH_CFG_H_ @}*/
diff --git a/src/libstrongswan/credentials/credential_manager.c b/src/libstrongswan/credentials/credential_manager.c
index 0e4adf7ac2..a49b8c9619 100644
--- a/src/libstrongswan/credentials/credential_manager.c
+++ b/src/libstrongswan/credentials/credential_manager.c
@@ -708,6 +708,25 @@ static certificate_t *get_issuer_cert(private_credential_manager_t *this,
 	return issuer;
 }

+/**
+ * Get the ECDSA curve from the given public key, add it to auth
+ */
+static void get_ecdsa_curve(public_key_t *key, auth_cfg_t *auth)
+{
+	chunk_t curve;
+	char *name;
+
+	if (key->get_encoding(key, PUBKEY_ECDSA_CURVE_DER, &curve))
+	{
+		name = ecdsa_curve_to_string(curve);
+		if (name)
+		{
+			auth->add(auth, AUTH_RULE_ECDSA_CURVE, name);
+		}
+		chunk_free(&curve);
+	}
+}
+
 /**
  * Get the strength of certificate, add it to auth
  */
@@ -731,6 +750,7 @@ static void get_key_strength(certificate_t *cert, auth_cfg_t *auth)
 				break;
 			case KEY_ECDSA:
 				auth->add(auth, AUTH_RULE_ECDSA_STRENGTH, strength);
+				get_ecdsa_curve(key, auth);
 				break;
 			default:
 				break;
diff --git a/src/libstrongswan/tests/suites/test_asn1.c b/src/libstrongswan/tests/suites/test_asn1.c
index 58d99cdd56..85f196d923 100644
--- a/src/libstrongswan/tests/suites/test_asn1.c
+++ b/src/libstrongswan/tests/suites/test_asn1.c
@@ -181,6 +181,8 @@ START_TEST(test_asn1_oid_from_string)
 	testdata_t test[] = {
 		{ "",  chunk_empty },
 		{ " ", chunk_empty },
+		{ ".", chunk_empty },
+		{ "0", chunk_empty },
 		{ "0.2.262.1", chunk_from_chars(
 			0x02, 0x82, 0x06, 0x01) },
 		{ "1.2.840.10045.4.1", chunk_from_chars(
diff --git a/src/libstrongswan/tests/suites/test_auth_cfg.c b/src/libstrongswan/tests/suites/test_auth_cfg.c
index 78c5d1d496..667d50f880 100644
--- a/src/libstrongswan/tests/suites/test_auth_cfg.c
+++ b/src/libstrongswan/tests/suites/test_auth_cfg.c
@@ -203,6 +203,136 @@ START_TEST(test_sig_constraints_rsa_pss)
 }
 END_TEST

+struct {
+	char *constraints;
+	char *curves[3];
+} curve_constraints_tests[] = {
+	{ "ecdsa-p256", { "prime256v1" }},
+	{ "ecdsa-bp384", { "brainpoolP384r1" }},
+	{ "ecdsa-brainpoolP256r1", { "brainpoolP256r1" }},
+	{ "ecdsa-1.3.36.3.3.2.8.1.1.7", { "brainpoolP256r1" }},
+	{ "ecdsa-1.3.6.1.4.1.36906.15", { "1.3.6.1.4.1.36906.15" }},
+	{ "ecdsa-p256-bp384", { "prime256v1", "brainpoolP384r1" }},
+	{ "ecdsa-384-brainpoolP384r1-sha384", { "brainpoolP384r1" }},
+	{ "pubkey-p256", {}},
+	{ "rsa-p256", {}},
+};
+
+static void check_curve_constraints(auth_cfg_t *cfg, char *curves[])
+{
+	enumerator_t *enumerator;
+	auth_rule_t t;
+	char *value;
+	int i = 0;
+
+	enumerator = cfg->create_enumerator(cfg);
+	while (enumerator->enumerate(enumerator, &t, &value))
+	{
+		if (t == AUTH_RULE_ECDSA_CURVE)
+		{
+			ck_assert_str_eq(curves[i], value);
+			i++;
+		}
+	}
+	enumerator->destroy(enumerator);
+	ck_assert(!curves[i]);
+}
+
+START_TEST(test_curve_constraints)
+{
+	auth_cfg_t *cfg;
+
+	cfg = auth_cfg_create();
+	cfg->add_pubkey_constraints(cfg, curve_constraints_tests[_i].constraints, TRUE);
+	check_curve_constraints(cfg, curve_constraints_tests[_i].curves);
+	cfg->destroy(cfg);
+}
+END_TEST
+
+struct {
+	bool compliant;
+	char *constraints;
+	struct {
+		auth_rule_t type;
+		void *value;
+	} rules[5];
+} complies_curves_tests[] = {
+	{ TRUE, "ecdsa-p256", {}},
+	{ TRUE, "rsa-2048-ecdsa-p256", {}},
+	{ FALSE, "ecdsa-p256", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 }, }},
+	{ TRUE, "ecdsa-256", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 }, }},
+	{ TRUE, "ecdsa-256", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 },
+		{ AUTH_RULE_ECDSA_CURVE, "prime256v1" }, }},
+	{ TRUE, "ecdsa-p256", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 },
+		{ AUTH_RULE_ECDSA_CURVE, "prime256v1" }, }},
+	{ TRUE, "ecdsa-256-p256", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 },
+		{ AUTH_RULE_ECDSA_CURVE, "prime256v1" }, }},
+	{ FALSE, "ecdsa-p384", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 },
+		{ AUTH_RULE_ECDSA_CURVE, "prime256v1" }, }},
+	{ TRUE, "ecdsa-p256-p384", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 },
+		{ AUTH_RULE_ECDSA_CURVE, "prime256v1" }, }},
+	{ TRUE, "ecdsa-p256-p384", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)384 },
+		{ AUTH_RULE_ECDSA_CURVE, "secp384r1" }, }},
+	{ TRUE, "ecdsa-p256-p384", {
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)384 },
+		{ AUTH_RULE_ECDSA_CURVE, "secp384r1" },
+		{ AUTH_RULE_ECDSA_STRENGTH, (void*)(uintptr_t)256 },
+		{ AUTH_RULE_ECDSA_CURVE, "prime256v1" }, }},
+};
+
+/**
+ * Add a test rule to the given config
+ */
+static void add_rule(auth_cfg_t *cfg, auth_rule_t type, void *value)
+{
+	switch (type)
+	{
+		case AUTH_RULE_ECDSA_STRENGTH:
+			cfg->add(cfg, type, (uintptr_t)value);
+			break;
+		case AUTH_RULE_ECDSA_CURVE:
+			cfg->add(cfg, type, strdup(value));
+			break;
+		default:
+			fail("unsupported rule type %N", auth_rule_names, type);
+	}
+}
+
+START_TEST(test_complies_curves)
+{
+	auth_cfg_t *constraints, *cfg;
+	int i;
+
+	constraints = auth_cfg_create();
+	constraints->add_pubkey_constraints(constraints,
+										complies_curves_tests[_i].constraints,
+										TRUE);
+
+	cfg = auth_cfg_create();
+	for (i = 0; i < countof(complies_curves_tests[_i].rules); i++)
+	{
+		if (!complies_curves_tests[_i].rules[i].value)
+		{
+			break;
+		}
+		add_rule(cfg, complies_curves_tests[_i].rules[i].type,
+				 complies_curves_tests[_i].rules[i].value);
+	}
+	ck_assert(complies_curves_tests[_i].compliant ==
+				cfg->complies(cfg, constraints, TRUE));
+	cfg->destroy(cfg);
+	constraints->destroy(constraints);
+}
+END_TEST
+
 Suite *auth_cfg_suite_create()
 {
 	Suite *s;
@@ -220,5 +350,13 @@ Suite *auth_cfg_suite_create()
 	tcase_add_loop_test(tc, test_sig_constraints_rsa_pss, 0, countof(sig_constraints_rsa_pss_tests));
 	suite_add_tcase(s, tc);

+	tc = tcase_create("add_pubkey_constraints curves");
+	tcase_add_loop_test(tc, test_curve_constraints, 0, countof(curve_constraints_tests));
+	suite_add_tcase(s, tc);
+
+	tc = tcase_create("complies");
+	tcase_add_loop_test(tc, test_complies_curves, 0, countof(complies_curves_tests));
+	suite_add_tcase(s, tc);
+
 	return s;
 }
diff --git a/src/swanctl/swanctl.opt b/src/swanctl/swanctl.opt
index a397203d87..e092af1596 100644
--- a/src/swanctl/swanctl.opt
+++ b/src/swanctl/swanctl.opt
@@ -457,9 +457,9 @@ connections.<conn>.local<suffix>.auth = pubkey
 	For example, with _ike:pubkey-sha384-sha256_ a public key signature scheme
 	with either SHA-384 or SHA-256 would get used for authentication, in that
 	order and depending on the hash algorithms supported by the peer. If no
-	specific hash algorithms are configured, the default is to prefer an
+	specific schemes are configured this way, the default is to prefer an
 	algorithm that matches or exceeds the strength of the signature key.
-	If no constraints with _ike:_ prefix are configured any signature scheme
+	If no constraints with _ike:_ prefix are configured, any signature scheme
 	constraint (without _ike:_ prefix) will also apply to IKEv2 authentication,
 	unless this is disabled in **strongswan.conf**(5). To use RSASSA-PSS
 	signatures use _rsa/pss_ instead of _pubkey_ or _rsa_ as in e.g.
@@ -686,21 +686,34 @@ connections.<conn>.remote<suffix>.auth = pubkey
 	Authentication to expect from remote. See the **local** section's **auth**
 	keyword description about the details of supported mechanisms.

-	To require a trustchain public key strength for the remote side, specify the
-	key type followed by the minimum strength in bits (for example _ecdsa-384_
-	or _rsa-2048-ecdsa-256_). To limit the acceptable set of hashing algorithms
-	for trustchain validation, append hash algorithms to _pubkey_ or a key
-	strength definition (for example _pubkey-sha256-sha512_,
-	_rsa-2048-sha256-sha384-sha512_ or
-	_rsa-2048-sha256-ecdsa-256-sha256-sha384_).
+	To require specific signature schemes in the trustchain for the remote side,
+	specify the key type followed by one or more accepted hash algorithms (e.g.
+	_pubkey-sha256-sha512_ or _ecdsa-sha384_). For EdDSA and ML-DSA use
+	_identity_ as hash algorithm (e.g. _ed25519-identity_ or
+	_mldsa87-identity_). To require a specific public key strength for RSA or
+	ECDSA, specify the key type followed by the minimum strength in bits (e.g.
+	_ecdsa-384_ or _rsa-3072-ecdsa-384_). Note that this does not enforce the
+	key type/signature scheme if no hash is specified after the strength.
+	To restrict the elliptic curves accepted for ECDSA public keys in the
+	trustchain, append one or more curve names or OIDs to an _ecdsa_ key type
+	(for example _ecdsa-p256-sha256_, _ecdsa-1.3.36.3.3.2.8.1.1.11-sha384_ or
+	_ecdsa-p384-brainpoolP384r1-sha384_). Again, without hash algorithm, this
+	does not enforce the signature scheme (i.e. curves will only be enforced if
+	ECDSA was used in the trustchain). Multiple curves may be specified as
+	alternatives. Names are matched case-insensitive and support the aliases
+	documented for _pki --gen_. However, hyphenated aliases like _p-256_ cannot
+	be used here because dashes separate constraints.
+
 	Unless disabled in **strongswan.conf**(5), or explicit IKEv2 signature
 	constraints are configured (refer to the description of the **local**
-	section's **auth** keyword for details), such key types and hash algorithms
-	are also applied as constraints against IKEv2 signature authentication
-	schemes used by the remote side. To require RSASSA-PSS signatures use
-	_rsa/pss_ instead of _pubkey_ or _rsa_ as in e.g. _rsa/pss-sha256_. If
-	_pubkey_ or _rsa_ constraints are configured RSASSA-PSS signatures will only
-	be accepted if enabled in **strongswan.conf**(5).
+	section's **auth** keyword for details), such signature schemes are also
+	applied as constraints against IKEv2 signature authentication schemes used
+	by the remote side.
+
+	To require RSASSA-PSS signatures use _rsa/pss_ instead of _pubkey_ or _rsa_
+	as in e.g. _rsa/pss-sha256_. If _pubkey_ or _rsa_ constraints are configured
+	RSASSA-PSS signatures will only be accepted if enabled in
+	**strongswan.conf**(5).

 	To specify trust chain constraints for EAP-(T)TLS, append a colon to the
 	EAP method, followed by the key type/size and hash algorithm as discussed