diff --git a/libavformat/tls.h b/libavformat/tls.h index df384da604..4d4999aa7c 100644 --- a/libavformat/tls.h +++ b/libavformat/tls.h @@ -63,6 +63,7 @@ typedef struct TLSShared { URLContext *tcp; int is_dtls; + int use_srtp; enum DTLSState state; @@ -97,6 +98,7 @@ typedef struct TLSShared { {"listen", "Listen for incoming connections", offsetof(pstruct, options_field . listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \ {"http_proxy", "Set proxy to tunnel through", offsetof(pstruct, options_field . http_proxy), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \ {"external_sock", "Use external socket", offsetof(pstruct, options_field . external_sock), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \ + {"use_srtp", "Enable use_srtp DTLS extension", offsetof(pstruct, options_field . use_srtp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \ {"mtu", "Maximum Transmission Unit", offsetof(pstruct, options_field . mtu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = TLS_OPTFL}, \ {"cert_pem", "Certificate PEM string", offsetof(pstruct, options_field . cert_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \ {"key_pem", "Private key PEM string", offsetof(pstruct, options_field . key_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \ diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c index c1db49d334..65b2966688 100644 --- a/libavformat/tls_openssl.c +++ b/libavformat/tls_openssl.c @@ -822,12 +822,6 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** av_assert0(s); s->is_dtls = 1; - /** - * 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. - */ - const char* profiles = "SRTP_AES128_CM_SHA1_80"; - c->ctx = SSL_CTX_new(s->listen ? DTLS_server_method() : DTLS_client_method()); if (!c->ctx) { ret = AVERROR(ENOMEM); @@ -841,12 +835,18 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary ** if (s->verify) SSL_CTX_set_verify(c->ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); - /* Setup the SRTP context */ - if (SSL_CTX_set_tlsext_use_srtp(c->ctx, profiles)) { - av_log(c, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n", - profiles, openssl_get_error(c)); - ret = AVERROR(EINVAL); - return ret; + if (s->use_srtp) { + /** + * 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. + */ + const char* profiles = "SRTP_AES128_CM_SHA1_80"; + if (SSL_CTX_set_tlsext_use_srtp(c->ctx, profiles)) { + av_log(c, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n", + profiles, openssl_get_error(c)); + ret = AVERROR(EINVAL); + goto fail; + } } /* The ssl should not be created unless the ctx has been initialized. */ diff --git a/libavformat/whip.c b/libavformat/whip.c index 256ea14d2c..65fd3b39b2 100644 --- a/libavformat/whip.c +++ b/libavformat/whip.c @@ -1303,6 +1303,7 @@ next_packet: } else av_dict_set(&opts, "key_pem", whip->key_buf, 0); av_dict_set_int(&opts, "external_sock", 1, 0); + av_dict_set_int(&opts, "use_srtp", 1, 0); av_dict_set_int(&opts, "listen", 1, 0); /* If got the first binding response, start DTLS handshake. */ ret = ffurl_open_whitelist(&whip->dtls_uc, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback,