2020-05-07 19:44:01 +08:00
|
|
|
SSL tests
|
|
|
|
=========
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
SSL testcases are configured in the `ssl-tests` directory.
|
|
|
|
|
2020-02-26 02:25:13 +08:00
|
|
|
Each `ssl_*.cnf.in` file contains a number of test configurations. These files
|
2016-03-17 22:14:30 +08:00
|
|
|
are used to generate testcases in the OpenSSL CONF format.
|
|
|
|
|
|
|
|
The precise test output can be dependent on the library configuration. The test
|
|
|
|
harness generates the output files on the fly.
|
|
|
|
|
|
|
|
However, for verification, we also include checked-in configuration outputs
|
|
|
|
corresponding to the default configuration. These testcases live in
|
2020-02-26 02:25:13 +08:00
|
|
|
`test/ssl-tests/*.cnf` files.
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2020-02-26 02:25:13 +08:00
|
|
|
For more details, see `ssl-tests/01-simple.cnf.in` for an example.
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
Configuring the test
|
|
|
|
--------------------
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
First, give your test a name. The names do not have to be unique.
|
|
|
|
|
|
|
|
An example test input looks like this:
|
|
|
|
|
|
|
|
{
|
|
|
|
name => "test-default",
|
|
|
|
server => { "CipherString" => "DEFAULT" },
|
|
|
|
client => { "CipherString" => "DEFAULT" },
|
|
|
|
test => { "ExpectedResult" => "Success" },
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
The test section supports the following options
|
|
|
|
|
|
|
|
### Test mode
|
|
|
|
|
|
|
|
* Method - the method to test. One of DTLS or TLS.
|
|
|
|
|
|
|
|
* HandshakeMode - which handshake flavour to test:
|
|
|
|
- Simple - plain handshake (default)
|
|
|
|
- Resume - test resumption
|
2016-09-27 18:50:43 +08:00
|
|
|
- RenegotiateServer - test server initiated renegotiation
|
|
|
|
- RenegotiateClient - test client initiated renegotiation
|
2016-07-21 22:29:48 +08:00
|
|
|
|
|
|
|
When HandshakeMode is Resume or Renegotiate, the original handshake is expected
|
|
|
|
to succeed. All configured test expectations are verified against the second
|
|
|
|
handshake.
|
|
|
|
|
2016-08-16 21:11:08 +08:00
|
|
|
* ApplicationData - amount of application data bytes to send (integer, defaults
|
|
|
|
to 256 bytes). Applies to both client and server. Application data is sent in
|
|
|
|
64kB chunks (but limited by MaxFragmentSize and available parallelization, see
|
|
|
|
below).
|
|
|
|
|
|
|
|
* MaxFragmentSize - maximum send fragment size (integer, defaults to 512 in
|
|
|
|
tests - see `SSL_CTX_set_max_send_fragment` for documentation). Applies to
|
|
|
|
both client and server. Lowering the fragment size will split handshake and
|
|
|
|
application data up between more `SSL_write` calls, thus allowing to exercise
|
|
|
|
different code paths. In particular, if the buffer size (64kB) is at least
|
|
|
|
four times as large as the maximum fragment, interleaved multi-buffer crypto
|
|
|
|
implementations may be used on some platforms.
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
### Test expectations
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
* ExpectedResult - expected handshake outcome. One of
|
|
|
|
- Success - handshake success
|
|
|
|
- ServerFail - serverside handshake failure
|
|
|
|
- ClientFail - clientside handshake failure
|
|
|
|
- InternalError - some other error
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
* ExpectedClientAlert, ExpectedServerAlert - expected alert. See
|
2021-05-22 01:26:33 +08:00
|
|
|
`test/helpers/ssl_test_ctx.c` for known values. Note: the expected alert is currently
|
2016-08-12 20:29:24 +08:00
|
|
|
matched against the _last_ received alert (i.e., a fatal alert or a
|
|
|
|
`close_notify`). Warning alert expectations are not yet supported. (A warning
|
|
|
|
alert will not be correctly matched, if followed by a `close_notify` or
|
|
|
|
another alert.)
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
* ExpectedProtocol - expected negotiated protocol. One of
|
2016-03-17 22:14:30 +08:00
|
|
|
SSLv3, TLSv1, TLSv1.1, TLSv1.2.
|
|
|
|
|
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 - whether or not a session ticket is expected
|
|
|
|
- Ignore - do not check for a session ticket (default)
|
|
|
|
- Yes - a session ticket is expected
|
|
|
|
- No - a session ticket is not expected
|
2016-07-06 01:06:23 +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 - whether or not a session id is expected
|
|
|
|
- Ignore - do not check for a session id (default)
|
|
|
|
- Yes - a session id is expected
|
|
|
|
- No - a session id is not expected
|
|
|
|
|
2016-07-06 01:06:23 +08:00
|
|
|
* ResumptionExpected - whether or not resumption is expected (Resume mode only)
|
|
|
|
- Yes - resumed handshake
|
|
|
|
- No - full handshake (default)
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
* ExpectedNPNProtocol, ExpectedALPNProtocol - NPN and ALPN expectations.
|
2016-07-05 02:16:14 +08:00
|
|
|
|
2017-01-08 08:09:08 +08:00
|
|
|
* ExpectedTmpKeyType - the expected algorithm or curve of server temp key
|
|
|
|
|
2017-01-12 21:58:48 +08:00
|
|
|
* ExpectedServerCertType, ExpectedClientCertType - the expected algorithm or
|
2017-01-09 03:30:41 +08:00
|
|
|
curve of server or client certificate
|
|
|
|
|
2017-01-27 23:06:16 +08:00
|
|
|
* ExpectedServerSignHash, ExpectedClientSignHash - the expected
|
2017-01-13 23:20:42 +08:00
|
|
|
signing hash used by server or client certificate
|
|
|
|
|
2017-01-27 23:06:16 +08:00
|
|
|
* ExpectedServerSignType, ExpectedClientSignType - the expected
|
|
|
|
signature type used by server or client when signing messages
|
|
|
|
|
2017-03-16 00:07:07 +08:00
|
|
|
* ExpectedClientCANames - for client auth list of CA names the server must
|
|
|
|
send. If this is "empty" the list is expected to be empty otherwise it
|
|
|
|
is a file of certificates whose subject names form the list.
|
|
|
|
|
2017-04-01 05:35:28 +08:00
|
|
|
* ExpectedServerCANames - list of CA names the client must send, TLS 1.3 only.
|
|
|
|
If this is "empty" the list is expected to be empty otherwise it is a file
|
|
|
|
of certificates whose subject names form the list.
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
Configuring the client and server
|
|
|
|
---------------------------------
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
The client and server configurations can be any valid `SSL_CTX`
|
|
|
|
configurations. For details, see the manpages for `SSL_CONF_cmd`.
|
|
|
|
|
|
|
|
Give your configurations as a dictionary of CONF commands, e.g.
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
server => {
|
|
|
|
"CipherString" => "DEFAULT",
|
|
|
|
"MinProtocol" => "TLSv1",
|
|
|
|
}
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2016-07-06 01:06:23 +08:00
|
|
|
The following sections may optionally be defined:
|
|
|
|
|
|
|
|
* server2 - this section configures a secondary context that is selected via the
|
|
|
|
ServerName test option. This context is used whenever a ServerNameCallback is
|
|
|
|
specified. If the server2 section is not present, then the configuration
|
|
|
|
matches server.
|
|
|
|
* resume_server - this section configures the client to resume its session
|
|
|
|
against a different server. This context is used whenever HandshakeMode is
|
2016-07-21 20:04:00 +08:00
|
|
|
Resume. If the resume_server section is not present, then the configuration
|
2016-07-06 01:06:23 +08:00
|
|
|
matches server.
|
2016-07-21 20:04:00 +08:00
|
|
|
* resume_client - this section configures the client to resume its session with
|
|
|
|
a different configuration. In practice this may occur when, for example,
|
|
|
|
upgraded clients reuse sessions persisted on disk. This context is used
|
|
|
|
whenever HandshakeMode is Resume. If the resume_client section is not present,
|
|
|
|
then the configuration matches 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-13 06:16:52 +08:00
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
### Configuring callbacks and additional options
|
|
|
|
|
|
|
|
Additional handshake settings can be configured in the `extra` section of each
|
|
|
|
client and server:
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
client => {
|
|
|
|
"CipherString" => "DEFAULT",
|
|
|
|
extra => {
|
|
|
|
"ServerName" => "server2",
|
|
|
|
}
|
2016-07-21 22:29:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#### Supported client-side options
|
|
|
|
|
|
|
|
* ClientVerifyCallback - the client's custom certificate verify callback.
|
|
|
|
Used to test callback behaviour. One of
|
|
|
|
- None - no custom callback (default)
|
|
|
|
- AcceptAll - accepts all certificates.
|
|
|
|
- RejectAll - rejects all certificates.
|
|
|
|
|
|
|
|
* ServerName - the server the client should attempt to connect to. One of
|
|
|
|
- None - do not use SNI (default)
|
|
|
|
- server1 - the initial context
|
|
|
|
- server2 - the secondary context
|
|
|
|
- invalid - an unknown context
|
|
|
|
|
2016-08-09 22:47:26 +08:00
|
|
|
* CTValidation - Certificate Transparency validation strategy. One of
|
|
|
|
- None - no validation (default)
|
|
|
|
- Permissive - SSL_CT_VALIDATION_PERMISSIVE
|
|
|
|
- Strict - SSL_CT_VALIDATION_STRICT
|
|
|
|
|
2016-07-21 22:29:48 +08:00
|
|
|
#### Supported server-side options
|
|
|
|
|
|
|
|
* ServerNameCallback - the SNI switching callback to use
|
|
|
|
- None - no callback (default)
|
|
|
|
- IgnoreMismatch - continue the handshake on SNI mismatch
|
|
|
|
- RejectMismatch - abort the handshake on SNI mismatch
|
|
|
|
|
|
|
|
* BrokenSessionTicket - a special test case where the session ticket callback
|
|
|
|
does not initialize crypto.
|
|
|
|
- No (default)
|
|
|
|
- Yes
|
|
|
|
|
|
|
|
#### Mutually supported options
|
|
|
|
|
|
|
|
* NPNProtocols, ALPNProtocols - NPN and ALPN settings. Server and client
|
|
|
|
protocols can be specified as a comma-separated list, and a callback with the
|
|
|
|
recommended behaviour will be installed automatically.
|
|
|
|
|
2017-03-14 20:48:54 +08:00
|
|
|
* SRPUser, SRPPassword - SRP settings. For client, this is the SRP user to
|
|
|
|
connect as; for server, this is a known SRP user.
|
|
|
|
|
2016-03-17 22:14:30 +08:00
|
|
|
### Default server and client configurations
|
|
|
|
|
|
|
|
The default server certificate and CA files are added to the configurations
|
|
|
|
automatically. Server certificate verification is requested by default.
|
|
|
|
|
|
|
|
You can override these options by redefining them:
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
client => {
|
|
|
|
"VerifyCAFile" => "/path/to/custom/file"
|
|
|
|
}
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
or by deleting them
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
client => {
|
|
|
|
"VerifyCAFile" => undef
|
|
|
|
}
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
Adding a test to the test harness
|
|
|
|
---------------------------------
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2016-08-19 20:19:32 +08:00
|
|
|
1. Add a new test configuration to `test/ssl-tests`, following the examples of
|
2020-02-26 02:25:13 +08:00
|
|
|
existing `*.cnf.in` files (for example, `01-simple.cnf.in`).
|
2016-08-19 20:19:32 +08:00
|
|
|
|
2020-02-26 02:25:13 +08:00
|
|
|
2. Generate the generated `*.cnf` test input file. You can do so by running
|
2016-08-19 20:19:32 +08:00
|
|
|
`generate_ssl_tests.pl`:
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
$ ./config
|
|
|
|
$ cd test
|
|
|
|
$ TOP=.. perl -I ../util/perl/ generate_ssl_tests.pl \
|
|
|
|
ssl-tests/my.cnf.in default > ssl-tests/my.cnf
|
2016-08-19 20:19:32 +08:00
|
|
|
|
2020-04-27 17:36:35 +08:00
|
|
|
where `my.cnf.in` is your test input file and `default` is the provider to use.
|
|
|
|
For all the pre-generated test files you should use the default provider.
|
2016-08-19 20:19:32 +08:00
|
|
|
|
2020-02-26 02:25:13 +08:00
|
|
|
For example, to generate the test cases in `ssl-tests/01-simple.cnf.in`, do
|
2016-08-19 20:19:32 +08:00
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
$ TOP=.. perl -I ../util/perl/ generate_ssl_tests.pl \
|
|
|
|
ssl-tests/01-simple.cnf.in default > ssl-tests/01-simple.cnf
|
2016-08-19 20:19:32 +08:00
|
|
|
|
|
|
|
Alternatively (hackish but simple), you can comment out
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
unlink glob $tmp_file;
|
2016-08-19 20:19:32 +08:00
|
|
|
|
|
|
|
in `test/recipes/80-test_ssl_new.t` and run
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
$ make TESTS=test_ssl_new test
|
2016-08-19 20:19:32 +08:00
|
|
|
|
|
|
|
This will save the generated output in a `*.tmp` file in the build directory.
|
|
|
|
|
|
|
|
3. Update the number of tests planned in `test/recipes/80-test_ssl_new.t`. If
|
|
|
|
the test suite has any skip conditions, update those too (see
|
|
|
|
`test/recipes/80-test_ssl_new.t` for details).
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
Running the tests with the test harness
|
|
|
|
---------------------------------------
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
HARNESS_VERBOSE=yes make TESTS=test_ssl_new test
|
2016-03-17 22:14:30 +08:00
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
Running a test manually
|
|
|
|
-----------------------
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
These steps are only needed during development. End users should run `make test`
|
|
|
|
or follow the instructions above to run the SSL test suite.
|
|
|
|
|
|
|
|
To run an SSL test manually from the command line, the `TEST_CERTS_DIR`
|
|
|
|
environment variable to point to the location of the certs. E.g., from the root
|
|
|
|
OpenSSL directory, do
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
$ CTLOG_FILE=test/ct/log_list.cnf TEST_CERTS_DIR=test/certs test/ssl_test \
|
2021-05-22 01:26:33 +08:00
|
|
|
test/ssl-tests/01-simple.cnf default
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
or for shared builds
|
|
|
|
|
2020-05-07 19:44:01 +08:00
|
|
|
$ CTLOG_FILE=test/ct/log_list.cnf TEST_CERTS_DIR=test/certs \
|
2021-05-22 01:26:33 +08:00
|
|
|
util/wrap.pl test/ssl_test test/ssl-tests/01-simple.cnf default
|
|
|
|
|
|
|
|
In the above examples, `default` is the provider to use.
|
2016-03-17 22:14:30 +08:00
|
|
|
|
|
|
|
Note that the test expectations sometimes depend on the Configure settings. For
|
|
|
|
example, the negotiated protocol depends on the set of available (enabled)
|
|
|
|
protocols: a build with `enable-ssl3` has different test expectations than a
|
|
|
|
build with `no-ssl3`.
|
|
|
|
|
|
|
|
The Perl test harness automatically generates expected outputs, so users who
|
|
|
|
just run `make test` do not need any extra steps.
|
|
|
|
|
|
|
|
However, when running a test manually, keep in mind that the repository version
|
2020-02-26 02:25:13 +08:00
|
|
|
of the generated `test/ssl-tests/*.cnf` correspond to expected outputs in with
|
2016-03-17 22:14:30 +08:00
|
|
|
the default Configure options. To run `ssl_test` manually from the command line
|
|
|
|
in a build with a different configuration, you may need to generate the right
|
2020-02-26 02:25:13 +08:00
|
|
|
`*.cnf` file from the `*.cnf.in` input first.
|
2022-05-25 23:39:20 +08:00
|
|
|
|
|
|
|
Running a test manually via make
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
Individual tests may be run by adding the SSL_TESTS variable to the `make`
|
|
|
|
command line. The SSL_TESTS variable is set to the list of input (or ".in")
|
|
|
|
files. The values in SSL_TESTS are globbed.
|
|
|
|
|
|
|
|
$ make test TESTS=test_ssl_new SSL_TESTS="0*.cnf.in"
|
|
|
|
|
|
|
|
$ make test TESTS=test_ssl_new SSL_TESTS="01-simple.cnf.in 05-sni.cnf.in"
|