blob: c92dff585e5f1dec44fb2116640ccbeb37daa72f [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090065 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080066)
Adam Langley95c29f32014-06-20 12:00:00 -070067
EKRf71d7ed2016-08-06 13:25:12 -070068// ShimConfigurations is used with the “json” package and represents a shim
69// config file.
70type ShimConfiguration struct {
71 // DisabledTests maps from a glob-based pattern to a freeform string.
72 // The glob pattern is used to exclude tests from being run and the
73 // freeform string is unparsed but expected to explain why the test is
74 // disabled.
75 DisabledTests map[string]string
76
77 // ErrorMap maps from expected error strings to the correct error
78 // string for the shim in question. For example, it might map
79 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
80 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
81 ErrorMap map[string]string
82}
83
84var shimConfig ShimConfiguration
85
David Benjamin33863262016-07-08 17:20:12 -070086type testCert int
87
David Benjamin025b3d32014-07-01 19:53:04 -040088const (
David Benjamin33863262016-07-08 17:20:12 -070089 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040090 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090091 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070092 testCertECDSAP256
93 testCertECDSAP384
94 testCertECDSAP521
95)
96
97const (
98 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040099 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900100 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700101 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
102 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
103 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400104)
105
106const (
David Benjamina08e49d2014-08-24 01:46:07 -0400107 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400108 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900109 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700110 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
111 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
112 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400113 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400114)
115
David Benjamin7944a9f2016-07-12 22:27:01 -0400116var (
117 rsaCertificate Certificate
118 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900119 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400120 ecdsaP256Certificate Certificate
121 ecdsaP384Certificate Certificate
122 ecdsaP521Certificate Certificate
123)
David Benjamin33863262016-07-08 17:20:12 -0700124
125var testCerts = []struct {
126 id testCert
127 certFile, keyFile string
128 cert *Certificate
129}{
130 {
131 id: testCertRSA,
132 certFile: rsaCertificateFile,
133 keyFile: rsaKeyFile,
134 cert: &rsaCertificate,
135 },
136 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 id: testCertRSA1024,
138 certFile: rsa1024CertificateFile,
139 keyFile: rsa1024KeyFile,
140 cert: &rsa1024Certificate,
141 },
142 {
David Benjamin2c516452016-11-15 10:16:54 +0900143 id: testCertRSAChain,
144 certFile: rsaChainCertificateFile,
145 keyFile: rsaChainKeyFile,
146 cert: &rsaChainCertificate,
147 },
148 {
David Benjamin33863262016-07-08 17:20:12 -0700149 id: testCertECDSAP256,
150 certFile: ecdsaP256CertificateFile,
151 keyFile: ecdsaP256KeyFile,
152 cert: &ecdsaP256Certificate,
153 },
154 {
155 id: testCertECDSAP384,
156 certFile: ecdsaP384CertificateFile,
157 keyFile: ecdsaP384KeyFile,
158 cert: &ecdsaP384Certificate,
159 },
160 {
161 id: testCertECDSAP521,
162 certFile: ecdsaP521CertificateFile,
163 keyFile: ecdsaP521KeyFile,
164 cert: &ecdsaP521Certificate,
165 },
166}
167
David Benjamina08e49d2014-08-24 01:46:07 -0400168var channelIDKey *ecdsa.PrivateKey
169var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700170
David Benjamin61f95272014-11-25 01:55:35 -0500171var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800172var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500173
Steven Valdeza833c352016-11-01 13:39:36 -0400174var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800175var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400176
Adam Langley95c29f32014-06-20 12:00:00 -0700177func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700178 for i := range testCerts {
179 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
180 if err != nil {
181 panic(err)
182 }
183 cert.OCSPStaple = testOCSPResponse
184 cert.SignedCertificateTimestampList = testSCTList
185 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700186 }
David Benjamina08e49d2014-08-24 01:46:07 -0400187
Adam Langley7c803a62015-06-15 15:35:05 -0700188 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400189 if err != nil {
190 panic(err)
191 }
192 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
193 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
194 panic("bad key type")
195 }
196 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
197 if err != nil {
198 panic(err)
199 }
200 if channelIDKey.Curve != elliptic.P256() {
201 panic("bad curve")
202 }
203
204 channelIDBytes = make([]byte, 64)
205 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
206 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700207}
208
David Benjamin33863262016-07-08 17:20:12 -0700209func getRunnerCertificate(t testCert) Certificate {
210 for _, cert := range testCerts {
211 if cert.id == t {
212 return *cert.cert
213 }
214 }
215 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700216}
217
David Benjamin33863262016-07-08 17:20:12 -0700218func getShimCertificate(t testCert) string {
219 for _, cert := range testCerts {
220 if cert.id == t {
221 return cert.certFile
222 }
223 }
224 panic("Unknown test certificate")
225}
226
227func getShimKey(t testCert) string {
228 for _, cert := range testCerts {
229 if cert.id == t {
230 return cert.keyFile
231 }
232 }
233 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700234}
235
David Benjamin025b3d32014-07-01 19:53:04 -0400236type testType int
237
238const (
239 clientTest testType = iota
240 serverTest
241)
242
David Benjamin6fd297b2014-08-11 18:43:38 -0400243type protocol int
244
245const (
246 tls protocol = iota
247 dtls
248)
249
David Benjaminfc7b0862014-09-06 13:21:53 -0400250const (
251 alpn = 1
252 npn = 2
253)
254
Adam Langley95c29f32014-06-20 12:00:00 -0700255type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400256 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400257 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700258 name string
259 config Config
260 shouldFail bool
261 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700262 // expectedLocalError, if not empty, contains a substring that must be
263 // found in the local error.
264 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400265 // expectedVersion, if non-zero, specifies the TLS version that must be
266 // negotiated.
267 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400268 // expectedResumeVersion, if non-zero, specifies the TLS version that
269 // must be negotiated on resumption. If zero, expectedVersion is used.
270 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400271 // expectedCipher, if non-zero, specifies the TLS cipher suite that
272 // should be negotiated.
273 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400274 // expectChannelID controls whether the connection should have
275 // negotiated a Channel ID with channelIDKey.
276 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400277 // expectedNextProto controls whether the connection should
278 // negotiate a next protocol via NPN or ALPN.
279 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400280 // expectNoNextProto, if true, means that no next protocol should be
281 // negotiated.
282 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400283 // expectedNextProtoType, if non-zero, is the expected next
284 // protocol negotiation mechanism.
285 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500286 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
287 // should be negotiated. If zero, none should be negotiated.
288 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100289 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
290 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100291 // expectedSCTList, if not nil, is the expected SCT list to be received.
292 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700293 // expectedPeerSignatureAlgorithm, if not zero, is the signature
294 // algorithm that the peer should have used in the handshake.
295 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400296 // expectedCurveID, if not zero, is the curve that the handshake should
297 // have used.
298 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700299 // messageLen is the length, in bytes, of the test message that will be
300 // sent.
301 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400302 // messageCount is the number of test messages that will be sent.
303 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400304 // certFile is the path to the certificate to use for the server.
305 certFile string
306 // keyFile is the path to the private key to use for the server.
307 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400308 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400309 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400310 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400311 // resumeRenewedSession controls whether a third connection should be
312 // tested which attempts to resume the second connection's session.
313 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700314 // expectResumeRejected, if true, specifies that the attempted
315 // resumption must be rejected by the client. This is only valid for a
316 // serverTest.
317 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400318 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500319 // resumption. Unless newSessionsOnResume is set,
320 // SessionTicketKey, ServerSessionCache, and
321 // ClientSessionCache are copied from the initial connection's
322 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400323 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500324 // newSessionsOnResume, if true, will cause resumeConfig to
325 // use a different session resumption context.
326 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400327 // noSessionCache, if true, will cause the server to run without a
328 // session cache.
329 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400330 // sendPrefix sends a prefix on the socket before actually performing a
331 // handshake.
332 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400333 // shimWritesFirst controls whether the shim sends an initial "hello"
334 // message before doing a roundtrip with the runner.
335 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400336 // shimShutsDown, if true, runs a test where the shim shuts down the
337 // connection immediately after the handshake rather than echoing
338 // messages from the runner.
339 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400340 // renegotiate indicates the number of times the connection should be
341 // renegotiated during the exchange.
342 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400343 // sendHalfHelloRequest, if true, causes the server to send half a
344 // HelloRequest when the handshake completes.
345 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700346 // renegotiateCiphers is a list of ciphersuite ids that will be
347 // switched in just before renegotiation.
348 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500349 // replayWrites, if true, configures the underlying transport
350 // to replay every write it makes in DTLS tests.
351 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500352 // damageFirstWrite, if true, configures the underlying transport to
353 // damage the final byte of the first application data write.
354 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400355 // exportKeyingMaterial, if non-zero, configures the test to exchange
356 // keying material and verify they match.
357 exportKeyingMaterial int
358 exportLabel string
359 exportContext string
360 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400361 // flags, if not empty, contains a list of command-line flags that will
362 // be passed to the shim program.
363 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700364 // testTLSUnique, if true, causes the shim to send the tls-unique value
365 // which will be compared against the expected value.
366 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400367 // sendEmptyRecords is the number of consecutive empty records to send
368 // before and after the test message.
369 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400370 // sendWarningAlerts is the number of consecutive warning alerts to send
371 // before and after the test message.
372 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400373 // sendKeyUpdates is the number of consecutive key updates to send
374 // before and after the test message.
375 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400376 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
377 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400378 // expectMessageDropped, if true, means the test message is expected to
379 // be dropped by the client rather than echoed back.
380 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900381 // expectPeerCertificate, if not nil, is the certificate chain the peer
382 // is expected to send.
383 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700384}
385
Adam Langley7c803a62015-06-15 15:35:05 -0700386var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700387
David Benjaminc07afb72016-09-22 10:18:58 -0400388func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500389 if len(data) == 0 {
390 return
391 }
392
393 protocol := "tls"
394 if test.protocol == dtls {
395 protocol = "dtls"
396 }
397
398 side := "client"
399 if test.testType == serverTest {
400 side = "server"
401 }
402
403 dir := path.Join(*transcriptDir, protocol, side)
404 if err := os.MkdirAll(dir, 0755); err != nil {
405 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
406 return
407 }
408
David Benjaminc07afb72016-09-22 10:18:58 -0400409 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500410 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
411 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
412 }
413}
414
David Benjamin3ed59772016-03-08 12:50:21 -0500415// A timeoutConn implements an idle timeout on each Read and Write operation.
416type timeoutConn struct {
417 net.Conn
418 timeout time.Duration
419}
420
421func (t *timeoutConn) Read(b []byte) (int, error) {
422 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
423 return 0, err
424 }
425 return t.Conn.Read(b)
426}
427
428func (t *timeoutConn) Write(b []byte) (int, error) {
429 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
430 return 0, err
431 }
432 return t.Conn.Write(b)
433}
434
David Benjaminc07afb72016-09-22 10:18:58 -0400435func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400436 if !test.noSessionCache {
437 if config.ClientSessionCache == nil {
438 config.ClientSessionCache = NewLRUClientSessionCache(1)
439 }
440 if config.ServerSessionCache == nil {
441 config.ServerSessionCache = NewLRUServerSessionCache(1)
442 }
443 }
444 if test.testType == clientTest {
445 if len(config.Certificates) == 0 {
446 config.Certificates = []Certificate{rsaCertificate}
447 }
448 } else {
449 // Supply a ServerName to ensure a constant session cache key,
450 // rather than falling back to net.Conn.RemoteAddr.
451 if len(config.ServerName) == 0 {
452 config.ServerName = "test"
453 }
454 }
455 if *fuzzer {
456 config.Bugs.NullAllCiphers = true
457 }
David Benjamin01a90572016-09-22 00:11:43 -0400458 if *deterministic {
459 config.Time = func() time.Time { return time.Unix(1234, 1234) }
460 }
David Benjamine54af062016-08-08 19:21:18 -0400461
David Benjamin01784b42016-06-07 18:00:52 -0400462 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500463
David Benjamin6fd297b2014-08-11 18:43:38 -0400464 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500465 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
466 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500467 }
468
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500470 local, peer := "client", "server"
471 if test.testType == clientTest {
472 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500473 }
David Benjaminebda9b32015-11-02 15:33:18 -0500474 connDebug := &recordingConn{
475 Conn: conn,
476 isDatagram: test.protocol == dtls,
477 local: local,
478 peer: peer,
479 }
480 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 if *flagDebug {
482 defer connDebug.WriteTo(os.Stdout)
483 }
484 if len(*transcriptDir) != 0 {
485 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400486 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500487 }()
488 }
David Benjaminebda9b32015-11-02 15:33:18 -0500489
490 if config.Bugs.PacketAdaptor != nil {
491 config.Bugs.PacketAdaptor.debug = connDebug
492 }
493 }
494
495 if test.replayWrites {
496 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400497 }
498
David Benjamin3ed59772016-03-08 12:50:21 -0500499 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500500 if test.damageFirstWrite {
501 connDamage = newDamageAdaptor(conn)
502 conn = connDamage
503 }
504
David Benjamin6fd297b2014-08-11 18:43:38 -0400505 if test.sendPrefix != "" {
506 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
507 return err
508 }
David Benjamin98e882e2014-08-08 13:24:34 -0400509 }
510
David Benjamin1d5c83e2014-07-22 19:20:02 -0400511 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400512 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400513 if test.protocol == dtls {
514 tlsConn = DTLSServer(conn, config)
515 } else {
516 tlsConn = Server(conn, config)
517 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400518 } else {
519 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400520 if test.protocol == dtls {
521 tlsConn = DTLSClient(conn, config)
522 } else {
523 tlsConn = Client(conn, config)
524 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400525 }
David Benjamin30789da2015-08-29 22:56:45 -0400526 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400527
Adam Langley95c29f32014-06-20 12:00:00 -0700528 if err := tlsConn.Handshake(); err != nil {
529 return err
530 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700531
David Benjamin01fe8202014-09-24 15:21:44 -0400532 // TODO(davidben): move all per-connection expectations into a dedicated
533 // expectations struct that can be specified separately for the two
534 // legs.
535 expectedVersion := test.expectedVersion
536 if isResume && test.expectedResumeVersion != 0 {
537 expectedVersion = test.expectedResumeVersion
538 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700539 connState := tlsConn.ConnectionState()
540 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400541 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400542 }
543
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700544 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400545 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
546 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700547 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
548 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
549 }
David Benjamin90da8c82015-04-20 14:57:57 -0400550
David Benjamina08e49d2014-08-24 01:46:07 -0400551 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700552 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400553 if channelID == nil {
554 return fmt.Errorf("no channel ID negotiated")
555 }
556 if channelID.Curve != channelIDKey.Curve ||
557 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
558 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
559 return fmt.Errorf("incorrect channel ID")
560 }
561 }
562
David Benjaminae2888f2014-09-06 12:58:58 -0400563 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400565 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
566 }
567 }
568
David Benjaminc7ce9772015-10-09 19:32:41 -0400569 if test.expectNoNextProto {
570 if actual := connState.NegotiatedProtocol; actual != "" {
571 return fmt.Errorf("got unexpected next proto %s", actual)
572 }
573 }
574
David Benjaminfc7b0862014-09-06 13:21:53 -0400575 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700576 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400577 return fmt.Errorf("next proto type mismatch")
578 }
579 }
580
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700581 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500582 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
583 }
584
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100585 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300586 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100587 }
588
Paul Lietar4fac72e2015-09-09 13:44:55 +0100589 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
590 return fmt.Errorf("SCT list mismatch")
591 }
592
Nick Harper60edffd2016-06-21 15:19:24 -0700593 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
594 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400595 }
596
Steven Valdez5440fe02016-07-18 12:40:30 -0400597 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
598 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
599 }
600
David Benjamin2c516452016-11-15 10:16:54 +0900601 if test.expectPeerCertificate != nil {
602 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
603 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
604 }
605 for i, cert := range connState.PeerCertificates {
606 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
607 return fmt.Errorf("peer certificate %d did not match", i+1)
608 }
609 }
610 }
611
David Benjaminc565ebb2015-04-03 04:06:36 -0400612 if test.exportKeyingMaterial > 0 {
613 actual := make([]byte, test.exportKeyingMaterial)
614 if _, err := io.ReadFull(tlsConn, actual); err != nil {
615 return err
616 }
617 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
618 if err != nil {
619 return err
620 }
621 if !bytes.Equal(actual, expected) {
622 return fmt.Errorf("keying material mismatch")
623 }
624 }
625
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700626 if test.testTLSUnique {
627 var peersValue [12]byte
628 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
629 return err
630 }
631 expected := tlsConn.ConnectionState().TLSUnique
632 if !bytes.Equal(peersValue[:], expected) {
633 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
634 }
635 }
636
David Benjamine58c4f52014-08-24 03:47:07 -0400637 if test.shimWritesFirst {
638 var buf [5]byte
639 _, err := io.ReadFull(tlsConn, buf[:])
640 if err != nil {
641 return err
642 }
643 if string(buf[:]) != "hello" {
644 return fmt.Errorf("bad initial message")
645 }
646 }
647
Steven Valdez32635b82016-08-16 11:25:03 -0400648 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400649 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400650 return err
651 }
Steven Valdez32635b82016-08-16 11:25:03 -0400652 }
653
David Benjamina8ebe222015-06-06 03:04:39 -0400654 for i := 0; i < test.sendEmptyRecords; i++ {
655 tlsConn.Write(nil)
656 }
657
David Benjamin24f346d2015-06-06 03:28:08 -0400658 for i := 0; i < test.sendWarningAlerts; i++ {
659 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
660 }
661
David Benjamin47921102016-07-28 11:29:18 -0400662 if test.sendHalfHelloRequest {
663 tlsConn.SendHalfHelloRequest()
664 }
665
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400666 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700667 if test.renegotiateCiphers != nil {
668 config.CipherSuites = test.renegotiateCiphers
669 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400670 for i := 0; i < test.renegotiate; i++ {
671 if err := tlsConn.Renegotiate(); err != nil {
672 return err
673 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700674 }
675 } else if test.renegotiateCiphers != nil {
676 panic("renegotiateCiphers without renegotiate")
677 }
678
David Benjamin5fa3eba2015-01-22 16:35:40 -0500679 if test.damageFirstWrite {
680 connDamage.setDamage(true)
681 tlsConn.Write([]byte("DAMAGED WRITE"))
682 connDamage.setDamage(false)
683 }
684
David Benjamin8e6db492015-07-25 18:29:23 -0400685 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700686 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400687 if test.protocol == dtls {
688 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
689 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700690 // Read until EOF.
691 _, err := io.Copy(ioutil.Discard, tlsConn)
692 return err
693 }
David Benjamin4417d052015-04-05 04:17:25 -0400694 if messageLen == 0 {
695 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700696 }
Adam Langley95c29f32014-06-20 12:00:00 -0700697
David Benjamin8e6db492015-07-25 18:29:23 -0400698 messageCount := test.messageCount
699 if messageCount == 0 {
700 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400701 }
702
David Benjamin8e6db492015-07-25 18:29:23 -0400703 for j := 0; j < messageCount; j++ {
704 testMessage := make([]byte, messageLen)
705 for i := range testMessage {
706 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400707 }
David Benjamin8e6db492015-07-25 18:29:23 -0400708 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700709
Steven Valdez32635b82016-08-16 11:25:03 -0400710 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400711 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400712 }
713
David Benjamin8e6db492015-07-25 18:29:23 -0400714 for i := 0; i < test.sendEmptyRecords; i++ {
715 tlsConn.Write(nil)
716 }
717
718 for i := 0; i < test.sendWarningAlerts; i++ {
719 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
720 }
721
David Benjamin4f75aaf2015-09-01 16:53:10 -0400722 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400723 // The shim will not respond.
724 continue
725 }
726
David Benjamin8e6db492015-07-25 18:29:23 -0400727 buf := make([]byte, len(testMessage))
728 if test.protocol == dtls {
729 bufTmp := make([]byte, len(buf)+1)
730 n, err := tlsConn.Read(bufTmp)
731 if err != nil {
732 return err
733 }
734 if n != len(buf) {
735 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
736 }
737 copy(buf, bufTmp)
738 } else {
739 _, err := io.ReadFull(tlsConn, buf)
740 if err != nil {
741 return err
742 }
743 }
744
745 for i, v := range buf {
746 if v != testMessage[i]^0xff {
747 return fmt.Errorf("bad reply contents at byte %d", i)
748 }
Adam Langley95c29f32014-06-20 12:00:00 -0700749 }
750 }
751
752 return nil
753}
754
David Benjamin325b5c32014-07-01 19:40:31 -0400755func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400756 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700757 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400758 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700759 }
David Benjamin325b5c32014-07-01 19:40:31 -0400760 valgrindArgs = append(valgrindArgs, path)
761 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700762
David Benjamin325b5c32014-07-01 19:40:31 -0400763 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700764}
765
David Benjamin325b5c32014-07-01 19:40:31 -0400766func gdbOf(path string, args ...string) *exec.Cmd {
767 xtermArgs := []string{"-e", "gdb", "--args"}
768 xtermArgs = append(xtermArgs, path)
769 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700770
David Benjamin325b5c32014-07-01 19:40:31 -0400771 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700772}
773
David Benjamind16bf342015-12-18 00:53:12 -0500774func lldbOf(path string, args ...string) *exec.Cmd {
775 xtermArgs := []string{"-e", "lldb", "--"}
776 xtermArgs = append(xtermArgs, path)
777 xtermArgs = append(xtermArgs, args...)
778
779 return exec.Command("xterm", xtermArgs...)
780}
781
EKR842ae6c2016-07-27 09:22:05 +0200782var (
783 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
784 errUnimplemented = errors.New("child process does not implement needed flags")
785)
Adam Langley69a01602014-11-17 17:26:55 -0800786
David Benjamin87c8a642015-02-21 01:54:29 -0500787// accept accepts a connection from listener, unless waitChan signals a process
788// exit first.
789func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
790 type connOrError struct {
791 conn net.Conn
792 err error
793 }
794 connChan := make(chan connOrError, 1)
795 go func() {
796 conn, err := listener.Accept()
797 connChan <- connOrError{conn, err}
798 close(connChan)
799 }()
800 select {
801 case result := <-connChan:
802 return result.conn, result.err
803 case childErr := <-waitChan:
804 waitChan <- childErr
805 return nil, fmt.Errorf("child exited early: %s", childErr)
806 }
807}
808
EKRf71d7ed2016-08-06 13:25:12 -0700809func translateExpectedError(errorStr string) string {
810 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
811 return translated
812 }
813
814 if *looseErrors {
815 return ""
816 }
817
818 return errorStr
819}
820
Adam Langley7c803a62015-06-15 15:35:05 -0700821func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400822 // Help debugging panics on the Go side.
823 defer func() {
824 if r := recover(); r != nil {
825 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
826 panic(r)
827 }
828 }()
829
Adam Langley38311732014-10-16 19:04:35 -0700830 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
831 panic("Error expected without shouldFail in " + test.name)
832 }
833
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700834 if test.expectResumeRejected && !test.resumeSession {
835 panic("expectResumeRejected without resumeSession in " + test.name)
836 }
837
Adam Langley33b1d4f2016-12-07 15:03:45 -0800838 for _, ver := range tlsVersions {
839 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
840 continue
841 }
842
843 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
844 continue
845 }
846
847 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
848 }
849
David Benjamin87c8a642015-02-21 01:54:29 -0500850 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
851 if err != nil {
852 panic(err)
853 }
854 defer func() {
855 if listener != nil {
856 listener.Close()
857 }
858 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700859
David Benjamin87c8a642015-02-21 01:54:29 -0500860 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400861 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400862 flags = append(flags, "-server")
863
David Benjamin025b3d32014-07-01 19:53:04 -0400864 flags = append(flags, "-key-file")
865 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700866 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400867 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700868 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400869 }
870
871 flags = append(flags, "-cert-file")
872 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400874 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700875 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400876 }
877 }
David Benjamin5a593af2014-08-11 19:51:50 -0400878
David Benjamin6fd297b2014-08-11 18:43:38 -0400879 if test.protocol == dtls {
880 flags = append(flags, "-dtls")
881 }
882
David Benjamin46662482016-08-17 00:51:00 -0400883 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400884 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400885 resumeCount++
886 if test.resumeRenewedSession {
887 resumeCount++
888 }
889 }
890
891 if resumeCount > 0 {
892 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400893 }
894
David Benjamine58c4f52014-08-24 03:47:07 -0400895 if test.shimWritesFirst {
896 flags = append(flags, "-shim-writes-first")
897 }
898
David Benjamin30789da2015-08-29 22:56:45 -0400899 if test.shimShutsDown {
900 flags = append(flags, "-shim-shuts-down")
901 }
902
David Benjaminc565ebb2015-04-03 04:06:36 -0400903 if test.exportKeyingMaterial > 0 {
904 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
905 flags = append(flags, "-export-label", test.exportLabel)
906 flags = append(flags, "-export-context", test.exportContext)
907 if test.useExportContext {
908 flags = append(flags, "-use-export-context")
909 }
910 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700911 if test.expectResumeRejected {
912 flags = append(flags, "-expect-session-miss")
913 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400914
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700915 if test.testTLSUnique {
916 flags = append(flags, "-tls-unique")
917 }
918
David Benjamin025b3d32014-07-01 19:53:04 -0400919 flags = append(flags, test.flags...)
920
921 var shim *exec.Cmd
922 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700923 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700924 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700925 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500926 } else if *useLLDB {
927 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400928 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700929 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400930 }
David Benjamin025b3d32014-07-01 19:53:04 -0400931 shim.Stdin = os.Stdin
932 var stdoutBuf, stderrBuf bytes.Buffer
933 shim.Stdout = &stdoutBuf
934 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800935 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500936 shim.Env = os.Environ()
937 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800938 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400939 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800940 }
941 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
942 }
David Benjamin025b3d32014-07-01 19:53:04 -0400943
944 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700945 panic(err)
946 }
David Benjamin87c8a642015-02-21 01:54:29 -0500947 waitChan := make(chan error, 1)
948 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700949
950 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700951
David Benjamin7a4aaa42016-09-20 17:58:14 -0400952 if *deterministic {
953 config.Rand = &deterministicRand{}
954 }
955
David Benjamin87c8a642015-02-21 01:54:29 -0500956 conn, err := acceptOrWait(listener, waitChan)
957 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400958 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500959 conn.Close()
960 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500961
David Benjamin46662482016-08-17 00:51:00 -0400962 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400963 var resumeConfig Config
964 if test.resumeConfig != nil {
965 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400966 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500967 resumeConfig.SessionTicketKey = config.SessionTicketKey
968 resumeConfig.ClientSessionCache = config.ClientSessionCache
969 resumeConfig.ServerSessionCache = config.ServerSessionCache
970 }
David Benjamin2e045a92016-06-08 13:09:56 -0400971 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400972 } else {
973 resumeConfig = config
974 }
David Benjamin87c8a642015-02-21 01:54:29 -0500975 var connResume net.Conn
976 connResume, err = acceptOrWait(listener, waitChan)
977 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400978 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500979 connResume.Close()
980 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400981 }
982
David Benjamin87c8a642015-02-21 01:54:29 -0500983 // Close the listener now. This is to avoid hangs should the shim try to
984 // open more connections than expected.
985 listener.Close()
986 listener = nil
987
988 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400989 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800990 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200991 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
992 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800993 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200994 case 89:
995 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400996 case 99:
997 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800998 }
999 }
Adam Langley95c29f32014-06-20 12:00:00 -07001000
David Benjamin9bea3492016-03-02 10:59:16 -05001001 // Account for Windows line endings.
1002 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1003 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001004
1005 // Separate the errors from the shim and those from tools like
1006 // AddressSanitizer.
1007 var extraStderr string
1008 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1009 stderr = stderrParts[0]
1010 extraStderr = stderrParts[1]
1011 }
1012
Adam Langley95c29f32014-06-20 12:00:00 -07001013 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001014 expectedError := translateExpectedError(test.expectedError)
1015 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001016
Adam Langleyac61fa32014-06-23 12:03:11 -07001017 localError := "none"
1018 if err != nil {
1019 localError = err.Error()
1020 }
1021 if len(test.expectedLocalError) != 0 {
1022 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1023 }
Adam Langley95c29f32014-06-20 12:00:00 -07001024
1025 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001026 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001027 if childErr != nil {
1028 childError = childErr.Error()
1029 }
1030
1031 var msg string
1032 switch {
1033 case failed && !test.shouldFail:
1034 msg = "unexpected failure"
1035 case !failed && test.shouldFail:
1036 msg = "unexpected success"
1037 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001038 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001039 default:
1040 panic("internal error")
1041 }
1042
David Benjamin9aafb642016-09-20 19:36:53 -04001043 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001044 }
1045
David Benjamind2ba8892016-09-20 19:41:04 -04001046 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001047 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001048 }
1049
David Benjamind2ba8892016-09-20 19:41:04 -04001050 if *useValgrind && isValgrindError {
1051 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1052 }
1053
Adam Langley95c29f32014-06-20 12:00:00 -07001054 return nil
1055}
1056
1057var tlsVersions = []struct {
1058 name string
1059 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001060 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001061 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001062}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001063 {"SSL3", VersionSSL30, "-no-ssl3", false},
1064 {"TLS1", VersionTLS10, "-no-tls1", true},
1065 {"TLS11", VersionTLS11, "-no-tls11", false},
1066 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001067 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001068}
1069
1070var testCipherSuites = []struct {
1071 name string
1072 id uint16
1073}{
1074 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001075 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001076 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001077 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001078 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001079 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001080 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001081 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1082 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001083 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001084 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1085 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001086 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001087 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1088 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001089 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1090 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001091 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001092 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001093 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001094 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001095 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001096 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001097 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001098 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001099 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001100 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001101 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001102 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001103 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1104 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1105 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1106 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001107 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1108 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001109 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1110 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001111 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001112 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1113 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1114 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001115 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001116}
1117
David Benjamin8b8c0062014-11-23 02:47:52 -05001118func hasComponent(suiteName, component string) bool {
1119 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1120}
1121
David Benjaminf7768e42014-08-31 02:06:47 -04001122func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001123 return hasComponent(suiteName, "GCM") ||
1124 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001125 hasComponent(suiteName, "SHA384") ||
1126 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001127}
1128
Nick Harper1fd39d82016-06-14 18:14:35 -07001129func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001130 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001131}
1132
David Benjamin8b8c0062014-11-23 02:47:52 -05001133func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001134 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001135}
1136
Adam Langleya7997f12015-05-14 17:38:50 -07001137func bigFromHex(hex string) *big.Int {
1138 ret, ok := new(big.Int).SetString(hex, 16)
1139 if !ok {
1140 panic("failed to parse hex number 0x" + hex)
1141 }
1142 return ret
1143}
1144
Adam Langley7c803a62015-06-15 15:35:05 -07001145func addBasicTests() {
1146 basicTests := []testCase{
1147 {
Adam Langley7c803a62015-06-15 15:35:05 -07001148 name: "NoFallbackSCSV",
1149 config: Config{
1150 Bugs: ProtocolBugs{
1151 FailIfNotFallbackSCSV: true,
1152 },
1153 },
1154 shouldFail: true,
1155 expectedLocalError: "no fallback SCSV found",
1156 },
1157 {
1158 name: "SendFallbackSCSV",
1159 config: Config{
1160 Bugs: ProtocolBugs{
1161 FailIfNotFallbackSCSV: true,
1162 },
1163 },
1164 flags: []string{"-fallback-scsv"},
1165 },
1166 {
1167 name: "ClientCertificateTypes",
1168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001169 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001170 ClientAuth: RequestClientCert,
1171 ClientCertificateTypes: []byte{
1172 CertTypeDSSSign,
1173 CertTypeRSASign,
1174 CertTypeECDSASign,
1175 },
1176 },
1177 flags: []string{
1178 "-expect-certificate-types",
1179 base64.StdEncoding.EncodeToString([]byte{
1180 CertTypeDSSSign,
1181 CertTypeRSASign,
1182 CertTypeECDSASign,
1183 }),
1184 },
1185 },
1186 {
Adam Langley7c803a62015-06-15 15:35:05 -07001187 name: "UnauthenticatedECDH",
1188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001189 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001190 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1191 Bugs: ProtocolBugs{
1192 UnauthenticatedECDH: true,
1193 },
1194 },
1195 shouldFail: true,
1196 expectedError: ":UNEXPECTED_MESSAGE:",
1197 },
1198 {
1199 name: "SkipCertificateStatus",
1200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001201 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001202 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1203 Bugs: ProtocolBugs{
1204 SkipCertificateStatus: true,
1205 },
1206 },
1207 flags: []string{
1208 "-enable-ocsp-stapling",
1209 },
1210 },
1211 {
1212 name: "SkipServerKeyExchange",
1213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001214 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001215 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1216 Bugs: ProtocolBugs{
1217 SkipServerKeyExchange: true,
1218 },
1219 },
1220 shouldFail: true,
1221 expectedError: ":UNEXPECTED_MESSAGE:",
1222 },
1223 {
Adam Langley7c803a62015-06-15 15:35:05 -07001224 testType: serverTest,
1225 name: "Alert",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 SendSpuriousAlert: alertRecordOverflow,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1233 },
1234 {
1235 protocol: dtls,
1236 testType: serverTest,
1237 name: "Alert-DTLS",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 SendSpuriousAlert: alertRecordOverflow,
1241 },
1242 },
1243 shouldFail: true,
1244 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1245 },
1246 {
1247 testType: serverTest,
1248 name: "FragmentAlert",
1249 config: Config{
1250 Bugs: ProtocolBugs{
1251 FragmentAlert: true,
1252 SendSpuriousAlert: alertRecordOverflow,
1253 },
1254 },
1255 shouldFail: true,
1256 expectedError: ":BAD_ALERT:",
1257 },
1258 {
1259 protocol: dtls,
1260 testType: serverTest,
1261 name: "FragmentAlert-DTLS",
1262 config: Config{
1263 Bugs: ProtocolBugs{
1264 FragmentAlert: true,
1265 SendSpuriousAlert: alertRecordOverflow,
1266 },
1267 },
1268 shouldFail: true,
1269 expectedError: ":BAD_ALERT:",
1270 },
1271 {
1272 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001273 name: "DoubleAlert",
1274 config: Config{
1275 Bugs: ProtocolBugs{
1276 DoubleAlert: true,
1277 SendSpuriousAlert: alertRecordOverflow,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":BAD_ALERT:",
1282 },
1283 {
1284 protocol: dtls,
1285 testType: serverTest,
1286 name: "DoubleAlert-DTLS",
1287 config: Config{
1288 Bugs: ProtocolBugs{
1289 DoubleAlert: true,
1290 SendSpuriousAlert: alertRecordOverflow,
1291 },
1292 },
1293 shouldFail: true,
1294 expectedError: ":BAD_ALERT:",
1295 },
1296 {
Adam Langley7c803a62015-06-15 15:35:05 -07001297 name: "SkipNewSessionTicket",
1298 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001299 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001300 Bugs: ProtocolBugs{
1301 SkipNewSessionTicket: true,
1302 },
1303 },
1304 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001305 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001306 },
1307 {
1308 testType: serverTest,
1309 name: "FallbackSCSV",
1310 config: Config{
1311 MaxVersion: VersionTLS11,
1312 Bugs: ProtocolBugs{
1313 SendFallbackSCSV: true,
1314 },
1315 },
1316 shouldFail: true,
1317 expectedError: ":INAPPROPRIATE_FALLBACK:",
1318 },
1319 {
1320 testType: serverTest,
1321 name: "FallbackSCSV-VersionMatch",
1322 config: Config{
1323 Bugs: ProtocolBugs{
1324 SendFallbackSCSV: true,
1325 },
1326 },
1327 },
1328 {
1329 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001330 name: "FallbackSCSV-VersionMatch-TLS12",
1331 config: Config{
1332 MaxVersion: VersionTLS12,
1333 Bugs: ProtocolBugs{
1334 SendFallbackSCSV: true,
1335 },
1336 },
1337 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1338 },
1339 {
1340 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001341 name: "FragmentedClientVersion",
1342 config: Config{
1343 Bugs: ProtocolBugs{
1344 MaxHandshakeRecordLength: 1,
1345 FragmentClientVersion: true,
1346 },
1347 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001348 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001349 },
1350 {
Adam Langley7c803a62015-06-15 15:35:05 -07001351 testType: serverTest,
1352 name: "HttpGET",
1353 sendPrefix: "GET / HTTP/1.0\n",
1354 shouldFail: true,
1355 expectedError: ":HTTP_REQUEST:",
1356 },
1357 {
1358 testType: serverTest,
1359 name: "HttpPOST",
1360 sendPrefix: "POST / HTTP/1.0\n",
1361 shouldFail: true,
1362 expectedError: ":HTTP_REQUEST:",
1363 },
1364 {
1365 testType: serverTest,
1366 name: "HttpHEAD",
1367 sendPrefix: "HEAD / HTTP/1.0\n",
1368 shouldFail: true,
1369 expectedError: ":HTTP_REQUEST:",
1370 },
1371 {
1372 testType: serverTest,
1373 name: "HttpPUT",
1374 sendPrefix: "PUT / HTTP/1.0\n",
1375 shouldFail: true,
1376 expectedError: ":HTTP_REQUEST:",
1377 },
1378 {
1379 testType: serverTest,
1380 name: "HttpCONNECT",
1381 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1382 shouldFail: true,
1383 expectedError: ":HTTPS_PROXY_REQUEST:",
1384 },
1385 {
1386 testType: serverTest,
1387 name: "Garbage",
1388 sendPrefix: "blah",
1389 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001390 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001391 },
1392 {
Adam Langley7c803a62015-06-15 15:35:05 -07001393 name: "RSAEphemeralKey",
1394 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001395 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001396 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1397 Bugs: ProtocolBugs{
1398 RSAEphemeralKey: true,
1399 },
1400 },
1401 shouldFail: true,
1402 expectedError: ":UNEXPECTED_MESSAGE:",
1403 },
1404 {
1405 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001406 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001407 shouldFail: true,
1408 expectedError: ":WRONG_SSL_VERSION:",
1409 },
1410 {
1411 protocol: dtls,
1412 name: "DisableEverything-DTLS",
1413 flags: []string{"-no-tls12", "-no-tls1"},
1414 shouldFail: true,
1415 expectedError: ":WRONG_SSL_VERSION:",
1416 },
1417 {
Adam Langley7c803a62015-06-15 15:35:05 -07001418 protocol: dtls,
1419 testType: serverTest,
1420 name: "MTU",
1421 config: Config{
1422 Bugs: ProtocolBugs{
1423 MaxPacketLength: 256,
1424 },
1425 },
1426 flags: []string{"-mtu", "256"},
1427 },
1428 {
1429 protocol: dtls,
1430 testType: serverTest,
1431 name: "MTUExceeded",
1432 config: Config{
1433 Bugs: ProtocolBugs{
1434 MaxPacketLength: 255,
1435 },
1436 },
1437 flags: []string{"-mtu", "256"},
1438 shouldFail: true,
1439 expectedLocalError: "dtls: exceeded maximum packet length",
1440 },
1441 {
1442 name: "CertMismatchRSA",
1443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001444 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001445 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001446 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001447 Bugs: ProtocolBugs{
1448 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1449 },
1450 },
1451 shouldFail: true,
1452 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1453 },
1454 {
1455 name: "CertMismatchECDSA",
1456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001457 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001458 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001459 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001460 Bugs: ProtocolBugs{
1461 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1462 },
1463 },
1464 shouldFail: true,
1465 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1466 },
1467 {
1468 name: "EmptyCertificateList",
1469 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001470 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001471 Bugs: ProtocolBugs{
1472 EmptyCertificateList: true,
1473 },
1474 },
1475 shouldFail: true,
1476 expectedError: ":DECODE_ERROR:",
1477 },
1478 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001479 name: "EmptyCertificateList-TLS13",
1480 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001481 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001482 Bugs: ProtocolBugs{
1483 EmptyCertificateList: true,
1484 },
1485 },
1486 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001487 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001488 },
1489 {
Adam Langley7c803a62015-06-15 15:35:05 -07001490 name: "TLSFatalBadPackets",
1491 damageFirstWrite: true,
1492 shouldFail: true,
1493 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1494 },
1495 {
1496 protocol: dtls,
1497 name: "DTLSIgnoreBadPackets",
1498 damageFirstWrite: true,
1499 },
1500 {
1501 protocol: dtls,
1502 name: "DTLSIgnoreBadPackets-Async",
1503 damageFirstWrite: true,
1504 flags: []string{"-async"},
1505 },
1506 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001507 name: "AppDataBeforeHandshake",
1508 config: Config{
1509 Bugs: ProtocolBugs{
1510 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1511 },
1512 },
1513 shouldFail: true,
1514 expectedError: ":UNEXPECTED_RECORD:",
1515 },
1516 {
1517 name: "AppDataBeforeHandshake-Empty",
1518 config: Config{
1519 Bugs: ProtocolBugs{
1520 AppDataBeforeHandshake: []byte{},
1521 },
1522 },
1523 shouldFail: true,
1524 expectedError: ":UNEXPECTED_RECORD:",
1525 },
1526 {
1527 protocol: dtls,
1528 name: "AppDataBeforeHandshake-DTLS",
1529 config: Config{
1530 Bugs: ProtocolBugs{
1531 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1532 },
1533 },
1534 shouldFail: true,
1535 expectedError: ":UNEXPECTED_RECORD:",
1536 },
1537 {
1538 protocol: dtls,
1539 name: "AppDataBeforeHandshake-DTLS-Empty",
1540 config: Config{
1541 Bugs: ProtocolBugs{
1542 AppDataBeforeHandshake: []byte{},
1543 },
1544 },
1545 shouldFail: true,
1546 expectedError: ":UNEXPECTED_RECORD:",
1547 },
1548 {
Adam Langley7c803a62015-06-15 15:35:05 -07001549 name: "AppDataAfterChangeCipherSpec",
1550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001551 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001552 Bugs: ProtocolBugs{
1553 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1554 },
1555 },
1556 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001557 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001558 },
1559 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001560 name: "AppDataAfterChangeCipherSpec-Empty",
1561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001562 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001563 Bugs: ProtocolBugs{
1564 AppDataAfterChangeCipherSpec: []byte{},
1565 },
1566 },
1567 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001568 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001569 },
1570 {
Adam Langley7c803a62015-06-15 15:35:05 -07001571 protocol: dtls,
1572 name: "AppDataAfterChangeCipherSpec-DTLS",
1573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001575 Bugs: ProtocolBugs{
1576 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1577 },
1578 },
1579 // BoringSSL's DTLS implementation will drop the out-of-order
1580 // application data.
1581 },
1582 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001583 protocol: dtls,
1584 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001586 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001587 Bugs: ProtocolBugs{
1588 AppDataAfterChangeCipherSpec: []byte{},
1589 },
1590 },
1591 // BoringSSL's DTLS implementation will drop the out-of-order
1592 // application data.
1593 },
1594 {
Adam Langley7c803a62015-06-15 15:35:05 -07001595 name: "AlertAfterChangeCipherSpec",
1596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001597 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001598 Bugs: ProtocolBugs{
1599 AlertAfterChangeCipherSpec: alertRecordOverflow,
1600 },
1601 },
1602 shouldFail: true,
1603 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1604 },
1605 {
1606 protocol: dtls,
1607 name: "AlertAfterChangeCipherSpec-DTLS",
1608 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001609 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001610 Bugs: ProtocolBugs{
1611 AlertAfterChangeCipherSpec: alertRecordOverflow,
1612 },
1613 },
1614 shouldFail: true,
1615 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1616 },
1617 {
1618 protocol: dtls,
1619 name: "ReorderHandshakeFragments-Small-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 ReorderHandshakeFragments: true,
1623 // Small enough that every handshake message is
1624 // fragmented.
1625 MaxHandshakeRecordLength: 2,
1626 },
1627 },
1628 },
1629 {
1630 protocol: dtls,
1631 name: "ReorderHandshakeFragments-Large-DTLS",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 ReorderHandshakeFragments: true,
1635 // Large enough that no handshake message is
1636 // fragmented.
1637 MaxHandshakeRecordLength: 2048,
1638 },
1639 },
1640 },
1641 {
1642 protocol: dtls,
1643 name: "MixCompleteMessageWithFragments-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 ReorderHandshakeFragments: true,
1647 MixCompleteMessageWithFragments: true,
1648 MaxHandshakeRecordLength: 2,
1649 },
1650 },
1651 },
1652 {
1653 name: "SendInvalidRecordType",
1654 config: Config{
1655 Bugs: ProtocolBugs{
1656 SendInvalidRecordType: true,
1657 },
1658 },
1659 shouldFail: true,
1660 expectedError: ":UNEXPECTED_RECORD:",
1661 },
1662 {
1663 protocol: dtls,
1664 name: "SendInvalidRecordType-DTLS",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 SendInvalidRecordType: true,
1668 },
1669 },
1670 shouldFail: true,
1671 expectedError: ":UNEXPECTED_RECORD:",
1672 },
1673 {
1674 name: "FalseStart-SkipServerSecondLeg",
1675 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001676 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001677 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1678 NextProtos: []string{"foo"},
1679 Bugs: ProtocolBugs{
1680 SkipNewSessionTicket: true,
1681 SkipChangeCipherSpec: true,
1682 SkipFinished: true,
1683 ExpectFalseStart: true,
1684 },
1685 },
1686 flags: []string{
1687 "-false-start",
1688 "-handshake-never-done",
1689 "-advertise-alpn", "\x03foo",
1690 },
1691 shimWritesFirst: true,
1692 shouldFail: true,
1693 expectedError: ":UNEXPECTED_RECORD:",
1694 },
1695 {
1696 name: "FalseStart-SkipServerSecondLeg-Implicit",
1697 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001698 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001699 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1700 NextProtos: []string{"foo"},
1701 Bugs: ProtocolBugs{
1702 SkipNewSessionTicket: true,
1703 SkipChangeCipherSpec: true,
1704 SkipFinished: true,
1705 },
1706 },
1707 flags: []string{
1708 "-implicit-handshake",
1709 "-false-start",
1710 "-handshake-never-done",
1711 "-advertise-alpn", "\x03foo",
1712 },
1713 shouldFail: true,
1714 expectedError: ":UNEXPECTED_RECORD:",
1715 },
1716 {
1717 testType: serverTest,
1718 name: "FailEarlyCallback",
1719 flags: []string{"-fail-early-callback"},
1720 shouldFail: true,
1721 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001722 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001723 },
1724 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001725 name: "FailCertCallback-Client-TLS12",
1726 config: Config{
1727 MaxVersion: VersionTLS12,
1728 ClientAuth: RequestClientCert,
1729 },
1730 flags: []string{"-fail-cert-callback"},
1731 shouldFail: true,
1732 expectedError: ":CERT_CB_ERROR:",
1733 expectedLocalError: "remote error: internal error",
1734 },
1735 {
1736 testType: serverTest,
1737 name: "FailCertCallback-Server-TLS12",
1738 config: Config{
1739 MaxVersion: VersionTLS12,
1740 },
1741 flags: []string{"-fail-cert-callback"},
1742 shouldFail: true,
1743 expectedError: ":CERT_CB_ERROR:",
1744 expectedLocalError: "remote error: internal error",
1745 },
1746 {
1747 name: "FailCertCallback-Client-TLS13",
1748 config: Config{
1749 MaxVersion: VersionTLS13,
1750 ClientAuth: RequestClientCert,
1751 },
1752 flags: []string{"-fail-cert-callback"},
1753 shouldFail: true,
1754 expectedError: ":CERT_CB_ERROR:",
1755 expectedLocalError: "remote error: internal error",
1756 },
1757 {
1758 testType: serverTest,
1759 name: "FailCertCallback-Server-TLS13",
1760 config: Config{
1761 MaxVersion: VersionTLS13,
1762 },
1763 flags: []string{"-fail-cert-callback"},
1764 shouldFail: true,
1765 expectedError: ":CERT_CB_ERROR:",
1766 expectedLocalError: "remote error: internal error",
1767 },
1768 {
Adam Langley7c803a62015-06-15 15:35:05 -07001769 protocol: dtls,
1770 name: "FragmentMessageTypeMismatch-DTLS",
1771 config: Config{
1772 Bugs: ProtocolBugs{
1773 MaxHandshakeRecordLength: 2,
1774 FragmentMessageTypeMismatch: true,
1775 },
1776 },
1777 shouldFail: true,
1778 expectedError: ":FRAGMENT_MISMATCH:",
1779 },
1780 {
1781 protocol: dtls,
1782 name: "FragmentMessageLengthMismatch-DTLS",
1783 config: Config{
1784 Bugs: ProtocolBugs{
1785 MaxHandshakeRecordLength: 2,
1786 FragmentMessageLengthMismatch: true,
1787 },
1788 },
1789 shouldFail: true,
1790 expectedError: ":FRAGMENT_MISMATCH:",
1791 },
1792 {
1793 protocol: dtls,
1794 name: "SplitFragments-Header-DTLS",
1795 config: Config{
1796 Bugs: ProtocolBugs{
1797 SplitFragments: 2,
1798 },
1799 },
1800 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001801 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001802 },
1803 {
1804 protocol: dtls,
1805 name: "SplitFragments-Boundary-DTLS",
1806 config: Config{
1807 Bugs: ProtocolBugs{
1808 SplitFragments: dtlsRecordHeaderLen,
1809 },
1810 },
1811 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001812 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001813 },
1814 {
1815 protocol: dtls,
1816 name: "SplitFragments-Body-DTLS",
1817 config: Config{
1818 Bugs: ProtocolBugs{
1819 SplitFragments: dtlsRecordHeaderLen + 1,
1820 },
1821 },
1822 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001823 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001824 },
1825 {
1826 protocol: dtls,
1827 name: "SendEmptyFragments-DTLS",
1828 config: Config{
1829 Bugs: ProtocolBugs{
1830 SendEmptyFragments: true,
1831 },
1832 },
1833 },
1834 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001835 name: "BadFinished-Client",
1836 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001837 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001838 Bugs: ProtocolBugs{
1839 BadFinished: true,
1840 },
1841 },
1842 shouldFail: true,
1843 expectedError: ":DIGEST_CHECK_FAILED:",
1844 },
1845 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001846 name: "BadFinished-Client-TLS13",
1847 config: Config{
1848 MaxVersion: VersionTLS13,
1849 Bugs: ProtocolBugs{
1850 BadFinished: true,
1851 },
1852 },
1853 shouldFail: true,
1854 expectedError: ":DIGEST_CHECK_FAILED:",
1855 },
1856 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001857 testType: serverTest,
1858 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001860 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001861 Bugs: ProtocolBugs{
1862 BadFinished: true,
1863 },
1864 },
1865 shouldFail: true,
1866 expectedError: ":DIGEST_CHECK_FAILED:",
1867 },
1868 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001869 testType: serverTest,
1870 name: "BadFinished-Server-TLS13",
1871 config: Config{
1872 MaxVersion: VersionTLS13,
1873 Bugs: ProtocolBugs{
1874 BadFinished: true,
1875 },
1876 },
1877 shouldFail: true,
1878 expectedError: ":DIGEST_CHECK_FAILED:",
1879 },
1880 {
Adam Langley7c803a62015-06-15 15:35:05 -07001881 name: "FalseStart-BadFinished",
1882 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001883 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001884 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1885 NextProtos: []string{"foo"},
1886 Bugs: ProtocolBugs{
1887 BadFinished: true,
1888 ExpectFalseStart: true,
1889 },
1890 },
1891 flags: []string{
1892 "-false-start",
1893 "-handshake-never-done",
1894 "-advertise-alpn", "\x03foo",
1895 },
1896 shimWritesFirst: true,
1897 shouldFail: true,
1898 expectedError: ":DIGEST_CHECK_FAILED:",
1899 },
1900 {
1901 name: "NoFalseStart-NoALPN",
1902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001903 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1905 Bugs: ProtocolBugs{
1906 ExpectFalseStart: true,
1907 AlertBeforeFalseStartTest: alertAccessDenied,
1908 },
1909 },
1910 flags: []string{
1911 "-false-start",
1912 },
1913 shimWritesFirst: true,
1914 shouldFail: true,
1915 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1916 expectedLocalError: "tls: peer did not false start: EOF",
1917 },
1918 {
1919 name: "NoFalseStart-NoAEAD",
1920 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001921 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001922 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1923 NextProtos: []string{"foo"},
1924 Bugs: ProtocolBugs{
1925 ExpectFalseStart: true,
1926 AlertBeforeFalseStartTest: alertAccessDenied,
1927 },
1928 },
1929 flags: []string{
1930 "-false-start",
1931 "-advertise-alpn", "\x03foo",
1932 },
1933 shimWritesFirst: true,
1934 shouldFail: true,
1935 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1936 expectedLocalError: "tls: peer did not false start: EOF",
1937 },
1938 {
1939 name: "NoFalseStart-RSA",
1940 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001941 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001942 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1943 NextProtos: []string{"foo"},
1944 Bugs: ProtocolBugs{
1945 ExpectFalseStart: true,
1946 AlertBeforeFalseStartTest: alertAccessDenied,
1947 },
1948 },
1949 flags: []string{
1950 "-false-start",
1951 "-advertise-alpn", "\x03foo",
1952 },
1953 shimWritesFirst: true,
1954 shouldFail: true,
1955 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1956 expectedLocalError: "tls: peer did not false start: EOF",
1957 },
1958 {
1959 name: "NoFalseStart-DHE_RSA",
1960 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001961 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001962 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1963 NextProtos: []string{"foo"},
1964 Bugs: ProtocolBugs{
1965 ExpectFalseStart: true,
1966 AlertBeforeFalseStartTest: alertAccessDenied,
1967 },
1968 },
1969 flags: []string{
1970 "-false-start",
1971 "-advertise-alpn", "\x03foo",
1972 },
1973 shimWritesFirst: true,
1974 shouldFail: true,
1975 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1976 expectedLocalError: "tls: peer did not false start: EOF",
1977 },
1978 {
Adam Langley7c803a62015-06-15 15:35:05 -07001979 protocol: dtls,
1980 name: "SendSplitAlert-Sync",
1981 config: Config{
1982 Bugs: ProtocolBugs{
1983 SendSplitAlert: true,
1984 },
1985 },
1986 },
1987 {
1988 protocol: dtls,
1989 name: "SendSplitAlert-Async",
1990 config: Config{
1991 Bugs: ProtocolBugs{
1992 SendSplitAlert: true,
1993 },
1994 },
1995 flags: []string{"-async"},
1996 },
1997 {
1998 protocol: dtls,
1999 name: "PackDTLSHandshake",
2000 config: Config{
2001 Bugs: ProtocolBugs{
2002 MaxHandshakeRecordLength: 2,
2003 PackHandshakeFragments: 20,
2004 PackHandshakeRecords: 200,
2005 },
2006 },
2007 },
2008 {
Adam Langley7c803a62015-06-15 15:35:05 -07002009 name: "SendEmptyRecords-Pass",
2010 sendEmptyRecords: 32,
2011 },
2012 {
2013 name: "SendEmptyRecords",
2014 sendEmptyRecords: 33,
2015 shouldFail: true,
2016 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2017 },
2018 {
2019 name: "SendEmptyRecords-Async",
2020 sendEmptyRecords: 33,
2021 flags: []string{"-async"},
2022 shouldFail: true,
2023 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2024 },
2025 {
David Benjamine8e84b92016-08-03 15:39:47 -04002026 name: "SendWarningAlerts-Pass",
2027 config: Config{
2028 MaxVersion: VersionTLS12,
2029 },
Adam Langley7c803a62015-06-15 15:35:05 -07002030 sendWarningAlerts: 4,
2031 },
2032 {
David Benjamine8e84b92016-08-03 15:39:47 -04002033 protocol: dtls,
2034 name: "SendWarningAlerts-DTLS-Pass",
2035 config: Config{
2036 MaxVersion: VersionTLS12,
2037 },
Adam Langley7c803a62015-06-15 15:35:05 -07002038 sendWarningAlerts: 4,
2039 },
2040 {
David Benjamine8e84b92016-08-03 15:39:47 -04002041 name: "SendWarningAlerts-TLS13",
2042 config: Config{
2043 MaxVersion: VersionTLS13,
2044 },
2045 sendWarningAlerts: 4,
2046 shouldFail: true,
2047 expectedError: ":BAD_ALERT:",
2048 expectedLocalError: "remote error: error decoding message",
2049 },
2050 {
2051 name: "SendWarningAlerts",
2052 config: Config{
2053 MaxVersion: VersionTLS12,
2054 },
Adam Langley7c803a62015-06-15 15:35:05 -07002055 sendWarningAlerts: 5,
2056 shouldFail: true,
2057 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2058 },
2059 {
David Benjamine8e84b92016-08-03 15:39:47 -04002060 name: "SendWarningAlerts-Async",
2061 config: Config{
2062 MaxVersion: VersionTLS12,
2063 },
Adam Langley7c803a62015-06-15 15:35:05 -07002064 sendWarningAlerts: 5,
2065 flags: []string{"-async"},
2066 shouldFail: true,
2067 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2068 },
David Benjaminba4594a2015-06-18 18:36:15 -04002069 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002070 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002071 config: Config{
2072 MaxVersion: VersionTLS13,
2073 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002074 sendKeyUpdates: 33,
2075 keyUpdateRequest: keyUpdateNotRequested,
2076 shouldFail: true,
2077 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002078 },
2079 {
David Benjaminba4594a2015-06-18 18:36:15 -04002080 name: "EmptySessionID",
2081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002082 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002083 SessionTicketsDisabled: true,
2084 },
2085 noSessionCache: true,
2086 flags: []string{"-expect-no-session"},
2087 },
David Benjamin30789da2015-08-29 22:56:45 -04002088 {
2089 name: "Unclean-Shutdown",
2090 config: Config{
2091 Bugs: ProtocolBugs{
2092 NoCloseNotify: true,
2093 ExpectCloseNotify: true,
2094 },
2095 },
2096 shimShutsDown: true,
2097 flags: []string{"-check-close-notify"},
2098 shouldFail: true,
2099 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2100 },
2101 {
2102 name: "Unclean-Shutdown-Ignored",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 NoCloseNotify: true,
2106 },
2107 },
2108 shimShutsDown: true,
2109 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002110 {
David Benjaminfa214e42016-05-10 17:03:10 -04002111 name: "Unclean-Shutdown-Alert",
2112 config: Config{
2113 Bugs: ProtocolBugs{
2114 SendAlertOnShutdown: alertDecompressionFailure,
2115 ExpectCloseNotify: true,
2116 },
2117 },
2118 shimShutsDown: true,
2119 flags: []string{"-check-close-notify"},
2120 shouldFail: true,
2121 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2122 },
2123 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002124 name: "LargePlaintext",
2125 config: Config{
2126 Bugs: ProtocolBugs{
2127 SendLargeRecords: true,
2128 },
2129 },
2130 messageLen: maxPlaintext + 1,
2131 shouldFail: true,
2132 expectedError: ":DATA_LENGTH_TOO_LONG:",
2133 },
2134 {
2135 protocol: dtls,
2136 name: "LargePlaintext-DTLS",
2137 config: Config{
2138 Bugs: ProtocolBugs{
2139 SendLargeRecords: true,
2140 },
2141 },
2142 messageLen: maxPlaintext + 1,
2143 shouldFail: true,
2144 expectedError: ":DATA_LENGTH_TOO_LONG:",
2145 },
2146 {
2147 name: "LargeCiphertext",
2148 config: Config{
2149 Bugs: ProtocolBugs{
2150 SendLargeRecords: true,
2151 },
2152 },
2153 messageLen: maxPlaintext * 2,
2154 shouldFail: true,
2155 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2156 },
2157 {
2158 protocol: dtls,
2159 name: "LargeCiphertext-DTLS",
2160 config: Config{
2161 Bugs: ProtocolBugs{
2162 SendLargeRecords: true,
2163 },
2164 },
2165 messageLen: maxPlaintext * 2,
2166 // Unlike the other four cases, DTLS drops records which
2167 // are invalid before authentication, so the connection
2168 // does not fail.
2169 expectMessageDropped: true,
2170 },
David Benjamindd6fed92015-10-23 17:41:12 -04002171 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002172 name: "BadHelloRequest-1",
2173 renegotiate: 1,
2174 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002175 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002176 Bugs: ProtocolBugs{
2177 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2178 },
2179 },
2180 flags: []string{
2181 "-renegotiate-freely",
2182 "-expect-total-renegotiations", "1",
2183 },
2184 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002185 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002186 },
2187 {
2188 name: "BadHelloRequest-2",
2189 renegotiate: 1,
2190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002191 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002192 Bugs: ProtocolBugs{
2193 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2194 },
2195 },
2196 flags: []string{
2197 "-renegotiate-freely",
2198 "-expect-total-renegotiations", "1",
2199 },
2200 shouldFail: true,
2201 expectedError: ":BAD_HELLO_REQUEST:",
2202 },
David Benjaminef1b0092015-11-21 14:05:44 -05002203 {
2204 testType: serverTest,
2205 name: "SupportTicketsWithSessionID",
2206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002207 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002208 SessionTicketsDisabled: true,
2209 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002210 resumeConfig: &Config{
2211 MaxVersion: VersionTLS12,
2212 },
David Benjaminef1b0092015-11-21 14:05:44 -05002213 resumeSession: true,
2214 },
David Benjamin02edcd02016-07-27 17:40:37 -04002215 {
2216 protocol: dtls,
2217 name: "DTLS-SendExtraFinished",
2218 config: Config{
2219 Bugs: ProtocolBugs{
2220 SendExtraFinished: true,
2221 },
2222 },
2223 shouldFail: true,
2224 expectedError: ":UNEXPECTED_RECORD:",
2225 },
2226 {
2227 protocol: dtls,
2228 name: "DTLS-SendExtraFinished-Reordered",
2229 config: Config{
2230 Bugs: ProtocolBugs{
2231 MaxHandshakeRecordLength: 2,
2232 ReorderHandshakeFragments: true,
2233 SendExtraFinished: true,
2234 },
2235 },
2236 shouldFail: true,
2237 expectedError: ":UNEXPECTED_RECORD:",
2238 },
David Benjamine97fb482016-07-29 09:23:07 -04002239 {
2240 testType: serverTest,
2241 name: "V2ClientHello-EmptyRecordPrefix",
2242 config: Config{
2243 // Choose a cipher suite that does not involve
2244 // elliptic curves, so no extensions are
2245 // involved.
2246 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002247 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002248 Bugs: ProtocolBugs{
2249 SendV2ClientHello: true,
2250 },
2251 },
2252 sendPrefix: string([]byte{
2253 byte(recordTypeHandshake),
2254 3, 1, // version
2255 0, 0, // length
2256 }),
2257 // A no-op empty record may not be sent before V2ClientHello.
2258 shouldFail: true,
2259 expectedError: ":WRONG_VERSION_NUMBER:",
2260 },
2261 {
2262 testType: serverTest,
2263 name: "V2ClientHello-WarningAlertPrefix",
2264 config: Config{
2265 // Choose a cipher suite that does not involve
2266 // elliptic curves, so no extensions are
2267 // involved.
2268 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002269 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002270 Bugs: ProtocolBugs{
2271 SendV2ClientHello: true,
2272 },
2273 },
2274 sendPrefix: string([]byte{
2275 byte(recordTypeAlert),
2276 3, 1, // version
2277 0, 2, // length
2278 alertLevelWarning, byte(alertDecompressionFailure),
2279 }),
2280 // A no-op warning alert may not be sent before V2ClientHello.
2281 shouldFail: true,
2282 expectedError: ":WRONG_VERSION_NUMBER:",
2283 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002284 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002285 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002286 config: Config{
2287 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002288 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002289 sendKeyUpdates: 1,
2290 keyUpdateRequest: keyUpdateNotRequested,
2291 },
2292 {
2293 name: "KeyUpdate-InvalidRequestMode",
2294 config: Config{
2295 MaxVersion: VersionTLS13,
2296 },
2297 sendKeyUpdates: 1,
2298 keyUpdateRequest: 42,
2299 shouldFail: true,
2300 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002301 },
David Benjaminabe94e32016-09-04 14:18:58 -04002302 {
2303 name: "SendSNIWarningAlert",
2304 config: Config{
2305 MaxVersion: VersionTLS12,
2306 Bugs: ProtocolBugs{
2307 SendSNIWarningAlert: true,
2308 },
2309 },
2310 },
David Benjaminc241d792016-09-09 10:34:20 -04002311 {
2312 testType: serverTest,
2313 name: "ExtraCompressionMethods-TLS12",
2314 config: Config{
2315 MaxVersion: VersionTLS12,
2316 Bugs: ProtocolBugs{
2317 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2318 },
2319 },
2320 },
2321 {
2322 testType: serverTest,
2323 name: "ExtraCompressionMethods-TLS13",
2324 config: Config{
2325 MaxVersion: VersionTLS13,
2326 Bugs: ProtocolBugs{
2327 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2328 },
2329 },
2330 shouldFail: true,
2331 expectedError: ":INVALID_COMPRESSION_LIST:",
2332 expectedLocalError: "remote error: illegal parameter",
2333 },
2334 {
2335 testType: serverTest,
2336 name: "NoNullCompression-TLS12",
2337 config: Config{
2338 MaxVersion: VersionTLS12,
2339 Bugs: ProtocolBugs{
2340 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2341 },
2342 },
2343 shouldFail: true,
2344 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2345 expectedLocalError: "remote error: illegal parameter",
2346 },
2347 {
2348 testType: serverTest,
2349 name: "NoNullCompression-TLS13",
2350 config: Config{
2351 MaxVersion: VersionTLS13,
2352 Bugs: ProtocolBugs{
2353 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2354 },
2355 },
2356 shouldFail: true,
2357 expectedError: ":INVALID_COMPRESSION_LIST:",
2358 expectedLocalError: "remote error: illegal parameter",
2359 },
David Benjamin65ac9972016-09-02 21:35:25 -04002360 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002361 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002362 config: Config{
2363 MaxVersion: VersionTLS12,
2364 Bugs: ProtocolBugs{
2365 ExpectGREASE: true,
2366 },
2367 },
2368 flags: []string{"-enable-grease"},
2369 },
2370 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002371 name: "GREASE-Client-TLS13",
2372 config: Config{
2373 MaxVersion: VersionTLS13,
2374 Bugs: ProtocolBugs{
2375 ExpectGREASE: true,
2376 },
2377 },
2378 flags: []string{"-enable-grease"},
2379 },
2380 {
2381 testType: serverTest,
2382 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002383 config: Config{
2384 MaxVersion: VersionTLS13,
2385 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002386 // TLS 1.3 servers are expected to
2387 // always enable GREASE. TLS 1.3 is new,
2388 // so there is no existing ecosystem to
2389 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002390 ExpectGREASE: true,
2391 },
2392 },
David Benjamin65ac9972016-09-02 21:35:25 -04002393 },
Adam Langley7c803a62015-06-15 15:35:05 -07002394 }
Adam Langley7c803a62015-06-15 15:35:05 -07002395 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002396
2397 // Test that very large messages can be received.
2398 cert := rsaCertificate
2399 for i := 0; i < 50; i++ {
2400 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2401 }
2402 testCases = append(testCases, testCase{
2403 name: "LargeMessage",
2404 config: Config{
2405 Certificates: []Certificate{cert},
2406 },
2407 })
2408 testCases = append(testCases, testCase{
2409 protocol: dtls,
2410 name: "LargeMessage-DTLS",
2411 config: Config{
2412 Certificates: []Certificate{cert},
2413 },
2414 })
2415
2416 // They are rejected if the maximum certificate chain length is capped.
2417 testCases = append(testCases, testCase{
2418 name: "LargeMessage-Reject",
2419 config: Config{
2420 Certificates: []Certificate{cert},
2421 },
2422 flags: []string{"-max-cert-list", "16384"},
2423 shouldFail: true,
2424 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2425 })
2426 testCases = append(testCases, testCase{
2427 protocol: dtls,
2428 name: "LargeMessage-Reject-DTLS",
2429 config: Config{
2430 Certificates: []Certificate{cert},
2431 },
2432 flags: []string{"-max-cert-list", "16384"},
2433 shouldFail: true,
2434 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2435 })
Adam Langley7c803a62015-06-15 15:35:05 -07002436}
2437
Adam Langley95c29f32014-06-20 12:00:00 -07002438func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002439 const bogusCipher = 0xfe00
2440
Adam Langley95c29f32014-06-20 12:00:00 -07002441 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002442 const psk = "12345"
2443 const pskIdentity = "luggage combo"
2444
Adam Langley95c29f32014-06-20 12:00:00 -07002445 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002446 var certFile string
2447 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002448 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002449 cert = ecdsaP256Certificate
2450 certFile = ecdsaP256CertificateFile
2451 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002452 } else {
David Benjamin33863262016-07-08 17:20:12 -07002453 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002454 certFile = rsaCertificateFile
2455 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002456 }
2457
David Benjamin48cae082014-10-27 01:06:24 -04002458 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002459 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002460 flags = append(flags,
2461 "-psk", psk,
2462 "-psk-identity", pskIdentity)
2463 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002464 if hasComponent(suite.name, "NULL") {
2465 // NULL ciphers must be explicitly enabled.
2466 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2467 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002468 if hasComponent(suite.name, "CECPQ1") {
2469 // CECPQ1 ciphers must be explicitly enabled.
2470 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2471 }
David Benjamin881f1962016-08-10 18:29:12 -04002472 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2473 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2474 // for now.
2475 flags = append(flags, "-cipher", suite.name)
2476 }
David Benjamin48cae082014-10-27 01:06:24 -04002477
Adam Langley95c29f32014-06-20 12:00:00 -07002478 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002479 for _, protocol := range []protocol{tls, dtls} {
2480 var prefix string
2481 if protocol == dtls {
2482 if !ver.hasDTLS {
2483 continue
2484 }
2485 prefix = "D"
2486 }
Adam Langley95c29f32014-06-20 12:00:00 -07002487
David Benjamin0407e762016-06-17 16:41:18 -04002488 var shouldServerFail, shouldClientFail bool
2489 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2490 // BoringSSL clients accept ECDHE on SSLv3, but
2491 // a BoringSSL server will never select it
2492 // because the extension is missing.
2493 shouldServerFail = true
2494 }
2495 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2496 shouldClientFail = true
2497 shouldServerFail = true
2498 }
David Benjamin54c217c2016-07-13 12:35:25 -04002499 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002500 shouldClientFail = true
2501 shouldServerFail = true
2502 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002503 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2504 shouldClientFail = true
2505 shouldServerFail = true
2506 }
David Benjamin0407e762016-06-17 16:41:18 -04002507 if !isDTLSCipher(suite.name) && protocol == dtls {
2508 shouldClientFail = true
2509 shouldServerFail = true
2510 }
David Benjamin4298d772015-12-19 00:18:25 -05002511
David Benjamin5ecb88b2016-10-04 17:51:35 -04002512 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002513 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002514 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002515 if shouldServerFail {
2516 expectedServerError = ":NO_SHARED_CIPHER:"
2517 }
2518 if shouldClientFail {
2519 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002520 // Configure the server to select ciphers as normal but
2521 // select an incompatible cipher in ServerHello.
2522 serverCipherSuites = nil
2523 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002524 }
David Benjamin025b3d32014-07-01 19:53:04 -04002525
David Benjamin6fd297b2014-08-11 18:43:38 -04002526 testCases = append(testCases, testCase{
2527 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002528 protocol: protocol,
2529
2530 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002531 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002532 MinVersion: ver.version,
2533 MaxVersion: ver.version,
2534 CipherSuites: []uint16{suite.id},
2535 Certificates: []Certificate{cert},
2536 PreSharedKey: []byte(psk),
2537 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002538 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002539 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002540 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002541 },
2542 certFile: certFile,
2543 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002544 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002545 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002546 shouldFail: shouldServerFail,
2547 expectedError: expectedServerError,
2548 })
2549
2550 testCases = append(testCases, testCase{
2551 testType: clientTest,
2552 protocol: protocol,
2553 name: prefix + ver.name + "-" + suite.name + "-client",
2554 config: Config{
2555 MinVersion: ver.version,
2556 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002557 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002558 Certificates: []Certificate{cert},
2559 PreSharedKey: []byte(psk),
2560 PreSharedKeyIdentity: pskIdentity,
2561 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002562 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002563 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002564 },
2565 },
2566 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002567 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002568 shouldFail: shouldClientFail,
2569 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002570 })
David Benjamin2c99d282015-09-01 10:23:00 -04002571
Nick Harper1fd39d82016-06-14 18:14:35 -07002572 if !shouldClientFail {
2573 // Ensure the maximum record size is accepted.
2574 testCases = append(testCases, testCase{
David Benjamin231a4752016-11-10 10:46:00 -05002575 protocol: protocol,
2576 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
Nick Harper1fd39d82016-06-14 18:14:35 -07002577 config: Config{
2578 MinVersion: ver.version,
2579 MaxVersion: ver.version,
2580 CipherSuites: []uint16{suite.id},
2581 Certificates: []Certificate{cert},
2582 PreSharedKey: []byte(psk),
2583 PreSharedKeyIdentity: pskIdentity,
2584 },
2585 flags: flags,
2586 messageLen: maxPlaintext,
2587 })
David Benjamin231a4752016-11-10 10:46:00 -05002588
2589 // Test bad records for all ciphers. Bad records are fatal in TLS
2590 // and ignored in DTLS.
2591 var shouldFail bool
2592 var expectedError string
2593 if protocol == tls {
2594 shouldFail = true
2595 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2596 }
2597
2598 testCases = append(testCases, testCase{
2599 protocol: protocol,
2600 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2601 config: Config{
2602 MinVersion: ver.version,
2603 MaxVersion: ver.version,
2604 CipherSuites: []uint16{suite.id},
2605 Certificates: []Certificate{cert},
2606 PreSharedKey: []byte(psk),
2607 PreSharedKeyIdentity: pskIdentity,
2608 },
2609 flags: flags,
2610 damageFirstWrite: true,
2611 messageLen: maxPlaintext,
2612 shouldFail: shouldFail,
2613 expectedError: expectedError,
2614 })
Nick Harper1fd39d82016-06-14 18:14:35 -07002615 }
2616 }
David Benjamin2c99d282015-09-01 10:23:00 -04002617 }
Adam Langley95c29f32014-06-20 12:00:00 -07002618 }
Adam Langleya7997f12015-05-14 17:38:50 -07002619
2620 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002621 name: "NoSharedCipher",
2622 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002623 MaxVersion: VersionTLS12,
2624 CipherSuites: []uint16{},
2625 },
2626 shouldFail: true,
2627 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2628 })
2629
2630 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002631 name: "NoSharedCipher-TLS13",
2632 config: Config{
2633 MaxVersion: VersionTLS13,
2634 CipherSuites: []uint16{},
2635 },
2636 shouldFail: true,
2637 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2638 })
2639
2640 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002641 name: "UnsupportedCipherSuite",
2642 config: Config{
2643 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002644 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002645 Bugs: ProtocolBugs{
2646 IgnorePeerCipherPreferences: true,
2647 },
2648 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002649 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002650 shouldFail: true,
2651 expectedError: ":WRONG_CIPHER_RETURNED:",
2652 })
2653
2654 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002655 name: "ServerHelloBogusCipher",
2656 config: Config{
2657 MaxVersion: VersionTLS12,
2658 Bugs: ProtocolBugs{
2659 SendCipherSuite: bogusCipher,
2660 },
2661 },
2662 shouldFail: true,
2663 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2664 })
2665 testCases = append(testCases, testCase{
2666 name: "ServerHelloBogusCipher-TLS13",
2667 config: Config{
2668 MaxVersion: VersionTLS13,
2669 Bugs: ProtocolBugs{
2670 SendCipherSuite: bogusCipher,
2671 },
2672 },
2673 shouldFail: true,
2674 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2675 })
2676
2677 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002678 name: "WeakDH",
2679 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002680 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002681 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2682 Bugs: ProtocolBugs{
2683 // This is a 1023-bit prime number, generated
2684 // with:
2685 // openssl gendh 1023 | openssl asn1parse -i
2686 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2687 },
2688 },
2689 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002690 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002691 })
Adam Langleycef75832015-09-03 14:51:12 -07002692
David Benjamincd24a392015-11-11 13:23:05 -08002693 testCases = append(testCases, testCase{
2694 name: "SillyDH",
2695 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002696 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002697 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2698 Bugs: ProtocolBugs{
2699 // This is a 4097-bit prime number, generated
2700 // with:
2701 // openssl gendh 4097 | openssl asn1parse -i
2702 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2703 },
2704 },
2705 shouldFail: true,
2706 expectedError: ":DH_P_TOO_LONG:",
2707 })
2708
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002709 // This test ensures that Diffie-Hellman public values are padded with
2710 // zeros so that they're the same length as the prime. This is to avoid
2711 // hitting a bug in yaSSL.
2712 testCases = append(testCases, testCase{
2713 testType: serverTest,
2714 name: "DHPublicValuePadded",
2715 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002716 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002717 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2718 Bugs: ProtocolBugs{
2719 RequireDHPublicValueLen: (1025 + 7) / 8,
2720 },
2721 },
2722 flags: []string{"-use-sparse-dh-prime"},
2723 })
David Benjamincd24a392015-11-11 13:23:05 -08002724
David Benjamin241ae832016-01-15 03:04:54 -05002725 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002726 testCases = append(testCases, testCase{
2727 testType: serverTest,
2728 name: "UnknownCipher",
2729 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002730 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002731 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002732 Bugs: ProtocolBugs{
2733 AdvertiseAllConfiguredCiphers: true,
2734 },
2735 },
2736 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002737
2738 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002739 testCases = append(testCases, testCase{
2740 testType: serverTest,
2741 name: "UnknownCipher-TLS13",
2742 config: Config{
2743 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002744 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002745 Bugs: ProtocolBugs{
2746 AdvertiseAllConfiguredCiphers: true,
2747 },
David Benjamin241ae832016-01-15 03:04:54 -05002748 },
2749 })
2750
David Benjamin78679342016-09-16 19:42:05 -04002751 // Test empty ECDHE_PSK identity hints work as expected.
2752 testCases = append(testCases, testCase{
2753 name: "EmptyECDHEPSKHint",
2754 config: Config{
2755 MaxVersion: VersionTLS12,
2756 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2757 PreSharedKey: []byte("secret"),
2758 },
2759 flags: []string{"-psk", "secret"},
2760 })
2761
2762 // Test empty PSK identity hints work as expected, even if an explicit
2763 // ServerKeyExchange is sent.
2764 testCases = append(testCases, testCase{
2765 name: "ExplicitEmptyPSKHint",
2766 config: Config{
2767 MaxVersion: VersionTLS12,
2768 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2769 PreSharedKey: []byte("secret"),
2770 Bugs: ProtocolBugs{
2771 AlwaysSendPreSharedKeyIdentityHint: true,
2772 },
2773 },
2774 flags: []string{"-psk", "secret"},
2775 })
2776
Adam Langleycef75832015-09-03 14:51:12 -07002777 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2778 // 1.1 specific cipher suite settings. A server is setup with the given
2779 // cipher lists and then a connection is made for each member of
2780 // expectations. The cipher suite that the server selects must match
2781 // the specified one.
2782 var versionSpecificCiphersTest = []struct {
2783 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2784 // expectations is a map from TLS version to cipher suite id.
2785 expectations map[uint16]uint16
2786 }{
2787 {
2788 // Test that the null case (where no version-specific ciphers are set)
2789 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002790 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2791 "", // no ciphers specifically for TLS ≥ 1.0
2792 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002793 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002794 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2795 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2796 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2797 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002798 },
2799 },
2800 {
2801 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2802 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002803 "DES-CBC3-SHA:AES128-SHA", // default
2804 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2805 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002806 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002807 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002808 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2809 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2810 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2811 },
2812 },
2813 {
2814 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2815 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002816 "DES-CBC3-SHA:AES128-SHA", // default
2817 "", // no ciphers specifically for TLS ≥ 1.0
2818 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002819 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002820 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2821 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002822 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2823 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2824 },
2825 },
2826 {
2827 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2828 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002829 "DES-CBC3-SHA:AES128-SHA", // default
2830 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2831 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002832 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002833 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002834 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2835 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2836 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2837 },
2838 },
2839 }
2840
2841 for i, test := range versionSpecificCiphersTest {
2842 for version, expectedCipherSuite := range test.expectations {
2843 flags := []string{"-cipher", test.ciphersDefault}
2844 if len(test.ciphersTLS10) > 0 {
2845 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2846 }
2847 if len(test.ciphersTLS11) > 0 {
2848 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2849 }
2850
2851 testCases = append(testCases, testCase{
2852 testType: serverTest,
2853 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2854 config: Config{
2855 MaxVersion: version,
2856 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002857 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002858 },
2859 flags: flags,
2860 expectedCipher: expectedCipherSuite,
2861 })
2862 }
2863 }
Adam Langley95c29f32014-06-20 12:00:00 -07002864}
2865
2866func addBadECDSASignatureTests() {
2867 for badR := BadValue(1); badR < NumBadValues; badR++ {
2868 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002869 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002870 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2871 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002872 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002873 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002874 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002875 Bugs: ProtocolBugs{
2876 BadECDSAR: badR,
2877 BadECDSAS: badS,
2878 },
2879 },
2880 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002881 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002882 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002883 testCases = append(testCases, testCase{
2884 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2885 config: Config{
2886 MaxVersion: VersionTLS13,
2887 Certificates: []Certificate{ecdsaP256Certificate},
2888 Bugs: ProtocolBugs{
2889 BadECDSAR: badR,
2890 BadECDSAS: badS,
2891 },
2892 },
2893 shouldFail: true,
2894 expectedError: ":BAD_SIGNATURE:",
2895 })
Adam Langley95c29f32014-06-20 12:00:00 -07002896 }
2897 }
2898}
2899
Adam Langley80842bd2014-06-20 12:00:00 -07002900func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002901 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002902 name: "MaxCBCPadding",
2903 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002904 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002905 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2906 Bugs: ProtocolBugs{
2907 MaxPadding: true,
2908 },
2909 },
2910 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2911 })
David Benjamin025b3d32014-07-01 19:53:04 -04002912 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002913 name: "BadCBCPadding",
2914 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002915 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002916 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2917 Bugs: ProtocolBugs{
2918 PaddingFirstByteBad: true,
2919 },
2920 },
2921 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002922 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002923 })
2924 // OpenSSL previously had an issue where the first byte of padding in
2925 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002926 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002927 name: "BadCBCPadding255",
2928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002929 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2931 Bugs: ProtocolBugs{
2932 MaxPadding: true,
2933 PaddingFirstByteBadIf255: true,
2934 },
2935 },
2936 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2937 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002938 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002939 })
2940}
2941
Kenny Root7fdeaf12014-08-05 15:23:37 -07002942func addCBCSplittingTests() {
2943 testCases = append(testCases, testCase{
2944 name: "CBCRecordSplitting",
2945 config: Config{
2946 MaxVersion: VersionTLS10,
2947 MinVersion: VersionTLS10,
2948 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2949 },
David Benjaminac8302a2015-09-01 17:18:15 -04002950 messageLen: -1, // read until EOF
2951 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002952 flags: []string{
2953 "-async",
2954 "-write-different-record-sizes",
2955 "-cbc-record-splitting",
2956 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002957 })
2958 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002959 name: "CBCRecordSplittingPartialWrite",
2960 config: Config{
2961 MaxVersion: VersionTLS10,
2962 MinVersion: VersionTLS10,
2963 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2964 },
2965 messageLen: -1, // read until EOF
2966 flags: []string{
2967 "-async",
2968 "-write-different-record-sizes",
2969 "-cbc-record-splitting",
2970 "-partial-write",
2971 },
2972 })
2973}
2974
David Benjamin636293b2014-07-08 17:59:18 -04002975func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002976 // Add a dummy cert pool to stress certificate authority parsing.
2977 // TODO(davidben): Add tests that those values parse out correctly.
2978 certPool := x509.NewCertPool()
2979 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2980 if err != nil {
2981 panic(err)
2982 }
2983 certPool.AddCert(cert)
2984
David Benjamin636293b2014-07-08 17:59:18 -04002985 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002986 testCases = append(testCases, testCase{
2987 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002988 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002989 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002990 MinVersion: ver.version,
2991 MaxVersion: ver.version,
2992 ClientAuth: RequireAnyClientCert,
2993 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002994 },
2995 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002996 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2997 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002998 },
2999 })
3000 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003001 testType: serverTest,
3002 name: ver.name + "-Server-ClientAuth-RSA",
3003 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003004 MinVersion: ver.version,
3005 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003006 Certificates: []Certificate{rsaCertificate},
3007 },
3008 flags: []string{"-require-any-client-certificate"},
3009 })
David Benjamine098ec22014-08-27 23:13:20 -04003010 if ver.version != VersionSSL30 {
3011 testCases = append(testCases, testCase{
3012 testType: serverTest,
3013 name: ver.name + "-Server-ClientAuth-ECDSA",
3014 config: Config{
3015 MinVersion: ver.version,
3016 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003017 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003018 },
3019 flags: []string{"-require-any-client-certificate"},
3020 })
3021 testCases = append(testCases, testCase{
3022 testType: clientTest,
3023 name: ver.name + "-Client-ClientAuth-ECDSA",
3024 config: Config{
3025 MinVersion: ver.version,
3026 MaxVersion: ver.version,
3027 ClientAuth: RequireAnyClientCert,
3028 ClientCAs: certPool,
3029 },
3030 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003031 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3032 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003033 },
3034 })
3035 }
Adam Langley37646832016-08-01 16:16:46 -07003036
3037 testCases = append(testCases, testCase{
3038 name: "NoClientCertificate-" + ver.name,
3039 config: Config{
3040 MinVersion: ver.version,
3041 MaxVersion: ver.version,
3042 ClientAuth: RequireAnyClientCert,
3043 },
3044 shouldFail: true,
3045 expectedLocalError: "client didn't provide a certificate",
3046 })
3047
3048 testCases = append(testCases, testCase{
3049 // Even if not configured to expect a certificate, OpenSSL will
3050 // return X509_V_OK as the verify_result.
3051 testType: serverTest,
3052 name: "NoClientCertificateRequested-Server-" + ver.name,
3053 config: Config{
3054 MinVersion: ver.version,
3055 MaxVersion: ver.version,
3056 },
3057 flags: []string{
3058 "-expect-verify-result",
3059 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003060 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003061 })
3062
3063 testCases = append(testCases, testCase{
3064 // If a client certificate is not provided, OpenSSL will still
3065 // return X509_V_OK as the verify_result.
3066 testType: serverTest,
3067 name: "NoClientCertificate-Server-" + ver.name,
3068 config: Config{
3069 MinVersion: ver.version,
3070 MaxVersion: ver.version,
3071 },
3072 flags: []string{
3073 "-expect-verify-result",
3074 "-verify-peer",
3075 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003076 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003077 })
3078
David Benjamin1db9e1b2016-10-07 20:51:43 -04003079 certificateRequired := "remote error: certificate required"
3080 if ver.version < VersionTLS13 {
3081 // Prior to TLS 1.3, the generic handshake_failure alert
3082 // was used.
3083 certificateRequired = "remote error: handshake failure"
3084 }
Adam Langley37646832016-08-01 16:16:46 -07003085 testCases = append(testCases, testCase{
3086 testType: serverTest,
3087 name: "RequireAnyClientCertificate-" + ver.name,
3088 config: Config{
3089 MinVersion: ver.version,
3090 MaxVersion: ver.version,
3091 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003092 flags: []string{"-require-any-client-certificate"},
3093 shouldFail: true,
3094 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3095 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003096 })
3097
3098 if ver.version != VersionSSL30 {
3099 testCases = append(testCases, testCase{
3100 testType: serverTest,
3101 name: "SkipClientCertificate-" + ver.name,
3102 config: Config{
3103 MinVersion: ver.version,
3104 MaxVersion: ver.version,
3105 Bugs: ProtocolBugs{
3106 SkipClientCertificate: true,
3107 },
3108 },
3109 // Setting SSL_VERIFY_PEER allows anonymous clients.
3110 flags: []string{"-verify-peer"},
3111 shouldFail: true,
3112 expectedError: ":UNEXPECTED_MESSAGE:",
3113 })
3114 }
David Benjamin636293b2014-07-08 17:59:18 -04003115 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003116
David Benjaminc032dfa2016-05-12 14:54:57 -04003117 // Client auth is only legal in certificate-based ciphers.
3118 testCases = append(testCases, testCase{
3119 testType: clientTest,
3120 name: "ClientAuth-PSK",
3121 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003122 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003123 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3124 PreSharedKey: []byte("secret"),
3125 ClientAuth: RequireAnyClientCert,
3126 },
3127 flags: []string{
3128 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3129 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3130 "-psk", "secret",
3131 },
3132 shouldFail: true,
3133 expectedError: ":UNEXPECTED_MESSAGE:",
3134 })
3135 testCases = append(testCases, testCase{
3136 testType: clientTest,
3137 name: "ClientAuth-ECDHE_PSK",
3138 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003139 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003140 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3141 PreSharedKey: []byte("secret"),
3142 ClientAuth: RequireAnyClientCert,
3143 },
3144 flags: []string{
3145 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3146 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3147 "-psk", "secret",
3148 },
3149 shouldFail: true,
3150 expectedError: ":UNEXPECTED_MESSAGE:",
3151 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003152
3153 // Regression test for a bug where the client CA list, if explicitly
3154 // set to NULL, was mis-encoded.
3155 testCases = append(testCases, testCase{
3156 testType: serverTest,
3157 name: "Null-Client-CA-List",
3158 config: Config{
3159 MaxVersion: VersionTLS12,
3160 Certificates: []Certificate{rsaCertificate},
3161 },
3162 flags: []string{
3163 "-require-any-client-certificate",
3164 "-use-null-client-ca-list",
3165 },
3166 })
David Benjamin636293b2014-07-08 17:59:18 -04003167}
3168
Adam Langley75712922014-10-10 16:23:43 -07003169func addExtendedMasterSecretTests() {
3170 const expectEMSFlag = "-expect-extended-master-secret"
3171
3172 for _, with := range []bool{false, true} {
3173 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003174 if with {
3175 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003176 }
3177
3178 for _, isClient := range []bool{false, true} {
3179 suffix := "-Server"
3180 testType := serverTest
3181 if isClient {
3182 suffix = "-Client"
3183 testType = clientTest
3184 }
3185
3186 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003187 // In TLS 1.3, the extension is irrelevant and
3188 // always reports as enabled.
3189 var flags []string
3190 if with || ver.version >= VersionTLS13 {
3191 flags = []string{expectEMSFlag}
3192 }
3193
Adam Langley75712922014-10-10 16:23:43 -07003194 test := testCase{
3195 testType: testType,
3196 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3197 config: Config{
3198 MinVersion: ver.version,
3199 MaxVersion: ver.version,
3200 Bugs: ProtocolBugs{
3201 NoExtendedMasterSecret: !with,
3202 RequireExtendedMasterSecret: with,
3203 },
3204 },
David Benjamin48cae082014-10-27 01:06:24 -04003205 flags: flags,
3206 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003207 }
3208 if test.shouldFail {
3209 test.expectedLocalError = "extended master secret required but not supported by peer"
3210 }
3211 testCases = append(testCases, test)
3212 }
3213 }
3214 }
3215
Adam Langleyba5934b2015-06-02 10:50:35 -07003216 for _, isClient := range []bool{false, true} {
3217 for _, supportedInFirstConnection := range []bool{false, true} {
3218 for _, supportedInResumeConnection := range []bool{false, true} {
3219 boolToWord := func(b bool) string {
3220 if b {
3221 return "Yes"
3222 }
3223 return "No"
3224 }
3225 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3226 if isClient {
3227 suffix += "Client"
3228 } else {
3229 suffix += "Server"
3230 }
3231
3232 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003233 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003234 Bugs: ProtocolBugs{
3235 RequireExtendedMasterSecret: true,
3236 },
3237 }
3238
3239 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003240 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003241 Bugs: ProtocolBugs{
3242 NoExtendedMasterSecret: true,
3243 },
3244 }
3245
3246 test := testCase{
3247 name: "ExtendedMasterSecret-" + suffix,
3248 resumeSession: true,
3249 }
3250
3251 if !isClient {
3252 test.testType = serverTest
3253 }
3254
3255 if supportedInFirstConnection {
3256 test.config = supportedConfig
3257 } else {
3258 test.config = noSupportConfig
3259 }
3260
3261 if supportedInResumeConnection {
3262 test.resumeConfig = &supportedConfig
3263 } else {
3264 test.resumeConfig = &noSupportConfig
3265 }
3266
3267 switch suffix {
3268 case "YesToYes-Client", "YesToYes-Server":
3269 // When a session is resumed, it should
3270 // still be aware that its master
3271 // secret was generated via EMS and
3272 // thus it's safe to use tls-unique.
3273 test.flags = []string{expectEMSFlag}
3274 case "NoToYes-Server":
3275 // If an original connection did not
3276 // contain EMS, but a resumption
3277 // handshake does, then a server should
3278 // not resume the session.
3279 test.expectResumeRejected = true
3280 case "YesToNo-Server":
3281 // Resuming an EMS session without the
3282 // EMS extension should cause the
3283 // server to abort the connection.
3284 test.shouldFail = true
3285 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3286 case "NoToYes-Client":
3287 // A client should abort a connection
3288 // where the server resumed a non-EMS
3289 // session but echoed the EMS
3290 // extension.
3291 test.shouldFail = true
3292 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3293 case "YesToNo-Client":
3294 // A client should abort a connection
3295 // where the server didn't echo EMS
3296 // when the session used it.
3297 test.shouldFail = true
3298 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3299 }
3300
3301 testCases = append(testCases, test)
3302 }
3303 }
3304 }
David Benjamin163c9562016-08-29 23:14:17 -04003305
3306 // Switching EMS on renegotiation is forbidden.
3307 testCases = append(testCases, testCase{
3308 name: "ExtendedMasterSecret-Renego-NoEMS",
3309 config: Config{
3310 MaxVersion: VersionTLS12,
3311 Bugs: ProtocolBugs{
3312 NoExtendedMasterSecret: true,
3313 NoExtendedMasterSecretOnRenegotiation: true,
3314 },
3315 },
3316 renegotiate: 1,
3317 flags: []string{
3318 "-renegotiate-freely",
3319 "-expect-total-renegotiations", "1",
3320 },
3321 })
3322
3323 testCases = append(testCases, testCase{
3324 name: "ExtendedMasterSecret-Renego-Upgrade",
3325 config: Config{
3326 MaxVersion: VersionTLS12,
3327 Bugs: ProtocolBugs{
3328 NoExtendedMasterSecret: true,
3329 },
3330 },
3331 renegotiate: 1,
3332 flags: []string{
3333 "-renegotiate-freely",
3334 "-expect-total-renegotiations", "1",
3335 },
3336 shouldFail: true,
3337 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3338 })
3339
3340 testCases = append(testCases, testCase{
3341 name: "ExtendedMasterSecret-Renego-Downgrade",
3342 config: Config{
3343 MaxVersion: VersionTLS12,
3344 Bugs: ProtocolBugs{
3345 NoExtendedMasterSecretOnRenegotiation: true,
3346 },
3347 },
3348 renegotiate: 1,
3349 flags: []string{
3350 "-renegotiate-freely",
3351 "-expect-total-renegotiations", "1",
3352 },
3353 shouldFail: true,
3354 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3355 })
Adam Langley75712922014-10-10 16:23:43 -07003356}
3357
David Benjamin582ba042016-07-07 12:33:25 -07003358type stateMachineTestConfig struct {
3359 protocol protocol
3360 async bool
3361 splitHandshake, packHandshakeFlight bool
3362}
3363
David Benjamin43ec06f2014-08-05 02:28:57 -04003364// Adds tests that try to cover the range of the handshake state machine, under
3365// various conditions. Some of these are redundant with other tests, but they
3366// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003367func addAllStateMachineCoverageTests() {
3368 for _, async := range []bool{false, true} {
3369 for _, protocol := range []protocol{tls, dtls} {
3370 addStateMachineCoverageTests(stateMachineTestConfig{
3371 protocol: protocol,
3372 async: async,
3373 })
3374 addStateMachineCoverageTests(stateMachineTestConfig{
3375 protocol: protocol,
3376 async: async,
3377 splitHandshake: true,
3378 })
3379 if protocol == tls {
3380 addStateMachineCoverageTests(stateMachineTestConfig{
3381 protocol: protocol,
3382 async: async,
3383 packHandshakeFlight: true,
3384 })
3385 }
3386 }
3387 }
3388}
3389
3390func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003391 var tests []testCase
3392
3393 // Basic handshake, with resumption. Client and server,
3394 // session ID and session ticket.
3395 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003396 name: "Basic-Client",
3397 config: Config{
3398 MaxVersion: VersionTLS12,
3399 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003400 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003401 // Ensure session tickets are used, not session IDs.
3402 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003403 })
3404 tests = append(tests, testCase{
3405 name: "Basic-Client-RenewTicket",
3406 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003407 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003408 Bugs: ProtocolBugs{
3409 RenewTicketOnResume: true,
3410 },
3411 },
David Benjamin46662482016-08-17 00:51:00 -04003412 flags: []string{"-expect-ticket-renewal"},
3413 resumeSession: true,
3414 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003415 })
3416 tests = append(tests, testCase{
3417 name: "Basic-Client-NoTicket",
3418 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003419 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003420 SessionTicketsDisabled: true,
3421 },
3422 resumeSession: true,
3423 })
3424 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003425 name: "Basic-Client-Implicit",
3426 config: Config{
3427 MaxVersion: VersionTLS12,
3428 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003429 flags: []string{"-implicit-handshake"},
3430 resumeSession: true,
3431 })
3432 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003433 testType: serverTest,
3434 name: "Basic-Server",
3435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003436 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003437 Bugs: ProtocolBugs{
3438 RequireSessionTickets: true,
3439 },
3440 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003441 resumeSession: true,
3442 })
3443 tests = append(tests, testCase{
3444 testType: serverTest,
3445 name: "Basic-Server-NoTickets",
3446 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003447 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003448 SessionTicketsDisabled: true,
3449 },
3450 resumeSession: true,
3451 })
3452 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003453 testType: serverTest,
3454 name: "Basic-Server-Implicit",
3455 config: Config{
3456 MaxVersion: VersionTLS12,
3457 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003458 flags: []string{"-implicit-handshake"},
3459 resumeSession: true,
3460 })
3461 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003462 testType: serverTest,
3463 name: "Basic-Server-EarlyCallback",
3464 config: Config{
3465 MaxVersion: VersionTLS12,
3466 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003467 flags: []string{"-use-early-callback"},
3468 resumeSession: true,
3469 })
3470
Steven Valdez143e8b32016-07-11 13:19:03 -04003471 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003472 if config.protocol == tls {
3473 tests = append(tests, testCase{
3474 name: "TLS13-1RTT-Client",
3475 config: Config{
3476 MaxVersion: VersionTLS13,
3477 MinVersion: VersionTLS13,
3478 },
David Benjamin46662482016-08-17 00:51:00 -04003479 resumeSession: true,
3480 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003481 })
3482
3483 tests = append(tests, testCase{
3484 testType: serverTest,
3485 name: "TLS13-1RTT-Server",
3486 config: Config{
3487 MaxVersion: VersionTLS13,
3488 MinVersion: VersionTLS13,
3489 },
David Benjamin46662482016-08-17 00:51:00 -04003490 resumeSession: true,
3491 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003492 })
3493
3494 tests = append(tests, testCase{
3495 name: "TLS13-HelloRetryRequest-Client",
3496 config: Config{
3497 MaxVersion: VersionTLS13,
3498 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003499 // P-384 requires a HelloRetryRequest against BoringSSL's default
3500 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003501 CurvePreferences: []CurveID{CurveP384},
3502 Bugs: ProtocolBugs{
3503 ExpectMissingKeyShare: true,
3504 },
3505 },
3506 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3507 resumeSession: true,
3508 })
3509
3510 tests = append(tests, testCase{
3511 testType: serverTest,
3512 name: "TLS13-HelloRetryRequest-Server",
3513 config: Config{
3514 MaxVersion: VersionTLS13,
3515 MinVersion: VersionTLS13,
3516 // Require a HelloRetryRequest for every curve.
3517 DefaultCurves: []CurveID{},
3518 },
3519 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3520 resumeSession: true,
3521 })
3522 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003523
David Benjamin760b1dd2015-05-15 23:33:48 -04003524 // TLS client auth.
3525 tests = append(tests, testCase{
3526 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003527 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003529 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003530 ClientAuth: RequestClientCert,
3531 },
3532 })
3533 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003534 testType: serverTest,
3535 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003536 config: Config{
3537 MaxVersion: VersionTLS12,
3538 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003539 // Setting SSL_VERIFY_PEER allows anonymous clients.
3540 flags: []string{"-verify-peer"},
3541 })
David Benjamin582ba042016-07-07 12:33:25 -07003542 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003543 tests = append(tests, testCase{
3544 testType: clientTest,
3545 name: "ClientAuth-NoCertificate-Client-SSL3",
3546 config: Config{
3547 MaxVersion: VersionSSL30,
3548 ClientAuth: RequestClientCert,
3549 },
3550 })
3551 tests = append(tests, testCase{
3552 testType: serverTest,
3553 name: "ClientAuth-NoCertificate-Server-SSL3",
3554 config: Config{
3555 MaxVersion: VersionSSL30,
3556 },
3557 // Setting SSL_VERIFY_PEER allows anonymous clients.
3558 flags: []string{"-verify-peer"},
3559 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003560 tests = append(tests, testCase{
3561 testType: clientTest,
3562 name: "ClientAuth-NoCertificate-Client-TLS13",
3563 config: Config{
3564 MaxVersion: VersionTLS13,
3565 ClientAuth: RequestClientCert,
3566 },
3567 })
3568 tests = append(tests, testCase{
3569 testType: serverTest,
3570 name: "ClientAuth-NoCertificate-Server-TLS13",
3571 config: Config{
3572 MaxVersion: VersionTLS13,
3573 },
3574 // Setting SSL_VERIFY_PEER allows anonymous clients.
3575 flags: []string{"-verify-peer"},
3576 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003577 }
3578 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003579 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003580 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003581 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003582 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003583 ClientAuth: RequireAnyClientCert,
3584 },
3585 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003586 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3587 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003588 },
3589 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003590 tests = append(tests, testCase{
3591 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003592 name: "ClientAuth-RSA-Client-TLS13",
3593 config: Config{
3594 MaxVersion: VersionTLS13,
3595 ClientAuth: RequireAnyClientCert,
3596 },
3597 flags: []string{
3598 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3599 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3600 },
3601 })
3602 tests = append(tests, testCase{
3603 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003604 name: "ClientAuth-ECDSA-Client",
3605 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003606 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003607 ClientAuth: RequireAnyClientCert,
3608 },
3609 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003610 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3611 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003612 },
3613 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003614 tests = append(tests, testCase{
3615 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003616 name: "ClientAuth-ECDSA-Client-TLS13",
3617 config: Config{
3618 MaxVersion: VersionTLS13,
3619 ClientAuth: RequireAnyClientCert,
3620 },
3621 flags: []string{
3622 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3623 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3624 },
3625 })
3626 tests = append(tests, testCase{
3627 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003628 name: "ClientAuth-NoCertificate-OldCallback",
3629 config: Config{
3630 MaxVersion: VersionTLS12,
3631 ClientAuth: RequestClientCert,
3632 },
3633 flags: []string{"-use-old-client-cert-callback"},
3634 })
3635 tests = append(tests, testCase{
3636 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003637 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3638 config: Config{
3639 MaxVersion: VersionTLS13,
3640 ClientAuth: RequestClientCert,
3641 },
3642 flags: []string{"-use-old-client-cert-callback"},
3643 })
3644 tests = append(tests, testCase{
3645 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003646 name: "ClientAuth-OldCallback",
3647 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003648 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003649 ClientAuth: RequireAnyClientCert,
3650 },
3651 flags: []string{
3652 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3653 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3654 "-use-old-client-cert-callback",
3655 },
3656 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003657 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003658 testType: clientTest,
3659 name: "ClientAuth-OldCallback-TLS13",
3660 config: Config{
3661 MaxVersion: VersionTLS13,
3662 ClientAuth: RequireAnyClientCert,
3663 },
3664 flags: []string{
3665 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3666 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3667 "-use-old-client-cert-callback",
3668 },
3669 })
3670 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003671 testType: serverTest,
3672 name: "ClientAuth-Server",
3673 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003674 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003675 Certificates: []Certificate{rsaCertificate},
3676 },
3677 flags: []string{"-require-any-client-certificate"},
3678 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003679 tests = append(tests, testCase{
3680 testType: serverTest,
3681 name: "ClientAuth-Server-TLS13",
3682 config: Config{
3683 MaxVersion: VersionTLS13,
3684 Certificates: []Certificate{rsaCertificate},
3685 },
3686 flags: []string{"-require-any-client-certificate"},
3687 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003688
David Benjamin4c3ddf72016-06-29 18:13:53 -04003689 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003690 tests = append(tests, testCase{
3691 testType: serverTest,
3692 name: "Basic-Server-RSA",
3693 config: Config{
3694 MaxVersion: VersionTLS12,
3695 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3696 },
3697 flags: []string{
3698 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3699 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3700 },
3701 })
3702 tests = append(tests, testCase{
3703 testType: serverTest,
3704 name: "Basic-Server-ECDHE-RSA",
3705 config: Config{
3706 MaxVersion: VersionTLS12,
3707 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3708 },
3709 flags: []string{
3710 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3711 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3712 },
3713 })
3714 tests = append(tests, testCase{
3715 testType: serverTest,
3716 name: "Basic-Server-ECDHE-ECDSA",
3717 config: Config{
3718 MaxVersion: VersionTLS12,
3719 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3720 },
3721 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003722 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3723 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003724 },
3725 })
3726
David Benjamin760b1dd2015-05-15 23:33:48 -04003727 // No session ticket support; server doesn't send NewSessionTicket.
3728 tests = append(tests, testCase{
3729 name: "SessionTicketsDisabled-Client",
3730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003731 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003732 SessionTicketsDisabled: true,
3733 },
3734 })
3735 tests = append(tests, testCase{
3736 testType: serverTest,
3737 name: "SessionTicketsDisabled-Server",
3738 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003739 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003740 SessionTicketsDisabled: true,
3741 },
3742 })
3743
3744 // Skip ServerKeyExchange in PSK key exchange if there's no
3745 // identity hint.
3746 tests = append(tests, testCase{
3747 name: "EmptyPSKHint-Client",
3748 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003749 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003750 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3751 PreSharedKey: []byte("secret"),
3752 },
3753 flags: []string{"-psk", "secret"},
3754 })
3755 tests = append(tests, testCase{
3756 testType: serverTest,
3757 name: "EmptyPSKHint-Server",
3758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003759 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003760 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3761 PreSharedKey: []byte("secret"),
3762 },
3763 flags: []string{"-psk", "secret"},
3764 })
3765
David Benjamin4c3ddf72016-06-29 18:13:53 -04003766 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003767 tests = append(tests, testCase{
3768 testType: clientTest,
3769 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003770 config: Config{
3771 MaxVersion: VersionTLS12,
3772 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003773 flags: []string{
3774 "-enable-ocsp-stapling",
3775 "-expect-ocsp-response",
3776 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003777 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003778 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003779 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003780 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003781 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003782 testType: serverTest,
3783 name: "OCSPStapling-Server",
3784 config: Config{
3785 MaxVersion: VersionTLS12,
3786 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003787 expectedOCSPResponse: testOCSPResponse,
3788 flags: []string{
3789 "-ocsp-response",
3790 base64.StdEncoding.EncodeToString(testOCSPResponse),
3791 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003792 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003793 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003794 tests = append(tests, testCase{
3795 testType: clientTest,
3796 name: "OCSPStapling-Client-TLS13",
3797 config: Config{
3798 MaxVersion: VersionTLS13,
3799 },
3800 flags: []string{
3801 "-enable-ocsp-stapling",
3802 "-expect-ocsp-response",
3803 base64.StdEncoding.EncodeToString(testOCSPResponse),
3804 "-verify-peer",
3805 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003806 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003807 })
3808 tests = append(tests, testCase{
3809 testType: serverTest,
3810 name: "OCSPStapling-Server-TLS13",
3811 config: Config{
3812 MaxVersion: VersionTLS13,
3813 },
3814 expectedOCSPResponse: testOCSPResponse,
3815 flags: []string{
3816 "-ocsp-response",
3817 base64.StdEncoding.EncodeToString(testOCSPResponse),
3818 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003819 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003820 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003821
David Benjamin4c3ddf72016-06-29 18:13:53 -04003822 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003823 for _, vers := range tlsVersions {
3824 if config.protocol == dtls && !vers.hasDTLS {
3825 continue
3826 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003827 for _, testType := range []testType{clientTest, serverTest} {
3828 suffix := "-Client"
3829 if testType == serverTest {
3830 suffix = "-Server"
3831 }
3832 suffix += "-" + vers.name
3833
3834 flag := "-verify-peer"
3835 if testType == serverTest {
3836 flag = "-require-any-client-certificate"
3837 }
3838
3839 tests = append(tests, testCase{
3840 testType: testType,
3841 name: "CertificateVerificationSucceed" + suffix,
3842 config: Config{
3843 MaxVersion: vers.version,
3844 Certificates: []Certificate{rsaCertificate},
3845 },
3846 flags: []string{
3847 flag,
3848 "-expect-verify-result",
3849 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003850 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003851 })
3852 tests = append(tests, testCase{
3853 testType: testType,
3854 name: "CertificateVerificationFail" + suffix,
3855 config: Config{
3856 MaxVersion: vers.version,
3857 Certificates: []Certificate{rsaCertificate},
3858 },
3859 flags: []string{
3860 flag,
3861 "-verify-fail",
3862 },
3863 shouldFail: true,
3864 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3865 })
3866 }
3867
3868 // By default, the client is in a soft fail mode where the peer
3869 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003870 tests = append(tests, testCase{
3871 testType: clientTest,
3872 name: "CertificateVerificationSoftFail-" + vers.name,
3873 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003874 MaxVersion: vers.version,
3875 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003876 },
3877 flags: []string{
3878 "-verify-fail",
3879 "-expect-verify-result",
3880 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003881 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003882 })
3883 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003884
David Benjamin1d4f4c02016-07-26 18:03:08 -04003885 tests = append(tests, testCase{
3886 name: "ShimSendAlert",
3887 flags: []string{"-send-alert"},
3888 shimWritesFirst: true,
3889 shouldFail: true,
3890 expectedLocalError: "remote error: decompression failure",
3891 })
3892
David Benjamin582ba042016-07-07 12:33:25 -07003893 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003894 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003895 name: "Renegotiate-Client",
3896 config: Config{
3897 MaxVersion: VersionTLS12,
3898 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003899 renegotiate: 1,
3900 flags: []string{
3901 "-renegotiate-freely",
3902 "-expect-total-renegotiations", "1",
3903 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003904 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003905
David Benjamin47921102016-07-28 11:29:18 -04003906 tests = append(tests, testCase{
3907 name: "SendHalfHelloRequest",
3908 config: Config{
3909 MaxVersion: VersionTLS12,
3910 Bugs: ProtocolBugs{
3911 PackHelloRequestWithFinished: config.packHandshakeFlight,
3912 },
3913 },
3914 sendHalfHelloRequest: true,
3915 flags: []string{"-renegotiate-ignore"},
3916 shouldFail: true,
3917 expectedError: ":UNEXPECTED_RECORD:",
3918 })
3919
David Benjamin760b1dd2015-05-15 23:33:48 -04003920 // NPN on client and server; results in post-handshake message.
3921 tests = append(tests, testCase{
3922 name: "NPN-Client",
3923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003924 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 NextProtos: []string{"foo"},
3926 },
3927 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003928 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003929 expectedNextProto: "foo",
3930 expectedNextProtoType: npn,
3931 })
3932 tests = append(tests, testCase{
3933 testType: serverTest,
3934 name: "NPN-Server",
3935 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003936 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003937 NextProtos: []string{"bar"},
3938 },
3939 flags: []string{
3940 "-advertise-npn", "\x03foo\x03bar\x03baz",
3941 "-expect-next-proto", "bar",
3942 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003943 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003944 expectedNextProto: "bar",
3945 expectedNextProtoType: npn,
3946 })
3947
3948 // TODO(davidben): Add tests for when False Start doesn't trigger.
3949
3950 // Client does False Start and negotiates NPN.
3951 tests = append(tests, testCase{
3952 name: "FalseStart",
3953 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003954 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003955 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3956 NextProtos: []string{"foo"},
3957 Bugs: ProtocolBugs{
3958 ExpectFalseStart: true,
3959 },
3960 },
3961 flags: []string{
3962 "-false-start",
3963 "-select-next-proto", "foo",
3964 },
3965 shimWritesFirst: true,
3966 resumeSession: true,
3967 })
3968
3969 // Client does False Start and negotiates ALPN.
3970 tests = append(tests, testCase{
3971 name: "FalseStart-ALPN",
3972 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003973 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3975 NextProtos: []string{"foo"},
3976 Bugs: ProtocolBugs{
3977 ExpectFalseStart: true,
3978 },
3979 },
3980 flags: []string{
3981 "-false-start",
3982 "-advertise-alpn", "\x03foo",
3983 },
3984 shimWritesFirst: true,
3985 resumeSession: true,
3986 })
3987
3988 // Client does False Start but doesn't explicitly call
3989 // SSL_connect.
3990 tests = append(tests, testCase{
3991 name: "FalseStart-Implicit",
3992 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003993 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003994 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3995 NextProtos: []string{"foo"},
3996 },
3997 flags: []string{
3998 "-implicit-handshake",
3999 "-false-start",
4000 "-advertise-alpn", "\x03foo",
4001 },
4002 })
4003
4004 // False Start without session tickets.
4005 tests = append(tests, testCase{
4006 name: "FalseStart-SessionTicketsDisabled",
4007 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004008 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004009 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4010 NextProtos: []string{"foo"},
4011 SessionTicketsDisabled: true,
4012 Bugs: ProtocolBugs{
4013 ExpectFalseStart: true,
4014 },
4015 },
4016 flags: []string{
4017 "-false-start",
4018 "-select-next-proto", "foo",
4019 },
4020 shimWritesFirst: true,
4021 })
4022
Adam Langleydf759b52016-07-11 15:24:37 -07004023 tests = append(tests, testCase{
4024 name: "FalseStart-CECPQ1",
4025 config: Config{
4026 MaxVersion: VersionTLS12,
4027 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
4028 NextProtos: []string{"foo"},
4029 Bugs: ProtocolBugs{
4030 ExpectFalseStart: true,
4031 },
4032 },
4033 flags: []string{
4034 "-false-start",
4035 "-cipher", "DEFAULT:kCECPQ1",
4036 "-select-next-proto", "foo",
4037 },
4038 shimWritesFirst: true,
4039 resumeSession: true,
4040 })
4041
David Benjamin760b1dd2015-05-15 23:33:48 -04004042 // Server parses a V2ClientHello.
4043 tests = append(tests, testCase{
4044 testType: serverTest,
4045 name: "SendV2ClientHello",
4046 config: Config{
4047 // Choose a cipher suite that does not involve
4048 // elliptic curves, so no extensions are
4049 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004050 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004051 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004052 Bugs: ProtocolBugs{
4053 SendV2ClientHello: true,
4054 },
4055 },
4056 })
4057
Nick Harper60a85cb2016-09-23 16:25:11 -07004058 // Test Channel ID
4059 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004060 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004061 continue
4062 }
4063 // Client sends a Channel ID.
4064 tests = append(tests, testCase{
4065 name: "ChannelID-Client-" + ver.name,
4066 config: Config{
4067 MaxVersion: ver.version,
4068 RequestChannelID: true,
4069 },
4070 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4071 resumeSession: true,
4072 expectChannelID: true,
4073 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004074
Nick Harper60a85cb2016-09-23 16:25:11 -07004075 // Server accepts a Channel ID.
4076 tests = append(tests, testCase{
4077 testType: serverTest,
4078 name: "ChannelID-Server-" + ver.name,
4079 config: Config{
4080 MaxVersion: ver.version,
4081 ChannelID: channelIDKey,
4082 },
4083 flags: []string{
4084 "-expect-channel-id",
4085 base64.StdEncoding.EncodeToString(channelIDBytes),
4086 },
4087 resumeSession: true,
4088 expectChannelID: true,
4089 })
4090
4091 tests = append(tests, testCase{
4092 testType: serverTest,
4093 name: "InvalidChannelIDSignature-" + ver.name,
4094 config: Config{
4095 MaxVersion: ver.version,
4096 ChannelID: channelIDKey,
4097 Bugs: ProtocolBugs{
4098 InvalidChannelIDSignature: true,
4099 },
4100 },
4101 flags: []string{"-enable-channel-id"},
4102 shouldFail: true,
4103 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4104 })
4105 }
David Benjamin30789da2015-08-29 22:56:45 -04004106
David Benjaminf8fcdf32016-06-08 15:56:13 -04004107 // Channel ID and NPN at the same time, to ensure their relative
4108 // ordering is correct.
4109 tests = append(tests, testCase{
4110 name: "ChannelID-NPN-Client",
4111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004112 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004113 RequestChannelID: true,
4114 NextProtos: []string{"foo"},
4115 },
4116 flags: []string{
4117 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4118 "-select-next-proto", "foo",
4119 },
4120 resumeSession: true,
4121 expectChannelID: true,
4122 expectedNextProto: "foo",
4123 expectedNextProtoType: npn,
4124 })
4125 tests = append(tests, testCase{
4126 testType: serverTest,
4127 name: "ChannelID-NPN-Server",
4128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004129 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004130 ChannelID: channelIDKey,
4131 NextProtos: []string{"bar"},
4132 },
4133 flags: []string{
4134 "-expect-channel-id",
4135 base64.StdEncoding.EncodeToString(channelIDBytes),
4136 "-advertise-npn", "\x03foo\x03bar\x03baz",
4137 "-expect-next-proto", "bar",
4138 },
4139 resumeSession: true,
4140 expectChannelID: true,
4141 expectedNextProto: "bar",
4142 expectedNextProtoType: npn,
4143 })
4144
David Benjamin30789da2015-08-29 22:56:45 -04004145 // Bidirectional shutdown with the runner initiating.
4146 tests = append(tests, testCase{
4147 name: "Shutdown-Runner",
4148 config: Config{
4149 Bugs: ProtocolBugs{
4150 ExpectCloseNotify: true,
4151 },
4152 },
4153 flags: []string{"-check-close-notify"},
4154 })
4155
4156 // Bidirectional shutdown with the shim initiating. The runner,
4157 // in the meantime, sends garbage before the close_notify which
4158 // the shim must ignore.
4159 tests = append(tests, testCase{
4160 name: "Shutdown-Shim",
4161 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004162 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004163 Bugs: ProtocolBugs{
4164 ExpectCloseNotify: true,
4165 },
4166 },
4167 shimShutsDown: true,
4168 sendEmptyRecords: 1,
4169 sendWarningAlerts: 1,
4170 flags: []string{"-check-close-notify"},
4171 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004172 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004173 // TODO(davidben): DTLS 1.3 will want a similar thing for
4174 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004175 tests = append(tests, testCase{
4176 name: "SkipHelloVerifyRequest",
4177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004178 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004179 Bugs: ProtocolBugs{
4180 SkipHelloVerifyRequest: true,
4181 },
4182 },
4183 })
4184 }
4185
David Benjamin760b1dd2015-05-15 23:33:48 -04004186 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004187 test.protocol = config.protocol
4188 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004189 test.name += "-DTLS"
4190 }
David Benjamin582ba042016-07-07 12:33:25 -07004191 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004192 test.name += "-Async"
4193 test.flags = append(test.flags, "-async")
4194 } else {
4195 test.name += "-Sync"
4196 }
David Benjamin582ba042016-07-07 12:33:25 -07004197 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004198 test.name += "-SplitHandshakeRecords"
4199 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004200 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004201 test.config.Bugs.MaxPacketLength = 256
4202 test.flags = append(test.flags, "-mtu", "256")
4203 }
4204 }
David Benjamin582ba042016-07-07 12:33:25 -07004205 if config.packHandshakeFlight {
4206 test.name += "-PackHandshakeFlight"
4207 test.config.Bugs.PackHandshakeFlight = true
4208 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004209 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004210 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004211}
4212
Adam Langley524e7172015-02-20 16:04:00 -08004213func addDDoSCallbackTests() {
4214 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004215 for _, resume := range []bool{false, true} {
4216 suffix := "Resume"
4217 if resume {
4218 suffix = "No" + suffix
4219 }
4220
4221 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004222 testType: serverTest,
4223 name: "Server-DDoS-OK-" + suffix,
4224 config: Config{
4225 MaxVersion: VersionTLS12,
4226 },
Adam Langley524e7172015-02-20 16:04:00 -08004227 flags: []string{"-install-ddos-callback"},
4228 resumeSession: resume,
4229 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004230 testCases = append(testCases, testCase{
4231 testType: serverTest,
4232 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4233 config: Config{
4234 MaxVersion: VersionTLS13,
4235 },
4236 flags: []string{"-install-ddos-callback"},
4237 resumeSession: resume,
4238 })
Adam Langley524e7172015-02-20 16:04:00 -08004239
4240 failFlag := "-fail-ddos-callback"
4241 if resume {
4242 failFlag = "-fail-second-ddos-callback"
4243 }
4244 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004245 testType: serverTest,
4246 name: "Server-DDoS-Reject-" + suffix,
4247 config: Config{
4248 MaxVersion: VersionTLS12,
4249 },
David Benjamin2c66e072016-09-16 15:58:00 -04004250 flags: []string{"-install-ddos-callback", failFlag},
4251 resumeSession: resume,
4252 shouldFail: true,
4253 expectedError: ":CONNECTION_REJECTED:",
4254 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004255 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004256 testCases = append(testCases, testCase{
4257 testType: serverTest,
4258 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4259 config: Config{
4260 MaxVersion: VersionTLS13,
4261 },
David Benjamin2c66e072016-09-16 15:58:00 -04004262 flags: []string{"-install-ddos-callback", failFlag},
4263 resumeSession: resume,
4264 shouldFail: true,
4265 expectedError: ":CONNECTION_REJECTED:",
4266 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004267 })
Adam Langley524e7172015-02-20 16:04:00 -08004268 }
4269}
4270
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004271func addVersionNegotiationTests() {
4272 for i, shimVers := range tlsVersions {
4273 // Assemble flags to disable all newer versions on the shim.
4274 var flags []string
4275 for _, vers := range tlsVersions[i+1:] {
4276 flags = append(flags, vers.flag)
4277 }
4278
Steven Valdezfdd10992016-09-15 16:27:05 -04004279 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004280 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004281 protocols := []protocol{tls}
4282 if runnerVers.hasDTLS && shimVers.hasDTLS {
4283 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004284 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004285 for _, protocol := range protocols {
4286 expectedVersion := shimVers.version
4287 if runnerVers.version < shimVers.version {
4288 expectedVersion = runnerVers.version
4289 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004290
David Benjamin8b8c0062014-11-23 02:47:52 -05004291 suffix := shimVers.name + "-" + runnerVers.name
4292 if protocol == dtls {
4293 suffix += "-DTLS"
4294 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004295
David Benjamin1eb367c2014-12-12 18:17:51 -05004296 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4297
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004298 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004299 clientVers := shimVers.version
4300 if clientVers > VersionTLS10 {
4301 clientVers = VersionTLS10
4302 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004303 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004304 serverVers := expectedVersion
4305 if expectedVersion >= VersionTLS13 {
4306 serverVers = VersionTLS10
4307 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004308 serverVers = versionToWire(serverVers, protocol == dtls)
4309
David Benjamin8b8c0062014-11-23 02:47:52 -05004310 testCases = append(testCases, testCase{
4311 protocol: protocol,
4312 testType: clientTest,
4313 name: "VersionNegotiation-Client-" + suffix,
4314 config: Config{
4315 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004316 Bugs: ProtocolBugs{
4317 ExpectInitialRecordVersion: clientVers,
4318 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004319 },
4320 flags: flags,
4321 expectedVersion: expectedVersion,
4322 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004323 testCases = append(testCases, testCase{
4324 protocol: protocol,
4325 testType: clientTest,
4326 name: "VersionNegotiation-Client2-" + suffix,
4327 config: Config{
4328 MaxVersion: runnerVers.version,
4329 Bugs: ProtocolBugs{
4330 ExpectInitialRecordVersion: clientVers,
4331 },
4332 },
4333 flags: []string{"-max-version", shimVersFlag},
4334 expectedVersion: expectedVersion,
4335 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004336
4337 testCases = append(testCases, testCase{
4338 protocol: protocol,
4339 testType: serverTest,
4340 name: "VersionNegotiation-Server-" + suffix,
4341 config: Config{
4342 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004343 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004344 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004345 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004346 },
4347 flags: flags,
4348 expectedVersion: expectedVersion,
4349 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004350 testCases = append(testCases, testCase{
4351 protocol: protocol,
4352 testType: serverTest,
4353 name: "VersionNegotiation-Server2-" + suffix,
4354 config: Config{
4355 MaxVersion: runnerVers.version,
4356 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004357 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004358 },
4359 },
4360 flags: []string{"-max-version", shimVersFlag},
4361 expectedVersion: expectedVersion,
4362 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004363 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004364 }
4365 }
David Benjamin95c69562016-06-29 18:15:03 -04004366
Steven Valdezfdd10992016-09-15 16:27:05 -04004367 // Test the version extension at all versions.
4368 for _, vers := range tlsVersions {
4369 protocols := []protocol{tls}
4370 if vers.hasDTLS {
4371 protocols = append(protocols, dtls)
4372 }
4373 for _, protocol := range protocols {
4374 suffix := vers.name
4375 if protocol == dtls {
4376 suffix += "-DTLS"
4377 }
4378
4379 wireVersion := versionToWire(vers.version, protocol == dtls)
4380 testCases = append(testCases, testCase{
4381 protocol: protocol,
4382 testType: serverTest,
4383 name: "VersionNegotiationExtension-" + suffix,
4384 config: Config{
4385 Bugs: ProtocolBugs{
4386 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4387 },
4388 },
4389 expectedVersion: vers.version,
4390 })
4391 }
4392
4393 }
4394
4395 // If all versions are unknown, negotiation fails.
4396 testCases = append(testCases, testCase{
4397 testType: serverTest,
4398 name: "NoSupportedVersions",
4399 config: Config{
4400 Bugs: ProtocolBugs{
4401 SendSupportedVersions: []uint16{0x1111},
4402 },
4403 },
4404 shouldFail: true,
4405 expectedError: ":UNSUPPORTED_PROTOCOL:",
4406 })
4407 testCases = append(testCases, testCase{
4408 protocol: dtls,
4409 testType: serverTest,
4410 name: "NoSupportedVersions-DTLS",
4411 config: Config{
4412 Bugs: ProtocolBugs{
4413 SendSupportedVersions: []uint16{0x1111},
4414 },
4415 },
4416 shouldFail: true,
4417 expectedError: ":UNSUPPORTED_PROTOCOL:",
4418 })
4419
4420 testCases = append(testCases, testCase{
4421 testType: serverTest,
4422 name: "ClientHelloVersionTooHigh",
4423 config: Config{
4424 MaxVersion: VersionTLS13,
4425 Bugs: ProtocolBugs{
4426 SendClientVersion: 0x0304,
4427 OmitSupportedVersions: true,
4428 },
4429 },
4430 expectedVersion: VersionTLS12,
4431 })
4432
4433 testCases = append(testCases, testCase{
4434 testType: serverTest,
4435 name: "ConflictingVersionNegotiation",
4436 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004437 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004438 SendClientVersion: VersionTLS12,
4439 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004440 },
4441 },
David Benjaminad75a662016-09-30 15:42:59 -04004442 // The extension takes precedence over the ClientHello version.
4443 expectedVersion: VersionTLS11,
4444 })
4445
4446 testCases = append(testCases, testCase{
4447 testType: serverTest,
4448 name: "ConflictingVersionNegotiation-2",
4449 config: Config{
4450 Bugs: ProtocolBugs{
4451 SendClientVersion: VersionTLS11,
4452 SendSupportedVersions: []uint16{VersionTLS12},
4453 },
4454 },
4455 // The extension takes precedence over the ClientHello version.
4456 expectedVersion: VersionTLS12,
4457 })
4458
4459 testCases = append(testCases, testCase{
4460 testType: serverTest,
4461 name: "RejectFinalTLS13",
4462 config: Config{
4463 Bugs: ProtocolBugs{
4464 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4465 },
4466 },
4467 // We currently implement a draft TLS 1.3 version. Ensure that
4468 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004469 expectedVersion: VersionTLS12,
4470 })
4471
Brian Smithf85d3232016-10-28 10:34:06 -10004472 // Test that the maximum version is selected regardless of the
4473 // client-sent order.
4474 testCases = append(testCases, testCase{
4475 testType: serverTest,
4476 name: "IgnoreClientVersionOrder",
4477 config: Config{
4478 Bugs: ProtocolBugs{
4479 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4480 },
4481 },
4482 expectedVersion: VersionTLS13,
4483 })
4484
David Benjamin95c69562016-06-29 18:15:03 -04004485 // Test for version tolerance.
4486 testCases = append(testCases, testCase{
4487 testType: serverTest,
4488 name: "MinorVersionTolerance",
4489 config: Config{
4490 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004491 SendClientVersion: 0x03ff,
4492 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004493 },
4494 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004495 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004496 })
4497 testCases = append(testCases, testCase{
4498 testType: serverTest,
4499 name: "MajorVersionTolerance",
4500 config: Config{
4501 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004502 SendClientVersion: 0x0400,
4503 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004504 },
4505 },
David Benjaminad75a662016-09-30 15:42:59 -04004506 // TLS 1.3 must be negotiated with the supported_versions
4507 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004508 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004509 })
David Benjaminad75a662016-09-30 15:42:59 -04004510 testCases = append(testCases, testCase{
4511 testType: serverTest,
4512 name: "VersionTolerance-TLS13",
4513 config: Config{
4514 Bugs: ProtocolBugs{
4515 // Although TLS 1.3 does not use
4516 // ClientHello.version, it still tolerates high
4517 // values there.
4518 SendClientVersion: 0x0400,
4519 },
4520 },
4521 expectedVersion: VersionTLS13,
4522 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004523
David Benjamin95c69562016-06-29 18:15:03 -04004524 testCases = append(testCases, testCase{
4525 protocol: dtls,
4526 testType: serverTest,
4527 name: "MinorVersionTolerance-DTLS",
4528 config: Config{
4529 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004530 SendClientVersion: 0xfe00,
4531 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004532 },
4533 },
4534 expectedVersion: VersionTLS12,
4535 })
4536 testCases = append(testCases, testCase{
4537 protocol: dtls,
4538 testType: serverTest,
4539 name: "MajorVersionTolerance-DTLS",
4540 config: Config{
4541 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004542 SendClientVersion: 0xfdff,
4543 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004544 },
4545 },
4546 expectedVersion: VersionTLS12,
4547 })
4548
4549 // Test that versions below 3.0 are rejected.
4550 testCases = append(testCases, testCase{
4551 testType: serverTest,
4552 name: "VersionTooLow",
4553 config: Config{
4554 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004555 SendClientVersion: 0x0200,
4556 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004557 },
4558 },
4559 shouldFail: true,
4560 expectedError: ":UNSUPPORTED_PROTOCOL:",
4561 })
4562 testCases = append(testCases, testCase{
4563 protocol: dtls,
4564 testType: serverTest,
4565 name: "VersionTooLow-DTLS",
4566 config: Config{
4567 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004568 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004569 },
4570 },
4571 shouldFail: true,
4572 expectedError: ":UNSUPPORTED_PROTOCOL:",
4573 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004574
David Benjamin2dc02042016-09-19 19:57:37 -04004575 testCases = append(testCases, testCase{
4576 name: "ServerBogusVersion",
4577 config: Config{
4578 Bugs: ProtocolBugs{
4579 SendServerHelloVersion: 0x1234,
4580 },
4581 },
4582 shouldFail: true,
4583 expectedError: ":UNSUPPORTED_PROTOCOL:",
4584 })
4585
David Benjamin1f61f0d2016-07-10 12:20:35 -04004586 // Test TLS 1.3's downgrade signal.
4587 testCases = append(testCases, testCase{
4588 name: "Downgrade-TLS12-Client",
4589 config: Config{
4590 Bugs: ProtocolBugs{
4591 NegotiateVersion: VersionTLS12,
4592 },
4593 },
David Benjamin592b5322016-09-30 15:15:01 -04004594 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004595 // TODO(davidben): This test should fail once TLS 1.3 is final
4596 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004597 })
4598 testCases = append(testCases, testCase{
4599 testType: serverTest,
4600 name: "Downgrade-TLS12-Server",
4601 config: Config{
4602 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004603 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004604 },
4605 },
David Benjamin592b5322016-09-30 15:15:01 -04004606 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004607 // TODO(davidben): This test should fail once TLS 1.3 is final
4608 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004609 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004610}
4611
David Benjaminaccb4542014-12-12 23:44:33 -05004612func addMinimumVersionTests() {
4613 for i, shimVers := range tlsVersions {
4614 // Assemble flags to disable all older versions on the shim.
4615 var flags []string
4616 for _, vers := range tlsVersions[:i] {
4617 flags = append(flags, vers.flag)
4618 }
4619
4620 for _, runnerVers := range tlsVersions {
4621 protocols := []protocol{tls}
4622 if runnerVers.hasDTLS && shimVers.hasDTLS {
4623 protocols = append(protocols, dtls)
4624 }
4625 for _, protocol := range protocols {
4626 suffix := shimVers.name + "-" + runnerVers.name
4627 if protocol == dtls {
4628 suffix += "-DTLS"
4629 }
4630 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4631
David Benjaminaccb4542014-12-12 23:44:33 -05004632 var expectedVersion uint16
4633 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004634 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004635 if runnerVers.version >= shimVers.version {
4636 expectedVersion = runnerVers.version
4637 } else {
4638 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004639 expectedError = ":UNSUPPORTED_PROTOCOL:"
4640 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004641 }
4642
4643 testCases = append(testCases, testCase{
4644 protocol: protocol,
4645 testType: clientTest,
4646 name: "MinimumVersion-Client-" + suffix,
4647 config: Config{
4648 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004649 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004650 // Ensure the server does not decline to
4651 // select a version (versions extension) or
4652 // cipher (some ciphers depend on versions).
4653 NegotiateVersion: runnerVers.version,
4654 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004655 },
David Benjaminaccb4542014-12-12 23:44:33 -05004656 },
David Benjamin87909c02014-12-13 01:55:01 -05004657 flags: flags,
4658 expectedVersion: expectedVersion,
4659 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004660 expectedError: expectedError,
4661 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004662 })
4663 testCases = append(testCases, testCase{
4664 protocol: protocol,
4665 testType: clientTest,
4666 name: "MinimumVersion-Client2-" + suffix,
4667 config: Config{
4668 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004669 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004670 // Ensure the server does not decline to
4671 // select a version (versions extension) or
4672 // cipher (some ciphers depend on versions).
4673 NegotiateVersion: runnerVers.version,
4674 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004675 },
David Benjaminaccb4542014-12-12 23:44:33 -05004676 },
David Benjamin87909c02014-12-13 01:55:01 -05004677 flags: []string{"-min-version", shimVersFlag},
4678 expectedVersion: expectedVersion,
4679 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004680 expectedError: expectedError,
4681 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004682 })
4683
4684 testCases = append(testCases, testCase{
4685 protocol: protocol,
4686 testType: serverTest,
4687 name: "MinimumVersion-Server-" + suffix,
4688 config: Config{
4689 MaxVersion: runnerVers.version,
4690 },
David Benjamin87909c02014-12-13 01:55:01 -05004691 flags: flags,
4692 expectedVersion: expectedVersion,
4693 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004694 expectedError: expectedError,
4695 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004696 })
4697 testCases = append(testCases, testCase{
4698 protocol: protocol,
4699 testType: serverTest,
4700 name: "MinimumVersion-Server2-" + suffix,
4701 config: Config{
4702 MaxVersion: runnerVers.version,
4703 },
David Benjamin87909c02014-12-13 01:55:01 -05004704 flags: []string{"-min-version", shimVersFlag},
4705 expectedVersion: expectedVersion,
4706 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004707 expectedError: expectedError,
4708 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004709 })
4710 }
4711 }
4712 }
4713}
4714
David Benjamine78bfde2014-09-06 12:45:15 -04004715func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004716 // TODO(davidben): Extensions, where applicable, all move their server
4717 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4718 // tests for both. Also test interaction with 0-RTT when implemented.
4719
David Benjamin97d17d92016-07-14 16:12:00 -04004720 // Repeat extensions tests all versions except SSL 3.0.
4721 for _, ver := range tlsVersions {
4722 if ver.version == VersionSSL30 {
4723 continue
4724 }
4725
David Benjamin97d17d92016-07-14 16:12:00 -04004726 // Test that duplicate extensions are rejected.
4727 testCases = append(testCases, testCase{
4728 testType: clientTest,
4729 name: "DuplicateExtensionClient-" + ver.name,
4730 config: Config{
4731 MaxVersion: ver.version,
4732 Bugs: ProtocolBugs{
4733 DuplicateExtension: true,
4734 },
David Benjamine78bfde2014-09-06 12:45:15 -04004735 },
David Benjamin97d17d92016-07-14 16:12:00 -04004736 shouldFail: true,
4737 expectedLocalError: "remote error: error decoding message",
4738 })
4739 testCases = append(testCases, testCase{
4740 testType: serverTest,
4741 name: "DuplicateExtensionServer-" + ver.name,
4742 config: Config{
4743 MaxVersion: ver.version,
4744 Bugs: ProtocolBugs{
4745 DuplicateExtension: true,
4746 },
David Benjamine78bfde2014-09-06 12:45:15 -04004747 },
David Benjamin97d17d92016-07-14 16:12:00 -04004748 shouldFail: true,
4749 expectedLocalError: "remote error: error decoding message",
4750 })
4751
4752 // Test SNI.
4753 testCases = append(testCases, testCase{
4754 testType: clientTest,
4755 name: "ServerNameExtensionClient-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 Bugs: ProtocolBugs{
4759 ExpectServerName: "example.com",
4760 },
David Benjamine78bfde2014-09-06 12:45:15 -04004761 },
David Benjamin97d17d92016-07-14 16:12:00 -04004762 flags: []string{"-host-name", "example.com"},
4763 })
4764 testCases = append(testCases, testCase{
4765 testType: clientTest,
4766 name: "ServerNameExtensionClientMismatch-" + ver.name,
4767 config: Config{
4768 MaxVersion: ver.version,
4769 Bugs: ProtocolBugs{
4770 ExpectServerName: "mismatch.com",
4771 },
David Benjamine78bfde2014-09-06 12:45:15 -04004772 },
David Benjamin97d17d92016-07-14 16:12:00 -04004773 flags: []string{"-host-name", "example.com"},
4774 shouldFail: true,
4775 expectedLocalError: "tls: unexpected server name",
4776 })
4777 testCases = append(testCases, testCase{
4778 testType: clientTest,
4779 name: "ServerNameExtensionClientMissing-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 Bugs: ProtocolBugs{
4783 ExpectServerName: "missing.com",
4784 },
David Benjamine78bfde2014-09-06 12:45:15 -04004785 },
David Benjamin97d17d92016-07-14 16:12:00 -04004786 shouldFail: true,
4787 expectedLocalError: "tls: unexpected server name",
4788 })
4789 testCases = append(testCases, testCase{
4790 testType: serverTest,
4791 name: "ServerNameExtensionServer-" + ver.name,
4792 config: Config{
4793 MaxVersion: ver.version,
4794 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004795 },
David Benjamin97d17d92016-07-14 16:12:00 -04004796 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004797 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004798 })
4799
4800 // Test ALPN.
4801 testCases = append(testCases, testCase{
4802 testType: clientTest,
4803 name: "ALPNClient-" + ver.name,
4804 config: Config{
4805 MaxVersion: ver.version,
4806 NextProtos: []string{"foo"},
4807 },
4808 flags: []string{
4809 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4810 "-expect-alpn", "foo",
4811 },
4812 expectedNextProto: "foo",
4813 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004814 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004815 })
4816 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004817 testType: clientTest,
4818 name: "ALPNClient-Mismatch-" + ver.name,
4819 config: Config{
4820 MaxVersion: ver.version,
4821 Bugs: ProtocolBugs{
4822 SendALPN: "baz",
4823 },
4824 },
4825 flags: []string{
4826 "-advertise-alpn", "\x03foo\x03bar",
4827 },
4828 shouldFail: true,
4829 expectedError: ":INVALID_ALPN_PROTOCOL:",
4830 expectedLocalError: "remote error: illegal parameter",
4831 })
4832 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004833 testType: serverTest,
4834 name: "ALPNServer-" + ver.name,
4835 config: Config{
4836 MaxVersion: ver.version,
4837 NextProtos: []string{"foo", "bar", "baz"},
4838 },
4839 flags: []string{
4840 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4841 "-select-alpn", "foo",
4842 },
4843 expectedNextProto: "foo",
4844 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004845 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004846 })
4847 testCases = append(testCases, testCase{
4848 testType: serverTest,
4849 name: "ALPNServer-Decline-" + ver.name,
4850 config: Config{
4851 MaxVersion: ver.version,
4852 NextProtos: []string{"foo", "bar", "baz"},
4853 },
4854 flags: []string{"-decline-alpn"},
4855 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004856 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004857 })
4858
David Benjamin25fe85b2016-08-09 20:00:32 -04004859 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4860 // called once.
4861 testCases = append(testCases, testCase{
4862 testType: serverTest,
4863 name: "ALPNServer-Async-" + ver.name,
4864 config: Config{
4865 MaxVersion: ver.version,
4866 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004867 // Prior to TLS 1.3, exercise the asynchronous session callback.
4868 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004869 },
4870 flags: []string{
4871 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4872 "-select-alpn", "foo",
4873 "-async",
4874 },
4875 expectedNextProto: "foo",
4876 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004877 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004878 })
4879
David Benjamin97d17d92016-07-14 16:12:00 -04004880 var emptyString string
4881 testCases = append(testCases, testCase{
4882 testType: clientTest,
4883 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4884 config: Config{
4885 MaxVersion: ver.version,
4886 NextProtos: []string{""},
4887 Bugs: ProtocolBugs{
4888 // A server returning an empty ALPN protocol
4889 // should be rejected.
4890 ALPNProtocol: &emptyString,
4891 },
4892 },
4893 flags: []string{
4894 "-advertise-alpn", "\x03foo",
4895 },
4896 shouldFail: true,
4897 expectedError: ":PARSE_TLSEXT:",
4898 })
4899 testCases = append(testCases, testCase{
4900 testType: serverTest,
4901 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4902 config: Config{
4903 MaxVersion: ver.version,
4904 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004905 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004906 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004907 },
David Benjamin97d17d92016-07-14 16:12:00 -04004908 flags: []string{
4909 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004910 },
David Benjamin97d17d92016-07-14 16:12:00 -04004911 shouldFail: true,
4912 expectedError: ":PARSE_TLSEXT:",
4913 })
4914
4915 // Test NPN and the interaction with ALPN.
4916 if ver.version < VersionTLS13 {
4917 // Test that the server prefers ALPN over NPN.
4918 testCases = append(testCases, testCase{
4919 testType: serverTest,
4920 name: "ALPNServer-Preferred-" + ver.name,
4921 config: Config{
4922 MaxVersion: ver.version,
4923 NextProtos: []string{"foo", "bar", "baz"},
4924 },
4925 flags: []string{
4926 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4927 "-select-alpn", "foo",
4928 "-advertise-npn", "\x03foo\x03bar\x03baz",
4929 },
4930 expectedNextProto: "foo",
4931 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004932 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004933 })
4934 testCases = append(testCases, testCase{
4935 testType: serverTest,
4936 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4937 config: Config{
4938 MaxVersion: ver.version,
4939 NextProtos: []string{"foo", "bar", "baz"},
4940 Bugs: ProtocolBugs{
4941 SwapNPNAndALPN: true,
4942 },
4943 },
4944 flags: []string{
4945 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4946 "-select-alpn", "foo",
4947 "-advertise-npn", "\x03foo\x03bar\x03baz",
4948 },
4949 expectedNextProto: "foo",
4950 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004951 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004952 })
4953
4954 // Test that negotiating both NPN and ALPN is forbidden.
4955 testCases = append(testCases, testCase{
4956 name: "NegotiateALPNAndNPN-" + ver.name,
4957 config: Config{
4958 MaxVersion: ver.version,
4959 NextProtos: []string{"foo", "bar", "baz"},
4960 Bugs: ProtocolBugs{
4961 NegotiateALPNAndNPN: true,
4962 },
4963 },
4964 flags: []string{
4965 "-advertise-alpn", "\x03foo",
4966 "-select-next-proto", "foo",
4967 },
4968 shouldFail: true,
4969 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4970 })
4971 testCases = append(testCases, testCase{
4972 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4973 config: Config{
4974 MaxVersion: ver.version,
4975 NextProtos: []string{"foo", "bar", "baz"},
4976 Bugs: ProtocolBugs{
4977 NegotiateALPNAndNPN: true,
4978 SwapNPNAndALPN: true,
4979 },
4980 },
4981 flags: []string{
4982 "-advertise-alpn", "\x03foo",
4983 "-select-next-proto", "foo",
4984 },
4985 shouldFail: true,
4986 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4987 })
4988
4989 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4990 testCases = append(testCases, testCase{
4991 name: "DisableNPN-" + ver.name,
4992 config: Config{
4993 MaxVersion: ver.version,
4994 NextProtos: []string{"foo"},
4995 },
4996 flags: []string{
4997 "-select-next-proto", "foo",
4998 "-disable-npn",
4999 },
5000 expectNoNextProto: true,
5001 })
5002 }
5003
5004 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005005
5006 // Resume with a corrupt ticket.
5007 testCases = append(testCases, testCase{
5008 testType: serverTest,
5009 name: "CorruptTicket-" + ver.name,
5010 config: Config{
5011 MaxVersion: ver.version,
5012 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005013 FilterTicket: func(in []byte) ([]byte, error) {
5014 in[len(in)-1] ^= 1
5015 return in, nil
5016 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005017 },
5018 },
5019 resumeSession: true,
5020 expectResumeRejected: true,
5021 })
5022 // Test the ticket callback, with and without renewal.
5023 testCases = append(testCases, testCase{
5024 testType: serverTest,
5025 name: "TicketCallback-" + ver.name,
5026 config: Config{
5027 MaxVersion: ver.version,
5028 },
5029 resumeSession: true,
5030 flags: []string{"-use-ticket-callback"},
5031 })
5032 testCases = append(testCases, testCase{
5033 testType: serverTest,
5034 name: "TicketCallback-Renew-" + ver.name,
5035 config: Config{
5036 MaxVersion: ver.version,
5037 Bugs: ProtocolBugs{
5038 ExpectNewTicket: true,
5039 },
5040 },
5041 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5042 resumeSession: true,
5043 })
5044
5045 // Test that the ticket callback is only called once when everything before
5046 // it in the ClientHello is asynchronous. This corrupts the ticket so
5047 // certificate selection callbacks run.
5048 testCases = append(testCases, testCase{
5049 testType: serverTest,
5050 name: "TicketCallback-SingleCall-" + ver.name,
5051 config: Config{
5052 MaxVersion: ver.version,
5053 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005054 FilterTicket: func(in []byte) ([]byte, error) {
5055 in[len(in)-1] ^= 1
5056 return in, nil
5057 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005058 },
5059 },
5060 resumeSession: true,
5061 expectResumeRejected: true,
5062 flags: []string{
5063 "-use-ticket-callback",
5064 "-async",
5065 },
5066 })
5067
5068 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005069 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005070 testCases = append(testCases, testCase{
5071 testType: serverTest,
5072 name: "OversizedSessionId-" + ver.name,
5073 config: Config{
5074 MaxVersion: ver.version,
5075 Bugs: ProtocolBugs{
5076 OversizedSessionId: true,
5077 },
5078 },
5079 resumeSession: true,
5080 shouldFail: true,
5081 expectedError: ":DECODE_ERROR:",
5082 })
5083 }
5084
5085 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5086 // are ignored.
5087 if ver.hasDTLS {
5088 testCases = append(testCases, testCase{
5089 protocol: dtls,
5090 name: "SRTP-Client-" + ver.name,
5091 config: Config{
5092 MaxVersion: ver.version,
5093 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5094 },
5095 flags: []string{
5096 "-srtp-profiles",
5097 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5098 },
5099 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5100 })
5101 testCases = append(testCases, testCase{
5102 protocol: dtls,
5103 testType: serverTest,
5104 name: "SRTP-Server-" + ver.name,
5105 config: Config{
5106 MaxVersion: ver.version,
5107 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5108 },
5109 flags: []string{
5110 "-srtp-profiles",
5111 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5112 },
5113 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5114 })
5115 // Test that the MKI is ignored.
5116 testCases = append(testCases, testCase{
5117 protocol: dtls,
5118 testType: serverTest,
5119 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5120 config: Config{
5121 MaxVersion: ver.version,
5122 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5123 Bugs: ProtocolBugs{
5124 SRTPMasterKeyIdentifer: "bogus",
5125 },
5126 },
5127 flags: []string{
5128 "-srtp-profiles",
5129 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5130 },
5131 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5132 })
5133 // Test that SRTP isn't negotiated on the server if there were
5134 // no matching profiles.
5135 testCases = append(testCases, testCase{
5136 protocol: dtls,
5137 testType: serverTest,
5138 name: "SRTP-Server-NoMatch-" + ver.name,
5139 config: Config{
5140 MaxVersion: ver.version,
5141 SRTPProtectionProfiles: []uint16{100, 101, 102},
5142 },
5143 flags: []string{
5144 "-srtp-profiles",
5145 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5146 },
5147 expectedSRTPProtectionProfile: 0,
5148 })
5149 // Test that the server returning an invalid SRTP profile is
5150 // flagged as an error by the client.
5151 testCases = append(testCases, testCase{
5152 protocol: dtls,
5153 name: "SRTP-Client-NoMatch-" + ver.name,
5154 config: Config{
5155 MaxVersion: ver.version,
5156 Bugs: ProtocolBugs{
5157 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5158 },
5159 },
5160 flags: []string{
5161 "-srtp-profiles",
5162 "SRTP_AES128_CM_SHA1_80",
5163 },
5164 shouldFail: true,
5165 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5166 })
5167 }
5168
5169 // Test SCT list.
5170 testCases = append(testCases, testCase{
5171 name: "SignedCertificateTimestampList-Client-" + ver.name,
5172 testType: clientTest,
5173 config: Config{
5174 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005175 },
David Benjamin97d17d92016-07-14 16:12:00 -04005176 flags: []string{
5177 "-enable-signed-cert-timestamps",
5178 "-expect-signed-cert-timestamps",
5179 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005180 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005181 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005182 })
David Benjamindaa88502016-10-04 16:32:16 -04005183
Adam Langleycfa08c32016-11-17 13:21:27 -08005184 var differentSCTList []byte
5185 differentSCTList = append(differentSCTList, testSCTList...)
5186 differentSCTList[len(differentSCTList)-1] ^= 1
5187
David Benjamindaa88502016-10-04 16:32:16 -04005188 // The SCT extension did not specify that it must only be sent on resumption as it
5189 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005190 testCases = append(testCases, testCase{
5191 name: "SendSCTListOnResume-" + ver.name,
5192 config: Config{
5193 MaxVersion: ver.version,
5194 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005195 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005196 },
David Benjamind98452d2015-06-16 14:16:23 -04005197 },
David Benjamin97d17d92016-07-14 16:12:00 -04005198 flags: []string{
5199 "-enable-signed-cert-timestamps",
5200 "-expect-signed-cert-timestamps",
5201 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005202 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005203 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005204 })
David Benjamindaa88502016-10-04 16:32:16 -04005205
David Benjamin97d17d92016-07-14 16:12:00 -04005206 testCases = append(testCases, testCase{
5207 name: "SignedCertificateTimestampList-Server-" + ver.name,
5208 testType: serverTest,
5209 config: Config{
5210 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005211 },
David Benjamin97d17d92016-07-14 16:12:00 -04005212 flags: []string{
5213 "-signed-cert-timestamps",
5214 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005215 },
David Benjamin97d17d92016-07-14 16:12:00 -04005216 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005217 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005218 })
David Benjamin53210cb2016-11-16 09:01:48 +09005219
Adam Langleycfa08c32016-11-17 13:21:27 -08005220 emptySCTListCert := *testCerts[0].cert
5221 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5222
5223 // Test empty SCT list.
5224 testCases = append(testCases, testCase{
5225 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5226 testType: clientTest,
5227 config: Config{
5228 MaxVersion: ver.version,
5229 Certificates: []Certificate{emptySCTListCert},
5230 },
5231 flags: []string{
5232 "-enable-signed-cert-timestamps",
5233 },
5234 shouldFail: true,
5235 expectedError: ":ERROR_PARSING_EXTENSION:",
5236 })
5237
5238 emptySCTCert := *testCerts[0].cert
5239 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5240
5241 // Test empty SCT in non-empty list.
5242 testCases = append(testCases, testCase{
5243 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5244 testType: clientTest,
5245 config: Config{
5246 MaxVersion: ver.version,
5247 Certificates: []Certificate{emptySCTCert},
5248 },
5249 flags: []string{
5250 "-enable-signed-cert-timestamps",
5251 },
5252 shouldFail: true,
5253 expectedError: ":ERROR_PARSING_EXTENSION:",
5254 })
5255
David Benjamin53210cb2016-11-16 09:01:48 +09005256 // Test that certificate-related extensions are not sent unsolicited.
5257 testCases = append(testCases, testCase{
5258 testType: serverTest,
5259 name: "UnsolicitedCertificateExtensions-" + ver.name,
5260 config: Config{
5261 MaxVersion: ver.version,
5262 Bugs: ProtocolBugs{
5263 NoOCSPStapling: true,
5264 NoSignedCertificateTimestamps: true,
5265 },
5266 },
5267 flags: []string{
5268 "-ocsp-response",
5269 base64.StdEncoding.EncodeToString(testOCSPResponse),
5270 "-signed-cert-timestamps",
5271 base64.StdEncoding.EncodeToString(testSCTList),
5272 },
5273 })
David Benjamin97d17d92016-07-14 16:12:00 -04005274 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005275
Paul Lietar4fac72e2015-09-09 13:44:55 +01005276 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005277 testType: clientTest,
5278 name: "ClientHelloPadding",
5279 config: Config{
5280 Bugs: ProtocolBugs{
5281 RequireClientHelloSize: 512,
5282 },
5283 },
5284 // This hostname just needs to be long enough to push the
5285 // ClientHello into F5's danger zone between 256 and 511 bytes
5286 // long.
5287 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5288 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005289
5290 // Extensions should not function in SSL 3.0.
5291 testCases = append(testCases, testCase{
5292 testType: serverTest,
5293 name: "SSLv3Extensions-NoALPN",
5294 config: Config{
5295 MaxVersion: VersionSSL30,
5296 NextProtos: []string{"foo", "bar", "baz"},
5297 },
5298 flags: []string{
5299 "-select-alpn", "foo",
5300 },
5301 expectNoNextProto: true,
5302 })
5303
5304 // Test session tickets separately as they follow a different codepath.
5305 testCases = append(testCases, testCase{
5306 testType: serverTest,
5307 name: "SSLv3Extensions-NoTickets",
5308 config: Config{
5309 MaxVersion: VersionSSL30,
5310 Bugs: ProtocolBugs{
5311 // Historically, session tickets in SSL 3.0
5312 // failed in different ways depending on whether
5313 // the client supported renegotiation_info.
5314 NoRenegotiationInfo: true,
5315 },
5316 },
5317 resumeSession: true,
5318 })
5319 testCases = append(testCases, testCase{
5320 testType: serverTest,
5321 name: "SSLv3Extensions-NoTickets2",
5322 config: Config{
5323 MaxVersion: VersionSSL30,
5324 },
5325 resumeSession: true,
5326 })
5327
5328 // But SSL 3.0 does send and process renegotiation_info.
5329 testCases = append(testCases, testCase{
5330 testType: serverTest,
5331 name: "SSLv3Extensions-RenegotiationInfo",
5332 config: Config{
5333 MaxVersion: VersionSSL30,
5334 Bugs: ProtocolBugs{
5335 RequireRenegotiationInfo: true,
5336 },
5337 },
5338 })
5339 testCases = append(testCases, testCase{
5340 testType: serverTest,
5341 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5342 config: Config{
5343 MaxVersion: VersionSSL30,
5344 Bugs: ProtocolBugs{
5345 NoRenegotiationInfo: true,
5346 SendRenegotiationSCSV: true,
5347 RequireRenegotiationInfo: true,
5348 },
5349 },
5350 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005351
5352 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5353 // in ServerHello.
5354 testCases = append(testCases, testCase{
5355 name: "NPN-Forbidden-TLS13",
5356 config: Config{
5357 MaxVersion: VersionTLS13,
5358 NextProtos: []string{"foo"},
5359 Bugs: ProtocolBugs{
5360 NegotiateNPNAtAllVersions: true,
5361 },
5362 },
5363 flags: []string{"-select-next-proto", "foo"},
5364 shouldFail: true,
5365 expectedError: ":ERROR_PARSING_EXTENSION:",
5366 })
5367 testCases = append(testCases, testCase{
5368 name: "EMS-Forbidden-TLS13",
5369 config: Config{
5370 MaxVersion: VersionTLS13,
5371 Bugs: ProtocolBugs{
5372 NegotiateEMSAtAllVersions: true,
5373 },
5374 },
5375 shouldFail: true,
5376 expectedError: ":ERROR_PARSING_EXTENSION:",
5377 })
5378 testCases = append(testCases, testCase{
5379 name: "RenegotiationInfo-Forbidden-TLS13",
5380 config: Config{
5381 MaxVersion: VersionTLS13,
5382 Bugs: ProtocolBugs{
5383 NegotiateRenegotiationInfoAtAllVersions: true,
5384 },
5385 },
5386 shouldFail: true,
5387 expectedError: ":ERROR_PARSING_EXTENSION:",
5388 })
5389 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005390 name: "Ticket-Forbidden-TLS13",
5391 config: Config{
5392 MaxVersion: VersionTLS12,
5393 },
5394 resumeConfig: &Config{
5395 MaxVersion: VersionTLS13,
5396 Bugs: ProtocolBugs{
5397 AdvertiseTicketExtension: true,
5398 },
5399 },
5400 resumeSession: true,
5401 shouldFail: true,
5402 expectedError: ":ERROR_PARSING_EXTENSION:",
5403 })
5404
5405 // Test that illegal extensions in TLS 1.3 are declined by the server if
5406 // offered in ClientHello. The runner's server will fail if this occurs,
5407 // so we exercise the offering path. (EMS and Renegotiation Info are
5408 // implicit in every test.)
5409 testCases = append(testCases, testCase{
5410 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005411 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005412 config: Config{
5413 MaxVersion: VersionTLS13,
5414 NextProtos: []string{"bar"},
5415 },
5416 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5417 })
David Benjamin196df5b2016-09-21 16:23:27 -04005418
David Benjamindaa88502016-10-04 16:32:16 -04005419 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5420 // tolerated.
5421 testCases = append(testCases, testCase{
5422 name: "SendOCSPResponseOnResume-TLS12",
5423 config: Config{
5424 MaxVersion: VersionTLS12,
5425 Bugs: ProtocolBugs{
5426 SendOCSPResponseOnResume: []byte("bogus"),
5427 },
5428 },
5429 flags: []string{
5430 "-enable-ocsp-stapling",
5431 "-expect-ocsp-response",
5432 base64.StdEncoding.EncodeToString(testOCSPResponse),
5433 },
5434 resumeSession: true,
5435 })
5436
David Benjamindaa88502016-10-04 16:32:16 -04005437 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005438 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005439 config: Config{
5440 MaxVersion: VersionTLS13,
5441 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005442 SendExtensionOnCertificate: testOCSPExtension,
5443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":UNEXPECTED_EXTENSION:",
5447 })
5448
5449 testCases = append(testCases, testCase{
5450 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5451 config: Config{
5452 MaxVersion: VersionTLS13,
5453 Bugs: ProtocolBugs{
5454 SendExtensionOnCertificate: testSCTExtension,
5455 },
5456 },
5457 shouldFail: true,
5458 expectedError: ":UNEXPECTED_EXTENSION:",
5459 })
5460
5461 // Test that extensions on client certificates are never accepted.
5462 testCases = append(testCases, testCase{
5463 name: "SendExtensionOnClientCertificate-TLS13",
5464 testType: serverTest,
5465 config: Config{
5466 MaxVersion: VersionTLS13,
5467 Certificates: []Certificate{rsaCertificate},
5468 Bugs: ProtocolBugs{
5469 SendExtensionOnCertificate: testOCSPExtension,
5470 },
5471 },
5472 flags: []string{
5473 "-enable-ocsp-stapling",
5474 "-require-any-client-certificate",
5475 },
5476 shouldFail: true,
5477 expectedError: ":UNEXPECTED_EXTENSION:",
5478 })
5479
5480 testCases = append(testCases, testCase{
5481 name: "SendUnknownExtensionOnCertificate-TLS13",
5482 config: Config{
5483 MaxVersion: VersionTLS13,
5484 Bugs: ProtocolBugs{
5485 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5486 },
5487 },
5488 shouldFail: true,
5489 expectedError: ":UNEXPECTED_EXTENSION:",
5490 })
5491
Adam Langleycfa08c32016-11-17 13:21:27 -08005492 var differentSCTList []byte
5493 differentSCTList = append(differentSCTList, testSCTList...)
5494 differentSCTList[len(differentSCTList)-1] ^= 1
5495
Steven Valdeza833c352016-11-01 13:39:36 -04005496 // Test that extensions on intermediates are allowed but ignored.
5497 testCases = append(testCases, testCase{
5498 name: "IgnoreExtensionsOnIntermediates-TLS13",
5499 config: Config{
5500 MaxVersion: VersionTLS13,
5501 Certificates: []Certificate{rsaChainCertificate},
5502 Bugs: ProtocolBugs{
5503 // Send different values on the intermediate. This tests
5504 // the intermediate's extensions do not override the
5505 // leaf's.
5506 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005507 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005508 },
5509 },
5510 flags: []string{
5511 "-enable-ocsp-stapling",
5512 "-expect-ocsp-response",
5513 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005514 "-enable-signed-cert-timestamps",
5515 "-expect-signed-cert-timestamps",
5516 base64.StdEncoding.EncodeToString(testSCTList),
5517 },
5518 resumeSession: true,
5519 })
5520
5521 // Test that extensions are not sent on intermediates when configured
5522 // only for a leaf.
5523 testCases = append(testCases, testCase{
5524 testType: serverTest,
5525 name: "SendNoExtensionsOnIntermediate-TLS13",
5526 config: Config{
5527 MaxVersion: VersionTLS13,
5528 Bugs: ProtocolBugs{
5529 ExpectNoExtensionsOnIntermediate: true,
5530 },
5531 },
5532 flags: []string{
5533 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5534 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5535 "-ocsp-response",
5536 base64.StdEncoding.EncodeToString(testOCSPResponse),
5537 "-signed-cert-timestamps",
5538 base64.StdEncoding.EncodeToString(testSCTList),
5539 },
5540 })
5541
5542 // Test that extensions are not sent on client certificates.
5543 testCases = append(testCases, testCase{
5544 name: "SendNoClientCertificateExtensions-TLS13",
5545 config: Config{
5546 MaxVersion: VersionTLS13,
5547 ClientAuth: RequireAnyClientCert,
5548 },
5549 flags: []string{
5550 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5551 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5552 "-ocsp-response",
5553 base64.StdEncoding.EncodeToString(testOCSPResponse),
5554 "-signed-cert-timestamps",
5555 base64.StdEncoding.EncodeToString(testSCTList),
5556 },
5557 })
5558
5559 testCases = append(testCases, testCase{
5560 name: "SendDuplicateExtensionsOnCerts-TLS13",
5561 config: Config{
5562 MaxVersion: VersionTLS13,
5563 Bugs: ProtocolBugs{
5564 SendDuplicateCertExtensions: true,
5565 },
5566 },
5567 flags: []string{
5568 "-enable-ocsp-stapling",
5569 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005570 },
5571 resumeSession: true,
5572 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005573 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005574 })
Adam Langley9b885c52016-11-18 14:21:03 -08005575
5576 testCases = append(testCases, testCase{
5577 name: "SignedCertificateTimestampListInvalid-Server",
5578 testType: serverTest,
5579 flags: []string{
5580 "-signed-cert-timestamps",
5581 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5582 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005583 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005584 expectedError: ":INVALID_SCT_LIST:",
5585 })
David Benjamine78bfde2014-09-06 12:45:15 -04005586}
5587
David Benjamin01fe8202014-09-24 15:21:44 -04005588func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005589 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005590 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005591 // SSL 3.0 does not have tickets and TLS 1.3 does not
5592 // have session IDs, so skip their cross-resumption
5593 // tests.
5594 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5595 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5596 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005597 }
5598
David Benjamin8b8c0062014-11-23 02:47:52 -05005599 protocols := []protocol{tls}
5600 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5601 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005602 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005603 for _, protocol := range protocols {
5604 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5605 if protocol == dtls {
5606 suffix += "-DTLS"
5607 }
5608
David Benjaminece3de92015-03-16 18:02:20 -04005609 if sessionVers.version == resumeVers.version {
5610 testCases = append(testCases, testCase{
5611 protocol: protocol,
5612 name: "Resume-Client" + suffix,
5613 resumeSession: true,
5614 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005615 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005616 Bugs: ProtocolBugs{
5617 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5618 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5619 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005620 },
David Benjaminece3de92015-03-16 18:02:20 -04005621 expectedVersion: sessionVers.version,
5622 expectedResumeVersion: resumeVers.version,
5623 })
5624 } else {
David Benjamin405da482016-08-08 17:25:07 -04005625 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5626
5627 // Offering a TLS 1.3 session sends an empty session ID, so
5628 // there is no way to convince a non-lookahead client the
5629 // session was resumed. It will appear to the client that a
5630 // stray ChangeCipherSpec was sent.
5631 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5632 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005633 }
5634
David Benjaminece3de92015-03-16 18:02:20 -04005635 testCases = append(testCases, testCase{
5636 protocol: protocol,
5637 name: "Resume-Client-Mismatch" + suffix,
5638 resumeSession: true,
5639 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005640 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005641 },
David Benjaminece3de92015-03-16 18:02:20 -04005642 expectedVersion: sessionVers.version,
5643 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005644 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005645 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005646 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005647 },
5648 },
5649 expectedResumeVersion: resumeVers.version,
5650 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005651 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005652 })
5653 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005654
5655 testCases = append(testCases, testCase{
5656 protocol: protocol,
5657 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005658 resumeSession: true,
5659 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005660 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005661 },
5662 expectedVersion: sessionVers.version,
5663 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005664 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005665 },
5666 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005667 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005668 expectedResumeVersion: resumeVers.version,
5669 })
5670
David Benjamin8b8c0062014-11-23 02:47:52 -05005671 testCases = append(testCases, testCase{
5672 protocol: protocol,
5673 testType: serverTest,
5674 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005675 resumeSession: true,
5676 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005677 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005678 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005679 expectedVersion: sessionVers.version,
5680 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005681 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005682 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005683 Bugs: ProtocolBugs{
5684 SendBothTickets: true,
5685 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005686 },
5687 expectedResumeVersion: resumeVers.version,
5688 })
5689 }
David Benjamin01fe8202014-09-24 15:21:44 -04005690 }
5691 }
David Benjaminece3de92015-03-16 18:02:20 -04005692
David Benjamin4199b0d2016-11-01 13:58:25 -04005693 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005694 testCases = append(testCases, testCase{
5695 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005696 name: "ShimTicketRewritable",
5697 resumeSession: true,
5698 config: Config{
5699 MaxVersion: VersionTLS12,
5700 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5701 Bugs: ProtocolBugs{
5702 FilterTicket: func(in []byte) ([]byte, error) {
5703 in, err := SetShimTicketVersion(in, VersionTLS12)
5704 if err != nil {
5705 return nil, err
5706 }
5707 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5708 },
5709 },
5710 },
5711 flags: []string{
5712 "-ticket-key",
5713 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5714 },
5715 })
5716
5717 // Resumptions are declined if the version does not match.
5718 testCases = append(testCases, testCase{
5719 testType: serverTest,
5720 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005721 resumeSession: true,
5722 config: Config{
5723 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005724 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005725 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005726 FilterTicket: func(in []byte) ([]byte, error) {
5727 return SetShimTicketVersion(in, VersionTLS13)
5728 },
5729 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005730 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005731 flags: []string{
5732 "-ticket-key",
5733 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5734 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005735 expectResumeRejected: true,
5736 })
5737
5738 testCases = append(testCases, testCase{
5739 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005740 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005741 resumeSession: true,
5742 config: Config{
5743 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005744 Bugs: ProtocolBugs{
5745 FilterTicket: func(in []byte) ([]byte, error) {
5746 return SetShimTicketVersion(in, VersionTLS12)
5747 },
5748 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005749 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005750 flags: []string{
5751 "-ticket-key",
5752 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5753 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005754 expectResumeRejected: true,
5755 })
5756
David Benjamin4199b0d2016-11-01 13:58:25 -04005757 // Resumptions are declined if the cipher is invalid or disabled.
5758 testCases = append(testCases, testCase{
5759 testType: serverTest,
5760 name: "Resume-Server-DeclineBadCipher",
5761 resumeSession: true,
5762 config: Config{
5763 MaxVersion: VersionTLS12,
5764 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005765 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005766 FilterTicket: func(in []byte) ([]byte, error) {
5767 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5768 },
5769 },
5770 },
5771 flags: []string{
5772 "-ticket-key",
5773 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5774 },
5775 expectResumeRejected: true,
5776 })
5777
5778 testCases = append(testCases, testCase{
5779 testType: serverTest,
5780 name: "Resume-Server-DeclineBadCipher-2",
5781 resumeSession: true,
5782 config: Config{
5783 MaxVersion: VersionTLS12,
5784 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005785 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005786 FilterTicket: func(in []byte) ([]byte, error) {
5787 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5788 },
5789 },
5790 },
5791 flags: []string{
5792 "-cipher", "AES128",
5793 "-ticket-key",
5794 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5795 },
5796 expectResumeRejected: true,
5797 })
5798
David Benjaminf01f42a2016-11-16 19:05:33 +09005799 // Sessions are not resumed if they do not use the preferred cipher.
5800 testCases = append(testCases, testCase{
5801 testType: serverTest,
5802 name: "Resume-Server-CipherNotPreferred",
5803 resumeSession: true,
5804 config: Config{
5805 MaxVersion: VersionTLS12,
5806 Bugs: ProtocolBugs{
5807 ExpectNewTicket: true,
5808 FilterTicket: func(in []byte) ([]byte, error) {
5809 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5810 },
5811 },
5812 },
5813 flags: []string{
5814 "-ticket-key",
5815 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5816 },
5817 shouldFail: false,
5818 expectResumeRejected: true,
5819 })
5820
5821 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5822 // PRF hashes match, but BoringSSL will always decline such resumptions.
5823 testCases = append(testCases, testCase{
5824 testType: serverTest,
5825 name: "Resume-Server-CipherNotPreferred-TLS13",
5826 resumeSession: true,
5827 config: Config{
5828 MaxVersion: VersionTLS13,
5829 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5830 Bugs: ProtocolBugs{
5831 FilterTicket: func(in []byte) ([]byte, error) {
5832 // If the client (runner) offers ChaCha20-Poly1305 first, the
5833 // server (shim) always prefers it. Switch it to AES-GCM.
5834 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5835 },
5836 },
5837 },
5838 flags: []string{
5839 "-ticket-key",
5840 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5841 },
5842 shouldFail: false,
5843 expectResumeRejected: true,
5844 })
5845
5846 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005847 testCases = append(testCases, testCase{
5848 testType: serverTest,
5849 name: "Resume-Server-DeclineBadCipher-TLS13",
5850 resumeSession: true,
5851 config: Config{
5852 MaxVersion: VersionTLS13,
5853 Bugs: ProtocolBugs{
5854 FilterTicket: func(in []byte) ([]byte, error) {
5855 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5856 },
5857 },
5858 },
5859 flags: []string{
5860 "-ticket-key",
5861 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5862 },
5863 expectResumeRejected: true,
5864 })
5865
David Benjaminf01f42a2016-11-16 19:05:33 +09005866 // If the client does not offer the cipher from the session, decline to
5867 // resume. Clients are forbidden from doing this, but BoringSSL selects
5868 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005869 testCases = append(testCases, testCase{
5870 testType: serverTest,
5871 name: "Resume-Server-UnofferedCipher",
5872 resumeSession: true,
5873 config: Config{
5874 MaxVersion: VersionTLS12,
5875 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5876 },
5877 resumeConfig: &Config{
5878 MaxVersion: VersionTLS12,
5879 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5880 Bugs: ProtocolBugs{
5881 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5882 },
5883 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005884 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005885 })
5886
David Benjaminf01f42a2016-11-16 19:05:33 +09005887 // In TLS 1.3, clients may advertise a cipher list which does not
5888 // include the selected cipher. Test that we tolerate this. Servers may
5889 // resume at another cipher if the PRF matches, but BoringSSL will
5890 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005891 testCases = append(testCases, testCase{
5892 testType: serverTest,
5893 name: "Resume-Server-UnofferedCipher-TLS13",
5894 resumeSession: true,
5895 config: Config{
5896 MaxVersion: VersionTLS13,
5897 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5898 },
5899 resumeConfig: &Config{
5900 MaxVersion: VersionTLS13,
5901 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5902 Bugs: ProtocolBugs{
5903 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5904 },
5905 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005906 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005907 })
5908
David Benjamin4199b0d2016-11-01 13:58:25 -04005909 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005910 testCases = append(testCases, testCase{
5911 name: "Resume-Client-CipherMismatch",
5912 resumeSession: true,
5913 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005914 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005915 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5916 },
5917 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005918 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005919 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5920 Bugs: ProtocolBugs{
5921 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5922 },
5923 },
5924 shouldFail: true,
5925 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5926 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005927
David Benjamine1cc35e2016-11-16 16:25:58 +09005928 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5929 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005930 testCases = append(testCases, testCase{
5931 name: "Resume-Client-CipherMismatch-TLS13",
5932 resumeSession: true,
5933 config: Config{
5934 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005935 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005936 },
5937 resumeConfig: &Config{
5938 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005939 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5940 },
5941 })
5942
5943 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5944 testCases = append(testCases, testCase{
5945 name: "Resume-Client-PRFMismatch-TLS13",
5946 resumeSession: true,
5947 config: Config{
5948 MaxVersion: VersionTLS13,
5949 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5950 },
5951 resumeConfig: &Config{
5952 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005953 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005954 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005955 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005956 },
5957 },
5958 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005959 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005960 })
Steven Valdeza833c352016-11-01 13:39:36 -04005961
5962 testCases = append(testCases, testCase{
5963 testType: serverTest,
5964 name: "Resume-Server-BinderWrongLength",
5965 resumeSession: true,
5966 config: Config{
5967 MaxVersion: VersionTLS13,
5968 Bugs: ProtocolBugs{
5969 SendShortPSKBinder: true,
5970 },
5971 },
5972 shouldFail: true,
5973 expectedLocalError: "remote error: error decrypting message",
5974 expectedError: ":DIGEST_CHECK_FAILED:",
5975 })
5976
5977 testCases = append(testCases, testCase{
5978 testType: serverTest,
5979 name: "Resume-Server-NoPSKBinder",
5980 resumeSession: true,
5981 config: Config{
5982 MaxVersion: VersionTLS13,
5983 Bugs: ProtocolBugs{
5984 SendNoPSKBinder: true,
5985 },
5986 },
5987 shouldFail: true,
5988 expectedLocalError: "remote error: error decoding message",
5989 expectedError: ":DECODE_ERROR:",
5990 })
5991
5992 testCases = append(testCases, testCase{
5993 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005994 name: "Resume-Server-ExtraPSKBinder",
5995 resumeSession: true,
5996 config: Config{
5997 MaxVersion: VersionTLS13,
5998 Bugs: ProtocolBugs{
5999 SendExtraPSKBinder: true,
6000 },
6001 },
6002 shouldFail: true,
6003 expectedLocalError: "remote error: illegal parameter",
6004 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6005 })
6006
6007 testCases = append(testCases, testCase{
6008 testType: serverTest,
6009 name: "Resume-Server-ExtraIdentityNoBinder",
6010 resumeSession: true,
6011 config: Config{
6012 MaxVersion: VersionTLS13,
6013 Bugs: ProtocolBugs{
6014 ExtraPSKIdentity: true,
6015 },
6016 },
6017 shouldFail: true,
6018 expectedLocalError: "remote error: illegal parameter",
6019 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6020 })
6021
6022 testCases = append(testCases, testCase{
6023 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006024 name: "Resume-Server-InvalidPSKBinder",
6025 resumeSession: true,
6026 config: Config{
6027 MaxVersion: VersionTLS13,
6028 Bugs: ProtocolBugs{
6029 SendInvalidPSKBinder: true,
6030 },
6031 },
6032 shouldFail: true,
6033 expectedLocalError: "remote error: error decrypting message",
6034 expectedError: ":DIGEST_CHECK_FAILED:",
6035 })
6036
6037 testCases = append(testCases, testCase{
6038 testType: serverTest,
6039 name: "Resume-Server-PSKBinderFirstExtension",
6040 resumeSession: true,
6041 config: Config{
6042 MaxVersion: VersionTLS13,
6043 Bugs: ProtocolBugs{
6044 PSKBinderFirst: true,
6045 },
6046 },
6047 shouldFail: true,
6048 expectedLocalError: "remote error: illegal parameter",
6049 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6050 })
David Benjamin01fe8202014-09-24 15:21:44 -04006051}
6052
Adam Langley2ae77d22014-10-28 17:29:33 -07006053func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006054 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006055 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006056 testType: serverTest,
6057 name: "Renegotiate-Server-Forbidden",
6058 config: Config{
6059 MaxVersion: VersionTLS12,
6060 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006061 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006062 shouldFail: true,
6063 expectedError: ":NO_RENEGOTIATION:",
6064 expectedLocalError: "remote error: no renegotiation",
6065 })
Adam Langley5021b222015-06-12 18:27:58 -07006066 // The server shouldn't echo the renegotiation extension unless
6067 // requested by the client.
6068 testCases = append(testCases, testCase{
6069 testType: serverTest,
6070 name: "Renegotiate-Server-NoExt",
6071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006072 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006073 Bugs: ProtocolBugs{
6074 NoRenegotiationInfo: true,
6075 RequireRenegotiationInfo: true,
6076 },
6077 },
6078 shouldFail: true,
6079 expectedLocalError: "renegotiation extension missing",
6080 })
6081 // The renegotiation SCSV should be sufficient for the server to echo
6082 // the extension.
6083 testCases = append(testCases, testCase{
6084 testType: serverTest,
6085 name: "Renegotiate-Server-NoExt-SCSV",
6086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006087 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006088 Bugs: ProtocolBugs{
6089 NoRenegotiationInfo: true,
6090 SendRenegotiationSCSV: true,
6091 RequireRenegotiationInfo: true,
6092 },
6093 },
6094 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006095 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006096 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006098 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006099 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006100 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006101 },
6102 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006103 renegotiate: 1,
6104 flags: []string{
6105 "-renegotiate-freely",
6106 "-expect-total-renegotiations", "1",
6107 },
David Benjamincdea40c2015-03-19 14:09:43 -04006108 })
6109 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006110 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006111 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006113 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006114 Bugs: ProtocolBugs{
6115 EmptyRenegotiationInfo: true,
6116 },
6117 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006118 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006119 shouldFail: true,
6120 expectedError: ":RENEGOTIATION_MISMATCH:",
6121 })
6122 testCases = append(testCases, testCase{
6123 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006124 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006126 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006127 Bugs: ProtocolBugs{
6128 BadRenegotiationInfo: true,
6129 },
6130 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006131 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006132 shouldFail: true,
6133 expectedError: ":RENEGOTIATION_MISMATCH:",
6134 })
6135 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006136 name: "Renegotiate-Client-Downgrade",
6137 renegotiate: 1,
6138 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006139 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006140 Bugs: ProtocolBugs{
6141 NoRenegotiationInfoAfterInitial: true,
6142 },
6143 },
6144 flags: []string{"-renegotiate-freely"},
6145 shouldFail: true,
6146 expectedError: ":RENEGOTIATION_MISMATCH:",
6147 })
6148 testCases = append(testCases, testCase{
6149 name: "Renegotiate-Client-Upgrade",
6150 renegotiate: 1,
6151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006152 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006153 Bugs: ProtocolBugs{
6154 NoRenegotiationInfoInInitial: true,
6155 },
6156 },
6157 flags: []string{"-renegotiate-freely"},
6158 shouldFail: true,
6159 expectedError: ":RENEGOTIATION_MISMATCH:",
6160 })
6161 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006162 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006163 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006165 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006166 Bugs: ProtocolBugs{
6167 NoRenegotiationInfo: true,
6168 },
6169 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006170 flags: []string{
6171 "-renegotiate-freely",
6172 "-expect-total-renegotiations", "1",
6173 },
David Benjamincff0b902015-05-15 23:09:47 -04006174 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006175
6176 // Test that the server may switch ciphers on renegotiation without
6177 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006178 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006179 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006180 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006181 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006182 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006183 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006184 },
6185 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006186 flags: []string{
6187 "-renegotiate-freely",
6188 "-expect-total-renegotiations", "1",
6189 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006190 })
6191 testCases = append(testCases, testCase{
6192 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006193 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006194 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006195 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006196 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6197 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006198 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006199 flags: []string{
6200 "-renegotiate-freely",
6201 "-expect-total-renegotiations", "1",
6202 },
David Benjaminb16346b2015-04-08 19:16:58 -04006203 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006204
6205 // Test that the server may not switch versions on renegotiation.
6206 testCases = append(testCases, testCase{
6207 name: "Renegotiate-Client-SwitchVersion",
6208 config: Config{
6209 MaxVersion: VersionTLS12,
6210 // Pick a cipher which exists at both versions.
6211 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6212 Bugs: ProtocolBugs{
6213 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006214 // Avoid failing early at the record layer.
6215 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006216 },
6217 },
6218 renegotiate: 1,
6219 flags: []string{
6220 "-renegotiate-freely",
6221 "-expect-total-renegotiations", "1",
6222 },
6223 shouldFail: true,
6224 expectedError: ":WRONG_SSL_VERSION:",
6225 })
6226
David Benjaminb16346b2015-04-08 19:16:58 -04006227 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006228 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006229 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006230 config: Config{
6231 MaxVersion: VersionTLS10,
6232 Bugs: ProtocolBugs{
6233 RequireSameRenegoClientVersion: true,
6234 },
6235 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006236 flags: []string{
6237 "-renegotiate-freely",
6238 "-expect-total-renegotiations", "1",
6239 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006240 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006241 testCases = append(testCases, testCase{
6242 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006243 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006244 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006245 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006246 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6247 NextProtos: []string{"foo"},
6248 },
6249 flags: []string{
6250 "-false-start",
6251 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006252 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006253 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006254 },
6255 shimWritesFirst: true,
6256 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006257
6258 // Client-side renegotiation controls.
6259 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006260 name: "Renegotiate-Client-Forbidden-1",
6261 config: Config{
6262 MaxVersion: VersionTLS12,
6263 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006264 renegotiate: 1,
6265 shouldFail: true,
6266 expectedError: ":NO_RENEGOTIATION:",
6267 expectedLocalError: "remote error: no renegotiation",
6268 })
6269 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006270 name: "Renegotiate-Client-Once-1",
6271 config: Config{
6272 MaxVersion: VersionTLS12,
6273 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006274 renegotiate: 1,
6275 flags: []string{
6276 "-renegotiate-once",
6277 "-expect-total-renegotiations", "1",
6278 },
6279 })
6280 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006281 name: "Renegotiate-Client-Freely-1",
6282 config: Config{
6283 MaxVersion: VersionTLS12,
6284 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006285 renegotiate: 1,
6286 flags: []string{
6287 "-renegotiate-freely",
6288 "-expect-total-renegotiations", "1",
6289 },
6290 })
6291 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006292 name: "Renegotiate-Client-Once-2",
6293 config: Config{
6294 MaxVersion: VersionTLS12,
6295 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006296 renegotiate: 2,
6297 flags: []string{"-renegotiate-once"},
6298 shouldFail: true,
6299 expectedError: ":NO_RENEGOTIATION:",
6300 expectedLocalError: "remote error: no renegotiation",
6301 })
6302 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006303 name: "Renegotiate-Client-Freely-2",
6304 config: Config{
6305 MaxVersion: VersionTLS12,
6306 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006307 renegotiate: 2,
6308 flags: []string{
6309 "-renegotiate-freely",
6310 "-expect-total-renegotiations", "2",
6311 },
6312 })
Adam Langley27a0d082015-11-03 13:34:10 -08006313 testCases = append(testCases, testCase{
6314 name: "Renegotiate-Client-NoIgnore",
6315 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006316 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006317 Bugs: ProtocolBugs{
6318 SendHelloRequestBeforeEveryAppDataRecord: true,
6319 },
6320 },
6321 shouldFail: true,
6322 expectedError: ":NO_RENEGOTIATION:",
6323 })
6324 testCases = append(testCases, testCase{
6325 name: "Renegotiate-Client-Ignore",
6326 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006327 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006328 Bugs: ProtocolBugs{
6329 SendHelloRequestBeforeEveryAppDataRecord: true,
6330 },
6331 },
6332 flags: []string{
6333 "-renegotiate-ignore",
6334 "-expect-total-renegotiations", "0",
6335 },
6336 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006337
David Benjamin34941c02016-10-08 11:45:31 -04006338 // Renegotiation is not allowed at SSL 3.0.
6339 testCases = append(testCases, testCase{
6340 name: "Renegotiate-Client-SSL3",
6341 config: Config{
6342 MaxVersion: VersionSSL30,
6343 },
6344 renegotiate: 1,
6345 flags: []string{
6346 "-renegotiate-freely",
6347 "-expect-total-renegotiations", "1",
6348 },
6349 shouldFail: true,
6350 expectedError: ":NO_RENEGOTIATION:",
6351 expectedLocalError: "remote error: no renegotiation",
6352 })
6353
David Benjamin397c8e62016-07-08 14:14:36 -07006354 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006355 testCases = append(testCases, testCase{
6356 name: "StrayHelloRequest",
6357 config: Config{
6358 MaxVersion: VersionTLS12,
6359 Bugs: ProtocolBugs{
6360 SendHelloRequestBeforeEveryHandshakeMessage: true,
6361 },
6362 },
6363 })
6364 testCases = append(testCases, testCase{
6365 name: "StrayHelloRequest-Packed",
6366 config: Config{
6367 MaxVersion: VersionTLS12,
6368 Bugs: ProtocolBugs{
6369 PackHandshakeFlight: true,
6370 SendHelloRequestBeforeEveryHandshakeMessage: true,
6371 },
6372 },
6373 })
6374
David Benjamin12d2c482016-07-24 10:56:51 -04006375 // Test renegotiation works if HelloRequest and server Finished come in
6376 // the same record.
6377 testCases = append(testCases, testCase{
6378 name: "Renegotiate-Client-Packed",
6379 config: Config{
6380 MaxVersion: VersionTLS12,
6381 Bugs: ProtocolBugs{
6382 PackHandshakeFlight: true,
6383 PackHelloRequestWithFinished: true,
6384 },
6385 },
6386 renegotiate: 1,
6387 flags: []string{
6388 "-renegotiate-freely",
6389 "-expect-total-renegotiations", "1",
6390 },
6391 })
6392
David Benjamin397c8e62016-07-08 14:14:36 -07006393 // Renegotiation is forbidden in TLS 1.3.
6394 testCases = append(testCases, testCase{
6395 name: "Renegotiate-Client-TLS13",
6396 config: Config{
6397 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006398 Bugs: ProtocolBugs{
6399 SendHelloRequestBeforeEveryAppDataRecord: true,
6400 },
David Benjamin397c8e62016-07-08 14:14:36 -07006401 },
David Benjamin397c8e62016-07-08 14:14:36 -07006402 flags: []string{
6403 "-renegotiate-freely",
6404 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006405 shouldFail: true,
6406 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006407 })
6408
6409 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6410 testCases = append(testCases, testCase{
6411 name: "StrayHelloRequest-TLS13",
6412 config: Config{
6413 MaxVersion: VersionTLS13,
6414 Bugs: ProtocolBugs{
6415 SendHelloRequestBeforeEveryHandshakeMessage: true,
6416 },
6417 },
6418 shouldFail: true,
6419 expectedError: ":UNEXPECTED_MESSAGE:",
6420 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006421}
6422
David Benjamin5e961c12014-11-07 01:48:35 -05006423func addDTLSReplayTests() {
6424 // Test that sequence number replays are detected.
6425 testCases = append(testCases, testCase{
6426 protocol: dtls,
6427 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006428 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006429 replayWrites: true,
6430 })
6431
David Benjamin8e6db492015-07-25 18:29:23 -04006432 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006433 // than the retransmit window.
6434 testCases = append(testCases, testCase{
6435 protocol: dtls,
6436 name: "DTLS-Replay-LargeGaps",
6437 config: Config{
6438 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006439 SequenceNumberMapping: func(in uint64) uint64 {
6440 return in * 127
6441 },
David Benjamin5e961c12014-11-07 01:48:35 -05006442 },
6443 },
David Benjamin8e6db492015-07-25 18:29:23 -04006444 messageCount: 200,
6445 replayWrites: true,
6446 })
6447
6448 // Test the incoming sequence number changing non-monotonically.
6449 testCases = append(testCases, testCase{
6450 protocol: dtls,
6451 name: "DTLS-Replay-NonMonotonic",
6452 config: Config{
6453 Bugs: ProtocolBugs{
6454 SequenceNumberMapping: func(in uint64) uint64 {
6455 return in ^ 31
6456 },
6457 },
6458 },
6459 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006460 replayWrites: true,
6461 })
6462}
6463
Nick Harper60edffd2016-06-21 15:19:24 -07006464var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006465 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006466 id signatureAlgorithm
6467 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006468}{
Nick Harper60edffd2016-06-21 15:19:24 -07006469 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6470 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6471 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6472 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006473 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006474 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6475 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6476 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006477 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6478 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6479 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006480 // Tests for key types prior to TLS 1.2.
6481 {"RSA", 0, testCertRSA},
6482 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006483}
6484
Nick Harper60edffd2016-06-21 15:19:24 -07006485const fakeSigAlg1 signatureAlgorithm = 0x2a01
6486const fakeSigAlg2 signatureAlgorithm = 0xff01
6487
6488func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006489 // Not all ciphers involve a signature. Advertise a list which gives all
6490 // versions a signing cipher.
6491 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006492 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006493 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6494 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6495 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6496 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6497 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6498 }
6499
David Benjaminca3d5452016-07-14 12:51:01 -04006500 var allAlgorithms []signatureAlgorithm
6501 for _, alg := range testSignatureAlgorithms {
6502 if alg.id != 0 {
6503 allAlgorithms = append(allAlgorithms, alg.id)
6504 }
6505 }
6506
Nick Harper60edffd2016-06-21 15:19:24 -07006507 // Make sure each signature algorithm works. Include some fake values in
6508 // the list and ensure they're ignored.
6509 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006510 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006511 if (ver.version < VersionTLS12) != (alg.id == 0) {
6512 continue
6513 }
6514
6515 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6516 // or remove it in C.
6517 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006518 continue
6519 }
Nick Harper60edffd2016-06-21 15:19:24 -07006520
David Benjamin3ef76972016-10-17 17:59:54 -04006521 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006522 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006523 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006524 shouldSignFail = true
6525 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006526 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006527 // RSA-PKCS1 does not exist in TLS 1.3.
6528 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006529 shouldSignFail = true
6530 shouldVerifyFail = true
6531 }
6532
6533 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6534 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6535 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006536 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006537
6538 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006539 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006540 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006541 }
6542 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006543 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006544 }
David Benjamin000800a2014-11-14 01:43:59 -05006545
David Benjamin1fb125c2016-07-08 18:52:12 -07006546 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006547
David Benjamin7a41d372016-07-09 11:21:54 -07006548 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006549 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006550 config: Config{
6551 MaxVersion: ver.version,
6552 ClientAuth: RequireAnyClientCert,
6553 VerifySignatureAlgorithms: []signatureAlgorithm{
6554 fakeSigAlg1,
6555 alg.id,
6556 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006557 },
David Benjamin7a41d372016-07-09 11:21:54 -07006558 },
6559 flags: []string{
6560 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6561 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6562 "-enable-all-curves",
6563 },
David Benjamin3ef76972016-10-17 17:59:54 -04006564 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006565 expectedError: signError,
6566 expectedPeerSignatureAlgorithm: alg.id,
6567 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006568
David Benjamin7a41d372016-07-09 11:21:54 -07006569 testCases = append(testCases, testCase{
6570 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006571 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006572 config: Config{
6573 MaxVersion: ver.version,
6574 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6575 SignSignatureAlgorithms: []signatureAlgorithm{
6576 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006577 },
David Benjamin7a41d372016-07-09 11:21:54 -07006578 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006579 SkipECDSACurveCheck: shouldVerifyFail,
6580 IgnoreSignatureVersionChecks: shouldVerifyFail,
6581 // Some signature algorithms may not be advertised.
6582 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006583 },
David Benjamin7a41d372016-07-09 11:21:54 -07006584 },
6585 flags: []string{
6586 "-require-any-client-certificate",
6587 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6588 "-enable-all-curves",
6589 },
David Benjamin3ef76972016-10-17 17:59:54 -04006590 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006591 expectedError: verifyError,
6592 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006593
6594 testCases = append(testCases, testCase{
6595 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006596 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006597 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006598 MaxVersion: ver.version,
6599 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006600 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006601 fakeSigAlg1,
6602 alg.id,
6603 fakeSigAlg2,
6604 },
6605 },
6606 flags: []string{
6607 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6608 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6609 "-enable-all-curves",
6610 },
David Benjamin3ef76972016-10-17 17:59:54 -04006611 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006612 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006613 expectedPeerSignatureAlgorithm: alg.id,
6614 })
6615
6616 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006617 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006618 config: Config{
6619 MaxVersion: ver.version,
6620 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006621 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006622 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006623 alg.id,
6624 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006625 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006626 SkipECDSACurveCheck: shouldVerifyFail,
6627 IgnoreSignatureVersionChecks: shouldVerifyFail,
6628 // Some signature algorithms may not be advertised.
6629 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006630 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006631 },
6632 flags: []string{
6633 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6634 "-enable-all-curves",
6635 },
David Benjamin3ef76972016-10-17 17:59:54 -04006636 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006637 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006638 })
David Benjamin5208fd42016-07-13 21:43:25 -04006639
David Benjamin3ef76972016-10-17 17:59:54 -04006640 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006641 testCases = append(testCases, testCase{
6642 testType: serverTest,
6643 name: "ClientAuth-InvalidSignature" + suffix,
6644 config: Config{
6645 MaxVersion: ver.version,
6646 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6647 SignSignatureAlgorithms: []signatureAlgorithm{
6648 alg.id,
6649 },
6650 Bugs: ProtocolBugs{
6651 InvalidSignature: true,
6652 },
6653 },
6654 flags: []string{
6655 "-require-any-client-certificate",
6656 "-enable-all-curves",
6657 },
6658 shouldFail: true,
6659 expectedError: ":BAD_SIGNATURE:",
6660 })
6661
6662 testCases = append(testCases, testCase{
6663 name: "ServerAuth-InvalidSignature" + suffix,
6664 config: Config{
6665 MaxVersion: ver.version,
6666 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6667 CipherSuites: signingCiphers,
6668 SignSignatureAlgorithms: []signatureAlgorithm{
6669 alg.id,
6670 },
6671 Bugs: ProtocolBugs{
6672 InvalidSignature: true,
6673 },
6674 },
6675 flags: []string{"-enable-all-curves"},
6676 shouldFail: true,
6677 expectedError: ":BAD_SIGNATURE:",
6678 })
6679 }
David Benjaminca3d5452016-07-14 12:51:01 -04006680
David Benjamin3ef76972016-10-17 17:59:54 -04006681 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006682 testCases = append(testCases, testCase{
6683 name: "ClientAuth-Sign-Negotiate" + suffix,
6684 config: Config{
6685 MaxVersion: ver.version,
6686 ClientAuth: RequireAnyClientCert,
6687 VerifySignatureAlgorithms: allAlgorithms,
6688 },
6689 flags: []string{
6690 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6691 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6692 "-enable-all-curves",
6693 "-signing-prefs", strconv.Itoa(int(alg.id)),
6694 },
6695 expectedPeerSignatureAlgorithm: alg.id,
6696 })
6697
6698 testCases = append(testCases, testCase{
6699 testType: serverTest,
6700 name: "ServerAuth-Sign-Negotiate" + suffix,
6701 config: Config{
6702 MaxVersion: ver.version,
6703 CipherSuites: signingCiphers,
6704 VerifySignatureAlgorithms: allAlgorithms,
6705 },
6706 flags: []string{
6707 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6708 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6709 "-enable-all-curves",
6710 "-signing-prefs", strconv.Itoa(int(alg.id)),
6711 },
6712 expectedPeerSignatureAlgorithm: alg.id,
6713 })
6714 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006715 }
David Benjamin000800a2014-11-14 01:43:59 -05006716 }
6717
Nick Harper60edffd2016-06-21 15:19:24 -07006718 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006719 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006720 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006721 config: Config{
6722 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006723 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006724 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006725 signatureECDSAWithP521AndSHA512,
6726 signatureRSAPKCS1WithSHA384,
6727 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006728 },
6729 },
6730 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006731 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6732 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006733 },
Nick Harper60edffd2016-06-21 15:19:24 -07006734 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006735 })
6736
6737 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006738 name: "ClientAuth-SignatureType-TLS13",
6739 config: Config{
6740 ClientAuth: RequireAnyClientCert,
6741 MaxVersion: VersionTLS13,
6742 VerifySignatureAlgorithms: []signatureAlgorithm{
6743 signatureECDSAWithP521AndSHA512,
6744 signatureRSAPKCS1WithSHA384,
6745 signatureRSAPSSWithSHA384,
6746 signatureECDSAWithSHA1,
6747 },
6748 },
6749 flags: []string{
6750 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6751 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6752 },
6753 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6754 })
6755
6756 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006757 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006758 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006759 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006760 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006762 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006763 signatureECDSAWithP521AndSHA512,
6764 signatureRSAPKCS1WithSHA384,
6765 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006766 },
6767 },
Nick Harper60edffd2016-06-21 15:19:24 -07006768 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006769 })
6770
Steven Valdez143e8b32016-07-11 13:19:03 -04006771 testCases = append(testCases, testCase{
6772 testType: serverTest,
6773 name: "ServerAuth-SignatureType-TLS13",
6774 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006775 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006776 VerifySignatureAlgorithms: []signatureAlgorithm{
6777 signatureECDSAWithP521AndSHA512,
6778 signatureRSAPKCS1WithSHA384,
6779 signatureRSAPSSWithSHA384,
6780 signatureECDSAWithSHA1,
6781 },
6782 },
6783 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6784 })
6785
David Benjamina95e9f32016-07-08 16:28:04 -07006786 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006787 testCases = append(testCases, testCase{
6788 testType: serverTest,
6789 name: "Verify-ClientAuth-SignatureType",
6790 config: Config{
6791 MaxVersion: VersionTLS12,
6792 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006793 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006794 signatureRSAPKCS1WithSHA256,
6795 },
6796 Bugs: ProtocolBugs{
6797 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6798 },
6799 },
6800 flags: []string{
6801 "-require-any-client-certificate",
6802 },
6803 shouldFail: true,
6804 expectedError: ":WRONG_SIGNATURE_TYPE:",
6805 })
6806
6807 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006808 testType: serverTest,
6809 name: "Verify-ClientAuth-SignatureType-TLS13",
6810 config: Config{
6811 MaxVersion: VersionTLS13,
6812 Certificates: []Certificate{rsaCertificate},
6813 SignSignatureAlgorithms: []signatureAlgorithm{
6814 signatureRSAPSSWithSHA256,
6815 },
6816 Bugs: ProtocolBugs{
6817 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6818 },
6819 },
6820 flags: []string{
6821 "-require-any-client-certificate",
6822 },
6823 shouldFail: true,
6824 expectedError: ":WRONG_SIGNATURE_TYPE:",
6825 })
6826
6827 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006828 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006829 config: Config{
6830 MaxVersion: VersionTLS12,
6831 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006832 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006833 signatureRSAPKCS1WithSHA256,
6834 },
6835 Bugs: ProtocolBugs{
6836 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6837 },
6838 },
6839 shouldFail: true,
6840 expectedError: ":WRONG_SIGNATURE_TYPE:",
6841 })
6842
Steven Valdez143e8b32016-07-11 13:19:03 -04006843 testCases = append(testCases, testCase{
6844 name: "Verify-ServerAuth-SignatureType-TLS13",
6845 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006846 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006847 SignSignatureAlgorithms: []signatureAlgorithm{
6848 signatureRSAPSSWithSHA256,
6849 },
6850 Bugs: ProtocolBugs{
6851 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6852 },
6853 },
6854 shouldFail: true,
6855 expectedError: ":WRONG_SIGNATURE_TYPE:",
6856 })
6857
David Benjamin51dd7d62016-07-08 16:07:01 -07006858 // Test that, if the list is missing, the peer falls back to SHA-1 in
6859 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006860 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006861 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006863 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006864 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006865 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006866 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006867 },
6868 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006869 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006870 },
6871 },
6872 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006873 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6874 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006875 },
6876 })
6877
6878 testCases = append(testCases, testCase{
6879 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006880 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006881 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006882 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006883 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006884 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006885 },
6886 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006887 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006888 },
6889 },
David Benjaminee32bea2016-08-17 13:36:44 -04006890 flags: []string{
6891 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6892 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6893 },
6894 })
6895
6896 testCases = append(testCases, testCase{
6897 name: "ClientAuth-SHA1-Fallback-ECDSA",
6898 config: Config{
6899 MaxVersion: VersionTLS12,
6900 ClientAuth: RequireAnyClientCert,
6901 VerifySignatureAlgorithms: []signatureAlgorithm{
6902 signatureECDSAWithSHA1,
6903 },
6904 Bugs: ProtocolBugs{
6905 NoSignatureAlgorithms: true,
6906 },
6907 },
6908 flags: []string{
6909 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6910 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6911 },
6912 })
6913
6914 testCases = append(testCases, testCase{
6915 testType: serverTest,
6916 name: "ServerAuth-SHA1-Fallback-ECDSA",
6917 config: Config{
6918 MaxVersion: VersionTLS12,
6919 VerifySignatureAlgorithms: []signatureAlgorithm{
6920 signatureECDSAWithSHA1,
6921 },
6922 Bugs: ProtocolBugs{
6923 NoSignatureAlgorithms: true,
6924 },
6925 },
6926 flags: []string{
6927 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6928 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6929 },
David Benjamin000800a2014-11-14 01:43:59 -05006930 })
David Benjamin72dc7832015-03-16 17:49:43 -04006931
David Benjamin51dd7d62016-07-08 16:07:01 -07006932 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006933 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006934 config: Config{
6935 MaxVersion: VersionTLS13,
6936 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006937 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006938 signatureRSAPKCS1WithSHA1,
6939 },
6940 Bugs: ProtocolBugs{
6941 NoSignatureAlgorithms: true,
6942 },
6943 },
6944 flags: []string{
6945 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6946 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6947 },
David Benjamin48901652016-08-01 12:12:47 -04006948 shouldFail: true,
6949 // An empty CertificateRequest signature algorithm list is a
6950 // syntax error in TLS 1.3.
6951 expectedError: ":DECODE_ERROR:",
6952 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006953 })
6954
6955 testCases = append(testCases, testCase{
6956 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006957 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006958 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006959 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006960 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006961 signatureRSAPKCS1WithSHA1,
6962 },
6963 Bugs: ProtocolBugs{
6964 NoSignatureAlgorithms: true,
6965 },
6966 },
6967 shouldFail: true,
6968 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6969 })
6970
David Benjaminb62d2872016-07-18 14:55:02 +02006971 // Test that hash preferences are enforced. BoringSSL does not implement
6972 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006973 testCases = append(testCases, testCase{
6974 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006975 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006977 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006978 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006979 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006980 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006981 },
6982 Bugs: ProtocolBugs{
6983 IgnorePeerSignatureAlgorithmPreferences: true,
6984 },
6985 },
6986 flags: []string{"-require-any-client-certificate"},
6987 shouldFail: true,
6988 expectedError: ":WRONG_SIGNATURE_TYPE:",
6989 })
6990
6991 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006992 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006994 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006995 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006996 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006997 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006998 },
6999 Bugs: ProtocolBugs{
7000 IgnorePeerSignatureAlgorithmPreferences: true,
7001 },
7002 },
7003 shouldFail: true,
7004 expectedError: ":WRONG_SIGNATURE_TYPE:",
7005 })
David Benjaminb62d2872016-07-18 14:55:02 +02007006 testCases = append(testCases, testCase{
7007 testType: serverTest,
7008 name: "ClientAuth-Enforced-TLS13",
7009 config: Config{
7010 MaxVersion: VersionTLS13,
7011 Certificates: []Certificate{rsaCertificate},
7012 SignSignatureAlgorithms: []signatureAlgorithm{
7013 signatureRSAPKCS1WithMD5,
7014 },
7015 Bugs: ProtocolBugs{
7016 IgnorePeerSignatureAlgorithmPreferences: true,
7017 IgnoreSignatureVersionChecks: true,
7018 },
7019 },
7020 flags: []string{"-require-any-client-certificate"},
7021 shouldFail: true,
7022 expectedError: ":WRONG_SIGNATURE_TYPE:",
7023 })
7024
7025 testCases = append(testCases, testCase{
7026 name: "ServerAuth-Enforced-TLS13",
7027 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007028 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007029 SignSignatureAlgorithms: []signatureAlgorithm{
7030 signatureRSAPKCS1WithMD5,
7031 },
7032 Bugs: ProtocolBugs{
7033 IgnorePeerSignatureAlgorithmPreferences: true,
7034 IgnoreSignatureVersionChecks: true,
7035 },
7036 },
7037 shouldFail: true,
7038 expectedError: ":WRONG_SIGNATURE_TYPE:",
7039 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007040
7041 // Test that the agreed upon digest respects the client preferences and
7042 // the server digests.
7043 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007044 name: "NoCommonAlgorithms-Digests",
7045 config: Config{
7046 MaxVersion: VersionTLS12,
7047 ClientAuth: RequireAnyClientCert,
7048 VerifySignatureAlgorithms: []signatureAlgorithm{
7049 signatureRSAPKCS1WithSHA512,
7050 signatureRSAPKCS1WithSHA1,
7051 },
7052 },
7053 flags: []string{
7054 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7055 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7056 "-digest-prefs", "SHA256",
7057 },
7058 shouldFail: true,
7059 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7060 })
7061 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007062 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007064 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007065 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007066 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007067 signatureRSAPKCS1WithSHA512,
7068 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007069 },
7070 },
7071 flags: []string{
7072 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7073 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007074 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007075 },
David Benjaminca3d5452016-07-14 12:51:01 -04007076 shouldFail: true,
7077 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7078 })
7079 testCases = append(testCases, testCase{
7080 name: "NoCommonAlgorithms-TLS13",
7081 config: Config{
7082 MaxVersion: VersionTLS13,
7083 ClientAuth: RequireAnyClientCert,
7084 VerifySignatureAlgorithms: []signatureAlgorithm{
7085 signatureRSAPSSWithSHA512,
7086 signatureRSAPSSWithSHA384,
7087 },
7088 },
7089 flags: []string{
7090 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7091 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7092 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7093 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007094 shouldFail: true,
7095 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007096 })
7097 testCases = append(testCases, testCase{
7098 name: "Agree-Digest-SHA256",
7099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007100 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007101 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007102 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007103 signatureRSAPKCS1WithSHA1,
7104 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007105 },
7106 },
7107 flags: []string{
7108 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7109 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007110 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007111 },
Nick Harper60edffd2016-06-21 15:19:24 -07007112 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007113 })
7114 testCases = append(testCases, testCase{
7115 name: "Agree-Digest-SHA1",
7116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007117 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007118 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007119 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007120 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007121 },
7122 },
7123 flags: []string{
7124 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7125 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007126 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007127 },
Nick Harper60edffd2016-06-21 15:19:24 -07007128 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007129 })
7130 testCases = append(testCases, testCase{
7131 name: "Agree-Digest-Default",
7132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007133 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007134 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007135 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007136 signatureRSAPKCS1WithSHA256,
7137 signatureECDSAWithP256AndSHA256,
7138 signatureRSAPKCS1WithSHA1,
7139 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007140 },
7141 },
7142 flags: []string{
7143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7145 },
Nick Harper60edffd2016-06-21 15:19:24 -07007146 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007147 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007148
David Benjaminca3d5452016-07-14 12:51:01 -04007149 // Test that the signing preference list may include extra algorithms
7150 // without negotiation problems.
7151 testCases = append(testCases, testCase{
7152 testType: serverTest,
7153 name: "FilterExtraAlgorithms",
7154 config: Config{
7155 MaxVersion: VersionTLS12,
7156 VerifySignatureAlgorithms: []signatureAlgorithm{
7157 signatureRSAPKCS1WithSHA256,
7158 },
7159 },
7160 flags: []string{
7161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7163 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7164 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7165 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7166 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7167 },
7168 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7169 })
7170
David Benjamin4c3ddf72016-06-29 18:13:53 -04007171 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7172 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007173 testCases = append(testCases, testCase{
7174 name: "CheckLeafCurve",
7175 config: Config{
7176 MaxVersion: VersionTLS12,
7177 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007178 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007179 },
7180 flags: []string{"-p384-only"},
7181 shouldFail: true,
7182 expectedError: ":BAD_ECC_CERT:",
7183 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007184
7185 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7186 testCases = append(testCases, testCase{
7187 name: "CheckLeafCurve-TLS13",
7188 config: Config{
7189 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007190 Certificates: []Certificate{ecdsaP256Certificate},
7191 },
7192 flags: []string{"-p384-only"},
7193 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007194
7195 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7196 testCases = append(testCases, testCase{
7197 name: "ECDSACurveMismatch-Verify-TLS12",
7198 config: Config{
7199 MaxVersion: VersionTLS12,
7200 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7201 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007202 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007203 signatureECDSAWithP384AndSHA384,
7204 },
7205 },
7206 })
7207
7208 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7209 testCases = append(testCases, testCase{
7210 name: "ECDSACurveMismatch-Verify-TLS13",
7211 config: Config{
7212 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007213 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007214 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007215 signatureECDSAWithP384AndSHA384,
7216 },
7217 Bugs: ProtocolBugs{
7218 SkipECDSACurveCheck: true,
7219 },
7220 },
7221 shouldFail: true,
7222 expectedError: ":WRONG_SIGNATURE_TYPE:",
7223 })
7224
7225 // Signature algorithm selection in TLS 1.3 should take the curve into
7226 // account.
7227 testCases = append(testCases, testCase{
7228 testType: serverTest,
7229 name: "ECDSACurveMismatch-Sign-TLS13",
7230 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007231 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007232 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007233 signatureECDSAWithP384AndSHA384,
7234 signatureECDSAWithP256AndSHA256,
7235 },
7236 },
7237 flags: []string{
7238 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7239 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7240 },
7241 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7242 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007243
7244 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7245 // server does not attempt to sign in that case.
7246 testCases = append(testCases, testCase{
7247 testType: serverTest,
7248 name: "RSA-PSS-Large",
7249 config: Config{
7250 MaxVersion: VersionTLS13,
7251 VerifySignatureAlgorithms: []signatureAlgorithm{
7252 signatureRSAPSSWithSHA512,
7253 },
7254 },
7255 flags: []string{
7256 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7257 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7258 },
7259 shouldFail: true,
7260 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7261 })
David Benjamin57e929f2016-08-30 00:30:38 -04007262
7263 // Test that RSA-PSS is enabled by default for TLS 1.2.
7264 testCases = append(testCases, testCase{
7265 testType: clientTest,
7266 name: "RSA-PSS-Default-Verify",
7267 config: Config{
7268 MaxVersion: VersionTLS12,
7269 SignSignatureAlgorithms: []signatureAlgorithm{
7270 signatureRSAPSSWithSHA256,
7271 },
7272 },
7273 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7274 })
7275
7276 testCases = append(testCases, testCase{
7277 testType: serverTest,
7278 name: "RSA-PSS-Default-Sign",
7279 config: Config{
7280 MaxVersion: VersionTLS12,
7281 VerifySignatureAlgorithms: []signatureAlgorithm{
7282 signatureRSAPSSWithSHA256,
7283 },
7284 },
7285 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7286 })
David Benjamin000800a2014-11-14 01:43:59 -05007287}
7288
David Benjamin83f90402015-01-27 01:09:43 -05007289// timeouts is the retransmit schedule for BoringSSL. It doubles and
7290// caps at 60 seconds. On the 13th timeout, it gives up.
7291var timeouts = []time.Duration{
7292 1 * time.Second,
7293 2 * time.Second,
7294 4 * time.Second,
7295 8 * time.Second,
7296 16 * time.Second,
7297 32 * time.Second,
7298 60 * time.Second,
7299 60 * time.Second,
7300 60 * time.Second,
7301 60 * time.Second,
7302 60 * time.Second,
7303 60 * time.Second,
7304 60 * time.Second,
7305}
7306
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007307// shortTimeouts is an alternate set of timeouts which would occur if the
7308// initial timeout duration was set to 250ms.
7309var shortTimeouts = []time.Duration{
7310 250 * time.Millisecond,
7311 500 * time.Millisecond,
7312 1 * time.Second,
7313 2 * time.Second,
7314 4 * time.Second,
7315 8 * time.Second,
7316 16 * time.Second,
7317 32 * time.Second,
7318 60 * time.Second,
7319 60 * time.Second,
7320 60 * time.Second,
7321 60 * time.Second,
7322 60 * time.Second,
7323}
7324
David Benjamin83f90402015-01-27 01:09:43 -05007325func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007326 // These tests work by coordinating some behavior on both the shim and
7327 // the runner.
7328 //
7329 // TimeoutSchedule configures the runner to send a series of timeout
7330 // opcodes to the shim (see packetAdaptor) immediately before reading
7331 // each peer handshake flight N. The timeout opcode both simulates a
7332 // timeout in the shim and acts as a synchronization point to help the
7333 // runner bracket each handshake flight.
7334 //
7335 // We assume the shim does not read from the channel eagerly. It must
7336 // first wait until it has sent flight N and is ready to receive
7337 // handshake flight N+1. At this point, it will process the timeout
7338 // opcode. It must then immediately respond with a timeout ACK and act
7339 // as if the shim was idle for the specified amount of time.
7340 //
7341 // The runner then drops all packets received before the ACK and
7342 // continues waiting for flight N. This ordering results in one attempt
7343 // at sending flight N to be dropped. For the test to complete, the
7344 // shim must send flight N again, testing that the shim implements DTLS
7345 // retransmit on a timeout.
7346
Steven Valdez143e8b32016-07-11 13:19:03 -04007347 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007348 // likely be more epochs to cross and the final message's retransmit may
7349 // be more complex.
7350
David Benjamin585d7a42016-06-02 14:58:00 -04007351 for _, async := range []bool{true, false} {
7352 var tests []testCase
7353
7354 // Test that this is indeed the timeout schedule. Stress all
7355 // four patterns of handshake.
7356 for i := 1; i < len(timeouts); i++ {
7357 number := strconv.Itoa(i)
7358 tests = append(tests, testCase{
7359 protocol: dtls,
7360 name: "DTLS-Retransmit-Client-" + number,
7361 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007362 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007363 Bugs: ProtocolBugs{
7364 TimeoutSchedule: timeouts[:i],
7365 },
7366 },
7367 resumeSession: true,
7368 })
7369 tests = append(tests, testCase{
7370 protocol: dtls,
7371 testType: serverTest,
7372 name: "DTLS-Retransmit-Server-" + number,
7373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007374 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007375 Bugs: ProtocolBugs{
7376 TimeoutSchedule: timeouts[:i],
7377 },
7378 },
7379 resumeSession: true,
7380 })
7381 }
7382
7383 // Test that exceeding the timeout schedule hits a read
7384 // timeout.
7385 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007386 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007387 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007389 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007390 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007391 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007392 },
7393 },
7394 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007395 shouldFail: true,
7396 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007397 })
David Benjamin585d7a42016-06-02 14:58:00 -04007398
7399 if async {
7400 // Test that timeout handling has a fudge factor, due to API
7401 // problems.
7402 tests = append(tests, testCase{
7403 protocol: dtls,
7404 name: "DTLS-Retransmit-Fudge",
7405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007406 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007407 Bugs: ProtocolBugs{
7408 TimeoutSchedule: []time.Duration{
7409 timeouts[0] - 10*time.Millisecond,
7410 },
7411 },
7412 },
7413 resumeSession: true,
7414 })
7415 }
7416
7417 // Test that the final Finished retransmitting isn't
7418 // duplicated if the peer badly fragments everything.
7419 tests = append(tests, testCase{
7420 testType: serverTest,
7421 protocol: dtls,
7422 name: "DTLS-Retransmit-Fragmented",
7423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007424 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007425 Bugs: ProtocolBugs{
7426 TimeoutSchedule: []time.Duration{timeouts[0]},
7427 MaxHandshakeRecordLength: 2,
7428 },
7429 },
7430 })
7431
7432 // Test the timeout schedule when a shorter initial timeout duration is set.
7433 tests = append(tests, testCase{
7434 protocol: dtls,
7435 name: "DTLS-Retransmit-Short-Client",
7436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007437 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007438 Bugs: ProtocolBugs{
7439 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7440 },
7441 },
7442 resumeSession: true,
7443 flags: []string{"-initial-timeout-duration-ms", "250"},
7444 })
7445 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007446 protocol: dtls,
7447 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007448 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007450 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007451 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007452 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007453 },
7454 },
7455 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007456 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007457 })
David Benjamin585d7a42016-06-02 14:58:00 -04007458
7459 for _, test := range tests {
7460 if async {
7461 test.name += "-Async"
7462 test.flags = append(test.flags, "-async")
7463 }
7464
7465 testCases = append(testCases, test)
7466 }
David Benjamin83f90402015-01-27 01:09:43 -05007467 }
David Benjamin83f90402015-01-27 01:09:43 -05007468}
7469
David Benjaminc565ebb2015-04-03 04:06:36 -04007470func addExportKeyingMaterialTests() {
7471 for _, vers := range tlsVersions {
7472 if vers.version == VersionSSL30 {
7473 continue
7474 }
7475 testCases = append(testCases, testCase{
7476 name: "ExportKeyingMaterial-" + vers.name,
7477 config: Config{
7478 MaxVersion: vers.version,
7479 },
7480 exportKeyingMaterial: 1024,
7481 exportLabel: "label",
7482 exportContext: "context",
7483 useExportContext: true,
7484 })
7485 testCases = append(testCases, testCase{
7486 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7487 config: Config{
7488 MaxVersion: vers.version,
7489 },
7490 exportKeyingMaterial: 1024,
7491 })
7492 testCases = append(testCases, testCase{
7493 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7494 config: Config{
7495 MaxVersion: vers.version,
7496 },
7497 exportKeyingMaterial: 1024,
7498 useExportContext: true,
7499 })
7500 testCases = append(testCases, testCase{
7501 name: "ExportKeyingMaterial-Small-" + vers.name,
7502 config: Config{
7503 MaxVersion: vers.version,
7504 },
7505 exportKeyingMaterial: 1,
7506 exportLabel: "label",
7507 exportContext: "context",
7508 useExportContext: true,
7509 })
7510 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007511
David Benjaminc565ebb2015-04-03 04:06:36 -04007512 testCases = append(testCases, testCase{
7513 name: "ExportKeyingMaterial-SSL3",
7514 config: Config{
7515 MaxVersion: VersionSSL30,
7516 },
7517 exportKeyingMaterial: 1024,
7518 exportLabel: "label",
7519 exportContext: "context",
7520 useExportContext: true,
7521 shouldFail: true,
7522 expectedError: "failed to export keying material",
7523 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007524
7525 // Exporters work during a False Start.
7526 testCases = append(testCases, testCase{
7527 name: "ExportKeyingMaterial-FalseStart",
7528 config: Config{
7529 MaxVersion: VersionTLS12,
7530 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7531 NextProtos: []string{"foo"},
7532 Bugs: ProtocolBugs{
7533 ExpectFalseStart: true,
7534 },
7535 },
7536 flags: []string{
7537 "-false-start",
7538 "-advertise-alpn", "\x03foo",
7539 },
7540 shimWritesFirst: true,
7541 exportKeyingMaterial: 1024,
7542 exportLabel: "label",
7543 exportContext: "context",
7544 useExportContext: true,
7545 })
7546
7547 // Exporters do not work in the middle of a renegotiation. Test this by
7548 // triggering the exporter after every SSL_read call and configuring the
7549 // shim to run asynchronously.
7550 testCases = append(testCases, testCase{
7551 name: "ExportKeyingMaterial-Renegotiate",
7552 config: Config{
7553 MaxVersion: VersionTLS12,
7554 },
7555 renegotiate: 1,
7556 flags: []string{
7557 "-async",
7558 "-use-exporter-between-reads",
7559 "-renegotiate-freely",
7560 "-expect-total-renegotiations", "1",
7561 },
7562 shouldFail: true,
7563 expectedError: "failed to export keying material",
7564 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007565}
7566
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007567func addTLSUniqueTests() {
7568 for _, isClient := range []bool{false, true} {
7569 for _, isResumption := range []bool{false, true} {
7570 for _, hasEMS := range []bool{false, true} {
7571 var suffix string
7572 if isResumption {
7573 suffix = "Resume-"
7574 } else {
7575 suffix = "Full-"
7576 }
7577
7578 if hasEMS {
7579 suffix += "EMS-"
7580 } else {
7581 suffix += "NoEMS-"
7582 }
7583
7584 if isClient {
7585 suffix += "Client"
7586 } else {
7587 suffix += "Server"
7588 }
7589
7590 test := testCase{
7591 name: "TLSUnique-" + suffix,
7592 testTLSUnique: true,
7593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007594 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007595 Bugs: ProtocolBugs{
7596 NoExtendedMasterSecret: !hasEMS,
7597 },
7598 },
7599 }
7600
7601 if isResumption {
7602 test.resumeSession = true
7603 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007604 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007605 Bugs: ProtocolBugs{
7606 NoExtendedMasterSecret: !hasEMS,
7607 },
7608 }
7609 }
7610
7611 if isResumption && !hasEMS {
7612 test.shouldFail = true
7613 test.expectedError = "failed to get tls-unique"
7614 }
7615
7616 testCases = append(testCases, test)
7617 }
7618 }
7619 }
7620}
7621
Adam Langley09505632015-07-30 18:10:13 -07007622func addCustomExtensionTests() {
7623 expectedContents := "custom extension"
7624 emptyString := ""
7625
7626 for _, isClient := range []bool{false, true} {
7627 suffix := "Server"
7628 flag := "-enable-server-custom-extension"
7629 testType := serverTest
7630 if isClient {
7631 suffix = "Client"
7632 flag = "-enable-client-custom-extension"
7633 testType = clientTest
7634 }
7635
7636 testCases = append(testCases, testCase{
7637 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007638 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007639 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007640 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007641 Bugs: ProtocolBugs{
7642 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007643 ExpectedCustomExtension: &expectedContents,
7644 },
7645 },
7646 flags: []string{flag},
7647 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007648 testCases = append(testCases, testCase{
7649 testType: testType,
7650 name: "CustomExtensions-" + suffix + "-TLS13",
7651 config: Config{
7652 MaxVersion: VersionTLS13,
7653 Bugs: ProtocolBugs{
7654 CustomExtension: expectedContents,
7655 ExpectedCustomExtension: &expectedContents,
7656 },
7657 },
7658 flags: []string{flag},
7659 })
Adam Langley09505632015-07-30 18:10:13 -07007660
7661 // If the parse callback fails, the handshake should also fail.
7662 testCases = append(testCases, testCase{
7663 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007664 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007665 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007666 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007667 Bugs: ProtocolBugs{
7668 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007669 ExpectedCustomExtension: &expectedContents,
7670 },
7671 },
David Benjamin399e7c92015-07-30 23:01:27 -04007672 flags: []string{flag},
7673 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007674 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7675 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007676 testCases = append(testCases, testCase{
7677 testType: testType,
7678 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7679 config: Config{
7680 MaxVersion: VersionTLS13,
7681 Bugs: ProtocolBugs{
7682 CustomExtension: expectedContents + "foo",
7683 ExpectedCustomExtension: &expectedContents,
7684 },
7685 },
7686 flags: []string{flag},
7687 shouldFail: true,
7688 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7689 })
Adam Langley09505632015-07-30 18:10:13 -07007690
7691 // If the add callback fails, the handshake should also fail.
7692 testCases = append(testCases, testCase{
7693 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007694 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007695 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007696 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007697 Bugs: ProtocolBugs{
7698 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007699 ExpectedCustomExtension: &expectedContents,
7700 },
7701 },
David Benjamin399e7c92015-07-30 23:01:27 -04007702 flags: []string{flag, "-custom-extension-fail-add"},
7703 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007704 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7705 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007706 testCases = append(testCases, testCase{
7707 testType: testType,
7708 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7709 config: Config{
7710 MaxVersion: VersionTLS13,
7711 Bugs: ProtocolBugs{
7712 CustomExtension: expectedContents,
7713 ExpectedCustomExtension: &expectedContents,
7714 },
7715 },
7716 flags: []string{flag, "-custom-extension-fail-add"},
7717 shouldFail: true,
7718 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7719 })
Adam Langley09505632015-07-30 18:10:13 -07007720
7721 // If the add callback returns zero, no extension should be
7722 // added.
7723 skipCustomExtension := expectedContents
7724 if isClient {
7725 // For the case where the client skips sending the
7726 // custom extension, the server must not “echo” it.
7727 skipCustomExtension = ""
7728 }
7729 testCases = append(testCases, testCase{
7730 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007731 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007733 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007734 Bugs: ProtocolBugs{
7735 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007736 ExpectedCustomExtension: &emptyString,
7737 },
7738 },
7739 flags: []string{flag, "-custom-extension-skip"},
7740 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007741 testCases = append(testCases, testCase{
7742 testType: testType,
7743 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7744 config: Config{
7745 MaxVersion: VersionTLS13,
7746 Bugs: ProtocolBugs{
7747 CustomExtension: skipCustomExtension,
7748 ExpectedCustomExtension: &emptyString,
7749 },
7750 },
7751 flags: []string{flag, "-custom-extension-skip"},
7752 })
Adam Langley09505632015-07-30 18:10:13 -07007753 }
7754
7755 // The custom extension add callback should not be called if the client
7756 // doesn't send the extension.
7757 testCases = append(testCases, testCase{
7758 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007759 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007760 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007761 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007762 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007763 ExpectedCustomExtension: &emptyString,
7764 },
7765 },
7766 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7767 })
Adam Langley2deb9842015-08-07 11:15:37 -07007768
Steven Valdez143e8b32016-07-11 13:19:03 -04007769 testCases = append(testCases, testCase{
7770 testType: serverTest,
7771 name: "CustomExtensions-NotCalled-Server-TLS13",
7772 config: Config{
7773 MaxVersion: VersionTLS13,
7774 Bugs: ProtocolBugs{
7775 ExpectedCustomExtension: &emptyString,
7776 },
7777 },
7778 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7779 })
7780
Adam Langley2deb9842015-08-07 11:15:37 -07007781 // Test an unknown extension from the server.
7782 testCases = append(testCases, testCase{
7783 testType: clientTest,
7784 name: "UnknownExtension-Client",
7785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007786 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007787 Bugs: ProtocolBugs{
7788 CustomExtension: expectedContents,
7789 },
7790 },
David Benjamin0c40a962016-08-01 12:05:50 -04007791 shouldFail: true,
7792 expectedError: ":UNEXPECTED_EXTENSION:",
7793 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007794 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007795 testCases = append(testCases, testCase{
7796 testType: clientTest,
7797 name: "UnknownExtension-Client-TLS13",
7798 config: Config{
7799 MaxVersion: VersionTLS13,
7800 Bugs: ProtocolBugs{
7801 CustomExtension: expectedContents,
7802 },
7803 },
David Benjamin0c40a962016-08-01 12:05:50 -04007804 shouldFail: true,
7805 expectedError: ":UNEXPECTED_EXTENSION:",
7806 expectedLocalError: "remote error: unsupported extension",
7807 })
David Benjamin490469f2016-10-05 22:44:38 -04007808 testCases = append(testCases, testCase{
7809 testType: clientTest,
7810 name: "UnknownUnencryptedExtension-Client-TLS13",
7811 config: Config{
7812 MaxVersion: VersionTLS13,
7813 Bugs: ProtocolBugs{
7814 CustomUnencryptedExtension: expectedContents,
7815 },
7816 },
7817 shouldFail: true,
7818 expectedError: ":UNEXPECTED_EXTENSION:",
7819 // The shim must send an alert, but alerts at this point do not
7820 // get successfully decrypted by the runner.
7821 expectedLocalError: "local error: bad record MAC",
7822 })
7823 testCases = append(testCases, testCase{
7824 testType: clientTest,
7825 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 Bugs: ProtocolBugs{
7829 SendUnencryptedALPN: "foo",
7830 },
7831 },
7832 flags: []string{
7833 "-advertise-alpn", "\x03foo\x03bar",
7834 },
7835 shouldFail: true,
7836 expectedError: ":UNEXPECTED_EXTENSION:",
7837 // The shim must send an alert, but alerts at this point do not
7838 // get successfully decrypted by the runner.
7839 expectedLocalError: "local error: bad record MAC",
7840 })
David Benjamin0c40a962016-08-01 12:05:50 -04007841
7842 // Test a known but unoffered extension from the server.
7843 testCases = append(testCases, testCase{
7844 testType: clientTest,
7845 name: "UnofferedExtension-Client",
7846 config: Config{
7847 MaxVersion: VersionTLS12,
7848 Bugs: ProtocolBugs{
7849 SendALPN: "alpn",
7850 },
7851 },
7852 shouldFail: true,
7853 expectedError: ":UNEXPECTED_EXTENSION:",
7854 expectedLocalError: "remote error: unsupported extension",
7855 })
7856 testCases = append(testCases, testCase{
7857 testType: clientTest,
7858 name: "UnofferedExtension-Client-TLS13",
7859 config: Config{
7860 MaxVersion: VersionTLS13,
7861 Bugs: ProtocolBugs{
7862 SendALPN: "alpn",
7863 },
7864 },
7865 shouldFail: true,
7866 expectedError: ":UNEXPECTED_EXTENSION:",
7867 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007868 })
Adam Langley09505632015-07-30 18:10:13 -07007869}
7870
David Benjaminb36a3952015-12-01 18:53:13 -05007871func addRSAClientKeyExchangeTests() {
7872 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7873 testCases = append(testCases, testCase{
7874 testType: serverTest,
7875 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7876 config: Config{
7877 // Ensure the ClientHello version and final
7878 // version are different, to detect if the
7879 // server uses the wrong one.
7880 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007881 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007882 Bugs: ProtocolBugs{
7883 BadRSAClientKeyExchange: bad,
7884 },
7885 },
7886 shouldFail: true,
7887 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7888 })
7889 }
David Benjamine63d9d72016-09-19 18:27:34 -04007890
7891 // The server must compare whatever was in ClientHello.version for the
7892 // RSA premaster.
7893 testCases = append(testCases, testCase{
7894 testType: serverTest,
7895 name: "SendClientVersion-RSA",
7896 config: Config{
7897 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7898 Bugs: ProtocolBugs{
7899 SendClientVersion: 0x1234,
7900 },
7901 },
7902 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7903 })
David Benjaminb36a3952015-12-01 18:53:13 -05007904}
7905
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007906var testCurves = []struct {
7907 name string
7908 id CurveID
7909}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007910 {"P-256", CurveP256},
7911 {"P-384", CurveP384},
7912 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007913 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007914}
7915
Steven Valdez5440fe02016-07-18 12:40:30 -04007916const bogusCurve = 0x1234
7917
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007918func addCurveTests() {
7919 for _, curve := range testCurves {
7920 testCases = append(testCases, testCase{
7921 name: "CurveTest-Client-" + curve.name,
7922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007923 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007924 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7925 CurvePreferences: []CurveID{curve.id},
7926 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007927 flags: []string{
7928 "-enable-all-curves",
7929 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7930 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007931 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007932 })
7933 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007934 name: "CurveTest-Client-" + curve.name + "-TLS13",
7935 config: Config{
7936 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007937 CurvePreferences: []CurveID{curve.id},
7938 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007939 flags: []string{
7940 "-enable-all-curves",
7941 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7942 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007943 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007944 })
7945 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007946 testType: serverTest,
7947 name: "CurveTest-Server-" + curve.name,
7948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007949 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7951 CurvePreferences: []CurveID{curve.id},
7952 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007953 flags: []string{
7954 "-enable-all-curves",
7955 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7956 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007957 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007958 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007959 testCases = append(testCases, testCase{
7960 testType: serverTest,
7961 name: "CurveTest-Server-" + curve.name + "-TLS13",
7962 config: Config{
7963 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007964 CurvePreferences: []CurveID{curve.id},
7965 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007966 flags: []string{
7967 "-enable-all-curves",
7968 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7969 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007970 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007971 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007972 }
David Benjamin241ae832016-01-15 03:04:54 -05007973
7974 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007975 testCases = append(testCases, testCase{
7976 testType: serverTest,
7977 name: "UnknownCurve",
7978 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007979 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007980 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7981 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7982 },
7983 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007984
Steven Valdez803c77a2016-09-06 14:13:43 -04007985 // The server must be tolerant to bogus curves.
7986 testCases = append(testCases, testCase{
7987 testType: serverTest,
7988 name: "UnknownCurve-TLS13",
7989 config: Config{
7990 MaxVersion: VersionTLS13,
7991 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7992 },
7993 })
7994
David Benjamin4c3ddf72016-06-29 18:13:53 -04007995 // The server must not consider ECDHE ciphers when there are no
7996 // supported curves.
7997 testCases = append(testCases, testCase{
7998 testType: serverTest,
7999 name: "NoSupportedCurves",
8000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008001 MaxVersion: VersionTLS12,
8002 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8003 Bugs: ProtocolBugs{
8004 NoSupportedCurves: true,
8005 },
8006 },
8007 shouldFail: true,
8008 expectedError: ":NO_SHARED_CIPHER:",
8009 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008010 testCases = append(testCases, testCase{
8011 testType: serverTest,
8012 name: "NoSupportedCurves-TLS13",
8013 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008014 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008015 Bugs: ProtocolBugs{
8016 NoSupportedCurves: true,
8017 },
8018 },
8019 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008020 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008021 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008022
8023 // The server must fall back to another cipher when there are no
8024 // supported curves.
8025 testCases = append(testCases, testCase{
8026 testType: serverTest,
8027 name: "NoCommonCurves",
8028 config: Config{
8029 MaxVersion: VersionTLS12,
8030 CipherSuites: []uint16{
8031 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8032 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8033 },
8034 CurvePreferences: []CurveID{CurveP224},
8035 },
8036 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8037 })
8038
8039 // The client must reject bogus curves and disabled curves.
8040 testCases = append(testCases, testCase{
8041 name: "BadECDHECurve",
8042 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008043 MaxVersion: VersionTLS12,
8044 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8045 Bugs: ProtocolBugs{
8046 SendCurve: bogusCurve,
8047 },
8048 },
8049 shouldFail: true,
8050 expectedError: ":WRONG_CURVE:",
8051 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008052 testCases = append(testCases, testCase{
8053 name: "BadECDHECurve-TLS13",
8054 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008055 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008056 Bugs: ProtocolBugs{
8057 SendCurve: bogusCurve,
8058 },
8059 },
8060 shouldFail: true,
8061 expectedError: ":WRONG_CURVE:",
8062 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008063
8064 testCases = append(testCases, testCase{
8065 name: "UnsupportedCurve",
8066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008067 MaxVersion: VersionTLS12,
8068 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8069 CurvePreferences: []CurveID{CurveP256},
8070 Bugs: ProtocolBugs{
8071 IgnorePeerCurvePreferences: true,
8072 },
8073 },
8074 flags: []string{"-p384-only"},
8075 shouldFail: true,
8076 expectedError: ":WRONG_CURVE:",
8077 })
8078
David Benjamin4f921572016-07-17 14:20:10 +02008079 testCases = append(testCases, testCase{
8080 // TODO(davidben): Add a TLS 1.3 version where
8081 // HelloRetryRequest requests an unsupported curve.
8082 name: "UnsupportedCurve-ServerHello-TLS13",
8083 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008084 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008085 CurvePreferences: []CurveID{CurveP384},
8086 Bugs: ProtocolBugs{
8087 SendCurve: CurveP256,
8088 },
8089 },
8090 flags: []string{"-p384-only"},
8091 shouldFail: true,
8092 expectedError: ":WRONG_CURVE:",
8093 })
8094
David Benjamin4c3ddf72016-06-29 18:13:53 -04008095 // Test invalid curve points.
8096 testCases = append(testCases, testCase{
8097 name: "InvalidECDHPoint-Client",
8098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008099 MaxVersion: VersionTLS12,
8100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8101 CurvePreferences: []CurveID{CurveP256},
8102 Bugs: ProtocolBugs{
8103 InvalidECDHPoint: true,
8104 },
8105 },
8106 shouldFail: true,
8107 expectedError: ":INVALID_ENCODING:",
8108 })
8109 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008110 name: "InvalidECDHPoint-Client-TLS13",
8111 config: Config{
8112 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008113 CurvePreferences: []CurveID{CurveP256},
8114 Bugs: ProtocolBugs{
8115 InvalidECDHPoint: true,
8116 },
8117 },
8118 shouldFail: true,
8119 expectedError: ":INVALID_ENCODING:",
8120 })
8121 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008122 testType: serverTest,
8123 name: "InvalidECDHPoint-Server",
8124 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008125 MaxVersion: VersionTLS12,
8126 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8127 CurvePreferences: []CurveID{CurveP256},
8128 Bugs: ProtocolBugs{
8129 InvalidECDHPoint: true,
8130 },
8131 },
8132 shouldFail: true,
8133 expectedError: ":INVALID_ENCODING:",
8134 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008135 testCases = append(testCases, testCase{
8136 testType: serverTest,
8137 name: "InvalidECDHPoint-Server-TLS13",
8138 config: Config{
8139 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008140 CurvePreferences: []CurveID{CurveP256},
8141 Bugs: ProtocolBugs{
8142 InvalidECDHPoint: true,
8143 },
8144 },
8145 shouldFail: true,
8146 expectedError: ":INVALID_ENCODING:",
8147 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008148}
8149
Matt Braithwaite54217e42016-06-13 13:03:47 -07008150func addCECPQ1Tests() {
8151 testCases = append(testCases, testCase{
8152 testType: clientTest,
8153 name: "CECPQ1-Client-BadX25519Part",
8154 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008155 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008156 MinVersion: VersionTLS12,
8157 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8158 Bugs: ProtocolBugs{
8159 CECPQ1BadX25519Part: true,
8160 },
8161 },
8162 flags: []string{"-cipher", "kCECPQ1"},
8163 shouldFail: true,
8164 expectedLocalError: "local error: bad record MAC",
8165 })
8166 testCases = append(testCases, testCase{
8167 testType: clientTest,
8168 name: "CECPQ1-Client-BadNewhopePart",
8169 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008170 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008171 MinVersion: VersionTLS12,
8172 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8173 Bugs: ProtocolBugs{
8174 CECPQ1BadNewhopePart: true,
8175 },
8176 },
8177 flags: []string{"-cipher", "kCECPQ1"},
8178 shouldFail: true,
8179 expectedLocalError: "local error: bad record MAC",
8180 })
8181 testCases = append(testCases, testCase{
8182 testType: serverTest,
8183 name: "CECPQ1-Server-BadX25519Part",
8184 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008185 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008186 MinVersion: VersionTLS12,
8187 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8188 Bugs: ProtocolBugs{
8189 CECPQ1BadX25519Part: true,
8190 },
8191 },
8192 flags: []string{"-cipher", "kCECPQ1"},
8193 shouldFail: true,
8194 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8195 })
8196 testCases = append(testCases, testCase{
8197 testType: serverTest,
8198 name: "CECPQ1-Server-BadNewhopePart",
8199 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008200 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008201 MinVersion: VersionTLS12,
8202 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8203 Bugs: ProtocolBugs{
8204 CECPQ1BadNewhopePart: true,
8205 },
8206 },
8207 flags: []string{"-cipher", "kCECPQ1"},
8208 shouldFail: true,
8209 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8210 })
8211}
8212
David Benjamin5c4e8572016-08-19 17:44:53 -04008213func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05008214 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04008215 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008216 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008217 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008218 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8219 Bugs: ProtocolBugs{
8220 // This is a 1234-bit prime number, generated
8221 // with:
8222 // openssl gendh 1234 | openssl asn1parse -i
8223 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
8224 },
8225 },
David Benjamin9e68f192016-06-30 14:55:33 -04008226 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008227 })
8228 testCases = append(testCases, testCase{
8229 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04008230 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008231 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008232 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008233 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8234 },
8235 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04008236 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008237 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05008238}
8239
David Benjaminc9ae27c2016-06-24 22:56:37 -04008240func addTLS13RecordTests() {
8241 testCases = append(testCases, testCase{
8242 name: "TLS13-RecordPadding",
8243 config: Config{
8244 MaxVersion: VersionTLS13,
8245 MinVersion: VersionTLS13,
8246 Bugs: ProtocolBugs{
8247 RecordPadding: 10,
8248 },
8249 },
8250 })
8251
8252 testCases = append(testCases, testCase{
8253 name: "TLS13-EmptyRecords",
8254 config: Config{
8255 MaxVersion: VersionTLS13,
8256 MinVersion: VersionTLS13,
8257 Bugs: ProtocolBugs{
8258 OmitRecordContents: true,
8259 },
8260 },
8261 shouldFail: true,
8262 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8263 })
8264
8265 testCases = append(testCases, testCase{
8266 name: "TLS13-OnlyPadding",
8267 config: Config{
8268 MaxVersion: VersionTLS13,
8269 MinVersion: VersionTLS13,
8270 Bugs: ProtocolBugs{
8271 OmitRecordContents: true,
8272 RecordPadding: 10,
8273 },
8274 },
8275 shouldFail: true,
8276 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8277 })
8278
8279 testCases = append(testCases, testCase{
8280 name: "TLS13-WrongOuterRecord",
8281 config: Config{
8282 MaxVersion: VersionTLS13,
8283 MinVersion: VersionTLS13,
8284 Bugs: ProtocolBugs{
8285 OuterRecordType: recordTypeHandshake,
8286 },
8287 },
8288 shouldFail: true,
8289 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8290 })
8291}
8292
Steven Valdez5b986082016-09-01 12:29:49 -04008293func addSessionTicketTests() {
8294 testCases = append(testCases, testCase{
8295 // In TLS 1.2 and below, empty NewSessionTicket messages
8296 // mean the server changed its mind on sending a ticket.
8297 name: "SendEmptySessionTicket",
8298 config: Config{
8299 MaxVersion: VersionTLS12,
8300 Bugs: ProtocolBugs{
8301 SendEmptySessionTicket: true,
8302 },
8303 },
8304 flags: []string{"-expect-no-session"},
8305 })
8306
8307 // Test that the server ignores unknown PSK modes.
8308 testCases = append(testCases, testCase{
8309 testType: serverTest,
8310 name: "TLS13-SendUnknownModeSessionTicket-Server",
8311 config: Config{
8312 MaxVersion: VersionTLS13,
8313 Bugs: ProtocolBugs{
8314 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008315 },
8316 },
8317 resumeSession: true,
8318 expectedResumeVersion: VersionTLS13,
8319 })
8320
Steven Valdeza833c352016-11-01 13:39:36 -04008321 // Test that the server does not send session tickets with no matching key exchange mode.
8322 testCases = append(testCases, testCase{
8323 testType: serverTest,
8324 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8325 config: Config{
8326 MaxVersion: VersionTLS13,
8327 Bugs: ProtocolBugs{
8328 SendPSKKeyExchangeModes: []byte{0x1a},
8329 ExpectNoNewSessionTicket: true,
8330 },
8331 },
8332 })
8333
8334 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008335 testCases = append(testCases, testCase{
8336 testType: serverTest,
8337 name: "TLS13-SendBadKEModeSessionTicket-Server",
8338 config: Config{
8339 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008340 },
8341 resumeConfig: &Config{
8342 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008343 Bugs: ProtocolBugs{
8344 SendPSKKeyExchangeModes: []byte{0x1a},
8345 },
8346 },
8347 resumeSession: true,
8348 expectResumeRejected: true,
8349 })
8350
Steven Valdeza833c352016-11-01 13:39:36 -04008351 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008352 testCases = append(testCases, testCase{
8353 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008354 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008355 config: Config{
8356 MaxVersion: VersionTLS13,
8357 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008358 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008359 },
8360 },
Steven Valdeza833c352016-11-01 13:39:36 -04008361 resumeSession: true,
8362 flags: []string{
8363 "-resumption-delay", "10",
8364 },
Steven Valdez5b986082016-09-01 12:29:49 -04008365 })
8366
Steven Valdeza833c352016-11-01 13:39:36 -04008367 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008368 testCases = append(testCases, testCase{
8369 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008370 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008371 config: Config{
8372 MaxVersion: VersionTLS13,
8373 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008374 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008375 },
8376 },
Steven Valdeza833c352016-11-01 13:39:36 -04008377 resumeSession: true,
8378 shouldFail: true,
8379 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008380 })
8381
Steven Valdez5b986082016-09-01 12:29:49 -04008382}
8383
David Benjamin82261be2016-07-07 14:32:50 -07008384func addChangeCipherSpecTests() {
8385 // Test missing ChangeCipherSpecs.
8386 testCases = append(testCases, testCase{
8387 name: "SkipChangeCipherSpec-Client",
8388 config: Config{
8389 MaxVersion: VersionTLS12,
8390 Bugs: ProtocolBugs{
8391 SkipChangeCipherSpec: true,
8392 },
8393 },
8394 shouldFail: true,
8395 expectedError: ":UNEXPECTED_RECORD:",
8396 })
8397 testCases = append(testCases, testCase{
8398 testType: serverTest,
8399 name: "SkipChangeCipherSpec-Server",
8400 config: Config{
8401 MaxVersion: VersionTLS12,
8402 Bugs: ProtocolBugs{
8403 SkipChangeCipherSpec: true,
8404 },
8405 },
8406 shouldFail: true,
8407 expectedError: ":UNEXPECTED_RECORD:",
8408 })
8409 testCases = append(testCases, testCase{
8410 testType: serverTest,
8411 name: "SkipChangeCipherSpec-Server-NPN",
8412 config: Config{
8413 MaxVersion: VersionTLS12,
8414 NextProtos: []string{"bar"},
8415 Bugs: ProtocolBugs{
8416 SkipChangeCipherSpec: true,
8417 },
8418 },
8419 flags: []string{
8420 "-advertise-npn", "\x03foo\x03bar\x03baz",
8421 },
8422 shouldFail: true,
8423 expectedError: ":UNEXPECTED_RECORD:",
8424 })
8425
8426 // Test synchronization between the handshake and ChangeCipherSpec.
8427 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8428 // rejected. Test both with and without handshake packing to handle both
8429 // when the partial post-CCS message is in its own record and when it is
8430 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008431 for _, packed := range []bool{false, true} {
8432 var suffix string
8433 if packed {
8434 suffix = "-Packed"
8435 }
8436
8437 testCases = append(testCases, testCase{
8438 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8439 config: Config{
8440 MaxVersion: VersionTLS12,
8441 Bugs: ProtocolBugs{
8442 FragmentAcrossChangeCipherSpec: true,
8443 PackHandshakeFlight: packed,
8444 },
8445 },
8446 shouldFail: true,
8447 expectedError: ":UNEXPECTED_RECORD:",
8448 })
8449 testCases = append(testCases, testCase{
8450 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8451 config: Config{
8452 MaxVersion: VersionTLS12,
8453 },
8454 resumeSession: true,
8455 resumeConfig: &Config{
8456 MaxVersion: VersionTLS12,
8457 Bugs: ProtocolBugs{
8458 FragmentAcrossChangeCipherSpec: true,
8459 PackHandshakeFlight: packed,
8460 },
8461 },
8462 shouldFail: true,
8463 expectedError: ":UNEXPECTED_RECORD:",
8464 })
8465 testCases = append(testCases, testCase{
8466 testType: serverTest,
8467 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8468 config: Config{
8469 MaxVersion: VersionTLS12,
8470 Bugs: ProtocolBugs{
8471 FragmentAcrossChangeCipherSpec: true,
8472 PackHandshakeFlight: packed,
8473 },
8474 },
8475 shouldFail: true,
8476 expectedError: ":UNEXPECTED_RECORD:",
8477 })
8478 testCases = append(testCases, testCase{
8479 testType: serverTest,
8480 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8481 config: Config{
8482 MaxVersion: VersionTLS12,
8483 },
8484 resumeSession: true,
8485 resumeConfig: &Config{
8486 MaxVersion: VersionTLS12,
8487 Bugs: ProtocolBugs{
8488 FragmentAcrossChangeCipherSpec: true,
8489 PackHandshakeFlight: packed,
8490 },
8491 },
8492 shouldFail: true,
8493 expectedError: ":UNEXPECTED_RECORD:",
8494 })
8495 testCases = append(testCases, testCase{
8496 testType: serverTest,
8497 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8498 config: Config{
8499 MaxVersion: VersionTLS12,
8500 NextProtos: []string{"bar"},
8501 Bugs: ProtocolBugs{
8502 FragmentAcrossChangeCipherSpec: true,
8503 PackHandshakeFlight: packed,
8504 },
8505 },
8506 flags: []string{
8507 "-advertise-npn", "\x03foo\x03bar\x03baz",
8508 },
8509 shouldFail: true,
8510 expectedError: ":UNEXPECTED_RECORD:",
8511 })
8512 }
8513
David Benjamin61672812016-07-14 23:10:43 -04008514 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8515 // messages in the handshake queue. Do this by testing the server
8516 // reading the client Finished, reversing the flight so Finished comes
8517 // first.
8518 testCases = append(testCases, testCase{
8519 protocol: dtls,
8520 testType: serverTest,
8521 name: "SendUnencryptedFinished-DTLS",
8522 config: Config{
8523 MaxVersion: VersionTLS12,
8524 Bugs: ProtocolBugs{
8525 SendUnencryptedFinished: true,
8526 ReverseHandshakeFragments: true,
8527 },
8528 },
8529 shouldFail: true,
8530 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8531 })
8532
Steven Valdez143e8b32016-07-11 13:19:03 -04008533 // Test synchronization between encryption changes and the handshake in
8534 // TLS 1.3, where ChangeCipherSpec is implicit.
8535 testCases = append(testCases, testCase{
8536 name: "PartialEncryptedExtensionsWithServerHello",
8537 config: Config{
8538 MaxVersion: VersionTLS13,
8539 Bugs: ProtocolBugs{
8540 PartialEncryptedExtensionsWithServerHello: true,
8541 },
8542 },
8543 shouldFail: true,
8544 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8545 })
8546 testCases = append(testCases, testCase{
8547 testType: serverTest,
8548 name: "PartialClientFinishedWithClientHello",
8549 config: Config{
8550 MaxVersion: VersionTLS13,
8551 Bugs: ProtocolBugs{
8552 PartialClientFinishedWithClientHello: true,
8553 },
8554 },
8555 shouldFail: true,
8556 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8557 })
8558
David Benjamin82261be2016-07-07 14:32:50 -07008559 // Test that early ChangeCipherSpecs are handled correctly.
8560 testCases = append(testCases, testCase{
8561 testType: serverTest,
8562 name: "EarlyChangeCipherSpec-server-1",
8563 config: Config{
8564 MaxVersion: VersionTLS12,
8565 Bugs: ProtocolBugs{
8566 EarlyChangeCipherSpec: 1,
8567 },
8568 },
8569 shouldFail: true,
8570 expectedError: ":UNEXPECTED_RECORD:",
8571 })
8572 testCases = append(testCases, testCase{
8573 testType: serverTest,
8574 name: "EarlyChangeCipherSpec-server-2",
8575 config: Config{
8576 MaxVersion: VersionTLS12,
8577 Bugs: ProtocolBugs{
8578 EarlyChangeCipherSpec: 2,
8579 },
8580 },
8581 shouldFail: true,
8582 expectedError: ":UNEXPECTED_RECORD:",
8583 })
8584 testCases = append(testCases, testCase{
8585 protocol: dtls,
8586 name: "StrayChangeCipherSpec",
8587 config: Config{
8588 // TODO(davidben): Once DTLS 1.3 exists, test
8589 // that stray ChangeCipherSpec messages are
8590 // rejected.
8591 MaxVersion: VersionTLS12,
8592 Bugs: ProtocolBugs{
8593 StrayChangeCipherSpec: true,
8594 },
8595 },
8596 })
8597
8598 // Test that the contents of ChangeCipherSpec are checked.
8599 testCases = append(testCases, testCase{
8600 name: "BadChangeCipherSpec-1",
8601 config: Config{
8602 MaxVersion: VersionTLS12,
8603 Bugs: ProtocolBugs{
8604 BadChangeCipherSpec: []byte{2},
8605 },
8606 },
8607 shouldFail: true,
8608 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8609 })
8610 testCases = append(testCases, testCase{
8611 name: "BadChangeCipherSpec-2",
8612 config: Config{
8613 MaxVersion: VersionTLS12,
8614 Bugs: ProtocolBugs{
8615 BadChangeCipherSpec: []byte{1, 1},
8616 },
8617 },
8618 shouldFail: true,
8619 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8620 })
8621 testCases = append(testCases, testCase{
8622 protocol: dtls,
8623 name: "BadChangeCipherSpec-DTLS-1",
8624 config: Config{
8625 MaxVersion: VersionTLS12,
8626 Bugs: ProtocolBugs{
8627 BadChangeCipherSpec: []byte{2},
8628 },
8629 },
8630 shouldFail: true,
8631 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8632 })
8633 testCases = append(testCases, testCase{
8634 protocol: dtls,
8635 name: "BadChangeCipherSpec-DTLS-2",
8636 config: Config{
8637 MaxVersion: VersionTLS12,
8638 Bugs: ProtocolBugs{
8639 BadChangeCipherSpec: []byte{1, 1},
8640 },
8641 },
8642 shouldFail: true,
8643 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8644 })
8645}
8646
David Benjamincd2c8062016-09-09 11:28:16 -04008647type perMessageTest struct {
8648 messageType uint8
8649 test testCase
8650}
8651
8652// makePerMessageTests returns a series of test templates which cover each
8653// message in the TLS handshake. These may be used with bugs like
8654// WrongMessageType to fully test a per-message bug.
8655func makePerMessageTests() []perMessageTest {
8656 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008657 for _, protocol := range []protocol{tls, dtls} {
8658 var suffix string
8659 if protocol == dtls {
8660 suffix = "-DTLS"
8661 }
8662
David Benjamincd2c8062016-09-09 11:28:16 -04008663 ret = append(ret, perMessageTest{
8664 messageType: typeClientHello,
8665 test: testCase{
8666 protocol: protocol,
8667 testType: serverTest,
8668 name: "ClientHello" + suffix,
8669 config: Config{
8670 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008671 },
8672 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008673 })
8674
8675 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008676 ret = append(ret, perMessageTest{
8677 messageType: typeHelloVerifyRequest,
8678 test: testCase{
8679 protocol: protocol,
8680 name: "HelloVerifyRequest" + suffix,
8681 config: Config{
8682 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008683 },
8684 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008685 })
8686 }
8687
David Benjamincd2c8062016-09-09 11:28:16 -04008688 ret = append(ret, perMessageTest{
8689 messageType: typeServerHello,
8690 test: testCase{
8691 protocol: protocol,
8692 name: "ServerHello" + suffix,
8693 config: Config{
8694 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008695 },
8696 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008697 })
8698
David Benjamincd2c8062016-09-09 11:28:16 -04008699 ret = append(ret, perMessageTest{
8700 messageType: typeCertificate,
8701 test: testCase{
8702 protocol: protocol,
8703 name: "ServerCertificate" + suffix,
8704 config: Config{
8705 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008706 },
8707 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008708 })
8709
David Benjamincd2c8062016-09-09 11:28:16 -04008710 ret = append(ret, perMessageTest{
8711 messageType: typeCertificateStatus,
8712 test: testCase{
8713 protocol: protocol,
8714 name: "CertificateStatus" + suffix,
8715 config: Config{
8716 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008717 },
David Benjamincd2c8062016-09-09 11:28:16 -04008718 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008719 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008720 })
8721
David Benjamincd2c8062016-09-09 11:28:16 -04008722 ret = append(ret, perMessageTest{
8723 messageType: typeServerKeyExchange,
8724 test: testCase{
8725 protocol: protocol,
8726 name: "ServerKeyExchange" + suffix,
8727 config: Config{
8728 MaxVersion: VersionTLS12,
8729 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008730 },
8731 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008732 })
8733
David Benjamincd2c8062016-09-09 11:28:16 -04008734 ret = append(ret, perMessageTest{
8735 messageType: typeCertificateRequest,
8736 test: testCase{
8737 protocol: protocol,
8738 name: "CertificateRequest" + suffix,
8739 config: Config{
8740 MaxVersion: VersionTLS12,
8741 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008742 },
8743 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008744 })
8745
David Benjamincd2c8062016-09-09 11:28:16 -04008746 ret = append(ret, perMessageTest{
8747 messageType: typeServerHelloDone,
8748 test: testCase{
8749 protocol: protocol,
8750 name: "ServerHelloDone" + suffix,
8751 config: Config{
8752 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008753 },
8754 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008755 })
8756
David Benjamincd2c8062016-09-09 11:28:16 -04008757 ret = append(ret, perMessageTest{
8758 messageType: typeCertificate,
8759 test: testCase{
8760 testType: serverTest,
8761 protocol: protocol,
8762 name: "ClientCertificate" + suffix,
8763 config: Config{
8764 Certificates: []Certificate{rsaCertificate},
8765 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008766 },
David Benjamincd2c8062016-09-09 11:28:16 -04008767 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008768 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008769 })
8770
David Benjamincd2c8062016-09-09 11:28:16 -04008771 ret = append(ret, perMessageTest{
8772 messageType: typeCertificateVerify,
8773 test: testCase{
8774 testType: serverTest,
8775 protocol: protocol,
8776 name: "CertificateVerify" + suffix,
8777 config: Config{
8778 Certificates: []Certificate{rsaCertificate},
8779 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008780 },
David Benjamincd2c8062016-09-09 11:28:16 -04008781 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008782 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008783 })
8784
David Benjamincd2c8062016-09-09 11:28:16 -04008785 ret = append(ret, perMessageTest{
8786 messageType: typeClientKeyExchange,
8787 test: testCase{
8788 testType: serverTest,
8789 protocol: protocol,
8790 name: "ClientKeyExchange" + suffix,
8791 config: Config{
8792 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008793 },
8794 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008795 })
8796
8797 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008798 ret = append(ret, perMessageTest{
8799 messageType: typeNextProtocol,
8800 test: testCase{
8801 testType: serverTest,
8802 protocol: protocol,
8803 name: "NextProtocol" + suffix,
8804 config: Config{
8805 MaxVersion: VersionTLS12,
8806 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008807 },
David Benjamincd2c8062016-09-09 11:28:16 -04008808 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008809 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008810 })
8811
David Benjamincd2c8062016-09-09 11:28:16 -04008812 ret = append(ret, perMessageTest{
8813 messageType: typeChannelID,
8814 test: testCase{
8815 testType: serverTest,
8816 protocol: protocol,
8817 name: "ChannelID" + suffix,
8818 config: Config{
8819 MaxVersion: VersionTLS12,
8820 ChannelID: channelIDKey,
8821 },
8822 flags: []string{
8823 "-expect-channel-id",
8824 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008825 },
8826 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008827 })
8828 }
8829
David Benjamincd2c8062016-09-09 11:28:16 -04008830 ret = append(ret, perMessageTest{
8831 messageType: typeFinished,
8832 test: testCase{
8833 testType: serverTest,
8834 protocol: protocol,
8835 name: "ClientFinished" + suffix,
8836 config: Config{
8837 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008838 },
8839 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008840 })
8841
David Benjamincd2c8062016-09-09 11:28:16 -04008842 ret = append(ret, perMessageTest{
8843 messageType: typeNewSessionTicket,
8844 test: testCase{
8845 protocol: protocol,
8846 name: "NewSessionTicket" + suffix,
8847 config: Config{
8848 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008849 },
8850 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008851 })
8852
David Benjamincd2c8062016-09-09 11:28:16 -04008853 ret = append(ret, perMessageTest{
8854 messageType: typeFinished,
8855 test: testCase{
8856 protocol: protocol,
8857 name: "ServerFinished" + suffix,
8858 config: Config{
8859 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008860 },
8861 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008862 })
8863
8864 }
David Benjamincd2c8062016-09-09 11:28:16 -04008865
8866 ret = append(ret, perMessageTest{
8867 messageType: typeClientHello,
8868 test: testCase{
8869 testType: serverTest,
8870 name: "TLS13-ClientHello",
8871 config: Config{
8872 MaxVersion: VersionTLS13,
8873 },
8874 },
8875 })
8876
8877 ret = append(ret, perMessageTest{
8878 messageType: typeServerHello,
8879 test: testCase{
8880 name: "TLS13-ServerHello",
8881 config: Config{
8882 MaxVersion: VersionTLS13,
8883 },
8884 },
8885 })
8886
8887 ret = append(ret, perMessageTest{
8888 messageType: typeEncryptedExtensions,
8889 test: testCase{
8890 name: "TLS13-EncryptedExtensions",
8891 config: Config{
8892 MaxVersion: VersionTLS13,
8893 },
8894 },
8895 })
8896
8897 ret = append(ret, perMessageTest{
8898 messageType: typeCertificateRequest,
8899 test: testCase{
8900 name: "TLS13-CertificateRequest",
8901 config: Config{
8902 MaxVersion: VersionTLS13,
8903 ClientAuth: RequireAnyClientCert,
8904 },
8905 },
8906 })
8907
8908 ret = append(ret, perMessageTest{
8909 messageType: typeCertificate,
8910 test: testCase{
8911 name: "TLS13-ServerCertificate",
8912 config: Config{
8913 MaxVersion: VersionTLS13,
8914 },
8915 },
8916 })
8917
8918 ret = append(ret, perMessageTest{
8919 messageType: typeCertificateVerify,
8920 test: testCase{
8921 name: "TLS13-ServerCertificateVerify",
8922 config: Config{
8923 MaxVersion: VersionTLS13,
8924 },
8925 },
8926 })
8927
8928 ret = append(ret, perMessageTest{
8929 messageType: typeFinished,
8930 test: testCase{
8931 name: "TLS13-ServerFinished",
8932 config: Config{
8933 MaxVersion: VersionTLS13,
8934 },
8935 },
8936 })
8937
8938 ret = append(ret, perMessageTest{
8939 messageType: typeCertificate,
8940 test: testCase{
8941 testType: serverTest,
8942 name: "TLS13-ClientCertificate",
8943 config: Config{
8944 Certificates: []Certificate{rsaCertificate},
8945 MaxVersion: VersionTLS13,
8946 },
8947 flags: []string{"-require-any-client-certificate"},
8948 },
8949 })
8950
8951 ret = append(ret, perMessageTest{
8952 messageType: typeCertificateVerify,
8953 test: testCase{
8954 testType: serverTest,
8955 name: "TLS13-ClientCertificateVerify",
8956 config: Config{
8957 Certificates: []Certificate{rsaCertificate},
8958 MaxVersion: VersionTLS13,
8959 },
8960 flags: []string{"-require-any-client-certificate"},
8961 },
8962 })
8963
8964 ret = append(ret, perMessageTest{
8965 messageType: typeFinished,
8966 test: testCase{
8967 testType: serverTest,
8968 name: "TLS13-ClientFinished",
8969 config: Config{
8970 MaxVersion: VersionTLS13,
8971 },
8972 },
8973 })
8974
8975 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008976}
8977
David Benjamincd2c8062016-09-09 11:28:16 -04008978func addWrongMessageTypeTests() {
8979 for _, t := range makePerMessageTests() {
8980 t.test.name = "WrongMessageType-" + t.test.name
8981 t.test.config.Bugs.SendWrongMessageType = t.messageType
8982 t.test.shouldFail = true
8983 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8984 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008985
David Benjamincd2c8062016-09-09 11:28:16 -04008986 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8987 // In TLS 1.3, a bad ServerHello means the client sends
8988 // an unencrypted alert while the server expects
8989 // encryption, so the alert is not readable by runner.
8990 t.test.expectedLocalError = "local error: bad record MAC"
8991 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008992
David Benjamincd2c8062016-09-09 11:28:16 -04008993 testCases = append(testCases, t.test)
8994 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008995}
8996
David Benjamin639846e2016-09-09 11:41:18 -04008997func addTrailingMessageDataTests() {
8998 for _, t := range makePerMessageTests() {
8999 t.test.name = "TrailingMessageData-" + t.test.name
9000 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9001 t.test.shouldFail = true
9002 t.test.expectedError = ":DECODE_ERROR:"
9003 t.test.expectedLocalError = "remote error: error decoding message"
9004
9005 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9006 // In TLS 1.3, a bad ServerHello means the client sends
9007 // an unencrypted alert while the server expects
9008 // encryption, so the alert is not readable by runner.
9009 t.test.expectedLocalError = "local error: bad record MAC"
9010 }
9011
9012 if t.messageType == typeFinished {
9013 // Bad Finished messages read as the verify data having
9014 // the wrong length.
9015 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9016 t.test.expectedLocalError = "remote error: error decrypting message"
9017 }
9018
9019 testCases = append(testCases, t.test)
9020 }
9021}
9022
Steven Valdez143e8b32016-07-11 13:19:03 -04009023func addTLS13HandshakeTests() {
9024 testCases = append(testCases, testCase{
9025 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009026 name: "NegotiatePSKResumption-TLS13",
9027 config: Config{
9028 MaxVersion: VersionTLS13,
9029 Bugs: ProtocolBugs{
9030 NegotiatePSKResumption: true,
9031 },
9032 },
9033 resumeSession: true,
9034 shouldFail: true,
9035 expectedError: ":UNEXPECTED_EXTENSION:",
9036 })
9037
9038 testCases = append(testCases, testCase{
9039 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009040 name: "MissingKeyShare-Client",
9041 config: Config{
9042 MaxVersion: VersionTLS13,
9043 Bugs: ProtocolBugs{
9044 MissingKeyShare: true,
9045 },
9046 },
9047 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009048 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009049 })
9050
9051 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009052 testType: serverTest,
9053 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009054 config: Config{
9055 MaxVersion: VersionTLS13,
9056 Bugs: ProtocolBugs{
9057 MissingKeyShare: true,
9058 },
9059 },
9060 shouldFail: true,
9061 expectedError: ":MISSING_KEY_SHARE:",
9062 })
9063
9064 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009065 testType: serverTest,
9066 name: "DuplicateKeyShares",
9067 config: Config{
9068 MaxVersion: VersionTLS13,
9069 Bugs: ProtocolBugs{
9070 DuplicateKeyShares: true,
9071 },
9072 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009073 shouldFail: true,
9074 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009075 })
9076
9077 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009078 testType: serverTest,
9079 name: "SkipEarlyData",
9080 config: Config{
9081 MaxVersion: VersionTLS13,
9082 Bugs: ProtocolBugs{
9083 SendEarlyDataLength: 4,
9084 },
9085 },
9086 })
9087
9088 testCases = append(testCases, testCase{
9089 testType: serverTest,
9090 name: "SkipEarlyData-OmitEarlyDataExtension",
9091 config: Config{
9092 MaxVersion: VersionTLS13,
9093 Bugs: ProtocolBugs{
9094 SendEarlyDataLength: 4,
9095 OmitEarlyDataExtension: true,
9096 },
9097 },
9098 shouldFail: true,
9099 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9100 })
9101
9102 testCases = append(testCases, testCase{
9103 testType: serverTest,
9104 name: "SkipEarlyData-TooMuchData",
9105 config: Config{
9106 MaxVersion: VersionTLS13,
9107 Bugs: ProtocolBugs{
9108 SendEarlyDataLength: 16384 + 1,
9109 },
9110 },
9111 shouldFail: true,
9112 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9113 })
9114
9115 testCases = append(testCases, testCase{
9116 testType: serverTest,
9117 name: "SkipEarlyData-Interleaved",
9118 config: Config{
9119 MaxVersion: VersionTLS13,
9120 Bugs: ProtocolBugs{
9121 SendEarlyDataLength: 4,
9122 InterleaveEarlyData: true,
9123 },
9124 },
9125 shouldFail: true,
9126 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9127 })
9128
9129 testCases = append(testCases, testCase{
9130 testType: serverTest,
9131 name: "SkipEarlyData-EarlyDataInTLS12",
9132 config: Config{
9133 MaxVersion: VersionTLS13,
9134 Bugs: ProtocolBugs{
9135 SendEarlyDataLength: 4,
9136 },
9137 },
9138 shouldFail: true,
9139 expectedError: ":UNEXPECTED_RECORD:",
9140 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9141 })
9142
9143 testCases = append(testCases, testCase{
9144 testType: serverTest,
9145 name: "SkipEarlyData-HRR",
9146 config: Config{
9147 MaxVersion: VersionTLS13,
9148 Bugs: ProtocolBugs{
9149 SendEarlyDataLength: 4,
9150 },
9151 DefaultCurves: []CurveID{},
9152 },
9153 })
9154
9155 testCases = append(testCases, testCase{
9156 testType: serverTest,
9157 name: "SkipEarlyData-HRR-Interleaved",
9158 config: Config{
9159 MaxVersion: VersionTLS13,
9160 Bugs: ProtocolBugs{
9161 SendEarlyDataLength: 4,
9162 InterleaveEarlyData: true,
9163 },
9164 DefaultCurves: []CurveID{},
9165 },
9166 shouldFail: true,
9167 expectedError: ":UNEXPECTED_RECORD:",
9168 })
9169
9170 testCases = append(testCases, testCase{
9171 testType: serverTest,
9172 name: "SkipEarlyData-HRR-TooMuchData",
9173 config: Config{
9174 MaxVersion: VersionTLS13,
9175 Bugs: ProtocolBugs{
9176 SendEarlyDataLength: 16384 + 1,
9177 },
9178 DefaultCurves: []CurveID{},
9179 },
9180 shouldFail: true,
9181 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9182 })
9183
9184 // Test that skipping early data looking for cleartext correctly
9185 // processes an alert record.
9186 testCases = append(testCases, testCase{
9187 testType: serverTest,
9188 name: "SkipEarlyData-HRR-FatalAlert",
9189 config: Config{
9190 MaxVersion: VersionTLS13,
9191 Bugs: ProtocolBugs{
9192 SendEarlyAlert: true,
9193 SendEarlyDataLength: 4,
9194 },
9195 DefaultCurves: []CurveID{},
9196 },
9197 shouldFail: true,
9198 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9199 })
9200
9201 testCases = append(testCases, testCase{
9202 testType: serverTest,
9203 name: "SkipEarlyData-SecondClientHelloEarlyData",
9204 config: Config{
9205 MaxVersion: VersionTLS13,
9206 Bugs: ProtocolBugs{
9207 SendEarlyDataOnSecondClientHello: true,
9208 },
9209 DefaultCurves: []CurveID{},
9210 },
9211 shouldFail: true,
9212 expectedLocalError: "remote error: bad record MAC",
9213 })
9214
9215 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009216 testType: clientTest,
9217 name: "EmptyEncryptedExtensions",
9218 config: Config{
9219 MaxVersion: VersionTLS13,
9220 Bugs: ProtocolBugs{
9221 EmptyEncryptedExtensions: true,
9222 },
9223 },
9224 shouldFail: true,
9225 expectedLocalError: "remote error: error decoding message",
9226 })
9227
9228 testCases = append(testCases, testCase{
9229 testType: clientTest,
9230 name: "EncryptedExtensionsWithKeyShare",
9231 config: Config{
9232 MaxVersion: VersionTLS13,
9233 Bugs: ProtocolBugs{
9234 EncryptedExtensionsWithKeyShare: true,
9235 },
9236 },
9237 shouldFail: true,
9238 expectedLocalError: "remote error: unsupported extension",
9239 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009240
9241 testCases = append(testCases, testCase{
9242 testType: serverTest,
9243 name: "SendHelloRetryRequest",
9244 config: Config{
9245 MaxVersion: VersionTLS13,
9246 // Require a HelloRetryRequest for every curve.
9247 DefaultCurves: []CurveID{},
9248 },
9249 expectedCurveID: CurveX25519,
9250 })
9251
9252 testCases = append(testCases, testCase{
9253 testType: serverTest,
9254 name: "SendHelloRetryRequest-2",
9255 config: Config{
9256 MaxVersion: VersionTLS13,
9257 DefaultCurves: []CurveID{CurveP384},
9258 },
9259 // Although the ClientHello did not predict our preferred curve,
9260 // we always select it whether it is predicted or not.
9261 expectedCurveID: CurveX25519,
9262 })
9263
9264 testCases = append(testCases, testCase{
9265 name: "UnknownCurve-HelloRetryRequest",
9266 config: Config{
9267 MaxVersion: VersionTLS13,
9268 // P-384 requires HelloRetryRequest in BoringSSL.
9269 CurvePreferences: []CurveID{CurveP384},
9270 Bugs: ProtocolBugs{
9271 SendHelloRetryRequestCurve: bogusCurve,
9272 },
9273 },
9274 shouldFail: true,
9275 expectedError: ":WRONG_CURVE:",
9276 })
9277
9278 testCases = append(testCases, testCase{
9279 name: "DisabledCurve-HelloRetryRequest",
9280 config: Config{
9281 MaxVersion: VersionTLS13,
9282 CurvePreferences: []CurveID{CurveP256},
9283 Bugs: ProtocolBugs{
9284 IgnorePeerCurvePreferences: true,
9285 },
9286 },
9287 flags: []string{"-p384-only"},
9288 shouldFail: true,
9289 expectedError: ":WRONG_CURVE:",
9290 })
9291
9292 testCases = append(testCases, testCase{
9293 name: "UnnecessaryHelloRetryRequest",
9294 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009295 MaxVersion: VersionTLS13,
9296 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009297 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009298 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009299 },
9300 },
9301 shouldFail: true,
9302 expectedError: ":WRONG_CURVE:",
9303 })
9304
9305 testCases = append(testCases, testCase{
9306 name: "SecondHelloRetryRequest",
9307 config: Config{
9308 MaxVersion: VersionTLS13,
9309 // P-384 requires HelloRetryRequest in BoringSSL.
9310 CurvePreferences: []CurveID{CurveP384},
9311 Bugs: ProtocolBugs{
9312 SecondHelloRetryRequest: true,
9313 },
9314 },
9315 shouldFail: true,
9316 expectedError: ":UNEXPECTED_MESSAGE:",
9317 })
9318
9319 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009320 name: "HelloRetryRequest-Empty",
9321 config: Config{
9322 MaxVersion: VersionTLS13,
9323 Bugs: ProtocolBugs{
9324 AlwaysSendHelloRetryRequest: true,
9325 },
9326 },
9327 shouldFail: true,
9328 expectedError: ":DECODE_ERROR:",
9329 })
9330
9331 testCases = append(testCases, testCase{
9332 name: "HelloRetryRequest-DuplicateCurve",
9333 config: Config{
9334 MaxVersion: VersionTLS13,
9335 // P-384 requires a HelloRetryRequest against BoringSSL's default
9336 // configuration. Assert this ExpectMissingKeyShare.
9337 CurvePreferences: []CurveID{CurveP384},
9338 Bugs: ProtocolBugs{
9339 ExpectMissingKeyShare: true,
9340 DuplicateHelloRetryRequestExtensions: true,
9341 },
9342 },
9343 shouldFail: true,
9344 expectedError: ":DUPLICATE_EXTENSION:",
9345 expectedLocalError: "remote error: illegal parameter",
9346 })
9347
9348 testCases = append(testCases, testCase{
9349 name: "HelloRetryRequest-Cookie",
9350 config: Config{
9351 MaxVersion: VersionTLS13,
9352 Bugs: ProtocolBugs{
9353 SendHelloRetryRequestCookie: []byte("cookie"),
9354 },
9355 },
9356 })
9357
9358 testCases = append(testCases, testCase{
9359 name: "HelloRetryRequest-DuplicateCookie",
9360 config: Config{
9361 MaxVersion: VersionTLS13,
9362 Bugs: ProtocolBugs{
9363 SendHelloRetryRequestCookie: []byte("cookie"),
9364 DuplicateHelloRetryRequestExtensions: true,
9365 },
9366 },
9367 shouldFail: true,
9368 expectedError: ":DUPLICATE_EXTENSION:",
9369 expectedLocalError: "remote error: illegal parameter",
9370 })
9371
9372 testCases = append(testCases, testCase{
9373 name: "HelloRetryRequest-EmptyCookie",
9374 config: Config{
9375 MaxVersion: VersionTLS13,
9376 Bugs: ProtocolBugs{
9377 SendHelloRetryRequestCookie: []byte{},
9378 },
9379 },
9380 shouldFail: true,
9381 expectedError: ":DECODE_ERROR:",
9382 })
9383
9384 testCases = append(testCases, testCase{
9385 name: "HelloRetryRequest-Cookie-Curve",
9386 config: Config{
9387 MaxVersion: VersionTLS13,
9388 // P-384 requires HelloRetryRequest in BoringSSL.
9389 CurvePreferences: []CurveID{CurveP384},
9390 Bugs: ProtocolBugs{
9391 SendHelloRetryRequestCookie: []byte("cookie"),
9392 ExpectMissingKeyShare: true,
9393 },
9394 },
9395 })
9396
9397 testCases = append(testCases, testCase{
9398 name: "HelloRetryRequest-Unknown",
9399 config: Config{
9400 MaxVersion: VersionTLS13,
9401 Bugs: ProtocolBugs{
9402 CustomHelloRetryRequestExtension: "extension",
9403 },
9404 },
9405 shouldFail: true,
9406 expectedError: ":UNEXPECTED_EXTENSION:",
9407 expectedLocalError: "remote error: unsupported extension",
9408 })
9409
9410 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009411 testType: serverTest,
9412 name: "SecondClientHelloMissingKeyShare",
9413 config: Config{
9414 MaxVersion: VersionTLS13,
9415 DefaultCurves: []CurveID{},
9416 Bugs: ProtocolBugs{
9417 SecondClientHelloMissingKeyShare: true,
9418 },
9419 },
9420 shouldFail: true,
9421 expectedError: ":MISSING_KEY_SHARE:",
9422 })
9423
9424 testCases = append(testCases, testCase{
9425 testType: serverTest,
9426 name: "SecondClientHelloWrongCurve",
9427 config: Config{
9428 MaxVersion: VersionTLS13,
9429 DefaultCurves: []CurveID{},
9430 Bugs: ProtocolBugs{
9431 MisinterpretHelloRetryRequestCurve: CurveP521,
9432 },
9433 },
9434 shouldFail: true,
9435 expectedError: ":WRONG_CURVE:",
9436 })
9437
9438 testCases = append(testCases, testCase{
9439 name: "HelloRetryRequestVersionMismatch",
9440 config: Config{
9441 MaxVersion: VersionTLS13,
9442 // P-384 requires HelloRetryRequest in BoringSSL.
9443 CurvePreferences: []CurveID{CurveP384},
9444 Bugs: ProtocolBugs{
9445 SendServerHelloVersion: 0x0305,
9446 },
9447 },
9448 shouldFail: true,
9449 expectedError: ":WRONG_VERSION_NUMBER:",
9450 })
9451
9452 testCases = append(testCases, testCase{
9453 name: "HelloRetryRequestCurveMismatch",
9454 config: Config{
9455 MaxVersion: VersionTLS13,
9456 // P-384 requires HelloRetryRequest in BoringSSL.
9457 CurvePreferences: []CurveID{CurveP384},
9458 Bugs: ProtocolBugs{
9459 // Send P-384 (correct) in the HelloRetryRequest.
9460 SendHelloRetryRequestCurve: CurveP384,
9461 // But send P-256 in the ServerHello.
9462 SendCurve: CurveP256,
9463 },
9464 },
9465 shouldFail: true,
9466 expectedError: ":WRONG_CURVE:",
9467 })
9468
9469 // Test the server selecting a curve that requires a HelloRetryRequest
9470 // without sending it.
9471 testCases = append(testCases, testCase{
9472 name: "SkipHelloRetryRequest",
9473 config: Config{
9474 MaxVersion: VersionTLS13,
9475 // P-384 requires HelloRetryRequest in BoringSSL.
9476 CurvePreferences: []CurveID{CurveP384},
9477 Bugs: ProtocolBugs{
9478 SkipHelloRetryRequest: true,
9479 },
9480 },
9481 shouldFail: true,
9482 expectedError: ":WRONG_CURVE:",
9483 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009484
9485 testCases = append(testCases, testCase{
9486 name: "TLS13-RequestContextInHandshake",
9487 config: Config{
9488 MaxVersion: VersionTLS13,
9489 MinVersion: VersionTLS13,
9490 ClientAuth: RequireAnyClientCert,
9491 Bugs: ProtocolBugs{
9492 SendRequestContext: []byte("request context"),
9493 },
9494 },
9495 flags: []string{
9496 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9497 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9498 },
9499 shouldFail: true,
9500 expectedError: ":DECODE_ERROR:",
9501 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009502
9503 testCases = append(testCases, testCase{
9504 testType: serverTest,
9505 name: "TLS13-TrailingKeyShareData",
9506 config: Config{
9507 MaxVersion: VersionTLS13,
9508 Bugs: ProtocolBugs{
9509 TrailingKeyShareData: true,
9510 },
9511 },
9512 shouldFail: true,
9513 expectedError: ":DECODE_ERROR:",
9514 })
David Benjamin7f78df42016-10-05 22:33:19 -04009515
9516 testCases = append(testCases, testCase{
9517 name: "TLS13-AlwaysSelectPSKIdentity",
9518 config: Config{
9519 MaxVersion: VersionTLS13,
9520 Bugs: ProtocolBugs{
9521 AlwaysSelectPSKIdentity: true,
9522 },
9523 },
9524 shouldFail: true,
9525 expectedError: ":UNEXPECTED_EXTENSION:",
9526 })
9527
9528 testCases = append(testCases, testCase{
9529 name: "TLS13-InvalidPSKIdentity",
9530 config: Config{
9531 MaxVersion: VersionTLS13,
9532 Bugs: ProtocolBugs{
9533 SelectPSKIdentityOnResume: 1,
9534 },
9535 },
9536 resumeSession: true,
9537 shouldFail: true,
9538 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9539 })
David Benjamin1286bee2016-10-07 15:25:06 -04009540
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009541 testCases = append(testCases, testCase{
9542 testType: serverTest,
9543 name: "TLS13-ExtraPSKIdentity",
9544 config: Config{
9545 MaxVersion: VersionTLS13,
9546 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009547 ExtraPSKIdentity: true,
9548 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009549 },
9550 },
9551 resumeSession: true,
9552 })
9553
David Benjamin1286bee2016-10-07 15:25:06 -04009554 // Test that unknown NewSessionTicket extensions are tolerated.
9555 testCases = append(testCases, testCase{
9556 name: "TLS13-CustomTicketExtension",
9557 config: Config{
9558 MaxVersion: VersionTLS13,
9559 Bugs: ProtocolBugs{
9560 CustomTicketExtension: "1234",
9561 },
9562 },
9563 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009564}
9565
David Benjaminabbbee12016-10-31 19:20:42 -04009566func addTLS13CipherPreferenceTests() {
9567 // Test that client preference is honored if the shim has AES hardware
9568 // and ChaCha20-Poly1305 is preferred otherwise.
9569 testCases = append(testCases, testCase{
9570 testType: serverTest,
9571 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9572 config: Config{
9573 MaxVersion: VersionTLS13,
9574 CipherSuites: []uint16{
9575 TLS_CHACHA20_POLY1305_SHA256,
9576 TLS_AES_128_GCM_SHA256,
9577 },
9578 },
9579 flags: []string{
9580 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9581 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9582 },
9583 })
9584
9585 testCases = append(testCases, testCase{
9586 testType: serverTest,
9587 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9588 config: Config{
9589 MaxVersion: VersionTLS13,
9590 CipherSuites: []uint16{
9591 TLS_AES_128_GCM_SHA256,
9592 TLS_CHACHA20_POLY1305_SHA256,
9593 },
9594 },
9595 flags: []string{
9596 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9597 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9598 },
9599 })
9600
9601 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9602 // whether it has AES hardware.
9603 testCases = append(testCases, testCase{
9604 name: "TLS13-CipherPreference-Client",
9605 config: Config{
9606 MaxVersion: VersionTLS13,
9607 // Use the client cipher order. (This is the default but
9608 // is listed to be explicit.)
9609 PreferServerCipherSuites: false,
9610 },
9611 flags: []string{
9612 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9613 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9614 },
9615 })
9616}
9617
David Benjaminf3fbade2016-09-19 13:08:16 -04009618func addPeekTests() {
9619 // Test SSL_peek works, including on empty records.
9620 testCases = append(testCases, testCase{
9621 name: "Peek-Basic",
9622 sendEmptyRecords: 1,
9623 flags: []string{"-peek-then-read"},
9624 })
9625
9626 // Test SSL_peek can drive the initial handshake.
9627 testCases = append(testCases, testCase{
9628 name: "Peek-ImplicitHandshake",
9629 flags: []string{
9630 "-peek-then-read",
9631 "-implicit-handshake",
9632 },
9633 })
9634
9635 // Test SSL_peek can discover and drive a renegotiation.
9636 testCases = append(testCases, testCase{
9637 name: "Peek-Renegotiate",
9638 config: Config{
9639 MaxVersion: VersionTLS12,
9640 },
9641 renegotiate: 1,
9642 flags: []string{
9643 "-peek-then-read",
9644 "-renegotiate-freely",
9645 "-expect-total-renegotiations", "1",
9646 },
9647 })
9648
9649 // Test SSL_peek can discover a close_notify.
9650 testCases = append(testCases, testCase{
9651 name: "Peek-Shutdown",
9652 config: Config{
9653 Bugs: ProtocolBugs{
9654 ExpectCloseNotify: true,
9655 },
9656 },
9657 flags: []string{
9658 "-peek-then-read",
9659 "-check-close-notify",
9660 },
9661 })
9662
9663 // Test SSL_peek can discover an alert.
9664 testCases = append(testCases, testCase{
9665 name: "Peek-Alert",
9666 config: Config{
9667 Bugs: ProtocolBugs{
9668 SendSpuriousAlert: alertRecordOverflow,
9669 },
9670 },
9671 flags: []string{"-peek-then-read"},
9672 shouldFail: true,
9673 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9674 })
9675
9676 // Test SSL_peek can handle KeyUpdate.
9677 testCases = append(testCases, testCase{
9678 name: "Peek-KeyUpdate",
9679 config: Config{
9680 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009681 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009682 sendKeyUpdates: 1,
9683 keyUpdateRequest: keyUpdateNotRequested,
9684 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009685 })
9686}
9687
David Benjamine6f22212016-11-08 14:28:24 -05009688func addRecordVersionTests() {
9689 for _, ver := range tlsVersions {
9690 // Test that the record version is enforced.
9691 testCases = append(testCases, testCase{
9692 name: "CheckRecordVersion-" + ver.name,
9693 config: Config{
9694 MinVersion: ver.version,
9695 MaxVersion: ver.version,
9696 Bugs: ProtocolBugs{
9697 SendRecordVersion: 0x03ff,
9698 },
9699 },
9700 shouldFail: true,
9701 expectedError: ":WRONG_VERSION_NUMBER:",
9702 })
9703
9704 // Test that the ClientHello may use any record version, for
9705 // compatibility reasons.
9706 testCases = append(testCases, testCase{
9707 testType: serverTest,
9708 name: "LooseInitialRecordVersion-" + ver.name,
9709 config: Config{
9710 MinVersion: ver.version,
9711 MaxVersion: ver.version,
9712 Bugs: ProtocolBugs{
9713 SendInitialRecordVersion: 0x03ff,
9714 },
9715 },
9716 })
9717
9718 // Test that garbage ClientHello record versions are rejected.
9719 testCases = append(testCases, testCase{
9720 testType: serverTest,
9721 name: "GarbageInitialRecordVersion-" + ver.name,
9722 config: Config{
9723 MinVersion: ver.version,
9724 MaxVersion: ver.version,
9725 Bugs: ProtocolBugs{
9726 SendInitialRecordVersion: 0xffff,
9727 },
9728 },
9729 shouldFail: true,
9730 expectedError: ":WRONG_VERSION_NUMBER:",
9731 })
9732 }
9733}
9734
David Benjamin2c516452016-11-15 10:16:54 +09009735func addCertificateTests() {
9736 // Test that a certificate chain with intermediate may be sent and
9737 // received as both client and server.
9738 for _, ver := range tlsVersions {
9739 testCases = append(testCases, testCase{
9740 testType: clientTest,
9741 name: "SendReceiveIntermediate-Client-" + ver.name,
9742 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009743 MinVersion: ver.version,
9744 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009745 Certificates: []Certificate{rsaChainCertificate},
9746 ClientAuth: RequireAnyClientCert,
9747 },
9748 expectPeerCertificate: &rsaChainCertificate,
9749 flags: []string{
9750 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9751 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9752 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9753 },
9754 })
9755
9756 testCases = append(testCases, testCase{
9757 testType: serverTest,
9758 name: "SendReceiveIntermediate-Server-" + ver.name,
9759 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009760 MinVersion: ver.version,
9761 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009762 Certificates: []Certificate{rsaChainCertificate},
9763 },
9764 expectPeerCertificate: &rsaChainCertificate,
9765 flags: []string{
9766 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9767 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9768 "-require-any-client-certificate",
9769 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9770 },
9771 })
9772 }
9773}
9774
David Benjaminbbaf3672016-11-17 10:53:09 +09009775func addRetainOnlySHA256ClientCertTests() {
9776 for _, ver := range tlsVersions {
9777 // Test that enabling
9778 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9779 // actually requesting a client certificate is a no-op.
9780 testCases = append(testCases, testCase{
9781 testType: serverTest,
9782 name: "RetainOnlySHA256-NoCert-" + ver.name,
9783 config: Config{
9784 MinVersion: ver.version,
9785 MaxVersion: ver.version,
9786 },
9787 flags: []string{
9788 "-retain-only-sha256-client-cert-initial",
9789 "-retain-only-sha256-client-cert-resume",
9790 },
9791 resumeSession: true,
9792 })
9793
9794 // Test that when retaining only a SHA-256 certificate is
9795 // enabled, the hash appears as expected.
9796 testCases = append(testCases, testCase{
9797 testType: serverTest,
9798 name: "RetainOnlySHA256-Cert-" + ver.name,
9799 config: Config{
9800 MinVersion: ver.version,
9801 MaxVersion: ver.version,
9802 Certificates: []Certificate{rsaCertificate},
9803 },
9804 flags: []string{
9805 "-verify-peer",
9806 "-retain-only-sha256-client-cert-initial",
9807 "-retain-only-sha256-client-cert-resume",
9808 "-expect-sha256-client-cert-initial",
9809 "-expect-sha256-client-cert-resume",
9810 },
9811 resumeSession: true,
9812 })
9813
9814 // Test that when the config changes from on to off, a
9815 // resumption is rejected because the server now wants the full
9816 // certificate chain.
9817 testCases = append(testCases, testCase{
9818 testType: serverTest,
9819 name: "RetainOnlySHA256-OnOff-" + ver.name,
9820 config: Config{
9821 MinVersion: ver.version,
9822 MaxVersion: ver.version,
9823 Certificates: []Certificate{rsaCertificate},
9824 },
9825 flags: []string{
9826 "-verify-peer",
9827 "-retain-only-sha256-client-cert-initial",
9828 "-expect-sha256-client-cert-initial",
9829 },
9830 resumeSession: true,
9831 expectResumeRejected: true,
9832 })
9833
9834 // Test that when the config changes from off to on, a
9835 // resumption is rejected because the server now wants just the
9836 // hash.
9837 testCases = append(testCases, testCase{
9838 testType: serverTest,
9839 name: "RetainOnlySHA256-OffOn-" + ver.name,
9840 config: Config{
9841 MinVersion: ver.version,
9842 MaxVersion: ver.version,
9843 Certificates: []Certificate{rsaCertificate},
9844 },
9845 flags: []string{
9846 "-verify-peer",
9847 "-retain-only-sha256-client-cert-resume",
9848 "-expect-sha256-client-cert-resume",
9849 },
9850 resumeSession: true,
9851 expectResumeRejected: true,
9852 })
9853 }
9854}
9855
Adam Langley7c803a62015-06-15 15:35:05 -07009856func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009857 defer wg.Done()
9858
9859 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009860 var err error
9861
David Benjaminba28dfc2016-11-15 17:47:21 +09009862 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009863 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9864 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009865 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009866 if err != nil {
9867 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9868 }
9869 break
9870 }
9871 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009872 } else if *repeatUntilFailure {
9873 for err == nil {
9874 statusChan <- statusMsg{test: test, started: true}
9875 err = runTest(test, shimPath, -1)
9876 }
9877 } else {
9878 statusChan <- statusMsg{test: test, started: true}
9879 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009880 }
Adam Langley95c29f32014-06-20 12:00:00 -07009881 statusChan <- statusMsg{test: test, err: err}
9882 }
9883}
9884
9885type statusMsg struct {
9886 test *testCase
9887 started bool
9888 err error
9889}
9890
David Benjamin5f237bc2015-02-11 17:14:15 -05009891func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009892 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009893
David Benjamin5f237bc2015-02-11 17:14:15 -05009894 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009895 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009896 if !*pipe {
9897 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009898 var erase string
9899 for i := 0; i < lineLen; i++ {
9900 erase += "\b \b"
9901 }
9902 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009903 }
9904
Adam Langley95c29f32014-06-20 12:00:00 -07009905 if msg.started {
9906 started++
9907 } else {
9908 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009909
9910 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009911 if msg.err == errUnimplemented {
9912 if *pipe {
9913 // Print each test instead of a status line.
9914 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9915 }
9916 unimplemented++
9917 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9918 } else {
9919 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9920 failed++
9921 testOutput.addResult(msg.test.name, "FAIL")
9922 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009923 } else {
9924 if *pipe {
9925 // Print each test instead of a status line.
9926 fmt.Printf("PASSED (%s)\n", msg.test.name)
9927 }
9928 testOutput.addResult(msg.test.name, "PASS")
9929 }
Adam Langley95c29f32014-06-20 12:00:00 -07009930 }
9931
David Benjamin5f237bc2015-02-11 17:14:15 -05009932 if !*pipe {
9933 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009934 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009935 lineLen = len(line)
9936 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009937 }
Adam Langley95c29f32014-06-20 12:00:00 -07009938 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009939
9940 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009941}
9942
9943func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009944 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009945 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009946 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009947
Adam Langley7c803a62015-06-15 15:35:05 -07009948 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009949 addCipherSuiteTests()
9950 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009951 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009952 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009953 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009954 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009955 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009956 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009957 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009958 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009959 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009960 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009961 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009962 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009963 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009964 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009965 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009966 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009967 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009968 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009969 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009970 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009971 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009972 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009973 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009974 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009975 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009976 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009977 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009978 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009979 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009980 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009981 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +09009982 addRetainOnlySHA256ClientCertTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009983
9984 var wg sync.WaitGroup
9985
Adam Langley7c803a62015-06-15 15:35:05 -07009986 statusChan := make(chan statusMsg, *numWorkers)
9987 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009988 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009989
EKRf71d7ed2016-08-06 13:25:12 -07009990 if len(*shimConfigFile) != 0 {
9991 encoded, err := ioutil.ReadFile(*shimConfigFile)
9992 if err != nil {
9993 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9994 os.Exit(1)
9995 }
9996
9997 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9998 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9999 os.Exit(1)
10000 }
10001 }
10002
David Benjamin025b3d32014-07-01 19:53:04 -040010003 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010004
Adam Langley7c803a62015-06-15 15:35:05 -070010005 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010006 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010007 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010008 }
10009
David Benjamin270f0a72016-03-17 14:41:36 -040010010 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010011 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010012 matched := true
10013 if len(*testToRun) != 0 {
10014 var err error
10015 matched, err = filepath.Match(*testToRun, testCases[i].name)
10016 if err != nil {
10017 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10018 os.Exit(1)
10019 }
10020 }
10021
EKRf71d7ed2016-08-06 13:25:12 -070010022 if !*includeDisabled {
10023 for pattern := range shimConfig.DisabledTests {
10024 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10025 if err != nil {
10026 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10027 os.Exit(1)
10028 }
10029
10030 if isDisabled {
10031 matched = false
10032 break
10033 }
10034 }
10035 }
10036
David Benjamin17e12922016-07-28 18:04:43 -040010037 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010038 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010039 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010040
10041 // Only run one test if repeating until failure.
10042 if *repeatUntilFailure {
10043 break
10044 }
Adam Langley95c29f32014-06-20 12:00:00 -070010045 }
10046 }
David Benjamin17e12922016-07-28 18:04:43 -040010047
David Benjamin270f0a72016-03-17 14:41:36 -040010048 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010049 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010050 os.Exit(1)
10051 }
Adam Langley95c29f32014-06-20 12:00:00 -070010052
10053 close(testChan)
10054 wg.Wait()
10055 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010056 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010057
10058 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010059
10060 if *jsonOutput != "" {
10061 if err := testOutput.writeTo(*jsonOutput); err != nil {
10062 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10063 }
10064 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010065
EKR842ae6c2016-07-27 09:22:05 +020010066 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10067 os.Exit(1)
10068 }
10069
10070 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010071 os.Exit(1)
10072 }
Adam Langley95c29f32014-06-20 12:00:00 -070010073}