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