35 #include <openssl/bio.h>
36 #include <openssl/ssl.h>
37 #include <openssl/err.h>
46 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
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();
71 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
73 BIO_set_data(b,
NULL);
88 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
89 #define GET_BIO_DATA(x) BIO_get_data(x)
91 #define GET_BIO_DATA(x) (x)->ptr
100 BIO_clear_retry_flags(b);
112 BIO_clear_retry_flags(b);
120 if (cmd == BIO_CTRL_FLUSH) {
121 BIO_clear_retry_flags(b);
132 #if OPENSSL_VERSION_NUMBER < 0x1010000fL
134 .type = BIO_TYPE_SOURCE_SINK,
135 .name =
"urlprotocol bio",
151 SSL_load_error_strings();
153 if (!CRYPTO_get_locking_callback()) {
156 if (!openssl_mutexes) {
161 for (i = 0; i < CRYPTO_num_locks(); i++)
163 CRYPTO_set_locking_callback(openssl_lock);
164 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
165 CRYPTO_set_id_callback(openssl_thread_id);
182 if (CRYPTO_get_locking_callback() == openssl_lock) {
184 CRYPTO_set_locking_callback(
NULL);
185 for (i = 0; i < CRYPTO_num_locks(); i++)
204 SSL_shutdown(c->
ssl);
208 SSL_CTX_free(c->
ctx);
211 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
212 if (c->url_bio_method)
213 BIO_meth_free(c->url_bio_method);
236 p->
ctx = SSL_CTX_new(c->
listen ? SSLv23_server_method() : SSLv23_client_method());
242 SSL_CTX_set_options(p->
ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
262 SSL_CTX_set_verify(p->
ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
NULL);
269 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
270 p->url_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK,
"urlprotocol bio");
277 bio = BIO_new(p->url_bio_method);
278 BIO_set_data(bio, c->
tcp);
280 bio = BIO_new(&url_bio_method);
283 SSL_set_bio(p->
ssl, bio, bio);
285 SSL_set_tlsext_host_name(p->
ssl, c->
host);
286 ret = c->
listen ? SSL_accept(p->
ssl) : SSL_connect(p->
ssl);
291 }
else if (ret < 0) {
305 int ret = SSL_read(c->
ssl, buf, size);
316 int ret = SSL_write(c->
ssl, buf, size);
351 .priv_data_class = &tls_class,
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
#define URL_PROTOCOL_FLAG_NETWORK
#define pthread_mutex_lock(a)
int avpriv_unlock_avformat(void)
#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.
static int url_bio_bwrite(BIO *b, const char *buf, int len)
Convenience header that includes libavutil's core.
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 int url_bio_bread(BIO *b, char *buf, int len)
miscellaneous OS support macros and functions.
static int url_bio_bputs(BIO *b, const char *str)
const URLProtocol ff_tls_openssl_protocol
#define AVERROR_EOF
End of file.
static int tls_get_file_handle(URLContext *h)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
int avpriv_lock_avformat(void)
static const AVOption options[]
void ff_openssl_deinit(void)
static const AVClass tls_class
#define TLS_COMMON_OPTIONS(pstruct, options_field)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
static int tls_write(URLContext *h, const uint8_t *buf, int size)
#define pthread_mutex_unlock(a)
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.
static int url_bio_destroy(BIO *b)
static int print_tls_error(URLContext *h, int ret)
int ff_openssl_init(void)
static int tls_read(URLContext *h, uint8_t *buf, int size)
Describe the class of an AVClass context structure.
static int tls_close(URLContext *h)
int ffurl_close(URLContext *h)
common internal api header.
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
static BIO_METHOD url_bio_method
static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
unbuffered private I/O API
#define av_malloc_array(a, b)
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...
mode
Use these values in ebur128_init (or'ed).
static int url_bio_create(BIO *b)