示例#1
0
static void SecCAIssuerRequestCompleted(asynchttp_t *http,
    CFTimeInterval maxAge) {
    /* Cast depends on http being first field in struct SecCAIssuerRequest. */
    SecCAIssuerRequestRef request = (SecCAIssuerRequestRef)http;
    CFDataRef data = (request->http.response ?
        CFHTTPMessageCopyBody(request->http.response) : NULL);
    if (data) {
        SecCertificateRef parent = SecCertificateCreateWithData(NULL, data);
        CFRelease(data);
        if (parent) {
            /* We keep responses in the cache for at least 7 days, or longer
             if the http response tells us to keep it around for more. */
            if (maxAge < SECONDS_PER_DAY * 7)
                maxAge = SECONDS_PER_DAY * 7;
            CFAbsoluteTime expires = CFAbsoluteTimeGetCurrent() + maxAge;
            CFURLRef issuer = CFArrayGetValueAtIndex(request->issuers,
                                                     request->issuerIX - 1);
            SecCAIssuerCacheAddCertificate(parent, issuer, expires);
            CFArrayRef parents = SecCAIssuerConvertToParents(
                request->certificate, parent);
            if (parents) {
                secdebug("caissuer", "response: %@ good", http->response);
                request->callback(request->context, parents);
                CFRelease(parents);
                SecCAIssuerRequestRelease(request);
                return;
            }
        }
    }

    secdebug("caissuer", "response: %@ not parent, trying next caissuer",
        http->response);
    SecCAIssuerRequestIssue(request);
}
示例#2
0
CRESTRequestRef CRESTRequestCreateWithBytes(UInt8 const *bytes, ssize_t len)
{
	CFURLRef url;
	CRESTRequestRef request;
	CFHTTPMessageRef message;

	message	= CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true);
	request = calloc(1, sizeof(struct CRESTRequest));
	assert(request);
	bool isAppended = CFHTTPMessageAppendBytes(message, bytes, (CFIndex) len);
	bool isComplete = CFHTTPMessageIsHeaderComplete(message);

	if( ! ( isAppended && isComplete ) )
	{
		CFRelease(message);
		CRESTRequestDealloc(request);
		return NULL;
	}

	url = CFHTTPMessageCopyRequestURL(message);

	CFMutableDictionaryRef params = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks,
			&kCFTypeDictionaryValueCallBacks);

	CFStringRef query = CFURLCopyQueryString(url, NULL);
	if( query )
	{
		parseParams(params, query);
		CFRelease(query);
	}

	CFDataRef bodyData = CFHTTPMessageCopyBody(message);
	if( CFDataGetLength(bodyData) )
	{
		CFStringRef bodyString = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, bodyData,
				kCFStringEncodingUTF8);
		parseParams(params, bodyString);
		CFRelease(bodyString);
	}
	CFRelease(bodyData);

	request->method = CFHTTPMessageCopyRequestMethod(message);
	request->path = CFURLCopyPath(url);
	request->params = (CFDictionaryRef) params;

	CFRelease(url);
	CFRelease(message);

	return request;
}