1*7a73e666Sschwarze.\" $OpenBSD: SSL_CTX_set_session_cache_mode.3,v 1.7 2019/06/12 09:36:30 schwarze Exp $ 282ca21fbSschwarze.\" OpenSSL 67adf0a7 Dec 25 19:58:38 2016 +0100 3f1a3c524Sschwarze.\" 4c04b070fSschwarze.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org> and 5c04b070fSschwarze.\" Geoff Thorpe <geoff@openssl.org>. 6c04b070fSschwarze.\" Copyright (c) 2001, 2002 The OpenSSL Project. All rights reserved. 7f1a3c524Sschwarze.\" 8c04b070fSschwarze.\" Redistribution and use in source and binary forms, with or without 9c04b070fSschwarze.\" modification, are permitted provided that the following conditions 10c04b070fSschwarze.\" are met: 11c04b070fSschwarze.\" 12c04b070fSschwarze.\" 1. Redistributions of source code must retain the above copyright 13c04b070fSschwarze.\" notice, this list of conditions and the following disclaimer. 14c04b070fSschwarze.\" 15c04b070fSschwarze.\" 2. Redistributions in binary form must reproduce the above copyright 16c04b070fSschwarze.\" notice, this list of conditions and the following disclaimer in 17c04b070fSschwarze.\" the documentation and/or other materials provided with the 18c04b070fSschwarze.\" distribution. 19c04b070fSschwarze.\" 20c04b070fSschwarze.\" 3. All advertising materials mentioning features or use of this 21c04b070fSschwarze.\" software must display the following acknowledgment: 22c04b070fSschwarze.\" "This product includes software developed by the OpenSSL Project 23c04b070fSschwarze.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24c04b070fSschwarze.\" 25c04b070fSschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26c04b070fSschwarze.\" endorse or promote products derived from this software without 27c04b070fSschwarze.\" prior written permission. For written permission, please contact 28c04b070fSschwarze.\" openssl-core@openssl.org. 29c04b070fSschwarze.\" 30c04b070fSschwarze.\" 5. Products derived from this software may not be called "OpenSSL" 31c04b070fSschwarze.\" nor may "OpenSSL" appear in their names without prior written 32c04b070fSschwarze.\" permission of the OpenSSL Project. 33c04b070fSschwarze.\" 34c04b070fSschwarze.\" 6. Redistributions of any form whatsoever must retain the following 35c04b070fSschwarze.\" acknowledgment: 36c04b070fSschwarze.\" "This product includes software developed by the OpenSSL Project 37c04b070fSschwarze.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38c04b070fSschwarze.\" 39c04b070fSschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40c04b070fSschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41c04b070fSschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42c04b070fSschwarze.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43c04b070fSschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44c04b070fSschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45c04b070fSschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46c04b070fSschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47c04b070fSschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48c04b070fSschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49c04b070fSschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50c04b070fSschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE. 51c04b070fSschwarze.\" 52*7a73e666Sschwarze.Dd $Mdocdate: June 12 2019 $ 53f1a3c524Sschwarze.Dt SSL_CTX_SET_SESSION_CACHE_MODE 3 54f1a3c524Sschwarze.Os 55f1a3c524Sschwarze.Sh NAME 56f1a3c524Sschwarze.Nm SSL_CTX_set_session_cache_mode , 57f1a3c524Sschwarze.Nm SSL_CTX_get_session_cache_mode 58f1a3c524Sschwarze.Nd enable/disable session caching 59f1a3c524Sschwarze.Sh SYNOPSIS 60f1a3c524Sschwarze.In openssl/ssl.h 61f1a3c524Sschwarze.Ft long 62f1a3c524Sschwarze.Fn SSL_CTX_set_session_cache_mode "SSL_CTX ctx" "long mode" 63f1a3c524Sschwarze.Ft long 64f1a3c524Sschwarze.Fn SSL_CTX_get_session_cache_mode "SSL_CTX ctx" 65f1a3c524Sschwarze.Sh DESCRIPTION 66f1a3c524Sschwarze.Fn SSL_CTX_set_session_cache_mode 67f1a3c524Sschwarzeenables/disables session caching by setting the operational mode for 68f1a3c524Sschwarze.Ar ctx 69f1a3c524Sschwarzeto 70f1a3c524Sschwarze.Ar mode . 71f1a3c524Sschwarze.Pp 72f1a3c524Sschwarze.Fn SSL_CTX_get_session_cache_mode 73f1a3c524Sschwarzereturns the currently used cache mode. 74c04b070fSschwarze.Pp 75f1a3c524SschwarzeThe OpenSSL library can store/retrieve SSL/TLS sessions for later reuse. 76f1a3c524SschwarzeThe sessions can be held in memory for each 77f1a3c524Sschwarze.Fa ctx , 78f1a3c524Sschwarzeif more than one 79f1a3c524Sschwarze.Vt SSL_CTX 80f1a3c524Sschwarzeobject is being maintained, the sessions are unique for each 81f1a3c524Sschwarze.Vt SSL_CTX 82f1a3c524Sschwarzeobject. 83f1a3c524Sschwarze.Pp 84f1a3c524SschwarzeIn order to reuse a session, a client must send the session's id to the server. 85f1a3c524SschwarzeIt can only send exactly one id. 86f1a3c524SschwarzeThe server then either agrees to reuse the session or it starts a full 87f1a3c524Sschwarzehandshake (to create a new session). 88f1a3c524Sschwarze.Pp 8982ca21fbSschwarzeA server will look up the session in its internal session storage. 90f1a3c524SschwarzeIf the session is not found in internal storage or lookups for the internal 91f1a3c524Sschwarzestorage have been deactivated 92f1a3c524Sschwarze.Pq Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP , 93f1a3c524Sschwarzethe server will try the external storage if available. 94f1a3c524Sschwarze.Pp 95f1a3c524SschwarzeSince a client may try to reuse a session intended for use in a different 96f1a3c524Sschwarzecontext, the session id context must be set by the server (see 97f1a3c524Sschwarze.Xr SSL_CTX_set_session_id_context 3 ) . 98f1a3c524Sschwarze.Pp 99f1a3c524SschwarzeThe following session cache modes and modifiers are available: 100f1a3c524Sschwarze.Bl -tag -width Ds 101f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_OFF 102f1a3c524SschwarzeNo session caching for client or server takes place. 103f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_CLIENT 104f1a3c524SschwarzeClient sessions are added to the session cache. 105f1a3c524SschwarzeAs there is no reliable way for the OpenSSL library to know whether a session 106f1a3c524Sschwarzeshould be reused or which session to choose (due to the abstract BIO layer the 107f1a3c524SschwarzeSSL engine does not have details about the connection), 108f1a3c524Sschwarzethe application must select the session to be reused by using the 109f1a3c524Sschwarze.Xr SSL_set_session 3 110f1a3c524Sschwarzefunction. 111f1a3c524SschwarzeThis option is not activated by default. 112f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_SERVER 113f1a3c524SschwarzeServer sessions are added to the session cache. 114f1a3c524SschwarzeWhen a client proposes a session to be reused, the server looks for the 115f1a3c524Sschwarzecorresponding session in (first) the internal session cache (unless 116f1a3c524Sschwarze.Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 117f1a3c524Sschwarzeis set), then (second) in the external cache if available. 118f1a3c524SschwarzeIf the session is found, the server will try to reuse the session. 119f1a3c524SschwarzeThis is the default. 120f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_BOTH 121f1a3c524SschwarzeEnable both 122f1a3c524Sschwarze.Dv SSL_SESS_CACHE_CLIENT 123f1a3c524Sschwarzeand 124f1a3c524Sschwarze.Dv SSL_SESS_CACHE_SERVER 125f1a3c524Sschwarzeat the same time. 126f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_NO_AUTO_CLEAR 127f1a3c524SschwarzeNormally the session cache is checked for expired sessions every 255 128f1a3c524Sschwarzeconnections using the 129f1a3c524Sschwarze.Xr SSL_CTX_flush_sessions 3 130f1a3c524Sschwarzefunction. 131f1a3c524SschwarzeSince this may lead to a delay which cannot be controlled, 132f1a3c524Sschwarzethe automatic flushing may be disabled and 133f1a3c524Sschwarze.Xr SSL_CTX_flush_sessions 3 134f1a3c524Sschwarzecan be called explicitly by the application. 135f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 136f1a3c524SschwarzeBy setting this flag, session-resume operations in an SSL/TLS server will not 137f1a3c524Sschwarzeautomatically look up sessions in the internal cache, 138f1a3c524Sschwarzeeven if sessions are automatically stored there. 139f1a3c524SschwarzeIf external session caching callbacks are in use, 140f1a3c524Sschwarzethis flag guarantees that all lookups are directed to the external cache. 141f1a3c524SschwarzeAs automatic lookup only applies for SSL/TLS servers, 142f1a3c524Sschwarzethe flag has no effect on clients. 143f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_NO_INTERNAL_STORE 144f1a3c524SschwarzeDepending on the presence of 145f1a3c524Sschwarze.Dv SSL_SESS_CACHE_CLIENT 146f1a3c524Sschwarzeand/or 147f1a3c524Sschwarze.Dv SSL_SESS_CACHE_SERVER , 148f1a3c524Sschwarzesessions negotiated in an SSL/TLS handshake may be cached for possible reuse. 149f1a3c524SschwarzeNormally a new session is added to the internal cache as well as any external 150f1a3c524Sschwarzesession caching (callback) that is configured for the 151f1a3c524Sschwarze.Vt SSL_CTX . 152f1a3c524SschwarzeThis flag will prevent sessions being stored in the internal cache 153f1a3c524Sschwarze(though the application can add them manually using 154f1a3c524Sschwarze.Xr SSL_CTX_add_session 3 ) . 155f1a3c524SschwarzeNote: 156f1a3c524Sschwarzein any SSL/TLS servers where external caching is configured, any successful 157f1a3c524Sschwarzesession lookups in the external cache (e.g., for session-resume requests) would 158f1a3c524Sschwarzenormally be copied into the local cache before processing continues \(en this 159f1a3c524Sschwarzeflag prevents these additions to the internal cache as well. 160f1a3c524Sschwarze.It Dv SSL_SESS_CACHE_NO_INTERNAL 161f1a3c524SschwarzeEnable both 162f1a3c524Sschwarze.Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 163f1a3c524Sschwarzeand 164f1a3c524Sschwarze.Dv SSL_SESS_CACHE_NO_INTERNAL_STORE 165f1a3c524Sschwarzeat the same time. 166f1a3c524Sschwarze.El 167f1a3c524Sschwarze.Pp 168f1a3c524SschwarzeThe default mode is 169f1a3c524Sschwarze.Dv SSL_SESS_CACHE_SERVER . 170f1a3c524Sschwarze.Sh RETURN VALUES 171f1a3c524Sschwarze.Fn SSL_CTX_set_session_cache_mode 172f1a3c524Sschwarzereturns the previously set cache mode. 173f1a3c524Sschwarze.Pp 174f1a3c524Sschwarze.Fn SSL_CTX_get_session_cache_mode 175f1a3c524Sschwarzereturns the currently set cache mode. 176f1a3c524Sschwarze.Sh SEE ALSO 177*7a73e666Sschwarze.Xr ssl 3 , 178f1a3c524Sschwarze.Xr SSL_CTX_add_session 3 , 179bb2ba699Sschwarze.Xr SSL_CTX_ctrl 3 , 180f1a3c524Sschwarze.Xr SSL_CTX_flush_sessions 3 , 181f1a3c524Sschwarze.Xr SSL_CTX_sess_number 3 , 182f1a3c524Sschwarze.Xr SSL_CTX_sess_set_cache_size 3 , 183f1a3c524Sschwarze.Xr SSL_CTX_sess_set_get_cb 3 , 184f1a3c524Sschwarze.Xr SSL_CTX_set_session_id_context 3 , 185f1a3c524Sschwarze.Xr SSL_CTX_set_timeout 3 , 186f1a3c524Sschwarze.Xr SSL_session_reused 3 , 187f1a3c524Sschwarze.Xr SSL_set_session 3 188f1a3c524Sschwarze.Sh HISTORY 1898fba1ec8Sschwarze.Fn SSL_CTX_set_session_cache_mode 1908fba1ec8Sschwarzeand 1918fba1ec8Sschwarze.Fn SSL_CTX_get_session_cache_mode 19210e00d17Sschwarzefirst appeared in SSLeay 0.6.1 and have been available since 1938fba1ec8Sschwarze.Ox 2.4 . 1948fba1ec8Sschwarze.Pp 195f1a3c524Sschwarze.Dv SSL_SESS_CACHE_NO_INTERNAL_STORE 196f1a3c524Sschwarzeand 197f1a3c524Sschwarze.Dv SSL_SESS_CACHE_NO_INTERNAL 198f1a3c524Sschwarzewere introduced in OpenSSL 0.9.6h. 199