]> git.ipfire.org Git - thirdparty/hostap.git/blame - patches/openssl-0.9.9-session-ticket.patch
Update ChangeLog files to match the current implementation
[thirdparty/hostap.git] / patches / openssl-0.9.9-session-ticket.patch
CommitLineData
d4092763 1This patch adds support for TLS SessionTicket extension (RFC 5077) for
6fc6879b
JM
2the parts used by EAP-FAST (RFC 4851).
3
4This is based on the patch from Alexey Kobozev <akobozev@cisco.com>
5(sent to openssl-dev mailing list on Tue, 07 Jun 2005 15:40:58 +0300).
6
31a4c885
JM
7NOTE: This patch (without SSL_set_hello_extension() wrapper) was
8merged into the upstream OpenSSL 0.9.9 tree and as such, an external
9patch for EAP-FAST support is not needed anymore.
10
6fc6879b
JM
11
12
d13c05ca 13Index: openssl-SNAP-20081111/ssl/s3_clnt.c
3d1aa251 14===================================================================
d13c05ca
JM
15--- openssl-SNAP-20081111.orig/ssl/s3_clnt.c
16+++ openssl-SNAP-20081111/ssl/s3_clnt.c
17@@ -788,6 +788,23 @@ int ssl3_get_server_hello(SSL *s)
6fc6879b
JM
18 goto f_err;
19 }
20
6fc6879b 21+#ifndef OPENSSL_NO_TLSEXT
d4092763 22+ /* check if we want to resume the session based on external pre-shared secret */
6fc6879b 23+ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
d13c05ca 24+ {
6fc6879b
JM
25+ SSL_CIPHER *pref_cipher=NULL;
26+ s->session->master_key_length=sizeof(s->session->master_key);
d13c05ca
JM
27+ if (s->tls_session_secret_cb(s, s->session->master_key,
28+ &s->session->master_key_length,
29+ NULL, &pref_cipher,
30+ s->tls_session_secret_cb_arg))
31+ {
32+ s->session->cipher = pref_cipher ?
33+ pref_cipher : ssl_get_cipher_by_char(s, p+j);
34+ }
6fc6879b 35+ }
6fc6879b
JM
36+#endif /* OPENSSL_NO_TLSEXT */
37+
d4092763 38 if (j != 0 && j == s->session->session_id_length
6fc6879b
JM
39 && memcmp(p,s->session->session_id,j) == 0)
40 {
d13c05ca 41@@ -2927,11 +2944,8 @@ static int ssl3_check_finished(SSL *s)
88160457
JM
42 {
43 int ok;
44 long n;
45- /* If we have no ticket or session ID is non-zero length (a match of
46- * a non-zero session length would never reach here) it cannot be a
47- * resumed session.
48- */
49- if (!s->session->tlsext_tick || s->session->session_id_length)
50+ /* If we have no ticket it cannot be a resumed session. */
51+ if (!s->session->tlsext_tick)
52 return 1;
53 /* this function is called when we really expect a Certificate
54 * message, so permit appropriate message length */
d13c05ca 55Index: openssl-SNAP-20081111/ssl/s3_srvr.c
3d1aa251 56===================================================================
d13c05ca
JM
57--- openssl-SNAP-20081111.orig/ssl/s3_srvr.c
58+++ openssl-SNAP-20081111/ssl/s3_srvr.c
1a647aaa 59@@ -1010,6 +1010,59 @@ int ssl3_get_client_hello(SSL *s)
6fc6879b
JM
60 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
61 goto err;
62 }
63+
64+ /* Check if we want to use external pre-shared secret for this
65+ * handshake for not reused session only. We need to generate
66+ * server_random before calling tls_session_secret_cb in order to allow
67+ * SessionTicket processing to use it in key derivation. */
68+ {
69+ unsigned long Time;
70+ unsigned char *pos;
71+ Time=(unsigned long)time(NULL); /* Time */
72+ pos=s->s3->server_random;
73+ l2n(Time,pos);
74+ if (RAND_pseudo_bytes(pos,SSL3_RANDOM_SIZE-4) <= 0)
d13c05ca 75+ {
6fc6879b
JM
76+ al=SSL_AD_INTERNAL_ERROR;
77+ goto f_err;
d13c05ca 78+ }
6fc6879b
JM
79+ }
80+
81+ if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb)
d13c05ca 82+ {
6fc6879b
JM
83+ SSL_CIPHER *pref_cipher=NULL;
84+
85+ s->session->master_key_length=sizeof(s->session->master_key);
3d1aa251 86+ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
6fc6879b 87+ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
d13c05ca 88+ {
6fc6879b
JM
89+ s->hit=1;
90+ s->session->ciphers=ciphers;
91+ s->session->verify_result=X509_V_OK;
3d1aa251 92+
6fc6879b 93+ ciphers=NULL;
3d1aa251 94+
6fc6879b
JM
95+ /* check if some cipher was preferred by call back */
96+ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
97+ if (pref_cipher == NULL)
98+ {
99+ al=SSL_AD_HANDSHAKE_FAILURE;
100+ SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
101+ goto f_err;
102+ }
103+
104+ s->session->cipher=pref_cipher;
105+
106+ if (s->cipher_list)
107+ sk_SSL_CIPHER_free(s->cipher_list);
108+
109+ if (s->cipher_list_by_id)
110+ sk_SSL_CIPHER_free(s->cipher_list_by_id);
111+
112+ s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
113+ s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);
d13c05ca 114+ }
6fc6879b 115+ }
6fc6879b
JM
116 #endif
117
118 /* Worst case, we will use the NULL compression, but if we have other
1a647aaa 119@@ -1134,16 +1187,22 @@ int ssl3_send_server_hello(SSL *s)
6fc6879b
JM
120 unsigned char *buf;
121 unsigned char *p,*d;
122 int i,sl;
123- unsigned long l,Time;
124+ unsigned long l;
125+#ifdef OPENSSL_NO_TLSEXT
126+ unsigned long Time;
127+#endif
128
129 if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
130 {
131 buf=(unsigned char *)s->init_buf->data;
132+#ifdef OPENSSL_NO_TLSEXT
133 p=s->s3->server_random;
134+ /* Generate server_random if it was not needed previously */
135 Time=(unsigned long)time(NULL); /* Time */
136 l2n(Time,p);
137 if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
138 return -1;
139+#endif
140 /* Do the message type and length last */
141 d=p= &(buf[4]);
142
d13c05ca 143Index: openssl-SNAP-20081111/ssl/ssl_err.c
3d1aa251 144===================================================================
d13c05ca
JM
145--- openssl-SNAP-20081111.orig/ssl/ssl_err.c
146+++ openssl-SNAP-20081111/ssl/ssl_err.c
3d1aa251
JM
147@@ -263,6 +263,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
148 {ERR_FUNC(SSL_F_TLS1_PRF), "tls1_prf"},
149 {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
150 {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
1b554eb0 151+{ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT), "SSL_set_session_ticket_ext"},
3d1aa251
JM
152 {0,NULL}
153 };
154
d13c05ca 155Index: openssl-SNAP-20081111/ssl/ssl.h
3d1aa251 156===================================================================
d13c05ca
JM
157--- openssl-SNAP-20081111.orig/ssl/ssl.h
158+++ openssl-SNAP-20081111/ssl/ssl.h
1a647aaa 159@@ -355,6 +355,7 @@ extern "C" {
6fc6879b
JM
160 * 'struct ssl_st *' function parameters used to prototype callbacks
161 * in SSL_CTX. */
162 typedef struct ssl_st *ssl_crock_st;
1b554eb0 163+typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
6fc6879b
JM
164
165 /* used to hold info on the particular ciphers used */
166 typedef struct ssl_cipher_st
1a647aaa 167@@ -378,6 +379,8 @@ typedef struct ssl_cipher_st
3d1aa251
JM
168
169 DECLARE_STACK_OF(SSL_CIPHER)
6fc6879b
JM
170
171+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);
172+
173 /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
174 typedef struct ssl_method_st
175 {
1a647aaa 176@@ -1145,6 +1148,13 @@ struct ssl_st
6fc6879b
JM
177 void *tlsext_opaque_prf_input;
178 size_t tlsext_opaque_prf_input_len;
179
1b554eb0
JM
180+ /* TLS Session Ticket extension override */
181+ TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
6fc6879b
JM
182+
183+ /* TLS pre-shared secret session resumption */
184+ tls_session_secret_cb_fn tls_session_secret_cb;
185+ void *tls_session_secret_cb_arg;
186+
187 SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
188 #define session_ctx initial_ctx
189 #else
1b554eb0 190@@ -1746,6 +1756,16 @@ void *SSL_COMP_get_compression_methods(v
6fc6879b
JM
191 int SSL_COMP_add_compression_method(int id,void *cm);
192 #endif
193
1b554eb0
JM
194+/* NOTE: This function will be removed; it is only here for backwards
195+ * compatibility for the API during testing. */
6fc6879b
JM
196+int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len);
197+
1b554eb0
JM
198+/* TLS extensions functions */
199+int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);
200+
6fc6879b
JM
201+/* Pre-shared secret session resumption functions */
202+int SSL_set_session_secret_cb(SSL *s, tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
203+
204 /* BEGIN ERROR CODES */
205 /* The following lines are auto generated by the script mkerr.pl. Any changes
206 * made after this point may be overwritten when the script is next run.
1b554eb0 207@@ -1948,6 +1968,7 @@ void ERR_load_SSL_strings(void);
6fc6879b
JM
208 #define SSL_F_TLS1_PRF 284
209 #define SSL_F_TLS1_SETUP_KEY_BLOCK 211
210 #define SSL_F_WRITE_PENDING 212
1b554eb0 211+#define SSL_F_SSL_SET_SESSION_TICKET_EXT 213
6fc6879b
JM
212
213 /* Reason codes. */
214 #define SSL_R_APP_DATA_IN_HANDSHAKE 100
d13c05ca 215Index: openssl-SNAP-20081111/ssl/ssl_sess.c
3d1aa251 216===================================================================
d13c05ca
JM
217--- openssl-SNAP-20081111.orig/ssl/ssl_sess.c
218+++ openssl-SNAP-20081111/ssl/ssl_sess.c
1b554eb0 219@@ -834,6 +834,62 @@ long SSL_CTX_get_timeout(const SSL_CTX *
6fc6879b
JM
220 return(s->session_timeout);
221 }
222
223+#ifndef OPENSSL_NO_TLSEXT
3d1aa251 224+int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
6fc6879b 225+ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
d13c05ca 226+ {
6fc6879b
JM
227+ if (s == NULL) return(0);
228+ s->tls_session_secret_cb = tls_session_secret_cb;
229+ s->tls_session_secret_cb_arg = arg;
230+ return(1);
d13c05ca 231+ }
6fc6879b 232+
1b554eb0 233+int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
6fc6879b 234+ {
d13c05ca 235+ if (s->version >= TLS1_VERSION)
6fc6879b 236+ {
1b554eb0 237+ if (s->tlsext_session_ticket)
d13c05ca 238+ {
1b554eb0
JM
239+ OPENSSL_free(s->tlsext_session_ticket);
240+ s->tlsext_session_ticket = NULL;
d13c05ca 241+ }
6fc6879b 242+
1b554eb0
JM
243+ s->tlsext_session_ticket = OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
244+ if (!s->tlsext_session_ticket)
d13c05ca 245+ {
1b554eb0 246+ SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE);
6fc6879b 247+ return 0;
d13c05ca 248+ }
6fc6879b 249+
d13c05ca
JM
250+ if (ext_data)
251+ {
1b554eb0
JM
252+ s->tlsext_session_ticket->length = ext_len;
253+ s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1;
254+ memcpy(s->tlsext_session_ticket->data, ext_data, ext_len);
d13c05ca
JM
255+ }
256+ else
257+ {
1b554eb0
JM
258+ s->tlsext_session_ticket->length = 0;
259+ s->tlsext_session_ticket->data = NULL;
d13c05ca 260+ }
6fc6879b
JM
261+
262+ return 1;
d13c05ca 263+ }
6fc6879b
JM
264+
265+ return 0;
d13c05ca 266+ }
1b554eb0
JM
267+
268+/* NOTE: This function will be removed; it is only here for backwards
269+ * compatibility for the API during testing. */
270+int SSL_set_hello_extension(SSL *s, int ext_type, void *ext_data, int ext_len)
271+ {
272+ if (ext_type != TLSEXT_TYPE_session_ticket)
273+ return 0;
274+
275+ return SSL_set_session_ticket_ext(s, ext_data, ext_len);
276+ }
6fc6879b
JM
277+#endif /* OPENSSL_NO_TLSEXT */
278+
279 typedef struct timeout_param_st
280 {
281 SSL_CTX *ctx;
d13c05ca 282Index: openssl-SNAP-20081111/ssl/t1_lib.c
3d1aa251 283===================================================================
d13c05ca
JM
284--- openssl-SNAP-20081111.orig/ssl/t1_lib.c
285+++ openssl-SNAP-20081111/ssl/t1_lib.c
6fc6879b
JM
286@@ -154,6 +154,12 @@ int tls1_new(SSL *s)
287
288 void tls1_free(SSL *s)
289 {
290+#ifndef OPENSSL_NO_TLSEXT
1b554eb0 291+ if (s->tlsext_session_ticket)
d13c05ca 292+ {
1b554eb0 293+ OPENSSL_free(s->tlsext_session_ticket);
d13c05ca
JM
294+ }
295+#endif /* OPENSSL_NO_TLSEXT */
6fc6879b
JM
296 ssl3_free(s);
297 }
298
1b554eb0 299@@ -357,8 +363,23 @@ unsigned char *ssl_add_clienthello_tlsex
6fc6879b
JM
300 int ticklen;
301 if (s->session && s->session->tlsext_tick)
302 ticklen = s->session->tlsext_ticklen;
1b554eb0
JM
303+ else if (s->session && s->tlsext_session_ticket &&
304+ s->tlsext_session_ticket->data)
d13c05ca 305+ {
1b554eb0 306+ ticklen = s->tlsext_session_ticket->length;
6fc6879b
JM
307+ s->session->tlsext_tick = OPENSSL_malloc(ticklen);
308+ if (!s->session->tlsext_tick)
309+ return NULL;
1b554eb0
JM
310+ memcpy(s->session->tlsext_tick,
311+ s->tlsext_session_ticket->data,
6fc6879b
JM
312+ ticklen);
313+ s->session->tlsext_ticklen = ticklen;
d13c05ca 314+ }
6fc6879b
JM
315 else
316 ticklen = 0;
1b554eb0
JM
317+ if (ticklen == 0 && s->tlsext_session_ticket &&
318+ s->tlsext_session_ticket->data == NULL)
6fc6879b
JM
319+ goto skip_ext;
320 /* Check for enough room 2 for extension type, 2 for len
321 * rest for ticket
322 */
1b554eb0 323@@ -371,6 +392,7 @@ unsigned char *ssl_add_clienthello_tlsex
6fc6879b
JM
324 ret += ticklen;
325 }
326 }
327+ skip_ext:
328
329 #ifdef TLSEXT_TYPE_opaque_prf_input
330 if (s->s3->client_opaque_prf_input != NULL)
1b554eb0 331@@ -1435,6 +1457,15 @@ int tls1_process_ticket(SSL *s, unsigned
6fc6879b
JM
332 s->tlsext_ticket_expected = 1;
333 return 0; /* Cache miss */
334 }
335+ if (s->tls_session_secret_cb)
3d1aa251
JM
336+ {
337+ /* Indicate cache miss here and instead of
338+ * generating the session from ticket now,
339+ * trigger abbreviated handshake based on
340+ * external mechanism to calculate the master
341+ * secret later. */
6fc6879b 342+ return 0;
3d1aa251 343+ }
6fc6879b
JM
344 return tls_decrypt_ticket(s, p, size, session_id, len,
345 ret);
346 }
d13c05ca 347Index: openssl-SNAP-20081111/ssl/tls1.h
3d1aa251 348===================================================================
d13c05ca
JM
349--- openssl-SNAP-20081111.orig/ssl/tls1.h
350+++ openssl-SNAP-20081111/ssl/tls1.h
1b554eb0 351@@ -512,6 +512,13 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_T
6fc6879b
JM
352 #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
353 #endif
354
1b554eb0
JM
355+/* TLS Session Ticket extension struct */
356+struct tls_session_ticket_ext_st
d13c05ca 357+ {
6fc6879b
JM
358+ unsigned short length;
359+ void *data;
d13c05ca 360+ };
6fc6879b
JM
361+
362 #ifdef __cplusplus
363 }
364 #endif
d13c05ca 365Index: openssl-SNAP-20081111/util/ssleay.num
3d1aa251 366===================================================================
d13c05ca
JM
367--- openssl-SNAP-20081111.orig/util/ssleay.num
368+++ openssl-SNAP-20081111/util/ssleay.num
3d1aa251
JM
369@@ -254,3 +254,5 @@ PEM_read_bio_SSL_SESSION
370 SSL_CTX_set_psk_server_callback 303 EXIST::FUNCTION:PSK
371 SSL_get_psk_identity 304 EXIST::FUNCTION:PSK
372 PEM_write_SSL_SESSION 305 EXIST:!WIN16:FUNCTION:
1b554eb0 373+SSL_set_session_ticket_ext 306 EXIST::FUNCTION:TLSEXT
3d1aa251 374+SSL_set_session_secret_cb 307 EXIST::FUNCTION:TLSEXT