1 diff -up openssl-0.9.8j/ssl/t1_lib.c.eap-fast openssl-0.9.8j/ssl/t1_lib.c
2 --- openssl-0.9.8j/ssl/t1_lib.c.eap-fast 2009-01-14 16:39:41.000000000 +0100
3 +++ openssl-0.9.8j/ssl/t1_lib.c 2009-01-14 21:35:38.000000000 +0100
4 @@ -106,6 +106,12 @@ int tls1_new(SSL *s)
8 +#ifndef OPENSSL_NO_TLSEXT
9 + if (s && s->tlsext_session_ticket)
11 + OPENSSL_free(s->tlsext_session_ticket);
13 +#endif /* OPENSSL_NO_TLSEXT */
17 @@ -180,8 +186,23 @@ unsigned char *ssl_add_clienthello_tlsex
19 if (s->session && s->session->tlsext_tick)
20 ticklen = s->session->tlsext_ticklen;
21 + else if (s->session && s->tlsext_session_ticket &&
22 + s->tlsext_session_ticket->data)
24 + ticklen = s->tlsext_session_ticket->length;
25 + s->session->tlsext_tick = OPENSSL_malloc(ticklen);
26 + if (!s->session->tlsext_tick)
28 + memcpy(s->session->tlsext_tick,
29 + s->tlsext_session_ticket->data,
31 + s->session->tlsext_ticklen = ticklen;
35 + if (ticklen == 0 && s->tlsext_session_ticket &&
36 + s->tlsext_session_ticket->data == NULL)
38 /* Check for enough room 2 for extension type, 2 for len
41 @@ -195,6 +216,7 @@ unsigned char *ssl_add_clienthello_tlsex
47 if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp)
49 @@ -417,6 +439,15 @@ int ssl_parse_clienthello_tlsext(SSL *s,
53 + else if (type == TLSEXT_TYPE_session_ticket)
55 + if (s->tls_session_ticket_ext_cb &&
56 + !s->tls_session_ticket_ext_cb(s, data, size, s->tls_session_ticket_ext_cb_arg))
58 + *al = TLS1_AD_INTERNAL_ERROR;
62 else if (type == TLSEXT_TYPE_status_request
63 && s->ctx->tlsext_status_cb)
65 @@ -563,6 +594,12 @@ int ssl_parse_serverhello_tlsext(SSL *s,
67 else if (type == TLSEXT_TYPE_session_ticket)
69 + if (s->tls_session_ticket_ext_cb &&
70 + !s->tls_session_ticket_ext_cb(s, data, size, s->tls_session_ticket_ext_cb_arg))
72 + *al = TLS1_AD_INTERNAL_ERROR;
75 if ((SSL_get_options(s) & SSL_OP_NO_TICKET)
78 @@ -786,6 +823,15 @@ int tls1_process_ticket(SSL *s, unsigned
79 s->tlsext_ticket_expected = 1;
80 return 0; /* Cache miss */
82 + if (s->tls_session_secret_cb)
84 + /* Indicate cache miss here and instead of
85 + * generating the session from ticket now,
86 + * trigger abbreviated handshake based on
87 + * external mechanism to calculate the master
91 return tls_decrypt_ticket(s, p, size, session_id, len,
94 diff -up openssl-0.9.8j/ssl/s3_clnt.c.eap-fast openssl-0.9.8j/ssl/s3_clnt.c
95 --- openssl-0.9.8j/ssl/s3_clnt.c.eap-fast 2009-01-07 11:48:23.000000000 +0100
96 +++ openssl-0.9.8j/ssl/s3_clnt.c 2009-01-14 21:13:47.000000000 +0100
97 @@ -759,6 +759,23 @@ int ssl3_get_server_hello(SSL *s)
101 +#ifndef OPENSSL_NO_TLSEXT
102 + /* check if we want to resume the session based on external pre-shared secret */
103 + if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
105 + SSL_CIPHER *pref_cipher=NULL;
106 + s->session->master_key_length=sizeof(s->session->master_key);
107 + if (s->tls_session_secret_cb(s, s->session->master_key,
108 + &s->session->master_key_length,
109 + NULL, &pref_cipher,
110 + s->tls_session_secret_cb_arg))
112 + s->session->cipher = pref_cipher ?
113 + pref_cipher : ssl_get_cipher_by_char(s, p+j);
116 +#endif /* OPENSSL_NO_TLSEXT */
118 if (j != 0 && j == s->session->session_id_length
119 && memcmp(p,s->session->session_id,j) == 0)
121 @@ -2701,11 +2718,8 @@ static int ssl3_check_finished(SSL *s)
125 - /* If we have no ticket or session ID is non-zero length (a match of
126 - * a non-zero session length would never reach here) it cannot be a
129 - if (!s->session->tlsext_tick || s->session->session_id_length)
130 + /* If we have no ticket it cannot be a resumed session. */
131 + if (!s->session->tlsext_tick)
133 /* this function is called when we really expect a Certificate
134 * message, so permit appropriate message length */
135 diff -up openssl-0.9.8j/ssl/ssl_sess.c.eap-fast openssl-0.9.8j/ssl/ssl_sess.c
136 --- openssl-0.9.8j/ssl/ssl_sess.c.eap-fast 2008-06-04 20:35:27.000000000 +0200
137 +++ openssl-0.9.8j/ssl/ssl_sess.c 2009-01-14 21:13:47.000000000 +0100
138 @@ -707,6 +707,61 @@ long SSL_CTX_get_timeout(const SSL_CTX *
139 return(s->session_timeout);
142 +#ifndef OPENSSL_NO_TLSEXT
143 +int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
144 + STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
146 + if (s == NULL) return(0);
147 + s->tls_session_secret_cb = tls_session_secret_cb;
148 + s->tls_session_secret_cb_arg = arg;
152 +int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
155 + if (s == NULL) return(0);
156 + s->tls_session_ticket_ext_cb = cb;
157 + s->tls_session_ticket_ext_cb_arg = arg;
161 +int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
163 + if (s->version >= TLS1_VERSION)
165 + if (s->tlsext_session_ticket)
167 + OPENSSL_free(s->tlsext_session_ticket);
168 + s->tlsext_session_ticket = NULL;
171 + s->tlsext_session_ticket = OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
172 + if (!s->tlsext_session_ticket)
174 + SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE);
180 + s->tlsext_session_ticket->length = ext_len;
181 + s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1;
182 + memcpy(s->tlsext_session_ticket->data, ext_data, ext_len);
186 + s->tlsext_session_ticket->length = 0;
187 + s->tlsext_session_ticket->data = NULL;
195 +#endif /* OPENSSL_NO_TLSEXT */
197 typedef struct timeout_param_st
200 diff -up openssl-0.9.8j/ssl/s3_srvr.c.eap-fast openssl-0.9.8j/ssl/s3_srvr.c
201 --- openssl-0.9.8j/ssl/s3_srvr.c.eap-fast 2009-01-07 11:48:23.000000000 +0100
202 +++ openssl-0.9.8j/ssl/s3_srvr.c 2009-01-14 21:22:37.000000000 +0100
203 @@ -965,6 +965,59 @@ int ssl3_get_client_hello(SSL *s)
204 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
208 + /* Check if we want to use external pre-shared secret for this
209 + * handshake for not reused session only. We need to generate
210 + * server_random before calling tls_session_secret_cb in order to allow
211 + * SessionTicket processing to use it in key derivation. */
213 + unsigned long Time;
214 + unsigned char *pos;
215 + Time=(unsigned long)time(NULL); /* Time */
216 + pos=s->s3->server_random;
218 + if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE-4) <= 0)
220 + al=SSL_AD_INTERNAL_ERROR;
225 + if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
227 + SSL_CIPHER *pref_cipher=NULL;
229 + s->session->master_key_length=sizeof(s->session->master_key);
230 + if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
231 + ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
234 + s->session->ciphers=ciphers;
235 + s->session->verify_result=X509_V_OK;
239 + /* check if some cipher was preferred by call back */
240 + pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
241 + if (pref_cipher == NULL)
243 + al=SSL_AD_HANDSHAKE_FAILURE;
244 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
248 + s->session->cipher=pref_cipher;
250 + if (s->cipher_list)
251 + sk_SSL_CIPHER_free(s->cipher_list);
253 + if (s->cipher_list_by_id)
254 + sk_SSL_CIPHER_free(s->cipher_list_by_id);
256 + s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
257 + s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
261 /* Worst case, we will use the NULL compression, but if we have other
262 * options, we will now look for them. We have i-1 compression
263 @@ -1103,16 +1156,22 @@ int ssl3_send_server_hello(SSL *s)
267 - unsigned long l,Time;
269 +#ifdef OPENSSL_NO_TLSEXT
270 + unsigned long Time;
273 if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
275 buf=(unsigned char *)s->init_buf->data;
276 +#ifdef OPENSSL_NO_TLSEXT
277 p=s->s3->server_random;
278 + /* Generate server_random if it was not needed previously */
279 Time=(unsigned long)time(NULL); /* Time */
281 if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
284 /* Do the message type and length last */
287 diff -up openssl-0.9.8j/ssl/tls1.h.eap-fast openssl-0.9.8j/ssl/tls1.h
288 --- openssl-0.9.8j/ssl/tls1.h.eap-fast 2009-01-14 16:39:41.000000000 +0100
289 +++ openssl-0.9.8j/ssl/tls1.h 2009-01-14 21:13:47.000000000 +0100
290 @@ -398,6 +398,13 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_T
291 #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
294 +/* TLS Session Ticket extension struct */
295 +struct tls_session_ticket_ext_st
297 + unsigned short length;
304 diff -up openssl-0.9.8j/ssl/ssl_err.c.eap-fast openssl-0.9.8j/ssl/ssl_err.c
305 --- openssl-0.9.8j/ssl/ssl_err.c.eap-fast 2008-08-13 21:44:44.000000000 +0200
306 +++ openssl-0.9.8j/ssl/ssl_err.c 2009-01-14 21:13:47.000000000 +0100
307 @@ -253,6 +253,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
308 {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
309 {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
310 {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
311 +{ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT), "SSL_set_session_ticket_ext"},
315 diff -up openssl-0.9.8j/ssl/ssl.h.eap-fast openssl-0.9.8j/ssl/ssl.h
316 --- openssl-0.9.8j/ssl/ssl.h.eap-fast 2009-01-14 16:39:41.000000000 +0100
317 +++ openssl-0.9.8j/ssl/ssl.h 2009-01-14 21:26:45.000000000 +0100
318 @@ -344,6 +344,7 @@ extern "C" {
319 * 'struct ssl_st *' function parameters used to prototype callbacks
321 typedef struct ssl_st *ssl_crock_st;
322 +typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
324 /* used to hold info on the particular ciphers used */
325 typedef struct ssl_cipher_st
326 @@ -362,6 +363,9 @@ typedef struct ssl_cipher_st
328 DECLARE_STACK_OF(SSL_CIPHER)
330 +typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data, int len, void *arg);
331 +typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
333 /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
334 typedef struct ssl_method_st
336 @@ -1034,6 +1038,18 @@ struct ssl_st
338 /* RFC4507 session ticket expected to be received or sent */
339 int tlsext_ticket_expected;
341 + /* TLS Session Ticket extension override */
342 + TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
344 + /* TLS Session Ticket extension callback */
345 + tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb;
346 + void *tls_session_ticket_ext_cb_arg;
348 + /* TLS pre-shared secret session resumption */
349 + tls_session_secret_cb_fn tls_session_secret_cb;
350 + void *tls_session_secret_cb_arg;
352 SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
353 #define session_ctx initial_ctx
355 @@ -1624,6 +1640,15 @@ void *SSL_COMP_get_compression_methods(v
356 int SSL_COMP_add_compression_method(int id,void *cm);
359 +/* TLS extensions functions */
360 +int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);
362 +int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
365 +/* Pre-shared secret session resumption functions */
366 +int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
368 /* BEGIN ERROR CODES */
369 /* The following lines are auto generated by the script mkerr.pl. Any changes
370 * made after this point may be overwritten when the script is next run.
371 @@ -1816,6 +1841,7 @@ void ERR_load_SSL_strings(void);
372 #define SSL_F_TLS1_ENC 210
373 #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
374 #define SSL_F_WRITE_PENDING 212
375 +#define SSL_F_SSL_SET_SESSION_TICKET_EXT 213
378 #define SSL_R_APP_DATA_IN_HANDSHAKE 100