Lines Matching refs:session

57 // Helper struct used to store session IDs in a SessionIdIndex container
59 // to the session ID buffer, which must outlive the entry itself. On the
69 explicit SessionId(SSL_SESSION* session)
70 : id(session->session_id),
71 id_len(session->session_id_length),
72 hash(ComputeHash(session->session_id, session->session_id_length)) {}
124 // find the cached session associated with a given key.
128 // as well as check for the existence of a session ID value in the cache.
190 // cached session ID. If one is found, call SSL_set_session() to associate
196 // Return true if a cached session ID was found, false otherwise.
221 SSL_SESSION* session = *it->second;
222 DCHECK(session);
224 DVLOG(2) << "Lookup session: " << session << " for " << cache_key;
227 SSL_SESSION_get_ex_data(session, GetSSLSessionExIndex());
232 ordering_.push_front(session);
236 return SSL_set_session(ssl, session) == 1;
239 // Return true iff a cached session was associated with the given |cache_key|.
246 SSL_SESSION* session = *it->second;
247 DCHECK(session);
250 SSL_SESSION_get_ex_data(session, GetSSLSessionExIndex());
256 SSL_SESSION* session = SSL_get_session(ssl);
257 CHECK(session);
259 // Mark the session as good, allowing it to be used for future connections.
261 session, GetSSLSessionExIndex(), reinterpret_cast<void*>(1));
270 SSL_SESSION* session = ordering_.front();
272 SSL_SESSION_free(session);
279 // Type for a dictionary from unique cache keys to session list nodes.
284 // Return the key associated with a given session, or the empty string if
286 std::string SessionKey(SSL_SESSION* session) {
287 if (!session)
288 return std::string("<null-session>");
290 if (session->session_id_length == 0)
291 return std::string("<empty-session-id>");
293 SessionIdIndex::iterator it = id_index_.find(SessionId(session));
295 return std::string("<unknown-session>");
300 // Remove a given |session| from the cache. Lock must be held.
301 void RemoveSessionLocked(SSL_SESSION* session) {
303 DCHECK(session);
304 DCHECK_GT(session->session_id_length, 0U);
305 SessionId session_id(session);
308 LOG(ERROR) << "Trying to remove unknown session from cache: " << session;
313 DCHECK_EQ(session, *key_it->second);
319 SSL_SESSION_free(session);
328 // Unfortunately, OpenSSL initializes |session->time| with a time()
333 SSL_SESSION* session = *it++;
337 // behaviour will use a session timeout of 0 seconds.
338 if (session->time + session->timeout <= timeout_secs) {
339 DVLOG(2) << "Expiring session " << session << " for "
340 << SessionKey(session);
341 RemoveSessionLocked(session);
354 // Called by OpenSSL when a new |session| was created and added to a given
355 // |ssl| connection. Note that the session's reference count was already
357 // to indicate that it took ownership of the session, i.e. that the caller
359 static int NewSessionCallbackStatic(SSL* ssl, SSL_SESSION* session) {
361 cache->OnSessionAdded(ssl, session);
365 // Called by OpenSSL to indicate that a session must be removed from the
367 static void RemoveSessionCallbackStatic(SSL_CTX* ctx, SSL_SESSION* session) {
368 GetCache(ctx)->OnSessionRemoved(session);
371 // Called by OpenSSL to generate a new session ID. This happens during a
372 // SSL connection operation, when the SSL object doesn't have a session yet.
374 // A session ID is a random string of bytes used to uniquely identify the
375 // session between a client and a server.
384 // another session in the cache doesn't already use the same value. It must
395 // Add |session| to the cache in association with |cache_key|. If a session
397 // caller already incremented the session's reference count.
398 void OnSessionAdded(SSL* ssl, SSL_SESSION* session) {
401 DCHECK_GT(session->session_id_length, 0U);
405 DVLOG(2) << "Add session " << session << " for " << cache_key;
406 // This is a new session. Add it to the cache.
407 ordering_.push_front(session);
414 // An existing session exists for this key, so replace it if needed.
415 DVLOG(2) << "Replace session " << *it->second << " with " << session
418 if (old_session != session) {
423 ordering_.push_front(session);
427 id_index_[SessionId(session)] = it;
447 SSL_SESSION* session = *it;
448 DCHECK(session);
449 DVLOG(2) << "Evicting session " << session << " for "
450 << SessionKey(session);
451 RemoveSessionLocked(session);
455 // Remove |session| from the cache.
456 void OnSessionRemoved(SSL_SESSION* session) {
458 DVLOG(2) << "Remove session " << session << " for " << SessionKey(session);
459 RemoveSessionLocked(session);
478 DLOG(ERROR) << "Couldn't generate unique session ID of " << id_len