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