-This patch adds support for TLS SessionTicket extension (RFC 4507) for
+This patch adds support for TLS SessionTicket extension (RFC 5077) for
the parts used by EAP-FAST (RFC 4851).
This is based on the patch from Alexey Kobozev <akobozev@cisco.com>
-diff -upr openssl-SNAP-20071101.orig/ssl/s3_clnt.c openssl-SNAP-20071101/ssl/s3_clnt.c
---- openssl-SNAP-20071101.orig/ssl/s3_clnt.c 2007-10-26 06:00:28.000000000 -0700
-+++ openssl-SNAP-20071101/ssl/s3_clnt.c 2007-11-01 19:19:43.000000000 -0700
-@@ -715,7 +715,7 @@ int ssl3_get_server_hello(SSL *s)
- STACK_OF(SSL_CIPHER) *sk;
- SSL_CIPHER *c;
- unsigned char *p,*d;
-- int i,al,ok;
-+ int i,al,ok,pre_shared;
- unsigned int j;
- long n;
- #ifndef OPENSSL_NO_COMP
-@@ -782,7 +782,26 @@ int ssl3_get_server_hello(SSL *s)
+Index: openssl-SNAP-20080928/ssl/s3_clnt.c
+===================================================================
+--- openssl-SNAP-20080928.orig/ssl/s3_clnt.c
++++ openssl-SNAP-20080928/ssl/s3_clnt.c
+@@ -788,6 +788,20 @@ int ssl3_get_server_hello(SSL *s)
goto f_err;
}
-- if (j != 0 && j == s->session->session_id_length
-+ /* check if we want to resume the session based on external pre-shared secret */
-+ pre_shared = 0;
+#ifndef OPENSSL_NO_TLSEXT
++ /* check if we want to resume the session based on external pre-shared secret */
+ if (s->version >= TLS1_VERSION && s->tls_session_secret_cb)
+ {
+ SSL_CIPHER *pref_cipher=NULL;
+ if (s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
+ NULL, &pref_cipher, s->tls_session_secret_cb_arg))
+ {
-+ s->hit=1;
+ s->session->cipher=pref_cipher ? pref_cipher : ssl_get_cipher_by_char(s,p+j);
-+ s->session->session_id_length = j;
-+ memcpy(s->session->session_id, p, j);
-+ pre_shared = 1;
+ }
+ }
+#endif /* OPENSSL_NO_TLSEXT */
+
-+ if ((pre_shared || j != 0) && j == s->session->session_id_length
+ if (j != 0 && j == s->session->session_id_length
&& memcmp(p,s->session->session_id,j) == 0)
{
- if(s->sid_ctx_length != s->session->sid_ctx_length
-diff -upr openssl-SNAP-20071101.orig/ssl/s3_srvr.c openssl-SNAP-20071101/ssl/s3_srvr.c
---- openssl-SNAP-20071101.orig/ssl/s3_srvr.c 2007-10-26 06:00:29.000000000 -0700
-+++ openssl-SNAP-20071101/ssl/s3_srvr.c 2007-11-01 19:19:43.000000000 -0700
-@@ -992,6 +992,59 @@ int ssl3_get_client_hello(SSL *s)
+@@ -2927,11 +2941,8 @@ static int ssl3_check_finished(SSL *s)
+ {
+ int ok;
+ long n;
+- /* If we have no ticket or session ID is non-zero length (a match of
+- * a non-zero session length would never reach here) it cannot be a
+- * resumed session.
+- */
+- if (!s->session->tlsext_tick || s->session->session_id_length)
++ /* If we have no ticket it cannot be a resumed session. */
++ if (!s->session->tlsext_tick)
+ return 1;
+ /* this function is called when we really expect a Certificate
+ * message, so permit appropriate message length */
+Index: openssl-SNAP-20080928/ssl/s3_srvr.c
+===================================================================
+--- openssl-SNAP-20080928.orig/ssl/s3_srvr.c
++++ openssl-SNAP-20080928/ssl/s3_srvr.c
+@@ -1010,6 +1010,59 @@ int ssl3_get_client_hello(SSL *s)
SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT);
goto err;
}
+ SSL_CIPHER *pref_cipher=NULL;
+
+ s->session->master_key_length=sizeof(s->session->master_key);
-+ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
++ if(s->tls_session_secret_cb(s, s->session->master_key, &s->session->master_key_length,
+ ciphers, &pref_cipher, s->tls_session_secret_cb_arg))
+ {
+ s->hit=1;
+ s->session->ciphers=ciphers;
+ s->session->verify_result=X509_V_OK;
-+
++
+ ciphers=NULL;
-+
++
+ /* check if some cipher was preferred by call back */
+ pref_cipher=pref_cipher ? pref_cipher : ssl3_choose_cipher(s, s->session->ciphers, SSL_get_ciphers(s));
+ if (pref_cipher == NULL)
#endif
/* Worst case, we will use the NULL compression, but if we have other
-@@ -1118,16 +1171,22 @@ int ssl3_send_server_hello(SSL *s)
+@@ -1134,16 +1187,22 @@ int ssl3_send_server_hello(SSL *s)
unsigned char *buf;
unsigned char *p,*d;
int i,sl;
/* Do the message type and length last */
d=p= &(buf[4]);
-diff -upr openssl-SNAP-20071101.orig/ssl/ssl.h openssl-SNAP-20071101/ssl/ssl.h
---- openssl-SNAP-20071101.orig/ssl/ssl.h 2007-10-26 17:01:28.000000000 -0700
-+++ openssl-SNAP-20071101/ssl/ssl.h 2007-11-01 19:20:47.000000000 -0700
-@@ -353,6 +353,7 @@ extern "C" {
+Index: openssl-SNAP-20080928/ssl/ssl_err.c
+===================================================================
+--- openssl-SNAP-20080928.orig/ssl/ssl_err.c
++++ openssl-SNAP-20080928/ssl/ssl_err.c
+@@ -263,6 +263,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
+ {ERR_FUNC(SSL_F_TLS1_PRF), "tls1_prf"},
+ {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
+ {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
++{ERR_FUNC(SSL_F_SSL_SET_HELLO_EXTENSION), "SSL_set_hello_extension"},
+ {0,NULL}
+ };
+
+Index: openssl-SNAP-20080928/ssl/ssl.h
+===================================================================
+--- openssl-SNAP-20080928.orig/ssl/ssl.h
++++ openssl-SNAP-20080928/ssl/ssl.h
+@@ -355,6 +355,7 @@ extern "C" {
* 'struct ssl_st *' function parameters used to prototype callbacks
* in SSL_CTX. */
typedef struct ssl_st *ssl_crock_st;
/* used to hold info on the particular ciphers used */
typedef struct ssl_cipher_st
-@@ -379,6 +380,8 @@ DECLARE_STACK_OF(SSL_CIPHER)
- typedef struct ssl_st SSL;
- typedef struct ssl_ctx_st SSL_CTX;
+@@ -378,6 +379,8 @@ typedef struct ssl_cipher_st
+
+ DECLARE_STACK_OF(SSL_CIPHER)
+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);
+
/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
typedef struct ssl_method_st
{
-@@ -1121,6 +1124,13 @@ struct ssl_st
+@@ -1145,6 +1148,13 @@ struct ssl_st
void *tlsext_opaque_prf_input;
size_t tlsext_opaque_prf_input_len;
SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
#define session_ctx initial_ctx
#else
-@@ -1721,6 +1731,12 @@ void *SSL_COMP_get_compression_methods(v
+@@ -1746,6 +1756,12 @@ void *SSL_COMP_get_compression_methods(v
int SSL_COMP_add_compression_method(int id,void *cm);
#endif
/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.
-@@ -1920,6 +1936,7 @@ void ERR_load_SSL_strings(void);
+@@ -1948,6 +1964,7 @@ void ERR_load_SSL_strings(void);
#define SSL_F_TLS1_PRF 284
#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
#define SSL_F_WRITE_PENDING 212
/* Reason codes. */
#define SSL_R_APP_DATA_IN_HANDSHAKE 100
-diff -upr openssl-SNAP-20071101.orig/ssl/ssl_err.c openssl-SNAP-20071101/ssl/ssl_err.c
---- openssl-SNAP-20071101.orig/ssl/ssl_err.c 2007-10-26 17:01:29.000000000 -0700
-+++ openssl-SNAP-20071101/ssl/ssl_err.c 2007-11-01 19:19:43.000000000 -0700
-@@ -260,6 +260,7 @@ static ERR_STRING_DATA SSL_str_functs[]=
- {ERR_FUNC(SSL_F_TLS1_PRF), "tls1_prf"},
- {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
- {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
-+{ERR_FUNC(SSL_F_SSL_SET_HELLO_EXTENSION), "SSL_set_hello_extension"},
- {0,NULL}
- };
-
-diff -upr openssl-SNAP-20071101.orig/ssl/ssl_sess.c openssl-SNAP-20071101/ssl/ssl_sess.c
---- openssl-SNAP-20071101.orig/ssl/ssl_sess.c 2007-10-17 11:00:45.000000000 -0700
-+++ openssl-SNAP-20071101/ssl/ssl_sess.c 2007-11-01 19:19:43.000000000 -0700
-@@ -831,6 +831,52 @@ long SSL_CTX_get_timeout(const SSL_CTX *
+Index: openssl-SNAP-20080928/ssl/ssl_sess.c
+===================================================================
+--- openssl-SNAP-20080928.orig/ssl/ssl_sess.c
++++ openssl-SNAP-20080928/ssl/ssl_sess.c
+@@ -834,6 +834,52 @@ long SSL_CTX_get_timeout(const SSL_CTX *
return(s->session_timeout);
}
+#ifndef OPENSSL_NO_TLSEXT
-+int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
++int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
+ STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
+{
+ if (s == NULL) return(0);
typedef struct timeout_param_st
{
SSL_CTX *ctx;
-diff -upr openssl-SNAP-20071101.orig/ssl/t1_lib.c openssl-SNAP-20071101/ssl/t1_lib.c
---- openssl-SNAP-20071101.orig/ssl/t1_lib.c 2007-10-26 06:00:29.000000000 -0700
-+++ openssl-SNAP-20071101/ssl/t1_lib.c 2007-11-01 19:19:43.000000000 -0700
+Index: openssl-SNAP-20080928/ssl/t1_lib.c
+===================================================================
+--- openssl-SNAP-20080928.orig/ssl/t1_lib.c
++++ openssl-SNAP-20080928/ssl/t1_lib.c
@@ -154,6 +154,12 @@ int tls1_new(SSL *s)
void tls1_free(SSL *s)
ssl3_free(s);
}
-@@ -355,8 +361,24 @@ unsigned char *ssl_add_clienthello_tlsex
+@@ -357,8 +363,24 @@ unsigned char *ssl_add_clienthello_tlsex
int ticklen;
if (s->session && s->session->tlsext_tick)
ticklen = s->session->tlsext_ticklen;
/* Check for enough room 2 for extension type, 2 for len
* rest for ticket
*/
-@@ -369,6 +391,7 @@ unsigned char *ssl_add_clienthello_tlsex
+@@ -371,6 +393,7 @@ unsigned char *ssl_add_clienthello_tlsex
ret += ticklen;
}
}
#ifdef TLSEXT_TYPE_opaque_prf_input
if (s->s3->client_opaque_prf_input != NULL)
-@@ -1422,6 +1445,8 @@ int tls1_process_ticket(SSL *s, unsigned
+@@ -1435,6 +1458,15 @@ int tls1_process_ticket(SSL *s, unsigned
s->tlsext_ticket_expected = 1;
return 0; /* Cache miss */
}
+ if (s->tls_session_secret_cb)
++ {
++ /* Indicate cache miss here and instead of
++ * generating the session from ticket now,
++ * trigger abbreviated handshake based on
++ * external mechanism to calculate the master
++ * secret later. */
+ return 0;
++ }
return tls_decrypt_ticket(s, p, size, session_id, len,
ret);
}
-diff -upr openssl-SNAP-20071101.orig/ssl/tls1.h openssl-SNAP-20071101/ssl/tls1.h
---- openssl-SNAP-20071101.orig/ssl/tls1.h 2007-09-26 15:01:39.000000000 -0700
-+++ openssl-SNAP-20071101/ssl/tls1.h 2007-11-01 19:19:43.000000000 -0700
-@@ -509,6 +509,14 @@ SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_OPA
+Index: openssl-SNAP-20080928/ssl/tls1.h
+===================================================================
+--- openssl-SNAP-20080928.orig/ssl/tls1.h
++++ openssl-SNAP-20080928/ssl/tls1.h
+@@ -512,6 +512,14 @@ SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_T
#define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
#endif
#ifdef __cplusplus
}
#endif
-diff -upr openssl-SNAP-20071101.orig/util/ssleay.num openssl-SNAP-20071101/util/ssleay.num
---- openssl-SNAP-20071101.orig/util/ssleay.num 2007-08-31 06:03:14.000000000 -0700
-+++ openssl-SNAP-20071101/util/ssleay.num 2007-11-01 19:19:43.000000000 -0700
-@@ -253,3 +253,5 @@ PEM_write_bio_SSL_SESSION
- PEM_read_SSL_SESSION 302 EXIST:!WIN16:FUNCTION:
- PEM_read_bio_SSL_SESSION 303 EXIST::FUNCTION:
- PEM_write_SSL_SESSION 304 EXIST:!WIN16:FUNCTION:
-+SSL_set_hello_extension 305 EXIST::FUNCTION:TLSEXT
-+SSL_set_session_secret_cb 306 EXIST::FUNCTION:TLSEXT
+Index: openssl-SNAP-20080928/util/ssleay.num
+===================================================================
+--- openssl-SNAP-20080928.orig/util/ssleay.num
++++ openssl-SNAP-20080928/util/ssleay.num
+@@ -254,3 +254,5 @@ PEM_read_bio_SSL_SESSION
+ SSL_CTX_set_psk_server_callback 303 EXIST::FUNCTION:PSK
+ SSL_get_psk_identity 304 EXIST::FUNCTION:PSK
+ PEM_write_SSL_SESSION 305 EXIST:!WIN16:FUNCTION:
++SSL_set_hello_extension 306 EXIST::FUNCTION:TLSEXT
++SSL_set_session_secret_cb 307 EXIST::FUNCTION:TLSEXT