blob: fb9086ad6f87d7d3f5b97cd92923ff75dd967663 [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
Steven Valdez0d62f262015-09-04 12:41:04 -0400262 // digestPrefs is the list of digest preferences from the client.
263 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400264 // certFile is the path to the certificate to use for the server.
265 certFile string
266 // keyFile is the path to the private key to use for the server.
267 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400268 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400269 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400270 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700271 // expectResumeRejected, if true, specifies that the attempted
272 // resumption must be rejected by the client. This is only valid for a
273 // serverTest.
274 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400275 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500276 // resumption. Unless newSessionsOnResume is set,
277 // SessionTicketKey, ServerSessionCache, and
278 // ClientSessionCache are copied from the initial connection's
279 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400280 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500281 // newSessionsOnResume, if true, will cause resumeConfig to
282 // use a different session resumption context.
283 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400284 // noSessionCache, if true, will cause the server to run without a
285 // session cache.
286 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400287 // sendPrefix sends a prefix on the socket before actually performing a
288 // handshake.
289 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400290 // shimWritesFirst controls whether the shim sends an initial "hello"
291 // message before doing a roundtrip with the runner.
292 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400293 // shimShutsDown, if true, runs a test where the shim shuts down the
294 // connection immediately after the handshake rather than echoing
295 // messages from the runner.
296 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400297 // renegotiate indicates the number of times the connection should be
298 // renegotiated during the exchange.
299 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700300 // renegotiateCiphers is a list of ciphersuite ids that will be
301 // switched in just before renegotiation.
302 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500303 // replayWrites, if true, configures the underlying transport
304 // to replay every write it makes in DTLS tests.
305 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500306 // damageFirstWrite, if true, configures the underlying transport to
307 // damage the final byte of the first application data write.
308 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400309 // exportKeyingMaterial, if non-zero, configures the test to exchange
310 // keying material and verify they match.
311 exportKeyingMaterial int
312 exportLabel string
313 exportContext string
314 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400315 // flags, if not empty, contains a list of command-line flags that will
316 // be passed to the shim program.
317 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700318 // testTLSUnique, if true, causes the shim to send the tls-unique value
319 // which will be compared against the expected value.
320 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400321 // sendEmptyRecords is the number of consecutive empty records to send
322 // before and after the test message.
323 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400324 // sendWarningAlerts is the number of consecutive warning alerts to send
325 // before and after the test message.
326 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400327 // expectMessageDropped, if true, means the test message is expected to
328 // be dropped by the client rather than echoed back.
329 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700330}
331
Adam Langley7c803a62015-06-15 15:35:05 -0700332var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700333
David Benjamin9867b7d2016-03-01 23:25:48 -0500334func writeTranscript(test *testCase, isResume bool, data []byte) {
335 if len(data) == 0 {
336 return
337 }
338
339 protocol := "tls"
340 if test.protocol == dtls {
341 protocol = "dtls"
342 }
343
344 side := "client"
345 if test.testType == serverTest {
346 side = "server"
347 }
348
349 dir := path.Join(*transcriptDir, protocol, side)
350 if err := os.MkdirAll(dir, 0755); err != nil {
351 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
352 return
353 }
354
355 name := test.name
356 if isResume {
357 name += "-Resume"
358 } else {
359 name += "-Normal"
360 }
361
362 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
363 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
364 }
365}
366
David Benjamin3ed59772016-03-08 12:50:21 -0500367// A timeoutConn implements an idle timeout on each Read and Write operation.
368type timeoutConn struct {
369 net.Conn
370 timeout time.Duration
371}
372
373func (t *timeoutConn) Read(b []byte) (int, error) {
374 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
375 return 0, err
376 }
377 return t.Conn.Read(b)
378}
379
380func (t *timeoutConn) Write(b []byte) (int, error) {
381 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
382 return 0, err
383 }
384 return t.Conn.Write(b)
385}
386
David Benjamin8e6db492015-07-25 18:29:23 -0400387func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400388 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500389
David Benjamin6fd297b2014-08-11 18:43:38 -0400390 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500391 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
392 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500393 }
394
David Benjamin9867b7d2016-03-01 23:25:48 -0500395 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500396 local, peer := "client", "server"
397 if test.testType == clientTest {
398 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500399 }
David Benjaminebda9b32015-11-02 15:33:18 -0500400 connDebug := &recordingConn{
401 Conn: conn,
402 isDatagram: test.protocol == dtls,
403 local: local,
404 peer: peer,
405 }
406 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500407 if *flagDebug {
408 defer connDebug.WriteTo(os.Stdout)
409 }
410 if len(*transcriptDir) != 0 {
411 defer func() {
412 writeTranscript(test, isResume, connDebug.Transcript())
413 }()
414 }
David Benjaminebda9b32015-11-02 15:33:18 -0500415
416 if config.Bugs.PacketAdaptor != nil {
417 config.Bugs.PacketAdaptor.debug = connDebug
418 }
419 }
420
421 if test.replayWrites {
422 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400423 }
424
David Benjamin3ed59772016-03-08 12:50:21 -0500425 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500426 if test.damageFirstWrite {
427 connDamage = newDamageAdaptor(conn)
428 conn = connDamage
429 }
430
David Benjamin6fd297b2014-08-11 18:43:38 -0400431 if test.sendPrefix != "" {
432 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
433 return err
434 }
David Benjamin98e882e2014-08-08 13:24:34 -0400435 }
436
David Benjamin1d5c83e2014-07-22 19:20:02 -0400437 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400438 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400439 if test.protocol == dtls {
440 tlsConn = DTLSServer(conn, config)
441 } else {
442 tlsConn = Server(conn, config)
443 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400444 } else {
445 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400446 if test.protocol == dtls {
447 tlsConn = DTLSClient(conn, config)
448 } else {
449 tlsConn = Client(conn, config)
450 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400451 }
David Benjamin30789da2015-08-29 22:56:45 -0400452 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400453
Adam Langley95c29f32014-06-20 12:00:00 -0700454 if err := tlsConn.Handshake(); err != nil {
455 return err
456 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700457
David Benjamin01fe8202014-09-24 15:21:44 -0400458 // TODO(davidben): move all per-connection expectations into a dedicated
459 // expectations struct that can be specified separately for the two
460 // legs.
461 expectedVersion := test.expectedVersion
462 if isResume && test.expectedResumeVersion != 0 {
463 expectedVersion = test.expectedResumeVersion
464 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700465 connState := tlsConn.ConnectionState()
466 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400467 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400468 }
469
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700470 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400471 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
472 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700473 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
474 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
475 }
David Benjamin90da8c82015-04-20 14:57:57 -0400476
David Benjamina08e49d2014-08-24 01:46:07 -0400477 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700478 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400479 if channelID == nil {
480 return fmt.Errorf("no channel ID negotiated")
481 }
482 if channelID.Curve != channelIDKey.Curve ||
483 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
484 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
485 return fmt.Errorf("incorrect channel ID")
486 }
487 }
488
David Benjaminae2888f2014-09-06 12:58:58 -0400489 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700490 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400491 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
492 }
493 }
494
David Benjaminc7ce9772015-10-09 19:32:41 -0400495 if test.expectNoNextProto {
496 if actual := connState.NegotiatedProtocol; actual != "" {
497 return fmt.Errorf("got unexpected next proto %s", actual)
498 }
499 }
500
David Benjaminfc7b0862014-09-06 13:21:53 -0400501 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700502 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400503 return fmt.Errorf("next proto type mismatch")
504 }
505 }
506
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700507 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500508 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
509 }
510
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100511 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
512 return fmt.Errorf("OCSP Response mismatch")
513 }
514
Paul Lietar4fac72e2015-09-09 13:44:55 +0100515 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
516 return fmt.Errorf("SCT list mismatch")
517 }
518
Nick Harper60edffd2016-06-21 15:19:24 -0700519 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
520 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400521 }
522
David Benjaminc565ebb2015-04-03 04:06:36 -0400523 if test.exportKeyingMaterial > 0 {
524 actual := make([]byte, test.exportKeyingMaterial)
525 if _, err := io.ReadFull(tlsConn, actual); err != nil {
526 return err
527 }
528 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
529 if err != nil {
530 return err
531 }
532 if !bytes.Equal(actual, expected) {
533 return fmt.Errorf("keying material mismatch")
534 }
535 }
536
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700537 if test.testTLSUnique {
538 var peersValue [12]byte
539 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
540 return err
541 }
542 expected := tlsConn.ConnectionState().TLSUnique
543 if !bytes.Equal(peersValue[:], expected) {
544 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
545 }
546 }
547
David Benjamine58c4f52014-08-24 03:47:07 -0400548 if test.shimWritesFirst {
549 var buf [5]byte
550 _, err := io.ReadFull(tlsConn, buf[:])
551 if err != nil {
552 return err
553 }
554 if string(buf[:]) != "hello" {
555 return fmt.Errorf("bad initial message")
556 }
557 }
558
David Benjamina8ebe222015-06-06 03:04:39 -0400559 for i := 0; i < test.sendEmptyRecords; i++ {
560 tlsConn.Write(nil)
561 }
562
David Benjamin24f346d2015-06-06 03:28:08 -0400563 for i := 0; i < test.sendWarningAlerts; i++ {
564 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
565 }
566
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400567 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700568 if test.renegotiateCiphers != nil {
569 config.CipherSuites = test.renegotiateCiphers
570 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400571 for i := 0; i < test.renegotiate; i++ {
572 if err := tlsConn.Renegotiate(); err != nil {
573 return err
574 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700575 }
576 } else if test.renegotiateCiphers != nil {
577 panic("renegotiateCiphers without renegotiate")
578 }
579
David Benjamin5fa3eba2015-01-22 16:35:40 -0500580 if test.damageFirstWrite {
581 connDamage.setDamage(true)
582 tlsConn.Write([]byte("DAMAGED WRITE"))
583 connDamage.setDamage(false)
584 }
585
David Benjamin8e6db492015-07-25 18:29:23 -0400586 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700587 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400588 if test.protocol == dtls {
589 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
590 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700591 // Read until EOF.
592 _, err := io.Copy(ioutil.Discard, tlsConn)
593 return err
594 }
David Benjamin4417d052015-04-05 04:17:25 -0400595 if messageLen == 0 {
596 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700597 }
Adam Langley95c29f32014-06-20 12:00:00 -0700598
David Benjamin8e6db492015-07-25 18:29:23 -0400599 messageCount := test.messageCount
600 if messageCount == 0 {
601 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400602 }
603
David Benjamin8e6db492015-07-25 18:29:23 -0400604 for j := 0; j < messageCount; j++ {
605 testMessage := make([]byte, messageLen)
606 for i := range testMessage {
607 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400608 }
David Benjamin8e6db492015-07-25 18:29:23 -0400609 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700610
David Benjamin8e6db492015-07-25 18:29:23 -0400611 for i := 0; i < test.sendEmptyRecords; i++ {
612 tlsConn.Write(nil)
613 }
614
615 for i := 0; i < test.sendWarningAlerts; i++ {
616 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
617 }
618
David Benjamin4f75aaf2015-09-01 16:53:10 -0400619 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400620 // The shim will not respond.
621 continue
622 }
623
David Benjamin8e6db492015-07-25 18:29:23 -0400624 buf := make([]byte, len(testMessage))
625 if test.protocol == dtls {
626 bufTmp := make([]byte, len(buf)+1)
627 n, err := tlsConn.Read(bufTmp)
628 if err != nil {
629 return err
630 }
631 if n != len(buf) {
632 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
633 }
634 copy(buf, bufTmp)
635 } else {
636 _, err := io.ReadFull(tlsConn, buf)
637 if err != nil {
638 return err
639 }
640 }
641
642 for i, v := range buf {
643 if v != testMessage[i]^0xff {
644 return fmt.Errorf("bad reply contents at byte %d", i)
645 }
Adam Langley95c29f32014-06-20 12:00:00 -0700646 }
647 }
648
649 return nil
650}
651
David Benjamin325b5c32014-07-01 19:40:31 -0400652func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
653 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700654 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400655 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700656 }
David Benjamin325b5c32014-07-01 19:40:31 -0400657 valgrindArgs = append(valgrindArgs, path)
658 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700659
David Benjamin325b5c32014-07-01 19:40:31 -0400660 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700661}
662
David Benjamin325b5c32014-07-01 19:40:31 -0400663func gdbOf(path string, args ...string) *exec.Cmd {
664 xtermArgs := []string{"-e", "gdb", "--args"}
665 xtermArgs = append(xtermArgs, path)
666 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700667
David Benjamin325b5c32014-07-01 19:40:31 -0400668 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700669}
670
David Benjamind16bf342015-12-18 00:53:12 -0500671func lldbOf(path string, args ...string) *exec.Cmd {
672 xtermArgs := []string{"-e", "lldb", "--"}
673 xtermArgs = append(xtermArgs, path)
674 xtermArgs = append(xtermArgs, args...)
675
676 return exec.Command("xterm", xtermArgs...)
677}
678
Adam Langley69a01602014-11-17 17:26:55 -0800679type moreMallocsError struct{}
680
681func (moreMallocsError) Error() string {
682 return "child process did not exhaust all allocation calls"
683}
684
685var errMoreMallocs = moreMallocsError{}
686
David Benjamin87c8a642015-02-21 01:54:29 -0500687// accept accepts a connection from listener, unless waitChan signals a process
688// exit first.
689func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
690 type connOrError struct {
691 conn net.Conn
692 err error
693 }
694 connChan := make(chan connOrError, 1)
695 go func() {
696 conn, err := listener.Accept()
697 connChan <- connOrError{conn, err}
698 close(connChan)
699 }()
700 select {
701 case result := <-connChan:
702 return result.conn, result.err
703 case childErr := <-waitChan:
704 waitChan <- childErr
705 return nil, fmt.Errorf("child exited early: %s", childErr)
706 }
707}
708
Adam Langley7c803a62015-06-15 15:35:05 -0700709func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700710 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
711 panic("Error expected without shouldFail in " + test.name)
712 }
713
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700714 if test.expectResumeRejected && !test.resumeSession {
715 panic("expectResumeRejected without resumeSession in " + test.name)
716 }
717
David Benjamin87c8a642015-02-21 01:54:29 -0500718 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
719 if err != nil {
720 panic(err)
721 }
722 defer func() {
723 if listener != nil {
724 listener.Close()
725 }
726 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700727
David Benjamin87c8a642015-02-21 01:54:29 -0500728 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400729 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400730 flags = append(flags, "-server")
731
David Benjamin025b3d32014-07-01 19:53:04 -0400732 flags = append(flags, "-key-file")
733 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700734 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400735 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700736 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400737 }
738
739 flags = append(flags, "-cert-file")
740 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700741 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400742 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700743 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400744 }
745 }
David Benjamin5a593af2014-08-11 19:51:50 -0400746
Steven Valdez0d62f262015-09-04 12:41:04 -0400747 if test.digestPrefs != "" {
748 flags = append(flags, "-digest-prefs")
749 flags = append(flags, test.digestPrefs)
750 }
751
David Benjamin6fd297b2014-08-11 18:43:38 -0400752 if test.protocol == dtls {
753 flags = append(flags, "-dtls")
754 }
755
David Benjamin5a593af2014-08-11 19:51:50 -0400756 if test.resumeSession {
757 flags = append(flags, "-resume")
758 }
759
David Benjamine58c4f52014-08-24 03:47:07 -0400760 if test.shimWritesFirst {
761 flags = append(flags, "-shim-writes-first")
762 }
763
David Benjamin30789da2015-08-29 22:56:45 -0400764 if test.shimShutsDown {
765 flags = append(flags, "-shim-shuts-down")
766 }
767
David Benjaminc565ebb2015-04-03 04:06:36 -0400768 if test.exportKeyingMaterial > 0 {
769 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
770 flags = append(flags, "-export-label", test.exportLabel)
771 flags = append(flags, "-export-context", test.exportContext)
772 if test.useExportContext {
773 flags = append(flags, "-use-export-context")
774 }
775 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700776 if test.expectResumeRejected {
777 flags = append(flags, "-expect-session-miss")
778 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400779
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700780 if test.testTLSUnique {
781 flags = append(flags, "-tls-unique")
782 }
783
David Benjamin025b3d32014-07-01 19:53:04 -0400784 flags = append(flags, test.flags...)
785
786 var shim *exec.Cmd
787 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700788 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700789 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700790 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500791 } else if *useLLDB {
792 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400793 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700794 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400795 }
David Benjamin025b3d32014-07-01 19:53:04 -0400796 shim.Stdin = os.Stdin
797 var stdoutBuf, stderrBuf bytes.Buffer
798 shim.Stdout = &stdoutBuf
799 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800800 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500801 shim.Env = os.Environ()
802 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800803 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400804 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800805 }
806 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
807 }
David Benjamin025b3d32014-07-01 19:53:04 -0400808
809 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700810 panic(err)
811 }
David Benjamin87c8a642015-02-21 01:54:29 -0500812 waitChan := make(chan error, 1)
813 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700814
815 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400816 if !test.noSessionCache {
817 config.ClientSessionCache = NewLRUClientSessionCache(1)
818 config.ServerSessionCache = NewLRUServerSessionCache(1)
819 }
David Benjamin025b3d32014-07-01 19:53:04 -0400820 if test.testType == clientTest {
821 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700822 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400823 }
David Benjamin87c8a642015-02-21 01:54:29 -0500824 } else {
825 // Supply a ServerName to ensure a constant session cache key,
826 // rather than falling back to net.Conn.RemoteAddr.
827 if len(config.ServerName) == 0 {
828 config.ServerName = "test"
829 }
David Benjamin025b3d32014-07-01 19:53:04 -0400830 }
David Benjaminf2b83632016-03-01 22:57:46 -0500831 if *fuzzer {
832 config.Bugs.NullAllCiphers = true
833 }
David Benjamin2e045a92016-06-08 13:09:56 -0400834 if *deterministic {
835 config.Rand = &deterministicRand{}
836 }
Adam Langley95c29f32014-06-20 12:00:00 -0700837
David Benjamin87c8a642015-02-21 01:54:29 -0500838 conn, err := acceptOrWait(listener, waitChan)
839 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400840 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500841 conn.Close()
842 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500843
David Benjamin1d5c83e2014-07-22 19:20:02 -0400844 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400845 var resumeConfig Config
846 if test.resumeConfig != nil {
847 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500848 if len(resumeConfig.ServerName) == 0 {
849 resumeConfig.ServerName = config.ServerName
850 }
David Benjamin01fe8202014-09-24 15:21:44 -0400851 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700852 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400853 }
David Benjaminba4594a2015-06-18 18:36:15 -0400854 if test.newSessionsOnResume {
855 if !test.noSessionCache {
856 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
857 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
858 }
859 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500860 resumeConfig.SessionTicketKey = config.SessionTicketKey
861 resumeConfig.ClientSessionCache = config.ClientSessionCache
862 resumeConfig.ServerSessionCache = config.ServerSessionCache
863 }
David Benjaminf2b83632016-03-01 22:57:46 -0500864 if *fuzzer {
865 resumeConfig.Bugs.NullAllCiphers = true
866 }
David Benjamin2e045a92016-06-08 13:09:56 -0400867 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400868 } else {
869 resumeConfig = config
870 }
David Benjamin87c8a642015-02-21 01:54:29 -0500871 var connResume net.Conn
872 connResume, err = acceptOrWait(listener, waitChan)
873 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400874 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500875 connResume.Close()
876 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400877 }
878
David Benjamin87c8a642015-02-21 01:54:29 -0500879 // Close the listener now. This is to avoid hangs should the shim try to
880 // open more connections than expected.
881 listener.Close()
882 listener = nil
883
884 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800885 if exitError, ok := childErr.(*exec.ExitError); ok {
886 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
887 return errMoreMallocs
888 }
889 }
Adam Langley95c29f32014-06-20 12:00:00 -0700890
David Benjamin9bea3492016-03-02 10:59:16 -0500891 // Account for Windows line endings.
892 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
893 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500894
895 // Separate the errors from the shim and those from tools like
896 // AddressSanitizer.
897 var extraStderr string
898 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
899 stderr = stderrParts[0]
900 extraStderr = stderrParts[1]
901 }
902
Adam Langley95c29f32014-06-20 12:00:00 -0700903 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400904 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700905 localError := "none"
906 if err != nil {
907 localError = err.Error()
908 }
909 if len(test.expectedLocalError) != 0 {
910 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
911 }
Adam Langley95c29f32014-06-20 12:00:00 -0700912
913 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700914 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700915 if childErr != nil {
916 childError = childErr.Error()
917 }
918
919 var msg string
920 switch {
921 case failed && !test.shouldFail:
922 msg = "unexpected failure"
923 case !failed && test.shouldFail:
924 msg = "unexpected success"
925 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700926 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700927 default:
928 panic("internal error")
929 }
930
David Benjaminc565ebb2015-04-03 04:06:36 -0400931 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 -0700932 }
933
David Benjaminff3a1492016-03-02 10:12:06 -0500934 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
935 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700936 }
937
938 return nil
939}
940
941var tlsVersions = []struct {
942 name string
943 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400944 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500945 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700946}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500947 {"SSL3", VersionSSL30, "-no-ssl3", false},
948 {"TLS1", VersionTLS10, "-no-tls1", true},
949 {"TLS11", VersionTLS11, "-no-tls11", false},
950 {"TLS12", VersionTLS12, "-no-tls12", true},
Nick Harper1fd39d82016-06-14 18:14:35 -0700951 // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here.
952 {"FakeTLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700953}
954
955var testCipherSuites = []struct {
956 name string
957 id uint16
958}{
959 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400960 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700961 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400962 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400963 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700964 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400965 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400966 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
967 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400968 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400969 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
970 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400971 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
973 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400974 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
975 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700976 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400977 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500978 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500979 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700980 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700982 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400983 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400984 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700985 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400986 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500987 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500988 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700989 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700990 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
991 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
992 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
993 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400994 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
995 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700996 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
997 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500998 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400999 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1000 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001001 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001002 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001003 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001004 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001005}
1006
David Benjamin8b8c0062014-11-23 02:47:52 -05001007func hasComponent(suiteName, component string) bool {
1008 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1009}
1010
David Benjaminf7768e42014-08-31 02:06:47 -04001011func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001012 return hasComponent(suiteName, "GCM") ||
1013 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001014 hasComponent(suiteName, "SHA384") ||
1015 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001016}
1017
Nick Harper1fd39d82016-06-14 18:14:35 -07001018func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001019 // Only AEADs.
1020 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1021 return false
1022 }
1023 // No old CHACHA20_POLY1305.
1024 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1025 return false
1026 }
1027 // Must have ECDHE.
1028 // TODO(davidben,svaldez): Add pure PSK support.
1029 if !hasComponent(suiteName, "ECDHE") {
1030 return false
1031 }
1032 // TODO(davidben,svaldez): Add PSK support.
1033 if hasComponent(suiteName, "PSK") {
1034 return false
1035 }
1036 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001037}
1038
David Benjamin8b8c0062014-11-23 02:47:52 -05001039func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001040 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001041}
1042
Adam Langleya7997f12015-05-14 17:38:50 -07001043func bigFromHex(hex string) *big.Int {
1044 ret, ok := new(big.Int).SetString(hex, 16)
1045 if !ok {
1046 panic("failed to parse hex number 0x" + hex)
1047 }
1048 return ret
1049}
1050
Adam Langley7c803a62015-06-15 15:35:05 -07001051func addBasicTests() {
1052 basicTests := []testCase{
1053 {
1054 name: "BadRSASignature",
1055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001056 // TODO(davidben): Add a TLS 1.3 version of this.
1057 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001058 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1059 Bugs: ProtocolBugs{
1060 InvalidSKXSignature: true,
1061 },
1062 },
1063 shouldFail: true,
1064 expectedError: ":BAD_SIGNATURE:",
1065 },
1066 {
1067 name: "BadECDSASignature",
1068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001069 // TODO(davidben): Add a TLS 1.3 version of this.
1070 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001071 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1072 Bugs: ProtocolBugs{
1073 InvalidSKXSignature: true,
1074 },
David Benjamin33863262016-07-08 17:20:12 -07001075 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001076 },
1077 shouldFail: true,
1078 expectedError: ":BAD_SIGNATURE:",
1079 },
1080 {
David Benjamin6de0e532015-07-28 22:43:19 -04001081 testType: serverTest,
1082 name: "BadRSASignature-ClientAuth",
1083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001084 // TODO(davidben): Add a TLS 1.3 version of this.
1085 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001086 Bugs: ProtocolBugs{
1087 InvalidCertVerifySignature: true,
1088 },
David Benjamin33863262016-07-08 17:20:12 -07001089 Certificates: []Certificate{rsaCertificate},
David Benjamin6de0e532015-07-28 22:43:19 -04001090 },
1091 shouldFail: true,
1092 expectedError: ":BAD_SIGNATURE:",
1093 flags: []string{"-require-any-client-certificate"},
1094 },
1095 {
1096 testType: serverTest,
1097 name: "BadECDSASignature-ClientAuth",
1098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001099 // TODO(davidben): Add a TLS 1.3 version of this.
1100 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001101 Bugs: ProtocolBugs{
1102 InvalidCertVerifySignature: true,
1103 },
David Benjamin33863262016-07-08 17:20:12 -07001104 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin6de0e532015-07-28 22:43:19 -04001105 },
1106 shouldFail: true,
1107 expectedError: ":BAD_SIGNATURE:",
1108 flags: []string{"-require-any-client-certificate"},
1109 },
1110 {
Adam Langley7c803a62015-06-15 15:35:05 -07001111 name: "NoFallbackSCSV",
1112 config: Config{
1113 Bugs: ProtocolBugs{
1114 FailIfNotFallbackSCSV: true,
1115 },
1116 },
1117 shouldFail: true,
1118 expectedLocalError: "no fallback SCSV found",
1119 },
1120 {
1121 name: "SendFallbackSCSV",
1122 config: Config{
1123 Bugs: ProtocolBugs{
1124 FailIfNotFallbackSCSV: true,
1125 },
1126 },
1127 flags: []string{"-fallback-scsv"},
1128 },
1129 {
1130 name: "ClientCertificateTypes",
1131 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001132 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001133 ClientAuth: RequestClientCert,
1134 ClientCertificateTypes: []byte{
1135 CertTypeDSSSign,
1136 CertTypeRSASign,
1137 CertTypeECDSASign,
1138 },
1139 },
1140 flags: []string{
1141 "-expect-certificate-types",
1142 base64.StdEncoding.EncodeToString([]byte{
1143 CertTypeDSSSign,
1144 CertTypeRSASign,
1145 CertTypeECDSASign,
1146 }),
1147 },
1148 },
1149 {
Adam Langley7c803a62015-06-15 15:35:05 -07001150 name: "UnauthenticatedECDH",
1151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001152 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1154 Bugs: ProtocolBugs{
1155 UnauthenticatedECDH: true,
1156 },
1157 },
1158 shouldFail: true,
1159 expectedError: ":UNEXPECTED_MESSAGE:",
1160 },
1161 {
1162 name: "SkipCertificateStatus",
1163 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001164 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001165 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1166 Bugs: ProtocolBugs{
1167 SkipCertificateStatus: true,
1168 },
1169 },
1170 flags: []string{
1171 "-enable-ocsp-stapling",
1172 },
1173 },
1174 {
1175 name: "SkipServerKeyExchange",
1176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001177 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001178 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1179 Bugs: ProtocolBugs{
1180 SkipServerKeyExchange: true,
1181 },
1182 },
1183 shouldFail: true,
1184 expectedError: ":UNEXPECTED_MESSAGE:",
1185 },
1186 {
Adam Langley7c803a62015-06-15 15:35:05 -07001187 testType: serverTest,
1188 name: "Alert",
1189 config: Config{
1190 Bugs: ProtocolBugs{
1191 SendSpuriousAlert: alertRecordOverflow,
1192 },
1193 },
1194 shouldFail: true,
1195 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1196 },
1197 {
1198 protocol: dtls,
1199 testType: serverTest,
1200 name: "Alert-DTLS",
1201 config: Config{
1202 Bugs: ProtocolBugs{
1203 SendSpuriousAlert: alertRecordOverflow,
1204 },
1205 },
1206 shouldFail: true,
1207 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1208 },
1209 {
1210 testType: serverTest,
1211 name: "FragmentAlert",
1212 config: Config{
1213 Bugs: ProtocolBugs{
1214 FragmentAlert: true,
1215 SendSpuriousAlert: alertRecordOverflow,
1216 },
1217 },
1218 shouldFail: true,
1219 expectedError: ":BAD_ALERT:",
1220 },
1221 {
1222 protocol: dtls,
1223 testType: serverTest,
1224 name: "FragmentAlert-DTLS",
1225 config: Config{
1226 Bugs: ProtocolBugs{
1227 FragmentAlert: true,
1228 SendSpuriousAlert: alertRecordOverflow,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":BAD_ALERT:",
1233 },
1234 {
1235 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001236 name: "DoubleAlert",
1237 config: Config{
1238 Bugs: ProtocolBugs{
1239 DoubleAlert: true,
1240 SendSpuriousAlert: alertRecordOverflow,
1241 },
1242 },
1243 shouldFail: true,
1244 expectedError: ":BAD_ALERT:",
1245 },
1246 {
1247 protocol: dtls,
1248 testType: serverTest,
1249 name: "DoubleAlert-DTLS",
1250 config: Config{
1251 Bugs: ProtocolBugs{
1252 DoubleAlert: true,
1253 SendSpuriousAlert: alertRecordOverflow,
1254 },
1255 },
1256 shouldFail: true,
1257 expectedError: ":BAD_ALERT:",
1258 },
1259 {
Adam Langley7c803a62015-06-15 15:35:05 -07001260 name: "SkipNewSessionTicket",
1261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001262 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001263 Bugs: ProtocolBugs{
1264 SkipNewSessionTicket: true,
1265 },
1266 },
1267 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001268 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001269 },
1270 {
1271 testType: serverTest,
1272 name: "FallbackSCSV",
1273 config: Config{
1274 MaxVersion: VersionTLS11,
1275 Bugs: ProtocolBugs{
1276 SendFallbackSCSV: true,
1277 },
1278 },
1279 shouldFail: true,
1280 expectedError: ":INAPPROPRIATE_FALLBACK:",
1281 },
1282 {
1283 testType: serverTest,
1284 name: "FallbackSCSV-VersionMatch",
1285 config: Config{
1286 Bugs: ProtocolBugs{
1287 SendFallbackSCSV: true,
1288 },
1289 },
1290 },
1291 {
1292 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001293 name: "FallbackSCSV-VersionMatch-TLS12",
1294 config: Config{
1295 MaxVersion: VersionTLS12,
1296 Bugs: ProtocolBugs{
1297 SendFallbackSCSV: true,
1298 },
1299 },
1300 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1301 },
1302 {
1303 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001304 name: "FragmentedClientVersion",
1305 config: Config{
1306 Bugs: ProtocolBugs{
1307 MaxHandshakeRecordLength: 1,
1308 FragmentClientVersion: true,
1309 },
1310 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001311 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001312 },
1313 {
Adam Langley7c803a62015-06-15 15:35:05 -07001314 testType: serverTest,
1315 name: "HttpGET",
1316 sendPrefix: "GET / HTTP/1.0\n",
1317 shouldFail: true,
1318 expectedError: ":HTTP_REQUEST:",
1319 },
1320 {
1321 testType: serverTest,
1322 name: "HttpPOST",
1323 sendPrefix: "POST / HTTP/1.0\n",
1324 shouldFail: true,
1325 expectedError: ":HTTP_REQUEST:",
1326 },
1327 {
1328 testType: serverTest,
1329 name: "HttpHEAD",
1330 sendPrefix: "HEAD / HTTP/1.0\n",
1331 shouldFail: true,
1332 expectedError: ":HTTP_REQUEST:",
1333 },
1334 {
1335 testType: serverTest,
1336 name: "HttpPUT",
1337 sendPrefix: "PUT / HTTP/1.0\n",
1338 shouldFail: true,
1339 expectedError: ":HTTP_REQUEST:",
1340 },
1341 {
1342 testType: serverTest,
1343 name: "HttpCONNECT",
1344 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1345 shouldFail: true,
1346 expectedError: ":HTTPS_PROXY_REQUEST:",
1347 },
1348 {
1349 testType: serverTest,
1350 name: "Garbage",
1351 sendPrefix: "blah",
1352 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001353 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001354 },
1355 {
Adam Langley7c803a62015-06-15 15:35:05 -07001356 name: "RSAEphemeralKey",
1357 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001358 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001359 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1360 Bugs: ProtocolBugs{
1361 RSAEphemeralKey: true,
1362 },
1363 },
1364 shouldFail: true,
1365 expectedError: ":UNEXPECTED_MESSAGE:",
1366 },
1367 {
1368 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001369 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001370 shouldFail: true,
1371 expectedError: ":WRONG_SSL_VERSION:",
1372 },
1373 {
1374 protocol: dtls,
1375 name: "DisableEverything-DTLS",
1376 flags: []string{"-no-tls12", "-no-tls1"},
1377 shouldFail: true,
1378 expectedError: ":WRONG_SSL_VERSION:",
1379 },
1380 {
Adam Langley7c803a62015-06-15 15:35:05 -07001381 protocol: dtls,
1382 testType: serverTest,
1383 name: "MTU",
1384 config: Config{
1385 Bugs: ProtocolBugs{
1386 MaxPacketLength: 256,
1387 },
1388 },
1389 flags: []string{"-mtu", "256"},
1390 },
1391 {
1392 protocol: dtls,
1393 testType: serverTest,
1394 name: "MTUExceeded",
1395 config: Config{
1396 Bugs: ProtocolBugs{
1397 MaxPacketLength: 255,
1398 },
1399 },
1400 flags: []string{"-mtu", "256"},
1401 shouldFail: true,
1402 expectedLocalError: "dtls: exceeded maximum packet length",
1403 },
1404 {
1405 name: "CertMismatchRSA",
1406 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001407 // TODO(davidben): Add a TLS 1.3 version of this test.
1408 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001409 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001410 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001411 Bugs: ProtocolBugs{
1412 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1417 },
1418 {
1419 name: "CertMismatchECDSA",
1420 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001421 // TODO(davidben): Add a TLS 1.3 version of this test.
1422 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001423 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001424 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001425 Bugs: ProtocolBugs{
1426 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1427 },
1428 },
1429 shouldFail: true,
1430 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1431 },
1432 {
1433 name: "EmptyCertificateList",
1434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001435 // TODO(davidben): Add a TLS 1.3 version of this test.
1436 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001437 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1438 Bugs: ProtocolBugs{
1439 EmptyCertificateList: true,
1440 },
1441 },
1442 shouldFail: true,
1443 expectedError: ":DECODE_ERROR:",
1444 },
1445 {
1446 name: "TLSFatalBadPackets",
1447 damageFirstWrite: true,
1448 shouldFail: true,
1449 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1450 },
1451 {
1452 protocol: dtls,
1453 name: "DTLSIgnoreBadPackets",
1454 damageFirstWrite: true,
1455 },
1456 {
1457 protocol: dtls,
1458 name: "DTLSIgnoreBadPackets-Async",
1459 damageFirstWrite: true,
1460 flags: []string{"-async"},
1461 },
1462 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001463 name: "AppDataBeforeHandshake",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":UNEXPECTED_RECORD:",
1471 },
1472 {
1473 name: "AppDataBeforeHandshake-Empty",
1474 config: Config{
1475 Bugs: ProtocolBugs{
1476 AppDataBeforeHandshake: []byte{},
1477 },
1478 },
1479 shouldFail: true,
1480 expectedError: ":UNEXPECTED_RECORD:",
1481 },
1482 {
1483 protocol: dtls,
1484 name: "AppDataBeforeHandshake-DTLS",
1485 config: Config{
1486 Bugs: ProtocolBugs{
1487 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1488 },
1489 },
1490 shouldFail: true,
1491 expectedError: ":UNEXPECTED_RECORD:",
1492 },
1493 {
1494 protocol: dtls,
1495 name: "AppDataBeforeHandshake-DTLS-Empty",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 AppDataBeforeHandshake: []byte{},
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":UNEXPECTED_RECORD:",
1503 },
1504 {
Adam Langley7c803a62015-06-15 15:35:05 -07001505 name: "AppDataAfterChangeCipherSpec",
1506 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001507 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001508 Bugs: ProtocolBugs{
1509 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1510 },
1511 },
1512 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001513 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001514 },
1515 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001516 name: "AppDataAfterChangeCipherSpec-Empty",
1517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001518 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001519 Bugs: ProtocolBugs{
1520 AppDataAfterChangeCipherSpec: []byte{},
1521 },
1522 },
1523 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001524 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001525 },
1526 {
Adam Langley7c803a62015-06-15 15:35:05 -07001527 protocol: dtls,
1528 name: "AppDataAfterChangeCipherSpec-DTLS",
1529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001530 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001531 Bugs: ProtocolBugs{
1532 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1533 },
1534 },
1535 // BoringSSL's DTLS implementation will drop the out-of-order
1536 // application data.
1537 },
1538 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001539 protocol: dtls,
1540 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001542 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001543 Bugs: ProtocolBugs{
1544 AppDataAfterChangeCipherSpec: []byte{},
1545 },
1546 },
1547 // BoringSSL's DTLS implementation will drop the out-of-order
1548 // application data.
1549 },
1550 {
Adam Langley7c803a62015-06-15 15:35:05 -07001551 name: "AlertAfterChangeCipherSpec",
1552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001553 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001554 Bugs: ProtocolBugs{
1555 AlertAfterChangeCipherSpec: alertRecordOverflow,
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1560 },
1561 {
1562 protocol: dtls,
1563 name: "AlertAfterChangeCipherSpec-DTLS",
1564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001565 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001566 Bugs: ProtocolBugs{
1567 AlertAfterChangeCipherSpec: alertRecordOverflow,
1568 },
1569 },
1570 shouldFail: true,
1571 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1572 },
1573 {
1574 protocol: dtls,
1575 name: "ReorderHandshakeFragments-Small-DTLS",
1576 config: Config{
1577 Bugs: ProtocolBugs{
1578 ReorderHandshakeFragments: true,
1579 // Small enough that every handshake message is
1580 // fragmented.
1581 MaxHandshakeRecordLength: 2,
1582 },
1583 },
1584 },
1585 {
1586 protocol: dtls,
1587 name: "ReorderHandshakeFragments-Large-DTLS",
1588 config: Config{
1589 Bugs: ProtocolBugs{
1590 ReorderHandshakeFragments: true,
1591 // Large enough that no handshake message is
1592 // fragmented.
1593 MaxHandshakeRecordLength: 2048,
1594 },
1595 },
1596 },
1597 {
1598 protocol: dtls,
1599 name: "MixCompleteMessageWithFragments-DTLS",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 ReorderHandshakeFragments: true,
1603 MixCompleteMessageWithFragments: true,
1604 MaxHandshakeRecordLength: 2,
1605 },
1606 },
1607 },
1608 {
1609 name: "SendInvalidRecordType",
1610 config: Config{
1611 Bugs: ProtocolBugs{
1612 SendInvalidRecordType: true,
1613 },
1614 },
1615 shouldFail: true,
1616 expectedError: ":UNEXPECTED_RECORD:",
1617 },
1618 {
1619 protocol: dtls,
1620 name: "SendInvalidRecordType-DTLS",
1621 config: Config{
1622 Bugs: ProtocolBugs{
1623 SendInvalidRecordType: true,
1624 },
1625 },
1626 shouldFail: true,
1627 expectedError: ":UNEXPECTED_RECORD:",
1628 },
1629 {
1630 name: "FalseStart-SkipServerSecondLeg",
1631 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001632 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001633 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1634 NextProtos: []string{"foo"},
1635 Bugs: ProtocolBugs{
1636 SkipNewSessionTicket: true,
1637 SkipChangeCipherSpec: true,
1638 SkipFinished: true,
1639 ExpectFalseStart: true,
1640 },
1641 },
1642 flags: []string{
1643 "-false-start",
1644 "-handshake-never-done",
1645 "-advertise-alpn", "\x03foo",
1646 },
1647 shimWritesFirst: true,
1648 shouldFail: true,
1649 expectedError: ":UNEXPECTED_RECORD:",
1650 },
1651 {
1652 name: "FalseStart-SkipServerSecondLeg-Implicit",
1653 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001654 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001655 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1656 NextProtos: []string{"foo"},
1657 Bugs: ProtocolBugs{
1658 SkipNewSessionTicket: true,
1659 SkipChangeCipherSpec: true,
1660 SkipFinished: true,
1661 },
1662 },
1663 flags: []string{
1664 "-implicit-handshake",
1665 "-false-start",
1666 "-handshake-never-done",
1667 "-advertise-alpn", "\x03foo",
1668 },
1669 shouldFail: true,
1670 expectedError: ":UNEXPECTED_RECORD:",
1671 },
1672 {
1673 testType: serverTest,
1674 name: "FailEarlyCallback",
1675 flags: []string{"-fail-early-callback"},
1676 shouldFail: true,
1677 expectedError: ":CONNECTION_REJECTED:",
1678 expectedLocalError: "remote error: access denied",
1679 },
1680 {
1681 name: "WrongMessageType",
1682 config: Config{
David Benjamin1edae6b2016-07-13 16:58:23 -04001683 MaxVersion: VersionTLS12,
1684 Bugs: ProtocolBugs{
1685 WrongCertificateMessageType: true,
1686 },
1687 },
1688 shouldFail: true,
1689 expectedError: ":UNEXPECTED_MESSAGE:",
1690 expectedLocalError: "remote error: unexpected message",
1691 },
1692 {
1693 name: "WrongMessageType-TLS13",
1694 config: Config{
Adam Langley7c803a62015-06-15 15:35:05 -07001695 Bugs: ProtocolBugs{
1696 WrongCertificateMessageType: true,
1697 },
1698 },
1699 shouldFail: true,
1700 expectedError: ":UNEXPECTED_MESSAGE:",
1701 expectedLocalError: "remote error: unexpected message",
1702 },
1703 {
1704 protocol: dtls,
1705 name: "WrongMessageType-DTLS",
1706 config: Config{
1707 Bugs: ProtocolBugs{
1708 WrongCertificateMessageType: true,
1709 },
1710 },
1711 shouldFail: true,
1712 expectedError: ":UNEXPECTED_MESSAGE:",
1713 expectedLocalError: "remote error: unexpected message",
1714 },
1715 {
1716 protocol: dtls,
1717 name: "FragmentMessageTypeMismatch-DTLS",
1718 config: Config{
1719 Bugs: ProtocolBugs{
1720 MaxHandshakeRecordLength: 2,
1721 FragmentMessageTypeMismatch: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":FRAGMENT_MISMATCH:",
1726 },
1727 {
1728 protocol: dtls,
1729 name: "FragmentMessageLengthMismatch-DTLS",
1730 config: Config{
1731 Bugs: ProtocolBugs{
1732 MaxHandshakeRecordLength: 2,
1733 FragmentMessageLengthMismatch: true,
1734 },
1735 },
1736 shouldFail: true,
1737 expectedError: ":FRAGMENT_MISMATCH:",
1738 },
1739 {
1740 protocol: dtls,
1741 name: "SplitFragments-Header-DTLS",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 SplitFragments: 2,
1745 },
1746 },
1747 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001748 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001749 },
1750 {
1751 protocol: dtls,
1752 name: "SplitFragments-Boundary-DTLS",
1753 config: Config{
1754 Bugs: ProtocolBugs{
1755 SplitFragments: dtlsRecordHeaderLen,
1756 },
1757 },
1758 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001759 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001760 },
1761 {
1762 protocol: dtls,
1763 name: "SplitFragments-Body-DTLS",
1764 config: Config{
1765 Bugs: ProtocolBugs{
1766 SplitFragments: dtlsRecordHeaderLen + 1,
1767 },
1768 },
1769 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001770 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001771 },
1772 {
1773 protocol: dtls,
1774 name: "SendEmptyFragments-DTLS",
1775 config: Config{
1776 Bugs: ProtocolBugs{
1777 SendEmptyFragments: true,
1778 },
1779 },
1780 },
1781 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001782 name: "BadFinished-Client",
1783 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001784 // TODO(davidben): Add a TLS 1.3 version of this.
1785 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 Bugs: ProtocolBugs{
1787 BadFinished: true,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":DIGEST_CHECK_FAILED:",
1792 },
1793 {
1794 testType: serverTest,
1795 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001797 // TODO(davidben): Add a TLS 1.3 version of this.
1798 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001799 Bugs: ProtocolBugs{
1800 BadFinished: true,
1801 },
1802 },
1803 shouldFail: true,
1804 expectedError: ":DIGEST_CHECK_FAILED:",
1805 },
1806 {
1807 name: "FalseStart-BadFinished",
1808 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001809 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1811 NextProtos: []string{"foo"},
1812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 ExpectFalseStart: true,
1815 },
1816 },
1817 flags: []string{
1818 "-false-start",
1819 "-handshake-never-done",
1820 "-advertise-alpn", "\x03foo",
1821 },
1822 shimWritesFirst: true,
1823 shouldFail: true,
1824 expectedError: ":DIGEST_CHECK_FAILED:",
1825 },
1826 {
1827 name: "NoFalseStart-NoALPN",
1828 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001829 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001830 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1831 Bugs: ProtocolBugs{
1832 ExpectFalseStart: true,
1833 AlertBeforeFalseStartTest: alertAccessDenied,
1834 },
1835 },
1836 flags: []string{
1837 "-false-start",
1838 },
1839 shimWritesFirst: true,
1840 shouldFail: true,
1841 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1842 expectedLocalError: "tls: peer did not false start: EOF",
1843 },
1844 {
1845 name: "NoFalseStart-NoAEAD",
1846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1849 NextProtos: []string{"foo"},
1850 Bugs: ProtocolBugs{
1851 ExpectFalseStart: true,
1852 AlertBeforeFalseStartTest: alertAccessDenied,
1853 },
1854 },
1855 flags: []string{
1856 "-false-start",
1857 "-advertise-alpn", "\x03foo",
1858 },
1859 shimWritesFirst: true,
1860 shouldFail: true,
1861 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1862 expectedLocalError: "tls: peer did not false start: EOF",
1863 },
1864 {
1865 name: "NoFalseStart-RSA",
1866 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001867 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001868 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1869 NextProtos: []string{"foo"},
1870 Bugs: ProtocolBugs{
1871 ExpectFalseStart: true,
1872 AlertBeforeFalseStartTest: alertAccessDenied,
1873 },
1874 },
1875 flags: []string{
1876 "-false-start",
1877 "-advertise-alpn", "\x03foo",
1878 },
1879 shimWritesFirst: true,
1880 shouldFail: true,
1881 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1882 expectedLocalError: "tls: peer did not false start: EOF",
1883 },
1884 {
1885 name: "NoFalseStart-DHE_RSA",
1886 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001887 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001888 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1889 NextProtos: []string{"foo"},
1890 Bugs: ProtocolBugs{
1891 ExpectFalseStart: true,
1892 AlertBeforeFalseStartTest: alertAccessDenied,
1893 },
1894 },
1895 flags: []string{
1896 "-false-start",
1897 "-advertise-alpn", "\x03foo",
1898 },
1899 shimWritesFirst: true,
1900 shouldFail: true,
1901 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1902 expectedLocalError: "tls: peer did not false start: EOF",
1903 },
1904 {
Adam Langley7c803a62015-06-15 15:35:05 -07001905 protocol: dtls,
1906 name: "SendSplitAlert-Sync",
1907 config: Config{
1908 Bugs: ProtocolBugs{
1909 SendSplitAlert: true,
1910 },
1911 },
1912 },
1913 {
1914 protocol: dtls,
1915 name: "SendSplitAlert-Async",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 SendSplitAlert: true,
1919 },
1920 },
1921 flags: []string{"-async"},
1922 },
1923 {
1924 protocol: dtls,
1925 name: "PackDTLSHandshake",
1926 config: Config{
1927 Bugs: ProtocolBugs{
1928 MaxHandshakeRecordLength: 2,
1929 PackHandshakeFragments: 20,
1930 PackHandshakeRecords: 200,
1931 },
1932 },
1933 },
1934 {
Adam Langley7c803a62015-06-15 15:35:05 -07001935 name: "SendEmptyRecords-Pass",
1936 sendEmptyRecords: 32,
1937 },
1938 {
1939 name: "SendEmptyRecords",
1940 sendEmptyRecords: 33,
1941 shouldFail: true,
1942 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1943 },
1944 {
1945 name: "SendEmptyRecords-Async",
1946 sendEmptyRecords: 33,
1947 flags: []string{"-async"},
1948 shouldFail: true,
1949 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1950 },
1951 {
1952 name: "SendWarningAlerts-Pass",
1953 sendWarningAlerts: 4,
1954 },
1955 {
1956 protocol: dtls,
1957 name: "SendWarningAlerts-DTLS-Pass",
1958 sendWarningAlerts: 4,
1959 },
1960 {
1961 name: "SendWarningAlerts",
1962 sendWarningAlerts: 5,
1963 shouldFail: true,
1964 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1965 },
1966 {
1967 name: "SendWarningAlerts-Async",
1968 sendWarningAlerts: 5,
1969 flags: []string{"-async"},
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1972 },
David Benjaminba4594a2015-06-18 18:36:15 -04001973 {
1974 name: "EmptySessionID",
1975 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001976 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001977 SessionTicketsDisabled: true,
1978 },
1979 noSessionCache: true,
1980 flags: []string{"-expect-no-session"},
1981 },
David Benjamin30789da2015-08-29 22:56:45 -04001982 {
1983 name: "Unclean-Shutdown",
1984 config: Config{
1985 Bugs: ProtocolBugs{
1986 NoCloseNotify: true,
1987 ExpectCloseNotify: true,
1988 },
1989 },
1990 shimShutsDown: true,
1991 flags: []string{"-check-close-notify"},
1992 shouldFail: true,
1993 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1994 },
1995 {
1996 name: "Unclean-Shutdown-Ignored",
1997 config: Config{
1998 Bugs: ProtocolBugs{
1999 NoCloseNotify: true,
2000 },
2001 },
2002 shimShutsDown: true,
2003 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002004 {
David Benjaminfa214e42016-05-10 17:03:10 -04002005 name: "Unclean-Shutdown-Alert",
2006 config: Config{
2007 Bugs: ProtocolBugs{
2008 SendAlertOnShutdown: alertDecompressionFailure,
2009 ExpectCloseNotify: true,
2010 },
2011 },
2012 shimShutsDown: true,
2013 flags: []string{"-check-close-notify"},
2014 shouldFail: true,
2015 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2016 },
2017 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002018 name: "LargePlaintext",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 SendLargeRecords: true,
2022 },
2023 },
2024 messageLen: maxPlaintext + 1,
2025 shouldFail: true,
2026 expectedError: ":DATA_LENGTH_TOO_LONG:",
2027 },
2028 {
2029 protocol: dtls,
2030 name: "LargePlaintext-DTLS",
2031 config: Config{
2032 Bugs: ProtocolBugs{
2033 SendLargeRecords: true,
2034 },
2035 },
2036 messageLen: maxPlaintext + 1,
2037 shouldFail: true,
2038 expectedError: ":DATA_LENGTH_TOO_LONG:",
2039 },
2040 {
2041 name: "LargeCiphertext",
2042 config: Config{
2043 Bugs: ProtocolBugs{
2044 SendLargeRecords: true,
2045 },
2046 },
2047 messageLen: maxPlaintext * 2,
2048 shouldFail: true,
2049 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2050 },
2051 {
2052 protocol: dtls,
2053 name: "LargeCiphertext-DTLS",
2054 config: Config{
2055 Bugs: ProtocolBugs{
2056 SendLargeRecords: true,
2057 },
2058 },
2059 messageLen: maxPlaintext * 2,
2060 // Unlike the other four cases, DTLS drops records which
2061 // are invalid before authentication, so the connection
2062 // does not fail.
2063 expectMessageDropped: true,
2064 },
David Benjamindd6fed92015-10-23 17:41:12 -04002065 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002066 // In TLS 1.2 and below, empty NewSessionTicket messages
2067 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002068 name: "SendEmptySessionTicket",
2069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002070 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002071 Bugs: ProtocolBugs{
2072 SendEmptySessionTicket: true,
2073 FailIfSessionOffered: true,
2074 },
2075 },
2076 flags: []string{"-expect-no-session"},
2077 resumeSession: true,
2078 expectResumeRejected: true,
2079 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002080 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002081 name: "BadHelloRequest-1",
2082 renegotiate: 1,
2083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002084 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002085 Bugs: ProtocolBugs{
2086 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2087 },
2088 },
2089 flags: []string{
2090 "-renegotiate-freely",
2091 "-expect-total-renegotiations", "1",
2092 },
2093 shouldFail: true,
2094 expectedError: ":BAD_HELLO_REQUEST:",
2095 },
2096 {
2097 name: "BadHelloRequest-2",
2098 renegotiate: 1,
2099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002100 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002101 Bugs: ProtocolBugs{
2102 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2103 },
2104 },
2105 flags: []string{
2106 "-renegotiate-freely",
2107 "-expect-total-renegotiations", "1",
2108 },
2109 shouldFail: true,
2110 expectedError: ":BAD_HELLO_REQUEST:",
2111 },
David Benjaminef1b0092015-11-21 14:05:44 -05002112 {
2113 testType: serverTest,
2114 name: "SupportTicketsWithSessionID",
2115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002116 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002117 SessionTicketsDisabled: true,
2118 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 resumeConfig: &Config{
2120 MaxVersion: VersionTLS12,
2121 },
David Benjaminef1b0092015-11-21 14:05:44 -05002122 resumeSession: true,
2123 },
Adam Langley7c803a62015-06-15 15:35:05 -07002124 }
Adam Langley7c803a62015-06-15 15:35:05 -07002125 testCases = append(testCases, basicTests...)
2126}
2127
Adam Langley95c29f32014-06-20 12:00:00 -07002128func addCipherSuiteTests() {
2129 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002130 const psk = "12345"
2131 const pskIdentity = "luggage combo"
2132
Adam Langley95c29f32014-06-20 12:00:00 -07002133 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002134 var certFile string
2135 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002136 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002137 cert = ecdsaP256Certificate
2138 certFile = ecdsaP256CertificateFile
2139 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002140 } else {
David Benjamin33863262016-07-08 17:20:12 -07002141 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002142 certFile = rsaCertificateFile
2143 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002144 }
2145
David Benjamin48cae082014-10-27 01:06:24 -04002146 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002147 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002148 flags = append(flags,
2149 "-psk", psk,
2150 "-psk-identity", pskIdentity)
2151 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002152 if hasComponent(suite.name, "NULL") {
2153 // NULL ciphers must be explicitly enabled.
2154 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2155 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002156 if hasComponent(suite.name, "CECPQ1") {
2157 // CECPQ1 ciphers must be explicitly enabled.
2158 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2159 }
David Benjamin48cae082014-10-27 01:06:24 -04002160
Adam Langley95c29f32014-06-20 12:00:00 -07002161 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002162 for _, protocol := range []protocol{tls, dtls} {
2163 var prefix string
2164 if protocol == dtls {
2165 if !ver.hasDTLS {
2166 continue
2167 }
2168 prefix = "D"
2169 }
Adam Langley95c29f32014-06-20 12:00:00 -07002170
David Benjamin0407e762016-06-17 16:41:18 -04002171 var shouldServerFail, shouldClientFail bool
2172 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2173 // BoringSSL clients accept ECDHE on SSLv3, but
2174 // a BoringSSL server will never select it
2175 // because the extension is missing.
2176 shouldServerFail = true
2177 }
2178 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2179 shouldClientFail = true
2180 shouldServerFail = true
2181 }
David Benjamin54c217c2016-07-13 12:35:25 -04002182 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002183 shouldClientFail = true
2184 shouldServerFail = true
2185 }
David Benjamin0407e762016-06-17 16:41:18 -04002186 if !isDTLSCipher(suite.name) && protocol == dtls {
2187 shouldClientFail = true
2188 shouldServerFail = true
2189 }
David Benjamin4298d772015-12-19 00:18:25 -05002190
David Benjamin0407e762016-06-17 16:41:18 -04002191 var expectedServerError, expectedClientError string
2192 if shouldServerFail {
2193 expectedServerError = ":NO_SHARED_CIPHER:"
2194 }
2195 if shouldClientFail {
2196 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2197 }
David Benjamin025b3d32014-07-01 19:53:04 -04002198
David Benjamin6fd297b2014-08-11 18:43:38 -04002199 testCases = append(testCases, testCase{
2200 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002201 protocol: protocol,
2202
2203 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002204 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002205 MinVersion: ver.version,
2206 MaxVersion: ver.version,
2207 CipherSuites: []uint16{suite.id},
2208 Certificates: []Certificate{cert},
2209 PreSharedKey: []byte(psk),
2210 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002211 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002212 EnableAllCiphers: shouldServerFail,
2213 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002214 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002215 },
2216 certFile: certFile,
2217 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002218 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002219 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002220 shouldFail: shouldServerFail,
2221 expectedError: expectedServerError,
2222 })
2223
2224 testCases = append(testCases, testCase{
2225 testType: clientTest,
2226 protocol: protocol,
2227 name: prefix + ver.name + "-" + suite.name + "-client",
2228 config: Config{
2229 MinVersion: ver.version,
2230 MaxVersion: ver.version,
2231 CipherSuites: []uint16{suite.id},
2232 Certificates: []Certificate{cert},
2233 PreSharedKey: []byte(psk),
2234 PreSharedKeyIdentity: pskIdentity,
2235 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002236 EnableAllCiphers: shouldClientFail,
2237 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002238 },
2239 },
2240 flags: flags,
2241 resumeSession: true,
2242 shouldFail: shouldClientFail,
2243 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002244 })
David Benjamin2c99d282015-09-01 10:23:00 -04002245
Nick Harper1fd39d82016-06-14 18:14:35 -07002246 if !shouldClientFail {
2247 // Ensure the maximum record size is accepted.
2248 testCases = append(testCases, testCase{
2249 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2250 config: Config{
2251 MinVersion: ver.version,
2252 MaxVersion: ver.version,
2253 CipherSuites: []uint16{suite.id},
2254 Certificates: []Certificate{cert},
2255 PreSharedKey: []byte(psk),
2256 PreSharedKeyIdentity: pskIdentity,
2257 },
2258 flags: flags,
2259 messageLen: maxPlaintext,
2260 })
2261 }
2262 }
David Benjamin2c99d282015-09-01 10:23:00 -04002263 }
Adam Langley95c29f32014-06-20 12:00:00 -07002264 }
Adam Langleya7997f12015-05-14 17:38:50 -07002265
2266 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002267 name: "NoSharedCipher",
2268 config: Config{
2269 // TODO(davidben): Add a TLS 1.3 version of this test.
2270 MaxVersion: VersionTLS12,
2271 CipherSuites: []uint16{},
2272 },
2273 shouldFail: true,
2274 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2275 })
2276
2277 testCases = append(testCases, testCase{
2278 name: "UnsupportedCipherSuite",
2279 config: Config{
2280 MaxVersion: VersionTLS12,
2281 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2282 Bugs: ProtocolBugs{
2283 IgnorePeerCipherPreferences: true,
2284 },
2285 },
2286 flags: []string{"-cipher", "DEFAULT:!RC4"},
2287 shouldFail: true,
2288 expectedError: ":WRONG_CIPHER_RETURNED:",
2289 })
2290
2291 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002292 name: "WeakDH",
2293 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002294 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002295 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2296 Bugs: ProtocolBugs{
2297 // This is a 1023-bit prime number, generated
2298 // with:
2299 // openssl gendh 1023 | openssl asn1parse -i
2300 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2301 },
2302 },
2303 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002304 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002305 })
Adam Langleycef75832015-09-03 14:51:12 -07002306
David Benjamincd24a392015-11-11 13:23:05 -08002307 testCases = append(testCases, testCase{
2308 name: "SillyDH",
2309 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002310 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002311 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2312 Bugs: ProtocolBugs{
2313 // This is a 4097-bit prime number, generated
2314 // with:
2315 // openssl gendh 4097 | openssl asn1parse -i
2316 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2317 },
2318 },
2319 shouldFail: true,
2320 expectedError: ":DH_P_TOO_LONG:",
2321 })
2322
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002323 // This test ensures that Diffie-Hellman public values are padded with
2324 // zeros so that they're the same length as the prime. This is to avoid
2325 // hitting a bug in yaSSL.
2326 testCases = append(testCases, testCase{
2327 testType: serverTest,
2328 name: "DHPublicValuePadded",
2329 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002330 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002331 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2332 Bugs: ProtocolBugs{
2333 RequireDHPublicValueLen: (1025 + 7) / 8,
2334 },
2335 },
2336 flags: []string{"-use-sparse-dh-prime"},
2337 })
David Benjamincd24a392015-11-11 13:23:05 -08002338
David Benjamin241ae832016-01-15 03:04:54 -05002339 // The server must be tolerant to bogus ciphers.
2340 const bogusCipher = 0x1234
2341 testCases = append(testCases, testCase{
2342 testType: serverTest,
2343 name: "UnknownCipher",
2344 config: Config{
2345 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2346 },
2347 })
2348
Adam Langleycef75832015-09-03 14:51:12 -07002349 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2350 // 1.1 specific cipher suite settings. A server is setup with the given
2351 // cipher lists and then a connection is made for each member of
2352 // expectations. The cipher suite that the server selects must match
2353 // the specified one.
2354 var versionSpecificCiphersTest = []struct {
2355 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2356 // expectations is a map from TLS version to cipher suite id.
2357 expectations map[uint16]uint16
2358 }{
2359 {
2360 // Test that the null case (where no version-specific ciphers are set)
2361 // works as expected.
2362 "RC4-SHA:AES128-SHA", // default ciphers
2363 "", // no ciphers specifically for TLS ≥ 1.0
2364 "", // no ciphers specifically for TLS ≥ 1.1
2365 map[uint16]uint16{
2366 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2367 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2368 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2369 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2370 },
2371 },
2372 {
2373 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2374 // cipher.
2375 "RC4-SHA:AES128-SHA", // default
2376 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2377 "", // no ciphers specifically for TLS ≥ 1.1
2378 map[uint16]uint16{
2379 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2380 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2381 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2382 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2383 },
2384 },
2385 {
2386 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2387 // cipher.
2388 "RC4-SHA:AES128-SHA", // default
2389 "", // no ciphers specifically for TLS ≥ 1.0
2390 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2391 map[uint16]uint16{
2392 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2393 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2394 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2395 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2396 },
2397 },
2398 {
2399 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2400 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2401 "RC4-SHA:AES128-SHA", // default
2402 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2403 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2404 map[uint16]uint16{
2405 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2406 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2407 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2408 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2409 },
2410 },
2411 }
2412
2413 for i, test := range versionSpecificCiphersTest {
2414 for version, expectedCipherSuite := range test.expectations {
2415 flags := []string{"-cipher", test.ciphersDefault}
2416 if len(test.ciphersTLS10) > 0 {
2417 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2418 }
2419 if len(test.ciphersTLS11) > 0 {
2420 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2421 }
2422
2423 testCases = append(testCases, testCase{
2424 testType: serverTest,
2425 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2426 config: Config{
2427 MaxVersion: version,
2428 MinVersion: version,
2429 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2430 },
2431 flags: flags,
2432 expectedCipher: expectedCipherSuite,
2433 })
2434 }
2435 }
Adam Langley95c29f32014-06-20 12:00:00 -07002436}
2437
2438func addBadECDSASignatureTests() {
2439 for badR := BadValue(1); badR < NumBadValues; badR++ {
2440 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002441 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002442 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2443 config: Config{
2444 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002445 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002446 Bugs: ProtocolBugs{
2447 BadECDSAR: badR,
2448 BadECDSAS: badS,
2449 },
2450 },
2451 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002452 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002453 })
2454 }
2455 }
2456}
2457
Adam Langley80842bd2014-06-20 12:00:00 -07002458func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002459 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002460 name: "MaxCBCPadding",
2461 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002462 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002463 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2464 Bugs: ProtocolBugs{
2465 MaxPadding: true,
2466 },
2467 },
2468 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2469 })
David Benjamin025b3d32014-07-01 19:53:04 -04002470 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002471 name: "BadCBCPadding",
2472 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002473 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2475 Bugs: ProtocolBugs{
2476 PaddingFirstByteBad: true,
2477 },
2478 },
2479 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002480 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002481 })
2482 // OpenSSL previously had an issue where the first byte of padding in
2483 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002484 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002485 name: "BadCBCPadding255",
2486 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002487 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002488 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2489 Bugs: ProtocolBugs{
2490 MaxPadding: true,
2491 PaddingFirstByteBadIf255: true,
2492 },
2493 },
2494 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2495 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002496 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002497 })
2498}
2499
Kenny Root7fdeaf12014-08-05 15:23:37 -07002500func addCBCSplittingTests() {
2501 testCases = append(testCases, testCase{
2502 name: "CBCRecordSplitting",
2503 config: Config{
2504 MaxVersion: VersionTLS10,
2505 MinVersion: VersionTLS10,
2506 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2507 },
David Benjaminac8302a2015-09-01 17:18:15 -04002508 messageLen: -1, // read until EOF
2509 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002510 flags: []string{
2511 "-async",
2512 "-write-different-record-sizes",
2513 "-cbc-record-splitting",
2514 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002515 })
2516 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002517 name: "CBCRecordSplittingPartialWrite",
2518 config: Config{
2519 MaxVersion: VersionTLS10,
2520 MinVersion: VersionTLS10,
2521 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2522 },
2523 messageLen: -1, // read until EOF
2524 flags: []string{
2525 "-async",
2526 "-write-different-record-sizes",
2527 "-cbc-record-splitting",
2528 "-partial-write",
2529 },
2530 })
2531}
2532
David Benjamin636293b2014-07-08 17:59:18 -04002533func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002534 // Add a dummy cert pool to stress certificate authority parsing.
2535 // TODO(davidben): Add tests that those values parse out correctly.
2536 certPool := x509.NewCertPool()
2537 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2538 if err != nil {
2539 panic(err)
2540 }
2541 certPool.AddCert(cert)
2542
David Benjamin636293b2014-07-08 17:59:18 -04002543 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002544 testCases = append(testCases, testCase{
2545 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002546 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002547 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002548 MinVersion: ver.version,
2549 MaxVersion: ver.version,
2550 ClientAuth: RequireAnyClientCert,
2551 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002552 },
2553 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002554 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2555 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002556 },
2557 })
2558 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002559 testType: serverTest,
2560 name: ver.name + "-Server-ClientAuth-RSA",
2561 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002562 MinVersion: ver.version,
2563 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002564 Certificates: []Certificate{rsaCertificate},
2565 },
2566 flags: []string{"-require-any-client-certificate"},
2567 })
David Benjamine098ec22014-08-27 23:13:20 -04002568 if ver.version != VersionSSL30 {
2569 testCases = append(testCases, testCase{
2570 testType: serverTest,
2571 name: ver.name + "-Server-ClientAuth-ECDSA",
2572 config: Config{
2573 MinVersion: ver.version,
2574 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002575 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002576 },
2577 flags: []string{"-require-any-client-certificate"},
2578 })
2579 testCases = append(testCases, testCase{
2580 testType: clientTest,
2581 name: ver.name + "-Client-ClientAuth-ECDSA",
2582 config: Config{
2583 MinVersion: ver.version,
2584 MaxVersion: ver.version,
2585 ClientAuth: RequireAnyClientCert,
2586 ClientCAs: certPool,
2587 },
2588 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002589 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2590 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002591 },
2592 })
2593 }
David Benjamin636293b2014-07-08 17:59:18 -04002594 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002595
Nick Harper1fd39d82016-06-14 18:14:35 -07002596 // TODO(davidben): These tests will need TLS 1.3 versions when the
2597 // handshake is separate.
2598
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002599 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002600 name: "NoClientCertificate",
2601 config: Config{
2602 MaxVersion: VersionTLS12,
2603 ClientAuth: RequireAnyClientCert,
2604 },
2605 shouldFail: true,
2606 expectedLocalError: "client didn't provide a certificate",
2607 })
2608
2609 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002610 testType: serverTest,
2611 name: "RequireAnyClientCertificate",
2612 config: Config{
2613 MaxVersion: VersionTLS12,
2614 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002615 flags: []string{"-require-any-client-certificate"},
2616 shouldFail: true,
2617 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2618 })
2619
2620 testCases = append(testCases, testCase{
2621 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002622 name: "RequireAnyClientCertificate-SSL3",
2623 config: Config{
2624 MaxVersion: VersionSSL30,
2625 },
2626 flags: []string{"-require-any-client-certificate"},
2627 shouldFail: true,
2628 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2629 })
2630
2631 testCases = append(testCases, testCase{
2632 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002633 name: "SkipClientCertificate",
2634 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002635 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002636 Bugs: ProtocolBugs{
2637 SkipClientCertificate: true,
2638 },
2639 },
2640 // Setting SSL_VERIFY_PEER allows anonymous clients.
2641 flags: []string{"-verify-peer"},
2642 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002643 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002644 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002645
2646 // Client auth is only legal in certificate-based ciphers.
2647 testCases = append(testCases, testCase{
2648 testType: clientTest,
2649 name: "ClientAuth-PSK",
2650 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002651 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002652 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2653 PreSharedKey: []byte("secret"),
2654 ClientAuth: RequireAnyClientCert,
2655 },
2656 flags: []string{
2657 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2658 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2659 "-psk", "secret",
2660 },
2661 shouldFail: true,
2662 expectedError: ":UNEXPECTED_MESSAGE:",
2663 })
2664 testCases = append(testCases, testCase{
2665 testType: clientTest,
2666 name: "ClientAuth-ECDHE_PSK",
2667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002668 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002669 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2670 PreSharedKey: []byte("secret"),
2671 ClientAuth: RequireAnyClientCert,
2672 },
2673 flags: []string{
2674 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2675 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2676 "-psk", "secret",
2677 },
2678 shouldFail: true,
2679 expectedError: ":UNEXPECTED_MESSAGE:",
2680 })
David Benjamin636293b2014-07-08 17:59:18 -04002681}
2682
Adam Langley75712922014-10-10 16:23:43 -07002683func addExtendedMasterSecretTests() {
2684 const expectEMSFlag = "-expect-extended-master-secret"
2685
2686 for _, with := range []bool{false, true} {
2687 prefix := "No"
2688 var flags []string
2689 if with {
2690 prefix = ""
2691 flags = []string{expectEMSFlag}
2692 }
2693
2694 for _, isClient := range []bool{false, true} {
2695 suffix := "-Server"
2696 testType := serverTest
2697 if isClient {
2698 suffix = "-Client"
2699 testType = clientTest
2700 }
2701
David Benjamin4c3ddf72016-06-29 18:13:53 -04002702 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2703 // test that the extension is irrelevant, but the API
2704 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002705 for _, ver := range tlsVersions {
2706 test := testCase{
2707 testType: testType,
2708 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2709 config: Config{
2710 MinVersion: ver.version,
2711 MaxVersion: ver.version,
2712 Bugs: ProtocolBugs{
2713 NoExtendedMasterSecret: !with,
2714 RequireExtendedMasterSecret: with,
2715 },
2716 },
David Benjamin48cae082014-10-27 01:06:24 -04002717 flags: flags,
2718 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002719 }
2720 if test.shouldFail {
2721 test.expectedLocalError = "extended master secret required but not supported by peer"
2722 }
2723 testCases = append(testCases, test)
2724 }
2725 }
2726 }
2727
Adam Langleyba5934b2015-06-02 10:50:35 -07002728 for _, isClient := range []bool{false, true} {
2729 for _, supportedInFirstConnection := range []bool{false, true} {
2730 for _, supportedInResumeConnection := range []bool{false, true} {
2731 boolToWord := func(b bool) string {
2732 if b {
2733 return "Yes"
2734 }
2735 return "No"
2736 }
2737 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2738 if isClient {
2739 suffix += "Client"
2740 } else {
2741 suffix += "Server"
2742 }
2743
2744 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002745 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002746 Bugs: ProtocolBugs{
2747 RequireExtendedMasterSecret: true,
2748 },
2749 }
2750
2751 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002752 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002753 Bugs: ProtocolBugs{
2754 NoExtendedMasterSecret: true,
2755 },
2756 }
2757
2758 test := testCase{
2759 name: "ExtendedMasterSecret-" + suffix,
2760 resumeSession: true,
2761 }
2762
2763 if !isClient {
2764 test.testType = serverTest
2765 }
2766
2767 if supportedInFirstConnection {
2768 test.config = supportedConfig
2769 } else {
2770 test.config = noSupportConfig
2771 }
2772
2773 if supportedInResumeConnection {
2774 test.resumeConfig = &supportedConfig
2775 } else {
2776 test.resumeConfig = &noSupportConfig
2777 }
2778
2779 switch suffix {
2780 case "YesToYes-Client", "YesToYes-Server":
2781 // When a session is resumed, it should
2782 // still be aware that its master
2783 // secret was generated via EMS and
2784 // thus it's safe to use tls-unique.
2785 test.flags = []string{expectEMSFlag}
2786 case "NoToYes-Server":
2787 // If an original connection did not
2788 // contain EMS, but a resumption
2789 // handshake does, then a server should
2790 // not resume the session.
2791 test.expectResumeRejected = true
2792 case "YesToNo-Server":
2793 // Resuming an EMS session without the
2794 // EMS extension should cause the
2795 // server to abort the connection.
2796 test.shouldFail = true
2797 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2798 case "NoToYes-Client":
2799 // A client should abort a connection
2800 // where the server resumed a non-EMS
2801 // session but echoed the EMS
2802 // extension.
2803 test.shouldFail = true
2804 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2805 case "YesToNo-Client":
2806 // A client should abort a connection
2807 // where the server didn't echo EMS
2808 // when the session used it.
2809 test.shouldFail = true
2810 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2811 }
2812
2813 testCases = append(testCases, test)
2814 }
2815 }
2816 }
Adam Langley75712922014-10-10 16:23:43 -07002817}
2818
David Benjamin582ba042016-07-07 12:33:25 -07002819type stateMachineTestConfig struct {
2820 protocol protocol
2821 async bool
2822 splitHandshake, packHandshakeFlight bool
2823}
2824
David Benjamin43ec06f2014-08-05 02:28:57 -04002825// Adds tests that try to cover the range of the handshake state machine, under
2826// various conditions. Some of these are redundant with other tests, but they
2827// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002828func addAllStateMachineCoverageTests() {
2829 for _, async := range []bool{false, true} {
2830 for _, protocol := range []protocol{tls, dtls} {
2831 addStateMachineCoverageTests(stateMachineTestConfig{
2832 protocol: protocol,
2833 async: async,
2834 })
2835 addStateMachineCoverageTests(stateMachineTestConfig{
2836 protocol: protocol,
2837 async: async,
2838 splitHandshake: true,
2839 })
2840 if protocol == tls {
2841 addStateMachineCoverageTests(stateMachineTestConfig{
2842 protocol: protocol,
2843 async: async,
2844 packHandshakeFlight: true,
2845 })
2846 }
2847 }
2848 }
2849}
2850
2851func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002852 var tests []testCase
2853
2854 // Basic handshake, with resumption. Client and server,
2855 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002856 //
2857 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2858 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002859 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002860 name: "Basic-Client",
2861 config: Config{
2862 MaxVersion: VersionTLS12,
2863 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002864 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002865 // Ensure session tickets are used, not session IDs.
2866 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002867 })
2868 tests = append(tests, testCase{
2869 name: "Basic-Client-RenewTicket",
2870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002871 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002872 Bugs: ProtocolBugs{
2873 RenewTicketOnResume: true,
2874 },
2875 },
David Benjaminba4594a2015-06-18 18:36:15 -04002876 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002877 resumeSession: true,
2878 })
2879 tests = append(tests, testCase{
2880 name: "Basic-Client-NoTicket",
2881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002882 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002883 SessionTicketsDisabled: true,
2884 },
2885 resumeSession: true,
2886 })
2887 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002888 name: "Basic-Client-Implicit",
2889 config: Config{
2890 MaxVersion: VersionTLS12,
2891 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002892 flags: []string{"-implicit-handshake"},
2893 resumeSession: true,
2894 })
2895 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002896 testType: serverTest,
2897 name: "Basic-Server",
2898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002899 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002900 Bugs: ProtocolBugs{
2901 RequireSessionTickets: true,
2902 },
2903 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002904 resumeSession: true,
2905 })
2906 tests = append(tests, testCase{
2907 testType: serverTest,
2908 name: "Basic-Server-NoTickets",
2909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002910 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002911 SessionTicketsDisabled: true,
2912 },
2913 resumeSession: true,
2914 })
2915 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002916 testType: serverTest,
2917 name: "Basic-Server-Implicit",
2918 config: Config{
2919 MaxVersion: VersionTLS12,
2920 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002921 flags: []string{"-implicit-handshake"},
2922 resumeSession: true,
2923 })
2924 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002925 testType: serverTest,
2926 name: "Basic-Server-EarlyCallback",
2927 config: Config{
2928 MaxVersion: VersionTLS12,
2929 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002930 flags: []string{"-use-early-callback"},
2931 resumeSession: true,
2932 })
2933
2934 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002935 //
2936 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002937 tests = append(tests, testCase{
2938 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002939 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002941 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002942 ClientAuth: RequestClientCert,
2943 },
2944 })
2945 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002946 testType: serverTest,
2947 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002948 config: Config{
2949 MaxVersion: VersionTLS12,
2950 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002951 // Setting SSL_VERIFY_PEER allows anonymous clients.
2952 flags: []string{"-verify-peer"},
2953 })
David Benjamin582ba042016-07-07 12:33:25 -07002954 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002955 tests = append(tests, testCase{
2956 testType: clientTest,
2957 name: "ClientAuth-NoCertificate-Client-SSL3",
2958 config: Config{
2959 MaxVersion: VersionSSL30,
2960 ClientAuth: RequestClientCert,
2961 },
2962 })
2963 tests = append(tests, testCase{
2964 testType: serverTest,
2965 name: "ClientAuth-NoCertificate-Server-SSL3",
2966 config: Config{
2967 MaxVersion: VersionSSL30,
2968 },
2969 // Setting SSL_VERIFY_PEER allows anonymous clients.
2970 flags: []string{"-verify-peer"},
2971 })
2972 }
2973 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002974 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002975 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002977 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002978 ClientAuth: RequireAnyClientCert,
2979 },
2980 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002981 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2982 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002983 },
2984 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002985 tests = append(tests, testCase{
2986 testType: clientTest,
2987 name: "ClientAuth-ECDSA-Client",
2988 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002989 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002990 ClientAuth: RequireAnyClientCert,
2991 },
2992 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002993 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2994 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002995 },
2996 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002997 tests = append(tests, testCase{
2998 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04002999 name: "ClientAuth-NoCertificate-OldCallback",
3000 config: Config{
3001 MaxVersion: VersionTLS12,
3002 ClientAuth: RequestClientCert,
3003 },
3004 flags: []string{"-use-old-client-cert-callback"},
3005 })
3006 tests = append(tests, testCase{
3007 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003008 name: "ClientAuth-OldCallback",
3009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003010 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003011 ClientAuth: RequireAnyClientCert,
3012 },
3013 flags: []string{
3014 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3015 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3016 "-use-old-client-cert-callback",
3017 },
3018 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003019 tests = append(tests, testCase{
3020 testType: serverTest,
3021 name: "ClientAuth-Server",
3022 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003023 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003024 Certificates: []Certificate{rsaCertificate},
3025 },
3026 flags: []string{"-require-any-client-certificate"},
3027 })
3028
David Benjamin4c3ddf72016-06-29 18:13:53 -04003029 // Test each key exchange on the server side for async keys.
3030 //
3031 // TODO(davidben): Add TLS 1.3 versions of these.
3032 tests = append(tests, testCase{
3033 testType: serverTest,
3034 name: "Basic-Server-RSA",
3035 config: Config{
3036 MaxVersion: VersionTLS12,
3037 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3038 },
3039 flags: []string{
3040 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3041 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3042 },
3043 })
3044 tests = append(tests, testCase{
3045 testType: serverTest,
3046 name: "Basic-Server-ECDHE-RSA",
3047 config: Config{
3048 MaxVersion: VersionTLS12,
3049 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3050 },
3051 flags: []string{
3052 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3053 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3054 },
3055 })
3056 tests = append(tests, testCase{
3057 testType: serverTest,
3058 name: "Basic-Server-ECDHE-ECDSA",
3059 config: Config{
3060 MaxVersion: VersionTLS12,
3061 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3062 },
3063 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003064 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3065 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003066 },
3067 })
3068
David Benjamin760b1dd2015-05-15 23:33:48 -04003069 // No session ticket support; server doesn't send NewSessionTicket.
3070 tests = append(tests, testCase{
3071 name: "SessionTicketsDisabled-Client",
3072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003073 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003074 SessionTicketsDisabled: true,
3075 },
3076 })
3077 tests = append(tests, testCase{
3078 testType: serverTest,
3079 name: "SessionTicketsDisabled-Server",
3080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003081 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003082 SessionTicketsDisabled: true,
3083 },
3084 })
3085
3086 // Skip ServerKeyExchange in PSK key exchange if there's no
3087 // identity hint.
3088 tests = append(tests, testCase{
3089 name: "EmptyPSKHint-Client",
3090 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003091 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003092 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3093 PreSharedKey: []byte("secret"),
3094 },
3095 flags: []string{"-psk", "secret"},
3096 })
3097 tests = append(tests, testCase{
3098 testType: serverTest,
3099 name: "EmptyPSKHint-Server",
3100 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003101 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003102 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3103 PreSharedKey: []byte("secret"),
3104 },
3105 flags: []string{"-psk", "secret"},
3106 })
3107
David Benjamin4c3ddf72016-06-29 18:13:53 -04003108 // OCSP stapling tests.
3109 //
3110 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003111 tests = append(tests, testCase{
3112 testType: clientTest,
3113 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 config: Config{
3115 MaxVersion: VersionTLS12,
3116 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003117 flags: []string{
3118 "-enable-ocsp-stapling",
3119 "-expect-ocsp-response",
3120 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003121 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003122 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003123 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003124 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003125 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003126 testType: serverTest,
3127 name: "OCSPStapling-Server",
3128 config: Config{
3129 MaxVersion: VersionTLS12,
3130 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003131 expectedOCSPResponse: testOCSPResponse,
3132 flags: []string{
3133 "-ocsp-response",
3134 base64.StdEncoding.EncodeToString(testOCSPResponse),
3135 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003136 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003137 })
3138
David Benjamin4c3ddf72016-06-29 18:13:53 -04003139 // Certificate verification tests.
3140 //
3141 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003142 tests = append(tests, testCase{
3143 testType: clientTest,
3144 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003145 config: Config{
3146 MaxVersion: VersionTLS12,
3147 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003148 flags: []string{
3149 "-verify-peer",
3150 },
3151 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003152 tests = append(tests, testCase{
3153 testType: clientTest,
3154 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003155 config: Config{
3156 MaxVersion: VersionTLS12,
3157 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003158 flags: []string{
3159 "-verify-fail",
3160 "-verify-peer",
3161 },
3162 shouldFail: true,
3163 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3164 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003165 tests = append(tests, testCase{
3166 testType: clientTest,
3167 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003168 config: Config{
3169 MaxVersion: VersionTLS12,
3170 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003171 flags: []string{
3172 "-verify-fail",
3173 "-expect-verify-result",
3174 },
3175 })
3176
David Benjamin582ba042016-07-07 12:33:25 -07003177 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003178 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003179 name: "Renegotiate-Client",
3180 config: Config{
3181 MaxVersion: VersionTLS12,
3182 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003183 renegotiate: 1,
3184 flags: []string{
3185 "-renegotiate-freely",
3186 "-expect-total-renegotiations", "1",
3187 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003188 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003189
David Benjamin760b1dd2015-05-15 23:33:48 -04003190 // NPN on client and server; results in post-handshake message.
3191 tests = append(tests, testCase{
3192 name: "NPN-Client",
3193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003194 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003195 NextProtos: []string{"foo"},
3196 },
3197 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003198 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003199 expectedNextProto: "foo",
3200 expectedNextProtoType: npn,
3201 })
3202 tests = append(tests, testCase{
3203 testType: serverTest,
3204 name: "NPN-Server",
3205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003206 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003207 NextProtos: []string{"bar"},
3208 },
3209 flags: []string{
3210 "-advertise-npn", "\x03foo\x03bar\x03baz",
3211 "-expect-next-proto", "bar",
3212 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003213 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003214 expectedNextProto: "bar",
3215 expectedNextProtoType: npn,
3216 })
3217
3218 // TODO(davidben): Add tests for when False Start doesn't trigger.
3219
3220 // Client does False Start and negotiates NPN.
3221 tests = append(tests, testCase{
3222 name: "FalseStart",
3223 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003224 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003225 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3226 NextProtos: []string{"foo"},
3227 Bugs: ProtocolBugs{
3228 ExpectFalseStart: true,
3229 },
3230 },
3231 flags: []string{
3232 "-false-start",
3233 "-select-next-proto", "foo",
3234 },
3235 shimWritesFirst: true,
3236 resumeSession: true,
3237 })
3238
3239 // Client does False Start and negotiates ALPN.
3240 tests = append(tests, testCase{
3241 name: "FalseStart-ALPN",
3242 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003243 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003244 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3245 NextProtos: []string{"foo"},
3246 Bugs: ProtocolBugs{
3247 ExpectFalseStart: true,
3248 },
3249 },
3250 flags: []string{
3251 "-false-start",
3252 "-advertise-alpn", "\x03foo",
3253 },
3254 shimWritesFirst: true,
3255 resumeSession: true,
3256 })
3257
3258 // Client does False Start but doesn't explicitly call
3259 // SSL_connect.
3260 tests = append(tests, testCase{
3261 name: "FalseStart-Implicit",
3262 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003263 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003264 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3265 NextProtos: []string{"foo"},
3266 },
3267 flags: []string{
3268 "-implicit-handshake",
3269 "-false-start",
3270 "-advertise-alpn", "\x03foo",
3271 },
3272 })
3273
3274 // False Start without session tickets.
3275 tests = append(tests, testCase{
3276 name: "FalseStart-SessionTicketsDisabled",
3277 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003278 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003279 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3280 NextProtos: []string{"foo"},
3281 SessionTicketsDisabled: true,
3282 Bugs: ProtocolBugs{
3283 ExpectFalseStart: true,
3284 },
3285 },
3286 flags: []string{
3287 "-false-start",
3288 "-select-next-proto", "foo",
3289 },
3290 shimWritesFirst: true,
3291 })
3292
Adam Langleydf759b52016-07-11 15:24:37 -07003293 tests = append(tests, testCase{
3294 name: "FalseStart-CECPQ1",
3295 config: Config{
3296 MaxVersion: VersionTLS12,
3297 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3298 NextProtos: []string{"foo"},
3299 Bugs: ProtocolBugs{
3300 ExpectFalseStart: true,
3301 },
3302 },
3303 flags: []string{
3304 "-false-start",
3305 "-cipher", "DEFAULT:kCECPQ1",
3306 "-select-next-proto", "foo",
3307 },
3308 shimWritesFirst: true,
3309 resumeSession: true,
3310 })
3311
David Benjamin760b1dd2015-05-15 23:33:48 -04003312 // Server parses a V2ClientHello.
3313 tests = append(tests, testCase{
3314 testType: serverTest,
3315 name: "SendV2ClientHello",
3316 config: Config{
3317 // Choose a cipher suite that does not involve
3318 // elliptic curves, so no extensions are
3319 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003320 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003321 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3322 Bugs: ProtocolBugs{
3323 SendV2ClientHello: true,
3324 },
3325 },
3326 })
3327
3328 // Client sends a Channel ID.
3329 tests = append(tests, testCase{
3330 name: "ChannelID-Client",
3331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003332 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003333 RequestChannelID: true,
3334 },
Adam Langley7c803a62015-06-15 15:35:05 -07003335 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003336 resumeSession: true,
3337 expectChannelID: true,
3338 })
3339
3340 // Server accepts a Channel ID.
3341 tests = append(tests, testCase{
3342 testType: serverTest,
3343 name: "ChannelID-Server",
3344 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003345 MaxVersion: VersionTLS12,
3346 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003347 },
3348 flags: []string{
3349 "-expect-channel-id",
3350 base64.StdEncoding.EncodeToString(channelIDBytes),
3351 },
3352 resumeSession: true,
3353 expectChannelID: true,
3354 })
David Benjamin30789da2015-08-29 22:56:45 -04003355
David Benjaminf8fcdf32016-06-08 15:56:13 -04003356 // Channel ID and NPN at the same time, to ensure their relative
3357 // ordering is correct.
3358 tests = append(tests, testCase{
3359 name: "ChannelID-NPN-Client",
3360 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003361 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003362 RequestChannelID: true,
3363 NextProtos: []string{"foo"},
3364 },
3365 flags: []string{
3366 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3367 "-select-next-proto", "foo",
3368 },
3369 resumeSession: true,
3370 expectChannelID: true,
3371 expectedNextProto: "foo",
3372 expectedNextProtoType: npn,
3373 })
3374 tests = append(tests, testCase{
3375 testType: serverTest,
3376 name: "ChannelID-NPN-Server",
3377 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003378 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003379 ChannelID: channelIDKey,
3380 NextProtos: []string{"bar"},
3381 },
3382 flags: []string{
3383 "-expect-channel-id",
3384 base64.StdEncoding.EncodeToString(channelIDBytes),
3385 "-advertise-npn", "\x03foo\x03bar\x03baz",
3386 "-expect-next-proto", "bar",
3387 },
3388 resumeSession: true,
3389 expectChannelID: true,
3390 expectedNextProto: "bar",
3391 expectedNextProtoType: npn,
3392 })
3393
David Benjamin30789da2015-08-29 22:56:45 -04003394 // Bidirectional shutdown with the runner initiating.
3395 tests = append(tests, testCase{
3396 name: "Shutdown-Runner",
3397 config: Config{
3398 Bugs: ProtocolBugs{
3399 ExpectCloseNotify: true,
3400 },
3401 },
3402 flags: []string{"-check-close-notify"},
3403 })
3404
3405 // Bidirectional shutdown with the shim initiating. The runner,
3406 // in the meantime, sends garbage before the close_notify which
3407 // the shim must ignore.
3408 tests = append(tests, testCase{
3409 name: "Shutdown-Shim",
3410 config: Config{
3411 Bugs: ProtocolBugs{
3412 ExpectCloseNotify: true,
3413 },
3414 },
3415 shimShutsDown: true,
3416 sendEmptyRecords: 1,
3417 sendWarningAlerts: 1,
3418 flags: []string{"-check-close-notify"},
3419 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003420 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003421 // TODO(davidben): DTLS 1.3 will want a similar thing for
3422 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003423 tests = append(tests, testCase{
3424 name: "SkipHelloVerifyRequest",
3425 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003426 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003427 Bugs: ProtocolBugs{
3428 SkipHelloVerifyRequest: true,
3429 },
3430 },
3431 })
3432 }
3433
David Benjamin760b1dd2015-05-15 23:33:48 -04003434 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003435 test.protocol = config.protocol
3436 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003437 test.name += "-DTLS"
3438 }
David Benjamin582ba042016-07-07 12:33:25 -07003439 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003440 test.name += "-Async"
3441 test.flags = append(test.flags, "-async")
3442 } else {
3443 test.name += "-Sync"
3444 }
David Benjamin582ba042016-07-07 12:33:25 -07003445 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003446 test.name += "-SplitHandshakeRecords"
3447 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003448 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003449 test.config.Bugs.MaxPacketLength = 256
3450 test.flags = append(test.flags, "-mtu", "256")
3451 }
3452 }
David Benjamin582ba042016-07-07 12:33:25 -07003453 if config.packHandshakeFlight {
3454 test.name += "-PackHandshakeFlight"
3455 test.config.Bugs.PackHandshakeFlight = true
3456 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003457 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003458 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003459}
3460
Adam Langley524e7172015-02-20 16:04:00 -08003461func addDDoSCallbackTests() {
3462 // DDoS callback.
3463
3464 for _, resume := range []bool{false, true} {
3465 suffix := "Resume"
3466 if resume {
3467 suffix = "No" + suffix
3468 }
3469
David Benjamin4c3ddf72016-06-29 18:13:53 -04003470 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3471
Adam Langley524e7172015-02-20 16:04:00 -08003472 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003473 testType: serverTest,
3474 name: "Server-DDoS-OK-" + suffix,
3475 config: Config{
3476 MaxVersion: VersionTLS12,
3477 },
Adam Langley524e7172015-02-20 16:04:00 -08003478 flags: []string{"-install-ddos-callback"},
3479 resumeSession: resume,
3480 })
3481
3482 failFlag := "-fail-ddos-callback"
3483 if resume {
3484 failFlag = "-fail-second-ddos-callback"
3485 }
3486 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003487 testType: serverTest,
3488 name: "Server-DDoS-Reject-" + suffix,
3489 config: Config{
3490 MaxVersion: VersionTLS12,
3491 },
Adam Langley524e7172015-02-20 16:04:00 -08003492 flags: []string{"-install-ddos-callback", failFlag},
3493 resumeSession: resume,
3494 shouldFail: true,
3495 expectedError: ":CONNECTION_REJECTED:",
3496 })
3497 }
3498}
3499
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003500func addVersionNegotiationTests() {
3501 for i, shimVers := range tlsVersions {
3502 // Assemble flags to disable all newer versions on the shim.
3503 var flags []string
3504 for _, vers := range tlsVersions[i+1:] {
3505 flags = append(flags, vers.flag)
3506 }
3507
3508 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003509 protocols := []protocol{tls}
3510 if runnerVers.hasDTLS && shimVers.hasDTLS {
3511 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003512 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003513 for _, protocol := range protocols {
3514 expectedVersion := shimVers.version
3515 if runnerVers.version < shimVers.version {
3516 expectedVersion = runnerVers.version
3517 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003518
David Benjamin8b8c0062014-11-23 02:47:52 -05003519 suffix := shimVers.name + "-" + runnerVers.name
3520 if protocol == dtls {
3521 suffix += "-DTLS"
3522 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003523
David Benjamin1eb367c2014-12-12 18:17:51 -05003524 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3525
David Benjamin1e29a6b2014-12-10 02:27:24 -05003526 clientVers := shimVers.version
3527 if clientVers > VersionTLS10 {
3528 clientVers = VersionTLS10
3529 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003530 serverVers := expectedVersion
3531 if expectedVersion >= VersionTLS13 {
3532 serverVers = VersionTLS10
3533 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003534 testCases = append(testCases, testCase{
3535 protocol: protocol,
3536 testType: clientTest,
3537 name: "VersionNegotiation-Client-" + suffix,
3538 config: Config{
3539 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003540 Bugs: ProtocolBugs{
3541 ExpectInitialRecordVersion: clientVers,
3542 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003543 },
3544 flags: flags,
3545 expectedVersion: expectedVersion,
3546 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003547 testCases = append(testCases, testCase{
3548 protocol: protocol,
3549 testType: clientTest,
3550 name: "VersionNegotiation-Client2-" + suffix,
3551 config: Config{
3552 MaxVersion: runnerVers.version,
3553 Bugs: ProtocolBugs{
3554 ExpectInitialRecordVersion: clientVers,
3555 },
3556 },
3557 flags: []string{"-max-version", shimVersFlag},
3558 expectedVersion: expectedVersion,
3559 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003560
3561 testCases = append(testCases, testCase{
3562 protocol: protocol,
3563 testType: serverTest,
3564 name: "VersionNegotiation-Server-" + suffix,
3565 config: Config{
3566 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003567 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003568 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003569 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003570 },
3571 flags: flags,
3572 expectedVersion: expectedVersion,
3573 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003574 testCases = append(testCases, testCase{
3575 protocol: protocol,
3576 testType: serverTest,
3577 name: "VersionNegotiation-Server2-" + suffix,
3578 config: Config{
3579 MaxVersion: runnerVers.version,
3580 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003581 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003582 },
3583 },
3584 flags: []string{"-max-version", shimVersFlag},
3585 expectedVersion: expectedVersion,
3586 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003587 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003588 }
3589 }
David Benjamin95c69562016-06-29 18:15:03 -04003590
3591 // Test for version tolerance.
3592 testCases = append(testCases, testCase{
3593 testType: serverTest,
3594 name: "MinorVersionTolerance",
3595 config: Config{
3596 Bugs: ProtocolBugs{
3597 SendClientVersion: 0x03ff,
3598 },
3599 },
3600 expectedVersion: VersionTLS13,
3601 })
3602 testCases = append(testCases, testCase{
3603 testType: serverTest,
3604 name: "MajorVersionTolerance",
3605 config: Config{
3606 Bugs: ProtocolBugs{
3607 SendClientVersion: 0x0400,
3608 },
3609 },
3610 expectedVersion: VersionTLS13,
3611 })
3612 testCases = append(testCases, testCase{
3613 protocol: dtls,
3614 testType: serverTest,
3615 name: "MinorVersionTolerance-DTLS",
3616 config: Config{
3617 Bugs: ProtocolBugs{
3618 SendClientVersion: 0x03ff,
3619 },
3620 },
3621 expectedVersion: VersionTLS12,
3622 })
3623 testCases = append(testCases, testCase{
3624 protocol: dtls,
3625 testType: serverTest,
3626 name: "MajorVersionTolerance-DTLS",
3627 config: Config{
3628 Bugs: ProtocolBugs{
3629 SendClientVersion: 0x0400,
3630 },
3631 },
3632 expectedVersion: VersionTLS12,
3633 })
3634
3635 // Test that versions below 3.0 are rejected.
3636 testCases = append(testCases, testCase{
3637 testType: serverTest,
3638 name: "VersionTooLow",
3639 config: Config{
3640 Bugs: ProtocolBugs{
3641 SendClientVersion: 0x0200,
3642 },
3643 },
3644 shouldFail: true,
3645 expectedError: ":UNSUPPORTED_PROTOCOL:",
3646 })
3647 testCases = append(testCases, testCase{
3648 protocol: dtls,
3649 testType: serverTest,
3650 name: "VersionTooLow-DTLS",
3651 config: Config{
3652 Bugs: ProtocolBugs{
3653 // 0x0201 is the lowest version expressable in
3654 // DTLS.
3655 SendClientVersion: 0x0201,
3656 },
3657 },
3658 shouldFail: true,
3659 expectedError: ":UNSUPPORTED_PROTOCOL:",
3660 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003661
3662 // Test TLS 1.3's downgrade signal.
3663 testCases = append(testCases, testCase{
3664 name: "Downgrade-TLS12-Client",
3665 config: Config{
3666 Bugs: ProtocolBugs{
3667 NegotiateVersion: VersionTLS12,
3668 },
3669 },
3670 shouldFail: true,
3671 expectedError: ":DOWNGRADE_DETECTED:",
3672 })
3673 testCases = append(testCases, testCase{
3674 testType: serverTest,
3675 name: "Downgrade-TLS12-Server",
3676 config: Config{
3677 Bugs: ProtocolBugs{
3678 SendClientVersion: VersionTLS12,
3679 },
3680 },
3681 shouldFail: true,
3682 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3683 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003684}
3685
David Benjaminaccb4542014-12-12 23:44:33 -05003686func addMinimumVersionTests() {
3687 for i, shimVers := range tlsVersions {
3688 // Assemble flags to disable all older versions on the shim.
3689 var flags []string
3690 for _, vers := range tlsVersions[:i] {
3691 flags = append(flags, vers.flag)
3692 }
3693
3694 for _, runnerVers := range tlsVersions {
3695 protocols := []protocol{tls}
3696 if runnerVers.hasDTLS && shimVers.hasDTLS {
3697 protocols = append(protocols, dtls)
3698 }
3699 for _, protocol := range protocols {
3700 suffix := shimVers.name + "-" + runnerVers.name
3701 if protocol == dtls {
3702 suffix += "-DTLS"
3703 }
3704 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3705
David Benjaminaccb4542014-12-12 23:44:33 -05003706 var expectedVersion uint16
3707 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003708 var expectedClientError, expectedServerError string
3709 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003710 if runnerVers.version >= shimVers.version {
3711 expectedVersion = runnerVers.version
3712 } else {
3713 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003714 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3715 expectedServerLocalError = "remote error: protocol version not supported"
3716 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3717 // If the client's minimum version is TLS 1.3 and the runner's
3718 // maximum is below TLS 1.2, the runner will fail to select a
3719 // cipher before the shim rejects the selected version.
3720 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3721 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3722 } else {
3723 expectedClientError = expectedServerError
3724 expectedClientLocalError = expectedServerLocalError
3725 }
David Benjaminaccb4542014-12-12 23:44:33 -05003726 }
3727
3728 testCases = append(testCases, testCase{
3729 protocol: protocol,
3730 testType: clientTest,
3731 name: "MinimumVersion-Client-" + suffix,
3732 config: Config{
3733 MaxVersion: runnerVers.version,
3734 },
David Benjamin87909c02014-12-13 01:55:01 -05003735 flags: flags,
3736 expectedVersion: expectedVersion,
3737 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003738 expectedError: expectedClientError,
3739 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003740 })
3741 testCases = append(testCases, testCase{
3742 protocol: protocol,
3743 testType: clientTest,
3744 name: "MinimumVersion-Client2-" + suffix,
3745 config: Config{
3746 MaxVersion: runnerVers.version,
3747 },
David Benjamin87909c02014-12-13 01:55:01 -05003748 flags: []string{"-min-version", shimVersFlag},
3749 expectedVersion: expectedVersion,
3750 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003751 expectedError: expectedClientError,
3752 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003753 })
3754
3755 testCases = append(testCases, testCase{
3756 protocol: protocol,
3757 testType: serverTest,
3758 name: "MinimumVersion-Server-" + suffix,
3759 config: Config{
3760 MaxVersion: runnerVers.version,
3761 },
David Benjamin87909c02014-12-13 01:55:01 -05003762 flags: flags,
3763 expectedVersion: expectedVersion,
3764 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003765 expectedError: expectedServerError,
3766 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003767 })
3768 testCases = append(testCases, testCase{
3769 protocol: protocol,
3770 testType: serverTest,
3771 name: "MinimumVersion-Server2-" + suffix,
3772 config: Config{
3773 MaxVersion: runnerVers.version,
3774 },
David Benjamin87909c02014-12-13 01:55:01 -05003775 flags: []string{"-min-version", shimVersFlag},
3776 expectedVersion: expectedVersion,
3777 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003778 expectedError: expectedServerError,
3779 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003780 })
3781 }
3782 }
3783 }
3784}
3785
David Benjamine78bfde2014-09-06 12:45:15 -04003786func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003787 // TODO(davidben): Extensions, where applicable, all move their server
3788 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3789 // tests for both. Also test interaction with 0-RTT when implemented.
3790
David Benjamine78bfde2014-09-06 12:45:15 -04003791 testCases = append(testCases, testCase{
3792 testType: clientTest,
3793 name: "DuplicateExtensionClient",
3794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003795 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003796 Bugs: ProtocolBugs{
3797 DuplicateExtension: true,
3798 },
3799 },
3800 shouldFail: true,
3801 expectedLocalError: "remote error: error decoding message",
3802 })
3803 testCases = append(testCases, testCase{
3804 testType: serverTest,
3805 name: "DuplicateExtensionServer",
3806 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003807 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003808 Bugs: ProtocolBugs{
3809 DuplicateExtension: true,
3810 },
3811 },
3812 shouldFail: true,
3813 expectedLocalError: "remote error: error decoding message",
3814 })
3815 testCases = append(testCases, testCase{
3816 testType: clientTest,
3817 name: "ServerNameExtensionClient",
3818 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003819 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003820 Bugs: ProtocolBugs{
3821 ExpectServerName: "example.com",
3822 },
3823 },
3824 flags: []string{"-host-name", "example.com"},
3825 })
3826 testCases = append(testCases, testCase{
3827 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003828 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003829 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003830 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003831 Bugs: ProtocolBugs{
3832 ExpectServerName: "mismatch.com",
3833 },
3834 },
3835 flags: []string{"-host-name", "example.com"},
3836 shouldFail: true,
3837 expectedLocalError: "tls: unexpected server name",
3838 })
3839 testCases = append(testCases, testCase{
3840 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003841 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003843 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003844 Bugs: ProtocolBugs{
3845 ExpectServerName: "missing.com",
3846 },
3847 },
3848 shouldFail: true,
3849 expectedLocalError: "tls: unexpected server name",
3850 })
3851 testCases = append(testCases, testCase{
3852 testType: serverTest,
3853 name: "ServerNameExtensionServer",
3854 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003855 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003856 ServerName: "example.com",
3857 },
3858 flags: []string{"-expect-server-name", "example.com"},
3859 resumeSession: true,
3860 })
David Benjaminae2888f2014-09-06 12:58:58 -04003861 testCases = append(testCases, testCase{
3862 testType: clientTest,
3863 name: "ALPNClient",
3864 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003865 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003866 NextProtos: []string{"foo"},
3867 },
3868 flags: []string{
3869 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3870 "-expect-alpn", "foo",
3871 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003872 expectedNextProto: "foo",
3873 expectedNextProtoType: alpn,
3874 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003875 })
3876 testCases = append(testCases, testCase{
3877 testType: serverTest,
3878 name: "ALPNServer",
3879 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003880 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003881 NextProtos: []string{"foo", "bar", "baz"},
3882 },
3883 flags: []string{
3884 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3885 "-select-alpn", "foo",
3886 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003887 expectedNextProto: "foo",
3888 expectedNextProtoType: alpn,
3889 resumeSession: true,
3890 })
David Benjamin594e7d22016-03-17 17:49:56 -04003891 testCases = append(testCases, testCase{
3892 testType: serverTest,
3893 name: "ALPNServer-Decline",
3894 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003895 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003896 NextProtos: []string{"foo", "bar", "baz"},
3897 },
3898 flags: []string{"-decline-alpn"},
3899 expectNoNextProto: true,
3900 resumeSession: true,
3901 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003902 // Test that the server prefers ALPN over NPN.
3903 testCases = append(testCases, testCase{
3904 testType: serverTest,
3905 name: "ALPNServer-Preferred",
3906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003907 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003908 NextProtos: []string{"foo", "bar", "baz"},
3909 },
3910 flags: []string{
3911 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3912 "-select-alpn", "foo",
3913 "-advertise-npn", "\x03foo\x03bar\x03baz",
3914 },
3915 expectedNextProto: "foo",
3916 expectedNextProtoType: alpn,
3917 resumeSession: true,
3918 })
3919 testCases = append(testCases, testCase{
3920 testType: serverTest,
3921 name: "ALPNServer-Preferred-Swapped",
3922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003923 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003924 NextProtos: []string{"foo", "bar", "baz"},
3925 Bugs: ProtocolBugs{
3926 SwapNPNAndALPN: true,
3927 },
3928 },
3929 flags: []string{
3930 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3931 "-select-alpn", "foo",
3932 "-advertise-npn", "\x03foo\x03bar\x03baz",
3933 },
3934 expectedNextProto: "foo",
3935 expectedNextProtoType: alpn,
3936 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003937 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003938 var emptyString string
3939 testCases = append(testCases, testCase{
3940 testType: clientTest,
3941 name: "ALPNClient-EmptyProtocolName",
3942 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003943 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003944 NextProtos: []string{""},
3945 Bugs: ProtocolBugs{
3946 // A server returning an empty ALPN protocol
3947 // should be rejected.
3948 ALPNProtocol: &emptyString,
3949 },
3950 },
3951 flags: []string{
3952 "-advertise-alpn", "\x03foo",
3953 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003954 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003955 expectedError: ":PARSE_TLSEXT:",
3956 })
3957 testCases = append(testCases, testCase{
3958 testType: serverTest,
3959 name: "ALPNServer-EmptyProtocolName",
3960 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003961 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003962 // A ClientHello containing an empty ALPN protocol
3963 // should be rejected.
3964 NextProtos: []string{"foo", "", "baz"},
3965 },
3966 flags: []string{
3967 "-select-alpn", "foo",
3968 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003969 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003970 expectedError: ":PARSE_TLSEXT:",
3971 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003972 // Test that negotiating both NPN and ALPN is forbidden.
3973 testCases = append(testCases, testCase{
3974 name: "NegotiateALPNAndNPN",
3975 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003976 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003977 NextProtos: []string{"foo", "bar", "baz"},
3978 Bugs: ProtocolBugs{
3979 NegotiateALPNAndNPN: true,
3980 },
3981 },
3982 flags: []string{
3983 "-advertise-alpn", "\x03foo",
3984 "-select-next-proto", "foo",
3985 },
3986 shouldFail: true,
3987 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3988 })
3989 testCases = append(testCases, testCase{
3990 name: "NegotiateALPNAndNPN-Swapped",
3991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003992 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003993 NextProtos: []string{"foo", "bar", "baz"},
3994 Bugs: ProtocolBugs{
3995 NegotiateALPNAndNPN: true,
3996 SwapNPNAndALPN: true,
3997 },
3998 },
3999 flags: []string{
4000 "-advertise-alpn", "\x03foo",
4001 "-select-next-proto", "foo",
4002 },
4003 shouldFail: true,
4004 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4005 })
David Benjamin091c4b92015-10-26 13:33:21 -04004006 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4007 testCases = append(testCases, testCase{
4008 name: "DisableNPN",
4009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004010 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04004011 NextProtos: []string{"foo"},
4012 },
4013 flags: []string{
4014 "-select-next-proto", "foo",
4015 "-disable-npn",
4016 },
4017 expectNoNextProto: true,
4018 })
Adam Langley38311732014-10-16 19:04:35 -07004019 // Resume with a corrupt ticket.
4020 testCases = append(testCases, testCase{
4021 testType: serverTest,
4022 name: "CorruptTicket",
4023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004024 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004025 Bugs: ProtocolBugs{
4026 CorruptTicket: true,
4027 },
4028 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004029 resumeSession: true,
4030 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07004031 })
David Benjamind98452d2015-06-16 14:16:23 -04004032 // Test the ticket callback, with and without renewal.
4033 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004034 testType: serverTest,
4035 name: "TicketCallback",
4036 config: Config{
4037 MaxVersion: VersionTLS12,
4038 },
David Benjamind98452d2015-06-16 14:16:23 -04004039 resumeSession: true,
4040 flags: []string{"-use-ticket-callback"},
4041 })
4042 testCases = append(testCases, testCase{
4043 testType: serverTest,
4044 name: "TicketCallback-Renew",
4045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004046 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004047 Bugs: ProtocolBugs{
4048 ExpectNewTicket: true,
4049 },
4050 },
4051 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4052 resumeSession: true,
4053 })
Adam Langley38311732014-10-16 19:04:35 -07004054 // Resume with an oversized session id.
4055 testCases = append(testCases, testCase{
4056 testType: serverTest,
4057 name: "OversizedSessionId",
4058 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004059 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004060 Bugs: ProtocolBugs{
4061 OversizedSessionId: true,
4062 },
4063 },
4064 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004065 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004066 expectedError: ":DECODE_ERROR:",
4067 })
David Benjaminca6c8262014-11-15 19:06:08 -05004068 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4069 // are ignored.
4070 testCases = append(testCases, testCase{
4071 protocol: dtls,
4072 name: "SRTP-Client",
4073 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004074 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004075 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4076 },
4077 flags: []string{
4078 "-srtp-profiles",
4079 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4080 },
4081 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4082 })
4083 testCases = append(testCases, testCase{
4084 protocol: dtls,
4085 testType: serverTest,
4086 name: "SRTP-Server",
4087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004088 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004089 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4090 },
4091 flags: []string{
4092 "-srtp-profiles",
4093 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4094 },
4095 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4096 })
4097 // Test that the MKI is ignored.
4098 testCases = append(testCases, testCase{
4099 protocol: dtls,
4100 testType: serverTest,
4101 name: "SRTP-Server-IgnoreMKI",
4102 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004103 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004104 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4105 Bugs: ProtocolBugs{
4106 SRTPMasterKeyIdentifer: "bogus",
4107 },
4108 },
4109 flags: []string{
4110 "-srtp-profiles",
4111 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4112 },
4113 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4114 })
4115 // Test that SRTP isn't negotiated on the server if there were
4116 // no matching profiles.
4117 testCases = append(testCases, testCase{
4118 protocol: dtls,
4119 testType: serverTest,
4120 name: "SRTP-Server-NoMatch",
4121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004122 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004123 SRTPProtectionProfiles: []uint16{100, 101, 102},
4124 },
4125 flags: []string{
4126 "-srtp-profiles",
4127 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4128 },
4129 expectedSRTPProtectionProfile: 0,
4130 })
4131 // Test that the server returning an invalid SRTP profile is
4132 // flagged as an error by the client.
4133 testCases = append(testCases, testCase{
4134 protocol: dtls,
4135 name: "SRTP-Client-NoMatch",
4136 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004137 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004138 Bugs: ProtocolBugs{
4139 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4140 },
4141 },
4142 flags: []string{
4143 "-srtp-profiles",
4144 "SRTP_AES128_CM_SHA1_80",
4145 },
4146 shouldFail: true,
4147 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4148 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004149 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004150 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004151 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004152 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004153 config: Config{
4154 MaxVersion: VersionTLS12,
4155 },
David Benjamin61f95272014-11-25 01:55:35 -05004156 flags: []string{
4157 "-enable-signed-cert-timestamps",
4158 "-expect-signed-cert-timestamps",
4159 base64.StdEncoding.EncodeToString(testSCTList),
4160 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004161 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004162 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004163 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004164 name: "SendSCTListOnResume",
4165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004166 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004167 Bugs: ProtocolBugs{
4168 SendSCTListOnResume: []byte("bogus"),
4169 },
4170 },
4171 flags: []string{
4172 "-enable-signed-cert-timestamps",
4173 "-expect-signed-cert-timestamps",
4174 base64.StdEncoding.EncodeToString(testSCTList),
4175 },
4176 resumeSession: true,
4177 })
4178 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004179 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004180 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004181 config: Config{
4182 MaxVersion: VersionTLS12,
4183 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004184 flags: []string{
4185 "-signed-cert-timestamps",
4186 base64.StdEncoding.EncodeToString(testSCTList),
4187 },
4188 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004189 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004190 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004191
Paul Lietar4fac72e2015-09-09 13:44:55 +01004192 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004193 testType: clientTest,
4194 name: "ClientHelloPadding",
4195 config: Config{
4196 Bugs: ProtocolBugs{
4197 RequireClientHelloSize: 512,
4198 },
4199 },
4200 // This hostname just needs to be long enough to push the
4201 // ClientHello into F5's danger zone between 256 and 511 bytes
4202 // long.
4203 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4204 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004205
4206 // Extensions should not function in SSL 3.0.
4207 testCases = append(testCases, testCase{
4208 testType: serverTest,
4209 name: "SSLv3Extensions-NoALPN",
4210 config: Config{
4211 MaxVersion: VersionSSL30,
4212 NextProtos: []string{"foo", "bar", "baz"},
4213 },
4214 flags: []string{
4215 "-select-alpn", "foo",
4216 },
4217 expectNoNextProto: true,
4218 })
4219
4220 // Test session tickets separately as they follow a different codepath.
4221 testCases = append(testCases, testCase{
4222 testType: serverTest,
4223 name: "SSLv3Extensions-NoTickets",
4224 config: Config{
4225 MaxVersion: VersionSSL30,
4226 Bugs: ProtocolBugs{
4227 // Historically, session tickets in SSL 3.0
4228 // failed in different ways depending on whether
4229 // the client supported renegotiation_info.
4230 NoRenegotiationInfo: true,
4231 },
4232 },
4233 resumeSession: true,
4234 })
4235 testCases = append(testCases, testCase{
4236 testType: serverTest,
4237 name: "SSLv3Extensions-NoTickets2",
4238 config: Config{
4239 MaxVersion: VersionSSL30,
4240 },
4241 resumeSession: true,
4242 })
4243
4244 // But SSL 3.0 does send and process renegotiation_info.
4245 testCases = append(testCases, testCase{
4246 testType: serverTest,
4247 name: "SSLv3Extensions-RenegotiationInfo",
4248 config: Config{
4249 MaxVersion: VersionSSL30,
4250 Bugs: ProtocolBugs{
4251 RequireRenegotiationInfo: true,
4252 },
4253 },
4254 })
4255 testCases = append(testCases, testCase{
4256 testType: serverTest,
4257 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4258 config: Config{
4259 MaxVersion: VersionSSL30,
4260 Bugs: ProtocolBugs{
4261 NoRenegotiationInfo: true,
4262 SendRenegotiationSCSV: true,
4263 RequireRenegotiationInfo: true,
4264 },
4265 },
4266 })
David Benjamine78bfde2014-09-06 12:45:15 -04004267}
4268
David Benjamin01fe8202014-09-24 15:21:44 -04004269func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004270 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004271 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004272 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4273 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4274 // TLS 1.3 only shares ciphers with TLS 1.2, so
4275 // we skip certain combinations and use a
4276 // different cipher to test with.
4277 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4278 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4279 continue
4280 }
4281 }
4282
David Benjamin8b8c0062014-11-23 02:47:52 -05004283 protocols := []protocol{tls}
4284 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4285 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004286 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004287 for _, protocol := range protocols {
4288 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4289 if protocol == dtls {
4290 suffix += "-DTLS"
4291 }
4292
David Benjaminece3de92015-03-16 18:02:20 -04004293 if sessionVers.version == resumeVers.version {
4294 testCases = append(testCases, testCase{
4295 protocol: protocol,
4296 name: "Resume-Client" + suffix,
4297 resumeSession: true,
4298 config: Config{
4299 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004300 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004301 },
David Benjaminece3de92015-03-16 18:02:20 -04004302 expectedVersion: sessionVers.version,
4303 expectedResumeVersion: resumeVers.version,
4304 })
4305 } else {
4306 testCases = append(testCases, testCase{
4307 protocol: protocol,
4308 name: "Resume-Client-Mismatch" + suffix,
4309 resumeSession: true,
4310 config: Config{
4311 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004312 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004313 },
David Benjaminece3de92015-03-16 18:02:20 -04004314 expectedVersion: sessionVers.version,
4315 resumeConfig: &Config{
4316 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004317 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004318 Bugs: ProtocolBugs{
4319 AllowSessionVersionMismatch: true,
4320 },
4321 },
4322 expectedResumeVersion: resumeVers.version,
4323 shouldFail: true,
4324 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4325 })
4326 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004327
4328 testCases = append(testCases, testCase{
4329 protocol: protocol,
4330 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004331 resumeSession: true,
4332 config: Config{
4333 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004334 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004335 },
4336 expectedVersion: sessionVers.version,
4337 resumeConfig: &Config{
4338 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004339 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004340 },
4341 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004342 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004343 expectedResumeVersion: resumeVers.version,
4344 })
4345
David Benjamin8b8c0062014-11-23 02:47:52 -05004346 testCases = append(testCases, testCase{
4347 protocol: protocol,
4348 testType: serverTest,
4349 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004350 resumeSession: true,
4351 config: Config{
4352 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004353 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004354 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004355 expectedVersion: sessionVers.version,
4356 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004357 resumeConfig: &Config{
4358 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004359 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004360 },
4361 expectedResumeVersion: resumeVers.version,
4362 })
4363 }
David Benjamin01fe8202014-09-24 15:21:44 -04004364 }
4365 }
David Benjaminece3de92015-03-16 18:02:20 -04004366
Nick Harper1fd39d82016-06-14 18:14:35 -07004367 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004368 testCases = append(testCases, testCase{
4369 name: "Resume-Client-CipherMismatch",
4370 resumeSession: true,
4371 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004372 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004373 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4374 },
4375 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004376 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004377 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4378 Bugs: ProtocolBugs{
4379 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4380 },
4381 },
4382 shouldFail: true,
4383 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4384 })
David Benjamin01fe8202014-09-24 15:21:44 -04004385}
4386
Adam Langley2ae77d22014-10-28 17:29:33 -07004387func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004388 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004389 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004390 testType: serverTest,
4391 name: "Renegotiate-Server-Forbidden",
4392 config: Config{
4393 MaxVersion: VersionTLS12,
4394 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004395 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004396 shouldFail: true,
4397 expectedError: ":NO_RENEGOTIATION:",
4398 expectedLocalError: "remote error: no renegotiation",
4399 })
Adam Langley5021b222015-06-12 18:27:58 -07004400 // The server shouldn't echo the renegotiation extension unless
4401 // requested by the client.
4402 testCases = append(testCases, testCase{
4403 testType: serverTest,
4404 name: "Renegotiate-Server-NoExt",
4405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004406 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004407 Bugs: ProtocolBugs{
4408 NoRenegotiationInfo: true,
4409 RequireRenegotiationInfo: true,
4410 },
4411 },
4412 shouldFail: true,
4413 expectedLocalError: "renegotiation extension missing",
4414 })
4415 // The renegotiation SCSV should be sufficient for the server to echo
4416 // the extension.
4417 testCases = append(testCases, testCase{
4418 testType: serverTest,
4419 name: "Renegotiate-Server-NoExt-SCSV",
4420 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004421 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004422 Bugs: ProtocolBugs{
4423 NoRenegotiationInfo: true,
4424 SendRenegotiationSCSV: true,
4425 RequireRenegotiationInfo: true,
4426 },
4427 },
4428 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004429 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004430 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004432 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004433 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004434 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004435 },
4436 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004437 renegotiate: 1,
4438 flags: []string{
4439 "-renegotiate-freely",
4440 "-expect-total-renegotiations", "1",
4441 },
David Benjamincdea40c2015-03-19 14:09:43 -04004442 })
4443 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004444 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004445 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004446 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004447 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004448 Bugs: ProtocolBugs{
4449 EmptyRenegotiationInfo: true,
4450 },
4451 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004452 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004453 shouldFail: true,
4454 expectedError: ":RENEGOTIATION_MISMATCH:",
4455 })
4456 testCases = append(testCases, testCase{
4457 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004458 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004461 Bugs: ProtocolBugs{
4462 BadRenegotiationInfo: true,
4463 },
4464 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004465 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004466 shouldFail: true,
4467 expectedError: ":RENEGOTIATION_MISMATCH:",
4468 })
4469 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004470 name: "Renegotiate-Client-Downgrade",
4471 renegotiate: 1,
4472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004473 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004474 Bugs: ProtocolBugs{
4475 NoRenegotiationInfoAfterInitial: true,
4476 },
4477 },
4478 flags: []string{"-renegotiate-freely"},
4479 shouldFail: true,
4480 expectedError: ":RENEGOTIATION_MISMATCH:",
4481 })
4482 testCases = append(testCases, testCase{
4483 name: "Renegotiate-Client-Upgrade",
4484 renegotiate: 1,
4485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004486 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004487 Bugs: ProtocolBugs{
4488 NoRenegotiationInfoInInitial: true,
4489 },
4490 },
4491 flags: []string{"-renegotiate-freely"},
4492 shouldFail: true,
4493 expectedError: ":RENEGOTIATION_MISMATCH:",
4494 })
4495 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004496 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004497 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004498 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004499 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004500 Bugs: ProtocolBugs{
4501 NoRenegotiationInfo: true,
4502 },
4503 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004504 flags: []string{
4505 "-renegotiate-freely",
4506 "-expect-total-renegotiations", "1",
4507 },
David Benjamincff0b902015-05-15 23:09:47 -04004508 })
4509 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004510 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004511 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004512 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004513 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004514 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4515 },
4516 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004517 flags: []string{
4518 "-renegotiate-freely",
4519 "-expect-total-renegotiations", "1",
4520 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004521 })
4522 testCases = append(testCases, testCase{
4523 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004524 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004525 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004526 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004527 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4528 },
4529 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004530 flags: []string{
4531 "-renegotiate-freely",
4532 "-expect-total-renegotiations", "1",
4533 },
David Benjaminb16346b2015-04-08 19:16:58 -04004534 })
4535 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004536 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004537 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004538 config: Config{
4539 MaxVersion: VersionTLS10,
4540 Bugs: ProtocolBugs{
4541 RequireSameRenegoClientVersion: true,
4542 },
4543 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004544 flags: []string{
4545 "-renegotiate-freely",
4546 "-expect-total-renegotiations", "1",
4547 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004548 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004549 testCases = append(testCases, testCase{
4550 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004551 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004552 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004553 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004554 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4555 NextProtos: []string{"foo"},
4556 },
4557 flags: []string{
4558 "-false-start",
4559 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004560 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004561 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004562 },
4563 shimWritesFirst: true,
4564 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004565
4566 // Client-side renegotiation controls.
4567 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004568 name: "Renegotiate-Client-Forbidden-1",
4569 config: Config{
4570 MaxVersion: VersionTLS12,
4571 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004572 renegotiate: 1,
4573 shouldFail: true,
4574 expectedError: ":NO_RENEGOTIATION:",
4575 expectedLocalError: "remote error: no renegotiation",
4576 })
4577 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004578 name: "Renegotiate-Client-Once-1",
4579 config: Config{
4580 MaxVersion: VersionTLS12,
4581 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004582 renegotiate: 1,
4583 flags: []string{
4584 "-renegotiate-once",
4585 "-expect-total-renegotiations", "1",
4586 },
4587 })
4588 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004589 name: "Renegotiate-Client-Freely-1",
4590 config: Config{
4591 MaxVersion: VersionTLS12,
4592 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004593 renegotiate: 1,
4594 flags: []string{
4595 "-renegotiate-freely",
4596 "-expect-total-renegotiations", "1",
4597 },
4598 })
4599 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004600 name: "Renegotiate-Client-Once-2",
4601 config: Config{
4602 MaxVersion: VersionTLS12,
4603 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004604 renegotiate: 2,
4605 flags: []string{"-renegotiate-once"},
4606 shouldFail: true,
4607 expectedError: ":NO_RENEGOTIATION:",
4608 expectedLocalError: "remote error: no renegotiation",
4609 })
4610 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004611 name: "Renegotiate-Client-Freely-2",
4612 config: Config{
4613 MaxVersion: VersionTLS12,
4614 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004615 renegotiate: 2,
4616 flags: []string{
4617 "-renegotiate-freely",
4618 "-expect-total-renegotiations", "2",
4619 },
4620 })
Adam Langley27a0d082015-11-03 13:34:10 -08004621 testCases = append(testCases, testCase{
4622 name: "Renegotiate-Client-NoIgnore",
4623 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004624 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004625 Bugs: ProtocolBugs{
4626 SendHelloRequestBeforeEveryAppDataRecord: true,
4627 },
4628 },
4629 shouldFail: true,
4630 expectedError: ":NO_RENEGOTIATION:",
4631 })
4632 testCases = append(testCases, testCase{
4633 name: "Renegotiate-Client-Ignore",
4634 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004635 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004636 Bugs: ProtocolBugs{
4637 SendHelloRequestBeforeEveryAppDataRecord: true,
4638 },
4639 },
4640 flags: []string{
4641 "-renegotiate-ignore",
4642 "-expect-total-renegotiations", "0",
4643 },
4644 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004645
David Benjamin397c8e62016-07-08 14:14:36 -07004646 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004647 testCases = append(testCases, testCase{
4648 name: "StrayHelloRequest",
4649 config: Config{
4650 MaxVersion: VersionTLS12,
4651 Bugs: ProtocolBugs{
4652 SendHelloRequestBeforeEveryHandshakeMessage: true,
4653 },
4654 },
4655 })
4656 testCases = append(testCases, testCase{
4657 name: "StrayHelloRequest-Packed",
4658 config: Config{
4659 MaxVersion: VersionTLS12,
4660 Bugs: ProtocolBugs{
4661 PackHandshakeFlight: true,
4662 SendHelloRequestBeforeEveryHandshakeMessage: true,
4663 },
4664 },
4665 })
4666
David Benjamin397c8e62016-07-08 14:14:36 -07004667 // Renegotiation is forbidden in TLS 1.3.
4668 testCases = append(testCases, testCase{
4669 name: "Renegotiate-Client-TLS13",
4670 config: Config{
4671 MaxVersion: VersionTLS13,
4672 },
4673 renegotiate: 1,
4674 flags: []string{
4675 "-renegotiate-freely",
4676 },
4677 shouldFail: true,
4678 expectedError: ":NO_RENEGOTIATION:",
4679 })
4680
4681 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4682 testCases = append(testCases, testCase{
4683 name: "StrayHelloRequest-TLS13",
4684 config: Config{
4685 MaxVersion: VersionTLS13,
4686 Bugs: ProtocolBugs{
4687 SendHelloRequestBeforeEveryHandshakeMessage: true,
4688 },
4689 },
4690 shouldFail: true,
4691 expectedError: ":UNEXPECTED_MESSAGE:",
4692 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004693}
4694
David Benjamin5e961c12014-11-07 01:48:35 -05004695func addDTLSReplayTests() {
4696 // Test that sequence number replays are detected.
4697 testCases = append(testCases, testCase{
4698 protocol: dtls,
4699 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004700 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004701 replayWrites: true,
4702 })
4703
David Benjamin8e6db492015-07-25 18:29:23 -04004704 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004705 // than the retransmit window.
4706 testCases = append(testCases, testCase{
4707 protocol: dtls,
4708 name: "DTLS-Replay-LargeGaps",
4709 config: Config{
4710 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004711 SequenceNumberMapping: func(in uint64) uint64 {
4712 return in * 127
4713 },
David Benjamin5e961c12014-11-07 01:48:35 -05004714 },
4715 },
David Benjamin8e6db492015-07-25 18:29:23 -04004716 messageCount: 200,
4717 replayWrites: true,
4718 })
4719
4720 // Test the incoming sequence number changing non-monotonically.
4721 testCases = append(testCases, testCase{
4722 protocol: dtls,
4723 name: "DTLS-Replay-NonMonotonic",
4724 config: Config{
4725 Bugs: ProtocolBugs{
4726 SequenceNumberMapping: func(in uint64) uint64 {
4727 return in ^ 31
4728 },
4729 },
4730 },
4731 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004732 replayWrites: true,
4733 })
4734}
4735
Nick Harper60edffd2016-06-21 15:19:24 -07004736var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004737 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004738 id signatureAlgorithm
4739 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004740}{
Nick Harper60edffd2016-06-21 15:19:24 -07004741 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4742 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4743 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4744 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004745 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07004746 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4747 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4748 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004749 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
4750 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
4751 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin000800a2014-11-14 01:43:59 -05004752}
4753
Nick Harper60edffd2016-06-21 15:19:24 -07004754const fakeSigAlg1 signatureAlgorithm = 0x2a01
4755const fakeSigAlg2 signatureAlgorithm = 0xff01
4756
4757func addSignatureAlgorithmTests() {
4758 // Make sure each signature algorithm works. Include some fake values in
4759 // the list and ensure they're ignored.
4760 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07004761 for _, ver := range tlsVersions {
4762 if ver.version < VersionTLS12 {
4763 continue
4764 }
Nick Harper60edffd2016-06-21 15:19:24 -07004765
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004766 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07004767 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004768 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
4769 shouldFail = true
4770 }
4771 // RSA-PSS does not exist in TLS 1.2.
4772 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
4773 shouldFail = true
4774 }
4775
4776 var signError, verifyError string
4777 if shouldFail {
4778 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
4779 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07004780 }
David Benjamin000800a2014-11-14 01:43:59 -05004781
David Benjamin1fb125c2016-07-08 18:52:12 -07004782 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05004783
David Benjamin7a41d372016-07-09 11:21:54 -07004784 testCases = append(testCases, testCase{
4785 name: "SigningHash-ClientAuth-Sign" + suffix,
4786 config: Config{
4787 MaxVersion: ver.version,
4788 ClientAuth: RequireAnyClientCert,
4789 VerifySignatureAlgorithms: []signatureAlgorithm{
4790 fakeSigAlg1,
4791 alg.id,
4792 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07004793 },
David Benjamin7a41d372016-07-09 11:21:54 -07004794 },
4795 flags: []string{
4796 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4797 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4798 "-enable-all-curves",
4799 },
4800 shouldFail: shouldFail,
4801 expectedError: signError,
4802 expectedPeerSignatureAlgorithm: alg.id,
4803 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004804
David Benjamin7a41d372016-07-09 11:21:54 -07004805 testCases = append(testCases, testCase{
4806 testType: serverTest,
4807 name: "SigningHash-ClientAuth-Verify" + suffix,
4808 config: Config{
4809 MaxVersion: ver.version,
4810 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4811 SignSignatureAlgorithms: []signatureAlgorithm{
4812 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004813 },
David Benjamin7a41d372016-07-09 11:21:54 -07004814 Bugs: ProtocolBugs{
4815 SkipECDSACurveCheck: shouldFail,
4816 IgnoreSignatureVersionChecks: shouldFail,
4817 // The client won't advertise 1.3-only algorithms after
4818 // version negotiation.
4819 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004820 },
David Benjamin7a41d372016-07-09 11:21:54 -07004821 },
4822 flags: []string{
4823 "-require-any-client-certificate",
4824 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4825 "-enable-all-curves",
4826 },
4827 shouldFail: shouldFail,
4828 expectedError: verifyError,
4829 })
David Benjamin1fb125c2016-07-08 18:52:12 -07004830
4831 testCases = append(testCases, testCase{
4832 testType: serverTest,
4833 name: "SigningHash-ServerKeyExchange-Sign" + suffix,
4834 config: Config{
4835 MaxVersion: ver.version,
4836 CipherSuites: []uint16{
4837 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4838 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4839 },
David Benjamin7a41d372016-07-09 11:21:54 -07004840 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004841 fakeSigAlg1,
4842 alg.id,
4843 fakeSigAlg2,
4844 },
4845 },
4846 flags: []string{
4847 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4848 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4849 "-enable-all-curves",
4850 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004851 shouldFail: shouldFail,
4852 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004853 expectedPeerSignatureAlgorithm: alg.id,
4854 })
4855
4856 testCases = append(testCases, testCase{
4857 name: "SigningHash-ServerKeyExchange-Verify" + suffix,
4858 config: Config{
4859 MaxVersion: ver.version,
4860 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4861 CipherSuites: []uint16{
4862 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4863 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4864 },
David Benjamin7a41d372016-07-09 11:21:54 -07004865 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004866 alg.id,
4867 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004868 Bugs: ProtocolBugs{
4869 SkipECDSACurveCheck: shouldFail,
4870 IgnoreSignatureVersionChecks: shouldFail,
4871 },
David Benjamin1fb125c2016-07-08 18:52:12 -07004872 },
4873 flags: []string{
4874 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4875 "-enable-all-curves",
4876 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004877 shouldFail: shouldFail,
4878 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004879 })
4880 }
David Benjamin000800a2014-11-14 01:43:59 -05004881 }
4882
Nick Harper60edffd2016-06-21 15:19:24 -07004883 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004884 //
4885 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004886 testCases = append(testCases, testCase{
4887 name: "SigningHash-ClientAuth-SignatureType",
4888 config: Config{
4889 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004890 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07004891 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004892 signatureECDSAWithP521AndSHA512,
4893 signatureRSAPKCS1WithSHA384,
4894 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004895 },
4896 },
4897 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004898 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4899 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004900 },
Nick Harper60edffd2016-06-21 15:19:24 -07004901 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004902 })
4903
4904 testCases = append(testCases, testCase{
4905 testType: serverTest,
4906 name: "SigningHash-ServerKeyExchange-SignatureType",
4907 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004908 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004909 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004910 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004911 signatureECDSAWithP521AndSHA512,
4912 signatureRSAPKCS1WithSHA384,
4913 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004914 },
4915 },
Nick Harper60edffd2016-06-21 15:19:24 -07004916 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004917 })
4918
David Benjamina95e9f32016-07-08 16:28:04 -07004919 // Test that signature verification takes the key type into account.
4920 //
4921 // TODO(davidben): Test this in TLS 1.3.
4922 testCases = append(testCases, testCase{
4923 testType: serverTest,
4924 name: "Verify-ClientAuth-SignatureType",
4925 config: Config{
4926 MaxVersion: VersionTLS12,
4927 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004928 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004929 signatureRSAPKCS1WithSHA256,
4930 },
4931 Bugs: ProtocolBugs{
4932 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4933 },
4934 },
4935 flags: []string{
4936 "-require-any-client-certificate",
4937 },
4938 shouldFail: true,
4939 expectedError: ":WRONG_SIGNATURE_TYPE:",
4940 })
4941
4942 testCases = append(testCases, testCase{
4943 name: "Verify-ServerKeyExchange-SignatureType",
4944 config: Config{
4945 MaxVersion: VersionTLS12,
4946 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004947 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004948 signatureRSAPKCS1WithSHA256,
4949 },
4950 Bugs: ProtocolBugs{
4951 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4952 },
4953 },
4954 shouldFail: true,
4955 expectedError: ":WRONG_SIGNATURE_TYPE:",
4956 })
4957
David Benjamin51dd7d62016-07-08 16:07:01 -07004958 // Test that, if the list is missing, the peer falls back to SHA-1 in
4959 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004960 testCases = append(testCases, testCase{
4961 name: "SigningHash-ClientAuth-Fallback",
4962 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004963 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004964 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004965 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004966 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004967 },
4968 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004969 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004970 },
4971 },
4972 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004973 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4974 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004975 },
4976 })
4977
4978 testCases = append(testCases, testCase{
4979 testType: serverTest,
4980 name: "SigningHash-ServerKeyExchange-Fallback",
4981 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004982 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004983 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004984 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004985 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004986 },
4987 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004988 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004989 },
4990 },
4991 })
David Benjamin72dc7832015-03-16 17:49:43 -04004992
David Benjamin51dd7d62016-07-08 16:07:01 -07004993 testCases = append(testCases, testCase{
4994 name: "SigningHash-ClientAuth-Fallback-TLS13",
4995 config: Config{
4996 MaxVersion: VersionTLS13,
4997 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004998 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07004999 signatureRSAPKCS1WithSHA1,
5000 },
5001 Bugs: ProtocolBugs{
5002 NoSignatureAlgorithms: true,
5003 },
5004 },
5005 flags: []string{
5006 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5007 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5008 },
5009 shouldFail: true,
5010 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5011 })
5012
5013 testCases = append(testCases, testCase{
5014 testType: serverTest,
5015 name: "SigningHash-ServerKeyExchange-Fallback-TLS13",
5016 config: Config{
5017 MaxVersion: VersionTLS13,
5018 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005019 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005020 signatureRSAPKCS1WithSHA1,
5021 },
5022 Bugs: ProtocolBugs{
5023 NoSignatureAlgorithms: true,
5024 },
5025 },
5026 shouldFail: true,
5027 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5028 })
5029
David Benjamin72dc7832015-03-16 17:49:43 -04005030 // Test that hash preferences are enforced. BoringSSL defaults to
5031 // rejecting MD5 signatures.
5032 testCases = append(testCases, testCase{
5033 testType: serverTest,
5034 name: "SigningHash-ClientAuth-Enforced",
5035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005036 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005037 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005038 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005039 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005040 // Advertise SHA-1 so the handshake will
5041 // proceed, but the shim's preferences will be
5042 // ignored in CertificateVerify generation, so
5043 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005044 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005045 },
5046 Bugs: ProtocolBugs{
5047 IgnorePeerSignatureAlgorithmPreferences: true,
5048 },
5049 },
5050 flags: []string{"-require-any-client-certificate"},
5051 shouldFail: true,
5052 expectedError: ":WRONG_SIGNATURE_TYPE:",
5053 })
5054
5055 testCases = append(testCases, testCase{
5056 name: "SigningHash-ServerKeyExchange-Enforced",
5057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005058 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005059 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005060 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005061 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005062 },
5063 Bugs: ProtocolBugs{
5064 IgnorePeerSignatureAlgorithmPreferences: true,
5065 },
5066 },
5067 shouldFail: true,
5068 expectedError: ":WRONG_SIGNATURE_TYPE:",
5069 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005070
5071 // Test that the agreed upon digest respects the client preferences and
5072 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005073 //
5074 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04005075 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005076 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005078 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005079 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005080 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005081 signatureRSAPKCS1WithSHA512,
5082 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005083 },
5084 },
5085 flags: []string{
5086 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5087 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5088 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005089 digestPrefs: "SHA256",
5090 shouldFail: true,
5091 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005092 })
5093 testCases = append(testCases, testCase{
5094 name: "Agree-Digest-SHA256",
5095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005096 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005097 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005098 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005099 signatureRSAPKCS1WithSHA1,
5100 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005101 },
5102 },
5103 flags: []string{
5104 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5105 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5106 },
Nick Harper60edffd2016-06-21 15:19:24 -07005107 digestPrefs: "SHA256,SHA1",
5108 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005109 })
5110 testCases = append(testCases, testCase{
5111 name: "Agree-Digest-SHA1",
5112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005113 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005114 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005115 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005116 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005117 },
5118 },
5119 flags: []string{
5120 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5121 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5122 },
Nick Harper60edffd2016-06-21 15:19:24 -07005123 digestPrefs: "SHA512,SHA256,SHA1",
5124 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005125 })
5126 testCases = append(testCases, testCase{
5127 name: "Agree-Digest-Default",
5128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005129 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005130 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005131 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005132 signatureRSAPKCS1WithSHA256,
5133 signatureECDSAWithP256AndSHA256,
5134 signatureRSAPKCS1WithSHA1,
5135 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005136 },
5137 },
5138 flags: []string{
5139 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5140 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5141 },
Nick Harper60edffd2016-06-21 15:19:24 -07005142 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005143 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005144
5145 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5146 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005147 testCases = append(testCases, testCase{
5148 name: "CheckLeafCurve",
5149 config: Config{
5150 MaxVersion: VersionTLS12,
5151 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005152 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005153 },
5154 flags: []string{"-p384-only"},
5155 shouldFail: true,
5156 expectedError: ":BAD_ECC_CERT:",
5157 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005158
5159 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5160 testCases = append(testCases, testCase{
5161 name: "CheckLeafCurve-TLS13",
5162 config: Config{
5163 MaxVersion: VersionTLS13,
5164 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5165 Certificates: []Certificate{ecdsaP256Certificate},
5166 },
5167 flags: []string{"-p384-only"},
5168 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005169
5170 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5171 testCases = append(testCases, testCase{
5172 name: "ECDSACurveMismatch-Verify-TLS12",
5173 config: Config{
5174 MaxVersion: VersionTLS12,
5175 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5176 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005177 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005178 signatureECDSAWithP384AndSHA384,
5179 },
5180 },
5181 })
5182
5183 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5184 testCases = append(testCases, testCase{
5185 name: "ECDSACurveMismatch-Verify-TLS13",
5186 config: Config{
5187 MaxVersion: VersionTLS13,
5188 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5189 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005190 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005191 signatureECDSAWithP384AndSHA384,
5192 },
5193 Bugs: ProtocolBugs{
5194 SkipECDSACurveCheck: true,
5195 },
5196 },
5197 shouldFail: true,
5198 expectedError: ":WRONG_SIGNATURE_TYPE:",
5199 })
5200
5201 // Signature algorithm selection in TLS 1.3 should take the curve into
5202 // account.
5203 testCases = append(testCases, testCase{
5204 testType: serverTest,
5205 name: "ECDSACurveMismatch-Sign-TLS13",
5206 config: Config{
5207 MaxVersion: VersionTLS13,
5208 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005209 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005210 signatureECDSAWithP384AndSHA384,
5211 signatureECDSAWithP256AndSHA256,
5212 },
5213 },
5214 flags: []string{
5215 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5216 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5217 },
5218 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5219 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005220
5221 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5222 // server does not attempt to sign in that case.
5223 testCases = append(testCases, testCase{
5224 testType: serverTest,
5225 name: "RSA-PSS-Large",
5226 config: Config{
5227 MaxVersion: VersionTLS13,
5228 VerifySignatureAlgorithms: []signatureAlgorithm{
5229 signatureRSAPSSWithSHA512,
5230 },
5231 },
5232 flags: []string{
5233 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5234 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5235 },
5236 shouldFail: true,
5237 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5238 })
David Benjamin000800a2014-11-14 01:43:59 -05005239}
5240
David Benjamin83f90402015-01-27 01:09:43 -05005241// timeouts is the retransmit schedule for BoringSSL. It doubles and
5242// caps at 60 seconds. On the 13th timeout, it gives up.
5243var timeouts = []time.Duration{
5244 1 * time.Second,
5245 2 * time.Second,
5246 4 * time.Second,
5247 8 * time.Second,
5248 16 * time.Second,
5249 32 * time.Second,
5250 60 * time.Second,
5251 60 * time.Second,
5252 60 * time.Second,
5253 60 * time.Second,
5254 60 * time.Second,
5255 60 * time.Second,
5256 60 * time.Second,
5257}
5258
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005259// shortTimeouts is an alternate set of timeouts which would occur if the
5260// initial timeout duration was set to 250ms.
5261var shortTimeouts = []time.Duration{
5262 250 * time.Millisecond,
5263 500 * time.Millisecond,
5264 1 * time.Second,
5265 2 * time.Second,
5266 4 * time.Second,
5267 8 * time.Second,
5268 16 * time.Second,
5269 32 * time.Second,
5270 60 * time.Second,
5271 60 * time.Second,
5272 60 * time.Second,
5273 60 * time.Second,
5274 60 * time.Second,
5275}
5276
David Benjamin83f90402015-01-27 01:09:43 -05005277func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005278 // These tests work by coordinating some behavior on both the shim and
5279 // the runner.
5280 //
5281 // TimeoutSchedule configures the runner to send a series of timeout
5282 // opcodes to the shim (see packetAdaptor) immediately before reading
5283 // each peer handshake flight N. The timeout opcode both simulates a
5284 // timeout in the shim and acts as a synchronization point to help the
5285 // runner bracket each handshake flight.
5286 //
5287 // We assume the shim does not read from the channel eagerly. It must
5288 // first wait until it has sent flight N and is ready to receive
5289 // handshake flight N+1. At this point, it will process the timeout
5290 // opcode. It must then immediately respond with a timeout ACK and act
5291 // as if the shim was idle for the specified amount of time.
5292 //
5293 // The runner then drops all packets received before the ACK and
5294 // continues waiting for flight N. This ordering results in one attempt
5295 // at sending flight N to be dropped. For the test to complete, the
5296 // shim must send flight N again, testing that the shim implements DTLS
5297 // retransmit on a timeout.
5298
David Benjamin4c3ddf72016-06-29 18:13:53 -04005299 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5300 // likely be more epochs to cross and the final message's retransmit may
5301 // be more complex.
5302
David Benjamin585d7a42016-06-02 14:58:00 -04005303 for _, async := range []bool{true, false} {
5304 var tests []testCase
5305
5306 // Test that this is indeed the timeout schedule. Stress all
5307 // four patterns of handshake.
5308 for i := 1; i < len(timeouts); i++ {
5309 number := strconv.Itoa(i)
5310 tests = append(tests, testCase{
5311 protocol: dtls,
5312 name: "DTLS-Retransmit-Client-" + number,
5313 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005314 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005315 Bugs: ProtocolBugs{
5316 TimeoutSchedule: timeouts[:i],
5317 },
5318 },
5319 resumeSession: true,
5320 })
5321 tests = append(tests, testCase{
5322 protocol: dtls,
5323 testType: serverTest,
5324 name: "DTLS-Retransmit-Server-" + number,
5325 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005326 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005327 Bugs: ProtocolBugs{
5328 TimeoutSchedule: timeouts[:i],
5329 },
5330 },
5331 resumeSession: true,
5332 })
5333 }
5334
5335 // Test that exceeding the timeout schedule hits a read
5336 // timeout.
5337 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005338 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005339 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005341 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005342 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005343 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005344 },
5345 },
5346 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005347 shouldFail: true,
5348 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005349 })
David Benjamin585d7a42016-06-02 14:58:00 -04005350
5351 if async {
5352 // Test that timeout handling has a fudge factor, due to API
5353 // problems.
5354 tests = append(tests, testCase{
5355 protocol: dtls,
5356 name: "DTLS-Retransmit-Fudge",
5357 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005358 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005359 Bugs: ProtocolBugs{
5360 TimeoutSchedule: []time.Duration{
5361 timeouts[0] - 10*time.Millisecond,
5362 },
5363 },
5364 },
5365 resumeSession: true,
5366 })
5367 }
5368
5369 // Test that the final Finished retransmitting isn't
5370 // duplicated if the peer badly fragments everything.
5371 tests = append(tests, testCase{
5372 testType: serverTest,
5373 protocol: dtls,
5374 name: "DTLS-Retransmit-Fragmented",
5375 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005376 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005377 Bugs: ProtocolBugs{
5378 TimeoutSchedule: []time.Duration{timeouts[0]},
5379 MaxHandshakeRecordLength: 2,
5380 },
5381 },
5382 })
5383
5384 // Test the timeout schedule when a shorter initial timeout duration is set.
5385 tests = append(tests, testCase{
5386 protocol: dtls,
5387 name: "DTLS-Retransmit-Short-Client",
5388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005389 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005390 Bugs: ProtocolBugs{
5391 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5392 },
5393 },
5394 resumeSession: true,
5395 flags: []string{"-initial-timeout-duration-ms", "250"},
5396 })
5397 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005398 protocol: dtls,
5399 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005400 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005402 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005403 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005404 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005405 },
5406 },
5407 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005408 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005409 })
David Benjamin585d7a42016-06-02 14:58:00 -04005410
5411 for _, test := range tests {
5412 if async {
5413 test.name += "-Async"
5414 test.flags = append(test.flags, "-async")
5415 }
5416
5417 testCases = append(testCases, test)
5418 }
David Benjamin83f90402015-01-27 01:09:43 -05005419 }
David Benjamin83f90402015-01-27 01:09:43 -05005420}
5421
David Benjaminc565ebb2015-04-03 04:06:36 -04005422func addExportKeyingMaterialTests() {
5423 for _, vers := range tlsVersions {
5424 if vers.version == VersionSSL30 {
5425 continue
5426 }
5427 testCases = append(testCases, testCase{
5428 name: "ExportKeyingMaterial-" + vers.name,
5429 config: Config{
5430 MaxVersion: vers.version,
5431 },
5432 exportKeyingMaterial: 1024,
5433 exportLabel: "label",
5434 exportContext: "context",
5435 useExportContext: true,
5436 })
5437 testCases = append(testCases, testCase{
5438 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5439 config: Config{
5440 MaxVersion: vers.version,
5441 },
5442 exportKeyingMaterial: 1024,
5443 })
5444 testCases = append(testCases, testCase{
5445 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5446 config: Config{
5447 MaxVersion: vers.version,
5448 },
5449 exportKeyingMaterial: 1024,
5450 useExportContext: true,
5451 })
5452 testCases = append(testCases, testCase{
5453 name: "ExportKeyingMaterial-Small-" + vers.name,
5454 config: Config{
5455 MaxVersion: vers.version,
5456 },
5457 exportKeyingMaterial: 1,
5458 exportLabel: "label",
5459 exportContext: "context",
5460 useExportContext: true,
5461 })
5462 }
5463 testCases = append(testCases, testCase{
5464 name: "ExportKeyingMaterial-SSL3",
5465 config: Config{
5466 MaxVersion: VersionSSL30,
5467 },
5468 exportKeyingMaterial: 1024,
5469 exportLabel: "label",
5470 exportContext: "context",
5471 useExportContext: true,
5472 shouldFail: true,
5473 expectedError: "failed to export keying material",
5474 })
5475}
5476
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005477func addTLSUniqueTests() {
5478 for _, isClient := range []bool{false, true} {
5479 for _, isResumption := range []bool{false, true} {
5480 for _, hasEMS := range []bool{false, true} {
5481 var suffix string
5482 if isResumption {
5483 suffix = "Resume-"
5484 } else {
5485 suffix = "Full-"
5486 }
5487
5488 if hasEMS {
5489 suffix += "EMS-"
5490 } else {
5491 suffix += "NoEMS-"
5492 }
5493
5494 if isClient {
5495 suffix += "Client"
5496 } else {
5497 suffix += "Server"
5498 }
5499
5500 test := testCase{
5501 name: "TLSUnique-" + suffix,
5502 testTLSUnique: true,
5503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005504 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005505 Bugs: ProtocolBugs{
5506 NoExtendedMasterSecret: !hasEMS,
5507 },
5508 },
5509 }
5510
5511 if isResumption {
5512 test.resumeSession = true
5513 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005514 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005515 Bugs: ProtocolBugs{
5516 NoExtendedMasterSecret: !hasEMS,
5517 },
5518 }
5519 }
5520
5521 if isResumption && !hasEMS {
5522 test.shouldFail = true
5523 test.expectedError = "failed to get tls-unique"
5524 }
5525
5526 testCases = append(testCases, test)
5527 }
5528 }
5529 }
5530}
5531
Adam Langley09505632015-07-30 18:10:13 -07005532func addCustomExtensionTests() {
5533 expectedContents := "custom extension"
5534 emptyString := ""
5535
David Benjamin4c3ddf72016-06-29 18:13:53 -04005536 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005537 for _, isClient := range []bool{false, true} {
5538 suffix := "Server"
5539 flag := "-enable-server-custom-extension"
5540 testType := serverTest
5541 if isClient {
5542 suffix = "Client"
5543 flag = "-enable-client-custom-extension"
5544 testType = clientTest
5545 }
5546
5547 testCases = append(testCases, testCase{
5548 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005549 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005551 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005552 Bugs: ProtocolBugs{
5553 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005554 ExpectedCustomExtension: &expectedContents,
5555 },
5556 },
5557 flags: []string{flag},
5558 })
5559
5560 // If the parse callback fails, the handshake should also fail.
5561 testCases = append(testCases, testCase{
5562 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005563 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005565 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005566 Bugs: ProtocolBugs{
5567 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005568 ExpectedCustomExtension: &expectedContents,
5569 },
5570 },
David Benjamin399e7c92015-07-30 23:01:27 -04005571 flags: []string{flag},
5572 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005573 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5574 })
5575
5576 // If the add callback fails, the handshake should also fail.
5577 testCases = append(testCases, testCase{
5578 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005579 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005581 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005582 Bugs: ProtocolBugs{
5583 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005584 ExpectedCustomExtension: &expectedContents,
5585 },
5586 },
David Benjamin399e7c92015-07-30 23:01:27 -04005587 flags: []string{flag, "-custom-extension-fail-add"},
5588 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005589 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5590 })
5591
5592 // If the add callback returns zero, no extension should be
5593 // added.
5594 skipCustomExtension := expectedContents
5595 if isClient {
5596 // For the case where the client skips sending the
5597 // custom extension, the server must not “echo” it.
5598 skipCustomExtension = ""
5599 }
5600 testCases = append(testCases, testCase{
5601 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005602 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005604 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005605 Bugs: ProtocolBugs{
5606 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005607 ExpectedCustomExtension: &emptyString,
5608 },
5609 },
5610 flags: []string{flag, "-custom-extension-skip"},
5611 })
5612 }
5613
5614 // The custom extension add callback should not be called if the client
5615 // doesn't send the extension.
5616 testCases = append(testCases, testCase{
5617 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005618 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005619 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005620 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005621 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005622 ExpectedCustomExtension: &emptyString,
5623 },
5624 },
5625 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5626 })
Adam Langley2deb9842015-08-07 11:15:37 -07005627
5628 // Test an unknown extension from the server.
5629 testCases = append(testCases, testCase{
5630 testType: clientTest,
5631 name: "UnknownExtension-Client",
5632 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005633 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005634 Bugs: ProtocolBugs{
5635 CustomExtension: expectedContents,
5636 },
5637 },
5638 shouldFail: true,
5639 expectedError: ":UNEXPECTED_EXTENSION:",
5640 })
Adam Langley09505632015-07-30 18:10:13 -07005641}
5642
David Benjaminb36a3952015-12-01 18:53:13 -05005643func addRSAClientKeyExchangeTests() {
5644 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5645 testCases = append(testCases, testCase{
5646 testType: serverTest,
5647 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5648 config: Config{
5649 // Ensure the ClientHello version and final
5650 // version are different, to detect if the
5651 // server uses the wrong one.
5652 MaxVersion: VersionTLS11,
5653 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5654 Bugs: ProtocolBugs{
5655 BadRSAClientKeyExchange: bad,
5656 },
5657 },
5658 shouldFail: true,
5659 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5660 })
5661 }
5662}
5663
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005664var testCurves = []struct {
5665 name string
5666 id CurveID
5667}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005668 {"P-256", CurveP256},
5669 {"P-384", CurveP384},
5670 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005671 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005672}
5673
5674func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005675 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005676 for _, curve := range testCurves {
5677 testCases = append(testCases, testCase{
5678 name: "CurveTest-Client-" + curve.name,
5679 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005680 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005681 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5682 CurvePreferences: []CurveID{curve.id},
5683 },
5684 flags: []string{"-enable-all-curves"},
5685 })
5686 testCases = append(testCases, testCase{
5687 testType: serverTest,
5688 name: "CurveTest-Server-" + curve.name,
5689 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005690 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005691 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5692 CurvePreferences: []CurveID{curve.id},
5693 },
5694 flags: []string{"-enable-all-curves"},
5695 })
5696 }
David Benjamin241ae832016-01-15 03:04:54 -05005697
5698 // The server must be tolerant to bogus curves.
5699 const bogusCurve = 0x1234
5700 testCases = append(testCases, testCase{
5701 testType: serverTest,
5702 name: "UnknownCurve",
5703 config: Config{
5704 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5705 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5706 },
5707 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005708
5709 // The server must not consider ECDHE ciphers when there are no
5710 // supported curves.
5711 testCases = append(testCases, testCase{
5712 testType: serverTest,
5713 name: "NoSupportedCurves",
5714 config: Config{
5715 // TODO(davidben): Add a TLS 1.3 version of this.
5716 MaxVersion: VersionTLS12,
5717 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5718 Bugs: ProtocolBugs{
5719 NoSupportedCurves: true,
5720 },
5721 },
5722 shouldFail: true,
5723 expectedError: ":NO_SHARED_CIPHER:",
5724 })
5725
5726 // The server must fall back to another cipher when there are no
5727 // supported curves.
5728 testCases = append(testCases, testCase{
5729 testType: serverTest,
5730 name: "NoCommonCurves",
5731 config: Config{
5732 MaxVersion: VersionTLS12,
5733 CipherSuites: []uint16{
5734 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5735 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5736 },
5737 CurvePreferences: []CurveID{CurveP224},
5738 },
5739 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5740 })
5741
5742 // The client must reject bogus curves and disabled curves.
5743 testCases = append(testCases, testCase{
5744 name: "BadECDHECurve",
5745 config: Config{
5746 // TODO(davidben): Add a TLS 1.3 version of this.
5747 MaxVersion: VersionTLS12,
5748 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5749 Bugs: ProtocolBugs{
5750 SendCurve: bogusCurve,
5751 },
5752 },
5753 shouldFail: true,
5754 expectedError: ":WRONG_CURVE:",
5755 })
5756
5757 testCases = append(testCases, testCase{
5758 name: "UnsupportedCurve",
5759 config: Config{
5760 // TODO(davidben): Add a TLS 1.3 version of this.
5761 MaxVersion: VersionTLS12,
5762 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5763 CurvePreferences: []CurveID{CurveP256},
5764 Bugs: ProtocolBugs{
5765 IgnorePeerCurvePreferences: true,
5766 },
5767 },
5768 flags: []string{"-p384-only"},
5769 shouldFail: true,
5770 expectedError: ":WRONG_CURVE:",
5771 })
5772
5773 // Test invalid curve points.
5774 testCases = append(testCases, testCase{
5775 name: "InvalidECDHPoint-Client",
5776 config: Config{
5777 // TODO(davidben): Add a TLS 1.3 version of this test.
5778 MaxVersion: VersionTLS12,
5779 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5780 CurvePreferences: []CurveID{CurveP256},
5781 Bugs: ProtocolBugs{
5782 InvalidECDHPoint: true,
5783 },
5784 },
5785 shouldFail: true,
5786 expectedError: ":INVALID_ENCODING:",
5787 })
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "InvalidECDHPoint-Server",
5791 config: Config{
5792 // TODO(davidben): Add a TLS 1.3 version of this test.
5793 MaxVersion: VersionTLS12,
5794 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5795 CurvePreferences: []CurveID{CurveP256},
5796 Bugs: ProtocolBugs{
5797 InvalidECDHPoint: true,
5798 },
5799 },
5800 shouldFail: true,
5801 expectedError: ":INVALID_ENCODING:",
5802 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005803}
5804
Matt Braithwaite54217e42016-06-13 13:03:47 -07005805func addCECPQ1Tests() {
5806 testCases = append(testCases, testCase{
5807 testType: clientTest,
5808 name: "CECPQ1-Client-BadX25519Part",
5809 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005810 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005811 MinVersion: VersionTLS12,
5812 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5813 Bugs: ProtocolBugs{
5814 CECPQ1BadX25519Part: true,
5815 },
5816 },
5817 flags: []string{"-cipher", "kCECPQ1"},
5818 shouldFail: true,
5819 expectedLocalError: "local error: bad record MAC",
5820 })
5821 testCases = append(testCases, testCase{
5822 testType: clientTest,
5823 name: "CECPQ1-Client-BadNewhopePart",
5824 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005825 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005826 MinVersion: VersionTLS12,
5827 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5828 Bugs: ProtocolBugs{
5829 CECPQ1BadNewhopePart: true,
5830 },
5831 },
5832 flags: []string{"-cipher", "kCECPQ1"},
5833 shouldFail: true,
5834 expectedLocalError: "local error: bad record MAC",
5835 })
5836 testCases = append(testCases, testCase{
5837 testType: serverTest,
5838 name: "CECPQ1-Server-BadX25519Part",
5839 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005840 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005841 MinVersion: VersionTLS12,
5842 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5843 Bugs: ProtocolBugs{
5844 CECPQ1BadX25519Part: true,
5845 },
5846 },
5847 flags: []string{"-cipher", "kCECPQ1"},
5848 shouldFail: true,
5849 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5850 })
5851 testCases = append(testCases, testCase{
5852 testType: serverTest,
5853 name: "CECPQ1-Server-BadNewhopePart",
5854 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005855 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005856 MinVersion: VersionTLS12,
5857 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5858 Bugs: ProtocolBugs{
5859 CECPQ1BadNewhopePart: true,
5860 },
5861 },
5862 flags: []string{"-cipher", "kCECPQ1"},
5863 shouldFail: true,
5864 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5865 })
5866}
5867
David Benjamin4cc36ad2015-12-19 14:23:26 -05005868func addKeyExchangeInfoTests() {
5869 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005870 name: "KeyExchangeInfo-DHE-Client",
5871 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005872 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005873 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5874 Bugs: ProtocolBugs{
5875 // This is a 1234-bit prime number, generated
5876 // with:
5877 // openssl gendh 1234 | openssl asn1parse -i
5878 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5879 },
5880 },
David Benjamin9e68f192016-06-30 14:55:33 -04005881 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005882 })
5883 testCases = append(testCases, testCase{
5884 testType: serverTest,
5885 name: "KeyExchangeInfo-DHE-Server",
5886 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005887 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005888 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5889 },
5890 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005891 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005892 })
5893
Nick Harper1fd39d82016-06-14 18:14:35 -07005894 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5895 // handshake is separate.
5896
David Benjamin4cc36ad2015-12-19 14:23:26 -05005897 testCases = append(testCases, testCase{
5898 name: "KeyExchangeInfo-ECDHE-Client",
5899 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005900 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005901 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5902 CurvePreferences: []CurveID{CurveX25519},
5903 },
David Benjamin9e68f192016-06-30 14:55:33 -04005904 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005905 })
5906 testCases = append(testCases, testCase{
5907 testType: serverTest,
5908 name: "KeyExchangeInfo-ECDHE-Server",
5909 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005910 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005911 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5912 CurvePreferences: []CurveID{CurveX25519},
5913 },
David Benjamin9e68f192016-06-30 14:55:33 -04005914 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005915 })
5916}
5917
David Benjaminc9ae27c2016-06-24 22:56:37 -04005918func addTLS13RecordTests() {
5919 testCases = append(testCases, testCase{
5920 name: "TLS13-RecordPadding",
5921 config: Config{
5922 MaxVersion: VersionTLS13,
5923 MinVersion: VersionTLS13,
5924 Bugs: ProtocolBugs{
5925 RecordPadding: 10,
5926 },
5927 },
5928 })
5929
5930 testCases = append(testCases, testCase{
5931 name: "TLS13-EmptyRecords",
5932 config: Config{
5933 MaxVersion: VersionTLS13,
5934 MinVersion: VersionTLS13,
5935 Bugs: ProtocolBugs{
5936 OmitRecordContents: true,
5937 },
5938 },
5939 shouldFail: true,
5940 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5941 })
5942
5943 testCases = append(testCases, testCase{
5944 name: "TLS13-OnlyPadding",
5945 config: Config{
5946 MaxVersion: VersionTLS13,
5947 MinVersion: VersionTLS13,
5948 Bugs: ProtocolBugs{
5949 OmitRecordContents: true,
5950 RecordPadding: 10,
5951 },
5952 },
5953 shouldFail: true,
5954 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5955 })
5956
5957 testCases = append(testCases, testCase{
5958 name: "TLS13-WrongOuterRecord",
5959 config: Config{
5960 MaxVersion: VersionTLS13,
5961 MinVersion: VersionTLS13,
5962 Bugs: ProtocolBugs{
5963 OuterRecordType: recordTypeHandshake,
5964 },
5965 },
5966 shouldFail: true,
5967 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5968 })
5969}
5970
David Benjamin82261be2016-07-07 14:32:50 -07005971func addChangeCipherSpecTests() {
5972 // Test missing ChangeCipherSpecs.
5973 testCases = append(testCases, testCase{
5974 name: "SkipChangeCipherSpec-Client",
5975 config: Config{
5976 MaxVersion: VersionTLS12,
5977 Bugs: ProtocolBugs{
5978 SkipChangeCipherSpec: true,
5979 },
5980 },
5981 shouldFail: true,
5982 expectedError: ":UNEXPECTED_RECORD:",
5983 })
5984 testCases = append(testCases, testCase{
5985 testType: serverTest,
5986 name: "SkipChangeCipherSpec-Server",
5987 config: Config{
5988 MaxVersion: VersionTLS12,
5989 Bugs: ProtocolBugs{
5990 SkipChangeCipherSpec: true,
5991 },
5992 },
5993 shouldFail: true,
5994 expectedError: ":UNEXPECTED_RECORD:",
5995 })
5996 testCases = append(testCases, testCase{
5997 testType: serverTest,
5998 name: "SkipChangeCipherSpec-Server-NPN",
5999 config: Config{
6000 MaxVersion: VersionTLS12,
6001 NextProtos: []string{"bar"},
6002 Bugs: ProtocolBugs{
6003 SkipChangeCipherSpec: true,
6004 },
6005 },
6006 flags: []string{
6007 "-advertise-npn", "\x03foo\x03bar\x03baz",
6008 },
6009 shouldFail: true,
6010 expectedError: ":UNEXPECTED_RECORD:",
6011 })
6012
6013 // Test synchronization between the handshake and ChangeCipherSpec.
6014 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6015 // rejected. Test both with and without handshake packing to handle both
6016 // when the partial post-CCS message is in its own record and when it is
6017 // attached to the pre-CCS message.
6018 //
6019 // TODO(davidben): Fix and test DTLS as well.
6020 for _, packed := range []bool{false, true} {
6021 var suffix string
6022 if packed {
6023 suffix = "-Packed"
6024 }
6025
6026 testCases = append(testCases, testCase{
6027 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6028 config: Config{
6029 MaxVersion: VersionTLS12,
6030 Bugs: ProtocolBugs{
6031 FragmentAcrossChangeCipherSpec: true,
6032 PackHandshakeFlight: packed,
6033 },
6034 },
6035 shouldFail: true,
6036 expectedError: ":UNEXPECTED_RECORD:",
6037 })
6038 testCases = append(testCases, testCase{
6039 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6040 config: Config{
6041 MaxVersion: VersionTLS12,
6042 },
6043 resumeSession: true,
6044 resumeConfig: &Config{
6045 MaxVersion: VersionTLS12,
6046 Bugs: ProtocolBugs{
6047 FragmentAcrossChangeCipherSpec: true,
6048 PackHandshakeFlight: packed,
6049 },
6050 },
6051 shouldFail: true,
6052 expectedError: ":UNEXPECTED_RECORD:",
6053 })
6054 testCases = append(testCases, testCase{
6055 testType: serverTest,
6056 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6057 config: Config{
6058 MaxVersion: VersionTLS12,
6059 Bugs: ProtocolBugs{
6060 FragmentAcrossChangeCipherSpec: true,
6061 PackHandshakeFlight: packed,
6062 },
6063 },
6064 shouldFail: true,
6065 expectedError: ":UNEXPECTED_RECORD:",
6066 })
6067 testCases = append(testCases, testCase{
6068 testType: serverTest,
6069 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6070 config: Config{
6071 MaxVersion: VersionTLS12,
6072 },
6073 resumeSession: true,
6074 resumeConfig: &Config{
6075 MaxVersion: VersionTLS12,
6076 Bugs: ProtocolBugs{
6077 FragmentAcrossChangeCipherSpec: true,
6078 PackHandshakeFlight: packed,
6079 },
6080 },
6081 shouldFail: true,
6082 expectedError: ":UNEXPECTED_RECORD:",
6083 })
6084 testCases = append(testCases, testCase{
6085 testType: serverTest,
6086 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6087 config: Config{
6088 MaxVersion: VersionTLS12,
6089 NextProtos: []string{"bar"},
6090 Bugs: ProtocolBugs{
6091 FragmentAcrossChangeCipherSpec: true,
6092 PackHandshakeFlight: packed,
6093 },
6094 },
6095 flags: []string{
6096 "-advertise-npn", "\x03foo\x03bar\x03baz",
6097 },
6098 shouldFail: true,
6099 expectedError: ":UNEXPECTED_RECORD:",
6100 })
6101 }
6102
6103 // Test that early ChangeCipherSpecs are handled correctly.
6104 testCases = append(testCases, testCase{
6105 testType: serverTest,
6106 name: "EarlyChangeCipherSpec-server-1",
6107 config: Config{
6108 MaxVersion: VersionTLS12,
6109 Bugs: ProtocolBugs{
6110 EarlyChangeCipherSpec: 1,
6111 },
6112 },
6113 shouldFail: true,
6114 expectedError: ":UNEXPECTED_RECORD:",
6115 })
6116 testCases = append(testCases, testCase{
6117 testType: serverTest,
6118 name: "EarlyChangeCipherSpec-server-2",
6119 config: Config{
6120 MaxVersion: VersionTLS12,
6121 Bugs: ProtocolBugs{
6122 EarlyChangeCipherSpec: 2,
6123 },
6124 },
6125 shouldFail: true,
6126 expectedError: ":UNEXPECTED_RECORD:",
6127 })
6128 testCases = append(testCases, testCase{
6129 protocol: dtls,
6130 name: "StrayChangeCipherSpec",
6131 config: Config{
6132 // TODO(davidben): Once DTLS 1.3 exists, test
6133 // that stray ChangeCipherSpec messages are
6134 // rejected.
6135 MaxVersion: VersionTLS12,
6136 Bugs: ProtocolBugs{
6137 StrayChangeCipherSpec: true,
6138 },
6139 },
6140 })
6141
6142 // Test that the contents of ChangeCipherSpec are checked.
6143 testCases = append(testCases, testCase{
6144 name: "BadChangeCipherSpec-1",
6145 config: Config{
6146 MaxVersion: VersionTLS12,
6147 Bugs: ProtocolBugs{
6148 BadChangeCipherSpec: []byte{2},
6149 },
6150 },
6151 shouldFail: true,
6152 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6153 })
6154 testCases = append(testCases, testCase{
6155 name: "BadChangeCipherSpec-2",
6156 config: Config{
6157 MaxVersion: VersionTLS12,
6158 Bugs: ProtocolBugs{
6159 BadChangeCipherSpec: []byte{1, 1},
6160 },
6161 },
6162 shouldFail: true,
6163 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6164 })
6165 testCases = append(testCases, testCase{
6166 protocol: dtls,
6167 name: "BadChangeCipherSpec-DTLS-1",
6168 config: Config{
6169 MaxVersion: VersionTLS12,
6170 Bugs: ProtocolBugs{
6171 BadChangeCipherSpec: []byte{2},
6172 },
6173 },
6174 shouldFail: true,
6175 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6176 })
6177 testCases = append(testCases, testCase{
6178 protocol: dtls,
6179 name: "BadChangeCipherSpec-DTLS-2",
6180 config: Config{
6181 MaxVersion: VersionTLS12,
6182 Bugs: ProtocolBugs{
6183 BadChangeCipherSpec: []byte{1, 1},
6184 },
6185 },
6186 shouldFail: true,
6187 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6188 })
6189}
6190
Adam Langley7c803a62015-06-15 15:35:05 -07006191func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006192 defer wg.Done()
6193
6194 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006195 var err error
6196
6197 if *mallocTest < 0 {
6198 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006199 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006200 } else {
6201 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6202 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006203 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006204 if err != nil {
6205 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6206 }
6207 break
6208 }
6209 }
6210 }
Adam Langley95c29f32014-06-20 12:00:00 -07006211 statusChan <- statusMsg{test: test, err: err}
6212 }
6213}
6214
6215type statusMsg struct {
6216 test *testCase
6217 started bool
6218 err error
6219}
6220
David Benjamin5f237bc2015-02-11 17:14:15 -05006221func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006222 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006223
David Benjamin5f237bc2015-02-11 17:14:15 -05006224 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006225 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006226 if !*pipe {
6227 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006228 var erase string
6229 for i := 0; i < lineLen; i++ {
6230 erase += "\b \b"
6231 }
6232 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006233 }
6234
Adam Langley95c29f32014-06-20 12:00:00 -07006235 if msg.started {
6236 started++
6237 } else {
6238 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006239
6240 if msg.err != nil {
6241 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6242 failed++
6243 testOutput.addResult(msg.test.name, "FAIL")
6244 } else {
6245 if *pipe {
6246 // Print each test instead of a status line.
6247 fmt.Printf("PASSED (%s)\n", msg.test.name)
6248 }
6249 testOutput.addResult(msg.test.name, "PASS")
6250 }
Adam Langley95c29f32014-06-20 12:00:00 -07006251 }
6252
David Benjamin5f237bc2015-02-11 17:14:15 -05006253 if !*pipe {
6254 // Print a new status line.
6255 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6256 lineLen = len(line)
6257 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006258 }
Adam Langley95c29f32014-06-20 12:00:00 -07006259 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006260
6261 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006262}
6263
6264func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006265 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006266 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006267 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006268
Adam Langley7c803a62015-06-15 15:35:05 -07006269 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006270 addCipherSuiteTests()
6271 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006272 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006273 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006274 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006275 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006276 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006277 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006278 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006279 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006280 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006281 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006282 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006283 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006284 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006285 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006286 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006287 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006288 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006289 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006290 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006291 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006292 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006293 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006294 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006295
6296 var wg sync.WaitGroup
6297
Adam Langley7c803a62015-06-15 15:35:05 -07006298 statusChan := make(chan statusMsg, *numWorkers)
6299 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006300 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006301
David Benjamin025b3d32014-07-01 19:53:04 -04006302 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006303
Adam Langley7c803a62015-06-15 15:35:05 -07006304 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006305 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006306 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006307 }
6308
David Benjamin270f0a72016-03-17 14:41:36 -04006309 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006310 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006311 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006312 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006313 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006314 }
6315 }
David Benjamin270f0a72016-03-17 14:41:36 -04006316 if !foundTest {
6317 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6318 os.Exit(1)
6319 }
Adam Langley95c29f32014-06-20 12:00:00 -07006320
6321 close(testChan)
6322 wg.Wait()
6323 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006324 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006325
6326 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006327
6328 if *jsonOutput != "" {
6329 if err := testOutput.writeTo(*jsonOutput); err != nil {
6330 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6331 }
6332 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006333
6334 if !testOutput.allPassed {
6335 os.Exit(1)
6336 }
Adam Langley95c29f32014-06-20 12:00:00 -07006337}