Initial import from FreeBSD RELENG_4:
[dragonfly.git] / secure / lib / libssl / man / SSL_CTX_set_generate_session_id.3
1.\" Automatically generated by Pod::Man version 1.15
2.\" Wed Feb 19 16:47:41 2003
4.\" Standard preamble:
5.\" ====================================================================== Sh \" Subsection heading
8.if t .Sp 5
13.. Sp \" Vertical space (when we can't use .PP)
15.if t .sp .5v
16.if n .sp
17.. Ip \" List item \\n(.$>=3 .ne \\$3
21.el .ne 3
22.IP "\\$1" \\$2
23.. Vb \" Begin verbatim text
25.ft CW \\$1
28.. Ve \" End verbatim text
30.ft R
34.\" Set up some character translations and predefined strings. \*(-- will
35.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
36.\" double quote, and \*(R" will give a right double quote. | will give a
37.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used
38.\" to do unbreakable dashes and therefore won't be available. \*(C` and
39.\" \*(C' expand to `' in nroff, nothing in troff, for use with C<> \(*W-|\(bv\*(Tr
41.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' n \{\
43. ds -- \(*W-
44. ds PI pi
45. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
46. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
47. ds L" ""
48. ds R" ""
49. ds C` ""
50. ds C' ""
53. ds -- \|\(em\|
54. ds PI \(*p
55. ds L" ``
56. ds R" ''
59.\" If the F register is turned on, we'll generate index entries on stderr
60.\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
61.\" index entries marked with X<> in POD. Of course, you'll have to process
62.\" the output yourself in some meaningful fashion.
63.if \nF \{\
64. de IX
65. tm Index:\\$1\t\\n%\t"\\$2"
67. nr % 0
68. rr F
71.\" For nroff, turn off justification. Always turn off hyphenation; it
72.\" makes way too many mistakes in technical documents.
73.hy 0
74.if n .na
76.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
77.\" Fear. Run. Save yourself. No user-serviceable parts. B 3
79. \" fudge factors for nroff and troff
80.if n \{\
81. ds #H 0
82. ds #V .8m
83. ds #F .3m
84. ds #[ \f1
85. ds #] \fP
87.if t \{\
88. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
89. ds #V .6m
90. ds #F 0
91. ds #[ \&
92. ds #] \&
94. \" simple accents for nroff and troff
95.if n \{\
96. ds ' \&
97. ds ` \&
98. ds ^ \&
99. ds , \&
100. ds ~ ~
101. ds /
103.if t \{\
104. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
105. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
106. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
107. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
108. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
109. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
111. \" troff and (daisy-wheel) nroff accents
112.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
113.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
114.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
115.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
116.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
117.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
118.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
119.ds ae a\h'-(\w'a'u*4/10)'e
120.ds Ae A\h'-(\w'A'u*4/10)'E
121. \" corrections for vroff
122.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
123.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
124. \" for low resolution devices (crt and lpr)
125.if \n(.H>23 .if \n(.V>19 \
127. ds : e
128. ds 8 ss
129. ds o a
130. ds d- d\h'-1'\(ga
131. ds D- D\h'-1'\(hy
132. ds th \o'bp'
133. ds Th \o'LP'
134. ds ae ae
135. ds Ae AE
137.rm #[ #] #H #V #F C
138.\" ======================================================================
140.IX Title "SSL_CTX_set_generate_session_id 3"
141.TH SSL_CTX_set_generate_session_id 3 "0.9.7a" "2003-02-19" "OpenSSL"
143.SH "NAME"
144SSL_CTX_set_generate_session_id, SSL_set_generate_session_id, SSL_has_matching_session_id \- manipulate generation of \s-1SSL\s0 session IDs (server only)
146.IX Header "SYNOPSIS"
147.Vb 1
148\& #include <openssl/ssl.h>
150.Vb 2
151\& typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
152\& unsigned int *id_len);
154.Vb 4
155\& int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb);
156\& int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB, cb);
157\& int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
158\& unsigned int id_len);
162\&\fISSL_CTX_set_generate_session_id()\fR sets the callback function for generating
163new session ids for \s-1SSL/TLS\s0 sessions for \fBctx\fR to be \fBcb\fR.
165\&\fISSL_set_generate_session_id()\fR sets the callback function for generating
166new session ids for \s-1SSL/TLS\s0 sessions for \fBssl\fR to be \fBcb\fR.
168\&\fISSL_has_matching_session_id()\fR checks, whether a session with id \fBid\fR
169(of length \fBid_len\fR) is already contained in the internal session cache
170of the parent context of \fBssl\fR.
171.SH "NOTES"
172.IX Header "NOTES"
173When a new session is established between client and server, the server
174generates a session id. The session id is an arbitrary sequence of bytes.
175The length of the session id is 16 bytes for SSLv2 sessions and between
1761 and 32 bytes for SSLv3/TLSv1. The session id is not security critical
177but must be unique for the server. Additionally, the session id is
178transmitted in the clear when reusing the session so it must not contain
179sensitive information.
181Without a callback being set, an OpenSSL server will generate a unique
182session id from pseudo random numbers of the maximum possible length.
183Using the callback function, the session id can be changed to contain
184additional information like e.g. a host id in order to improve load balancing
185or external caching techniques.
187The callback function receives a pointer to the memory location to put
188\&\fBid\fR into and a pointer to the maximum allowed length \fBid_len\fR. The
189buffer at location \fBid\fR is only guaranteed to have the size \fBid_len\fR.
190The callback is only allowed to generate a shorter id and reduce \fBid_len\fR;
191the callback \fBmust never\fR increase \fBid_len\fR or write to the location
192\&\fBid\fR exceeding the given limit.
194If a SSLv2 session id is generated and \fBid_len\fR is reduced, it will be
195restored after the callback has finished and the session id will be padded
196with 0x00. It is not recommended to change the \fBid_len\fR for SSLv2 sessions.
197The callback can use the SSL_get_version(3) function
198to check, whether the session is of type SSLv2.
200The location \fBid\fR is filled with 0x00 before the callback is called, so the
201callback may only fill part of the possible length and leave \fBid_len\fR
202untouched while maintaining reproducibility.
204Since the sessions must be distinguished, session ids must be unique.
205Without the callback a random number is used, so that the probability
206of generating the same session id is extremely small (2^128 possible ids
207for an SSLv2 session, 2^256 for SSLv3/TLSv1). In order to assure the
208uniqueness of the generated session id, the callback must call
209\&\fISSL_has_matching_session_id()\fR and generate another id if a conflict occurs.
210If an id conflict is not resolved, the handshake will fail.
211If the application codes e.g. a unique host id, a unique process number, and
212a unique sequence number into the session id, uniqueness could easily be
213achieved without randomness added (it should however be taken care that
214no confidential information is leaked this way). If the application can not
215guarantee uniqueness, it is recommended to use the maximum \fBid_len\fR and
216fill in the bytes not used to code special information with random data
217to avoid collisions.
219\&\fISSL_has_matching_session_id()\fR will only query the internal session cache,
220not the external one. Since the session id is generated before the
221handshake is completed, it is not immediately added to the cache. If
222another thread is using the same internal session cache, a race condition
223can occur in that another thread generates the same session id.
224Collisions can also occur when using an external session cache, since
225the external cache is not tested with \fISSL_has_matching_session_id()\fR
226and the same race condition applies.
228When calling \fISSL_has_matching_session_id()\fR for an SSLv2 session with
229reduced \fBid_len\fR, the match operation will be performed using the
230fixed length required and with a 0x00 padded id.
232The callback must return 0 if it cannot generate a session id for whatever
233reason and return 1 on success.
235.IX Header "EXAMPLES"
236The callback function listed will generate a session id with the
237server id given, and will fill the rest with pseudo random bytes:
239.Vb 1
240\& const char session_id_prefix = "www-18";
242.Vb 6
243\& #define MAX_SESSION_ID_ATTEMPTS 10
244\& static int generate_session_id(const SSL *ssl, unsigned char *id,
245\& unsigned int *id_len)
246\& {
247\& unsigned int count = 0;
248\& const char *version;
250.Vb 3
251\& version = SSL_get_version(ssl);
252\& if (!strcmp(version, "SSLv2"))
253\& /* we must not change id_len */;
255.Vb 17
256\& do {
257\& RAND_pseudo_bytes(id, *id_len);
258\& /* Prefix the session_id with the required prefix. NB: If our
259\& * prefix is too long, clip it - but there will be worse effects
260\& * anyway, eg. the server could only possibly create 1 session
261\& * ID (ie. the prefix!) so all future session negotiations will
262\& * fail due to conflicts. */
263\& memcpy(id, session_id_prefix,
264\& (strlen(session_id_prefix) < *id_len) ?
265\& strlen(session_id_prefix) : *id_len);
266\& }
267\& while(SSL_has_matching_session_id(ssl, id, *id_len) &&
268\& (++count < MAX_SESSION_ID_ATTEMPTS));
269\& if(count >= MAX_SESSION_ID_ATTEMPTS)
270\& return 0;
271\& return 1;
272\& }
276\&\fISSL_CTX_set_generate_session_id()\fR and \fISSL_set_generate_session_id()\fR
277always return 1.
279\&\fISSL_has_matching_session_id()\fR returns 1 if another session with the
280same id is already in the cache.
282.IX Header "SEE ALSO"
283ssl(3), SSL_get_version(3)
285.IX Header "HISTORY"
286\&\fISSL_CTX_set_generate_session_id()\fR, \fISSL_set_generate_session_id()\fR
287and \fISSL_has_matching_session_id()\fR have been introduced in
288OpenSSL 0.9.7.