2016-03-17 14:14:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
*
|
2016-05-17 18:20:24 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
2016-03-17 14:14:30 +00:00
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <openssl/bio.h>
|
2016-04-07 17:07:50 +00:00
|
|
|
#include <openssl/x509_vfy.h>
|
2016-03-17 14:14:30 +00:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
|
|
|
#include "handshake_helper.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since there appears to be no way to extract the sent/received alert
|
|
|
|
* from the SSL object directly, we use the info callback and stash
|
|
|
|
* the result in ex_data.
|
|
|
|
*/
|
|
|
|
typedef struct handshake_ex_data {
|
|
|
|
int alert_sent;
|
|
|
|
int alert_received;
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
int session_ticket_do_not_call;
|
2016-03-17 14:14:30 +00:00
|
|
|
} HANDSHAKE_EX_DATA;
|
|
|
|
|
|
|
|
static int ex_data_idx;
|
|
|
|
|
|
|
|
static void info_callback(const SSL *s, int where, int ret)
|
|
|
|
{
|
|
|
|
if (where & SSL_CB_ALERT) {
|
|
|
|
HANDSHAKE_EX_DATA *ex_data =
|
|
|
|
(HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
|
|
|
|
if (where & SSL_CB_WRITE) {
|
|
|
|
ex_data->alert_sent = ret;
|
|
|
|
} else {
|
|
|
|
ex_data->alert_received = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:39:22 +00:00
|
|
|
static int servername_callback(SSL *s, int *ad, void *arg)
|
|
|
|
{
|
|
|
|
const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
|
|
|
|
if (servername != NULL && !strcmp(servername, "server2")) {
|
|
|
|
SSL_CTX *new_ctx = (SSL_CTX*)arg;
|
|
|
|
SSL_set_SSL_CTX(s, new_ctx);
|
|
|
|
/*
|
|
|
|
* Copy over all the SSL_CTX options - reasonable behavior
|
|
|
|
* allows testing of cases where the options between two
|
|
|
|
* contexts differ/conflict
|
|
|
|
*/
|
|
|
|
SSL_clear_options(s, 0xFFFFFFFFL);
|
|
|
|
SSL_set_options(s, SSL_CTX_get_options(new_ctx));
|
|
|
|
}
|
|
|
|
return SSL_TLSEXT_ERR_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-07 17:07:50 +00:00
|
|
|
static int verify_reject_callback(X509_STORE_CTX *ctx, void *arg) {
|
|
|
|
X509_STORE_CTX_set_error(ctx, X509_V_ERR_APPLICATION_VERIFICATION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int verify_accept_callback(X509_STORE_CTX *ctx, void *arg) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:39:22 +00:00
|
|
|
static 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)
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-04-07 17:07:50 +00:00
|
|
|
/*
|
|
|
|
* Configure callbacks and other properties that can't be set directly
|
|
|
|
* in the server/client CONF.
|
|
|
|
*/
|
2016-06-09 22:39:22 +00:00
|
|
|
static void configure_handshake_ctx(SSL_CTX *server_ctx, SSL_CTX *server2_ctx,
|
|
|
|
SSL_CTX *client_ctx,
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
const SSL_TEST_CTX *test_ctx)
|
2016-04-07 17:07:50 +00:00
|
|
|
{
|
|
|
|
switch (test_ctx->client_verify_callback) {
|
|
|
|
case SSL_TEST_VERIFY_ACCEPT_ALL:
|
|
|
|
SSL_CTX_set_cert_verify_callback(client_ctx, &verify_accept_callback,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case SSL_TEST_VERIFY_REJECT_ALL:
|
|
|
|
SSL_CTX_set_cert_verify_callback(client_ctx, &verify_reject_callback,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-06-09 22:39:22 +00:00
|
|
|
|
|
|
|
/* link the two contexts for SNI purposes */
|
|
|
|
SSL_CTX_set_tlsext_servername_callback(server_ctx, servername_callback);
|
|
|
|
SSL_CTX_set_tlsext_servername_arg(server_ctx, server2_ctx);
|
|
|
|
/*
|
|
|
|
* The initial_ctx/session_ctx always handles the encrypt/decrypt of the
|
|
|
|
* session ticket. This ticket_key callback is assigned to the second
|
|
|
|
* session (assigned via SNI), and should never be invoked
|
|
|
|
*/
|
|
|
|
SSL_CTX_set_tlsext_ticket_key_cb(server2_ctx, do_not_call_session_ticket_callback);
|
|
|
|
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-06-09 22:39:22 +00:00
|
|
|
if (test_ctx->servername != SSL_TEST_SERVERNAME_NONE)
|
|
|
|
SSL_set_tlsext_host_name(client,
|
|
|
|
ssl_servername_name(test_ctx->servername));
|
2016-04-07 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-17 14:14:30 +00:00
|
|
|
typedef enum {
|
|
|
|
PEER_SUCCESS,
|
|
|
|
PEER_RETRY,
|
|
|
|
PEER_ERROR
|
|
|
|
} peer_status_t;
|
|
|
|
|
|
|
|
static peer_status_t do_handshake_step(SSL *ssl)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = SSL_do_handshake(ssl);
|
|
|
|
|
|
|
|
if (ret == 1) {
|
|
|
|
return PEER_SUCCESS;
|
|
|
|
} else if (ret == 0) {
|
|
|
|
return PEER_ERROR;
|
|
|
|
} else {
|
|
|
|
int error = SSL_get_error(ssl, ret);
|
|
|
|
/* Memory bios should never block with SSL_ERROR_WANT_WRITE. */
|
|
|
|
if (error == SSL_ERROR_WANT_READ)
|
|
|
|
return PEER_RETRY;
|
|
|
|
else
|
|
|
|
return PEER_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* Both parties succeeded. */
|
|
|
|
HANDSHAKE_SUCCESS,
|
|
|
|
/* Client errored. */
|
|
|
|
CLIENT_ERROR,
|
|
|
|
/* Server errored. */
|
|
|
|
SERVER_ERROR,
|
|
|
|
/* Peers are in inconsistent state. */
|
|
|
|
INTERNAL_ERROR,
|
|
|
|
/* One or both peers not done. */
|
|
|
|
HANDSHAKE_RETRY
|
|
|
|
} handshake_status_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the handshake outcome.
|
|
|
|
* last_status: the status of the peer to have acted last.
|
|
|
|
* previous_status: the status of the peer that didn't act last.
|
|
|
|
* client_spoke_last: 1 if the client went last.
|
|
|
|
*/
|
|
|
|
static handshake_status_t handshake_status(peer_status_t last_status,
|
|
|
|
peer_status_t previous_status,
|
|
|
|
int client_spoke_last)
|
|
|
|
{
|
|
|
|
switch (last_status) {
|
|
|
|
case PEER_SUCCESS:
|
|
|
|
switch (previous_status) {
|
|
|
|
case PEER_SUCCESS:
|
|
|
|
/* Both succeeded. */
|
|
|
|
return HANDSHAKE_SUCCESS;
|
|
|
|
case PEER_RETRY:
|
|
|
|
/* Let the first peer finish. */
|
|
|
|
return HANDSHAKE_RETRY;
|
|
|
|
case PEER_ERROR:
|
|
|
|
/*
|
|
|
|
* Second peer succeeded despite the fact that the first peer
|
|
|
|
* already errored. This shouldn't happen.
|
|
|
|
*/
|
|
|
|
return INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PEER_RETRY:
|
|
|
|
if (previous_status == PEER_RETRY) {
|
|
|
|
/* Neither peer is done. */
|
|
|
|
return HANDSHAKE_RETRY;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Deadlock: second peer is waiting for more input while first
|
|
|
|
* peer thinks they're done (no more input is coming).
|
|
|
|
*/
|
|
|
|
return INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
case PEER_ERROR:
|
|
|
|
switch (previous_status) {
|
|
|
|
case PEER_SUCCESS:
|
|
|
|
/*
|
|
|
|
* First peer succeeded but second peer errored.
|
|
|
|
* TODO(emilia): we should be able to continue here (with some
|
|
|
|
* application data?) to ensure the first peer receives the
|
|
|
|
* alert / close_notify.
|
|
|
|
*/
|
|
|
|
return client_spoke_last ? CLIENT_ERROR : SERVER_ERROR;
|
|
|
|
case PEER_RETRY:
|
|
|
|
/* We errored; let the peer finish. */
|
|
|
|
return HANDSHAKE_RETRY;
|
|
|
|
case PEER_ERROR:
|
|
|
|
/* Both peers errored. Return the one that errored first. */
|
|
|
|
return client_spoke_last ? SERVER_ERROR : CLIENT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Control should never reach here. */
|
|
|
|
return INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:39:22 +00:00
|
|
|
HANDSHAKE_RESULT do_handshake(SSL_CTX *server_ctx, SSL_CTX *server2_ctx,
|
|
|
|
SSL_CTX *client_ctx, const SSL_TEST_CTX *test_ctx)
|
2016-03-17 14:14:30 +00:00
|
|
|
{
|
|
|
|
SSL *server, *client;
|
|
|
|
BIO *client_to_server, *server_to_client;
|
|
|
|
HANDSHAKE_EX_DATA server_ex_data, client_ex_data;
|
|
|
|
HANDSHAKE_RESULT ret;
|
|
|
|
int client_turn = 1;
|
|
|
|
peer_status_t client_status = PEER_RETRY, server_status = PEER_RETRY;
|
|
|
|
handshake_status_t status = HANDSHAKE_RETRY;
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
unsigned char* tick = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
SSL_SESSION* sess = NULL;
|
2016-03-17 14:14:30 +00:00
|
|
|
|
2016-06-09 22:39:22 +00:00
|
|
|
configure_handshake_ctx(server_ctx, server2_ctx, client_ctx, test_ctx);
|
2016-04-07 17:07:50 +00:00
|
|
|
|
2016-03-17 14:14:30 +00:00
|
|
|
server = SSL_new(server_ctx);
|
|
|
|
client = SSL_new(client_ctx);
|
|
|
|
OPENSSL_assert(server != NULL && client != NULL);
|
|
|
|
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
configure_handshake_ssl(server, client, test_ctx);
|
|
|
|
|
2016-03-17 14:14:30 +00:00
|
|
|
memset(&server_ex_data, 0, sizeof(server_ex_data));
|
|
|
|
memset(&client_ex_data, 0, sizeof(client_ex_data));
|
|
|
|
memset(&ret, 0, sizeof(ret));
|
|
|
|
ret.result = SSL_TEST_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
client_to_server = BIO_new(BIO_s_mem());
|
|
|
|
server_to_client = BIO_new(BIO_s_mem());
|
|
|
|
|
|
|
|
OPENSSL_assert(client_to_server != NULL && server_to_client != NULL);
|
|
|
|
|
|
|
|
/* Non-blocking bio. */
|
|
|
|
BIO_set_nbio(client_to_server, 1);
|
|
|
|
BIO_set_nbio(server_to_client, 1);
|
|
|
|
|
|
|
|
SSL_set_connect_state(client);
|
|
|
|
SSL_set_accept_state(server);
|
|
|
|
|
|
|
|
/* The bios are now owned by the SSL object. */
|
|
|
|
SSL_set_bio(client, server_to_client, client_to_server);
|
|
|
|
OPENSSL_assert(BIO_up_ref(server_to_client) > 0);
|
|
|
|
OPENSSL_assert(BIO_up_ref(client_to_server) > 0);
|
|
|
|
SSL_set_bio(server, client_to_server, server_to_client);
|
|
|
|
|
|
|
|
ex_data_idx = SSL_get_ex_new_index(0, "ex data", NULL, NULL, NULL);
|
|
|
|
OPENSSL_assert(ex_data_idx >= 0);
|
|
|
|
|
|
|
|
OPENSSL_assert(SSL_set_ex_data(server, ex_data_idx,
|
|
|
|
&server_ex_data) == 1);
|
|
|
|
OPENSSL_assert(SSL_set_ex_data(client, ex_data_idx,
|
|
|
|
&client_ex_data) == 1);
|
|
|
|
|
|
|
|
SSL_set_info_callback(server, &info_callback);
|
|
|
|
SSL_set_info_callback(client, &info_callback);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Half-duplex handshake loop.
|
|
|
|
* Client and server speak to each other synchronously in the same process.
|
|
|
|
* We use non-blocking BIOs, so whenever one peer blocks for read, it
|
|
|
|
* returns PEER_RETRY to indicate that it's the other peer's turn to write.
|
|
|
|
* The handshake succeeds once both peers have succeeded. If one peer
|
|
|
|
* errors out, we also let the other peer retry (and presumably fail).
|
|
|
|
*/
|
|
|
|
for(;;) {
|
|
|
|
if (client_turn) {
|
|
|
|
client_status = do_handshake_step(client);
|
|
|
|
status = handshake_status(client_status, server_status,
|
|
|
|
1 /* client went last */);
|
|
|
|
} else {
|
|
|
|
server_status = do_handshake_step(server);
|
|
|
|
status = handshake_status(server_status, client_status,
|
|
|
|
0 /* server went last */);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case HANDSHAKE_SUCCESS:
|
|
|
|
ret.result = SSL_TEST_SUCCESS;
|
|
|
|
goto err;
|
|
|
|
case CLIENT_ERROR:
|
|
|
|
ret.result = SSL_TEST_CLIENT_FAIL;
|
|
|
|
goto err;
|
|
|
|
case SERVER_ERROR:
|
|
|
|
ret.result = SSL_TEST_SERVER_FAIL;
|
|
|
|
goto err;
|
|
|
|
case INTERNAL_ERROR:
|
|
|
|
ret.result = SSL_TEST_INTERNAL_ERROR;
|
|
|
|
goto err;
|
|
|
|
case HANDSHAKE_RETRY:
|
|
|
|
/* Continue. */
|
|
|
|
client_turn ^= 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
ret.server_alert_sent = server_ex_data.alert_sent;
|
|
|
|
ret.server_alert_received = client_ex_data.alert_received;
|
|
|
|
ret.client_alert_sent = client_ex_data.alert_sent;
|
|
|
|
ret.client_alert_received = server_ex_data.alert_received;
|
|
|
|
ret.server_protocol = SSL_version(server);
|
|
|
|
ret.client_protocol = SSL_version(client);
|
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)
2016-05-12 22:16:52 +00:00
|
|
|
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;
|
2016-03-17 14:14:30 +00:00
|
|
|
|
|
|
|
SSL_free(server);
|
|
|
|
SSL_free(client);
|
|
|
|
return ret;
|
|
|
|
}
|