From: Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Jack Lau <jacklau1222@qq.com> Subject: [FFmpeg-devel] [PATCH v2] avformat/tls_openssl: fix build error when openssl version < 3 Date: Fri, 6 Jun 2025 16:17:38 +0800 Message-ID: <tencent_B1E45E144EE247A86781F9D2C676A04EB509@qq.com> (raw) add the missing data structure pkey in the tls_context properly set this pkey and free it Signed-off-by: Jack Lau <jacklau1222@qq.com> --- libavformat/tls_openssl.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c index b589d5d90a..86e8935fee 100644 --- a/libavformat/tls_openssl.c +++ b/libavformat/tls_openssl.c @@ -467,6 +467,7 @@ typedef struct TLSContext { TLSShared tls_shared; SSL_CTX *ctx; SSL *ssl; + EVP_PKEY *pkey; #if OPENSSL_VERSION_NUMBER >= 0x1010000fL BIO_METHOD* url_bio_method; #endif @@ -849,7 +850,7 @@ static av_cold int openssl_init_ca_key_cert(URLContext *h) goto fail; } } else if (p->tls_shared.key_buf) { - pkey = pkey_from_pem_string(p->tls_shared.key_buf, 1); + p->pkey = pkey = pkey_from_pem_string(p->tls_shared.key_buf, 1); if (SSL_CTX_use_PrivateKey(p->ctx, pkey) != 1) { av_log(p, AV_LOG_ERROR, "TLS: Init SSL_CTX_use_PrivateKey failed, %s\n", openssl_get_error(p)); ret = AVERROR(EINVAL); @@ -876,6 +877,9 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** int ret = 0; c->is_dtls = 1; const char* ciphers = "ALL"; +#if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2 + EC_KEY *ec_key = NULL; +#endif /** * The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c. * The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c. @@ -908,15 +912,6 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** } #endif -#if OPENSSL_VERSION_NUMBER < 0x10100000L // v1.1.x -#if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2 - if (ctx->dtls_eckey) - SSL_CTX_set_tmp_ecdh(p->ctx, p->dtls_eckey); -#else - SSL_CTX_set_ecdh_auto(p->ctx, 1); -#endif -#endif - /** * We activate "ALL" cipher suites to align with the peer's capabilities, * ensuring maximum compatibility. @@ -930,6 +925,17 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** ret = openssl_init_ca_key_cert(h); if (ret < 0) goto fail; +#if OPENSSL_VERSION_NUMBER < 0x10100000L // v1.1.x +#if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2 + if (p->pkey) + ec_key = EVP_PKEY_get1_EC_KEY(p->pkey); + if (ec_key) + SSL_CTX_set_tmp_ecdh(p->ctx, ec_key); +#else + SSL_CTX_set_ecdh_auto(p->ctx, 1); +#endif +#endif + /* Server will send Certificate Request. */ SSL_CTX_set_verify(p->ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, openssl_dtls_verify_callback); /* The depth count is "level 0:peer certificate", "level 1: CA certificate", @@ -1001,6 +1007,9 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** ret = 0; fail: +#if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2 + EC_KEY_free(ec_key); +#endif return ret; } @@ -1015,9 +1024,7 @@ static av_cold int dtls_close(URLContext *h) av_freep(&ctx->tls_shared.fingerprint); av_freep(&ctx->tls_shared.cert_buf); av_freep(&ctx->tls_shared.key_buf); -#if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */ - EC_KEY_free(ctx->dtls_eckey); -#endif + EVP_PKEY_free(ctx->pkey); return 0; } -- 2.49.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2025-06-06 8:17 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-06-06 8:17 Jack Lau via ffmpeg-devel [this message] 2025-06-06 8:32 ` Martin Storsjö 2025-06-07 12:29 ` Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_B1E45E144EE247A86781F9D2C676A04EB509@qq.com \ --to=ffmpeg-devel@ffmpeg.org \ --cc=jacklau1222@qq.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git