2011-02-05 22:19:49 +00:00
|
|
|
/*
|
|
|
|
* TLS/SSL Protocol
|
|
|
|
* Copyright (c) 2011 Martin Storsjo
|
|
|
|
*
|
2013-08-15 21:12:51 +00:00
|
|
|
* This file is part of FFmpeg.
|
2011-02-05 22:19:49 +00:00
|
|
|
*
|
2013-08-15 21:12:51 +00:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2011-02-05 22:19:49 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2013-08-15 21:12:51 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2011-02-05 22:19:49 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2013-08-15 21:12:51 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2011-02-05 22:19:49 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
|
|
|
#include "url.h"
|
|
|
|
#include "libavutil/avstring.h"
|
2011-02-22 10:02:01 +00:00
|
|
|
#include "libavutil/opt.h"
|
2012-07-22 04:24:43 +00:00
|
|
|
#include "libavutil/parseutils.h"
|
2014-01-20 12:13:51 +00:00
|
|
|
#include "network.h"
|
|
|
|
#include "os_support.h"
|
|
|
|
#include "internal.h"
|
2011-02-05 22:19:49 +00:00
|
|
|
#if CONFIG_GNUTLS
|
|
|
|
#include <gnutls/gnutls.h>
|
2011-02-22 10:02:01 +00:00
|
|
|
#include <gnutls/x509.h>
|
2011-02-05 22:19:49 +00:00
|
|
|
#define TLS_read(c, buf, size) gnutls_record_recv(c->session, buf, size)
|
|
|
|
#define TLS_write(c, buf, size) gnutls_record_send(c->session, buf, size)
|
|
|
|
#define TLS_shutdown(c) gnutls_bye(c->session, GNUTLS_SHUT_RDWR)
|
|
|
|
#define TLS_free(c) do { \
|
|
|
|
if (c->session) \
|
|
|
|
gnutls_deinit(c->session); \
|
|
|
|
if (c->cred) \
|
|
|
|
gnutls_certificate_free_credentials(c->cred); \
|
|
|
|
} while (0)
|
|
|
|
#elif CONFIG_OPENSSL
|
|
|
|
#include <openssl/bio.h>
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#define TLS_read(c, buf, size) SSL_read(c->ssl, buf, size)
|
|
|
|
#define TLS_write(c, buf, size) SSL_write(c->ssl, buf, size)
|
|
|
|
#define TLS_shutdown(c) SSL_shutdown(c->ssl)
|
|
|
|
#define TLS_free(c) do { \
|
|
|
|
if (c->ssl) \
|
|
|
|
SSL_free(c->ssl); \
|
|
|
|
if (c->ctx) \
|
|
|
|
SSL_CTX_free(c->ctx); \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
#if HAVE_POLL_H
|
|
|
|
#include <poll.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const AVClass *class;
|
|
|
|
URLContext *tcp;
|
|
|
|
#if CONFIG_GNUTLS
|
|
|
|
gnutls_session_t session;
|
|
|
|
gnutls_certificate_credentials_t cred;
|
|
|
|
#elif CONFIG_OPENSSL
|
|
|
|
SSL_CTX *ctx;
|
|
|
|
SSL *ssl;
|
|
|
|
#endif
|
|
|
|
int fd;
|
2011-02-22 10:02:01 +00:00
|
|
|
char *ca_file;
|
|
|
|
int verify;
|
2013-09-19 09:30:52 +00:00
|
|
|
char *cert_file;
|
|
|
|
char *key_file;
|
|
|
|
int listen;
|
2011-02-05 22:19:49 +00:00
|
|
|
} TLSContext;
|
|
|
|
|
2011-02-22 10:02:01 +00:00
|
|
|
#define OFFSET(x) offsetof(TLSContext, x)
|
|
|
|
#define D AV_OPT_FLAG_DECODING_PARAM
|
|
|
|
#define E AV_OPT_FLAG_ENCODING_PARAM
|
|
|
|
static const AVOption options[] = {
|
|
|
|
{"ca_file", "Certificate Authority database file", OFFSET(ca_file), AV_OPT_TYPE_STRING, .flags = D|E },
|
2013-09-27 07:22:42 +00:00
|
|
|
{"cafile", "Certificate Authority database file", OFFSET(ca_file), AV_OPT_TYPE_STRING, .flags = D|E },
|
2011-02-22 10:02:01 +00:00
|
|
|
{"tls_verify", "Verify the peer certificate", OFFSET(verify), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = D|E },
|
2013-09-19 09:30:52 +00:00
|
|
|
{"cert_file", "Certificate file", OFFSET(cert_file), AV_OPT_TYPE_STRING, .flags = D|E },
|
|
|
|
{"key_file", "Private key file", OFFSET(key_file), AV_OPT_TYPE_STRING, .flags = D|E },
|
|
|
|
{"listen", "Listen for incoming connections", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = D|E },
|
2011-02-22 10:02:01 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass tls_class = {
|
|
|
|
.class_name = "tls",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2011-02-05 22:19:49 +00:00
|
|
|
static int do_tls_poll(URLContext *h, int ret)
|
|
|
|
{
|
|
|
|
TLSContext *c = h->priv_data;
|
|
|
|
struct pollfd p = { c->fd, 0, 0 };
|
|
|
|
#if CONFIG_GNUTLS
|
2013-09-21 22:02:36 +00:00
|
|
|
switch (ret) {
|
|
|
|
case GNUTLS_E_AGAIN:
|
|
|
|
case GNUTLS_E_INTERRUPTED:
|
|
|
|
break;
|
|
|
|
case GNUTLS_E_WARNING_ALERT_RECEIVED:
|
|
|
|
av_log(h, AV_LOG_WARNING, "%s\n", gnutls_strerror(ret));
|
|
|
|
break;
|
|
|
|
default:
|
2011-11-10 15:52:38 +00:00
|
|
|
av_log(h, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret));
|
2011-02-05 22:19:49 +00:00
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
if (gnutls_record_get_direction(c->session))
|
|
|
|
p.events = POLLOUT;
|
|
|
|
else
|
|
|
|
p.events = POLLIN;
|
|
|
|
#elif CONFIG_OPENSSL
|
|
|
|
ret = SSL_get_error(c->ssl, ret);
|
|
|
|
if (ret == SSL_ERROR_WANT_READ) {
|
|
|
|
p.events = POLLIN;
|
|
|
|
} else if (ret == SSL_ERROR_WANT_WRITE) {
|
|
|
|
p.events = POLLOUT;
|
|
|
|
} else {
|
2011-11-10 15:52:38 +00:00
|
|
|
av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
|
2011-02-05 22:19:49 +00:00
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-05 11:48:02 +00:00
|
|
|
if (h->flags & AVIO_FLAG_NONBLOCK)
|
2011-02-05 22:19:49 +00:00
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
while (1) {
|
|
|
|
int n = poll(&p, 1, 100);
|
|
|
|
if (n > 0)
|
|
|
|
break;
|
2011-11-06 20:34:24 +00:00
|
|
|
if (ff_check_interrupt(&h->interrupt_callback))
|
2011-02-05 22:19:49 +00:00
|
|
|
return AVERROR(EINTR);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-22 04:24:43 +00:00
|
|
|
static void set_options(URLContext *h, const char *uri)
|
|
|
|
{
|
|
|
|
TLSContext *c = h->priv_data;
|
2013-09-27 09:21:42 +00:00
|
|
|
char buf[1024];
|
2012-07-22 04:24:43 +00:00
|
|
|
const char *p = strchr(uri, '?');
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
2013-09-27 07:22:42 +00:00
|
|
|
if (!c->ca_file && av_find_info_tag(buf, sizeof(buf), "cafile", p))
|
|
|
|
c->ca_file = av_strdup(buf);
|
2012-07-22 04:24:43 +00:00
|
|
|
|
2013-09-27 07:22:42 +00:00
|
|
|
if (!c->verify && av_find_info_tag(buf, sizeof(buf), "verify", p)) {
|
2012-07-22 04:24:53 +00:00
|
|
|
char *endptr = NULL;
|
2013-09-27 07:22:42 +00:00
|
|
|
c->verify = strtol(buf, &endptr, 10);
|
2012-07-22 04:24:53 +00:00
|
|
|
if (buf == endptr)
|
2013-09-27 07:22:42 +00:00
|
|
|
c->verify = 1;
|
2012-07-22 04:24:53 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 09:21:42 +00:00
|
|
|
if (!c->cert_file && av_find_info_tag(buf, sizeof(buf), "cert", p))
|
|
|
|
c->cert_file = av_strdup(buf);
|
|
|
|
|
|
|
|
if (!c->key_file && av_find_info_tag(buf, sizeof(buf), "key", p))
|
|
|
|
c->key_file = av_strdup(buf);
|
2012-07-22 04:24:43 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 22:19:49 +00:00
|
|
|
static int tls_open(URLContext *h, const char *uri, int flags)
|
|
|
|
{
|
|
|
|
TLSContext *c = h->priv_data;
|
|
|
|
int ret;
|
|
|
|
int port;
|
2013-09-19 09:30:52 +00:00
|
|
|
char buf[200], host[200], opts[50] = "";
|
2011-02-05 22:19:49 +00:00
|
|
|
int numerichost = 0;
|
|
|
|
struct addrinfo hints = { 0 }, *ai = NULL;
|
2011-11-10 13:26:23 +00:00
|
|
|
const char *proxy_path;
|
|
|
|
int use_proxy;
|
2012-07-22 04:25:12 +00:00
|
|
|
const char *p = strchr(uri, '?');
|
2011-02-05 22:19:49 +00:00
|
|
|
|
|
|
|
ff_tls_init();
|
|
|
|
|
2013-09-27 09:21:42 +00:00
|
|
|
if(p && av_find_info_tag(buf, sizeof(buf), "listen", p))
|
|
|
|
c->listen = 1;
|
2013-09-19 09:30:52 +00:00
|
|
|
if (c->listen)
|
|
|
|
snprintf(opts, sizeof(opts), "?listen=1");
|
|
|
|
|
2011-02-05 22:19:49 +00:00
|
|
|
av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, uri);
|
2013-09-19 09:30:52 +00:00
|
|
|
ff_url_join(buf, sizeof(buf), "tcp", NULL, host, port, "%s", opts);
|
2011-02-05 22:19:49 +00:00
|
|
|
|
|
|
|
hints.ai_flags = AI_NUMERICHOST;
|
|
|
|
if (!getaddrinfo(host, NULL, &hints, &ai)) {
|
|
|
|
numerichost = 1;
|
|
|
|
freeaddrinfo(ai);
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:13:47 +00:00
|
|
|
proxy_path = getenv("http_proxy");
|
|
|
|
use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), host) &&
|
|
|
|
proxy_path != NULL && av_strstart(proxy_path, "http://", NULL);
|
|
|
|
|
2011-11-10 13:26:23 +00:00
|
|
|
if (use_proxy) {
|
|
|
|
char proxy_host[200], proxy_auth[200], dest[200];
|
|
|
|
int proxy_port;
|
|
|
|
av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth),
|
|
|
|
proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0,
|
|
|
|
proxy_path);
|
|
|
|
ff_url_join(dest, sizeof(dest), NULL, NULL, host, port, NULL);
|
|
|
|
ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host,
|
|
|
|
proxy_port, "/%s", dest);
|
|
|
|
}
|
|
|
|
|
2011-11-05 09:04:04 +00:00
|
|
|
ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
|
|
|
|
&h->interrupt_callback, NULL);
|
2011-02-05 22:19:49 +00:00
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
c->fd = ffurl_get_file_handle(c->tcp);
|
|
|
|
|
|
|
|
#if CONFIG_GNUTLS
|
2013-09-19 09:30:52 +00:00
|
|
|
gnutls_init(&c->session, c->listen ? GNUTLS_SERVER : GNUTLS_CLIENT);
|
|
|
|
if (!c->listen && !numerichost)
|
2011-02-05 22:19:49 +00:00
|
|
|
gnutls_server_name_set(c->session, GNUTLS_NAME_DNS, host, strlen(host));
|
|
|
|
gnutls_certificate_allocate_credentials(&c->cred);
|
2012-07-22 04:24:43 +00:00
|
|
|
set_options(h, uri);
|
2013-09-27 07:22:42 +00:00
|
|
|
if (c->ca_file) {
|
|
|
|
ret = gnutls_certificate_set_x509_trust_file(c->cred, c->ca_file, GNUTLS_X509_FMT_PEM);
|
|
|
|
if (ret < 0)
|
|
|
|
av_log(h, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret));
|
|
|
|
}
|
2011-02-22 10:02:01 +00:00
|
|
|
#if GNUTLS_VERSION_MAJOR >= 3
|
|
|
|
else
|
|
|
|
gnutls_certificate_set_x509_system_trust(c->cred);
|
|
|
|
#endif
|
|
|
|
gnutls_certificate_set_verify_flags(c->cred, c->verify ?
|
|
|
|
GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT : 0);
|
2013-09-19 09:30:52 +00:00
|
|
|
if (c->cert_file && c->key_file) {
|
|
|
|
ret = gnutls_certificate_set_x509_key_file(c->cred,
|
|
|
|
c->cert_file, c->key_file,
|
|
|
|
GNUTLS_X509_FMT_PEM);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(h, AV_LOG_ERROR,
|
|
|
|
"Unable to set cert/key files %s and %s: %s\n",
|
|
|
|
c->cert_file, c->key_file, gnutls_strerror(ret));
|
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-09-27 13:55:11 +00:00
|
|
|
} else if (c->cert_file || c->key_file)
|
2013-09-27 09:21:42 +00:00
|
|
|
av_log(h, AV_LOG_ERROR, "cert and key required\n");
|
2011-02-05 22:19:49 +00:00
|
|
|
gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, c->cred);
|
|
|
|
gnutls_transport_set_ptr(c->session, (gnutls_transport_ptr_t)
|
|
|
|
(intptr_t) c->fd);
|
|
|
|
gnutls_priority_set_direct(c->session, "NORMAL", NULL);
|
|
|
|
while (1) {
|
|
|
|
ret = gnutls_handshake(c->session);
|
|
|
|
if (ret == 0)
|
|
|
|
break;
|
|
|
|
if ((ret = do_tls_poll(h, ret)) < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-02-22 10:02:01 +00:00
|
|
|
if (c->verify) {
|
|
|
|
unsigned int status, cert_list_size;
|
|
|
|
gnutls_x509_crt_t cert;
|
|
|
|
const gnutls_datum_t *cert_list;
|
|
|
|
if ((ret = gnutls_certificate_verify_peers2(c->session, &status)) < 0) {
|
|
|
|
av_log(h, AV_LOG_ERROR, "Unable to verify peer certificate: %s\n",
|
|
|
|
gnutls_strerror(ret));
|
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (status & GNUTLS_CERT_INVALID) {
|
|
|
|
av_log(h, AV_LOG_ERROR, "Peer certificate failed verification\n");
|
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (gnutls_certificate_type_get(c->session) != GNUTLS_CRT_X509) {
|
|
|
|
av_log(h, AV_LOG_ERROR, "Unsupported certificate type\n");
|
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
gnutls_x509_crt_init(&cert);
|
|
|
|
cert_list = gnutls_certificate_get_peers(c->session, &cert_list_size);
|
|
|
|
gnutls_x509_crt_import(cert, cert_list, GNUTLS_X509_FMT_DER);
|
|
|
|
ret = gnutls_x509_crt_check_hostname(cert, host);
|
|
|
|
gnutls_x509_crt_deinit(cert);
|
|
|
|
if (!ret) {
|
|
|
|
av_log(h, AV_LOG_ERROR,
|
|
|
|
"The certificate's owner does not match hostname %s\n", host);
|
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2011-02-05 22:19:49 +00:00
|
|
|
#elif CONFIG_OPENSSL
|
2013-09-19 09:30:52 +00:00
|
|
|
c->ctx = SSL_CTX_new(c->listen ? TLSv1_server_method() : TLSv1_client_method());
|
2011-02-05 22:19:49 +00:00
|
|
|
if (!c->ctx) {
|
2011-11-10 15:52:38 +00:00
|
|
|
av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
|
2011-02-05 22:19:49 +00:00
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-07-22 04:24:43 +00:00
|
|
|
set_options(h, uri);
|
2013-09-27 07:22:42 +00:00
|
|
|
if (c->ca_file) {
|
|
|
|
if (!SSL_CTX_load_verify_locations(c->ctx, c->ca_file, NULL))
|
|
|
|
av_log(h, AV_LOG_ERROR, "SSL_CTX_load_verify_locations %s\n", ERR_error_string(ERR_get_error(), NULL));
|
|
|
|
}
|
2013-09-19 09:30:52 +00:00
|
|
|
if (c->cert_file && !SSL_CTX_use_certificate_chain_file(c->ctx, c->cert_file)) {
|
|
|
|
av_log(h, AV_LOG_ERROR, "Unable to load cert file %s: %s\n",
|
|
|
|
c->cert_file, ERR_error_string(ERR_get_error(), NULL));
|
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (c->key_file && !SSL_CTX_use_PrivateKey_file(c->ctx, c->key_file, SSL_FILETYPE_PEM)) {
|
|
|
|
av_log(h, AV_LOG_ERROR, "Unable to load key file %s: %s\n",
|
|
|
|
c->key_file, ERR_error_string(ERR_get_error(), NULL));
|
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-02-22 10:02:01 +00:00
|
|
|
// Note, this doesn't check that the peer certificate actually matches
|
|
|
|
// the requested hostname.
|
|
|
|
if (c->verify)
|
2013-09-27 07:22:42 +00:00
|
|
|
SSL_CTX_set_verify(c->ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
|
2011-02-05 22:19:49 +00:00
|
|
|
c->ssl = SSL_new(c->ctx);
|
|
|
|
if (!c->ssl) {
|
2011-11-10 15:52:38 +00:00
|
|
|
av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
|
2011-02-05 22:19:49 +00:00
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
SSL_set_fd(c->ssl, c->fd);
|
2013-09-19 09:30:52 +00:00
|
|
|
if (!c->listen && !numerichost)
|
2011-02-05 22:19:49 +00:00
|
|
|
SSL_set_tlsext_host_name(c->ssl, host);
|
|
|
|
while (1) {
|
2013-09-19 09:30:52 +00:00
|
|
|
ret = c->listen ? SSL_accept(c->ssl) : SSL_connect(c->ssl);
|
2011-02-05 22:19:49 +00:00
|
|
|
if (ret > 0)
|
|
|
|
break;
|
|
|
|
if (ret == 0) {
|
2011-11-10 15:52:38 +00:00
|
|
|
av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n");
|
2011-02-05 22:19:49 +00:00
|
|
|
ret = AVERROR(EIO);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if ((ret = do_tls_poll(h, ret)) < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
TLS_free(c);
|
|
|
|
if (c->tcp)
|
|
|
|
ffurl_close(c->tcp);
|
|
|
|
ff_tls_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tls_read(URLContext *h, uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
TLSContext *c = h->priv_data;
|
|
|
|
while (1) {
|
|
|
|
int ret = TLS_read(c, buf, size);
|
|
|
|
if (ret > 0)
|
|
|
|
return ret;
|
|
|
|
if (ret == 0)
|
2012-07-27 17:22:51 +00:00
|
|
|
return AVERROR_EOF;
|
2011-02-05 22:19:49 +00:00
|
|
|
if ((ret = do_tls_poll(h, ret)) < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tls_write(URLContext *h, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
TLSContext *c = h->priv_data;
|
|
|
|
while (1) {
|
|
|
|
int ret = TLS_write(c, buf, size);
|
|
|
|
if (ret > 0)
|
|
|
|
return ret;
|
|
|
|
if (ret == 0)
|
2012-07-27 17:22:51 +00:00
|
|
|
return AVERROR_EOF;
|
2011-02-05 22:19:49 +00:00
|
|
|
if ((ret = do_tls_poll(h, ret)) < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tls_close(URLContext *h)
|
|
|
|
{
|
|
|
|
TLSContext *c = h->priv_data;
|
|
|
|
TLS_shutdown(c);
|
|
|
|
TLS_free(c);
|
|
|
|
ffurl_close(c->tcp);
|
|
|
|
ff_tls_deinit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
URLProtocol ff_tls_protocol = {
|
|
|
|
.name = "tls",
|
|
|
|
.url_open = tls_open,
|
|
|
|
.url_read = tls_read,
|
|
|
|
.url_write = tls_write,
|
|
|
|
.url_close = tls_close,
|
|
|
|
.priv_data_size = sizeof(TLSContext),
|
2011-12-30 09:38:05 +00:00
|
|
|
.flags = URL_PROTOCOL_FLAG_NETWORK,
|
2011-02-22 10:02:01 +00:00
|
|
|
.priv_data_class = &tls_class,
|
2011-02-05 22:19:49 +00:00
|
|
|
};
|