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