2016-03-17 22:14:30 +08:00
|
|
|
/*
|
2018-02-13 20:51:29 +08:00
|
|
|
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2016-03-17 22:14:30 +08:00
|
|
|
*
|
2016-05-18 02:20:24 +08: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 22:14:30 +08:00
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <openssl/e_os2.h>
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
|
2017-08-22 20:35:43 +08:00
|
|
|
#include "internal/nelem.h"
|
2016-03-17 22:14:30 +08:00
|
|
|
#include "ssl_test_ctx.h"
|
2016-08-09 23:03:23 +08:00
|
|
|
#include "testutil.h"
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2018-01-22 18:00:59 +08:00
|
|
|
#ifdef OPENSSL_SYS_WINDOWS
|
|
|
|
# define strcasecmp _stricmp
|
|
|
|
#endif
|
|
|
|
|
2016-08-12 02:51:57 +08:00
|
|
|
static const int default_app_data_size = 256;
|
2016-08-16 21:11:08 +08:00
|
|
|
/* Default set to be as small as possible to exercise fragmentation. */
|
|
|
|
static const int default_max_fragment_size = 512;
|
2016-08-12 02:51:57 +08:00
|
|
|
|
|
|
|
static int parse_boolean(const char *value, int *result)
|
|
|
|
{
|
|
|
|
if (strcasecmp(value, "Yes") == 0) {
|
|
|
|
*result = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (strcasecmp(value, "No") == 0) {
|
|
|
|
*result = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2017-06-22 12:00:55 +08:00
|
|
|
TEST_error("parse_boolean given: '%s'", value);
|
2016-08-12 02:51:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IMPLEMENT_SSL_TEST_BOOL_OPTION(struct_type, name, field) \
|
|
|
|
static int parse_##name##_##field(struct_type *ctx, const char *value) \
|
|
|
|
{ \
|
|
|
|
return parse_boolean(value, &ctx->field); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IMPLEMENT_SSL_TEST_STRING_OPTION(struct_type, name, field) \
|
|
|
|
static int parse_##name##_##field(struct_type *ctx, const char *value) \
|
|
|
|
{ \
|
|
|
|
OPENSSL_free(ctx->field); \
|
|
|
|
ctx->field = OPENSSL_strdup(value); \
|
2017-06-22 12:00:55 +08:00
|
|
|
return TEST_ptr(ctx->field); \
|
2016-08-12 02:51:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define IMPLEMENT_SSL_TEST_INT_OPTION(struct_type, name, field) \
|
|
|
|
static int parse_##name##_##field(struct_type *ctx, const char *value) \
|
|
|
|
{ \
|
|
|
|
ctx->field = atoi(value); \
|
|
|
|
return 1; \
|
|
|
|
}
|
|
|
|
|
2016-03-17 22:14:30 +08:00
|
|
|
/* True enums and other test configuration values that map to an int. */
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
int value;
|
|
|
|
} test_enum;
|
|
|
|
|
|
|
|
|
|
|
|
__owur static int parse_enum(const test_enum *enums, size_t num_enums,
|
|
|
|
int *value, const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < num_enums; i++) {
|
|
|
|
if (strcmp(enums[i].name, name) == 0) {
|
|
|
|
*value = enums[i].value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *enum_name(const test_enum *enums, size_t num_enums,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < num_enums; i++) {
|
|
|
|
if (enums[i].value == value) {
|
|
|
|
return enums[i].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "InvalidValue";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* ExpectedResult */
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_test_results[] = {
|
|
|
|
{"Success", SSL_TEST_SUCCESS},
|
|
|
|
{"ServerFail", SSL_TEST_SERVER_FAIL},
|
|
|
|
{"ClientFail", SSL_TEST_CLIENT_FAIL},
|
|
|
|
{"InternalError", SSL_TEST_INTERNAL_ERROR},
|
2017-03-16 01:25:55 +08:00
|
|
|
{"FirstHandshakeFailed", SSL_TEST_FIRST_HANDSHAKE_FAILED},
|
2016-03-17 22:14:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_expected_result(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_test_results, OSSL_NELEM(ssl_test_results),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_ctx->expected_result = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-04-08 01:07:50 +08:00
|
|
|
const char *ssl_test_result_name(ssl_test_result_t result)
|
2016-03-17 22:14:30 +08:00
|
|
|
{
|
|
|
|
return enum_name(ssl_test_results, OSSL_NELEM(ssl_test_results), result);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* ExpectedClientAlert / ExpectedServerAlert */
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_alerts[] = {
|
|
|
|
{"UnknownCA", SSL_AD_UNKNOWN_CA},
|
2016-04-08 01:07:50 +08:00
|
|
|
{"HandshakeFailure", SSL_AD_HANDSHAKE_FAILURE},
|
2016-06-20 23:20:25 +08:00
|
|
|
{"UnrecognizedName", SSL_AD_UNRECOGNIZED_NAME},
|
2016-07-05 02:16:14 +08:00
|
|
|
{"BadCertificate", SSL_AD_BAD_CERTIFICATE},
|
|
|
|
{"NoApplicationProtocol", SSL_AD_NO_APPLICATION_PROTOCOL},
|
2018-07-30 16:13:14 +08:00
|
|
|
{"CertificateRequired", SSL_AD_CERTIFICATE_REQUIRED},
|
2016-03-17 22:14:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_alert(int *alert, const char *value)
|
|
|
|
{
|
|
|
|
return parse_enum(ssl_alerts, OSSL_NELEM(ssl_alerts), alert, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
__owur static int parse_client_alert(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
2016-07-21 22:29:48 +08:00
|
|
|
return parse_alert(&test_ctx->expected_client_alert, value);
|
2016-03-17 22:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
__owur static int parse_server_alert(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
2016-07-21 22:29:48 +08:00
|
|
|
return parse_alert(&test_ctx->expected_server_alert, value);
|
2016-03-17 22:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_alert_name(int alert)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_alerts, OSSL_NELEM(ssl_alerts), alert);
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
/* ExpectedProtocol */
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_protocols[] = {
|
2016-10-22 00:39:33 +08:00
|
|
|
{"TLSv1.3", TLS1_3_VERSION},
|
2016-03-17 22:14:30 +08:00
|
|
|
{"TLSv1.2", TLS1_2_VERSION},
|
|
|
|
{"TLSv1.1", TLS1_1_VERSION},
|
|
|
|
{"TLSv1", TLS1_VERSION},
|
|
|
|
{"SSLv3", SSL3_VERSION},
|
2016-06-03 23:49:04 +08:00
|
|
|
{"DTLSv1", DTLS1_VERSION},
|
|
|
|
{"DTLSv1.2", DTLS1_2_VERSION},
|
2016-03-17 22:14:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_protocol(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
|
|
|
return parse_enum(ssl_protocols, OSSL_NELEM(ssl_protocols),
|
2016-07-21 22:29:48 +08:00
|
|
|
&test_ctx->expected_protocol, value);
|
2016-03-17 22:14:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_protocol_name(int protocol)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_protocols, OSSL_NELEM(ssl_protocols), protocol);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* VerifyCallback */
|
2016-04-08 01:07:50 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_verify_callbacks[] = {
|
|
|
|
{"None", SSL_TEST_VERIFY_NONE},
|
|
|
|
{"AcceptAll", SSL_TEST_VERIFY_ACCEPT_ALL},
|
|
|
|
{"RejectAll", SSL_TEST_VERIFY_REJECT_ALL},
|
|
|
|
};
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
__owur static int parse_client_verify_callback(SSL_TEST_CLIENT_CONF *client_conf,
|
2016-08-09 22:47:26 +08:00
|
|
|
const char *value)
|
2016-04-08 01:07:50 +08:00
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_verify_callbacks, OSSL_NELEM(ssl_verify_callbacks),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-21 22:29:48 +08:00
|
|
|
client_conf->verify_callback = ret_value;
|
2016-04-08 01:07:50 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_verify_callback_name(ssl_verify_callback_t callback)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_verify_callbacks, OSSL_NELEM(ssl_verify_callbacks),
|
|
|
|
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-13 06:16:52 +08:00
|
|
|
/* ServerName */
|
|
|
|
|
|
|
|
static const test_enum ssl_servername[] = {
|
2016-06-10 06:39:22 +08:00
|
|
|
{"None", SSL_TEST_SERVERNAME_NONE},
|
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-13 06:16:52 +08:00
|
|
|
{"server1", SSL_TEST_SERVERNAME_SERVER1},
|
|
|
|
{"server2", SSL_TEST_SERVERNAME_SERVER2},
|
2016-06-20 23:20:25 +08:00
|
|
|
{"invalid", SSL_TEST_SERVERNAME_INVALID},
|
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-13 06:16:52 +08:00
|
|
|
};
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
__owur static int parse_servername(SSL_TEST_CLIENT_CONF *client_conf,
|
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-13 06:16:52 +08:00
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_servername, OSSL_NELEM(ssl_servername),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-21 22:29:48 +08:00
|
|
|
client_conf->servername = ret_value;
|
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-13 06:16:52 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-06-20 23:20:25 +08:00
|
|
|
__owur static int parse_expected_servername(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_servername, OSSL_NELEM(ssl_servername),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_ctx->expected_servername = ret_value;
|
|
|
|
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-13 06:16:52 +08:00
|
|
|
const char *ssl_servername_name(ssl_servername_t server)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_servername, OSSL_NELEM(ssl_servername),
|
|
|
|
server);
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
/* ServerNameCallback */
|
2016-06-20 23:20:25 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_servername_callbacks[] = {
|
|
|
|
{"None", SSL_TEST_SERVERNAME_CB_NONE},
|
|
|
|
{"IgnoreMismatch", SSL_TEST_SERVERNAME_IGNORE_MISMATCH},
|
|
|
|
{"RejectMismatch", SSL_TEST_SERVERNAME_REJECT_MISMATCH},
|
2017-09-08 06:39:40 +08:00
|
|
|
{"ClientHelloIgnoreMismatch",
|
|
|
|
SSL_TEST_SERVERNAME_CLIENT_HELLO_IGNORE_MISMATCH},
|
|
|
|
{"ClientHelloRejectMismatch",
|
|
|
|
SSL_TEST_SERVERNAME_CLIENT_HELLO_REJECT_MISMATCH},
|
|
|
|
{"ClientHelloNoV12", SSL_TEST_SERVERNAME_CLIENT_HELLO_NO_V12},
|
2016-06-20 23:20:25 +08:00
|
|
|
};
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
__owur static int parse_servername_callback(SSL_TEST_SERVER_CONF *server_conf,
|
|
|
|
const char *value)
|
2016-06-20 23:20:25 +08:00
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_servername_callbacks,
|
|
|
|
OSSL_NELEM(ssl_servername_callbacks), &ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-21 22:29:48 +08:00
|
|
|
server_conf->servername_callback = ret_value;
|
2016-06-20 23:20:25 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_servername_callback_name(ssl_servername_callback_t callback)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_servername_callbacks,
|
|
|
|
OSSL_NELEM(ssl_servername_callbacks), 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-13 06:16:52 +08:00
|
|
|
/* SessionTicketExpected */
|
|
|
|
|
2016-06-10 06:39:22 +08:00
|
|
|
static const test_enum ssl_session_ticket[] = {
|
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-13 06:16:52 +08:00
|
|
|
{"Ignore", SSL_TEST_SESSION_TICKET_IGNORE},
|
|
|
|
{"Yes", SSL_TEST_SESSION_TICKET_YES},
|
|
|
|
{"No", SSL_TEST_SESSION_TICKET_NO},
|
|
|
|
};
|
|
|
|
|
2016-06-10 06:39:22 +08:00
|
|
|
__owur static int parse_session_ticket(SSL_TEST_CTX *test_ctx, const char *value)
|
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-13 06:16:52 +08:00
|
|
|
{
|
|
|
|
int ret_value;
|
2016-06-10 06:39:22 +08:00
|
|
|
if (!parse_enum(ssl_session_ticket, OSSL_NELEM(ssl_session_ticket),
|
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-13 06:16:52 +08:00
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_ctx->session_ticket_expected = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-06-10 06:39:22 +08:00
|
|
|
const char *ssl_session_ticket_name(ssl_session_ticket_t server)
|
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-13 06:16:52 +08:00
|
|
|
{
|
2016-06-10 06:39:22 +08:00
|
|
|
return enum_name(ssl_session_ticket,
|
|
|
|
OSSL_NELEM(ssl_session_ticket),
|
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-13 06:16:52 +08:00
|
|
|
server);
|
|
|
|
}
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2017-03-01 20:11:51 +08:00
|
|
|
/* CompressionExpected */
|
|
|
|
|
2017-03-02 21:41:10 +08:00
|
|
|
IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, compression_expected)
|
2017-03-01 20:11:51 +08:00
|
|
|
|
Session resume broken switching contexts
When an SSL's context is swtiched from a ticket-enabled context to
a ticket-disabled context in the servername callback, no session-id
is generated, so the session can't be resumed.
If a servername callback changes the SSL_OP_NO_TICKET option, check
to see if it's changed to disable, and whether a session ticket is
expected (i.e. the client indicated ticket support and the SSL had
tickets enabled at the time), and whether we already have a previous
session (i.e. s->hit is set).
In this case, clear the ticket-expected flag, remove any ticket data
and generate a session-id in the session.
If the SSL hit (resumed) and switched to a ticket-disabled context,
assume that the resumption was via session-id, and don't bother to
update the session.
Before this fix, the updated unit-tests in 06-sni-ticket.conf would
fail test #4 (server1 = SNI, server2 = no SNI).
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/1529)
2016-09-01 20:40:54 +08:00
|
|
|
/* SessionIdExpected */
|
|
|
|
|
|
|
|
static const test_enum ssl_session_id[] = {
|
|
|
|
{"Ignore", SSL_TEST_SESSION_ID_IGNORE},
|
|
|
|
{"Yes", SSL_TEST_SESSION_ID_YES},
|
|
|
|
{"No", SSL_TEST_SESSION_ID_NO},
|
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_session_id(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_session_id, OSSL_NELEM(ssl_session_id),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_ctx->session_id_expected = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_session_id_name(ssl_session_id_t server)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_session_id,
|
|
|
|
OSSL_NELEM(ssl_session_id),
|
|
|
|
server);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* Method */
|
2016-06-03 23:49:04 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_test_methods[] = {
|
|
|
|
{"TLS", SSL_TEST_METHOD_TLS},
|
|
|
|
{"DTLS", SSL_TEST_METHOD_DTLS},
|
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_test_method(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_test_methods, OSSL_NELEM(ssl_test_methods),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_ctx->method = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_test_method_name(ssl_test_method_t method)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_test_methods, OSSL_NELEM(ssl_test_methods), method);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* NPN and ALPN options */
|
2016-07-05 02:16:14 +08:00
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CLIENT_CONF, client, npn_protocols)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_SERVER_CONF, server, npn_protocols)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CTX, test, expected_npn_protocol)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CLIENT_CONF, client, alpn_protocols)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_SERVER_CONF, server, alpn_protocols)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CTX, test, expected_alpn_protocol)
|
2016-07-05 02:16:14 +08:00
|
|
|
|
2017-03-14 20:48:54 +08:00
|
|
|
/* SRP options */
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CLIENT_CONF, client, srp_user)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_SERVER_CONF, server, srp_user)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CLIENT_CONF, client, srp_password)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_SERVER_CONF, server, srp_password)
|
|
|
|
|
2017-03-16 01:25:55 +08:00
|
|
|
/* Session Ticket App Data options */
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CTX, test, expected_session_ticket_app_data)
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_SERVER_CONF, server, session_ticket_app_data)
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* Handshake mode */
|
2016-07-06 01:06:23 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_handshake_modes[] = {
|
|
|
|
{"Simple", SSL_TEST_HANDSHAKE_SIMPLE},
|
|
|
|
{"Resume", SSL_TEST_HANDSHAKE_RESUME},
|
2016-09-27 18:50:43 +08:00
|
|
|
{"RenegotiateServer", SSL_TEST_HANDSHAKE_RENEG_SERVER},
|
|
|
|
{"RenegotiateClient", SSL_TEST_HANDSHAKE_RENEG_CLIENT},
|
2017-02-15 17:25:52 +08:00
|
|
|
{"KeyUpdateServer", SSL_TEST_HANDSHAKE_KEY_UPDATE_SERVER},
|
|
|
|
{"KeyUpdateClient", SSL_TEST_HANDSHAKE_KEY_UPDATE_CLIENT},
|
Add TLSv1.3 post-handshake authentication (PHA)
Add SSL_verify_client_post_handshake() for servers to initiate PHA
Add SSL_force_post_handshake_auth() for clients that don't have certificates
initially configured, but use a certificate callback.
Update SSL_CTX_set_verify()/SSL_set_verify() mode:
* Add SSL_VERIFY_POST_HANDSHAKE to postpone client authentication until after
the initial handshake.
* Update SSL_VERIFY_CLIENT_ONCE now only sends out one CertRequest regardless
of when the certificate authentication takes place; either initial handshake,
re-negotiation, or post-handshake authentication.
Add 'RequestPostHandshake' and 'RequirePostHandshake' SSL_CONF options that
add the SSL_VERIFY_POST_HANDSHAKE to the 'Request' and 'Require' options
Add support to s_client:
* Enabled automatically when cert is configured
* Can be forced enabled via -force_pha
Add support to s_server:
* Use 'c' to invoke PHA in s_server
* Remove some dead code
Update documentation
Update unit tests:
* Illegal use of PHA extension
* TLSv1.3 certificate tests
DTLS and TLS behave ever-so-slightly differently. So, when DTLS1.3 is
implemented, it's PHA support state machine may need to be different.
Add a TODO and a #error
Update handshake context to deal with PHA.
The handshake context for TLSv1.3 post-handshake auth is up through the
ClientFinish message, plus the CertificateRequest message. Subsequent
Certificate, CertificateVerify, and Finish messages are based on this
handshake context (not the Certificate message per se, but it's included
after the hash). KeyUpdate, NewSessionTicket, and prior Certificate
Request messages are not included in post-handshake authentication.
After the ClientFinished message is processed, save off the digest state
for future post-handshake authentication. When post-handshake auth occurs,
copy over the saved handshake context into the "main" handshake digest.
This effectively discards the any KeyUpdate or NewSessionTicket messages
and any prior post-handshake authentication.
This, of course, assumes that the ID-22 did not mean to include any
previous post-handshake authentication into the new handshake transcript.
This is implied by section 4.4.1 that lists messages only up to the
first ClientFinished.
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4964)
2017-12-19 05:52:28 +08:00
|
|
|
{"PostHandshakeAuth", SSL_TEST_HANDSHAKE_POST_HANDSHAKE_AUTH},
|
2016-07-06 01:06:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_handshake_mode(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_handshake_modes, OSSL_NELEM(ssl_handshake_modes),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_ctx->handshake_mode = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_handshake_modes, OSSL_NELEM(ssl_handshake_modes),
|
|
|
|
mode);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* Renegotiation Ciphersuites */
|
|
|
|
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CLIENT_CONF, client, reneg_ciphers)
|
|
|
|
|
2017-02-15 17:25:52 +08:00
|
|
|
/* KeyUpdateType */
|
|
|
|
|
|
|
|
static const test_enum ssl_key_update_types[] = {
|
|
|
|
{"KeyUpdateRequested", SSL_KEY_UPDATE_REQUESTED},
|
|
|
|
{"KeyUpdateNotRequested", SSL_KEY_UPDATE_NOT_REQUESTED},
|
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_key_update_type(SSL_TEST_CTX *test_ctx, const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_key_update_types, OSSL_NELEM(ssl_key_update_types),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_ctx->key_update_type = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* CT Validation */
|
2016-08-09 22:47:26 +08:00
|
|
|
|
|
|
|
static const test_enum ssl_ct_validation_modes[] = {
|
|
|
|
{"None", SSL_TEST_CT_VALIDATION_NONE},
|
|
|
|
{"Permissive", SSL_TEST_CT_VALIDATION_PERMISSIVE},
|
|
|
|
{"Strict", SSL_TEST_CT_VALIDATION_STRICT},
|
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_ct_validation(SSL_TEST_CLIENT_CONF *client_conf,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_ct_validation_modes, OSSL_NELEM(ssl_ct_validation_modes),
|
|
|
|
&ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
client_conf->ct_validation = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_ct_validation_name(ssl_ct_validation_t mode)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_ct_validation_modes, OSSL_NELEM(ssl_ct_validation_modes),
|
|
|
|
mode);
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, resumption_expected)
|
|
|
|
IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_SERVER_CONF, server, broken_session_ticket)
|
2017-04-24 16:42:28 +08:00
|
|
|
IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, use_sctp)
|
2016-07-06 01:06:23 +08:00
|
|
|
|
2016-08-30 21:20:18 +08:00
|
|
|
/* CertStatus */
|
|
|
|
|
|
|
|
static const test_enum ssl_certstatus[] = {
|
|
|
|
{"None", SSL_TEST_CERT_STATUS_NONE},
|
|
|
|
{"GoodResponse", SSL_TEST_CERT_STATUS_GOOD_RESPONSE},
|
|
|
|
{"BadResponse", SSL_TEST_CERT_STATUS_BAD_RESPONSE}
|
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_certstatus(SSL_TEST_SERVER_CONF *server_conf,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
if (!parse_enum(ssl_certstatus, OSSL_NELEM(ssl_certstatus), &ret_value,
|
|
|
|
value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
server_conf->cert_status = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_certstatus_name(ssl_cert_status_t cert_status)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_certstatus,
|
|
|
|
OSSL_NELEM(ssl_certstatus), cert_status);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
/* ApplicationData */
|
2016-08-12 02:51:57 +08:00
|
|
|
|
|
|
|
IMPLEMENT_SSL_TEST_INT_OPTION(SSL_TEST_CTX, test, app_data_size)
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
|
|
|
|
/* MaxFragmentSize */
|
2016-08-16 21:11:08 +08:00
|
|
|
|
|
|
|
IMPLEMENT_SSL_TEST_INT_OPTION(SSL_TEST_CTX, test, max_fragment_size)
|
|
|
|
|
2017-11-06 00:46:48 +08:00
|
|
|
/* Maximum-Fragment-Length TLS extension mode */
|
|
|
|
static const test_enum ssl_max_fragment_len_mode[] = {
|
|
|
|
{"None", TLSEXT_max_fragment_length_DISABLED},
|
|
|
|
{ "512", TLSEXT_max_fragment_length_512},
|
|
|
|
{"1024", TLSEXT_max_fragment_length_1024},
|
|
|
|
{"2048", TLSEXT_max_fragment_length_2048},
|
|
|
|
{"4096", TLSEXT_max_fragment_length_4096}
|
|
|
|
};
|
|
|
|
|
|
|
|
__owur static int parse_max_fragment_len_mode(SSL_TEST_CLIENT_CONF *client_conf,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
int ret_value;
|
|
|
|
|
|
|
|
if (!parse_enum(ssl_max_fragment_len_mode,
|
|
|
|
OSSL_NELEM(ssl_max_fragment_len_mode), &ret_value, value)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
client_conf->max_fragment_len_mode = ret_value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ssl_max_fragment_len_name(int MFL_mode)
|
|
|
|
{
|
|
|
|
return enum_name(ssl_max_fragment_len_mode,
|
|
|
|
OSSL_NELEM(ssl_max_fragment_len_mode), MFL_mode);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
|
|
|
|
/* Expected key and signature types */
|
2017-01-08 08:09:08 +08:00
|
|
|
|
2017-01-09 03:30:41 +08:00
|
|
|
__owur static int parse_expected_key_type(int *ptype, const char *value)
|
2017-01-08 08:09:08 +08:00
|
|
|
{
|
|
|
|
int nid;
|
2017-01-09 03:30:41 +08:00
|
|
|
const EVP_PKEY_ASN1_METHOD *ameth;
|
2017-01-08 08:09:08 +08:00
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
return 0;
|
2017-01-09 03:30:41 +08:00
|
|
|
ameth = EVP_PKEY_asn1_find_str(NULL, value, -1);
|
|
|
|
if (ameth != NULL)
|
|
|
|
EVP_PKEY_asn1_get0_info(&nid, NULL, NULL, NULL, NULL, ameth);
|
|
|
|
else
|
|
|
|
nid = OBJ_sn2nid(value);
|
2017-01-08 08:09:08 +08:00
|
|
|
if (nid == NID_undef)
|
|
|
|
nid = OBJ_ln2nid(value);
|
|
|
|
#ifndef OPENSSL_NO_EC
|
|
|
|
if (nid == NID_undef)
|
|
|
|
nid = EC_curve_nist2nid(value);
|
|
|
|
#endif
|
|
|
|
if (nid == NID_undef)
|
|
|
|
return 0;
|
2017-01-09 03:30:41 +08:00
|
|
|
*ptype = nid;
|
2017-01-08 08:09:08 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-01-09 03:30:41 +08:00
|
|
|
__owur static int parse_expected_tmp_key_type(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_key_type(&test_ctx->expected_tmp_key_type, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
__owur static int parse_expected_server_cert_type(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_key_type(&test_ctx->expected_server_cert_type,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:06:16 +08:00
|
|
|
__owur static int parse_expected_server_sign_type(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_key_type(&test_ctx->expected_server_sign_type,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2017-01-09 03:30:41 +08:00
|
|
|
__owur static int parse_expected_client_cert_type(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_key_type(&test_ctx->expected_client_cert_type,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:06:16 +08:00
|
|
|
__owur static int parse_expected_client_sign_type(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_key_type(&test_ctx->expected_client_sign_type,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2017-02-03 19:21:07 +08:00
|
|
|
|
2017-01-13 23:20:42 +08:00
|
|
|
/* Expected signing hash */
|
|
|
|
|
|
|
|
__owur static int parse_expected_sign_hash(int *ptype, const char *value)
|
|
|
|
{
|
|
|
|
int nid;
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
return 0;
|
|
|
|
nid = OBJ_sn2nid(value);
|
|
|
|
if (nid == NID_undef)
|
|
|
|
nid = OBJ_ln2nid(value);
|
|
|
|
if (nid == NID_undef)
|
|
|
|
return 0;
|
|
|
|
*ptype = nid;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__owur static int parse_expected_server_sign_hash(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_sign_hash(&test_ctx->expected_server_sign_hash,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
__owur static int parse_expected_client_sign_hash(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
2017-01-26 04:25:53 +08:00
|
|
|
return parse_expected_sign_hash(&test_ctx->expected_client_sign_hash,
|
2017-01-13 23:20:42 +08:00
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:07:07 +08:00
|
|
|
__owur static int parse_expected_ca_names(STACK_OF(X509_NAME) **pnames,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
if (value == NULL)
|
|
|
|
return 0;
|
|
|
|
if (!strcmp(value, "empty"))
|
|
|
|
*pnames = sk_X509_NAME_new_null();
|
|
|
|
else
|
|
|
|
*pnames = SSL_load_client_CA_file(value);
|
|
|
|
return *pnames != NULL;
|
|
|
|
}
|
2017-04-01 05:35:28 +08:00
|
|
|
__owur static int parse_expected_server_ca_names(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_ca_names(&test_ctx->expected_server_ca_names, value);
|
|
|
|
}
|
2017-03-16 00:07:07 +08:00
|
|
|
__owur static int parse_expected_client_ca_names(SSL_TEST_CTX *test_ctx,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
return parse_expected_ca_names(&test_ctx->expected_client_ca_names, value);
|
|
|
|
}
|
2017-02-03 19:21:07 +08:00
|
|
|
|
2015-12-22 04:19:29 +08:00
|
|
|
/* ExpectedCipher */
|
|
|
|
|
|
|
|
IMPLEMENT_SSL_TEST_STRING_OPTION(SSL_TEST_CTX, test, expected_cipher)
|
|
|
|
|
2018-08-13 22:23:27 +08:00
|
|
|
/* Client and Server PHA */
|
Add TLSv1.3 post-handshake authentication (PHA)
Add SSL_verify_client_post_handshake() for servers to initiate PHA
Add SSL_force_post_handshake_auth() for clients that don't have certificates
initially configured, but use a certificate callback.
Update SSL_CTX_set_verify()/SSL_set_verify() mode:
* Add SSL_VERIFY_POST_HANDSHAKE to postpone client authentication until after
the initial handshake.
* Update SSL_VERIFY_CLIENT_ONCE now only sends out one CertRequest regardless
of when the certificate authentication takes place; either initial handshake,
re-negotiation, or post-handshake authentication.
Add 'RequestPostHandshake' and 'RequirePostHandshake' SSL_CONF options that
add the SSL_VERIFY_POST_HANDSHAKE to the 'Request' and 'Require' options
Add support to s_client:
* Enabled automatically when cert is configured
* Can be forced enabled via -force_pha
Add support to s_server:
* Use 'c' to invoke PHA in s_server
* Remove some dead code
Update documentation
Update unit tests:
* Illegal use of PHA extension
* TLSv1.3 certificate tests
DTLS and TLS behave ever-so-slightly differently. So, when DTLS1.3 is
implemented, it's PHA support state machine may need to be different.
Add a TODO and a #error
Update handshake context to deal with PHA.
The handshake context for TLSv1.3 post-handshake auth is up through the
ClientFinish message, plus the CertificateRequest message. Subsequent
Certificate, CertificateVerify, and Finish messages are based on this
handshake context (not the Certificate message per se, but it's included
after the hash). KeyUpdate, NewSessionTicket, and prior Certificate
Request messages are not included in post-handshake authentication.
After the ClientFinished message is processed, save off the digest state
for future post-handshake authentication. When post-handshake auth occurs,
copy over the saved handshake context into the "main" handshake digest.
This effectively discards the any KeyUpdate or NewSessionTicket messages
and any prior post-handshake authentication.
This, of course, assumes that the ID-22 did not mean to include any
previous post-handshake authentication into the new handshake transcript.
This is implied by section 4.4.1 that lists messages only up to the
first ClientFinished.
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4964)
2017-12-19 05:52:28 +08:00
|
|
|
|
2018-08-13 22:23:27 +08:00
|
|
|
IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CLIENT_CONF, client, enable_pha)
|
Add TLSv1.3 post-handshake authentication (PHA)
Add SSL_verify_client_post_handshake() for servers to initiate PHA
Add SSL_force_post_handshake_auth() for clients that don't have certificates
initially configured, but use a certificate callback.
Update SSL_CTX_set_verify()/SSL_set_verify() mode:
* Add SSL_VERIFY_POST_HANDSHAKE to postpone client authentication until after
the initial handshake.
* Update SSL_VERIFY_CLIENT_ONCE now only sends out one CertRequest regardless
of when the certificate authentication takes place; either initial handshake,
re-negotiation, or post-handshake authentication.
Add 'RequestPostHandshake' and 'RequirePostHandshake' SSL_CONF options that
add the SSL_VERIFY_POST_HANDSHAKE to the 'Request' and 'Require' options
Add support to s_client:
* Enabled automatically when cert is configured
* Can be forced enabled via -force_pha
Add support to s_server:
* Use 'c' to invoke PHA in s_server
* Remove some dead code
Update documentation
Update unit tests:
* Illegal use of PHA extension
* TLSv1.3 certificate tests
DTLS and TLS behave ever-so-slightly differently. So, when DTLS1.3 is
implemented, it's PHA support state machine may need to be different.
Add a TODO and a #error
Update handshake context to deal with PHA.
The handshake context for TLSv1.3 post-handshake auth is up through the
ClientFinish message, plus the CertificateRequest message. Subsequent
Certificate, CertificateVerify, and Finish messages are based on this
handshake context (not the Certificate message per se, but it's included
after the hash). KeyUpdate, NewSessionTicket, and prior Certificate
Request messages are not included in post-handshake authentication.
After the ClientFinished message is processed, save off the digest state
for future post-handshake authentication. When post-handshake auth occurs,
copy over the saved handshake context into the "main" handshake digest.
This effectively discards the any KeyUpdate or NewSessionTicket messages
and any prior post-handshake authentication.
This, of course, assumes that the ID-22 did not mean to include any
previous post-handshake authentication into the new handshake transcript.
This is implied by section 4.4.1 that lists messages only up to the
first ClientFinished.
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4964)
2017-12-19 05:52:28 +08:00
|
|
|
IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_SERVER_CONF, server, force_pha)
|
|
|
|
|
2016-03-17 22:14:30 +08:00
|
|
|
/* Known test options and their corresponding parse methods. */
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
/* Top-level options. */
|
2016-03-17 22:14:30 +08:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
int (*parse)(SSL_TEST_CTX *test_ctx, const char *value);
|
|
|
|
} ssl_test_ctx_option;
|
|
|
|
|
|
|
|
static const ssl_test_ctx_option ssl_test_ctx_options[] = {
|
|
|
|
{ "ExpectedResult", &parse_expected_result },
|
2016-07-21 22:29:48 +08:00
|
|
|
{ "ExpectedClientAlert", &parse_client_alert },
|
|
|
|
{ "ExpectedServerAlert", &parse_server_alert },
|
|
|
|
{ "ExpectedProtocol", &parse_protocol },
|
2016-06-20 23:20:25 +08:00
|
|
|
{ "ExpectedServerName", &parse_expected_servername },
|
2016-06-10 06:39:22 +08:00
|
|
|
{ "SessionTicketExpected", &parse_session_ticket },
|
2017-03-02 21:41:10 +08:00
|
|
|
{ "CompressionExpected", &parse_test_compression_expected },
|
Session resume broken switching contexts
When an SSL's context is swtiched from a ticket-enabled context to
a ticket-disabled context in the servername callback, no session-id
is generated, so the session can't be resumed.
If a servername callback changes the SSL_OP_NO_TICKET option, check
to see if it's changed to disable, and whether a session ticket is
expected (i.e. the client indicated ticket support and the SSL had
tickets enabled at the time), and whether we already have a previous
session (i.e. s->hit is set).
In this case, clear the ticket-expected flag, remove any ticket data
and generate a session-id in the session.
If the SSL hit (resumed) and switched to a ticket-disabled context,
assume that the resumption was via session-id, and don't bother to
update the session.
Before this fix, the updated unit-tests in 06-sni-ticket.conf would
fail test #4 (server1 = SNI, server2 = no SNI).
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/1529)
2016-09-01 20:40:54 +08:00
|
|
|
{ "SessionIdExpected", &parse_session_id },
|
2016-06-03 23:49:04 +08:00
|
|
|
{ "Method", &parse_test_method },
|
2016-07-21 22:29:48 +08:00
|
|
|
{ "ExpectedNPNProtocol", &parse_test_expected_npn_protocol },
|
|
|
|
{ "ExpectedALPNProtocol", &parse_test_expected_alpn_protocol },
|
2016-07-06 01:06:23 +08:00
|
|
|
{ "HandshakeMode", &parse_handshake_mode },
|
2017-02-15 17:25:52 +08:00
|
|
|
{ "KeyUpdateType", &parse_key_update_type },
|
2016-07-21 22:29:48 +08:00
|
|
|
{ "ResumptionExpected", &parse_test_resumption_expected },
|
2016-08-12 02:51:57 +08:00
|
|
|
{ "ApplicationData", &parse_test_app_data_size },
|
2016-08-16 21:11:08 +08:00
|
|
|
{ "MaxFragmentSize", &parse_test_max_fragment_size },
|
2017-01-08 08:09:08 +08:00
|
|
|
{ "ExpectedTmpKeyType", &parse_expected_tmp_key_type },
|
2017-01-09 03:30:41 +08:00
|
|
|
{ "ExpectedServerCertType", &parse_expected_server_cert_type },
|
2017-01-13 23:20:42 +08:00
|
|
|
{ "ExpectedServerSignHash", &parse_expected_server_sign_hash },
|
2017-01-27 23:06:16 +08:00
|
|
|
{ "ExpectedServerSignType", &parse_expected_server_sign_type },
|
2017-04-01 05:35:28 +08:00
|
|
|
{ "ExpectedServerCANames", &parse_expected_server_ca_names },
|
2017-01-09 03:30:41 +08:00
|
|
|
{ "ExpectedClientCertType", &parse_expected_client_cert_type },
|
2017-01-13 23:20:42 +08:00
|
|
|
{ "ExpectedClientSignHash", &parse_expected_client_sign_hash },
|
2017-01-27 23:06:16 +08:00
|
|
|
{ "ExpectedClientSignType", &parse_expected_client_sign_type },
|
2017-03-16 00:07:07 +08:00
|
|
|
{ "ExpectedClientCANames", &parse_expected_client_ca_names },
|
2017-04-24 16:42:28 +08:00
|
|
|
{ "UseSCTP", &parse_test_use_sctp },
|
2015-12-22 04:19:29 +08:00
|
|
|
{ "ExpectedCipher", &parse_test_expected_cipher },
|
2017-03-16 01:25:55 +08:00
|
|
|
{ "ExpectedSessionTicketAppData", &parse_test_expected_session_ticket_app_data },
|
2016-07-21 22:29:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Nested client options. */
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
int (*parse)(SSL_TEST_CLIENT_CONF *conf, const char *value);
|
|
|
|
} ssl_test_client_option;
|
|
|
|
|
|
|
|
static const ssl_test_client_option ssl_test_client_options[] = {
|
|
|
|
{ "VerifyCallback", &parse_client_verify_callback },
|
|
|
|
{ "ServerName", &parse_servername },
|
|
|
|
{ "NPNProtocols", &parse_client_npn_protocols },
|
|
|
|
{ "ALPNProtocols", &parse_client_alpn_protocols },
|
2016-08-09 22:47:26 +08:00
|
|
|
{ "CTValidation", &parse_ct_validation },
|
2017-02-03 19:21:07 +08:00
|
|
|
{ "RenegotiateCiphers", &parse_client_reneg_ciphers},
|
2017-03-14 20:48:54 +08:00
|
|
|
{ "SRPUser", &parse_client_srp_user },
|
|
|
|
{ "SRPPassword", &parse_client_srp_password },
|
2017-11-06 00:46:48 +08:00
|
|
|
{ "MaxFragmentLenExt", &parse_max_fragment_len_mode },
|
2018-08-13 22:23:27 +08:00
|
|
|
{ "EnablePHA", &parse_client_enable_pha },
|
2016-07-21 22:29:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Nested server options. */
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
int (*parse)(SSL_TEST_SERVER_CONF *conf, const char *value);
|
|
|
|
} ssl_test_server_option;
|
|
|
|
|
|
|
|
static const ssl_test_server_option ssl_test_server_options[] = {
|
|
|
|
{ "ServerNameCallback", &parse_servername_callback },
|
|
|
|
{ "NPNProtocols", &parse_server_npn_protocols },
|
|
|
|
{ "ALPNProtocols", &parse_server_alpn_protocols },
|
|
|
|
{ "BrokenSessionTicket", &parse_server_broken_session_ticket },
|
2016-08-30 21:20:18 +08:00
|
|
|
{ "CertStatus", &parse_certstatus },
|
2017-03-14 20:48:54 +08:00
|
|
|
{ "SRPUser", &parse_server_srp_user },
|
|
|
|
{ "SRPPassword", &parse_server_srp_password },
|
Add TLSv1.3 post-handshake authentication (PHA)
Add SSL_verify_client_post_handshake() for servers to initiate PHA
Add SSL_force_post_handshake_auth() for clients that don't have certificates
initially configured, but use a certificate callback.
Update SSL_CTX_set_verify()/SSL_set_verify() mode:
* Add SSL_VERIFY_POST_HANDSHAKE to postpone client authentication until after
the initial handshake.
* Update SSL_VERIFY_CLIENT_ONCE now only sends out one CertRequest regardless
of when the certificate authentication takes place; either initial handshake,
re-negotiation, or post-handshake authentication.
Add 'RequestPostHandshake' and 'RequirePostHandshake' SSL_CONF options that
add the SSL_VERIFY_POST_HANDSHAKE to the 'Request' and 'Require' options
Add support to s_client:
* Enabled automatically when cert is configured
* Can be forced enabled via -force_pha
Add support to s_server:
* Use 'c' to invoke PHA in s_server
* Remove some dead code
Update documentation
Update unit tests:
* Illegal use of PHA extension
* TLSv1.3 certificate tests
DTLS and TLS behave ever-so-slightly differently. So, when DTLS1.3 is
implemented, it's PHA support state machine may need to be different.
Add a TODO and a #error
Update handshake context to deal with PHA.
The handshake context for TLSv1.3 post-handshake auth is up through the
ClientFinish message, plus the CertificateRequest message. Subsequent
Certificate, CertificateVerify, and Finish messages are based on this
handshake context (not the Certificate message per se, but it's included
after the hash). KeyUpdate, NewSessionTicket, and prior Certificate
Request messages are not included in post-handshake authentication.
After the ClientFinished message is processed, save off the digest state
for future post-handshake authentication. When post-handshake auth occurs,
copy over the saved handshake context into the "main" handshake digest.
This effectively discards the any KeyUpdate or NewSessionTicket messages
and any prior post-handshake authentication.
This, of course, assumes that the ID-22 did not mean to include any
previous post-handshake authentication into the new handshake transcript.
This is implied by section 4.4.1 that lists messages only up to the
first ClientFinished.
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4964)
2017-12-19 05:52:28 +08:00
|
|
|
{ "ForcePHA", &parse_server_force_pha },
|
2017-03-16 01:25:55 +08:00
|
|
|
{ "SessionTicketAppData", &parse_server_session_ticket_app_data },
|
2016-03-17 22:14:30 +08:00
|
|
|
};
|
|
|
|
|
2018-05-09 23:09:50 +08:00
|
|
|
SSL_TEST_CTX *SSL_TEST_CTX_new(void)
|
2016-03-17 22:14:30 +08:00
|
|
|
{
|
|
|
|
SSL_TEST_CTX *ret;
|
2017-06-22 12:00:55 +08:00
|
|
|
|
|
|
|
/* The return code is checked by caller */
|
|
|
|
if ((ret = OPENSSL_zalloc(sizeof(*ret))) != NULL) {
|
|
|
|
ret->app_data_size = default_app_data_size;
|
|
|
|
ret->max_fragment_size = default_max_fragment_size;
|
|
|
|
}
|
2016-03-17 22:14:30 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
static void ssl_test_extra_conf_free_data(SSL_TEST_EXTRA_CONF *conf)
|
|
|
|
{
|
|
|
|
OPENSSL_free(conf->client.npn_protocols);
|
|
|
|
OPENSSL_free(conf->server.npn_protocols);
|
|
|
|
OPENSSL_free(conf->server2.npn_protocols);
|
|
|
|
OPENSSL_free(conf->client.alpn_protocols);
|
|
|
|
OPENSSL_free(conf->server.alpn_protocols);
|
|
|
|
OPENSSL_free(conf->server2.alpn_protocols);
|
2017-02-16 22:47:26 +08:00
|
|
|
OPENSSL_free(conf->client.reneg_ciphers);
|
2017-03-14 20:48:54 +08:00
|
|
|
OPENSSL_free(conf->server.srp_user);
|
|
|
|
OPENSSL_free(conf->server.srp_password);
|
|
|
|
OPENSSL_free(conf->server2.srp_user);
|
|
|
|
OPENSSL_free(conf->server2.srp_password);
|
|
|
|
OPENSSL_free(conf->client.srp_user);
|
|
|
|
OPENSSL_free(conf->client.srp_password);
|
2017-03-16 01:25:55 +08:00
|
|
|
OPENSSL_free(conf->server.session_ticket_app_data);
|
|
|
|
OPENSSL_free(conf->server2.session_ticket_app_data);
|
2016-07-21 22:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ssl_test_ctx_free_extra_data(SSL_TEST_CTX *ctx)
|
2016-03-17 22:14:30 +08:00
|
|
|
{
|
2016-07-21 22:29:48 +08:00
|
|
|
ssl_test_extra_conf_free_data(&ctx->extra);
|
|
|
|
ssl_test_extra_conf_free_data(&ctx->resume_extra);
|
|
|
|
}
|
2016-07-05 02:16:14 +08:00
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx)
|
|
|
|
{
|
|
|
|
ssl_test_ctx_free_extra_data(ctx);
|
2016-07-05 02:16:14 +08:00
|
|
|
OPENSSL_free(ctx->expected_npn_protocol);
|
|
|
|
OPENSSL_free(ctx->expected_alpn_protocol);
|
2017-03-16 01:25:55 +08:00
|
|
|
OPENSSL_free(ctx->expected_session_ticket_app_data);
|
2017-04-01 05:35:28 +08:00
|
|
|
sk_X509_NAME_pop_free(ctx->expected_server_ca_names, X509_NAME_free);
|
2017-03-16 00:07:07 +08:00
|
|
|
sk_X509_NAME_pop_free(ctx->expected_client_ca_names, X509_NAME_free);
|
2015-12-22 04:19:29 +08:00
|
|
|
OPENSSL_free(ctx->expected_cipher);
|
2016-03-17 22:14:30 +08:00
|
|
|
OPENSSL_free(ctx);
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
static int parse_client_options(SSL_TEST_CLIENT_CONF *client, const CONF *conf,
|
|
|
|
const char *client_section)
|
2016-03-17 22:14:30 +08:00
|
|
|
{
|
|
|
|
STACK_OF(CONF_VALUE) *sk_conf;
|
|
|
|
int i;
|
|
|
|
size_t j;
|
|
|
|
|
2017-06-22 12:00:55 +08:00
|
|
|
if (!TEST_ptr(sk_conf = NCONF_get_section(conf, client_section)))
|
|
|
|
return 0;
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(sk_conf); i++) {
|
|
|
|
int found = 0;
|
|
|
|
const CONF_VALUE *option = sk_CONF_VALUE_value(sk_conf, i);
|
|
|
|
for (j = 0; j < OSSL_NELEM(ssl_test_client_options); j++) {
|
|
|
|
if (strcmp(option->name, ssl_test_client_options[j].name) == 0) {
|
|
|
|
if (!ssl_test_client_options[j].parse(client, option->value)) {
|
2017-06-19 09:21:22 +08:00
|
|
|
TEST_info("Bad value %s for option %s",
|
|
|
|
option->value, option->name);
|
2016-07-21 22:29:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2017-06-19 09:21:22 +08:00
|
|
|
TEST_info("Unknown test option: %s", option->name);
|
2016-07-21 22:29:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_server_options(SSL_TEST_SERVER_CONF *server, const CONF *conf,
|
|
|
|
const char *server_section)
|
|
|
|
{
|
|
|
|
STACK_OF(CONF_VALUE) *sk_conf;
|
|
|
|
int i;
|
|
|
|
size_t j;
|
|
|
|
|
2017-06-22 12:00:55 +08:00
|
|
|
if (!TEST_ptr(sk_conf = NCONF_get_section(conf, server_section)))
|
|
|
|
return 0;
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(sk_conf); i++) {
|
|
|
|
int found = 0;
|
|
|
|
const CONF_VALUE *option = sk_CONF_VALUE_value(sk_conf, i);
|
2016-07-21 22:29:48 +08:00
|
|
|
for (j = 0; j < OSSL_NELEM(ssl_test_server_options); j++) {
|
|
|
|
if (strcmp(option->name, ssl_test_server_options[j].name) == 0) {
|
|
|
|
if (!ssl_test_server_options[j].parse(server, option->value)) {
|
2017-06-19 09:21:22 +08:00
|
|
|
TEST_info("Bad value %s for option %s",
|
|
|
|
option->value, option->name);
|
2016-07-21 22:29:48 +08:00
|
|
|
return 0;
|
2016-03-17 22:14:30 +08:00
|
|
|
}
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2017-06-19 09:21:22 +08:00
|
|
|
TEST_info("Unknown test option: %s", option->name);
|
2016-07-21 22:29:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section)
|
|
|
|
{
|
2017-06-22 12:00:55 +08:00
|
|
|
STACK_OF(CONF_VALUE) *sk_conf = NULL;
|
|
|
|
SSL_TEST_CTX *ctx = NULL;
|
2016-07-21 22:29:48 +08:00
|
|
|
int i;
|
|
|
|
size_t j;
|
|
|
|
|
2017-06-22 12:00:55 +08:00
|
|
|
if (!TEST_ptr(sk_conf = NCONF_get_section(conf, test_section))
|
|
|
|
|| !TEST_ptr(ctx = SSL_TEST_CTX_new()))
|
|
|
|
goto err;
|
2016-07-21 22:29:48 +08:00
|
|
|
|
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(sk_conf); i++) {
|
|
|
|
int found = 0;
|
|
|
|
const CONF_VALUE *option = sk_CONF_VALUE_value(sk_conf, i);
|
|
|
|
|
|
|
|
/* Subsections */
|
|
|
|
if (strcmp(option->name, "client") == 0) {
|
2017-08-21 08:37:34 +08:00
|
|
|
if (!parse_client_options(&ctx->extra.client, conf, option->value))
|
2016-07-21 22:29:48 +08:00
|
|
|
goto err;
|
|
|
|
} else if (strcmp(option->name, "server") == 0) {
|
2017-08-21 08:37:34 +08:00
|
|
|
if (!parse_server_options(&ctx->extra.server, conf, option->value))
|
2016-07-21 22:29:48 +08:00
|
|
|
goto err;
|
|
|
|
} else if (strcmp(option->name, "server2") == 0) {
|
2017-08-21 08:37:34 +08:00
|
|
|
if (!parse_server_options(&ctx->extra.server2, conf, option->value))
|
2016-07-21 22:29:48 +08:00
|
|
|
goto err;
|
|
|
|
} else if (strcmp(option->name, "resume-client") == 0) {
|
2017-08-21 08:37:34 +08:00
|
|
|
if (!parse_client_options(&ctx->resume_extra.client, conf,
|
|
|
|
option->value))
|
2016-07-21 22:29:48 +08:00
|
|
|
goto err;
|
|
|
|
} else if (strcmp(option->name, "resume-server") == 0) {
|
2017-08-21 08:37:34 +08:00
|
|
|
if (!parse_server_options(&ctx->resume_extra.server, conf,
|
|
|
|
option->value))
|
2016-07-21 22:29:48 +08:00
|
|
|
goto err;
|
|
|
|
} else if (strcmp(option->name, "resume-server2") == 0) {
|
|
|
|
if (!parse_server_options(&ctx->resume_extra.server2, conf,
|
|
|
|
option->value))
|
|
|
|
goto err;
|
|
|
|
} else {
|
|
|
|
for (j = 0; j < OSSL_NELEM(ssl_test_ctx_options); j++) {
|
|
|
|
if (strcmp(option->name, ssl_test_ctx_options[j].name) == 0) {
|
|
|
|
if (!ssl_test_ctx_options[j].parse(ctx, option->value)) {
|
2017-06-19 09:21:22 +08:00
|
|
|
TEST_info("Bad value %s for option %s",
|
|
|
|
option->value, option->name);
|
2016-07-21 22:29:48 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2017-06-19 09:21:22 +08:00
|
|
|
TEST_info("Unknown test option: %s", option->name);
|
2016-07-21 22:29:48 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2016-03-17 22:14:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
err:
|
|
|
|
SSL_TEST_CTX_free(ctx);
|
|
|
|
ctx = NULL;
|
|
|
|
done:
|
|
|
|
return ctx;
|
|
|
|
}
|