5e2b2d76fc1422554aa26b3a5c2fa9cb077f0789
[openssl.git] / test / README.ssltest.md
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
13 `test/ssl-tests/*.conf` files.
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
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
41   - RenegotiateServer - test server initiated renegotiation
42   - RenegotiateClient - test client initiated renegotiation
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
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
61 ### Test expectations
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
69 * ExpectedClientAlert, ExpectedServerAlert - expected alert. See
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.)
75
76 * ExpectedProtocol - expected negotiated protocol. One of
77   SSLv3, TLSv1, TLSv1.1, TLSv1.2.
78
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
83
84 * ResumptionExpected - whether or not resumption is expected (Resume mode only)
85   - Yes - resumed handshake
86   - No - full handshake (default)
87
88 * ExpectedNPNProtocol, ExpectedALPNProtocol - NPN and ALPN expectations.
89
90 * ExpectedTmpKeyType - the expected algorithm or curve of server temp key
91
92 * ExpectedServerCertType, ExpectedClientCertType - the expected algorithm or
93   curve of server or client certificate
94
95 * ExpectedServerSignatureHash, ExpectedClientSignatureHash - the expected
96   signing hash used by server or client certificate
97
98 ## Configuring the client and server
99
100 The client and server configurations can be any valid `SSL_CTX`
101 configurations. For details, see the manpages for `SSL_CONF_cmd`.
102
103 Give your configurations as a dictionary of CONF commands, e.g.
104
105 ```
106 server => {
107     "CipherString" => "DEFAULT",
108     "MinProtocol" => "TLSv1",
109 }
110 ```
111
112 The following sections may optionally be defined:
113
114 * server2 - this section configures a secondary context that is selected via the
115   ServerName test option. This context is used whenever a ServerNameCallback is
116   specified. If the server2 section is not present, then the configuration
117   matches server.
118 * resume_server - this section configures the client to resume its session
119   against a different server. This context is used whenever HandshakeMode is
120   Resume. If the resume_server section is not present, then the configuration
121   matches server.
122 * resume_client - this section configures the client to resume its session with
123   a different configuration. In practice this may occur when, for example,
124   upgraded clients reuse sessions persisted on disk.  This context is used
125   whenever HandshakeMode is Resume. If the resume_client section is not present,
126   then the configuration matches client.
127
128 ### Configuring callbacks and additional options
129
130 Additional handshake settings can be configured in the `extra` section of each
131 client and server:
132
133 ```
134 client => {
135     "CipherString" => "DEFAULT",
136     extra => {
137         "ServerName" => "server2",
138     }
139 }
140 ```
141
142 #### Supported client-side options
143
144 * ClientVerifyCallback - the client's custom certificate verify callback.
145   Used to test callback behaviour. One of
146   - None - no custom callback (default)
147   - AcceptAll - accepts all certificates.
148   - RejectAll - rejects all certificates.
149
150 * ServerName - the server the client should attempt to connect to. One of
151   - None - do not use SNI (default)
152   - server1 - the initial context
153   - server2 - the secondary context
154   - invalid - an unknown context
155
156 * CTValidation - Certificate Transparency validation strategy. One of
157   - None - no validation (default)
158   - Permissive - SSL_CT_VALIDATION_PERMISSIVE
159   - Strict - SSL_CT_VALIDATION_STRICT
160
161 #### Supported server-side options
162
163 * ServerNameCallback - the SNI switching callback to use
164   - None - no callback (default)
165   - IgnoreMismatch - continue the handshake on SNI mismatch
166   - RejectMismatch - abort the handshake on SNI mismatch
167
168 * BrokenSessionTicket - a special test case where the session ticket callback
169   does not initialize crypto.
170   - No (default)
171   - Yes
172
173 #### Mutually supported options
174
175 * NPNProtocols, ALPNProtocols - NPN and ALPN settings. Server and client
176   protocols can be specified as a comma-separated list, and a callback with the
177   recommended behaviour will be installed automatically.
178
179 ### Default server and client configurations
180
181 The default server certificate and CA files are added to the configurations
182 automatically. Server certificate verification is requested by default.
183
184 You can override these options by redefining them:
185
186 ```
187 client => {
188     "VerifyCAFile" => "/path/to/custom/file"
189 }
190 ```
191
192 or by deleting them
193
194 ```
195 client => {
196     "VerifyCAFile" => undef
197 }
198 ```
199
200 ## Adding a test to the test harness
201
202 1. Add a new test configuration to `test/ssl-tests`, following the examples of
203    existing `*.conf.in` files (for example, `01-simple.conf.in`).
204
205 2. Generate the generated `*.conf` test input file. You can do so by running
206    `generate_ssl_tests.pl`:
207
208 ```
209 $ ./config
210 $ cd test
211 $ TOP=.. perl -I testlib/ generate_ssl_tests.pl ssl-tests/my.conf.in \
212   > ssl-tests/my.conf
213 ```
214
215 where `my.conf.in` is your test input file.
216
217 For example, to generate the test cases in `ssl-tests/01-simple.conf.in`, do
218
219 ```
220 $ TOP=.. perl -I testlib/ generate_ssl_tests.pl ssl-tests/01-simple.conf.in > ssl-tests/01-simple.conf
221 ```
222
223 Alternatively (hackish but simple), you can comment out
224
225 ```
226 unlink glob $tmp_file;
227 ```
228
229 in `test/recipes/80-test_ssl_new.t` and run
230
231 ```
232 $ make TESTS=test_ssl_new test
233 ```
234
235 This will save the generated output in a `*.tmp` file in the build directory.
236
237 3. Update the number of tests planned in `test/recipes/80-test_ssl_new.t`. If
238    the test suite has any skip conditions, update those too (see
239    `test/recipes/80-test_ssl_new.t` for details).
240
241 ## Running the tests with the test harness
242
243 ```
244 HARNESS_VERBOSE=yes make TESTS=test_ssl_new test
245 ```
246
247 ## Running a test manually
248
249 These steps are only needed during development. End users should run `make test`
250 or follow the instructions above to run the SSL test suite.
251
252 To run an SSL test manually from the command line, the `TEST_CERTS_DIR`
253 environment variable to point to the location of the certs. E.g., from the root
254 OpenSSL directory, do
255
256 ```
257 $ CTLOG_FILE=test/ct/log_list.conf TEST_CERTS_DIR=test/certs test/ssl_test \
258   test/ssl-tests/01-simple.conf
259 ```
260
261 or for shared builds
262
263 ```
264 $ CTLOG_FILE=test/ct/log_list.conf  TEST_CERTS_DIR=test/certs \
265   util/shlib_wrap.sh test/ssl_test test/ssl-tests/01-simple.conf
266 ```
267
268 Note that the test expectations sometimes depend on the Configure settings. For
269 example, the negotiated protocol depends on the set of available (enabled)
270 protocols: a build with `enable-ssl3` has different test expectations than a
271 build with `no-ssl3`.
272
273 The Perl test harness automatically generates expected outputs, so users who
274 just run `make test` do not need any extra steps.
275
276 However, when running a test manually, keep in mind that the repository version
277 of the generated `test/ssl-tests/*.conf` correspond to expected outputs in with
278 the default Configure options. To run `ssl_test` manually from the command line
279 in a build with a different configuration, you may need to generate the right
280 `*.conf` file from the `*.conf.in` input first.