Go to the documentation of this file.
37 #include <Security/Security.h>
38 #include <Security/SecureTransport.h>
39 #include <CoreFoundation/CoreFoundation.h>
42 SecIdentityRef
SecIdentityCreate(CFAllocatorRef allocator, SecCertificateRef certificate, SecKeyRef privateKey);
57 case errSSLWouldBlock:
59 case errSSLXCertChainInvalid:
73 #if !HAVE_SECITEMIMPORT
80 SecExternalFormat
format = kSecFormatPEMSequence;
81 SecExternalFormat
type = kSecItemTypeAggregate;
82 CFStringRef pathStr = CFStringCreateWithCString(
NULL, path, 0x08000100);
89 &
h->interrupt_callback,
NULL,
90 h->protocol_whitelist,
h->protocol_blacklist)) < 0)
109 data = CFDataCreate(kCFAllocatorDefault, buf,
ret);
117 if (CFArrayGetCount(*
array) == 0) {
143 if (!(
c->ca_array = CFRetain(
array))) {
158 CFArrayRef certArray =
NULL;
159 CFArrayRef keyArray =
NULL;
160 SecIdentityRef
id =
NULL;
161 CFMutableArrayRef outArray =
NULL;
170 (SecCertificateRef)CFArrayGetValueAtIndex(certArray, 0),
171 (SecKeyRef)CFArrayGetValueAtIndex(keyArray, 0)))) {
176 if (!(outArray = CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, certArray))) {
181 CFArraySetValueAtIndex(outArray, 0,
id);
183 SSLSetCertificate(
c->ssl_context, outArray);
187 CFRelease(certArray);
197 static OSStatus
tls_read_cb(SSLConnectionRef connection,
void *
data,
size_t *dataLength)
201 size_t requested = *dataLength;
208 return errSSLClosedGraceful;
210 return errSSLClosedAbort;
212 return errSSLWouldBlock;
219 if (
read < requested)
220 return errSSLWouldBlock;
226 static OSStatus
tls_write_cb(SSLConnectionRef connection,
const void *
data,
size_t *dataLength)
235 return errSSLWouldBlock;
237 c->lastErr = written;
241 *dataLength = written;
249 if (
c->ssl_context) {
250 SSLClose(
c->ssl_context);
251 CFRelease(
c->ssl_context);
254 CFRelease(
c->ca_array);
259 #define CHECK_ERROR(func, ...) do { \
260 OSStatus status = func(__VA_ARGS__); \
261 if (status != noErr) { \
262 ret = AVERROR_UNKNOWN; \
263 av_log(h, AV_LOG_ERROR, #func ": Error %i\n", (int)status); \
277 c->ssl_context = SSLCreateContext(
NULL,
s->listen ? kSSLServerSide : kSSLClientSide, kSSLStreamType);
278 if (!
c->ssl_context) {
287 if (
s->ca_file || !
s->verify)
288 CHECK_ERROR(SSLSetSessionOption,
c->ssl_context, kSSLSessionOptionBreakOnServerAuth,
true);
292 CHECK_ERROR(SSLSetPeerDomainName,
c->ssl_context,
s->host, strlen(
s->host));
296 OSStatus
status = SSLHandshake(
c->ssl_context);
297 if (
status == errSSLServerAuthCompleted) {
298 SecTrustRef peerTrust;
299 SecTrustResultType trustResult;
303 if (SSLCopyPeerTrust(
c->ssl_context, &peerTrust) != noErr) {
308 if (SecTrustSetAnchorCertificates(peerTrust,
c->ca_array) != noErr) {
313 if (SecTrustEvaluate(peerTrust, &trustResult) != noErr) {
318 if (trustResult == kSecTrustResultProceed ||
319 trustResult == kSecTrustResultUnspecified) {
321 status = errSSLWouldBlock;
322 }
else if (trustResult == kSecTrustResultRecoverableTrustFailure) {
324 status = errSSLXCertChainInvalid;
331 CFRelease(peerTrust);
335 }
else if (
status != errSSLWouldBlock) {
353 case errSSLClosedGraceful:
354 case errSSLClosedNoNotify:
356 case errSSLWouldBlock:
369 SSLGetBufferedReadSize(
c->ssl_context, &
available);
int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
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
#define CHECK_ERROR(func,...)
#define URL_PROTOCOL_FLAG_NETWORK
#define AVERROR_EOF
End of file.
static int print_tls_error(URLContext *h, int ret)
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
static int map_ssl_error(OSStatus status, size_t processed)
static int tls_write(URLContext *h, const uint8_t *buf, int size)
status_in is a status change that must be taken into account after all frames in fifo have been processed
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int64_t avio_size(AVIOContext *s)
Get the filesize.
#define TLS_COMMON_OPTIONS(pstruct, options_field)
int ffurl_get_short_seek(void *urlcontext)
Return the current short seek threshold value for this URL.
static OSStatus tls_write_cb(SSLConnectionRef connection, const void *data, size_t *dataLength)
static OSStatus tls_read_cb(SSLConnectionRef connection, void *data, size_t *dataLength)
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 type
static int tls_get_short_seek(URLContext *h)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int load_ca(URLContext *h)
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
const char * av_default_item_name(void *ptr)
Return the context name.
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
SecIdentityRef SecIdentityCreate(CFAllocatorRef allocator, SecCertificateRef certificate, SecKeyRef privateKey)
static int tls_get_file_handle(URLContext *h)
static int tls_read(URLContext *h, uint8_t *buf, int size)
static const AVClass tls_class
static int import_pem(URLContext *h, char *path, CFArrayRef *array)
SSLContextRef ssl_context
static int tls_close(URLContext *h)
static const AVOption options[]
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
static int array[MAX_W *MAX_W]
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, 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...
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int load_cert(URLContext *h)
#define AVIO_FLAG_READ
read-only
#define flags(name, subs,...)
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const URLProtocol ff_tls_protocol
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
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.