aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/tls_openssl.c
diff options
context:
space:
mode:
authorTimo Rothenpieler <timo@rothenpieler.org>2025-07-13 16:35:20 +0200
committerTimo Rothenpieler <timo@rothenpieler.org>2025-07-16 18:46:55 +0200
commit5edbfc4bae4636af20623f426db38049ece3d332 (patch)
tree384963c97502b1378005ba965301837a30e4d5e5 /libavformat/tls_openssl.c
parent95fd0840feb2d0d37cf57045bf02b84244bc3f78 (diff)
downloadffmpeg-5edbfc4bae4636af20623f426db38049ece3d332.tar.gz
avformat/tls_openssl: clean up peer verify logic in dtls mode
Diffstat (limited to 'libavformat/tls_openssl.c')
-rw-r--r--libavformat/tls_openssl.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index bb9a5b8054..a497d4dfd8 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -674,15 +674,6 @@ static void openssl_info_callback(const SSL *ssl, int where, int ret) {
}
}
-/**
- * Always return 1 to accept any certificate. This is because we allow the peer to
- * use a temporary self-signed certificate for DTLS.
- */
-static int openssl_dtls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
-{
- return 1;
-}
-
static int dtls_handshake(URLContext *h)
{
int ret = 1, r0, r1;
@@ -792,13 +783,16 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
ret = openssl_init_ca_key_cert(h);
if (ret < 0) goto fail;
- /* 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",
- * "level 2: higher level CA certificate", and so on. */
- SSL_CTX_set_verify_depth(p->ctx, 4);
+ /* Note, this doesn't check that the peer certificate actually matches the requested hostname. */
+ if (c->verify)
+ SSL_CTX_set_verify(p->ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
+
+ if (!c->listen && !c->numerichost)
+ SSL_set_tlsext_host_name(p->ssl, c->host);
+
/* Whether we should read as many input bytes as possible (for non-blocking reads) or not. */
SSL_CTX_set_read_ahead(p->ctx, 1);
+
/* Setup the SRTP context */
if (SSL_CTX_set_tlsext_use_srtp(p->ctx, profiles)) {
av_log(p, AV_LOG_ERROR, "TLS: Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",