summaryrefslogtreecommitdiffstats
path: root/test/handshake_helper.c
diff options
context:
space:
mode:
authorTodd Short <tshort@akamai.com>2016-05-12 18:16:52 -0400
committerRich Salz <rsalz@openssl.org>2016-06-09 13:07:51 -0400
commit5c753de668322bf9903a49ba713b2cbc62667571 (patch)
treeb165b9fc4c4a67b7383e7794a4c010775ca98867 /test/handshake_helper.c
parent2a7de0fd5d9baf946ef4d2c51096b04dd47a8143 (diff)
Fix session ticket and SNI
When session tickets are used, it's possible that SNI might swtich the SSL_CTX on an SSL. Normally, this is not a problem, because the initial_ctx/session_ctx are used for all session ticket/id processes. However, when the SNI callback occurs, it's possible that the callback may update the options in the SSL from the SSL_CTX, and this could cause SSL_OP_NO_TICKET to be set. If this occurs, then two bad things can happen: 1. The session ticket TLSEXT may not be written when the ticket expected flag is set. The state machine transistions to writing the ticket, and the client responds with an error as its not expecting a ticket. 2. When creating the session ticket, if the ticket key cb returns 0 the crypto/hmac contexts are not initialized, and the code crashes when trying to encrypt the session ticket. To fix 1, if the ticket TLSEXT is not written out, clear the expected ticket flag. To fix 2, consider a return of 0 from the ticket key cb a recoverable error, and write a 0 length ticket and continue. The client-side code can explicitly handle this case. Fix these two cases, and add unit test code to validate ticket behavior. Reviewed-by: Emilia Käsper <emilia@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/1098)
Diffstat (limited to 'test/handshake_helper.c')
-rw-r--r--test/handshake_helper.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/test/handshake_helper.c b/test/handshake_helper.c
index 8f1359eb0b..f7ab841f57 100644
--- a/test/handshake_helper.c
+++ b/test/handshake_helper.c
@@ -23,6 +23,7 @@
typedef struct handshake_ex_data {
int alert_sent;
int alert_received;
+ int session_ticket_do_not_call;
} HANDSHAKE_EX_DATA;
static int ex_data_idx;
@@ -49,12 +50,27 @@ static int verify_accept_callback(X509_STORE_CTX *ctx, void *arg) {
return 1;
}
+static int broken_session_ticket_callback(SSL* s, unsigned char* key_name, unsigned char *iv,
+ EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc)
+{
+ return 0;
+}
+
+int do_not_call_session_ticket_callback(SSL* s, unsigned char* key_name, unsigned char *iv,
+ EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc)
+{
+ HANDSHAKE_EX_DATA *ex_data =
+ (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
+ ex_data->session_ticket_do_not_call = 1;
+ return 0;
+}
+
/*
* Configure callbacks and other properties that can't be set directly
* in the server/client CONF.
*/
-static void configure_handshake(SSL_CTX *server_ctx, SSL_CTX *client_ctx,
- const SSL_TEST_CTX *test_ctx)
+static void configure_handshake_ctx(SSL_CTX *server_ctx, SSL_CTX *client_ctx,
+ const SSL_TEST_CTX *test_ctx)
{
switch (test_ctx->client_verify_callback) {
case SSL_TEST_VERIFY_ACCEPT_ALL:
@@ -68,6 +84,19 @@ static void configure_handshake(SSL_CTX *server_ctx, SSL_CTX *client_ctx,
default:
break;
}
+ if (test_ctx->session_ticket_expected == SSL_TEST_SESSION_TICKET_BROKEN) {
+ SSL_CTX_set_tlsext_ticket_key_cb(server_ctx, broken_session_ticket_callback);
+ }
+}
+
+/*
+ * Configure callbacks and other properties that can't be set directly
+ * in the server/client CONF.
+ */
+static void configure_handshake_ssl(SSL *server, SSL *client,
+ const SSL_TEST_CTX *test_ctx)
+{
+ SSL_set_tlsext_host_name(client, ssl_servername_name(test_ctx->servername));
}
@@ -180,13 +209,18 @@ HANDSHAKE_RESULT do_handshake(SSL_CTX *server_ctx, SSL_CTX *client_ctx,
int client_turn = 1;
peer_status_t client_status = PEER_RETRY, server_status = PEER_RETRY;
handshake_status_t status = HANDSHAKE_RETRY;
+ unsigned char* tick = NULL;
+ size_t len = 0;
+ SSL_SESSION* sess = NULL;
- configure_handshake(server_ctx, client_ctx, test_ctx);
+ configure_handshake_ctx(server_ctx, client_ctx, test_ctx);
server = SSL_new(server_ctx);
client = SSL_new(client_ctx);
OPENSSL_assert(server != NULL && client != NULL);
+ configure_handshake_ssl(server, client, test_ctx);
+
memset(&server_ex_data, 0, sizeof(server_ex_data));
memset(&client_ex_data, 0, sizeof(client_ex_data));
memset(&ret, 0, sizeof(ret));
@@ -266,6 +300,16 @@ HANDSHAKE_RESULT do_handshake(SSL_CTX *server_ctx, SSL_CTX *client_ctx,
ret.client_alert_received = server_ex_data.alert_received;
ret.server_protocol = SSL_version(server);
ret.client_protocol = SSL_version(client);
+ ret.servername = ((SSL_get_SSL_CTX(server) == server_ctx)
+ ? SSL_TEST_SERVERNAME_SERVER1
+ : SSL_TEST_SERVERNAME_SERVER2);
+ if ((sess = SSL_get0_session(client)) != NULL)
+ SSL_SESSION_get0_ticket(sess, &tick, &len);
+ if (tick == NULL || len == 0)
+ ret.session_ticket = SSL_TEST_SESSION_TICKET_NO;
+ else
+ ret.session_ticket = SSL_TEST_SESSION_TICKET_YES;
+ ret.session_ticket_do_not_call = server_ex_data.session_ticket_do_not_call;
SSL_free(server);
SSL_free(client);