1 /*
2 * TLS/SSL Protocol
3 * Copyright (c) 2011 Martin Storsjo
4 * Copyright (c) 2017 sfan5 <sfan5@live.de>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
31
33
39
41 {
46 }
49 return 0;
50 }
51
53 {
57 return TLS_WANT_POLLIN;
59 return 0;
60 return ret >= 0 ? ret : -1;
61 }
62
64 {
68 return TLS_WANT_POLLOUT;
70 return 0;
71 return ret >= 0 ? ret : -1;
72 }
73
75 {
78 struct tls_config *cfg =
NULL;
79 int ret;
80
81 if (tls_init() == -1) {
84 }
85
88
89 p->
ctx = !c->
listen ? tls_client() : tls_server();
93 }
94
95 cfg = tls_config_new();
99 }
100 if (tls_config_set_protocols(cfg, TLS_PROTOCOLS_ALL) == -1)
101 goto err_config;
102 // While TLSv1.0 and TLSv1.1 are already enabled by the above,
103 // we need to be less strict with ciphers so it works in practice.
104 if (tls_config_set_ciphers(cfg, "compat") == -1)
105 goto err_config;
107 goto err_config;
109 goto err_config;
111 goto err_config;
113 tls_config_insecure_noverifycert(cfg);
114 tls_config_insecure_noverifyname(cfg);
115 tls_config_insecure_noverifytime(cfg);
116 }
117 if (tls_configure(p->
ctx, cfg) == -1)
118 goto err_ctx;
119
123 } else {
124 struct tls *ctx_new;
127 if (ret == 0) {
128 // free "server" context and replace by "connection" context
131 }
132 }
133 if (ret == -1)
134 goto err_ctx;
135
136 tls_config_free(cfg);
137 return 0;
138 err_config:
142 err_ctx:
145 /* fallthrough */
147 if (cfg)
148 tls_config_free(cfg);
150 return ret;
151 }
152
154 {
156 ssize_t ret;
158 if (ret > 0)
159 return ret;
160 else if (ret == 0)
164 }
165
167 {
169 ssize_t ret;
171 if (ret > 0)
172 return ret;
173 else if (ret == 0)
177 }
178
180 {
183 }
184
188 };
189
195 };
196
206 .priv_data_class = &tls_class,
207 };
#define URL_PROTOCOL_FLAG_NETWORK
#define LIBAVUTIL_VERSION_INT
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
const char * av_default_item_name(void *ptr)
Return the context name.
Convenience header that includes libavutil's core.
static int ff_tls_read(URLContext *h, uint8_t *buf, int size)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const AVOption options[]
#define AVERROR_EOF
End of file.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int tls_read(URLContext *h, uint8_t *buf, int size)
static ssize_t tls_read_callback(struct tls *ctx, void *buf, size_t buflen, void *cb_arg)
#define TLS_COMMON_OPTIONS(pstruct, options_field)
static int tls_close(URLContext *h)
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
const URLProtocol ff_tls_protocol
static int tls_get_file_handle(URLContext *h)
Describe the class of an AVClass context structure.
static int ff_tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
int ffurl_close(URLContext *h)
static ssize_t tls_write_callback(struct tls *ctx, const void *buf, size_t buflen, void *cb_arg)
common internal api header.
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
static const AVClass tls_class
static int ff_tls_write(URLContext *h, const uint8_t *buf, int size)
static int tls_write(URLContext *h, const uint8_t *buf, int size)
unbuffered private I/O API
static int ff_tls_close(URLContext *h)
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...