35 #include <Security/Security.h>
36 #include <Security/SecureTransport.h>
37 #include <CoreFoundation/CoreFoundation.h>
40 SecIdentityRef
SecIdentityCreate(CFAllocatorRef allocator, SecCertificateRef certificate, SecKeyRef privateKey);
55 case errSSLWouldBlock:
57 case errSSLXCertChainInvalid:
75 SecExternalFormat format = kSecFormatPEMSequence;
76 SecExternalFormat
type = kSecItemTypeAggregate;
77 CFStringRef pathStr = CFStringCreateWithCString(
NULL, path, 0x08000100);
103 data = CFDataCreate(kCFAllocatorDefault, buf, ret);
105 if (SecItemImport(data, pathStr, &format, &type,
106 0,
NULL,
NULL, array) != noErr || !array) {
111 if (CFArrayGetCount(*array) == 0) {
131 CFArrayRef array =
NULL;
136 if (!(c->
ca_array = CFRetain(array))) {
151 CFArrayRef certArray =
NULL;
152 CFArrayRef keyArray =
NULL;
153 SecIdentityRef
id =
NULL;
154 CFMutableArrayRef outArray =
NULL;
163 (SecCertificateRef)CFArrayGetValueAtIndex(certArray, 0),
164 (SecKeyRef)CFArrayGetValueAtIndex(keyArray, 0)))) {
169 if (!(outArray = CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, certArray))) {
174 CFArraySetValueAtIndex(outArray, 0,
id);
180 CFRelease(certArray);
190 static OSStatus
tls_read_cb(SSLConnectionRef connection,
void *
data,
size_t *dataLength)
200 return errSSLClosedGraceful;
202 return errSSLClosedAbort;
204 return errSSLWouldBlock;
215 static OSStatus
tls_write_cb(SSLConnectionRef connection,
const void *
data,
size_t *dataLength)
224 return errSSLWouldBlock;
230 *dataLength = written;
249 #define CHECK_ERROR(func, ...) do { \
250 OSStatus status = func(__VA_ARGS__); \
251 if (status != noErr) { \
252 ret = AVERROR_UNKNOWN; \
253 av_log(h, AV_LOG_ERROR, #func ": Error %i\n", (int)status); \
267 c->
ssl_context = SSLCreateContext(
NULL, s->
listen ? kSSLServerSide : kSSLClientSide, kSSLStreamType);
287 if (status == errSSLServerAuthCompleted) {
288 SecTrustRef peerTrust;
289 SecTrustResultType trustResult;
293 if (SSLCopyPeerTrust(c->
ssl_context, &peerTrust) != noErr) {
298 if (SecTrustSetAnchorCertificates(peerTrust, c->
ca_array) != noErr) {
303 if (SecTrustEvaluate(peerTrust, &trustResult) != noErr) {
308 if (trustResult == kSecTrustResultProceed ||
309 trustResult == kSecTrustResultUnspecified) {
311 status = errSSLWouldBlock;
312 }
else if (trustResult == kSecTrustResultRecoverableTrustFailure) {
314 status = errSSLXCertChainInvalid;
317 status = errSSLBadCert;
321 CFRelease(peerTrust);
342 case errSSLClosedGraceful:
343 case errSSLClosedNoNotify:
394 .priv_data_class = &tls_class,
static const AVClass tls_class
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t avio_size(AVIOContext *s)
Get the filesize.
#define URL_PROTOCOL_FLAG_NETWORK
#define CHECK_ERROR(func,...)
ptrdiff_t const GLvoid * data
#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.
AVIOInterruptCB interrupt_callback
#define AVIO_FLAG_READ
read-only
static int tls_close(URLContext *h)
static int print_tls_error(URLContext *h, int ret)
static OSStatus tls_write_cb(SSLConnectionRef connection, const void *data, size_t *dataLength)
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
miscellaneous OS support macros and functions.
static av_cold int end(AVCodecContext *avctx)
#define AVERROR_EOF
End of file.
static int load_ca(URLContext *h)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
static int tls_read(URLContext *h, uint8_t *buf, int size)
static int import_pem(URLContext *h, char *path, CFArrayRef *array)
#define TLS_COMMON_OPTIONS(pstruct, options_field)
static int map_ssl_error(OSStatus status, size_t processed)
URLProtocol ff_tls_securetransport_protocol
Describe the class of an AVClass context structure.
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
SSLContextRef ssl_context
static const AVOption options[]
int ffurl_close(URLContext *h)
common internal api header.
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
Read as many bytes as possible (up to size), calling the read function multiple times if necessary...
static int tls_write(URLContext *h, const uint8_t *buf, int size)
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static OSStatus tls_read_cb(SSLConnectionRef connection, void *data, size_t *dataLength)
SecIdentityRef SecIdentityCreate(CFAllocatorRef allocator, SecCertificateRef certificate, SecKeyRef privateKey)
unbuffered private I/O API
static int load_cert(URLContext *h)