/* cleanup, delete stale entries */ static bool SessionCacheCleanup(SessionCache *cache) { bool brtn = false; CFAbsoluteTime rightNow = CFAbsoluteTimeGetCurrent(); SessionCacheEntry **current; for (current = &(cache->head); *current;) { SessionCacheEntry *entry = *current; if(SessionCacheEntryIsStale(entry, rightNow)) { #ifndef DEBUG sslLogSessCacheDebug("...SessionCacheCleanup: deleting " "cached session (%p)", entry); cachePrint(entry, &entry->mKey, &entry->mSessionData); #endif *current = entry->next; SessionCacheEntryDelete(entry); } else { current = &((*current)->next); /* we're leaving one in the map */ brtn = true; } } return brtn; }
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); }
static OSStatus SessionCacheDeleteEntry( SessionCache *cache, const SSLBuffer *sessionKey) { SessionCacheEntry **current; for (current = &(cache->head); *current; current = &((*current)->next)) { SessionCacheEntry *entry = *current; if (SessionCacheEntryMatchKey(entry, sessionKey)) { #ifndef DEBUG sslLogSessCacheDebug("...SessionCacheDeleteEntry: deleting " "cached session (%p)", entry); cachePrint(entry, &entry->mKey, &entry->mSessionData); #endif *current = entry->next; SessionCacheEntryDelete(entry); return noErr; } } return noErr; }
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 }