Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 1 | # SSL tests |
| 2 | |
| 3 | SSL testcases are configured in the `ssl-tests` directory. |
| 4 | |
| 5 | Each `ssl_*.conf.in` file contains a number of test configurations. These files |
| 6 | are used to generate testcases in the OpenSSL CONF format. |
| 7 | |
| 8 | The precise test output can be dependent on the library configuration. The test |
| 9 | harness generates the output files on the fly. |
| 10 | |
| 11 | However, for verification, we also include checked-in configuration outputs |
| 12 | corresponding to the default configuration. These testcases live in |
Emilia Kasper | 15269e5 | 2016-08-19 14:19:32 +0200 | [diff] [blame] | 13 | `test/ssl-tests/*.conf` files. |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 14 | |
| 15 | For more details, see `ssl-tests/01-simple.conf.in` for an example. |
| 16 | |
| 17 | ## Configuring the test |
| 18 | |
| 19 | First, give your test a name. The names do not have to be unique. |
| 20 | |
| 21 | An example test input looks like this: |
| 22 | |
| 23 | ``` |
| 24 | { |
| 25 | name => "test-default", |
| 26 | server => { "CipherString" => "DEFAULT" }, |
| 27 | client => { "CipherString" => "DEFAULT" }, |
| 28 | test => { "ExpectedResult" => "Success" }, |
| 29 | } |
| 30 | ``` |
| 31 | |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 32 | The test section supports the following options |
| 33 | |
| 34 | ### Test mode |
| 35 | |
| 36 | * Method - the method to test. One of DTLS or TLS. |
| 37 | |
| 38 | * HandshakeMode - which handshake flavour to test: |
| 39 | - Simple - plain handshake (default) |
| 40 | - Resume - test resumption |
Matt Caswell | fe7dd55 | 2016-09-27 11:50:43 +0100 | [diff] [blame] | 41 | - RenegotiateServer - test server initiated renegotiation |
| 42 | - RenegotiateClient - test client initiated renegotiation |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 43 | |
| 44 | When HandshakeMode is Resume or Renegotiate, the original handshake is expected |
| 45 | to succeed. All configured test expectations are verified against the second |
| 46 | handshake. |
| 47 | |
Emilia Kasper | 6dc9974 | 2016-08-16 15:11:08 +0200 | [diff] [blame] | 48 | * ApplicationData - amount of application data bytes to send (integer, defaults |
| 49 | to 256 bytes). Applies to both client and server. Application data is sent in |
| 50 | 64kB chunks (but limited by MaxFragmentSize and available parallelization, see |
| 51 | below). |
| 52 | |
| 53 | * MaxFragmentSize - maximum send fragment size (integer, defaults to 512 in |
| 54 | tests - see `SSL_CTX_set_max_send_fragment` for documentation). Applies to |
| 55 | both client and server. Lowering the fragment size will split handshake and |
| 56 | application data up between more `SSL_write` calls, thus allowing to exercise |
| 57 | different code paths. In particular, if the buffer size (64kB) is at least |
| 58 | four times as large as the maximum fragment, interleaved multi-buffer crypto |
| 59 | implementations may be used on some platforms. |
| 60 | |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 61 | ### Test expectations |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 62 | |
| 63 | * ExpectedResult - expected handshake outcome. One of |
| 64 | - Success - handshake success |
| 65 | - ServerFail - serverside handshake failure |
| 66 | - ClientFail - clientside handshake failure |
| 67 | - InternalError - some other error |
| 68 | |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 69 | * ExpectedClientAlert, ExpectedServerAlert - expected alert. See |
Emilia Kasper | dd8e5a5 | 2016-08-12 14:29:24 +0200 | [diff] [blame] | 70 | `ssl_test_ctx.c` for known values. Note: the expected alert is currently |
| 71 | matched against the _last_ received alert (i.e., a fatal alert or a |
| 72 | `close_notify`). Warning alert expectations are not yet supported. (A warning |
| 73 | alert will not be correctly matched, if followed by a `close_notify` or |
| 74 | another alert.) |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 75 | |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 76 | * ExpectedProtocol - expected negotiated protocol. One of |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 77 | SSLv3, TLSv1, TLSv1.1, TLSv1.2. |
| 78 | |
Todd Short | 5c753de | 2016-05-12 18:16:52 -0400 | [diff] [blame] | 79 | * SessionTicketExpected - whether or not a session ticket is expected |
| 80 | - Ignore - do not check for a session ticket (default) |
| 81 | - Yes - a session ticket is expected |
| 82 | - No - a session ticket is not expected |
Emilia Kasper | 590ed3d | 2016-07-05 19:06:23 +0200 | [diff] [blame] | 83 | |
| 84 | * ResumptionExpected - whether or not resumption is expected (Resume mode only) |
| 85 | - Yes - resumed handshake |
| 86 | - No - full handshake (default) |
| 87 | |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 88 | * ExpectedNPNProtocol, ExpectedALPNProtocol - NPN and ALPN expectations. |
Emilia Kasper | ce2cdac | 2016-07-04 20:16:14 +0200 | [diff] [blame] | 89 | |
Dr. Stephen Henson | b93ad05 | 2017-01-08 00:09:08 +0000 | [diff] [blame] | 90 | * ExpectedTmpKeyType - the expected algorithm or curve of server temp key |
| 91 | |
Dr. Stephen Henson | 7289ab4 | 2017-01-12 13:58:48 +0000 | [diff] [blame] | 92 | * ExpectedServerCertType, ExpectedClientCertType - the expected algorithm or |
Dr. Stephen Henson | 7f5f35a | 2017-01-08 19:30:41 +0000 | [diff] [blame] | 93 | curve of server or client certificate |
| 94 | |
Dr. Stephen Henson | 54b7f2a | 2017-01-27 15:06:16 +0000 | [diff] [blame] | 95 | * ExpectedServerSignHash, ExpectedClientSignHash - the expected |
Dr. Stephen Henson | ee5b6a4 | 2017-01-13 15:20:42 +0000 | [diff] [blame] | 96 | signing hash used by server or client certificate |
| 97 | |
Dr. Stephen Henson | 54b7f2a | 2017-01-27 15:06:16 +0000 | [diff] [blame] | 98 | * ExpectedServerSignType, ExpectedClientSignType - the expected |
| 99 | signature type used by server or client when signing messages |
| 100 | |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 101 | ## Configuring the client and server |
| 102 | |
| 103 | The client and server configurations can be any valid `SSL_CTX` |
| 104 | configurations. For details, see the manpages for `SSL_CONF_cmd`. |
| 105 | |
| 106 | Give your configurations as a dictionary of CONF commands, e.g. |
| 107 | |
| 108 | ``` |
| 109 | server => { |
| 110 | "CipherString" => "DEFAULT", |
| 111 | "MinProtocol" => "TLSv1", |
| 112 | } |
| 113 | ``` |
| 114 | |
Emilia Kasper | 590ed3d | 2016-07-05 19:06:23 +0200 | [diff] [blame] | 115 | The following sections may optionally be defined: |
| 116 | |
| 117 | * server2 - this section configures a secondary context that is selected via the |
| 118 | ServerName test option. This context is used whenever a ServerNameCallback is |
| 119 | specified. If the server2 section is not present, then the configuration |
| 120 | matches server. |
| 121 | * resume_server - this section configures the client to resume its session |
| 122 | against a different server. This context is used whenever HandshakeMode is |
Emilia Kasper | 11279b1 | 2016-07-21 14:04:00 +0200 | [diff] [blame] | 123 | Resume. If the resume_server section is not present, then the configuration |
Emilia Kasper | 590ed3d | 2016-07-05 19:06:23 +0200 | [diff] [blame] | 124 | matches server. |
Emilia Kasper | 11279b1 | 2016-07-21 14:04:00 +0200 | [diff] [blame] | 125 | * resume_client - this section configures the client to resume its session with |
| 126 | a different configuration. In practice this may occur when, for example, |
| 127 | upgraded clients reuse sessions persisted on disk. This context is used |
| 128 | whenever HandshakeMode is Resume. If the resume_client section is not present, |
| 129 | then the configuration matches client. |
Todd Short | 5c753de | 2016-05-12 18:16:52 -0400 | [diff] [blame] | 130 | |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 131 | ### Configuring callbacks and additional options |
| 132 | |
| 133 | Additional handshake settings can be configured in the `extra` section of each |
| 134 | client and server: |
| 135 | |
| 136 | ``` |
| 137 | client => { |
| 138 | "CipherString" => "DEFAULT", |
| 139 | extra => { |
| 140 | "ServerName" => "server2", |
| 141 | } |
| 142 | } |
| 143 | ``` |
| 144 | |
| 145 | #### Supported client-side options |
| 146 | |
| 147 | * ClientVerifyCallback - the client's custom certificate verify callback. |
| 148 | Used to test callback behaviour. One of |
| 149 | - None - no custom callback (default) |
| 150 | - AcceptAll - accepts all certificates. |
| 151 | - RejectAll - rejects all certificates. |
| 152 | |
| 153 | * ServerName - the server the client should attempt to connect to. One of |
| 154 | - None - do not use SNI (default) |
| 155 | - server1 - the initial context |
| 156 | - server2 - the secondary context |
| 157 | - invalid - an unknown context |
| 158 | |
Emilia Kasper | da085d2 | 2016-08-09 16:47:26 +0200 | [diff] [blame] | 159 | * CTValidation - Certificate Transparency validation strategy. One of |
| 160 | - None - no validation (default) |
| 161 | - Permissive - SSL_CT_VALIDATION_PERMISSIVE |
| 162 | - Strict - SSL_CT_VALIDATION_STRICT |
| 163 | |
Emilia Kasper | 9f48bba | 2016-07-21 16:29:48 +0200 | [diff] [blame] | 164 | #### Supported server-side options |
| 165 | |
| 166 | * ServerNameCallback - the SNI switching callback to use |
| 167 | - None - no callback (default) |
| 168 | - IgnoreMismatch - continue the handshake on SNI mismatch |
| 169 | - RejectMismatch - abort the handshake on SNI mismatch |
| 170 | |
| 171 | * BrokenSessionTicket - a special test case where the session ticket callback |
| 172 | does not initialize crypto. |
| 173 | - No (default) |
| 174 | - Yes |
| 175 | |
| 176 | #### Mutually supported options |
| 177 | |
| 178 | * NPNProtocols, ALPNProtocols - NPN and ALPN settings. Server and client |
| 179 | protocols can be specified as a comma-separated list, and a callback with the |
| 180 | recommended behaviour will be installed automatically. |
| 181 | |
Emilia Kasper | ea1ecd9 | 2017-03-14 13:48:54 +0100 | [diff] [blame] | 182 | * SRPUser, SRPPassword - SRP settings. For client, this is the SRP user to |
| 183 | connect as; for server, this is a known SRP user. |
| 184 | |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 185 | ### Default server and client configurations |
| 186 | |
| 187 | The default server certificate and CA files are added to the configurations |
| 188 | automatically. Server certificate verification is requested by default. |
| 189 | |
| 190 | You can override these options by redefining them: |
| 191 | |
| 192 | ``` |
| 193 | client => { |
| 194 | "VerifyCAFile" => "/path/to/custom/file" |
| 195 | } |
| 196 | ``` |
| 197 | |
| 198 | or by deleting them |
| 199 | |
| 200 | ``` |
| 201 | client => { |
| 202 | "VerifyCAFile" => undef |
| 203 | } |
| 204 | ``` |
| 205 | |
| 206 | ## Adding a test to the test harness |
| 207 | |
Emilia Kasper | 15269e5 | 2016-08-19 14:19:32 +0200 | [diff] [blame] | 208 | 1. Add a new test configuration to `test/ssl-tests`, following the examples of |
| 209 | existing `*.conf.in` files (for example, `01-simple.conf.in`). |
| 210 | |
| 211 | 2. Generate the generated `*.conf` test input file. You can do so by running |
| 212 | `generate_ssl_tests.pl`: |
| 213 | |
| 214 | ``` |
| 215 | $ ./config |
| 216 | $ cd test |
| 217 | $ TOP=.. perl -I testlib/ generate_ssl_tests.pl ssl-tests/my.conf.in \ |
| 218 | > ssl-tests/my.conf |
| 219 | ``` |
| 220 | |
| 221 | where `my.conf.in` is your test input file. |
| 222 | |
| 223 | For example, to generate the test cases in `ssl-tests/01-simple.conf.in`, do |
| 224 | |
| 225 | ``` |
| 226 | $ TOP=.. perl -I testlib/ generate_ssl_tests.pl ssl-tests/01-simple.conf.in > ssl-tests/01-simple.conf |
| 227 | ``` |
| 228 | |
| 229 | Alternatively (hackish but simple), you can comment out |
| 230 | |
| 231 | ``` |
| 232 | unlink glob $tmp_file; |
| 233 | ``` |
| 234 | |
| 235 | in `test/recipes/80-test_ssl_new.t` and run |
| 236 | |
| 237 | ``` |
| 238 | $ make TESTS=test_ssl_new test |
| 239 | ``` |
| 240 | |
| 241 | This will save the generated output in a `*.tmp` file in the build directory. |
| 242 | |
| 243 | 3. Update the number of tests planned in `test/recipes/80-test_ssl_new.t`. If |
| 244 | the test suite has any skip conditions, update those too (see |
| 245 | `test/recipes/80-test_ssl_new.t` for details). |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 246 | |
| 247 | ## Running the tests with the test harness |
| 248 | |
| 249 | ``` |
| 250 | HARNESS_VERBOSE=yes make TESTS=test_ssl_new test |
| 251 | ``` |
| 252 | |
| 253 | ## Running a test manually |
| 254 | |
| 255 | These steps are only needed during development. End users should run `make test` |
| 256 | or follow the instructions above to run the SSL test suite. |
| 257 | |
| 258 | To run an SSL test manually from the command line, the `TEST_CERTS_DIR` |
| 259 | environment variable to point to the location of the certs. E.g., from the root |
| 260 | OpenSSL directory, do |
| 261 | |
| 262 | ``` |
Matt Caswell | 1329b95 | 2016-09-27 10:18:00 +0100 | [diff] [blame] | 263 | $ CTLOG_FILE=test/ct/log_list.conf TEST_CERTS_DIR=test/certs test/ssl_test \ |
| 264 | test/ssl-tests/01-simple.conf |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 265 | ``` |
| 266 | |
| 267 | or for shared builds |
| 268 | |
| 269 | ``` |
Matt Caswell | 1329b95 | 2016-09-27 10:18:00 +0100 | [diff] [blame] | 270 | $ CTLOG_FILE=test/ct/log_list.conf TEST_CERTS_DIR=test/certs \ |
| 271 | util/shlib_wrap.sh test/ssl_test test/ssl-tests/01-simple.conf |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 272 | ``` |
| 273 | |
Emilia Kasper | 453dfd8 | 2016-03-17 15:14:30 +0100 | [diff] [blame] | 274 | Note that the test expectations sometimes depend on the Configure settings. For |
| 275 | example, the negotiated protocol depends on the set of available (enabled) |
| 276 | protocols: a build with `enable-ssl3` has different test expectations than a |
| 277 | build with `no-ssl3`. |
| 278 | |
| 279 | The Perl test harness automatically generates expected outputs, so users who |
| 280 | just run `make test` do not need any extra steps. |
| 281 | |
| 282 | However, when running a test manually, keep in mind that the repository version |
| 283 | of the generated `test/ssl-tests/*.conf` correspond to expected outputs in with |
| 284 | the default Configure options. To run `ssl_test` manually from the command line |
| 285 | in a build with a different configuration, you may need to generate the right |
| 286 | `*.conf` file from the `*.conf.in` input first. |