Add TLS options to RTSP for when TLS is used for the lower protocol.
Unified · Split
| @@ -53,6 +53,7 @@ · 52 unmodified lines | |||
| 53 | #include "rtpdec_formats.h" | 53 | #include "rtpdec_formats.h" |
| 54 | #include "rtpenc_chain.h" | 54 | #include "rtpenc_chain.h" |
| 55 | #include "url.h" | 55 | #include "url.h" |
| 56 | #include "tls.h" | ||
| 56 | #include "rtpenc.h" | 57 | #include "rtpenc.h" |
| 57 | #include "mpegts.h" | 58 | #include "mpegts.h" |
| 58 | #include "version.h" | 59 | #include "version.h" |
| @@ -103,6 +104,9 @@ const AVOption ff_rtsp_options[] = { · 44 unmodified lines | |||
| 103 | { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT64, {.i64 = 0}, INT_MIN, INT64_MAX, DEC }, | 104 | { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT64, {.i64 = 0}, INT_MIN, INT64_MAX, DEC }, |
| 104 | COMMON_OPTS(), | 105 | COMMON_OPTS(), |
| 105 | { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC }, | 106 | { "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), | ||
| 106 | { NULL }, | 110 | { NULL }, |
| 107 | }; | 111 | }; |
| 108 | 112 | ||
| @@ -139,6 +143,18 @@ static AVDictionary *map_to_opts(RTSPState *rt) · 30 unmodified lines | |||
| 139 | return opts; | 143 | return opts; |
| 140 | } | 144 | } |
| 141 | 145 | ||
| 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 | |||
| 142 | static void get_word_until_chars(char *buf, int buf_size, | 158 | static void get_word_until_chars(char *buf, int buf_size, |
| 143 | const char *sep, const char **pp) | 159 | const char *sep, const char **pp) |
| 144 | { | 160 | { |
| @@ -1821,6 +1837,8 @@ redirect: · 1676 unmodified lines | |||
| 1821 | AVDictionary *options = NULL; | 1837 | AVDictionary *options = NULL; |
| 1822 | 1838 | ||
| 1823 | av_dict_set_int(&options, "timeout", rt->stimeout, 0); | 1839 | av_dict_set_int(&options, "timeout", rt->stimeout, 0); |
| 1840 | if (https_tunnel) | ||
| 1841 | copy_tls_opts_dict(rt, &options); | ||
| 1824 | 1842 | ||
| 1825 | ff_url_join(httpname, sizeof(httpname), https_tunnel ? "https" : "http", auth, host, port, "%s", path); | 1843 | ff_url_join(httpname, sizeof(httpname), https_tunnel ? "https" : "http", auth, host, port, "%s", path); |
| 1826 | snprintf(sessioncookie, sizeof(sessioncookie), "%08x%08x", | 1844 | snprintf(sessioncookie, sizeof(sessioncookie), "%08x%08x", |
| @@ -1905,14 +1923,20 @@ redirect: · 78 unmodified lines | |||
| 1905 | } else { | 1923 | } else { |
| 1906 | int ret; | 1924 | int ret; |
| 1907 | /* open the tcp connection */ | 1925 | /* 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 | |||
| 1908 | ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL, | 1930 | ff_url_join(tcpname, sizeof(tcpname), lower_rtsp_proto, NULL, |
| 1909 | host, port, | 1931 | host, port, |
| 1910 | "?timeout=%"PRId64, rt->stimeout); | 1932 | "?timeout=%"PRId64, rt->stimeout); |
| 1911 | if ((ret = ffurl_open_whitelist(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE, | 1933 | 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); | ||
| 1913 | err = ret; | 1936 | err = ret; |
| 1914 | goto fail; | 1937 | goto fail; |
| 1915 | } | 1938 | } |
| 1939 | av_dict_free(&proto_opts); | ||
| 1916 | rt->rtsp_hd_out = rt->rtsp_hd; | 1940 | rt->rtsp_hd_out = rt->rtsp_hd; |
| 1917 | } | 1941 | } |
| 1918 | rt->seq = 0; | 1942 | rt->seq = 0; |
| @@ -419,6 +419,17 @@ typedef struct RTSPState { · 418 unmodified lines | |||
| 419 | int buffer_size; | 419 | int buffer_size; |
| 420 | int pkt_size; | 420 | int pkt_size; |
| 421 | char *localaddr; | 421 | 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; | ||
| 422 | } RTSPState; | 433 | } RTSPState; |
| 423 | 434 | ||
| 424 | #define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets - | 435 | #define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets - |