From 4ad20a2c09c41f064b367abc6291fba93941db6e Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Fri, 23 Jan 2026 11:17:29 +0800 Subject: [PATCH] avformat/tls_gnutls: set key and cert when they're PEM string Signed-off-by: Jack Lau --- libavformat/tls_gnutls.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c index e6d73bff61..d0358c162c 100644 --- a/libavformat/tls_gnutls.c +++ b/libavformat/tls_gnutls.c @@ -573,8 +573,20 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op ret = AVERROR(EIO); goto fail; } - } else if (s->cert_file || s->key_file) + } else if (s->cert_file || s->key_file) { av_log(h, AV_LOG_ERROR, "cert and key required\n"); + } else if (s->cert_buf && s->key_buf) { + gnutls_datum_t cert_data = { .data = s->cert_buf, .size = strlen(s->cert_buf)}; + gnutls_datum_t pkey_data = { .data = s->key_buf, .size = strlen(s->key_buf)}; + ret = gnutls_certificate_set_x509_key_mem(c->cred, &cert_data, &pkey_data, GNUTLS_X509_FMT_PEM); + if (ret < 0) { + av_log(h, AV_LOG_ERROR, "Unable to set cert/key memory: %s\n", gnutls_strerror(ret)); + ret = AVERROR(EINVAL); + goto fail; + } + } else if (s->cert_buf || s->key_buf) { + av_log(h, AV_LOG_ERROR, "cert and key required\n"); + } if (s->listen && !s->cert_file && !s->cert_buf && !s->key_file && !s->key_buf) { av_log(h, AV_LOG_VERBOSE, "No server certificate provided, using self-signed\n");