blob: d3cd77ff3eee3538943cba1441fb9038c74502e0 [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
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
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"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020024 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070025 "flag"
26 "fmt"
27 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070028 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070029 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070030 "net"
31 "os"
32 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040033 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040034 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080035 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070036 "strings"
37 "sync"
38 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050039 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070040)
41
Adam Langley69a01602014-11-17 17:26:55 -080042var (
EKR842ae6c2016-07-27 09:22:05 +020043 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
44 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
45 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
46 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
47 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
48 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.")
49 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
50 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
51 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
52 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
53 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
54 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
55 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
56 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
57 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
58 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
59 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
Adam Langley69a01602014-11-17 17:26:55 -080060)
Adam Langley95c29f32014-06-20 12:00:00 -070061
David Benjamin33863262016-07-08 17:20:12 -070062type testCert int
63
David Benjamin025b3d32014-07-01 19:53:04 -040064const (
David Benjamin33863262016-07-08 17:20:12 -070065 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040066 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070067 testCertECDSAP256
68 testCertECDSAP384
69 testCertECDSAP521
70)
71
72const (
73 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040074 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070075 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
76 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
77 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040078)
79
80const (
David Benjamina08e49d2014-08-24 01:46:07 -040081 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040082 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -070083 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
84 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
85 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040086 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040087)
88
David Benjamin7944a9f2016-07-12 22:27:01 -040089var (
90 rsaCertificate Certificate
91 rsa1024Certificate Certificate
92 ecdsaP256Certificate Certificate
93 ecdsaP384Certificate Certificate
94 ecdsaP521Certificate Certificate
95)
David Benjamin33863262016-07-08 17:20:12 -070096
97var testCerts = []struct {
98 id testCert
99 certFile, keyFile string
100 cert *Certificate
101}{
102 {
103 id: testCertRSA,
104 certFile: rsaCertificateFile,
105 keyFile: rsaKeyFile,
106 cert: &rsaCertificate,
107 },
108 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400109 id: testCertRSA1024,
110 certFile: rsa1024CertificateFile,
111 keyFile: rsa1024KeyFile,
112 cert: &rsa1024Certificate,
113 },
114 {
David Benjamin33863262016-07-08 17:20:12 -0700115 id: testCertECDSAP256,
116 certFile: ecdsaP256CertificateFile,
117 keyFile: ecdsaP256KeyFile,
118 cert: &ecdsaP256Certificate,
119 },
120 {
121 id: testCertECDSAP384,
122 certFile: ecdsaP384CertificateFile,
123 keyFile: ecdsaP384KeyFile,
124 cert: &ecdsaP384Certificate,
125 },
126 {
127 id: testCertECDSAP521,
128 certFile: ecdsaP521CertificateFile,
129 keyFile: ecdsaP521KeyFile,
130 cert: &ecdsaP521Certificate,
131 },
132}
133
David Benjamina08e49d2014-08-24 01:46:07 -0400134var channelIDKey *ecdsa.PrivateKey
135var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700136
David Benjamin61f95272014-11-25 01:55:35 -0500137var testOCSPResponse = []byte{1, 2, 3, 4}
138var testSCTList = []byte{5, 6, 7, 8}
139
Adam Langley95c29f32014-06-20 12:00:00 -0700140func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700141 for i := range testCerts {
142 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
143 if err != nil {
144 panic(err)
145 }
146 cert.OCSPStaple = testOCSPResponse
147 cert.SignedCertificateTimestampList = testSCTList
148 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700149 }
David Benjamina08e49d2014-08-24 01:46:07 -0400150
Adam Langley7c803a62015-06-15 15:35:05 -0700151 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400152 if err != nil {
153 panic(err)
154 }
155 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
156 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
157 panic("bad key type")
158 }
159 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
160 if err != nil {
161 panic(err)
162 }
163 if channelIDKey.Curve != elliptic.P256() {
164 panic("bad curve")
165 }
166
167 channelIDBytes = make([]byte, 64)
168 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
169 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700170}
171
David Benjamin33863262016-07-08 17:20:12 -0700172func getRunnerCertificate(t testCert) Certificate {
173 for _, cert := range testCerts {
174 if cert.id == t {
175 return *cert.cert
176 }
177 }
178 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700179}
180
David Benjamin33863262016-07-08 17:20:12 -0700181func getShimCertificate(t testCert) string {
182 for _, cert := range testCerts {
183 if cert.id == t {
184 return cert.certFile
185 }
186 }
187 panic("Unknown test certificate")
188}
189
190func getShimKey(t testCert) string {
191 for _, cert := range testCerts {
192 if cert.id == t {
193 return cert.keyFile
194 }
195 }
196 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700197}
198
David Benjamin025b3d32014-07-01 19:53:04 -0400199type testType int
200
201const (
202 clientTest testType = iota
203 serverTest
204)
205
David Benjamin6fd297b2014-08-11 18:43:38 -0400206type protocol int
207
208const (
209 tls protocol = iota
210 dtls
211)
212
David Benjaminfc7b0862014-09-06 13:21:53 -0400213const (
214 alpn = 1
215 npn = 2
216)
217
Adam Langley95c29f32014-06-20 12:00:00 -0700218type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400219 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400220 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700221 name string
222 config Config
223 shouldFail bool
224 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700225 // expectedLocalError, if not empty, contains a substring that must be
226 // found in the local error.
227 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400228 // expectedVersion, if non-zero, specifies the TLS version that must be
229 // negotiated.
230 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400231 // expectedResumeVersion, if non-zero, specifies the TLS version that
232 // must be negotiated on resumption. If zero, expectedVersion is used.
233 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400234 // expectedCipher, if non-zero, specifies the TLS cipher suite that
235 // should be negotiated.
236 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400237 // expectChannelID controls whether the connection should have
238 // negotiated a Channel ID with channelIDKey.
239 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400240 // expectedNextProto controls whether the connection should
241 // negotiate a next protocol via NPN or ALPN.
242 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400243 // expectNoNextProto, if true, means that no next protocol should be
244 // negotiated.
245 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400246 // expectedNextProtoType, if non-zero, is the expected next
247 // protocol negotiation mechanism.
248 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500249 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
250 // should be negotiated. If zero, none should be negotiated.
251 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100252 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
253 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100254 // expectedSCTList, if not nil, is the expected SCT list to be received.
255 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700256 // expectedPeerSignatureAlgorithm, if not zero, is the signature
257 // algorithm that the peer should have used in the handshake.
258 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400259 // expectedCurveID, if not zero, is the curve that the handshake should
260 // have used.
261 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700262 // messageLen is the length, in bytes, of the test message that will be
263 // sent.
264 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400265 // messageCount is the number of test messages that will be sent.
266 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400267 // certFile is the path to the certificate to use for the server.
268 certFile string
269 // keyFile is the path to the private key to use for the server.
270 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400271 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400272 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400273 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700274 // expectResumeRejected, if true, specifies that the attempted
275 // resumption must be rejected by the client. This is only valid for a
276 // serverTest.
277 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400278 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500279 // resumption. Unless newSessionsOnResume is set,
280 // SessionTicketKey, ServerSessionCache, and
281 // ClientSessionCache are copied from the initial connection's
282 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400283 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500284 // newSessionsOnResume, if true, will cause resumeConfig to
285 // use a different session resumption context.
286 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400287 // noSessionCache, if true, will cause the server to run without a
288 // session cache.
289 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400290 // sendPrefix sends a prefix on the socket before actually performing a
291 // handshake.
292 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400293 // shimWritesFirst controls whether the shim sends an initial "hello"
294 // message before doing a roundtrip with the runner.
295 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400296 // shimShutsDown, if true, runs a test where the shim shuts down the
297 // connection immediately after the handshake rather than echoing
298 // messages from the runner.
299 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400300 // renegotiate indicates the number of times the connection should be
301 // renegotiated during the exchange.
302 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700303 // renegotiateCiphers is a list of ciphersuite ids that will be
304 // switched in just before renegotiation.
305 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500306 // replayWrites, if true, configures the underlying transport
307 // to replay every write it makes in DTLS tests.
308 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500309 // damageFirstWrite, if true, configures the underlying transport to
310 // damage the final byte of the first application data write.
311 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400312 // exportKeyingMaterial, if non-zero, configures the test to exchange
313 // keying material and verify they match.
314 exportKeyingMaterial int
315 exportLabel string
316 exportContext string
317 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400318 // flags, if not empty, contains a list of command-line flags that will
319 // be passed to the shim program.
320 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700321 // testTLSUnique, if true, causes the shim to send the tls-unique value
322 // which will be compared against the expected value.
323 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400324 // sendEmptyRecords is the number of consecutive empty records to send
325 // before and after the test message.
326 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400327 // sendWarningAlerts is the number of consecutive warning alerts to send
328 // before and after the test message.
329 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400330 // expectMessageDropped, if true, means the test message is expected to
331 // be dropped by the client rather than echoed back.
332 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700333}
334
Adam Langley7c803a62015-06-15 15:35:05 -0700335var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700336
David Benjamin9867b7d2016-03-01 23:25:48 -0500337func writeTranscript(test *testCase, isResume bool, data []byte) {
338 if len(data) == 0 {
339 return
340 }
341
342 protocol := "tls"
343 if test.protocol == dtls {
344 protocol = "dtls"
345 }
346
347 side := "client"
348 if test.testType == serverTest {
349 side = "server"
350 }
351
352 dir := path.Join(*transcriptDir, protocol, side)
353 if err := os.MkdirAll(dir, 0755); err != nil {
354 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
355 return
356 }
357
358 name := test.name
359 if isResume {
360 name += "-Resume"
361 } else {
362 name += "-Normal"
363 }
364
365 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
366 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
367 }
368}
369
David Benjamin3ed59772016-03-08 12:50:21 -0500370// A timeoutConn implements an idle timeout on each Read and Write operation.
371type timeoutConn struct {
372 net.Conn
373 timeout time.Duration
374}
375
376func (t *timeoutConn) Read(b []byte) (int, error) {
377 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
378 return 0, err
379 }
380 return t.Conn.Read(b)
381}
382
383func (t *timeoutConn) Write(b []byte) (int, error) {
384 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
385 return 0, err
386 }
387 return t.Conn.Write(b)
388}
389
David Benjamin8e6db492015-07-25 18:29:23 -0400390func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400391 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500392
David Benjamin6fd297b2014-08-11 18:43:38 -0400393 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500394 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
395 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500396 }
397
David Benjamin9867b7d2016-03-01 23:25:48 -0500398 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500399 local, peer := "client", "server"
400 if test.testType == clientTest {
401 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500402 }
David Benjaminebda9b32015-11-02 15:33:18 -0500403 connDebug := &recordingConn{
404 Conn: conn,
405 isDatagram: test.protocol == dtls,
406 local: local,
407 peer: peer,
408 }
409 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500410 if *flagDebug {
411 defer connDebug.WriteTo(os.Stdout)
412 }
413 if len(*transcriptDir) != 0 {
414 defer func() {
415 writeTranscript(test, isResume, connDebug.Transcript())
416 }()
417 }
David Benjaminebda9b32015-11-02 15:33:18 -0500418
419 if config.Bugs.PacketAdaptor != nil {
420 config.Bugs.PacketAdaptor.debug = connDebug
421 }
422 }
423
424 if test.replayWrites {
425 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400426 }
427
David Benjamin3ed59772016-03-08 12:50:21 -0500428 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500429 if test.damageFirstWrite {
430 connDamage = newDamageAdaptor(conn)
431 conn = connDamage
432 }
433
David Benjamin6fd297b2014-08-11 18:43:38 -0400434 if test.sendPrefix != "" {
435 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
436 return err
437 }
David Benjamin98e882e2014-08-08 13:24:34 -0400438 }
439
David Benjamin1d5c83e2014-07-22 19:20:02 -0400440 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400441 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400442 if test.protocol == dtls {
443 tlsConn = DTLSServer(conn, config)
444 } else {
445 tlsConn = Server(conn, config)
446 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400447 } else {
448 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400449 if test.protocol == dtls {
450 tlsConn = DTLSClient(conn, config)
451 } else {
452 tlsConn = Client(conn, config)
453 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400454 }
David Benjamin30789da2015-08-29 22:56:45 -0400455 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400456
Adam Langley95c29f32014-06-20 12:00:00 -0700457 if err := tlsConn.Handshake(); err != nil {
458 return err
459 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700460
David Benjamin01fe8202014-09-24 15:21:44 -0400461 // TODO(davidben): move all per-connection expectations into a dedicated
462 // expectations struct that can be specified separately for the two
463 // legs.
464 expectedVersion := test.expectedVersion
465 if isResume && test.expectedResumeVersion != 0 {
466 expectedVersion = test.expectedResumeVersion
467 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700468 connState := tlsConn.ConnectionState()
469 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400470 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400471 }
472
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700473 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400474 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
475 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700476 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
477 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
478 }
David Benjamin90da8c82015-04-20 14:57:57 -0400479
David Benjamina08e49d2014-08-24 01:46:07 -0400480 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700481 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400482 if channelID == nil {
483 return fmt.Errorf("no channel ID negotiated")
484 }
485 if channelID.Curve != channelIDKey.Curve ||
486 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
487 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
488 return fmt.Errorf("incorrect channel ID")
489 }
490 }
491
David Benjaminae2888f2014-09-06 12:58:58 -0400492 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700493 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400494 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
495 }
496 }
497
David Benjaminc7ce9772015-10-09 19:32:41 -0400498 if test.expectNoNextProto {
499 if actual := connState.NegotiatedProtocol; actual != "" {
500 return fmt.Errorf("got unexpected next proto %s", actual)
501 }
502 }
503
David Benjaminfc7b0862014-09-06 13:21:53 -0400504 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700505 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400506 return fmt.Errorf("next proto type mismatch")
507 }
508 }
509
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700510 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500511 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
512 }
513
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100514 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300515 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100516 }
517
Paul Lietar4fac72e2015-09-09 13:44:55 +0100518 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
519 return fmt.Errorf("SCT list mismatch")
520 }
521
Nick Harper60edffd2016-06-21 15:19:24 -0700522 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
523 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400524 }
525
Steven Valdez5440fe02016-07-18 12:40:30 -0400526 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
527 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
528 }
529
David Benjaminc565ebb2015-04-03 04:06:36 -0400530 if test.exportKeyingMaterial > 0 {
531 actual := make([]byte, test.exportKeyingMaterial)
532 if _, err := io.ReadFull(tlsConn, actual); err != nil {
533 return err
534 }
535 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
536 if err != nil {
537 return err
538 }
539 if !bytes.Equal(actual, expected) {
540 return fmt.Errorf("keying material mismatch")
541 }
542 }
543
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700544 if test.testTLSUnique {
545 var peersValue [12]byte
546 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
547 return err
548 }
549 expected := tlsConn.ConnectionState().TLSUnique
550 if !bytes.Equal(peersValue[:], expected) {
551 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
552 }
553 }
554
David Benjamine58c4f52014-08-24 03:47:07 -0400555 if test.shimWritesFirst {
556 var buf [5]byte
557 _, err := io.ReadFull(tlsConn, buf[:])
558 if err != nil {
559 return err
560 }
561 if string(buf[:]) != "hello" {
562 return fmt.Errorf("bad initial message")
563 }
564 }
565
David Benjamina8ebe222015-06-06 03:04:39 -0400566 for i := 0; i < test.sendEmptyRecords; i++ {
567 tlsConn.Write(nil)
568 }
569
David Benjamin24f346d2015-06-06 03:28:08 -0400570 for i := 0; i < test.sendWarningAlerts; i++ {
571 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
572 }
573
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400574 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700575 if test.renegotiateCiphers != nil {
576 config.CipherSuites = test.renegotiateCiphers
577 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400578 for i := 0; i < test.renegotiate; i++ {
579 if err := tlsConn.Renegotiate(); err != nil {
580 return err
581 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700582 }
583 } else if test.renegotiateCiphers != nil {
584 panic("renegotiateCiphers without renegotiate")
585 }
586
David Benjamin5fa3eba2015-01-22 16:35:40 -0500587 if test.damageFirstWrite {
588 connDamage.setDamage(true)
589 tlsConn.Write([]byte("DAMAGED WRITE"))
590 connDamage.setDamage(false)
591 }
592
David Benjamin8e6db492015-07-25 18:29:23 -0400593 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700594 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400595 if test.protocol == dtls {
596 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
597 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700598 // Read until EOF.
599 _, err := io.Copy(ioutil.Discard, tlsConn)
600 return err
601 }
David Benjamin4417d052015-04-05 04:17:25 -0400602 if messageLen == 0 {
603 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700604 }
Adam Langley95c29f32014-06-20 12:00:00 -0700605
David Benjamin8e6db492015-07-25 18:29:23 -0400606 messageCount := test.messageCount
607 if messageCount == 0 {
608 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400609 }
610
David Benjamin8e6db492015-07-25 18:29:23 -0400611 for j := 0; j < messageCount; j++ {
612 testMessage := make([]byte, messageLen)
613 for i := range testMessage {
614 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400615 }
David Benjamin8e6db492015-07-25 18:29:23 -0400616 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700617
David Benjamin8e6db492015-07-25 18:29:23 -0400618 for i := 0; i < test.sendEmptyRecords; i++ {
619 tlsConn.Write(nil)
620 }
621
622 for i := 0; i < test.sendWarningAlerts; i++ {
623 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
624 }
625
David Benjamin4f75aaf2015-09-01 16:53:10 -0400626 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400627 // The shim will not respond.
628 continue
629 }
630
David Benjamin8e6db492015-07-25 18:29:23 -0400631 buf := make([]byte, len(testMessage))
632 if test.protocol == dtls {
633 bufTmp := make([]byte, len(buf)+1)
634 n, err := tlsConn.Read(bufTmp)
635 if err != nil {
636 return err
637 }
638 if n != len(buf) {
639 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
640 }
641 copy(buf, bufTmp)
642 } else {
643 _, err := io.ReadFull(tlsConn, buf)
644 if err != nil {
645 return err
646 }
647 }
648
649 for i, v := range buf {
650 if v != testMessage[i]^0xff {
651 return fmt.Errorf("bad reply contents at byte %d", i)
652 }
Adam Langley95c29f32014-06-20 12:00:00 -0700653 }
654 }
655
656 return nil
657}
658
David Benjamin325b5c32014-07-01 19:40:31 -0400659func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
660 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700661 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400662 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700663 }
David Benjamin325b5c32014-07-01 19:40:31 -0400664 valgrindArgs = append(valgrindArgs, path)
665 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700666
David Benjamin325b5c32014-07-01 19:40:31 -0400667 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700668}
669
David Benjamin325b5c32014-07-01 19:40:31 -0400670func gdbOf(path string, args ...string) *exec.Cmd {
671 xtermArgs := []string{"-e", "gdb", "--args"}
672 xtermArgs = append(xtermArgs, path)
673 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700674
David Benjamin325b5c32014-07-01 19:40:31 -0400675 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700676}
677
David Benjamind16bf342015-12-18 00:53:12 -0500678func lldbOf(path string, args ...string) *exec.Cmd {
679 xtermArgs := []string{"-e", "lldb", "--"}
680 xtermArgs = append(xtermArgs, path)
681 xtermArgs = append(xtermArgs, args...)
682
683 return exec.Command("xterm", xtermArgs...)
684}
685
EKR842ae6c2016-07-27 09:22:05 +0200686var (
687 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
688 errUnimplemented = errors.New("child process does not implement needed flags")
689)
Adam Langley69a01602014-11-17 17:26:55 -0800690
David Benjamin87c8a642015-02-21 01:54:29 -0500691// accept accepts a connection from listener, unless waitChan signals a process
692// exit first.
693func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
694 type connOrError struct {
695 conn net.Conn
696 err error
697 }
698 connChan := make(chan connOrError, 1)
699 go func() {
700 conn, err := listener.Accept()
701 connChan <- connOrError{conn, err}
702 close(connChan)
703 }()
704 select {
705 case result := <-connChan:
706 return result.conn, result.err
707 case childErr := <-waitChan:
708 waitChan <- childErr
709 return nil, fmt.Errorf("child exited early: %s", childErr)
710 }
711}
712
Adam Langley7c803a62015-06-15 15:35:05 -0700713func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700714 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
715 panic("Error expected without shouldFail in " + test.name)
716 }
717
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700718 if test.expectResumeRejected && !test.resumeSession {
719 panic("expectResumeRejected without resumeSession in " + test.name)
720 }
721
David Benjamin87c8a642015-02-21 01:54:29 -0500722 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
723 if err != nil {
724 panic(err)
725 }
726 defer func() {
727 if listener != nil {
728 listener.Close()
729 }
730 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700731
David Benjamin87c8a642015-02-21 01:54:29 -0500732 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400733 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400734 flags = append(flags, "-server")
735
David Benjamin025b3d32014-07-01 19:53:04 -0400736 flags = append(flags, "-key-file")
737 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700738 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400739 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700740 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400741 }
742
743 flags = append(flags, "-cert-file")
744 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700745 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400746 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700747 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400748 }
749 }
David Benjamin5a593af2014-08-11 19:51:50 -0400750
David Benjamin6fd297b2014-08-11 18:43:38 -0400751 if test.protocol == dtls {
752 flags = append(flags, "-dtls")
753 }
754
David Benjamin5a593af2014-08-11 19:51:50 -0400755 if test.resumeSession {
756 flags = append(flags, "-resume")
757 }
758
David Benjamine58c4f52014-08-24 03:47:07 -0400759 if test.shimWritesFirst {
760 flags = append(flags, "-shim-writes-first")
761 }
762
David Benjamin30789da2015-08-29 22:56:45 -0400763 if test.shimShutsDown {
764 flags = append(flags, "-shim-shuts-down")
765 }
766
David Benjaminc565ebb2015-04-03 04:06:36 -0400767 if test.exportKeyingMaterial > 0 {
768 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
769 flags = append(flags, "-export-label", test.exportLabel)
770 flags = append(flags, "-export-context", test.exportContext)
771 if test.useExportContext {
772 flags = append(flags, "-use-export-context")
773 }
774 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700775 if test.expectResumeRejected {
776 flags = append(flags, "-expect-session-miss")
777 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400778
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700779 if test.testTLSUnique {
780 flags = append(flags, "-tls-unique")
781 }
782
David Benjamin025b3d32014-07-01 19:53:04 -0400783 flags = append(flags, test.flags...)
784
785 var shim *exec.Cmd
786 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700787 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700788 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700789 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500790 } else if *useLLDB {
791 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400792 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700793 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400794 }
David Benjamin025b3d32014-07-01 19:53:04 -0400795 shim.Stdin = os.Stdin
796 var stdoutBuf, stderrBuf bytes.Buffer
797 shim.Stdout = &stdoutBuf
798 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800799 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500800 shim.Env = os.Environ()
801 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800802 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400803 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800804 }
805 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
806 }
David Benjamin025b3d32014-07-01 19:53:04 -0400807
808 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700809 panic(err)
810 }
David Benjamin87c8a642015-02-21 01:54:29 -0500811 waitChan := make(chan error, 1)
812 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700813
814 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400815 if !test.noSessionCache {
816 config.ClientSessionCache = NewLRUClientSessionCache(1)
817 config.ServerSessionCache = NewLRUServerSessionCache(1)
818 }
David Benjamin025b3d32014-07-01 19:53:04 -0400819 if test.testType == clientTest {
820 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700821 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400822 }
David Benjamin87c8a642015-02-21 01:54:29 -0500823 } else {
824 // Supply a ServerName to ensure a constant session cache key,
825 // rather than falling back to net.Conn.RemoteAddr.
826 if len(config.ServerName) == 0 {
827 config.ServerName = "test"
828 }
David Benjamin025b3d32014-07-01 19:53:04 -0400829 }
David Benjaminf2b83632016-03-01 22:57:46 -0500830 if *fuzzer {
831 config.Bugs.NullAllCiphers = true
832 }
David Benjamin2e045a92016-06-08 13:09:56 -0400833 if *deterministic {
834 config.Rand = &deterministicRand{}
835 }
Adam Langley95c29f32014-06-20 12:00:00 -0700836
David Benjamin87c8a642015-02-21 01:54:29 -0500837 conn, err := acceptOrWait(listener, waitChan)
838 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400839 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500840 conn.Close()
841 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500842
David Benjamin1d5c83e2014-07-22 19:20:02 -0400843 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400844 var resumeConfig Config
845 if test.resumeConfig != nil {
846 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500847 if len(resumeConfig.ServerName) == 0 {
848 resumeConfig.ServerName = config.ServerName
849 }
David Benjamin01fe8202014-09-24 15:21:44 -0400850 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700851 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400852 }
David Benjaminba4594a2015-06-18 18:36:15 -0400853 if test.newSessionsOnResume {
854 if !test.noSessionCache {
855 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
856 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
857 }
858 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500859 resumeConfig.SessionTicketKey = config.SessionTicketKey
860 resumeConfig.ClientSessionCache = config.ClientSessionCache
861 resumeConfig.ServerSessionCache = config.ServerSessionCache
862 }
David Benjaminf2b83632016-03-01 22:57:46 -0500863 if *fuzzer {
864 resumeConfig.Bugs.NullAllCiphers = true
865 }
David Benjamin2e045a92016-06-08 13:09:56 -0400866 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400867 } else {
868 resumeConfig = config
869 }
David Benjamin87c8a642015-02-21 01:54:29 -0500870 var connResume net.Conn
871 connResume, err = acceptOrWait(listener, waitChan)
872 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400873 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500874 connResume.Close()
875 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400876 }
877
David Benjamin87c8a642015-02-21 01:54:29 -0500878 // Close the listener now. This is to avoid hangs should the shim try to
879 // open more connections than expected.
880 listener.Close()
881 listener = nil
882
883 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800884 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200885 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
886 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800887 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200888 case 89:
889 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800890 }
891 }
Adam Langley95c29f32014-06-20 12:00:00 -0700892
David Benjamin9bea3492016-03-02 10:59:16 -0500893 // Account for Windows line endings.
894 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
895 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500896
897 // Separate the errors from the shim and those from tools like
898 // AddressSanitizer.
899 var extraStderr string
900 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
901 stderr = stderrParts[0]
902 extraStderr = stderrParts[1]
903 }
904
Adam Langley95c29f32014-06-20 12:00:00 -0700905 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400906 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700907 localError := "none"
908 if err != nil {
909 localError = err.Error()
910 }
911 if len(test.expectedLocalError) != 0 {
912 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
913 }
Adam Langley95c29f32014-06-20 12:00:00 -0700914
915 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700916 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700917 if childErr != nil {
918 childError = childErr.Error()
919 }
920
921 var msg string
922 switch {
923 case failed && !test.shouldFail:
924 msg = "unexpected failure"
925 case !failed && test.shouldFail:
926 msg = "unexpected success"
927 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700928 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700929 default:
930 panic("internal error")
931 }
932
David Benjaminc565ebb2015-04-03 04:06:36 -0400933 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 -0700934 }
935
David Benjaminff3a1492016-03-02 10:12:06 -0500936 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
937 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700938 }
939
940 return nil
941}
942
943var tlsVersions = []struct {
944 name string
945 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400946 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500947 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700948}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500949 {"SSL3", VersionSSL30, "-no-ssl3", false},
950 {"TLS1", VersionTLS10, "-no-tls1", true},
951 {"TLS11", VersionTLS11, "-no-tls11", false},
952 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400953 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700954}
955
956var testCipherSuites = []struct {
957 name string
958 id uint16
959}{
960 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400961 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700962 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400963 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400964 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700965 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400966 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400967 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
968 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400969 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400970 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
971 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400972 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700973 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
974 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400975 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
976 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700977 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400978 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500979 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500980 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700982 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700983 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400984 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400985 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700986 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400987 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500988 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500989 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700990 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700991 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
992 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
993 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
994 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400995 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
996 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700997 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
998 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500999 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001000 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1001 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001002 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001003 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001004 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001005 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001006}
1007
David Benjamin8b8c0062014-11-23 02:47:52 -05001008func hasComponent(suiteName, component string) bool {
1009 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1010}
1011
David Benjaminf7768e42014-08-31 02:06:47 -04001012func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001013 return hasComponent(suiteName, "GCM") ||
1014 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001015 hasComponent(suiteName, "SHA384") ||
1016 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001017}
1018
Nick Harper1fd39d82016-06-14 18:14:35 -07001019func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001020 // Only AEADs.
1021 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1022 return false
1023 }
1024 // No old CHACHA20_POLY1305.
1025 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1026 return false
1027 }
1028 // Must have ECDHE.
1029 // TODO(davidben,svaldez): Add pure PSK support.
1030 if !hasComponent(suiteName, "ECDHE") {
1031 return false
1032 }
1033 // TODO(davidben,svaldez): Add PSK support.
1034 if hasComponent(suiteName, "PSK") {
1035 return false
1036 }
1037 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001038}
1039
David Benjamin8b8c0062014-11-23 02:47:52 -05001040func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001041 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001042}
1043
Adam Langleya7997f12015-05-14 17:38:50 -07001044func bigFromHex(hex string) *big.Int {
1045 ret, ok := new(big.Int).SetString(hex, 16)
1046 if !ok {
1047 panic("failed to parse hex number 0x" + hex)
1048 }
1049 return ret
1050}
1051
Adam Langley7c803a62015-06-15 15:35:05 -07001052func addBasicTests() {
1053 basicTests := []testCase{
1054 {
Adam Langley7c803a62015-06-15 15:35:05 -07001055 name: "NoFallbackSCSV",
1056 config: Config{
1057 Bugs: ProtocolBugs{
1058 FailIfNotFallbackSCSV: true,
1059 },
1060 },
1061 shouldFail: true,
1062 expectedLocalError: "no fallback SCSV found",
1063 },
1064 {
1065 name: "SendFallbackSCSV",
1066 config: Config{
1067 Bugs: ProtocolBugs{
1068 FailIfNotFallbackSCSV: true,
1069 },
1070 },
1071 flags: []string{"-fallback-scsv"},
1072 },
1073 {
1074 name: "ClientCertificateTypes",
1075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001076 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001077 ClientAuth: RequestClientCert,
1078 ClientCertificateTypes: []byte{
1079 CertTypeDSSSign,
1080 CertTypeRSASign,
1081 CertTypeECDSASign,
1082 },
1083 },
1084 flags: []string{
1085 "-expect-certificate-types",
1086 base64.StdEncoding.EncodeToString([]byte{
1087 CertTypeDSSSign,
1088 CertTypeRSASign,
1089 CertTypeECDSASign,
1090 }),
1091 },
1092 },
1093 {
Adam Langley7c803a62015-06-15 15:35:05 -07001094 name: "UnauthenticatedECDH",
1095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001096 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001097 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1098 Bugs: ProtocolBugs{
1099 UnauthenticatedECDH: true,
1100 },
1101 },
1102 shouldFail: true,
1103 expectedError: ":UNEXPECTED_MESSAGE:",
1104 },
1105 {
1106 name: "SkipCertificateStatus",
1107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001108 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001109 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1110 Bugs: ProtocolBugs{
1111 SkipCertificateStatus: true,
1112 },
1113 },
1114 flags: []string{
1115 "-enable-ocsp-stapling",
1116 },
1117 },
1118 {
1119 name: "SkipServerKeyExchange",
1120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001121 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001122 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1123 Bugs: ProtocolBugs{
1124 SkipServerKeyExchange: true,
1125 },
1126 },
1127 shouldFail: true,
1128 expectedError: ":UNEXPECTED_MESSAGE:",
1129 },
1130 {
Adam Langley7c803a62015-06-15 15:35:05 -07001131 testType: serverTest,
1132 name: "Alert",
1133 config: Config{
1134 Bugs: ProtocolBugs{
1135 SendSpuriousAlert: alertRecordOverflow,
1136 },
1137 },
1138 shouldFail: true,
1139 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1140 },
1141 {
1142 protocol: dtls,
1143 testType: serverTest,
1144 name: "Alert-DTLS",
1145 config: Config{
1146 Bugs: ProtocolBugs{
1147 SendSpuriousAlert: alertRecordOverflow,
1148 },
1149 },
1150 shouldFail: true,
1151 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1152 },
1153 {
1154 testType: serverTest,
1155 name: "FragmentAlert",
1156 config: Config{
1157 Bugs: ProtocolBugs{
1158 FragmentAlert: true,
1159 SendSpuriousAlert: alertRecordOverflow,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":BAD_ALERT:",
1164 },
1165 {
1166 protocol: dtls,
1167 testType: serverTest,
1168 name: "FragmentAlert-DTLS",
1169 config: Config{
1170 Bugs: ProtocolBugs{
1171 FragmentAlert: true,
1172 SendSpuriousAlert: alertRecordOverflow,
1173 },
1174 },
1175 shouldFail: true,
1176 expectedError: ":BAD_ALERT:",
1177 },
1178 {
1179 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001180 name: "DoubleAlert",
1181 config: Config{
1182 Bugs: ProtocolBugs{
1183 DoubleAlert: true,
1184 SendSpuriousAlert: alertRecordOverflow,
1185 },
1186 },
1187 shouldFail: true,
1188 expectedError: ":BAD_ALERT:",
1189 },
1190 {
1191 protocol: dtls,
1192 testType: serverTest,
1193 name: "DoubleAlert-DTLS",
1194 config: Config{
1195 Bugs: ProtocolBugs{
1196 DoubleAlert: true,
1197 SendSpuriousAlert: alertRecordOverflow,
1198 },
1199 },
1200 shouldFail: true,
1201 expectedError: ":BAD_ALERT:",
1202 },
1203 {
Adam Langley7c803a62015-06-15 15:35:05 -07001204 name: "SkipNewSessionTicket",
1205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001206 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001207 Bugs: ProtocolBugs{
1208 SkipNewSessionTicket: true,
1209 },
1210 },
1211 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001212 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001213 },
1214 {
1215 testType: serverTest,
1216 name: "FallbackSCSV",
1217 config: Config{
1218 MaxVersion: VersionTLS11,
1219 Bugs: ProtocolBugs{
1220 SendFallbackSCSV: true,
1221 },
1222 },
1223 shouldFail: true,
1224 expectedError: ":INAPPROPRIATE_FALLBACK:",
1225 },
1226 {
1227 testType: serverTest,
1228 name: "FallbackSCSV-VersionMatch",
1229 config: Config{
1230 Bugs: ProtocolBugs{
1231 SendFallbackSCSV: true,
1232 },
1233 },
1234 },
1235 {
1236 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001237 name: "FallbackSCSV-VersionMatch-TLS12",
1238 config: Config{
1239 MaxVersion: VersionTLS12,
1240 Bugs: ProtocolBugs{
1241 SendFallbackSCSV: true,
1242 },
1243 },
1244 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1245 },
1246 {
1247 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001248 name: "FragmentedClientVersion",
1249 config: Config{
1250 Bugs: ProtocolBugs{
1251 MaxHandshakeRecordLength: 1,
1252 FragmentClientVersion: true,
1253 },
1254 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001255 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001256 },
1257 {
Adam Langley7c803a62015-06-15 15:35:05 -07001258 testType: serverTest,
1259 name: "HttpGET",
1260 sendPrefix: "GET / HTTP/1.0\n",
1261 shouldFail: true,
1262 expectedError: ":HTTP_REQUEST:",
1263 },
1264 {
1265 testType: serverTest,
1266 name: "HttpPOST",
1267 sendPrefix: "POST / HTTP/1.0\n",
1268 shouldFail: true,
1269 expectedError: ":HTTP_REQUEST:",
1270 },
1271 {
1272 testType: serverTest,
1273 name: "HttpHEAD",
1274 sendPrefix: "HEAD / HTTP/1.0\n",
1275 shouldFail: true,
1276 expectedError: ":HTTP_REQUEST:",
1277 },
1278 {
1279 testType: serverTest,
1280 name: "HttpPUT",
1281 sendPrefix: "PUT / HTTP/1.0\n",
1282 shouldFail: true,
1283 expectedError: ":HTTP_REQUEST:",
1284 },
1285 {
1286 testType: serverTest,
1287 name: "HttpCONNECT",
1288 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1289 shouldFail: true,
1290 expectedError: ":HTTPS_PROXY_REQUEST:",
1291 },
1292 {
1293 testType: serverTest,
1294 name: "Garbage",
1295 sendPrefix: "blah",
1296 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001297 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001298 },
1299 {
Adam Langley7c803a62015-06-15 15:35:05 -07001300 name: "RSAEphemeralKey",
1301 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001302 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001303 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1304 Bugs: ProtocolBugs{
1305 RSAEphemeralKey: true,
1306 },
1307 },
1308 shouldFail: true,
1309 expectedError: ":UNEXPECTED_MESSAGE:",
1310 },
1311 {
1312 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001313 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001314 shouldFail: true,
1315 expectedError: ":WRONG_SSL_VERSION:",
1316 },
1317 {
1318 protocol: dtls,
1319 name: "DisableEverything-DTLS",
1320 flags: []string{"-no-tls12", "-no-tls1"},
1321 shouldFail: true,
1322 expectedError: ":WRONG_SSL_VERSION:",
1323 },
1324 {
Adam Langley7c803a62015-06-15 15:35:05 -07001325 protocol: dtls,
1326 testType: serverTest,
1327 name: "MTU",
1328 config: Config{
1329 Bugs: ProtocolBugs{
1330 MaxPacketLength: 256,
1331 },
1332 },
1333 flags: []string{"-mtu", "256"},
1334 },
1335 {
1336 protocol: dtls,
1337 testType: serverTest,
1338 name: "MTUExceeded",
1339 config: Config{
1340 Bugs: ProtocolBugs{
1341 MaxPacketLength: 255,
1342 },
1343 },
1344 flags: []string{"-mtu", "256"},
1345 shouldFail: true,
1346 expectedLocalError: "dtls: exceeded maximum packet length",
1347 },
1348 {
1349 name: "CertMismatchRSA",
1350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001351 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001352 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001353 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001354 Bugs: ProtocolBugs{
1355 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1356 },
1357 },
1358 shouldFail: true,
1359 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1360 },
1361 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001362 name: "CertMismatchRSA-TLS13",
1363 config: Config{
1364 MaxVersion: VersionTLS13,
1365 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1366 Certificates: []Certificate{ecdsaP256Certificate},
1367 Bugs: ProtocolBugs{
1368 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1369 },
1370 },
1371 shouldFail: true,
1372 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1373 },
1374 {
Adam Langley7c803a62015-06-15 15:35:05 -07001375 name: "CertMismatchECDSA",
1376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001377 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001378 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001379 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001380 Bugs: ProtocolBugs{
1381 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1382 },
1383 },
1384 shouldFail: true,
1385 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1386 },
1387 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001388 name: "CertMismatchECDSA-TLS13",
1389 config: Config{
1390 MaxVersion: VersionTLS13,
1391 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1392 Certificates: []Certificate{rsaCertificate},
1393 Bugs: ProtocolBugs{
1394 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1395 },
1396 },
1397 shouldFail: true,
1398 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1399 },
1400 {
Adam Langley7c803a62015-06-15 15:35:05 -07001401 name: "EmptyCertificateList",
1402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001403 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001404 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1405 Bugs: ProtocolBugs{
1406 EmptyCertificateList: true,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedError: ":DECODE_ERROR:",
1411 },
1412 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001413 name: "EmptyCertificateList-TLS13",
1414 config: Config{
1415 MaxVersion: VersionTLS13,
1416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1417 Bugs: ProtocolBugs{
1418 EmptyCertificateList: true,
1419 },
1420 },
1421 shouldFail: true,
1422 expectedError: ":DECODE_ERROR:",
1423 },
1424 {
Adam Langley7c803a62015-06-15 15:35:05 -07001425 name: "TLSFatalBadPackets",
1426 damageFirstWrite: true,
1427 shouldFail: true,
1428 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1429 },
1430 {
1431 protocol: dtls,
1432 name: "DTLSIgnoreBadPackets",
1433 damageFirstWrite: true,
1434 },
1435 {
1436 protocol: dtls,
1437 name: "DTLSIgnoreBadPackets-Async",
1438 damageFirstWrite: true,
1439 flags: []string{"-async"},
1440 },
1441 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001442 name: "AppDataBeforeHandshake",
1443 config: Config{
1444 Bugs: ProtocolBugs{
1445 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1446 },
1447 },
1448 shouldFail: true,
1449 expectedError: ":UNEXPECTED_RECORD:",
1450 },
1451 {
1452 name: "AppDataBeforeHandshake-Empty",
1453 config: Config{
1454 Bugs: ProtocolBugs{
1455 AppDataBeforeHandshake: []byte{},
1456 },
1457 },
1458 shouldFail: true,
1459 expectedError: ":UNEXPECTED_RECORD:",
1460 },
1461 {
1462 protocol: dtls,
1463 name: "AppDataBeforeHandshake-DTLS",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":UNEXPECTED_RECORD:",
1471 },
1472 {
1473 protocol: dtls,
1474 name: "AppDataBeforeHandshake-DTLS-Empty",
1475 config: Config{
1476 Bugs: ProtocolBugs{
1477 AppDataBeforeHandshake: []byte{},
1478 },
1479 },
1480 shouldFail: true,
1481 expectedError: ":UNEXPECTED_RECORD:",
1482 },
1483 {
Adam Langley7c803a62015-06-15 15:35:05 -07001484 name: "AppDataAfterChangeCipherSpec",
1485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001486 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001487 Bugs: ProtocolBugs{
1488 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1489 },
1490 },
1491 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001492 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001493 },
1494 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 name: "AppDataAfterChangeCipherSpec-Empty",
1496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001497 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001498 Bugs: ProtocolBugs{
1499 AppDataAfterChangeCipherSpec: []byte{},
1500 },
1501 },
1502 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001503 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001504 },
1505 {
Adam Langley7c803a62015-06-15 15:35:05 -07001506 protocol: dtls,
1507 name: "AppDataAfterChangeCipherSpec-DTLS",
1508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001509 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001510 Bugs: ProtocolBugs{
1511 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1512 },
1513 },
1514 // BoringSSL's DTLS implementation will drop the out-of-order
1515 // application data.
1516 },
1517 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001518 protocol: dtls,
1519 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001521 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001522 Bugs: ProtocolBugs{
1523 AppDataAfterChangeCipherSpec: []byte{},
1524 },
1525 },
1526 // BoringSSL's DTLS implementation will drop the out-of-order
1527 // application data.
1528 },
1529 {
Adam Langley7c803a62015-06-15 15:35:05 -07001530 name: "AlertAfterChangeCipherSpec",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 Bugs: ProtocolBugs{
1534 AlertAfterChangeCipherSpec: alertRecordOverflow,
1535 },
1536 },
1537 shouldFail: true,
1538 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1539 },
1540 {
1541 protocol: dtls,
1542 name: "AlertAfterChangeCipherSpec-DTLS",
1543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001544 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001545 Bugs: ProtocolBugs{
1546 AlertAfterChangeCipherSpec: alertRecordOverflow,
1547 },
1548 },
1549 shouldFail: true,
1550 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1551 },
1552 {
1553 protocol: dtls,
1554 name: "ReorderHandshakeFragments-Small-DTLS",
1555 config: Config{
1556 Bugs: ProtocolBugs{
1557 ReorderHandshakeFragments: true,
1558 // Small enough that every handshake message is
1559 // fragmented.
1560 MaxHandshakeRecordLength: 2,
1561 },
1562 },
1563 },
1564 {
1565 protocol: dtls,
1566 name: "ReorderHandshakeFragments-Large-DTLS",
1567 config: Config{
1568 Bugs: ProtocolBugs{
1569 ReorderHandshakeFragments: true,
1570 // Large enough that no handshake message is
1571 // fragmented.
1572 MaxHandshakeRecordLength: 2048,
1573 },
1574 },
1575 },
1576 {
1577 protocol: dtls,
1578 name: "MixCompleteMessageWithFragments-DTLS",
1579 config: Config{
1580 Bugs: ProtocolBugs{
1581 ReorderHandshakeFragments: true,
1582 MixCompleteMessageWithFragments: true,
1583 MaxHandshakeRecordLength: 2,
1584 },
1585 },
1586 },
1587 {
1588 name: "SendInvalidRecordType",
1589 config: Config{
1590 Bugs: ProtocolBugs{
1591 SendInvalidRecordType: true,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":UNEXPECTED_RECORD:",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "SendInvalidRecordType-DTLS",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 SendInvalidRecordType: true,
1603 },
1604 },
1605 shouldFail: true,
1606 expectedError: ":UNEXPECTED_RECORD:",
1607 },
1608 {
1609 name: "FalseStart-SkipServerSecondLeg",
1610 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001611 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001612 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1613 NextProtos: []string{"foo"},
1614 Bugs: ProtocolBugs{
1615 SkipNewSessionTicket: true,
1616 SkipChangeCipherSpec: true,
1617 SkipFinished: true,
1618 ExpectFalseStart: true,
1619 },
1620 },
1621 flags: []string{
1622 "-false-start",
1623 "-handshake-never-done",
1624 "-advertise-alpn", "\x03foo",
1625 },
1626 shimWritesFirst: true,
1627 shouldFail: true,
1628 expectedError: ":UNEXPECTED_RECORD:",
1629 },
1630 {
1631 name: "FalseStart-SkipServerSecondLeg-Implicit",
1632 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001633 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001634 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1635 NextProtos: []string{"foo"},
1636 Bugs: ProtocolBugs{
1637 SkipNewSessionTicket: true,
1638 SkipChangeCipherSpec: true,
1639 SkipFinished: true,
1640 },
1641 },
1642 flags: []string{
1643 "-implicit-handshake",
1644 "-false-start",
1645 "-handshake-never-done",
1646 "-advertise-alpn", "\x03foo",
1647 },
1648 shouldFail: true,
1649 expectedError: ":UNEXPECTED_RECORD:",
1650 },
1651 {
1652 testType: serverTest,
1653 name: "FailEarlyCallback",
1654 flags: []string{"-fail-early-callback"},
1655 shouldFail: true,
1656 expectedError: ":CONNECTION_REJECTED:",
1657 expectedLocalError: "remote error: access denied",
1658 },
1659 {
Adam Langley7c803a62015-06-15 15:35:05 -07001660 protocol: dtls,
1661 name: "FragmentMessageTypeMismatch-DTLS",
1662 config: Config{
1663 Bugs: ProtocolBugs{
1664 MaxHandshakeRecordLength: 2,
1665 FragmentMessageTypeMismatch: true,
1666 },
1667 },
1668 shouldFail: true,
1669 expectedError: ":FRAGMENT_MISMATCH:",
1670 },
1671 {
1672 protocol: dtls,
1673 name: "FragmentMessageLengthMismatch-DTLS",
1674 config: Config{
1675 Bugs: ProtocolBugs{
1676 MaxHandshakeRecordLength: 2,
1677 FragmentMessageLengthMismatch: true,
1678 },
1679 },
1680 shouldFail: true,
1681 expectedError: ":FRAGMENT_MISMATCH:",
1682 },
1683 {
1684 protocol: dtls,
1685 name: "SplitFragments-Header-DTLS",
1686 config: Config{
1687 Bugs: ProtocolBugs{
1688 SplitFragments: 2,
1689 },
1690 },
1691 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001692 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001693 },
1694 {
1695 protocol: dtls,
1696 name: "SplitFragments-Boundary-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 SplitFragments: dtlsRecordHeaderLen,
1700 },
1701 },
1702 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001703 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001704 },
1705 {
1706 protocol: dtls,
1707 name: "SplitFragments-Body-DTLS",
1708 config: Config{
1709 Bugs: ProtocolBugs{
1710 SplitFragments: dtlsRecordHeaderLen + 1,
1711 },
1712 },
1713 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001714 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001715 },
1716 {
1717 protocol: dtls,
1718 name: "SendEmptyFragments-DTLS",
1719 config: Config{
1720 Bugs: ProtocolBugs{
1721 SendEmptyFragments: true,
1722 },
1723 },
1724 },
1725 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001726 name: "BadFinished-Client",
1727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001728 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001729 Bugs: ProtocolBugs{
1730 BadFinished: true,
1731 },
1732 },
1733 shouldFail: true,
1734 expectedError: ":DIGEST_CHECK_FAILED:",
1735 },
1736 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001737 name: "BadFinished-Client-TLS13",
1738 config: Config{
1739 MaxVersion: VersionTLS13,
1740 Bugs: ProtocolBugs{
1741 BadFinished: true,
1742 },
1743 },
1744 shouldFail: true,
1745 expectedError: ":DIGEST_CHECK_FAILED:",
1746 },
1747 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001748 testType: serverTest,
1749 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001751 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001752 Bugs: ProtocolBugs{
1753 BadFinished: true,
1754 },
1755 },
1756 shouldFail: true,
1757 expectedError: ":DIGEST_CHECK_FAILED:",
1758 },
1759 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001760 testType: serverTest,
1761 name: "BadFinished-Server-TLS13",
1762 config: Config{
1763 MaxVersion: VersionTLS13,
1764 Bugs: ProtocolBugs{
1765 BadFinished: true,
1766 },
1767 },
1768 shouldFail: true,
1769 expectedError: ":DIGEST_CHECK_FAILED:",
1770 },
1771 {
Adam Langley7c803a62015-06-15 15:35:05 -07001772 name: "FalseStart-BadFinished",
1773 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001774 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001775 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1776 NextProtos: []string{"foo"},
1777 Bugs: ProtocolBugs{
1778 BadFinished: true,
1779 ExpectFalseStart: true,
1780 },
1781 },
1782 flags: []string{
1783 "-false-start",
1784 "-handshake-never-done",
1785 "-advertise-alpn", "\x03foo",
1786 },
1787 shimWritesFirst: true,
1788 shouldFail: true,
1789 expectedError: ":DIGEST_CHECK_FAILED:",
1790 },
1791 {
1792 name: "NoFalseStart-NoALPN",
1793 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001794 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001795 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1796 Bugs: ProtocolBugs{
1797 ExpectFalseStart: true,
1798 AlertBeforeFalseStartTest: alertAccessDenied,
1799 },
1800 },
1801 flags: []string{
1802 "-false-start",
1803 },
1804 shimWritesFirst: true,
1805 shouldFail: true,
1806 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1807 expectedLocalError: "tls: peer did not false start: EOF",
1808 },
1809 {
1810 name: "NoFalseStart-NoAEAD",
1811 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001812 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1814 NextProtos: []string{"foo"},
1815 Bugs: ProtocolBugs{
1816 ExpectFalseStart: true,
1817 AlertBeforeFalseStartTest: alertAccessDenied,
1818 },
1819 },
1820 flags: []string{
1821 "-false-start",
1822 "-advertise-alpn", "\x03foo",
1823 },
1824 shimWritesFirst: true,
1825 shouldFail: true,
1826 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1827 expectedLocalError: "tls: peer did not false start: EOF",
1828 },
1829 {
1830 name: "NoFalseStart-RSA",
1831 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001832 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001833 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1834 NextProtos: []string{"foo"},
1835 Bugs: ProtocolBugs{
1836 ExpectFalseStart: true,
1837 AlertBeforeFalseStartTest: alertAccessDenied,
1838 },
1839 },
1840 flags: []string{
1841 "-false-start",
1842 "-advertise-alpn", "\x03foo",
1843 },
1844 shimWritesFirst: true,
1845 shouldFail: true,
1846 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1847 expectedLocalError: "tls: peer did not false start: EOF",
1848 },
1849 {
1850 name: "NoFalseStart-DHE_RSA",
1851 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001852 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001853 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1854 NextProtos: []string{"foo"},
1855 Bugs: ProtocolBugs{
1856 ExpectFalseStart: true,
1857 AlertBeforeFalseStartTest: alertAccessDenied,
1858 },
1859 },
1860 flags: []string{
1861 "-false-start",
1862 "-advertise-alpn", "\x03foo",
1863 },
1864 shimWritesFirst: true,
1865 shouldFail: true,
1866 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1867 expectedLocalError: "tls: peer did not false start: EOF",
1868 },
1869 {
Adam Langley7c803a62015-06-15 15:35:05 -07001870 protocol: dtls,
1871 name: "SendSplitAlert-Sync",
1872 config: Config{
1873 Bugs: ProtocolBugs{
1874 SendSplitAlert: true,
1875 },
1876 },
1877 },
1878 {
1879 protocol: dtls,
1880 name: "SendSplitAlert-Async",
1881 config: Config{
1882 Bugs: ProtocolBugs{
1883 SendSplitAlert: true,
1884 },
1885 },
1886 flags: []string{"-async"},
1887 },
1888 {
1889 protocol: dtls,
1890 name: "PackDTLSHandshake",
1891 config: Config{
1892 Bugs: ProtocolBugs{
1893 MaxHandshakeRecordLength: 2,
1894 PackHandshakeFragments: 20,
1895 PackHandshakeRecords: 200,
1896 },
1897 },
1898 },
1899 {
Adam Langley7c803a62015-06-15 15:35:05 -07001900 name: "SendEmptyRecords-Pass",
1901 sendEmptyRecords: 32,
1902 },
1903 {
1904 name: "SendEmptyRecords",
1905 sendEmptyRecords: 33,
1906 shouldFail: true,
1907 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1908 },
1909 {
1910 name: "SendEmptyRecords-Async",
1911 sendEmptyRecords: 33,
1912 flags: []string{"-async"},
1913 shouldFail: true,
1914 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1915 },
1916 {
1917 name: "SendWarningAlerts-Pass",
1918 sendWarningAlerts: 4,
1919 },
1920 {
1921 protocol: dtls,
1922 name: "SendWarningAlerts-DTLS-Pass",
1923 sendWarningAlerts: 4,
1924 },
1925 {
1926 name: "SendWarningAlerts",
1927 sendWarningAlerts: 5,
1928 shouldFail: true,
1929 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1930 },
1931 {
1932 name: "SendWarningAlerts-Async",
1933 sendWarningAlerts: 5,
1934 flags: []string{"-async"},
1935 shouldFail: true,
1936 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1937 },
David Benjaminba4594a2015-06-18 18:36:15 -04001938 {
1939 name: "EmptySessionID",
1940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001941 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001942 SessionTicketsDisabled: true,
1943 },
1944 noSessionCache: true,
1945 flags: []string{"-expect-no-session"},
1946 },
David Benjamin30789da2015-08-29 22:56:45 -04001947 {
1948 name: "Unclean-Shutdown",
1949 config: Config{
1950 Bugs: ProtocolBugs{
1951 NoCloseNotify: true,
1952 ExpectCloseNotify: true,
1953 },
1954 },
1955 shimShutsDown: true,
1956 flags: []string{"-check-close-notify"},
1957 shouldFail: true,
1958 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1959 },
1960 {
1961 name: "Unclean-Shutdown-Ignored",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 NoCloseNotify: true,
1965 },
1966 },
1967 shimShutsDown: true,
1968 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001969 {
David Benjaminfa214e42016-05-10 17:03:10 -04001970 name: "Unclean-Shutdown-Alert",
1971 config: Config{
1972 Bugs: ProtocolBugs{
1973 SendAlertOnShutdown: alertDecompressionFailure,
1974 ExpectCloseNotify: true,
1975 },
1976 },
1977 shimShutsDown: true,
1978 flags: []string{"-check-close-notify"},
1979 shouldFail: true,
1980 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1981 },
1982 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001983 name: "LargePlaintext",
1984 config: Config{
1985 Bugs: ProtocolBugs{
1986 SendLargeRecords: true,
1987 },
1988 },
1989 messageLen: maxPlaintext + 1,
1990 shouldFail: true,
1991 expectedError: ":DATA_LENGTH_TOO_LONG:",
1992 },
1993 {
1994 protocol: dtls,
1995 name: "LargePlaintext-DTLS",
1996 config: Config{
1997 Bugs: ProtocolBugs{
1998 SendLargeRecords: true,
1999 },
2000 },
2001 messageLen: maxPlaintext + 1,
2002 shouldFail: true,
2003 expectedError: ":DATA_LENGTH_TOO_LONG:",
2004 },
2005 {
2006 name: "LargeCiphertext",
2007 config: Config{
2008 Bugs: ProtocolBugs{
2009 SendLargeRecords: true,
2010 },
2011 },
2012 messageLen: maxPlaintext * 2,
2013 shouldFail: true,
2014 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2015 },
2016 {
2017 protocol: dtls,
2018 name: "LargeCiphertext-DTLS",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 SendLargeRecords: true,
2022 },
2023 },
2024 messageLen: maxPlaintext * 2,
2025 // Unlike the other four cases, DTLS drops records which
2026 // are invalid before authentication, so the connection
2027 // does not fail.
2028 expectMessageDropped: true,
2029 },
David Benjamindd6fed92015-10-23 17:41:12 -04002030 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002031 // In TLS 1.2 and below, empty NewSessionTicket messages
2032 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002033 name: "SendEmptySessionTicket",
2034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002035 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002036 Bugs: ProtocolBugs{
2037 SendEmptySessionTicket: true,
2038 FailIfSessionOffered: true,
2039 },
2040 },
2041 flags: []string{"-expect-no-session"},
2042 resumeSession: true,
2043 expectResumeRejected: true,
2044 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002045 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002046 name: "BadHelloRequest-1",
2047 renegotiate: 1,
2048 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002049 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002050 Bugs: ProtocolBugs{
2051 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2052 },
2053 },
2054 flags: []string{
2055 "-renegotiate-freely",
2056 "-expect-total-renegotiations", "1",
2057 },
2058 shouldFail: true,
2059 expectedError: ":BAD_HELLO_REQUEST:",
2060 },
2061 {
2062 name: "BadHelloRequest-2",
2063 renegotiate: 1,
2064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002065 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002066 Bugs: ProtocolBugs{
2067 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2068 },
2069 },
2070 flags: []string{
2071 "-renegotiate-freely",
2072 "-expect-total-renegotiations", "1",
2073 },
2074 shouldFail: true,
2075 expectedError: ":BAD_HELLO_REQUEST:",
2076 },
David Benjaminef1b0092015-11-21 14:05:44 -05002077 {
2078 testType: serverTest,
2079 name: "SupportTicketsWithSessionID",
2080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002081 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002082 SessionTicketsDisabled: true,
2083 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002084 resumeConfig: &Config{
2085 MaxVersion: VersionTLS12,
2086 },
David Benjaminef1b0092015-11-21 14:05:44 -05002087 resumeSession: true,
2088 },
Adam Langley7c803a62015-06-15 15:35:05 -07002089 }
Adam Langley7c803a62015-06-15 15:35:05 -07002090 testCases = append(testCases, basicTests...)
2091}
2092
Adam Langley95c29f32014-06-20 12:00:00 -07002093func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002094 const bogusCipher = 0xfe00
2095
Adam Langley95c29f32014-06-20 12:00:00 -07002096 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002097 const psk = "12345"
2098 const pskIdentity = "luggage combo"
2099
Adam Langley95c29f32014-06-20 12:00:00 -07002100 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002101 var certFile string
2102 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002103 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002104 cert = ecdsaP256Certificate
2105 certFile = ecdsaP256CertificateFile
2106 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002107 } else {
David Benjamin33863262016-07-08 17:20:12 -07002108 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002109 certFile = rsaCertificateFile
2110 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002111 }
2112
David Benjamin48cae082014-10-27 01:06:24 -04002113 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002114 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002115 flags = append(flags,
2116 "-psk", psk,
2117 "-psk-identity", pskIdentity)
2118 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002119 if hasComponent(suite.name, "NULL") {
2120 // NULL ciphers must be explicitly enabled.
2121 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2122 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002123 if hasComponent(suite.name, "CECPQ1") {
2124 // CECPQ1 ciphers must be explicitly enabled.
2125 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2126 }
David Benjamin48cae082014-10-27 01:06:24 -04002127
Adam Langley95c29f32014-06-20 12:00:00 -07002128 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002129 for _, protocol := range []protocol{tls, dtls} {
2130 var prefix string
2131 if protocol == dtls {
2132 if !ver.hasDTLS {
2133 continue
2134 }
2135 prefix = "D"
2136 }
Adam Langley95c29f32014-06-20 12:00:00 -07002137
David Benjamin0407e762016-06-17 16:41:18 -04002138 var shouldServerFail, shouldClientFail bool
2139 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2140 // BoringSSL clients accept ECDHE on SSLv3, but
2141 // a BoringSSL server will never select it
2142 // because the extension is missing.
2143 shouldServerFail = true
2144 }
2145 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2146 shouldClientFail = true
2147 shouldServerFail = true
2148 }
David Benjamin54c217c2016-07-13 12:35:25 -04002149 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002150 shouldClientFail = true
2151 shouldServerFail = true
2152 }
David Benjamin0407e762016-06-17 16:41:18 -04002153 if !isDTLSCipher(suite.name) && protocol == dtls {
2154 shouldClientFail = true
2155 shouldServerFail = true
2156 }
David Benjamin4298d772015-12-19 00:18:25 -05002157
David Benjamin0407e762016-06-17 16:41:18 -04002158 var expectedServerError, expectedClientError string
2159 if shouldServerFail {
2160 expectedServerError = ":NO_SHARED_CIPHER:"
2161 }
2162 if shouldClientFail {
2163 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2164 }
David Benjamin025b3d32014-07-01 19:53:04 -04002165
David Benjamin9deb1172016-07-13 17:13:49 -04002166 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2167 resumeSession := ver.version < VersionTLS13
2168
David Benjamin6fd297b2014-08-11 18:43:38 -04002169 testCases = append(testCases, testCase{
2170 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002171 protocol: protocol,
2172
2173 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002174 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002175 MinVersion: ver.version,
2176 MaxVersion: ver.version,
2177 CipherSuites: []uint16{suite.id},
2178 Certificates: []Certificate{cert},
2179 PreSharedKey: []byte(psk),
2180 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002181 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002182 EnableAllCiphers: shouldServerFail,
2183 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002184 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002185 },
2186 certFile: certFile,
2187 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002188 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002189 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002190 shouldFail: shouldServerFail,
2191 expectedError: expectedServerError,
2192 })
2193
2194 testCases = append(testCases, testCase{
2195 testType: clientTest,
2196 protocol: protocol,
2197 name: prefix + ver.name + "-" + suite.name + "-client",
2198 config: Config{
2199 MinVersion: ver.version,
2200 MaxVersion: ver.version,
2201 CipherSuites: []uint16{suite.id},
2202 Certificates: []Certificate{cert},
2203 PreSharedKey: []byte(psk),
2204 PreSharedKeyIdentity: pskIdentity,
2205 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002206 EnableAllCiphers: shouldClientFail,
2207 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002208 },
2209 },
2210 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002211 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002212 shouldFail: shouldClientFail,
2213 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002214 })
David Benjamin2c99d282015-09-01 10:23:00 -04002215
Nick Harper1fd39d82016-06-14 18:14:35 -07002216 if !shouldClientFail {
2217 // Ensure the maximum record size is accepted.
2218 testCases = append(testCases, testCase{
2219 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2220 config: Config{
2221 MinVersion: ver.version,
2222 MaxVersion: ver.version,
2223 CipherSuites: []uint16{suite.id},
2224 Certificates: []Certificate{cert},
2225 PreSharedKey: []byte(psk),
2226 PreSharedKeyIdentity: pskIdentity,
2227 },
2228 flags: flags,
2229 messageLen: maxPlaintext,
2230 })
2231 }
2232 }
David Benjamin2c99d282015-09-01 10:23:00 -04002233 }
Adam Langley95c29f32014-06-20 12:00:00 -07002234 }
Adam Langleya7997f12015-05-14 17:38:50 -07002235
2236 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002237 name: "NoSharedCipher",
2238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002239 MaxVersion: VersionTLS12,
2240 CipherSuites: []uint16{},
2241 },
2242 shouldFail: true,
2243 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2244 })
2245
2246 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002247 name: "NoSharedCipher-TLS13",
2248 config: Config{
2249 MaxVersion: VersionTLS13,
2250 CipherSuites: []uint16{},
2251 },
2252 shouldFail: true,
2253 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2254 })
2255
2256 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002257 name: "UnsupportedCipherSuite",
2258 config: Config{
2259 MaxVersion: VersionTLS12,
2260 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2261 Bugs: ProtocolBugs{
2262 IgnorePeerCipherPreferences: true,
2263 },
2264 },
2265 flags: []string{"-cipher", "DEFAULT:!RC4"},
2266 shouldFail: true,
2267 expectedError: ":WRONG_CIPHER_RETURNED:",
2268 })
2269
2270 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002271 name: "ServerHelloBogusCipher",
2272 config: Config{
2273 MaxVersion: VersionTLS12,
2274 Bugs: ProtocolBugs{
2275 SendCipherSuite: bogusCipher,
2276 },
2277 },
2278 shouldFail: true,
2279 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2280 })
2281 testCases = append(testCases, testCase{
2282 name: "ServerHelloBogusCipher-TLS13",
2283 config: Config{
2284 MaxVersion: VersionTLS13,
2285 Bugs: ProtocolBugs{
2286 SendCipherSuite: bogusCipher,
2287 },
2288 },
2289 shouldFail: true,
2290 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2291 })
2292
2293 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002294 name: "WeakDH",
2295 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002296 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002297 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2298 Bugs: ProtocolBugs{
2299 // This is a 1023-bit prime number, generated
2300 // with:
2301 // openssl gendh 1023 | openssl asn1parse -i
2302 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2303 },
2304 },
2305 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002306 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002307 })
Adam Langleycef75832015-09-03 14:51:12 -07002308
David Benjamincd24a392015-11-11 13:23:05 -08002309 testCases = append(testCases, testCase{
2310 name: "SillyDH",
2311 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002312 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002313 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2314 Bugs: ProtocolBugs{
2315 // This is a 4097-bit prime number, generated
2316 // with:
2317 // openssl gendh 4097 | openssl asn1parse -i
2318 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2319 },
2320 },
2321 shouldFail: true,
2322 expectedError: ":DH_P_TOO_LONG:",
2323 })
2324
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002325 // This test ensures that Diffie-Hellman public values are padded with
2326 // zeros so that they're the same length as the prime. This is to avoid
2327 // hitting a bug in yaSSL.
2328 testCases = append(testCases, testCase{
2329 testType: serverTest,
2330 name: "DHPublicValuePadded",
2331 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002332 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002333 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2334 Bugs: ProtocolBugs{
2335 RequireDHPublicValueLen: (1025 + 7) / 8,
2336 },
2337 },
2338 flags: []string{"-use-sparse-dh-prime"},
2339 })
David Benjamincd24a392015-11-11 13:23:05 -08002340
David Benjamin241ae832016-01-15 03:04:54 -05002341 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002342 testCases = append(testCases, testCase{
2343 testType: serverTest,
2344 name: "UnknownCipher",
2345 config: Config{
2346 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2347 },
2348 })
2349
Adam Langleycef75832015-09-03 14:51:12 -07002350 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2351 // 1.1 specific cipher suite settings. A server is setup with the given
2352 // cipher lists and then a connection is made for each member of
2353 // expectations. The cipher suite that the server selects must match
2354 // the specified one.
2355 var versionSpecificCiphersTest = []struct {
2356 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2357 // expectations is a map from TLS version to cipher suite id.
2358 expectations map[uint16]uint16
2359 }{
2360 {
2361 // Test that the null case (where no version-specific ciphers are set)
2362 // works as expected.
2363 "RC4-SHA:AES128-SHA", // default ciphers
2364 "", // no ciphers specifically for TLS ≥ 1.0
2365 "", // no ciphers specifically for TLS ≥ 1.1
2366 map[uint16]uint16{
2367 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2368 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2369 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2370 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2371 },
2372 },
2373 {
2374 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2375 // cipher.
2376 "RC4-SHA:AES128-SHA", // default
2377 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2378 "", // no ciphers specifically for TLS ≥ 1.1
2379 map[uint16]uint16{
2380 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2381 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2382 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2383 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2384 },
2385 },
2386 {
2387 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2388 // cipher.
2389 "RC4-SHA:AES128-SHA", // default
2390 "", // no ciphers specifically for TLS ≥ 1.0
2391 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2392 map[uint16]uint16{
2393 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2394 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2395 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2396 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2397 },
2398 },
2399 {
2400 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2401 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2402 "RC4-SHA:AES128-SHA", // default
2403 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2404 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2405 map[uint16]uint16{
2406 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2407 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2408 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2409 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2410 },
2411 },
2412 }
2413
2414 for i, test := range versionSpecificCiphersTest {
2415 for version, expectedCipherSuite := range test.expectations {
2416 flags := []string{"-cipher", test.ciphersDefault}
2417 if len(test.ciphersTLS10) > 0 {
2418 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2419 }
2420 if len(test.ciphersTLS11) > 0 {
2421 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2422 }
2423
2424 testCases = append(testCases, testCase{
2425 testType: serverTest,
2426 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2427 config: Config{
2428 MaxVersion: version,
2429 MinVersion: version,
2430 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2431 },
2432 flags: flags,
2433 expectedCipher: expectedCipherSuite,
2434 })
2435 }
2436 }
Adam Langley95c29f32014-06-20 12:00:00 -07002437}
2438
2439func addBadECDSASignatureTests() {
2440 for badR := BadValue(1); badR < NumBadValues; badR++ {
2441 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002442 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002443 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2444 config: Config{
2445 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002446 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002447 Bugs: ProtocolBugs{
2448 BadECDSAR: badR,
2449 BadECDSAS: badS,
2450 },
2451 },
2452 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002453 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002454 })
2455 }
2456 }
2457}
2458
Adam Langley80842bd2014-06-20 12:00:00 -07002459func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002460 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002461 name: "MaxCBCPadding",
2462 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002463 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2465 Bugs: ProtocolBugs{
2466 MaxPadding: true,
2467 },
2468 },
2469 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2470 })
David Benjamin025b3d32014-07-01 19:53:04 -04002471 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002472 name: "BadCBCPadding",
2473 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002474 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002475 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2476 Bugs: ProtocolBugs{
2477 PaddingFirstByteBad: true,
2478 },
2479 },
2480 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002482 })
2483 // OpenSSL previously had an issue where the first byte of padding in
2484 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002485 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002486 name: "BadCBCPadding255",
2487 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002488 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002489 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2490 Bugs: ProtocolBugs{
2491 MaxPadding: true,
2492 PaddingFirstByteBadIf255: true,
2493 },
2494 },
2495 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2496 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002497 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002498 })
2499}
2500
Kenny Root7fdeaf12014-08-05 15:23:37 -07002501func addCBCSplittingTests() {
2502 testCases = append(testCases, testCase{
2503 name: "CBCRecordSplitting",
2504 config: Config{
2505 MaxVersion: VersionTLS10,
2506 MinVersion: VersionTLS10,
2507 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2508 },
David Benjaminac8302a2015-09-01 17:18:15 -04002509 messageLen: -1, // read until EOF
2510 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002511 flags: []string{
2512 "-async",
2513 "-write-different-record-sizes",
2514 "-cbc-record-splitting",
2515 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002516 })
2517 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002518 name: "CBCRecordSplittingPartialWrite",
2519 config: Config{
2520 MaxVersion: VersionTLS10,
2521 MinVersion: VersionTLS10,
2522 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2523 },
2524 messageLen: -1, // read until EOF
2525 flags: []string{
2526 "-async",
2527 "-write-different-record-sizes",
2528 "-cbc-record-splitting",
2529 "-partial-write",
2530 },
2531 })
2532}
2533
David Benjamin636293b2014-07-08 17:59:18 -04002534func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002535 // Add a dummy cert pool to stress certificate authority parsing.
2536 // TODO(davidben): Add tests that those values parse out correctly.
2537 certPool := x509.NewCertPool()
2538 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2539 if err != nil {
2540 panic(err)
2541 }
2542 certPool.AddCert(cert)
2543
David Benjamin636293b2014-07-08 17:59:18 -04002544 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002545 testCases = append(testCases, testCase{
2546 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002547 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002548 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002549 MinVersion: ver.version,
2550 MaxVersion: ver.version,
2551 ClientAuth: RequireAnyClientCert,
2552 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002553 },
2554 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002555 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2556 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002557 },
2558 })
2559 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002560 testType: serverTest,
2561 name: ver.name + "-Server-ClientAuth-RSA",
2562 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002563 MinVersion: ver.version,
2564 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002565 Certificates: []Certificate{rsaCertificate},
2566 },
2567 flags: []string{"-require-any-client-certificate"},
2568 })
David Benjamine098ec22014-08-27 23:13:20 -04002569 if ver.version != VersionSSL30 {
2570 testCases = append(testCases, testCase{
2571 testType: serverTest,
2572 name: ver.name + "-Server-ClientAuth-ECDSA",
2573 config: Config{
2574 MinVersion: ver.version,
2575 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002576 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002577 },
2578 flags: []string{"-require-any-client-certificate"},
2579 })
2580 testCases = append(testCases, testCase{
2581 testType: clientTest,
2582 name: ver.name + "-Client-ClientAuth-ECDSA",
2583 config: Config{
2584 MinVersion: ver.version,
2585 MaxVersion: ver.version,
2586 ClientAuth: RequireAnyClientCert,
2587 ClientCAs: certPool,
2588 },
2589 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002590 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2591 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002592 },
2593 })
2594 }
David Benjamin636293b2014-07-08 17:59:18 -04002595 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002596
2597 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002598 name: "NoClientCertificate",
2599 config: Config{
2600 MaxVersion: VersionTLS12,
2601 ClientAuth: RequireAnyClientCert,
2602 },
2603 shouldFail: true,
2604 expectedLocalError: "client didn't provide a certificate",
2605 })
2606
2607 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002608 name: "NoClientCertificate-TLS13",
2609 config: Config{
2610 MaxVersion: VersionTLS13,
2611 ClientAuth: RequireAnyClientCert,
2612 },
2613 shouldFail: true,
2614 expectedLocalError: "client didn't provide a certificate",
2615 })
2616
2617 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002618 testType: serverTest,
2619 name: "RequireAnyClientCertificate",
2620 config: Config{
2621 MaxVersion: VersionTLS12,
2622 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002623 flags: []string{"-require-any-client-certificate"},
2624 shouldFail: true,
2625 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2626 })
2627
2628 testCases = append(testCases, testCase{
2629 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002630 name: "RequireAnyClientCertificate-TLS13",
2631 config: Config{
2632 MaxVersion: VersionTLS13,
2633 },
2634 flags: []string{"-require-any-client-certificate"},
2635 shouldFail: true,
2636 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2637 })
2638
2639 testCases = append(testCases, testCase{
2640 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002641 name: "RequireAnyClientCertificate-SSL3",
2642 config: Config{
2643 MaxVersion: VersionSSL30,
2644 },
2645 flags: []string{"-require-any-client-certificate"},
2646 shouldFail: true,
2647 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2648 })
2649
2650 testCases = append(testCases, testCase{
2651 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002652 name: "SkipClientCertificate",
2653 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002654 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002655 Bugs: ProtocolBugs{
2656 SkipClientCertificate: true,
2657 },
2658 },
2659 // Setting SSL_VERIFY_PEER allows anonymous clients.
2660 flags: []string{"-verify-peer"},
2661 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002662 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002663 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002664
Steven Valdez143e8b32016-07-11 13:19:03 -04002665 testCases = append(testCases, testCase{
2666 testType: serverTest,
2667 name: "SkipClientCertificate-TLS13",
2668 config: Config{
2669 MaxVersion: VersionTLS13,
2670 Bugs: ProtocolBugs{
2671 SkipClientCertificate: true,
2672 },
2673 },
2674 // Setting SSL_VERIFY_PEER allows anonymous clients.
2675 flags: []string{"-verify-peer"},
2676 shouldFail: true,
2677 expectedError: ":UNEXPECTED_MESSAGE:",
2678 })
2679
David Benjaminc032dfa2016-05-12 14:54:57 -04002680 // Client auth is only legal in certificate-based ciphers.
2681 testCases = append(testCases, testCase{
2682 testType: clientTest,
2683 name: "ClientAuth-PSK",
2684 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002685 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002686 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2687 PreSharedKey: []byte("secret"),
2688 ClientAuth: RequireAnyClientCert,
2689 },
2690 flags: []string{
2691 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2692 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2693 "-psk", "secret",
2694 },
2695 shouldFail: true,
2696 expectedError: ":UNEXPECTED_MESSAGE:",
2697 })
2698 testCases = append(testCases, testCase{
2699 testType: clientTest,
2700 name: "ClientAuth-ECDHE_PSK",
2701 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002702 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002703 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2704 PreSharedKey: []byte("secret"),
2705 ClientAuth: RequireAnyClientCert,
2706 },
2707 flags: []string{
2708 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2709 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2710 "-psk", "secret",
2711 },
2712 shouldFail: true,
2713 expectedError: ":UNEXPECTED_MESSAGE:",
2714 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002715
2716 // Regression test for a bug where the client CA list, if explicitly
2717 // set to NULL, was mis-encoded.
2718 testCases = append(testCases, testCase{
2719 testType: serverTest,
2720 name: "Null-Client-CA-List",
2721 config: Config{
2722 MaxVersion: VersionTLS12,
2723 Certificates: []Certificate{rsaCertificate},
2724 },
2725 flags: []string{
2726 "-require-any-client-certificate",
2727 "-use-null-client-ca-list",
2728 },
2729 })
David Benjamin636293b2014-07-08 17:59:18 -04002730}
2731
Adam Langley75712922014-10-10 16:23:43 -07002732func addExtendedMasterSecretTests() {
2733 const expectEMSFlag = "-expect-extended-master-secret"
2734
2735 for _, with := range []bool{false, true} {
2736 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002737 if with {
2738 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002739 }
2740
2741 for _, isClient := range []bool{false, true} {
2742 suffix := "-Server"
2743 testType := serverTest
2744 if isClient {
2745 suffix = "-Client"
2746 testType = clientTest
2747 }
2748
2749 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002750 // In TLS 1.3, the extension is irrelevant and
2751 // always reports as enabled.
2752 var flags []string
2753 if with || ver.version >= VersionTLS13 {
2754 flags = []string{expectEMSFlag}
2755 }
2756
Adam Langley75712922014-10-10 16:23:43 -07002757 test := testCase{
2758 testType: testType,
2759 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2760 config: Config{
2761 MinVersion: ver.version,
2762 MaxVersion: ver.version,
2763 Bugs: ProtocolBugs{
2764 NoExtendedMasterSecret: !with,
2765 RequireExtendedMasterSecret: with,
2766 },
2767 },
David Benjamin48cae082014-10-27 01:06:24 -04002768 flags: flags,
2769 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002770 }
2771 if test.shouldFail {
2772 test.expectedLocalError = "extended master secret required but not supported by peer"
2773 }
2774 testCases = append(testCases, test)
2775 }
2776 }
2777 }
2778
Adam Langleyba5934b2015-06-02 10:50:35 -07002779 for _, isClient := range []bool{false, true} {
2780 for _, supportedInFirstConnection := range []bool{false, true} {
2781 for _, supportedInResumeConnection := range []bool{false, true} {
2782 boolToWord := func(b bool) string {
2783 if b {
2784 return "Yes"
2785 }
2786 return "No"
2787 }
2788 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2789 if isClient {
2790 suffix += "Client"
2791 } else {
2792 suffix += "Server"
2793 }
2794
2795 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002796 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002797 Bugs: ProtocolBugs{
2798 RequireExtendedMasterSecret: true,
2799 },
2800 }
2801
2802 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002803 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002804 Bugs: ProtocolBugs{
2805 NoExtendedMasterSecret: true,
2806 },
2807 }
2808
2809 test := testCase{
2810 name: "ExtendedMasterSecret-" + suffix,
2811 resumeSession: true,
2812 }
2813
2814 if !isClient {
2815 test.testType = serverTest
2816 }
2817
2818 if supportedInFirstConnection {
2819 test.config = supportedConfig
2820 } else {
2821 test.config = noSupportConfig
2822 }
2823
2824 if supportedInResumeConnection {
2825 test.resumeConfig = &supportedConfig
2826 } else {
2827 test.resumeConfig = &noSupportConfig
2828 }
2829
2830 switch suffix {
2831 case "YesToYes-Client", "YesToYes-Server":
2832 // When a session is resumed, it should
2833 // still be aware that its master
2834 // secret was generated via EMS and
2835 // thus it's safe to use tls-unique.
2836 test.flags = []string{expectEMSFlag}
2837 case "NoToYes-Server":
2838 // If an original connection did not
2839 // contain EMS, but a resumption
2840 // handshake does, then a server should
2841 // not resume the session.
2842 test.expectResumeRejected = true
2843 case "YesToNo-Server":
2844 // Resuming an EMS session without the
2845 // EMS extension should cause the
2846 // server to abort the connection.
2847 test.shouldFail = true
2848 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2849 case "NoToYes-Client":
2850 // A client should abort a connection
2851 // where the server resumed a non-EMS
2852 // session but echoed the EMS
2853 // extension.
2854 test.shouldFail = true
2855 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2856 case "YesToNo-Client":
2857 // A client should abort a connection
2858 // where the server didn't echo EMS
2859 // when the session used it.
2860 test.shouldFail = true
2861 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2862 }
2863
2864 testCases = append(testCases, test)
2865 }
2866 }
2867 }
Adam Langley75712922014-10-10 16:23:43 -07002868}
2869
David Benjamin582ba042016-07-07 12:33:25 -07002870type stateMachineTestConfig struct {
2871 protocol protocol
2872 async bool
2873 splitHandshake, packHandshakeFlight bool
2874}
2875
David Benjamin43ec06f2014-08-05 02:28:57 -04002876// Adds tests that try to cover the range of the handshake state machine, under
2877// various conditions. Some of these are redundant with other tests, but they
2878// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002879func addAllStateMachineCoverageTests() {
2880 for _, async := range []bool{false, true} {
2881 for _, protocol := range []protocol{tls, dtls} {
2882 addStateMachineCoverageTests(stateMachineTestConfig{
2883 protocol: protocol,
2884 async: async,
2885 })
2886 addStateMachineCoverageTests(stateMachineTestConfig{
2887 protocol: protocol,
2888 async: async,
2889 splitHandshake: true,
2890 })
2891 if protocol == tls {
2892 addStateMachineCoverageTests(stateMachineTestConfig{
2893 protocol: protocol,
2894 async: async,
2895 packHandshakeFlight: true,
2896 })
2897 }
2898 }
2899 }
2900}
2901
2902func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002903 var tests []testCase
2904
2905 // Basic handshake, with resumption. Client and server,
2906 // session ID and session ticket.
2907 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002908 name: "Basic-Client",
2909 config: Config{
2910 MaxVersion: VersionTLS12,
2911 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002912 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002913 // Ensure session tickets are used, not session IDs.
2914 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002915 })
2916 tests = append(tests, testCase{
2917 name: "Basic-Client-RenewTicket",
2918 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002919 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002920 Bugs: ProtocolBugs{
2921 RenewTicketOnResume: true,
2922 },
2923 },
David Benjaminba4594a2015-06-18 18:36:15 -04002924 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002925 resumeSession: true,
2926 })
2927 tests = append(tests, testCase{
2928 name: "Basic-Client-NoTicket",
2929 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002930 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002931 SessionTicketsDisabled: true,
2932 },
2933 resumeSession: true,
2934 })
2935 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002936 name: "Basic-Client-Implicit",
2937 config: Config{
2938 MaxVersion: VersionTLS12,
2939 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002940 flags: []string{"-implicit-handshake"},
2941 resumeSession: true,
2942 })
2943 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002944 testType: serverTest,
2945 name: "Basic-Server",
2946 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002947 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002948 Bugs: ProtocolBugs{
2949 RequireSessionTickets: true,
2950 },
2951 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002952 resumeSession: true,
2953 })
2954 tests = append(tests, testCase{
2955 testType: serverTest,
2956 name: "Basic-Server-NoTickets",
2957 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002958 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002959 SessionTicketsDisabled: true,
2960 },
2961 resumeSession: true,
2962 })
2963 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002964 testType: serverTest,
2965 name: "Basic-Server-Implicit",
2966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002969 flags: []string{"-implicit-handshake"},
2970 resumeSession: true,
2971 })
2972 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002973 testType: serverTest,
2974 name: "Basic-Server-EarlyCallback",
2975 config: Config{
2976 MaxVersion: VersionTLS12,
2977 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002978 flags: []string{"-use-early-callback"},
2979 resumeSession: true,
2980 })
2981
Steven Valdez143e8b32016-07-11 13:19:03 -04002982 // TLS 1.3 basic handshake shapes.
2983 tests = append(tests, testCase{
2984 name: "TLS13-1RTT-Client",
2985 config: Config{
2986 MaxVersion: VersionTLS13,
2987 },
2988 })
2989 tests = append(tests, testCase{
2990 testType: serverTest,
2991 name: "TLS13-1RTT-Server",
2992 config: Config{
2993 MaxVersion: VersionTLS13,
2994 },
2995 })
2996
David Benjamin760b1dd2015-05-15 23:33:48 -04002997 // TLS client auth.
2998 tests = append(tests, testCase{
2999 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003000 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003002 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003003 ClientAuth: RequestClientCert,
3004 },
3005 })
3006 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003007 testType: serverTest,
3008 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003009 config: Config{
3010 MaxVersion: VersionTLS12,
3011 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003012 // Setting SSL_VERIFY_PEER allows anonymous clients.
3013 flags: []string{"-verify-peer"},
3014 })
David Benjamin582ba042016-07-07 12:33:25 -07003015 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003016 tests = append(tests, testCase{
3017 testType: clientTest,
3018 name: "ClientAuth-NoCertificate-Client-SSL3",
3019 config: Config{
3020 MaxVersion: VersionSSL30,
3021 ClientAuth: RequestClientCert,
3022 },
3023 })
3024 tests = append(tests, testCase{
3025 testType: serverTest,
3026 name: "ClientAuth-NoCertificate-Server-SSL3",
3027 config: Config{
3028 MaxVersion: VersionSSL30,
3029 },
3030 // Setting SSL_VERIFY_PEER allows anonymous clients.
3031 flags: []string{"-verify-peer"},
3032 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003033 tests = append(tests, testCase{
3034 testType: clientTest,
3035 name: "ClientAuth-NoCertificate-Client-TLS13",
3036 config: Config{
3037 MaxVersion: VersionTLS13,
3038 ClientAuth: RequestClientCert,
3039 },
3040 })
3041 tests = append(tests, testCase{
3042 testType: serverTest,
3043 name: "ClientAuth-NoCertificate-Server-TLS13",
3044 config: Config{
3045 MaxVersion: VersionTLS13,
3046 },
3047 // Setting SSL_VERIFY_PEER allows anonymous clients.
3048 flags: []string{"-verify-peer"},
3049 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003050 }
3051 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003052 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003053 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003055 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003056 ClientAuth: RequireAnyClientCert,
3057 },
3058 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003059 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3060 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003061 },
3062 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003063 tests = append(tests, testCase{
3064 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003065 name: "ClientAuth-RSA-Client-TLS13",
3066 config: Config{
3067 MaxVersion: VersionTLS13,
3068 ClientAuth: RequireAnyClientCert,
3069 },
3070 flags: []string{
3071 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3072 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3073 },
3074 })
3075 tests = append(tests, testCase{
3076 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003077 name: "ClientAuth-ECDSA-Client",
3078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003079 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003080 ClientAuth: RequireAnyClientCert,
3081 },
3082 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003083 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3084 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003085 },
3086 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003087 tests = append(tests, testCase{
3088 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003089 name: "ClientAuth-ECDSA-Client-TLS13",
3090 config: Config{
3091 MaxVersion: VersionTLS13,
3092 ClientAuth: RequireAnyClientCert,
3093 },
3094 flags: []string{
3095 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3096 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3097 },
3098 })
3099 tests = append(tests, testCase{
3100 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003101 name: "ClientAuth-NoCertificate-OldCallback",
3102 config: Config{
3103 MaxVersion: VersionTLS12,
3104 ClientAuth: RequestClientCert,
3105 },
3106 flags: []string{"-use-old-client-cert-callback"},
3107 })
3108 tests = append(tests, testCase{
3109 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003110 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3111 config: Config{
3112 MaxVersion: VersionTLS13,
3113 ClientAuth: RequestClientCert,
3114 },
3115 flags: []string{"-use-old-client-cert-callback"},
3116 })
3117 tests = append(tests, testCase{
3118 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003119 name: "ClientAuth-OldCallback",
3120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003121 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003122 ClientAuth: RequireAnyClientCert,
3123 },
3124 flags: []string{
3125 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3126 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3127 "-use-old-client-cert-callback",
3128 },
3129 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003130 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003131 testType: clientTest,
3132 name: "ClientAuth-OldCallback-TLS13",
3133 config: Config{
3134 MaxVersion: VersionTLS13,
3135 ClientAuth: RequireAnyClientCert,
3136 },
3137 flags: []string{
3138 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3139 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3140 "-use-old-client-cert-callback",
3141 },
3142 })
3143 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003144 testType: serverTest,
3145 name: "ClientAuth-Server",
3146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003147 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003148 Certificates: []Certificate{rsaCertificate},
3149 },
3150 flags: []string{"-require-any-client-certificate"},
3151 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003152 tests = append(tests, testCase{
3153 testType: serverTest,
3154 name: "ClientAuth-Server-TLS13",
3155 config: Config{
3156 MaxVersion: VersionTLS13,
3157 Certificates: []Certificate{rsaCertificate},
3158 },
3159 flags: []string{"-require-any-client-certificate"},
3160 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003161
David Benjamin4c3ddf72016-06-29 18:13:53 -04003162 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003163 tests = append(tests, testCase{
3164 testType: serverTest,
3165 name: "Basic-Server-RSA",
3166 config: Config{
3167 MaxVersion: VersionTLS12,
3168 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3169 },
3170 flags: []string{
3171 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3172 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3173 },
3174 })
3175 tests = append(tests, testCase{
3176 testType: serverTest,
3177 name: "Basic-Server-ECDHE-RSA",
3178 config: Config{
3179 MaxVersion: VersionTLS12,
3180 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3181 },
3182 flags: []string{
3183 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3184 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3185 },
3186 })
3187 tests = append(tests, testCase{
3188 testType: serverTest,
3189 name: "Basic-Server-ECDHE-ECDSA",
3190 config: Config{
3191 MaxVersion: VersionTLS12,
3192 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3193 },
3194 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003195 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3196 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003197 },
3198 })
3199
David Benjamin760b1dd2015-05-15 23:33:48 -04003200 // No session ticket support; server doesn't send NewSessionTicket.
3201 tests = append(tests, testCase{
3202 name: "SessionTicketsDisabled-Client",
3203 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003204 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003205 SessionTicketsDisabled: true,
3206 },
3207 })
3208 tests = append(tests, testCase{
3209 testType: serverTest,
3210 name: "SessionTicketsDisabled-Server",
3211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003212 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003213 SessionTicketsDisabled: true,
3214 },
3215 })
3216
3217 // Skip ServerKeyExchange in PSK key exchange if there's no
3218 // identity hint.
3219 tests = append(tests, testCase{
3220 name: "EmptyPSKHint-Client",
3221 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003222 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003223 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3224 PreSharedKey: []byte("secret"),
3225 },
3226 flags: []string{"-psk", "secret"},
3227 })
3228 tests = append(tests, testCase{
3229 testType: serverTest,
3230 name: "EmptyPSKHint-Server",
3231 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003232 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003233 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3234 PreSharedKey: []byte("secret"),
3235 },
3236 flags: []string{"-psk", "secret"},
3237 })
3238
David Benjamin4c3ddf72016-06-29 18:13:53 -04003239 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003240 tests = append(tests, testCase{
3241 testType: clientTest,
3242 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003243 config: Config{
3244 MaxVersion: VersionTLS12,
3245 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003246 flags: []string{
3247 "-enable-ocsp-stapling",
3248 "-expect-ocsp-response",
3249 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003250 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003251 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003252 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003253 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003254 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003255 testType: serverTest,
3256 name: "OCSPStapling-Server",
3257 config: Config{
3258 MaxVersion: VersionTLS12,
3259 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003260 expectedOCSPResponse: testOCSPResponse,
3261 flags: []string{
3262 "-ocsp-response",
3263 base64.StdEncoding.EncodeToString(testOCSPResponse),
3264 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003265 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003266 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003267 tests = append(tests, testCase{
3268 testType: clientTest,
3269 name: "OCSPStapling-Client-TLS13",
3270 config: Config{
3271 MaxVersion: VersionTLS13,
3272 },
3273 flags: []string{
3274 "-enable-ocsp-stapling",
3275 "-expect-ocsp-response",
3276 base64.StdEncoding.EncodeToString(testOCSPResponse),
3277 "-verify-peer",
3278 },
3279 // TODO(davidben): Enable this when resumption is implemented
3280 // in TLS 1.3.
3281 resumeSession: false,
3282 })
3283 tests = append(tests, testCase{
3284 testType: serverTest,
3285 name: "OCSPStapling-Server-TLS13",
3286 config: Config{
3287 MaxVersion: VersionTLS13,
3288 },
3289 expectedOCSPResponse: testOCSPResponse,
3290 flags: []string{
3291 "-ocsp-response",
3292 base64.StdEncoding.EncodeToString(testOCSPResponse),
3293 },
3294 // TODO(davidben): Enable this when resumption is implemented
3295 // in TLS 1.3.
3296 resumeSession: false,
3297 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003298
David Benjamin4c3ddf72016-06-29 18:13:53 -04003299 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003300 for _, vers := range tlsVersions {
3301 if config.protocol == dtls && !vers.hasDTLS {
3302 continue
3303 }
3304 tests = append(tests, testCase{
3305 testType: clientTest,
3306 name: "CertificateVerificationSucceed-" + vers.name,
3307 config: Config{
3308 MaxVersion: vers.version,
3309 },
3310 flags: []string{
3311 "-verify-peer",
3312 },
3313 })
3314 tests = append(tests, testCase{
3315 testType: clientTest,
3316 name: "CertificateVerificationFail-" + vers.name,
3317 config: Config{
3318 MaxVersion: vers.version,
3319 },
3320 flags: []string{
3321 "-verify-fail",
3322 "-verify-peer",
3323 },
3324 shouldFail: true,
3325 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3326 })
3327 tests = append(tests, testCase{
3328 testType: clientTest,
3329 name: "CertificateVerificationSoftFail-" + vers.name,
3330 config: Config{
3331 MaxVersion: vers.version,
3332 },
3333 flags: []string{
3334 "-verify-fail",
3335 "-expect-verify-result",
3336 },
3337 })
3338 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003339
David Benjamin1d4f4c02016-07-26 18:03:08 -04003340 tests = append(tests, testCase{
3341 name: "ShimSendAlert",
3342 flags: []string{"-send-alert"},
3343 shimWritesFirst: true,
3344 shouldFail: true,
3345 expectedLocalError: "remote error: decompression failure",
3346 })
3347
David Benjamin582ba042016-07-07 12:33:25 -07003348 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003349 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003350 name: "Renegotiate-Client",
3351 config: Config{
3352 MaxVersion: VersionTLS12,
3353 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003354 renegotiate: 1,
3355 flags: []string{
3356 "-renegotiate-freely",
3357 "-expect-total-renegotiations", "1",
3358 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003359 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003360
David Benjamin760b1dd2015-05-15 23:33:48 -04003361 // NPN on client and server; results in post-handshake message.
3362 tests = append(tests, testCase{
3363 name: "NPN-Client",
3364 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003365 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003366 NextProtos: []string{"foo"},
3367 },
3368 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003369 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003370 expectedNextProto: "foo",
3371 expectedNextProtoType: npn,
3372 })
3373 tests = append(tests, testCase{
3374 testType: serverTest,
3375 name: "NPN-Server",
3376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003377 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003378 NextProtos: []string{"bar"},
3379 },
3380 flags: []string{
3381 "-advertise-npn", "\x03foo\x03bar\x03baz",
3382 "-expect-next-proto", "bar",
3383 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003384 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003385 expectedNextProto: "bar",
3386 expectedNextProtoType: npn,
3387 })
3388
3389 // TODO(davidben): Add tests for when False Start doesn't trigger.
3390
3391 // Client does False Start and negotiates NPN.
3392 tests = append(tests, testCase{
3393 name: "FalseStart",
3394 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003395 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003396 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3397 NextProtos: []string{"foo"},
3398 Bugs: ProtocolBugs{
3399 ExpectFalseStart: true,
3400 },
3401 },
3402 flags: []string{
3403 "-false-start",
3404 "-select-next-proto", "foo",
3405 },
3406 shimWritesFirst: true,
3407 resumeSession: true,
3408 })
3409
3410 // Client does False Start and negotiates ALPN.
3411 tests = append(tests, testCase{
3412 name: "FalseStart-ALPN",
3413 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003414 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3416 NextProtos: []string{"foo"},
3417 Bugs: ProtocolBugs{
3418 ExpectFalseStart: true,
3419 },
3420 },
3421 flags: []string{
3422 "-false-start",
3423 "-advertise-alpn", "\x03foo",
3424 },
3425 shimWritesFirst: true,
3426 resumeSession: true,
3427 })
3428
3429 // Client does False Start but doesn't explicitly call
3430 // SSL_connect.
3431 tests = append(tests, testCase{
3432 name: "FalseStart-Implicit",
3433 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003434 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3436 NextProtos: []string{"foo"},
3437 },
3438 flags: []string{
3439 "-implicit-handshake",
3440 "-false-start",
3441 "-advertise-alpn", "\x03foo",
3442 },
3443 })
3444
3445 // False Start without session tickets.
3446 tests = append(tests, testCase{
3447 name: "FalseStart-SessionTicketsDisabled",
3448 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003449 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3451 NextProtos: []string{"foo"},
3452 SessionTicketsDisabled: true,
3453 Bugs: ProtocolBugs{
3454 ExpectFalseStart: true,
3455 },
3456 },
3457 flags: []string{
3458 "-false-start",
3459 "-select-next-proto", "foo",
3460 },
3461 shimWritesFirst: true,
3462 })
3463
Adam Langleydf759b52016-07-11 15:24:37 -07003464 tests = append(tests, testCase{
3465 name: "FalseStart-CECPQ1",
3466 config: Config{
3467 MaxVersion: VersionTLS12,
3468 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3469 NextProtos: []string{"foo"},
3470 Bugs: ProtocolBugs{
3471 ExpectFalseStart: true,
3472 },
3473 },
3474 flags: []string{
3475 "-false-start",
3476 "-cipher", "DEFAULT:kCECPQ1",
3477 "-select-next-proto", "foo",
3478 },
3479 shimWritesFirst: true,
3480 resumeSession: true,
3481 })
3482
David Benjamin760b1dd2015-05-15 23:33:48 -04003483 // Server parses a V2ClientHello.
3484 tests = append(tests, testCase{
3485 testType: serverTest,
3486 name: "SendV2ClientHello",
3487 config: Config{
3488 // Choose a cipher suite that does not involve
3489 // elliptic curves, so no extensions are
3490 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003491 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003492 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3493 Bugs: ProtocolBugs{
3494 SendV2ClientHello: true,
3495 },
3496 },
3497 })
3498
3499 // Client sends a Channel ID.
3500 tests = append(tests, testCase{
3501 name: "ChannelID-Client",
3502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003503 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003504 RequestChannelID: true,
3505 },
Adam Langley7c803a62015-06-15 15:35:05 -07003506 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003507 resumeSession: true,
3508 expectChannelID: true,
3509 })
3510
3511 // Server accepts a Channel ID.
3512 tests = append(tests, testCase{
3513 testType: serverTest,
3514 name: "ChannelID-Server",
3515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003516 MaxVersion: VersionTLS12,
3517 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003518 },
3519 flags: []string{
3520 "-expect-channel-id",
3521 base64.StdEncoding.EncodeToString(channelIDBytes),
3522 },
3523 resumeSession: true,
3524 expectChannelID: true,
3525 })
David Benjamin30789da2015-08-29 22:56:45 -04003526
David Benjaminf8fcdf32016-06-08 15:56:13 -04003527 // Channel ID and NPN at the same time, to ensure their relative
3528 // ordering is correct.
3529 tests = append(tests, testCase{
3530 name: "ChannelID-NPN-Client",
3531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003532 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003533 RequestChannelID: true,
3534 NextProtos: []string{"foo"},
3535 },
3536 flags: []string{
3537 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3538 "-select-next-proto", "foo",
3539 },
3540 resumeSession: true,
3541 expectChannelID: true,
3542 expectedNextProto: "foo",
3543 expectedNextProtoType: npn,
3544 })
3545 tests = append(tests, testCase{
3546 testType: serverTest,
3547 name: "ChannelID-NPN-Server",
3548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003549 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003550 ChannelID: channelIDKey,
3551 NextProtos: []string{"bar"},
3552 },
3553 flags: []string{
3554 "-expect-channel-id",
3555 base64.StdEncoding.EncodeToString(channelIDBytes),
3556 "-advertise-npn", "\x03foo\x03bar\x03baz",
3557 "-expect-next-proto", "bar",
3558 },
3559 resumeSession: true,
3560 expectChannelID: true,
3561 expectedNextProto: "bar",
3562 expectedNextProtoType: npn,
3563 })
3564
David Benjamin30789da2015-08-29 22:56:45 -04003565 // Bidirectional shutdown with the runner initiating.
3566 tests = append(tests, testCase{
3567 name: "Shutdown-Runner",
3568 config: Config{
3569 Bugs: ProtocolBugs{
3570 ExpectCloseNotify: true,
3571 },
3572 },
3573 flags: []string{"-check-close-notify"},
3574 })
3575
3576 // Bidirectional shutdown with the shim initiating. The runner,
3577 // in the meantime, sends garbage before the close_notify which
3578 // the shim must ignore.
3579 tests = append(tests, testCase{
3580 name: "Shutdown-Shim",
3581 config: Config{
3582 Bugs: ProtocolBugs{
3583 ExpectCloseNotify: true,
3584 },
3585 },
3586 shimShutsDown: true,
3587 sendEmptyRecords: 1,
3588 sendWarningAlerts: 1,
3589 flags: []string{"-check-close-notify"},
3590 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003591 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003592 // TODO(davidben): DTLS 1.3 will want a similar thing for
3593 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003594 tests = append(tests, testCase{
3595 name: "SkipHelloVerifyRequest",
3596 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003597 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003598 Bugs: ProtocolBugs{
3599 SkipHelloVerifyRequest: true,
3600 },
3601 },
3602 })
3603 }
3604
David Benjamin760b1dd2015-05-15 23:33:48 -04003605 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003606 test.protocol = config.protocol
3607 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003608 test.name += "-DTLS"
3609 }
David Benjamin582ba042016-07-07 12:33:25 -07003610 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003611 test.name += "-Async"
3612 test.flags = append(test.flags, "-async")
3613 } else {
3614 test.name += "-Sync"
3615 }
David Benjamin582ba042016-07-07 12:33:25 -07003616 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003617 test.name += "-SplitHandshakeRecords"
3618 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003619 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003620 test.config.Bugs.MaxPacketLength = 256
3621 test.flags = append(test.flags, "-mtu", "256")
3622 }
3623 }
David Benjamin582ba042016-07-07 12:33:25 -07003624 if config.packHandshakeFlight {
3625 test.name += "-PackHandshakeFlight"
3626 test.config.Bugs.PackHandshakeFlight = true
3627 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003628 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003629 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003630}
3631
Adam Langley524e7172015-02-20 16:04:00 -08003632func addDDoSCallbackTests() {
3633 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003634 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003635 for _, resume := range []bool{false, true} {
3636 suffix := "Resume"
3637 if resume {
3638 suffix = "No" + suffix
3639 }
3640
3641 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003642 testType: serverTest,
3643 name: "Server-DDoS-OK-" + suffix,
3644 config: Config{
3645 MaxVersion: VersionTLS12,
3646 },
Adam Langley524e7172015-02-20 16:04:00 -08003647 flags: []string{"-install-ddos-callback"},
3648 resumeSession: resume,
3649 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003650 if !resume {
3651 testCases = append(testCases, testCase{
3652 testType: serverTest,
3653 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3654 config: Config{
3655 MaxVersion: VersionTLS13,
3656 },
3657 flags: []string{"-install-ddos-callback"},
3658 resumeSession: resume,
3659 })
3660 }
Adam Langley524e7172015-02-20 16:04:00 -08003661
3662 failFlag := "-fail-ddos-callback"
3663 if resume {
3664 failFlag = "-fail-second-ddos-callback"
3665 }
3666 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003667 testType: serverTest,
3668 name: "Server-DDoS-Reject-" + suffix,
3669 config: Config{
3670 MaxVersion: VersionTLS12,
3671 },
Adam Langley524e7172015-02-20 16:04:00 -08003672 flags: []string{"-install-ddos-callback", failFlag},
3673 resumeSession: resume,
3674 shouldFail: true,
3675 expectedError: ":CONNECTION_REJECTED:",
3676 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003677 if !resume {
3678 testCases = append(testCases, testCase{
3679 testType: serverTest,
3680 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3681 config: Config{
3682 MaxVersion: VersionTLS13,
3683 },
3684 flags: []string{"-install-ddos-callback", failFlag},
3685 resumeSession: resume,
3686 shouldFail: true,
3687 expectedError: ":CONNECTION_REJECTED:",
3688 })
3689 }
Adam Langley524e7172015-02-20 16:04:00 -08003690 }
3691}
3692
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003693func addVersionNegotiationTests() {
3694 for i, shimVers := range tlsVersions {
3695 // Assemble flags to disable all newer versions on the shim.
3696 var flags []string
3697 for _, vers := range tlsVersions[i+1:] {
3698 flags = append(flags, vers.flag)
3699 }
3700
3701 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003702 protocols := []protocol{tls}
3703 if runnerVers.hasDTLS && shimVers.hasDTLS {
3704 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003705 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003706 for _, protocol := range protocols {
3707 expectedVersion := shimVers.version
3708 if runnerVers.version < shimVers.version {
3709 expectedVersion = runnerVers.version
3710 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003711
David Benjamin8b8c0062014-11-23 02:47:52 -05003712 suffix := shimVers.name + "-" + runnerVers.name
3713 if protocol == dtls {
3714 suffix += "-DTLS"
3715 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003716
David Benjamin1eb367c2014-12-12 18:17:51 -05003717 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3718
David Benjamin1e29a6b2014-12-10 02:27:24 -05003719 clientVers := shimVers.version
3720 if clientVers > VersionTLS10 {
3721 clientVers = VersionTLS10
3722 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003723 serverVers := expectedVersion
3724 if expectedVersion >= VersionTLS13 {
3725 serverVers = VersionTLS10
3726 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003727 testCases = append(testCases, testCase{
3728 protocol: protocol,
3729 testType: clientTest,
3730 name: "VersionNegotiation-Client-" + suffix,
3731 config: Config{
3732 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003733 Bugs: ProtocolBugs{
3734 ExpectInitialRecordVersion: clientVers,
3735 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003736 },
3737 flags: flags,
3738 expectedVersion: expectedVersion,
3739 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003740 testCases = append(testCases, testCase{
3741 protocol: protocol,
3742 testType: clientTest,
3743 name: "VersionNegotiation-Client2-" + suffix,
3744 config: Config{
3745 MaxVersion: runnerVers.version,
3746 Bugs: ProtocolBugs{
3747 ExpectInitialRecordVersion: clientVers,
3748 },
3749 },
3750 flags: []string{"-max-version", shimVersFlag},
3751 expectedVersion: expectedVersion,
3752 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003753
3754 testCases = append(testCases, testCase{
3755 protocol: protocol,
3756 testType: serverTest,
3757 name: "VersionNegotiation-Server-" + suffix,
3758 config: Config{
3759 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003760 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003761 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003762 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003763 },
3764 flags: flags,
3765 expectedVersion: expectedVersion,
3766 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003767 testCases = append(testCases, testCase{
3768 protocol: protocol,
3769 testType: serverTest,
3770 name: "VersionNegotiation-Server2-" + suffix,
3771 config: Config{
3772 MaxVersion: runnerVers.version,
3773 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003774 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003775 },
3776 },
3777 flags: []string{"-max-version", shimVersFlag},
3778 expectedVersion: expectedVersion,
3779 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003780 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003781 }
3782 }
David Benjamin95c69562016-06-29 18:15:03 -04003783
3784 // Test for version tolerance.
3785 testCases = append(testCases, testCase{
3786 testType: serverTest,
3787 name: "MinorVersionTolerance",
3788 config: Config{
3789 Bugs: ProtocolBugs{
3790 SendClientVersion: 0x03ff,
3791 },
3792 },
3793 expectedVersion: VersionTLS13,
3794 })
3795 testCases = append(testCases, testCase{
3796 testType: serverTest,
3797 name: "MajorVersionTolerance",
3798 config: Config{
3799 Bugs: ProtocolBugs{
3800 SendClientVersion: 0x0400,
3801 },
3802 },
3803 expectedVersion: VersionTLS13,
3804 })
3805 testCases = append(testCases, testCase{
3806 protocol: dtls,
3807 testType: serverTest,
3808 name: "MinorVersionTolerance-DTLS",
3809 config: Config{
3810 Bugs: ProtocolBugs{
3811 SendClientVersion: 0x03ff,
3812 },
3813 },
3814 expectedVersion: VersionTLS12,
3815 })
3816 testCases = append(testCases, testCase{
3817 protocol: dtls,
3818 testType: serverTest,
3819 name: "MajorVersionTolerance-DTLS",
3820 config: Config{
3821 Bugs: ProtocolBugs{
3822 SendClientVersion: 0x0400,
3823 },
3824 },
3825 expectedVersion: VersionTLS12,
3826 })
3827
3828 // Test that versions below 3.0 are rejected.
3829 testCases = append(testCases, testCase{
3830 testType: serverTest,
3831 name: "VersionTooLow",
3832 config: Config{
3833 Bugs: ProtocolBugs{
3834 SendClientVersion: 0x0200,
3835 },
3836 },
3837 shouldFail: true,
3838 expectedError: ":UNSUPPORTED_PROTOCOL:",
3839 })
3840 testCases = append(testCases, testCase{
3841 protocol: dtls,
3842 testType: serverTest,
3843 name: "VersionTooLow-DTLS",
3844 config: Config{
3845 Bugs: ProtocolBugs{
3846 // 0x0201 is the lowest version expressable in
3847 // DTLS.
3848 SendClientVersion: 0x0201,
3849 },
3850 },
3851 shouldFail: true,
3852 expectedError: ":UNSUPPORTED_PROTOCOL:",
3853 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003854
3855 // Test TLS 1.3's downgrade signal.
3856 testCases = append(testCases, testCase{
3857 name: "Downgrade-TLS12-Client",
3858 config: Config{
3859 Bugs: ProtocolBugs{
3860 NegotiateVersion: VersionTLS12,
3861 },
3862 },
3863 shouldFail: true,
3864 expectedError: ":DOWNGRADE_DETECTED:",
3865 })
3866 testCases = append(testCases, testCase{
3867 testType: serverTest,
3868 name: "Downgrade-TLS12-Server",
3869 config: Config{
3870 Bugs: ProtocolBugs{
3871 SendClientVersion: VersionTLS12,
3872 },
3873 },
3874 shouldFail: true,
3875 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3876 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02003877
3878 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
3879 // behave correctly when both real maximum and fallback versions are
3880 // set.
3881 testCases = append(testCases, testCase{
3882 name: "Downgrade-TLS12-Client-Fallback",
3883 config: Config{
3884 Bugs: ProtocolBugs{
3885 FailIfNotFallbackSCSV: true,
3886 },
3887 },
3888 flags: []string{
3889 "-max-version", strconv.Itoa(VersionTLS13),
3890 "-fallback-version", strconv.Itoa(VersionTLS12),
3891 },
3892 shouldFail: true,
3893 expectedError: ":DOWNGRADE_DETECTED:",
3894 })
3895 testCases = append(testCases, testCase{
3896 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
3897 flags: []string{
3898 "-max-version", strconv.Itoa(VersionTLS12),
3899 "-fallback-version", strconv.Itoa(VersionTLS12),
3900 },
3901 })
3902
3903 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
3904 // just have such connections fail than risk getting confused because we
3905 // didn't sent the 1.3 ClientHello.)
3906 testCases = append(testCases, testCase{
3907 name: "Downgrade-TLS12-Fallback-CheckVersion",
3908 config: Config{
3909 Bugs: ProtocolBugs{
3910 NegotiateVersion: VersionTLS13,
3911 FailIfNotFallbackSCSV: true,
3912 },
3913 },
3914 flags: []string{
3915 "-max-version", strconv.Itoa(VersionTLS13),
3916 "-fallback-version", strconv.Itoa(VersionTLS12),
3917 },
3918 shouldFail: true,
3919 expectedError: ":UNSUPPORTED_PROTOCOL:",
3920 })
3921
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003922}
3923
David Benjaminaccb4542014-12-12 23:44:33 -05003924func addMinimumVersionTests() {
3925 for i, shimVers := range tlsVersions {
3926 // Assemble flags to disable all older versions on the shim.
3927 var flags []string
3928 for _, vers := range tlsVersions[:i] {
3929 flags = append(flags, vers.flag)
3930 }
3931
3932 for _, runnerVers := range tlsVersions {
3933 protocols := []protocol{tls}
3934 if runnerVers.hasDTLS && shimVers.hasDTLS {
3935 protocols = append(protocols, dtls)
3936 }
3937 for _, protocol := range protocols {
3938 suffix := shimVers.name + "-" + runnerVers.name
3939 if protocol == dtls {
3940 suffix += "-DTLS"
3941 }
3942 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3943
David Benjaminaccb4542014-12-12 23:44:33 -05003944 var expectedVersion uint16
3945 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003946 var expectedClientError, expectedServerError string
3947 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003948 if runnerVers.version >= shimVers.version {
3949 expectedVersion = runnerVers.version
3950 } else {
3951 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003952 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3953 expectedServerLocalError = "remote error: protocol version not supported"
3954 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3955 // If the client's minimum version is TLS 1.3 and the runner's
3956 // maximum is below TLS 1.2, the runner will fail to select a
3957 // cipher before the shim rejects the selected version.
3958 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3959 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3960 } else {
3961 expectedClientError = expectedServerError
3962 expectedClientLocalError = expectedServerLocalError
3963 }
David Benjaminaccb4542014-12-12 23:44:33 -05003964 }
3965
3966 testCases = append(testCases, testCase{
3967 protocol: protocol,
3968 testType: clientTest,
3969 name: "MinimumVersion-Client-" + suffix,
3970 config: Config{
3971 MaxVersion: runnerVers.version,
3972 },
David Benjamin87909c02014-12-13 01:55:01 -05003973 flags: flags,
3974 expectedVersion: expectedVersion,
3975 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003976 expectedError: expectedClientError,
3977 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003978 })
3979 testCases = append(testCases, testCase{
3980 protocol: protocol,
3981 testType: clientTest,
3982 name: "MinimumVersion-Client2-" + suffix,
3983 config: Config{
3984 MaxVersion: runnerVers.version,
3985 },
David Benjamin87909c02014-12-13 01:55:01 -05003986 flags: []string{"-min-version", shimVersFlag},
3987 expectedVersion: expectedVersion,
3988 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003989 expectedError: expectedClientError,
3990 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003991 })
3992
3993 testCases = append(testCases, testCase{
3994 protocol: protocol,
3995 testType: serverTest,
3996 name: "MinimumVersion-Server-" + suffix,
3997 config: Config{
3998 MaxVersion: runnerVers.version,
3999 },
David Benjamin87909c02014-12-13 01:55:01 -05004000 flags: flags,
4001 expectedVersion: expectedVersion,
4002 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004003 expectedError: expectedServerError,
4004 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004005 })
4006 testCases = append(testCases, testCase{
4007 protocol: protocol,
4008 testType: serverTest,
4009 name: "MinimumVersion-Server2-" + suffix,
4010 config: Config{
4011 MaxVersion: runnerVers.version,
4012 },
David Benjamin87909c02014-12-13 01:55:01 -05004013 flags: []string{"-min-version", shimVersFlag},
4014 expectedVersion: expectedVersion,
4015 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004016 expectedError: expectedServerError,
4017 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004018 })
4019 }
4020 }
4021 }
4022}
4023
David Benjamine78bfde2014-09-06 12:45:15 -04004024func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004025 // TODO(davidben): Extensions, where applicable, all move their server
4026 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4027 // tests for both. Also test interaction with 0-RTT when implemented.
4028
David Benjamin97d17d92016-07-14 16:12:00 -04004029 // Repeat extensions tests all versions except SSL 3.0.
4030 for _, ver := range tlsVersions {
4031 if ver.version == VersionSSL30 {
4032 continue
4033 }
4034
4035 // TODO(davidben): Implement resumption in TLS 1.3.
4036 resumeSession := ver.version < VersionTLS13
4037
4038 // Test that duplicate extensions are rejected.
4039 testCases = append(testCases, testCase{
4040 testType: clientTest,
4041 name: "DuplicateExtensionClient-" + ver.name,
4042 config: Config{
4043 MaxVersion: ver.version,
4044 Bugs: ProtocolBugs{
4045 DuplicateExtension: true,
4046 },
David Benjamine78bfde2014-09-06 12:45:15 -04004047 },
David Benjamin97d17d92016-07-14 16:12:00 -04004048 shouldFail: true,
4049 expectedLocalError: "remote error: error decoding message",
4050 })
4051 testCases = append(testCases, testCase{
4052 testType: serverTest,
4053 name: "DuplicateExtensionServer-" + ver.name,
4054 config: Config{
4055 MaxVersion: ver.version,
4056 Bugs: ProtocolBugs{
4057 DuplicateExtension: true,
4058 },
David Benjamine78bfde2014-09-06 12:45:15 -04004059 },
David Benjamin97d17d92016-07-14 16:12:00 -04004060 shouldFail: true,
4061 expectedLocalError: "remote error: error decoding message",
4062 })
4063
4064 // Test SNI.
4065 testCases = append(testCases, testCase{
4066 testType: clientTest,
4067 name: "ServerNameExtensionClient-" + ver.name,
4068 config: Config{
4069 MaxVersion: ver.version,
4070 Bugs: ProtocolBugs{
4071 ExpectServerName: "example.com",
4072 },
David Benjamine78bfde2014-09-06 12:45:15 -04004073 },
David Benjamin97d17d92016-07-14 16:12:00 -04004074 flags: []string{"-host-name", "example.com"},
4075 })
4076 testCases = append(testCases, testCase{
4077 testType: clientTest,
4078 name: "ServerNameExtensionClientMismatch-" + ver.name,
4079 config: Config{
4080 MaxVersion: ver.version,
4081 Bugs: ProtocolBugs{
4082 ExpectServerName: "mismatch.com",
4083 },
David Benjamine78bfde2014-09-06 12:45:15 -04004084 },
David Benjamin97d17d92016-07-14 16:12:00 -04004085 flags: []string{"-host-name", "example.com"},
4086 shouldFail: true,
4087 expectedLocalError: "tls: unexpected server name",
4088 })
4089 testCases = append(testCases, testCase{
4090 testType: clientTest,
4091 name: "ServerNameExtensionClientMissing-" + ver.name,
4092 config: Config{
4093 MaxVersion: ver.version,
4094 Bugs: ProtocolBugs{
4095 ExpectServerName: "missing.com",
4096 },
David Benjamine78bfde2014-09-06 12:45:15 -04004097 },
David Benjamin97d17d92016-07-14 16:12:00 -04004098 shouldFail: true,
4099 expectedLocalError: "tls: unexpected server name",
4100 })
4101 testCases = append(testCases, testCase{
4102 testType: serverTest,
4103 name: "ServerNameExtensionServer-" + ver.name,
4104 config: Config{
4105 MaxVersion: ver.version,
4106 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004107 },
David Benjamin97d17d92016-07-14 16:12:00 -04004108 flags: []string{"-expect-server-name", "example.com"},
4109 resumeSession: resumeSession,
4110 })
4111
4112 // Test ALPN.
4113 testCases = append(testCases, testCase{
4114 testType: clientTest,
4115 name: "ALPNClient-" + ver.name,
4116 config: Config{
4117 MaxVersion: ver.version,
4118 NextProtos: []string{"foo"},
4119 },
4120 flags: []string{
4121 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4122 "-expect-alpn", "foo",
4123 },
4124 expectedNextProto: "foo",
4125 expectedNextProtoType: alpn,
4126 resumeSession: resumeSession,
4127 })
4128 testCases = append(testCases, testCase{
4129 testType: serverTest,
4130 name: "ALPNServer-" + ver.name,
4131 config: Config{
4132 MaxVersion: ver.version,
4133 NextProtos: []string{"foo", "bar", "baz"},
4134 },
4135 flags: []string{
4136 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4137 "-select-alpn", "foo",
4138 },
4139 expectedNextProto: "foo",
4140 expectedNextProtoType: alpn,
4141 resumeSession: resumeSession,
4142 })
4143 testCases = append(testCases, testCase{
4144 testType: serverTest,
4145 name: "ALPNServer-Decline-" + ver.name,
4146 config: Config{
4147 MaxVersion: ver.version,
4148 NextProtos: []string{"foo", "bar", "baz"},
4149 },
4150 flags: []string{"-decline-alpn"},
4151 expectNoNextProto: true,
4152 resumeSession: resumeSession,
4153 })
4154
4155 var emptyString string
4156 testCases = append(testCases, testCase{
4157 testType: clientTest,
4158 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4159 config: Config{
4160 MaxVersion: ver.version,
4161 NextProtos: []string{""},
4162 Bugs: ProtocolBugs{
4163 // A server returning an empty ALPN protocol
4164 // should be rejected.
4165 ALPNProtocol: &emptyString,
4166 },
4167 },
4168 flags: []string{
4169 "-advertise-alpn", "\x03foo",
4170 },
4171 shouldFail: true,
4172 expectedError: ":PARSE_TLSEXT:",
4173 })
4174 testCases = append(testCases, testCase{
4175 testType: serverTest,
4176 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4177 config: Config{
4178 MaxVersion: ver.version,
4179 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004180 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004181 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004182 },
David Benjamin97d17d92016-07-14 16:12:00 -04004183 flags: []string{
4184 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004185 },
David Benjamin97d17d92016-07-14 16:12:00 -04004186 shouldFail: true,
4187 expectedError: ":PARSE_TLSEXT:",
4188 })
4189
4190 // Test NPN and the interaction with ALPN.
4191 if ver.version < VersionTLS13 {
4192 // Test that the server prefers ALPN over NPN.
4193 testCases = append(testCases, testCase{
4194 testType: serverTest,
4195 name: "ALPNServer-Preferred-" + ver.name,
4196 config: Config{
4197 MaxVersion: ver.version,
4198 NextProtos: []string{"foo", "bar", "baz"},
4199 },
4200 flags: []string{
4201 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4202 "-select-alpn", "foo",
4203 "-advertise-npn", "\x03foo\x03bar\x03baz",
4204 },
4205 expectedNextProto: "foo",
4206 expectedNextProtoType: alpn,
4207 resumeSession: resumeSession,
4208 })
4209 testCases = append(testCases, testCase{
4210 testType: serverTest,
4211 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4212 config: Config{
4213 MaxVersion: ver.version,
4214 NextProtos: []string{"foo", "bar", "baz"},
4215 Bugs: ProtocolBugs{
4216 SwapNPNAndALPN: true,
4217 },
4218 },
4219 flags: []string{
4220 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4221 "-select-alpn", "foo",
4222 "-advertise-npn", "\x03foo\x03bar\x03baz",
4223 },
4224 expectedNextProto: "foo",
4225 expectedNextProtoType: alpn,
4226 resumeSession: resumeSession,
4227 })
4228
4229 // Test that negotiating both NPN and ALPN is forbidden.
4230 testCases = append(testCases, testCase{
4231 name: "NegotiateALPNAndNPN-" + ver.name,
4232 config: Config{
4233 MaxVersion: ver.version,
4234 NextProtos: []string{"foo", "bar", "baz"},
4235 Bugs: ProtocolBugs{
4236 NegotiateALPNAndNPN: true,
4237 },
4238 },
4239 flags: []string{
4240 "-advertise-alpn", "\x03foo",
4241 "-select-next-proto", "foo",
4242 },
4243 shouldFail: true,
4244 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4245 })
4246 testCases = append(testCases, testCase{
4247 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4248 config: Config{
4249 MaxVersion: ver.version,
4250 NextProtos: []string{"foo", "bar", "baz"},
4251 Bugs: ProtocolBugs{
4252 NegotiateALPNAndNPN: true,
4253 SwapNPNAndALPN: true,
4254 },
4255 },
4256 flags: []string{
4257 "-advertise-alpn", "\x03foo",
4258 "-select-next-proto", "foo",
4259 },
4260 shouldFail: true,
4261 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4262 })
4263
4264 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4265 testCases = append(testCases, testCase{
4266 name: "DisableNPN-" + ver.name,
4267 config: Config{
4268 MaxVersion: ver.version,
4269 NextProtos: []string{"foo"},
4270 },
4271 flags: []string{
4272 "-select-next-proto", "foo",
4273 "-disable-npn",
4274 },
4275 expectNoNextProto: true,
4276 })
4277 }
4278
4279 // Test ticket behavior.
4280 //
4281 // TODO(davidben): Add TLS 1.3 versions of these.
4282 if ver.version < VersionTLS13 {
4283 // Resume with a corrupt ticket.
4284 testCases = append(testCases, testCase{
4285 testType: serverTest,
4286 name: "CorruptTicket-" + ver.name,
4287 config: Config{
4288 MaxVersion: ver.version,
4289 Bugs: ProtocolBugs{
4290 CorruptTicket: true,
4291 },
4292 },
4293 resumeSession: true,
4294 expectResumeRejected: true,
4295 })
4296 // Test the ticket callback, with and without renewal.
4297 testCases = append(testCases, testCase{
4298 testType: serverTest,
4299 name: "TicketCallback-" + ver.name,
4300 config: Config{
4301 MaxVersion: ver.version,
4302 },
4303 resumeSession: true,
4304 flags: []string{"-use-ticket-callback"},
4305 })
4306 testCases = append(testCases, testCase{
4307 testType: serverTest,
4308 name: "TicketCallback-Renew-" + ver.name,
4309 config: Config{
4310 MaxVersion: ver.version,
4311 Bugs: ProtocolBugs{
4312 ExpectNewTicket: true,
4313 },
4314 },
4315 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4316 resumeSession: true,
4317 })
4318
4319 // Resume with an oversized session id.
4320 testCases = append(testCases, testCase{
4321 testType: serverTest,
4322 name: "OversizedSessionId-" + ver.name,
4323 config: Config{
4324 MaxVersion: ver.version,
4325 Bugs: ProtocolBugs{
4326 OversizedSessionId: true,
4327 },
4328 },
4329 resumeSession: true,
4330 shouldFail: true,
4331 expectedError: ":DECODE_ERROR:",
4332 })
4333 }
4334
4335 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4336 // are ignored.
4337 if ver.hasDTLS {
4338 testCases = append(testCases, testCase{
4339 protocol: dtls,
4340 name: "SRTP-Client-" + ver.name,
4341 config: Config{
4342 MaxVersion: ver.version,
4343 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4344 },
4345 flags: []string{
4346 "-srtp-profiles",
4347 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4348 },
4349 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4350 })
4351 testCases = append(testCases, testCase{
4352 protocol: dtls,
4353 testType: serverTest,
4354 name: "SRTP-Server-" + ver.name,
4355 config: Config{
4356 MaxVersion: ver.version,
4357 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4358 },
4359 flags: []string{
4360 "-srtp-profiles",
4361 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4362 },
4363 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4364 })
4365 // Test that the MKI is ignored.
4366 testCases = append(testCases, testCase{
4367 protocol: dtls,
4368 testType: serverTest,
4369 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4370 config: Config{
4371 MaxVersion: ver.version,
4372 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4373 Bugs: ProtocolBugs{
4374 SRTPMasterKeyIdentifer: "bogus",
4375 },
4376 },
4377 flags: []string{
4378 "-srtp-profiles",
4379 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4380 },
4381 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4382 })
4383 // Test that SRTP isn't negotiated on the server if there were
4384 // no matching profiles.
4385 testCases = append(testCases, testCase{
4386 protocol: dtls,
4387 testType: serverTest,
4388 name: "SRTP-Server-NoMatch-" + ver.name,
4389 config: Config{
4390 MaxVersion: ver.version,
4391 SRTPProtectionProfiles: []uint16{100, 101, 102},
4392 },
4393 flags: []string{
4394 "-srtp-profiles",
4395 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4396 },
4397 expectedSRTPProtectionProfile: 0,
4398 })
4399 // Test that the server returning an invalid SRTP profile is
4400 // flagged as an error by the client.
4401 testCases = append(testCases, testCase{
4402 protocol: dtls,
4403 name: "SRTP-Client-NoMatch-" + ver.name,
4404 config: Config{
4405 MaxVersion: ver.version,
4406 Bugs: ProtocolBugs{
4407 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4408 },
4409 },
4410 flags: []string{
4411 "-srtp-profiles",
4412 "SRTP_AES128_CM_SHA1_80",
4413 },
4414 shouldFail: true,
4415 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4416 })
4417 }
4418
4419 // Test SCT list.
4420 testCases = append(testCases, testCase{
4421 name: "SignedCertificateTimestampList-Client-" + ver.name,
4422 testType: clientTest,
4423 config: Config{
4424 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004425 },
David Benjamin97d17d92016-07-14 16:12:00 -04004426 flags: []string{
4427 "-enable-signed-cert-timestamps",
4428 "-expect-signed-cert-timestamps",
4429 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004430 },
David Benjamin97d17d92016-07-14 16:12:00 -04004431 resumeSession: resumeSession,
4432 })
4433 testCases = append(testCases, testCase{
4434 name: "SendSCTListOnResume-" + ver.name,
4435 config: Config{
4436 MaxVersion: ver.version,
4437 Bugs: ProtocolBugs{
4438 SendSCTListOnResume: []byte("bogus"),
4439 },
David Benjamind98452d2015-06-16 14:16:23 -04004440 },
David Benjamin97d17d92016-07-14 16:12:00 -04004441 flags: []string{
4442 "-enable-signed-cert-timestamps",
4443 "-expect-signed-cert-timestamps",
4444 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004445 },
David Benjamin97d17d92016-07-14 16:12:00 -04004446 resumeSession: resumeSession,
4447 })
4448 testCases = append(testCases, testCase{
4449 name: "SignedCertificateTimestampList-Server-" + ver.name,
4450 testType: serverTest,
4451 config: Config{
4452 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004453 },
David Benjamin97d17d92016-07-14 16:12:00 -04004454 flags: []string{
4455 "-signed-cert-timestamps",
4456 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004457 },
David Benjamin97d17d92016-07-14 16:12:00 -04004458 expectedSCTList: testSCTList,
4459 resumeSession: resumeSession,
4460 })
4461 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004462
Paul Lietar4fac72e2015-09-09 13:44:55 +01004463 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004464 testType: clientTest,
4465 name: "ClientHelloPadding",
4466 config: Config{
4467 Bugs: ProtocolBugs{
4468 RequireClientHelloSize: 512,
4469 },
4470 },
4471 // This hostname just needs to be long enough to push the
4472 // ClientHello into F5's danger zone between 256 and 511 bytes
4473 // long.
4474 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4475 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004476
4477 // Extensions should not function in SSL 3.0.
4478 testCases = append(testCases, testCase{
4479 testType: serverTest,
4480 name: "SSLv3Extensions-NoALPN",
4481 config: Config{
4482 MaxVersion: VersionSSL30,
4483 NextProtos: []string{"foo", "bar", "baz"},
4484 },
4485 flags: []string{
4486 "-select-alpn", "foo",
4487 },
4488 expectNoNextProto: true,
4489 })
4490
4491 // Test session tickets separately as they follow a different codepath.
4492 testCases = append(testCases, testCase{
4493 testType: serverTest,
4494 name: "SSLv3Extensions-NoTickets",
4495 config: Config{
4496 MaxVersion: VersionSSL30,
4497 Bugs: ProtocolBugs{
4498 // Historically, session tickets in SSL 3.0
4499 // failed in different ways depending on whether
4500 // the client supported renegotiation_info.
4501 NoRenegotiationInfo: true,
4502 },
4503 },
4504 resumeSession: true,
4505 })
4506 testCases = append(testCases, testCase{
4507 testType: serverTest,
4508 name: "SSLv3Extensions-NoTickets2",
4509 config: Config{
4510 MaxVersion: VersionSSL30,
4511 },
4512 resumeSession: true,
4513 })
4514
4515 // But SSL 3.0 does send and process renegotiation_info.
4516 testCases = append(testCases, testCase{
4517 testType: serverTest,
4518 name: "SSLv3Extensions-RenegotiationInfo",
4519 config: Config{
4520 MaxVersion: VersionSSL30,
4521 Bugs: ProtocolBugs{
4522 RequireRenegotiationInfo: true,
4523 },
4524 },
4525 })
4526 testCases = append(testCases, testCase{
4527 testType: serverTest,
4528 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4529 config: Config{
4530 MaxVersion: VersionSSL30,
4531 Bugs: ProtocolBugs{
4532 NoRenegotiationInfo: true,
4533 SendRenegotiationSCSV: true,
4534 RequireRenegotiationInfo: true,
4535 },
4536 },
4537 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004538
4539 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4540 // in ServerHello.
4541 testCases = append(testCases, testCase{
4542 name: "NPN-Forbidden-TLS13",
4543 config: Config{
4544 MaxVersion: VersionTLS13,
4545 NextProtos: []string{"foo"},
4546 Bugs: ProtocolBugs{
4547 NegotiateNPNAtAllVersions: true,
4548 },
4549 },
4550 flags: []string{"-select-next-proto", "foo"},
4551 shouldFail: true,
4552 expectedError: ":ERROR_PARSING_EXTENSION:",
4553 })
4554 testCases = append(testCases, testCase{
4555 name: "EMS-Forbidden-TLS13",
4556 config: Config{
4557 MaxVersion: VersionTLS13,
4558 Bugs: ProtocolBugs{
4559 NegotiateEMSAtAllVersions: true,
4560 },
4561 },
4562 shouldFail: true,
4563 expectedError: ":ERROR_PARSING_EXTENSION:",
4564 })
4565 testCases = append(testCases, testCase{
4566 name: "RenegotiationInfo-Forbidden-TLS13",
4567 config: Config{
4568 MaxVersion: VersionTLS13,
4569 Bugs: ProtocolBugs{
4570 NegotiateRenegotiationInfoAtAllVersions: true,
4571 },
4572 },
4573 shouldFail: true,
4574 expectedError: ":ERROR_PARSING_EXTENSION:",
4575 })
4576 testCases = append(testCases, testCase{
4577 name: "ChannelID-Forbidden-TLS13",
4578 config: Config{
4579 MaxVersion: VersionTLS13,
4580 RequestChannelID: true,
4581 Bugs: ProtocolBugs{
4582 NegotiateChannelIDAtAllVersions: true,
4583 },
4584 },
4585 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4586 shouldFail: true,
4587 expectedError: ":ERROR_PARSING_EXTENSION:",
4588 })
4589 testCases = append(testCases, testCase{
4590 name: "Ticket-Forbidden-TLS13",
4591 config: Config{
4592 MaxVersion: VersionTLS12,
4593 },
4594 resumeConfig: &Config{
4595 MaxVersion: VersionTLS13,
4596 Bugs: ProtocolBugs{
4597 AdvertiseTicketExtension: true,
4598 },
4599 },
4600 resumeSession: true,
4601 shouldFail: true,
4602 expectedError: ":ERROR_PARSING_EXTENSION:",
4603 })
4604
4605 // Test that illegal extensions in TLS 1.3 are declined by the server if
4606 // offered in ClientHello. The runner's server will fail if this occurs,
4607 // so we exercise the offering path. (EMS and Renegotiation Info are
4608 // implicit in every test.)
4609 testCases = append(testCases, testCase{
4610 testType: serverTest,
4611 name: "ChannelID-Declined-TLS13",
4612 config: Config{
4613 MaxVersion: VersionTLS13,
4614 ChannelID: channelIDKey,
4615 },
4616 flags: []string{"-enable-channel-id"},
4617 })
4618 testCases = append(testCases, testCase{
4619 testType: serverTest,
4620 name: "NPN-Server",
4621 config: Config{
4622 MaxVersion: VersionTLS13,
4623 NextProtos: []string{"bar"},
4624 },
4625 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4626 })
David Benjamine78bfde2014-09-06 12:45:15 -04004627}
4628
David Benjamin01fe8202014-09-24 15:21:44 -04004629func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004630 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004631 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4632 if sessionVers.version >= VersionTLS13 {
4633 continue
4634 }
David Benjamin01fe8202014-09-24 15:21:44 -04004635 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004636 if resumeVers.version >= VersionTLS13 {
4637 continue
4638 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004639 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4640 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4641 // TLS 1.3 only shares ciphers with TLS 1.2, so
4642 // we skip certain combinations and use a
4643 // different cipher to test with.
4644 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4645 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4646 continue
4647 }
4648 }
4649
David Benjamin8b8c0062014-11-23 02:47:52 -05004650 protocols := []protocol{tls}
4651 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4652 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004653 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004654 for _, protocol := range protocols {
4655 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4656 if protocol == dtls {
4657 suffix += "-DTLS"
4658 }
4659
David Benjaminece3de92015-03-16 18:02:20 -04004660 if sessionVers.version == resumeVers.version {
4661 testCases = append(testCases, testCase{
4662 protocol: protocol,
4663 name: "Resume-Client" + suffix,
4664 resumeSession: true,
4665 config: Config{
4666 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004667 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004668 },
David Benjaminece3de92015-03-16 18:02:20 -04004669 expectedVersion: sessionVers.version,
4670 expectedResumeVersion: resumeVers.version,
4671 })
4672 } else {
4673 testCases = append(testCases, testCase{
4674 protocol: protocol,
4675 name: "Resume-Client-Mismatch" + suffix,
4676 resumeSession: true,
4677 config: Config{
4678 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004679 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004680 },
David Benjaminece3de92015-03-16 18:02:20 -04004681 expectedVersion: sessionVers.version,
4682 resumeConfig: &Config{
4683 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004684 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004685 Bugs: ProtocolBugs{
4686 AllowSessionVersionMismatch: true,
4687 },
4688 },
4689 expectedResumeVersion: resumeVers.version,
4690 shouldFail: true,
4691 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4692 })
4693 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004694
4695 testCases = append(testCases, testCase{
4696 protocol: protocol,
4697 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004698 resumeSession: true,
4699 config: Config{
4700 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004701 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004702 },
4703 expectedVersion: sessionVers.version,
4704 resumeConfig: &Config{
4705 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004706 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004707 },
4708 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004709 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004710 expectedResumeVersion: resumeVers.version,
4711 })
4712
David Benjamin8b8c0062014-11-23 02:47:52 -05004713 testCases = append(testCases, testCase{
4714 protocol: protocol,
4715 testType: serverTest,
4716 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004717 resumeSession: true,
4718 config: Config{
4719 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004720 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004721 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004722 expectedVersion: sessionVers.version,
4723 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004724 resumeConfig: &Config{
4725 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004726 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004727 },
4728 expectedResumeVersion: resumeVers.version,
4729 })
4730 }
David Benjamin01fe8202014-09-24 15:21:44 -04004731 }
4732 }
David Benjaminece3de92015-03-16 18:02:20 -04004733
Nick Harper1fd39d82016-06-14 18:14:35 -07004734 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004735 testCases = append(testCases, testCase{
4736 name: "Resume-Client-CipherMismatch",
4737 resumeSession: true,
4738 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004739 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004740 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4741 },
4742 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004743 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004744 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4745 Bugs: ProtocolBugs{
4746 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4747 },
4748 },
4749 shouldFail: true,
4750 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4751 })
David Benjamin01fe8202014-09-24 15:21:44 -04004752}
4753
Adam Langley2ae77d22014-10-28 17:29:33 -07004754func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004755 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004756 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004757 testType: serverTest,
4758 name: "Renegotiate-Server-Forbidden",
4759 config: Config{
4760 MaxVersion: VersionTLS12,
4761 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004762 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004763 shouldFail: true,
4764 expectedError: ":NO_RENEGOTIATION:",
4765 expectedLocalError: "remote error: no renegotiation",
4766 })
Adam Langley5021b222015-06-12 18:27:58 -07004767 // The server shouldn't echo the renegotiation extension unless
4768 // requested by the client.
4769 testCases = append(testCases, testCase{
4770 testType: serverTest,
4771 name: "Renegotiate-Server-NoExt",
4772 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004773 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004774 Bugs: ProtocolBugs{
4775 NoRenegotiationInfo: true,
4776 RequireRenegotiationInfo: true,
4777 },
4778 },
4779 shouldFail: true,
4780 expectedLocalError: "renegotiation extension missing",
4781 })
4782 // The renegotiation SCSV should be sufficient for the server to echo
4783 // the extension.
4784 testCases = append(testCases, testCase{
4785 testType: serverTest,
4786 name: "Renegotiate-Server-NoExt-SCSV",
4787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004788 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004789 Bugs: ProtocolBugs{
4790 NoRenegotiationInfo: true,
4791 SendRenegotiationSCSV: true,
4792 RequireRenegotiationInfo: true,
4793 },
4794 },
4795 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004796 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004797 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004799 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004800 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004801 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004802 },
4803 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004804 renegotiate: 1,
4805 flags: []string{
4806 "-renegotiate-freely",
4807 "-expect-total-renegotiations", "1",
4808 },
David Benjamincdea40c2015-03-19 14:09:43 -04004809 })
4810 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004811 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004812 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004813 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004814 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004815 Bugs: ProtocolBugs{
4816 EmptyRenegotiationInfo: true,
4817 },
4818 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004819 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004820 shouldFail: true,
4821 expectedError: ":RENEGOTIATION_MISMATCH:",
4822 })
4823 testCases = append(testCases, testCase{
4824 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004825 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004827 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004828 Bugs: ProtocolBugs{
4829 BadRenegotiationInfo: true,
4830 },
4831 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004832 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004833 shouldFail: true,
4834 expectedError: ":RENEGOTIATION_MISMATCH:",
4835 })
4836 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004837 name: "Renegotiate-Client-Downgrade",
4838 renegotiate: 1,
4839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004840 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004841 Bugs: ProtocolBugs{
4842 NoRenegotiationInfoAfterInitial: true,
4843 },
4844 },
4845 flags: []string{"-renegotiate-freely"},
4846 shouldFail: true,
4847 expectedError: ":RENEGOTIATION_MISMATCH:",
4848 })
4849 testCases = append(testCases, testCase{
4850 name: "Renegotiate-Client-Upgrade",
4851 renegotiate: 1,
4852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004853 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004854 Bugs: ProtocolBugs{
4855 NoRenegotiationInfoInInitial: true,
4856 },
4857 },
4858 flags: []string{"-renegotiate-freely"},
4859 shouldFail: true,
4860 expectedError: ":RENEGOTIATION_MISMATCH:",
4861 })
4862 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004863 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004864 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004865 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004866 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004867 Bugs: ProtocolBugs{
4868 NoRenegotiationInfo: true,
4869 },
4870 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004871 flags: []string{
4872 "-renegotiate-freely",
4873 "-expect-total-renegotiations", "1",
4874 },
David Benjamincff0b902015-05-15 23:09:47 -04004875 })
4876 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004877 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004878 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004879 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004880 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004881 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4882 },
4883 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004884 flags: []string{
4885 "-renegotiate-freely",
4886 "-expect-total-renegotiations", "1",
4887 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004888 })
4889 testCases = append(testCases, testCase{
4890 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004891 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004892 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004893 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4895 },
4896 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004897 flags: []string{
4898 "-renegotiate-freely",
4899 "-expect-total-renegotiations", "1",
4900 },
David Benjaminb16346b2015-04-08 19:16:58 -04004901 })
4902 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004903 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004904 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004905 config: Config{
4906 MaxVersion: VersionTLS10,
4907 Bugs: ProtocolBugs{
4908 RequireSameRenegoClientVersion: true,
4909 },
4910 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004911 flags: []string{
4912 "-renegotiate-freely",
4913 "-expect-total-renegotiations", "1",
4914 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004915 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004916 testCases = append(testCases, testCase{
4917 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004918 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004919 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004920 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004921 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4922 NextProtos: []string{"foo"},
4923 },
4924 flags: []string{
4925 "-false-start",
4926 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004927 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004928 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004929 },
4930 shimWritesFirst: true,
4931 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004932
4933 // Client-side renegotiation controls.
4934 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004935 name: "Renegotiate-Client-Forbidden-1",
4936 config: Config{
4937 MaxVersion: VersionTLS12,
4938 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004939 renegotiate: 1,
4940 shouldFail: true,
4941 expectedError: ":NO_RENEGOTIATION:",
4942 expectedLocalError: "remote error: no renegotiation",
4943 })
4944 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004945 name: "Renegotiate-Client-Once-1",
4946 config: Config{
4947 MaxVersion: VersionTLS12,
4948 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004949 renegotiate: 1,
4950 flags: []string{
4951 "-renegotiate-once",
4952 "-expect-total-renegotiations", "1",
4953 },
4954 })
4955 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004956 name: "Renegotiate-Client-Freely-1",
4957 config: Config{
4958 MaxVersion: VersionTLS12,
4959 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004960 renegotiate: 1,
4961 flags: []string{
4962 "-renegotiate-freely",
4963 "-expect-total-renegotiations", "1",
4964 },
4965 })
4966 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004967 name: "Renegotiate-Client-Once-2",
4968 config: Config{
4969 MaxVersion: VersionTLS12,
4970 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004971 renegotiate: 2,
4972 flags: []string{"-renegotiate-once"},
4973 shouldFail: true,
4974 expectedError: ":NO_RENEGOTIATION:",
4975 expectedLocalError: "remote error: no renegotiation",
4976 })
4977 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004978 name: "Renegotiate-Client-Freely-2",
4979 config: Config{
4980 MaxVersion: VersionTLS12,
4981 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004982 renegotiate: 2,
4983 flags: []string{
4984 "-renegotiate-freely",
4985 "-expect-total-renegotiations", "2",
4986 },
4987 })
Adam Langley27a0d082015-11-03 13:34:10 -08004988 testCases = append(testCases, testCase{
4989 name: "Renegotiate-Client-NoIgnore",
4990 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004991 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004992 Bugs: ProtocolBugs{
4993 SendHelloRequestBeforeEveryAppDataRecord: true,
4994 },
4995 },
4996 shouldFail: true,
4997 expectedError: ":NO_RENEGOTIATION:",
4998 })
4999 testCases = append(testCases, testCase{
5000 name: "Renegotiate-Client-Ignore",
5001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005002 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005003 Bugs: ProtocolBugs{
5004 SendHelloRequestBeforeEveryAppDataRecord: true,
5005 },
5006 },
5007 flags: []string{
5008 "-renegotiate-ignore",
5009 "-expect-total-renegotiations", "0",
5010 },
5011 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005012
David Benjamin397c8e62016-07-08 14:14:36 -07005013 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005014 testCases = append(testCases, testCase{
5015 name: "StrayHelloRequest",
5016 config: Config{
5017 MaxVersion: VersionTLS12,
5018 Bugs: ProtocolBugs{
5019 SendHelloRequestBeforeEveryHandshakeMessage: true,
5020 },
5021 },
5022 })
5023 testCases = append(testCases, testCase{
5024 name: "StrayHelloRequest-Packed",
5025 config: Config{
5026 MaxVersion: VersionTLS12,
5027 Bugs: ProtocolBugs{
5028 PackHandshakeFlight: true,
5029 SendHelloRequestBeforeEveryHandshakeMessage: true,
5030 },
5031 },
5032 })
5033
David Benjamin12d2c482016-07-24 10:56:51 -04005034 // Test renegotiation works if HelloRequest and server Finished come in
5035 // the same record.
5036 testCases = append(testCases, testCase{
5037 name: "Renegotiate-Client-Packed",
5038 config: Config{
5039 MaxVersion: VersionTLS12,
5040 Bugs: ProtocolBugs{
5041 PackHandshakeFlight: true,
5042 PackHelloRequestWithFinished: true,
5043 },
5044 },
5045 renegotiate: 1,
5046 flags: []string{
5047 "-renegotiate-freely",
5048 "-expect-total-renegotiations", "1",
5049 },
5050 })
5051
David Benjamin397c8e62016-07-08 14:14:36 -07005052 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04005053 //
5054 // TODO(davidben): This test current asserts that we ignore
5055 // HelloRequests, but we actually should hard reject them. Fix this
5056 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07005057 testCases = append(testCases, testCase{
5058 name: "Renegotiate-Client-TLS13",
5059 config: Config{
5060 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005061 Bugs: ProtocolBugs{
5062 SendHelloRequestBeforeEveryAppDataRecord: true,
5063 },
David Benjamin397c8e62016-07-08 14:14:36 -07005064 },
David Benjamin397c8e62016-07-08 14:14:36 -07005065 flags: []string{
5066 "-renegotiate-freely",
5067 },
David Benjamin397c8e62016-07-08 14:14:36 -07005068 })
5069
5070 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5071 testCases = append(testCases, testCase{
5072 name: "StrayHelloRequest-TLS13",
5073 config: Config{
5074 MaxVersion: VersionTLS13,
5075 Bugs: ProtocolBugs{
5076 SendHelloRequestBeforeEveryHandshakeMessage: true,
5077 },
5078 },
5079 shouldFail: true,
5080 expectedError: ":UNEXPECTED_MESSAGE:",
5081 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005082}
5083
David Benjamin5e961c12014-11-07 01:48:35 -05005084func addDTLSReplayTests() {
5085 // Test that sequence number replays are detected.
5086 testCases = append(testCases, testCase{
5087 protocol: dtls,
5088 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005089 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005090 replayWrites: true,
5091 })
5092
David Benjamin8e6db492015-07-25 18:29:23 -04005093 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005094 // than the retransmit window.
5095 testCases = append(testCases, testCase{
5096 protocol: dtls,
5097 name: "DTLS-Replay-LargeGaps",
5098 config: Config{
5099 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005100 SequenceNumberMapping: func(in uint64) uint64 {
5101 return in * 127
5102 },
David Benjamin5e961c12014-11-07 01:48:35 -05005103 },
5104 },
David Benjamin8e6db492015-07-25 18:29:23 -04005105 messageCount: 200,
5106 replayWrites: true,
5107 })
5108
5109 // Test the incoming sequence number changing non-monotonically.
5110 testCases = append(testCases, testCase{
5111 protocol: dtls,
5112 name: "DTLS-Replay-NonMonotonic",
5113 config: Config{
5114 Bugs: ProtocolBugs{
5115 SequenceNumberMapping: func(in uint64) uint64 {
5116 return in ^ 31
5117 },
5118 },
5119 },
5120 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005121 replayWrites: true,
5122 })
5123}
5124
Nick Harper60edffd2016-06-21 15:19:24 -07005125var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005126 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005127 id signatureAlgorithm
5128 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005129}{
Nick Harper60edffd2016-06-21 15:19:24 -07005130 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5131 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5132 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5133 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005134 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005135 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5136 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5137 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005138 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5139 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5140 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005141 // Tests for key types prior to TLS 1.2.
5142 {"RSA", 0, testCertRSA},
5143 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005144}
5145
Nick Harper60edffd2016-06-21 15:19:24 -07005146const fakeSigAlg1 signatureAlgorithm = 0x2a01
5147const fakeSigAlg2 signatureAlgorithm = 0xff01
5148
5149func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005150 // Not all ciphers involve a signature. Advertise a list which gives all
5151 // versions a signing cipher.
5152 signingCiphers := []uint16{
5153 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5154 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5155 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5156 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5157 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5158 }
5159
David Benjaminca3d5452016-07-14 12:51:01 -04005160 var allAlgorithms []signatureAlgorithm
5161 for _, alg := range testSignatureAlgorithms {
5162 if alg.id != 0 {
5163 allAlgorithms = append(allAlgorithms, alg.id)
5164 }
5165 }
5166
Nick Harper60edffd2016-06-21 15:19:24 -07005167 // Make sure each signature algorithm works. Include some fake values in
5168 // the list and ensure they're ignored.
5169 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005170 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005171 if (ver.version < VersionTLS12) != (alg.id == 0) {
5172 continue
5173 }
5174
5175 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5176 // or remove it in C.
5177 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005178 continue
5179 }
Nick Harper60edffd2016-06-21 15:19:24 -07005180
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005181 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005182 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005183 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5184 shouldFail = true
5185 }
5186 // RSA-PSS does not exist in TLS 1.2.
5187 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5188 shouldFail = true
5189 }
5190
5191 var signError, verifyError string
5192 if shouldFail {
5193 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5194 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005195 }
David Benjamin000800a2014-11-14 01:43:59 -05005196
David Benjamin1fb125c2016-07-08 18:52:12 -07005197 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005198
David Benjamin7a41d372016-07-09 11:21:54 -07005199 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005200 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005201 config: Config{
5202 MaxVersion: ver.version,
5203 ClientAuth: RequireAnyClientCert,
5204 VerifySignatureAlgorithms: []signatureAlgorithm{
5205 fakeSigAlg1,
5206 alg.id,
5207 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005208 },
David Benjamin7a41d372016-07-09 11:21:54 -07005209 },
5210 flags: []string{
5211 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5212 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5213 "-enable-all-curves",
5214 },
5215 shouldFail: shouldFail,
5216 expectedError: signError,
5217 expectedPeerSignatureAlgorithm: alg.id,
5218 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005219
David Benjamin7a41d372016-07-09 11:21:54 -07005220 testCases = append(testCases, testCase{
5221 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005222 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005223 config: Config{
5224 MaxVersion: ver.version,
5225 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5226 SignSignatureAlgorithms: []signatureAlgorithm{
5227 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005228 },
David Benjamin7a41d372016-07-09 11:21:54 -07005229 Bugs: ProtocolBugs{
5230 SkipECDSACurveCheck: shouldFail,
5231 IgnoreSignatureVersionChecks: shouldFail,
5232 // The client won't advertise 1.3-only algorithms after
5233 // version negotiation.
5234 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005235 },
David Benjamin7a41d372016-07-09 11:21:54 -07005236 },
5237 flags: []string{
5238 "-require-any-client-certificate",
5239 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5240 "-enable-all-curves",
5241 },
5242 shouldFail: shouldFail,
5243 expectedError: verifyError,
5244 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005245
5246 testCases = append(testCases, testCase{
5247 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005248 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005249 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005250 MaxVersion: ver.version,
5251 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005252 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005253 fakeSigAlg1,
5254 alg.id,
5255 fakeSigAlg2,
5256 },
5257 },
5258 flags: []string{
5259 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5260 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5261 "-enable-all-curves",
5262 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005263 shouldFail: shouldFail,
5264 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005265 expectedPeerSignatureAlgorithm: alg.id,
5266 })
5267
5268 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005269 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005270 config: Config{
5271 MaxVersion: ver.version,
5272 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005273 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005274 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005275 alg.id,
5276 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005277 Bugs: ProtocolBugs{
5278 SkipECDSACurveCheck: shouldFail,
5279 IgnoreSignatureVersionChecks: shouldFail,
5280 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005281 },
5282 flags: []string{
5283 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5284 "-enable-all-curves",
5285 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005286 shouldFail: shouldFail,
5287 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005288 })
David Benjamin5208fd42016-07-13 21:43:25 -04005289
5290 if !shouldFail {
5291 testCases = append(testCases, testCase{
5292 testType: serverTest,
5293 name: "ClientAuth-InvalidSignature" + suffix,
5294 config: Config{
5295 MaxVersion: ver.version,
5296 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5297 SignSignatureAlgorithms: []signatureAlgorithm{
5298 alg.id,
5299 },
5300 Bugs: ProtocolBugs{
5301 InvalidSignature: true,
5302 },
5303 },
5304 flags: []string{
5305 "-require-any-client-certificate",
5306 "-enable-all-curves",
5307 },
5308 shouldFail: true,
5309 expectedError: ":BAD_SIGNATURE:",
5310 })
5311
5312 testCases = append(testCases, testCase{
5313 name: "ServerAuth-InvalidSignature" + suffix,
5314 config: Config{
5315 MaxVersion: ver.version,
5316 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5317 CipherSuites: signingCiphers,
5318 SignSignatureAlgorithms: []signatureAlgorithm{
5319 alg.id,
5320 },
5321 Bugs: ProtocolBugs{
5322 InvalidSignature: true,
5323 },
5324 },
5325 flags: []string{"-enable-all-curves"},
5326 shouldFail: true,
5327 expectedError: ":BAD_SIGNATURE:",
5328 })
5329 }
David Benjaminca3d5452016-07-14 12:51:01 -04005330
5331 if ver.version >= VersionTLS12 && !shouldFail {
5332 testCases = append(testCases, testCase{
5333 name: "ClientAuth-Sign-Negotiate" + suffix,
5334 config: Config{
5335 MaxVersion: ver.version,
5336 ClientAuth: RequireAnyClientCert,
5337 VerifySignatureAlgorithms: allAlgorithms,
5338 },
5339 flags: []string{
5340 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5341 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5342 "-enable-all-curves",
5343 "-signing-prefs", strconv.Itoa(int(alg.id)),
5344 },
5345 expectedPeerSignatureAlgorithm: alg.id,
5346 })
5347
5348 testCases = append(testCases, testCase{
5349 testType: serverTest,
5350 name: "ServerAuth-Sign-Negotiate" + suffix,
5351 config: Config{
5352 MaxVersion: ver.version,
5353 CipherSuites: signingCiphers,
5354 VerifySignatureAlgorithms: allAlgorithms,
5355 },
5356 flags: []string{
5357 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5358 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5359 "-enable-all-curves",
5360 "-signing-prefs", strconv.Itoa(int(alg.id)),
5361 },
5362 expectedPeerSignatureAlgorithm: alg.id,
5363 })
5364 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005365 }
David Benjamin000800a2014-11-14 01:43:59 -05005366 }
5367
Nick Harper60edffd2016-06-21 15:19:24 -07005368 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005369 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005370 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005371 config: Config{
5372 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005373 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005374 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005375 signatureECDSAWithP521AndSHA512,
5376 signatureRSAPKCS1WithSHA384,
5377 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005378 },
5379 },
5380 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005381 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5382 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005383 },
Nick Harper60edffd2016-06-21 15:19:24 -07005384 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005385 })
5386
5387 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005388 name: "ClientAuth-SignatureType-TLS13",
5389 config: Config{
5390 ClientAuth: RequireAnyClientCert,
5391 MaxVersion: VersionTLS13,
5392 VerifySignatureAlgorithms: []signatureAlgorithm{
5393 signatureECDSAWithP521AndSHA512,
5394 signatureRSAPKCS1WithSHA384,
5395 signatureRSAPSSWithSHA384,
5396 signatureECDSAWithSHA1,
5397 },
5398 },
5399 flags: []string{
5400 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5401 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5402 },
5403 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5404 })
5405
5406 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005407 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005408 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005409 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005410 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005411 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005412 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005413 signatureECDSAWithP521AndSHA512,
5414 signatureRSAPKCS1WithSHA384,
5415 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005416 },
5417 },
Nick Harper60edffd2016-06-21 15:19:24 -07005418 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005419 })
5420
Steven Valdez143e8b32016-07-11 13:19:03 -04005421 testCases = append(testCases, testCase{
5422 testType: serverTest,
5423 name: "ServerAuth-SignatureType-TLS13",
5424 config: Config{
5425 MaxVersion: VersionTLS13,
5426 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5427 VerifySignatureAlgorithms: []signatureAlgorithm{
5428 signatureECDSAWithP521AndSHA512,
5429 signatureRSAPKCS1WithSHA384,
5430 signatureRSAPSSWithSHA384,
5431 signatureECDSAWithSHA1,
5432 },
5433 },
5434 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5435 })
5436
David Benjamina95e9f32016-07-08 16:28:04 -07005437 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005438 testCases = append(testCases, testCase{
5439 testType: serverTest,
5440 name: "Verify-ClientAuth-SignatureType",
5441 config: Config{
5442 MaxVersion: VersionTLS12,
5443 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005444 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005445 signatureRSAPKCS1WithSHA256,
5446 },
5447 Bugs: ProtocolBugs{
5448 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5449 },
5450 },
5451 flags: []string{
5452 "-require-any-client-certificate",
5453 },
5454 shouldFail: true,
5455 expectedError: ":WRONG_SIGNATURE_TYPE:",
5456 })
5457
5458 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005459 testType: serverTest,
5460 name: "Verify-ClientAuth-SignatureType-TLS13",
5461 config: Config{
5462 MaxVersion: VersionTLS13,
5463 Certificates: []Certificate{rsaCertificate},
5464 SignSignatureAlgorithms: []signatureAlgorithm{
5465 signatureRSAPSSWithSHA256,
5466 },
5467 Bugs: ProtocolBugs{
5468 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5469 },
5470 },
5471 flags: []string{
5472 "-require-any-client-certificate",
5473 },
5474 shouldFail: true,
5475 expectedError: ":WRONG_SIGNATURE_TYPE:",
5476 })
5477
5478 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005479 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005480 config: Config{
5481 MaxVersion: VersionTLS12,
5482 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005483 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005484 signatureRSAPKCS1WithSHA256,
5485 },
5486 Bugs: ProtocolBugs{
5487 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5488 },
5489 },
5490 shouldFail: true,
5491 expectedError: ":WRONG_SIGNATURE_TYPE:",
5492 })
5493
Steven Valdez143e8b32016-07-11 13:19:03 -04005494 testCases = append(testCases, testCase{
5495 name: "Verify-ServerAuth-SignatureType-TLS13",
5496 config: Config{
5497 MaxVersion: VersionTLS13,
5498 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5499 SignSignatureAlgorithms: []signatureAlgorithm{
5500 signatureRSAPSSWithSHA256,
5501 },
5502 Bugs: ProtocolBugs{
5503 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5504 },
5505 },
5506 shouldFail: true,
5507 expectedError: ":WRONG_SIGNATURE_TYPE:",
5508 })
5509
David Benjamin51dd7d62016-07-08 16:07:01 -07005510 // Test that, if the list is missing, the peer falls back to SHA-1 in
5511 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005512 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005513 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005514 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005515 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005516 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005517 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005518 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005519 },
5520 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005521 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005522 },
5523 },
5524 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005525 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5526 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005527 },
5528 })
5529
5530 testCases = append(testCases, testCase{
5531 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005532 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005533 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005534 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005535 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005536 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005537 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005538 },
5539 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005540 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005541 },
5542 },
5543 })
David Benjamin72dc7832015-03-16 17:49:43 -04005544
David Benjamin51dd7d62016-07-08 16:07:01 -07005545 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005546 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005547 config: Config{
5548 MaxVersion: VersionTLS13,
5549 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005550 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005551 signatureRSAPKCS1WithSHA1,
5552 },
5553 Bugs: ProtocolBugs{
5554 NoSignatureAlgorithms: true,
5555 },
5556 },
5557 flags: []string{
5558 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5559 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5560 },
5561 shouldFail: true,
5562 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5563 })
5564
5565 testCases = append(testCases, testCase{
5566 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005567 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005568 config: Config{
5569 MaxVersion: VersionTLS13,
5570 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005571 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005572 signatureRSAPKCS1WithSHA1,
5573 },
5574 Bugs: ProtocolBugs{
5575 NoSignatureAlgorithms: true,
5576 },
5577 },
5578 shouldFail: true,
5579 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5580 })
5581
David Benjaminb62d2872016-07-18 14:55:02 +02005582 // Test that hash preferences are enforced. BoringSSL does not implement
5583 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005584 testCases = append(testCases, testCase{
5585 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005586 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005588 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005589 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005590 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005591 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005592 },
5593 Bugs: ProtocolBugs{
5594 IgnorePeerSignatureAlgorithmPreferences: true,
5595 },
5596 },
5597 flags: []string{"-require-any-client-certificate"},
5598 shouldFail: true,
5599 expectedError: ":WRONG_SIGNATURE_TYPE:",
5600 })
5601
5602 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005603 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005604 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005605 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005606 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005607 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005608 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005609 },
5610 Bugs: ProtocolBugs{
5611 IgnorePeerSignatureAlgorithmPreferences: true,
5612 },
5613 },
5614 shouldFail: true,
5615 expectedError: ":WRONG_SIGNATURE_TYPE:",
5616 })
David Benjaminb62d2872016-07-18 14:55:02 +02005617 testCases = append(testCases, testCase{
5618 testType: serverTest,
5619 name: "ClientAuth-Enforced-TLS13",
5620 config: Config{
5621 MaxVersion: VersionTLS13,
5622 Certificates: []Certificate{rsaCertificate},
5623 SignSignatureAlgorithms: []signatureAlgorithm{
5624 signatureRSAPKCS1WithMD5,
5625 },
5626 Bugs: ProtocolBugs{
5627 IgnorePeerSignatureAlgorithmPreferences: true,
5628 IgnoreSignatureVersionChecks: true,
5629 },
5630 },
5631 flags: []string{"-require-any-client-certificate"},
5632 shouldFail: true,
5633 expectedError: ":WRONG_SIGNATURE_TYPE:",
5634 })
5635
5636 testCases = append(testCases, testCase{
5637 name: "ServerAuth-Enforced-TLS13",
5638 config: Config{
5639 MaxVersion: VersionTLS13,
5640 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5641 SignSignatureAlgorithms: []signatureAlgorithm{
5642 signatureRSAPKCS1WithMD5,
5643 },
5644 Bugs: ProtocolBugs{
5645 IgnorePeerSignatureAlgorithmPreferences: true,
5646 IgnoreSignatureVersionChecks: true,
5647 },
5648 },
5649 shouldFail: true,
5650 expectedError: ":WRONG_SIGNATURE_TYPE:",
5651 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005652
5653 // Test that the agreed upon digest respects the client preferences and
5654 // the server digests.
5655 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005656 name: "NoCommonAlgorithms-Digests",
5657 config: Config{
5658 MaxVersion: VersionTLS12,
5659 ClientAuth: RequireAnyClientCert,
5660 VerifySignatureAlgorithms: []signatureAlgorithm{
5661 signatureRSAPKCS1WithSHA512,
5662 signatureRSAPKCS1WithSHA1,
5663 },
5664 },
5665 flags: []string{
5666 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5667 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5668 "-digest-prefs", "SHA256",
5669 },
5670 shouldFail: true,
5671 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5672 })
5673 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005674 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005675 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005676 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005677 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005678 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005679 signatureRSAPKCS1WithSHA512,
5680 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005681 },
5682 },
5683 flags: []string{
5684 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5685 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005686 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005687 },
David Benjaminca3d5452016-07-14 12:51:01 -04005688 shouldFail: true,
5689 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5690 })
5691 testCases = append(testCases, testCase{
5692 name: "NoCommonAlgorithms-TLS13",
5693 config: Config{
5694 MaxVersion: VersionTLS13,
5695 ClientAuth: RequireAnyClientCert,
5696 VerifySignatureAlgorithms: []signatureAlgorithm{
5697 signatureRSAPSSWithSHA512,
5698 signatureRSAPSSWithSHA384,
5699 },
5700 },
5701 flags: []string{
5702 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5703 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5704 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5705 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005706 shouldFail: true,
5707 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005708 })
5709 testCases = append(testCases, testCase{
5710 name: "Agree-Digest-SHA256",
5711 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005712 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005713 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005714 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005715 signatureRSAPKCS1WithSHA1,
5716 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005717 },
5718 },
5719 flags: []string{
5720 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5721 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005722 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005723 },
Nick Harper60edffd2016-06-21 15:19:24 -07005724 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005725 })
5726 testCases = append(testCases, testCase{
5727 name: "Agree-Digest-SHA1",
5728 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005729 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005730 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005731 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005732 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005733 },
5734 },
5735 flags: []string{
5736 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5737 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005738 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005739 },
Nick Harper60edffd2016-06-21 15:19:24 -07005740 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005741 })
5742 testCases = append(testCases, testCase{
5743 name: "Agree-Digest-Default",
5744 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005745 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005746 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005747 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005748 signatureRSAPKCS1WithSHA256,
5749 signatureECDSAWithP256AndSHA256,
5750 signatureRSAPKCS1WithSHA1,
5751 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005752 },
5753 },
5754 flags: []string{
5755 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5756 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5757 },
Nick Harper60edffd2016-06-21 15:19:24 -07005758 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005759 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005760
David Benjaminca3d5452016-07-14 12:51:01 -04005761 // Test that the signing preference list may include extra algorithms
5762 // without negotiation problems.
5763 testCases = append(testCases, testCase{
5764 testType: serverTest,
5765 name: "FilterExtraAlgorithms",
5766 config: Config{
5767 MaxVersion: VersionTLS12,
5768 VerifySignatureAlgorithms: []signatureAlgorithm{
5769 signatureRSAPKCS1WithSHA256,
5770 },
5771 },
5772 flags: []string{
5773 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5774 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5775 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5776 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5777 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5778 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5779 },
5780 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5781 })
5782
David Benjamin4c3ddf72016-06-29 18:13:53 -04005783 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5784 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005785 testCases = append(testCases, testCase{
5786 name: "CheckLeafCurve",
5787 config: Config{
5788 MaxVersion: VersionTLS12,
5789 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005790 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005791 },
5792 flags: []string{"-p384-only"},
5793 shouldFail: true,
5794 expectedError: ":BAD_ECC_CERT:",
5795 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005796
5797 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5798 testCases = append(testCases, testCase{
5799 name: "CheckLeafCurve-TLS13",
5800 config: Config{
5801 MaxVersion: VersionTLS13,
5802 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5803 Certificates: []Certificate{ecdsaP256Certificate},
5804 },
5805 flags: []string{"-p384-only"},
5806 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005807
5808 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5809 testCases = append(testCases, testCase{
5810 name: "ECDSACurveMismatch-Verify-TLS12",
5811 config: Config{
5812 MaxVersion: VersionTLS12,
5813 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5814 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005815 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005816 signatureECDSAWithP384AndSHA384,
5817 },
5818 },
5819 })
5820
5821 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5822 testCases = append(testCases, testCase{
5823 name: "ECDSACurveMismatch-Verify-TLS13",
5824 config: Config{
5825 MaxVersion: VersionTLS13,
5826 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5827 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005828 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005829 signatureECDSAWithP384AndSHA384,
5830 },
5831 Bugs: ProtocolBugs{
5832 SkipECDSACurveCheck: true,
5833 },
5834 },
5835 shouldFail: true,
5836 expectedError: ":WRONG_SIGNATURE_TYPE:",
5837 })
5838
5839 // Signature algorithm selection in TLS 1.3 should take the curve into
5840 // account.
5841 testCases = append(testCases, testCase{
5842 testType: serverTest,
5843 name: "ECDSACurveMismatch-Sign-TLS13",
5844 config: Config{
5845 MaxVersion: VersionTLS13,
5846 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005847 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005848 signatureECDSAWithP384AndSHA384,
5849 signatureECDSAWithP256AndSHA256,
5850 },
5851 },
5852 flags: []string{
5853 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5854 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5855 },
5856 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5857 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005858
5859 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5860 // server does not attempt to sign in that case.
5861 testCases = append(testCases, testCase{
5862 testType: serverTest,
5863 name: "RSA-PSS-Large",
5864 config: Config{
5865 MaxVersion: VersionTLS13,
5866 VerifySignatureAlgorithms: []signatureAlgorithm{
5867 signatureRSAPSSWithSHA512,
5868 },
5869 },
5870 flags: []string{
5871 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5872 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5873 },
5874 shouldFail: true,
5875 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5876 })
David Benjamin000800a2014-11-14 01:43:59 -05005877}
5878
David Benjamin83f90402015-01-27 01:09:43 -05005879// timeouts is the retransmit schedule for BoringSSL. It doubles and
5880// caps at 60 seconds. On the 13th timeout, it gives up.
5881var timeouts = []time.Duration{
5882 1 * time.Second,
5883 2 * time.Second,
5884 4 * time.Second,
5885 8 * time.Second,
5886 16 * time.Second,
5887 32 * time.Second,
5888 60 * time.Second,
5889 60 * time.Second,
5890 60 * time.Second,
5891 60 * time.Second,
5892 60 * time.Second,
5893 60 * time.Second,
5894 60 * time.Second,
5895}
5896
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005897// shortTimeouts is an alternate set of timeouts which would occur if the
5898// initial timeout duration was set to 250ms.
5899var shortTimeouts = []time.Duration{
5900 250 * time.Millisecond,
5901 500 * time.Millisecond,
5902 1 * time.Second,
5903 2 * time.Second,
5904 4 * time.Second,
5905 8 * time.Second,
5906 16 * time.Second,
5907 32 * time.Second,
5908 60 * time.Second,
5909 60 * time.Second,
5910 60 * time.Second,
5911 60 * time.Second,
5912 60 * time.Second,
5913}
5914
David Benjamin83f90402015-01-27 01:09:43 -05005915func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005916 // These tests work by coordinating some behavior on both the shim and
5917 // the runner.
5918 //
5919 // TimeoutSchedule configures the runner to send a series of timeout
5920 // opcodes to the shim (see packetAdaptor) immediately before reading
5921 // each peer handshake flight N. The timeout opcode both simulates a
5922 // timeout in the shim and acts as a synchronization point to help the
5923 // runner bracket each handshake flight.
5924 //
5925 // We assume the shim does not read from the channel eagerly. It must
5926 // first wait until it has sent flight N and is ready to receive
5927 // handshake flight N+1. At this point, it will process the timeout
5928 // opcode. It must then immediately respond with a timeout ACK and act
5929 // as if the shim was idle for the specified amount of time.
5930 //
5931 // The runner then drops all packets received before the ACK and
5932 // continues waiting for flight N. This ordering results in one attempt
5933 // at sending flight N to be dropped. For the test to complete, the
5934 // shim must send flight N again, testing that the shim implements DTLS
5935 // retransmit on a timeout.
5936
Steven Valdez143e8b32016-07-11 13:19:03 -04005937 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04005938 // likely be more epochs to cross and the final message's retransmit may
5939 // be more complex.
5940
David Benjamin585d7a42016-06-02 14:58:00 -04005941 for _, async := range []bool{true, false} {
5942 var tests []testCase
5943
5944 // Test that this is indeed the timeout schedule. Stress all
5945 // four patterns of handshake.
5946 for i := 1; i < len(timeouts); i++ {
5947 number := strconv.Itoa(i)
5948 tests = append(tests, testCase{
5949 protocol: dtls,
5950 name: "DTLS-Retransmit-Client-" + number,
5951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005952 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005953 Bugs: ProtocolBugs{
5954 TimeoutSchedule: timeouts[:i],
5955 },
5956 },
5957 resumeSession: true,
5958 })
5959 tests = append(tests, testCase{
5960 protocol: dtls,
5961 testType: serverTest,
5962 name: "DTLS-Retransmit-Server-" + number,
5963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005964 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005965 Bugs: ProtocolBugs{
5966 TimeoutSchedule: timeouts[:i],
5967 },
5968 },
5969 resumeSession: true,
5970 })
5971 }
5972
5973 // Test that exceeding the timeout schedule hits a read
5974 // timeout.
5975 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005976 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005977 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005979 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005980 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005981 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005982 },
5983 },
5984 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005985 shouldFail: true,
5986 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005987 })
David Benjamin585d7a42016-06-02 14:58:00 -04005988
5989 if async {
5990 // Test that timeout handling has a fudge factor, due to API
5991 // problems.
5992 tests = append(tests, testCase{
5993 protocol: dtls,
5994 name: "DTLS-Retransmit-Fudge",
5995 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005996 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005997 Bugs: ProtocolBugs{
5998 TimeoutSchedule: []time.Duration{
5999 timeouts[0] - 10*time.Millisecond,
6000 },
6001 },
6002 },
6003 resumeSession: true,
6004 })
6005 }
6006
6007 // Test that the final Finished retransmitting isn't
6008 // duplicated if the peer badly fragments everything.
6009 tests = append(tests, testCase{
6010 testType: serverTest,
6011 protocol: dtls,
6012 name: "DTLS-Retransmit-Fragmented",
6013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006014 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006015 Bugs: ProtocolBugs{
6016 TimeoutSchedule: []time.Duration{timeouts[0]},
6017 MaxHandshakeRecordLength: 2,
6018 },
6019 },
6020 })
6021
6022 // Test the timeout schedule when a shorter initial timeout duration is set.
6023 tests = append(tests, testCase{
6024 protocol: dtls,
6025 name: "DTLS-Retransmit-Short-Client",
6026 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006027 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006028 Bugs: ProtocolBugs{
6029 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6030 },
6031 },
6032 resumeSession: true,
6033 flags: []string{"-initial-timeout-duration-ms", "250"},
6034 })
6035 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006036 protocol: dtls,
6037 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006038 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006040 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006041 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006042 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006043 },
6044 },
6045 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006046 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006047 })
David Benjamin585d7a42016-06-02 14:58:00 -04006048
6049 for _, test := range tests {
6050 if async {
6051 test.name += "-Async"
6052 test.flags = append(test.flags, "-async")
6053 }
6054
6055 testCases = append(testCases, test)
6056 }
David Benjamin83f90402015-01-27 01:09:43 -05006057 }
David Benjamin83f90402015-01-27 01:09:43 -05006058}
6059
David Benjaminc565ebb2015-04-03 04:06:36 -04006060func addExportKeyingMaterialTests() {
6061 for _, vers := range tlsVersions {
6062 if vers.version == VersionSSL30 {
6063 continue
6064 }
6065 testCases = append(testCases, testCase{
6066 name: "ExportKeyingMaterial-" + vers.name,
6067 config: Config{
6068 MaxVersion: vers.version,
6069 },
6070 exportKeyingMaterial: 1024,
6071 exportLabel: "label",
6072 exportContext: "context",
6073 useExportContext: true,
6074 })
6075 testCases = append(testCases, testCase{
6076 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6077 config: Config{
6078 MaxVersion: vers.version,
6079 },
6080 exportKeyingMaterial: 1024,
6081 })
6082 testCases = append(testCases, testCase{
6083 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6084 config: Config{
6085 MaxVersion: vers.version,
6086 },
6087 exportKeyingMaterial: 1024,
6088 useExportContext: true,
6089 })
6090 testCases = append(testCases, testCase{
6091 name: "ExportKeyingMaterial-Small-" + vers.name,
6092 config: Config{
6093 MaxVersion: vers.version,
6094 },
6095 exportKeyingMaterial: 1,
6096 exportLabel: "label",
6097 exportContext: "context",
6098 useExportContext: true,
6099 })
6100 }
6101 testCases = append(testCases, testCase{
6102 name: "ExportKeyingMaterial-SSL3",
6103 config: Config{
6104 MaxVersion: VersionSSL30,
6105 },
6106 exportKeyingMaterial: 1024,
6107 exportLabel: "label",
6108 exportContext: "context",
6109 useExportContext: true,
6110 shouldFail: true,
6111 expectedError: "failed to export keying material",
6112 })
6113}
6114
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006115func addTLSUniqueTests() {
6116 for _, isClient := range []bool{false, true} {
6117 for _, isResumption := range []bool{false, true} {
6118 for _, hasEMS := range []bool{false, true} {
6119 var suffix string
6120 if isResumption {
6121 suffix = "Resume-"
6122 } else {
6123 suffix = "Full-"
6124 }
6125
6126 if hasEMS {
6127 suffix += "EMS-"
6128 } else {
6129 suffix += "NoEMS-"
6130 }
6131
6132 if isClient {
6133 suffix += "Client"
6134 } else {
6135 suffix += "Server"
6136 }
6137
6138 test := testCase{
6139 name: "TLSUnique-" + suffix,
6140 testTLSUnique: true,
6141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006142 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006143 Bugs: ProtocolBugs{
6144 NoExtendedMasterSecret: !hasEMS,
6145 },
6146 },
6147 }
6148
6149 if isResumption {
6150 test.resumeSession = true
6151 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006152 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006153 Bugs: ProtocolBugs{
6154 NoExtendedMasterSecret: !hasEMS,
6155 },
6156 }
6157 }
6158
6159 if isResumption && !hasEMS {
6160 test.shouldFail = true
6161 test.expectedError = "failed to get tls-unique"
6162 }
6163
6164 testCases = append(testCases, test)
6165 }
6166 }
6167 }
6168}
6169
Adam Langley09505632015-07-30 18:10:13 -07006170func addCustomExtensionTests() {
6171 expectedContents := "custom extension"
6172 emptyString := ""
6173
6174 for _, isClient := range []bool{false, true} {
6175 suffix := "Server"
6176 flag := "-enable-server-custom-extension"
6177 testType := serverTest
6178 if isClient {
6179 suffix = "Client"
6180 flag = "-enable-client-custom-extension"
6181 testType = clientTest
6182 }
6183
6184 testCases = append(testCases, testCase{
6185 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006186 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006188 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006189 Bugs: ProtocolBugs{
6190 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006191 ExpectedCustomExtension: &expectedContents,
6192 },
6193 },
6194 flags: []string{flag},
6195 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006196 testCases = append(testCases, testCase{
6197 testType: testType,
6198 name: "CustomExtensions-" + suffix + "-TLS13",
6199 config: Config{
6200 MaxVersion: VersionTLS13,
6201 Bugs: ProtocolBugs{
6202 CustomExtension: expectedContents,
6203 ExpectedCustomExtension: &expectedContents,
6204 },
6205 },
6206 flags: []string{flag},
6207 })
Adam Langley09505632015-07-30 18:10:13 -07006208
6209 // If the parse callback fails, the handshake should also fail.
6210 testCases = append(testCases, testCase{
6211 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006212 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006214 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006215 Bugs: ProtocolBugs{
6216 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006217 ExpectedCustomExtension: &expectedContents,
6218 },
6219 },
David Benjamin399e7c92015-07-30 23:01:27 -04006220 flags: []string{flag},
6221 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006222 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6223 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006224 testCases = append(testCases, testCase{
6225 testType: testType,
6226 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6227 config: Config{
6228 MaxVersion: VersionTLS13,
6229 Bugs: ProtocolBugs{
6230 CustomExtension: expectedContents + "foo",
6231 ExpectedCustomExtension: &expectedContents,
6232 },
6233 },
6234 flags: []string{flag},
6235 shouldFail: true,
6236 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6237 })
Adam Langley09505632015-07-30 18:10:13 -07006238
6239 // If the add callback fails, the handshake should also fail.
6240 testCases = append(testCases, testCase{
6241 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006242 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006244 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006245 Bugs: ProtocolBugs{
6246 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006247 ExpectedCustomExtension: &expectedContents,
6248 },
6249 },
David Benjamin399e7c92015-07-30 23:01:27 -04006250 flags: []string{flag, "-custom-extension-fail-add"},
6251 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006252 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6253 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006254 testCases = append(testCases, testCase{
6255 testType: testType,
6256 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6257 config: Config{
6258 MaxVersion: VersionTLS13,
6259 Bugs: ProtocolBugs{
6260 CustomExtension: expectedContents,
6261 ExpectedCustomExtension: &expectedContents,
6262 },
6263 },
6264 flags: []string{flag, "-custom-extension-fail-add"},
6265 shouldFail: true,
6266 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6267 })
Adam Langley09505632015-07-30 18:10:13 -07006268
6269 // If the add callback returns zero, no extension should be
6270 // added.
6271 skipCustomExtension := expectedContents
6272 if isClient {
6273 // For the case where the client skips sending the
6274 // custom extension, the server must not “echo” it.
6275 skipCustomExtension = ""
6276 }
6277 testCases = append(testCases, testCase{
6278 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006279 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006280 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006281 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006282 Bugs: ProtocolBugs{
6283 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006284 ExpectedCustomExtension: &emptyString,
6285 },
6286 },
6287 flags: []string{flag, "-custom-extension-skip"},
6288 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006289 testCases = append(testCases, testCase{
6290 testType: testType,
6291 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6292 config: Config{
6293 MaxVersion: VersionTLS13,
6294 Bugs: ProtocolBugs{
6295 CustomExtension: skipCustomExtension,
6296 ExpectedCustomExtension: &emptyString,
6297 },
6298 },
6299 flags: []string{flag, "-custom-extension-skip"},
6300 })
Adam Langley09505632015-07-30 18:10:13 -07006301 }
6302
6303 // The custom extension add callback should not be called if the client
6304 // doesn't send the extension.
6305 testCases = append(testCases, testCase{
6306 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006307 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006308 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006309 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006310 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006311 ExpectedCustomExtension: &emptyString,
6312 },
6313 },
6314 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6315 })
Adam Langley2deb9842015-08-07 11:15:37 -07006316
Steven Valdez143e8b32016-07-11 13:19:03 -04006317 testCases = append(testCases, testCase{
6318 testType: serverTest,
6319 name: "CustomExtensions-NotCalled-Server-TLS13",
6320 config: Config{
6321 MaxVersion: VersionTLS13,
6322 Bugs: ProtocolBugs{
6323 ExpectedCustomExtension: &emptyString,
6324 },
6325 },
6326 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6327 })
6328
Adam Langley2deb9842015-08-07 11:15:37 -07006329 // Test an unknown extension from the server.
6330 testCases = append(testCases, testCase{
6331 testType: clientTest,
6332 name: "UnknownExtension-Client",
6333 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006334 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006335 Bugs: ProtocolBugs{
6336 CustomExtension: expectedContents,
6337 },
6338 },
6339 shouldFail: true,
6340 expectedError: ":UNEXPECTED_EXTENSION:",
6341 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006342 testCases = append(testCases, testCase{
6343 testType: clientTest,
6344 name: "UnknownExtension-Client-TLS13",
6345 config: Config{
6346 MaxVersion: VersionTLS13,
6347 Bugs: ProtocolBugs{
6348 CustomExtension: expectedContents,
6349 },
6350 },
6351 shouldFail: true,
6352 expectedError: ":UNEXPECTED_EXTENSION:",
6353 })
Adam Langley09505632015-07-30 18:10:13 -07006354}
6355
David Benjaminb36a3952015-12-01 18:53:13 -05006356func addRSAClientKeyExchangeTests() {
6357 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6358 testCases = append(testCases, testCase{
6359 testType: serverTest,
6360 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6361 config: Config{
6362 // Ensure the ClientHello version and final
6363 // version are different, to detect if the
6364 // server uses the wrong one.
6365 MaxVersion: VersionTLS11,
6366 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6367 Bugs: ProtocolBugs{
6368 BadRSAClientKeyExchange: bad,
6369 },
6370 },
6371 shouldFail: true,
6372 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6373 })
6374 }
6375}
6376
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006377var testCurves = []struct {
6378 name string
6379 id CurveID
6380}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006381 {"P-256", CurveP256},
6382 {"P-384", CurveP384},
6383 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006384 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006385}
6386
Steven Valdez5440fe02016-07-18 12:40:30 -04006387const bogusCurve = 0x1234
6388
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006389func addCurveTests() {
6390 for _, curve := range testCurves {
6391 testCases = append(testCases, testCase{
6392 name: "CurveTest-Client-" + curve.name,
6393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006394 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006395 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6396 CurvePreferences: []CurveID{curve.id},
6397 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006398 flags: []string{"-enable-all-curves"},
6399 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006400 })
6401 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006402 name: "CurveTest-Client-" + curve.name + "-TLS13",
6403 config: Config{
6404 MaxVersion: VersionTLS13,
6405 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6406 CurvePreferences: []CurveID{curve.id},
6407 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006408 flags: []string{"-enable-all-curves"},
6409 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006410 })
6411 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006412 testType: serverTest,
6413 name: "CurveTest-Server-" + curve.name,
6414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006415 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6417 CurvePreferences: []CurveID{curve.id},
6418 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006419 flags: []string{"-enable-all-curves"},
6420 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006421 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006422 testCases = append(testCases, testCase{
6423 testType: serverTest,
6424 name: "CurveTest-Server-" + curve.name + "-TLS13",
6425 config: Config{
6426 MaxVersion: VersionTLS13,
6427 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6428 CurvePreferences: []CurveID{curve.id},
6429 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006430 flags: []string{"-enable-all-curves"},
6431 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006432 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006433 }
David Benjamin241ae832016-01-15 03:04:54 -05006434
6435 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006436 testCases = append(testCases, testCase{
6437 testType: serverTest,
6438 name: "UnknownCurve",
6439 config: Config{
6440 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6441 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6442 },
6443 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006444
6445 // The server must not consider ECDHE ciphers when there are no
6446 // supported curves.
6447 testCases = append(testCases, testCase{
6448 testType: serverTest,
6449 name: "NoSupportedCurves",
6450 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006451 MaxVersion: VersionTLS12,
6452 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6453 Bugs: ProtocolBugs{
6454 NoSupportedCurves: true,
6455 },
6456 },
6457 shouldFail: true,
6458 expectedError: ":NO_SHARED_CIPHER:",
6459 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006460 testCases = append(testCases, testCase{
6461 testType: serverTest,
6462 name: "NoSupportedCurves-TLS13",
6463 config: Config{
6464 MaxVersion: VersionTLS13,
6465 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6466 Bugs: ProtocolBugs{
6467 NoSupportedCurves: true,
6468 },
6469 },
6470 shouldFail: true,
6471 expectedError: ":NO_SHARED_CIPHER:",
6472 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006473
6474 // The server must fall back to another cipher when there are no
6475 // supported curves.
6476 testCases = append(testCases, testCase{
6477 testType: serverTest,
6478 name: "NoCommonCurves",
6479 config: Config{
6480 MaxVersion: VersionTLS12,
6481 CipherSuites: []uint16{
6482 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6483 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6484 },
6485 CurvePreferences: []CurveID{CurveP224},
6486 },
6487 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6488 })
6489
6490 // The client must reject bogus curves and disabled curves.
6491 testCases = append(testCases, testCase{
6492 name: "BadECDHECurve",
6493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006494 MaxVersion: VersionTLS12,
6495 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6496 Bugs: ProtocolBugs{
6497 SendCurve: bogusCurve,
6498 },
6499 },
6500 shouldFail: true,
6501 expectedError: ":WRONG_CURVE:",
6502 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006503 testCases = append(testCases, testCase{
6504 name: "BadECDHECurve-TLS13",
6505 config: Config{
6506 MaxVersion: VersionTLS13,
6507 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6508 Bugs: ProtocolBugs{
6509 SendCurve: bogusCurve,
6510 },
6511 },
6512 shouldFail: true,
6513 expectedError: ":WRONG_CURVE:",
6514 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006515
6516 testCases = append(testCases, testCase{
6517 name: "UnsupportedCurve",
6518 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006519 MaxVersion: VersionTLS12,
6520 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6521 CurvePreferences: []CurveID{CurveP256},
6522 Bugs: ProtocolBugs{
6523 IgnorePeerCurvePreferences: true,
6524 },
6525 },
6526 flags: []string{"-p384-only"},
6527 shouldFail: true,
6528 expectedError: ":WRONG_CURVE:",
6529 })
6530
David Benjamin4f921572016-07-17 14:20:10 +02006531 testCases = append(testCases, testCase{
6532 // TODO(davidben): Add a TLS 1.3 version where
6533 // HelloRetryRequest requests an unsupported curve.
6534 name: "UnsupportedCurve-ServerHello-TLS13",
6535 config: Config{
6536 MaxVersion: VersionTLS12,
6537 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6538 CurvePreferences: []CurveID{CurveP384},
6539 Bugs: ProtocolBugs{
6540 SendCurve: CurveP256,
6541 },
6542 },
6543 flags: []string{"-p384-only"},
6544 shouldFail: true,
6545 expectedError: ":WRONG_CURVE:",
6546 })
6547
David Benjamin4c3ddf72016-06-29 18:13:53 -04006548 // Test invalid curve points.
6549 testCases = append(testCases, testCase{
6550 name: "InvalidECDHPoint-Client",
6551 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006552 MaxVersion: VersionTLS12,
6553 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6554 CurvePreferences: []CurveID{CurveP256},
6555 Bugs: ProtocolBugs{
6556 InvalidECDHPoint: true,
6557 },
6558 },
6559 shouldFail: true,
6560 expectedError: ":INVALID_ENCODING:",
6561 })
6562 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006563 name: "InvalidECDHPoint-Client-TLS13",
6564 config: Config{
6565 MaxVersion: VersionTLS13,
6566 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6567 CurvePreferences: []CurveID{CurveP256},
6568 Bugs: ProtocolBugs{
6569 InvalidECDHPoint: true,
6570 },
6571 },
6572 shouldFail: true,
6573 expectedError: ":INVALID_ENCODING:",
6574 })
6575 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006576 testType: serverTest,
6577 name: "InvalidECDHPoint-Server",
6578 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006579 MaxVersion: VersionTLS12,
6580 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6581 CurvePreferences: []CurveID{CurveP256},
6582 Bugs: ProtocolBugs{
6583 InvalidECDHPoint: true,
6584 },
6585 },
6586 shouldFail: true,
6587 expectedError: ":INVALID_ENCODING:",
6588 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006589 testCases = append(testCases, testCase{
6590 testType: serverTest,
6591 name: "InvalidECDHPoint-Server-TLS13",
6592 config: Config{
6593 MaxVersion: VersionTLS13,
6594 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6595 CurvePreferences: []CurveID{CurveP256},
6596 Bugs: ProtocolBugs{
6597 InvalidECDHPoint: true,
6598 },
6599 },
6600 shouldFail: true,
6601 expectedError: ":INVALID_ENCODING:",
6602 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006603}
6604
Matt Braithwaite54217e42016-06-13 13:03:47 -07006605func addCECPQ1Tests() {
6606 testCases = append(testCases, testCase{
6607 testType: clientTest,
6608 name: "CECPQ1-Client-BadX25519Part",
6609 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006610 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006611 MinVersion: VersionTLS12,
6612 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6613 Bugs: ProtocolBugs{
6614 CECPQ1BadX25519Part: true,
6615 },
6616 },
6617 flags: []string{"-cipher", "kCECPQ1"},
6618 shouldFail: true,
6619 expectedLocalError: "local error: bad record MAC",
6620 })
6621 testCases = append(testCases, testCase{
6622 testType: clientTest,
6623 name: "CECPQ1-Client-BadNewhopePart",
6624 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006625 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006626 MinVersion: VersionTLS12,
6627 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6628 Bugs: ProtocolBugs{
6629 CECPQ1BadNewhopePart: true,
6630 },
6631 },
6632 flags: []string{"-cipher", "kCECPQ1"},
6633 shouldFail: true,
6634 expectedLocalError: "local error: bad record MAC",
6635 })
6636 testCases = append(testCases, testCase{
6637 testType: serverTest,
6638 name: "CECPQ1-Server-BadX25519Part",
6639 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006640 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006641 MinVersion: VersionTLS12,
6642 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6643 Bugs: ProtocolBugs{
6644 CECPQ1BadX25519Part: true,
6645 },
6646 },
6647 flags: []string{"-cipher", "kCECPQ1"},
6648 shouldFail: true,
6649 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6650 })
6651 testCases = append(testCases, testCase{
6652 testType: serverTest,
6653 name: "CECPQ1-Server-BadNewhopePart",
6654 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006655 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006656 MinVersion: VersionTLS12,
6657 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6658 Bugs: ProtocolBugs{
6659 CECPQ1BadNewhopePart: true,
6660 },
6661 },
6662 flags: []string{"-cipher", "kCECPQ1"},
6663 shouldFail: true,
6664 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6665 })
6666}
6667
David Benjamin4cc36ad2015-12-19 14:23:26 -05006668func addKeyExchangeInfoTests() {
6669 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006670 name: "KeyExchangeInfo-DHE-Client",
6671 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006672 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006673 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6674 Bugs: ProtocolBugs{
6675 // This is a 1234-bit prime number, generated
6676 // with:
6677 // openssl gendh 1234 | openssl asn1parse -i
6678 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6679 },
6680 },
David Benjamin9e68f192016-06-30 14:55:33 -04006681 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006682 })
6683 testCases = append(testCases, testCase{
6684 testType: serverTest,
6685 name: "KeyExchangeInfo-DHE-Server",
6686 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006687 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006688 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6689 },
6690 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006691 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006692 })
6693
6694 testCases = append(testCases, testCase{
6695 name: "KeyExchangeInfo-ECDHE-Client",
6696 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006697 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6699 CurvePreferences: []CurveID{CurveX25519},
6700 },
David Benjamin9e68f192016-06-30 14:55:33 -04006701 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006702 })
6703 testCases = append(testCases, testCase{
6704 testType: serverTest,
6705 name: "KeyExchangeInfo-ECDHE-Server",
6706 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006707 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006708 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6709 CurvePreferences: []CurveID{CurveX25519},
6710 },
David Benjamin9e68f192016-06-30 14:55:33 -04006711 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006712 })
6713}
6714
David Benjaminc9ae27c2016-06-24 22:56:37 -04006715func addTLS13RecordTests() {
6716 testCases = append(testCases, testCase{
6717 name: "TLS13-RecordPadding",
6718 config: Config{
6719 MaxVersion: VersionTLS13,
6720 MinVersion: VersionTLS13,
6721 Bugs: ProtocolBugs{
6722 RecordPadding: 10,
6723 },
6724 },
6725 })
6726
6727 testCases = append(testCases, testCase{
6728 name: "TLS13-EmptyRecords",
6729 config: Config{
6730 MaxVersion: VersionTLS13,
6731 MinVersion: VersionTLS13,
6732 Bugs: ProtocolBugs{
6733 OmitRecordContents: true,
6734 },
6735 },
6736 shouldFail: true,
6737 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6738 })
6739
6740 testCases = append(testCases, testCase{
6741 name: "TLS13-OnlyPadding",
6742 config: Config{
6743 MaxVersion: VersionTLS13,
6744 MinVersion: VersionTLS13,
6745 Bugs: ProtocolBugs{
6746 OmitRecordContents: true,
6747 RecordPadding: 10,
6748 },
6749 },
6750 shouldFail: true,
6751 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6752 })
6753
6754 testCases = append(testCases, testCase{
6755 name: "TLS13-WrongOuterRecord",
6756 config: Config{
6757 MaxVersion: VersionTLS13,
6758 MinVersion: VersionTLS13,
6759 Bugs: ProtocolBugs{
6760 OuterRecordType: recordTypeHandshake,
6761 },
6762 },
6763 shouldFail: true,
6764 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6765 })
6766}
6767
David Benjamin82261be2016-07-07 14:32:50 -07006768func addChangeCipherSpecTests() {
6769 // Test missing ChangeCipherSpecs.
6770 testCases = append(testCases, testCase{
6771 name: "SkipChangeCipherSpec-Client",
6772 config: Config{
6773 MaxVersion: VersionTLS12,
6774 Bugs: ProtocolBugs{
6775 SkipChangeCipherSpec: true,
6776 },
6777 },
6778 shouldFail: true,
6779 expectedError: ":UNEXPECTED_RECORD:",
6780 })
6781 testCases = append(testCases, testCase{
6782 testType: serverTest,
6783 name: "SkipChangeCipherSpec-Server",
6784 config: Config{
6785 MaxVersion: VersionTLS12,
6786 Bugs: ProtocolBugs{
6787 SkipChangeCipherSpec: true,
6788 },
6789 },
6790 shouldFail: true,
6791 expectedError: ":UNEXPECTED_RECORD:",
6792 })
6793 testCases = append(testCases, testCase{
6794 testType: serverTest,
6795 name: "SkipChangeCipherSpec-Server-NPN",
6796 config: Config{
6797 MaxVersion: VersionTLS12,
6798 NextProtos: []string{"bar"},
6799 Bugs: ProtocolBugs{
6800 SkipChangeCipherSpec: true,
6801 },
6802 },
6803 flags: []string{
6804 "-advertise-npn", "\x03foo\x03bar\x03baz",
6805 },
6806 shouldFail: true,
6807 expectedError: ":UNEXPECTED_RECORD:",
6808 })
6809
6810 // Test synchronization between the handshake and ChangeCipherSpec.
6811 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6812 // rejected. Test both with and without handshake packing to handle both
6813 // when the partial post-CCS message is in its own record and when it is
6814 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006815 for _, packed := range []bool{false, true} {
6816 var suffix string
6817 if packed {
6818 suffix = "-Packed"
6819 }
6820
6821 testCases = append(testCases, testCase{
6822 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6823 config: Config{
6824 MaxVersion: VersionTLS12,
6825 Bugs: ProtocolBugs{
6826 FragmentAcrossChangeCipherSpec: true,
6827 PackHandshakeFlight: packed,
6828 },
6829 },
6830 shouldFail: true,
6831 expectedError: ":UNEXPECTED_RECORD:",
6832 })
6833 testCases = append(testCases, testCase{
6834 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6835 config: Config{
6836 MaxVersion: VersionTLS12,
6837 },
6838 resumeSession: true,
6839 resumeConfig: &Config{
6840 MaxVersion: VersionTLS12,
6841 Bugs: ProtocolBugs{
6842 FragmentAcrossChangeCipherSpec: true,
6843 PackHandshakeFlight: packed,
6844 },
6845 },
6846 shouldFail: true,
6847 expectedError: ":UNEXPECTED_RECORD:",
6848 })
6849 testCases = append(testCases, testCase{
6850 testType: serverTest,
6851 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6852 config: Config{
6853 MaxVersion: VersionTLS12,
6854 Bugs: ProtocolBugs{
6855 FragmentAcrossChangeCipherSpec: true,
6856 PackHandshakeFlight: packed,
6857 },
6858 },
6859 shouldFail: true,
6860 expectedError: ":UNEXPECTED_RECORD:",
6861 })
6862 testCases = append(testCases, testCase{
6863 testType: serverTest,
6864 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6865 config: Config{
6866 MaxVersion: VersionTLS12,
6867 },
6868 resumeSession: true,
6869 resumeConfig: &Config{
6870 MaxVersion: VersionTLS12,
6871 Bugs: ProtocolBugs{
6872 FragmentAcrossChangeCipherSpec: true,
6873 PackHandshakeFlight: packed,
6874 },
6875 },
6876 shouldFail: true,
6877 expectedError: ":UNEXPECTED_RECORD:",
6878 })
6879 testCases = append(testCases, testCase{
6880 testType: serverTest,
6881 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6882 config: Config{
6883 MaxVersion: VersionTLS12,
6884 NextProtos: []string{"bar"},
6885 Bugs: ProtocolBugs{
6886 FragmentAcrossChangeCipherSpec: true,
6887 PackHandshakeFlight: packed,
6888 },
6889 },
6890 flags: []string{
6891 "-advertise-npn", "\x03foo\x03bar\x03baz",
6892 },
6893 shouldFail: true,
6894 expectedError: ":UNEXPECTED_RECORD:",
6895 })
6896 }
6897
David Benjamin61672812016-07-14 23:10:43 -04006898 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6899 // messages in the handshake queue. Do this by testing the server
6900 // reading the client Finished, reversing the flight so Finished comes
6901 // first.
6902 testCases = append(testCases, testCase{
6903 protocol: dtls,
6904 testType: serverTest,
6905 name: "SendUnencryptedFinished-DTLS",
6906 config: Config{
6907 MaxVersion: VersionTLS12,
6908 Bugs: ProtocolBugs{
6909 SendUnencryptedFinished: true,
6910 ReverseHandshakeFragments: true,
6911 },
6912 },
6913 shouldFail: true,
6914 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6915 })
6916
Steven Valdez143e8b32016-07-11 13:19:03 -04006917 // Test synchronization between encryption changes and the handshake in
6918 // TLS 1.3, where ChangeCipherSpec is implicit.
6919 testCases = append(testCases, testCase{
6920 name: "PartialEncryptedExtensionsWithServerHello",
6921 config: Config{
6922 MaxVersion: VersionTLS13,
6923 Bugs: ProtocolBugs{
6924 PartialEncryptedExtensionsWithServerHello: true,
6925 },
6926 },
6927 shouldFail: true,
6928 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6929 })
6930 testCases = append(testCases, testCase{
6931 testType: serverTest,
6932 name: "PartialClientFinishedWithClientHello",
6933 config: Config{
6934 MaxVersion: VersionTLS13,
6935 Bugs: ProtocolBugs{
6936 PartialClientFinishedWithClientHello: true,
6937 },
6938 },
6939 shouldFail: true,
6940 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6941 })
6942
David Benjamin82261be2016-07-07 14:32:50 -07006943 // Test that early ChangeCipherSpecs are handled correctly.
6944 testCases = append(testCases, testCase{
6945 testType: serverTest,
6946 name: "EarlyChangeCipherSpec-server-1",
6947 config: Config{
6948 MaxVersion: VersionTLS12,
6949 Bugs: ProtocolBugs{
6950 EarlyChangeCipherSpec: 1,
6951 },
6952 },
6953 shouldFail: true,
6954 expectedError: ":UNEXPECTED_RECORD:",
6955 })
6956 testCases = append(testCases, testCase{
6957 testType: serverTest,
6958 name: "EarlyChangeCipherSpec-server-2",
6959 config: Config{
6960 MaxVersion: VersionTLS12,
6961 Bugs: ProtocolBugs{
6962 EarlyChangeCipherSpec: 2,
6963 },
6964 },
6965 shouldFail: true,
6966 expectedError: ":UNEXPECTED_RECORD:",
6967 })
6968 testCases = append(testCases, testCase{
6969 protocol: dtls,
6970 name: "StrayChangeCipherSpec",
6971 config: Config{
6972 // TODO(davidben): Once DTLS 1.3 exists, test
6973 // that stray ChangeCipherSpec messages are
6974 // rejected.
6975 MaxVersion: VersionTLS12,
6976 Bugs: ProtocolBugs{
6977 StrayChangeCipherSpec: true,
6978 },
6979 },
6980 })
6981
6982 // Test that the contents of ChangeCipherSpec are checked.
6983 testCases = append(testCases, testCase{
6984 name: "BadChangeCipherSpec-1",
6985 config: Config{
6986 MaxVersion: VersionTLS12,
6987 Bugs: ProtocolBugs{
6988 BadChangeCipherSpec: []byte{2},
6989 },
6990 },
6991 shouldFail: true,
6992 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6993 })
6994 testCases = append(testCases, testCase{
6995 name: "BadChangeCipherSpec-2",
6996 config: Config{
6997 MaxVersion: VersionTLS12,
6998 Bugs: ProtocolBugs{
6999 BadChangeCipherSpec: []byte{1, 1},
7000 },
7001 },
7002 shouldFail: true,
7003 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7004 })
7005 testCases = append(testCases, testCase{
7006 protocol: dtls,
7007 name: "BadChangeCipherSpec-DTLS-1",
7008 config: Config{
7009 MaxVersion: VersionTLS12,
7010 Bugs: ProtocolBugs{
7011 BadChangeCipherSpec: []byte{2},
7012 },
7013 },
7014 shouldFail: true,
7015 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7016 })
7017 testCases = append(testCases, testCase{
7018 protocol: dtls,
7019 name: "BadChangeCipherSpec-DTLS-2",
7020 config: Config{
7021 MaxVersion: VersionTLS12,
7022 Bugs: ProtocolBugs{
7023 BadChangeCipherSpec: []byte{1, 1},
7024 },
7025 },
7026 shouldFail: true,
7027 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7028 })
7029}
7030
David Benjamin0b8d5da2016-07-15 00:39:56 -04007031func addWrongMessageTypeTests() {
7032 for _, protocol := range []protocol{tls, dtls} {
7033 var suffix string
7034 if protocol == dtls {
7035 suffix = "-DTLS"
7036 }
7037
7038 testCases = append(testCases, testCase{
7039 protocol: protocol,
7040 testType: serverTest,
7041 name: "WrongMessageType-ClientHello" + suffix,
7042 config: Config{
7043 MaxVersion: VersionTLS12,
7044 Bugs: ProtocolBugs{
7045 SendWrongMessageType: typeClientHello,
7046 },
7047 },
7048 shouldFail: true,
7049 expectedError: ":UNEXPECTED_MESSAGE:",
7050 expectedLocalError: "remote error: unexpected message",
7051 })
7052
7053 if protocol == dtls {
7054 testCases = append(testCases, testCase{
7055 protocol: protocol,
7056 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7057 config: Config{
7058 MaxVersion: VersionTLS12,
7059 Bugs: ProtocolBugs{
7060 SendWrongMessageType: typeHelloVerifyRequest,
7061 },
7062 },
7063 shouldFail: true,
7064 expectedError: ":UNEXPECTED_MESSAGE:",
7065 expectedLocalError: "remote error: unexpected message",
7066 })
7067 }
7068
7069 testCases = append(testCases, testCase{
7070 protocol: protocol,
7071 name: "WrongMessageType-ServerHello" + suffix,
7072 config: Config{
7073 MaxVersion: VersionTLS12,
7074 Bugs: ProtocolBugs{
7075 SendWrongMessageType: typeServerHello,
7076 },
7077 },
7078 shouldFail: true,
7079 expectedError: ":UNEXPECTED_MESSAGE:",
7080 expectedLocalError: "remote error: unexpected message",
7081 })
7082
7083 testCases = append(testCases, testCase{
7084 protocol: protocol,
7085 name: "WrongMessageType-ServerCertificate" + suffix,
7086 config: Config{
7087 MaxVersion: VersionTLS12,
7088 Bugs: ProtocolBugs{
7089 SendWrongMessageType: typeCertificate,
7090 },
7091 },
7092 shouldFail: true,
7093 expectedError: ":UNEXPECTED_MESSAGE:",
7094 expectedLocalError: "remote error: unexpected message",
7095 })
7096
7097 testCases = append(testCases, testCase{
7098 protocol: protocol,
7099 name: "WrongMessageType-CertificateStatus" + suffix,
7100 config: Config{
7101 MaxVersion: VersionTLS12,
7102 Bugs: ProtocolBugs{
7103 SendWrongMessageType: typeCertificateStatus,
7104 },
7105 },
7106 flags: []string{"-enable-ocsp-stapling"},
7107 shouldFail: true,
7108 expectedError: ":UNEXPECTED_MESSAGE:",
7109 expectedLocalError: "remote error: unexpected message",
7110 })
7111
7112 testCases = append(testCases, testCase{
7113 protocol: protocol,
7114 name: "WrongMessageType-ServerKeyExchange" + suffix,
7115 config: Config{
7116 MaxVersion: VersionTLS12,
7117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7118 Bugs: ProtocolBugs{
7119 SendWrongMessageType: typeServerKeyExchange,
7120 },
7121 },
7122 shouldFail: true,
7123 expectedError: ":UNEXPECTED_MESSAGE:",
7124 expectedLocalError: "remote error: unexpected message",
7125 })
7126
7127 testCases = append(testCases, testCase{
7128 protocol: protocol,
7129 name: "WrongMessageType-CertificateRequest" + suffix,
7130 config: Config{
7131 MaxVersion: VersionTLS12,
7132 ClientAuth: RequireAnyClientCert,
7133 Bugs: ProtocolBugs{
7134 SendWrongMessageType: typeCertificateRequest,
7135 },
7136 },
7137 shouldFail: true,
7138 expectedError: ":UNEXPECTED_MESSAGE:",
7139 expectedLocalError: "remote error: unexpected message",
7140 })
7141
7142 testCases = append(testCases, testCase{
7143 protocol: protocol,
7144 name: "WrongMessageType-ServerHelloDone" + suffix,
7145 config: Config{
7146 MaxVersion: VersionTLS12,
7147 Bugs: ProtocolBugs{
7148 SendWrongMessageType: typeServerHelloDone,
7149 },
7150 },
7151 shouldFail: true,
7152 expectedError: ":UNEXPECTED_MESSAGE:",
7153 expectedLocalError: "remote error: unexpected message",
7154 })
7155
7156 testCases = append(testCases, testCase{
7157 testType: serverTest,
7158 protocol: protocol,
7159 name: "WrongMessageType-ClientCertificate" + suffix,
7160 config: Config{
7161 Certificates: []Certificate{rsaCertificate},
7162 MaxVersion: VersionTLS12,
7163 Bugs: ProtocolBugs{
7164 SendWrongMessageType: typeCertificate,
7165 },
7166 },
7167 flags: []string{"-require-any-client-certificate"},
7168 shouldFail: true,
7169 expectedError: ":UNEXPECTED_MESSAGE:",
7170 expectedLocalError: "remote error: unexpected message",
7171 })
7172
7173 testCases = append(testCases, testCase{
7174 testType: serverTest,
7175 protocol: protocol,
7176 name: "WrongMessageType-CertificateVerify" + suffix,
7177 config: Config{
7178 Certificates: []Certificate{rsaCertificate},
7179 MaxVersion: VersionTLS12,
7180 Bugs: ProtocolBugs{
7181 SendWrongMessageType: typeCertificateVerify,
7182 },
7183 },
7184 flags: []string{"-require-any-client-certificate"},
7185 shouldFail: true,
7186 expectedError: ":UNEXPECTED_MESSAGE:",
7187 expectedLocalError: "remote error: unexpected message",
7188 })
7189
7190 testCases = append(testCases, testCase{
7191 testType: serverTest,
7192 protocol: protocol,
7193 name: "WrongMessageType-ClientKeyExchange" + suffix,
7194 config: Config{
7195 MaxVersion: VersionTLS12,
7196 Bugs: ProtocolBugs{
7197 SendWrongMessageType: typeClientKeyExchange,
7198 },
7199 },
7200 shouldFail: true,
7201 expectedError: ":UNEXPECTED_MESSAGE:",
7202 expectedLocalError: "remote error: unexpected message",
7203 })
7204
7205 if protocol != dtls {
7206 testCases = append(testCases, testCase{
7207 testType: serverTest,
7208 protocol: protocol,
7209 name: "WrongMessageType-NextProtocol" + suffix,
7210 config: Config{
7211 MaxVersion: VersionTLS12,
7212 NextProtos: []string{"bar"},
7213 Bugs: ProtocolBugs{
7214 SendWrongMessageType: typeNextProtocol,
7215 },
7216 },
7217 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7218 shouldFail: true,
7219 expectedError: ":UNEXPECTED_MESSAGE:",
7220 expectedLocalError: "remote error: unexpected message",
7221 })
7222
7223 testCases = append(testCases, testCase{
7224 testType: serverTest,
7225 protocol: protocol,
7226 name: "WrongMessageType-ChannelID" + suffix,
7227 config: Config{
7228 MaxVersion: VersionTLS12,
7229 ChannelID: channelIDKey,
7230 Bugs: ProtocolBugs{
7231 SendWrongMessageType: typeChannelID,
7232 },
7233 },
7234 flags: []string{
7235 "-expect-channel-id",
7236 base64.StdEncoding.EncodeToString(channelIDBytes),
7237 },
7238 shouldFail: true,
7239 expectedError: ":UNEXPECTED_MESSAGE:",
7240 expectedLocalError: "remote error: unexpected message",
7241 })
7242 }
7243
7244 testCases = append(testCases, testCase{
7245 testType: serverTest,
7246 protocol: protocol,
7247 name: "WrongMessageType-ClientFinished" + suffix,
7248 config: Config{
7249 MaxVersion: VersionTLS12,
7250 Bugs: ProtocolBugs{
7251 SendWrongMessageType: typeFinished,
7252 },
7253 },
7254 shouldFail: true,
7255 expectedError: ":UNEXPECTED_MESSAGE:",
7256 expectedLocalError: "remote error: unexpected message",
7257 })
7258
7259 testCases = append(testCases, testCase{
7260 protocol: protocol,
7261 name: "WrongMessageType-NewSessionTicket" + suffix,
7262 config: Config{
7263 MaxVersion: VersionTLS12,
7264 Bugs: ProtocolBugs{
7265 SendWrongMessageType: typeNewSessionTicket,
7266 },
7267 },
7268 shouldFail: true,
7269 expectedError: ":UNEXPECTED_MESSAGE:",
7270 expectedLocalError: "remote error: unexpected message",
7271 })
7272
7273 testCases = append(testCases, testCase{
7274 protocol: protocol,
7275 name: "WrongMessageType-ServerFinished" + suffix,
7276 config: Config{
7277 MaxVersion: VersionTLS12,
7278 Bugs: ProtocolBugs{
7279 SendWrongMessageType: typeFinished,
7280 },
7281 },
7282 shouldFail: true,
7283 expectedError: ":UNEXPECTED_MESSAGE:",
7284 expectedLocalError: "remote error: unexpected message",
7285 })
7286
7287 }
7288}
7289
Steven Valdez143e8b32016-07-11 13:19:03 -04007290func addTLS13WrongMessageTypeTests() {
7291 testCases = append(testCases, testCase{
7292 testType: serverTest,
7293 name: "WrongMessageType-TLS13-ClientHello",
7294 config: Config{
7295 MaxVersion: VersionTLS13,
7296 Bugs: ProtocolBugs{
7297 SendWrongMessageType: typeClientHello,
7298 },
7299 },
7300 shouldFail: true,
7301 expectedError: ":UNEXPECTED_MESSAGE:",
7302 expectedLocalError: "remote error: unexpected message",
7303 })
7304
7305 testCases = append(testCases, testCase{
7306 name: "WrongMessageType-TLS13-ServerHello",
7307 config: Config{
7308 MaxVersion: VersionTLS13,
7309 Bugs: ProtocolBugs{
7310 SendWrongMessageType: typeServerHello,
7311 },
7312 },
7313 shouldFail: true,
7314 expectedError: ":UNEXPECTED_MESSAGE:",
7315 // The alert comes in with the wrong encryption.
7316 expectedLocalError: "local error: bad record MAC",
7317 })
7318
7319 testCases = append(testCases, testCase{
7320 name: "WrongMessageType-TLS13-EncryptedExtensions",
7321 config: Config{
7322 MaxVersion: VersionTLS13,
7323 Bugs: ProtocolBugs{
7324 SendWrongMessageType: typeEncryptedExtensions,
7325 },
7326 },
7327 shouldFail: true,
7328 expectedError: ":UNEXPECTED_MESSAGE:",
7329 expectedLocalError: "remote error: unexpected message",
7330 })
7331
7332 testCases = append(testCases, testCase{
7333 name: "WrongMessageType-TLS13-CertificateRequest",
7334 config: Config{
7335 MaxVersion: VersionTLS13,
7336 ClientAuth: RequireAnyClientCert,
7337 Bugs: ProtocolBugs{
7338 SendWrongMessageType: typeCertificateRequest,
7339 },
7340 },
7341 shouldFail: true,
7342 expectedError: ":UNEXPECTED_MESSAGE:",
7343 expectedLocalError: "remote error: unexpected message",
7344 })
7345
7346 testCases = append(testCases, testCase{
7347 name: "WrongMessageType-TLS13-ServerCertificate",
7348 config: Config{
7349 MaxVersion: VersionTLS13,
7350 Bugs: ProtocolBugs{
7351 SendWrongMessageType: typeCertificate,
7352 },
7353 },
7354 shouldFail: true,
7355 expectedError: ":UNEXPECTED_MESSAGE:",
7356 expectedLocalError: "remote error: unexpected message",
7357 })
7358
7359 testCases = append(testCases, testCase{
7360 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7361 config: Config{
7362 MaxVersion: VersionTLS13,
7363 Bugs: ProtocolBugs{
7364 SendWrongMessageType: typeCertificateVerify,
7365 },
7366 },
7367 shouldFail: true,
7368 expectedError: ":UNEXPECTED_MESSAGE:",
7369 expectedLocalError: "remote error: unexpected message",
7370 })
7371
7372 testCases = append(testCases, testCase{
7373 name: "WrongMessageType-TLS13-ServerFinished",
7374 config: Config{
7375 MaxVersion: VersionTLS13,
7376 Bugs: ProtocolBugs{
7377 SendWrongMessageType: typeFinished,
7378 },
7379 },
7380 shouldFail: true,
7381 expectedError: ":UNEXPECTED_MESSAGE:",
7382 expectedLocalError: "remote error: unexpected message",
7383 })
7384
7385 testCases = append(testCases, testCase{
7386 testType: serverTest,
7387 name: "WrongMessageType-TLS13-ClientCertificate",
7388 config: Config{
7389 Certificates: []Certificate{rsaCertificate},
7390 MaxVersion: VersionTLS13,
7391 Bugs: ProtocolBugs{
7392 SendWrongMessageType: typeCertificate,
7393 },
7394 },
7395 flags: []string{"-require-any-client-certificate"},
7396 shouldFail: true,
7397 expectedError: ":UNEXPECTED_MESSAGE:",
7398 expectedLocalError: "remote error: unexpected message",
7399 })
7400
7401 testCases = append(testCases, testCase{
7402 testType: serverTest,
7403 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7404 config: Config{
7405 Certificates: []Certificate{rsaCertificate},
7406 MaxVersion: VersionTLS13,
7407 Bugs: ProtocolBugs{
7408 SendWrongMessageType: typeCertificateVerify,
7409 },
7410 },
7411 flags: []string{"-require-any-client-certificate"},
7412 shouldFail: true,
7413 expectedError: ":UNEXPECTED_MESSAGE:",
7414 expectedLocalError: "remote error: unexpected message",
7415 })
7416
7417 testCases = append(testCases, testCase{
7418 testType: serverTest,
7419 name: "WrongMessageType-TLS13-ClientFinished",
7420 config: Config{
7421 MaxVersion: VersionTLS13,
7422 Bugs: ProtocolBugs{
7423 SendWrongMessageType: typeFinished,
7424 },
7425 },
7426 shouldFail: true,
7427 expectedError: ":UNEXPECTED_MESSAGE:",
7428 expectedLocalError: "remote error: unexpected message",
7429 })
7430}
7431
7432func addTLS13HandshakeTests() {
7433 testCases = append(testCases, testCase{
7434 testType: clientTest,
7435 name: "MissingKeyShare-Client",
7436 config: Config{
7437 MaxVersion: VersionTLS13,
7438 Bugs: ProtocolBugs{
7439 MissingKeyShare: true,
7440 },
7441 },
7442 shouldFail: true,
7443 expectedError: ":MISSING_KEY_SHARE:",
7444 })
7445
7446 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007447 testType: serverTest,
7448 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007449 config: Config{
7450 MaxVersion: VersionTLS13,
7451 Bugs: ProtocolBugs{
7452 MissingKeyShare: true,
7453 },
7454 },
7455 shouldFail: true,
7456 expectedError: ":MISSING_KEY_SHARE:",
7457 })
7458
7459 testCases = append(testCases, testCase{
7460 testType: clientTest,
7461 name: "ClientHelloMissingKeyShare",
7462 config: Config{
7463 MaxVersion: VersionTLS13,
7464 Bugs: ProtocolBugs{
7465 MissingKeyShare: true,
7466 },
7467 },
7468 shouldFail: true,
7469 expectedError: ":MISSING_KEY_SHARE:",
7470 })
7471
7472 testCases = append(testCases, testCase{
7473 testType: clientTest,
7474 name: "MissingKeyShare",
7475 config: Config{
7476 MaxVersion: VersionTLS13,
7477 Bugs: ProtocolBugs{
7478 MissingKeyShare: true,
7479 },
7480 },
7481 shouldFail: true,
7482 expectedError: ":MISSING_KEY_SHARE:",
7483 })
7484
7485 testCases = append(testCases, testCase{
7486 testType: serverTest,
7487 name: "DuplicateKeyShares",
7488 config: Config{
7489 MaxVersion: VersionTLS13,
7490 Bugs: ProtocolBugs{
7491 DuplicateKeyShares: true,
7492 },
7493 },
7494 })
7495
7496 testCases = append(testCases, testCase{
7497 testType: clientTest,
7498 name: "EmptyEncryptedExtensions",
7499 config: Config{
7500 MaxVersion: VersionTLS13,
7501 Bugs: ProtocolBugs{
7502 EmptyEncryptedExtensions: true,
7503 },
7504 },
7505 shouldFail: true,
7506 expectedLocalError: "remote error: error decoding message",
7507 })
7508
7509 testCases = append(testCases, testCase{
7510 testType: clientTest,
7511 name: "EncryptedExtensionsWithKeyShare",
7512 config: Config{
7513 MaxVersion: VersionTLS13,
7514 Bugs: ProtocolBugs{
7515 EncryptedExtensionsWithKeyShare: true,
7516 },
7517 },
7518 shouldFail: true,
7519 expectedLocalError: "remote error: unsupported extension",
7520 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007521
7522 testCases = append(testCases, testCase{
7523 testType: serverTest,
7524 name: "SendHelloRetryRequest",
7525 config: Config{
7526 MaxVersion: VersionTLS13,
7527 // Require a HelloRetryRequest for every curve.
7528 DefaultCurves: []CurveID{},
7529 },
7530 expectedCurveID: CurveX25519,
7531 })
7532
7533 testCases = append(testCases, testCase{
7534 testType: serverTest,
7535 name: "SendHelloRetryRequest-2",
7536 config: Config{
7537 MaxVersion: VersionTLS13,
7538 DefaultCurves: []CurveID{CurveP384},
7539 },
7540 // Although the ClientHello did not predict our preferred curve,
7541 // we always select it whether it is predicted or not.
7542 expectedCurveID: CurveX25519,
7543 })
7544
7545 testCases = append(testCases, testCase{
7546 name: "UnknownCurve-HelloRetryRequest",
7547 config: Config{
7548 MaxVersion: VersionTLS13,
7549 // P-384 requires HelloRetryRequest in BoringSSL.
7550 CurvePreferences: []CurveID{CurveP384},
7551 Bugs: ProtocolBugs{
7552 SendHelloRetryRequestCurve: bogusCurve,
7553 },
7554 },
7555 shouldFail: true,
7556 expectedError: ":WRONG_CURVE:",
7557 })
7558
7559 testCases = append(testCases, testCase{
7560 name: "DisabledCurve-HelloRetryRequest",
7561 config: Config{
7562 MaxVersion: VersionTLS13,
7563 CurvePreferences: []CurveID{CurveP256},
7564 Bugs: ProtocolBugs{
7565 IgnorePeerCurvePreferences: true,
7566 },
7567 },
7568 flags: []string{"-p384-only"},
7569 shouldFail: true,
7570 expectedError: ":WRONG_CURVE:",
7571 })
7572
7573 testCases = append(testCases, testCase{
7574 name: "UnnecessaryHelloRetryRequest",
7575 config: Config{
7576 MaxVersion: VersionTLS13,
7577 Bugs: ProtocolBugs{
7578 UnnecessaryHelloRetryRequest: true,
7579 },
7580 },
7581 shouldFail: true,
7582 expectedError: ":WRONG_CURVE:",
7583 })
7584
7585 testCases = append(testCases, testCase{
7586 name: "SecondHelloRetryRequest",
7587 config: Config{
7588 MaxVersion: VersionTLS13,
7589 // P-384 requires HelloRetryRequest in BoringSSL.
7590 CurvePreferences: []CurveID{CurveP384},
7591 Bugs: ProtocolBugs{
7592 SecondHelloRetryRequest: true,
7593 },
7594 },
7595 shouldFail: true,
7596 expectedError: ":UNEXPECTED_MESSAGE:",
7597 })
7598
7599 testCases = append(testCases, testCase{
7600 testType: serverTest,
7601 name: "SecondClientHelloMissingKeyShare",
7602 config: Config{
7603 MaxVersion: VersionTLS13,
7604 DefaultCurves: []CurveID{},
7605 Bugs: ProtocolBugs{
7606 SecondClientHelloMissingKeyShare: true,
7607 },
7608 },
7609 shouldFail: true,
7610 expectedError: ":MISSING_KEY_SHARE:",
7611 })
7612
7613 testCases = append(testCases, testCase{
7614 testType: serverTest,
7615 name: "SecondClientHelloWrongCurve",
7616 config: Config{
7617 MaxVersion: VersionTLS13,
7618 DefaultCurves: []CurveID{},
7619 Bugs: ProtocolBugs{
7620 MisinterpretHelloRetryRequestCurve: CurveP521,
7621 },
7622 },
7623 shouldFail: true,
7624 expectedError: ":WRONG_CURVE:",
7625 })
7626
7627 testCases = append(testCases, testCase{
7628 name: "HelloRetryRequestVersionMismatch",
7629 config: Config{
7630 MaxVersion: VersionTLS13,
7631 // P-384 requires HelloRetryRequest in BoringSSL.
7632 CurvePreferences: []CurveID{CurveP384},
7633 Bugs: ProtocolBugs{
7634 SendServerHelloVersion: 0x0305,
7635 },
7636 },
7637 shouldFail: true,
7638 expectedError: ":WRONG_VERSION_NUMBER:",
7639 })
7640
7641 testCases = append(testCases, testCase{
7642 name: "HelloRetryRequestCurveMismatch",
7643 config: Config{
7644 MaxVersion: VersionTLS13,
7645 // P-384 requires HelloRetryRequest in BoringSSL.
7646 CurvePreferences: []CurveID{CurveP384},
7647 Bugs: ProtocolBugs{
7648 // Send P-384 (correct) in the HelloRetryRequest.
7649 SendHelloRetryRequestCurve: CurveP384,
7650 // But send P-256 in the ServerHello.
7651 SendCurve: CurveP256,
7652 },
7653 },
7654 shouldFail: true,
7655 expectedError: ":WRONG_CURVE:",
7656 })
7657
7658 // Test the server selecting a curve that requires a HelloRetryRequest
7659 // without sending it.
7660 testCases = append(testCases, testCase{
7661 name: "SkipHelloRetryRequest",
7662 config: Config{
7663 MaxVersion: VersionTLS13,
7664 // P-384 requires HelloRetryRequest in BoringSSL.
7665 CurvePreferences: []CurveID{CurveP384},
7666 Bugs: ProtocolBugs{
7667 SkipHelloRetryRequest: true,
7668 },
7669 },
7670 shouldFail: true,
7671 expectedError: ":WRONG_CURVE:",
7672 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007673}
7674
Adam Langley7c803a62015-06-15 15:35:05 -07007675func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007676 defer wg.Done()
7677
7678 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007679 var err error
7680
7681 if *mallocTest < 0 {
7682 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007683 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007684 } else {
7685 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7686 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007687 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007688 if err != nil {
7689 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7690 }
7691 break
7692 }
7693 }
7694 }
Adam Langley95c29f32014-06-20 12:00:00 -07007695 statusChan <- statusMsg{test: test, err: err}
7696 }
7697}
7698
7699type statusMsg struct {
7700 test *testCase
7701 started bool
7702 err error
7703}
7704
David Benjamin5f237bc2015-02-11 17:14:15 -05007705func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02007706 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007707
David Benjamin5f237bc2015-02-11 17:14:15 -05007708 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007709 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007710 if !*pipe {
7711 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007712 var erase string
7713 for i := 0; i < lineLen; i++ {
7714 erase += "\b \b"
7715 }
7716 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007717 }
7718
Adam Langley95c29f32014-06-20 12:00:00 -07007719 if msg.started {
7720 started++
7721 } else {
7722 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007723
7724 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02007725 if msg.err == errUnimplemented {
7726 if *pipe {
7727 // Print each test instead of a status line.
7728 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
7729 }
7730 unimplemented++
7731 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
7732 } else {
7733 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7734 failed++
7735 testOutput.addResult(msg.test.name, "FAIL")
7736 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007737 } else {
7738 if *pipe {
7739 // Print each test instead of a status line.
7740 fmt.Printf("PASSED (%s)\n", msg.test.name)
7741 }
7742 testOutput.addResult(msg.test.name, "PASS")
7743 }
Adam Langley95c29f32014-06-20 12:00:00 -07007744 }
7745
David Benjamin5f237bc2015-02-11 17:14:15 -05007746 if !*pipe {
7747 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02007748 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05007749 lineLen = len(line)
7750 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007751 }
Adam Langley95c29f32014-06-20 12:00:00 -07007752 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007753
7754 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007755}
7756
7757func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007758 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007759 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007760 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007761
Adam Langley7c803a62015-06-15 15:35:05 -07007762 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007763 addCipherSuiteTests()
7764 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007765 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007766 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007767 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007768 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007769 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007770 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007771 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007772 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007773 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007774 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007775 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007776 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007777 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007778 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007779 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007780 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007781 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007782 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007783 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007784 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007785 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007786 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007787 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007788 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007789 addTLS13WrongMessageTypeTests()
7790 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007791
7792 var wg sync.WaitGroup
7793
Adam Langley7c803a62015-06-15 15:35:05 -07007794 statusChan := make(chan statusMsg, *numWorkers)
7795 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007796 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007797
David Benjamin025b3d32014-07-01 19:53:04 -04007798 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007799
Adam Langley7c803a62015-06-15 15:35:05 -07007800 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007801 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007802 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007803 }
7804
David Benjamin270f0a72016-03-17 14:41:36 -04007805 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007806 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07007807 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04007808 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007809 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007810 }
7811 }
David Benjamin270f0a72016-03-17 14:41:36 -04007812 if !foundTest {
7813 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
7814 os.Exit(1)
7815 }
Adam Langley95c29f32014-06-20 12:00:00 -07007816
7817 close(testChan)
7818 wg.Wait()
7819 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007820 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007821
7822 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007823
7824 if *jsonOutput != "" {
7825 if err := testOutput.writeTo(*jsonOutput); err != nil {
7826 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7827 }
7828 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007829
EKR842ae6c2016-07-27 09:22:05 +02007830 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
7831 os.Exit(1)
7832 }
7833
7834 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04007835 os.Exit(1)
7836 }
Adam Langley95c29f32014-06-20 12:00:00 -07007837}