History

avformat/rtsp: add TLS options

Add TLS options to RTSP for when TLS is used for the lower protocol.

Daniel N Pettersson committed 5 years ago

Commit e1ef33d1 parent ba9817d2 files · +36 −1Browse files

Unified · Split

2 files
  1. libavformat/rtsp.c +25 −1
  2. libavformat/rtsp.h +11 −0
libavformat/rtsp.c+25−1
@@ -53,6 +53,7 @@ · 52 unmodified lines
5353 #include "rtpdec_formats.h"
5454 #include "rtpenc_chain.h"
5555 #include "url.h"
56+#include "tls.h"
5657 #include "rtpenc.h"
5758 #include "mpegts.h"
5859 #include "version.h"
@@ -103,6 +104,9 @@ const AVOption ff_rtsp_options[] = { · 44 unmodified lines
103104 { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT64, {.i64 = 0}, INT_MIN, INT64_MAX, DEC },
104105 COMMON_OPTS(),
105106 { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC },
107+
108+ // TLS options
109+ FF_TLS_CLIENT_OPTIONS(RTSPState, tls_opts),
106110 { NULL },
107111 };
108112
@@ -139,6 +143,18 @@ static AVDictionary *map_to_opts(RTSPState *rt) · 30 unmodified lines
139143 return opts;
140144 }
141145
146+/**
147+ * Add the TLS options of the given RTSPState to the dict
148+ */
149+static void copy_tls_opts_dict(RTSPState *rt, AVDictionary **dict)
150+{
151+ av_dict_set_int(dict, "tls_verify", rt->tls_opts.verify, 0);
152+ av_dict_set(dict, "ca_file", rt->tls_opts.ca_file, 0);
153+ av_dict_set(dict, "cert_file", rt->tls_opts.cert_file, 0);
154+ av_dict_set(dict, "key_file", rt->tls_opts.key_file, 0);
155+ av_dict_set(dict, "verifyhost", rt->tls_opts.host, 0);
156+}
157+
142158 static void get_word_until_chars(char *buf, int buf_size,
143159 const char *sep, const char **pp)
144160 {
@@ -1821,6 +1837,8 @@ redirect: · 1676 unmodified lines
18211837 AVDictionary *options = NULL;
18221838
18231839 av_dict_set_int(&options, "timeout", rt->stimeout, 0);
1840+ if (https_tunnel)
1841+ copy_tls_opts_dict(rt, &options);
18241842
18251843 ff_url_join(httpname, sizeof(httpname), https_tunnel ? "https" : "http", auth, host, port, "%s", path);
18261844 snprintf(sessioncookie, sizeof(sessioncookie), "%08x%08x",
@@ -1905,14 +1923,20 @@ redirect: · 78 unmodified lines
19051923 } else {
19061924 int ret;
19071925 /* open the tcp connection */
1926+ AVDictionary *proto_opts = NULL;
1927+ if (strcmp("tls", lower_rtsp_proto) == 0)
1928+ copy_tls_opts_dict(rt, &proto_opts);
1929+
19081930 ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL,
19091931 host, port,
19101932 "?timeout=%"PRId64, rt->stimeout);
19111933 if ((ret = ffurl_open_whitelist(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
1912− &s->interrupt_callback, NULL, s->protocol_whitelist, s->protocol_blacklist, NULL)) < 0) {
1934+ &s->interrupt_callback, &proto_opts, s->protocol_whitelist, s->protocol_blacklist, NULL)) < 0) {
1935+ av_dict_free(&proto_opts);
19131936 err = ret;
19141937 goto fail;
19151938 }
1939+ av_dict_free(&proto_opts);
19161940 rt->rtsp_hd_out = rt->rtsp_hd;
19171941 }
19181942 rt->seq = 0;
libavformat/rtsp.h+11−0
@@ -419,6 +419,17 @@ typedef struct RTSPState { · 418 unmodified lines
419419 int buffer_size;
420420 int pkt_size;
421421 char *localaddr;
422+
423+ /**
424+ * Options used for TLS based RTSP streams.
425+ */
426+ struct {
427+ char *ca_file;
428+ int verify;
429+ char *cert_file;
430+ char *key_file;
431+ char *host;
432+ } tls_opts;
422433 } RTSPState;
423434
424435 #define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets -

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t