Commit 62c4813afd for strongswan.org

commit 62c4813afd3eb4764280565d744e2377a0761cb5
Author: Tobias Brunner <tobias@strongswan.org>
Date:   Thu Mar 12 18:36:22 2026 +0100

    pkcs1: Support encoding/extracting the curve from an ECDSA public key

    This is helpful with plugins for which we can't determine or encode the
    curve otherwise (e.g. Botan currently doesn't provide an interface to
    get the curve from a public key).

diff --git a/src/libstrongswan/plugins/pkcs1/pkcs1_encoder.c b/src/libstrongswan/plugins/pkcs1/pkcs1_encoder.c
index a205ebc2e8..b578d11ef8 100644
--- a/src/libstrongswan/plugins/pkcs1/pkcs1_encoder.c
+++ b/src/libstrongswan/plugins/pkcs1/pkcs1_encoder.c
@@ -80,6 +80,33 @@ static bool build_pub_modulus(chunk_t *encoding, va_list args)
 	return FALSE;
 }

+/**
+ * Encode the DER-encoded OID of an ECDSA public key we expect as
+ * subjectPublicKeyInfo structure
+ */
+static bool build_pub_curve(chunk_t *encoding, va_list args)
+{
+	chunk_t outer, inner, curve;
+
+	if (cred_encoding_args(args, CRED_PART_ECDSA_PUB_ASN1_DER, &outer,
+						   CRED_PART_END) ||
+		cred_encoding_args(args, CRED_PART_PUB_ASN1_DER, &outer, CRED_PART_END))
+	{
+		if (asn1_unwrap(&outer, &outer) == ASN1_SEQUENCE &&
+			asn1_unwrap(&outer, &outer) == ASN1_SEQUENCE &&
+			asn1_unwrap(&outer, &inner) == ASN1_OID)
+		{
+			curve = outer;
+			if (asn1_unwrap(&outer, &inner) == ASN1_OID)
+			{
+				*encoding = chunk_clone(curve);
+				return TRUE;
+			}
+		}
+	}
+	return FALSE;
+}
+
 /**
  * Encode a private key in PKCS#1/ASN.1 DER
  */
@@ -175,6 +202,8 @@ bool pkcs1_encoder_encode(cred_encoding_type_t type, chunk_t *encoding,
 			return build_pub_info(encoding, args);
 		case PUBKEY_RSA_MODULUS:
 			return build_pub_modulus(encoding, args);
+		case PUBKEY_ECDSA_CURVE_DER:
+			return build_pub_curve(encoding, args);
 		case PRIVKEY_ASN1_DER:
 			return build_priv(encoding, args);
 		default: