Blame test/README.ssltest.md

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