1d562666b729d7ca3964f821c3e98ddc971b8641
[dragonfly.git] / secure / lib / libssl / man / SSL_CTX_set_tlsext_ticket_key_cb.3
1 .\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.20)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 'br\}
42 .\"
43 .\" Escape single quotes in literal strings from groff's Unicode transform.
44 .ie \n(.g .ds Aq \(aq
45 .el       .ds Aq '
46 .\"
47 .\" If the F register is turned on, we'll generate index entries on stderr for
48 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
49 .\" entries marked with X<> in POD.  Of course, you'll have to process the
50 .\" output yourself in some meaningful fashion.
51 .ie \nF \{\
52 .    de IX
53 .    tm Index:\\$1\t\\n%\t"\\$2"
54 ..
55 .    nr % 0
56 .    rr F
57 .\}
58 .el \{\
59 .    de IX
60 ..
61 .\}
62 .\"
63 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
65 .    \" fudge factors for nroff and troff
66 .if n \{\
67 .    ds #H 0
68 .    ds #V .8m
69 .    ds #F .3m
70 .    ds #[ \f1
71 .    ds #] \fP
72 .\}
73 .if t \{\
74 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
75 .    ds #V .6m
76 .    ds #F 0
77 .    ds #[ \&
78 .    ds #] \&
79 .\}
80 .    \" simple accents for nroff and troff
81 .if n \{\
82 .    ds ' \&
83 .    ds ` \&
84 .    ds ^ \&
85 .    ds , \&
86 .    ds ~ ~
87 .    ds /
88 .\}
89 .if t \{\
90 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
96 .\}
97 .    \" troff and (daisy-wheel) nroff accents
98 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105 .ds ae a\h'-(\w'a'u*4/10)'e
106 .ds Ae A\h'-(\w'A'u*4/10)'E
107 .    \" corrections for vroff
108 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110 .    \" for low resolution devices (crt and lpr)
111 .if \n(.H>23 .if \n(.V>19 \
112 \{\
113 .    ds : e
114 .    ds 8 ss
115 .    ds o a
116 .    ds d- d\h'-1'\(ga
117 .    ds D- D\h'-1'\(hy
118 .    ds th \o'bp'
119 .    ds Th \o'LP'
120 .    ds ae ae
121 .    ds Ae AE
122 .\}
123 .rm #[ #] #H #V #F C
124 .\" ========================================================================
125 .\"
126 .IX Title "SSL_CTX_set_tlsext_ticket_key_cb 3"
127 .TH SSL_CTX_set_tlsext_ticket_key_cb 3 "2014-06-05" "1.0.1h" "OpenSSL"
128 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
129 .\" way too many mistakes in technical documents.
130 .if n .ad l
131 .nh
132 .SH "NAME"
133 SSL_CTX_set_tlsext_ticket_key_cb \- set a callback for session ticket processing
134 .SH "SYNOPSIS"
135 .IX Header "SYNOPSIS"
136 .Vb 1
137 \& #include <openssl/tls1.h>
138 \&
139 \& long SSL_CTX_set_tlsext_ticket_key_cb(SSL_CTX sslctx,
140 \&        int (*cb)(SSL *s, unsigned char key_name[16],
141 \&                  unsigned char iv[EVP_MAX_IV_LENGTH],
142 \&                  EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc));
143 .Ve
144 .SH "DESCRIPTION"
145 .IX Header "DESCRIPTION"
146 \&\fISSL_CTX_set_tlsext_ticket_key_cb()\fR sets a callback fuction \fIcb\fR for handling 
147 session tickets for the ssl context \fIsslctx\fR. Session tickets, defined in 
148 \&\s-1RFC5077\s0 provide an enhanced session resumption capability where the server
149 implementation is not required to maintain per session state. It only applies
150 to \s-1TLS\s0 and there is no SSLv3 implementation.
151 .PP
152 The callback is available when the OpenSSL library was built without 
153 \&\fI\s-1OPENSSL_NO_TLSEXT\s0\fR being defined.
154 .PP
155 The callback function \fIcb\fR will be called for every client instigated \s-1TLS\s0
156 session when session ticket extension is presented in the \s-1TLS\s0 hello
157 message. It is the responsibility of this function to create or retrieve the
158 cryptographic parameters and to maintain their state.
159 .PP
160 The OpenSSL library uses your callback function to help implement a common \s-1TLS\s0 
161 ticket construction state according to \s-1RFC5077\s0 Section 4 such that per session
162 state is unnecessary and a small set of cryptographic variables needs to be 
163 maintained by the callback function implementation.
164 .PP
165 In order to reuse a session, a \s-1TLS\s0 client must send the a session ticket
166 extension to the server. The client can only send exactly one session ticket.
167 The server, through the callback function, either agrees to reuse the session
168 ticket information or it starts a full \s-1TLS\s0 handshake to create a new session
169 ticket.
170 .PP
171 Before the callback function is started \fIctx\fR and \fIhctx\fR have been 
172 initialised with EVP_CIPHER_CTX_init and HMAC_CTX_init respectively.
173 .PP
174 For new sessions tickets, when the client doesn't present a session ticket, or
175 an attempted retreival of the ticket failed, or a renew option was indicated,
176 the callback function will be called with \fIenc\fR equal to 1. The OpenSSL
177 library expects that the function will set an arbitary \fIname\fR, initialize
178 \&\fIiv\fR, and set the cipher context \fIctx\fR and the hash context \fIhctx\fR.
179 .PP
180 The \fIname\fR is 16 characters long and is used as a key identifier.
181 .PP
182 The \fIiv\fR length is the length of the \s-1IV\s0 of the corresponding cipher. The
183 maximum \s-1IV\s0 length is \s-1EVP_MAX_IV_LENGTH\s0 bytes defined in \fBevp.h\fR.
184 .PP
185 The initialization vector \fIiv\fR should be a random value. The cipher context 
186 \&\fIctx\fR should use the initialisation vector \fIiv\fR. The cipher context can be 
187 set using EVP_EncryptInit_ex. The hmac context can be set using HMAC_Init_ex.
188 .PP
189 When the client presents a session ticket, the callback function with be called 
190 with \fIenc\fR set to 0 indicating that the \fIcb\fR function should retreive a set
191 of parameters. In this case \fIname\fR and \fIiv\fR have already been parsed out of
192 the session ticket. The OpenSSL library expects that the \fIname\fR will be used
193 to retrieve a cryptographic parameters and that the cryptographic context
194 \&\fIctx\fR will be set with the retreived parameters and the initialization vector
195 \&\fIiv\fR. using a function like EVP_DecryptInit_ex. The \fIhctx\fR needs to be set
196 using HMAC_Init_ex.
197 .PP
198 If the \fIname\fR is still valid but a renewal of the ticket is required the
199 callback function should return 2. The library will call the callback again
200 with an arguement of enc equal to 1 to set the new ticket.
201 .PP
202 The return value of the \fIcb\fR function is used by OpenSSL to determine what
203 further processing will occur. The following return values have meaning:
204 .IP "2" 4
205 .IX Item "2"
206 This indicates that the \fIctx\fR and \fIhctx\fR have been set and the session can 
207 continue on those parameters. Additionally it indicates that the session
208 ticket is in a renewal period and should be replaced. The OpenSSL library will
209 call \fIcb\fR again with an enc argument of 1 to set the new ticket (see \s-1RFC5077\s0
210 3.3 paragraph 2).
211 .IP "1" 4
212 .IX Item "1"
213 This indicates that the \fIctx\fR and \fIhctx\fR have been set and the session can 
214 continue on those parameters.
215 .IP "0" 4
216 This indicates that it was not possible to set/retrieve a session ticket and 
217 the \s-1SSL/TLS\s0 session will continue by by negiotationing a set of cryptographic
218 parameters or using the alternate \s-1SSL/TLS\s0 resumption mechanism, session ids.
219 .Sp
220 If called with enc equal to 0 the library will call the \fIcb\fR again to get
221 a new set of parameters.
222 .IP "less than 0" 4
223 .IX Item "less than 0"
224 This indicates an error.
225 .SH "NOTES"
226 .IX Header "NOTES"
227 Session resumption shortcuts the \s-1TLS\s0 so that the client certificate
228 negiotation don't occur. It makes up for this by storing client certificate
229 an all other negotiated state information encrypted within the ticket. In a
230 resumed session the applications will have all this state information available
231 exactly as if a full negiotation had occured.
232 .PP
233 If an attacker can obtain the key used to encrypt a session ticket, they can
234 obtain the master secret for any ticket using that key and decrypt any traffic
235 using that session: even if the ciphersuite supports forward secrecy. As
236 a result applications may wish to use multiple keys and avoid using long term
237 keys stored in files.
238 .PP
239 Applications can use longer keys to maintain a consistent level of security.
240 For example if a ciphersuite uses 256 bit ciphers but only a 128 bit ticket key
241 the overall security is only 128 bits because breaking the ticket key will
242 enable an attacker to obtain the session keys.
243 .SH "EXAMPLES"
244 .IX Header "EXAMPLES"
245 Reference Implemention:
246   SSL_CTX_set_tlsext_ticket_key_cb(\s-1SSL\s0,ssl_tlsext_ticket_key_cb);
247   ....
248 .PP
249 .Vb 6
250 \&  static int ssl_tlsext_ticket_key_cb(SSL *s, unsigned char key_name[16], unsigned char *iv, EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc)
251 \&  {
252 \&      if (enc) { /* create new session */
253 \&          if (RAND_bytes(iv, EVP_MAX_IV_LENGTH) ) {
254 \&              return \-1; /* insufficient random */
255 \&          }
256 \&  
257 \&          key = currentkey(); /* something that you need to implement */
258 \&          if ( !key ) {
259 \&              /* current key doesn\*(Aqt exist or isn\*(Aqt valid */
260 \&              key = createkey(); /* something that you need to implement.
261 \&                                   * createkey needs to initialise, a name,
262 \&                                   * an aes_key, a hmac_key and optionally
263 \&                                   * an expire time. */
264 \&              if ( !key ) { /* key couldn\*(Aqt be created */
265 \&                  return 0;
266 \&              }
267 \&          }
268 \&          memcpy(key_name, key\->name, 16);
269 \&  
270 \&          EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key\->aes_key, iv);
271 \&          HMAC_Init_ex(&hctx, key\->hmac_key, 16, EVP_sha256(), NULL);
272 \&  
273 \&          return 1;
274 \&  
275 \&      } else { /* retrieve session */
276 \&          key = findkey(name);
277 \&  
278 \&          if  (!key || key\->expire < now() ) {
279 \&              return 0;
280 \&          }
281 \&  
282 \&          HMAC_Init_ex(&hctx, key\->hmac_key, 16, EVP_sha256(), NULL);
283 \&          EVP_DecryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key\->aes_key, iv );
284 \&
285 \&          if (key\->expire < ( now() \- RENEW_TIME ) ) {
286 \&              /* return 2 \- this session will get a new ticket even though the current is still valid */
287 \&              return 2;
288 \&          }
289 \&          return 1;
290 \&  
291 \&      }
292 \&  }
293 .Ve
294 .SH "RETURN VALUES"
295 .IX Header "RETURN VALUES"
296 returns 0 to indicate the callback function was set.
297 .SH "SEE ALSO"
298 .IX Header "SEE ALSO"
299 \&\fIssl\fR\|(3), \fISSL_set_session\fR\|(3),
300 \&\fISSL_session_reused\fR\|(3),
301 \&\fISSL_CTX_add_session\fR\|(3),
302 \&\fISSL_CTX_sess_number\fR\|(3),
303 \&\fISSL_CTX_sess_set_get_cb\fR\|(3),
304 \&\fISSL_CTX_set_session_id_context\fR\|(3),
305 .SH "HISTORY"
306 .IX Header "HISTORY"
307 This function was introduced in OpenSSL 0.9.8h