FFmpeg
tls_mbedtls.c
Go to the documentation of this file.
1 /*
2  * TLS/SSL Protocol
3  * Copyright (c) 2018 Thomas Volkert
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <mbedtls/version.h>
23 #include <mbedtls/ctr_drbg.h>
24 #include <mbedtls/entropy.h>
25 #include <mbedtls/net_sockets.h>
26 #include <mbedtls/platform.h>
27 #include <mbedtls/ssl.h>
28 #include <mbedtls/x509_crt.h>
29 #include <mbedtls/debug.h>
30 #include <mbedtls/timing.h>
31 #ifdef MBEDTLS_PSA_CRYPTO_C
32 #include <psa/crypto.h>
33 #endif
34 
35 #include "config_components.h"
36 
37 #include "avformat.h"
38 #include "internal.h"
39 #include "network.h"
40 #include "url.h"
41 #include "tls.h"
42 #include "libavutil/mem.h"
43 #include "libavutil/parseutils.h"
44 #include "libavutil/avstring.h"
45 #include "libavutil/random_seed.h"
46 
47 static int mbedtls_x509_fingerprint(char *cert_buf, size_t cert_sz, char **fingerprint)
48 {
49  unsigned char md[32];
50  size_t n = sizeof(md);
51  AVBPrint buf;
52  int ret;
53  mbedtls_x509_crt crt;
54 
55  mbedtls_x509_crt_init(&crt);
56 
57  if ((ret = mbedtls_x509_crt_parse(&crt, cert_buf, cert_sz)) != 0) {
58  mbedtls_x509_crt_free(&crt);
59  return AVERROR(EINVAL);
60  }
61 
62  if ((ret = mbedtls_sha256(crt.raw.p, crt.raw.len, md, 0)) != 0) {
63  mbedtls_x509_crt_free(&crt);
64  return AVERROR(EINVAL);
65  }
66 
67  av_bprint_init(&buf, n*3, n*3);
68 
69  for (int i = 0; i < n - 1; i++)
70  av_bprintf(&buf, "%02X:", md[i]);
71  av_bprintf(&buf, "%02X", md[n - 1]);
72 
73  return av_bprint_finalize(&buf, fingerprint);
74 }
75 
76 int ff_ssl_read_key_cert(char *key_url, char *cert_url, char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint)
77 {
78  int ret = 0;
79  AVBPrint key_bp, cert_bp;
82 
83  ret = ff_url_read_all(key_url, &key_bp);
84  if (ret < 0) {
85  av_log(NULL, AV_LOG_ERROR, "TLS: Failed to open key file %s\n", key_url);
86  goto end;
87  }
88 
89  ret = ff_url_read_all(cert_url, &cert_bp);
90  if (ret < 0) {
91  av_log(NULL, AV_LOG_ERROR, "TLS: Failed to open cert file %s\n", cert_url);
92  goto end;
93  }
94 
95  if (key_sz < key_bp.size || cert_sz < cert_bp.size) {
96  av_log(NULL, AV_LOG_ERROR, "TLS: Key or Cert buffer is too samall\n");
98  goto end;
99  }
100 
101  key_buf = key_bp.str;
102  cert_buf = cert_bp.str;
103 
104  ret = mbedtls_x509_fingerprint(cert_buf, cert_sz, fingerprint);
105  if (ret < 0)
106  av_log(NULL, AV_LOG_ERROR, "TLS: Failed to generate fingerprint\n");
107 end:
108  av_bprint_finalize(&key_bp, NULL);
109  av_bprint_finalize(&cert_bp, NULL);
110  return ret;
111 }
112 
113 static int mbedtls_gen_pkey(mbedtls_pk_context *key)
114 {
115  int ret = 0;
116  mbedtls_entropy_context entropy;
117  mbedtls_ctr_drbg_context ctr_drbg;
118 
119  mbedtls_entropy_init(&entropy);
120  mbedtls_ctr_drbg_init(&ctr_drbg);
121 
122  if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
123  &entropy, NULL, 0)) != 0) {
124  av_log(NULL, AV_LOG_ERROR, "mbedtls_ctr_drbg_seed returned %d\n", ret);
125  goto end;
126  }
127 
128  if ((ret = mbedtls_pk_setup(key,
129  mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY))) != 0) {
130  av_log(NULL, AV_LOG_ERROR, "mbedtls_pk_setup returned %d\n", ret);
131  goto end;
132  }
133  /**
134  * See RFC 8827 section 6.5,
135  * All implementations MUST support DTLS 1.2 with the
136  * TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 cipher suite
137  * and the P-256 curve.
138  */
139  if ((ret = mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R1,
140  mbedtls_pk_ec(*key),
141  mbedtls_ctr_drbg_random, &ctr_drbg)) != 0) {
142  av_log(NULL, AV_LOG_ERROR, "mbedtls_ecp_gen_key returned %d\n", ret);
143  goto end;
144  }
145 end:
146  mbedtls_entropy_free(&entropy);
147  mbedtls_ctr_drbg_free(&ctr_drbg);
148  return ret;
149 }
150 
151 static int mbedtls_gen_x509_cert(mbedtls_pk_context *key, char *cert_buf, size_t cert_sz)
152 {
153  int ret = 0;
154  const char *name = "CN=lavf";
155  time_t now;
156  struct tm tm;
157  char not_before[16], not_after[16];
158  unsigned char serial[20];
159  mbedtls_entropy_context entropy;
160  mbedtls_ctr_drbg_context ctr_drbg;
161  mbedtls_x509write_cert crt;
162 
163  mbedtls_entropy_init(&entropy);
164  mbedtls_ctr_drbg_init(&ctr_drbg);
165  mbedtls_x509write_crt_init(&crt);
166 
167  if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0)) != 0) {
168  av_log(NULL, AV_LOG_ERROR, "mbedtls_ctr_drbg_seed returned %d\n", ret);
169  goto end;
170  }
171 
172  mbedtls_x509write_crt_set_subject_key(&crt, key);
173  mbedtls_x509write_crt_set_issuer_key(&crt, key);
174  if ((ret = mbedtls_x509write_crt_set_subject_name(&crt, name)) != 0) {
175  av_log(NULL, AV_LOG_ERROR, "mbedtls_x509write_crt_set_subject_name returned %d\n", ret);
176  goto end;
177  }
178 
179  if ((ret = mbedtls_x509write_crt_set_issuer_name(&crt, name)) != 0) {
180  av_log(NULL, AV_LOG_ERROR, "mbedtls_x509write_crt_set_issuer_name returned %d\n", ret);
181  goto end;
182  }
183  mbedtls_x509write_crt_set_version(&crt, MBEDTLS_X509_CRT_VERSION_3);
184  mbedtls_x509write_crt_set_md_alg(&crt, MBEDTLS_MD_SHA256);
185 
186  ret = av_random_bytes((uint8_t *)serial, sizeof(serial));
187  if (ret < 0) {
188  av_log(NULL, AV_LOG_ERROR, "Failed to generate random serial number!\n");
189  return ret;
190  }
191 
192  if ((ret = mbedtls_x509write_crt_set_serial_raw(&crt, serial, sizeof(serial))) != 0) {
193  av_log(NULL, AV_LOG_ERROR, "mbedtls_x509write_crt_set_serial_raw returned %d\n", ret);
194  goto end;
195  }
196 
197  time(&now);
198  gmtime_r(&now, &tm);
199  strftime(not_before, sizeof(not_before), "%Y%m%d%H%M%S", &tm);
200  tm.tm_year += 1;
201  strftime(not_after, sizeof(not_after), "%Y%m%d%H%M%S", &tm);
202 
203  if ((ret = mbedtls_x509write_crt_set_validity(&crt, not_before, not_after)) != 0) {
204  av_log(NULL, AV_LOG_ERROR, "mbedtls_x509write_crt_set_validity returned %d\n", ret);
205  goto end;
206  }
207 
208  if ((ret = mbedtls_x509write_crt_pem(&crt, cert_buf, cert_sz,
209  mbedtls_ctr_drbg_random, &ctr_drbg)) != 0) {
210  av_log(NULL, AV_LOG_ERROR, "mbedtls_x509write_crt_pem returned %d\n", ret);
211  return ret;
212  }
213 
214 end:
215  mbedtls_entropy_free(&entropy);
216  mbedtls_ctr_drbg_free(&ctr_drbg);
217  mbedtls_x509write_crt_free(&crt);
218  return ret;
219 }
220 
221 int ff_ssl_gen_key_cert(char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint)
222 {
223  int ret = 0;
224  mbedtls_pk_context key;
225 
226  mbedtls_pk_init(&key);
227 
228  if ((ret = mbedtls_gen_pkey(&key)) != 0)
229  goto end;
230 
231  if ((ret = mbedtls_pk_write_key_pem(&key, key_buf, key_sz)) != 0)
232  goto end;
233 
234  if ((ret = mbedtls_gen_x509_cert(&key, cert_buf, cert_sz)) != 0)
235  goto end;
236 
237  ret = mbedtls_x509_fingerprint(cert_buf, cert_sz, fingerprint);
238  if (ret < 0)
239  av_log(NULL, AV_LOG_ERROR, "TLS: Failed to generate fingerprint\n");
240 
241 end:
242  mbedtls_pk_free(&key);
243  return ret;
244 }
245 
246 typedef struct dtls_srtp_keys {
247  unsigned char master_secret[48];
248  unsigned char randbytes[64];
249  mbedtls_tls_prf_types tls_prf_type;
251 
252 typedef struct TLSContext {
254  mbedtls_ssl_context ssl_context;
255  mbedtls_ssl_config ssl_config;
256  mbedtls_entropy_context entropy_context;
257  mbedtls_ctr_drbg_context ctr_drbg_context;
258  mbedtls_timing_delay_context timer;
259  mbedtls_x509_crt ca_cert;
260  mbedtls_x509_crt own_cert;
261  mbedtls_pk_context priv_key;
262  char *priv_key_pw;
265  socklen_t dest_addr_len;
266 } TLSContext;
267 
269 {
270  TLSContext *tls_ctx = h->priv_data;
271  TLSShared *shr = &tls_ctx->tls_shared;
272 
273  if (shr->is_dtls)
274  shr->udp = sock;
275  else
276  shr->tcp = sock;
277 
278  return 0;
279 }
280 
281 #if defined(MBEDTLS_SSL_DTLS_SRTP)
282 static void dtls_srtp_key_derivation(void *p_expkey,
283  mbedtls_ssl_key_export_type secret_type,
284  const unsigned char *secret,
285  size_t secret_len,
286  const unsigned char client_random[32],
287  const unsigned char server_random[32],
288  mbedtls_tls_prf_types tls_prf_type)
289 {
290  dtls_srtp_keys *keys = (dtls_srtp_keys *) p_expkey;
291 
292  if (secret_len != sizeof(keys->master_secret))
293  return;
294 
295  memcpy(keys->master_secret, secret, secret_len);
296  memcpy(keys->randbytes, client_random, 32);
297  memcpy(keys->randbytes + 32, server_random, 32);
298  keys->tls_prf_type = tls_prf_type;
299 }
300 #endif
301 
302 int ff_dtls_export_materials(URLContext *h, char *dtls_srtp_materials, size_t materials_sz)
303 {
304  int ret = 0;
305  TLSContext *tls_ctx = h->priv_data;
306 #if defined(MBEDTLS_SSL_DTLS_SRTP)
307  const char* dst = "EXTRACTOR-dtls_srtp";
308  mbedtls_dtls_srtp_info dtls_srtp_negotiation_result;
309  mbedtls_ssl_get_dtls_srtp_negotiation_result(&tls_ctx->ssl_context, &dtls_srtp_negotiation_result);
310 
311  if ((ret = mbedtls_ssl_tls_prf(tls_ctx->srtp_key.tls_prf_type,
312  tls_ctx->srtp_key.master_secret,
313  sizeof(tls_ctx->srtp_key.master_secret),
314  dst,
315  tls_ctx->srtp_key.randbytes,
316  sizeof(tls_ctx->srtp_key.randbytes),
317  dtls_srtp_materials,
318  materials_sz)) != 0) {
319  av_log(h, AV_LOG_ERROR,"mbedtls_ssl_tls_prf returned %d\n", ret);
320  ret = AVERROR(EINVAL);
321  }
322 #else
323  av_log(h, AV_LOG_ERROR, "DTLS-SRTP is not supported in this mbedtls build\n");
324  ret = AVERROR(ENOSYS);
325 #endif
326  return ret;
327 }
328 
329 #define OFFSET(x) offsetof(TLSContext, x)
330 
331 static int tls_close(URLContext *h)
332 {
333  TLSContext *tls_ctx = h->priv_data;
334  TLSShared *shr = &tls_ctx->tls_shared;
335 
336  mbedtls_ssl_close_notify(&tls_ctx->ssl_context);
337  mbedtls_pk_free(&tls_ctx->priv_key);
338  mbedtls_x509_crt_free(&tls_ctx->ca_cert);
339  mbedtls_x509_crt_free(&tls_ctx->own_cert);
340  mbedtls_ssl_free(&tls_ctx->ssl_context);
341  mbedtls_ssl_config_free(&tls_ctx->ssl_config);
342  mbedtls_ctr_drbg_free(&tls_ctx->ctr_drbg_context);
343  mbedtls_entropy_free(&tls_ctx->entropy_context);
344  if (!shr->external_sock)
345  ffurl_closep(shr->is_dtls ? &shr->udp : &shr->tcp);
346  return 0;
347 }
348 
349 static int handle_transport_error(URLContext *h, const char* func_name, int react_on_eagain, int ret)
350 {
351  switch (ret) {
352  case AVERROR(EAGAIN):
353  return react_on_eagain;
354  case AVERROR_EXIT:
355  return 0;
356  case AVERROR(EPIPE):
357  case AVERROR(ECONNRESET):
358  return MBEDTLS_ERR_NET_CONN_RESET;
359  default:
360  av_log(h, AV_LOG_ERROR, "%s returned 0x%x\n", func_name, ret);
361  errno = EIO;
362  return MBEDTLS_ERR_NET_SEND_FAILED;
363  }
364 }
365 
366 static int mbedtls_send(void *ctx, const unsigned char *buf, size_t len)
367 {
368  TLSContext *tls_ctx = (TLSContext*) ctx;
369  TLSShared *shr = &tls_ctx->tls_shared;
370  URLContext *h = shr->is_dtls ? shr->udp : shr->tcp;
371  int ret = ffurl_write(h, buf, len);
372  if (ret >= 0)
373  return ret;
374 
375  if (h->max_packet_size && len > h->max_packet_size)
376  return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL;
377 
378  return handle_transport_error(h, "ffurl_write", MBEDTLS_ERR_SSL_WANT_WRITE, ret);
379 }
380 
381 static int mbedtls_recv(void *ctx, unsigned char *buf, size_t len)
382 {
383  TLSContext *tls_ctx = (TLSContext*) ctx;
384  TLSShared *shr = &tls_ctx->tls_shared;
385  URLContext *h = shr->is_dtls ? shr->udp : shr->tcp;
386  int ret = ffurl_read(h, buf, len);
387  if (ret >= 0) {
388 #if CONFIG_UDP_PROTOCOL
389  if (shr->is_dtls && shr->listen && !tls_ctx->dest_addr_len) {
390  int err_ret;
391 
392  ff_udp_get_last_recv_addr(shr->udp, &tls_ctx->dest_addr, &tls_ctx->dest_addr_len);
393  err_ret = ff_udp_set_remote_addr(shr->udp, (struct sockaddr *)&tls_ctx->dest_addr, tls_ctx->dest_addr_len, 1);
394  if (err_ret < 0) {
395  av_log(tls_ctx, AV_LOG_ERROR, "Failed connecting udp context\n");
396  return err_ret;
397  }
398  av_log(tls_ctx, AV_LOG_TRACE, "Set UDP remote addr on UDP socket, now 'connected'\n");
399  }
400 #endif
401  /* Skip non-DTLS packets such as STUN to avoid failures. */
402  if (shr->is_dtls && !ff_is_dtls_packet(buf, ret))
403  return MBEDTLS_ERR_SSL_WANT_READ;
404  return ret;
405  }
406  if (h->max_packet_size && len > h->max_packet_size)
407  return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL;
408 
409  return handle_transport_error(h, "ffurl_read", MBEDTLS_ERR_SSL_WANT_READ, ret);
410 }
411 
412 static void mbedtls_debug(void *ctx, int lvl, const char *file, int line, const char *msg)
413 {
414  URLContext *h = (URLContext*) ctx;
415  int av_lvl = lvl >= 4 ? AV_LOG_TRACE : AV_LOG_DEBUG;
416  av_log(h, av_lvl, "%s:%d: %s", av_basename(file), line, msg);
417 }
418 
420 {
421  switch (ret) {
422  case MBEDTLS_ERR_PK_FILE_IO_ERROR:
423  av_log(h, AV_LOG_ERROR, "Read of key file failed. Is it actually there, are the access permissions correct?\n");
424  break;
425  case MBEDTLS_ERR_PK_PASSWORD_REQUIRED:
426  av_log(h, AV_LOG_ERROR, "A password for the private key is missing.\n");
427  break;
428  case MBEDTLS_ERR_PK_PASSWORD_MISMATCH:
429  av_log(h, AV_LOG_ERROR, "The given password for the private key is wrong.\n");
430  break;
431  default:
432  av_log(h, AV_LOG_ERROR, "mbedtls_pk_parse_key returned -0x%x\n", -ret);
433  break;
434  }
435 }
436 
438 {
439  switch (ret) {
440 #if MBEDTLS_VERSION_MAJOR < 3
441  case MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE:
442  av_log(h, AV_LOG_ERROR, "None of the common ciphersuites is usable. Was the local certificate correctly set?\n");
443  break;
444 #else
445  case MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE:
446  av_log(h, AV_LOG_ERROR, "TLS handshake failed.\n");
447  break;
448  case MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION:
449  av_log(h, AV_LOG_ERROR, "TLS protocol version mismatch.\n");
450  break;
451 #endif
452  case MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE:
453  av_log(h, AV_LOG_ERROR, "A fatal alert message was received from the peer, has the peer a correct certificate?\n");
454  break;
455  case MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED:
456  av_log(h, AV_LOG_ERROR, "No CA chain is set, but required to operate. Was the CA correctly set?\n");
457  break;
458  case MBEDTLS_ERR_SSL_INTERNAL_ERROR:
459  av_log(h, AV_LOG_ERROR, "Internal error encountered.\n");
460  break;
461  case MBEDTLS_ERR_NET_CONN_RESET:
462  av_log(h, AV_LOG_ERROR, "TLS handshake was aborted by peer.\n");
463  break;
464  case MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:
465  av_log(h, AV_LOG_ERROR, "Certificate verification failed.\n");
466  break;
467  default:
468  av_log(h, AV_LOG_ERROR, "mbedtls_ssl_handshake returned -0x%x\n", -ret);
469  break;
470  }
471 }
472 
474 {
475  TLSContext *tls_ctx = h->priv_data;
476  TLSShared *shr = &tls_ctx->tls_shared;
477  URLContext *uc = shr->is_dtls ? shr->udp : shr->tcp;
478  int ret;
479 
480  uc->flags &= ~AVIO_FLAG_NONBLOCK;
481 
482  while (1) {
483  ret = mbedtls_ssl_handshake(&tls_ctx->ssl_context);
484 
485  if (!ret)
486  break;
487  if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
489  return ret;
490  }
491  }
492 
493  return ret;
494 }
495 
496 static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
497 {
498  TLSContext *tls_ctx = h->priv_data;
499  TLSShared *shr = &tls_ctx->tls_shared;
500  uint32_t verify_res_flags;
501  int ret;
502 #if defined(MBEDTLS_SSL_DTLS_SRTP)
503  const mbedtls_ssl_srtp_profile profiles[] = {
504  MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80,
505  MBEDTLS_TLS_SRTP_UNSET
506  };
507 #endif
508 
509  if (!shr->external_sock) {
510  if ((ret = ff_tls_open_underlying(shr, h, uri, options)) < 0)
511  goto fail;
512  }
513 
514 #ifdef MBEDTLS_PSA_CRYPTO_C
515  if ((ret = psa_crypto_init()) != PSA_SUCCESS) {
516  av_log(h, AV_LOG_ERROR, "psa_crypto_init returned %d\n", ret);
517  goto fail;
518  }
519 #endif
520 
521  mbedtls_ssl_init(&tls_ctx->ssl_context);
522  mbedtls_ssl_config_init(&tls_ctx->ssl_config);
523  mbedtls_entropy_init(&tls_ctx->entropy_context);
524  mbedtls_ctr_drbg_init(&tls_ctx->ctr_drbg_context);
525  mbedtls_x509_crt_init(&tls_ctx->ca_cert);
526  mbedtls_pk_init(&tls_ctx->priv_key);
527 
528  if (av_log_get_level() >= AV_LOG_DEBUG) {
529  mbedtls_ssl_conf_dbg(&tls_ctx->ssl_config, mbedtls_debug, shr->is_dtls ? shr->udp : shr->tcp);
530  /*
531  * Note: we can't call mbedtls_debug_set_threshold() here because
532  * it's global state. The user is thus expected to manage this.
533  */
534  }
535 
536  // load trusted CA
537  if (shr->ca_file) {
538  if ((ret = mbedtls_x509_crt_parse_file(&tls_ctx->ca_cert, shr->ca_file)) != 0) {
539  av_log(h, AV_LOG_ERROR, "mbedtls_x509_crt_parse_file for CA cert returned %d\n", ret);
540  goto fail;
541  }
542  }
543 
544  // load own certificate
545  if (shr->cert_file) {
546  if ((ret = mbedtls_x509_crt_parse_file(&tls_ctx->own_cert, shr->cert_file)) != 0) {
547  av_log(h, AV_LOG_ERROR, "mbedtls_x509_crt_parse_file for own cert returned %d\n", ret);
548  goto fail;
549  }
550  } else if (shr->cert_buf) {
551  if ((ret = mbedtls_x509_crt_parse(&tls_ctx->own_cert, shr->cert_buf, strlen(shr->cert_buf) + 1)) != 0) {
552  av_log(h, AV_LOG_ERROR, "mbedtls_x509_crt_parse for own cert returned %d\n", ret);
553  goto fail;
554  }
555  }
556 
557  // seed the random number generator
558  if ((ret = mbedtls_ctr_drbg_seed(&tls_ctx->ctr_drbg_context,
559  mbedtls_entropy_func,
560  &tls_ctx->entropy_context,
561  NULL, 0)) != 0) {
562  av_log(h, AV_LOG_ERROR, "mbedtls_ctr_drbg_seed returned %d\n", ret);
563  goto fail;
564  }
565 
566  // load key file
567  if (shr->key_file) {
568  if ((ret = mbedtls_pk_parse_keyfile(&tls_ctx->priv_key,
569  shr->key_file,
570  tls_ctx->priv_key_pw
571 #if MBEDTLS_VERSION_MAJOR >= 3
572  , mbedtls_ctr_drbg_random,
573  &tls_ctx->ctr_drbg_context
574 #endif
575  )) != 0) {
577  goto fail;
578  }
579  } else if (shr->key_buf) {
580  if ((ret = mbedtls_pk_parse_key(&tls_ctx->priv_key,
581  shr->key_buf,
582  strlen(shr->key_buf) + 1,
583  NULL,
584  0
585 #if MBEDTLS_VERSION_MAJOR >= 3
586  , mbedtls_ctr_drbg_random,
587  &tls_ctx->ctr_drbg_context
588 #endif
589  )) != 0) {
591  goto fail;
592  }
593  }
594 
595  if (shr->listen && !shr->cert_file && !shr->cert_buf && !shr->key_file && !shr->key_buf) {
596  char buf[4096];
597  if ((ret = mbedtls_gen_pkey(&tls_ctx->priv_key)) != 0) {
598  av_log(h, AV_LOG_ERROR, "failed to generate priv_key, returned %d\n", ret);
599  goto fail;
600  }
601  if ((ret = mbedtls_gen_x509_cert(&tls_ctx->priv_key, buf, sizeof(buf))) != 0) {
602  av_log(h, AV_LOG_ERROR, "failed to generate cert, returned %d\n", ret);
603  goto fail;
604  }
605  if ((ret = mbedtls_x509_crt_parse(&tls_ctx->own_cert, buf, sizeof(buf))) != 0) {
606  av_log(h, AV_LOG_ERROR, "failed to parse generated cert, returned %d\n", ret);
607  goto fail;
608  }
609  }
610 
611  if ((ret = mbedtls_ssl_config_defaults(&tls_ctx->ssl_config,
612  shr->listen ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT,
613  shr->is_dtls ? MBEDTLS_SSL_TRANSPORT_DATAGRAM : MBEDTLS_SSL_TRANSPORT_STREAM,
614  MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
615  av_log(h, AV_LOG_ERROR, "mbedtls_ssl_config_defaults returned %d\n", ret);
616  goto fail;
617  }
618 
619 #ifdef MBEDTLS_SSL_PROTO_TLS1_3
620  // this version does not allow disabling certificate verification with TLSv1.3 (yes, really).
621  if (mbedtls_version_get_number() == 0x03060000 && !shr->verify) {
622  av_log(h, AV_LOG_INFO, "Forcing TLSv1.2 because certificate verification is disabled\n");
623  mbedtls_ssl_conf_max_tls_version(&tls_ctx->ssl_config, MBEDTLS_SSL_VERSION_TLS1_2);
624  }
625 #endif
626 
627  // not VERIFY_REQUIRED because we manually check after handshake
628  mbedtls_ssl_conf_authmode(&tls_ctx->ssl_config,
629  shr->verify ? MBEDTLS_SSL_VERIFY_OPTIONAL : MBEDTLS_SSL_VERIFY_NONE);
630  mbedtls_ssl_conf_rng(&tls_ctx->ssl_config, mbedtls_ctr_drbg_random, &tls_ctx->ctr_drbg_context);
631  mbedtls_ssl_conf_ca_chain(&tls_ctx->ssl_config, &tls_ctx->ca_cert, NULL);
632 
633  // set own certificate and private key
634  if ((ret = mbedtls_ssl_conf_own_cert(&tls_ctx->ssl_config, &tls_ctx->own_cert, &tls_ctx->priv_key)) != 0) {
635  av_log(h, AV_LOG_ERROR, "mbedtls_ssl_conf_own_cert returned %d\n", ret);
636  goto fail;
637  }
638  if (shr->is_dtls) {
639  mbedtls_ssl_conf_dtls_cookies(&tls_ctx->ssl_config, NULL, NULL, NULL);
640  if (shr->use_srtp) {
641 #if defined(MBEDTLS_SSL_DTLS_SRTP)
642  if ((ret = mbedtls_ssl_conf_dtls_srtp_protection_profiles(&tls_ctx->ssl_config, profiles)) != 0) {
643  av_log(h, AV_LOG_ERROR, "mbedtls_ssl_conf_dtls_srtp_protection_profiles returned %d\n", ret);
644  goto fail;
645  }
646  mbedtls_ssl_set_export_keys_cb(&tls_ctx->ssl_context, dtls_srtp_key_derivation, &tls_ctx->srtp_key);
647 #else
648  av_log(h, AV_LOG_ERROR, "DTLS-SRTP is not supported in this mbedtls build\n");
649  ret = AVERROR(ENOSYS);
650  goto fail;
651 #endif
652  }
653 
654  }
655  if ((ret = mbedtls_ssl_setup(&tls_ctx->ssl_context, &tls_ctx->ssl_config)) != 0) {
656  av_log(h, AV_LOG_ERROR, "mbedtls_ssl_setup returned %d\n", ret);
657  goto fail;
658  }
659 
660  if (!shr->listen && !shr->numerichost) {
661  if ((ret = mbedtls_ssl_set_hostname(&tls_ctx->ssl_context, shr->host)) != 0) {
662  av_log(h, AV_LOG_ERROR, "mbedtls_ssl_set_hostname returned %d\n", ret);
663  goto fail;
664  }
665  }
666 
667  // set I/O functions to use FFmpeg internal code for transport layer
668  mbedtls_ssl_set_bio(&tls_ctx->ssl_context, tls_ctx, mbedtls_send, mbedtls_recv, NULL);
669 
670  if (shr->is_dtls) {
671  mbedtls_ssl_set_timer_cb(&tls_ctx->ssl_context, &tls_ctx->timer, mbedtls_timing_set_delay, mbedtls_timing_get_delay);
672  if (shr->mtu)
673  mbedtls_ssl_set_mtu(&tls_ctx->ssl_context, shr->mtu);
674  }
675  if (!shr->external_sock) {
676  ret = tls_handshake(h);
677  if (ret < 0)
678  goto fail;
679  }
680 
681  if (shr->verify) {
682  // check the result of the certificate verification
683  if ((verify_res_flags = mbedtls_ssl_get_verify_result(&tls_ctx->ssl_context)) != 0) {
684  av_log(h, AV_LOG_ERROR, "mbedtls_ssl_get_verify_result reported problems "\
685  "with the certificate verification, returned flags: %"PRIu32"\n",
686  verify_res_flags);
687  if (verify_res_flags & MBEDTLS_X509_BADCERT_NOT_TRUSTED)
688  av_log(h, AV_LOG_ERROR, "The certificate is not correctly signed by the trusted CA.\n");
689  goto fail;
690  }
691  }
692 
693  return 0;
694 
695 fail:
696  tls_close(h);
697  return AVERROR(EIO);
698 }
699 
700 static int dtls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
701 {
702  TLSContext *tls_ctx = h->priv_data;
703  TLSShared *shr = &tls_ctx->tls_shared;
704  shr->is_dtls = 1;
705  return tls_open(h, uri, flags, options);
706 }
707 
708 static int handle_tls_error(URLContext *h, const char* func_name, int ret)
709 {
710  switch (ret) {
711  case MBEDTLS_ERR_SSL_WANT_READ:
712  case MBEDTLS_ERR_SSL_WANT_WRITE:
713 #ifdef MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET
714  case MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET:
715 #endif
716  return AVERROR(EAGAIN);
717  case MBEDTLS_ERR_NET_SEND_FAILED:
718  case MBEDTLS_ERR_NET_RECV_FAILED:
719  return AVERROR(EIO);
720  case MBEDTLS_ERR_NET_CONN_RESET:
721  case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
722  av_log(h, AV_LOG_WARNING, "%s reported connection reset by peer\n", func_name);
723  return AVERROR_EOF;
724  default:
725  av_log(h, AV_LOG_ERROR, "%s returned -0x%x\n", func_name, -ret);
726  return AVERROR(EIO);
727  }
728 }
729 
730 static int tls_read(URLContext *h, uint8_t *buf, int size)
731 {
732  TLSContext *tls_ctx = h->priv_data;
733  TLSShared *shr = &tls_ctx->tls_shared;
734  URLContext *uc = shr->is_dtls ? shr->udp : shr->tcp;
735  int ret;
736 
737  uc->flags &= ~AVIO_FLAG_NONBLOCK;
738  uc->flags |= h->flags & AVIO_FLAG_NONBLOCK;
739  if ((ret = mbedtls_ssl_read(&tls_ctx->ssl_context, buf, size)) > 0) {
740  // return read length
741  return ret;
742  }
743 
744  return handle_tls_error(h, "mbedtls_ssl_read", ret);
745 }
746 
747 static int tls_write(URLContext *h, const uint8_t *buf, int size)
748 {
749  TLSContext *tls_ctx = h->priv_data;
750  TLSShared *shr = &tls_ctx->tls_shared;
751  URLContext *uc = shr->is_dtls ? shr->udp : shr->tcp;
752  int ret;
753 
754  uc->flags &= ~AVIO_FLAG_NONBLOCK;
755  uc->flags |= h->flags & AVIO_FLAG_NONBLOCK;
756  if ((ret = mbedtls_ssl_write(&tls_ctx->ssl_context, buf, size)) > 0) {
757  // return written length
758  return ret;
759  }
760 
761  return handle_tls_error(h, "mbedtls_ssl_write", ret);
762 }
763 
765 {
766  TLSContext *c = h->priv_data;
767  return ffurl_get_file_handle(c->tls_shared.tcp);
768 }
769 
771 {
772  TLSContext *s = h->priv_data;
773  return ffurl_get_short_seek(s->tls_shared.tcp);
774 }
775 
776 static const AVOption options[] = {
777  TLS_COMMON_OPTIONS(TLSContext, tls_shared), \
778  {"key_password", "Password for the private key file", OFFSET(priv_key_pw), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
779  { NULL }
780 };
781 
782 static const AVClass tls_class = {
783  .class_name = "tls",
784  .item_name = av_default_item_name,
785  .option = options,
786  .version = LIBAVUTIL_VERSION_INT,
787 };
788 
790  .name = "tls",
791  .url_open2 = tls_open,
792  .url_read = tls_read,
793  .url_write = tls_write,
794  .url_close = tls_close,
795  .url_get_file_handle = tls_get_file_handle,
796  .url_get_short_seek = tls_get_short_seek,
797  .priv_data_size = sizeof(TLSContext),
799  .priv_data_class = &tls_class,
800 };
801 
802 static const AVClass dtls_class = {
803  .class_name = "dtls",
804  .item_name = av_default_item_name,
805  .option = options,
806  .version = LIBAVUTIL_VERSION_INT,
807 };
808 
810  .name = "dtls",
811  .url_open2 = dtls_open,
812  .url_handshake = tls_handshake,
813  .url_read = tls_read,
814  .url_write = tls_write,
815  .url_close = tls_close,
816  .url_get_file_handle = tls_get_file_handle,
817  .url_get_short_seek = tls_get_short_seek,
818  .priv_data_size = sizeof(TLSContext),
820  .priv_data_class = &dtls_class,
821 };
flags
const SwsFlags flags[]
Definition: swscale.c:84
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
TLSContext
Definition: tls_gnutls.c:336
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
URL_PROTOCOL_FLAG_NETWORK
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:33
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
TLSContext::entropy_context
mbedtls_entropy_context entropy_context
Definition: tls_mbedtls.c:256
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
handle_pk_parse_error
static void handle_pk_parse_error(URLContext *h, int ret)
Definition: tls_mbedtls.c:419
ffurl_write
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: url.h:202
md
#define md
Definition: vf_colormatrix.c:101
AVOption
AVOption.
Definition: opt.h:429
mbedtls_x509_fingerprint
static int mbedtls_x509_fingerprint(char *cert_buf, size_t cert_sz, char **fingerprint)
Definition: tls_mbedtls.c:47
dtls_srtp_keys::randbytes
unsigned char randbytes[64]
Definition: tls_mbedtls.c:248
AVDictionary
Definition: dict.c:32
URLProtocol
Definition: url.h:51
av_basename
const char * av_basename(const char *path)
Thread safe basename.
Definition: avstring.c:253
sockaddr_storage
Definition: network.h:111
TLSShared::verify
int verify
Definition: tls.h:60
TLSShared::listen
int listen
Definition: tls.h:63
TLSContext::ctr_drbg_context
mbedtls_ctr_drbg_context ctr_drbg_context
Definition: tls_mbedtls.c:257
TLS_COMMON_OPTIONS
#define TLS_COMMON_OPTIONS(pstruct, options_field)
Definition: tls.h:108
ff_tls_set_external_socket
int ff_tls_set_external_socket(URLContext *h, URLContext *sock)
Definition: tls_mbedtls.c:268
ffurl_get_short_seek
int ffurl_get_short_seek(void *urlcontext)
Return the current short seek threshold value for this URL.
Definition: avio.c:844
gmtime_r
#define gmtime_r
Definition: time_internal.h:34
AVERROR_BUFFER_TOO_SMALL
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition: error.h:53
TLSContext::ca_cert
mbedtls_x509_crt ca_cert
Definition: tls_mbedtls.c:259
tls_close
static int tls_close(URLContext *h)
Definition: tls_mbedtls.c:331
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:236
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
mbedtls_recv
static int mbedtls_recv(void *ctx, unsigned char *buf, size_t len)
Definition: tls_mbedtls.c:381
s
#define s(width, name)
Definition: cbs_vp9.c:198
dtls_srtp_keys::tls_prf_type
mbedtls_tls_prf_types tls_prf_type
Definition: tls_mbedtls.c:249
TLS_OPTFL
#define TLS_OPTFL
Definition: tls.h:89
URLContext::flags
int flags
Definition: url.h:40
TLSContext::priv_key
mbedtls_pk_context priv_key
Definition: tls_mbedtls.c:261
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
TLSContext::ssl_context
mbedtls_ssl_context ssl_context
Definition: tls_mbedtls.c:254
tls_handshake
static int tls_handshake(URLContext *h)
Definition: tls_mbedtls.c:473
key
const char * key
Definition: hwcontext_opencl.c:189
TLSContext::timer
mbedtls_timing_delay_context timer
Definition: tls_mbedtls.c:258
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:472
fail
#define fail
Definition: test.h:478
ff_udp_set_remote_addr
int ff_udp_set_remote_addr(URLContext *h, const struct sockaddr *dest_addr, socklen_t dest_addr_len, int do_connect)
This function is identical to ff_udp_set_remote_url, except that it takes a sockaddr directly.
Definition: udp.c:472
internal.h
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
mbedtls_gen_x509_cert
static int mbedtls_gen_x509_cert(mbedtls_pk_context *key, char *cert_buf, size_t cert_sz)
Definition: tls_mbedtls.c:151
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
ff_udp_get_last_recv_addr
void ff_udp_get_last_recv_addr(URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len)
Definition: udp.c:510
parseutils.h
options
Definition: swscale.c:49
dtls_srtp_keys::master_secret
unsigned char master_secret[48]
Definition: tls_mbedtls.c:247
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
TLSShared::host
char * host
Definition: tls.h:65
OFFSET
#define OFFSET(x)
Definition: tls_mbedtls.c:329
TLSShared::cert_buf
char * cert_buf
Definition: tls.h:79
ff_tls_protocol
const URLProtocol ff_tls_protocol
Definition: tls_mbedtls.c:789
ff_dtls_export_materials
int ff_dtls_export_materials(URLContext *h, char *dtls_srtp_materials, size_t materials_sz)
Definition: tls_mbedtls.c:302
ff_url_read_all
int ff_url_read_all(const char *url, AVBPrint *bp)
Read all data from the given URL url and store it in the given buffer bp.
Definition: tls.c:128
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
TLSContext::ssl_config
mbedtls_ssl_config ssl_config
Definition: tls_mbedtls.c:255
TLSShared::external_sock
int external_sock
Definition: tls.h:71
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
mbedtls_send
static int mbedtls_send(void *ctx, const unsigned char *buf, size_t len)
Definition: tls_mbedtls.c:366
dtls_srtp_keys
Definition: tls_mbedtls.c:246
ff_ssl_gen_key_cert
int ff_ssl_gen_key_cert(char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint)
Definition: tls_mbedtls.c:221
size
int size
Definition: twinvq_data.h:10344
ff_ssl_read_key_cert
int ff_ssl_read_key_cert(char *key_url, char *cert_url, char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint)
Definition: tls_mbedtls.c:76
handle_handshake_error
static void handle_handshake_error(URLContext *h, int ret)
Definition: tls_mbedtls.c:437
TLSContext::tls_shared
TLSShared tls_shared
Definition: tls_gnutls.c:337
URLProtocol::name
const char * name
Definition: url.h:52
tls_read
static int tls_read(URLContext *h, uint8_t *buf, int size)
Definition: tls_mbedtls.c:730
line
Definition: graph2dot.c:48
handle_transport_error
static int handle_transport_error(URLContext *h, const char *func_name, int react_on_eagain, int ret)
Definition: tls_mbedtls.c:349
TLSShared::key_buf
char * key_buf
Definition: tls.h:80
dtls_class
static const AVClass dtls_class
Definition: tls_mbedtls.c:802
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
options
static const AVOption options[]
Definition: tls_mbedtls.c:776
TLSContext::dest_addr
struct sockaddr_storage dest_addr
Definition: tls_gnutls.c:342
ff_is_dtls_packet
int ff_is_dtls_packet(const uint8_t *buf, int size)
Whether the packet is a DTLS packet, as defined by RFC 5764 Section 5.1.2.
Definition: tls.c:167
URLContext
Definition: url.h:35
TLSContext::dest_addr_len
socklen_t dest_addr_len
Definition: tls_gnutls.c:343
url.h
av_random_bytes
int av_random_bytes(uint8_t *buf, size_t len)
Generate cryptographically secure random data, i.e.
Definition: random_seed.c:159
len
int len
Definition: vorbis_enc_data.h:426
TLSShared::cert_file
char * cert_file
Definition: tls.h:61
ffurl_closep
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:594
ff_tls_open_underlying
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
Definition: tls.c:54
ret
ret
Definition: filter_design.txt:187
TLSShared::is_dtls
int is_dtls
Definition: tls.h:75
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
TLSShared::ca_file
char * ca_file
Definition: tls.h:59
ff_dtls_protocol
const URLProtocol ff_dtls_protocol
Definition: tls_mbedtls.c:809
avformat.h
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
network.h
tls_class
static const AVClass tls_class
Definition: tls_mbedtls.c:782
tls.h
dtls_open
static int dtls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
Definition: tls_mbedtls.c:700
random_seed.h
TLSContext::own_cert
mbedtls_x509_crt own_cert
Definition: tls_mbedtls.c:260
TLSShared::key_file
char * key_file
Definition: tls.h:62
tls_get_short_seek
static int tls_get_short_seek(URLContext *h)
Definition: tls_mbedtls.c:770
profiles
static const AVProfile profiles[]
Definition: libfdk-aacenc.c:557
tls_open
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
Definition: tls_mbedtls.c:496
TLSShared::use_srtp
int use_srtp
Definition: tls.h:76
mbedtls_debug
static void mbedtls_debug(void *ctx, int lvl, const char *file, int line, const char *msg)
Definition: tls_mbedtls.c:412
mem.h
MAX_CERTIFICATE_SIZE
#define MAX_CERTIFICATE_SIZE
Maximum size limit of a certificate and private key size.
Definition: tls.h:35
TLSShared::mtu
int mtu
The size of RTP packet, should generally be set to MTU.
Definition: tls.h:86
tls_write
static int tls_write(URLContext *h, const uint8_t *buf, int size)
Definition: tls_mbedtls.c:747
TLSShared
Definition: tls.h:57
AVIO_FLAG_NONBLOCK
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Definition: avio.h:636
TLSShared::udp
URLContext * udp
Definition: tls.h:72
handle_tls_error
static int handle_tls_error(URLContext *h, const char *func_name, int ret)
Definition: tls_mbedtls.c:708
tls_get_file_handle
static int tls_get_file_handle(URLContext *h)
Definition: tls_mbedtls.c:764
TLSContext::priv_key_pw
char * priv_key_pw
Definition: tls_mbedtls.c:262
TLSShared::numerichost
int numerichost
Definition: tls.h:69
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2070
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
ffurl_get_file_handle
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Definition: avio.c:820
mbedtls_gen_pkey
static int mbedtls_gen_pkey(mbedtls_pk_context *key)
Definition: tls_mbedtls.c:113
TLSShared::tcp
URLContext * tcp
Definition: tls.h:73
ffurl_read
static int ffurl_read(URLContext *h, uint8_t *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.
Definition: url.h:181
TLSContext::srtp_key
dtls_srtp_keys srtp_key
Definition: tls_mbedtls.c:263