Skip to content

Commit 63537ca

Browse files
authored
fix(crypto): support OpenSSL 1.1.x for ECDSA cert generation (#61)
EVP_EC_gen("P-256") is OpenSSL 3.0+ only. Wrap it in an OPENSSL_VERSION_NUMBER guard with an EC_KEY_new_by_curve_name / EVP_PKEY_assign_EC_KEY fallback so DTLS cert generation also builds against OpenSSL 1.1.x (Debian 11 Bullseye libssl), unblocking the radxa-cubie-a7z UVC publisher example whose BSP sysroot ships 1.1.1. OpenSSL 3.0 path is unchanged.
1 parent 84c590d commit 63537ca

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

crypto/nanortc_crypto_openssl.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,35 @@ static int ossl_compute_fingerprint(X509 *cert, char *buf, size_t buf_len)
102102

103103
static int ossl_generate_cert(nanortc_crypto_dtls_ctx_t *ctx)
104104
{
105-
/* Generate ECDSA P-256 key */
105+
/* Generate ECDSA P-256 key. EVP_EC_gen() is the OpenSSL 3.0+ shorthand;
106+
* fall back to the classic EC_KEY -> EVP_PKEY flow on 1.1.x (Debian 11
107+
* Bullseye's libssl, which the Radxa Cubie A7Z BSP sysroot is built on). */
108+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
106109
ctx->pkey = EVP_EC_gen("P-256");
110+
#else
111+
{
112+
EC_KEY *ec = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
113+
if (!ec) {
114+
return -1;
115+
}
116+
if (EC_KEY_generate_key(ec) != 1) {
117+
EC_KEY_free(ec);
118+
return -1;
119+
}
120+
ctx->pkey = EVP_PKEY_new();
121+
if (!ctx->pkey) {
122+
EC_KEY_free(ec);
123+
return -1;
124+
}
125+
if (EVP_PKEY_assign_EC_KEY(ctx->pkey, ec) != 1) {
126+
EC_KEY_free(ec);
127+
EVP_PKEY_free(ctx->pkey);
128+
ctx->pkey = NULL;
129+
return -1;
130+
}
131+
/* ec is now owned by ctx->pkey; do not free separately. */
132+
}
133+
#endif
107134
if (!ctx->pkey) {
108135
return -1;
109136
}

0 commit comments

Comments
 (0)