blob: 7d2a6bf7a61208f126d6f0d7c26a250b296da4ff [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.")
Matt Braithwaite9c8c4182016-08-24 14:36:54 -070065 includeRC4 = flag.Bool("include-rc4", false, "If true, test RC4 ciphersuites.")
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 Benjamin33863262016-07-08 17:20:12 -070091 testCertECDSAP256
92 testCertECDSAP384
93 testCertECDSAP521
94)
95
96const (
97 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040098 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070099 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
100 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
101 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400102)
103
104const (
David Benjamina08e49d2014-08-24 01:46:07 -0400105 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400106 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700107 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
108 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
109 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400110 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400111)
112
David Benjamin7944a9f2016-07-12 22:27:01 -0400113var (
114 rsaCertificate Certificate
115 rsa1024Certificate Certificate
116 ecdsaP256Certificate Certificate
117 ecdsaP384Certificate Certificate
118 ecdsaP521Certificate Certificate
119)
David Benjamin33863262016-07-08 17:20:12 -0700120
121var testCerts = []struct {
122 id testCert
123 certFile, keyFile string
124 cert *Certificate
125}{
126 {
127 id: testCertRSA,
128 certFile: rsaCertificateFile,
129 keyFile: rsaKeyFile,
130 cert: &rsaCertificate,
131 },
132 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400133 id: testCertRSA1024,
134 certFile: rsa1024CertificateFile,
135 keyFile: rsa1024KeyFile,
136 cert: &rsa1024Certificate,
137 },
138 {
David Benjamin33863262016-07-08 17:20:12 -0700139 id: testCertECDSAP256,
140 certFile: ecdsaP256CertificateFile,
141 keyFile: ecdsaP256KeyFile,
142 cert: &ecdsaP256Certificate,
143 },
144 {
145 id: testCertECDSAP384,
146 certFile: ecdsaP384CertificateFile,
147 keyFile: ecdsaP384KeyFile,
148 cert: &ecdsaP384Certificate,
149 },
150 {
151 id: testCertECDSAP521,
152 certFile: ecdsaP521CertificateFile,
153 keyFile: ecdsaP521KeyFile,
154 cert: &ecdsaP521Certificate,
155 },
156}
157
David Benjamina08e49d2014-08-24 01:46:07 -0400158var channelIDKey *ecdsa.PrivateKey
159var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700160
David Benjamin61f95272014-11-25 01:55:35 -0500161var testOCSPResponse = []byte{1, 2, 3, 4}
162var testSCTList = []byte{5, 6, 7, 8}
163
Adam Langley95c29f32014-06-20 12:00:00 -0700164func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700165 for i := range testCerts {
166 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
167 if err != nil {
168 panic(err)
169 }
170 cert.OCSPStaple = testOCSPResponse
171 cert.SignedCertificateTimestampList = testSCTList
172 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700173 }
David Benjamina08e49d2014-08-24 01:46:07 -0400174
Adam Langley7c803a62015-06-15 15:35:05 -0700175 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400176 if err != nil {
177 panic(err)
178 }
179 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
180 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
181 panic("bad key type")
182 }
183 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
184 if err != nil {
185 panic(err)
186 }
187 if channelIDKey.Curve != elliptic.P256() {
188 panic("bad curve")
189 }
190
191 channelIDBytes = make([]byte, 64)
192 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
193 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700194}
195
David Benjamin33863262016-07-08 17:20:12 -0700196func getRunnerCertificate(t testCert) Certificate {
197 for _, cert := range testCerts {
198 if cert.id == t {
199 return *cert.cert
200 }
201 }
202 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700203}
204
David Benjamin33863262016-07-08 17:20:12 -0700205func getShimCertificate(t testCert) string {
206 for _, cert := range testCerts {
207 if cert.id == t {
208 return cert.certFile
209 }
210 }
211 panic("Unknown test certificate")
212}
213
214func getShimKey(t testCert) string {
215 for _, cert := range testCerts {
216 if cert.id == t {
217 return cert.keyFile
218 }
219 }
220 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700221}
222
David Benjamin025b3d32014-07-01 19:53:04 -0400223type testType int
224
225const (
226 clientTest testType = iota
227 serverTest
228)
229
David Benjamin6fd297b2014-08-11 18:43:38 -0400230type protocol int
231
232const (
233 tls protocol = iota
234 dtls
235)
236
David Benjaminfc7b0862014-09-06 13:21:53 -0400237const (
238 alpn = 1
239 npn = 2
240)
241
Adam Langley95c29f32014-06-20 12:00:00 -0700242type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400243 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400244 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700245 name string
246 config Config
247 shouldFail bool
248 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700249 // expectedLocalError, if not empty, contains a substring that must be
250 // found in the local error.
251 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400252 // expectedVersion, if non-zero, specifies the TLS version that must be
253 // negotiated.
254 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400255 // expectedResumeVersion, if non-zero, specifies the TLS version that
256 // must be negotiated on resumption. If zero, expectedVersion is used.
257 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400258 // expectedCipher, if non-zero, specifies the TLS cipher suite that
259 // should be negotiated.
260 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400261 // expectChannelID controls whether the connection should have
262 // negotiated a Channel ID with channelIDKey.
263 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400264 // expectedNextProto controls whether the connection should
265 // negotiate a next protocol via NPN or ALPN.
266 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400267 // expectNoNextProto, if true, means that no next protocol should be
268 // negotiated.
269 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400270 // expectedNextProtoType, if non-zero, is the expected next
271 // protocol negotiation mechanism.
272 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500273 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
274 // should be negotiated. If zero, none should be negotiated.
275 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100276 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
277 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100278 // expectedSCTList, if not nil, is the expected SCT list to be received.
279 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700280 // expectedPeerSignatureAlgorithm, if not zero, is the signature
281 // algorithm that the peer should have used in the handshake.
282 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400283 // expectedCurveID, if not zero, is the curve that the handshake should
284 // have used.
285 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700286 // messageLen is the length, in bytes, of the test message that will be
287 // sent.
288 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400289 // messageCount is the number of test messages that will be sent.
290 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400291 // certFile is the path to the certificate to use for the server.
292 certFile string
293 // keyFile is the path to the private key to use for the server.
294 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400295 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400296 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400297 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400298 // resumeRenewedSession controls whether a third connection should be
299 // tested which attempts to resume the second connection's session.
300 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700301 // expectResumeRejected, if true, specifies that the attempted
302 // resumption must be rejected by the client. This is only valid for a
303 // serverTest.
304 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400305 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500306 // resumption. Unless newSessionsOnResume is set,
307 // SessionTicketKey, ServerSessionCache, and
308 // ClientSessionCache are copied from the initial connection's
309 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400310 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500311 // newSessionsOnResume, if true, will cause resumeConfig to
312 // use a different session resumption context.
313 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400314 // noSessionCache, if true, will cause the server to run without a
315 // session cache.
316 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400317 // sendPrefix sends a prefix on the socket before actually performing a
318 // handshake.
319 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400320 // shimWritesFirst controls whether the shim sends an initial "hello"
321 // message before doing a roundtrip with the runner.
322 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400323 // shimShutsDown, if true, runs a test where the shim shuts down the
324 // connection immediately after the handshake rather than echoing
325 // messages from the runner.
326 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400327 // renegotiate indicates the number of times the connection should be
328 // renegotiated during the exchange.
329 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400330 // sendHalfHelloRequest, if true, causes the server to send half a
331 // HelloRequest when the handshake completes.
332 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700333 // renegotiateCiphers is a list of ciphersuite ids that will be
334 // switched in just before renegotiation.
335 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500336 // replayWrites, if true, configures the underlying transport
337 // to replay every write it makes in DTLS tests.
338 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500339 // damageFirstWrite, if true, configures the underlying transport to
340 // damage the final byte of the first application data write.
341 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400342 // exportKeyingMaterial, if non-zero, configures the test to exchange
343 // keying material and verify they match.
344 exportKeyingMaterial int
345 exportLabel string
346 exportContext string
347 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400348 // flags, if not empty, contains a list of command-line flags that will
349 // be passed to the shim program.
350 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700351 // testTLSUnique, if true, causes the shim to send the tls-unique value
352 // which will be compared against the expected value.
353 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400354 // sendEmptyRecords is the number of consecutive empty records to send
355 // before and after the test message.
356 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400357 // sendWarningAlerts is the number of consecutive warning alerts to send
358 // before and after the test message.
359 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400360 // sendKeyUpdates is the number of consecutive key updates to send
361 // before and after the test message.
362 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400363 // expectMessageDropped, if true, means the test message is expected to
364 // be dropped by the client rather than echoed back.
365 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700366}
367
Adam Langley7c803a62015-06-15 15:35:05 -0700368var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700369
David Benjamin9867b7d2016-03-01 23:25:48 -0500370func writeTranscript(test *testCase, isResume bool, data []byte) {
371 if len(data) == 0 {
372 return
373 }
374
375 protocol := "tls"
376 if test.protocol == dtls {
377 protocol = "dtls"
378 }
379
380 side := "client"
381 if test.testType == serverTest {
382 side = "server"
383 }
384
385 dir := path.Join(*transcriptDir, protocol, side)
386 if err := os.MkdirAll(dir, 0755); err != nil {
387 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
388 return
389 }
390
391 name := test.name
392 if isResume {
393 name += "-Resume"
394 } else {
395 name += "-Normal"
396 }
397
398 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
399 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
400 }
401}
402
David Benjamin3ed59772016-03-08 12:50:21 -0500403// A timeoutConn implements an idle timeout on each Read and Write operation.
404type timeoutConn struct {
405 net.Conn
406 timeout time.Duration
407}
408
409func (t *timeoutConn) Read(b []byte) (int, error) {
410 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Read(b)
414}
415
416func (t *timeoutConn) Write(b []byte) (int, error) {
417 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
418 return 0, err
419 }
420 return t.Conn.Write(b)
421}
422
David Benjamin8e6db492015-07-25 18:29:23 -0400423func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400424 if !test.noSessionCache {
425 if config.ClientSessionCache == nil {
426 config.ClientSessionCache = NewLRUClientSessionCache(1)
427 }
428 if config.ServerSessionCache == nil {
429 config.ServerSessionCache = NewLRUServerSessionCache(1)
430 }
431 }
432 if test.testType == clientTest {
433 if len(config.Certificates) == 0 {
434 config.Certificates = []Certificate{rsaCertificate}
435 }
436 } else {
437 // Supply a ServerName to ensure a constant session cache key,
438 // rather than falling back to net.Conn.RemoteAddr.
439 if len(config.ServerName) == 0 {
440 config.ServerName = "test"
441 }
442 }
443 if *fuzzer {
444 config.Bugs.NullAllCiphers = true
445 }
446 if *deterministic {
447 config.Rand = &deterministicRand{}
448 }
449
David Benjamin01784b42016-06-07 18:00:52 -0400450 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500451
David Benjamin6fd297b2014-08-11 18:43:38 -0400452 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500453 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
454 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500455 }
456
David Benjamin9867b7d2016-03-01 23:25:48 -0500457 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500458 local, peer := "client", "server"
459 if test.testType == clientTest {
460 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500461 }
David Benjaminebda9b32015-11-02 15:33:18 -0500462 connDebug := &recordingConn{
463 Conn: conn,
464 isDatagram: test.protocol == dtls,
465 local: local,
466 peer: peer,
467 }
468 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if *flagDebug {
470 defer connDebug.WriteTo(os.Stdout)
471 }
472 if len(*transcriptDir) != 0 {
473 defer func() {
474 writeTranscript(test, isResume, connDebug.Transcript())
475 }()
476 }
David Benjaminebda9b32015-11-02 15:33:18 -0500477
478 if config.Bugs.PacketAdaptor != nil {
479 config.Bugs.PacketAdaptor.debug = connDebug
480 }
481 }
482
483 if test.replayWrites {
484 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400485 }
486
David Benjamin3ed59772016-03-08 12:50:21 -0500487 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500488 if test.damageFirstWrite {
489 connDamage = newDamageAdaptor(conn)
490 conn = connDamage
491 }
492
David Benjamin6fd297b2014-08-11 18:43:38 -0400493 if test.sendPrefix != "" {
494 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
495 return err
496 }
David Benjamin98e882e2014-08-08 13:24:34 -0400497 }
498
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400500 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSServer(conn, config)
503 } else {
504 tlsConn = Server(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 } else {
507 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400508 if test.protocol == dtls {
509 tlsConn = DTLSClient(conn, config)
510 } else {
511 tlsConn = Client(conn, config)
512 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400513 }
David Benjamin30789da2015-08-29 22:56:45 -0400514 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400515
Adam Langley95c29f32014-06-20 12:00:00 -0700516 if err := tlsConn.Handshake(); err != nil {
517 return err
518 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700519
David Benjamin01fe8202014-09-24 15:21:44 -0400520 // TODO(davidben): move all per-connection expectations into a dedicated
521 // expectations struct that can be specified separately for the two
522 // legs.
523 expectedVersion := test.expectedVersion
524 if isResume && test.expectedResumeVersion != 0 {
525 expectedVersion = test.expectedResumeVersion
526 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700527 connState := tlsConn.ConnectionState()
528 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400529 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400530 }
531
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700532 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400533 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
534 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700535 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
536 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
537 }
David Benjamin90da8c82015-04-20 14:57:57 -0400538
David Benjamina08e49d2014-08-24 01:46:07 -0400539 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700540 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400541 if channelID == nil {
542 return fmt.Errorf("no channel ID negotiated")
543 }
544 if channelID.Curve != channelIDKey.Curve ||
545 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
546 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
547 return fmt.Errorf("incorrect channel ID")
548 }
549 }
550
David Benjaminae2888f2014-09-06 12:58:58 -0400551 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700552 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400553 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
554 }
555 }
556
David Benjaminc7ce9772015-10-09 19:32:41 -0400557 if test.expectNoNextProto {
558 if actual := connState.NegotiatedProtocol; actual != "" {
559 return fmt.Errorf("got unexpected next proto %s", actual)
560 }
561 }
562
David Benjaminfc7b0862014-09-06 13:21:53 -0400563 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700564 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400565 return fmt.Errorf("next proto type mismatch")
566 }
567 }
568
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700569 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500570 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
571 }
572
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100573 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300574 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100575 }
576
Paul Lietar4fac72e2015-09-09 13:44:55 +0100577 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
578 return fmt.Errorf("SCT list mismatch")
579 }
580
Nick Harper60edffd2016-06-21 15:19:24 -0700581 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
582 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400583 }
584
Steven Valdez5440fe02016-07-18 12:40:30 -0400585 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
586 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
587 }
588
David Benjaminc565ebb2015-04-03 04:06:36 -0400589 if test.exportKeyingMaterial > 0 {
590 actual := make([]byte, test.exportKeyingMaterial)
591 if _, err := io.ReadFull(tlsConn, actual); err != nil {
592 return err
593 }
594 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
595 if err != nil {
596 return err
597 }
598 if !bytes.Equal(actual, expected) {
599 return fmt.Errorf("keying material mismatch")
600 }
601 }
602
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700603 if test.testTLSUnique {
604 var peersValue [12]byte
605 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
606 return err
607 }
608 expected := tlsConn.ConnectionState().TLSUnique
609 if !bytes.Equal(peersValue[:], expected) {
610 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
611 }
612 }
613
David Benjamine58c4f52014-08-24 03:47:07 -0400614 if test.shimWritesFirst {
615 var buf [5]byte
616 _, err := io.ReadFull(tlsConn, buf[:])
617 if err != nil {
618 return err
619 }
620 if string(buf[:]) != "hello" {
621 return fmt.Errorf("bad initial message")
622 }
623 }
624
Steven Valdez32635b82016-08-16 11:25:03 -0400625 for i := 0; i < test.sendKeyUpdates; i++ {
626 tlsConn.SendKeyUpdate()
627 }
628
David Benjamina8ebe222015-06-06 03:04:39 -0400629 for i := 0; i < test.sendEmptyRecords; i++ {
630 tlsConn.Write(nil)
631 }
632
David Benjamin24f346d2015-06-06 03:28:08 -0400633 for i := 0; i < test.sendWarningAlerts; i++ {
634 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
635 }
636
David Benjamin47921102016-07-28 11:29:18 -0400637 if test.sendHalfHelloRequest {
638 tlsConn.SendHalfHelloRequest()
639 }
640
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400641 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700642 if test.renegotiateCiphers != nil {
643 config.CipherSuites = test.renegotiateCiphers
644 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400645 for i := 0; i < test.renegotiate; i++ {
646 if err := tlsConn.Renegotiate(); err != nil {
647 return err
648 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700649 }
650 } else if test.renegotiateCiphers != nil {
651 panic("renegotiateCiphers without renegotiate")
652 }
653
David Benjamin5fa3eba2015-01-22 16:35:40 -0500654 if test.damageFirstWrite {
655 connDamage.setDamage(true)
656 tlsConn.Write([]byte("DAMAGED WRITE"))
657 connDamage.setDamage(false)
658 }
659
David Benjamin8e6db492015-07-25 18:29:23 -0400660 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700661 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400662 if test.protocol == dtls {
663 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
664 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700665 // Read until EOF.
666 _, err := io.Copy(ioutil.Discard, tlsConn)
667 return err
668 }
David Benjamin4417d052015-04-05 04:17:25 -0400669 if messageLen == 0 {
670 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700671 }
Adam Langley95c29f32014-06-20 12:00:00 -0700672
David Benjamin8e6db492015-07-25 18:29:23 -0400673 messageCount := test.messageCount
674 if messageCount == 0 {
675 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400676 }
677
David Benjamin8e6db492015-07-25 18:29:23 -0400678 for j := 0; j < messageCount; j++ {
679 testMessage := make([]byte, messageLen)
680 for i := range testMessage {
681 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400682 }
David Benjamin8e6db492015-07-25 18:29:23 -0400683 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700684
Steven Valdez32635b82016-08-16 11:25:03 -0400685 for i := 0; i < test.sendKeyUpdates; i++ {
686 tlsConn.SendKeyUpdate()
687 }
688
David Benjamin8e6db492015-07-25 18:29:23 -0400689 for i := 0; i < test.sendEmptyRecords; i++ {
690 tlsConn.Write(nil)
691 }
692
693 for i := 0; i < test.sendWarningAlerts; i++ {
694 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
695 }
696
David Benjamin4f75aaf2015-09-01 16:53:10 -0400697 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400698 // The shim will not respond.
699 continue
700 }
701
David Benjamin8e6db492015-07-25 18:29:23 -0400702 buf := make([]byte, len(testMessage))
703 if test.protocol == dtls {
704 bufTmp := make([]byte, len(buf)+1)
705 n, err := tlsConn.Read(bufTmp)
706 if err != nil {
707 return err
708 }
709 if n != len(buf) {
710 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
711 }
712 copy(buf, bufTmp)
713 } else {
714 _, err := io.ReadFull(tlsConn, buf)
715 if err != nil {
716 return err
717 }
718 }
719
720 for i, v := range buf {
721 if v != testMessage[i]^0xff {
722 return fmt.Errorf("bad reply contents at byte %d", i)
723 }
Adam Langley95c29f32014-06-20 12:00:00 -0700724 }
725 }
726
727 return nil
728}
729
David Benjamin325b5c32014-07-01 19:40:31 -0400730func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
731 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700732 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400733 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700734 }
David Benjamin325b5c32014-07-01 19:40:31 -0400735 valgrindArgs = append(valgrindArgs, path)
736 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700737
David Benjamin325b5c32014-07-01 19:40:31 -0400738 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700739}
740
David Benjamin325b5c32014-07-01 19:40:31 -0400741func gdbOf(path string, args ...string) *exec.Cmd {
742 xtermArgs := []string{"-e", "gdb", "--args"}
743 xtermArgs = append(xtermArgs, path)
744 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700745
David Benjamin325b5c32014-07-01 19:40:31 -0400746 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700747}
748
David Benjamind16bf342015-12-18 00:53:12 -0500749func lldbOf(path string, args ...string) *exec.Cmd {
750 xtermArgs := []string{"-e", "lldb", "--"}
751 xtermArgs = append(xtermArgs, path)
752 xtermArgs = append(xtermArgs, args...)
753
754 return exec.Command("xterm", xtermArgs...)
755}
756
EKR842ae6c2016-07-27 09:22:05 +0200757var (
758 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
759 errUnimplemented = errors.New("child process does not implement needed flags")
760)
Adam Langley69a01602014-11-17 17:26:55 -0800761
David Benjamin87c8a642015-02-21 01:54:29 -0500762// accept accepts a connection from listener, unless waitChan signals a process
763// exit first.
764func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
765 type connOrError struct {
766 conn net.Conn
767 err error
768 }
769 connChan := make(chan connOrError, 1)
770 go func() {
771 conn, err := listener.Accept()
772 connChan <- connOrError{conn, err}
773 close(connChan)
774 }()
775 select {
776 case result := <-connChan:
777 return result.conn, result.err
778 case childErr := <-waitChan:
779 waitChan <- childErr
780 return nil, fmt.Errorf("child exited early: %s", childErr)
781 }
782}
783
EKRf71d7ed2016-08-06 13:25:12 -0700784func translateExpectedError(errorStr string) string {
785 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
786 return translated
787 }
788
789 if *looseErrors {
790 return ""
791 }
792
793 return errorStr
794}
795
Adam Langley7c803a62015-06-15 15:35:05 -0700796func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700797 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
798 panic("Error expected without shouldFail in " + test.name)
799 }
800
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700801 if test.expectResumeRejected && !test.resumeSession {
802 panic("expectResumeRejected without resumeSession in " + test.name)
803 }
804
David Benjamin87c8a642015-02-21 01:54:29 -0500805 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
806 if err != nil {
807 panic(err)
808 }
809 defer func() {
810 if listener != nil {
811 listener.Close()
812 }
813 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700814
David Benjamin87c8a642015-02-21 01:54:29 -0500815 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400816 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400817 flags = append(flags, "-server")
818
David Benjamin025b3d32014-07-01 19:53:04 -0400819 flags = append(flags, "-key-file")
820 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700821 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400822 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700823 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400824 }
825
826 flags = append(flags, "-cert-file")
827 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700828 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400829 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700830 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400831 }
832 }
David Benjamin5a593af2014-08-11 19:51:50 -0400833
David Benjamin6fd297b2014-08-11 18:43:38 -0400834 if test.protocol == dtls {
835 flags = append(flags, "-dtls")
836 }
837
David Benjamin46662482016-08-17 00:51:00 -0400838 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400839 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400840 resumeCount++
841 if test.resumeRenewedSession {
842 resumeCount++
843 }
844 }
845
846 if resumeCount > 0 {
847 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400848 }
849
David Benjamine58c4f52014-08-24 03:47:07 -0400850 if test.shimWritesFirst {
851 flags = append(flags, "-shim-writes-first")
852 }
853
David Benjamin30789da2015-08-29 22:56:45 -0400854 if test.shimShutsDown {
855 flags = append(flags, "-shim-shuts-down")
856 }
857
David Benjaminc565ebb2015-04-03 04:06:36 -0400858 if test.exportKeyingMaterial > 0 {
859 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
860 flags = append(flags, "-export-label", test.exportLabel)
861 flags = append(flags, "-export-context", test.exportContext)
862 if test.useExportContext {
863 flags = append(flags, "-use-export-context")
864 }
865 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700866 if test.expectResumeRejected {
867 flags = append(flags, "-expect-session-miss")
868 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400869
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700870 if test.testTLSUnique {
871 flags = append(flags, "-tls-unique")
872 }
873
David Benjamin025b3d32014-07-01 19:53:04 -0400874 flags = append(flags, test.flags...)
875
876 var shim *exec.Cmd
877 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700878 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700879 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700880 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500881 } else if *useLLDB {
882 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400883 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700884 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400885 }
David Benjamin025b3d32014-07-01 19:53:04 -0400886 shim.Stdin = os.Stdin
887 var stdoutBuf, stderrBuf bytes.Buffer
888 shim.Stdout = &stdoutBuf
889 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800890 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500891 shim.Env = os.Environ()
892 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800893 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400894 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800895 }
896 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
897 }
David Benjamin025b3d32014-07-01 19:53:04 -0400898
899 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700900 panic(err)
901 }
David Benjamin87c8a642015-02-21 01:54:29 -0500902 waitChan := make(chan error, 1)
903 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700904
905 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700906
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn, err := acceptOrWait(listener, waitChan)
908 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400909 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500910 conn.Close()
911 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500912
David Benjamin46662482016-08-17 00:51:00 -0400913 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400914 var resumeConfig Config
915 if test.resumeConfig != nil {
916 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400917 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500918 resumeConfig.SessionTicketKey = config.SessionTicketKey
919 resumeConfig.ClientSessionCache = config.ClientSessionCache
920 resumeConfig.ServerSessionCache = config.ServerSessionCache
921 }
David Benjamin2e045a92016-06-08 13:09:56 -0400922 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400923 } else {
924 resumeConfig = config
925 }
David Benjamin87c8a642015-02-21 01:54:29 -0500926 var connResume net.Conn
927 connResume, err = acceptOrWait(listener, waitChan)
928 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400929 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500930 connResume.Close()
931 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400932 }
933
David Benjamin87c8a642015-02-21 01:54:29 -0500934 // Close the listener now. This is to avoid hangs should the shim try to
935 // open more connections than expected.
936 listener.Close()
937 listener = nil
938
939 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800940 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200941 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
942 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800943 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200944 case 89:
945 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800946 }
947 }
Adam Langley95c29f32014-06-20 12:00:00 -0700948
David Benjamin9bea3492016-03-02 10:59:16 -0500949 // Account for Windows line endings.
950 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
951 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500952
953 // Separate the errors from the shim and those from tools like
954 // AddressSanitizer.
955 var extraStderr string
956 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
957 stderr = stderrParts[0]
958 extraStderr = stderrParts[1]
959 }
960
Adam Langley95c29f32014-06-20 12:00:00 -0700961 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700962 expectedError := translateExpectedError(test.expectedError)
963 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200964
Adam Langleyac61fa32014-06-23 12:03:11 -0700965 localError := "none"
966 if err != nil {
967 localError = err.Error()
968 }
969 if len(test.expectedLocalError) != 0 {
970 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
971 }
Adam Langley95c29f32014-06-20 12:00:00 -0700972
973 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700974 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 if childErr != nil {
976 childError = childErr.Error()
977 }
978
979 var msg string
980 switch {
981 case failed && !test.shouldFail:
982 msg = "unexpected failure"
983 case !failed && test.shouldFail:
984 msg = "unexpected success"
985 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700986 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 default:
988 panic("internal error")
989 }
990
David Benjaminc565ebb2015-04-03 04:06:36 -0400991 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700992 }
993
David Benjaminff3a1492016-03-02 10:12:06 -0500994 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
995 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700996 }
997
998 return nil
999}
1000
1001var tlsVersions = []struct {
1002 name string
1003 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001004 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001005 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001006}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001007 {"SSL3", VersionSSL30, "-no-ssl3", false},
1008 {"TLS1", VersionTLS10, "-no-tls1", true},
1009 {"TLS11", VersionTLS11, "-no-tls11", false},
1010 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001011 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001012}
1013
1014var testCipherSuites = []struct {
1015 name string
1016 id uint16
1017}{
1018 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001019 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001020 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001021 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001022 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001023 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001024 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001025 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1026 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001027 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001028 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1029 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001030 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001031 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1032 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001033 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1034 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001035 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001036 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001037 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001038 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001040 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001045 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001046 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001047 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1048 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1049 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1050 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001051 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1052 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001053 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1054 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001055 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001056 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1057 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001058 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001059}
1060
David Benjamin8b8c0062014-11-23 02:47:52 -05001061func hasComponent(suiteName, component string) bool {
1062 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1063}
1064
David Benjaminf7768e42014-08-31 02:06:47 -04001065func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001066 return hasComponent(suiteName, "GCM") ||
1067 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001068 hasComponent(suiteName, "SHA384") ||
1069 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001070}
1071
Nick Harper1fd39d82016-06-14 18:14:35 -07001072func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001073 // Only AEADs.
1074 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1075 return false
1076 }
1077 // No old CHACHA20_POLY1305.
1078 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1079 return false
1080 }
1081 // Must have ECDHE.
1082 // TODO(davidben,svaldez): Add pure PSK support.
1083 if !hasComponent(suiteName, "ECDHE") {
1084 return false
1085 }
1086 // TODO(davidben,svaldez): Add PSK support.
1087 if hasComponent(suiteName, "PSK") {
1088 return false
1089 }
1090 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001091}
1092
David Benjamin8b8c0062014-11-23 02:47:52 -05001093func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001094 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001095}
1096
Adam Langleya7997f12015-05-14 17:38:50 -07001097func bigFromHex(hex string) *big.Int {
1098 ret, ok := new(big.Int).SetString(hex, 16)
1099 if !ok {
1100 panic("failed to parse hex number 0x" + hex)
1101 }
1102 return ret
1103}
1104
Adam Langley7c803a62015-06-15 15:35:05 -07001105func addBasicTests() {
1106 basicTests := []testCase{
1107 {
Adam Langley7c803a62015-06-15 15:35:05 -07001108 name: "NoFallbackSCSV",
1109 config: Config{
1110 Bugs: ProtocolBugs{
1111 FailIfNotFallbackSCSV: true,
1112 },
1113 },
1114 shouldFail: true,
1115 expectedLocalError: "no fallback SCSV found",
1116 },
1117 {
1118 name: "SendFallbackSCSV",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 FailIfNotFallbackSCSV: true,
1122 },
1123 },
1124 flags: []string{"-fallback-scsv"},
1125 },
1126 {
1127 name: "ClientCertificateTypes",
1128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001129 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001130 ClientAuth: RequestClientCert,
1131 ClientCertificateTypes: []byte{
1132 CertTypeDSSSign,
1133 CertTypeRSASign,
1134 CertTypeECDSASign,
1135 },
1136 },
1137 flags: []string{
1138 "-expect-certificate-types",
1139 base64.StdEncoding.EncodeToString([]byte{
1140 CertTypeDSSSign,
1141 CertTypeRSASign,
1142 CertTypeECDSASign,
1143 }),
1144 },
1145 },
1146 {
Adam Langley7c803a62015-06-15 15:35:05 -07001147 name: "UnauthenticatedECDH",
1148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001149 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1151 Bugs: ProtocolBugs{
1152 UnauthenticatedECDH: true,
1153 },
1154 },
1155 shouldFail: true,
1156 expectedError: ":UNEXPECTED_MESSAGE:",
1157 },
1158 {
1159 name: "SkipCertificateStatus",
1160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001161 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001162 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1163 Bugs: ProtocolBugs{
1164 SkipCertificateStatus: true,
1165 },
1166 },
1167 flags: []string{
1168 "-enable-ocsp-stapling",
1169 },
1170 },
1171 {
1172 name: "SkipServerKeyExchange",
1173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001174 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1176 Bugs: ProtocolBugs{
1177 SkipServerKeyExchange: true,
1178 },
1179 },
1180 shouldFail: true,
1181 expectedError: ":UNEXPECTED_MESSAGE:",
1182 },
1183 {
Adam Langley7c803a62015-06-15 15:35:05 -07001184 testType: serverTest,
1185 name: "Alert",
1186 config: Config{
1187 Bugs: ProtocolBugs{
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1193 },
1194 {
1195 protocol: dtls,
1196 testType: serverTest,
1197 name: "Alert-DTLS",
1198 config: Config{
1199 Bugs: ProtocolBugs{
1200 SendSpuriousAlert: alertRecordOverflow,
1201 },
1202 },
1203 shouldFail: true,
1204 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1205 },
1206 {
1207 testType: serverTest,
1208 name: "FragmentAlert",
1209 config: Config{
1210 Bugs: ProtocolBugs{
1211 FragmentAlert: true,
1212 SendSpuriousAlert: alertRecordOverflow,
1213 },
1214 },
1215 shouldFail: true,
1216 expectedError: ":BAD_ALERT:",
1217 },
1218 {
1219 protocol: dtls,
1220 testType: serverTest,
1221 name: "FragmentAlert-DTLS",
1222 config: Config{
1223 Bugs: ProtocolBugs{
1224 FragmentAlert: true,
1225 SendSpuriousAlert: alertRecordOverflow,
1226 },
1227 },
1228 shouldFail: true,
1229 expectedError: ":BAD_ALERT:",
1230 },
1231 {
1232 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001233 name: "DoubleAlert",
1234 config: Config{
1235 Bugs: ProtocolBugs{
1236 DoubleAlert: true,
1237 SendSpuriousAlert: alertRecordOverflow,
1238 },
1239 },
1240 shouldFail: true,
1241 expectedError: ":BAD_ALERT:",
1242 },
1243 {
1244 protocol: dtls,
1245 testType: serverTest,
1246 name: "DoubleAlert-DTLS",
1247 config: Config{
1248 Bugs: ProtocolBugs{
1249 DoubleAlert: true,
1250 SendSpuriousAlert: alertRecordOverflow,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":BAD_ALERT:",
1255 },
1256 {
Adam Langley7c803a62015-06-15 15:35:05 -07001257 name: "SkipNewSessionTicket",
1258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001259 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001260 Bugs: ProtocolBugs{
1261 SkipNewSessionTicket: true,
1262 },
1263 },
1264 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001265 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001266 },
1267 {
1268 testType: serverTest,
1269 name: "FallbackSCSV",
1270 config: Config{
1271 MaxVersion: VersionTLS11,
1272 Bugs: ProtocolBugs{
1273 SendFallbackSCSV: true,
1274 },
1275 },
1276 shouldFail: true,
1277 expectedError: ":INAPPROPRIATE_FALLBACK:",
1278 },
1279 {
1280 testType: serverTest,
1281 name: "FallbackSCSV-VersionMatch",
1282 config: Config{
1283 Bugs: ProtocolBugs{
1284 SendFallbackSCSV: true,
1285 },
1286 },
1287 },
1288 {
1289 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001290 name: "FallbackSCSV-VersionMatch-TLS12",
1291 config: Config{
1292 MaxVersion: VersionTLS12,
1293 Bugs: ProtocolBugs{
1294 SendFallbackSCSV: true,
1295 },
1296 },
1297 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1298 },
1299 {
1300 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001301 name: "FragmentedClientVersion",
1302 config: Config{
1303 Bugs: ProtocolBugs{
1304 MaxHandshakeRecordLength: 1,
1305 FragmentClientVersion: true,
1306 },
1307 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001308 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001309 },
1310 {
Adam Langley7c803a62015-06-15 15:35:05 -07001311 testType: serverTest,
1312 name: "HttpGET",
1313 sendPrefix: "GET / HTTP/1.0\n",
1314 shouldFail: true,
1315 expectedError: ":HTTP_REQUEST:",
1316 },
1317 {
1318 testType: serverTest,
1319 name: "HttpPOST",
1320 sendPrefix: "POST / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpHEAD",
1327 sendPrefix: "HEAD / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpPUT",
1334 sendPrefix: "PUT / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpCONNECT",
1341 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTPS_PROXY_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "Garbage",
1348 sendPrefix: "blah",
1349 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001350 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001351 },
1352 {
Adam Langley7c803a62015-06-15 15:35:05 -07001353 name: "RSAEphemeralKey",
1354 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001355 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001356 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1357 Bugs: ProtocolBugs{
1358 RSAEphemeralKey: true,
1359 },
1360 },
1361 shouldFail: true,
1362 expectedError: ":UNEXPECTED_MESSAGE:",
1363 },
1364 {
1365 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001366 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001367 shouldFail: true,
1368 expectedError: ":WRONG_SSL_VERSION:",
1369 },
1370 {
1371 protocol: dtls,
1372 name: "DisableEverything-DTLS",
1373 flags: []string{"-no-tls12", "-no-tls1"},
1374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
Adam Langley7c803a62015-06-15 15:35:05 -07001378 protocol: dtls,
1379 testType: serverTest,
1380 name: "MTU",
1381 config: Config{
1382 Bugs: ProtocolBugs{
1383 MaxPacketLength: 256,
1384 },
1385 },
1386 flags: []string{"-mtu", "256"},
1387 },
1388 {
1389 protocol: dtls,
1390 testType: serverTest,
1391 name: "MTUExceeded",
1392 config: Config{
1393 Bugs: ProtocolBugs{
1394 MaxPacketLength: 255,
1395 },
1396 },
1397 flags: []string{"-mtu", "256"},
1398 shouldFail: true,
1399 expectedLocalError: "dtls: exceeded maximum packet length",
1400 },
1401 {
1402 name: "CertMismatchRSA",
1403 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001404 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001405 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001406 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001407 Bugs: ProtocolBugs{
1408 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1413 },
1414 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001415 name: "CertMismatchRSA-TLS13",
1416 config: Config{
1417 MaxVersion: VersionTLS13,
1418 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1419 Certificates: []Certificate{ecdsaP256Certificate},
1420 Bugs: ProtocolBugs{
1421 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1422 },
1423 },
1424 shouldFail: true,
1425 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1426 },
1427 {
Adam Langley7c803a62015-06-15 15:35:05 -07001428 name: "CertMismatchECDSA",
1429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001430 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001432 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001433 Bugs: ProtocolBugs{
1434 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1439 },
1440 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001441 name: "CertMismatchECDSA-TLS13",
1442 config: Config{
1443 MaxVersion: VersionTLS13,
1444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1445 Certificates: []Certificate{rsaCertificate},
1446 Bugs: ProtocolBugs{
1447 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1448 },
1449 },
1450 shouldFail: true,
1451 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1452 },
1453 {
Adam Langley7c803a62015-06-15 15:35:05 -07001454 name: "EmptyCertificateList",
1455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001456 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1458 Bugs: ProtocolBugs{
1459 EmptyCertificateList: true,
1460 },
1461 },
1462 shouldFail: true,
1463 expectedError: ":DECODE_ERROR:",
1464 },
1465 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001466 name: "EmptyCertificateList-TLS13",
1467 config: Config{
1468 MaxVersion: VersionTLS13,
1469 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1470 Bugs: ProtocolBugs{
1471 EmptyCertificateList: true,
1472 },
1473 },
1474 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001475 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001476 },
1477 {
Adam Langley7c803a62015-06-15 15:35:05 -07001478 name: "TLSFatalBadPackets",
1479 damageFirstWrite: true,
1480 shouldFail: true,
1481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1482 },
1483 {
1484 protocol: dtls,
1485 name: "DTLSIgnoreBadPackets",
1486 damageFirstWrite: true,
1487 },
1488 {
1489 protocol: dtls,
1490 name: "DTLSIgnoreBadPackets-Async",
1491 damageFirstWrite: true,
1492 flags: []string{"-async"},
1493 },
1494 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 name: "AppDataBeforeHandshake",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":UNEXPECTED_RECORD:",
1503 },
1504 {
1505 name: "AppDataBeforeHandshake-Empty",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 AppDataBeforeHandshake: []byte{},
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "AppDataBeforeHandshake-DTLS",
1517 config: Config{
1518 Bugs: ProtocolBugs{
1519 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":UNEXPECTED_RECORD:",
1524 },
1525 {
1526 protocol: dtls,
1527 name: "AppDataBeforeHandshake-DTLS-Empty",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 AppDataBeforeHandshake: []byte{},
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":UNEXPECTED_RECORD:",
1535 },
1536 {
Adam Langley7c803a62015-06-15 15:35:05 -07001537 name: "AppDataAfterChangeCipherSpec",
1538 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001539 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001540 Bugs: ProtocolBugs{
1541 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1542 },
1543 },
1544 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001545 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001546 },
1547 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001548 name: "AppDataAfterChangeCipherSpec-Empty",
1549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001550 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001551 Bugs: ProtocolBugs{
1552 AppDataAfterChangeCipherSpec: []byte{},
1553 },
1554 },
1555 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001556 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 protocol: dtls,
1560 name: "AppDataAfterChangeCipherSpec-DTLS",
1561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001562 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001563 Bugs: ProtocolBugs{
1564 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1565 },
1566 },
1567 // BoringSSL's DTLS implementation will drop the out-of-order
1568 // application data.
1569 },
1570 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 protocol: dtls,
1572 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1573 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001574 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 Bugs: ProtocolBugs{
1576 AppDataAfterChangeCipherSpec: []byte{},
1577 },
1578 },
1579 // BoringSSL's DTLS implementation will drop the out-of-order
1580 // application data.
1581 },
1582 {
Adam Langley7c803a62015-06-15 15:35:05 -07001583 name: "AlertAfterChangeCipherSpec",
1584 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 Bugs: ProtocolBugs{
1587 AlertAfterChangeCipherSpec: alertRecordOverflow,
1588 },
1589 },
1590 shouldFail: true,
1591 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1592 },
1593 {
1594 protocol: dtls,
1595 name: "AlertAfterChangeCipherSpec-DTLS",
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: "ReorderHandshakeFragments-Small-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 ReorderHandshakeFragments: true,
1611 // Small enough that every handshake message is
1612 // fragmented.
1613 MaxHandshakeRecordLength: 2,
1614 },
1615 },
1616 },
1617 {
1618 protocol: dtls,
1619 name: "ReorderHandshakeFragments-Large-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 ReorderHandshakeFragments: true,
1623 // Large enough that no handshake message is
1624 // fragmented.
1625 MaxHandshakeRecordLength: 2048,
1626 },
1627 },
1628 },
1629 {
1630 protocol: dtls,
1631 name: "MixCompleteMessageWithFragments-DTLS",
1632 config: Config{
1633 Bugs: ProtocolBugs{
1634 ReorderHandshakeFragments: true,
1635 MixCompleteMessageWithFragments: true,
1636 MaxHandshakeRecordLength: 2,
1637 },
1638 },
1639 },
1640 {
1641 name: "SendInvalidRecordType",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 SendInvalidRecordType: true,
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "SendInvalidRecordType-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 SendInvalidRecordType: true,
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
1662 name: "FalseStart-SkipServerSecondLeg",
1663 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1666 NextProtos: []string{"foo"},
1667 Bugs: ProtocolBugs{
1668 SkipNewSessionTicket: true,
1669 SkipChangeCipherSpec: true,
1670 SkipFinished: true,
1671 ExpectFalseStart: true,
1672 },
1673 },
1674 flags: []string{
1675 "-false-start",
1676 "-handshake-never-done",
1677 "-advertise-alpn", "\x03foo",
1678 },
1679 shimWritesFirst: true,
1680 shouldFail: true,
1681 expectedError: ":UNEXPECTED_RECORD:",
1682 },
1683 {
1684 name: "FalseStart-SkipServerSecondLeg-Implicit",
1685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001686 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1688 NextProtos: []string{"foo"},
1689 Bugs: ProtocolBugs{
1690 SkipNewSessionTicket: true,
1691 SkipChangeCipherSpec: true,
1692 SkipFinished: true,
1693 },
1694 },
1695 flags: []string{
1696 "-implicit-handshake",
1697 "-false-start",
1698 "-handshake-never-done",
1699 "-advertise-alpn", "\x03foo",
1700 },
1701 shouldFail: true,
1702 expectedError: ":UNEXPECTED_RECORD:",
1703 },
1704 {
1705 testType: serverTest,
1706 name: "FailEarlyCallback",
1707 flags: []string{"-fail-early-callback"},
1708 shouldFail: true,
1709 expectedError: ":CONNECTION_REJECTED:",
1710 expectedLocalError: "remote error: access denied",
1711 },
1712 {
Adam Langley7c803a62015-06-15 15:35:05 -07001713 protocol: dtls,
1714 name: "FragmentMessageTypeMismatch-DTLS",
1715 config: Config{
1716 Bugs: ProtocolBugs{
1717 MaxHandshakeRecordLength: 2,
1718 FragmentMessageTypeMismatch: true,
1719 },
1720 },
1721 shouldFail: true,
1722 expectedError: ":FRAGMENT_MISMATCH:",
1723 },
1724 {
1725 protocol: dtls,
1726 name: "FragmentMessageLengthMismatch-DTLS",
1727 config: Config{
1728 Bugs: ProtocolBugs{
1729 MaxHandshakeRecordLength: 2,
1730 FragmentMessageLengthMismatch: true,
1731 },
1732 },
1733 shouldFail: true,
1734 expectedError: ":FRAGMENT_MISMATCH:",
1735 },
1736 {
1737 protocol: dtls,
1738 name: "SplitFragments-Header-DTLS",
1739 config: Config{
1740 Bugs: ProtocolBugs{
1741 SplitFragments: 2,
1742 },
1743 },
1744 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001745 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001746 },
1747 {
1748 protocol: dtls,
1749 name: "SplitFragments-Boundary-DTLS",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 SplitFragments: dtlsRecordHeaderLen,
1753 },
1754 },
1755 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001756 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001757 },
1758 {
1759 protocol: dtls,
1760 name: "SplitFragments-Body-DTLS",
1761 config: Config{
1762 Bugs: ProtocolBugs{
1763 SplitFragments: dtlsRecordHeaderLen + 1,
1764 },
1765 },
1766 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001767 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001768 },
1769 {
1770 protocol: dtls,
1771 name: "SendEmptyFragments-DTLS",
1772 config: Config{
1773 Bugs: ProtocolBugs{
1774 SendEmptyFragments: true,
1775 },
1776 },
1777 },
1778 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001779 name: "BadFinished-Client",
1780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001781 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001782 Bugs: ProtocolBugs{
1783 BadFinished: true,
1784 },
1785 },
1786 shouldFail: true,
1787 expectedError: ":DIGEST_CHECK_FAILED:",
1788 },
1789 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001790 name: "BadFinished-Client-TLS13",
1791 config: Config{
1792 MaxVersion: VersionTLS13,
1793 Bugs: ProtocolBugs{
1794 BadFinished: true,
1795 },
1796 },
1797 shouldFail: true,
1798 expectedError: ":DIGEST_CHECK_FAILED:",
1799 },
1800 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001801 testType: serverTest,
1802 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001804 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001805 Bugs: ProtocolBugs{
1806 BadFinished: true,
1807 },
1808 },
1809 shouldFail: true,
1810 expectedError: ":DIGEST_CHECK_FAILED:",
1811 },
1812 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001813 testType: serverTest,
1814 name: "BadFinished-Server-TLS13",
1815 config: Config{
1816 MaxVersion: VersionTLS13,
1817 Bugs: ProtocolBugs{
1818 BadFinished: true,
1819 },
1820 },
1821 shouldFail: true,
1822 expectedError: ":DIGEST_CHECK_FAILED:",
1823 },
1824 {
Adam Langley7c803a62015-06-15 15:35:05 -07001825 name: "FalseStart-BadFinished",
1826 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001827 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1829 NextProtos: []string{"foo"},
1830 Bugs: ProtocolBugs{
1831 BadFinished: true,
1832 ExpectFalseStart: true,
1833 },
1834 },
1835 flags: []string{
1836 "-false-start",
1837 "-handshake-never-done",
1838 "-advertise-alpn", "\x03foo",
1839 },
1840 shimWritesFirst: true,
1841 shouldFail: true,
1842 expectedError: ":DIGEST_CHECK_FAILED:",
1843 },
1844 {
1845 name: "NoFalseStart-NoALPN",
1846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1849 Bugs: ProtocolBugs{
1850 ExpectFalseStart: true,
1851 AlertBeforeFalseStartTest: alertAccessDenied,
1852 },
1853 },
1854 flags: []string{
1855 "-false-start",
1856 },
1857 shimWritesFirst: true,
1858 shouldFail: true,
1859 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1860 expectedLocalError: "tls: peer did not false start: EOF",
1861 },
1862 {
1863 name: "NoFalseStart-NoAEAD",
1864 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001865 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001866 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1867 NextProtos: []string{"foo"},
1868 Bugs: ProtocolBugs{
1869 ExpectFalseStart: true,
1870 AlertBeforeFalseStartTest: alertAccessDenied,
1871 },
1872 },
1873 flags: []string{
1874 "-false-start",
1875 "-advertise-alpn", "\x03foo",
1876 },
1877 shimWritesFirst: true,
1878 shouldFail: true,
1879 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1880 expectedLocalError: "tls: peer did not false start: EOF",
1881 },
1882 {
1883 name: "NoFalseStart-RSA",
1884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001885 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001886 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1887 NextProtos: []string{"foo"},
1888 Bugs: ProtocolBugs{
1889 ExpectFalseStart: true,
1890 AlertBeforeFalseStartTest: alertAccessDenied,
1891 },
1892 },
1893 flags: []string{
1894 "-false-start",
1895 "-advertise-alpn", "\x03foo",
1896 },
1897 shimWritesFirst: true,
1898 shouldFail: true,
1899 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1900 expectedLocalError: "tls: peer did not false start: EOF",
1901 },
1902 {
1903 name: "NoFalseStart-DHE_RSA",
1904 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001905 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001906 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1907 NextProtos: []string{"foo"},
1908 Bugs: ProtocolBugs{
1909 ExpectFalseStart: true,
1910 AlertBeforeFalseStartTest: alertAccessDenied,
1911 },
1912 },
1913 flags: []string{
1914 "-false-start",
1915 "-advertise-alpn", "\x03foo",
1916 },
1917 shimWritesFirst: true,
1918 shouldFail: true,
1919 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1920 expectedLocalError: "tls: peer did not false start: EOF",
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 protocol: dtls,
1924 name: "SendSplitAlert-Sync",
1925 config: Config{
1926 Bugs: ProtocolBugs{
1927 SendSplitAlert: true,
1928 },
1929 },
1930 },
1931 {
1932 protocol: dtls,
1933 name: "SendSplitAlert-Async",
1934 config: Config{
1935 Bugs: ProtocolBugs{
1936 SendSplitAlert: true,
1937 },
1938 },
1939 flags: []string{"-async"},
1940 },
1941 {
1942 protocol: dtls,
1943 name: "PackDTLSHandshake",
1944 config: Config{
1945 Bugs: ProtocolBugs{
1946 MaxHandshakeRecordLength: 2,
1947 PackHandshakeFragments: 20,
1948 PackHandshakeRecords: 200,
1949 },
1950 },
1951 },
1952 {
Adam Langley7c803a62015-06-15 15:35:05 -07001953 name: "SendEmptyRecords-Pass",
1954 sendEmptyRecords: 32,
1955 },
1956 {
1957 name: "SendEmptyRecords",
1958 sendEmptyRecords: 33,
1959 shouldFail: true,
1960 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1961 },
1962 {
1963 name: "SendEmptyRecords-Async",
1964 sendEmptyRecords: 33,
1965 flags: []string{"-async"},
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
David Benjamine8e84b92016-08-03 15:39:47 -04001970 name: "SendWarningAlerts-Pass",
1971 config: Config{
1972 MaxVersion: VersionTLS12,
1973 },
Adam Langley7c803a62015-06-15 15:35:05 -07001974 sendWarningAlerts: 4,
1975 },
1976 {
David Benjamine8e84b92016-08-03 15:39:47 -04001977 protocol: dtls,
1978 name: "SendWarningAlerts-DTLS-Pass",
1979 config: Config{
1980 MaxVersion: VersionTLS12,
1981 },
Adam Langley7c803a62015-06-15 15:35:05 -07001982 sendWarningAlerts: 4,
1983 },
1984 {
David Benjamine8e84b92016-08-03 15:39:47 -04001985 name: "SendWarningAlerts-TLS13",
1986 config: Config{
1987 MaxVersion: VersionTLS13,
1988 },
1989 sendWarningAlerts: 4,
1990 shouldFail: true,
1991 expectedError: ":BAD_ALERT:",
1992 expectedLocalError: "remote error: error decoding message",
1993 },
1994 {
1995 name: "SendWarningAlerts",
1996 config: Config{
1997 MaxVersion: VersionTLS12,
1998 },
Adam Langley7c803a62015-06-15 15:35:05 -07001999 sendWarningAlerts: 5,
2000 shouldFail: true,
2001 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2002 },
2003 {
David Benjamine8e84b92016-08-03 15:39:47 -04002004 name: "SendWarningAlerts-Async",
2005 config: Config{
2006 MaxVersion: VersionTLS12,
2007 },
Adam Langley7c803a62015-06-15 15:35:05 -07002008 sendWarningAlerts: 5,
2009 flags: []string{"-async"},
2010 shouldFail: true,
2011 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2012 },
David Benjaminba4594a2015-06-18 18:36:15 -04002013 {
Steven Valdez32635b82016-08-16 11:25:03 -04002014 name: "SendKeyUpdates",
2015 config: Config{
2016 MaxVersion: VersionTLS13,
2017 },
2018 sendKeyUpdates: 33,
2019 shouldFail: true,
2020 expectedError: ":TOO_MANY_KEY_UPDATES:",
2021 },
2022 {
David Benjaminba4594a2015-06-18 18:36:15 -04002023 name: "EmptySessionID",
2024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002025 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002026 SessionTicketsDisabled: true,
2027 },
2028 noSessionCache: true,
2029 flags: []string{"-expect-no-session"},
2030 },
David Benjamin30789da2015-08-29 22:56:45 -04002031 {
2032 name: "Unclean-Shutdown",
2033 config: Config{
2034 Bugs: ProtocolBugs{
2035 NoCloseNotify: true,
2036 ExpectCloseNotify: true,
2037 },
2038 },
2039 shimShutsDown: true,
2040 flags: []string{"-check-close-notify"},
2041 shouldFail: true,
2042 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2043 },
2044 {
2045 name: "Unclean-Shutdown-Ignored",
2046 config: Config{
2047 Bugs: ProtocolBugs{
2048 NoCloseNotify: true,
2049 },
2050 },
2051 shimShutsDown: true,
2052 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002053 {
David Benjaminfa214e42016-05-10 17:03:10 -04002054 name: "Unclean-Shutdown-Alert",
2055 config: Config{
2056 Bugs: ProtocolBugs{
2057 SendAlertOnShutdown: alertDecompressionFailure,
2058 ExpectCloseNotify: true,
2059 },
2060 },
2061 shimShutsDown: true,
2062 flags: []string{"-check-close-notify"},
2063 shouldFail: true,
2064 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2065 },
2066 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002067 name: "LargePlaintext",
2068 config: Config{
2069 Bugs: ProtocolBugs{
2070 SendLargeRecords: true,
2071 },
2072 },
2073 messageLen: maxPlaintext + 1,
2074 shouldFail: true,
2075 expectedError: ":DATA_LENGTH_TOO_LONG:",
2076 },
2077 {
2078 protocol: dtls,
2079 name: "LargePlaintext-DTLS",
2080 config: Config{
2081 Bugs: ProtocolBugs{
2082 SendLargeRecords: true,
2083 },
2084 },
2085 messageLen: maxPlaintext + 1,
2086 shouldFail: true,
2087 expectedError: ":DATA_LENGTH_TOO_LONG:",
2088 },
2089 {
2090 name: "LargeCiphertext",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 SendLargeRecords: true,
2094 },
2095 },
2096 messageLen: maxPlaintext * 2,
2097 shouldFail: true,
2098 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2099 },
2100 {
2101 protocol: dtls,
2102 name: "LargeCiphertext-DTLS",
2103 config: Config{
2104 Bugs: ProtocolBugs{
2105 SendLargeRecords: true,
2106 },
2107 },
2108 messageLen: maxPlaintext * 2,
2109 // Unlike the other four cases, DTLS drops records which
2110 // are invalid before authentication, so the connection
2111 // does not fail.
2112 expectMessageDropped: true,
2113 },
David Benjamindd6fed92015-10-23 17:41:12 -04002114 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002115 // In TLS 1.2 and below, empty NewSessionTicket messages
2116 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002117 name: "SendEmptySessionTicket",
2118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002120 Bugs: ProtocolBugs{
2121 SendEmptySessionTicket: true,
2122 FailIfSessionOffered: true,
2123 },
2124 },
David Benjamin46662482016-08-17 00:51:00 -04002125 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002126 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002127 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002128 name: "BadHelloRequest-1",
2129 renegotiate: 1,
2130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002131 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 Bugs: ProtocolBugs{
2133 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2134 },
2135 },
2136 flags: []string{
2137 "-renegotiate-freely",
2138 "-expect-total-renegotiations", "1",
2139 },
2140 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002141 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002142 },
2143 {
2144 name: "BadHelloRequest-2",
2145 renegotiate: 1,
2146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002147 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002148 Bugs: ProtocolBugs{
2149 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2150 },
2151 },
2152 flags: []string{
2153 "-renegotiate-freely",
2154 "-expect-total-renegotiations", "1",
2155 },
2156 shouldFail: true,
2157 expectedError: ":BAD_HELLO_REQUEST:",
2158 },
David Benjaminef1b0092015-11-21 14:05:44 -05002159 {
2160 testType: serverTest,
2161 name: "SupportTicketsWithSessionID",
2162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002163 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002164 SessionTicketsDisabled: true,
2165 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002166 resumeConfig: &Config{
2167 MaxVersion: VersionTLS12,
2168 },
David Benjaminef1b0092015-11-21 14:05:44 -05002169 resumeSession: true,
2170 },
David Benjamin02edcd02016-07-27 17:40:37 -04002171 {
2172 protocol: dtls,
2173 name: "DTLS-SendExtraFinished",
2174 config: Config{
2175 Bugs: ProtocolBugs{
2176 SendExtraFinished: true,
2177 },
2178 },
2179 shouldFail: true,
2180 expectedError: ":UNEXPECTED_RECORD:",
2181 },
2182 {
2183 protocol: dtls,
2184 name: "DTLS-SendExtraFinished-Reordered",
2185 config: Config{
2186 Bugs: ProtocolBugs{
2187 MaxHandshakeRecordLength: 2,
2188 ReorderHandshakeFragments: true,
2189 SendExtraFinished: true,
2190 },
2191 },
2192 shouldFail: true,
2193 expectedError: ":UNEXPECTED_RECORD:",
2194 },
David Benjamine97fb482016-07-29 09:23:07 -04002195 {
2196 testType: serverTest,
2197 name: "V2ClientHello-EmptyRecordPrefix",
2198 config: Config{
2199 // Choose a cipher suite that does not involve
2200 // elliptic curves, so no extensions are
2201 // involved.
2202 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002203 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002204 Bugs: ProtocolBugs{
2205 SendV2ClientHello: true,
2206 },
2207 },
2208 sendPrefix: string([]byte{
2209 byte(recordTypeHandshake),
2210 3, 1, // version
2211 0, 0, // length
2212 }),
2213 // A no-op empty record may not be sent before V2ClientHello.
2214 shouldFail: true,
2215 expectedError: ":WRONG_VERSION_NUMBER:",
2216 },
2217 {
2218 testType: serverTest,
2219 name: "V2ClientHello-WarningAlertPrefix",
2220 config: Config{
2221 // Choose a cipher suite that does not involve
2222 // elliptic curves, so no extensions are
2223 // involved.
2224 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002225 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002226 Bugs: ProtocolBugs{
2227 SendV2ClientHello: true,
2228 },
2229 },
2230 sendPrefix: string([]byte{
2231 byte(recordTypeAlert),
2232 3, 1, // version
2233 0, 2, // length
2234 alertLevelWarning, byte(alertDecompressionFailure),
2235 }),
2236 // A no-op warning alert may not be sent before V2ClientHello.
2237 shouldFail: true,
2238 expectedError: ":WRONG_VERSION_NUMBER:",
2239 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002240 {
2241 testType: clientTest,
2242 name: "KeyUpdate",
2243 config: Config{
2244 MaxVersion: VersionTLS13,
2245 Bugs: ProtocolBugs{
2246 SendKeyUpdateBeforeEveryAppDataRecord: true,
2247 },
2248 },
2249 },
David Benjaminabe94e32016-09-04 14:18:58 -04002250 {
2251 name: "SendSNIWarningAlert",
2252 config: Config{
2253 MaxVersion: VersionTLS12,
2254 Bugs: ProtocolBugs{
2255 SendSNIWarningAlert: true,
2256 },
2257 },
2258 },
David Benjaminc241d792016-09-09 10:34:20 -04002259 {
2260 testType: serverTest,
2261 name: "ExtraCompressionMethods-TLS12",
2262 config: Config{
2263 MaxVersion: VersionTLS12,
2264 Bugs: ProtocolBugs{
2265 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2266 },
2267 },
2268 },
2269 {
2270 testType: serverTest,
2271 name: "ExtraCompressionMethods-TLS13",
2272 config: Config{
2273 MaxVersion: VersionTLS13,
2274 Bugs: ProtocolBugs{
2275 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2276 },
2277 },
2278 shouldFail: true,
2279 expectedError: ":INVALID_COMPRESSION_LIST:",
2280 expectedLocalError: "remote error: illegal parameter",
2281 },
2282 {
2283 testType: serverTest,
2284 name: "NoNullCompression-TLS12",
2285 config: Config{
2286 MaxVersion: VersionTLS12,
2287 Bugs: ProtocolBugs{
2288 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2289 },
2290 },
2291 shouldFail: true,
2292 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2293 expectedLocalError: "remote error: illegal parameter",
2294 },
2295 {
2296 testType: serverTest,
2297 name: "NoNullCompression-TLS13",
2298 config: Config{
2299 MaxVersion: VersionTLS13,
2300 Bugs: ProtocolBugs{
2301 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2302 },
2303 },
2304 shouldFail: true,
2305 expectedError: ":INVALID_COMPRESSION_LIST:",
2306 expectedLocalError: "remote error: illegal parameter",
2307 },
Adam Langley7c803a62015-06-15 15:35:05 -07002308 }
Adam Langley7c803a62015-06-15 15:35:05 -07002309 testCases = append(testCases, basicTests...)
2310}
2311
Adam Langley95c29f32014-06-20 12:00:00 -07002312func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002313 const bogusCipher = 0xfe00
2314
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002315 if *includeRC4 {
2316 testCipherSuites = append(testCipherSuites, []struct {
2317 name string
2318 id uint16
2319 }{
2320 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
2321 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
2322 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
2323 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
2324 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
2325 }...)
2326 }
2327
Adam Langley95c29f32014-06-20 12:00:00 -07002328 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002329 const psk = "12345"
2330 const pskIdentity = "luggage combo"
2331
Adam Langley95c29f32014-06-20 12:00:00 -07002332 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002333 var certFile string
2334 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002335 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002336 cert = ecdsaP256Certificate
2337 certFile = ecdsaP256CertificateFile
2338 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002339 } else {
David Benjamin33863262016-07-08 17:20:12 -07002340 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002341 certFile = rsaCertificateFile
2342 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002343 }
2344
David Benjamin48cae082014-10-27 01:06:24 -04002345 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002346 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002347 flags = append(flags,
2348 "-psk", psk,
2349 "-psk-identity", pskIdentity)
2350 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002351 if hasComponent(suite.name, "NULL") {
2352 // NULL ciphers must be explicitly enabled.
2353 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2354 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002355 if hasComponent(suite.name, "CECPQ1") {
2356 // CECPQ1 ciphers must be explicitly enabled.
2357 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2358 }
David Benjamin881f1962016-08-10 18:29:12 -04002359 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2360 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2361 // for now.
2362 flags = append(flags, "-cipher", suite.name)
2363 }
David Benjamin48cae082014-10-27 01:06:24 -04002364
Adam Langley95c29f32014-06-20 12:00:00 -07002365 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002366 for _, protocol := range []protocol{tls, dtls} {
2367 var prefix string
2368 if protocol == dtls {
2369 if !ver.hasDTLS {
2370 continue
2371 }
2372 prefix = "D"
2373 }
Adam Langley95c29f32014-06-20 12:00:00 -07002374
David Benjamin0407e762016-06-17 16:41:18 -04002375 var shouldServerFail, shouldClientFail bool
2376 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2377 // BoringSSL clients accept ECDHE on SSLv3, but
2378 // a BoringSSL server will never select it
2379 // because the extension is missing.
2380 shouldServerFail = true
2381 }
2382 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2383 shouldClientFail = true
2384 shouldServerFail = true
2385 }
David Benjamin54c217c2016-07-13 12:35:25 -04002386 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002387 shouldClientFail = true
2388 shouldServerFail = true
2389 }
David Benjamin0407e762016-06-17 16:41:18 -04002390 if !isDTLSCipher(suite.name) && protocol == dtls {
2391 shouldClientFail = true
2392 shouldServerFail = true
2393 }
David Benjamin4298d772015-12-19 00:18:25 -05002394
David Benjamin0407e762016-06-17 16:41:18 -04002395 var expectedServerError, expectedClientError string
2396 if shouldServerFail {
2397 expectedServerError = ":NO_SHARED_CIPHER:"
2398 }
2399 if shouldClientFail {
2400 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2401 }
David Benjamin025b3d32014-07-01 19:53:04 -04002402
David Benjamin6fd297b2014-08-11 18:43:38 -04002403 testCases = append(testCases, testCase{
2404 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002405 protocol: protocol,
2406
2407 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002408 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002409 MinVersion: ver.version,
2410 MaxVersion: ver.version,
2411 CipherSuites: []uint16{suite.id},
2412 Certificates: []Certificate{cert},
2413 PreSharedKey: []byte(psk),
2414 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002415 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002416 EnableAllCiphers: shouldServerFail,
2417 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002418 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002419 },
2420 certFile: certFile,
2421 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002422 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002423 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002424 shouldFail: shouldServerFail,
2425 expectedError: expectedServerError,
2426 })
2427
2428 testCases = append(testCases, testCase{
2429 testType: clientTest,
2430 protocol: protocol,
2431 name: prefix + ver.name + "-" + suite.name + "-client",
2432 config: Config{
2433 MinVersion: ver.version,
2434 MaxVersion: ver.version,
2435 CipherSuites: []uint16{suite.id},
2436 Certificates: []Certificate{cert},
2437 PreSharedKey: []byte(psk),
2438 PreSharedKeyIdentity: pskIdentity,
2439 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002440 EnableAllCiphers: shouldClientFail,
2441 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002442 },
2443 },
2444 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002445 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002446 shouldFail: shouldClientFail,
2447 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002448 })
David Benjamin2c99d282015-09-01 10:23:00 -04002449
Nick Harper1fd39d82016-06-14 18:14:35 -07002450 if !shouldClientFail {
2451 // Ensure the maximum record size is accepted.
2452 testCases = append(testCases, testCase{
2453 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2454 config: Config{
2455 MinVersion: ver.version,
2456 MaxVersion: ver.version,
2457 CipherSuites: []uint16{suite.id},
2458 Certificates: []Certificate{cert},
2459 PreSharedKey: []byte(psk),
2460 PreSharedKeyIdentity: pskIdentity,
2461 },
2462 flags: flags,
2463 messageLen: maxPlaintext,
2464 })
2465 }
2466 }
David Benjamin2c99d282015-09-01 10:23:00 -04002467 }
Adam Langley95c29f32014-06-20 12:00:00 -07002468 }
Adam Langleya7997f12015-05-14 17:38:50 -07002469
2470 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002471 name: "NoSharedCipher",
2472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002473 MaxVersion: VersionTLS12,
2474 CipherSuites: []uint16{},
2475 },
2476 shouldFail: true,
2477 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2478 })
2479
2480 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002481 name: "NoSharedCipher-TLS13",
2482 config: Config{
2483 MaxVersion: VersionTLS13,
2484 CipherSuites: []uint16{},
2485 },
2486 shouldFail: true,
2487 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2488 })
2489
2490 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002491 name: "UnsupportedCipherSuite",
2492 config: Config{
2493 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002494 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002495 Bugs: ProtocolBugs{
2496 IgnorePeerCipherPreferences: true,
2497 },
2498 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002499 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002500 shouldFail: true,
2501 expectedError: ":WRONG_CIPHER_RETURNED:",
2502 })
2503
2504 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002505 name: "ServerHelloBogusCipher",
2506 config: Config{
2507 MaxVersion: VersionTLS12,
2508 Bugs: ProtocolBugs{
2509 SendCipherSuite: bogusCipher,
2510 },
2511 },
2512 shouldFail: true,
2513 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2514 })
2515 testCases = append(testCases, testCase{
2516 name: "ServerHelloBogusCipher-TLS13",
2517 config: Config{
2518 MaxVersion: VersionTLS13,
2519 Bugs: ProtocolBugs{
2520 SendCipherSuite: bogusCipher,
2521 },
2522 },
2523 shouldFail: true,
2524 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2525 })
2526
2527 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002528 name: "WeakDH",
2529 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002530 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002531 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2532 Bugs: ProtocolBugs{
2533 // This is a 1023-bit prime number, generated
2534 // with:
2535 // openssl gendh 1023 | openssl asn1parse -i
2536 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2537 },
2538 },
2539 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002540 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002541 })
Adam Langleycef75832015-09-03 14:51:12 -07002542
David Benjamincd24a392015-11-11 13:23:05 -08002543 testCases = append(testCases, testCase{
2544 name: "SillyDH",
2545 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002546 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002547 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2548 Bugs: ProtocolBugs{
2549 // This is a 4097-bit prime number, generated
2550 // with:
2551 // openssl gendh 4097 | openssl asn1parse -i
2552 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2553 },
2554 },
2555 shouldFail: true,
2556 expectedError: ":DH_P_TOO_LONG:",
2557 })
2558
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002559 // This test ensures that Diffie-Hellman public values are padded with
2560 // zeros so that they're the same length as the prime. This is to avoid
2561 // hitting a bug in yaSSL.
2562 testCases = append(testCases, testCase{
2563 testType: serverTest,
2564 name: "DHPublicValuePadded",
2565 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002566 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002567 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2568 Bugs: ProtocolBugs{
2569 RequireDHPublicValueLen: (1025 + 7) / 8,
2570 },
2571 },
2572 flags: []string{"-use-sparse-dh-prime"},
2573 })
David Benjamincd24a392015-11-11 13:23:05 -08002574
David Benjamin241ae832016-01-15 03:04:54 -05002575 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002576 testCases = append(testCases, testCase{
2577 testType: serverTest,
2578 name: "UnknownCipher",
2579 config: Config{
2580 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2581 },
2582 })
2583
Adam Langleycef75832015-09-03 14:51:12 -07002584 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2585 // 1.1 specific cipher suite settings. A server is setup with the given
2586 // cipher lists and then a connection is made for each member of
2587 // expectations. The cipher suite that the server selects must match
2588 // the specified one.
2589 var versionSpecificCiphersTest = []struct {
2590 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2591 // expectations is a map from TLS version to cipher suite id.
2592 expectations map[uint16]uint16
2593 }{
2594 {
2595 // Test that the null case (where no version-specific ciphers are set)
2596 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002597 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2598 "", // no ciphers specifically for TLS ≥ 1.0
2599 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002600 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002601 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2602 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2603 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2604 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002605 },
2606 },
2607 {
2608 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2609 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002610 "DES-CBC3-SHA:AES128-SHA", // default
2611 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2612 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002613 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002614 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002615 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2616 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2617 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2618 },
2619 },
2620 {
2621 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2622 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002623 "DES-CBC3-SHA:AES128-SHA", // default
2624 "", // no ciphers specifically for TLS ≥ 1.0
2625 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002626 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002627 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2628 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002629 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2630 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2631 },
2632 },
2633 {
2634 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2635 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002636 "DES-CBC3-SHA:AES128-SHA", // default
2637 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2638 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002639 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002640 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002641 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2642 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2643 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2644 },
2645 },
2646 }
2647
2648 for i, test := range versionSpecificCiphersTest {
2649 for version, expectedCipherSuite := range test.expectations {
2650 flags := []string{"-cipher", test.ciphersDefault}
2651 if len(test.ciphersTLS10) > 0 {
2652 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2653 }
2654 if len(test.ciphersTLS11) > 0 {
2655 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2656 }
2657
2658 testCases = append(testCases, testCase{
2659 testType: serverTest,
2660 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2661 config: Config{
2662 MaxVersion: version,
2663 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002664 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 -07002665 },
2666 flags: flags,
2667 expectedCipher: expectedCipherSuite,
2668 })
2669 }
2670 }
Adam Langley95c29f32014-06-20 12:00:00 -07002671}
2672
2673func addBadECDSASignatureTests() {
2674 for badR := BadValue(1); badR < NumBadValues; badR++ {
2675 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002676 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002677 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2678 config: Config{
2679 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002680 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002681 Bugs: ProtocolBugs{
2682 BadECDSAR: badR,
2683 BadECDSAS: badS,
2684 },
2685 },
2686 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002687 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002688 })
2689 }
2690 }
2691}
2692
Adam Langley80842bd2014-06-20 12:00:00 -07002693func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002694 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002695 name: "MaxCBCPadding",
2696 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002697 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2699 Bugs: ProtocolBugs{
2700 MaxPadding: true,
2701 },
2702 },
2703 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2704 })
David Benjamin025b3d32014-07-01 19:53:04 -04002705 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002706 name: "BadCBCPadding",
2707 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002708 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002709 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2710 Bugs: ProtocolBugs{
2711 PaddingFirstByteBad: true,
2712 },
2713 },
2714 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002715 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002716 })
2717 // OpenSSL previously had an issue where the first byte of padding in
2718 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002719 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002720 name: "BadCBCPadding255",
2721 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002722 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002723 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2724 Bugs: ProtocolBugs{
2725 MaxPadding: true,
2726 PaddingFirstByteBadIf255: true,
2727 },
2728 },
2729 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2730 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002731 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002732 })
2733}
2734
Kenny Root7fdeaf12014-08-05 15:23:37 -07002735func addCBCSplittingTests() {
2736 testCases = append(testCases, testCase{
2737 name: "CBCRecordSplitting",
2738 config: Config{
2739 MaxVersion: VersionTLS10,
2740 MinVersion: VersionTLS10,
2741 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2742 },
David Benjaminac8302a2015-09-01 17:18:15 -04002743 messageLen: -1, // read until EOF
2744 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002745 flags: []string{
2746 "-async",
2747 "-write-different-record-sizes",
2748 "-cbc-record-splitting",
2749 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002750 })
2751 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002752 name: "CBCRecordSplittingPartialWrite",
2753 config: Config{
2754 MaxVersion: VersionTLS10,
2755 MinVersion: VersionTLS10,
2756 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2757 },
2758 messageLen: -1, // read until EOF
2759 flags: []string{
2760 "-async",
2761 "-write-different-record-sizes",
2762 "-cbc-record-splitting",
2763 "-partial-write",
2764 },
2765 })
2766}
2767
David Benjamin636293b2014-07-08 17:59:18 -04002768func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002769 // Add a dummy cert pool to stress certificate authority parsing.
2770 // TODO(davidben): Add tests that those values parse out correctly.
2771 certPool := x509.NewCertPool()
2772 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2773 if err != nil {
2774 panic(err)
2775 }
2776 certPool.AddCert(cert)
2777
David Benjamin636293b2014-07-08 17:59:18 -04002778 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002779 testCases = append(testCases, testCase{
2780 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002781 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002782 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002783 MinVersion: ver.version,
2784 MaxVersion: ver.version,
2785 ClientAuth: RequireAnyClientCert,
2786 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002787 },
2788 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002789 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2790 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002791 },
2792 })
2793 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002794 testType: serverTest,
2795 name: ver.name + "-Server-ClientAuth-RSA",
2796 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002797 MinVersion: ver.version,
2798 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002799 Certificates: []Certificate{rsaCertificate},
2800 },
2801 flags: []string{"-require-any-client-certificate"},
2802 })
David Benjamine098ec22014-08-27 23:13:20 -04002803 if ver.version != VersionSSL30 {
2804 testCases = append(testCases, testCase{
2805 testType: serverTest,
2806 name: ver.name + "-Server-ClientAuth-ECDSA",
2807 config: Config{
2808 MinVersion: ver.version,
2809 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002810 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002811 },
2812 flags: []string{"-require-any-client-certificate"},
2813 })
2814 testCases = append(testCases, testCase{
2815 testType: clientTest,
2816 name: ver.name + "-Client-ClientAuth-ECDSA",
2817 config: Config{
2818 MinVersion: ver.version,
2819 MaxVersion: ver.version,
2820 ClientAuth: RequireAnyClientCert,
2821 ClientCAs: certPool,
2822 },
2823 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002824 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2825 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002826 },
2827 })
2828 }
Adam Langley37646832016-08-01 16:16:46 -07002829
2830 testCases = append(testCases, testCase{
2831 name: "NoClientCertificate-" + ver.name,
2832 config: Config{
2833 MinVersion: ver.version,
2834 MaxVersion: ver.version,
2835 ClientAuth: RequireAnyClientCert,
2836 },
2837 shouldFail: true,
2838 expectedLocalError: "client didn't provide a certificate",
2839 })
2840
2841 testCases = append(testCases, testCase{
2842 // Even if not configured to expect a certificate, OpenSSL will
2843 // return X509_V_OK as the verify_result.
2844 testType: serverTest,
2845 name: "NoClientCertificateRequested-Server-" + ver.name,
2846 config: Config{
2847 MinVersion: ver.version,
2848 MaxVersion: ver.version,
2849 },
2850 flags: []string{
2851 "-expect-verify-result",
2852 },
2853 // TODO(davidben): Switch this to true when TLS 1.3
2854 // supports session resumption.
2855 resumeSession: ver.version < VersionTLS13,
2856 })
2857
2858 testCases = append(testCases, testCase{
2859 // If a client certificate is not provided, OpenSSL will still
2860 // return X509_V_OK as the verify_result.
2861 testType: serverTest,
2862 name: "NoClientCertificate-Server-" + ver.name,
2863 config: Config{
2864 MinVersion: ver.version,
2865 MaxVersion: ver.version,
2866 },
2867 flags: []string{
2868 "-expect-verify-result",
2869 "-verify-peer",
2870 },
2871 // TODO(davidben): Switch this to true when TLS 1.3
2872 // supports session resumption.
2873 resumeSession: ver.version < VersionTLS13,
2874 })
2875
2876 testCases = append(testCases, testCase{
2877 testType: serverTest,
2878 name: "RequireAnyClientCertificate-" + ver.name,
2879 config: Config{
2880 MinVersion: ver.version,
2881 MaxVersion: ver.version,
2882 },
2883 flags: []string{"-require-any-client-certificate"},
2884 shouldFail: true,
2885 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2886 })
2887
2888 if ver.version != VersionSSL30 {
2889 testCases = append(testCases, testCase{
2890 testType: serverTest,
2891 name: "SkipClientCertificate-" + ver.name,
2892 config: Config{
2893 MinVersion: ver.version,
2894 MaxVersion: ver.version,
2895 Bugs: ProtocolBugs{
2896 SkipClientCertificate: true,
2897 },
2898 },
2899 // Setting SSL_VERIFY_PEER allows anonymous clients.
2900 flags: []string{"-verify-peer"},
2901 shouldFail: true,
2902 expectedError: ":UNEXPECTED_MESSAGE:",
2903 })
2904 }
David Benjamin636293b2014-07-08 17:59:18 -04002905 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002906
David Benjaminc032dfa2016-05-12 14:54:57 -04002907 // Client auth is only legal in certificate-based ciphers.
2908 testCases = append(testCases, testCase{
2909 testType: clientTest,
2910 name: "ClientAuth-PSK",
2911 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002912 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002913 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2914 PreSharedKey: []byte("secret"),
2915 ClientAuth: RequireAnyClientCert,
2916 },
2917 flags: []string{
2918 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2919 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2920 "-psk", "secret",
2921 },
2922 shouldFail: true,
2923 expectedError: ":UNEXPECTED_MESSAGE:",
2924 })
2925 testCases = append(testCases, testCase{
2926 testType: clientTest,
2927 name: "ClientAuth-ECDHE_PSK",
2928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002929 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002930 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2931 PreSharedKey: []byte("secret"),
2932 ClientAuth: RequireAnyClientCert,
2933 },
2934 flags: []string{
2935 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2936 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2937 "-psk", "secret",
2938 },
2939 shouldFail: true,
2940 expectedError: ":UNEXPECTED_MESSAGE:",
2941 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002942
2943 // Regression test for a bug where the client CA list, if explicitly
2944 // set to NULL, was mis-encoded.
2945 testCases = append(testCases, testCase{
2946 testType: serverTest,
2947 name: "Null-Client-CA-List",
2948 config: Config{
2949 MaxVersion: VersionTLS12,
2950 Certificates: []Certificate{rsaCertificate},
2951 },
2952 flags: []string{
2953 "-require-any-client-certificate",
2954 "-use-null-client-ca-list",
2955 },
2956 })
David Benjamin636293b2014-07-08 17:59:18 -04002957}
2958
Adam Langley75712922014-10-10 16:23:43 -07002959func addExtendedMasterSecretTests() {
2960 const expectEMSFlag = "-expect-extended-master-secret"
2961
2962 for _, with := range []bool{false, true} {
2963 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002964 if with {
2965 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002966 }
2967
2968 for _, isClient := range []bool{false, true} {
2969 suffix := "-Server"
2970 testType := serverTest
2971 if isClient {
2972 suffix = "-Client"
2973 testType = clientTest
2974 }
2975
2976 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002977 // In TLS 1.3, the extension is irrelevant and
2978 // always reports as enabled.
2979 var flags []string
2980 if with || ver.version >= VersionTLS13 {
2981 flags = []string{expectEMSFlag}
2982 }
2983
Adam Langley75712922014-10-10 16:23:43 -07002984 test := testCase{
2985 testType: testType,
2986 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2987 config: Config{
2988 MinVersion: ver.version,
2989 MaxVersion: ver.version,
2990 Bugs: ProtocolBugs{
2991 NoExtendedMasterSecret: !with,
2992 RequireExtendedMasterSecret: with,
2993 },
2994 },
David Benjamin48cae082014-10-27 01:06:24 -04002995 flags: flags,
2996 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002997 }
2998 if test.shouldFail {
2999 test.expectedLocalError = "extended master secret required but not supported by peer"
3000 }
3001 testCases = append(testCases, test)
3002 }
3003 }
3004 }
3005
Adam Langleyba5934b2015-06-02 10:50:35 -07003006 for _, isClient := range []bool{false, true} {
3007 for _, supportedInFirstConnection := range []bool{false, true} {
3008 for _, supportedInResumeConnection := range []bool{false, true} {
3009 boolToWord := func(b bool) string {
3010 if b {
3011 return "Yes"
3012 }
3013 return "No"
3014 }
3015 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3016 if isClient {
3017 suffix += "Client"
3018 } else {
3019 suffix += "Server"
3020 }
3021
3022 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003023 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003024 Bugs: ProtocolBugs{
3025 RequireExtendedMasterSecret: true,
3026 },
3027 }
3028
3029 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003030 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003031 Bugs: ProtocolBugs{
3032 NoExtendedMasterSecret: true,
3033 },
3034 }
3035
3036 test := testCase{
3037 name: "ExtendedMasterSecret-" + suffix,
3038 resumeSession: true,
3039 }
3040
3041 if !isClient {
3042 test.testType = serverTest
3043 }
3044
3045 if supportedInFirstConnection {
3046 test.config = supportedConfig
3047 } else {
3048 test.config = noSupportConfig
3049 }
3050
3051 if supportedInResumeConnection {
3052 test.resumeConfig = &supportedConfig
3053 } else {
3054 test.resumeConfig = &noSupportConfig
3055 }
3056
3057 switch suffix {
3058 case "YesToYes-Client", "YesToYes-Server":
3059 // When a session is resumed, it should
3060 // still be aware that its master
3061 // secret was generated via EMS and
3062 // thus it's safe to use tls-unique.
3063 test.flags = []string{expectEMSFlag}
3064 case "NoToYes-Server":
3065 // If an original connection did not
3066 // contain EMS, but a resumption
3067 // handshake does, then a server should
3068 // not resume the session.
3069 test.expectResumeRejected = true
3070 case "YesToNo-Server":
3071 // Resuming an EMS session without the
3072 // EMS extension should cause the
3073 // server to abort the connection.
3074 test.shouldFail = true
3075 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3076 case "NoToYes-Client":
3077 // A client should abort a connection
3078 // where the server resumed a non-EMS
3079 // session but echoed the EMS
3080 // extension.
3081 test.shouldFail = true
3082 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3083 case "YesToNo-Client":
3084 // A client should abort a connection
3085 // where the server didn't echo EMS
3086 // when the session used it.
3087 test.shouldFail = true
3088 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3089 }
3090
3091 testCases = append(testCases, test)
3092 }
3093 }
3094 }
David Benjamin163c9562016-08-29 23:14:17 -04003095
3096 // Switching EMS on renegotiation is forbidden.
3097 testCases = append(testCases, testCase{
3098 name: "ExtendedMasterSecret-Renego-NoEMS",
3099 config: Config{
3100 MaxVersion: VersionTLS12,
3101 Bugs: ProtocolBugs{
3102 NoExtendedMasterSecret: true,
3103 NoExtendedMasterSecretOnRenegotiation: true,
3104 },
3105 },
3106 renegotiate: 1,
3107 flags: []string{
3108 "-renegotiate-freely",
3109 "-expect-total-renegotiations", "1",
3110 },
3111 })
3112
3113 testCases = append(testCases, testCase{
3114 name: "ExtendedMasterSecret-Renego-Upgrade",
3115 config: Config{
3116 MaxVersion: VersionTLS12,
3117 Bugs: ProtocolBugs{
3118 NoExtendedMasterSecret: true,
3119 },
3120 },
3121 renegotiate: 1,
3122 flags: []string{
3123 "-renegotiate-freely",
3124 "-expect-total-renegotiations", "1",
3125 },
3126 shouldFail: true,
3127 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3128 })
3129
3130 testCases = append(testCases, testCase{
3131 name: "ExtendedMasterSecret-Renego-Downgrade",
3132 config: Config{
3133 MaxVersion: VersionTLS12,
3134 Bugs: ProtocolBugs{
3135 NoExtendedMasterSecretOnRenegotiation: true,
3136 },
3137 },
3138 renegotiate: 1,
3139 flags: []string{
3140 "-renegotiate-freely",
3141 "-expect-total-renegotiations", "1",
3142 },
3143 shouldFail: true,
3144 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3145 })
Adam Langley75712922014-10-10 16:23:43 -07003146}
3147
David Benjamin582ba042016-07-07 12:33:25 -07003148type stateMachineTestConfig struct {
3149 protocol protocol
3150 async bool
3151 splitHandshake, packHandshakeFlight bool
3152}
3153
David Benjamin43ec06f2014-08-05 02:28:57 -04003154// Adds tests that try to cover the range of the handshake state machine, under
3155// various conditions. Some of these are redundant with other tests, but they
3156// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003157func addAllStateMachineCoverageTests() {
3158 for _, async := range []bool{false, true} {
3159 for _, protocol := range []protocol{tls, dtls} {
3160 addStateMachineCoverageTests(stateMachineTestConfig{
3161 protocol: protocol,
3162 async: async,
3163 })
3164 addStateMachineCoverageTests(stateMachineTestConfig{
3165 protocol: protocol,
3166 async: async,
3167 splitHandshake: true,
3168 })
3169 if protocol == tls {
3170 addStateMachineCoverageTests(stateMachineTestConfig{
3171 protocol: protocol,
3172 async: async,
3173 packHandshakeFlight: true,
3174 })
3175 }
3176 }
3177 }
3178}
3179
3180func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003181 var tests []testCase
3182
3183 // Basic handshake, with resumption. Client and server,
3184 // session ID and session ticket.
3185 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003186 name: "Basic-Client",
3187 config: Config{
3188 MaxVersion: VersionTLS12,
3189 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003190 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003191 // Ensure session tickets are used, not session IDs.
3192 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003193 })
3194 tests = append(tests, testCase{
3195 name: "Basic-Client-RenewTicket",
3196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003197 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003198 Bugs: ProtocolBugs{
3199 RenewTicketOnResume: true,
3200 },
3201 },
David Benjamin46662482016-08-17 00:51:00 -04003202 flags: []string{"-expect-ticket-renewal"},
3203 resumeSession: true,
3204 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003205 })
3206 tests = append(tests, testCase{
3207 name: "Basic-Client-NoTicket",
3208 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003209 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003210 SessionTicketsDisabled: true,
3211 },
3212 resumeSession: true,
3213 })
3214 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003215 name: "Basic-Client-Implicit",
3216 config: Config{
3217 MaxVersion: VersionTLS12,
3218 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003219 flags: []string{"-implicit-handshake"},
3220 resumeSession: true,
3221 })
3222 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003223 testType: serverTest,
3224 name: "Basic-Server",
3225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003226 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003227 Bugs: ProtocolBugs{
3228 RequireSessionTickets: true,
3229 },
3230 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003231 resumeSession: true,
3232 })
3233 tests = append(tests, testCase{
3234 testType: serverTest,
3235 name: "Basic-Server-NoTickets",
3236 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003237 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003238 SessionTicketsDisabled: true,
3239 },
3240 resumeSession: true,
3241 })
3242 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003243 testType: serverTest,
3244 name: "Basic-Server-Implicit",
3245 config: Config{
3246 MaxVersion: VersionTLS12,
3247 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003248 flags: []string{"-implicit-handshake"},
3249 resumeSession: true,
3250 })
3251 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003252 testType: serverTest,
3253 name: "Basic-Server-EarlyCallback",
3254 config: Config{
3255 MaxVersion: VersionTLS12,
3256 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003257 flags: []string{"-use-early-callback"},
3258 resumeSession: true,
3259 })
3260
Steven Valdez143e8b32016-07-11 13:19:03 -04003261 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003262 if config.protocol == tls {
3263 tests = append(tests, testCase{
3264 name: "TLS13-1RTT-Client",
3265 config: Config{
3266 MaxVersion: VersionTLS13,
3267 MinVersion: VersionTLS13,
3268 },
David Benjamin46662482016-08-17 00:51:00 -04003269 resumeSession: true,
3270 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003271 })
3272
3273 tests = append(tests, testCase{
3274 testType: serverTest,
3275 name: "TLS13-1RTT-Server",
3276 config: Config{
3277 MaxVersion: VersionTLS13,
3278 MinVersion: VersionTLS13,
3279 },
David Benjamin46662482016-08-17 00:51:00 -04003280 resumeSession: true,
3281 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003282 })
3283
3284 tests = append(tests, testCase{
3285 name: "TLS13-HelloRetryRequest-Client",
3286 config: Config{
3287 MaxVersion: VersionTLS13,
3288 MinVersion: VersionTLS13,
3289 // P-384 requires a HelloRetryRequest against
3290 // BoringSSL's default configuration. Assert
3291 // that we do indeed test this with
3292 // ExpectMissingKeyShare.
3293 CurvePreferences: []CurveID{CurveP384},
3294 Bugs: ProtocolBugs{
3295 ExpectMissingKeyShare: true,
3296 },
3297 },
3298 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3299 resumeSession: true,
3300 })
3301
3302 tests = append(tests, testCase{
3303 testType: serverTest,
3304 name: "TLS13-HelloRetryRequest-Server",
3305 config: Config{
3306 MaxVersion: VersionTLS13,
3307 MinVersion: VersionTLS13,
3308 // Require a HelloRetryRequest for every curve.
3309 DefaultCurves: []CurveID{},
3310 },
3311 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3312 resumeSession: true,
3313 })
3314 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003315
David Benjamin760b1dd2015-05-15 23:33:48 -04003316 // TLS client auth.
3317 tests = append(tests, testCase{
3318 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003319 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003321 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003322 ClientAuth: RequestClientCert,
3323 },
3324 })
3325 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003326 testType: serverTest,
3327 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003328 config: Config{
3329 MaxVersion: VersionTLS12,
3330 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003331 // Setting SSL_VERIFY_PEER allows anonymous clients.
3332 flags: []string{"-verify-peer"},
3333 })
David Benjamin582ba042016-07-07 12:33:25 -07003334 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003335 tests = append(tests, testCase{
3336 testType: clientTest,
3337 name: "ClientAuth-NoCertificate-Client-SSL3",
3338 config: Config{
3339 MaxVersion: VersionSSL30,
3340 ClientAuth: RequestClientCert,
3341 },
3342 })
3343 tests = append(tests, testCase{
3344 testType: serverTest,
3345 name: "ClientAuth-NoCertificate-Server-SSL3",
3346 config: Config{
3347 MaxVersion: VersionSSL30,
3348 },
3349 // Setting SSL_VERIFY_PEER allows anonymous clients.
3350 flags: []string{"-verify-peer"},
3351 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003352 tests = append(tests, testCase{
3353 testType: clientTest,
3354 name: "ClientAuth-NoCertificate-Client-TLS13",
3355 config: Config{
3356 MaxVersion: VersionTLS13,
3357 ClientAuth: RequestClientCert,
3358 },
3359 })
3360 tests = append(tests, testCase{
3361 testType: serverTest,
3362 name: "ClientAuth-NoCertificate-Server-TLS13",
3363 config: Config{
3364 MaxVersion: VersionTLS13,
3365 },
3366 // Setting SSL_VERIFY_PEER allows anonymous clients.
3367 flags: []string{"-verify-peer"},
3368 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003369 }
3370 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003371 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003372 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003374 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003375 ClientAuth: RequireAnyClientCert,
3376 },
3377 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003378 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3379 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003380 },
3381 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003382 tests = append(tests, testCase{
3383 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003384 name: "ClientAuth-RSA-Client-TLS13",
3385 config: Config{
3386 MaxVersion: VersionTLS13,
3387 ClientAuth: RequireAnyClientCert,
3388 },
3389 flags: []string{
3390 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3391 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3392 },
3393 })
3394 tests = append(tests, testCase{
3395 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003396 name: "ClientAuth-ECDSA-Client",
3397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003398 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003399 ClientAuth: RequireAnyClientCert,
3400 },
3401 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003402 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3403 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003404 },
3405 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003406 tests = append(tests, testCase{
3407 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003408 name: "ClientAuth-ECDSA-Client-TLS13",
3409 config: Config{
3410 MaxVersion: VersionTLS13,
3411 ClientAuth: RequireAnyClientCert,
3412 },
3413 flags: []string{
3414 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3415 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3416 },
3417 })
3418 tests = append(tests, testCase{
3419 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003420 name: "ClientAuth-NoCertificate-OldCallback",
3421 config: Config{
3422 MaxVersion: VersionTLS12,
3423 ClientAuth: RequestClientCert,
3424 },
3425 flags: []string{"-use-old-client-cert-callback"},
3426 })
3427 tests = append(tests, testCase{
3428 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003429 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3430 config: Config{
3431 MaxVersion: VersionTLS13,
3432 ClientAuth: RequestClientCert,
3433 },
3434 flags: []string{"-use-old-client-cert-callback"},
3435 })
3436 tests = append(tests, testCase{
3437 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003438 name: "ClientAuth-OldCallback",
3439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003440 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003441 ClientAuth: RequireAnyClientCert,
3442 },
3443 flags: []string{
3444 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3445 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3446 "-use-old-client-cert-callback",
3447 },
3448 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003449 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003450 testType: clientTest,
3451 name: "ClientAuth-OldCallback-TLS13",
3452 config: Config{
3453 MaxVersion: VersionTLS13,
3454 ClientAuth: RequireAnyClientCert,
3455 },
3456 flags: []string{
3457 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3458 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3459 "-use-old-client-cert-callback",
3460 },
3461 })
3462 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003463 testType: serverTest,
3464 name: "ClientAuth-Server",
3465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003466 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003467 Certificates: []Certificate{rsaCertificate},
3468 },
3469 flags: []string{"-require-any-client-certificate"},
3470 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003471 tests = append(tests, testCase{
3472 testType: serverTest,
3473 name: "ClientAuth-Server-TLS13",
3474 config: Config{
3475 MaxVersion: VersionTLS13,
3476 Certificates: []Certificate{rsaCertificate},
3477 },
3478 flags: []string{"-require-any-client-certificate"},
3479 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003480
David Benjamin4c3ddf72016-06-29 18:13:53 -04003481 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003482 tests = append(tests, testCase{
3483 testType: serverTest,
3484 name: "Basic-Server-RSA",
3485 config: Config{
3486 MaxVersion: VersionTLS12,
3487 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3488 },
3489 flags: []string{
3490 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3491 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3492 },
3493 })
3494 tests = append(tests, testCase{
3495 testType: serverTest,
3496 name: "Basic-Server-ECDHE-RSA",
3497 config: Config{
3498 MaxVersion: VersionTLS12,
3499 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3500 },
3501 flags: []string{
3502 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3503 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3504 },
3505 })
3506 tests = append(tests, testCase{
3507 testType: serverTest,
3508 name: "Basic-Server-ECDHE-ECDSA",
3509 config: Config{
3510 MaxVersion: VersionTLS12,
3511 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3512 },
3513 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003514 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3515 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003516 },
3517 })
3518
David Benjamin760b1dd2015-05-15 23:33:48 -04003519 // No session ticket support; server doesn't send NewSessionTicket.
3520 tests = append(tests, testCase{
3521 name: "SessionTicketsDisabled-Client",
3522 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003523 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003524 SessionTicketsDisabled: true,
3525 },
3526 })
3527 tests = append(tests, testCase{
3528 testType: serverTest,
3529 name: "SessionTicketsDisabled-Server",
3530 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003531 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003532 SessionTicketsDisabled: true,
3533 },
3534 })
3535
3536 // Skip ServerKeyExchange in PSK key exchange if there's no
3537 // identity hint.
3538 tests = append(tests, testCase{
3539 name: "EmptyPSKHint-Client",
3540 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003541 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003542 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3543 PreSharedKey: []byte("secret"),
3544 },
3545 flags: []string{"-psk", "secret"},
3546 })
3547 tests = append(tests, testCase{
3548 testType: serverTest,
3549 name: "EmptyPSKHint-Server",
3550 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003551 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003552 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3553 PreSharedKey: []byte("secret"),
3554 },
3555 flags: []string{"-psk", "secret"},
3556 })
3557
David Benjamin4c3ddf72016-06-29 18:13:53 -04003558 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003559 tests = append(tests, testCase{
3560 testType: clientTest,
3561 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003562 config: Config{
3563 MaxVersion: VersionTLS12,
3564 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003565 flags: []string{
3566 "-enable-ocsp-stapling",
3567 "-expect-ocsp-response",
3568 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003569 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003570 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003571 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003572 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003573 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003574 testType: serverTest,
3575 name: "OCSPStapling-Server",
3576 config: Config{
3577 MaxVersion: VersionTLS12,
3578 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003579 expectedOCSPResponse: testOCSPResponse,
3580 flags: []string{
3581 "-ocsp-response",
3582 base64.StdEncoding.EncodeToString(testOCSPResponse),
3583 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003584 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003585 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003586 tests = append(tests, testCase{
3587 testType: clientTest,
3588 name: "OCSPStapling-Client-TLS13",
3589 config: Config{
3590 MaxVersion: VersionTLS13,
3591 },
3592 flags: []string{
3593 "-enable-ocsp-stapling",
3594 "-expect-ocsp-response",
3595 base64.StdEncoding.EncodeToString(testOCSPResponse),
3596 "-verify-peer",
3597 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003598 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003599 })
3600 tests = append(tests, testCase{
3601 testType: serverTest,
3602 name: "OCSPStapling-Server-TLS13",
3603 config: Config{
3604 MaxVersion: VersionTLS13,
3605 },
3606 expectedOCSPResponse: testOCSPResponse,
3607 flags: []string{
3608 "-ocsp-response",
3609 base64.StdEncoding.EncodeToString(testOCSPResponse),
3610 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003611 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003612 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003613
David Benjamin4c3ddf72016-06-29 18:13:53 -04003614 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003615 for _, vers := range tlsVersions {
3616 if config.protocol == dtls && !vers.hasDTLS {
3617 continue
3618 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003619 for _, testType := range []testType{clientTest, serverTest} {
3620 suffix := "-Client"
3621 if testType == serverTest {
3622 suffix = "-Server"
3623 }
3624 suffix += "-" + vers.name
3625
3626 flag := "-verify-peer"
3627 if testType == serverTest {
3628 flag = "-require-any-client-certificate"
3629 }
3630
3631 tests = append(tests, testCase{
3632 testType: testType,
3633 name: "CertificateVerificationSucceed" + suffix,
3634 config: Config{
3635 MaxVersion: vers.version,
3636 Certificates: []Certificate{rsaCertificate},
3637 },
3638 flags: []string{
3639 flag,
3640 "-expect-verify-result",
3641 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003642 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003643 })
3644 tests = append(tests, testCase{
3645 testType: testType,
3646 name: "CertificateVerificationFail" + suffix,
3647 config: Config{
3648 MaxVersion: vers.version,
3649 Certificates: []Certificate{rsaCertificate},
3650 },
3651 flags: []string{
3652 flag,
3653 "-verify-fail",
3654 },
3655 shouldFail: true,
3656 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3657 })
3658 }
3659
3660 // By default, the client is in a soft fail mode where the peer
3661 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003662 tests = append(tests, testCase{
3663 testType: clientTest,
3664 name: "CertificateVerificationSoftFail-" + vers.name,
3665 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003666 MaxVersion: vers.version,
3667 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003668 },
3669 flags: []string{
3670 "-verify-fail",
3671 "-expect-verify-result",
3672 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003673 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003674 })
3675 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003676
David Benjamin1d4f4c02016-07-26 18:03:08 -04003677 tests = append(tests, testCase{
3678 name: "ShimSendAlert",
3679 flags: []string{"-send-alert"},
3680 shimWritesFirst: true,
3681 shouldFail: true,
3682 expectedLocalError: "remote error: decompression failure",
3683 })
3684
David Benjamin582ba042016-07-07 12:33:25 -07003685 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003686 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003687 name: "Renegotiate-Client",
3688 config: Config{
3689 MaxVersion: VersionTLS12,
3690 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003691 renegotiate: 1,
3692 flags: []string{
3693 "-renegotiate-freely",
3694 "-expect-total-renegotiations", "1",
3695 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003696 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003697
David Benjamin47921102016-07-28 11:29:18 -04003698 tests = append(tests, testCase{
3699 name: "SendHalfHelloRequest",
3700 config: Config{
3701 MaxVersion: VersionTLS12,
3702 Bugs: ProtocolBugs{
3703 PackHelloRequestWithFinished: config.packHandshakeFlight,
3704 },
3705 },
3706 sendHalfHelloRequest: true,
3707 flags: []string{"-renegotiate-ignore"},
3708 shouldFail: true,
3709 expectedError: ":UNEXPECTED_RECORD:",
3710 })
3711
David Benjamin760b1dd2015-05-15 23:33:48 -04003712 // NPN on client and server; results in post-handshake message.
3713 tests = append(tests, testCase{
3714 name: "NPN-Client",
3715 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003716 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003717 NextProtos: []string{"foo"},
3718 },
3719 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003720 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003721 expectedNextProto: "foo",
3722 expectedNextProtoType: npn,
3723 })
3724 tests = append(tests, testCase{
3725 testType: serverTest,
3726 name: "NPN-Server",
3727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003728 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003729 NextProtos: []string{"bar"},
3730 },
3731 flags: []string{
3732 "-advertise-npn", "\x03foo\x03bar\x03baz",
3733 "-expect-next-proto", "bar",
3734 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003735 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003736 expectedNextProto: "bar",
3737 expectedNextProtoType: npn,
3738 })
3739
3740 // TODO(davidben): Add tests for when False Start doesn't trigger.
3741
3742 // Client does False Start and negotiates NPN.
3743 tests = append(tests, testCase{
3744 name: "FalseStart",
3745 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003746 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003747 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3748 NextProtos: []string{"foo"},
3749 Bugs: ProtocolBugs{
3750 ExpectFalseStart: true,
3751 },
3752 },
3753 flags: []string{
3754 "-false-start",
3755 "-select-next-proto", "foo",
3756 },
3757 shimWritesFirst: true,
3758 resumeSession: true,
3759 })
3760
3761 // Client does False Start and negotiates ALPN.
3762 tests = append(tests, testCase{
3763 name: "FalseStart-ALPN",
3764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003765 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3767 NextProtos: []string{"foo"},
3768 Bugs: ProtocolBugs{
3769 ExpectFalseStart: true,
3770 },
3771 },
3772 flags: []string{
3773 "-false-start",
3774 "-advertise-alpn", "\x03foo",
3775 },
3776 shimWritesFirst: true,
3777 resumeSession: true,
3778 })
3779
3780 // Client does False Start but doesn't explicitly call
3781 // SSL_connect.
3782 tests = append(tests, testCase{
3783 name: "FalseStart-Implicit",
3784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003785 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3787 NextProtos: []string{"foo"},
3788 },
3789 flags: []string{
3790 "-implicit-handshake",
3791 "-false-start",
3792 "-advertise-alpn", "\x03foo",
3793 },
3794 })
3795
3796 // False Start without session tickets.
3797 tests = append(tests, testCase{
3798 name: "FalseStart-SessionTicketsDisabled",
3799 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003800 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003801 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3802 NextProtos: []string{"foo"},
3803 SessionTicketsDisabled: true,
3804 Bugs: ProtocolBugs{
3805 ExpectFalseStart: true,
3806 },
3807 },
3808 flags: []string{
3809 "-false-start",
3810 "-select-next-proto", "foo",
3811 },
3812 shimWritesFirst: true,
3813 })
3814
Adam Langleydf759b52016-07-11 15:24:37 -07003815 tests = append(tests, testCase{
3816 name: "FalseStart-CECPQ1",
3817 config: Config{
3818 MaxVersion: VersionTLS12,
3819 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3820 NextProtos: []string{"foo"},
3821 Bugs: ProtocolBugs{
3822 ExpectFalseStart: true,
3823 },
3824 },
3825 flags: []string{
3826 "-false-start",
3827 "-cipher", "DEFAULT:kCECPQ1",
3828 "-select-next-proto", "foo",
3829 },
3830 shimWritesFirst: true,
3831 resumeSession: true,
3832 })
3833
David Benjamin760b1dd2015-05-15 23:33:48 -04003834 // Server parses a V2ClientHello.
3835 tests = append(tests, testCase{
3836 testType: serverTest,
3837 name: "SendV2ClientHello",
3838 config: Config{
3839 // Choose a cipher suite that does not involve
3840 // elliptic curves, so no extensions are
3841 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003842 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003843 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003844 Bugs: ProtocolBugs{
3845 SendV2ClientHello: true,
3846 },
3847 },
3848 })
3849
3850 // Client sends a Channel ID.
3851 tests = append(tests, testCase{
3852 name: "ChannelID-Client",
3853 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003854 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003855 RequestChannelID: true,
3856 },
Adam Langley7c803a62015-06-15 15:35:05 -07003857 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003858 resumeSession: true,
3859 expectChannelID: true,
3860 })
3861
3862 // Server accepts a Channel ID.
3863 tests = append(tests, testCase{
3864 testType: serverTest,
3865 name: "ChannelID-Server",
3866 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003867 MaxVersion: VersionTLS12,
3868 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003869 },
3870 flags: []string{
3871 "-expect-channel-id",
3872 base64.StdEncoding.EncodeToString(channelIDBytes),
3873 },
3874 resumeSession: true,
3875 expectChannelID: true,
3876 })
David Benjamin30789da2015-08-29 22:56:45 -04003877
David Benjaminf8fcdf32016-06-08 15:56:13 -04003878 // Channel ID and NPN at the same time, to ensure their relative
3879 // ordering is correct.
3880 tests = append(tests, testCase{
3881 name: "ChannelID-NPN-Client",
3882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003884 RequestChannelID: true,
3885 NextProtos: []string{"foo"},
3886 },
3887 flags: []string{
3888 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3889 "-select-next-proto", "foo",
3890 },
3891 resumeSession: true,
3892 expectChannelID: true,
3893 expectedNextProto: "foo",
3894 expectedNextProtoType: npn,
3895 })
3896 tests = append(tests, testCase{
3897 testType: serverTest,
3898 name: "ChannelID-NPN-Server",
3899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003900 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003901 ChannelID: channelIDKey,
3902 NextProtos: []string{"bar"},
3903 },
3904 flags: []string{
3905 "-expect-channel-id",
3906 base64.StdEncoding.EncodeToString(channelIDBytes),
3907 "-advertise-npn", "\x03foo\x03bar\x03baz",
3908 "-expect-next-proto", "bar",
3909 },
3910 resumeSession: true,
3911 expectChannelID: true,
3912 expectedNextProto: "bar",
3913 expectedNextProtoType: npn,
3914 })
3915
David Benjamin30789da2015-08-29 22:56:45 -04003916 // Bidirectional shutdown with the runner initiating.
3917 tests = append(tests, testCase{
3918 name: "Shutdown-Runner",
3919 config: Config{
3920 Bugs: ProtocolBugs{
3921 ExpectCloseNotify: true,
3922 },
3923 },
3924 flags: []string{"-check-close-notify"},
3925 })
3926
3927 // Bidirectional shutdown with the shim initiating. The runner,
3928 // in the meantime, sends garbage before the close_notify which
3929 // the shim must ignore.
3930 tests = append(tests, testCase{
3931 name: "Shutdown-Shim",
3932 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003933 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003934 Bugs: ProtocolBugs{
3935 ExpectCloseNotify: true,
3936 },
3937 },
3938 shimShutsDown: true,
3939 sendEmptyRecords: 1,
3940 sendWarningAlerts: 1,
3941 flags: []string{"-check-close-notify"},
3942 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003943 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003944 // TODO(davidben): DTLS 1.3 will want a similar thing for
3945 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003946 tests = append(tests, testCase{
3947 name: "SkipHelloVerifyRequest",
3948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003949 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003950 Bugs: ProtocolBugs{
3951 SkipHelloVerifyRequest: true,
3952 },
3953 },
3954 })
3955 }
3956
David Benjamin760b1dd2015-05-15 23:33:48 -04003957 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003958 test.protocol = config.protocol
3959 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003960 test.name += "-DTLS"
3961 }
David Benjamin582ba042016-07-07 12:33:25 -07003962 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003963 test.name += "-Async"
3964 test.flags = append(test.flags, "-async")
3965 } else {
3966 test.name += "-Sync"
3967 }
David Benjamin582ba042016-07-07 12:33:25 -07003968 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003969 test.name += "-SplitHandshakeRecords"
3970 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003971 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003972 test.config.Bugs.MaxPacketLength = 256
3973 test.flags = append(test.flags, "-mtu", "256")
3974 }
3975 }
David Benjamin582ba042016-07-07 12:33:25 -07003976 if config.packHandshakeFlight {
3977 test.name += "-PackHandshakeFlight"
3978 test.config.Bugs.PackHandshakeFlight = true
3979 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003980 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003981 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003982}
3983
Adam Langley524e7172015-02-20 16:04:00 -08003984func addDDoSCallbackTests() {
3985 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08003986 for _, resume := range []bool{false, true} {
3987 suffix := "Resume"
3988 if resume {
3989 suffix = "No" + suffix
3990 }
3991
3992 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003993 testType: serverTest,
3994 name: "Server-DDoS-OK-" + suffix,
3995 config: Config{
3996 MaxVersion: VersionTLS12,
3997 },
Adam Langley524e7172015-02-20 16:04:00 -08003998 flags: []string{"-install-ddos-callback"},
3999 resumeSession: resume,
4000 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004001 testCases = append(testCases, testCase{
4002 testType: serverTest,
4003 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4004 config: Config{
4005 MaxVersion: VersionTLS13,
4006 },
4007 flags: []string{"-install-ddos-callback"},
4008 resumeSession: resume,
4009 })
Adam Langley524e7172015-02-20 16:04:00 -08004010
4011 failFlag := "-fail-ddos-callback"
4012 if resume {
4013 failFlag = "-fail-second-ddos-callback"
4014 }
4015 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004016 testType: serverTest,
4017 name: "Server-DDoS-Reject-" + suffix,
4018 config: Config{
4019 MaxVersion: VersionTLS12,
4020 },
Adam Langley524e7172015-02-20 16:04:00 -08004021 flags: []string{"-install-ddos-callback", failFlag},
4022 resumeSession: resume,
4023 shouldFail: true,
4024 expectedError: ":CONNECTION_REJECTED:",
4025 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004026 testCases = append(testCases, testCase{
4027 testType: serverTest,
4028 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4029 config: Config{
4030 MaxVersion: VersionTLS13,
4031 },
4032 flags: []string{"-install-ddos-callback", failFlag},
4033 resumeSession: resume,
4034 shouldFail: true,
4035 expectedError: ":CONNECTION_REJECTED:",
4036 })
Adam Langley524e7172015-02-20 16:04:00 -08004037 }
4038}
4039
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004040func addVersionNegotiationTests() {
4041 for i, shimVers := range tlsVersions {
4042 // Assemble flags to disable all newer versions on the shim.
4043 var flags []string
4044 for _, vers := range tlsVersions[i+1:] {
4045 flags = append(flags, vers.flag)
4046 }
4047
4048 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004049 protocols := []protocol{tls}
4050 if runnerVers.hasDTLS && shimVers.hasDTLS {
4051 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004052 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004053 for _, protocol := range protocols {
4054 expectedVersion := shimVers.version
4055 if runnerVers.version < shimVers.version {
4056 expectedVersion = runnerVers.version
4057 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004058
David Benjamin8b8c0062014-11-23 02:47:52 -05004059 suffix := shimVers.name + "-" + runnerVers.name
4060 if protocol == dtls {
4061 suffix += "-DTLS"
4062 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004063
David Benjamin1eb367c2014-12-12 18:17:51 -05004064 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4065
David Benjamin1e29a6b2014-12-10 02:27:24 -05004066 clientVers := shimVers.version
4067 if clientVers > VersionTLS10 {
4068 clientVers = VersionTLS10
4069 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004070 serverVers := expectedVersion
4071 if expectedVersion >= VersionTLS13 {
4072 serverVers = VersionTLS10
4073 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004074 testCases = append(testCases, testCase{
4075 protocol: protocol,
4076 testType: clientTest,
4077 name: "VersionNegotiation-Client-" + suffix,
4078 config: Config{
4079 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004080 Bugs: ProtocolBugs{
4081 ExpectInitialRecordVersion: clientVers,
4082 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004083 },
4084 flags: flags,
4085 expectedVersion: expectedVersion,
4086 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004087 testCases = append(testCases, testCase{
4088 protocol: protocol,
4089 testType: clientTest,
4090 name: "VersionNegotiation-Client2-" + suffix,
4091 config: Config{
4092 MaxVersion: runnerVers.version,
4093 Bugs: ProtocolBugs{
4094 ExpectInitialRecordVersion: clientVers,
4095 },
4096 },
4097 flags: []string{"-max-version", shimVersFlag},
4098 expectedVersion: expectedVersion,
4099 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004100
4101 testCases = append(testCases, testCase{
4102 protocol: protocol,
4103 testType: serverTest,
4104 name: "VersionNegotiation-Server-" + suffix,
4105 config: Config{
4106 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004107 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004108 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004109 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004110 },
4111 flags: flags,
4112 expectedVersion: expectedVersion,
4113 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004114 testCases = append(testCases, testCase{
4115 protocol: protocol,
4116 testType: serverTest,
4117 name: "VersionNegotiation-Server2-" + suffix,
4118 config: Config{
4119 MaxVersion: runnerVers.version,
4120 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004121 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004122 },
4123 },
4124 flags: []string{"-max-version", shimVersFlag},
4125 expectedVersion: expectedVersion,
4126 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004127 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004128 }
4129 }
David Benjamin95c69562016-06-29 18:15:03 -04004130
4131 // Test for version tolerance.
4132 testCases = append(testCases, testCase{
4133 testType: serverTest,
4134 name: "MinorVersionTolerance",
4135 config: Config{
4136 Bugs: ProtocolBugs{
4137 SendClientVersion: 0x03ff,
4138 },
4139 },
4140 expectedVersion: VersionTLS13,
4141 })
4142 testCases = append(testCases, testCase{
4143 testType: serverTest,
4144 name: "MajorVersionTolerance",
4145 config: Config{
4146 Bugs: ProtocolBugs{
4147 SendClientVersion: 0x0400,
4148 },
4149 },
4150 expectedVersion: VersionTLS13,
4151 })
4152 testCases = append(testCases, testCase{
4153 protocol: dtls,
4154 testType: serverTest,
4155 name: "MinorVersionTolerance-DTLS",
4156 config: Config{
4157 Bugs: ProtocolBugs{
4158 SendClientVersion: 0x03ff,
4159 },
4160 },
4161 expectedVersion: VersionTLS12,
4162 })
4163 testCases = append(testCases, testCase{
4164 protocol: dtls,
4165 testType: serverTest,
4166 name: "MajorVersionTolerance-DTLS",
4167 config: Config{
4168 Bugs: ProtocolBugs{
4169 SendClientVersion: 0x0400,
4170 },
4171 },
4172 expectedVersion: VersionTLS12,
4173 })
4174
4175 // Test that versions below 3.0 are rejected.
4176 testCases = append(testCases, testCase{
4177 testType: serverTest,
4178 name: "VersionTooLow",
4179 config: Config{
4180 Bugs: ProtocolBugs{
4181 SendClientVersion: 0x0200,
4182 },
4183 },
4184 shouldFail: true,
4185 expectedError: ":UNSUPPORTED_PROTOCOL:",
4186 })
4187 testCases = append(testCases, testCase{
4188 protocol: dtls,
4189 testType: serverTest,
4190 name: "VersionTooLow-DTLS",
4191 config: Config{
4192 Bugs: ProtocolBugs{
4193 // 0x0201 is the lowest version expressable in
4194 // DTLS.
4195 SendClientVersion: 0x0201,
4196 },
4197 },
4198 shouldFail: true,
4199 expectedError: ":UNSUPPORTED_PROTOCOL:",
4200 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004201
4202 // Test TLS 1.3's downgrade signal.
4203 testCases = append(testCases, testCase{
4204 name: "Downgrade-TLS12-Client",
4205 config: Config{
4206 Bugs: ProtocolBugs{
4207 NegotiateVersion: VersionTLS12,
4208 },
4209 },
4210 shouldFail: true,
4211 expectedError: ":DOWNGRADE_DETECTED:",
4212 })
4213 testCases = append(testCases, testCase{
4214 testType: serverTest,
4215 name: "Downgrade-TLS12-Server",
4216 config: Config{
4217 Bugs: ProtocolBugs{
4218 SendClientVersion: VersionTLS12,
4219 },
4220 },
4221 shouldFail: true,
4222 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4223 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004224
4225 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4226 // behave correctly when both real maximum and fallback versions are
4227 // set.
4228 testCases = append(testCases, testCase{
4229 name: "Downgrade-TLS12-Client-Fallback",
4230 config: Config{
4231 Bugs: ProtocolBugs{
4232 FailIfNotFallbackSCSV: true,
4233 },
4234 },
4235 flags: []string{
4236 "-max-version", strconv.Itoa(VersionTLS13),
4237 "-fallback-version", strconv.Itoa(VersionTLS12),
4238 },
4239 shouldFail: true,
4240 expectedError: ":DOWNGRADE_DETECTED:",
4241 })
4242 testCases = append(testCases, testCase{
4243 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4244 flags: []string{
4245 "-max-version", strconv.Itoa(VersionTLS12),
4246 "-fallback-version", strconv.Itoa(VersionTLS12),
4247 },
4248 })
4249
4250 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4251 // just have such connections fail than risk getting confused because we
4252 // didn't sent the 1.3 ClientHello.)
4253 testCases = append(testCases, testCase{
4254 name: "Downgrade-TLS12-Fallback-CheckVersion",
4255 config: Config{
4256 Bugs: ProtocolBugs{
4257 NegotiateVersion: VersionTLS13,
4258 FailIfNotFallbackSCSV: true,
4259 },
4260 },
4261 flags: []string{
4262 "-max-version", strconv.Itoa(VersionTLS13),
4263 "-fallback-version", strconv.Itoa(VersionTLS12),
4264 },
4265 shouldFail: true,
4266 expectedError: ":UNSUPPORTED_PROTOCOL:",
4267 })
4268
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004269}
4270
David Benjaminaccb4542014-12-12 23:44:33 -05004271func addMinimumVersionTests() {
4272 for i, shimVers := range tlsVersions {
4273 // Assemble flags to disable all older versions on the shim.
4274 var flags []string
4275 for _, vers := range tlsVersions[:i] {
4276 flags = append(flags, vers.flag)
4277 }
4278
4279 for _, runnerVers := range tlsVersions {
4280 protocols := []protocol{tls}
4281 if runnerVers.hasDTLS && shimVers.hasDTLS {
4282 protocols = append(protocols, dtls)
4283 }
4284 for _, protocol := range protocols {
4285 suffix := shimVers.name + "-" + runnerVers.name
4286 if protocol == dtls {
4287 suffix += "-DTLS"
4288 }
4289 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4290
David Benjaminaccb4542014-12-12 23:44:33 -05004291 var expectedVersion uint16
4292 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004293 var expectedClientError, expectedServerError string
4294 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004295 if runnerVers.version >= shimVers.version {
4296 expectedVersion = runnerVers.version
4297 } else {
4298 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004299 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4300 expectedServerLocalError = "remote error: protocol version not supported"
4301 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4302 // If the client's minimum version is TLS 1.3 and the runner's
4303 // maximum is below TLS 1.2, the runner will fail to select a
4304 // cipher before the shim rejects the selected version.
4305 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4306 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4307 } else {
4308 expectedClientError = expectedServerError
4309 expectedClientLocalError = expectedServerLocalError
4310 }
David Benjaminaccb4542014-12-12 23:44:33 -05004311 }
4312
4313 testCases = append(testCases, testCase{
4314 protocol: protocol,
4315 testType: clientTest,
4316 name: "MinimumVersion-Client-" + suffix,
4317 config: Config{
4318 MaxVersion: runnerVers.version,
4319 },
David Benjamin87909c02014-12-13 01:55:01 -05004320 flags: flags,
4321 expectedVersion: expectedVersion,
4322 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004323 expectedError: expectedClientError,
4324 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004325 })
4326 testCases = append(testCases, testCase{
4327 protocol: protocol,
4328 testType: clientTest,
4329 name: "MinimumVersion-Client2-" + suffix,
4330 config: Config{
4331 MaxVersion: runnerVers.version,
4332 },
David Benjamin87909c02014-12-13 01:55:01 -05004333 flags: []string{"-min-version", shimVersFlag},
4334 expectedVersion: expectedVersion,
4335 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004336 expectedError: expectedClientError,
4337 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004338 })
4339
4340 testCases = append(testCases, testCase{
4341 protocol: protocol,
4342 testType: serverTest,
4343 name: "MinimumVersion-Server-" + suffix,
4344 config: Config{
4345 MaxVersion: runnerVers.version,
4346 },
David Benjamin87909c02014-12-13 01:55:01 -05004347 flags: flags,
4348 expectedVersion: expectedVersion,
4349 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004350 expectedError: expectedServerError,
4351 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004352 })
4353 testCases = append(testCases, testCase{
4354 protocol: protocol,
4355 testType: serverTest,
4356 name: "MinimumVersion-Server2-" + suffix,
4357 config: Config{
4358 MaxVersion: runnerVers.version,
4359 },
David Benjamin87909c02014-12-13 01:55:01 -05004360 flags: []string{"-min-version", shimVersFlag},
4361 expectedVersion: expectedVersion,
4362 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004363 expectedError: expectedServerError,
4364 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004365 })
4366 }
4367 }
4368 }
4369}
4370
David Benjamine78bfde2014-09-06 12:45:15 -04004371func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004372 // TODO(davidben): Extensions, where applicable, all move their server
4373 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4374 // tests for both. Also test interaction with 0-RTT when implemented.
4375
David Benjamin97d17d92016-07-14 16:12:00 -04004376 // Repeat extensions tests all versions except SSL 3.0.
4377 for _, ver := range tlsVersions {
4378 if ver.version == VersionSSL30 {
4379 continue
4380 }
4381
David Benjamin97d17d92016-07-14 16:12:00 -04004382 // Test that duplicate extensions are rejected.
4383 testCases = append(testCases, testCase{
4384 testType: clientTest,
4385 name: "DuplicateExtensionClient-" + ver.name,
4386 config: Config{
4387 MaxVersion: ver.version,
4388 Bugs: ProtocolBugs{
4389 DuplicateExtension: true,
4390 },
David Benjamine78bfde2014-09-06 12:45:15 -04004391 },
David Benjamin97d17d92016-07-14 16:12:00 -04004392 shouldFail: true,
4393 expectedLocalError: "remote error: error decoding message",
4394 })
4395 testCases = append(testCases, testCase{
4396 testType: serverTest,
4397 name: "DuplicateExtensionServer-" + ver.name,
4398 config: Config{
4399 MaxVersion: ver.version,
4400 Bugs: ProtocolBugs{
4401 DuplicateExtension: true,
4402 },
David Benjamine78bfde2014-09-06 12:45:15 -04004403 },
David Benjamin97d17d92016-07-14 16:12:00 -04004404 shouldFail: true,
4405 expectedLocalError: "remote error: error decoding message",
4406 })
4407
4408 // Test SNI.
4409 testCases = append(testCases, testCase{
4410 testType: clientTest,
4411 name: "ServerNameExtensionClient-" + ver.name,
4412 config: Config{
4413 MaxVersion: ver.version,
4414 Bugs: ProtocolBugs{
4415 ExpectServerName: "example.com",
4416 },
David Benjamine78bfde2014-09-06 12:45:15 -04004417 },
David Benjamin97d17d92016-07-14 16:12:00 -04004418 flags: []string{"-host-name", "example.com"},
4419 })
4420 testCases = append(testCases, testCase{
4421 testType: clientTest,
4422 name: "ServerNameExtensionClientMismatch-" + ver.name,
4423 config: Config{
4424 MaxVersion: ver.version,
4425 Bugs: ProtocolBugs{
4426 ExpectServerName: "mismatch.com",
4427 },
David Benjamine78bfde2014-09-06 12:45:15 -04004428 },
David Benjamin97d17d92016-07-14 16:12:00 -04004429 flags: []string{"-host-name", "example.com"},
4430 shouldFail: true,
4431 expectedLocalError: "tls: unexpected server name",
4432 })
4433 testCases = append(testCases, testCase{
4434 testType: clientTest,
4435 name: "ServerNameExtensionClientMissing-" + ver.name,
4436 config: Config{
4437 MaxVersion: ver.version,
4438 Bugs: ProtocolBugs{
4439 ExpectServerName: "missing.com",
4440 },
David Benjamine78bfde2014-09-06 12:45:15 -04004441 },
David Benjamin97d17d92016-07-14 16:12:00 -04004442 shouldFail: true,
4443 expectedLocalError: "tls: unexpected server name",
4444 })
4445 testCases = append(testCases, testCase{
4446 testType: serverTest,
4447 name: "ServerNameExtensionServer-" + ver.name,
4448 config: Config{
4449 MaxVersion: ver.version,
4450 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004451 },
David Benjamin97d17d92016-07-14 16:12:00 -04004452 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004453 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004454 })
4455
4456 // Test ALPN.
4457 testCases = append(testCases, testCase{
4458 testType: clientTest,
4459 name: "ALPNClient-" + ver.name,
4460 config: Config{
4461 MaxVersion: ver.version,
4462 NextProtos: []string{"foo"},
4463 },
4464 flags: []string{
4465 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4466 "-expect-alpn", "foo",
4467 },
4468 expectedNextProto: "foo",
4469 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004470 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004471 })
4472 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004473 testType: clientTest,
4474 name: "ALPNClient-Mismatch-" + ver.name,
4475 config: Config{
4476 MaxVersion: ver.version,
4477 Bugs: ProtocolBugs{
4478 SendALPN: "baz",
4479 },
4480 },
4481 flags: []string{
4482 "-advertise-alpn", "\x03foo\x03bar",
4483 },
4484 shouldFail: true,
4485 expectedError: ":INVALID_ALPN_PROTOCOL:",
4486 expectedLocalError: "remote error: illegal parameter",
4487 })
4488 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004489 testType: serverTest,
4490 name: "ALPNServer-" + ver.name,
4491 config: Config{
4492 MaxVersion: ver.version,
4493 NextProtos: []string{"foo", "bar", "baz"},
4494 },
4495 flags: []string{
4496 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4497 "-select-alpn", "foo",
4498 },
4499 expectedNextProto: "foo",
4500 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004501 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004502 })
4503 testCases = append(testCases, testCase{
4504 testType: serverTest,
4505 name: "ALPNServer-Decline-" + ver.name,
4506 config: Config{
4507 MaxVersion: ver.version,
4508 NextProtos: []string{"foo", "bar", "baz"},
4509 },
4510 flags: []string{"-decline-alpn"},
4511 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004512 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004513 })
4514
David Benjamin25fe85b2016-08-09 20:00:32 -04004515 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4516 // called once.
4517 testCases = append(testCases, testCase{
4518 testType: serverTest,
4519 name: "ALPNServer-Async-" + ver.name,
4520 config: Config{
4521 MaxVersion: ver.version,
4522 NextProtos: []string{"foo", "bar", "baz"},
4523 },
4524 flags: []string{
4525 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4526 "-select-alpn", "foo",
4527 "-async",
4528 },
4529 expectedNextProto: "foo",
4530 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004531 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004532 })
4533
David Benjamin97d17d92016-07-14 16:12:00 -04004534 var emptyString string
4535 testCases = append(testCases, testCase{
4536 testType: clientTest,
4537 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4538 config: Config{
4539 MaxVersion: ver.version,
4540 NextProtos: []string{""},
4541 Bugs: ProtocolBugs{
4542 // A server returning an empty ALPN protocol
4543 // should be rejected.
4544 ALPNProtocol: &emptyString,
4545 },
4546 },
4547 flags: []string{
4548 "-advertise-alpn", "\x03foo",
4549 },
4550 shouldFail: true,
4551 expectedError: ":PARSE_TLSEXT:",
4552 })
4553 testCases = append(testCases, testCase{
4554 testType: serverTest,
4555 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4556 config: Config{
4557 MaxVersion: ver.version,
4558 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004559 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004560 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004561 },
David Benjamin97d17d92016-07-14 16:12:00 -04004562 flags: []string{
4563 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004564 },
David Benjamin97d17d92016-07-14 16:12:00 -04004565 shouldFail: true,
4566 expectedError: ":PARSE_TLSEXT:",
4567 })
4568
4569 // Test NPN and the interaction with ALPN.
4570 if ver.version < VersionTLS13 {
4571 // Test that the server prefers ALPN over NPN.
4572 testCases = append(testCases, testCase{
4573 testType: serverTest,
4574 name: "ALPNServer-Preferred-" + ver.name,
4575 config: Config{
4576 MaxVersion: ver.version,
4577 NextProtos: []string{"foo", "bar", "baz"},
4578 },
4579 flags: []string{
4580 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4581 "-select-alpn", "foo",
4582 "-advertise-npn", "\x03foo\x03bar\x03baz",
4583 },
4584 expectedNextProto: "foo",
4585 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004586 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004587 })
4588 testCases = append(testCases, testCase{
4589 testType: serverTest,
4590 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4591 config: Config{
4592 MaxVersion: ver.version,
4593 NextProtos: []string{"foo", "bar", "baz"},
4594 Bugs: ProtocolBugs{
4595 SwapNPNAndALPN: true,
4596 },
4597 },
4598 flags: []string{
4599 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4600 "-select-alpn", "foo",
4601 "-advertise-npn", "\x03foo\x03bar\x03baz",
4602 },
4603 expectedNextProto: "foo",
4604 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004605 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004606 })
4607
4608 // Test that negotiating both NPN and ALPN is forbidden.
4609 testCases = append(testCases, testCase{
4610 name: "NegotiateALPNAndNPN-" + ver.name,
4611 config: Config{
4612 MaxVersion: ver.version,
4613 NextProtos: []string{"foo", "bar", "baz"},
4614 Bugs: ProtocolBugs{
4615 NegotiateALPNAndNPN: true,
4616 },
4617 },
4618 flags: []string{
4619 "-advertise-alpn", "\x03foo",
4620 "-select-next-proto", "foo",
4621 },
4622 shouldFail: true,
4623 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4624 })
4625 testCases = append(testCases, testCase{
4626 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4627 config: Config{
4628 MaxVersion: ver.version,
4629 NextProtos: []string{"foo", "bar", "baz"},
4630 Bugs: ProtocolBugs{
4631 NegotiateALPNAndNPN: true,
4632 SwapNPNAndALPN: true,
4633 },
4634 },
4635 flags: []string{
4636 "-advertise-alpn", "\x03foo",
4637 "-select-next-proto", "foo",
4638 },
4639 shouldFail: true,
4640 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4641 })
4642
4643 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4644 testCases = append(testCases, testCase{
4645 name: "DisableNPN-" + ver.name,
4646 config: Config{
4647 MaxVersion: ver.version,
4648 NextProtos: []string{"foo"},
4649 },
4650 flags: []string{
4651 "-select-next-proto", "foo",
4652 "-disable-npn",
4653 },
4654 expectNoNextProto: true,
4655 })
4656 }
4657
4658 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004659
4660 // Resume with a corrupt ticket.
4661 testCases = append(testCases, testCase{
4662 testType: serverTest,
4663 name: "CorruptTicket-" + ver.name,
4664 config: Config{
4665 MaxVersion: ver.version,
4666 Bugs: ProtocolBugs{
4667 CorruptTicket: true,
4668 },
4669 },
4670 resumeSession: true,
4671 expectResumeRejected: true,
4672 })
4673 // Test the ticket callback, with and without renewal.
4674 testCases = append(testCases, testCase{
4675 testType: serverTest,
4676 name: "TicketCallback-" + ver.name,
4677 config: Config{
4678 MaxVersion: ver.version,
4679 },
4680 resumeSession: true,
4681 flags: []string{"-use-ticket-callback"},
4682 })
4683 testCases = append(testCases, testCase{
4684 testType: serverTest,
4685 name: "TicketCallback-Renew-" + ver.name,
4686 config: Config{
4687 MaxVersion: ver.version,
4688 Bugs: ProtocolBugs{
4689 ExpectNewTicket: true,
4690 },
4691 },
4692 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4693 resumeSession: true,
4694 })
4695
4696 // Test that the ticket callback is only called once when everything before
4697 // it in the ClientHello is asynchronous. This corrupts the ticket so
4698 // certificate selection callbacks run.
4699 testCases = append(testCases, testCase{
4700 testType: serverTest,
4701 name: "TicketCallback-SingleCall-" + ver.name,
4702 config: Config{
4703 MaxVersion: ver.version,
4704 Bugs: ProtocolBugs{
4705 CorruptTicket: true,
4706 },
4707 },
4708 resumeSession: true,
4709 expectResumeRejected: true,
4710 flags: []string{
4711 "-use-ticket-callback",
4712 "-async",
4713 },
4714 })
4715
4716 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004717 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004718 testCases = append(testCases, testCase{
4719 testType: serverTest,
4720 name: "OversizedSessionId-" + ver.name,
4721 config: Config{
4722 MaxVersion: ver.version,
4723 Bugs: ProtocolBugs{
4724 OversizedSessionId: true,
4725 },
4726 },
4727 resumeSession: true,
4728 shouldFail: true,
4729 expectedError: ":DECODE_ERROR:",
4730 })
4731 }
4732
4733 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4734 // are ignored.
4735 if ver.hasDTLS {
4736 testCases = append(testCases, testCase{
4737 protocol: dtls,
4738 name: "SRTP-Client-" + ver.name,
4739 config: Config{
4740 MaxVersion: ver.version,
4741 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4742 },
4743 flags: []string{
4744 "-srtp-profiles",
4745 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4746 },
4747 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4748 })
4749 testCases = append(testCases, testCase{
4750 protocol: dtls,
4751 testType: serverTest,
4752 name: "SRTP-Server-" + ver.name,
4753 config: Config{
4754 MaxVersion: ver.version,
4755 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4756 },
4757 flags: []string{
4758 "-srtp-profiles",
4759 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4760 },
4761 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4762 })
4763 // Test that the MKI is ignored.
4764 testCases = append(testCases, testCase{
4765 protocol: dtls,
4766 testType: serverTest,
4767 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4768 config: Config{
4769 MaxVersion: ver.version,
4770 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4771 Bugs: ProtocolBugs{
4772 SRTPMasterKeyIdentifer: "bogus",
4773 },
4774 },
4775 flags: []string{
4776 "-srtp-profiles",
4777 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4778 },
4779 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4780 })
4781 // Test that SRTP isn't negotiated on the server if there were
4782 // no matching profiles.
4783 testCases = append(testCases, testCase{
4784 protocol: dtls,
4785 testType: serverTest,
4786 name: "SRTP-Server-NoMatch-" + ver.name,
4787 config: Config{
4788 MaxVersion: ver.version,
4789 SRTPProtectionProfiles: []uint16{100, 101, 102},
4790 },
4791 flags: []string{
4792 "-srtp-profiles",
4793 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4794 },
4795 expectedSRTPProtectionProfile: 0,
4796 })
4797 // Test that the server returning an invalid SRTP profile is
4798 // flagged as an error by the client.
4799 testCases = append(testCases, testCase{
4800 protocol: dtls,
4801 name: "SRTP-Client-NoMatch-" + ver.name,
4802 config: Config{
4803 MaxVersion: ver.version,
4804 Bugs: ProtocolBugs{
4805 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4806 },
4807 },
4808 flags: []string{
4809 "-srtp-profiles",
4810 "SRTP_AES128_CM_SHA1_80",
4811 },
4812 shouldFail: true,
4813 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4814 })
4815 }
4816
4817 // Test SCT list.
4818 testCases = append(testCases, testCase{
4819 name: "SignedCertificateTimestampList-Client-" + ver.name,
4820 testType: clientTest,
4821 config: Config{
4822 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004823 },
David Benjamin97d17d92016-07-14 16:12:00 -04004824 flags: []string{
4825 "-enable-signed-cert-timestamps",
4826 "-expect-signed-cert-timestamps",
4827 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004828 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004829 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004830 })
4831 testCases = append(testCases, testCase{
4832 name: "SendSCTListOnResume-" + ver.name,
4833 config: Config{
4834 MaxVersion: ver.version,
4835 Bugs: ProtocolBugs{
4836 SendSCTListOnResume: []byte("bogus"),
4837 },
David Benjamind98452d2015-06-16 14:16:23 -04004838 },
David Benjamin97d17d92016-07-14 16:12:00 -04004839 flags: []string{
4840 "-enable-signed-cert-timestamps",
4841 "-expect-signed-cert-timestamps",
4842 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004843 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004844 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004845 })
4846 testCases = append(testCases, testCase{
4847 name: "SignedCertificateTimestampList-Server-" + ver.name,
4848 testType: serverTest,
4849 config: Config{
4850 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004851 },
David Benjamin97d17d92016-07-14 16:12:00 -04004852 flags: []string{
4853 "-signed-cert-timestamps",
4854 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004855 },
David Benjamin97d17d92016-07-14 16:12:00 -04004856 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004857 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004858 })
4859 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004860
Paul Lietar4fac72e2015-09-09 13:44:55 +01004861 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004862 testType: clientTest,
4863 name: "ClientHelloPadding",
4864 config: Config{
4865 Bugs: ProtocolBugs{
4866 RequireClientHelloSize: 512,
4867 },
4868 },
4869 // This hostname just needs to be long enough to push the
4870 // ClientHello into F5's danger zone between 256 and 511 bytes
4871 // long.
4872 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4873 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004874
4875 // Extensions should not function in SSL 3.0.
4876 testCases = append(testCases, testCase{
4877 testType: serverTest,
4878 name: "SSLv3Extensions-NoALPN",
4879 config: Config{
4880 MaxVersion: VersionSSL30,
4881 NextProtos: []string{"foo", "bar", "baz"},
4882 },
4883 flags: []string{
4884 "-select-alpn", "foo",
4885 },
4886 expectNoNextProto: true,
4887 })
4888
4889 // Test session tickets separately as they follow a different codepath.
4890 testCases = append(testCases, testCase{
4891 testType: serverTest,
4892 name: "SSLv3Extensions-NoTickets",
4893 config: Config{
4894 MaxVersion: VersionSSL30,
4895 Bugs: ProtocolBugs{
4896 // Historically, session tickets in SSL 3.0
4897 // failed in different ways depending on whether
4898 // the client supported renegotiation_info.
4899 NoRenegotiationInfo: true,
4900 },
4901 },
4902 resumeSession: true,
4903 })
4904 testCases = append(testCases, testCase{
4905 testType: serverTest,
4906 name: "SSLv3Extensions-NoTickets2",
4907 config: Config{
4908 MaxVersion: VersionSSL30,
4909 },
4910 resumeSession: true,
4911 })
4912
4913 // But SSL 3.0 does send and process renegotiation_info.
4914 testCases = append(testCases, testCase{
4915 testType: serverTest,
4916 name: "SSLv3Extensions-RenegotiationInfo",
4917 config: Config{
4918 MaxVersion: VersionSSL30,
4919 Bugs: ProtocolBugs{
4920 RequireRenegotiationInfo: true,
4921 },
4922 },
4923 })
4924 testCases = append(testCases, testCase{
4925 testType: serverTest,
4926 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4927 config: Config{
4928 MaxVersion: VersionSSL30,
4929 Bugs: ProtocolBugs{
4930 NoRenegotiationInfo: true,
4931 SendRenegotiationSCSV: true,
4932 RequireRenegotiationInfo: true,
4933 },
4934 },
4935 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004936
4937 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4938 // in ServerHello.
4939 testCases = append(testCases, testCase{
4940 name: "NPN-Forbidden-TLS13",
4941 config: Config{
4942 MaxVersion: VersionTLS13,
4943 NextProtos: []string{"foo"},
4944 Bugs: ProtocolBugs{
4945 NegotiateNPNAtAllVersions: true,
4946 },
4947 },
4948 flags: []string{"-select-next-proto", "foo"},
4949 shouldFail: true,
4950 expectedError: ":ERROR_PARSING_EXTENSION:",
4951 })
4952 testCases = append(testCases, testCase{
4953 name: "EMS-Forbidden-TLS13",
4954 config: Config{
4955 MaxVersion: VersionTLS13,
4956 Bugs: ProtocolBugs{
4957 NegotiateEMSAtAllVersions: true,
4958 },
4959 },
4960 shouldFail: true,
4961 expectedError: ":ERROR_PARSING_EXTENSION:",
4962 })
4963 testCases = append(testCases, testCase{
4964 name: "RenegotiationInfo-Forbidden-TLS13",
4965 config: Config{
4966 MaxVersion: VersionTLS13,
4967 Bugs: ProtocolBugs{
4968 NegotiateRenegotiationInfoAtAllVersions: true,
4969 },
4970 },
4971 shouldFail: true,
4972 expectedError: ":ERROR_PARSING_EXTENSION:",
4973 })
4974 testCases = append(testCases, testCase{
4975 name: "ChannelID-Forbidden-TLS13",
4976 config: Config{
4977 MaxVersion: VersionTLS13,
4978 RequestChannelID: true,
4979 Bugs: ProtocolBugs{
4980 NegotiateChannelIDAtAllVersions: true,
4981 },
4982 },
4983 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4984 shouldFail: true,
4985 expectedError: ":ERROR_PARSING_EXTENSION:",
4986 })
4987 testCases = append(testCases, testCase{
4988 name: "Ticket-Forbidden-TLS13",
4989 config: Config{
4990 MaxVersion: VersionTLS12,
4991 },
4992 resumeConfig: &Config{
4993 MaxVersion: VersionTLS13,
4994 Bugs: ProtocolBugs{
4995 AdvertiseTicketExtension: true,
4996 },
4997 },
4998 resumeSession: true,
4999 shouldFail: true,
5000 expectedError: ":ERROR_PARSING_EXTENSION:",
5001 })
5002
5003 // Test that illegal extensions in TLS 1.3 are declined by the server if
5004 // offered in ClientHello. The runner's server will fail if this occurs,
5005 // so we exercise the offering path. (EMS and Renegotiation Info are
5006 // implicit in every test.)
5007 testCases = append(testCases, testCase{
5008 testType: serverTest,
5009 name: "ChannelID-Declined-TLS13",
5010 config: Config{
5011 MaxVersion: VersionTLS13,
5012 ChannelID: channelIDKey,
5013 },
5014 flags: []string{"-enable-channel-id"},
5015 })
5016 testCases = append(testCases, testCase{
5017 testType: serverTest,
5018 name: "NPN-Server",
5019 config: Config{
5020 MaxVersion: VersionTLS13,
5021 NextProtos: []string{"bar"},
5022 },
5023 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5024 })
David Benjamine78bfde2014-09-06 12:45:15 -04005025}
5026
David Benjamin01fe8202014-09-24 15:21:44 -04005027func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005028 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005029 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005030 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5031 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5032 // TLS 1.3 only shares ciphers with TLS 1.2, so
5033 // we skip certain combinations and use a
5034 // different cipher to test with.
5035 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5036 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5037 continue
5038 }
5039 }
5040
David Benjamin8b8c0062014-11-23 02:47:52 -05005041 protocols := []protocol{tls}
5042 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5043 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005044 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005045 for _, protocol := range protocols {
5046 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5047 if protocol == dtls {
5048 suffix += "-DTLS"
5049 }
5050
David Benjaminece3de92015-03-16 18:02:20 -04005051 if sessionVers.version == resumeVers.version {
5052 testCases = append(testCases, testCase{
5053 protocol: protocol,
5054 name: "Resume-Client" + suffix,
5055 resumeSession: true,
5056 config: Config{
5057 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005058 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005059 Bugs: ProtocolBugs{
5060 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5061 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5062 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005063 },
David Benjaminece3de92015-03-16 18:02:20 -04005064 expectedVersion: sessionVers.version,
5065 expectedResumeVersion: resumeVers.version,
5066 })
5067 } else {
David Benjamin405da482016-08-08 17:25:07 -04005068 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5069
5070 // Offering a TLS 1.3 session sends an empty session ID, so
5071 // there is no way to convince a non-lookahead client the
5072 // session was resumed. It will appear to the client that a
5073 // stray ChangeCipherSpec was sent.
5074 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5075 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005076 }
5077
David Benjaminece3de92015-03-16 18:02:20 -04005078 testCases = append(testCases, testCase{
5079 protocol: protocol,
5080 name: "Resume-Client-Mismatch" + suffix,
5081 resumeSession: true,
5082 config: Config{
5083 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005084 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005085 },
David Benjaminece3de92015-03-16 18:02:20 -04005086 expectedVersion: sessionVers.version,
5087 resumeConfig: &Config{
5088 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005089 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005090 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005091 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005092 },
5093 },
5094 expectedResumeVersion: resumeVers.version,
5095 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005096 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005097 })
5098 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005099
5100 testCases = append(testCases, testCase{
5101 protocol: protocol,
5102 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005103 resumeSession: true,
5104 config: Config{
5105 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005106 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005107 },
5108 expectedVersion: sessionVers.version,
5109 resumeConfig: &Config{
5110 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005111 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005112 },
5113 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005114 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005115 expectedResumeVersion: resumeVers.version,
5116 })
5117
David Benjamin8b8c0062014-11-23 02:47:52 -05005118 testCases = append(testCases, testCase{
5119 protocol: protocol,
5120 testType: serverTest,
5121 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005122 resumeSession: true,
5123 config: Config{
5124 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005125 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005126 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005127 expectedVersion: sessionVers.version,
5128 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005129 resumeConfig: &Config{
5130 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005131 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005132 Bugs: ProtocolBugs{
5133 SendBothTickets: true,
5134 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005135 },
5136 expectedResumeVersion: resumeVers.version,
5137 })
5138 }
David Benjamin01fe8202014-09-24 15:21:44 -04005139 }
5140 }
David Benjaminece3de92015-03-16 18:02:20 -04005141
5142 testCases = append(testCases, testCase{
5143 name: "Resume-Client-CipherMismatch",
5144 resumeSession: true,
5145 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005146 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005147 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5148 },
5149 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005150 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005151 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5152 Bugs: ProtocolBugs{
5153 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5154 },
5155 },
5156 shouldFail: true,
5157 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5158 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005159
5160 testCases = append(testCases, testCase{
5161 name: "Resume-Client-CipherMismatch-TLS13",
5162 resumeSession: true,
5163 config: Config{
5164 MaxVersion: VersionTLS13,
5165 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5166 },
5167 resumeConfig: &Config{
5168 MaxVersion: VersionTLS13,
5169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5170 Bugs: ProtocolBugs{
5171 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5172 },
5173 },
5174 shouldFail: true,
5175 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5176 })
David Benjamin01fe8202014-09-24 15:21:44 -04005177}
5178
Adam Langley2ae77d22014-10-28 17:29:33 -07005179func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005180 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005181 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005182 testType: serverTest,
5183 name: "Renegotiate-Server-Forbidden",
5184 config: Config{
5185 MaxVersion: VersionTLS12,
5186 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005187 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005188 shouldFail: true,
5189 expectedError: ":NO_RENEGOTIATION:",
5190 expectedLocalError: "remote error: no renegotiation",
5191 })
Adam Langley5021b222015-06-12 18:27:58 -07005192 // The server shouldn't echo the renegotiation extension unless
5193 // requested by the client.
5194 testCases = append(testCases, testCase{
5195 testType: serverTest,
5196 name: "Renegotiate-Server-NoExt",
5197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005198 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005199 Bugs: ProtocolBugs{
5200 NoRenegotiationInfo: true,
5201 RequireRenegotiationInfo: true,
5202 },
5203 },
5204 shouldFail: true,
5205 expectedLocalError: "renegotiation extension missing",
5206 })
5207 // The renegotiation SCSV should be sufficient for the server to echo
5208 // the extension.
5209 testCases = append(testCases, testCase{
5210 testType: serverTest,
5211 name: "Renegotiate-Server-NoExt-SCSV",
5212 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005213 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005214 Bugs: ProtocolBugs{
5215 NoRenegotiationInfo: true,
5216 SendRenegotiationSCSV: true,
5217 RequireRenegotiationInfo: true,
5218 },
5219 },
5220 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005221 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005222 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005224 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005225 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005226 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005227 },
5228 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005229 renegotiate: 1,
5230 flags: []string{
5231 "-renegotiate-freely",
5232 "-expect-total-renegotiations", "1",
5233 },
David Benjamincdea40c2015-03-19 14:09:43 -04005234 })
5235 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005236 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005237 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005239 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005240 Bugs: ProtocolBugs{
5241 EmptyRenegotiationInfo: true,
5242 },
5243 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005244 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005245 shouldFail: true,
5246 expectedError: ":RENEGOTIATION_MISMATCH:",
5247 })
5248 testCases = append(testCases, testCase{
5249 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005250 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005251 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005252 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005253 Bugs: ProtocolBugs{
5254 BadRenegotiationInfo: true,
5255 },
5256 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005257 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005258 shouldFail: true,
5259 expectedError: ":RENEGOTIATION_MISMATCH:",
5260 })
5261 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005262 name: "Renegotiate-Client-Downgrade",
5263 renegotiate: 1,
5264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005265 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005266 Bugs: ProtocolBugs{
5267 NoRenegotiationInfoAfterInitial: true,
5268 },
5269 },
5270 flags: []string{"-renegotiate-freely"},
5271 shouldFail: true,
5272 expectedError: ":RENEGOTIATION_MISMATCH:",
5273 })
5274 testCases = append(testCases, testCase{
5275 name: "Renegotiate-Client-Upgrade",
5276 renegotiate: 1,
5277 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005278 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005279 Bugs: ProtocolBugs{
5280 NoRenegotiationInfoInInitial: true,
5281 },
5282 },
5283 flags: []string{"-renegotiate-freely"},
5284 shouldFail: true,
5285 expectedError: ":RENEGOTIATION_MISMATCH:",
5286 })
5287 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005288 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005289 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005290 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005291 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005292 Bugs: ProtocolBugs{
5293 NoRenegotiationInfo: true,
5294 },
5295 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005296 flags: []string{
5297 "-renegotiate-freely",
5298 "-expect-total-renegotiations", "1",
5299 },
David Benjamincff0b902015-05-15 23:09:47 -04005300 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005301
5302 // Test that the server may switch ciphers on renegotiation without
5303 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005304 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005305 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005306 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005307 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005308 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005309 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005310 },
5311 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005312 flags: []string{
5313 "-renegotiate-freely",
5314 "-expect-total-renegotiations", "1",
5315 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005316 })
5317 testCases = append(testCases, testCase{
5318 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005319 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005320 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005321 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005322 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5323 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005324 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005325 flags: []string{
5326 "-renegotiate-freely",
5327 "-expect-total-renegotiations", "1",
5328 },
David Benjaminb16346b2015-04-08 19:16:58 -04005329 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005330
5331 // Test that the server may not switch versions on renegotiation.
5332 testCases = append(testCases, testCase{
5333 name: "Renegotiate-Client-SwitchVersion",
5334 config: Config{
5335 MaxVersion: VersionTLS12,
5336 // Pick a cipher which exists at both versions.
5337 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5338 Bugs: ProtocolBugs{
5339 NegotiateVersionOnRenego: VersionTLS11,
5340 },
5341 },
5342 renegotiate: 1,
5343 flags: []string{
5344 "-renegotiate-freely",
5345 "-expect-total-renegotiations", "1",
5346 },
5347 shouldFail: true,
5348 expectedError: ":WRONG_SSL_VERSION:",
5349 })
5350
David Benjaminb16346b2015-04-08 19:16:58 -04005351 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005352 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005353 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005354 config: Config{
5355 MaxVersion: VersionTLS10,
5356 Bugs: ProtocolBugs{
5357 RequireSameRenegoClientVersion: true,
5358 },
5359 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005360 flags: []string{
5361 "-renegotiate-freely",
5362 "-expect-total-renegotiations", "1",
5363 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005364 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005365 testCases = append(testCases, testCase{
5366 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005367 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005368 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005369 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005370 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5371 NextProtos: []string{"foo"},
5372 },
5373 flags: []string{
5374 "-false-start",
5375 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005376 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005377 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005378 },
5379 shimWritesFirst: true,
5380 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005381
5382 // Client-side renegotiation controls.
5383 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005384 name: "Renegotiate-Client-Forbidden-1",
5385 config: Config{
5386 MaxVersion: VersionTLS12,
5387 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005388 renegotiate: 1,
5389 shouldFail: true,
5390 expectedError: ":NO_RENEGOTIATION:",
5391 expectedLocalError: "remote error: no renegotiation",
5392 })
5393 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005394 name: "Renegotiate-Client-Once-1",
5395 config: Config{
5396 MaxVersion: VersionTLS12,
5397 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005398 renegotiate: 1,
5399 flags: []string{
5400 "-renegotiate-once",
5401 "-expect-total-renegotiations", "1",
5402 },
5403 })
5404 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005405 name: "Renegotiate-Client-Freely-1",
5406 config: Config{
5407 MaxVersion: VersionTLS12,
5408 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005409 renegotiate: 1,
5410 flags: []string{
5411 "-renegotiate-freely",
5412 "-expect-total-renegotiations", "1",
5413 },
5414 })
5415 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005416 name: "Renegotiate-Client-Once-2",
5417 config: Config{
5418 MaxVersion: VersionTLS12,
5419 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005420 renegotiate: 2,
5421 flags: []string{"-renegotiate-once"},
5422 shouldFail: true,
5423 expectedError: ":NO_RENEGOTIATION:",
5424 expectedLocalError: "remote error: no renegotiation",
5425 })
5426 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005427 name: "Renegotiate-Client-Freely-2",
5428 config: Config{
5429 MaxVersion: VersionTLS12,
5430 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005431 renegotiate: 2,
5432 flags: []string{
5433 "-renegotiate-freely",
5434 "-expect-total-renegotiations", "2",
5435 },
5436 })
Adam Langley27a0d082015-11-03 13:34:10 -08005437 testCases = append(testCases, testCase{
5438 name: "Renegotiate-Client-NoIgnore",
5439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005440 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005441 Bugs: ProtocolBugs{
5442 SendHelloRequestBeforeEveryAppDataRecord: true,
5443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":NO_RENEGOTIATION:",
5447 })
5448 testCases = append(testCases, testCase{
5449 name: "Renegotiate-Client-Ignore",
5450 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005451 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005452 Bugs: ProtocolBugs{
5453 SendHelloRequestBeforeEveryAppDataRecord: true,
5454 },
5455 },
5456 flags: []string{
5457 "-renegotiate-ignore",
5458 "-expect-total-renegotiations", "0",
5459 },
5460 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005461
David Benjamin397c8e62016-07-08 14:14:36 -07005462 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005463 testCases = append(testCases, testCase{
5464 name: "StrayHelloRequest",
5465 config: Config{
5466 MaxVersion: VersionTLS12,
5467 Bugs: ProtocolBugs{
5468 SendHelloRequestBeforeEveryHandshakeMessage: true,
5469 },
5470 },
5471 })
5472 testCases = append(testCases, testCase{
5473 name: "StrayHelloRequest-Packed",
5474 config: Config{
5475 MaxVersion: VersionTLS12,
5476 Bugs: ProtocolBugs{
5477 PackHandshakeFlight: true,
5478 SendHelloRequestBeforeEveryHandshakeMessage: true,
5479 },
5480 },
5481 })
5482
David Benjamin12d2c482016-07-24 10:56:51 -04005483 // Test renegotiation works if HelloRequest and server Finished come in
5484 // the same record.
5485 testCases = append(testCases, testCase{
5486 name: "Renegotiate-Client-Packed",
5487 config: Config{
5488 MaxVersion: VersionTLS12,
5489 Bugs: ProtocolBugs{
5490 PackHandshakeFlight: true,
5491 PackHelloRequestWithFinished: true,
5492 },
5493 },
5494 renegotiate: 1,
5495 flags: []string{
5496 "-renegotiate-freely",
5497 "-expect-total-renegotiations", "1",
5498 },
5499 })
5500
David Benjamin397c8e62016-07-08 14:14:36 -07005501 // Renegotiation is forbidden in TLS 1.3.
5502 testCases = append(testCases, testCase{
5503 name: "Renegotiate-Client-TLS13",
5504 config: Config{
5505 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005506 Bugs: ProtocolBugs{
5507 SendHelloRequestBeforeEveryAppDataRecord: true,
5508 },
David Benjamin397c8e62016-07-08 14:14:36 -07005509 },
David Benjamin397c8e62016-07-08 14:14:36 -07005510 flags: []string{
5511 "-renegotiate-freely",
5512 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005513 shouldFail: true,
5514 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005515 })
5516
5517 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5518 testCases = append(testCases, testCase{
5519 name: "StrayHelloRequest-TLS13",
5520 config: Config{
5521 MaxVersion: VersionTLS13,
5522 Bugs: ProtocolBugs{
5523 SendHelloRequestBeforeEveryHandshakeMessage: true,
5524 },
5525 },
5526 shouldFail: true,
5527 expectedError: ":UNEXPECTED_MESSAGE:",
5528 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005529}
5530
David Benjamin5e961c12014-11-07 01:48:35 -05005531func addDTLSReplayTests() {
5532 // Test that sequence number replays are detected.
5533 testCases = append(testCases, testCase{
5534 protocol: dtls,
5535 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005536 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005537 replayWrites: true,
5538 })
5539
David Benjamin8e6db492015-07-25 18:29:23 -04005540 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005541 // than the retransmit window.
5542 testCases = append(testCases, testCase{
5543 protocol: dtls,
5544 name: "DTLS-Replay-LargeGaps",
5545 config: Config{
5546 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005547 SequenceNumberMapping: func(in uint64) uint64 {
5548 return in * 127
5549 },
David Benjamin5e961c12014-11-07 01:48:35 -05005550 },
5551 },
David Benjamin8e6db492015-07-25 18:29:23 -04005552 messageCount: 200,
5553 replayWrites: true,
5554 })
5555
5556 // Test the incoming sequence number changing non-monotonically.
5557 testCases = append(testCases, testCase{
5558 protocol: dtls,
5559 name: "DTLS-Replay-NonMonotonic",
5560 config: Config{
5561 Bugs: ProtocolBugs{
5562 SequenceNumberMapping: func(in uint64) uint64 {
5563 return in ^ 31
5564 },
5565 },
5566 },
5567 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005568 replayWrites: true,
5569 })
5570}
5571
Nick Harper60edffd2016-06-21 15:19:24 -07005572var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005573 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005574 id signatureAlgorithm
5575 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005576}{
Nick Harper60edffd2016-06-21 15:19:24 -07005577 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5578 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5579 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5580 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005581 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005582 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5583 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5584 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005585 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5586 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5587 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005588 // Tests for key types prior to TLS 1.2.
5589 {"RSA", 0, testCertRSA},
5590 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005591}
5592
Nick Harper60edffd2016-06-21 15:19:24 -07005593const fakeSigAlg1 signatureAlgorithm = 0x2a01
5594const fakeSigAlg2 signatureAlgorithm = 0xff01
5595
5596func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005597 // Not all ciphers involve a signature. Advertise a list which gives all
5598 // versions a signing cipher.
5599 signingCiphers := []uint16{
5600 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5601 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5602 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5603 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5604 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5605 }
5606
David Benjaminca3d5452016-07-14 12:51:01 -04005607 var allAlgorithms []signatureAlgorithm
5608 for _, alg := range testSignatureAlgorithms {
5609 if alg.id != 0 {
5610 allAlgorithms = append(allAlgorithms, alg.id)
5611 }
5612 }
5613
Nick Harper60edffd2016-06-21 15:19:24 -07005614 // Make sure each signature algorithm works. Include some fake values in
5615 // the list and ensure they're ignored.
5616 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005617 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005618 if (ver.version < VersionTLS12) != (alg.id == 0) {
5619 continue
5620 }
5621
5622 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5623 // or remove it in C.
5624 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005625 continue
5626 }
Nick Harper60edffd2016-06-21 15:19:24 -07005627
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005628 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005629 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005630 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5631 shouldFail = true
5632 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005633 // RSA-PKCS1 does not exist in TLS 1.3.
5634 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5635 shouldFail = true
5636 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005637
5638 var signError, verifyError string
5639 if shouldFail {
5640 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5641 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005642 }
David Benjamin000800a2014-11-14 01:43:59 -05005643
David Benjamin1fb125c2016-07-08 18:52:12 -07005644 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005645
David Benjamin7a41d372016-07-09 11:21:54 -07005646 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005647 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005648 config: Config{
5649 MaxVersion: ver.version,
5650 ClientAuth: RequireAnyClientCert,
5651 VerifySignatureAlgorithms: []signatureAlgorithm{
5652 fakeSigAlg1,
5653 alg.id,
5654 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005655 },
David Benjamin7a41d372016-07-09 11:21:54 -07005656 },
5657 flags: []string{
5658 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5659 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5660 "-enable-all-curves",
5661 },
5662 shouldFail: shouldFail,
5663 expectedError: signError,
5664 expectedPeerSignatureAlgorithm: alg.id,
5665 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005666
David Benjamin7a41d372016-07-09 11:21:54 -07005667 testCases = append(testCases, testCase{
5668 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005669 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005670 config: Config{
5671 MaxVersion: ver.version,
5672 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5673 SignSignatureAlgorithms: []signatureAlgorithm{
5674 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005675 },
David Benjamin7a41d372016-07-09 11:21:54 -07005676 Bugs: ProtocolBugs{
5677 SkipECDSACurveCheck: shouldFail,
5678 IgnoreSignatureVersionChecks: shouldFail,
5679 // The client won't advertise 1.3-only algorithms after
5680 // version negotiation.
5681 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005682 },
David Benjamin7a41d372016-07-09 11:21:54 -07005683 },
5684 flags: []string{
5685 "-require-any-client-certificate",
5686 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5687 "-enable-all-curves",
5688 },
5689 shouldFail: shouldFail,
5690 expectedError: verifyError,
5691 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005692
5693 testCases = append(testCases, testCase{
5694 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005695 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005696 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005697 MaxVersion: ver.version,
5698 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005699 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005700 fakeSigAlg1,
5701 alg.id,
5702 fakeSigAlg2,
5703 },
5704 },
5705 flags: []string{
5706 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5707 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5708 "-enable-all-curves",
5709 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005710 shouldFail: shouldFail,
5711 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005712 expectedPeerSignatureAlgorithm: alg.id,
5713 })
5714
5715 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005716 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005717 config: Config{
5718 MaxVersion: ver.version,
5719 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005720 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005721 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005722 alg.id,
5723 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005724 Bugs: ProtocolBugs{
5725 SkipECDSACurveCheck: shouldFail,
5726 IgnoreSignatureVersionChecks: shouldFail,
5727 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005728 },
5729 flags: []string{
5730 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5731 "-enable-all-curves",
5732 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005733 shouldFail: shouldFail,
5734 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005735 })
David Benjamin5208fd42016-07-13 21:43:25 -04005736
5737 if !shouldFail {
5738 testCases = append(testCases, testCase{
5739 testType: serverTest,
5740 name: "ClientAuth-InvalidSignature" + suffix,
5741 config: Config{
5742 MaxVersion: ver.version,
5743 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5744 SignSignatureAlgorithms: []signatureAlgorithm{
5745 alg.id,
5746 },
5747 Bugs: ProtocolBugs{
5748 InvalidSignature: true,
5749 },
5750 },
5751 flags: []string{
5752 "-require-any-client-certificate",
5753 "-enable-all-curves",
5754 },
5755 shouldFail: true,
5756 expectedError: ":BAD_SIGNATURE:",
5757 })
5758
5759 testCases = append(testCases, testCase{
5760 name: "ServerAuth-InvalidSignature" + suffix,
5761 config: Config{
5762 MaxVersion: ver.version,
5763 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5764 CipherSuites: signingCiphers,
5765 SignSignatureAlgorithms: []signatureAlgorithm{
5766 alg.id,
5767 },
5768 Bugs: ProtocolBugs{
5769 InvalidSignature: true,
5770 },
5771 },
5772 flags: []string{"-enable-all-curves"},
5773 shouldFail: true,
5774 expectedError: ":BAD_SIGNATURE:",
5775 })
5776 }
David Benjaminca3d5452016-07-14 12:51:01 -04005777
5778 if ver.version >= VersionTLS12 && !shouldFail {
5779 testCases = append(testCases, testCase{
5780 name: "ClientAuth-Sign-Negotiate" + suffix,
5781 config: Config{
5782 MaxVersion: ver.version,
5783 ClientAuth: RequireAnyClientCert,
5784 VerifySignatureAlgorithms: allAlgorithms,
5785 },
5786 flags: []string{
5787 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5788 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5789 "-enable-all-curves",
5790 "-signing-prefs", strconv.Itoa(int(alg.id)),
5791 },
5792 expectedPeerSignatureAlgorithm: alg.id,
5793 })
5794
5795 testCases = append(testCases, testCase{
5796 testType: serverTest,
5797 name: "ServerAuth-Sign-Negotiate" + suffix,
5798 config: Config{
5799 MaxVersion: ver.version,
5800 CipherSuites: signingCiphers,
5801 VerifySignatureAlgorithms: allAlgorithms,
5802 },
5803 flags: []string{
5804 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5805 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5806 "-enable-all-curves",
5807 "-signing-prefs", strconv.Itoa(int(alg.id)),
5808 },
5809 expectedPeerSignatureAlgorithm: alg.id,
5810 })
5811 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005812 }
David Benjamin000800a2014-11-14 01:43:59 -05005813 }
5814
Nick Harper60edffd2016-06-21 15:19:24 -07005815 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005816 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005817 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005818 config: Config{
5819 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005820 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005821 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005822 signatureECDSAWithP521AndSHA512,
5823 signatureRSAPKCS1WithSHA384,
5824 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005825 },
5826 },
5827 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005828 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5829 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005830 },
Nick Harper60edffd2016-06-21 15:19:24 -07005831 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005832 })
5833
5834 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005835 name: "ClientAuth-SignatureType-TLS13",
5836 config: Config{
5837 ClientAuth: RequireAnyClientCert,
5838 MaxVersion: VersionTLS13,
5839 VerifySignatureAlgorithms: []signatureAlgorithm{
5840 signatureECDSAWithP521AndSHA512,
5841 signatureRSAPKCS1WithSHA384,
5842 signatureRSAPSSWithSHA384,
5843 signatureECDSAWithSHA1,
5844 },
5845 },
5846 flags: []string{
5847 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5848 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5849 },
5850 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5851 })
5852
5853 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005854 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005855 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005856 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005857 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005858 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005859 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005860 signatureECDSAWithP521AndSHA512,
5861 signatureRSAPKCS1WithSHA384,
5862 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005863 },
5864 },
Nick Harper60edffd2016-06-21 15:19:24 -07005865 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005866 })
5867
Steven Valdez143e8b32016-07-11 13:19:03 -04005868 testCases = append(testCases, testCase{
5869 testType: serverTest,
5870 name: "ServerAuth-SignatureType-TLS13",
5871 config: Config{
5872 MaxVersion: VersionTLS13,
5873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5874 VerifySignatureAlgorithms: []signatureAlgorithm{
5875 signatureECDSAWithP521AndSHA512,
5876 signatureRSAPKCS1WithSHA384,
5877 signatureRSAPSSWithSHA384,
5878 signatureECDSAWithSHA1,
5879 },
5880 },
5881 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5882 })
5883
David Benjamina95e9f32016-07-08 16:28:04 -07005884 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005885 testCases = append(testCases, testCase{
5886 testType: serverTest,
5887 name: "Verify-ClientAuth-SignatureType",
5888 config: Config{
5889 MaxVersion: VersionTLS12,
5890 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005891 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005892 signatureRSAPKCS1WithSHA256,
5893 },
5894 Bugs: ProtocolBugs{
5895 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5896 },
5897 },
5898 flags: []string{
5899 "-require-any-client-certificate",
5900 },
5901 shouldFail: true,
5902 expectedError: ":WRONG_SIGNATURE_TYPE:",
5903 })
5904
5905 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005906 testType: serverTest,
5907 name: "Verify-ClientAuth-SignatureType-TLS13",
5908 config: Config{
5909 MaxVersion: VersionTLS13,
5910 Certificates: []Certificate{rsaCertificate},
5911 SignSignatureAlgorithms: []signatureAlgorithm{
5912 signatureRSAPSSWithSHA256,
5913 },
5914 Bugs: ProtocolBugs{
5915 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5916 },
5917 },
5918 flags: []string{
5919 "-require-any-client-certificate",
5920 },
5921 shouldFail: true,
5922 expectedError: ":WRONG_SIGNATURE_TYPE:",
5923 })
5924
5925 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005926 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005927 config: Config{
5928 MaxVersion: VersionTLS12,
5929 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005930 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005931 signatureRSAPKCS1WithSHA256,
5932 },
5933 Bugs: ProtocolBugs{
5934 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5935 },
5936 },
5937 shouldFail: true,
5938 expectedError: ":WRONG_SIGNATURE_TYPE:",
5939 })
5940
Steven Valdez143e8b32016-07-11 13:19:03 -04005941 testCases = append(testCases, testCase{
5942 name: "Verify-ServerAuth-SignatureType-TLS13",
5943 config: Config{
5944 MaxVersion: VersionTLS13,
5945 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5946 SignSignatureAlgorithms: []signatureAlgorithm{
5947 signatureRSAPSSWithSHA256,
5948 },
5949 Bugs: ProtocolBugs{
5950 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5951 },
5952 },
5953 shouldFail: true,
5954 expectedError: ":WRONG_SIGNATURE_TYPE:",
5955 })
5956
David Benjamin51dd7d62016-07-08 16:07:01 -07005957 // Test that, if the list is missing, the peer falls back to SHA-1 in
5958 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005959 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005960 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005962 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005963 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005964 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005965 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005966 },
5967 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005968 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005969 },
5970 },
5971 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005972 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5973 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005974 },
5975 })
5976
5977 testCases = append(testCases, testCase{
5978 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005979 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005980 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005981 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005982 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005983 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005984 },
5985 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005986 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005987 },
5988 },
David Benjaminee32bea2016-08-17 13:36:44 -04005989 flags: []string{
5990 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5991 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5992 },
5993 })
5994
5995 testCases = append(testCases, testCase{
5996 name: "ClientAuth-SHA1-Fallback-ECDSA",
5997 config: Config{
5998 MaxVersion: VersionTLS12,
5999 ClientAuth: RequireAnyClientCert,
6000 VerifySignatureAlgorithms: []signatureAlgorithm{
6001 signatureECDSAWithSHA1,
6002 },
6003 Bugs: ProtocolBugs{
6004 NoSignatureAlgorithms: true,
6005 },
6006 },
6007 flags: []string{
6008 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6009 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6010 },
6011 })
6012
6013 testCases = append(testCases, testCase{
6014 testType: serverTest,
6015 name: "ServerAuth-SHA1-Fallback-ECDSA",
6016 config: Config{
6017 MaxVersion: VersionTLS12,
6018 VerifySignatureAlgorithms: []signatureAlgorithm{
6019 signatureECDSAWithSHA1,
6020 },
6021 Bugs: ProtocolBugs{
6022 NoSignatureAlgorithms: true,
6023 },
6024 },
6025 flags: []string{
6026 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6027 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6028 },
David Benjamin000800a2014-11-14 01:43:59 -05006029 })
David Benjamin72dc7832015-03-16 17:49:43 -04006030
David Benjamin51dd7d62016-07-08 16:07:01 -07006031 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006032 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006033 config: Config{
6034 MaxVersion: VersionTLS13,
6035 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006036 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006037 signatureRSAPKCS1WithSHA1,
6038 },
6039 Bugs: ProtocolBugs{
6040 NoSignatureAlgorithms: true,
6041 },
6042 },
6043 flags: []string{
6044 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6045 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6046 },
David Benjamin48901652016-08-01 12:12:47 -04006047 shouldFail: true,
6048 // An empty CertificateRequest signature algorithm list is a
6049 // syntax error in TLS 1.3.
6050 expectedError: ":DECODE_ERROR:",
6051 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006052 })
6053
6054 testCases = append(testCases, testCase{
6055 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006056 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006057 config: Config{
6058 MaxVersion: VersionTLS13,
6059 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006060 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006061 signatureRSAPKCS1WithSHA1,
6062 },
6063 Bugs: ProtocolBugs{
6064 NoSignatureAlgorithms: true,
6065 },
6066 },
6067 shouldFail: true,
6068 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6069 })
6070
David Benjaminb62d2872016-07-18 14:55:02 +02006071 // Test that hash preferences are enforced. BoringSSL does not implement
6072 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006073 testCases = append(testCases, testCase{
6074 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006075 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006077 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006078 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006079 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006080 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006081 },
6082 Bugs: ProtocolBugs{
6083 IgnorePeerSignatureAlgorithmPreferences: true,
6084 },
6085 },
6086 flags: []string{"-require-any-client-certificate"},
6087 shouldFail: true,
6088 expectedError: ":WRONG_SIGNATURE_TYPE:",
6089 })
6090
6091 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006092 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006094 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006095 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006096 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006097 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006098 },
6099 Bugs: ProtocolBugs{
6100 IgnorePeerSignatureAlgorithmPreferences: true,
6101 },
6102 },
6103 shouldFail: true,
6104 expectedError: ":WRONG_SIGNATURE_TYPE:",
6105 })
David Benjaminb62d2872016-07-18 14:55:02 +02006106 testCases = append(testCases, testCase{
6107 testType: serverTest,
6108 name: "ClientAuth-Enforced-TLS13",
6109 config: Config{
6110 MaxVersion: VersionTLS13,
6111 Certificates: []Certificate{rsaCertificate},
6112 SignSignatureAlgorithms: []signatureAlgorithm{
6113 signatureRSAPKCS1WithMD5,
6114 },
6115 Bugs: ProtocolBugs{
6116 IgnorePeerSignatureAlgorithmPreferences: true,
6117 IgnoreSignatureVersionChecks: true,
6118 },
6119 },
6120 flags: []string{"-require-any-client-certificate"},
6121 shouldFail: true,
6122 expectedError: ":WRONG_SIGNATURE_TYPE:",
6123 })
6124
6125 testCases = append(testCases, testCase{
6126 name: "ServerAuth-Enforced-TLS13",
6127 config: Config{
6128 MaxVersion: VersionTLS13,
6129 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6130 SignSignatureAlgorithms: []signatureAlgorithm{
6131 signatureRSAPKCS1WithMD5,
6132 },
6133 Bugs: ProtocolBugs{
6134 IgnorePeerSignatureAlgorithmPreferences: true,
6135 IgnoreSignatureVersionChecks: true,
6136 },
6137 },
6138 shouldFail: true,
6139 expectedError: ":WRONG_SIGNATURE_TYPE:",
6140 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006141
6142 // Test that the agreed upon digest respects the client preferences and
6143 // the server digests.
6144 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006145 name: "NoCommonAlgorithms-Digests",
6146 config: Config{
6147 MaxVersion: VersionTLS12,
6148 ClientAuth: RequireAnyClientCert,
6149 VerifySignatureAlgorithms: []signatureAlgorithm{
6150 signatureRSAPKCS1WithSHA512,
6151 signatureRSAPKCS1WithSHA1,
6152 },
6153 },
6154 flags: []string{
6155 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6156 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6157 "-digest-prefs", "SHA256",
6158 },
6159 shouldFail: true,
6160 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6161 })
6162 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006163 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006165 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006166 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006167 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006168 signatureRSAPKCS1WithSHA512,
6169 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006170 },
6171 },
6172 flags: []string{
6173 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6174 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006175 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006176 },
David Benjaminca3d5452016-07-14 12:51:01 -04006177 shouldFail: true,
6178 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6179 })
6180 testCases = append(testCases, testCase{
6181 name: "NoCommonAlgorithms-TLS13",
6182 config: Config{
6183 MaxVersion: VersionTLS13,
6184 ClientAuth: RequireAnyClientCert,
6185 VerifySignatureAlgorithms: []signatureAlgorithm{
6186 signatureRSAPSSWithSHA512,
6187 signatureRSAPSSWithSHA384,
6188 },
6189 },
6190 flags: []string{
6191 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6192 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6193 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6194 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006195 shouldFail: true,
6196 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006197 })
6198 testCases = append(testCases, testCase{
6199 name: "Agree-Digest-SHA256",
6200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006201 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006202 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006203 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006204 signatureRSAPKCS1WithSHA1,
6205 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006206 },
6207 },
6208 flags: []string{
6209 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6210 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006211 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006212 },
Nick Harper60edffd2016-06-21 15:19:24 -07006213 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006214 })
6215 testCases = append(testCases, testCase{
6216 name: "Agree-Digest-SHA1",
6217 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006218 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006219 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006220 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006221 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006222 },
6223 },
6224 flags: []string{
6225 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6226 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006227 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006228 },
Nick Harper60edffd2016-06-21 15:19:24 -07006229 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006230 })
6231 testCases = append(testCases, testCase{
6232 name: "Agree-Digest-Default",
6233 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006234 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006235 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006236 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006237 signatureRSAPKCS1WithSHA256,
6238 signatureECDSAWithP256AndSHA256,
6239 signatureRSAPKCS1WithSHA1,
6240 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006241 },
6242 },
6243 flags: []string{
6244 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6245 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6246 },
Nick Harper60edffd2016-06-21 15:19:24 -07006247 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006248 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006249
David Benjaminca3d5452016-07-14 12:51:01 -04006250 // Test that the signing preference list may include extra algorithms
6251 // without negotiation problems.
6252 testCases = append(testCases, testCase{
6253 testType: serverTest,
6254 name: "FilterExtraAlgorithms",
6255 config: Config{
6256 MaxVersion: VersionTLS12,
6257 VerifySignatureAlgorithms: []signatureAlgorithm{
6258 signatureRSAPKCS1WithSHA256,
6259 },
6260 },
6261 flags: []string{
6262 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6263 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6264 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6265 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6266 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6267 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6268 },
6269 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6270 })
6271
David Benjamin4c3ddf72016-06-29 18:13:53 -04006272 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6273 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006274 testCases = append(testCases, testCase{
6275 name: "CheckLeafCurve",
6276 config: Config{
6277 MaxVersion: VersionTLS12,
6278 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006279 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006280 },
6281 flags: []string{"-p384-only"},
6282 shouldFail: true,
6283 expectedError: ":BAD_ECC_CERT:",
6284 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006285
6286 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6287 testCases = append(testCases, testCase{
6288 name: "CheckLeafCurve-TLS13",
6289 config: Config{
6290 MaxVersion: VersionTLS13,
6291 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6292 Certificates: []Certificate{ecdsaP256Certificate},
6293 },
6294 flags: []string{"-p384-only"},
6295 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006296
6297 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6298 testCases = append(testCases, testCase{
6299 name: "ECDSACurveMismatch-Verify-TLS12",
6300 config: Config{
6301 MaxVersion: VersionTLS12,
6302 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6303 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006304 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006305 signatureECDSAWithP384AndSHA384,
6306 },
6307 },
6308 })
6309
6310 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6311 testCases = append(testCases, testCase{
6312 name: "ECDSACurveMismatch-Verify-TLS13",
6313 config: Config{
6314 MaxVersion: VersionTLS13,
6315 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6316 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006317 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006318 signatureECDSAWithP384AndSHA384,
6319 },
6320 Bugs: ProtocolBugs{
6321 SkipECDSACurveCheck: true,
6322 },
6323 },
6324 shouldFail: true,
6325 expectedError: ":WRONG_SIGNATURE_TYPE:",
6326 })
6327
6328 // Signature algorithm selection in TLS 1.3 should take the curve into
6329 // account.
6330 testCases = append(testCases, testCase{
6331 testType: serverTest,
6332 name: "ECDSACurveMismatch-Sign-TLS13",
6333 config: Config{
6334 MaxVersion: VersionTLS13,
6335 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006336 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006337 signatureECDSAWithP384AndSHA384,
6338 signatureECDSAWithP256AndSHA256,
6339 },
6340 },
6341 flags: []string{
6342 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6343 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6344 },
6345 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6346 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006347
6348 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6349 // server does not attempt to sign in that case.
6350 testCases = append(testCases, testCase{
6351 testType: serverTest,
6352 name: "RSA-PSS-Large",
6353 config: Config{
6354 MaxVersion: VersionTLS13,
6355 VerifySignatureAlgorithms: []signatureAlgorithm{
6356 signatureRSAPSSWithSHA512,
6357 },
6358 },
6359 flags: []string{
6360 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6361 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6362 },
6363 shouldFail: true,
6364 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6365 })
David Benjamin57e929f2016-08-30 00:30:38 -04006366
6367 // Test that RSA-PSS is enabled by default for TLS 1.2.
6368 testCases = append(testCases, testCase{
6369 testType: clientTest,
6370 name: "RSA-PSS-Default-Verify",
6371 config: Config{
6372 MaxVersion: VersionTLS12,
6373 SignSignatureAlgorithms: []signatureAlgorithm{
6374 signatureRSAPSSWithSHA256,
6375 },
6376 },
6377 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6378 })
6379
6380 testCases = append(testCases, testCase{
6381 testType: serverTest,
6382 name: "RSA-PSS-Default-Sign",
6383 config: Config{
6384 MaxVersion: VersionTLS12,
6385 VerifySignatureAlgorithms: []signatureAlgorithm{
6386 signatureRSAPSSWithSHA256,
6387 },
6388 },
6389 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6390 })
David Benjamin000800a2014-11-14 01:43:59 -05006391}
6392
David Benjamin83f90402015-01-27 01:09:43 -05006393// timeouts is the retransmit schedule for BoringSSL. It doubles and
6394// caps at 60 seconds. On the 13th timeout, it gives up.
6395var timeouts = []time.Duration{
6396 1 * time.Second,
6397 2 * time.Second,
6398 4 * time.Second,
6399 8 * time.Second,
6400 16 * time.Second,
6401 32 * time.Second,
6402 60 * time.Second,
6403 60 * time.Second,
6404 60 * time.Second,
6405 60 * time.Second,
6406 60 * time.Second,
6407 60 * time.Second,
6408 60 * time.Second,
6409}
6410
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006411// shortTimeouts is an alternate set of timeouts which would occur if the
6412// initial timeout duration was set to 250ms.
6413var shortTimeouts = []time.Duration{
6414 250 * time.Millisecond,
6415 500 * time.Millisecond,
6416 1 * time.Second,
6417 2 * time.Second,
6418 4 * time.Second,
6419 8 * time.Second,
6420 16 * time.Second,
6421 32 * time.Second,
6422 60 * time.Second,
6423 60 * time.Second,
6424 60 * time.Second,
6425 60 * time.Second,
6426 60 * time.Second,
6427}
6428
David Benjamin83f90402015-01-27 01:09:43 -05006429func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006430 // These tests work by coordinating some behavior on both the shim and
6431 // the runner.
6432 //
6433 // TimeoutSchedule configures the runner to send a series of timeout
6434 // opcodes to the shim (see packetAdaptor) immediately before reading
6435 // each peer handshake flight N. The timeout opcode both simulates a
6436 // timeout in the shim and acts as a synchronization point to help the
6437 // runner bracket each handshake flight.
6438 //
6439 // We assume the shim does not read from the channel eagerly. It must
6440 // first wait until it has sent flight N and is ready to receive
6441 // handshake flight N+1. At this point, it will process the timeout
6442 // opcode. It must then immediately respond with a timeout ACK and act
6443 // as if the shim was idle for the specified amount of time.
6444 //
6445 // The runner then drops all packets received before the ACK and
6446 // continues waiting for flight N. This ordering results in one attempt
6447 // at sending flight N to be dropped. For the test to complete, the
6448 // shim must send flight N again, testing that the shim implements DTLS
6449 // retransmit on a timeout.
6450
Steven Valdez143e8b32016-07-11 13:19:03 -04006451 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006452 // likely be more epochs to cross and the final message's retransmit may
6453 // be more complex.
6454
David Benjamin585d7a42016-06-02 14:58:00 -04006455 for _, async := range []bool{true, false} {
6456 var tests []testCase
6457
6458 // Test that this is indeed the timeout schedule. Stress all
6459 // four patterns of handshake.
6460 for i := 1; i < len(timeouts); i++ {
6461 number := strconv.Itoa(i)
6462 tests = append(tests, testCase{
6463 protocol: dtls,
6464 name: "DTLS-Retransmit-Client-" + number,
6465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006466 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006467 Bugs: ProtocolBugs{
6468 TimeoutSchedule: timeouts[:i],
6469 },
6470 },
6471 resumeSession: true,
6472 })
6473 tests = append(tests, testCase{
6474 protocol: dtls,
6475 testType: serverTest,
6476 name: "DTLS-Retransmit-Server-" + number,
6477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006478 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006479 Bugs: ProtocolBugs{
6480 TimeoutSchedule: timeouts[:i],
6481 },
6482 },
6483 resumeSession: true,
6484 })
6485 }
6486
6487 // Test that exceeding the timeout schedule hits a read
6488 // timeout.
6489 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006490 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006491 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006492 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006493 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006494 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006495 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006496 },
6497 },
6498 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006499 shouldFail: true,
6500 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006501 })
David Benjamin585d7a42016-06-02 14:58:00 -04006502
6503 if async {
6504 // Test that timeout handling has a fudge factor, due to API
6505 // problems.
6506 tests = append(tests, testCase{
6507 protocol: dtls,
6508 name: "DTLS-Retransmit-Fudge",
6509 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006510 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006511 Bugs: ProtocolBugs{
6512 TimeoutSchedule: []time.Duration{
6513 timeouts[0] - 10*time.Millisecond,
6514 },
6515 },
6516 },
6517 resumeSession: true,
6518 })
6519 }
6520
6521 // Test that the final Finished retransmitting isn't
6522 // duplicated if the peer badly fragments everything.
6523 tests = append(tests, testCase{
6524 testType: serverTest,
6525 protocol: dtls,
6526 name: "DTLS-Retransmit-Fragmented",
6527 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006528 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006529 Bugs: ProtocolBugs{
6530 TimeoutSchedule: []time.Duration{timeouts[0]},
6531 MaxHandshakeRecordLength: 2,
6532 },
6533 },
6534 })
6535
6536 // Test the timeout schedule when a shorter initial timeout duration is set.
6537 tests = append(tests, testCase{
6538 protocol: dtls,
6539 name: "DTLS-Retransmit-Short-Client",
6540 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006541 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006542 Bugs: ProtocolBugs{
6543 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6544 },
6545 },
6546 resumeSession: true,
6547 flags: []string{"-initial-timeout-duration-ms", "250"},
6548 })
6549 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006550 protocol: dtls,
6551 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006552 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006554 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006555 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006556 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006557 },
6558 },
6559 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006560 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006561 })
David Benjamin585d7a42016-06-02 14:58:00 -04006562
6563 for _, test := range tests {
6564 if async {
6565 test.name += "-Async"
6566 test.flags = append(test.flags, "-async")
6567 }
6568
6569 testCases = append(testCases, test)
6570 }
David Benjamin83f90402015-01-27 01:09:43 -05006571 }
David Benjamin83f90402015-01-27 01:09:43 -05006572}
6573
David Benjaminc565ebb2015-04-03 04:06:36 -04006574func addExportKeyingMaterialTests() {
6575 for _, vers := range tlsVersions {
6576 if vers.version == VersionSSL30 {
6577 continue
6578 }
6579 testCases = append(testCases, testCase{
6580 name: "ExportKeyingMaterial-" + vers.name,
6581 config: Config{
6582 MaxVersion: vers.version,
6583 },
6584 exportKeyingMaterial: 1024,
6585 exportLabel: "label",
6586 exportContext: "context",
6587 useExportContext: true,
6588 })
6589 testCases = append(testCases, testCase{
6590 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6591 config: Config{
6592 MaxVersion: vers.version,
6593 },
6594 exportKeyingMaterial: 1024,
6595 })
6596 testCases = append(testCases, testCase{
6597 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6598 config: Config{
6599 MaxVersion: vers.version,
6600 },
6601 exportKeyingMaterial: 1024,
6602 useExportContext: true,
6603 })
6604 testCases = append(testCases, testCase{
6605 name: "ExportKeyingMaterial-Small-" + vers.name,
6606 config: Config{
6607 MaxVersion: vers.version,
6608 },
6609 exportKeyingMaterial: 1,
6610 exportLabel: "label",
6611 exportContext: "context",
6612 useExportContext: true,
6613 })
6614 }
6615 testCases = append(testCases, testCase{
6616 name: "ExportKeyingMaterial-SSL3",
6617 config: Config{
6618 MaxVersion: VersionSSL30,
6619 },
6620 exportKeyingMaterial: 1024,
6621 exportLabel: "label",
6622 exportContext: "context",
6623 useExportContext: true,
6624 shouldFail: true,
6625 expectedError: "failed to export keying material",
6626 })
6627}
6628
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006629func addTLSUniqueTests() {
6630 for _, isClient := range []bool{false, true} {
6631 for _, isResumption := range []bool{false, true} {
6632 for _, hasEMS := range []bool{false, true} {
6633 var suffix string
6634 if isResumption {
6635 suffix = "Resume-"
6636 } else {
6637 suffix = "Full-"
6638 }
6639
6640 if hasEMS {
6641 suffix += "EMS-"
6642 } else {
6643 suffix += "NoEMS-"
6644 }
6645
6646 if isClient {
6647 suffix += "Client"
6648 } else {
6649 suffix += "Server"
6650 }
6651
6652 test := testCase{
6653 name: "TLSUnique-" + suffix,
6654 testTLSUnique: true,
6655 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006656 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006657 Bugs: ProtocolBugs{
6658 NoExtendedMasterSecret: !hasEMS,
6659 },
6660 },
6661 }
6662
6663 if isResumption {
6664 test.resumeSession = true
6665 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006666 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006667 Bugs: ProtocolBugs{
6668 NoExtendedMasterSecret: !hasEMS,
6669 },
6670 }
6671 }
6672
6673 if isResumption && !hasEMS {
6674 test.shouldFail = true
6675 test.expectedError = "failed to get tls-unique"
6676 }
6677
6678 testCases = append(testCases, test)
6679 }
6680 }
6681 }
6682}
6683
Adam Langley09505632015-07-30 18:10:13 -07006684func addCustomExtensionTests() {
6685 expectedContents := "custom extension"
6686 emptyString := ""
6687
6688 for _, isClient := range []bool{false, true} {
6689 suffix := "Server"
6690 flag := "-enable-server-custom-extension"
6691 testType := serverTest
6692 if isClient {
6693 suffix = "Client"
6694 flag = "-enable-client-custom-extension"
6695 testType = clientTest
6696 }
6697
6698 testCases = append(testCases, testCase{
6699 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006700 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006701 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006702 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006703 Bugs: ProtocolBugs{
6704 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006705 ExpectedCustomExtension: &expectedContents,
6706 },
6707 },
6708 flags: []string{flag},
6709 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006710 testCases = append(testCases, testCase{
6711 testType: testType,
6712 name: "CustomExtensions-" + suffix + "-TLS13",
6713 config: Config{
6714 MaxVersion: VersionTLS13,
6715 Bugs: ProtocolBugs{
6716 CustomExtension: expectedContents,
6717 ExpectedCustomExtension: &expectedContents,
6718 },
6719 },
6720 flags: []string{flag},
6721 })
Adam Langley09505632015-07-30 18:10:13 -07006722
6723 // If the parse callback fails, the handshake should also fail.
6724 testCases = append(testCases, testCase{
6725 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006726 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006728 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006729 Bugs: ProtocolBugs{
6730 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006731 ExpectedCustomExtension: &expectedContents,
6732 },
6733 },
David Benjamin399e7c92015-07-30 23:01:27 -04006734 flags: []string{flag},
6735 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006736 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6737 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006738 testCases = append(testCases, testCase{
6739 testType: testType,
6740 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6741 config: Config{
6742 MaxVersion: VersionTLS13,
6743 Bugs: ProtocolBugs{
6744 CustomExtension: expectedContents + "foo",
6745 ExpectedCustomExtension: &expectedContents,
6746 },
6747 },
6748 flags: []string{flag},
6749 shouldFail: true,
6750 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6751 })
Adam Langley09505632015-07-30 18:10:13 -07006752
6753 // If the add callback fails, the handshake should also fail.
6754 testCases = append(testCases, testCase{
6755 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006756 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006757 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006758 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006759 Bugs: ProtocolBugs{
6760 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006761 ExpectedCustomExtension: &expectedContents,
6762 },
6763 },
David Benjamin399e7c92015-07-30 23:01:27 -04006764 flags: []string{flag, "-custom-extension-fail-add"},
6765 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006766 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6767 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006768 testCases = append(testCases, testCase{
6769 testType: testType,
6770 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6771 config: Config{
6772 MaxVersion: VersionTLS13,
6773 Bugs: ProtocolBugs{
6774 CustomExtension: expectedContents,
6775 ExpectedCustomExtension: &expectedContents,
6776 },
6777 },
6778 flags: []string{flag, "-custom-extension-fail-add"},
6779 shouldFail: true,
6780 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6781 })
Adam Langley09505632015-07-30 18:10:13 -07006782
6783 // If the add callback returns zero, no extension should be
6784 // added.
6785 skipCustomExtension := expectedContents
6786 if isClient {
6787 // For the case where the client skips sending the
6788 // custom extension, the server must not “echo” it.
6789 skipCustomExtension = ""
6790 }
6791 testCases = append(testCases, testCase{
6792 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006793 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006795 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006796 Bugs: ProtocolBugs{
6797 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006798 ExpectedCustomExtension: &emptyString,
6799 },
6800 },
6801 flags: []string{flag, "-custom-extension-skip"},
6802 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006803 testCases = append(testCases, testCase{
6804 testType: testType,
6805 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6806 config: Config{
6807 MaxVersion: VersionTLS13,
6808 Bugs: ProtocolBugs{
6809 CustomExtension: skipCustomExtension,
6810 ExpectedCustomExtension: &emptyString,
6811 },
6812 },
6813 flags: []string{flag, "-custom-extension-skip"},
6814 })
Adam Langley09505632015-07-30 18:10:13 -07006815 }
6816
6817 // The custom extension add callback should not be called if the client
6818 // doesn't send the extension.
6819 testCases = append(testCases, testCase{
6820 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006821 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006822 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006823 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006824 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006825 ExpectedCustomExtension: &emptyString,
6826 },
6827 },
6828 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6829 })
Adam Langley2deb9842015-08-07 11:15:37 -07006830
Steven Valdez143e8b32016-07-11 13:19:03 -04006831 testCases = append(testCases, testCase{
6832 testType: serverTest,
6833 name: "CustomExtensions-NotCalled-Server-TLS13",
6834 config: Config{
6835 MaxVersion: VersionTLS13,
6836 Bugs: ProtocolBugs{
6837 ExpectedCustomExtension: &emptyString,
6838 },
6839 },
6840 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6841 })
6842
Adam Langley2deb9842015-08-07 11:15:37 -07006843 // Test an unknown extension from the server.
6844 testCases = append(testCases, testCase{
6845 testType: clientTest,
6846 name: "UnknownExtension-Client",
6847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006848 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006849 Bugs: ProtocolBugs{
6850 CustomExtension: expectedContents,
6851 },
6852 },
David Benjamin0c40a962016-08-01 12:05:50 -04006853 shouldFail: true,
6854 expectedError: ":UNEXPECTED_EXTENSION:",
6855 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006856 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006857 testCases = append(testCases, testCase{
6858 testType: clientTest,
6859 name: "UnknownExtension-Client-TLS13",
6860 config: Config{
6861 MaxVersion: VersionTLS13,
6862 Bugs: ProtocolBugs{
6863 CustomExtension: expectedContents,
6864 },
6865 },
David Benjamin0c40a962016-08-01 12:05:50 -04006866 shouldFail: true,
6867 expectedError: ":UNEXPECTED_EXTENSION:",
6868 expectedLocalError: "remote error: unsupported extension",
6869 })
6870
6871 // Test a known but unoffered extension from the server.
6872 testCases = append(testCases, testCase{
6873 testType: clientTest,
6874 name: "UnofferedExtension-Client",
6875 config: Config{
6876 MaxVersion: VersionTLS12,
6877 Bugs: ProtocolBugs{
6878 SendALPN: "alpn",
6879 },
6880 },
6881 shouldFail: true,
6882 expectedError: ":UNEXPECTED_EXTENSION:",
6883 expectedLocalError: "remote error: unsupported extension",
6884 })
6885 testCases = append(testCases, testCase{
6886 testType: clientTest,
6887 name: "UnofferedExtension-Client-TLS13",
6888 config: Config{
6889 MaxVersion: VersionTLS13,
6890 Bugs: ProtocolBugs{
6891 SendALPN: "alpn",
6892 },
6893 },
6894 shouldFail: true,
6895 expectedError: ":UNEXPECTED_EXTENSION:",
6896 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006897 })
Adam Langley09505632015-07-30 18:10:13 -07006898}
6899
David Benjaminb36a3952015-12-01 18:53:13 -05006900func addRSAClientKeyExchangeTests() {
6901 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6902 testCases = append(testCases, testCase{
6903 testType: serverTest,
6904 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6905 config: Config{
6906 // Ensure the ClientHello version and final
6907 // version are different, to detect if the
6908 // server uses the wrong one.
6909 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006910 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006911 Bugs: ProtocolBugs{
6912 BadRSAClientKeyExchange: bad,
6913 },
6914 },
6915 shouldFail: true,
6916 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6917 })
6918 }
6919}
6920
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006921var testCurves = []struct {
6922 name string
6923 id CurveID
6924}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006925 {"P-256", CurveP256},
6926 {"P-384", CurveP384},
6927 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006928 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006929}
6930
Steven Valdez5440fe02016-07-18 12:40:30 -04006931const bogusCurve = 0x1234
6932
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006933func addCurveTests() {
6934 for _, curve := range testCurves {
6935 testCases = append(testCases, testCase{
6936 name: "CurveTest-Client-" + curve.name,
6937 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006938 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6940 CurvePreferences: []CurveID{curve.id},
6941 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006942 flags: []string{
6943 "-enable-all-curves",
6944 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6945 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006946 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006947 })
6948 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006949 name: "CurveTest-Client-" + curve.name + "-TLS13",
6950 config: Config{
6951 MaxVersion: VersionTLS13,
6952 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6953 CurvePreferences: []CurveID{curve.id},
6954 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006955 flags: []string{
6956 "-enable-all-curves",
6957 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6958 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006959 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006960 })
6961 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006962 testType: serverTest,
6963 name: "CurveTest-Server-" + curve.name,
6964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006965 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6967 CurvePreferences: []CurveID{curve.id},
6968 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006969 flags: []string{
6970 "-enable-all-curves",
6971 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6972 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006973 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006974 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006975 testCases = append(testCases, testCase{
6976 testType: serverTest,
6977 name: "CurveTest-Server-" + curve.name + "-TLS13",
6978 config: Config{
6979 MaxVersion: VersionTLS13,
6980 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6981 CurvePreferences: []CurveID{curve.id},
6982 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006983 flags: []string{
6984 "-enable-all-curves",
6985 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6986 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006987 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006988 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006989 }
David Benjamin241ae832016-01-15 03:04:54 -05006990
6991 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006992 testCases = append(testCases, testCase{
6993 testType: serverTest,
6994 name: "UnknownCurve",
6995 config: Config{
6996 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6997 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6998 },
6999 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007000
7001 // The server must not consider ECDHE ciphers when there are no
7002 // supported curves.
7003 testCases = append(testCases, testCase{
7004 testType: serverTest,
7005 name: "NoSupportedCurves",
7006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007007 MaxVersion: VersionTLS12,
7008 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7009 Bugs: ProtocolBugs{
7010 NoSupportedCurves: true,
7011 },
7012 },
7013 shouldFail: true,
7014 expectedError: ":NO_SHARED_CIPHER:",
7015 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007016 testCases = append(testCases, testCase{
7017 testType: serverTest,
7018 name: "NoSupportedCurves-TLS13",
7019 config: Config{
7020 MaxVersion: VersionTLS13,
7021 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7022 Bugs: ProtocolBugs{
7023 NoSupportedCurves: true,
7024 },
7025 },
7026 shouldFail: true,
7027 expectedError: ":NO_SHARED_CIPHER:",
7028 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007029
7030 // The server must fall back to another cipher when there are no
7031 // supported curves.
7032 testCases = append(testCases, testCase{
7033 testType: serverTest,
7034 name: "NoCommonCurves",
7035 config: Config{
7036 MaxVersion: VersionTLS12,
7037 CipherSuites: []uint16{
7038 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7039 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7040 },
7041 CurvePreferences: []CurveID{CurveP224},
7042 },
7043 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7044 })
7045
7046 // The client must reject bogus curves and disabled curves.
7047 testCases = append(testCases, testCase{
7048 name: "BadECDHECurve",
7049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007050 MaxVersion: VersionTLS12,
7051 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7052 Bugs: ProtocolBugs{
7053 SendCurve: bogusCurve,
7054 },
7055 },
7056 shouldFail: true,
7057 expectedError: ":WRONG_CURVE:",
7058 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007059 testCases = append(testCases, testCase{
7060 name: "BadECDHECurve-TLS13",
7061 config: Config{
7062 MaxVersion: VersionTLS13,
7063 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7064 Bugs: ProtocolBugs{
7065 SendCurve: bogusCurve,
7066 },
7067 },
7068 shouldFail: true,
7069 expectedError: ":WRONG_CURVE:",
7070 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007071
7072 testCases = append(testCases, testCase{
7073 name: "UnsupportedCurve",
7074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007075 MaxVersion: VersionTLS12,
7076 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7077 CurvePreferences: []CurveID{CurveP256},
7078 Bugs: ProtocolBugs{
7079 IgnorePeerCurvePreferences: true,
7080 },
7081 },
7082 flags: []string{"-p384-only"},
7083 shouldFail: true,
7084 expectedError: ":WRONG_CURVE:",
7085 })
7086
David Benjamin4f921572016-07-17 14:20:10 +02007087 testCases = append(testCases, testCase{
7088 // TODO(davidben): Add a TLS 1.3 version where
7089 // HelloRetryRequest requests an unsupported curve.
7090 name: "UnsupportedCurve-ServerHello-TLS13",
7091 config: Config{
7092 MaxVersion: VersionTLS12,
7093 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7094 CurvePreferences: []CurveID{CurveP384},
7095 Bugs: ProtocolBugs{
7096 SendCurve: CurveP256,
7097 },
7098 },
7099 flags: []string{"-p384-only"},
7100 shouldFail: true,
7101 expectedError: ":WRONG_CURVE:",
7102 })
7103
David Benjamin4c3ddf72016-06-29 18:13:53 -04007104 // Test invalid curve points.
7105 testCases = append(testCases, testCase{
7106 name: "InvalidECDHPoint-Client",
7107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007108 MaxVersion: VersionTLS12,
7109 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7110 CurvePreferences: []CurveID{CurveP256},
7111 Bugs: ProtocolBugs{
7112 InvalidECDHPoint: true,
7113 },
7114 },
7115 shouldFail: true,
7116 expectedError: ":INVALID_ENCODING:",
7117 })
7118 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007119 name: "InvalidECDHPoint-Client-TLS13",
7120 config: Config{
7121 MaxVersion: VersionTLS13,
7122 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7123 CurvePreferences: []CurveID{CurveP256},
7124 Bugs: ProtocolBugs{
7125 InvalidECDHPoint: true,
7126 },
7127 },
7128 shouldFail: true,
7129 expectedError: ":INVALID_ENCODING:",
7130 })
7131 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007132 testType: serverTest,
7133 name: "InvalidECDHPoint-Server",
7134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007135 MaxVersion: VersionTLS12,
7136 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7137 CurvePreferences: []CurveID{CurveP256},
7138 Bugs: ProtocolBugs{
7139 InvalidECDHPoint: true,
7140 },
7141 },
7142 shouldFail: true,
7143 expectedError: ":INVALID_ENCODING:",
7144 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007145 testCases = append(testCases, testCase{
7146 testType: serverTest,
7147 name: "InvalidECDHPoint-Server-TLS13",
7148 config: Config{
7149 MaxVersion: VersionTLS13,
7150 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7151 CurvePreferences: []CurveID{CurveP256},
7152 Bugs: ProtocolBugs{
7153 InvalidECDHPoint: true,
7154 },
7155 },
7156 shouldFail: true,
7157 expectedError: ":INVALID_ENCODING:",
7158 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007159}
7160
Matt Braithwaite54217e42016-06-13 13:03:47 -07007161func addCECPQ1Tests() {
7162 testCases = append(testCases, testCase{
7163 testType: clientTest,
7164 name: "CECPQ1-Client-BadX25519Part",
7165 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007166 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007167 MinVersion: VersionTLS12,
7168 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7169 Bugs: ProtocolBugs{
7170 CECPQ1BadX25519Part: true,
7171 },
7172 },
7173 flags: []string{"-cipher", "kCECPQ1"},
7174 shouldFail: true,
7175 expectedLocalError: "local error: bad record MAC",
7176 })
7177 testCases = append(testCases, testCase{
7178 testType: clientTest,
7179 name: "CECPQ1-Client-BadNewhopePart",
7180 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007181 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007182 MinVersion: VersionTLS12,
7183 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7184 Bugs: ProtocolBugs{
7185 CECPQ1BadNewhopePart: true,
7186 },
7187 },
7188 flags: []string{"-cipher", "kCECPQ1"},
7189 shouldFail: true,
7190 expectedLocalError: "local error: bad record MAC",
7191 })
7192 testCases = append(testCases, testCase{
7193 testType: serverTest,
7194 name: "CECPQ1-Server-BadX25519Part",
7195 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007196 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007197 MinVersion: VersionTLS12,
7198 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7199 Bugs: ProtocolBugs{
7200 CECPQ1BadX25519Part: true,
7201 },
7202 },
7203 flags: []string{"-cipher", "kCECPQ1"},
7204 shouldFail: true,
7205 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7206 })
7207 testCases = append(testCases, testCase{
7208 testType: serverTest,
7209 name: "CECPQ1-Server-BadNewhopePart",
7210 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007211 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007212 MinVersion: VersionTLS12,
7213 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7214 Bugs: ProtocolBugs{
7215 CECPQ1BadNewhopePart: true,
7216 },
7217 },
7218 flags: []string{"-cipher", "kCECPQ1"},
7219 shouldFail: true,
7220 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7221 })
7222}
7223
David Benjamin5c4e8572016-08-19 17:44:53 -04007224func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007225 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007226 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007227 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007228 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007229 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7230 Bugs: ProtocolBugs{
7231 // This is a 1234-bit prime number, generated
7232 // with:
7233 // openssl gendh 1234 | openssl asn1parse -i
7234 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7235 },
7236 },
David Benjamin9e68f192016-06-30 14:55:33 -04007237 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007238 })
7239 testCases = append(testCases, testCase{
7240 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007241 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007242 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007243 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007244 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7245 },
7246 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007247 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007248 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007249}
7250
David Benjaminc9ae27c2016-06-24 22:56:37 -04007251func addTLS13RecordTests() {
7252 testCases = append(testCases, testCase{
7253 name: "TLS13-RecordPadding",
7254 config: Config{
7255 MaxVersion: VersionTLS13,
7256 MinVersion: VersionTLS13,
7257 Bugs: ProtocolBugs{
7258 RecordPadding: 10,
7259 },
7260 },
7261 })
7262
7263 testCases = append(testCases, testCase{
7264 name: "TLS13-EmptyRecords",
7265 config: Config{
7266 MaxVersion: VersionTLS13,
7267 MinVersion: VersionTLS13,
7268 Bugs: ProtocolBugs{
7269 OmitRecordContents: true,
7270 },
7271 },
7272 shouldFail: true,
7273 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7274 })
7275
7276 testCases = append(testCases, testCase{
7277 name: "TLS13-OnlyPadding",
7278 config: Config{
7279 MaxVersion: VersionTLS13,
7280 MinVersion: VersionTLS13,
7281 Bugs: ProtocolBugs{
7282 OmitRecordContents: true,
7283 RecordPadding: 10,
7284 },
7285 },
7286 shouldFail: true,
7287 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7288 })
7289
7290 testCases = append(testCases, testCase{
7291 name: "TLS13-WrongOuterRecord",
7292 config: Config{
7293 MaxVersion: VersionTLS13,
7294 MinVersion: VersionTLS13,
7295 Bugs: ProtocolBugs{
7296 OuterRecordType: recordTypeHandshake,
7297 },
7298 },
7299 shouldFail: true,
7300 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7301 })
7302}
7303
David Benjamin82261be2016-07-07 14:32:50 -07007304func addChangeCipherSpecTests() {
7305 // Test missing ChangeCipherSpecs.
7306 testCases = append(testCases, testCase{
7307 name: "SkipChangeCipherSpec-Client",
7308 config: Config{
7309 MaxVersion: VersionTLS12,
7310 Bugs: ProtocolBugs{
7311 SkipChangeCipherSpec: true,
7312 },
7313 },
7314 shouldFail: true,
7315 expectedError: ":UNEXPECTED_RECORD:",
7316 })
7317 testCases = append(testCases, testCase{
7318 testType: serverTest,
7319 name: "SkipChangeCipherSpec-Server",
7320 config: Config{
7321 MaxVersion: VersionTLS12,
7322 Bugs: ProtocolBugs{
7323 SkipChangeCipherSpec: true,
7324 },
7325 },
7326 shouldFail: true,
7327 expectedError: ":UNEXPECTED_RECORD:",
7328 })
7329 testCases = append(testCases, testCase{
7330 testType: serverTest,
7331 name: "SkipChangeCipherSpec-Server-NPN",
7332 config: Config{
7333 MaxVersion: VersionTLS12,
7334 NextProtos: []string{"bar"},
7335 Bugs: ProtocolBugs{
7336 SkipChangeCipherSpec: true,
7337 },
7338 },
7339 flags: []string{
7340 "-advertise-npn", "\x03foo\x03bar\x03baz",
7341 },
7342 shouldFail: true,
7343 expectedError: ":UNEXPECTED_RECORD:",
7344 })
7345
7346 // Test synchronization between the handshake and ChangeCipherSpec.
7347 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7348 // rejected. Test both with and without handshake packing to handle both
7349 // when the partial post-CCS message is in its own record and when it is
7350 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007351 for _, packed := range []bool{false, true} {
7352 var suffix string
7353 if packed {
7354 suffix = "-Packed"
7355 }
7356
7357 testCases = append(testCases, testCase{
7358 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7359 config: Config{
7360 MaxVersion: VersionTLS12,
7361 Bugs: ProtocolBugs{
7362 FragmentAcrossChangeCipherSpec: true,
7363 PackHandshakeFlight: packed,
7364 },
7365 },
7366 shouldFail: true,
7367 expectedError: ":UNEXPECTED_RECORD:",
7368 })
7369 testCases = append(testCases, testCase{
7370 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7371 config: Config{
7372 MaxVersion: VersionTLS12,
7373 },
7374 resumeSession: true,
7375 resumeConfig: &Config{
7376 MaxVersion: VersionTLS12,
7377 Bugs: ProtocolBugs{
7378 FragmentAcrossChangeCipherSpec: true,
7379 PackHandshakeFlight: packed,
7380 },
7381 },
7382 shouldFail: true,
7383 expectedError: ":UNEXPECTED_RECORD:",
7384 })
7385 testCases = append(testCases, testCase{
7386 testType: serverTest,
7387 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7388 config: Config{
7389 MaxVersion: VersionTLS12,
7390 Bugs: ProtocolBugs{
7391 FragmentAcrossChangeCipherSpec: true,
7392 PackHandshakeFlight: packed,
7393 },
7394 },
7395 shouldFail: true,
7396 expectedError: ":UNEXPECTED_RECORD:",
7397 })
7398 testCases = append(testCases, testCase{
7399 testType: serverTest,
7400 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7401 config: Config{
7402 MaxVersion: VersionTLS12,
7403 },
7404 resumeSession: true,
7405 resumeConfig: &Config{
7406 MaxVersion: VersionTLS12,
7407 Bugs: ProtocolBugs{
7408 FragmentAcrossChangeCipherSpec: true,
7409 PackHandshakeFlight: packed,
7410 },
7411 },
7412 shouldFail: true,
7413 expectedError: ":UNEXPECTED_RECORD:",
7414 })
7415 testCases = append(testCases, testCase{
7416 testType: serverTest,
7417 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7418 config: Config{
7419 MaxVersion: VersionTLS12,
7420 NextProtos: []string{"bar"},
7421 Bugs: ProtocolBugs{
7422 FragmentAcrossChangeCipherSpec: true,
7423 PackHandshakeFlight: packed,
7424 },
7425 },
7426 flags: []string{
7427 "-advertise-npn", "\x03foo\x03bar\x03baz",
7428 },
7429 shouldFail: true,
7430 expectedError: ":UNEXPECTED_RECORD:",
7431 })
7432 }
7433
David Benjamin61672812016-07-14 23:10:43 -04007434 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7435 // messages in the handshake queue. Do this by testing the server
7436 // reading the client Finished, reversing the flight so Finished comes
7437 // first.
7438 testCases = append(testCases, testCase{
7439 protocol: dtls,
7440 testType: serverTest,
7441 name: "SendUnencryptedFinished-DTLS",
7442 config: Config{
7443 MaxVersion: VersionTLS12,
7444 Bugs: ProtocolBugs{
7445 SendUnencryptedFinished: true,
7446 ReverseHandshakeFragments: true,
7447 },
7448 },
7449 shouldFail: true,
7450 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7451 })
7452
Steven Valdez143e8b32016-07-11 13:19:03 -04007453 // Test synchronization between encryption changes and the handshake in
7454 // TLS 1.3, where ChangeCipherSpec is implicit.
7455 testCases = append(testCases, testCase{
7456 name: "PartialEncryptedExtensionsWithServerHello",
7457 config: Config{
7458 MaxVersion: VersionTLS13,
7459 Bugs: ProtocolBugs{
7460 PartialEncryptedExtensionsWithServerHello: true,
7461 },
7462 },
7463 shouldFail: true,
7464 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7465 })
7466 testCases = append(testCases, testCase{
7467 testType: serverTest,
7468 name: "PartialClientFinishedWithClientHello",
7469 config: Config{
7470 MaxVersion: VersionTLS13,
7471 Bugs: ProtocolBugs{
7472 PartialClientFinishedWithClientHello: true,
7473 },
7474 },
7475 shouldFail: true,
7476 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7477 })
7478
David Benjamin82261be2016-07-07 14:32:50 -07007479 // Test that early ChangeCipherSpecs are handled correctly.
7480 testCases = append(testCases, testCase{
7481 testType: serverTest,
7482 name: "EarlyChangeCipherSpec-server-1",
7483 config: Config{
7484 MaxVersion: VersionTLS12,
7485 Bugs: ProtocolBugs{
7486 EarlyChangeCipherSpec: 1,
7487 },
7488 },
7489 shouldFail: true,
7490 expectedError: ":UNEXPECTED_RECORD:",
7491 })
7492 testCases = append(testCases, testCase{
7493 testType: serverTest,
7494 name: "EarlyChangeCipherSpec-server-2",
7495 config: Config{
7496 MaxVersion: VersionTLS12,
7497 Bugs: ProtocolBugs{
7498 EarlyChangeCipherSpec: 2,
7499 },
7500 },
7501 shouldFail: true,
7502 expectedError: ":UNEXPECTED_RECORD:",
7503 })
7504 testCases = append(testCases, testCase{
7505 protocol: dtls,
7506 name: "StrayChangeCipherSpec",
7507 config: Config{
7508 // TODO(davidben): Once DTLS 1.3 exists, test
7509 // that stray ChangeCipherSpec messages are
7510 // rejected.
7511 MaxVersion: VersionTLS12,
7512 Bugs: ProtocolBugs{
7513 StrayChangeCipherSpec: true,
7514 },
7515 },
7516 })
7517
7518 // Test that the contents of ChangeCipherSpec are checked.
7519 testCases = append(testCases, testCase{
7520 name: "BadChangeCipherSpec-1",
7521 config: Config{
7522 MaxVersion: VersionTLS12,
7523 Bugs: ProtocolBugs{
7524 BadChangeCipherSpec: []byte{2},
7525 },
7526 },
7527 shouldFail: true,
7528 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7529 })
7530 testCases = append(testCases, testCase{
7531 name: "BadChangeCipherSpec-2",
7532 config: Config{
7533 MaxVersion: VersionTLS12,
7534 Bugs: ProtocolBugs{
7535 BadChangeCipherSpec: []byte{1, 1},
7536 },
7537 },
7538 shouldFail: true,
7539 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7540 })
7541 testCases = append(testCases, testCase{
7542 protocol: dtls,
7543 name: "BadChangeCipherSpec-DTLS-1",
7544 config: Config{
7545 MaxVersion: VersionTLS12,
7546 Bugs: ProtocolBugs{
7547 BadChangeCipherSpec: []byte{2},
7548 },
7549 },
7550 shouldFail: true,
7551 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7552 })
7553 testCases = append(testCases, testCase{
7554 protocol: dtls,
7555 name: "BadChangeCipherSpec-DTLS-2",
7556 config: Config{
7557 MaxVersion: VersionTLS12,
7558 Bugs: ProtocolBugs{
7559 BadChangeCipherSpec: []byte{1, 1},
7560 },
7561 },
7562 shouldFail: true,
7563 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7564 })
7565}
7566
David Benjamin0b8d5da2016-07-15 00:39:56 -04007567func addWrongMessageTypeTests() {
7568 for _, protocol := range []protocol{tls, dtls} {
7569 var suffix string
7570 if protocol == dtls {
7571 suffix = "-DTLS"
7572 }
7573
7574 testCases = append(testCases, testCase{
7575 protocol: protocol,
7576 testType: serverTest,
7577 name: "WrongMessageType-ClientHello" + suffix,
7578 config: Config{
7579 MaxVersion: VersionTLS12,
7580 Bugs: ProtocolBugs{
7581 SendWrongMessageType: typeClientHello,
7582 },
7583 },
7584 shouldFail: true,
7585 expectedError: ":UNEXPECTED_MESSAGE:",
7586 expectedLocalError: "remote error: unexpected message",
7587 })
7588
7589 if protocol == dtls {
7590 testCases = append(testCases, testCase{
7591 protocol: protocol,
7592 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7593 config: Config{
7594 MaxVersion: VersionTLS12,
7595 Bugs: ProtocolBugs{
7596 SendWrongMessageType: typeHelloVerifyRequest,
7597 },
7598 },
7599 shouldFail: true,
7600 expectedError: ":UNEXPECTED_MESSAGE:",
7601 expectedLocalError: "remote error: unexpected message",
7602 })
7603 }
7604
7605 testCases = append(testCases, testCase{
7606 protocol: protocol,
7607 name: "WrongMessageType-ServerHello" + suffix,
7608 config: Config{
7609 MaxVersion: VersionTLS12,
7610 Bugs: ProtocolBugs{
7611 SendWrongMessageType: typeServerHello,
7612 },
7613 },
7614 shouldFail: true,
7615 expectedError: ":UNEXPECTED_MESSAGE:",
7616 expectedLocalError: "remote error: unexpected message",
7617 })
7618
7619 testCases = append(testCases, testCase{
7620 protocol: protocol,
7621 name: "WrongMessageType-ServerCertificate" + suffix,
7622 config: Config{
7623 MaxVersion: VersionTLS12,
7624 Bugs: ProtocolBugs{
7625 SendWrongMessageType: typeCertificate,
7626 },
7627 },
7628 shouldFail: true,
7629 expectedError: ":UNEXPECTED_MESSAGE:",
7630 expectedLocalError: "remote error: unexpected message",
7631 })
7632
7633 testCases = append(testCases, testCase{
7634 protocol: protocol,
7635 name: "WrongMessageType-CertificateStatus" + suffix,
7636 config: Config{
7637 MaxVersion: VersionTLS12,
7638 Bugs: ProtocolBugs{
7639 SendWrongMessageType: typeCertificateStatus,
7640 },
7641 },
7642 flags: []string{"-enable-ocsp-stapling"},
7643 shouldFail: true,
7644 expectedError: ":UNEXPECTED_MESSAGE:",
7645 expectedLocalError: "remote error: unexpected message",
7646 })
7647
7648 testCases = append(testCases, testCase{
7649 protocol: protocol,
7650 name: "WrongMessageType-ServerKeyExchange" + suffix,
7651 config: Config{
7652 MaxVersion: VersionTLS12,
7653 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7654 Bugs: ProtocolBugs{
7655 SendWrongMessageType: typeServerKeyExchange,
7656 },
7657 },
7658 shouldFail: true,
7659 expectedError: ":UNEXPECTED_MESSAGE:",
7660 expectedLocalError: "remote error: unexpected message",
7661 })
7662
7663 testCases = append(testCases, testCase{
7664 protocol: protocol,
7665 name: "WrongMessageType-CertificateRequest" + suffix,
7666 config: Config{
7667 MaxVersion: VersionTLS12,
7668 ClientAuth: RequireAnyClientCert,
7669 Bugs: ProtocolBugs{
7670 SendWrongMessageType: typeCertificateRequest,
7671 },
7672 },
7673 shouldFail: true,
7674 expectedError: ":UNEXPECTED_MESSAGE:",
7675 expectedLocalError: "remote error: unexpected message",
7676 })
7677
7678 testCases = append(testCases, testCase{
7679 protocol: protocol,
7680 name: "WrongMessageType-ServerHelloDone" + suffix,
7681 config: Config{
7682 MaxVersion: VersionTLS12,
7683 Bugs: ProtocolBugs{
7684 SendWrongMessageType: typeServerHelloDone,
7685 },
7686 },
7687 shouldFail: true,
7688 expectedError: ":UNEXPECTED_MESSAGE:",
7689 expectedLocalError: "remote error: unexpected message",
7690 })
7691
7692 testCases = append(testCases, testCase{
7693 testType: serverTest,
7694 protocol: protocol,
7695 name: "WrongMessageType-ClientCertificate" + suffix,
7696 config: Config{
7697 Certificates: []Certificate{rsaCertificate},
7698 MaxVersion: VersionTLS12,
7699 Bugs: ProtocolBugs{
7700 SendWrongMessageType: typeCertificate,
7701 },
7702 },
7703 flags: []string{"-require-any-client-certificate"},
7704 shouldFail: true,
7705 expectedError: ":UNEXPECTED_MESSAGE:",
7706 expectedLocalError: "remote error: unexpected message",
7707 })
7708
7709 testCases = append(testCases, testCase{
7710 testType: serverTest,
7711 protocol: protocol,
7712 name: "WrongMessageType-CertificateVerify" + suffix,
7713 config: Config{
7714 Certificates: []Certificate{rsaCertificate},
7715 MaxVersion: VersionTLS12,
7716 Bugs: ProtocolBugs{
7717 SendWrongMessageType: typeCertificateVerify,
7718 },
7719 },
7720 flags: []string{"-require-any-client-certificate"},
7721 shouldFail: true,
7722 expectedError: ":UNEXPECTED_MESSAGE:",
7723 expectedLocalError: "remote error: unexpected message",
7724 })
7725
7726 testCases = append(testCases, testCase{
7727 testType: serverTest,
7728 protocol: protocol,
7729 name: "WrongMessageType-ClientKeyExchange" + suffix,
7730 config: Config{
7731 MaxVersion: VersionTLS12,
7732 Bugs: ProtocolBugs{
7733 SendWrongMessageType: typeClientKeyExchange,
7734 },
7735 },
7736 shouldFail: true,
7737 expectedError: ":UNEXPECTED_MESSAGE:",
7738 expectedLocalError: "remote error: unexpected message",
7739 })
7740
7741 if protocol != dtls {
7742 testCases = append(testCases, testCase{
7743 testType: serverTest,
7744 protocol: protocol,
7745 name: "WrongMessageType-NextProtocol" + suffix,
7746 config: Config{
7747 MaxVersion: VersionTLS12,
7748 NextProtos: []string{"bar"},
7749 Bugs: ProtocolBugs{
7750 SendWrongMessageType: typeNextProtocol,
7751 },
7752 },
7753 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7754 shouldFail: true,
7755 expectedError: ":UNEXPECTED_MESSAGE:",
7756 expectedLocalError: "remote error: unexpected message",
7757 })
7758
7759 testCases = append(testCases, testCase{
7760 testType: serverTest,
7761 protocol: protocol,
7762 name: "WrongMessageType-ChannelID" + suffix,
7763 config: Config{
7764 MaxVersion: VersionTLS12,
7765 ChannelID: channelIDKey,
7766 Bugs: ProtocolBugs{
7767 SendWrongMessageType: typeChannelID,
7768 },
7769 },
7770 flags: []string{
7771 "-expect-channel-id",
7772 base64.StdEncoding.EncodeToString(channelIDBytes),
7773 },
7774 shouldFail: true,
7775 expectedError: ":UNEXPECTED_MESSAGE:",
7776 expectedLocalError: "remote error: unexpected message",
7777 })
7778 }
7779
7780 testCases = append(testCases, testCase{
7781 testType: serverTest,
7782 protocol: protocol,
7783 name: "WrongMessageType-ClientFinished" + suffix,
7784 config: Config{
7785 MaxVersion: VersionTLS12,
7786 Bugs: ProtocolBugs{
7787 SendWrongMessageType: typeFinished,
7788 },
7789 },
7790 shouldFail: true,
7791 expectedError: ":UNEXPECTED_MESSAGE:",
7792 expectedLocalError: "remote error: unexpected message",
7793 })
7794
7795 testCases = append(testCases, testCase{
7796 protocol: protocol,
7797 name: "WrongMessageType-NewSessionTicket" + suffix,
7798 config: Config{
7799 MaxVersion: VersionTLS12,
7800 Bugs: ProtocolBugs{
7801 SendWrongMessageType: typeNewSessionTicket,
7802 },
7803 },
7804 shouldFail: true,
7805 expectedError: ":UNEXPECTED_MESSAGE:",
7806 expectedLocalError: "remote error: unexpected message",
7807 })
7808
7809 testCases = append(testCases, testCase{
7810 protocol: protocol,
7811 name: "WrongMessageType-ServerFinished" + suffix,
7812 config: Config{
7813 MaxVersion: VersionTLS12,
7814 Bugs: ProtocolBugs{
7815 SendWrongMessageType: typeFinished,
7816 },
7817 },
7818 shouldFail: true,
7819 expectedError: ":UNEXPECTED_MESSAGE:",
7820 expectedLocalError: "remote error: unexpected message",
7821 })
7822
7823 }
7824}
7825
Steven Valdez143e8b32016-07-11 13:19:03 -04007826func addTLS13WrongMessageTypeTests() {
7827 testCases = append(testCases, testCase{
7828 testType: serverTest,
7829 name: "WrongMessageType-TLS13-ClientHello",
7830 config: Config{
7831 MaxVersion: VersionTLS13,
7832 Bugs: ProtocolBugs{
7833 SendWrongMessageType: typeClientHello,
7834 },
7835 },
7836 shouldFail: true,
7837 expectedError: ":UNEXPECTED_MESSAGE:",
7838 expectedLocalError: "remote error: unexpected message",
7839 })
7840
7841 testCases = append(testCases, testCase{
7842 name: "WrongMessageType-TLS13-ServerHello",
7843 config: Config{
7844 MaxVersion: VersionTLS13,
7845 Bugs: ProtocolBugs{
7846 SendWrongMessageType: typeServerHello,
7847 },
7848 },
7849 shouldFail: true,
7850 expectedError: ":UNEXPECTED_MESSAGE:",
7851 // The alert comes in with the wrong encryption.
7852 expectedLocalError: "local error: bad record MAC",
7853 })
7854
7855 testCases = append(testCases, testCase{
7856 name: "WrongMessageType-TLS13-EncryptedExtensions",
7857 config: Config{
7858 MaxVersion: VersionTLS13,
7859 Bugs: ProtocolBugs{
7860 SendWrongMessageType: typeEncryptedExtensions,
7861 },
7862 },
7863 shouldFail: true,
7864 expectedError: ":UNEXPECTED_MESSAGE:",
7865 expectedLocalError: "remote error: unexpected message",
7866 })
7867
7868 testCases = append(testCases, testCase{
7869 name: "WrongMessageType-TLS13-CertificateRequest",
7870 config: Config{
7871 MaxVersion: VersionTLS13,
7872 ClientAuth: RequireAnyClientCert,
7873 Bugs: ProtocolBugs{
7874 SendWrongMessageType: typeCertificateRequest,
7875 },
7876 },
7877 shouldFail: true,
7878 expectedError: ":UNEXPECTED_MESSAGE:",
7879 expectedLocalError: "remote error: unexpected message",
7880 })
7881
7882 testCases = append(testCases, testCase{
7883 name: "WrongMessageType-TLS13-ServerCertificate",
7884 config: Config{
7885 MaxVersion: VersionTLS13,
7886 Bugs: ProtocolBugs{
7887 SendWrongMessageType: typeCertificate,
7888 },
7889 },
7890 shouldFail: true,
7891 expectedError: ":UNEXPECTED_MESSAGE:",
7892 expectedLocalError: "remote error: unexpected message",
7893 })
7894
7895 testCases = append(testCases, testCase{
7896 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7897 config: Config{
7898 MaxVersion: VersionTLS13,
7899 Bugs: ProtocolBugs{
7900 SendWrongMessageType: typeCertificateVerify,
7901 },
7902 },
7903 shouldFail: true,
7904 expectedError: ":UNEXPECTED_MESSAGE:",
7905 expectedLocalError: "remote error: unexpected message",
7906 })
7907
7908 testCases = append(testCases, testCase{
7909 name: "WrongMessageType-TLS13-ServerFinished",
7910 config: Config{
7911 MaxVersion: VersionTLS13,
7912 Bugs: ProtocolBugs{
7913 SendWrongMessageType: typeFinished,
7914 },
7915 },
7916 shouldFail: true,
7917 expectedError: ":UNEXPECTED_MESSAGE:",
7918 expectedLocalError: "remote error: unexpected message",
7919 })
7920
7921 testCases = append(testCases, testCase{
7922 testType: serverTest,
7923 name: "WrongMessageType-TLS13-ClientCertificate",
7924 config: Config{
7925 Certificates: []Certificate{rsaCertificate},
7926 MaxVersion: VersionTLS13,
7927 Bugs: ProtocolBugs{
7928 SendWrongMessageType: typeCertificate,
7929 },
7930 },
7931 flags: []string{"-require-any-client-certificate"},
7932 shouldFail: true,
7933 expectedError: ":UNEXPECTED_MESSAGE:",
7934 expectedLocalError: "remote error: unexpected message",
7935 })
7936
7937 testCases = append(testCases, testCase{
7938 testType: serverTest,
7939 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7940 config: Config{
7941 Certificates: []Certificate{rsaCertificate},
7942 MaxVersion: VersionTLS13,
7943 Bugs: ProtocolBugs{
7944 SendWrongMessageType: typeCertificateVerify,
7945 },
7946 },
7947 flags: []string{"-require-any-client-certificate"},
7948 shouldFail: true,
7949 expectedError: ":UNEXPECTED_MESSAGE:",
7950 expectedLocalError: "remote error: unexpected message",
7951 })
7952
7953 testCases = append(testCases, testCase{
7954 testType: serverTest,
7955 name: "WrongMessageType-TLS13-ClientFinished",
7956 config: Config{
7957 MaxVersion: VersionTLS13,
7958 Bugs: ProtocolBugs{
7959 SendWrongMessageType: typeFinished,
7960 },
7961 },
7962 shouldFail: true,
7963 expectedError: ":UNEXPECTED_MESSAGE:",
7964 expectedLocalError: "remote error: unexpected message",
7965 })
7966}
7967
7968func addTLS13HandshakeTests() {
7969 testCases = append(testCases, testCase{
7970 testType: clientTest,
7971 name: "MissingKeyShare-Client",
7972 config: Config{
7973 MaxVersion: VersionTLS13,
7974 Bugs: ProtocolBugs{
7975 MissingKeyShare: true,
7976 },
7977 },
7978 shouldFail: true,
7979 expectedError: ":MISSING_KEY_SHARE:",
7980 })
7981
7982 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007983 testType: serverTest,
7984 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007985 config: Config{
7986 MaxVersion: VersionTLS13,
7987 Bugs: ProtocolBugs{
7988 MissingKeyShare: true,
7989 },
7990 },
7991 shouldFail: true,
7992 expectedError: ":MISSING_KEY_SHARE:",
7993 })
7994
7995 testCases = append(testCases, testCase{
7996 testType: clientTest,
7997 name: "ClientHelloMissingKeyShare",
7998 config: Config{
7999 MaxVersion: VersionTLS13,
8000 Bugs: ProtocolBugs{
8001 MissingKeyShare: true,
8002 },
8003 },
8004 shouldFail: true,
8005 expectedError: ":MISSING_KEY_SHARE:",
8006 })
8007
8008 testCases = append(testCases, testCase{
8009 testType: clientTest,
8010 name: "MissingKeyShare",
8011 config: Config{
8012 MaxVersion: VersionTLS13,
8013 Bugs: ProtocolBugs{
8014 MissingKeyShare: true,
8015 },
8016 },
8017 shouldFail: true,
8018 expectedError: ":MISSING_KEY_SHARE:",
8019 })
8020
8021 testCases = append(testCases, testCase{
8022 testType: serverTest,
8023 name: "DuplicateKeyShares",
8024 config: Config{
8025 MaxVersion: VersionTLS13,
8026 Bugs: ProtocolBugs{
8027 DuplicateKeyShares: true,
8028 },
8029 },
8030 })
8031
8032 testCases = append(testCases, testCase{
8033 testType: clientTest,
8034 name: "EmptyEncryptedExtensions",
8035 config: Config{
8036 MaxVersion: VersionTLS13,
8037 Bugs: ProtocolBugs{
8038 EmptyEncryptedExtensions: true,
8039 },
8040 },
8041 shouldFail: true,
8042 expectedLocalError: "remote error: error decoding message",
8043 })
8044
8045 testCases = append(testCases, testCase{
8046 testType: clientTest,
8047 name: "EncryptedExtensionsWithKeyShare",
8048 config: Config{
8049 MaxVersion: VersionTLS13,
8050 Bugs: ProtocolBugs{
8051 EncryptedExtensionsWithKeyShare: true,
8052 },
8053 },
8054 shouldFail: true,
8055 expectedLocalError: "remote error: unsupported extension",
8056 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008057
8058 testCases = append(testCases, testCase{
8059 testType: serverTest,
8060 name: "SendHelloRetryRequest",
8061 config: Config{
8062 MaxVersion: VersionTLS13,
8063 // Require a HelloRetryRequest for every curve.
8064 DefaultCurves: []CurveID{},
8065 },
8066 expectedCurveID: CurveX25519,
8067 })
8068
8069 testCases = append(testCases, testCase{
8070 testType: serverTest,
8071 name: "SendHelloRetryRequest-2",
8072 config: Config{
8073 MaxVersion: VersionTLS13,
8074 DefaultCurves: []CurveID{CurveP384},
8075 },
8076 // Although the ClientHello did not predict our preferred curve,
8077 // we always select it whether it is predicted or not.
8078 expectedCurveID: CurveX25519,
8079 })
8080
8081 testCases = append(testCases, testCase{
8082 name: "UnknownCurve-HelloRetryRequest",
8083 config: Config{
8084 MaxVersion: VersionTLS13,
8085 // P-384 requires HelloRetryRequest in BoringSSL.
8086 CurvePreferences: []CurveID{CurveP384},
8087 Bugs: ProtocolBugs{
8088 SendHelloRetryRequestCurve: bogusCurve,
8089 },
8090 },
8091 shouldFail: true,
8092 expectedError: ":WRONG_CURVE:",
8093 })
8094
8095 testCases = append(testCases, testCase{
8096 name: "DisabledCurve-HelloRetryRequest",
8097 config: Config{
8098 MaxVersion: VersionTLS13,
8099 CurvePreferences: []CurveID{CurveP256},
8100 Bugs: ProtocolBugs{
8101 IgnorePeerCurvePreferences: true,
8102 },
8103 },
8104 flags: []string{"-p384-only"},
8105 shouldFail: true,
8106 expectedError: ":WRONG_CURVE:",
8107 })
8108
8109 testCases = append(testCases, testCase{
8110 name: "UnnecessaryHelloRetryRequest",
8111 config: Config{
8112 MaxVersion: VersionTLS13,
8113 Bugs: ProtocolBugs{
8114 UnnecessaryHelloRetryRequest: true,
8115 },
8116 },
8117 shouldFail: true,
8118 expectedError: ":WRONG_CURVE:",
8119 })
8120
8121 testCases = append(testCases, testCase{
8122 name: "SecondHelloRetryRequest",
8123 config: Config{
8124 MaxVersion: VersionTLS13,
8125 // P-384 requires HelloRetryRequest in BoringSSL.
8126 CurvePreferences: []CurveID{CurveP384},
8127 Bugs: ProtocolBugs{
8128 SecondHelloRetryRequest: true,
8129 },
8130 },
8131 shouldFail: true,
8132 expectedError: ":UNEXPECTED_MESSAGE:",
8133 })
8134
8135 testCases = append(testCases, testCase{
8136 testType: serverTest,
8137 name: "SecondClientHelloMissingKeyShare",
8138 config: Config{
8139 MaxVersion: VersionTLS13,
8140 DefaultCurves: []CurveID{},
8141 Bugs: ProtocolBugs{
8142 SecondClientHelloMissingKeyShare: true,
8143 },
8144 },
8145 shouldFail: true,
8146 expectedError: ":MISSING_KEY_SHARE:",
8147 })
8148
8149 testCases = append(testCases, testCase{
8150 testType: serverTest,
8151 name: "SecondClientHelloWrongCurve",
8152 config: Config{
8153 MaxVersion: VersionTLS13,
8154 DefaultCurves: []CurveID{},
8155 Bugs: ProtocolBugs{
8156 MisinterpretHelloRetryRequestCurve: CurveP521,
8157 },
8158 },
8159 shouldFail: true,
8160 expectedError: ":WRONG_CURVE:",
8161 })
8162
8163 testCases = append(testCases, testCase{
8164 name: "HelloRetryRequestVersionMismatch",
8165 config: Config{
8166 MaxVersion: VersionTLS13,
8167 // P-384 requires HelloRetryRequest in BoringSSL.
8168 CurvePreferences: []CurveID{CurveP384},
8169 Bugs: ProtocolBugs{
8170 SendServerHelloVersion: 0x0305,
8171 },
8172 },
8173 shouldFail: true,
8174 expectedError: ":WRONG_VERSION_NUMBER:",
8175 })
8176
8177 testCases = append(testCases, testCase{
8178 name: "HelloRetryRequestCurveMismatch",
8179 config: Config{
8180 MaxVersion: VersionTLS13,
8181 // P-384 requires HelloRetryRequest in BoringSSL.
8182 CurvePreferences: []CurveID{CurveP384},
8183 Bugs: ProtocolBugs{
8184 // Send P-384 (correct) in the HelloRetryRequest.
8185 SendHelloRetryRequestCurve: CurveP384,
8186 // But send P-256 in the ServerHello.
8187 SendCurve: CurveP256,
8188 },
8189 },
8190 shouldFail: true,
8191 expectedError: ":WRONG_CURVE:",
8192 })
8193
8194 // Test the server selecting a curve that requires a HelloRetryRequest
8195 // without sending it.
8196 testCases = append(testCases, testCase{
8197 name: "SkipHelloRetryRequest",
8198 config: Config{
8199 MaxVersion: VersionTLS13,
8200 // P-384 requires HelloRetryRequest in BoringSSL.
8201 CurvePreferences: []CurveID{CurveP384},
8202 Bugs: ProtocolBugs{
8203 SkipHelloRetryRequest: true,
8204 },
8205 },
8206 shouldFail: true,
8207 expectedError: ":WRONG_CURVE:",
8208 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008209
8210 testCases = append(testCases, testCase{
8211 name: "TLS13-RequestContextInHandshake",
8212 config: Config{
8213 MaxVersion: VersionTLS13,
8214 MinVersion: VersionTLS13,
8215 ClientAuth: RequireAnyClientCert,
8216 Bugs: ProtocolBugs{
8217 SendRequestContext: []byte("request context"),
8218 },
8219 },
8220 flags: []string{
8221 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8222 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8223 },
8224 shouldFail: true,
8225 expectedError: ":DECODE_ERROR:",
8226 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008227}
8228
Adam Langley7c803a62015-06-15 15:35:05 -07008229func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008230 defer wg.Done()
8231
8232 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008233 var err error
8234
8235 if *mallocTest < 0 {
8236 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008237 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008238 } else {
8239 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8240 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008241 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008242 if err != nil {
8243 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8244 }
8245 break
8246 }
8247 }
8248 }
Adam Langley95c29f32014-06-20 12:00:00 -07008249 statusChan <- statusMsg{test: test, err: err}
8250 }
8251}
8252
8253type statusMsg struct {
8254 test *testCase
8255 started bool
8256 err error
8257}
8258
David Benjamin5f237bc2015-02-11 17:14:15 -05008259func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008260 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008261
David Benjamin5f237bc2015-02-11 17:14:15 -05008262 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008263 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008264 if !*pipe {
8265 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008266 var erase string
8267 for i := 0; i < lineLen; i++ {
8268 erase += "\b \b"
8269 }
8270 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008271 }
8272
Adam Langley95c29f32014-06-20 12:00:00 -07008273 if msg.started {
8274 started++
8275 } else {
8276 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008277
8278 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008279 if msg.err == errUnimplemented {
8280 if *pipe {
8281 // Print each test instead of a status line.
8282 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8283 }
8284 unimplemented++
8285 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8286 } else {
8287 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8288 failed++
8289 testOutput.addResult(msg.test.name, "FAIL")
8290 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008291 } else {
8292 if *pipe {
8293 // Print each test instead of a status line.
8294 fmt.Printf("PASSED (%s)\n", msg.test.name)
8295 }
8296 testOutput.addResult(msg.test.name, "PASS")
8297 }
Adam Langley95c29f32014-06-20 12:00:00 -07008298 }
8299
David Benjamin5f237bc2015-02-11 17:14:15 -05008300 if !*pipe {
8301 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008302 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008303 lineLen = len(line)
8304 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008305 }
Adam Langley95c29f32014-06-20 12:00:00 -07008306 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008307
8308 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008309}
8310
8311func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008312 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008313 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008314 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008315
Adam Langley7c803a62015-06-15 15:35:05 -07008316 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008317 addCipherSuiteTests()
8318 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008319 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008320 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008321 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008322 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008323 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008324 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008325 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008326 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008327 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008328 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008329 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008330 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008331 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008332 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008333 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008334 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008335 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008336 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008337 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008338 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008339 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008340 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008341 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008342 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008343 addTLS13WrongMessageTypeTests()
8344 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008345
8346 var wg sync.WaitGroup
8347
Adam Langley7c803a62015-06-15 15:35:05 -07008348 statusChan := make(chan statusMsg, *numWorkers)
8349 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008350 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008351
EKRf71d7ed2016-08-06 13:25:12 -07008352 if len(*shimConfigFile) != 0 {
8353 encoded, err := ioutil.ReadFile(*shimConfigFile)
8354 if err != nil {
8355 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8356 os.Exit(1)
8357 }
8358
8359 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8360 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8361 os.Exit(1)
8362 }
8363 }
8364
David Benjamin025b3d32014-07-01 19:53:04 -04008365 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008366
Adam Langley7c803a62015-06-15 15:35:05 -07008367 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008368 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008369 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008370 }
8371
David Benjamin270f0a72016-03-17 14:41:36 -04008372 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008373 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008374 matched := true
8375 if len(*testToRun) != 0 {
8376 var err error
8377 matched, err = filepath.Match(*testToRun, testCases[i].name)
8378 if err != nil {
8379 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8380 os.Exit(1)
8381 }
8382 }
8383
EKRf71d7ed2016-08-06 13:25:12 -07008384 if !*includeDisabled {
8385 for pattern := range shimConfig.DisabledTests {
8386 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8387 if err != nil {
8388 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8389 os.Exit(1)
8390 }
8391
8392 if isDisabled {
8393 matched = false
8394 break
8395 }
8396 }
8397 }
8398
David Benjamin17e12922016-07-28 18:04:43 -04008399 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008400 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008401 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008402 }
8403 }
David Benjamin17e12922016-07-28 18:04:43 -04008404
David Benjamin270f0a72016-03-17 14:41:36 -04008405 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008406 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008407 os.Exit(1)
8408 }
Adam Langley95c29f32014-06-20 12:00:00 -07008409
8410 close(testChan)
8411 wg.Wait()
8412 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008413 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008414
8415 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008416
8417 if *jsonOutput != "" {
8418 if err := testOutput.writeTo(*jsonOutput); err != nil {
8419 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8420 }
8421 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008422
EKR842ae6c2016-07-27 09:22:05 +02008423 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8424 os.Exit(1)
8425 }
8426
8427 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008428 os.Exit(1)
8429 }
Adam Langley95c29f32014-06-20 12:00:00 -07008430}