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 }
48 return 0;
49 }
50
52 {
56 return TLS_WANT_POLLIN;
58 return 0;
59 return ret >= 0 ?
ret : -1;
60 }
61
63 {
67 return TLS_WANT_POLLOUT;
69 return 0;
70 return ret >= 0 ?
ret : -1;
71 }
72
74 {
77 struct tls_config *cfg =
NULL;
79
80 if (tls_init() == -1) {
83 }
84
87
88 p->
ctx = !
c->listen ? tls_client() : tls_server();
92 }
93
94 cfg = tls_config_new();
98 }
99 if (tls_config_set_protocols(cfg, TLS_PROTOCOLS_ALL) == -1)
100 goto err_config;
101 // While TLSv1.0 and TLSv1.1 are already enabled by the above,
102 // we need to be less strict with ciphers so it works in practice.
103 if (tls_config_set_ciphers(cfg, "compat") == -1)
104 goto err_config;
105 if (
c->ca_file && tls_config_set_ca_file(cfg,
c->ca_file) == -1)
106 goto err_config;
107 if (
c->cert_file && tls_config_set_cert_file(cfg,
c->cert_file) == -1)
108 goto err_config;
109 if (
c->key_file && tls_config_set_key_file(cfg,
c->key_file) == -1)
110 goto err_config;
112 tls_config_insecure_noverifycert(cfg);
113 tls_config_insecure_noverifyname(cfg);
114 tls_config_insecure_noverifytime(cfg);
115 }
116 if (tls_configure(p->
ctx, cfg) == -1)
117 goto err_ctx;
118
122 } else {
123 struct tls *ctx_new;
127 // free "server" context and replace by "connection" context
130 }
131 }
133 goto err_ctx;
134
135 tls_config_free(cfg);
136 return 0;
137 err_config:
141 err_ctx:
144 /* fallthrough */
146 if (cfg)
147 tls_config_free(cfg);
150 }
151
153 {
161 else if (
ret == TLS_WANT_POLLIN ||
ret == TLS_WANT_POLLOUT)
165 }
166
168 {
176 else if (
ret == TLS_WANT_POLLIN ||
ret == TLS_WANT_POLLOUT)
180 }
181
183 {
186 }
187
189 {
192 }
193
197 };
198
204 };
205
217 };