ea90efcfdc21f061ed20c6e34e6c910ebe4007e2
[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. Therefore, whenever you're adding or updating a
14 generated test, you should run
15
16 ```
17 $ ./config
18 $ cd test
19 $ TOP=.. perl -I testlib/ generate_ssl_tests.pl ssl-tests/my.conf.in \
20   > ssl-tests/my.conf
21 ```
22
23 where `my.conf.in` is your test input file.
24
25 For example, to generate the test cases in `ssl-tests/01-simple.conf.in`, do
26
27 ```
28 $ TOP=.. perl generate_ssl_tests.pl ssl-tests/01-simple.conf.in > ssl-tests/01-simple.conf
29 ```
30
31 For more details, see `ssl-tests/01-simple.conf.in` for an example.
32
33 ## Configuring the test
34
35 First, give your test a name. The names do not have to be unique.
36
37 An example test input looks like this:
38
39 ```
40     {
41         name => "test-default",
42         server => { "CipherString" => "DEFAULT" },
43         client => { "CipherString" => "DEFAULT" },
44         test   => { "ExpectedResult" => "Success" },
45     }
46 ```
47
48 The test section supports the following options:
49
50 * ExpectedResult - expected handshake outcome. One of
51   - Success - handshake success
52   - ServerFail - serverside handshake failure
53   - ClientFail - clientside handshake failure
54   - InternalError - some other error
55
56 * ClientAlert, ServerAlert - expected alert. See `ssl_test_ctx.c` for known
57   values.
58
59 * Protocol - expected negotiated protocol. One of
60   SSLv3, TLSv1, TLSv1.1, TLSv1.2.
61
62 * ClientVerifyCallback - the client's custom certificate verify callback.
63   Used to test callback behaviour. One of
64   - None - no custom callback (default)
65   - AcceptAll - accepts all certificates.
66   - RejectAll - rejects all certificates.
67
68 * Method - the method to test. One of DTLS or TLS.
69
70 * ServerName - the server the client should attempt to connect to. One of
71   - None - do not use SNI (default)
72   - server1 - the initial context
73   - server2 - the secondary context
74   - invalid - an unknown context
75
76 * ServerNameCallback - the SNI switching callback to use
77   - None - no callback (default)
78   - IgnoreMismatch - continue the handshake on SNI mismatch
79   - RejectMismatch - abort the handshake on SNI mismatch
80
81 * SessionTicketExpected - whether or not a session ticket is expected
82   - Ignore - do not check for a session ticket (default)
83   - Yes - a session ticket is expected
84   - No - a session ticket is not expected
85   - Broken - a special test case where the session ticket callback does not initialize crypto
86
87 ## Configuring the client and server
88
89 The client and server configurations can be any valid `SSL_CTX`
90 configurations. For details, see the manpages for `SSL_CONF_cmd`.
91
92 Give your configurations as a dictionary of CONF commands, e.g.
93
94 ```
95 server => {
96     "CipherString" => "DEFAULT",
97     "MinProtocol" => "TLSv1",
98 }
99 ```
100
101 A server2 section may optionally be defined to configure a secondary
102 context that is selected via the ServerName test option. If the server2
103 section is not configured, then the configuration matches server.
104
105 ### Default server and client configurations
106
107 The default server certificate and CA files are added to the configurations
108 automatically. Server certificate verification is requested by default.
109
110 You can override these options by redefining them:
111
112 ```
113 client => {
114     "VerifyCAFile" => "/path/to/custom/file"
115 }
116 ```
117
118 or by deleting them
119
120 ```
121 client => {
122     "VerifyCAFile" => undef
123 }
124 ```
125
126 ## Adding a test to the test harness
127
128 Add your configuration file to `test/recipes/80-test_ssl_new.t`.
129
130 ## Running the tests with the test harness
131
132 ```
133 HARNESS_VERBOSE=yes make TESTS=test_ssl_new test
134 ```
135
136 ## Running a test manually
137
138 These steps are only needed during development. End users should run `make test`
139 or follow the instructions above to run the SSL test suite.
140
141 To run an SSL test manually from the command line, the `TEST_CERTS_DIR`
142 environment variable to point to the location of the certs. E.g., from the root
143 OpenSSL directory, do
144
145 ```
146 $ TEST_CERTS_DIR=test/certs test/ssl_test test/ssl-tests/01-simple.conf
147 ```
148
149 or for shared builds
150
151 ```
152 $ TEST_CERTS_DIR=test/certs util/shlib_wrap.sh test/ssl_test \
153   test/ssl-tests/01-simple.conf
154 ```
155
156 Note that the test expectations sometimes depend on the Configure settings. For
157 example, the negotiated protocol depends on the set of available (enabled)
158 protocols: a build with `enable-ssl3` has different test expectations than a
159 build with `no-ssl3`.
160
161 The Perl test harness automatically generates expected outputs, so users who
162 just run `make test` do not need any extra steps.
163
164 However, when running a test manually, keep in mind that the repository version
165 of the generated `test/ssl-tests/*.conf` correspond to expected outputs in with
166 the default Configure options. To run `ssl_test` manually from the command line
167 in a build with a different configuration, you may need to generate the right
168 `*.conf` file from the `*.conf.in` input first.