1SSL_CTX_set_tlsext_ticket_key_cb(3) OpenSSLSSL_CTX_set_tlsext_ticket_key_cb(3)
2
3
4

NAME

6       SSL_CTX_set_tlsext_ticket_key_cb - set a callback for session ticket
7       processing
8

SYNOPSIS

10        #include <openssl/tls1.h>
11
12        long SSL_CTX_set_tlsext_ticket_key_cb(SSL_CTX sslctx,
13               int (*cb)(SSL *s, unsigned char key_name[16],
14                         unsigned char iv[EVP_MAX_IV_LENGTH],
15                         EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc));
16

DESCRIPTION

18       SSL_CTX_set_tlsext_ticket_key_cb() sets a callback fuction cb for
19       handling session tickets for the ssl context sslctx. Session tickets,
20       defined in RFC5077 provide an enhanced session resumption capability
21       where the server implementation is not required to maintain per session
22       state. It only applies to TLS and there is no SSLv3 implementation.
23
24       The callback is available when the OpenSSL library was built without
25       OPENSSL_NO_TLSEXT being defined.
26
27       The callback function cb will be called for every client instigated TLS
28       session when session ticket extension is presented in the TLS hello
29       message. It is the responsibility of this function to create or
30       retrieve the cryptographic parameters and to maintain their state.
31
32       The OpenSSL library uses your callback function to help implement a
33       common TLS ticket construction state according to RFC5077 Section 4
34       such that per session state is unnecessary and a small set of
35       cryptographic variables needs to be maintained by the callback function
36       implementation.
37
38       In order to reuse a session, a TLS client must send the a session
39       ticket extension to the server. The client can only send exactly one
40       session ticket.  The server, through the callback function, either
41       agrees to reuse the session ticket information or it starts a full TLS
42       handshake to create a new session ticket.
43
44       Before the callback function is started ctx and hctx have been
45       initialised with EVP_CIPHER_CTX_init and HMAC_CTX_init respectively.
46
47       For new sessions tickets, when the client doesn't present a session
48       ticket, or an attempted retreival of the ticket failed, or a renew
49       option was indicated, the callback function will be called with enc
50       equal to 1. The OpenSSL library expects that the function will set an
51       arbitary name, initialize iv, and set the cipher context ctx and the
52       hash context hctx.
53
54       The name is 16 characters long and is used as a key identifier.
55
56       The iv length is the length of the IV of the corresponding cipher. The
57       maximum IV length is EVP_MAX_IV_LENGTH bytes defined in evp.h.
58
59       The initialization vector iv should be a random value. The cipher
60       context ctx should use the initialisation vector iv. The cipher context
61       can be set using EVP_EncryptInit_ex. The hmac context can be set using
62       HMAC_Init_ex.
63
64       When the client presents a session ticket, the callback function with
65       be called with enc set to 0 indicating that the cb function should
66       retreive a set of parameters. In this case name and iv have already
67       been parsed out of the session ticket. The OpenSSL library expects that
68       the name will be used to retrieve a cryptographic parameters and that
69       the cryptographic context ctx will be set with the retreived parameters
70       and the initialization vector iv. using a function like
71       EVP_DecryptInit_ex. The hctx needs to be set using HMAC_Init_ex.
72
73       If the name is still valid but a renewal of the ticket is required the
74       callback function should return 2. The library will call the callback
75       again with an arguement of enc equal to 1 to set the new ticket.
76
77       The return value of the cb function is used by OpenSSL to determine
78       what further processing will occur. The following return values have
79       meaning:
80
81       2   This indicates that the ctx and hctx have been set and the session
82           can continue on those parameters. Additionally it indicates that
83           the session ticket is in a renewal period and should be replaced.
84           The OpenSSL library will call cb again with an enc argument of 1 to
85           set the new ticket (see RFC5077 3.3 paragraph 2).
86
87       1   This indicates that the ctx and hctx have been set and the session
88           can continue on those parameters.
89
90       0   This indicates that it was not possible to set/retrieve a session
91           ticket and the SSL/TLS session will continue by by negiotationing a
92           set of cryptographic parameters or using the alternate SSL/TLS
93           resumption mechanism, session ids.
94
95           If called with enc equal to 0 the library will call the cb again to
96           get a new set of parameters.
97
98       less than 0
99           This indicates an error.
100

NOTES

102       Session resumption shortcuts the TLS so that the client certificate
103       negiotation don't occur. It makes up for this by storing client
104       certificate an all other negotiated state information encrypted within
105       the ticket. In a resumed session the applications will have all this
106       state information available exactly as if a full negiotation had
107       occured.
108
109       If an attacker can obtain the key used to encrypt a session ticket,
110       they can obtain the master secret for any ticket using that key and
111       decrypt any traffic using that session: even if the ciphersuite
112       supports forward secrecy. As a result applications may wish to use
113       multiple keys and avoid using long term keys stored in files.
114
115       Applications can use longer keys to maintain a consistent level of
116       security.  For example if a ciphersuite uses 256 bit ciphers but only a
117       128 bit ticket key the overall security is only 128 bits because
118       breaking the ticket key will enable an attacker to obtain the session
119       keys.
120

EXAMPLES

122       Reference Implemention:
123         SSL_CTX_set_tlsext_ticket_key_cb(SSL,ssl_tlsext_ticket_key_cb);
124         ....
125
126         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)
127         {
128             if (enc) { /* create new session */
129                 if (RAND_bytes(iv, EVP_MAX_IV_LENGTH) ) {
130                     return -1; /* insufficient random */
131                 }
132
133                 key = currentkey(); /* something that you need to implement */
134                 if ( !key ) {
135                     /* current key doesn't exist or isn't valid */
136                     key = createkey(); /* something that you need to implement.
137                                          * createkey needs to initialise, a name,
138                                          * an aes_key, a hmac_key and optionally
139                                          * an expire time. */
140                     if ( !key ) { /* key couldn't be created */
141                         return 0;
142                     }
143                 }
144                 memcpy(key_name, key->name, 16);
145
146                 EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key->aes_key, iv);
147                 HMAC_Init_ex(&hctx, key->hmac_key, 16, EVP_sha256(), NULL);
148
149                 return 1;
150
151             } else { /* retrieve session */
152                 key = findkey(name);
153
154                 if  (!key || key->expire < now() ) {
155                     return 0;
156                 }
157
158                 HMAC_Init_ex(&hctx, key->hmac_key, 16, EVP_sha256(), NULL);
159                 EVP_DecryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key->aes_key, iv );
160
161                 if (key->expire < ( now() - RENEW_TIME ) ) {
162                     /* return 2 - this session will get a new ticket even though the current is still valid */
163                     return 2;
164                 }
165                 return 1;
166
167             }
168         }
169

RETURN VALUES

171       returns 0 to indicate the callback function was set.
172

SEE ALSO

174       ssl(3), SSL_set_session(3), SSL_session_reused(3),
175       SSL_CTX_add_session(3), SSL_CTX_sess_number(3),
176       SSL_CTX_sess_set_get_cb(3), SSL_CTX_set_session_id_context(3),
177

HISTORY

179       This function was introduced in OpenSSL 0.9.8h
180
181
182
1831.0.2o                            2020-08-01SSL_CTX_set_tlsext_ticket_key_cb(3)
Impressum