summaryrefslogtreecommitdiff
path: root/src/lib/libssl/doc/SSL_CTX_set_generate_session_id.3
diff options
context:
space:
mode:
authorbentley <>2014-10-12 09:33:04 +0000
committerbentley <>2014-10-12 09:33:04 +0000
commit82b7f378b6907ab315a6e50322d2a0a8794a0aa9 (patch)
treea5087bf8d016a6041c2b6822fbecfd8f6c5e70b1 /src/lib/libssl/doc/SSL_CTX_set_generate_session_id.3
parent0a63f0cf49369e1926567ab62e04e3355cedf0cd (diff)
downloadopenbsd-82b7f378b6907ab315a6e50322d2a0a8794a0aa9.tar.gz
openbsd-82b7f378b6907ab315a6e50322d2a0a8794a0aa9.tar.bz2
openbsd-82b7f378b6907ab315a6e50322d2a0a8794a0aa9.zip
Convert libssl manpages from pod to mdoc(7).
libcrypto has not been started yet. ok schwarze@ miod@
Diffstat (limited to 'src/lib/libssl/doc/SSL_CTX_set_generate_session_id.3')
-rw-r--r--src/lib/libssl/doc/SSL_CTX_set_generate_session_id.3193
1 files changed, 193 insertions, 0 deletions
diff --git a/src/lib/libssl/doc/SSL_CTX_set_generate_session_id.3 b/src/lib/libssl/doc/SSL_CTX_set_generate_session_id.3
new file mode 100644
index 0000000000..e2e2a70362
--- /dev/null
+++ b/src/lib/libssl/doc/SSL_CTX_set_generate_session_id.3
@@ -0,0 +1,193 @@
1.Dd $Mdocdate: October 12 2014 $
2.Dt SSL_CTX_SET_GENERATE_SESSION_ID 3
3.Os
4.Sh NAME
5.Nm SSL_CTX_set_generate_session_id ,
6.Nm SSL_set_generate_session_id ,
7.Nm SSL_has_matching_session_id
8.Nd manipulate generation of SSL session IDs (server only)
9.Sh SYNOPSIS
10.In openssl/ssl.h
11.Bd -literal
12 typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
13 unsigned int *id_len);
14.Ed
15.Ft int
16.Fn SSL_CTX_set_generate_session_id "SSL_CTX *ctx" "GEN_SESSION_CB cb"
17.Ft int
18.Fn SSL_set_generate_session_id "SSL *ssl" "GEN_SESSION_CB" "cb);"
19.Ft int
20.Fo SSL_has_matching_session_id
21.Fa "const SSL *ssl" "const unsigned char *id" "unsigned int id_len"
22.Fc
23.Sh DESCRIPTION
24.Fn SSL_CTX_set_generate_session_id
25sets the callback function for generating new session ids for SSL/TLS sessions
26for
27.Fa ctx
28to be
29.Fa cb .
30.Pp
31.Fn SSL_set_generate_session_id
32sets the callback function for generating new session ids for SSL/TLS sessions
33for
34.Fa ssl
35to be
36.Fa cb .
37.Pp
38.Fn SSL_has_matching_session_id
39checks, whether a session with id
40.Fa id
41(of length
42.Fa id_len )
43is already contained in the internal session cache
44of the parent context of
45.Fa ssl .
46.Sh NOTES
47When a new session is established between client and server,
48the server generates a session id.
49The session id is an arbitrary sequence of bytes.
50The length of the session id is 16 bytes for SSLv2 sessions and between 1 and
5132 bytes for SSLv3/TLSv1.
52The session id is not security critical but must be unique for the server.
53Additionally, the session id is transmitted in the clear when reusing the
54session so it must not contain sensitive information.
55.Pp
56Without a callback being set, an OpenSSL server will generate a unique session
57id from pseudo random numbers of the maximum possible length.
58Using the callback function, the session id can be changed to contain
59additional information like, e.g., a host id in order to improve load balancing
60or external caching techniques.
61.Pp
62The callback function receives a pointer to the memory location to put
63.Fa id
64into and a pointer to the maximum allowed length
65.Fa id_len .
66The buffer at location
67.Fa id
68is only guaranteed to have the size
69.Fa id_len .
70The callback is only allowed to generate a shorter id and reduce
71.Fa id_len ;
72the callback
73.Em must never
74increase
75.Fa id_len
76or write to the location
77.Fa id
78exceeding the given limit.
79.Pp
80If a SSLv2 session id is generated and
81.Fa id_len
82is reduced, it will be restored after the callback has finished and the session
83id will be padded with 0x00.
84It is not recommended to change the
85.Fa id_len
86for SSLv2 sessions.
87The callback can use the
88.Xr SSL_get_version 3
89function to check whether the session is of type SSLv2.
90.Pp
91The location
92.Fa id
93is filled with 0x00 before the callback is called,
94so the callback may only fill part of the possible length and leave
95.Fa id_len
96untouched while maintaining reproducibility.
97.Pp
98Since the sessions must be distinguished, session ids must be unique.
99Without the callback a random number is used,
100so that the probability of generating the same session id is extremely small
101(2^128 possible ids for an SSLv2 session, 2^256 for SSLv3/TLSv1).
102In order to ensure the uniqueness of the generated session id,
103the callback must call
104.Fn SSL_has_matching_session_id
105and generate another id if a conflict occurs.
106If an id conflict is not resolved, the handshake will fail.
107If the application codes, e.g., a unique host id, a unique process number, and
108a unique sequence number into the session id, uniqueness could easily be
109achieved without randomness added (it should however be taken care that
110no confidential information is leaked this way).
111If the application cannot guarantee uniqueness,
112it is recommended to use the maximum
113.Fa id_len
114and fill in the bytes not used to code special information with random data to
115avoid collisions.
116.Pp
117.Fn SSL_has_matching_session_id
118will only query the internal session cache, not the external one.
119Since the session id is generated before the handshake is completed,
120it is not immediately added to the cache.
121If another thread is using the same internal session cache,
122a race condition can occur in that another thread generates the same session id.
123Collisions can also occur when using an external session cache,
124since the external cache is not tested with
125.Fn SSL_has_matching_session_id
126and the same race condition applies.
127.Pp
128When calling
129.Fn SSL_has_matching_session_id
130for an SSLv2 session with reduced
131.Fa id_len Ns ,
132the match operation will be performed using the fixed length required and with
133a 0x00 padded id.
134.Pp
135The callback must return 0 if it cannot generate a session id for whatever
136reason and return 1 on success.
137.Sh RETURN VALUES
138.Fn SSL_CTX_set_generate_session_id
139and
140.Fn SSL_set_generate_session_id
141always return 1.
142.Pp
143.Fn SSL_has_matching_session_id
144returns 1 if another session with the same id is already in the cache.
145.Sh EXAMPLES
146The callback function listed will generate a session id with the server id
147given, and will fill the rest with pseudo random bytes:
148.Bd -literal
149const char session_id_prefix = "www-18";
150
151#define MAX_SESSION_ID_ATTEMPTS 10
152static int
153generate_session_id(const SSL *ssl, unsigned char *id,
154 unsigned int *id_len)
155{
156 unsigned int count = 0;
157 const char *version;
158
159 version = SSL_get_version(ssl);
160 if (!strcmp(version, "SSLv2")) {
161 /* we must not change id_len */
162 ;
163 }
164
165 do {
166 RAND_pseudo_bytes(id, *id_len);
167 /*
168 * Prefix the session_id with the required prefix. NB: If
169 * our prefix is too long, clip it \(en but there will be
170 * worse effects anyway, e.g., the server could only
171 * possibly create one session ID (the prefix!) so all
172 * future session negotiations will fail due to conflicts.
173 */
174 memcpy(id, session_id_prefix,
175 (strlen(session_id_prefix) < *id_len) ?
176 strlen(session_id_prefix) : *id_len);
177 } while (SSL_has_matching_session_id(ssl, id, *id_len) &&
178 (++count < MAX_SESSION_ID_ATTEMPTS));
179
180 if (count >= MAX_SESSION_ID_ATTEMPTS)
181 return 0;
182 return 1;
183}
184.Ed
185.Sh SEE ALSO
186.Xr ssl 3 ,
187.Xr SSL_get_version 3
188.Sh HISTORY
189.Fn SSL_CTX_set_generate_session_id ,
190.Fn SSL_set_generate_session_id
191and
192.Fn SSL_has_matching_session_id
193were introduced in OpenSSL 0.9.7.