blob: 92a2b6abaa3ed23e5397587230570fc8012d3998 [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"
Adam Langley95c29f32014-06-20 12:00:00 -070024 "flag"
25 "fmt"
26 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070027 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070028 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "net"
30 "os"
31 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040032 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040033 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080034 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070035 "strings"
36 "sync"
37 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050038 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070039)
40
Adam Langley69a01602014-11-17 17:26:55 -080041var (
David Benjamin5f237bc2015-02-11 17:14:15 -050042 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
43 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050044 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050045 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
46 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
47 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.")
48 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
49 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070050 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
51 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
52 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
53 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050054 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050055 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin01784b42016-06-07 18:00:52 -040056 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
David Benjamin2e045a92016-06-08 13:09:56 -040057 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
Adam Langley69a01602014-11-17 17:26:55 -080058)
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin33863262016-07-08 17:20:12 -070060type testCert int
61
David Benjamin025b3d32014-07-01 19:53:04 -040062const (
David Benjamin33863262016-07-08 17:20:12 -070063 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040064 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070065 testCertECDSAP256
66 testCertECDSAP384
67 testCertECDSAP521
68)
69
70const (
71 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040072 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070073 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
74 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
75 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040076)
77
78const (
David Benjamina08e49d2014-08-24 01:46:07 -040079 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040080 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -070081 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
82 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
83 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040084 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040085)
86
David Benjamin7944a9f2016-07-12 22:27:01 -040087var (
88 rsaCertificate Certificate
89 rsa1024Certificate Certificate
90 ecdsaP256Certificate Certificate
91 ecdsaP384Certificate Certificate
92 ecdsaP521Certificate Certificate
93)
David Benjamin33863262016-07-08 17:20:12 -070094
95var testCerts = []struct {
96 id testCert
97 certFile, keyFile string
98 cert *Certificate
99}{
100 {
101 id: testCertRSA,
102 certFile: rsaCertificateFile,
103 keyFile: rsaKeyFile,
104 cert: &rsaCertificate,
105 },
106 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400107 id: testCertRSA1024,
108 certFile: rsa1024CertificateFile,
109 keyFile: rsa1024KeyFile,
110 cert: &rsa1024Certificate,
111 },
112 {
David Benjamin33863262016-07-08 17:20:12 -0700113 id: testCertECDSAP256,
114 certFile: ecdsaP256CertificateFile,
115 keyFile: ecdsaP256KeyFile,
116 cert: &ecdsaP256Certificate,
117 },
118 {
119 id: testCertECDSAP384,
120 certFile: ecdsaP384CertificateFile,
121 keyFile: ecdsaP384KeyFile,
122 cert: &ecdsaP384Certificate,
123 },
124 {
125 id: testCertECDSAP521,
126 certFile: ecdsaP521CertificateFile,
127 keyFile: ecdsaP521KeyFile,
128 cert: &ecdsaP521Certificate,
129 },
130}
131
David Benjamina08e49d2014-08-24 01:46:07 -0400132var channelIDKey *ecdsa.PrivateKey
133var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700134
David Benjamin61f95272014-11-25 01:55:35 -0500135var testOCSPResponse = []byte{1, 2, 3, 4}
136var testSCTList = []byte{5, 6, 7, 8}
137
Adam Langley95c29f32014-06-20 12:00:00 -0700138func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700139 for i := range testCerts {
140 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
141 if err != nil {
142 panic(err)
143 }
144 cert.OCSPStaple = testOCSPResponse
145 cert.SignedCertificateTimestampList = testSCTList
146 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700147 }
David Benjamina08e49d2014-08-24 01:46:07 -0400148
Adam Langley7c803a62015-06-15 15:35:05 -0700149 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400150 if err != nil {
151 panic(err)
152 }
153 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
154 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
155 panic("bad key type")
156 }
157 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
158 if err != nil {
159 panic(err)
160 }
161 if channelIDKey.Curve != elliptic.P256() {
162 panic("bad curve")
163 }
164
165 channelIDBytes = make([]byte, 64)
166 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
167 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700168}
169
David Benjamin33863262016-07-08 17:20:12 -0700170func getRunnerCertificate(t testCert) Certificate {
171 for _, cert := range testCerts {
172 if cert.id == t {
173 return *cert.cert
174 }
175 }
176 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700177}
178
David Benjamin33863262016-07-08 17:20:12 -0700179func getShimCertificate(t testCert) string {
180 for _, cert := range testCerts {
181 if cert.id == t {
182 return cert.certFile
183 }
184 }
185 panic("Unknown test certificate")
186}
187
188func getShimKey(t testCert) string {
189 for _, cert := range testCerts {
190 if cert.id == t {
191 return cert.keyFile
192 }
193 }
194 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700195}
196
David Benjamin025b3d32014-07-01 19:53:04 -0400197type testType int
198
199const (
200 clientTest testType = iota
201 serverTest
202)
203
David Benjamin6fd297b2014-08-11 18:43:38 -0400204type protocol int
205
206const (
207 tls protocol = iota
208 dtls
209)
210
David Benjaminfc7b0862014-09-06 13:21:53 -0400211const (
212 alpn = 1
213 npn = 2
214)
215
Adam Langley95c29f32014-06-20 12:00:00 -0700216type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400217 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400218 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700219 name string
220 config Config
221 shouldFail bool
222 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700223 // expectedLocalError, if not empty, contains a substring that must be
224 // found in the local error.
225 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400226 // expectedVersion, if non-zero, specifies the TLS version that must be
227 // negotiated.
228 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400229 // expectedResumeVersion, if non-zero, specifies the TLS version that
230 // must be negotiated on resumption. If zero, expectedVersion is used.
231 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400232 // expectedCipher, if non-zero, specifies the TLS cipher suite that
233 // should be negotiated.
234 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400235 // expectChannelID controls whether the connection should have
236 // negotiated a Channel ID with channelIDKey.
237 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400238 // expectedNextProto controls whether the connection should
239 // negotiate a next protocol via NPN or ALPN.
240 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400241 // expectNoNextProto, if true, means that no next protocol should be
242 // negotiated.
243 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400244 // expectedNextProtoType, if non-zero, is the expected next
245 // protocol negotiation mechanism.
246 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500247 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
248 // should be negotiated. If zero, none should be negotiated.
249 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100250 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
251 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100252 // expectedSCTList, if not nil, is the expected SCT list to be received.
253 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700254 // expectedPeerSignatureAlgorithm, if not zero, is the signature
255 // algorithm that the peer should have used in the handshake.
256 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700257 // messageLen is the length, in bytes, of the test message that will be
258 // sent.
259 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400260 // messageCount is the number of test messages that will be sent.
261 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400262 // certFile is the path to the certificate to use for the server.
263 certFile string
264 // keyFile is the path to the private key to use for the server.
265 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400266 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400267 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400268 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700269 // expectResumeRejected, if true, specifies that the attempted
270 // resumption must be rejected by the client. This is only valid for a
271 // serverTest.
272 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400273 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500274 // resumption. Unless newSessionsOnResume is set,
275 // SessionTicketKey, ServerSessionCache, and
276 // ClientSessionCache are copied from the initial connection's
277 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400278 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500279 // newSessionsOnResume, if true, will cause resumeConfig to
280 // use a different session resumption context.
281 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400282 // noSessionCache, if true, will cause the server to run without a
283 // session cache.
284 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400285 // sendPrefix sends a prefix on the socket before actually performing a
286 // handshake.
287 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400288 // shimWritesFirst controls whether the shim sends an initial "hello"
289 // message before doing a roundtrip with the runner.
290 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400291 // shimShutsDown, if true, runs a test where the shim shuts down the
292 // connection immediately after the handshake rather than echoing
293 // messages from the runner.
294 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400295 // renegotiate indicates the number of times the connection should be
296 // renegotiated during the exchange.
297 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700298 // renegotiateCiphers is a list of ciphersuite ids that will be
299 // switched in just before renegotiation.
300 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500301 // replayWrites, if true, configures the underlying transport
302 // to replay every write it makes in DTLS tests.
303 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500304 // damageFirstWrite, if true, configures the underlying transport to
305 // damage the final byte of the first application data write.
306 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400307 // exportKeyingMaterial, if non-zero, configures the test to exchange
308 // keying material and verify they match.
309 exportKeyingMaterial int
310 exportLabel string
311 exportContext string
312 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400313 // flags, if not empty, contains a list of command-line flags that will
314 // be passed to the shim program.
315 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700316 // testTLSUnique, if true, causes the shim to send the tls-unique value
317 // which will be compared against the expected value.
318 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400319 // sendEmptyRecords is the number of consecutive empty records to send
320 // before and after the test message.
321 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400322 // sendWarningAlerts is the number of consecutive warning alerts to send
323 // before and after the test message.
324 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400325 // expectMessageDropped, if true, means the test message is expected to
326 // be dropped by the client rather than echoed back.
327 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700328}
329
Adam Langley7c803a62015-06-15 15:35:05 -0700330var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700331
David Benjamin9867b7d2016-03-01 23:25:48 -0500332func writeTranscript(test *testCase, isResume bool, data []byte) {
333 if len(data) == 0 {
334 return
335 }
336
337 protocol := "tls"
338 if test.protocol == dtls {
339 protocol = "dtls"
340 }
341
342 side := "client"
343 if test.testType == serverTest {
344 side = "server"
345 }
346
347 dir := path.Join(*transcriptDir, protocol, side)
348 if err := os.MkdirAll(dir, 0755); err != nil {
349 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
350 return
351 }
352
353 name := test.name
354 if isResume {
355 name += "-Resume"
356 } else {
357 name += "-Normal"
358 }
359
360 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
361 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
362 }
363}
364
David Benjamin3ed59772016-03-08 12:50:21 -0500365// A timeoutConn implements an idle timeout on each Read and Write operation.
366type timeoutConn struct {
367 net.Conn
368 timeout time.Duration
369}
370
371func (t *timeoutConn) Read(b []byte) (int, error) {
372 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
373 return 0, err
374 }
375 return t.Conn.Read(b)
376}
377
378func (t *timeoutConn) Write(b []byte) (int, error) {
379 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
380 return 0, err
381 }
382 return t.Conn.Write(b)
383}
384
David Benjamin8e6db492015-07-25 18:29:23 -0400385func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400386 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500387
David Benjamin6fd297b2014-08-11 18:43:38 -0400388 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500389 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
390 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500391 }
392
David Benjamin9867b7d2016-03-01 23:25:48 -0500393 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500394 local, peer := "client", "server"
395 if test.testType == clientTest {
396 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500397 }
David Benjaminebda9b32015-11-02 15:33:18 -0500398 connDebug := &recordingConn{
399 Conn: conn,
400 isDatagram: test.protocol == dtls,
401 local: local,
402 peer: peer,
403 }
404 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500405 if *flagDebug {
406 defer connDebug.WriteTo(os.Stdout)
407 }
408 if len(*transcriptDir) != 0 {
409 defer func() {
410 writeTranscript(test, isResume, connDebug.Transcript())
411 }()
412 }
David Benjaminebda9b32015-11-02 15:33:18 -0500413
414 if config.Bugs.PacketAdaptor != nil {
415 config.Bugs.PacketAdaptor.debug = connDebug
416 }
417 }
418
419 if test.replayWrites {
420 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400421 }
422
David Benjamin3ed59772016-03-08 12:50:21 -0500423 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 if test.damageFirstWrite {
425 connDamage = newDamageAdaptor(conn)
426 conn = connDamage
427 }
428
David Benjamin6fd297b2014-08-11 18:43:38 -0400429 if test.sendPrefix != "" {
430 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
431 return err
432 }
David Benjamin98e882e2014-08-08 13:24:34 -0400433 }
434
David Benjamin1d5c83e2014-07-22 19:20:02 -0400435 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400436 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400437 if test.protocol == dtls {
438 tlsConn = DTLSServer(conn, config)
439 } else {
440 tlsConn = Server(conn, config)
441 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400442 } else {
443 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400444 if test.protocol == dtls {
445 tlsConn = DTLSClient(conn, config)
446 } else {
447 tlsConn = Client(conn, config)
448 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400449 }
David Benjamin30789da2015-08-29 22:56:45 -0400450 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400451
Adam Langley95c29f32014-06-20 12:00:00 -0700452 if err := tlsConn.Handshake(); err != nil {
453 return err
454 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700455
David Benjamin01fe8202014-09-24 15:21:44 -0400456 // TODO(davidben): move all per-connection expectations into a dedicated
457 // expectations struct that can be specified separately for the two
458 // legs.
459 expectedVersion := test.expectedVersion
460 if isResume && test.expectedResumeVersion != 0 {
461 expectedVersion = test.expectedResumeVersion
462 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700463 connState := tlsConn.ConnectionState()
464 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400465 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400466 }
467
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700468 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400469 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
470 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700471 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
472 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
473 }
David Benjamin90da8c82015-04-20 14:57:57 -0400474
David Benjamina08e49d2014-08-24 01:46:07 -0400475 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700476 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400477 if channelID == nil {
478 return fmt.Errorf("no channel ID negotiated")
479 }
480 if channelID.Curve != channelIDKey.Curve ||
481 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
482 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
483 return fmt.Errorf("incorrect channel ID")
484 }
485 }
486
David Benjaminae2888f2014-09-06 12:58:58 -0400487 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700488 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400489 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
490 }
491 }
492
David Benjaminc7ce9772015-10-09 19:32:41 -0400493 if test.expectNoNextProto {
494 if actual := connState.NegotiatedProtocol; actual != "" {
495 return fmt.Errorf("got unexpected next proto %s", actual)
496 }
497 }
498
David Benjaminfc7b0862014-09-06 13:21:53 -0400499 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700500 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400501 return fmt.Errorf("next proto type mismatch")
502 }
503 }
504
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700505 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500506 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
507 }
508
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100509 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300510 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100511 }
512
Paul Lietar4fac72e2015-09-09 13:44:55 +0100513 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
514 return fmt.Errorf("SCT list mismatch")
515 }
516
Nick Harper60edffd2016-06-21 15:19:24 -0700517 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
518 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400519 }
520
David Benjaminc565ebb2015-04-03 04:06:36 -0400521 if test.exportKeyingMaterial > 0 {
522 actual := make([]byte, test.exportKeyingMaterial)
523 if _, err := io.ReadFull(tlsConn, actual); err != nil {
524 return err
525 }
526 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
527 if err != nil {
528 return err
529 }
530 if !bytes.Equal(actual, expected) {
531 return fmt.Errorf("keying material mismatch")
532 }
533 }
534
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700535 if test.testTLSUnique {
536 var peersValue [12]byte
537 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
538 return err
539 }
540 expected := tlsConn.ConnectionState().TLSUnique
541 if !bytes.Equal(peersValue[:], expected) {
542 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
543 }
544 }
545
David Benjamine58c4f52014-08-24 03:47:07 -0400546 if test.shimWritesFirst {
547 var buf [5]byte
548 _, err := io.ReadFull(tlsConn, buf[:])
549 if err != nil {
550 return err
551 }
552 if string(buf[:]) != "hello" {
553 return fmt.Errorf("bad initial message")
554 }
555 }
556
David Benjamina8ebe222015-06-06 03:04:39 -0400557 for i := 0; i < test.sendEmptyRecords; i++ {
558 tlsConn.Write(nil)
559 }
560
David Benjamin24f346d2015-06-06 03:28:08 -0400561 for i := 0; i < test.sendWarningAlerts; i++ {
562 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
563 }
564
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400565 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700566 if test.renegotiateCiphers != nil {
567 config.CipherSuites = test.renegotiateCiphers
568 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400569 for i := 0; i < test.renegotiate; i++ {
570 if err := tlsConn.Renegotiate(); err != nil {
571 return err
572 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700573 }
574 } else if test.renegotiateCiphers != nil {
575 panic("renegotiateCiphers without renegotiate")
576 }
577
David Benjamin5fa3eba2015-01-22 16:35:40 -0500578 if test.damageFirstWrite {
579 connDamage.setDamage(true)
580 tlsConn.Write([]byte("DAMAGED WRITE"))
581 connDamage.setDamage(false)
582 }
583
David Benjamin8e6db492015-07-25 18:29:23 -0400584 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700585 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400586 if test.protocol == dtls {
587 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
588 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700589 // Read until EOF.
590 _, err := io.Copy(ioutil.Discard, tlsConn)
591 return err
592 }
David Benjamin4417d052015-04-05 04:17:25 -0400593 if messageLen == 0 {
594 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700595 }
Adam Langley95c29f32014-06-20 12:00:00 -0700596
David Benjamin8e6db492015-07-25 18:29:23 -0400597 messageCount := test.messageCount
598 if messageCount == 0 {
599 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400600 }
601
David Benjamin8e6db492015-07-25 18:29:23 -0400602 for j := 0; j < messageCount; j++ {
603 testMessage := make([]byte, messageLen)
604 for i := range testMessage {
605 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400606 }
David Benjamin8e6db492015-07-25 18:29:23 -0400607 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700608
David Benjamin8e6db492015-07-25 18:29:23 -0400609 for i := 0; i < test.sendEmptyRecords; i++ {
610 tlsConn.Write(nil)
611 }
612
613 for i := 0; i < test.sendWarningAlerts; i++ {
614 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
615 }
616
David Benjamin4f75aaf2015-09-01 16:53:10 -0400617 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400618 // The shim will not respond.
619 continue
620 }
621
David Benjamin8e6db492015-07-25 18:29:23 -0400622 buf := make([]byte, len(testMessage))
623 if test.protocol == dtls {
624 bufTmp := make([]byte, len(buf)+1)
625 n, err := tlsConn.Read(bufTmp)
626 if err != nil {
627 return err
628 }
629 if n != len(buf) {
630 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
631 }
632 copy(buf, bufTmp)
633 } else {
634 _, err := io.ReadFull(tlsConn, buf)
635 if err != nil {
636 return err
637 }
638 }
639
640 for i, v := range buf {
641 if v != testMessage[i]^0xff {
642 return fmt.Errorf("bad reply contents at byte %d", i)
643 }
Adam Langley95c29f32014-06-20 12:00:00 -0700644 }
645 }
646
647 return nil
648}
649
David Benjamin325b5c32014-07-01 19:40:31 -0400650func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
651 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700652 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400653 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700654 }
David Benjamin325b5c32014-07-01 19:40:31 -0400655 valgrindArgs = append(valgrindArgs, path)
656 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700657
David Benjamin325b5c32014-07-01 19:40:31 -0400658 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700659}
660
David Benjamin325b5c32014-07-01 19:40:31 -0400661func gdbOf(path string, args ...string) *exec.Cmd {
662 xtermArgs := []string{"-e", "gdb", "--args"}
663 xtermArgs = append(xtermArgs, path)
664 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700665
David Benjamin325b5c32014-07-01 19:40:31 -0400666 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700667}
668
David Benjamind16bf342015-12-18 00:53:12 -0500669func lldbOf(path string, args ...string) *exec.Cmd {
670 xtermArgs := []string{"-e", "lldb", "--"}
671 xtermArgs = append(xtermArgs, path)
672 xtermArgs = append(xtermArgs, args...)
673
674 return exec.Command("xterm", xtermArgs...)
675}
676
Adam Langley69a01602014-11-17 17:26:55 -0800677type moreMallocsError struct{}
678
679func (moreMallocsError) Error() string {
680 return "child process did not exhaust all allocation calls"
681}
682
683var errMoreMallocs = moreMallocsError{}
684
David Benjamin87c8a642015-02-21 01:54:29 -0500685// accept accepts a connection from listener, unless waitChan signals a process
686// exit first.
687func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
688 type connOrError struct {
689 conn net.Conn
690 err error
691 }
692 connChan := make(chan connOrError, 1)
693 go func() {
694 conn, err := listener.Accept()
695 connChan <- connOrError{conn, err}
696 close(connChan)
697 }()
698 select {
699 case result := <-connChan:
700 return result.conn, result.err
701 case childErr := <-waitChan:
702 waitChan <- childErr
703 return nil, fmt.Errorf("child exited early: %s", childErr)
704 }
705}
706
Adam Langley7c803a62015-06-15 15:35:05 -0700707func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700708 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
709 panic("Error expected without shouldFail in " + test.name)
710 }
711
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700712 if test.expectResumeRejected && !test.resumeSession {
713 panic("expectResumeRejected without resumeSession in " + test.name)
714 }
715
David Benjamin87c8a642015-02-21 01:54:29 -0500716 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
717 if err != nil {
718 panic(err)
719 }
720 defer func() {
721 if listener != nil {
722 listener.Close()
723 }
724 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700725
David Benjamin87c8a642015-02-21 01:54:29 -0500726 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400727 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400728 flags = append(flags, "-server")
729
David Benjamin025b3d32014-07-01 19:53:04 -0400730 flags = append(flags, "-key-file")
731 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700732 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400733 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700734 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400735 }
736
737 flags = append(flags, "-cert-file")
738 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700739 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400740 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700741 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400742 }
743 }
David Benjamin5a593af2014-08-11 19:51:50 -0400744
David Benjamin6fd297b2014-08-11 18:43:38 -0400745 if test.protocol == dtls {
746 flags = append(flags, "-dtls")
747 }
748
David Benjamin5a593af2014-08-11 19:51:50 -0400749 if test.resumeSession {
750 flags = append(flags, "-resume")
751 }
752
David Benjamine58c4f52014-08-24 03:47:07 -0400753 if test.shimWritesFirst {
754 flags = append(flags, "-shim-writes-first")
755 }
756
David Benjamin30789da2015-08-29 22:56:45 -0400757 if test.shimShutsDown {
758 flags = append(flags, "-shim-shuts-down")
759 }
760
David Benjaminc565ebb2015-04-03 04:06:36 -0400761 if test.exportKeyingMaterial > 0 {
762 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
763 flags = append(flags, "-export-label", test.exportLabel)
764 flags = append(flags, "-export-context", test.exportContext)
765 if test.useExportContext {
766 flags = append(flags, "-use-export-context")
767 }
768 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700769 if test.expectResumeRejected {
770 flags = append(flags, "-expect-session-miss")
771 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400772
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700773 if test.testTLSUnique {
774 flags = append(flags, "-tls-unique")
775 }
776
David Benjamin025b3d32014-07-01 19:53:04 -0400777 flags = append(flags, test.flags...)
778
779 var shim *exec.Cmd
780 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700781 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700782 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700783 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500784 } else if *useLLDB {
785 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400786 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700787 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400788 }
David Benjamin025b3d32014-07-01 19:53:04 -0400789 shim.Stdin = os.Stdin
790 var stdoutBuf, stderrBuf bytes.Buffer
791 shim.Stdout = &stdoutBuf
792 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800793 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500794 shim.Env = os.Environ()
795 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800796 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400797 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800798 }
799 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
800 }
David Benjamin025b3d32014-07-01 19:53:04 -0400801
802 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700803 panic(err)
804 }
David Benjamin87c8a642015-02-21 01:54:29 -0500805 waitChan := make(chan error, 1)
806 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700807
808 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400809 if !test.noSessionCache {
810 config.ClientSessionCache = NewLRUClientSessionCache(1)
811 config.ServerSessionCache = NewLRUServerSessionCache(1)
812 }
David Benjamin025b3d32014-07-01 19:53:04 -0400813 if test.testType == clientTest {
814 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700815 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400816 }
David Benjamin87c8a642015-02-21 01:54:29 -0500817 } else {
818 // Supply a ServerName to ensure a constant session cache key,
819 // rather than falling back to net.Conn.RemoteAddr.
820 if len(config.ServerName) == 0 {
821 config.ServerName = "test"
822 }
David Benjamin025b3d32014-07-01 19:53:04 -0400823 }
David Benjaminf2b83632016-03-01 22:57:46 -0500824 if *fuzzer {
825 config.Bugs.NullAllCiphers = true
826 }
David Benjamin2e045a92016-06-08 13:09:56 -0400827 if *deterministic {
828 config.Rand = &deterministicRand{}
829 }
Adam Langley95c29f32014-06-20 12:00:00 -0700830
David Benjamin87c8a642015-02-21 01:54:29 -0500831 conn, err := acceptOrWait(listener, waitChan)
832 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400833 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500834 conn.Close()
835 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500836
David Benjamin1d5c83e2014-07-22 19:20:02 -0400837 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400838 var resumeConfig Config
839 if test.resumeConfig != nil {
840 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500841 if len(resumeConfig.ServerName) == 0 {
842 resumeConfig.ServerName = config.ServerName
843 }
David Benjamin01fe8202014-09-24 15:21:44 -0400844 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700845 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400846 }
David Benjaminba4594a2015-06-18 18:36:15 -0400847 if test.newSessionsOnResume {
848 if !test.noSessionCache {
849 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
850 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
851 }
852 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500853 resumeConfig.SessionTicketKey = config.SessionTicketKey
854 resumeConfig.ClientSessionCache = config.ClientSessionCache
855 resumeConfig.ServerSessionCache = config.ServerSessionCache
856 }
David Benjaminf2b83632016-03-01 22:57:46 -0500857 if *fuzzer {
858 resumeConfig.Bugs.NullAllCiphers = true
859 }
David Benjamin2e045a92016-06-08 13:09:56 -0400860 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400861 } else {
862 resumeConfig = config
863 }
David Benjamin87c8a642015-02-21 01:54:29 -0500864 var connResume net.Conn
865 connResume, err = acceptOrWait(listener, waitChan)
866 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400867 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500868 connResume.Close()
869 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400870 }
871
David Benjamin87c8a642015-02-21 01:54:29 -0500872 // Close the listener now. This is to avoid hangs should the shim try to
873 // open more connections than expected.
874 listener.Close()
875 listener = nil
876
877 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800878 if exitError, ok := childErr.(*exec.ExitError); ok {
879 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
880 return errMoreMallocs
881 }
882 }
Adam Langley95c29f32014-06-20 12:00:00 -0700883
David Benjamin9bea3492016-03-02 10:59:16 -0500884 // Account for Windows line endings.
885 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
886 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500887
888 // Separate the errors from the shim and those from tools like
889 // AddressSanitizer.
890 var extraStderr string
891 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
892 stderr = stderrParts[0]
893 extraStderr = stderrParts[1]
894 }
895
Adam Langley95c29f32014-06-20 12:00:00 -0700896 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400897 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700898 localError := "none"
899 if err != nil {
900 localError = err.Error()
901 }
902 if len(test.expectedLocalError) != 0 {
903 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
904 }
Adam Langley95c29f32014-06-20 12:00:00 -0700905
906 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700907 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700908 if childErr != nil {
909 childError = childErr.Error()
910 }
911
912 var msg string
913 switch {
914 case failed && !test.shouldFail:
915 msg = "unexpected failure"
916 case !failed && test.shouldFail:
917 msg = "unexpected success"
918 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700919 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700920 default:
921 panic("internal error")
922 }
923
David Benjaminc565ebb2015-04-03 04:06:36 -0400924 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 -0700925 }
926
David Benjaminff3a1492016-03-02 10:12:06 -0500927 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
928 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700929 }
930
931 return nil
932}
933
934var tlsVersions = []struct {
935 name string
936 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400937 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500938 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700939}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500940 {"SSL3", VersionSSL30, "-no-ssl3", false},
941 {"TLS1", VersionTLS10, "-no-tls1", true},
942 {"TLS11", VersionTLS11, "-no-tls11", false},
943 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400944 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700945}
946
947var testCipherSuites = []struct {
948 name string
949 id uint16
950}{
951 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400952 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700953 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400954 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400955 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700956 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400957 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400958 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
959 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400960 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400961 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
962 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400963 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700964 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
965 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400966 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
967 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700968 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400969 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500970 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500971 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700973 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700974 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400975 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400976 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700977 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400978 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500979 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500980 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700982 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
983 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
984 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
985 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400986 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
987 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700988 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
989 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500990 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400991 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
992 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400993 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700994 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400995 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700996 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700997}
998
David Benjamin8b8c0062014-11-23 02:47:52 -0500999func hasComponent(suiteName, component string) bool {
1000 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1001}
1002
David Benjaminf7768e42014-08-31 02:06:47 -04001003func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001004 return hasComponent(suiteName, "GCM") ||
1005 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001006 hasComponent(suiteName, "SHA384") ||
1007 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001008}
1009
Nick Harper1fd39d82016-06-14 18:14:35 -07001010func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001011 // Only AEADs.
1012 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1013 return false
1014 }
1015 // No old CHACHA20_POLY1305.
1016 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1017 return false
1018 }
1019 // Must have ECDHE.
1020 // TODO(davidben,svaldez): Add pure PSK support.
1021 if !hasComponent(suiteName, "ECDHE") {
1022 return false
1023 }
1024 // TODO(davidben,svaldez): Add PSK support.
1025 if hasComponent(suiteName, "PSK") {
1026 return false
1027 }
1028 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001029}
1030
David Benjamin8b8c0062014-11-23 02:47:52 -05001031func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001032 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001033}
1034
Adam Langleya7997f12015-05-14 17:38:50 -07001035func bigFromHex(hex string) *big.Int {
1036 ret, ok := new(big.Int).SetString(hex, 16)
1037 if !ok {
1038 panic("failed to parse hex number 0x" + hex)
1039 }
1040 return ret
1041}
1042
Adam Langley7c803a62015-06-15 15:35:05 -07001043func addBasicTests() {
1044 basicTests := []testCase{
1045 {
Adam Langley7c803a62015-06-15 15:35:05 -07001046 name: "NoFallbackSCSV",
1047 config: Config{
1048 Bugs: ProtocolBugs{
1049 FailIfNotFallbackSCSV: true,
1050 },
1051 },
1052 shouldFail: true,
1053 expectedLocalError: "no fallback SCSV found",
1054 },
1055 {
1056 name: "SendFallbackSCSV",
1057 config: Config{
1058 Bugs: ProtocolBugs{
1059 FailIfNotFallbackSCSV: true,
1060 },
1061 },
1062 flags: []string{"-fallback-scsv"},
1063 },
1064 {
1065 name: "ClientCertificateTypes",
1066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001067 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001068 ClientAuth: RequestClientCert,
1069 ClientCertificateTypes: []byte{
1070 CertTypeDSSSign,
1071 CertTypeRSASign,
1072 CertTypeECDSASign,
1073 },
1074 },
1075 flags: []string{
1076 "-expect-certificate-types",
1077 base64.StdEncoding.EncodeToString([]byte{
1078 CertTypeDSSSign,
1079 CertTypeRSASign,
1080 CertTypeECDSASign,
1081 }),
1082 },
1083 },
1084 {
Adam Langley7c803a62015-06-15 15:35:05 -07001085 name: "UnauthenticatedECDH",
1086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001087 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001088 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1089 Bugs: ProtocolBugs{
1090 UnauthenticatedECDH: true,
1091 },
1092 },
1093 shouldFail: true,
1094 expectedError: ":UNEXPECTED_MESSAGE:",
1095 },
1096 {
1097 name: "SkipCertificateStatus",
1098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001099 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1101 Bugs: ProtocolBugs{
1102 SkipCertificateStatus: true,
1103 },
1104 },
1105 flags: []string{
1106 "-enable-ocsp-stapling",
1107 },
1108 },
1109 {
1110 name: "SkipServerKeyExchange",
1111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001112 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001113 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1114 Bugs: ProtocolBugs{
1115 SkipServerKeyExchange: true,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedError: ":UNEXPECTED_MESSAGE:",
1120 },
1121 {
Adam Langley7c803a62015-06-15 15:35:05 -07001122 testType: serverTest,
1123 name: "Alert",
1124 config: Config{
1125 Bugs: ProtocolBugs{
1126 SendSpuriousAlert: alertRecordOverflow,
1127 },
1128 },
1129 shouldFail: true,
1130 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1131 },
1132 {
1133 protocol: dtls,
1134 testType: serverTest,
1135 name: "Alert-DTLS",
1136 config: Config{
1137 Bugs: ProtocolBugs{
1138 SendSpuriousAlert: alertRecordOverflow,
1139 },
1140 },
1141 shouldFail: true,
1142 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1143 },
1144 {
1145 testType: serverTest,
1146 name: "FragmentAlert",
1147 config: Config{
1148 Bugs: ProtocolBugs{
1149 FragmentAlert: true,
1150 SendSpuriousAlert: alertRecordOverflow,
1151 },
1152 },
1153 shouldFail: true,
1154 expectedError: ":BAD_ALERT:",
1155 },
1156 {
1157 protocol: dtls,
1158 testType: serverTest,
1159 name: "FragmentAlert-DTLS",
1160 config: Config{
1161 Bugs: ProtocolBugs{
1162 FragmentAlert: true,
1163 SendSpuriousAlert: alertRecordOverflow,
1164 },
1165 },
1166 shouldFail: true,
1167 expectedError: ":BAD_ALERT:",
1168 },
1169 {
1170 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001171 name: "DoubleAlert",
1172 config: Config{
1173 Bugs: ProtocolBugs{
1174 DoubleAlert: true,
1175 SendSpuriousAlert: alertRecordOverflow,
1176 },
1177 },
1178 shouldFail: true,
1179 expectedError: ":BAD_ALERT:",
1180 },
1181 {
1182 protocol: dtls,
1183 testType: serverTest,
1184 name: "DoubleAlert-DTLS",
1185 config: Config{
1186 Bugs: ProtocolBugs{
1187 DoubleAlert: true,
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":BAD_ALERT:",
1193 },
1194 {
Adam Langley7c803a62015-06-15 15:35:05 -07001195 name: "SkipNewSessionTicket",
1196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001197 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001198 Bugs: ProtocolBugs{
1199 SkipNewSessionTicket: true,
1200 },
1201 },
1202 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001203 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001204 },
1205 {
1206 testType: serverTest,
1207 name: "FallbackSCSV",
1208 config: Config{
1209 MaxVersion: VersionTLS11,
1210 Bugs: ProtocolBugs{
1211 SendFallbackSCSV: true,
1212 },
1213 },
1214 shouldFail: true,
1215 expectedError: ":INAPPROPRIATE_FALLBACK:",
1216 },
1217 {
1218 testType: serverTest,
1219 name: "FallbackSCSV-VersionMatch",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 SendFallbackSCSV: true,
1223 },
1224 },
1225 },
1226 {
1227 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001228 name: "FallbackSCSV-VersionMatch-TLS12",
1229 config: Config{
1230 MaxVersion: VersionTLS12,
1231 Bugs: ProtocolBugs{
1232 SendFallbackSCSV: true,
1233 },
1234 },
1235 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1236 },
1237 {
1238 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001239 name: "FragmentedClientVersion",
1240 config: Config{
1241 Bugs: ProtocolBugs{
1242 MaxHandshakeRecordLength: 1,
1243 FragmentClientVersion: true,
1244 },
1245 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001246 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001247 },
1248 {
Adam Langley7c803a62015-06-15 15:35:05 -07001249 testType: serverTest,
1250 name: "HttpGET",
1251 sendPrefix: "GET / HTTP/1.0\n",
1252 shouldFail: true,
1253 expectedError: ":HTTP_REQUEST:",
1254 },
1255 {
1256 testType: serverTest,
1257 name: "HttpPOST",
1258 sendPrefix: "POST / HTTP/1.0\n",
1259 shouldFail: true,
1260 expectedError: ":HTTP_REQUEST:",
1261 },
1262 {
1263 testType: serverTest,
1264 name: "HttpHEAD",
1265 sendPrefix: "HEAD / HTTP/1.0\n",
1266 shouldFail: true,
1267 expectedError: ":HTTP_REQUEST:",
1268 },
1269 {
1270 testType: serverTest,
1271 name: "HttpPUT",
1272 sendPrefix: "PUT / HTTP/1.0\n",
1273 shouldFail: true,
1274 expectedError: ":HTTP_REQUEST:",
1275 },
1276 {
1277 testType: serverTest,
1278 name: "HttpCONNECT",
1279 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1280 shouldFail: true,
1281 expectedError: ":HTTPS_PROXY_REQUEST:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "Garbage",
1286 sendPrefix: "blah",
1287 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001288 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001289 },
1290 {
Adam Langley7c803a62015-06-15 15:35:05 -07001291 name: "RSAEphemeralKey",
1292 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001293 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001294 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1295 Bugs: ProtocolBugs{
1296 RSAEphemeralKey: true,
1297 },
1298 },
1299 shouldFail: true,
1300 expectedError: ":UNEXPECTED_MESSAGE:",
1301 },
1302 {
1303 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001304 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001305 shouldFail: true,
1306 expectedError: ":WRONG_SSL_VERSION:",
1307 },
1308 {
1309 protocol: dtls,
1310 name: "DisableEverything-DTLS",
1311 flags: []string{"-no-tls12", "-no-tls1"},
1312 shouldFail: true,
1313 expectedError: ":WRONG_SSL_VERSION:",
1314 },
1315 {
Adam Langley7c803a62015-06-15 15:35:05 -07001316 protocol: dtls,
1317 testType: serverTest,
1318 name: "MTU",
1319 config: Config{
1320 Bugs: ProtocolBugs{
1321 MaxPacketLength: 256,
1322 },
1323 },
1324 flags: []string{"-mtu", "256"},
1325 },
1326 {
1327 protocol: dtls,
1328 testType: serverTest,
1329 name: "MTUExceeded",
1330 config: Config{
1331 Bugs: ProtocolBugs{
1332 MaxPacketLength: 255,
1333 },
1334 },
1335 flags: []string{"-mtu", "256"},
1336 shouldFail: true,
1337 expectedLocalError: "dtls: exceeded maximum packet length",
1338 },
1339 {
1340 name: "CertMismatchRSA",
1341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001342 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001343 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001344 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001345 Bugs: ProtocolBugs{
1346 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1347 },
1348 },
1349 shouldFail: true,
1350 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1351 },
1352 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001353 name: "CertMismatchRSA-TLS13",
1354 config: Config{
1355 MaxVersion: VersionTLS13,
1356 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1357 Certificates: []Certificate{ecdsaP256Certificate},
1358 Bugs: ProtocolBugs{
1359 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1360 },
1361 },
1362 shouldFail: true,
1363 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1364 },
1365 {
Adam Langley7c803a62015-06-15 15:35:05 -07001366 name: "CertMismatchECDSA",
1367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001368 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001369 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001370 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001371 Bugs: ProtocolBugs{
1372 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1373 },
1374 },
1375 shouldFail: true,
1376 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1377 },
1378 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001379 name: "CertMismatchECDSA-TLS13",
1380 config: Config{
1381 MaxVersion: VersionTLS13,
1382 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1383 Certificates: []Certificate{rsaCertificate},
1384 Bugs: ProtocolBugs{
1385 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1386 },
1387 },
1388 shouldFail: true,
1389 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1390 },
1391 {
Adam Langley7c803a62015-06-15 15:35:05 -07001392 name: "EmptyCertificateList",
1393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001394 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001395 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1396 Bugs: ProtocolBugs{
1397 EmptyCertificateList: true,
1398 },
1399 },
1400 shouldFail: true,
1401 expectedError: ":DECODE_ERROR:",
1402 },
1403 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001404 name: "EmptyCertificateList-TLS13",
1405 config: Config{
1406 MaxVersion: VersionTLS13,
1407 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1408 Bugs: ProtocolBugs{
1409 EmptyCertificateList: true,
1410 },
1411 },
1412 shouldFail: true,
1413 expectedError: ":DECODE_ERROR:",
1414 },
1415 {
Adam Langley7c803a62015-06-15 15:35:05 -07001416 name: "TLSFatalBadPackets",
1417 damageFirstWrite: true,
1418 shouldFail: true,
1419 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1420 },
1421 {
1422 protocol: dtls,
1423 name: "DTLSIgnoreBadPackets",
1424 damageFirstWrite: true,
1425 },
1426 {
1427 protocol: dtls,
1428 name: "DTLSIgnoreBadPackets-Async",
1429 damageFirstWrite: true,
1430 flags: []string{"-async"},
1431 },
1432 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001433 name: "AppDataBeforeHandshake",
1434 config: Config{
1435 Bugs: ProtocolBugs{
1436 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1437 },
1438 },
1439 shouldFail: true,
1440 expectedError: ":UNEXPECTED_RECORD:",
1441 },
1442 {
1443 name: "AppDataBeforeHandshake-Empty",
1444 config: Config{
1445 Bugs: ProtocolBugs{
1446 AppDataBeforeHandshake: []byte{},
1447 },
1448 },
1449 shouldFail: true,
1450 expectedError: ":UNEXPECTED_RECORD:",
1451 },
1452 {
1453 protocol: dtls,
1454 name: "AppDataBeforeHandshake-DTLS",
1455 config: Config{
1456 Bugs: ProtocolBugs{
1457 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1458 },
1459 },
1460 shouldFail: true,
1461 expectedError: ":UNEXPECTED_RECORD:",
1462 },
1463 {
1464 protocol: dtls,
1465 name: "AppDataBeforeHandshake-DTLS-Empty",
1466 config: Config{
1467 Bugs: ProtocolBugs{
1468 AppDataBeforeHandshake: []byte{},
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":UNEXPECTED_RECORD:",
1473 },
1474 {
Adam Langley7c803a62015-06-15 15:35:05 -07001475 name: "AppDataAfterChangeCipherSpec",
1476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001477 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001478 Bugs: ProtocolBugs{
1479 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1480 },
1481 },
1482 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001483 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001484 },
1485 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001486 name: "AppDataAfterChangeCipherSpec-Empty",
1487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001488 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001489 Bugs: ProtocolBugs{
1490 AppDataAfterChangeCipherSpec: []byte{},
1491 },
1492 },
1493 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001494 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 },
1496 {
Adam Langley7c803a62015-06-15 15:35:05 -07001497 protocol: dtls,
1498 name: "AppDataAfterChangeCipherSpec-DTLS",
1499 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001500 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001501 Bugs: ProtocolBugs{
1502 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1503 },
1504 },
1505 // BoringSSL's DTLS implementation will drop the out-of-order
1506 // application data.
1507 },
1508 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001509 protocol: dtls,
1510 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1511 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001512 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001513 Bugs: ProtocolBugs{
1514 AppDataAfterChangeCipherSpec: []byte{},
1515 },
1516 },
1517 // BoringSSL's DTLS implementation will drop the out-of-order
1518 // application data.
1519 },
1520 {
Adam Langley7c803a62015-06-15 15:35:05 -07001521 name: "AlertAfterChangeCipherSpec",
1522 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001523 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001524 Bugs: ProtocolBugs{
1525 AlertAfterChangeCipherSpec: alertRecordOverflow,
1526 },
1527 },
1528 shouldFail: true,
1529 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1530 },
1531 {
1532 protocol: dtls,
1533 name: "AlertAfterChangeCipherSpec-DTLS",
1534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001535 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001536 Bugs: ProtocolBugs{
1537 AlertAfterChangeCipherSpec: alertRecordOverflow,
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1542 },
1543 {
1544 protocol: dtls,
1545 name: "ReorderHandshakeFragments-Small-DTLS",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 ReorderHandshakeFragments: true,
1549 // Small enough that every handshake message is
1550 // fragmented.
1551 MaxHandshakeRecordLength: 2,
1552 },
1553 },
1554 },
1555 {
1556 protocol: dtls,
1557 name: "ReorderHandshakeFragments-Large-DTLS",
1558 config: Config{
1559 Bugs: ProtocolBugs{
1560 ReorderHandshakeFragments: true,
1561 // Large enough that no handshake message is
1562 // fragmented.
1563 MaxHandshakeRecordLength: 2048,
1564 },
1565 },
1566 },
1567 {
1568 protocol: dtls,
1569 name: "MixCompleteMessageWithFragments-DTLS",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 ReorderHandshakeFragments: true,
1573 MixCompleteMessageWithFragments: true,
1574 MaxHandshakeRecordLength: 2,
1575 },
1576 },
1577 },
1578 {
1579 name: "SendInvalidRecordType",
1580 config: Config{
1581 Bugs: ProtocolBugs{
1582 SendInvalidRecordType: true,
1583 },
1584 },
1585 shouldFail: true,
1586 expectedError: ":UNEXPECTED_RECORD:",
1587 },
1588 {
1589 protocol: dtls,
1590 name: "SendInvalidRecordType-DTLS",
1591 config: Config{
1592 Bugs: ProtocolBugs{
1593 SendInvalidRecordType: true,
1594 },
1595 },
1596 shouldFail: true,
1597 expectedError: ":UNEXPECTED_RECORD:",
1598 },
1599 {
1600 name: "FalseStart-SkipServerSecondLeg",
1601 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001602 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001603 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1604 NextProtos: []string{"foo"},
1605 Bugs: ProtocolBugs{
1606 SkipNewSessionTicket: true,
1607 SkipChangeCipherSpec: true,
1608 SkipFinished: true,
1609 ExpectFalseStart: true,
1610 },
1611 },
1612 flags: []string{
1613 "-false-start",
1614 "-handshake-never-done",
1615 "-advertise-alpn", "\x03foo",
1616 },
1617 shimWritesFirst: true,
1618 shouldFail: true,
1619 expectedError: ":UNEXPECTED_RECORD:",
1620 },
1621 {
1622 name: "FalseStart-SkipServerSecondLeg-Implicit",
1623 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001624 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1626 NextProtos: []string{"foo"},
1627 Bugs: ProtocolBugs{
1628 SkipNewSessionTicket: true,
1629 SkipChangeCipherSpec: true,
1630 SkipFinished: true,
1631 },
1632 },
1633 flags: []string{
1634 "-implicit-handshake",
1635 "-false-start",
1636 "-handshake-never-done",
1637 "-advertise-alpn", "\x03foo",
1638 },
1639 shouldFail: true,
1640 expectedError: ":UNEXPECTED_RECORD:",
1641 },
1642 {
1643 testType: serverTest,
1644 name: "FailEarlyCallback",
1645 flags: []string{"-fail-early-callback"},
1646 shouldFail: true,
1647 expectedError: ":CONNECTION_REJECTED:",
1648 expectedLocalError: "remote error: access denied",
1649 },
1650 {
Adam Langley7c803a62015-06-15 15:35:05 -07001651 protocol: dtls,
1652 name: "FragmentMessageTypeMismatch-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 MaxHandshakeRecordLength: 2,
1656 FragmentMessageTypeMismatch: true,
1657 },
1658 },
1659 shouldFail: true,
1660 expectedError: ":FRAGMENT_MISMATCH:",
1661 },
1662 {
1663 protocol: dtls,
1664 name: "FragmentMessageLengthMismatch-DTLS",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 MaxHandshakeRecordLength: 2,
1668 FragmentMessageLengthMismatch: true,
1669 },
1670 },
1671 shouldFail: true,
1672 expectedError: ":FRAGMENT_MISMATCH:",
1673 },
1674 {
1675 protocol: dtls,
1676 name: "SplitFragments-Header-DTLS",
1677 config: Config{
1678 Bugs: ProtocolBugs{
1679 SplitFragments: 2,
1680 },
1681 },
1682 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001683 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001684 },
1685 {
1686 protocol: dtls,
1687 name: "SplitFragments-Boundary-DTLS",
1688 config: Config{
1689 Bugs: ProtocolBugs{
1690 SplitFragments: dtlsRecordHeaderLen,
1691 },
1692 },
1693 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001694 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001695 },
1696 {
1697 protocol: dtls,
1698 name: "SplitFragments-Body-DTLS",
1699 config: Config{
1700 Bugs: ProtocolBugs{
1701 SplitFragments: dtlsRecordHeaderLen + 1,
1702 },
1703 },
1704 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001705 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001706 },
1707 {
1708 protocol: dtls,
1709 name: "SendEmptyFragments-DTLS",
1710 config: Config{
1711 Bugs: ProtocolBugs{
1712 SendEmptyFragments: true,
1713 },
1714 },
1715 },
1716 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001717 name: "BadFinished-Client",
1718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001719 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001720 Bugs: ProtocolBugs{
1721 BadFinished: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":DIGEST_CHECK_FAILED:",
1726 },
1727 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001728 name: "BadFinished-Client-TLS13",
1729 config: Config{
1730 MaxVersion: VersionTLS13,
1731 Bugs: ProtocolBugs{
1732 BadFinished: true,
1733 },
1734 },
1735 shouldFail: true,
1736 expectedError: ":DIGEST_CHECK_FAILED:",
1737 },
1738 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001739 testType: serverTest,
1740 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001741 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001742 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001743 Bugs: ProtocolBugs{
1744 BadFinished: true,
1745 },
1746 },
1747 shouldFail: true,
1748 expectedError: ":DIGEST_CHECK_FAILED:",
1749 },
1750 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001751 testType: serverTest,
1752 name: "BadFinished-Server-TLS13",
1753 config: Config{
1754 MaxVersion: VersionTLS13,
1755 Bugs: ProtocolBugs{
1756 BadFinished: true,
1757 },
1758 },
1759 shouldFail: true,
1760 expectedError: ":DIGEST_CHECK_FAILED:",
1761 },
1762 {
Adam Langley7c803a62015-06-15 15:35:05 -07001763 name: "FalseStart-BadFinished",
1764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001765 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1767 NextProtos: []string{"foo"},
1768 Bugs: ProtocolBugs{
1769 BadFinished: true,
1770 ExpectFalseStart: true,
1771 },
1772 },
1773 flags: []string{
1774 "-false-start",
1775 "-handshake-never-done",
1776 "-advertise-alpn", "\x03foo",
1777 },
1778 shimWritesFirst: true,
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
1783 name: "NoFalseStart-NoALPN",
1784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001785 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1787 Bugs: ProtocolBugs{
1788 ExpectFalseStart: true,
1789 AlertBeforeFalseStartTest: alertAccessDenied,
1790 },
1791 },
1792 flags: []string{
1793 "-false-start",
1794 },
1795 shimWritesFirst: true,
1796 shouldFail: true,
1797 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1798 expectedLocalError: "tls: peer did not false start: EOF",
1799 },
1800 {
1801 name: "NoFalseStart-NoAEAD",
1802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001803 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1805 NextProtos: []string{"foo"},
1806 Bugs: ProtocolBugs{
1807 ExpectFalseStart: true,
1808 AlertBeforeFalseStartTest: alertAccessDenied,
1809 },
1810 },
1811 flags: []string{
1812 "-false-start",
1813 "-advertise-alpn", "\x03foo",
1814 },
1815 shimWritesFirst: true,
1816 shouldFail: true,
1817 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1818 expectedLocalError: "tls: peer did not false start: EOF",
1819 },
1820 {
1821 name: "NoFalseStart-RSA",
1822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001823 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001824 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1825 NextProtos: []string{"foo"},
1826 Bugs: ProtocolBugs{
1827 ExpectFalseStart: true,
1828 AlertBeforeFalseStartTest: alertAccessDenied,
1829 },
1830 },
1831 flags: []string{
1832 "-false-start",
1833 "-advertise-alpn", "\x03foo",
1834 },
1835 shimWritesFirst: true,
1836 shouldFail: true,
1837 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1838 expectedLocalError: "tls: peer did not false start: EOF",
1839 },
1840 {
1841 name: "NoFalseStart-DHE_RSA",
1842 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001843 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001844 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1845 NextProtos: []string{"foo"},
1846 Bugs: ProtocolBugs{
1847 ExpectFalseStart: true,
1848 AlertBeforeFalseStartTest: alertAccessDenied,
1849 },
1850 },
1851 flags: []string{
1852 "-false-start",
1853 "-advertise-alpn", "\x03foo",
1854 },
1855 shimWritesFirst: true,
1856 shouldFail: true,
1857 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1858 expectedLocalError: "tls: peer did not false start: EOF",
1859 },
1860 {
Adam Langley7c803a62015-06-15 15:35:05 -07001861 protocol: dtls,
1862 name: "SendSplitAlert-Sync",
1863 config: Config{
1864 Bugs: ProtocolBugs{
1865 SendSplitAlert: true,
1866 },
1867 },
1868 },
1869 {
1870 protocol: dtls,
1871 name: "SendSplitAlert-Async",
1872 config: Config{
1873 Bugs: ProtocolBugs{
1874 SendSplitAlert: true,
1875 },
1876 },
1877 flags: []string{"-async"},
1878 },
1879 {
1880 protocol: dtls,
1881 name: "PackDTLSHandshake",
1882 config: Config{
1883 Bugs: ProtocolBugs{
1884 MaxHandshakeRecordLength: 2,
1885 PackHandshakeFragments: 20,
1886 PackHandshakeRecords: 200,
1887 },
1888 },
1889 },
1890 {
Adam Langley7c803a62015-06-15 15:35:05 -07001891 name: "SendEmptyRecords-Pass",
1892 sendEmptyRecords: 32,
1893 },
1894 {
1895 name: "SendEmptyRecords",
1896 sendEmptyRecords: 33,
1897 shouldFail: true,
1898 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1899 },
1900 {
1901 name: "SendEmptyRecords-Async",
1902 sendEmptyRecords: 33,
1903 flags: []string{"-async"},
1904 shouldFail: true,
1905 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1906 },
1907 {
1908 name: "SendWarningAlerts-Pass",
1909 sendWarningAlerts: 4,
1910 },
1911 {
1912 protocol: dtls,
1913 name: "SendWarningAlerts-DTLS-Pass",
1914 sendWarningAlerts: 4,
1915 },
1916 {
1917 name: "SendWarningAlerts",
1918 sendWarningAlerts: 5,
1919 shouldFail: true,
1920 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1921 },
1922 {
1923 name: "SendWarningAlerts-Async",
1924 sendWarningAlerts: 5,
1925 flags: []string{"-async"},
1926 shouldFail: true,
1927 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1928 },
David Benjaminba4594a2015-06-18 18:36:15 -04001929 {
1930 name: "EmptySessionID",
1931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001932 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001933 SessionTicketsDisabled: true,
1934 },
1935 noSessionCache: true,
1936 flags: []string{"-expect-no-session"},
1937 },
David Benjamin30789da2015-08-29 22:56:45 -04001938 {
1939 name: "Unclean-Shutdown",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 NoCloseNotify: true,
1943 ExpectCloseNotify: true,
1944 },
1945 },
1946 shimShutsDown: true,
1947 flags: []string{"-check-close-notify"},
1948 shouldFail: true,
1949 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1950 },
1951 {
1952 name: "Unclean-Shutdown-Ignored",
1953 config: Config{
1954 Bugs: ProtocolBugs{
1955 NoCloseNotify: true,
1956 },
1957 },
1958 shimShutsDown: true,
1959 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001960 {
David Benjaminfa214e42016-05-10 17:03:10 -04001961 name: "Unclean-Shutdown-Alert",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 SendAlertOnShutdown: alertDecompressionFailure,
1965 ExpectCloseNotify: true,
1966 },
1967 },
1968 shimShutsDown: true,
1969 flags: []string{"-check-close-notify"},
1970 shouldFail: true,
1971 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1972 },
1973 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001974 name: "LargePlaintext",
1975 config: Config{
1976 Bugs: ProtocolBugs{
1977 SendLargeRecords: true,
1978 },
1979 },
1980 messageLen: maxPlaintext + 1,
1981 shouldFail: true,
1982 expectedError: ":DATA_LENGTH_TOO_LONG:",
1983 },
1984 {
1985 protocol: dtls,
1986 name: "LargePlaintext-DTLS",
1987 config: Config{
1988 Bugs: ProtocolBugs{
1989 SendLargeRecords: true,
1990 },
1991 },
1992 messageLen: maxPlaintext + 1,
1993 shouldFail: true,
1994 expectedError: ":DATA_LENGTH_TOO_LONG:",
1995 },
1996 {
1997 name: "LargeCiphertext",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SendLargeRecords: true,
2001 },
2002 },
2003 messageLen: maxPlaintext * 2,
2004 shouldFail: true,
2005 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2006 },
2007 {
2008 protocol: dtls,
2009 name: "LargeCiphertext-DTLS",
2010 config: Config{
2011 Bugs: ProtocolBugs{
2012 SendLargeRecords: true,
2013 },
2014 },
2015 messageLen: maxPlaintext * 2,
2016 // Unlike the other four cases, DTLS drops records which
2017 // are invalid before authentication, so the connection
2018 // does not fail.
2019 expectMessageDropped: true,
2020 },
David Benjamindd6fed92015-10-23 17:41:12 -04002021 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002022 // In TLS 1.2 and below, empty NewSessionTicket messages
2023 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002024 name: "SendEmptySessionTicket",
2025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002026 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002027 Bugs: ProtocolBugs{
2028 SendEmptySessionTicket: true,
2029 FailIfSessionOffered: true,
2030 },
2031 },
2032 flags: []string{"-expect-no-session"},
2033 resumeSession: true,
2034 expectResumeRejected: true,
2035 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002036 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002037 name: "BadHelloRequest-1",
2038 renegotiate: 1,
2039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002040 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002041 Bugs: ProtocolBugs{
2042 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2043 },
2044 },
2045 flags: []string{
2046 "-renegotiate-freely",
2047 "-expect-total-renegotiations", "1",
2048 },
2049 shouldFail: true,
2050 expectedError: ":BAD_HELLO_REQUEST:",
2051 },
2052 {
2053 name: "BadHelloRequest-2",
2054 renegotiate: 1,
2055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002056 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002057 Bugs: ProtocolBugs{
2058 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2059 },
2060 },
2061 flags: []string{
2062 "-renegotiate-freely",
2063 "-expect-total-renegotiations", "1",
2064 },
2065 shouldFail: true,
2066 expectedError: ":BAD_HELLO_REQUEST:",
2067 },
David Benjaminef1b0092015-11-21 14:05:44 -05002068 {
2069 testType: serverTest,
2070 name: "SupportTicketsWithSessionID",
2071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002072 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002073 SessionTicketsDisabled: true,
2074 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002075 resumeConfig: &Config{
2076 MaxVersion: VersionTLS12,
2077 },
David Benjaminef1b0092015-11-21 14:05:44 -05002078 resumeSession: true,
2079 },
Adam Langley7c803a62015-06-15 15:35:05 -07002080 }
Adam Langley7c803a62015-06-15 15:35:05 -07002081 testCases = append(testCases, basicTests...)
2082}
2083
Adam Langley95c29f32014-06-20 12:00:00 -07002084func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002085 const bogusCipher = 0xfe00
2086
Adam Langley95c29f32014-06-20 12:00:00 -07002087 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002088 const psk = "12345"
2089 const pskIdentity = "luggage combo"
2090
Adam Langley95c29f32014-06-20 12:00:00 -07002091 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002092 var certFile string
2093 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002094 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002095 cert = ecdsaP256Certificate
2096 certFile = ecdsaP256CertificateFile
2097 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002098 } else {
David Benjamin33863262016-07-08 17:20:12 -07002099 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002100 certFile = rsaCertificateFile
2101 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002102 }
2103
David Benjamin48cae082014-10-27 01:06:24 -04002104 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002105 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002106 flags = append(flags,
2107 "-psk", psk,
2108 "-psk-identity", pskIdentity)
2109 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002110 if hasComponent(suite.name, "NULL") {
2111 // NULL ciphers must be explicitly enabled.
2112 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2113 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002114 if hasComponent(suite.name, "CECPQ1") {
2115 // CECPQ1 ciphers must be explicitly enabled.
2116 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2117 }
David Benjamin48cae082014-10-27 01:06:24 -04002118
Adam Langley95c29f32014-06-20 12:00:00 -07002119 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002120 for _, protocol := range []protocol{tls, dtls} {
2121 var prefix string
2122 if protocol == dtls {
2123 if !ver.hasDTLS {
2124 continue
2125 }
2126 prefix = "D"
2127 }
Adam Langley95c29f32014-06-20 12:00:00 -07002128
David Benjamin0407e762016-06-17 16:41:18 -04002129 var shouldServerFail, shouldClientFail bool
2130 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2131 // BoringSSL clients accept ECDHE on SSLv3, but
2132 // a BoringSSL server will never select it
2133 // because the extension is missing.
2134 shouldServerFail = true
2135 }
2136 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2137 shouldClientFail = true
2138 shouldServerFail = true
2139 }
David Benjamin54c217c2016-07-13 12:35:25 -04002140 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002141 shouldClientFail = true
2142 shouldServerFail = true
2143 }
David Benjamin0407e762016-06-17 16:41:18 -04002144 if !isDTLSCipher(suite.name) && protocol == dtls {
2145 shouldClientFail = true
2146 shouldServerFail = true
2147 }
David Benjamin4298d772015-12-19 00:18:25 -05002148
David Benjamin0407e762016-06-17 16:41:18 -04002149 var expectedServerError, expectedClientError string
2150 if shouldServerFail {
2151 expectedServerError = ":NO_SHARED_CIPHER:"
2152 }
2153 if shouldClientFail {
2154 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2155 }
David Benjamin025b3d32014-07-01 19:53:04 -04002156
David Benjamin9deb1172016-07-13 17:13:49 -04002157 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2158 resumeSession := ver.version < VersionTLS13
2159
David Benjamin6fd297b2014-08-11 18:43:38 -04002160 testCases = append(testCases, testCase{
2161 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002162 protocol: protocol,
2163
2164 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002165 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002166 MinVersion: ver.version,
2167 MaxVersion: ver.version,
2168 CipherSuites: []uint16{suite.id},
2169 Certificates: []Certificate{cert},
2170 PreSharedKey: []byte(psk),
2171 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002172 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002173 EnableAllCiphers: shouldServerFail,
2174 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002175 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002176 },
2177 certFile: certFile,
2178 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002179 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002180 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002181 shouldFail: shouldServerFail,
2182 expectedError: expectedServerError,
2183 })
2184
2185 testCases = append(testCases, testCase{
2186 testType: clientTest,
2187 protocol: protocol,
2188 name: prefix + ver.name + "-" + suite.name + "-client",
2189 config: Config{
2190 MinVersion: ver.version,
2191 MaxVersion: ver.version,
2192 CipherSuites: []uint16{suite.id},
2193 Certificates: []Certificate{cert},
2194 PreSharedKey: []byte(psk),
2195 PreSharedKeyIdentity: pskIdentity,
2196 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002197 EnableAllCiphers: shouldClientFail,
2198 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002199 },
2200 },
2201 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002202 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002203 shouldFail: shouldClientFail,
2204 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002205 })
David Benjamin2c99d282015-09-01 10:23:00 -04002206
Nick Harper1fd39d82016-06-14 18:14:35 -07002207 if !shouldClientFail {
2208 // Ensure the maximum record size is accepted.
2209 testCases = append(testCases, testCase{
2210 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2211 config: Config{
2212 MinVersion: ver.version,
2213 MaxVersion: ver.version,
2214 CipherSuites: []uint16{suite.id},
2215 Certificates: []Certificate{cert},
2216 PreSharedKey: []byte(psk),
2217 PreSharedKeyIdentity: pskIdentity,
2218 },
2219 flags: flags,
2220 messageLen: maxPlaintext,
2221 })
2222 }
2223 }
David Benjamin2c99d282015-09-01 10:23:00 -04002224 }
Adam Langley95c29f32014-06-20 12:00:00 -07002225 }
Adam Langleya7997f12015-05-14 17:38:50 -07002226
2227 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002228 name: "NoSharedCipher",
2229 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002230 MaxVersion: VersionTLS12,
2231 CipherSuites: []uint16{},
2232 },
2233 shouldFail: true,
2234 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2235 })
2236
2237 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002238 name: "NoSharedCipher-TLS13",
2239 config: Config{
2240 MaxVersion: VersionTLS13,
2241 CipherSuites: []uint16{},
2242 },
2243 shouldFail: true,
2244 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2245 })
2246
2247 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002248 name: "UnsupportedCipherSuite",
2249 config: Config{
2250 MaxVersion: VersionTLS12,
2251 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2252 Bugs: ProtocolBugs{
2253 IgnorePeerCipherPreferences: true,
2254 },
2255 },
2256 flags: []string{"-cipher", "DEFAULT:!RC4"},
2257 shouldFail: true,
2258 expectedError: ":WRONG_CIPHER_RETURNED:",
2259 })
2260
2261 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002262 name: "ServerHelloBogusCipher",
2263 config: Config{
2264 MaxVersion: VersionTLS12,
2265 Bugs: ProtocolBugs{
2266 SendCipherSuite: bogusCipher,
2267 },
2268 },
2269 shouldFail: true,
2270 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2271 })
2272 testCases = append(testCases, testCase{
2273 name: "ServerHelloBogusCipher-TLS13",
2274 config: Config{
2275 MaxVersion: VersionTLS13,
2276 Bugs: ProtocolBugs{
2277 SendCipherSuite: bogusCipher,
2278 },
2279 },
2280 shouldFail: true,
2281 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2282 })
2283
2284 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002285 name: "WeakDH",
2286 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002287 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002288 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2289 Bugs: ProtocolBugs{
2290 // This is a 1023-bit prime number, generated
2291 // with:
2292 // openssl gendh 1023 | openssl asn1parse -i
2293 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2294 },
2295 },
2296 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002297 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002298 })
Adam Langleycef75832015-09-03 14:51:12 -07002299
David Benjamincd24a392015-11-11 13:23:05 -08002300 testCases = append(testCases, testCase{
2301 name: "SillyDH",
2302 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002303 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002304 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2305 Bugs: ProtocolBugs{
2306 // This is a 4097-bit prime number, generated
2307 // with:
2308 // openssl gendh 4097 | openssl asn1parse -i
2309 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2310 },
2311 },
2312 shouldFail: true,
2313 expectedError: ":DH_P_TOO_LONG:",
2314 })
2315
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002316 // This test ensures that Diffie-Hellman public values are padded with
2317 // zeros so that they're the same length as the prime. This is to avoid
2318 // hitting a bug in yaSSL.
2319 testCases = append(testCases, testCase{
2320 testType: serverTest,
2321 name: "DHPublicValuePadded",
2322 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002323 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002324 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2325 Bugs: ProtocolBugs{
2326 RequireDHPublicValueLen: (1025 + 7) / 8,
2327 },
2328 },
2329 flags: []string{"-use-sparse-dh-prime"},
2330 })
David Benjamincd24a392015-11-11 13:23:05 -08002331
David Benjamin241ae832016-01-15 03:04:54 -05002332 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002333 testCases = append(testCases, testCase{
2334 testType: serverTest,
2335 name: "UnknownCipher",
2336 config: Config{
2337 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2338 },
2339 })
2340
Adam Langleycef75832015-09-03 14:51:12 -07002341 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2342 // 1.1 specific cipher suite settings. A server is setup with the given
2343 // cipher lists and then a connection is made for each member of
2344 // expectations. The cipher suite that the server selects must match
2345 // the specified one.
2346 var versionSpecificCiphersTest = []struct {
2347 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2348 // expectations is a map from TLS version to cipher suite id.
2349 expectations map[uint16]uint16
2350 }{
2351 {
2352 // Test that the null case (where no version-specific ciphers are set)
2353 // works as expected.
2354 "RC4-SHA:AES128-SHA", // default ciphers
2355 "", // no ciphers specifically for TLS ≥ 1.0
2356 "", // no ciphers specifically for TLS ≥ 1.1
2357 map[uint16]uint16{
2358 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2359 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2360 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2361 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2362 },
2363 },
2364 {
2365 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2366 // cipher.
2367 "RC4-SHA:AES128-SHA", // default
2368 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2369 "", // no ciphers specifically for TLS ≥ 1.1
2370 map[uint16]uint16{
2371 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2372 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2373 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2374 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2375 },
2376 },
2377 {
2378 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2379 // cipher.
2380 "RC4-SHA:AES128-SHA", // default
2381 "", // no ciphers specifically for TLS ≥ 1.0
2382 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2383 map[uint16]uint16{
2384 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2385 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2386 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2387 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2388 },
2389 },
2390 {
2391 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2392 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2393 "RC4-SHA:AES128-SHA", // default
2394 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2395 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2396 map[uint16]uint16{
2397 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2398 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2399 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2400 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2401 },
2402 },
2403 }
2404
2405 for i, test := range versionSpecificCiphersTest {
2406 for version, expectedCipherSuite := range test.expectations {
2407 flags := []string{"-cipher", test.ciphersDefault}
2408 if len(test.ciphersTLS10) > 0 {
2409 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2410 }
2411 if len(test.ciphersTLS11) > 0 {
2412 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2413 }
2414
2415 testCases = append(testCases, testCase{
2416 testType: serverTest,
2417 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2418 config: Config{
2419 MaxVersion: version,
2420 MinVersion: version,
2421 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2422 },
2423 flags: flags,
2424 expectedCipher: expectedCipherSuite,
2425 })
2426 }
2427 }
Adam Langley95c29f32014-06-20 12:00:00 -07002428}
2429
2430func addBadECDSASignatureTests() {
2431 for badR := BadValue(1); badR < NumBadValues; badR++ {
2432 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002433 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002434 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2435 config: Config{
2436 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002437 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002438 Bugs: ProtocolBugs{
2439 BadECDSAR: badR,
2440 BadECDSAS: badS,
2441 },
2442 },
2443 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002444 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002445 })
2446 }
2447 }
2448}
2449
Adam Langley80842bd2014-06-20 12:00:00 -07002450func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002451 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002452 name: "MaxCBCPadding",
2453 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002454 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002455 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2456 Bugs: ProtocolBugs{
2457 MaxPadding: true,
2458 },
2459 },
2460 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2461 })
David Benjamin025b3d32014-07-01 19:53:04 -04002462 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002463 name: "BadCBCPadding",
2464 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002465 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002466 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2467 Bugs: ProtocolBugs{
2468 PaddingFirstByteBad: true,
2469 },
2470 },
2471 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002472 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002473 })
2474 // OpenSSL previously had an issue where the first byte of padding in
2475 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002476 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002477 name: "BadCBCPadding255",
2478 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002479 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002480 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2481 Bugs: ProtocolBugs{
2482 MaxPadding: true,
2483 PaddingFirstByteBadIf255: true,
2484 },
2485 },
2486 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2487 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002488 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002489 })
2490}
2491
Kenny Root7fdeaf12014-08-05 15:23:37 -07002492func addCBCSplittingTests() {
2493 testCases = append(testCases, testCase{
2494 name: "CBCRecordSplitting",
2495 config: Config{
2496 MaxVersion: VersionTLS10,
2497 MinVersion: VersionTLS10,
2498 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2499 },
David Benjaminac8302a2015-09-01 17:18:15 -04002500 messageLen: -1, // read until EOF
2501 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002502 flags: []string{
2503 "-async",
2504 "-write-different-record-sizes",
2505 "-cbc-record-splitting",
2506 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002507 })
2508 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002509 name: "CBCRecordSplittingPartialWrite",
2510 config: Config{
2511 MaxVersion: VersionTLS10,
2512 MinVersion: VersionTLS10,
2513 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2514 },
2515 messageLen: -1, // read until EOF
2516 flags: []string{
2517 "-async",
2518 "-write-different-record-sizes",
2519 "-cbc-record-splitting",
2520 "-partial-write",
2521 },
2522 })
2523}
2524
David Benjamin636293b2014-07-08 17:59:18 -04002525func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002526 // Add a dummy cert pool to stress certificate authority parsing.
2527 // TODO(davidben): Add tests that those values parse out correctly.
2528 certPool := x509.NewCertPool()
2529 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2530 if err != nil {
2531 panic(err)
2532 }
2533 certPool.AddCert(cert)
2534
David Benjamin636293b2014-07-08 17:59:18 -04002535 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002536 testCases = append(testCases, testCase{
2537 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002538 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002539 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002540 MinVersion: ver.version,
2541 MaxVersion: ver.version,
2542 ClientAuth: RequireAnyClientCert,
2543 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002544 },
2545 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002546 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2547 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002548 },
2549 })
2550 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002551 testType: serverTest,
2552 name: ver.name + "-Server-ClientAuth-RSA",
2553 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002554 MinVersion: ver.version,
2555 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002556 Certificates: []Certificate{rsaCertificate},
2557 },
2558 flags: []string{"-require-any-client-certificate"},
2559 })
David Benjamine098ec22014-08-27 23:13:20 -04002560 if ver.version != VersionSSL30 {
2561 testCases = append(testCases, testCase{
2562 testType: serverTest,
2563 name: ver.name + "-Server-ClientAuth-ECDSA",
2564 config: Config{
2565 MinVersion: ver.version,
2566 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002567 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002568 },
2569 flags: []string{"-require-any-client-certificate"},
2570 })
2571 testCases = append(testCases, testCase{
2572 testType: clientTest,
2573 name: ver.name + "-Client-ClientAuth-ECDSA",
2574 config: Config{
2575 MinVersion: ver.version,
2576 MaxVersion: ver.version,
2577 ClientAuth: RequireAnyClientCert,
2578 ClientCAs: certPool,
2579 },
2580 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002581 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2582 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002583 },
2584 })
2585 }
David Benjamin636293b2014-07-08 17:59:18 -04002586 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002587
2588 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002589 name: "NoClientCertificate",
2590 config: Config{
2591 MaxVersion: VersionTLS12,
2592 ClientAuth: RequireAnyClientCert,
2593 },
2594 shouldFail: true,
2595 expectedLocalError: "client didn't provide a certificate",
2596 })
2597
2598 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002599 name: "NoClientCertificate-TLS13",
2600 config: Config{
2601 MaxVersion: VersionTLS13,
2602 ClientAuth: RequireAnyClientCert,
2603 },
2604 shouldFail: true,
2605 expectedLocalError: "client didn't provide a certificate",
2606 })
2607
2608 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002609 testType: serverTest,
2610 name: "RequireAnyClientCertificate",
2611 config: Config{
2612 MaxVersion: VersionTLS12,
2613 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002614 flags: []string{"-require-any-client-certificate"},
2615 shouldFail: true,
2616 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2617 })
2618
2619 testCases = append(testCases, testCase{
2620 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002621 name: "RequireAnyClientCertificate-TLS13",
2622 config: Config{
2623 MaxVersion: VersionTLS13,
2624 },
2625 flags: []string{"-require-any-client-certificate"},
2626 shouldFail: true,
2627 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2628 })
2629
2630 testCases = append(testCases, testCase{
2631 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002632 name: "RequireAnyClientCertificate-SSL3",
2633 config: Config{
2634 MaxVersion: VersionSSL30,
2635 },
2636 flags: []string{"-require-any-client-certificate"},
2637 shouldFail: true,
2638 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2639 })
2640
2641 testCases = append(testCases, testCase{
2642 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002643 name: "SkipClientCertificate",
2644 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002645 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002646 Bugs: ProtocolBugs{
2647 SkipClientCertificate: true,
2648 },
2649 },
2650 // Setting SSL_VERIFY_PEER allows anonymous clients.
2651 flags: []string{"-verify-peer"},
2652 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002653 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002654 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002655
Steven Valdez143e8b32016-07-11 13:19:03 -04002656 testCases = append(testCases, testCase{
2657 testType: serverTest,
2658 name: "SkipClientCertificate-TLS13",
2659 config: Config{
2660 MaxVersion: VersionTLS13,
2661 Bugs: ProtocolBugs{
2662 SkipClientCertificate: true,
2663 },
2664 },
2665 // Setting SSL_VERIFY_PEER allows anonymous clients.
2666 flags: []string{"-verify-peer"},
2667 shouldFail: true,
2668 expectedError: ":UNEXPECTED_MESSAGE:",
2669 })
2670
David Benjaminc032dfa2016-05-12 14:54:57 -04002671 // Client auth is only legal in certificate-based ciphers.
2672 testCases = append(testCases, testCase{
2673 testType: clientTest,
2674 name: "ClientAuth-PSK",
2675 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002676 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002677 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2678 PreSharedKey: []byte("secret"),
2679 ClientAuth: RequireAnyClientCert,
2680 },
2681 flags: []string{
2682 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2683 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2684 "-psk", "secret",
2685 },
2686 shouldFail: true,
2687 expectedError: ":UNEXPECTED_MESSAGE:",
2688 })
2689 testCases = append(testCases, testCase{
2690 testType: clientTest,
2691 name: "ClientAuth-ECDHE_PSK",
2692 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002693 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002694 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2695 PreSharedKey: []byte("secret"),
2696 ClientAuth: RequireAnyClientCert,
2697 },
2698 flags: []string{
2699 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2700 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2701 "-psk", "secret",
2702 },
2703 shouldFail: true,
2704 expectedError: ":UNEXPECTED_MESSAGE:",
2705 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002706
2707 // Regression test for a bug where the client CA list, if explicitly
2708 // set to NULL, was mis-encoded.
2709 testCases = append(testCases, testCase{
2710 testType: serverTest,
2711 name: "Null-Client-CA-List",
2712 config: Config{
2713 MaxVersion: VersionTLS12,
2714 Certificates: []Certificate{rsaCertificate},
2715 },
2716 flags: []string{
2717 "-require-any-client-certificate",
2718 "-use-null-client-ca-list",
2719 },
2720 })
David Benjamin636293b2014-07-08 17:59:18 -04002721}
2722
Adam Langley75712922014-10-10 16:23:43 -07002723func addExtendedMasterSecretTests() {
2724 const expectEMSFlag = "-expect-extended-master-secret"
2725
2726 for _, with := range []bool{false, true} {
2727 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002728 if with {
2729 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002730 }
2731
2732 for _, isClient := range []bool{false, true} {
2733 suffix := "-Server"
2734 testType := serverTest
2735 if isClient {
2736 suffix = "-Client"
2737 testType = clientTest
2738 }
2739
2740 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002741 // In TLS 1.3, the extension is irrelevant and
2742 // always reports as enabled.
2743 var flags []string
2744 if with || ver.version >= VersionTLS13 {
2745 flags = []string{expectEMSFlag}
2746 }
2747
Adam Langley75712922014-10-10 16:23:43 -07002748 test := testCase{
2749 testType: testType,
2750 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2751 config: Config{
2752 MinVersion: ver.version,
2753 MaxVersion: ver.version,
2754 Bugs: ProtocolBugs{
2755 NoExtendedMasterSecret: !with,
2756 RequireExtendedMasterSecret: with,
2757 },
2758 },
David Benjamin48cae082014-10-27 01:06:24 -04002759 flags: flags,
2760 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002761 }
2762 if test.shouldFail {
2763 test.expectedLocalError = "extended master secret required but not supported by peer"
2764 }
2765 testCases = append(testCases, test)
2766 }
2767 }
2768 }
2769
Adam Langleyba5934b2015-06-02 10:50:35 -07002770 for _, isClient := range []bool{false, true} {
2771 for _, supportedInFirstConnection := range []bool{false, true} {
2772 for _, supportedInResumeConnection := range []bool{false, true} {
2773 boolToWord := func(b bool) string {
2774 if b {
2775 return "Yes"
2776 }
2777 return "No"
2778 }
2779 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2780 if isClient {
2781 suffix += "Client"
2782 } else {
2783 suffix += "Server"
2784 }
2785
2786 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002787 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002788 Bugs: ProtocolBugs{
2789 RequireExtendedMasterSecret: true,
2790 },
2791 }
2792
2793 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002794 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002795 Bugs: ProtocolBugs{
2796 NoExtendedMasterSecret: true,
2797 },
2798 }
2799
2800 test := testCase{
2801 name: "ExtendedMasterSecret-" + suffix,
2802 resumeSession: true,
2803 }
2804
2805 if !isClient {
2806 test.testType = serverTest
2807 }
2808
2809 if supportedInFirstConnection {
2810 test.config = supportedConfig
2811 } else {
2812 test.config = noSupportConfig
2813 }
2814
2815 if supportedInResumeConnection {
2816 test.resumeConfig = &supportedConfig
2817 } else {
2818 test.resumeConfig = &noSupportConfig
2819 }
2820
2821 switch suffix {
2822 case "YesToYes-Client", "YesToYes-Server":
2823 // When a session is resumed, it should
2824 // still be aware that its master
2825 // secret was generated via EMS and
2826 // thus it's safe to use tls-unique.
2827 test.flags = []string{expectEMSFlag}
2828 case "NoToYes-Server":
2829 // If an original connection did not
2830 // contain EMS, but a resumption
2831 // handshake does, then a server should
2832 // not resume the session.
2833 test.expectResumeRejected = true
2834 case "YesToNo-Server":
2835 // Resuming an EMS session without the
2836 // EMS extension should cause the
2837 // server to abort the connection.
2838 test.shouldFail = true
2839 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2840 case "NoToYes-Client":
2841 // A client should abort a connection
2842 // where the server resumed a non-EMS
2843 // session but echoed the EMS
2844 // extension.
2845 test.shouldFail = true
2846 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2847 case "YesToNo-Client":
2848 // A client should abort a connection
2849 // where the server didn't echo EMS
2850 // when the session used it.
2851 test.shouldFail = true
2852 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2853 }
2854
2855 testCases = append(testCases, test)
2856 }
2857 }
2858 }
Adam Langley75712922014-10-10 16:23:43 -07002859}
2860
David Benjamin582ba042016-07-07 12:33:25 -07002861type stateMachineTestConfig struct {
2862 protocol protocol
2863 async bool
2864 splitHandshake, packHandshakeFlight bool
2865}
2866
David Benjamin43ec06f2014-08-05 02:28:57 -04002867// Adds tests that try to cover the range of the handshake state machine, under
2868// various conditions. Some of these are redundant with other tests, but they
2869// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002870func addAllStateMachineCoverageTests() {
2871 for _, async := range []bool{false, true} {
2872 for _, protocol := range []protocol{tls, dtls} {
2873 addStateMachineCoverageTests(stateMachineTestConfig{
2874 protocol: protocol,
2875 async: async,
2876 })
2877 addStateMachineCoverageTests(stateMachineTestConfig{
2878 protocol: protocol,
2879 async: async,
2880 splitHandshake: true,
2881 })
2882 if protocol == tls {
2883 addStateMachineCoverageTests(stateMachineTestConfig{
2884 protocol: protocol,
2885 async: async,
2886 packHandshakeFlight: true,
2887 })
2888 }
2889 }
2890 }
2891}
2892
2893func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002894 var tests []testCase
2895
2896 // Basic handshake, with resumption. Client and server,
2897 // session ID and session ticket.
2898 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002899 name: "Basic-Client",
2900 config: Config{
2901 MaxVersion: VersionTLS12,
2902 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002903 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002904 // Ensure session tickets are used, not session IDs.
2905 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002906 })
2907 tests = append(tests, testCase{
2908 name: "Basic-Client-RenewTicket",
2909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002910 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002911 Bugs: ProtocolBugs{
2912 RenewTicketOnResume: true,
2913 },
2914 },
David Benjaminba4594a2015-06-18 18:36:15 -04002915 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002916 resumeSession: true,
2917 })
2918 tests = append(tests, testCase{
2919 name: "Basic-Client-NoTicket",
2920 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002921 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002922 SessionTicketsDisabled: true,
2923 },
2924 resumeSession: true,
2925 })
2926 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002927 name: "Basic-Client-Implicit",
2928 config: Config{
2929 MaxVersion: VersionTLS12,
2930 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002931 flags: []string{"-implicit-handshake"},
2932 resumeSession: true,
2933 })
2934 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002935 testType: serverTest,
2936 name: "Basic-Server",
2937 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002938 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002939 Bugs: ProtocolBugs{
2940 RequireSessionTickets: true,
2941 },
2942 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002943 resumeSession: true,
2944 })
2945 tests = append(tests, testCase{
2946 testType: serverTest,
2947 name: "Basic-Server-NoTickets",
2948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002949 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002950 SessionTicketsDisabled: true,
2951 },
2952 resumeSession: true,
2953 })
2954 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002955 testType: serverTest,
2956 name: "Basic-Server-Implicit",
2957 config: Config{
2958 MaxVersion: VersionTLS12,
2959 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002960 flags: []string{"-implicit-handshake"},
2961 resumeSession: true,
2962 })
2963 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002964 testType: serverTest,
2965 name: "Basic-Server-EarlyCallback",
2966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002969 flags: []string{"-use-early-callback"},
2970 resumeSession: true,
2971 })
2972
Steven Valdez143e8b32016-07-11 13:19:03 -04002973 // TLS 1.3 basic handshake shapes.
2974 tests = append(tests, testCase{
2975 name: "TLS13-1RTT-Client",
2976 config: Config{
2977 MaxVersion: VersionTLS13,
2978 },
2979 })
2980 tests = append(tests, testCase{
2981 testType: serverTest,
2982 name: "TLS13-1RTT-Server",
2983 config: Config{
2984 MaxVersion: VersionTLS13,
2985 },
2986 })
2987
David Benjamin760b1dd2015-05-15 23:33:48 -04002988 // TLS client auth.
2989 tests = append(tests, testCase{
2990 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002991 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002992 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002993 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002994 ClientAuth: RequestClientCert,
2995 },
2996 })
2997 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002998 testType: serverTest,
2999 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003000 config: Config{
3001 MaxVersion: VersionTLS12,
3002 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003003 // Setting SSL_VERIFY_PEER allows anonymous clients.
3004 flags: []string{"-verify-peer"},
3005 })
David Benjamin582ba042016-07-07 12:33:25 -07003006 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003007 tests = append(tests, testCase{
3008 testType: clientTest,
3009 name: "ClientAuth-NoCertificate-Client-SSL3",
3010 config: Config{
3011 MaxVersion: VersionSSL30,
3012 ClientAuth: RequestClientCert,
3013 },
3014 })
3015 tests = append(tests, testCase{
3016 testType: serverTest,
3017 name: "ClientAuth-NoCertificate-Server-SSL3",
3018 config: Config{
3019 MaxVersion: VersionSSL30,
3020 },
3021 // Setting SSL_VERIFY_PEER allows anonymous clients.
3022 flags: []string{"-verify-peer"},
3023 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003024 tests = append(tests, testCase{
3025 testType: clientTest,
3026 name: "ClientAuth-NoCertificate-Client-TLS13",
3027 config: Config{
3028 MaxVersion: VersionTLS13,
3029 ClientAuth: RequestClientCert,
3030 },
3031 })
3032 tests = append(tests, testCase{
3033 testType: serverTest,
3034 name: "ClientAuth-NoCertificate-Server-TLS13",
3035 config: Config{
3036 MaxVersion: VersionTLS13,
3037 },
3038 // Setting SSL_VERIFY_PEER allows anonymous clients.
3039 flags: []string{"-verify-peer"},
3040 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003041 }
3042 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003043 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003044 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003046 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003047 ClientAuth: RequireAnyClientCert,
3048 },
3049 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003050 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3051 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003052 },
3053 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003054 tests = append(tests, testCase{
3055 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003056 name: "ClientAuth-RSA-Client-TLS13",
3057 config: Config{
3058 MaxVersion: VersionTLS13,
3059 ClientAuth: RequireAnyClientCert,
3060 },
3061 flags: []string{
3062 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3063 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3064 },
3065 })
3066 tests = append(tests, testCase{
3067 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003068 name: "ClientAuth-ECDSA-Client",
3069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003070 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003071 ClientAuth: RequireAnyClientCert,
3072 },
3073 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003074 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3075 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003076 },
3077 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003078 tests = append(tests, testCase{
3079 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003080 name: "ClientAuth-ECDSA-Client-TLS13",
3081 config: Config{
3082 MaxVersion: VersionTLS13,
3083 ClientAuth: RequireAnyClientCert,
3084 },
3085 flags: []string{
3086 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3087 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3088 },
3089 })
3090 tests = append(tests, testCase{
3091 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003092 name: "ClientAuth-NoCertificate-OldCallback",
3093 config: Config{
3094 MaxVersion: VersionTLS12,
3095 ClientAuth: RequestClientCert,
3096 },
3097 flags: []string{"-use-old-client-cert-callback"},
3098 })
3099 tests = append(tests, testCase{
3100 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003101 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3102 config: Config{
3103 MaxVersion: VersionTLS13,
3104 ClientAuth: RequestClientCert,
3105 },
3106 flags: []string{"-use-old-client-cert-callback"},
3107 })
3108 tests = append(tests, testCase{
3109 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003110 name: "ClientAuth-OldCallback",
3111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003112 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003113 ClientAuth: RequireAnyClientCert,
3114 },
3115 flags: []string{
3116 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3117 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3118 "-use-old-client-cert-callback",
3119 },
3120 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003121 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003122 testType: clientTest,
3123 name: "ClientAuth-OldCallback-TLS13",
3124 config: Config{
3125 MaxVersion: VersionTLS13,
3126 ClientAuth: RequireAnyClientCert,
3127 },
3128 flags: []string{
3129 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3130 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3131 "-use-old-client-cert-callback",
3132 },
3133 })
3134 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003135 testType: serverTest,
3136 name: "ClientAuth-Server",
3137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003138 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003139 Certificates: []Certificate{rsaCertificate},
3140 },
3141 flags: []string{"-require-any-client-certificate"},
3142 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003143 tests = append(tests, testCase{
3144 testType: serverTest,
3145 name: "ClientAuth-Server-TLS13",
3146 config: Config{
3147 MaxVersion: VersionTLS13,
3148 Certificates: []Certificate{rsaCertificate},
3149 },
3150 flags: []string{"-require-any-client-certificate"},
3151 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003152
David Benjamin4c3ddf72016-06-29 18:13:53 -04003153 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003154 tests = append(tests, testCase{
3155 testType: serverTest,
3156 name: "Basic-Server-RSA",
3157 config: Config{
3158 MaxVersion: VersionTLS12,
3159 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3160 },
3161 flags: []string{
3162 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3163 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3164 },
3165 })
3166 tests = append(tests, testCase{
3167 testType: serverTest,
3168 name: "Basic-Server-ECDHE-RSA",
3169 config: Config{
3170 MaxVersion: VersionTLS12,
3171 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3172 },
3173 flags: []string{
3174 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3175 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3176 },
3177 })
3178 tests = append(tests, testCase{
3179 testType: serverTest,
3180 name: "Basic-Server-ECDHE-ECDSA",
3181 config: Config{
3182 MaxVersion: VersionTLS12,
3183 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3184 },
3185 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003186 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3187 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003188 },
3189 })
3190
David Benjamin760b1dd2015-05-15 23:33:48 -04003191 // No session ticket support; server doesn't send NewSessionTicket.
3192 tests = append(tests, testCase{
3193 name: "SessionTicketsDisabled-Client",
3194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003195 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003196 SessionTicketsDisabled: true,
3197 },
3198 })
3199 tests = append(tests, testCase{
3200 testType: serverTest,
3201 name: "SessionTicketsDisabled-Server",
3202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003203 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003204 SessionTicketsDisabled: true,
3205 },
3206 })
3207
3208 // Skip ServerKeyExchange in PSK key exchange if there's no
3209 // identity hint.
3210 tests = append(tests, testCase{
3211 name: "EmptyPSKHint-Client",
3212 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003213 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003214 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3215 PreSharedKey: []byte("secret"),
3216 },
3217 flags: []string{"-psk", "secret"},
3218 })
3219 tests = append(tests, testCase{
3220 testType: serverTest,
3221 name: "EmptyPSKHint-Server",
3222 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003223 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003224 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3225 PreSharedKey: []byte("secret"),
3226 },
3227 flags: []string{"-psk", "secret"},
3228 })
3229
David Benjamin4c3ddf72016-06-29 18:13:53 -04003230 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003231 tests = append(tests, testCase{
3232 testType: clientTest,
3233 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003234 config: Config{
3235 MaxVersion: VersionTLS12,
3236 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003237 flags: []string{
3238 "-enable-ocsp-stapling",
3239 "-expect-ocsp-response",
3240 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003241 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003242 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003243 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003244 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003245 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 testType: serverTest,
3247 name: "OCSPStapling-Server",
3248 config: Config{
3249 MaxVersion: VersionTLS12,
3250 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003251 expectedOCSPResponse: testOCSPResponse,
3252 flags: []string{
3253 "-ocsp-response",
3254 base64.StdEncoding.EncodeToString(testOCSPResponse),
3255 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003256 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003257 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003258 tests = append(tests, testCase{
3259 testType: clientTest,
3260 name: "OCSPStapling-Client-TLS13",
3261 config: Config{
3262 MaxVersion: VersionTLS13,
3263 },
3264 flags: []string{
3265 "-enable-ocsp-stapling",
3266 "-expect-ocsp-response",
3267 base64.StdEncoding.EncodeToString(testOCSPResponse),
3268 "-verify-peer",
3269 },
3270 // TODO(davidben): Enable this when resumption is implemented
3271 // in TLS 1.3.
3272 resumeSession: false,
3273 })
3274 tests = append(tests, testCase{
3275 testType: serverTest,
3276 name: "OCSPStapling-Server-TLS13",
3277 config: Config{
3278 MaxVersion: VersionTLS13,
3279 },
3280 expectedOCSPResponse: testOCSPResponse,
3281 flags: []string{
3282 "-ocsp-response",
3283 base64.StdEncoding.EncodeToString(testOCSPResponse),
3284 },
3285 // TODO(davidben): Enable this when resumption is implemented
3286 // in TLS 1.3.
3287 resumeSession: false,
3288 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003289
David Benjamin4c3ddf72016-06-29 18:13:53 -04003290 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003291 for _, vers := range tlsVersions {
3292 if config.protocol == dtls && !vers.hasDTLS {
3293 continue
3294 }
3295 tests = append(tests, testCase{
3296 testType: clientTest,
3297 name: "CertificateVerificationSucceed-" + vers.name,
3298 config: Config{
3299 MaxVersion: vers.version,
3300 },
3301 flags: []string{
3302 "-verify-peer",
3303 },
3304 })
3305 tests = append(tests, testCase{
3306 testType: clientTest,
3307 name: "CertificateVerificationFail-" + vers.name,
3308 config: Config{
3309 MaxVersion: vers.version,
3310 },
3311 flags: []string{
3312 "-verify-fail",
3313 "-verify-peer",
3314 },
3315 shouldFail: true,
3316 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3317 })
3318 tests = append(tests, testCase{
3319 testType: clientTest,
3320 name: "CertificateVerificationSoftFail-" + vers.name,
3321 config: Config{
3322 MaxVersion: vers.version,
3323 },
3324 flags: []string{
3325 "-verify-fail",
3326 "-expect-verify-result",
3327 },
3328 })
3329 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003330
David Benjamin582ba042016-07-07 12:33:25 -07003331 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003332 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003333 name: "Renegotiate-Client",
3334 config: Config{
3335 MaxVersion: VersionTLS12,
3336 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003337 renegotiate: 1,
3338 flags: []string{
3339 "-renegotiate-freely",
3340 "-expect-total-renegotiations", "1",
3341 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003342 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003343
David Benjamin760b1dd2015-05-15 23:33:48 -04003344 // NPN on client and server; results in post-handshake message.
3345 tests = append(tests, testCase{
3346 name: "NPN-Client",
3347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003349 NextProtos: []string{"foo"},
3350 },
3351 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003352 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003353 expectedNextProto: "foo",
3354 expectedNextProtoType: npn,
3355 })
3356 tests = append(tests, testCase{
3357 testType: serverTest,
3358 name: "NPN-Server",
3359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003360 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003361 NextProtos: []string{"bar"},
3362 },
3363 flags: []string{
3364 "-advertise-npn", "\x03foo\x03bar\x03baz",
3365 "-expect-next-proto", "bar",
3366 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003367 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003368 expectedNextProto: "bar",
3369 expectedNextProtoType: npn,
3370 })
3371
3372 // TODO(davidben): Add tests for when False Start doesn't trigger.
3373
3374 // Client does False Start and negotiates NPN.
3375 tests = append(tests, testCase{
3376 name: "FalseStart",
3377 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003378 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003379 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3380 NextProtos: []string{"foo"},
3381 Bugs: ProtocolBugs{
3382 ExpectFalseStart: true,
3383 },
3384 },
3385 flags: []string{
3386 "-false-start",
3387 "-select-next-proto", "foo",
3388 },
3389 shimWritesFirst: true,
3390 resumeSession: true,
3391 })
3392
3393 // Client does False Start and negotiates ALPN.
3394 tests = append(tests, testCase{
3395 name: "FalseStart-ALPN",
3396 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003397 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003398 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3399 NextProtos: []string{"foo"},
3400 Bugs: ProtocolBugs{
3401 ExpectFalseStart: true,
3402 },
3403 },
3404 flags: []string{
3405 "-false-start",
3406 "-advertise-alpn", "\x03foo",
3407 },
3408 shimWritesFirst: true,
3409 resumeSession: true,
3410 })
3411
3412 // Client does False Start but doesn't explicitly call
3413 // SSL_connect.
3414 tests = append(tests, testCase{
3415 name: "FalseStart-Implicit",
3416 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003417 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003418 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3419 NextProtos: []string{"foo"},
3420 },
3421 flags: []string{
3422 "-implicit-handshake",
3423 "-false-start",
3424 "-advertise-alpn", "\x03foo",
3425 },
3426 })
3427
3428 // False Start without session tickets.
3429 tests = append(tests, testCase{
3430 name: "FalseStart-SessionTicketsDisabled",
3431 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003432 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003433 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3434 NextProtos: []string{"foo"},
3435 SessionTicketsDisabled: true,
3436 Bugs: ProtocolBugs{
3437 ExpectFalseStart: true,
3438 },
3439 },
3440 flags: []string{
3441 "-false-start",
3442 "-select-next-proto", "foo",
3443 },
3444 shimWritesFirst: true,
3445 })
3446
Adam Langleydf759b52016-07-11 15:24:37 -07003447 tests = append(tests, testCase{
3448 name: "FalseStart-CECPQ1",
3449 config: Config{
3450 MaxVersion: VersionTLS12,
3451 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3452 NextProtos: []string{"foo"},
3453 Bugs: ProtocolBugs{
3454 ExpectFalseStart: true,
3455 },
3456 },
3457 flags: []string{
3458 "-false-start",
3459 "-cipher", "DEFAULT:kCECPQ1",
3460 "-select-next-proto", "foo",
3461 },
3462 shimWritesFirst: true,
3463 resumeSession: true,
3464 })
3465
David Benjamin760b1dd2015-05-15 23:33:48 -04003466 // Server parses a V2ClientHello.
3467 tests = append(tests, testCase{
3468 testType: serverTest,
3469 name: "SendV2ClientHello",
3470 config: Config{
3471 // Choose a cipher suite that does not involve
3472 // elliptic curves, so no extensions are
3473 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003474 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003475 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3476 Bugs: ProtocolBugs{
3477 SendV2ClientHello: true,
3478 },
3479 },
3480 })
3481
3482 // Client sends a Channel ID.
3483 tests = append(tests, testCase{
3484 name: "ChannelID-Client",
3485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003486 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003487 RequestChannelID: true,
3488 },
Adam Langley7c803a62015-06-15 15:35:05 -07003489 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003490 resumeSession: true,
3491 expectChannelID: true,
3492 })
3493
3494 // Server accepts a Channel ID.
3495 tests = append(tests, testCase{
3496 testType: serverTest,
3497 name: "ChannelID-Server",
3498 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003499 MaxVersion: VersionTLS12,
3500 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003501 },
3502 flags: []string{
3503 "-expect-channel-id",
3504 base64.StdEncoding.EncodeToString(channelIDBytes),
3505 },
3506 resumeSession: true,
3507 expectChannelID: true,
3508 })
David Benjamin30789da2015-08-29 22:56:45 -04003509
David Benjaminf8fcdf32016-06-08 15:56:13 -04003510 // Channel ID and NPN at the same time, to ensure their relative
3511 // ordering is correct.
3512 tests = append(tests, testCase{
3513 name: "ChannelID-NPN-Client",
3514 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003515 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003516 RequestChannelID: true,
3517 NextProtos: []string{"foo"},
3518 },
3519 flags: []string{
3520 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3521 "-select-next-proto", "foo",
3522 },
3523 resumeSession: true,
3524 expectChannelID: true,
3525 expectedNextProto: "foo",
3526 expectedNextProtoType: npn,
3527 })
3528 tests = append(tests, testCase{
3529 testType: serverTest,
3530 name: "ChannelID-NPN-Server",
3531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003532 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003533 ChannelID: channelIDKey,
3534 NextProtos: []string{"bar"},
3535 },
3536 flags: []string{
3537 "-expect-channel-id",
3538 base64.StdEncoding.EncodeToString(channelIDBytes),
3539 "-advertise-npn", "\x03foo\x03bar\x03baz",
3540 "-expect-next-proto", "bar",
3541 },
3542 resumeSession: true,
3543 expectChannelID: true,
3544 expectedNextProto: "bar",
3545 expectedNextProtoType: npn,
3546 })
3547
David Benjamin30789da2015-08-29 22:56:45 -04003548 // Bidirectional shutdown with the runner initiating.
3549 tests = append(tests, testCase{
3550 name: "Shutdown-Runner",
3551 config: Config{
3552 Bugs: ProtocolBugs{
3553 ExpectCloseNotify: true,
3554 },
3555 },
3556 flags: []string{"-check-close-notify"},
3557 })
3558
3559 // Bidirectional shutdown with the shim initiating. The runner,
3560 // in the meantime, sends garbage before the close_notify which
3561 // the shim must ignore.
3562 tests = append(tests, testCase{
3563 name: "Shutdown-Shim",
3564 config: Config{
3565 Bugs: ProtocolBugs{
3566 ExpectCloseNotify: true,
3567 },
3568 },
3569 shimShutsDown: true,
3570 sendEmptyRecords: 1,
3571 sendWarningAlerts: 1,
3572 flags: []string{"-check-close-notify"},
3573 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003574 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003575 // TODO(davidben): DTLS 1.3 will want a similar thing for
3576 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003577 tests = append(tests, testCase{
3578 name: "SkipHelloVerifyRequest",
3579 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003580 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003581 Bugs: ProtocolBugs{
3582 SkipHelloVerifyRequest: true,
3583 },
3584 },
3585 })
3586 }
3587
David Benjamin760b1dd2015-05-15 23:33:48 -04003588 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003589 test.protocol = config.protocol
3590 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003591 test.name += "-DTLS"
3592 }
David Benjamin582ba042016-07-07 12:33:25 -07003593 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003594 test.name += "-Async"
3595 test.flags = append(test.flags, "-async")
3596 } else {
3597 test.name += "-Sync"
3598 }
David Benjamin582ba042016-07-07 12:33:25 -07003599 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003600 test.name += "-SplitHandshakeRecords"
3601 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003602 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003603 test.config.Bugs.MaxPacketLength = 256
3604 test.flags = append(test.flags, "-mtu", "256")
3605 }
3606 }
David Benjamin582ba042016-07-07 12:33:25 -07003607 if config.packHandshakeFlight {
3608 test.name += "-PackHandshakeFlight"
3609 test.config.Bugs.PackHandshakeFlight = true
3610 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003611 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003612 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003613}
3614
Adam Langley524e7172015-02-20 16:04:00 -08003615func addDDoSCallbackTests() {
3616 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003617 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003618 for _, resume := range []bool{false, true} {
3619 suffix := "Resume"
3620 if resume {
3621 suffix = "No" + suffix
3622 }
3623
3624 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003625 testType: serverTest,
3626 name: "Server-DDoS-OK-" + suffix,
3627 config: Config{
3628 MaxVersion: VersionTLS12,
3629 },
Adam Langley524e7172015-02-20 16:04:00 -08003630 flags: []string{"-install-ddos-callback"},
3631 resumeSession: resume,
3632 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003633 if !resume {
3634 testCases = append(testCases, testCase{
3635 testType: serverTest,
3636 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3637 config: Config{
3638 MaxVersion: VersionTLS13,
3639 },
3640 flags: []string{"-install-ddos-callback"},
3641 resumeSession: resume,
3642 })
3643 }
Adam Langley524e7172015-02-20 16:04:00 -08003644
3645 failFlag := "-fail-ddos-callback"
3646 if resume {
3647 failFlag = "-fail-second-ddos-callback"
3648 }
3649 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003650 testType: serverTest,
3651 name: "Server-DDoS-Reject-" + suffix,
3652 config: Config{
3653 MaxVersion: VersionTLS12,
3654 },
Adam Langley524e7172015-02-20 16:04:00 -08003655 flags: []string{"-install-ddos-callback", failFlag},
3656 resumeSession: resume,
3657 shouldFail: true,
3658 expectedError: ":CONNECTION_REJECTED:",
3659 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003660 if !resume {
3661 testCases = append(testCases, testCase{
3662 testType: serverTest,
3663 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3664 config: Config{
3665 MaxVersion: VersionTLS13,
3666 },
3667 flags: []string{"-install-ddos-callback", failFlag},
3668 resumeSession: resume,
3669 shouldFail: true,
3670 expectedError: ":CONNECTION_REJECTED:",
3671 })
3672 }
Adam Langley524e7172015-02-20 16:04:00 -08003673 }
3674}
3675
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003676func addVersionNegotiationTests() {
3677 for i, shimVers := range tlsVersions {
3678 // Assemble flags to disable all newer versions on the shim.
3679 var flags []string
3680 for _, vers := range tlsVersions[i+1:] {
3681 flags = append(flags, vers.flag)
3682 }
3683
3684 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003685 protocols := []protocol{tls}
3686 if runnerVers.hasDTLS && shimVers.hasDTLS {
3687 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003688 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003689 for _, protocol := range protocols {
3690 expectedVersion := shimVers.version
3691 if runnerVers.version < shimVers.version {
3692 expectedVersion = runnerVers.version
3693 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003694
David Benjamin8b8c0062014-11-23 02:47:52 -05003695 suffix := shimVers.name + "-" + runnerVers.name
3696 if protocol == dtls {
3697 suffix += "-DTLS"
3698 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003699
David Benjamin1eb367c2014-12-12 18:17:51 -05003700 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3701
David Benjamin1e29a6b2014-12-10 02:27:24 -05003702 clientVers := shimVers.version
3703 if clientVers > VersionTLS10 {
3704 clientVers = VersionTLS10
3705 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003706 serverVers := expectedVersion
3707 if expectedVersion >= VersionTLS13 {
3708 serverVers = VersionTLS10
3709 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003710 testCases = append(testCases, testCase{
3711 protocol: protocol,
3712 testType: clientTest,
3713 name: "VersionNegotiation-Client-" + suffix,
3714 config: Config{
3715 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003716 Bugs: ProtocolBugs{
3717 ExpectInitialRecordVersion: clientVers,
3718 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003719 },
3720 flags: flags,
3721 expectedVersion: expectedVersion,
3722 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003723 testCases = append(testCases, testCase{
3724 protocol: protocol,
3725 testType: clientTest,
3726 name: "VersionNegotiation-Client2-" + suffix,
3727 config: Config{
3728 MaxVersion: runnerVers.version,
3729 Bugs: ProtocolBugs{
3730 ExpectInitialRecordVersion: clientVers,
3731 },
3732 },
3733 flags: []string{"-max-version", shimVersFlag},
3734 expectedVersion: expectedVersion,
3735 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003736
3737 testCases = append(testCases, testCase{
3738 protocol: protocol,
3739 testType: serverTest,
3740 name: "VersionNegotiation-Server-" + suffix,
3741 config: Config{
3742 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003743 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003744 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003745 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003746 },
3747 flags: flags,
3748 expectedVersion: expectedVersion,
3749 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003750 testCases = append(testCases, testCase{
3751 protocol: protocol,
3752 testType: serverTest,
3753 name: "VersionNegotiation-Server2-" + suffix,
3754 config: Config{
3755 MaxVersion: runnerVers.version,
3756 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003757 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003758 },
3759 },
3760 flags: []string{"-max-version", shimVersFlag},
3761 expectedVersion: expectedVersion,
3762 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003763 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003764 }
3765 }
David Benjamin95c69562016-06-29 18:15:03 -04003766
3767 // Test for version tolerance.
3768 testCases = append(testCases, testCase{
3769 testType: serverTest,
3770 name: "MinorVersionTolerance",
3771 config: Config{
3772 Bugs: ProtocolBugs{
3773 SendClientVersion: 0x03ff,
3774 },
3775 },
3776 expectedVersion: VersionTLS13,
3777 })
3778 testCases = append(testCases, testCase{
3779 testType: serverTest,
3780 name: "MajorVersionTolerance",
3781 config: Config{
3782 Bugs: ProtocolBugs{
3783 SendClientVersion: 0x0400,
3784 },
3785 },
3786 expectedVersion: VersionTLS13,
3787 })
3788 testCases = append(testCases, testCase{
3789 protocol: dtls,
3790 testType: serverTest,
3791 name: "MinorVersionTolerance-DTLS",
3792 config: Config{
3793 Bugs: ProtocolBugs{
3794 SendClientVersion: 0x03ff,
3795 },
3796 },
3797 expectedVersion: VersionTLS12,
3798 })
3799 testCases = append(testCases, testCase{
3800 protocol: dtls,
3801 testType: serverTest,
3802 name: "MajorVersionTolerance-DTLS",
3803 config: Config{
3804 Bugs: ProtocolBugs{
3805 SendClientVersion: 0x0400,
3806 },
3807 },
3808 expectedVersion: VersionTLS12,
3809 })
3810
3811 // Test that versions below 3.0 are rejected.
3812 testCases = append(testCases, testCase{
3813 testType: serverTest,
3814 name: "VersionTooLow",
3815 config: Config{
3816 Bugs: ProtocolBugs{
3817 SendClientVersion: 0x0200,
3818 },
3819 },
3820 shouldFail: true,
3821 expectedError: ":UNSUPPORTED_PROTOCOL:",
3822 })
3823 testCases = append(testCases, testCase{
3824 protocol: dtls,
3825 testType: serverTest,
3826 name: "VersionTooLow-DTLS",
3827 config: Config{
3828 Bugs: ProtocolBugs{
3829 // 0x0201 is the lowest version expressable in
3830 // DTLS.
3831 SendClientVersion: 0x0201,
3832 },
3833 },
3834 shouldFail: true,
3835 expectedError: ":UNSUPPORTED_PROTOCOL:",
3836 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003837
3838 // Test TLS 1.3's downgrade signal.
3839 testCases = append(testCases, testCase{
3840 name: "Downgrade-TLS12-Client",
3841 config: Config{
3842 Bugs: ProtocolBugs{
3843 NegotiateVersion: VersionTLS12,
3844 },
3845 },
3846 shouldFail: true,
3847 expectedError: ":DOWNGRADE_DETECTED:",
3848 })
3849 testCases = append(testCases, testCase{
3850 testType: serverTest,
3851 name: "Downgrade-TLS12-Server",
3852 config: Config{
3853 Bugs: ProtocolBugs{
3854 SendClientVersion: VersionTLS12,
3855 },
3856 },
3857 shouldFail: true,
3858 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3859 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003860}
3861
David Benjaminaccb4542014-12-12 23:44:33 -05003862func addMinimumVersionTests() {
3863 for i, shimVers := range tlsVersions {
3864 // Assemble flags to disable all older versions on the shim.
3865 var flags []string
3866 for _, vers := range tlsVersions[:i] {
3867 flags = append(flags, vers.flag)
3868 }
3869
3870 for _, runnerVers := range tlsVersions {
3871 protocols := []protocol{tls}
3872 if runnerVers.hasDTLS && shimVers.hasDTLS {
3873 protocols = append(protocols, dtls)
3874 }
3875 for _, protocol := range protocols {
3876 suffix := shimVers.name + "-" + runnerVers.name
3877 if protocol == dtls {
3878 suffix += "-DTLS"
3879 }
3880 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3881
David Benjaminaccb4542014-12-12 23:44:33 -05003882 var expectedVersion uint16
3883 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003884 var expectedClientError, expectedServerError string
3885 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003886 if runnerVers.version >= shimVers.version {
3887 expectedVersion = runnerVers.version
3888 } else {
3889 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003890 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3891 expectedServerLocalError = "remote error: protocol version not supported"
3892 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3893 // If the client's minimum version is TLS 1.3 and the runner's
3894 // maximum is below TLS 1.2, the runner will fail to select a
3895 // cipher before the shim rejects the selected version.
3896 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3897 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3898 } else {
3899 expectedClientError = expectedServerError
3900 expectedClientLocalError = expectedServerLocalError
3901 }
David Benjaminaccb4542014-12-12 23:44:33 -05003902 }
3903
3904 testCases = append(testCases, testCase{
3905 protocol: protocol,
3906 testType: clientTest,
3907 name: "MinimumVersion-Client-" + suffix,
3908 config: Config{
3909 MaxVersion: runnerVers.version,
3910 },
David Benjamin87909c02014-12-13 01:55:01 -05003911 flags: flags,
3912 expectedVersion: expectedVersion,
3913 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003914 expectedError: expectedClientError,
3915 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003916 })
3917 testCases = append(testCases, testCase{
3918 protocol: protocol,
3919 testType: clientTest,
3920 name: "MinimumVersion-Client2-" + suffix,
3921 config: Config{
3922 MaxVersion: runnerVers.version,
3923 },
David Benjamin87909c02014-12-13 01:55:01 -05003924 flags: []string{"-min-version", shimVersFlag},
3925 expectedVersion: expectedVersion,
3926 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003927 expectedError: expectedClientError,
3928 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003929 })
3930
3931 testCases = append(testCases, testCase{
3932 protocol: protocol,
3933 testType: serverTest,
3934 name: "MinimumVersion-Server-" + suffix,
3935 config: Config{
3936 MaxVersion: runnerVers.version,
3937 },
David Benjamin87909c02014-12-13 01:55:01 -05003938 flags: flags,
3939 expectedVersion: expectedVersion,
3940 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003941 expectedError: expectedServerError,
3942 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003943 })
3944 testCases = append(testCases, testCase{
3945 protocol: protocol,
3946 testType: serverTest,
3947 name: "MinimumVersion-Server2-" + suffix,
3948 config: Config{
3949 MaxVersion: runnerVers.version,
3950 },
David Benjamin87909c02014-12-13 01:55:01 -05003951 flags: []string{"-min-version", shimVersFlag},
3952 expectedVersion: expectedVersion,
3953 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003954 expectedError: expectedServerError,
3955 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003956 })
3957 }
3958 }
3959 }
3960}
3961
David Benjamine78bfde2014-09-06 12:45:15 -04003962func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003963 // TODO(davidben): Extensions, where applicable, all move their server
3964 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3965 // tests for both. Also test interaction with 0-RTT when implemented.
3966
David Benjamin97d17d92016-07-14 16:12:00 -04003967 // Repeat extensions tests all versions except SSL 3.0.
3968 for _, ver := range tlsVersions {
3969 if ver.version == VersionSSL30 {
3970 continue
3971 }
3972
3973 // TODO(davidben): Implement resumption in TLS 1.3.
3974 resumeSession := ver.version < VersionTLS13
3975
3976 // Test that duplicate extensions are rejected.
3977 testCases = append(testCases, testCase{
3978 testType: clientTest,
3979 name: "DuplicateExtensionClient-" + ver.name,
3980 config: Config{
3981 MaxVersion: ver.version,
3982 Bugs: ProtocolBugs{
3983 DuplicateExtension: true,
3984 },
David Benjamine78bfde2014-09-06 12:45:15 -04003985 },
David Benjamin97d17d92016-07-14 16:12:00 -04003986 shouldFail: true,
3987 expectedLocalError: "remote error: error decoding message",
3988 })
3989 testCases = append(testCases, testCase{
3990 testType: serverTest,
3991 name: "DuplicateExtensionServer-" + ver.name,
3992 config: Config{
3993 MaxVersion: ver.version,
3994 Bugs: ProtocolBugs{
3995 DuplicateExtension: true,
3996 },
David Benjamine78bfde2014-09-06 12:45:15 -04003997 },
David Benjamin97d17d92016-07-14 16:12:00 -04003998 shouldFail: true,
3999 expectedLocalError: "remote error: error decoding message",
4000 })
4001
4002 // Test SNI.
4003 testCases = append(testCases, testCase{
4004 testType: clientTest,
4005 name: "ServerNameExtensionClient-" + ver.name,
4006 config: Config{
4007 MaxVersion: ver.version,
4008 Bugs: ProtocolBugs{
4009 ExpectServerName: "example.com",
4010 },
David Benjamine78bfde2014-09-06 12:45:15 -04004011 },
David Benjamin97d17d92016-07-14 16:12:00 -04004012 flags: []string{"-host-name", "example.com"},
4013 })
4014 testCases = append(testCases, testCase{
4015 testType: clientTest,
4016 name: "ServerNameExtensionClientMismatch-" + ver.name,
4017 config: Config{
4018 MaxVersion: ver.version,
4019 Bugs: ProtocolBugs{
4020 ExpectServerName: "mismatch.com",
4021 },
David Benjamine78bfde2014-09-06 12:45:15 -04004022 },
David Benjamin97d17d92016-07-14 16:12:00 -04004023 flags: []string{"-host-name", "example.com"},
4024 shouldFail: true,
4025 expectedLocalError: "tls: unexpected server name",
4026 })
4027 testCases = append(testCases, testCase{
4028 testType: clientTest,
4029 name: "ServerNameExtensionClientMissing-" + ver.name,
4030 config: Config{
4031 MaxVersion: ver.version,
4032 Bugs: ProtocolBugs{
4033 ExpectServerName: "missing.com",
4034 },
David Benjamine78bfde2014-09-06 12:45:15 -04004035 },
David Benjamin97d17d92016-07-14 16:12:00 -04004036 shouldFail: true,
4037 expectedLocalError: "tls: unexpected server name",
4038 })
4039 testCases = append(testCases, testCase{
4040 testType: serverTest,
4041 name: "ServerNameExtensionServer-" + ver.name,
4042 config: Config{
4043 MaxVersion: ver.version,
4044 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004045 },
David Benjamin97d17d92016-07-14 16:12:00 -04004046 flags: []string{"-expect-server-name", "example.com"},
4047 resumeSession: resumeSession,
4048 })
4049
4050 // Test ALPN.
4051 testCases = append(testCases, testCase{
4052 testType: clientTest,
4053 name: "ALPNClient-" + ver.name,
4054 config: Config{
4055 MaxVersion: ver.version,
4056 NextProtos: []string{"foo"},
4057 },
4058 flags: []string{
4059 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4060 "-expect-alpn", "foo",
4061 },
4062 expectedNextProto: "foo",
4063 expectedNextProtoType: alpn,
4064 resumeSession: resumeSession,
4065 })
4066 testCases = append(testCases, testCase{
4067 testType: serverTest,
4068 name: "ALPNServer-" + ver.name,
4069 config: Config{
4070 MaxVersion: ver.version,
4071 NextProtos: []string{"foo", "bar", "baz"},
4072 },
4073 flags: []string{
4074 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4075 "-select-alpn", "foo",
4076 },
4077 expectedNextProto: "foo",
4078 expectedNextProtoType: alpn,
4079 resumeSession: resumeSession,
4080 })
4081 testCases = append(testCases, testCase{
4082 testType: serverTest,
4083 name: "ALPNServer-Decline-" + ver.name,
4084 config: Config{
4085 MaxVersion: ver.version,
4086 NextProtos: []string{"foo", "bar", "baz"},
4087 },
4088 flags: []string{"-decline-alpn"},
4089 expectNoNextProto: true,
4090 resumeSession: resumeSession,
4091 })
4092
4093 var emptyString string
4094 testCases = append(testCases, testCase{
4095 testType: clientTest,
4096 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4097 config: Config{
4098 MaxVersion: ver.version,
4099 NextProtos: []string{""},
4100 Bugs: ProtocolBugs{
4101 // A server returning an empty ALPN protocol
4102 // should be rejected.
4103 ALPNProtocol: &emptyString,
4104 },
4105 },
4106 flags: []string{
4107 "-advertise-alpn", "\x03foo",
4108 },
4109 shouldFail: true,
4110 expectedError: ":PARSE_TLSEXT:",
4111 })
4112 testCases = append(testCases, testCase{
4113 testType: serverTest,
4114 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4115 config: Config{
4116 MaxVersion: ver.version,
4117 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004118 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004119 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004120 },
David Benjamin97d17d92016-07-14 16:12:00 -04004121 flags: []string{
4122 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004123 },
David Benjamin97d17d92016-07-14 16:12:00 -04004124 shouldFail: true,
4125 expectedError: ":PARSE_TLSEXT:",
4126 })
4127
4128 // Test NPN and the interaction with ALPN.
4129 if ver.version < VersionTLS13 {
4130 // Test that the server prefers ALPN over NPN.
4131 testCases = append(testCases, testCase{
4132 testType: serverTest,
4133 name: "ALPNServer-Preferred-" + ver.name,
4134 config: Config{
4135 MaxVersion: ver.version,
4136 NextProtos: []string{"foo", "bar", "baz"},
4137 },
4138 flags: []string{
4139 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4140 "-select-alpn", "foo",
4141 "-advertise-npn", "\x03foo\x03bar\x03baz",
4142 },
4143 expectedNextProto: "foo",
4144 expectedNextProtoType: alpn,
4145 resumeSession: resumeSession,
4146 })
4147 testCases = append(testCases, testCase{
4148 testType: serverTest,
4149 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4150 config: Config{
4151 MaxVersion: ver.version,
4152 NextProtos: []string{"foo", "bar", "baz"},
4153 Bugs: ProtocolBugs{
4154 SwapNPNAndALPN: true,
4155 },
4156 },
4157 flags: []string{
4158 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4159 "-select-alpn", "foo",
4160 "-advertise-npn", "\x03foo\x03bar\x03baz",
4161 },
4162 expectedNextProto: "foo",
4163 expectedNextProtoType: alpn,
4164 resumeSession: resumeSession,
4165 })
4166
4167 // Test that negotiating both NPN and ALPN is forbidden.
4168 testCases = append(testCases, testCase{
4169 name: "NegotiateALPNAndNPN-" + ver.name,
4170 config: Config{
4171 MaxVersion: ver.version,
4172 NextProtos: []string{"foo", "bar", "baz"},
4173 Bugs: ProtocolBugs{
4174 NegotiateALPNAndNPN: true,
4175 },
4176 },
4177 flags: []string{
4178 "-advertise-alpn", "\x03foo",
4179 "-select-next-proto", "foo",
4180 },
4181 shouldFail: true,
4182 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4183 })
4184 testCases = append(testCases, testCase{
4185 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4186 config: Config{
4187 MaxVersion: ver.version,
4188 NextProtos: []string{"foo", "bar", "baz"},
4189 Bugs: ProtocolBugs{
4190 NegotiateALPNAndNPN: true,
4191 SwapNPNAndALPN: true,
4192 },
4193 },
4194 flags: []string{
4195 "-advertise-alpn", "\x03foo",
4196 "-select-next-proto", "foo",
4197 },
4198 shouldFail: true,
4199 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4200 })
4201
4202 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4203 testCases = append(testCases, testCase{
4204 name: "DisableNPN-" + ver.name,
4205 config: Config{
4206 MaxVersion: ver.version,
4207 NextProtos: []string{"foo"},
4208 },
4209 flags: []string{
4210 "-select-next-proto", "foo",
4211 "-disable-npn",
4212 },
4213 expectNoNextProto: true,
4214 })
4215 }
4216
4217 // Test ticket behavior.
4218 //
4219 // TODO(davidben): Add TLS 1.3 versions of these.
4220 if ver.version < VersionTLS13 {
4221 // Resume with a corrupt ticket.
4222 testCases = append(testCases, testCase{
4223 testType: serverTest,
4224 name: "CorruptTicket-" + ver.name,
4225 config: Config{
4226 MaxVersion: ver.version,
4227 Bugs: ProtocolBugs{
4228 CorruptTicket: true,
4229 },
4230 },
4231 resumeSession: true,
4232 expectResumeRejected: true,
4233 })
4234 // Test the ticket callback, with and without renewal.
4235 testCases = append(testCases, testCase{
4236 testType: serverTest,
4237 name: "TicketCallback-" + ver.name,
4238 config: Config{
4239 MaxVersion: ver.version,
4240 },
4241 resumeSession: true,
4242 flags: []string{"-use-ticket-callback"},
4243 })
4244 testCases = append(testCases, testCase{
4245 testType: serverTest,
4246 name: "TicketCallback-Renew-" + ver.name,
4247 config: Config{
4248 MaxVersion: ver.version,
4249 Bugs: ProtocolBugs{
4250 ExpectNewTicket: true,
4251 },
4252 },
4253 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4254 resumeSession: true,
4255 })
4256
4257 // Resume with an oversized session id.
4258 testCases = append(testCases, testCase{
4259 testType: serverTest,
4260 name: "OversizedSessionId-" + ver.name,
4261 config: Config{
4262 MaxVersion: ver.version,
4263 Bugs: ProtocolBugs{
4264 OversizedSessionId: true,
4265 },
4266 },
4267 resumeSession: true,
4268 shouldFail: true,
4269 expectedError: ":DECODE_ERROR:",
4270 })
4271 }
4272
4273 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4274 // are ignored.
4275 if ver.hasDTLS {
4276 testCases = append(testCases, testCase{
4277 protocol: dtls,
4278 name: "SRTP-Client-" + ver.name,
4279 config: Config{
4280 MaxVersion: ver.version,
4281 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4282 },
4283 flags: []string{
4284 "-srtp-profiles",
4285 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4286 },
4287 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4288 })
4289 testCases = append(testCases, testCase{
4290 protocol: dtls,
4291 testType: serverTest,
4292 name: "SRTP-Server-" + ver.name,
4293 config: Config{
4294 MaxVersion: ver.version,
4295 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4296 },
4297 flags: []string{
4298 "-srtp-profiles",
4299 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4300 },
4301 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4302 })
4303 // Test that the MKI is ignored.
4304 testCases = append(testCases, testCase{
4305 protocol: dtls,
4306 testType: serverTest,
4307 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4308 config: Config{
4309 MaxVersion: ver.version,
4310 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4311 Bugs: ProtocolBugs{
4312 SRTPMasterKeyIdentifer: "bogus",
4313 },
4314 },
4315 flags: []string{
4316 "-srtp-profiles",
4317 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4318 },
4319 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4320 })
4321 // Test that SRTP isn't negotiated on the server if there were
4322 // no matching profiles.
4323 testCases = append(testCases, testCase{
4324 protocol: dtls,
4325 testType: serverTest,
4326 name: "SRTP-Server-NoMatch-" + ver.name,
4327 config: Config{
4328 MaxVersion: ver.version,
4329 SRTPProtectionProfiles: []uint16{100, 101, 102},
4330 },
4331 flags: []string{
4332 "-srtp-profiles",
4333 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4334 },
4335 expectedSRTPProtectionProfile: 0,
4336 })
4337 // Test that the server returning an invalid SRTP profile is
4338 // flagged as an error by the client.
4339 testCases = append(testCases, testCase{
4340 protocol: dtls,
4341 name: "SRTP-Client-NoMatch-" + ver.name,
4342 config: Config{
4343 MaxVersion: ver.version,
4344 Bugs: ProtocolBugs{
4345 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4346 },
4347 },
4348 flags: []string{
4349 "-srtp-profiles",
4350 "SRTP_AES128_CM_SHA1_80",
4351 },
4352 shouldFail: true,
4353 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4354 })
4355 }
4356
4357 // Test SCT list.
4358 testCases = append(testCases, testCase{
4359 name: "SignedCertificateTimestampList-Client-" + ver.name,
4360 testType: clientTest,
4361 config: Config{
4362 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004363 },
David Benjamin97d17d92016-07-14 16:12:00 -04004364 flags: []string{
4365 "-enable-signed-cert-timestamps",
4366 "-expect-signed-cert-timestamps",
4367 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004368 },
David Benjamin97d17d92016-07-14 16:12:00 -04004369 resumeSession: resumeSession,
4370 })
4371 testCases = append(testCases, testCase{
4372 name: "SendSCTListOnResume-" + ver.name,
4373 config: Config{
4374 MaxVersion: ver.version,
4375 Bugs: ProtocolBugs{
4376 SendSCTListOnResume: []byte("bogus"),
4377 },
David Benjamind98452d2015-06-16 14:16:23 -04004378 },
David Benjamin97d17d92016-07-14 16:12:00 -04004379 flags: []string{
4380 "-enable-signed-cert-timestamps",
4381 "-expect-signed-cert-timestamps",
4382 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004383 },
David Benjamin97d17d92016-07-14 16:12:00 -04004384 resumeSession: resumeSession,
4385 })
4386 testCases = append(testCases, testCase{
4387 name: "SignedCertificateTimestampList-Server-" + ver.name,
4388 testType: serverTest,
4389 config: Config{
4390 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004391 },
David Benjamin97d17d92016-07-14 16:12:00 -04004392 flags: []string{
4393 "-signed-cert-timestamps",
4394 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004395 },
David Benjamin97d17d92016-07-14 16:12:00 -04004396 expectedSCTList: testSCTList,
4397 resumeSession: resumeSession,
4398 })
4399 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004400
Paul Lietar4fac72e2015-09-09 13:44:55 +01004401 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004402 testType: clientTest,
4403 name: "ClientHelloPadding",
4404 config: Config{
4405 Bugs: ProtocolBugs{
4406 RequireClientHelloSize: 512,
4407 },
4408 },
4409 // This hostname just needs to be long enough to push the
4410 // ClientHello into F5's danger zone between 256 and 511 bytes
4411 // long.
4412 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4413 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004414
4415 // Extensions should not function in SSL 3.0.
4416 testCases = append(testCases, testCase{
4417 testType: serverTest,
4418 name: "SSLv3Extensions-NoALPN",
4419 config: Config{
4420 MaxVersion: VersionSSL30,
4421 NextProtos: []string{"foo", "bar", "baz"},
4422 },
4423 flags: []string{
4424 "-select-alpn", "foo",
4425 },
4426 expectNoNextProto: true,
4427 })
4428
4429 // Test session tickets separately as they follow a different codepath.
4430 testCases = append(testCases, testCase{
4431 testType: serverTest,
4432 name: "SSLv3Extensions-NoTickets",
4433 config: Config{
4434 MaxVersion: VersionSSL30,
4435 Bugs: ProtocolBugs{
4436 // Historically, session tickets in SSL 3.0
4437 // failed in different ways depending on whether
4438 // the client supported renegotiation_info.
4439 NoRenegotiationInfo: true,
4440 },
4441 },
4442 resumeSession: true,
4443 })
4444 testCases = append(testCases, testCase{
4445 testType: serverTest,
4446 name: "SSLv3Extensions-NoTickets2",
4447 config: Config{
4448 MaxVersion: VersionSSL30,
4449 },
4450 resumeSession: true,
4451 })
4452
4453 // But SSL 3.0 does send and process renegotiation_info.
4454 testCases = append(testCases, testCase{
4455 testType: serverTest,
4456 name: "SSLv3Extensions-RenegotiationInfo",
4457 config: Config{
4458 MaxVersion: VersionSSL30,
4459 Bugs: ProtocolBugs{
4460 RequireRenegotiationInfo: true,
4461 },
4462 },
4463 })
4464 testCases = append(testCases, testCase{
4465 testType: serverTest,
4466 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4467 config: Config{
4468 MaxVersion: VersionSSL30,
4469 Bugs: ProtocolBugs{
4470 NoRenegotiationInfo: true,
4471 SendRenegotiationSCSV: true,
4472 RequireRenegotiationInfo: true,
4473 },
4474 },
4475 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004476
4477 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4478 // in ServerHello.
4479 testCases = append(testCases, testCase{
4480 name: "NPN-Forbidden-TLS13",
4481 config: Config{
4482 MaxVersion: VersionTLS13,
4483 NextProtos: []string{"foo"},
4484 Bugs: ProtocolBugs{
4485 NegotiateNPNAtAllVersions: true,
4486 },
4487 },
4488 flags: []string{"-select-next-proto", "foo"},
4489 shouldFail: true,
4490 expectedError: ":ERROR_PARSING_EXTENSION:",
4491 })
4492 testCases = append(testCases, testCase{
4493 name: "EMS-Forbidden-TLS13",
4494 config: Config{
4495 MaxVersion: VersionTLS13,
4496 Bugs: ProtocolBugs{
4497 NegotiateEMSAtAllVersions: true,
4498 },
4499 },
4500 shouldFail: true,
4501 expectedError: ":ERROR_PARSING_EXTENSION:",
4502 })
4503 testCases = append(testCases, testCase{
4504 name: "RenegotiationInfo-Forbidden-TLS13",
4505 config: Config{
4506 MaxVersion: VersionTLS13,
4507 Bugs: ProtocolBugs{
4508 NegotiateRenegotiationInfoAtAllVersions: true,
4509 },
4510 },
4511 shouldFail: true,
4512 expectedError: ":ERROR_PARSING_EXTENSION:",
4513 })
4514 testCases = append(testCases, testCase{
4515 name: "ChannelID-Forbidden-TLS13",
4516 config: Config{
4517 MaxVersion: VersionTLS13,
4518 RequestChannelID: true,
4519 Bugs: ProtocolBugs{
4520 NegotiateChannelIDAtAllVersions: true,
4521 },
4522 },
4523 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4524 shouldFail: true,
4525 expectedError: ":ERROR_PARSING_EXTENSION:",
4526 })
4527 testCases = append(testCases, testCase{
4528 name: "Ticket-Forbidden-TLS13",
4529 config: Config{
4530 MaxVersion: VersionTLS12,
4531 },
4532 resumeConfig: &Config{
4533 MaxVersion: VersionTLS13,
4534 Bugs: ProtocolBugs{
4535 AdvertiseTicketExtension: true,
4536 },
4537 },
4538 resumeSession: true,
4539 shouldFail: true,
4540 expectedError: ":ERROR_PARSING_EXTENSION:",
4541 })
4542
4543 // Test that illegal extensions in TLS 1.3 are declined by the server if
4544 // offered in ClientHello. The runner's server will fail if this occurs,
4545 // so we exercise the offering path. (EMS and Renegotiation Info are
4546 // implicit in every test.)
4547 testCases = append(testCases, testCase{
4548 testType: serverTest,
4549 name: "ChannelID-Declined-TLS13",
4550 config: Config{
4551 MaxVersion: VersionTLS13,
4552 ChannelID: channelIDKey,
4553 },
4554 flags: []string{"-enable-channel-id"},
4555 })
4556 testCases = append(testCases, testCase{
4557 testType: serverTest,
4558 name: "NPN-Server",
4559 config: Config{
4560 MaxVersion: VersionTLS13,
4561 NextProtos: []string{"bar"},
4562 },
4563 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4564 })
David Benjamine78bfde2014-09-06 12:45:15 -04004565}
4566
David Benjamin01fe8202014-09-24 15:21:44 -04004567func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004568 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004569 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4570 if sessionVers.version >= VersionTLS13 {
4571 continue
4572 }
David Benjamin01fe8202014-09-24 15:21:44 -04004573 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004574 if resumeVers.version >= VersionTLS13 {
4575 continue
4576 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004577 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4578 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4579 // TLS 1.3 only shares ciphers with TLS 1.2, so
4580 // we skip certain combinations and use a
4581 // different cipher to test with.
4582 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4583 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4584 continue
4585 }
4586 }
4587
David Benjamin8b8c0062014-11-23 02:47:52 -05004588 protocols := []protocol{tls}
4589 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4590 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004591 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004592 for _, protocol := range protocols {
4593 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4594 if protocol == dtls {
4595 suffix += "-DTLS"
4596 }
4597
David Benjaminece3de92015-03-16 18:02:20 -04004598 if sessionVers.version == resumeVers.version {
4599 testCases = append(testCases, testCase{
4600 protocol: protocol,
4601 name: "Resume-Client" + suffix,
4602 resumeSession: true,
4603 config: Config{
4604 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004605 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004606 },
David Benjaminece3de92015-03-16 18:02:20 -04004607 expectedVersion: sessionVers.version,
4608 expectedResumeVersion: resumeVers.version,
4609 })
4610 } else {
4611 testCases = append(testCases, testCase{
4612 protocol: protocol,
4613 name: "Resume-Client-Mismatch" + suffix,
4614 resumeSession: true,
4615 config: Config{
4616 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004617 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004618 },
David Benjaminece3de92015-03-16 18:02:20 -04004619 expectedVersion: sessionVers.version,
4620 resumeConfig: &Config{
4621 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004622 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004623 Bugs: ProtocolBugs{
4624 AllowSessionVersionMismatch: true,
4625 },
4626 },
4627 expectedResumeVersion: resumeVers.version,
4628 shouldFail: true,
4629 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4630 })
4631 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004632
4633 testCases = append(testCases, testCase{
4634 protocol: protocol,
4635 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004636 resumeSession: true,
4637 config: Config{
4638 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004639 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004640 },
4641 expectedVersion: sessionVers.version,
4642 resumeConfig: &Config{
4643 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004644 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004645 },
4646 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004647 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004648 expectedResumeVersion: resumeVers.version,
4649 })
4650
David Benjamin8b8c0062014-11-23 02:47:52 -05004651 testCases = append(testCases, testCase{
4652 protocol: protocol,
4653 testType: serverTest,
4654 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004655 resumeSession: true,
4656 config: Config{
4657 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004658 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004659 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004660 expectedVersion: sessionVers.version,
4661 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004662 resumeConfig: &Config{
4663 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004664 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004665 },
4666 expectedResumeVersion: resumeVers.version,
4667 })
4668 }
David Benjamin01fe8202014-09-24 15:21:44 -04004669 }
4670 }
David Benjaminece3de92015-03-16 18:02:20 -04004671
Nick Harper1fd39d82016-06-14 18:14:35 -07004672 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004673 testCases = append(testCases, testCase{
4674 name: "Resume-Client-CipherMismatch",
4675 resumeSession: true,
4676 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004677 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004678 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4679 },
4680 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004681 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004682 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4683 Bugs: ProtocolBugs{
4684 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4685 },
4686 },
4687 shouldFail: true,
4688 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4689 })
David Benjamin01fe8202014-09-24 15:21:44 -04004690}
4691
Adam Langley2ae77d22014-10-28 17:29:33 -07004692func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004693 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004694 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004695 testType: serverTest,
4696 name: "Renegotiate-Server-Forbidden",
4697 config: Config{
4698 MaxVersion: VersionTLS12,
4699 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004700 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004701 shouldFail: true,
4702 expectedError: ":NO_RENEGOTIATION:",
4703 expectedLocalError: "remote error: no renegotiation",
4704 })
Adam Langley5021b222015-06-12 18:27:58 -07004705 // The server shouldn't echo the renegotiation extension unless
4706 // requested by the client.
4707 testCases = append(testCases, testCase{
4708 testType: serverTest,
4709 name: "Renegotiate-Server-NoExt",
4710 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004711 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004712 Bugs: ProtocolBugs{
4713 NoRenegotiationInfo: true,
4714 RequireRenegotiationInfo: true,
4715 },
4716 },
4717 shouldFail: true,
4718 expectedLocalError: "renegotiation extension missing",
4719 })
4720 // The renegotiation SCSV should be sufficient for the server to echo
4721 // the extension.
4722 testCases = append(testCases, testCase{
4723 testType: serverTest,
4724 name: "Renegotiate-Server-NoExt-SCSV",
4725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004726 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004727 Bugs: ProtocolBugs{
4728 NoRenegotiationInfo: true,
4729 SendRenegotiationSCSV: true,
4730 RequireRenegotiationInfo: true,
4731 },
4732 },
4733 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004734 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004735 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004736 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004737 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004738 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004739 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004740 },
4741 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004742 renegotiate: 1,
4743 flags: []string{
4744 "-renegotiate-freely",
4745 "-expect-total-renegotiations", "1",
4746 },
David Benjamincdea40c2015-03-19 14:09:43 -04004747 })
4748 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004749 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004750 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004751 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004752 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004753 Bugs: ProtocolBugs{
4754 EmptyRenegotiationInfo: true,
4755 },
4756 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004757 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004758 shouldFail: true,
4759 expectedError: ":RENEGOTIATION_MISMATCH:",
4760 })
4761 testCases = append(testCases, testCase{
4762 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004763 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004765 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004766 Bugs: ProtocolBugs{
4767 BadRenegotiationInfo: true,
4768 },
4769 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004770 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004771 shouldFail: true,
4772 expectedError: ":RENEGOTIATION_MISMATCH:",
4773 })
4774 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004775 name: "Renegotiate-Client-Downgrade",
4776 renegotiate: 1,
4777 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004778 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004779 Bugs: ProtocolBugs{
4780 NoRenegotiationInfoAfterInitial: true,
4781 },
4782 },
4783 flags: []string{"-renegotiate-freely"},
4784 shouldFail: true,
4785 expectedError: ":RENEGOTIATION_MISMATCH:",
4786 })
4787 testCases = append(testCases, testCase{
4788 name: "Renegotiate-Client-Upgrade",
4789 renegotiate: 1,
4790 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004791 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004792 Bugs: ProtocolBugs{
4793 NoRenegotiationInfoInInitial: true,
4794 },
4795 },
4796 flags: []string{"-renegotiate-freely"},
4797 shouldFail: true,
4798 expectedError: ":RENEGOTIATION_MISMATCH:",
4799 })
4800 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004801 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004802 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004804 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004805 Bugs: ProtocolBugs{
4806 NoRenegotiationInfo: true,
4807 },
4808 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004809 flags: []string{
4810 "-renegotiate-freely",
4811 "-expect-total-renegotiations", "1",
4812 },
David Benjamincff0b902015-05-15 23:09:47 -04004813 })
4814 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004815 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004816 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004817 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004818 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004819 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4820 },
4821 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004822 flags: []string{
4823 "-renegotiate-freely",
4824 "-expect-total-renegotiations", "1",
4825 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004826 })
4827 testCases = append(testCases, testCase{
4828 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004829 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004830 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004831 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4833 },
4834 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004835 flags: []string{
4836 "-renegotiate-freely",
4837 "-expect-total-renegotiations", "1",
4838 },
David Benjaminb16346b2015-04-08 19:16:58 -04004839 })
4840 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004841 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004842 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004843 config: Config{
4844 MaxVersion: VersionTLS10,
4845 Bugs: ProtocolBugs{
4846 RequireSameRenegoClientVersion: true,
4847 },
4848 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004849 flags: []string{
4850 "-renegotiate-freely",
4851 "-expect-total-renegotiations", "1",
4852 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004853 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004854 testCases = append(testCases, testCase{
4855 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004856 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004857 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004858 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004859 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4860 NextProtos: []string{"foo"},
4861 },
4862 flags: []string{
4863 "-false-start",
4864 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004865 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004866 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004867 },
4868 shimWritesFirst: true,
4869 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004870
4871 // Client-side renegotiation controls.
4872 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004873 name: "Renegotiate-Client-Forbidden-1",
4874 config: Config{
4875 MaxVersion: VersionTLS12,
4876 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004877 renegotiate: 1,
4878 shouldFail: true,
4879 expectedError: ":NO_RENEGOTIATION:",
4880 expectedLocalError: "remote error: no renegotiation",
4881 })
4882 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004883 name: "Renegotiate-Client-Once-1",
4884 config: Config{
4885 MaxVersion: VersionTLS12,
4886 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004887 renegotiate: 1,
4888 flags: []string{
4889 "-renegotiate-once",
4890 "-expect-total-renegotiations", "1",
4891 },
4892 })
4893 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004894 name: "Renegotiate-Client-Freely-1",
4895 config: Config{
4896 MaxVersion: VersionTLS12,
4897 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004898 renegotiate: 1,
4899 flags: []string{
4900 "-renegotiate-freely",
4901 "-expect-total-renegotiations", "1",
4902 },
4903 })
4904 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004905 name: "Renegotiate-Client-Once-2",
4906 config: Config{
4907 MaxVersion: VersionTLS12,
4908 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004909 renegotiate: 2,
4910 flags: []string{"-renegotiate-once"},
4911 shouldFail: true,
4912 expectedError: ":NO_RENEGOTIATION:",
4913 expectedLocalError: "remote error: no renegotiation",
4914 })
4915 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004916 name: "Renegotiate-Client-Freely-2",
4917 config: Config{
4918 MaxVersion: VersionTLS12,
4919 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004920 renegotiate: 2,
4921 flags: []string{
4922 "-renegotiate-freely",
4923 "-expect-total-renegotiations", "2",
4924 },
4925 })
Adam Langley27a0d082015-11-03 13:34:10 -08004926 testCases = append(testCases, testCase{
4927 name: "Renegotiate-Client-NoIgnore",
4928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004929 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004930 Bugs: ProtocolBugs{
4931 SendHelloRequestBeforeEveryAppDataRecord: true,
4932 },
4933 },
4934 shouldFail: true,
4935 expectedError: ":NO_RENEGOTIATION:",
4936 })
4937 testCases = append(testCases, testCase{
4938 name: "Renegotiate-Client-Ignore",
4939 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004940 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004941 Bugs: ProtocolBugs{
4942 SendHelloRequestBeforeEveryAppDataRecord: true,
4943 },
4944 },
4945 flags: []string{
4946 "-renegotiate-ignore",
4947 "-expect-total-renegotiations", "0",
4948 },
4949 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004950
David Benjamin397c8e62016-07-08 14:14:36 -07004951 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004952 testCases = append(testCases, testCase{
4953 name: "StrayHelloRequest",
4954 config: Config{
4955 MaxVersion: VersionTLS12,
4956 Bugs: ProtocolBugs{
4957 SendHelloRequestBeforeEveryHandshakeMessage: true,
4958 },
4959 },
4960 })
4961 testCases = append(testCases, testCase{
4962 name: "StrayHelloRequest-Packed",
4963 config: Config{
4964 MaxVersion: VersionTLS12,
4965 Bugs: ProtocolBugs{
4966 PackHandshakeFlight: true,
4967 SendHelloRequestBeforeEveryHandshakeMessage: true,
4968 },
4969 },
4970 })
4971
David Benjamin397c8e62016-07-08 14:14:36 -07004972 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04004973 //
4974 // TODO(davidben): This test current asserts that we ignore
4975 // HelloRequests, but we actually should hard reject them. Fix this
4976 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07004977 testCases = append(testCases, testCase{
4978 name: "Renegotiate-Client-TLS13",
4979 config: Config{
4980 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04004981 Bugs: ProtocolBugs{
4982 SendHelloRequestBeforeEveryAppDataRecord: true,
4983 },
David Benjamin397c8e62016-07-08 14:14:36 -07004984 },
David Benjamin397c8e62016-07-08 14:14:36 -07004985 flags: []string{
4986 "-renegotiate-freely",
4987 },
David Benjamin397c8e62016-07-08 14:14:36 -07004988 })
4989
4990 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4991 testCases = append(testCases, testCase{
4992 name: "StrayHelloRequest-TLS13",
4993 config: Config{
4994 MaxVersion: VersionTLS13,
4995 Bugs: ProtocolBugs{
4996 SendHelloRequestBeforeEveryHandshakeMessage: true,
4997 },
4998 },
4999 shouldFail: true,
5000 expectedError: ":UNEXPECTED_MESSAGE:",
5001 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005002}
5003
David Benjamin5e961c12014-11-07 01:48:35 -05005004func addDTLSReplayTests() {
5005 // Test that sequence number replays are detected.
5006 testCases = append(testCases, testCase{
5007 protocol: dtls,
5008 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005009 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005010 replayWrites: true,
5011 })
5012
David Benjamin8e6db492015-07-25 18:29:23 -04005013 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005014 // than the retransmit window.
5015 testCases = append(testCases, testCase{
5016 protocol: dtls,
5017 name: "DTLS-Replay-LargeGaps",
5018 config: Config{
5019 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005020 SequenceNumberMapping: func(in uint64) uint64 {
5021 return in * 127
5022 },
David Benjamin5e961c12014-11-07 01:48:35 -05005023 },
5024 },
David Benjamin8e6db492015-07-25 18:29:23 -04005025 messageCount: 200,
5026 replayWrites: true,
5027 })
5028
5029 // Test the incoming sequence number changing non-monotonically.
5030 testCases = append(testCases, testCase{
5031 protocol: dtls,
5032 name: "DTLS-Replay-NonMonotonic",
5033 config: Config{
5034 Bugs: ProtocolBugs{
5035 SequenceNumberMapping: func(in uint64) uint64 {
5036 return in ^ 31
5037 },
5038 },
5039 },
5040 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005041 replayWrites: true,
5042 })
5043}
5044
Nick Harper60edffd2016-06-21 15:19:24 -07005045var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005046 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005047 id signatureAlgorithm
5048 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005049}{
Nick Harper60edffd2016-06-21 15:19:24 -07005050 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5051 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5052 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5053 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005054 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005055 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5056 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5057 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005058 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5059 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5060 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005061 // Tests for key types prior to TLS 1.2.
5062 {"RSA", 0, testCertRSA},
5063 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005064}
5065
Nick Harper60edffd2016-06-21 15:19:24 -07005066const fakeSigAlg1 signatureAlgorithm = 0x2a01
5067const fakeSigAlg2 signatureAlgorithm = 0xff01
5068
5069func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005070 // Not all ciphers involve a signature. Advertise a list which gives all
5071 // versions a signing cipher.
5072 signingCiphers := []uint16{
5073 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5074 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5075 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5076 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5077 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5078 }
5079
David Benjaminca3d5452016-07-14 12:51:01 -04005080 var allAlgorithms []signatureAlgorithm
5081 for _, alg := range testSignatureAlgorithms {
5082 if alg.id != 0 {
5083 allAlgorithms = append(allAlgorithms, alg.id)
5084 }
5085 }
5086
Nick Harper60edffd2016-06-21 15:19:24 -07005087 // Make sure each signature algorithm works. Include some fake values in
5088 // the list and ensure they're ignored.
5089 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005090 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005091 if (ver.version < VersionTLS12) != (alg.id == 0) {
5092 continue
5093 }
5094
5095 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5096 // or remove it in C.
5097 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005098 continue
5099 }
Nick Harper60edffd2016-06-21 15:19:24 -07005100
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005101 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005102 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005103 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5104 shouldFail = true
5105 }
5106 // RSA-PSS does not exist in TLS 1.2.
5107 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5108 shouldFail = true
5109 }
5110
5111 var signError, verifyError string
5112 if shouldFail {
5113 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5114 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005115 }
David Benjamin000800a2014-11-14 01:43:59 -05005116
David Benjamin1fb125c2016-07-08 18:52:12 -07005117 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005118
David Benjamin7a41d372016-07-09 11:21:54 -07005119 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005120 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005121 config: Config{
5122 MaxVersion: ver.version,
5123 ClientAuth: RequireAnyClientCert,
5124 VerifySignatureAlgorithms: []signatureAlgorithm{
5125 fakeSigAlg1,
5126 alg.id,
5127 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005128 },
David Benjamin7a41d372016-07-09 11:21:54 -07005129 },
5130 flags: []string{
5131 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5132 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5133 "-enable-all-curves",
5134 },
5135 shouldFail: shouldFail,
5136 expectedError: signError,
5137 expectedPeerSignatureAlgorithm: alg.id,
5138 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005139
David Benjamin7a41d372016-07-09 11:21:54 -07005140 testCases = append(testCases, testCase{
5141 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005142 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005143 config: Config{
5144 MaxVersion: ver.version,
5145 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5146 SignSignatureAlgorithms: []signatureAlgorithm{
5147 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005148 },
David Benjamin7a41d372016-07-09 11:21:54 -07005149 Bugs: ProtocolBugs{
5150 SkipECDSACurveCheck: shouldFail,
5151 IgnoreSignatureVersionChecks: shouldFail,
5152 // The client won't advertise 1.3-only algorithms after
5153 // version negotiation.
5154 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005155 },
David Benjamin7a41d372016-07-09 11:21:54 -07005156 },
5157 flags: []string{
5158 "-require-any-client-certificate",
5159 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5160 "-enable-all-curves",
5161 },
5162 shouldFail: shouldFail,
5163 expectedError: verifyError,
5164 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005165
5166 testCases = append(testCases, testCase{
5167 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005168 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005169 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005170 MaxVersion: ver.version,
5171 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005172 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005173 fakeSigAlg1,
5174 alg.id,
5175 fakeSigAlg2,
5176 },
5177 },
5178 flags: []string{
5179 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5180 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5181 "-enable-all-curves",
5182 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005183 shouldFail: shouldFail,
5184 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005185 expectedPeerSignatureAlgorithm: alg.id,
5186 })
5187
5188 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005189 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005190 config: Config{
5191 MaxVersion: ver.version,
5192 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005193 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005194 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005195 alg.id,
5196 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005197 Bugs: ProtocolBugs{
5198 SkipECDSACurveCheck: shouldFail,
5199 IgnoreSignatureVersionChecks: shouldFail,
5200 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005201 },
5202 flags: []string{
5203 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5204 "-enable-all-curves",
5205 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005206 shouldFail: shouldFail,
5207 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005208 })
David Benjamin5208fd42016-07-13 21:43:25 -04005209
5210 if !shouldFail {
5211 testCases = append(testCases, testCase{
5212 testType: serverTest,
5213 name: "ClientAuth-InvalidSignature" + suffix,
5214 config: Config{
5215 MaxVersion: ver.version,
5216 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5217 SignSignatureAlgorithms: []signatureAlgorithm{
5218 alg.id,
5219 },
5220 Bugs: ProtocolBugs{
5221 InvalidSignature: true,
5222 },
5223 },
5224 flags: []string{
5225 "-require-any-client-certificate",
5226 "-enable-all-curves",
5227 },
5228 shouldFail: true,
5229 expectedError: ":BAD_SIGNATURE:",
5230 })
5231
5232 testCases = append(testCases, testCase{
5233 name: "ServerAuth-InvalidSignature" + suffix,
5234 config: Config{
5235 MaxVersion: ver.version,
5236 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5237 CipherSuites: signingCiphers,
5238 SignSignatureAlgorithms: []signatureAlgorithm{
5239 alg.id,
5240 },
5241 Bugs: ProtocolBugs{
5242 InvalidSignature: true,
5243 },
5244 },
5245 flags: []string{"-enable-all-curves"},
5246 shouldFail: true,
5247 expectedError: ":BAD_SIGNATURE:",
5248 })
5249 }
David Benjaminca3d5452016-07-14 12:51:01 -04005250
5251 if ver.version >= VersionTLS12 && !shouldFail {
5252 testCases = append(testCases, testCase{
5253 name: "ClientAuth-Sign-Negotiate" + suffix,
5254 config: Config{
5255 MaxVersion: ver.version,
5256 ClientAuth: RequireAnyClientCert,
5257 VerifySignatureAlgorithms: allAlgorithms,
5258 },
5259 flags: []string{
5260 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5261 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5262 "-enable-all-curves",
5263 "-signing-prefs", strconv.Itoa(int(alg.id)),
5264 },
5265 expectedPeerSignatureAlgorithm: alg.id,
5266 })
5267
5268 testCases = append(testCases, testCase{
5269 testType: serverTest,
5270 name: "ServerAuth-Sign-Negotiate" + suffix,
5271 config: Config{
5272 MaxVersion: ver.version,
5273 CipherSuites: signingCiphers,
5274 VerifySignatureAlgorithms: allAlgorithms,
5275 },
5276 flags: []string{
5277 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5278 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5279 "-enable-all-curves",
5280 "-signing-prefs", strconv.Itoa(int(alg.id)),
5281 },
5282 expectedPeerSignatureAlgorithm: alg.id,
5283 })
5284 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005285 }
David Benjamin000800a2014-11-14 01:43:59 -05005286 }
5287
Nick Harper60edffd2016-06-21 15:19:24 -07005288 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005289 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005290 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005291 config: Config{
5292 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005293 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005294 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005295 signatureECDSAWithP521AndSHA512,
5296 signatureRSAPKCS1WithSHA384,
5297 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005298 },
5299 },
5300 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005301 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5302 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005303 },
Nick Harper60edffd2016-06-21 15:19:24 -07005304 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005305 })
5306
5307 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005308 name: "ClientAuth-SignatureType-TLS13",
5309 config: Config{
5310 ClientAuth: RequireAnyClientCert,
5311 MaxVersion: VersionTLS13,
5312 VerifySignatureAlgorithms: []signatureAlgorithm{
5313 signatureECDSAWithP521AndSHA512,
5314 signatureRSAPKCS1WithSHA384,
5315 signatureRSAPSSWithSHA384,
5316 signatureECDSAWithSHA1,
5317 },
5318 },
5319 flags: []string{
5320 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5321 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5322 },
5323 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5324 })
5325
5326 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005327 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005328 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005329 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005330 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005331 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005332 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005333 signatureECDSAWithP521AndSHA512,
5334 signatureRSAPKCS1WithSHA384,
5335 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005336 },
5337 },
Nick Harper60edffd2016-06-21 15:19:24 -07005338 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005339 })
5340
Steven Valdez143e8b32016-07-11 13:19:03 -04005341 testCases = append(testCases, testCase{
5342 testType: serverTest,
5343 name: "ServerAuth-SignatureType-TLS13",
5344 config: Config{
5345 MaxVersion: VersionTLS13,
5346 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5347 VerifySignatureAlgorithms: []signatureAlgorithm{
5348 signatureECDSAWithP521AndSHA512,
5349 signatureRSAPKCS1WithSHA384,
5350 signatureRSAPSSWithSHA384,
5351 signatureECDSAWithSHA1,
5352 },
5353 },
5354 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5355 })
5356
David Benjamina95e9f32016-07-08 16:28:04 -07005357 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005358 testCases = append(testCases, testCase{
5359 testType: serverTest,
5360 name: "Verify-ClientAuth-SignatureType",
5361 config: Config{
5362 MaxVersion: VersionTLS12,
5363 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005364 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005365 signatureRSAPKCS1WithSHA256,
5366 },
5367 Bugs: ProtocolBugs{
5368 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5369 },
5370 },
5371 flags: []string{
5372 "-require-any-client-certificate",
5373 },
5374 shouldFail: true,
5375 expectedError: ":WRONG_SIGNATURE_TYPE:",
5376 })
5377
5378 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005379 testType: serverTest,
5380 name: "Verify-ClientAuth-SignatureType-TLS13",
5381 config: Config{
5382 MaxVersion: VersionTLS13,
5383 Certificates: []Certificate{rsaCertificate},
5384 SignSignatureAlgorithms: []signatureAlgorithm{
5385 signatureRSAPSSWithSHA256,
5386 },
5387 Bugs: ProtocolBugs{
5388 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5389 },
5390 },
5391 flags: []string{
5392 "-require-any-client-certificate",
5393 },
5394 shouldFail: true,
5395 expectedError: ":WRONG_SIGNATURE_TYPE:",
5396 })
5397
5398 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005399 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005400 config: Config{
5401 MaxVersion: VersionTLS12,
5402 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005403 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005404 signatureRSAPKCS1WithSHA256,
5405 },
5406 Bugs: ProtocolBugs{
5407 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5408 },
5409 },
5410 shouldFail: true,
5411 expectedError: ":WRONG_SIGNATURE_TYPE:",
5412 })
5413
Steven Valdez143e8b32016-07-11 13:19:03 -04005414 testCases = append(testCases, testCase{
5415 name: "Verify-ServerAuth-SignatureType-TLS13",
5416 config: Config{
5417 MaxVersion: VersionTLS13,
5418 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5419 SignSignatureAlgorithms: []signatureAlgorithm{
5420 signatureRSAPSSWithSHA256,
5421 },
5422 Bugs: ProtocolBugs{
5423 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5424 },
5425 },
5426 shouldFail: true,
5427 expectedError: ":WRONG_SIGNATURE_TYPE:",
5428 })
5429
David Benjamin51dd7d62016-07-08 16:07:01 -07005430 // Test that, if the list is missing, the peer falls back to SHA-1 in
5431 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005432 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005433 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005435 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005436 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005437 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005438 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005439 },
5440 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005441 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005442 },
5443 },
5444 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005445 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5446 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005447 },
5448 })
5449
5450 testCases = append(testCases, testCase{
5451 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005452 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005454 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005455 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005456 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005457 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005458 },
5459 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005460 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005461 },
5462 },
5463 })
David Benjamin72dc7832015-03-16 17:49:43 -04005464
David Benjamin51dd7d62016-07-08 16:07:01 -07005465 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005466 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005467 config: Config{
5468 MaxVersion: VersionTLS13,
5469 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005470 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005471 signatureRSAPKCS1WithSHA1,
5472 },
5473 Bugs: ProtocolBugs{
5474 NoSignatureAlgorithms: true,
5475 },
5476 },
5477 flags: []string{
5478 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5479 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5480 },
5481 shouldFail: true,
5482 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5483 })
5484
5485 testCases = append(testCases, testCase{
5486 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005487 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005488 config: Config{
5489 MaxVersion: VersionTLS13,
5490 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005491 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005492 signatureRSAPKCS1WithSHA1,
5493 },
5494 Bugs: ProtocolBugs{
5495 NoSignatureAlgorithms: true,
5496 },
5497 },
5498 shouldFail: true,
5499 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5500 })
5501
David Benjaminb62d2872016-07-18 14:55:02 +02005502 // Test that hash preferences are enforced. BoringSSL does not implement
5503 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005504 testCases = append(testCases, testCase{
5505 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005506 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005507 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005508 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005509 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005510 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005511 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005512 },
5513 Bugs: ProtocolBugs{
5514 IgnorePeerSignatureAlgorithmPreferences: true,
5515 },
5516 },
5517 flags: []string{"-require-any-client-certificate"},
5518 shouldFail: true,
5519 expectedError: ":WRONG_SIGNATURE_TYPE:",
5520 })
5521
5522 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005523 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005524 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005525 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005526 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005527 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005528 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005529 },
5530 Bugs: ProtocolBugs{
5531 IgnorePeerSignatureAlgorithmPreferences: true,
5532 },
5533 },
5534 shouldFail: true,
5535 expectedError: ":WRONG_SIGNATURE_TYPE:",
5536 })
David Benjaminb62d2872016-07-18 14:55:02 +02005537 testCases = append(testCases, testCase{
5538 testType: serverTest,
5539 name: "ClientAuth-Enforced-TLS13",
5540 config: Config{
5541 MaxVersion: VersionTLS13,
5542 Certificates: []Certificate{rsaCertificate},
5543 SignSignatureAlgorithms: []signatureAlgorithm{
5544 signatureRSAPKCS1WithMD5,
5545 },
5546 Bugs: ProtocolBugs{
5547 IgnorePeerSignatureAlgorithmPreferences: true,
5548 IgnoreSignatureVersionChecks: true,
5549 },
5550 },
5551 flags: []string{"-require-any-client-certificate"},
5552 shouldFail: true,
5553 expectedError: ":WRONG_SIGNATURE_TYPE:",
5554 })
5555
5556 testCases = append(testCases, testCase{
5557 name: "ServerAuth-Enforced-TLS13",
5558 config: Config{
5559 MaxVersion: VersionTLS13,
5560 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5561 SignSignatureAlgorithms: []signatureAlgorithm{
5562 signatureRSAPKCS1WithMD5,
5563 },
5564 Bugs: ProtocolBugs{
5565 IgnorePeerSignatureAlgorithmPreferences: true,
5566 IgnoreSignatureVersionChecks: true,
5567 },
5568 },
5569 shouldFail: true,
5570 expectedError: ":WRONG_SIGNATURE_TYPE:",
5571 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005572
5573 // Test that the agreed upon digest respects the client preferences and
5574 // the server digests.
5575 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005576 name: "NoCommonAlgorithms-Digests",
5577 config: Config{
5578 MaxVersion: VersionTLS12,
5579 ClientAuth: RequireAnyClientCert,
5580 VerifySignatureAlgorithms: []signatureAlgorithm{
5581 signatureRSAPKCS1WithSHA512,
5582 signatureRSAPKCS1WithSHA1,
5583 },
5584 },
5585 flags: []string{
5586 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5587 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5588 "-digest-prefs", "SHA256",
5589 },
5590 shouldFail: true,
5591 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5592 })
5593 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005594 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005596 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005597 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005598 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005599 signatureRSAPKCS1WithSHA512,
5600 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005601 },
5602 },
5603 flags: []string{
5604 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5605 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005606 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005607 },
David Benjaminca3d5452016-07-14 12:51:01 -04005608 shouldFail: true,
5609 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5610 })
5611 testCases = append(testCases, testCase{
5612 name: "NoCommonAlgorithms-TLS13",
5613 config: Config{
5614 MaxVersion: VersionTLS13,
5615 ClientAuth: RequireAnyClientCert,
5616 VerifySignatureAlgorithms: []signatureAlgorithm{
5617 signatureRSAPSSWithSHA512,
5618 signatureRSAPSSWithSHA384,
5619 },
5620 },
5621 flags: []string{
5622 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5623 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5624 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5625 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005626 shouldFail: true,
5627 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005628 })
5629 testCases = append(testCases, testCase{
5630 name: "Agree-Digest-SHA256",
5631 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005632 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005633 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005634 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005635 signatureRSAPKCS1WithSHA1,
5636 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005637 },
5638 },
5639 flags: []string{
5640 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5641 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005642 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005643 },
Nick Harper60edffd2016-06-21 15:19:24 -07005644 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005645 })
5646 testCases = append(testCases, testCase{
5647 name: "Agree-Digest-SHA1",
5648 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005649 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005650 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005651 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005652 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005653 },
5654 },
5655 flags: []string{
5656 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5657 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005658 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005659 },
Nick Harper60edffd2016-06-21 15:19:24 -07005660 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005661 })
5662 testCases = append(testCases, testCase{
5663 name: "Agree-Digest-Default",
5664 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005665 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005666 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005667 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005668 signatureRSAPKCS1WithSHA256,
5669 signatureECDSAWithP256AndSHA256,
5670 signatureRSAPKCS1WithSHA1,
5671 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005672 },
5673 },
5674 flags: []string{
5675 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5676 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5677 },
Nick Harper60edffd2016-06-21 15:19:24 -07005678 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005679 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005680
David Benjaminca3d5452016-07-14 12:51:01 -04005681 // Test that the signing preference list may include extra algorithms
5682 // without negotiation problems.
5683 testCases = append(testCases, testCase{
5684 testType: serverTest,
5685 name: "FilterExtraAlgorithms",
5686 config: Config{
5687 MaxVersion: VersionTLS12,
5688 VerifySignatureAlgorithms: []signatureAlgorithm{
5689 signatureRSAPKCS1WithSHA256,
5690 },
5691 },
5692 flags: []string{
5693 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5694 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5695 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5696 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5697 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5698 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5699 },
5700 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5701 })
5702
David Benjamin4c3ddf72016-06-29 18:13:53 -04005703 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5704 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005705 testCases = append(testCases, testCase{
5706 name: "CheckLeafCurve",
5707 config: Config{
5708 MaxVersion: VersionTLS12,
5709 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005710 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005711 },
5712 flags: []string{"-p384-only"},
5713 shouldFail: true,
5714 expectedError: ":BAD_ECC_CERT:",
5715 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005716
5717 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5718 testCases = append(testCases, testCase{
5719 name: "CheckLeafCurve-TLS13",
5720 config: Config{
5721 MaxVersion: VersionTLS13,
5722 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5723 Certificates: []Certificate{ecdsaP256Certificate},
5724 },
5725 flags: []string{"-p384-only"},
5726 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005727
5728 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5729 testCases = append(testCases, testCase{
5730 name: "ECDSACurveMismatch-Verify-TLS12",
5731 config: Config{
5732 MaxVersion: VersionTLS12,
5733 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5734 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005735 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005736 signatureECDSAWithP384AndSHA384,
5737 },
5738 },
5739 })
5740
5741 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5742 testCases = append(testCases, testCase{
5743 name: "ECDSACurveMismatch-Verify-TLS13",
5744 config: Config{
5745 MaxVersion: VersionTLS13,
5746 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5747 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005748 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005749 signatureECDSAWithP384AndSHA384,
5750 },
5751 Bugs: ProtocolBugs{
5752 SkipECDSACurveCheck: true,
5753 },
5754 },
5755 shouldFail: true,
5756 expectedError: ":WRONG_SIGNATURE_TYPE:",
5757 })
5758
5759 // Signature algorithm selection in TLS 1.3 should take the curve into
5760 // account.
5761 testCases = append(testCases, testCase{
5762 testType: serverTest,
5763 name: "ECDSACurveMismatch-Sign-TLS13",
5764 config: Config{
5765 MaxVersion: VersionTLS13,
5766 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005767 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005768 signatureECDSAWithP384AndSHA384,
5769 signatureECDSAWithP256AndSHA256,
5770 },
5771 },
5772 flags: []string{
5773 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5774 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5775 },
5776 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5777 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005778
5779 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5780 // server does not attempt to sign in that case.
5781 testCases = append(testCases, testCase{
5782 testType: serverTest,
5783 name: "RSA-PSS-Large",
5784 config: Config{
5785 MaxVersion: VersionTLS13,
5786 VerifySignatureAlgorithms: []signatureAlgorithm{
5787 signatureRSAPSSWithSHA512,
5788 },
5789 },
5790 flags: []string{
5791 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5792 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5793 },
5794 shouldFail: true,
5795 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5796 })
David Benjamin000800a2014-11-14 01:43:59 -05005797}
5798
David Benjamin83f90402015-01-27 01:09:43 -05005799// timeouts is the retransmit schedule for BoringSSL. It doubles and
5800// caps at 60 seconds. On the 13th timeout, it gives up.
5801var timeouts = []time.Duration{
5802 1 * time.Second,
5803 2 * time.Second,
5804 4 * time.Second,
5805 8 * time.Second,
5806 16 * time.Second,
5807 32 * time.Second,
5808 60 * time.Second,
5809 60 * time.Second,
5810 60 * time.Second,
5811 60 * time.Second,
5812 60 * time.Second,
5813 60 * time.Second,
5814 60 * time.Second,
5815}
5816
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005817// shortTimeouts is an alternate set of timeouts which would occur if the
5818// initial timeout duration was set to 250ms.
5819var shortTimeouts = []time.Duration{
5820 250 * time.Millisecond,
5821 500 * time.Millisecond,
5822 1 * time.Second,
5823 2 * time.Second,
5824 4 * time.Second,
5825 8 * time.Second,
5826 16 * time.Second,
5827 32 * time.Second,
5828 60 * time.Second,
5829 60 * time.Second,
5830 60 * time.Second,
5831 60 * time.Second,
5832 60 * time.Second,
5833}
5834
David Benjamin83f90402015-01-27 01:09:43 -05005835func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005836 // These tests work by coordinating some behavior on both the shim and
5837 // the runner.
5838 //
5839 // TimeoutSchedule configures the runner to send a series of timeout
5840 // opcodes to the shim (see packetAdaptor) immediately before reading
5841 // each peer handshake flight N. The timeout opcode both simulates a
5842 // timeout in the shim and acts as a synchronization point to help the
5843 // runner bracket each handshake flight.
5844 //
5845 // We assume the shim does not read from the channel eagerly. It must
5846 // first wait until it has sent flight N and is ready to receive
5847 // handshake flight N+1. At this point, it will process the timeout
5848 // opcode. It must then immediately respond with a timeout ACK and act
5849 // as if the shim was idle for the specified amount of time.
5850 //
5851 // The runner then drops all packets received before the ACK and
5852 // continues waiting for flight N. This ordering results in one attempt
5853 // at sending flight N to be dropped. For the test to complete, the
5854 // shim must send flight N again, testing that the shim implements DTLS
5855 // retransmit on a timeout.
5856
Steven Valdez143e8b32016-07-11 13:19:03 -04005857 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04005858 // likely be more epochs to cross and the final message's retransmit may
5859 // be more complex.
5860
David Benjamin585d7a42016-06-02 14:58:00 -04005861 for _, async := range []bool{true, false} {
5862 var tests []testCase
5863
5864 // Test that this is indeed the timeout schedule. Stress all
5865 // four patterns of handshake.
5866 for i := 1; i < len(timeouts); i++ {
5867 number := strconv.Itoa(i)
5868 tests = append(tests, testCase{
5869 protocol: dtls,
5870 name: "DTLS-Retransmit-Client-" + number,
5871 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005872 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005873 Bugs: ProtocolBugs{
5874 TimeoutSchedule: timeouts[:i],
5875 },
5876 },
5877 resumeSession: true,
5878 })
5879 tests = append(tests, testCase{
5880 protocol: dtls,
5881 testType: serverTest,
5882 name: "DTLS-Retransmit-Server-" + number,
5883 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005884 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005885 Bugs: ProtocolBugs{
5886 TimeoutSchedule: timeouts[:i],
5887 },
5888 },
5889 resumeSession: true,
5890 })
5891 }
5892
5893 // Test that exceeding the timeout schedule hits a read
5894 // timeout.
5895 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005896 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005897 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005899 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005900 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005901 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005902 },
5903 },
5904 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005905 shouldFail: true,
5906 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005907 })
David Benjamin585d7a42016-06-02 14:58:00 -04005908
5909 if async {
5910 // Test that timeout handling has a fudge factor, due to API
5911 // problems.
5912 tests = append(tests, testCase{
5913 protocol: dtls,
5914 name: "DTLS-Retransmit-Fudge",
5915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005916 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005917 Bugs: ProtocolBugs{
5918 TimeoutSchedule: []time.Duration{
5919 timeouts[0] - 10*time.Millisecond,
5920 },
5921 },
5922 },
5923 resumeSession: true,
5924 })
5925 }
5926
5927 // Test that the final Finished retransmitting isn't
5928 // duplicated if the peer badly fragments everything.
5929 tests = append(tests, testCase{
5930 testType: serverTest,
5931 protocol: dtls,
5932 name: "DTLS-Retransmit-Fragmented",
5933 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005934 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005935 Bugs: ProtocolBugs{
5936 TimeoutSchedule: []time.Duration{timeouts[0]},
5937 MaxHandshakeRecordLength: 2,
5938 },
5939 },
5940 })
5941
5942 // Test the timeout schedule when a shorter initial timeout duration is set.
5943 tests = append(tests, testCase{
5944 protocol: dtls,
5945 name: "DTLS-Retransmit-Short-Client",
5946 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005947 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005948 Bugs: ProtocolBugs{
5949 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5950 },
5951 },
5952 resumeSession: true,
5953 flags: []string{"-initial-timeout-duration-ms", "250"},
5954 })
5955 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005956 protocol: dtls,
5957 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005958 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005959 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005960 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005961 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005962 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005963 },
5964 },
5965 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005966 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005967 })
David Benjamin585d7a42016-06-02 14:58:00 -04005968
5969 for _, test := range tests {
5970 if async {
5971 test.name += "-Async"
5972 test.flags = append(test.flags, "-async")
5973 }
5974
5975 testCases = append(testCases, test)
5976 }
David Benjamin83f90402015-01-27 01:09:43 -05005977 }
David Benjamin83f90402015-01-27 01:09:43 -05005978}
5979
David Benjaminc565ebb2015-04-03 04:06:36 -04005980func addExportKeyingMaterialTests() {
5981 for _, vers := range tlsVersions {
5982 if vers.version == VersionSSL30 {
5983 continue
5984 }
5985 testCases = append(testCases, testCase{
5986 name: "ExportKeyingMaterial-" + vers.name,
5987 config: Config{
5988 MaxVersion: vers.version,
5989 },
5990 exportKeyingMaterial: 1024,
5991 exportLabel: "label",
5992 exportContext: "context",
5993 useExportContext: true,
5994 })
5995 testCases = append(testCases, testCase{
5996 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5997 config: Config{
5998 MaxVersion: vers.version,
5999 },
6000 exportKeyingMaterial: 1024,
6001 })
6002 testCases = append(testCases, testCase{
6003 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6004 config: Config{
6005 MaxVersion: vers.version,
6006 },
6007 exportKeyingMaterial: 1024,
6008 useExportContext: true,
6009 })
6010 testCases = append(testCases, testCase{
6011 name: "ExportKeyingMaterial-Small-" + vers.name,
6012 config: Config{
6013 MaxVersion: vers.version,
6014 },
6015 exportKeyingMaterial: 1,
6016 exportLabel: "label",
6017 exportContext: "context",
6018 useExportContext: true,
6019 })
6020 }
6021 testCases = append(testCases, testCase{
6022 name: "ExportKeyingMaterial-SSL3",
6023 config: Config{
6024 MaxVersion: VersionSSL30,
6025 },
6026 exportKeyingMaterial: 1024,
6027 exportLabel: "label",
6028 exportContext: "context",
6029 useExportContext: true,
6030 shouldFail: true,
6031 expectedError: "failed to export keying material",
6032 })
6033}
6034
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006035func addTLSUniqueTests() {
6036 for _, isClient := range []bool{false, true} {
6037 for _, isResumption := range []bool{false, true} {
6038 for _, hasEMS := range []bool{false, true} {
6039 var suffix string
6040 if isResumption {
6041 suffix = "Resume-"
6042 } else {
6043 suffix = "Full-"
6044 }
6045
6046 if hasEMS {
6047 suffix += "EMS-"
6048 } else {
6049 suffix += "NoEMS-"
6050 }
6051
6052 if isClient {
6053 suffix += "Client"
6054 } else {
6055 suffix += "Server"
6056 }
6057
6058 test := testCase{
6059 name: "TLSUnique-" + suffix,
6060 testTLSUnique: true,
6061 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006062 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006063 Bugs: ProtocolBugs{
6064 NoExtendedMasterSecret: !hasEMS,
6065 },
6066 },
6067 }
6068
6069 if isResumption {
6070 test.resumeSession = true
6071 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006072 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006073 Bugs: ProtocolBugs{
6074 NoExtendedMasterSecret: !hasEMS,
6075 },
6076 }
6077 }
6078
6079 if isResumption && !hasEMS {
6080 test.shouldFail = true
6081 test.expectedError = "failed to get tls-unique"
6082 }
6083
6084 testCases = append(testCases, test)
6085 }
6086 }
6087 }
6088}
6089
Adam Langley09505632015-07-30 18:10:13 -07006090func addCustomExtensionTests() {
6091 expectedContents := "custom extension"
6092 emptyString := ""
6093
6094 for _, isClient := range []bool{false, true} {
6095 suffix := "Server"
6096 flag := "-enable-server-custom-extension"
6097 testType := serverTest
6098 if isClient {
6099 suffix = "Client"
6100 flag = "-enable-client-custom-extension"
6101 testType = clientTest
6102 }
6103
6104 testCases = append(testCases, testCase{
6105 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006106 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006108 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006109 Bugs: ProtocolBugs{
6110 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006111 ExpectedCustomExtension: &expectedContents,
6112 },
6113 },
6114 flags: []string{flag},
6115 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006116 testCases = append(testCases, testCase{
6117 testType: testType,
6118 name: "CustomExtensions-" + suffix + "-TLS13",
6119 config: Config{
6120 MaxVersion: VersionTLS13,
6121 Bugs: ProtocolBugs{
6122 CustomExtension: expectedContents,
6123 ExpectedCustomExtension: &expectedContents,
6124 },
6125 },
6126 flags: []string{flag},
6127 })
Adam Langley09505632015-07-30 18:10:13 -07006128
6129 // If the parse callback fails, the handshake should also fail.
6130 testCases = append(testCases, testCase{
6131 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006132 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006133 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006134 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006135 Bugs: ProtocolBugs{
6136 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006137 ExpectedCustomExtension: &expectedContents,
6138 },
6139 },
David Benjamin399e7c92015-07-30 23:01:27 -04006140 flags: []string{flag},
6141 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006142 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6143 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006144 testCases = append(testCases, testCase{
6145 testType: testType,
6146 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6147 config: Config{
6148 MaxVersion: VersionTLS13,
6149 Bugs: ProtocolBugs{
6150 CustomExtension: expectedContents + "foo",
6151 ExpectedCustomExtension: &expectedContents,
6152 },
6153 },
6154 flags: []string{flag},
6155 shouldFail: true,
6156 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6157 })
Adam Langley09505632015-07-30 18:10:13 -07006158
6159 // If the add callback fails, the handshake should also fail.
6160 testCases = append(testCases, testCase{
6161 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006162 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006163 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006164 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006165 Bugs: ProtocolBugs{
6166 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006167 ExpectedCustomExtension: &expectedContents,
6168 },
6169 },
David Benjamin399e7c92015-07-30 23:01:27 -04006170 flags: []string{flag, "-custom-extension-fail-add"},
6171 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006172 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6173 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006174 testCases = append(testCases, testCase{
6175 testType: testType,
6176 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6177 config: Config{
6178 MaxVersion: VersionTLS13,
6179 Bugs: ProtocolBugs{
6180 CustomExtension: expectedContents,
6181 ExpectedCustomExtension: &expectedContents,
6182 },
6183 },
6184 flags: []string{flag, "-custom-extension-fail-add"},
6185 shouldFail: true,
6186 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6187 })
Adam Langley09505632015-07-30 18:10:13 -07006188
6189 // If the add callback returns zero, no extension should be
6190 // added.
6191 skipCustomExtension := expectedContents
6192 if isClient {
6193 // For the case where the client skips sending the
6194 // custom extension, the server must not “echo” it.
6195 skipCustomExtension = ""
6196 }
6197 testCases = append(testCases, testCase{
6198 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006199 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006201 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006202 Bugs: ProtocolBugs{
6203 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006204 ExpectedCustomExtension: &emptyString,
6205 },
6206 },
6207 flags: []string{flag, "-custom-extension-skip"},
6208 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006209 testCases = append(testCases, testCase{
6210 testType: testType,
6211 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6212 config: Config{
6213 MaxVersion: VersionTLS13,
6214 Bugs: ProtocolBugs{
6215 CustomExtension: skipCustomExtension,
6216 ExpectedCustomExtension: &emptyString,
6217 },
6218 },
6219 flags: []string{flag, "-custom-extension-skip"},
6220 })
Adam Langley09505632015-07-30 18:10:13 -07006221 }
6222
6223 // The custom extension add callback should not be called if the client
6224 // doesn't send the extension.
6225 testCases = append(testCases, testCase{
6226 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006227 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006229 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006230 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006231 ExpectedCustomExtension: &emptyString,
6232 },
6233 },
6234 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6235 })
Adam Langley2deb9842015-08-07 11:15:37 -07006236
Steven Valdez143e8b32016-07-11 13:19:03 -04006237 testCases = append(testCases, testCase{
6238 testType: serverTest,
6239 name: "CustomExtensions-NotCalled-Server-TLS13",
6240 config: Config{
6241 MaxVersion: VersionTLS13,
6242 Bugs: ProtocolBugs{
6243 ExpectedCustomExtension: &emptyString,
6244 },
6245 },
6246 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6247 })
6248
Adam Langley2deb9842015-08-07 11:15:37 -07006249 // Test an unknown extension from the server.
6250 testCases = append(testCases, testCase{
6251 testType: clientTest,
6252 name: "UnknownExtension-Client",
6253 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006254 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006255 Bugs: ProtocolBugs{
6256 CustomExtension: expectedContents,
6257 },
6258 },
6259 shouldFail: true,
6260 expectedError: ":UNEXPECTED_EXTENSION:",
6261 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006262 testCases = append(testCases, testCase{
6263 testType: clientTest,
6264 name: "UnknownExtension-Client-TLS13",
6265 config: Config{
6266 MaxVersion: VersionTLS13,
6267 Bugs: ProtocolBugs{
6268 CustomExtension: expectedContents,
6269 },
6270 },
6271 shouldFail: true,
6272 expectedError: ":UNEXPECTED_EXTENSION:",
6273 })
Adam Langley09505632015-07-30 18:10:13 -07006274}
6275
David Benjaminb36a3952015-12-01 18:53:13 -05006276func addRSAClientKeyExchangeTests() {
6277 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6278 testCases = append(testCases, testCase{
6279 testType: serverTest,
6280 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6281 config: Config{
6282 // Ensure the ClientHello version and final
6283 // version are different, to detect if the
6284 // server uses the wrong one.
6285 MaxVersion: VersionTLS11,
6286 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6287 Bugs: ProtocolBugs{
6288 BadRSAClientKeyExchange: bad,
6289 },
6290 },
6291 shouldFail: true,
6292 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6293 })
6294 }
6295}
6296
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006297var testCurves = []struct {
6298 name string
6299 id CurveID
6300}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006301 {"P-256", CurveP256},
6302 {"P-384", CurveP384},
6303 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006304 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006305}
6306
6307func addCurveTests() {
6308 for _, curve := range testCurves {
6309 testCases = append(testCases, testCase{
6310 name: "CurveTest-Client-" + curve.name,
6311 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006312 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006313 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6314 CurvePreferences: []CurveID{curve.id},
6315 },
6316 flags: []string{"-enable-all-curves"},
6317 })
6318 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006319 name: "CurveTest-Client-" + curve.name + "-TLS13",
6320 config: Config{
6321 MaxVersion: VersionTLS13,
6322 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6323 CurvePreferences: []CurveID{curve.id},
6324 },
6325 flags: []string{"-enable-all-curves"},
6326 })
6327 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006328 testType: serverTest,
6329 name: "CurveTest-Server-" + curve.name,
6330 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006331 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006332 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6333 CurvePreferences: []CurveID{curve.id},
6334 },
6335 flags: []string{"-enable-all-curves"},
6336 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006337 testCases = append(testCases, testCase{
6338 testType: serverTest,
6339 name: "CurveTest-Server-" + curve.name + "-TLS13",
6340 config: Config{
6341 MaxVersion: VersionTLS13,
6342 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6343 CurvePreferences: []CurveID{curve.id},
6344 },
6345 flags: []string{"-enable-all-curves"},
6346 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006347 }
David Benjamin241ae832016-01-15 03:04:54 -05006348
6349 // The server must be tolerant to bogus curves.
6350 const bogusCurve = 0x1234
6351 testCases = append(testCases, testCase{
6352 testType: serverTest,
6353 name: "UnknownCurve",
6354 config: Config{
6355 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6356 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6357 },
6358 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006359
6360 // The server must not consider ECDHE ciphers when there are no
6361 // supported curves.
6362 testCases = append(testCases, testCase{
6363 testType: serverTest,
6364 name: "NoSupportedCurves",
6365 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006366 MaxVersion: VersionTLS12,
6367 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6368 Bugs: ProtocolBugs{
6369 NoSupportedCurves: true,
6370 },
6371 },
6372 shouldFail: true,
6373 expectedError: ":NO_SHARED_CIPHER:",
6374 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006375 testCases = append(testCases, testCase{
6376 testType: serverTest,
6377 name: "NoSupportedCurves-TLS13",
6378 config: Config{
6379 MaxVersion: VersionTLS13,
6380 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6381 Bugs: ProtocolBugs{
6382 NoSupportedCurves: true,
6383 },
6384 },
6385 shouldFail: true,
6386 expectedError: ":NO_SHARED_CIPHER:",
6387 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006388
6389 // The server must fall back to another cipher when there are no
6390 // supported curves.
6391 testCases = append(testCases, testCase{
6392 testType: serverTest,
6393 name: "NoCommonCurves",
6394 config: Config{
6395 MaxVersion: VersionTLS12,
6396 CipherSuites: []uint16{
6397 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6398 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6399 },
6400 CurvePreferences: []CurveID{CurveP224},
6401 },
6402 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6403 })
6404
6405 // The client must reject bogus curves and disabled curves.
6406 testCases = append(testCases, testCase{
6407 name: "BadECDHECurve",
6408 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006409 MaxVersion: VersionTLS12,
6410 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6411 Bugs: ProtocolBugs{
6412 SendCurve: bogusCurve,
6413 },
6414 },
6415 shouldFail: true,
6416 expectedError: ":WRONG_CURVE:",
6417 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006418 testCases = append(testCases, testCase{
6419 name: "BadECDHECurve-TLS13",
6420 config: Config{
6421 MaxVersion: VersionTLS13,
6422 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6423 Bugs: ProtocolBugs{
6424 SendCurve: bogusCurve,
6425 },
6426 },
6427 shouldFail: true,
6428 expectedError: ":WRONG_CURVE:",
6429 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006430
6431 testCases = append(testCases, testCase{
6432 name: "UnsupportedCurve",
6433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006434 MaxVersion: VersionTLS12,
6435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6436 CurvePreferences: []CurveID{CurveP256},
6437 Bugs: ProtocolBugs{
6438 IgnorePeerCurvePreferences: true,
6439 },
6440 },
6441 flags: []string{"-p384-only"},
6442 shouldFail: true,
6443 expectedError: ":WRONG_CURVE:",
6444 })
6445
David Benjamin4f921572016-07-17 14:20:10 +02006446 testCases = append(testCases, testCase{
6447 // TODO(davidben): Add a TLS 1.3 version where
6448 // HelloRetryRequest requests an unsupported curve.
6449 name: "UnsupportedCurve-ServerHello-TLS13",
6450 config: Config{
6451 MaxVersion: VersionTLS12,
6452 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6453 CurvePreferences: []CurveID{CurveP384},
6454 Bugs: ProtocolBugs{
6455 SendCurve: CurveP256,
6456 },
6457 },
6458 flags: []string{"-p384-only"},
6459 shouldFail: true,
6460 expectedError: ":WRONG_CURVE:",
6461 })
6462
David Benjamin4c3ddf72016-06-29 18:13:53 -04006463 // Test invalid curve points.
6464 testCases = append(testCases, testCase{
6465 name: "InvalidECDHPoint-Client",
6466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006467 MaxVersion: VersionTLS12,
6468 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6469 CurvePreferences: []CurveID{CurveP256},
6470 Bugs: ProtocolBugs{
6471 InvalidECDHPoint: true,
6472 },
6473 },
6474 shouldFail: true,
6475 expectedError: ":INVALID_ENCODING:",
6476 })
6477 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006478 name: "InvalidECDHPoint-Client-TLS13",
6479 config: Config{
6480 MaxVersion: VersionTLS13,
6481 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6482 CurvePreferences: []CurveID{CurveP256},
6483 Bugs: ProtocolBugs{
6484 InvalidECDHPoint: true,
6485 },
6486 },
6487 shouldFail: true,
6488 expectedError: ":INVALID_ENCODING:",
6489 })
6490 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006491 testType: serverTest,
6492 name: "InvalidECDHPoint-Server",
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 CurvePreferences: []CurveID{CurveP256},
6497 Bugs: ProtocolBugs{
6498 InvalidECDHPoint: true,
6499 },
6500 },
6501 shouldFail: true,
6502 expectedError: ":INVALID_ENCODING:",
6503 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006504 testCases = append(testCases, testCase{
6505 testType: serverTest,
6506 name: "InvalidECDHPoint-Server-TLS13",
6507 config: Config{
6508 MaxVersion: VersionTLS13,
6509 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6510 CurvePreferences: []CurveID{CurveP256},
6511 Bugs: ProtocolBugs{
6512 InvalidECDHPoint: true,
6513 },
6514 },
6515 shouldFail: true,
6516 expectedError: ":INVALID_ENCODING:",
6517 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006518}
6519
Matt Braithwaite54217e42016-06-13 13:03:47 -07006520func addCECPQ1Tests() {
6521 testCases = append(testCases, testCase{
6522 testType: clientTest,
6523 name: "CECPQ1-Client-BadX25519Part",
6524 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006525 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006526 MinVersion: VersionTLS12,
6527 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6528 Bugs: ProtocolBugs{
6529 CECPQ1BadX25519Part: true,
6530 },
6531 },
6532 flags: []string{"-cipher", "kCECPQ1"},
6533 shouldFail: true,
6534 expectedLocalError: "local error: bad record MAC",
6535 })
6536 testCases = append(testCases, testCase{
6537 testType: clientTest,
6538 name: "CECPQ1-Client-BadNewhopePart",
6539 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006540 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006541 MinVersion: VersionTLS12,
6542 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6543 Bugs: ProtocolBugs{
6544 CECPQ1BadNewhopePart: true,
6545 },
6546 },
6547 flags: []string{"-cipher", "kCECPQ1"},
6548 shouldFail: true,
6549 expectedLocalError: "local error: bad record MAC",
6550 })
6551 testCases = append(testCases, testCase{
6552 testType: serverTest,
6553 name: "CECPQ1-Server-BadX25519Part",
6554 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006555 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006556 MinVersion: VersionTLS12,
6557 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6558 Bugs: ProtocolBugs{
6559 CECPQ1BadX25519Part: true,
6560 },
6561 },
6562 flags: []string{"-cipher", "kCECPQ1"},
6563 shouldFail: true,
6564 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6565 })
6566 testCases = append(testCases, testCase{
6567 testType: serverTest,
6568 name: "CECPQ1-Server-BadNewhopePart",
6569 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006570 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006571 MinVersion: VersionTLS12,
6572 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6573 Bugs: ProtocolBugs{
6574 CECPQ1BadNewhopePart: true,
6575 },
6576 },
6577 flags: []string{"-cipher", "kCECPQ1"},
6578 shouldFail: true,
6579 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6580 })
6581}
6582
David Benjamin4cc36ad2015-12-19 14:23:26 -05006583func addKeyExchangeInfoTests() {
6584 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006585 name: "KeyExchangeInfo-DHE-Client",
6586 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006587 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006588 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6589 Bugs: ProtocolBugs{
6590 // This is a 1234-bit prime number, generated
6591 // with:
6592 // openssl gendh 1234 | openssl asn1parse -i
6593 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6594 },
6595 },
David Benjamin9e68f192016-06-30 14:55:33 -04006596 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006597 })
6598 testCases = append(testCases, testCase{
6599 testType: serverTest,
6600 name: "KeyExchangeInfo-DHE-Server",
6601 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006602 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006603 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6604 },
6605 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006606 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006607 })
6608
6609 testCases = append(testCases, testCase{
6610 name: "KeyExchangeInfo-ECDHE-Client",
6611 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006612 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006613 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6614 CurvePreferences: []CurveID{CurveX25519},
6615 },
David Benjamin9e68f192016-06-30 14:55:33 -04006616 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006617 })
6618 testCases = append(testCases, testCase{
6619 testType: serverTest,
6620 name: "KeyExchangeInfo-ECDHE-Server",
6621 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006622 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6624 CurvePreferences: []CurveID{CurveX25519},
6625 },
David Benjamin9e68f192016-06-30 14:55:33 -04006626 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006627 })
6628}
6629
David Benjaminc9ae27c2016-06-24 22:56:37 -04006630func addTLS13RecordTests() {
6631 testCases = append(testCases, testCase{
6632 name: "TLS13-RecordPadding",
6633 config: Config{
6634 MaxVersion: VersionTLS13,
6635 MinVersion: VersionTLS13,
6636 Bugs: ProtocolBugs{
6637 RecordPadding: 10,
6638 },
6639 },
6640 })
6641
6642 testCases = append(testCases, testCase{
6643 name: "TLS13-EmptyRecords",
6644 config: Config{
6645 MaxVersion: VersionTLS13,
6646 MinVersion: VersionTLS13,
6647 Bugs: ProtocolBugs{
6648 OmitRecordContents: true,
6649 },
6650 },
6651 shouldFail: true,
6652 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6653 })
6654
6655 testCases = append(testCases, testCase{
6656 name: "TLS13-OnlyPadding",
6657 config: Config{
6658 MaxVersion: VersionTLS13,
6659 MinVersion: VersionTLS13,
6660 Bugs: ProtocolBugs{
6661 OmitRecordContents: true,
6662 RecordPadding: 10,
6663 },
6664 },
6665 shouldFail: true,
6666 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6667 })
6668
6669 testCases = append(testCases, testCase{
6670 name: "TLS13-WrongOuterRecord",
6671 config: Config{
6672 MaxVersion: VersionTLS13,
6673 MinVersion: VersionTLS13,
6674 Bugs: ProtocolBugs{
6675 OuterRecordType: recordTypeHandshake,
6676 },
6677 },
6678 shouldFail: true,
6679 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6680 })
6681}
6682
David Benjamin82261be2016-07-07 14:32:50 -07006683func addChangeCipherSpecTests() {
6684 // Test missing ChangeCipherSpecs.
6685 testCases = append(testCases, testCase{
6686 name: "SkipChangeCipherSpec-Client",
6687 config: Config{
6688 MaxVersion: VersionTLS12,
6689 Bugs: ProtocolBugs{
6690 SkipChangeCipherSpec: true,
6691 },
6692 },
6693 shouldFail: true,
6694 expectedError: ":UNEXPECTED_RECORD:",
6695 })
6696 testCases = append(testCases, testCase{
6697 testType: serverTest,
6698 name: "SkipChangeCipherSpec-Server",
6699 config: Config{
6700 MaxVersion: VersionTLS12,
6701 Bugs: ProtocolBugs{
6702 SkipChangeCipherSpec: true,
6703 },
6704 },
6705 shouldFail: true,
6706 expectedError: ":UNEXPECTED_RECORD:",
6707 })
6708 testCases = append(testCases, testCase{
6709 testType: serverTest,
6710 name: "SkipChangeCipherSpec-Server-NPN",
6711 config: Config{
6712 MaxVersion: VersionTLS12,
6713 NextProtos: []string{"bar"},
6714 Bugs: ProtocolBugs{
6715 SkipChangeCipherSpec: true,
6716 },
6717 },
6718 flags: []string{
6719 "-advertise-npn", "\x03foo\x03bar\x03baz",
6720 },
6721 shouldFail: true,
6722 expectedError: ":UNEXPECTED_RECORD:",
6723 })
6724
6725 // Test synchronization between the handshake and ChangeCipherSpec.
6726 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6727 // rejected. Test both with and without handshake packing to handle both
6728 // when the partial post-CCS message is in its own record and when it is
6729 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006730 for _, packed := range []bool{false, true} {
6731 var suffix string
6732 if packed {
6733 suffix = "-Packed"
6734 }
6735
6736 testCases = append(testCases, testCase{
6737 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6738 config: Config{
6739 MaxVersion: VersionTLS12,
6740 Bugs: ProtocolBugs{
6741 FragmentAcrossChangeCipherSpec: true,
6742 PackHandshakeFlight: packed,
6743 },
6744 },
6745 shouldFail: true,
6746 expectedError: ":UNEXPECTED_RECORD:",
6747 })
6748 testCases = append(testCases, testCase{
6749 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6750 config: Config{
6751 MaxVersion: VersionTLS12,
6752 },
6753 resumeSession: true,
6754 resumeConfig: &Config{
6755 MaxVersion: VersionTLS12,
6756 Bugs: ProtocolBugs{
6757 FragmentAcrossChangeCipherSpec: true,
6758 PackHandshakeFlight: packed,
6759 },
6760 },
6761 shouldFail: true,
6762 expectedError: ":UNEXPECTED_RECORD:",
6763 })
6764 testCases = append(testCases, testCase{
6765 testType: serverTest,
6766 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6767 config: Config{
6768 MaxVersion: VersionTLS12,
6769 Bugs: ProtocolBugs{
6770 FragmentAcrossChangeCipherSpec: true,
6771 PackHandshakeFlight: packed,
6772 },
6773 },
6774 shouldFail: true,
6775 expectedError: ":UNEXPECTED_RECORD:",
6776 })
6777 testCases = append(testCases, testCase{
6778 testType: serverTest,
6779 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6780 config: Config{
6781 MaxVersion: VersionTLS12,
6782 },
6783 resumeSession: true,
6784 resumeConfig: &Config{
6785 MaxVersion: VersionTLS12,
6786 Bugs: ProtocolBugs{
6787 FragmentAcrossChangeCipherSpec: true,
6788 PackHandshakeFlight: packed,
6789 },
6790 },
6791 shouldFail: true,
6792 expectedError: ":UNEXPECTED_RECORD:",
6793 })
6794 testCases = append(testCases, testCase{
6795 testType: serverTest,
6796 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6797 config: Config{
6798 MaxVersion: VersionTLS12,
6799 NextProtos: []string{"bar"},
6800 Bugs: ProtocolBugs{
6801 FragmentAcrossChangeCipherSpec: true,
6802 PackHandshakeFlight: packed,
6803 },
6804 },
6805 flags: []string{
6806 "-advertise-npn", "\x03foo\x03bar\x03baz",
6807 },
6808 shouldFail: true,
6809 expectedError: ":UNEXPECTED_RECORD:",
6810 })
6811 }
6812
David Benjamin61672812016-07-14 23:10:43 -04006813 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6814 // messages in the handshake queue. Do this by testing the server
6815 // reading the client Finished, reversing the flight so Finished comes
6816 // first.
6817 testCases = append(testCases, testCase{
6818 protocol: dtls,
6819 testType: serverTest,
6820 name: "SendUnencryptedFinished-DTLS",
6821 config: Config{
6822 MaxVersion: VersionTLS12,
6823 Bugs: ProtocolBugs{
6824 SendUnencryptedFinished: true,
6825 ReverseHandshakeFragments: true,
6826 },
6827 },
6828 shouldFail: true,
6829 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6830 })
6831
Steven Valdez143e8b32016-07-11 13:19:03 -04006832 // Test synchronization between encryption changes and the handshake in
6833 // TLS 1.3, where ChangeCipherSpec is implicit.
6834 testCases = append(testCases, testCase{
6835 name: "PartialEncryptedExtensionsWithServerHello",
6836 config: Config{
6837 MaxVersion: VersionTLS13,
6838 Bugs: ProtocolBugs{
6839 PartialEncryptedExtensionsWithServerHello: true,
6840 },
6841 },
6842 shouldFail: true,
6843 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6844 })
6845 testCases = append(testCases, testCase{
6846 testType: serverTest,
6847 name: "PartialClientFinishedWithClientHello",
6848 config: Config{
6849 MaxVersion: VersionTLS13,
6850 Bugs: ProtocolBugs{
6851 PartialClientFinishedWithClientHello: true,
6852 },
6853 },
6854 shouldFail: true,
6855 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6856 })
6857
David Benjamin82261be2016-07-07 14:32:50 -07006858 // Test that early ChangeCipherSpecs are handled correctly.
6859 testCases = append(testCases, testCase{
6860 testType: serverTest,
6861 name: "EarlyChangeCipherSpec-server-1",
6862 config: Config{
6863 MaxVersion: VersionTLS12,
6864 Bugs: ProtocolBugs{
6865 EarlyChangeCipherSpec: 1,
6866 },
6867 },
6868 shouldFail: true,
6869 expectedError: ":UNEXPECTED_RECORD:",
6870 })
6871 testCases = append(testCases, testCase{
6872 testType: serverTest,
6873 name: "EarlyChangeCipherSpec-server-2",
6874 config: Config{
6875 MaxVersion: VersionTLS12,
6876 Bugs: ProtocolBugs{
6877 EarlyChangeCipherSpec: 2,
6878 },
6879 },
6880 shouldFail: true,
6881 expectedError: ":UNEXPECTED_RECORD:",
6882 })
6883 testCases = append(testCases, testCase{
6884 protocol: dtls,
6885 name: "StrayChangeCipherSpec",
6886 config: Config{
6887 // TODO(davidben): Once DTLS 1.3 exists, test
6888 // that stray ChangeCipherSpec messages are
6889 // rejected.
6890 MaxVersion: VersionTLS12,
6891 Bugs: ProtocolBugs{
6892 StrayChangeCipherSpec: true,
6893 },
6894 },
6895 })
6896
6897 // Test that the contents of ChangeCipherSpec are checked.
6898 testCases = append(testCases, testCase{
6899 name: "BadChangeCipherSpec-1",
6900 config: Config{
6901 MaxVersion: VersionTLS12,
6902 Bugs: ProtocolBugs{
6903 BadChangeCipherSpec: []byte{2},
6904 },
6905 },
6906 shouldFail: true,
6907 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6908 })
6909 testCases = append(testCases, testCase{
6910 name: "BadChangeCipherSpec-2",
6911 config: Config{
6912 MaxVersion: VersionTLS12,
6913 Bugs: ProtocolBugs{
6914 BadChangeCipherSpec: []byte{1, 1},
6915 },
6916 },
6917 shouldFail: true,
6918 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6919 })
6920 testCases = append(testCases, testCase{
6921 protocol: dtls,
6922 name: "BadChangeCipherSpec-DTLS-1",
6923 config: Config{
6924 MaxVersion: VersionTLS12,
6925 Bugs: ProtocolBugs{
6926 BadChangeCipherSpec: []byte{2},
6927 },
6928 },
6929 shouldFail: true,
6930 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6931 })
6932 testCases = append(testCases, testCase{
6933 protocol: dtls,
6934 name: "BadChangeCipherSpec-DTLS-2",
6935 config: Config{
6936 MaxVersion: VersionTLS12,
6937 Bugs: ProtocolBugs{
6938 BadChangeCipherSpec: []byte{1, 1},
6939 },
6940 },
6941 shouldFail: true,
6942 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6943 })
6944}
6945
David Benjamin0b8d5da2016-07-15 00:39:56 -04006946func addWrongMessageTypeTests() {
6947 for _, protocol := range []protocol{tls, dtls} {
6948 var suffix string
6949 if protocol == dtls {
6950 suffix = "-DTLS"
6951 }
6952
6953 testCases = append(testCases, testCase{
6954 protocol: protocol,
6955 testType: serverTest,
6956 name: "WrongMessageType-ClientHello" + suffix,
6957 config: Config{
6958 MaxVersion: VersionTLS12,
6959 Bugs: ProtocolBugs{
6960 SendWrongMessageType: typeClientHello,
6961 },
6962 },
6963 shouldFail: true,
6964 expectedError: ":UNEXPECTED_MESSAGE:",
6965 expectedLocalError: "remote error: unexpected message",
6966 })
6967
6968 if protocol == dtls {
6969 testCases = append(testCases, testCase{
6970 protocol: protocol,
6971 name: "WrongMessageType-HelloVerifyRequest" + suffix,
6972 config: Config{
6973 MaxVersion: VersionTLS12,
6974 Bugs: ProtocolBugs{
6975 SendWrongMessageType: typeHelloVerifyRequest,
6976 },
6977 },
6978 shouldFail: true,
6979 expectedError: ":UNEXPECTED_MESSAGE:",
6980 expectedLocalError: "remote error: unexpected message",
6981 })
6982 }
6983
6984 testCases = append(testCases, testCase{
6985 protocol: protocol,
6986 name: "WrongMessageType-ServerHello" + suffix,
6987 config: Config{
6988 MaxVersion: VersionTLS12,
6989 Bugs: ProtocolBugs{
6990 SendWrongMessageType: typeServerHello,
6991 },
6992 },
6993 shouldFail: true,
6994 expectedError: ":UNEXPECTED_MESSAGE:",
6995 expectedLocalError: "remote error: unexpected message",
6996 })
6997
6998 testCases = append(testCases, testCase{
6999 protocol: protocol,
7000 name: "WrongMessageType-ServerCertificate" + suffix,
7001 config: Config{
7002 MaxVersion: VersionTLS12,
7003 Bugs: ProtocolBugs{
7004 SendWrongMessageType: typeCertificate,
7005 },
7006 },
7007 shouldFail: true,
7008 expectedError: ":UNEXPECTED_MESSAGE:",
7009 expectedLocalError: "remote error: unexpected message",
7010 })
7011
7012 testCases = append(testCases, testCase{
7013 protocol: protocol,
7014 name: "WrongMessageType-CertificateStatus" + suffix,
7015 config: Config{
7016 MaxVersion: VersionTLS12,
7017 Bugs: ProtocolBugs{
7018 SendWrongMessageType: typeCertificateStatus,
7019 },
7020 },
7021 flags: []string{"-enable-ocsp-stapling"},
7022 shouldFail: true,
7023 expectedError: ":UNEXPECTED_MESSAGE:",
7024 expectedLocalError: "remote error: unexpected message",
7025 })
7026
7027 testCases = append(testCases, testCase{
7028 protocol: protocol,
7029 name: "WrongMessageType-ServerKeyExchange" + suffix,
7030 config: Config{
7031 MaxVersion: VersionTLS12,
7032 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7033 Bugs: ProtocolBugs{
7034 SendWrongMessageType: typeServerKeyExchange,
7035 },
7036 },
7037 shouldFail: true,
7038 expectedError: ":UNEXPECTED_MESSAGE:",
7039 expectedLocalError: "remote error: unexpected message",
7040 })
7041
7042 testCases = append(testCases, testCase{
7043 protocol: protocol,
7044 name: "WrongMessageType-CertificateRequest" + suffix,
7045 config: Config{
7046 MaxVersion: VersionTLS12,
7047 ClientAuth: RequireAnyClientCert,
7048 Bugs: ProtocolBugs{
7049 SendWrongMessageType: typeCertificateRequest,
7050 },
7051 },
7052 shouldFail: true,
7053 expectedError: ":UNEXPECTED_MESSAGE:",
7054 expectedLocalError: "remote error: unexpected message",
7055 })
7056
7057 testCases = append(testCases, testCase{
7058 protocol: protocol,
7059 name: "WrongMessageType-ServerHelloDone" + suffix,
7060 config: Config{
7061 MaxVersion: VersionTLS12,
7062 Bugs: ProtocolBugs{
7063 SendWrongMessageType: typeServerHelloDone,
7064 },
7065 },
7066 shouldFail: true,
7067 expectedError: ":UNEXPECTED_MESSAGE:",
7068 expectedLocalError: "remote error: unexpected message",
7069 })
7070
7071 testCases = append(testCases, testCase{
7072 testType: serverTest,
7073 protocol: protocol,
7074 name: "WrongMessageType-ClientCertificate" + suffix,
7075 config: Config{
7076 Certificates: []Certificate{rsaCertificate},
7077 MaxVersion: VersionTLS12,
7078 Bugs: ProtocolBugs{
7079 SendWrongMessageType: typeCertificate,
7080 },
7081 },
7082 flags: []string{"-require-any-client-certificate"},
7083 shouldFail: true,
7084 expectedError: ":UNEXPECTED_MESSAGE:",
7085 expectedLocalError: "remote error: unexpected message",
7086 })
7087
7088 testCases = append(testCases, testCase{
7089 testType: serverTest,
7090 protocol: protocol,
7091 name: "WrongMessageType-CertificateVerify" + suffix,
7092 config: Config{
7093 Certificates: []Certificate{rsaCertificate},
7094 MaxVersion: VersionTLS12,
7095 Bugs: ProtocolBugs{
7096 SendWrongMessageType: typeCertificateVerify,
7097 },
7098 },
7099 flags: []string{"-require-any-client-certificate"},
7100 shouldFail: true,
7101 expectedError: ":UNEXPECTED_MESSAGE:",
7102 expectedLocalError: "remote error: unexpected message",
7103 })
7104
7105 testCases = append(testCases, testCase{
7106 testType: serverTest,
7107 protocol: protocol,
7108 name: "WrongMessageType-ClientKeyExchange" + suffix,
7109 config: Config{
7110 MaxVersion: VersionTLS12,
7111 Bugs: ProtocolBugs{
7112 SendWrongMessageType: typeClientKeyExchange,
7113 },
7114 },
7115 shouldFail: true,
7116 expectedError: ":UNEXPECTED_MESSAGE:",
7117 expectedLocalError: "remote error: unexpected message",
7118 })
7119
7120 if protocol != dtls {
7121 testCases = append(testCases, testCase{
7122 testType: serverTest,
7123 protocol: protocol,
7124 name: "WrongMessageType-NextProtocol" + suffix,
7125 config: Config{
7126 MaxVersion: VersionTLS12,
7127 NextProtos: []string{"bar"},
7128 Bugs: ProtocolBugs{
7129 SendWrongMessageType: typeNextProtocol,
7130 },
7131 },
7132 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7133 shouldFail: true,
7134 expectedError: ":UNEXPECTED_MESSAGE:",
7135 expectedLocalError: "remote error: unexpected message",
7136 })
7137
7138 testCases = append(testCases, testCase{
7139 testType: serverTest,
7140 protocol: protocol,
7141 name: "WrongMessageType-ChannelID" + suffix,
7142 config: Config{
7143 MaxVersion: VersionTLS12,
7144 ChannelID: channelIDKey,
7145 Bugs: ProtocolBugs{
7146 SendWrongMessageType: typeChannelID,
7147 },
7148 },
7149 flags: []string{
7150 "-expect-channel-id",
7151 base64.StdEncoding.EncodeToString(channelIDBytes),
7152 },
7153 shouldFail: true,
7154 expectedError: ":UNEXPECTED_MESSAGE:",
7155 expectedLocalError: "remote error: unexpected message",
7156 })
7157 }
7158
7159 testCases = append(testCases, testCase{
7160 testType: serverTest,
7161 protocol: protocol,
7162 name: "WrongMessageType-ClientFinished" + suffix,
7163 config: Config{
7164 MaxVersion: VersionTLS12,
7165 Bugs: ProtocolBugs{
7166 SendWrongMessageType: typeFinished,
7167 },
7168 },
7169 shouldFail: true,
7170 expectedError: ":UNEXPECTED_MESSAGE:",
7171 expectedLocalError: "remote error: unexpected message",
7172 })
7173
7174 testCases = append(testCases, testCase{
7175 protocol: protocol,
7176 name: "WrongMessageType-NewSessionTicket" + suffix,
7177 config: Config{
7178 MaxVersion: VersionTLS12,
7179 Bugs: ProtocolBugs{
7180 SendWrongMessageType: typeNewSessionTicket,
7181 },
7182 },
7183 shouldFail: true,
7184 expectedError: ":UNEXPECTED_MESSAGE:",
7185 expectedLocalError: "remote error: unexpected message",
7186 })
7187
7188 testCases = append(testCases, testCase{
7189 protocol: protocol,
7190 name: "WrongMessageType-ServerFinished" + suffix,
7191 config: Config{
7192 MaxVersion: VersionTLS12,
7193 Bugs: ProtocolBugs{
7194 SendWrongMessageType: typeFinished,
7195 },
7196 },
7197 shouldFail: true,
7198 expectedError: ":UNEXPECTED_MESSAGE:",
7199 expectedLocalError: "remote error: unexpected message",
7200 })
7201
7202 }
7203}
7204
Steven Valdez143e8b32016-07-11 13:19:03 -04007205func addTLS13WrongMessageTypeTests() {
7206 testCases = append(testCases, testCase{
7207 testType: serverTest,
7208 name: "WrongMessageType-TLS13-ClientHello",
7209 config: Config{
7210 MaxVersion: VersionTLS13,
7211 Bugs: ProtocolBugs{
7212 SendWrongMessageType: typeClientHello,
7213 },
7214 },
7215 shouldFail: true,
7216 expectedError: ":UNEXPECTED_MESSAGE:",
7217 expectedLocalError: "remote error: unexpected message",
7218 })
7219
7220 testCases = append(testCases, testCase{
7221 name: "WrongMessageType-TLS13-ServerHello",
7222 config: Config{
7223 MaxVersion: VersionTLS13,
7224 Bugs: ProtocolBugs{
7225 SendWrongMessageType: typeServerHello,
7226 },
7227 },
7228 shouldFail: true,
7229 expectedError: ":UNEXPECTED_MESSAGE:",
7230 // The alert comes in with the wrong encryption.
7231 expectedLocalError: "local error: bad record MAC",
7232 })
7233
7234 testCases = append(testCases, testCase{
7235 name: "WrongMessageType-TLS13-EncryptedExtensions",
7236 config: Config{
7237 MaxVersion: VersionTLS13,
7238 Bugs: ProtocolBugs{
7239 SendWrongMessageType: typeEncryptedExtensions,
7240 },
7241 },
7242 shouldFail: true,
7243 expectedError: ":UNEXPECTED_MESSAGE:",
7244 expectedLocalError: "remote error: unexpected message",
7245 })
7246
7247 testCases = append(testCases, testCase{
7248 name: "WrongMessageType-TLS13-CertificateRequest",
7249 config: Config{
7250 MaxVersion: VersionTLS13,
7251 ClientAuth: RequireAnyClientCert,
7252 Bugs: ProtocolBugs{
7253 SendWrongMessageType: typeCertificateRequest,
7254 },
7255 },
7256 shouldFail: true,
7257 expectedError: ":UNEXPECTED_MESSAGE:",
7258 expectedLocalError: "remote error: unexpected message",
7259 })
7260
7261 testCases = append(testCases, testCase{
7262 name: "WrongMessageType-TLS13-ServerCertificate",
7263 config: Config{
7264 MaxVersion: VersionTLS13,
7265 Bugs: ProtocolBugs{
7266 SendWrongMessageType: typeCertificate,
7267 },
7268 },
7269 shouldFail: true,
7270 expectedError: ":UNEXPECTED_MESSAGE:",
7271 expectedLocalError: "remote error: unexpected message",
7272 })
7273
7274 testCases = append(testCases, testCase{
7275 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7276 config: Config{
7277 MaxVersion: VersionTLS13,
7278 Bugs: ProtocolBugs{
7279 SendWrongMessageType: typeCertificateVerify,
7280 },
7281 },
7282 shouldFail: true,
7283 expectedError: ":UNEXPECTED_MESSAGE:",
7284 expectedLocalError: "remote error: unexpected message",
7285 })
7286
7287 testCases = append(testCases, testCase{
7288 name: "WrongMessageType-TLS13-ServerFinished",
7289 config: Config{
7290 MaxVersion: VersionTLS13,
7291 Bugs: ProtocolBugs{
7292 SendWrongMessageType: typeFinished,
7293 },
7294 },
7295 shouldFail: true,
7296 expectedError: ":UNEXPECTED_MESSAGE:",
7297 expectedLocalError: "remote error: unexpected message",
7298 })
7299
7300 testCases = append(testCases, testCase{
7301 testType: serverTest,
7302 name: "WrongMessageType-TLS13-ClientCertificate",
7303 config: Config{
7304 Certificates: []Certificate{rsaCertificate},
7305 MaxVersion: VersionTLS13,
7306 Bugs: ProtocolBugs{
7307 SendWrongMessageType: typeCertificate,
7308 },
7309 },
7310 flags: []string{"-require-any-client-certificate"},
7311 shouldFail: true,
7312 expectedError: ":UNEXPECTED_MESSAGE:",
7313 expectedLocalError: "remote error: unexpected message",
7314 })
7315
7316 testCases = append(testCases, testCase{
7317 testType: serverTest,
7318 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7319 config: Config{
7320 Certificates: []Certificate{rsaCertificate},
7321 MaxVersion: VersionTLS13,
7322 Bugs: ProtocolBugs{
7323 SendWrongMessageType: typeCertificateVerify,
7324 },
7325 },
7326 flags: []string{"-require-any-client-certificate"},
7327 shouldFail: true,
7328 expectedError: ":UNEXPECTED_MESSAGE:",
7329 expectedLocalError: "remote error: unexpected message",
7330 })
7331
7332 testCases = append(testCases, testCase{
7333 testType: serverTest,
7334 name: "WrongMessageType-TLS13-ClientFinished",
7335 config: Config{
7336 MaxVersion: VersionTLS13,
7337 Bugs: ProtocolBugs{
7338 SendWrongMessageType: typeFinished,
7339 },
7340 },
7341 shouldFail: true,
7342 expectedError: ":UNEXPECTED_MESSAGE:",
7343 expectedLocalError: "remote error: unexpected message",
7344 })
7345}
7346
7347func addTLS13HandshakeTests() {
7348 testCases = append(testCases, testCase{
7349 testType: clientTest,
7350 name: "MissingKeyShare-Client",
7351 config: Config{
7352 MaxVersion: VersionTLS13,
7353 Bugs: ProtocolBugs{
7354 MissingKeyShare: true,
7355 },
7356 },
7357 shouldFail: true,
7358 expectedError: ":MISSING_KEY_SHARE:",
7359 })
7360
7361 testCases = append(testCases, testCase{
7362 name: "MissingKeyShare-Server",
7363 config: Config{
7364 MaxVersion: VersionTLS13,
7365 Bugs: ProtocolBugs{
7366 MissingKeyShare: true,
7367 },
7368 },
7369 shouldFail: true,
7370 expectedError: ":MISSING_KEY_SHARE:",
7371 })
7372
7373 testCases = append(testCases, testCase{
7374 testType: clientTest,
7375 name: "ClientHelloMissingKeyShare",
7376 config: Config{
7377 MaxVersion: VersionTLS13,
7378 Bugs: ProtocolBugs{
7379 MissingKeyShare: true,
7380 },
7381 },
7382 shouldFail: true,
7383 expectedError: ":MISSING_KEY_SHARE:",
7384 })
7385
7386 testCases = append(testCases, testCase{
7387 testType: clientTest,
7388 name: "MissingKeyShare",
7389 config: Config{
7390 MaxVersion: VersionTLS13,
7391 Bugs: ProtocolBugs{
7392 MissingKeyShare: true,
7393 },
7394 },
7395 shouldFail: true,
7396 expectedError: ":MISSING_KEY_SHARE:",
7397 })
7398
7399 testCases = append(testCases, testCase{
7400 testType: serverTest,
7401 name: "DuplicateKeyShares",
7402 config: Config{
7403 MaxVersion: VersionTLS13,
7404 Bugs: ProtocolBugs{
7405 DuplicateKeyShares: true,
7406 },
7407 },
7408 })
7409
7410 testCases = append(testCases, testCase{
7411 testType: clientTest,
7412 name: "EmptyEncryptedExtensions",
7413 config: Config{
7414 MaxVersion: VersionTLS13,
7415 Bugs: ProtocolBugs{
7416 EmptyEncryptedExtensions: true,
7417 },
7418 },
7419 shouldFail: true,
7420 expectedLocalError: "remote error: error decoding message",
7421 })
7422
7423 testCases = append(testCases, testCase{
7424 testType: clientTest,
7425 name: "EncryptedExtensionsWithKeyShare",
7426 config: Config{
7427 MaxVersion: VersionTLS13,
7428 Bugs: ProtocolBugs{
7429 EncryptedExtensionsWithKeyShare: true,
7430 },
7431 },
7432 shouldFail: true,
7433 expectedLocalError: "remote error: unsupported extension",
7434 })
7435}
7436
Adam Langley7c803a62015-06-15 15:35:05 -07007437func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007438 defer wg.Done()
7439
7440 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007441 var err error
7442
7443 if *mallocTest < 0 {
7444 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007445 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007446 } else {
7447 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7448 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007449 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007450 if err != nil {
7451 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7452 }
7453 break
7454 }
7455 }
7456 }
Adam Langley95c29f32014-06-20 12:00:00 -07007457 statusChan <- statusMsg{test: test, err: err}
7458 }
7459}
7460
7461type statusMsg struct {
7462 test *testCase
7463 started bool
7464 err error
7465}
7466
David Benjamin5f237bc2015-02-11 17:14:15 -05007467func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07007468 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007469
David Benjamin5f237bc2015-02-11 17:14:15 -05007470 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007471 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007472 if !*pipe {
7473 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007474 var erase string
7475 for i := 0; i < lineLen; i++ {
7476 erase += "\b \b"
7477 }
7478 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007479 }
7480
Adam Langley95c29f32014-06-20 12:00:00 -07007481 if msg.started {
7482 started++
7483 } else {
7484 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007485
7486 if msg.err != nil {
7487 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7488 failed++
7489 testOutput.addResult(msg.test.name, "FAIL")
7490 } else {
7491 if *pipe {
7492 // Print each test instead of a status line.
7493 fmt.Printf("PASSED (%s)\n", msg.test.name)
7494 }
7495 testOutput.addResult(msg.test.name, "PASS")
7496 }
Adam Langley95c29f32014-06-20 12:00:00 -07007497 }
7498
David Benjamin5f237bc2015-02-11 17:14:15 -05007499 if !*pipe {
7500 // Print a new status line.
7501 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
7502 lineLen = len(line)
7503 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007504 }
Adam Langley95c29f32014-06-20 12:00:00 -07007505 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007506
7507 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007508}
7509
7510func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007511 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007512 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007513 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007514
Adam Langley7c803a62015-06-15 15:35:05 -07007515 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007516 addCipherSuiteTests()
7517 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007518 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007519 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007520 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007521 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007522 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007523 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007524 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007525 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007526 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007527 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007528 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007529 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007530 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007531 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007532 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007533 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007534 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007535 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007536 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007537 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007538 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007539 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007540 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007541 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007542 addTLS13WrongMessageTypeTests()
7543 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007544
7545 var wg sync.WaitGroup
7546
Adam Langley7c803a62015-06-15 15:35:05 -07007547 statusChan := make(chan statusMsg, *numWorkers)
7548 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007549 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007550
David Benjamin025b3d32014-07-01 19:53:04 -04007551 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007552
Adam Langley7c803a62015-06-15 15:35:05 -07007553 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007554 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007555 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007556 }
7557
David Benjamin270f0a72016-03-17 14:41:36 -04007558 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007559 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07007560 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04007561 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007562 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007563 }
7564 }
David Benjamin270f0a72016-03-17 14:41:36 -04007565 if !foundTest {
7566 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
7567 os.Exit(1)
7568 }
Adam Langley95c29f32014-06-20 12:00:00 -07007569
7570 close(testChan)
7571 wg.Wait()
7572 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007573 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007574
7575 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007576
7577 if *jsonOutput != "" {
7578 if err := testOutput.writeTo(*jsonOutput); err != nil {
7579 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7580 }
7581 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007582
7583 if !testOutput.allPassed {
7584 os.Exit(1)
7585 }
Adam Langley95c29f32014-06-20 12:00:00 -07007586}