Exemplo n.º 1
0
static OSStatus SessionCacheLookupEntry(
    SessionCache *cache,
	const SSLBuffer *sessionKey, 
	SSLBuffer *sessionData)
{
    SessionCacheEntry *entry = NULL;
    SessionCacheEntry **current;
	for (current = &(cache->head); *current; current = &((*current)->next)) {
        entry = *current;
		if (SessionCacheEntryMatchKey(entry, sessionKey))
            break;
    }

	if (*current == NULL)
		return errSSLSessionNotFound;

	if (SessionCacheEntryIsStaleNow(entry)) {
		sslLogSessCacheDebug("SessionCache::lookupEntry %p: STALE "
			"entry, deleting; current %p, entry->next %p", 
			entry, current, entry->next);
		cachePrint(entry, sessionKey, &entry->mSessionData);
        *current = entry->next;
        SessionCacheEntryDelete(entry);
		return errSSLSessionNotFound;
	}

	/* alloc/copy sessionData from existing entry (caller must free) */
	return SSLCopyBuffer(&entry->mSessionData, sessionData);
}
Exemplo n.º 2
0
static OSStatus SessionCacheLookupEntry(
    SessionCache *cache,
	const tls_buffer *sessionKey,
	tls_buffer *sessionData)
{
    SessionCacheEntry *entry = NULL;
    SessionCacheEntry **current;
	for (current = &(cache->head); *current; current = &((*current)->next)) {
        entry = *current;
		if (SessionCacheEntryMatchKey(entry, sessionKey))
            break;
    }

	if (*current == NULL)
		return -9804; //errSSLSessionNotFound;

	if (SessionCacheEntryIsStaleNow(entry)) {
		sslLogSessCacheDebug("SessionCache::lookupEntry %p: STALE "
			"entry, deleting; current %p, entry->next %p",
			entry, current, entry->next);
		cachePrint(entry, sessionKey, &entry->mSessionData);
        *current = entry->next;
        SessionCacheEntryDelete(entry);
		return -9804; //errSSLSessionNotFound;
	}

#if 1
    // "get" not "copy", see: <rdar://problem/16277298> coreTLS: session cache callbacks can lead to leaks or crashes
    sessionData->data = entry->mSessionData.data;
    sessionData->length = entry->mSessionData.length;
    return 0;
#else
    /* alloc/copy sessionData from existing entry (caller must free) */
    return SSLCopyBuffer(&entry->mSessionData, sessionData);
#endif
}