35 #include <openssl/bio.h>
36 #include <openssl/ssl.h>
37 #include <openssl/err.h>
46 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
51 #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
52 #include <openssl/crypto.h>
54 static void openssl_lock(
int mode,
int type,
const char *file,
int line)
56 if (
mode & CRYPTO_LOCK)
61 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
62 static unsigned long openssl_thread_id(
void)
64 return (intptr_t) pthread_self();
78 #if OPENSSL_VERSION_NUMBER < 0x10100000L
80 SSL_load_error_strings();
82 #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
83 if (!CRYPTO_get_locking_callback()) {
86 if (!openssl_mutexes) {
91 for (
i = 0;
i < CRYPTO_num_locks();
i++)
93 CRYPTO_set_locking_callback(openssl_lock);
94 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
95 CRYPTO_set_id_callback(openssl_thread_id);
111 #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L
112 if (CRYPTO_get_locking_callback() == openssl_lock) {
114 CRYPTO_set_locking_callback(
NULL);
115 for (
i = 0;
i < CRYPTO_num_locks();
i++)
128 int err = SSL_get_error(
c->ssl, ret);
129 if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
140 SSL_shutdown(
c->ssl);
144 SSL_CTX_free(
c->ctx);
146 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
147 if (
c->url_bio_method)
148 BIO_meth_free(
c->url_bio_method);
156 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
158 BIO_set_data(
b,
NULL);
173 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
174 #define GET_BIO_DATA(x) BIO_get_data(x)
176 #define GET_BIO_DATA(x) (x)->ptr
185 BIO_clear_retry_flags(
b);
187 BIO_set_retry_read(
b);
199 BIO_clear_retry_flags(
b);
201 BIO_set_retry_write(
b);
209 if (cmd == BIO_CTRL_FLUSH) {
210 BIO_clear_retry_flags(
b);
221 #if OPENSSL_VERSION_NUMBER < 0x1010000fL
223 .type = BIO_TYPE_SOURCE_SINK,
224 .name =
"urlprotocol bio",
252 p->
ctx = SSL_CTX_new(
c->listen ? SSLv23_server_method() : SSLv23_client_method());
258 SSL_CTX_set_options(p->
ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
260 if (!SSL_CTX_load_verify_locations(p->
ctx,
c->ca_file,
NULL))
263 if (
c->cert_file && !SSL_CTX_use_certificate_chain_file(p->
ctx,
c->cert_file)) {
265 c->cert_file, ERR_error_string(ERR_get_error(),
NULL));
269 if (
c->key_file && !SSL_CTX_use_PrivateKey_file(p->
ctx,
c->key_file, SSL_FILETYPE_PEM)) {
271 c->key_file, ERR_error_string(ERR_get_error(),
NULL));
278 SSL_CTX_set_verify(p->
ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
NULL);
285 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
286 p->url_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK,
"urlprotocol bio");
293 bio = BIO_new(p->url_bio_method);
294 BIO_set_data(bio,
c->tcp);
299 SSL_set_bio(p->
ssl, bio, bio);
300 if (!
c->listen && !
c->numerichost)
301 SSL_set_tlsext_host_name(p->
ssl,
c->host);
302 ret =
c->listen ? SSL_accept(p->
ssl) : SSL_connect(p->
ssl);
307 }
else if (ret < 0) {
325 ret = SSL_read(
c->ssl, buf,
size);
340 ret = SSL_write(
c->ssl, buf,
size);
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.
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Convenience header that includes libavutil's core.
#define flags(name, subs,...)
mode
Use these values in ebur128_init (or'ed).
#define pthread_mutex_lock(a)
#define pthread_mutex_unlock(a)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_EOF
End of file.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
common internal api header.
common internal API header
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
miscellaneous OS support macros and functions.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_malloc_array(a, b)
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
#define TLS_COMMON_OPTIONS(pstruct, options_field)
int ff_openssl_init(void)
static BIO_METHOD url_bio_method
static int tls_close(URLContext *h)
static const AVClass tls_class
const URLProtocol ff_tls_protocol
static const AVOption options[]
static int tls_read(URLContext *h, uint8_t *buf, int size)
static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
static int url_bio_bread(BIO *b, char *buf, int len)
static int url_bio_bputs(BIO *b, const char *str)
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
static int url_bio_destroy(BIO *b)
static int url_bio_bwrite(BIO *b, const char *buf, int len)
static int tls_get_short_seek(URLContext *h)
static int tls_write(URLContext *h, const uint8_t *buf, int size)
static int print_tls_error(URLContext *h, int ret)
void ff_openssl_deinit(void)
static int tls_get_file_handle(URLContext *h)
static int url_bio_create(BIO *b)
unbuffered private I/O API
#define URL_PROTOCOL_FLAG_NETWORK