Skip to content

Commit 7eda183

Browse files
committed
avformat/tls: add new option use_srtp to control whether enable it
Signed-off-by: Jack Lau <[email protected]>
1 parent f8b7751 commit 7eda183

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

libavformat/tls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef struct TLSShared {
5151
URLContext *tcp;
5252

5353
int is_dtls;
54+
int use_srtp;
5455

5556
/* The certificate and private key content used for DTLS handshake */
5657
char* cert_buf;
@@ -77,6 +78,7 @@ typedef struct TLSShared {
7778
{"listen", "Listen for incoming connections", offsetof(pstruct, options_field . listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
7879
{"http_proxy", "Set proxy to tunnel through", offsetof(pstruct, options_field . http_proxy), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
7980
{"external_sock", "Use external socket", offsetof(pstruct, options_field . external_sock), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
81+
{"use_srtp", "Enable use_srtp DTLS extension", offsetof(pstruct, options_field . use_srtp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
8082
{"mtu", "Maximum Transmission Unit", offsetof(pstruct, options_field . mtu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = TLS_OPTFL}, \
8183
{"cert_pem", "Certificate PEM string", offsetof(pstruct, options_field . cert_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
8284
{"key_pem", "Private key PEM string", offsetof(pstruct, options_field . key_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \

libavformat/tls_openssl.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -814,12 +814,6 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
814814
int ret = 0;
815815
c->is_dtls = 1;
816816

817-
/**
818-
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
819-
* The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c.
820-
*/
821-
const char* profiles = "SRTP_AES128_CM_SHA1_80";
822-
823817
p->ctx = SSL_CTX_new(c->listen ? DTLS_server_method() : DTLS_client_method());
824818
if (!p->ctx) {
825819
ret = AVERROR(ENOMEM);
@@ -833,12 +827,18 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
833827
if (c->verify)
834828
SSL_CTX_set_verify(p->ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
835829

836-
/* Setup the SRTP context */
837-
if (SSL_CTX_set_tlsext_use_srtp(p->ctx, profiles)) {
838-
av_log(p, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",
839-
profiles, openssl_get_error(p));
840-
ret = AVERROR(EINVAL);
841-
return ret;
830+
if (c->use_srtp) {
831+
/**
832+
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
833+
* The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c.
834+
*/
835+
const char* profiles = "SRTP_AES128_CM_SHA1_80";
836+
if (SSL_CTX_set_tlsext_use_srtp(p->ctx, profiles)) {
837+
av_log(p, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",
838+
profiles, openssl_get_error(p));
839+
ret = AVERROR(EINVAL);
840+
goto fail;
841+
}
842842
}
843843

844844
/* The ssl should not be created unless the ctx has been initialized. */

libavformat/whip.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ static int handle_dtls_handshake(AVFormatContext *s)
13781378
} else
13791379
av_dict_set(&opts, "key_pem", whip->key_buf, 0);
13801380
av_dict_set_int(&opts, "external_sock", 1, 0);
1381+
av_dict_set_int(&opts, "use_srtp", 1, 0);
13811382
av_dict_set_int(&opts, "listen", whip->flags & WHIP_FLAG_DTLS_ACTIVE ? 0 : 1, 0);
13821383

13831384
ret = ffurl_open_whitelist(&whip->dtls_uc, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback,

0 commit comments

Comments
 (0)