Correct and enhance the behaviour of "internal" session caching as it
[openssl.git] / ssl / ssl_sess.c
index ca1a7427be1116e5317a25aaadd46a8abcb6655d..2a4a90897e4589d53aa0917c8c50404c3065e7b2 100644 (file)
@@ -309,9 +309,12 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)
                        if (copy)
                                CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
 
-                       /* The following should not return 1, otherwise,
-                        * things are very strange */
-                       SSL_CTX_add_session(s->ctx,ret);
+                       /* Add the externally cached session to the internal
+                        * cache as well if and only if we are supposed to. */
+                       if(!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE))
+                               /* The following should not return 1, otherwise,
+                                * things are very strange */
+                               SSL_CTX_add_session(s->ctx,ret);
                        }
                if (ret == NULL)
                        goto err;