blob: 3e70af8db93d25c90cc46bd3395f703ba4c6a136 [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 Benjamin9deb1172016-07-13 17:13:49 -04002199 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2200 resumeSession := ver.version < VersionTLS13
2201
David Benjamin6fd297b2014-08-11 18:43:38 -04002202 testCases = append(testCases, testCase{
2203 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002204 protocol: protocol,
2205
2206 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002207 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002208 MinVersion: ver.version,
2209 MaxVersion: ver.version,
2210 CipherSuites: []uint16{suite.id},
2211 Certificates: []Certificate{cert},
2212 PreSharedKey: []byte(psk),
2213 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002214 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002215 EnableAllCiphers: shouldServerFail,
2216 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002217 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002218 },
2219 certFile: certFile,
2220 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002221 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002222 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002223 shouldFail: shouldServerFail,
2224 expectedError: expectedServerError,
2225 })
2226
2227 testCases = append(testCases, testCase{
2228 testType: clientTest,
2229 protocol: protocol,
2230 name: prefix + ver.name + "-" + suite.name + "-client",
2231 config: Config{
2232 MinVersion: ver.version,
2233 MaxVersion: ver.version,
2234 CipherSuites: []uint16{suite.id},
2235 Certificates: []Certificate{cert},
2236 PreSharedKey: []byte(psk),
2237 PreSharedKeyIdentity: pskIdentity,
2238 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002239 EnableAllCiphers: shouldClientFail,
2240 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002241 },
2242 },
2243 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002244 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002245 shouldFail: shouldClientFail,
2246 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002247 })
David Benjamin2c99d282015-09-01 10:23:00 -04002248
Nick Harper1fd39d82016-06-14 18:14:35 -07002249 if !shouldClientFail {
2250 // Ensure the maximum record size is accepted.
2251 testCases = append(testCases, testCase{
2252 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2253 config: Config{
2254 MinVersion: ver.version,
2255 MaxVersion: ver.version,
2256 CipherSuites: []uint16{suite.id},
2257 Certificates: []Certificate{cert},
2258 PreSharedKey: []byte(psk),
2259 PreSharedKeyIdentity: pskIdentity,
2260 },
2261 flags: flags,
2262 messageLen: maxPlaintext,
2263 })
2264 }
2265 }
David Benjamin2c99d282015-09-01 10:23:00 -04002266 }
Adam Langley95c29f32014-06-20 12:00:00 -07002267 }
Adam Langleya7997f12015-05-14 17:38:50 -07002268
2269 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002270 name: "NoSharedCipher",
2271 config: Config{
2272 // TODO(davidben): Add a TLS 1.3 version of this test.
2273 MaxVersion: VersionTLS12,
2274 CipherSuites: []uint16{},
2275 },
2276 shouldFail: true,
2277 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2278 })
2279
2280 testCases = append(testCases, testCase{
2281 name: "UnsupportedCipherSuite",
2282 config: Config{
2283 MaxVersion: VersionTLS12,
2284 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2285 Bugs: ProtocolBugs{
2286 IgnorePeerCipherPreferences: true,
2287 },
2288 },
2289 flags: []string{"-cipher", "DEFAULT:!RC4"},
2290 shouldFail: true,
2291 expectedError: ":WRONG_CIPHER_RETURNED:",
2292 })
2293
2294 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002295 name: "WeakDH",
2296 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002297 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002298 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2299 Bugs: ProtocolBugs{
2300 // This is a 1023-bit prime number, generated
2301 // with:
2302 // openssl gendh 1023 | openssl asn1parse -i
2303 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2304 },
2305 },
2306 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002307 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002308 })
Adam Langleycef75832015-09-03 14:51:12 -07002309
David Benjamincd24a392015-11-11 13:23:05 -08002310 testCases = append(testCases, testCase{
2311 name: "SillyDH",
2312 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002313 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002314 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2315 Bugs: ProtocolBugs{
2316 // This is a 4097-bit prime number, generated
2317 // with:
2318 // openssl gendh 4097 | openssl asn1parse -i
2319 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2320 },
2321 },
2322 shouldFail: true,
2323 expectedError: ":DH_P_TOO_LONG:",
2324 })
2325
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002326 // This test ensures that Diffie-Hellman public values are padded with
2327 // zeros so that they're the same length as the prime. This is to avoid
2328 // hitting a bug in yaSSL.
2329 testCases = append(testCases, testCase{
2330 testType: serverTest,
2331 name: "DHPublicValuePadded",
2332 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002333 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002334 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2335 Bugs: ProtocolBugs{
2336 RequireDHPublicValueLen: (1025 + 7) / 8,
2337 },
2338 },
2339 flags: []string{"-use-sparse-dh-prime"},
2340 })
David Benjamincd24a392015-11-11 13:23:05 -08002341
David Benjamin241ae832016-01-15 03:04:54 -05002342 // The server must be tolerant to bogus ciphers.
2343 const bogusCipher = 0x1234
2344 testCases = append(testCases, testCase{
2345 testType: serverTest,
2346 name: "UnknownCipher",
2347 config: Config{
2348 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2349 },
2350 })
2351
Adam Langleycef75832015-09-03 14:51:12 -07002352 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2353 // 1.1 specific cipher suite settings. A server is setup with the given
2354 // cipher lists and then a connection is made for each member of
2355 // expectations. The cipher suite that the server selects must match
2356 // the specified one.
2357 var versionSpecificCiphersTest = []struct {
2358 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2359 // expectations is a map from TLS version to cipher suite id.
2360 expectations map[uint16]uint16
2361 }{
2362 {
2363 // Test that the null case (where no version-specific ciphers are set)
2364 // works as expected.
2365 "RC4-SHA:AES128-SHA", // default ciphers
2366 "", // no ciphers specifically for TLS ≥ 1.0
2367 "", // no ciphers specifically for TLS ≥ 1.1
2368 map[uint16]uint16{
2369 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2370 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2371 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2372 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2373 },
2374 },
2375 {
2376 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2377 // cipher.
2378 "RC4-SHA:AES128-SHA", // default
2379 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2380 "", // no ciphers specifically for TLS ≥ 1.1
2381 map[uint16]uint16{
2382 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2383 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2384 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2385 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2386 },
2387 },
2388 {
2389 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2390 // cipher.
2391 "RC4-SHA:AES128-SHA", // default
2392 "", // no ciphers specifically for TLS ≥ 1.0
2393 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2394 map[uint16]uint16{
2395 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2396 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2397 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2398 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2399 },
2400 },
2401 {
2402 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2403 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2404 "RC4-SHA:AES128-SHA", // default
2405 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2406 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2407 map[uint16]uint16{
2408 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2409 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2410 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2411 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2412 },
2413 },
2414 }
2415
2416 for i, test := range versionSpecificCiphersTest {
2417 for version, expectedCipherSuite := range test.expectations {
2418 flags := []string{"-cipher", test.ciphersDefault}
2419 if len(test.ciphersTLS10) > 0 {
2420 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2421 }
2422 if len(test.ciphersTLS11) > 0 {
2423 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2424 }
2425
2426 testCases = append(testCases, testCase{
2427 testType: serverTest,
2428 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2429 config: Config{
2430 MaxVersion: version,
2431 MinVersion: version,
2432 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2433 },
2434 flags: flags,
2435 expectedCipher: expectedCipherSuite,
2436 })
2437 }
2438 }
Adam Langley95c29f32014-06-20 12:00:00 -07002439}
2440
2441func addBadECDSASignatureTests() {
2442 for badR := BadValue(1); badR < NumBadValues; badR++ {
2443 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002444 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002445 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2446 config: Config{
2447 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002448 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002449 Bugs: ProtocolBugs{
2450 BadECDSAR: badR,
2451 BadECDSAS: badS,
2452 },
2453 },
2454 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002455 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002456 })
2457 }
2458 }
2459}
2460
Adam Langley80842bd2014-06-20 12:00:00 -07002461func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002462 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002463 name: "MaxCBCPadding",
2464 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002465 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002466 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2467 Bugs: ProtocolBugs{
2468 MaxPadding: true,
2469 },
2470 },
2471 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2472 })
David Benjamin025b3d32014-07-01 19:53:04 -04002473 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002474 name: "BadCBCPadding",
2475 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002476 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002477 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2478 Bugs: ProtocolBugs{
2479 PaddingFirstByteBad: true,
2480 },
2481 },
2482 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002483 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002484 })
2485 // OpenSSL previously had an issue where the first byte of padding in
2486 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002487 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002488 name: "BadCBCPadding255",
2489 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002490 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2492 Bugs: ProtocolBugs{
2493 MaxPadding: true,
2494 PaddingFirstByteBadIf255: true,
2495 },
2496 },
2497 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2498 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002499 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002500 })
2501}
2502
Kenny Root7fdeaf12014-08-05 15:23:37 -07002503func addCBCSplittingTests() {
2504 testCases = append(testCases, testCase{
2505 name: "CBCRecordSplitting",
2506 config: Config{
2507 MaxVersion: VersionTLS10,
2508 MinVersion: VersionTLS10,
2509 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2510 },
David Benjaminac8302a2015-09-01 17:18:15 -04002511 messageLen: -1, // read until EOF
2512 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002513 flags: []string{
2514 "-async",
2515 "-write-different-record-sizes",
2516 "-cbc-record-splitting",
2517 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002518 })
2519 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002520 name: "CBCRecordSplittingPartialWrite",
2521 config: Config{
2522 MaxVersion: VersionTLS10,
2523 MinVersion: VersionTLS10,
2524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2525 },
2526 messageLen: -1, // read until EOF
2527 flags: []string{
2528 "-async",
2529 "-write-different-record-sizes",
2530 "-cbc-record-splitting",
2531 "-partial-write",
2532 },
2533 })
2534}
2535
David Benjamin636293b2014-07-08 17:59:18 -04002536func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002537 // Add a dummy cert pool to stress certificate authority parsing.
2538 // TODO(davidben): Add tests that those values parse out correctly.
2539 certPool := x509.NewCertPool()
2540 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2541 if err != nil {
2542 panic(err)
2543 }
2544 certPool.AddCert(cert)
2545
David Benjamin636293b2014-07-08 17:59:18 -04002546 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002547 testCases = append(testCases, testCase{
2548 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002549 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002550 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002551 MinVersion: ver.version,
2552 MaxVersion: ver.version,
2553 ClientAuth: RequireAnyClientCert,
2554 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002555 },
2556 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002557 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2558 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002559 },
2560 })
2561 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002562 testType: serverTest,
2563 name: ver.name + "-Server-ClientAuth-RSA",
2564 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002565 MinVersion: ver.version,
2566 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002567 Certificates: []Certificate{rsaCertificate},
2568 },
2569 flags: []string{"-require-any-client-certificate"},
2570 })
David Benjamine098ec22014-08-27 23:13:20 -04002571 if ver.version != VersionSSL30 {
2572 testCases = append(testCases, testCase{
2573 testType: serverTest,
2574 name: ver.name + "-Server-ClientAuth-ECDSA",
2575 config: Config{
2576 MinVersion: ver.version,
2577 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002578 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002579 },
2580 flags: []string{"-require-any-client-certificate"},
2581 })
2582 testCases = append(testCases, testCase{
2583 testType: clientTest,
2584 name: ver.name + "-Client-ClientAuth-ECDSA",
2585 config: Config{
2586 MinVersion: ver.version,
2587 MaxVersion: ver.version,
2588 ClientAuth: RequireAnyClientCert,
2589 ClientCAs: certPool,
2590 },
2591 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002592 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2593 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002594 },
2595 })
2596 }
David Benjamin636293b2014-07-08 17:59:18 -04002597 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002598
Nick Harper1fd39d82016-06-14 18:14:35 -07002599 // TODO(davidben): These tests will need TLS 1.3 versions when the
2600 // handshake is separate.
2601
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002602 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002603 name: "NoClientCertificate",
2604 config: Config{
2605 MaxVersion: VersionTLS12,
2606 ClientAuth: RequireAnyClientCert,
2607 },
2608 shouldFail: true,
2609 expectedLocalError: "client didn't provide a certificate",
2610 })
2611
2612 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002613 testType: serverTest,
2614 name: "RequireAnyClientCertificate",
2615 config: Config{
2616 MaxVersion: VersionTLS12,
2617 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002618 flags: []string{"-require-any-client-certificate"},
2619 shouldFail: true,
2620 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2621 })
2622
2623 testCases = append(testCases, testCase{
2624 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002625 name: "RequireAnyClientCertificate-SSL3",
2626 config: Config{
2627 MaxVersion: VersionSSL30,
2628 },
2629 flags: []string{"-require-any-client-certificate"},
2630 shouldFail: true,
2631 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2632 })
2633
2634 testCases = append(testCases, testCase{
2635 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002636 name: "SkipClientCertificate",
2637 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002638 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002639 Bugs: ProtocolBugs{
2640 SkipClientCertificate: true,
2641 },
2642 },
2643 // Setting SSL_VERIFY_PEER allows anonymous clients.
2644 flags: []string{"-verify-peer"},
2645 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002646 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002647 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002648
2649 // Client auth is only legal in certificate-based ciphers.
2650 testCases = append(testCases, testCase{
2651 testType: clientTest,
2652 name: "ClientAuth-PSK",
2653 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002654 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002655 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2656 PreSharedKey: []byte("secret"),
2657 ClientAuth: RequireAnyClientCert,
2658 },
2659 flags: []string{
2660 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2661 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2662 "-psk", "secret",
2663 },
2664 shouldFail: true,
2665 expectedError: ":UNEXPECTED_MESSAGE:",
2666 })
2667 testCases = append(testCases, testCase{
2668 testType: clientTest,
2669 name: "ClientAuth-ECDHE_PSK",
2670 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002671 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002672 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2673 PreSharedKey: []byte("secret"),
2674 ClientAuth: RequireAnyClientCert,
2675 },
2676 flags: []string{
2677 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2678 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2679 "-psk", "secret",
2680 },
2681 shouldFail: true,
2682 expectedError: ":UNEXPECTED_MESSAGE:",
2683 })
David Benjamin636293b2014-07-08 17:59:18 -04002684}
2685
Adam Langley75712922014-10-10 16:23:43 -07002686func addExtendedMasterSecretTests() {
2687 const expectEMSFlag = "-expect-extended-master-secret"
2688
2689 for _, with := range []bool{false, true} {
2690 prefix := "No"
2691 var flags []string
2692 if with {
2693 prefix = ""
2694 flags = []string{expectEMSFlag}
2695 }
2696
2697 for _, isClient := range []bool{false, true} {
2698 suffix := "-Server"
2699 testType := serverTest
2700 if isClient {
2701 suffix = "-Client"
2702 testType = clientTest
2703 }
2704
David Benjamin4c3ddf72016-06-29 18:13:53 -04002705 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2706 // test that the extension is irrelevant, but the API
2707 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002708 for _, ver := range tlsVersions {
2709 test := testCase{
2710 testType: testType,
2711 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2712 config: Config{
2713 MinVersion: ver.version,
2714 MaxVersion: ver.version,
2715 Bugs: ProtocolBugs{
2716 NoExtendedMasterSecret: !with,
2717 RequireExtendedMasterSecret: with,
2718 },
2719 },
David Benjamin48cae082014-10-27 01:06:24 -04002720 flags: flags,
2721 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002722 }
2723 if test.shouldFail {
2724 test.expectedLocalError = "extended master secret required but not supported by peer"
2725 }
2726 testCases = append(testCases, test)
2727 }
2728 }
2729 }
2730
Adam Langleyba5934b2015-06-02 10:50:35 -07002731 for _, isClient := range []bool{false, true} {
2732 for _, supportedInFirstConnection := range []bool{false, true} {
2733 for _, supportedInResumeConnection := range []bool{false, true} {
2734 boolToWord := func(b bool) string {
2735 if b {
2736 return "Yes"
2737 }
2738 return "No"
2739 }
2740 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2741 if isClient {
2742 suffix += "Client"
2743 } else {
2744 suffix += "Server"
2745 }
2746
2747 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002748 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002749 Bugs: ProtocolBugs{
2750 RequireExtendedMasterSecret: true,
2751 },
2752 }
2753
2754 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002755 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002756 Bugs: ProtocolBugs{
2757 NoExtendedMasterSecret: true,
2758 },
2759 }
2760
2761 test := testCase{
2762 name: "ExtendedMasterSecret-" + suffix,
2763 resumeSession: true,
2764 }
2765
2766 if !isClient {
2767 test.testType = serverTest
2768 }
2769
2770 if supportedInFirstConnection {
2771 test.config = supportedConfig
2772 } else {
2773 test.config = noSupportConfig
2774 }
2775
2776 if supportedInResumeConnection {
2777 test.resumeConfig = &supportedConfig
2778 } else {
2779 test.resumeConfig = &noSupportConfig
2780 }
2781
2782 switch suffix {
2783 case "YesToYes-Client", "YesToYes-Server":
2784 // When a session is resumed, it should
2785 // still be aware that its master
2786 // secret was generated via EMS and
2787 // thus it's safe to use tls-unique.
2788 test.flags = []string{expectEMSFlag}
2789 case "NoToYes-Server":
2790 // If an original connection did not
2791 // contain EMS, but a resumption
2792 // handshake does, then a server should
2793 // not resume the session.
2794 test.expectResumeRejected = true
2795 case "YesToNo-Server":
2796 // Resuming an EMS session without the
2797 // EMS extension should cause the
2798 // server to abort the connection.
2799 test.shouldFail = true
2800 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2801 case "NoToYes-Client":
2802 // A client should abort a connection
2803 // where the server resumed a non-EMS
2804 // session but echoed the EMS
2805 // extension.
2806 test.shouldFail = true
2807 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2808 case "YesToNo-Client":
2809 // A client should abort a connection
2810 // where the server didn't echo EMS
2811 // when the session used it.
2812 test.shouldFail = true
2813 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2814 }
2815
2816 testCases = append(testCases, test)
2817 }
2818 }
2819 }
Adam Langley75712922014-10-10 16:23:43 -07002820}
2821
David Benjamin582ba042016-07-07 12:33:25 -07002822type stateMachineTestConfig struct {
2823 protocol protocol
2824 async bool
2825 splitHandshake, packHandshakeFlight bool
2826}
2827
David Benjamin43ec06f2014-08-05 02:28:57 -04002828// Adds tests that try to cover the range of the handshake state machine, under
2829// various conditions. Some of these are redundant with other tests, but they
2830// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002831func addAllStateMachineCoverageTests() {
2832 for _, async := range []bool{false, true} {
2833 for _, protocol := range []protocol{tls, dtls} {
2834 addStateMachineCoverageTests(stateMachineTestConfig{
2835 protocol: protocol,
2836 async: async,
2837 })
2838 addStateMachineCoverageTests(stateMachineTestConfig{
2839 protocol: protocol,
2840 async: async,
2841 splitHandshake: true,
2842 })
2843 if protocol == tls {
2844 addStateMachineCoverageTests(stateMachineTestConfig{
2845 protocol: protocol,
2846 async: async,
2847 packHandshakeFlight: true,
2848 })
2849 }
2850 }
2851 }
2852}
2853
2854func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002855 var tests []testCase
2856
2857 // Basic handshake, with resumption. Client and server,
2858 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002859 //
2860 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2861 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002862 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002863 name: "Basic-Client",
2864 config: Config{
2865 MaxVersion: VersionTLS12,
2866 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002867 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002868 // Ensure session tickets are used, not session IDs.
2869 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002870 })
2871 tests = append(tests, testCase{
2872 name: "Basic-Client-RenewTicket",
2873 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002874 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002875 Bugs: ProtocolBugs{
2876 RenewTicketOnResume: true,
2877 },
2878 },
David Benjaminba4594a2015-06-18 18:36:15 -04002879 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002880 resumeSession: true,
2881 })
2882 tests = append(tests, testCase{
2883 name: "Basic-Client-NoTicket",
2884 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002885 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002886 SessionTicketsDisabled: true,
2887 },
2888 resumeSession: true,
2889 })
2890 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002891 name: "Basic-Client-Implicit",
2892 config: Config{
2893 MaxVersion: VersionTLS12,
2894 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002895 flags: []string{"-implicit-handshake"},
2896 resumeSession: true,
2897 })
2898 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002899 testType: serverTest,
2900 name: "Basic-Server",
2901 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002902 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002903 Bugs: ProtocolBugs{
2904 RequireSessionTickets: true,
2905 },
2906 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002907 resumeSession: true,
2908 })
2909 tests = append(tests, testCase{
2910 testType: serverTest,
2911 name: "Basic-Server-NoTickets",
2912 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002913 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002914 SessionTicketsDisabled: true,
2915 },
2916 resumeSession: true,
2917 })
2918 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002919 testType: serverTest,
2920 name: "Basic-Server-Implicit",
2921 config: Config{
2922 MaxVersion: VersionTLS12,
2923 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002924 flags: []string{"-implicit-handshake"},
2925 resumeSession: true,
2926 })
2927 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002928 testType: serverTest,
2929 name: "Basic-Server-EarlyCallback",
2930 config: Config{
2931 MaxVersion: VersionTLS12,
2932 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002933 flags: []string{"-use-early-callback"},
2934 resumeSession: true,
2935 })
2936
2937 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002938 //
2939 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002940 tests = append(tests, testCase{
2941 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002942 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002943 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002944 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002945 ClientAuth: RequestClientCert,
2946 },
2947 })
2948 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002949 testType: serverTest,
2950 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002951 config: Config{
2952 MaxVersion: VersionTLS12,
2953 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002954 // Setting SSL_VERIFY_PEER allows anonymous clients.
2955 flags: []string{"-verify-peer"},
2956 })
David Benjamin582ba042016-07-07 12:33:25 -07002957 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002958 tests = append(tests, testCase{
2959 testType: clientTest,
2960 name: "ClientAuth-NoCertificate-Client-SSL3",
2961 config: Config{
2962 MaxVersion: VersionSSL30,
2963 ClientAuth: RequestClientCert,
2964 },
2965 })
2966 tests = append(tests, testCase{
2967 testType: serverTest,
2968 name: "ClientAuth-NoCertificate-Server-SSL3",
2969 config: Config{
2970 MaxVersion: VersionSSL30,
2971 },
2972 // Setting SSL_VERIFY_PEER allows anonymous clients.
2973 flags: []string{"-verify-peer"},
2974 })
2975 }
2976 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002977 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002978 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002980 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002981 ClientAuth: RequireAnyClientCert,
2982 },
2983 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002984 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2985 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002986 },
2987 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002988 tests = append(tests, testCase{
2989 testType: clientTest,
2990 name: "ClientAuth-ECDSA-Client",
2991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002992 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002993 ClientAuth: RequireAnyClientCert,
2994 },
2995 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002996 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2997 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002998 },
2999 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003000 tests = append(tests, testCase{
3001 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003002 name: "ClientAuth-NoCertificate-OldCallback",
3003 config: Config{
3004 MaxVersion: VersionTLS12,
3005 ClientAuth: RequestClientCert,
3006 },
3007 flags: []string{"-use-old-client-cert-callback"},
3008 })
3009 tests = append(tests, testCase{
3010 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003011 name: "ClientAuth-OldCallback",
3012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003013 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003014 ClientAuth: RequireAnyClientCert,
3015 },
3016 flags: []string{
3017 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3018 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3019 "-use-old-client-cert-callback",
3020 },
3021 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003022 tests = append(tests, testCase{
3023 testType: serverTest,
3024 name: "ClientAuth-Server",
3025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003026 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003027 Certificates: []Certificate{rsaCertificate},
3028 },
3029 flags: []string{"-require-any-client-certificate"},
3030 })
3031
David Benjamin4c3ddf72016-06-29 18:13:53 -04003032 // Test each key exchange on the server side for async keys.
3033 //
3034 // TODO(davidben): Add TLS 1.3 versions of these.
3035 tests = append(tests, testCase{
3036 testType: serverTest,
3037 name: "Basic-Server-RSA",
3038 config: Config{
3039 MaxVersion: VersionTLS12,
3040 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3041 },
3042 flags: []string{
3043 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3044 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3045 },
3046 })
3047 tests = append(tests, testCase{
3048 testType: serverTest,
3049 name: "Basic-Server-ECDHE-RSA",
3050 config: Config{
3051 MaxVersion: VersionTLS12,
3052 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3053 },
3054 flags: []string{
3055 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3056 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3057 },
3058 })
3059 tests = append(tests, testCase{
3060 testType: serverTest,
3061 name: "Basic-Server-ECDHE-ECDSA",
3062 config: Config{
3063 MaxVersion: VersionTLS12,
3064 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3065 },
3066 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003067 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3068 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003069 },
3070 })
3071
David Benjamin760b1dd2015-05-15 23:33:48 -04003072 // No session ticket support; server doesn't send NewSessionTicket.
3073 tests = append(tests, testCase{
3074 name: "SessionTicketsDisabled-Client",
3075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003076 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003077 SessionTicketsDisabled: true,
3078 },
3079 })
3080 tests = append(tests, testCase{
3081 testType: serverTest,
3082 name: "SessionTicketsDisabled-Server",
3083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003084 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003085 SessionTicketsDisabled: true,
3086 },
3087 })
3088
3089 // Skip ServerKeyExchange in PSK key exchange if there's no
3090 // identity hint.
3091 tests = append(tests, testCase{
3092 name: "EmptyPSKHint-Client",
3093 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003094 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003095 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3096 PreSharedKey: []byte("secret"),
3097 },
3098 flags: []string{"-psk", "secret"},
3099 })
3100 tests = append(tests, testCase{
3101 testType: serverTest,
3102 name: "EmptyPSKHint-Server",
3103 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003104 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003105 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3106 PreSharedKey: []byte("secret"),
3107 },
3108 flags: []string{"-psk", "secret"},
3109 })
3110
David Benjamin4c3ddf72016-06-29 18:13:53 -04003111 // OCSP stapling tests.
3112 //
3113 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003114 tests = append(tests, testCase{
3115 testType: clientTest,
3116 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003117 config: Config{
3118 MaxVersion: VersionTLS12,
3119 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003120 flags: []string{
3121 "-enable-ocsp-stapling",
3122 "-expect-ocsp-response",
3123 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003124 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003125 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003126 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003127 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003128 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003129 testType: serverTest,
3130 name: "OCSPStapling-Server",
3131 config: Config{
3132 MaxVersion: VersionTLS12,
3133 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003134 expectedOCSPResponse: testOCSPResponse,
3135 flags: []string{
3136 "-ocsp-response",
3137 base64.StdEncoding.EncodeToString(testOCSPResponse),
3138 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003139 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003140 })
3141
David Benjamin4c3ddf72016-06-29 18:13:53 -04003142 // Certificate verification tests.
3143 //
3144 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003145 tests = append(tests, testCase{
3146 testType: clientTest,
3147 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003148 config: Config{
3149 MaxVersion: VersionTLS12,
3150 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003151 flags: []string{
3152 "-verify-peer",
3153 },
3154 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003155 tests = append(tests, testCase{
3156 testType: clientTest,
3157 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003158 config: Config{
3159 MaxVersion: VersionTLS12,
3160 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003161 flags: []string{
3162 "-verify-fail",
3163 "-verify-peer",
3164 },
3165 shouldFail: true,
3166 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3167 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003168 tests = append(tests, testCase{
3169 testType: clientTest,
3170 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003171 config: Config{
3172 MaxVersion: VersionTLS12,
3173 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003174 flags: []string{
3175 "-verify-fail",
3176 "-expect-verify-result",
3177 },
3178 })
3179
David Benjamin582ba042016-07-07 12:33:25 -07003180 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003181 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003182 name: "Renegotiate-Client",
3183 config: Config{
3184 MaxVersion: VersionTLS12,
3185 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003186 renegotiate: 1,
3187 flags: []string{
3188 "-renegotiate-freely",
3189 "-expect-total-renegotiations", "1",
3190 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003191 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003192
David Benjamin760b1dd2015-05-15 23:33:48 -04003193 // NPN on client and server; results in post-handshake message.
3194 tests = append(tests, testCase{
3195 name: "NPN-Client",
3196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003197 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003198 NextProtos: []string{"foo"},
3199 },
3200 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003201 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003202 expectedNextProto: "foo",
3203 expectedNextProtoType: npn,
3204 })
3205 tests = append(tests, testCase{
3206 testType: serverTest,
3207 name: "NPN-Server",
3208 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003209 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003210 NextProtos: []string{"bar"},
3211 },
3212 flags: []string{
3213 "-advertise-npn", "\x03foo\x03bar\x03baz",
3214 "-expect-next-proto", "bar",
3215 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003216 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003217 expectedNextProto: "bar",
3218 expectedNextProtoType: npn,
3219 })
3220
3221 // TODO(davidben): Add tests for when False Start doesn't trigger.
3222
3223 // Client does False Start and negotiates NPN.
3224 tests = append(tests, testCase{
3225 name: "FalseStart",
3226 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003227 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003228 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3229 NextProtos: []string{"foo"},
3230 Bugs: ProtocolBugs{
3231 ExpectFalseStart: true,
3232 },
3233 },
3234 flags: []string{
3235 "-false-start",
3236 "-select-next-proto", "foo",
3237 },
3238 shimWritesFirst: true,
3239 resumeSession: true,
3240 })
3241
3242 // Client does False Start and negotiates ALPN.
3243 tests = append(tests, testCase{
3244 name: "FalseStart-ALPN",
3245 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003246 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003247 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3248 NextProtos: []string{"foo"},
3249 Bugs: ProtocolBugs{
3250 ExpectFalseStart: true,
3251 },
3252 },
3253 flags: []string{
3254 "-false-start",
3255 "-advertise-alpn", "\x03foo",
3256 },
3257 shimWritesFirst: true,
3258 resumeSession: true,
3259 })
3260
3261 // Client does False Start but doesn't explicitly call
3262 // SSL_connect.
3263 tests = append(tests, testCase{
3264 name: "FalseStart-Implicit",
3265 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003266 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003267 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3268 NextProtos: []string{"foo"},
3269 },
3270 flags: []string{
3271 "-implicit-handshake",
3272 "-false-start",
3273 "-advertise-alpn", "\x03foo",
3274 },
3275 })
3276
3277 // False Start without session tickets.
3278 tests = append(tests, testCase{
3279 name: "FalseStart-SessionTicketsDisabled",
3280 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003281 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003282 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3283 NextProtos: []string{"foo"},
3284 SessionTicketsDisabled: true,
3285 Bugs: ProtocolBugs{
3286 ExpectFalseStart: true,
3287 },
3288 },
3289 flags: []string{
3290 "-false-start",
3291 "-select-next-proto", "foo",
3292 },
3293 shimWritesFirst: true,
3294 })
3295
Adam Langleydf759b52016-07-11 15:24:37 -07003296 tests = append(tests, testCase{
3297 name: "FalseStart-CECPQ1",
3298 config: Config{
3299 MaxVersion: VersionTLS12,
3300 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3301 NextProtos: []string{"foo"},
3302 Bugs: ProtocolBugs{
3303 ExpectFalseStart: true,
3304 },
3305 },
3306 flags: []string{
3307 "-false-start",
3308 "-cipher", "DEFAULT:kCECPQ1",
3309 "-select-next-proto", "foo",
3310 },
3311 shimWritesFirst: true,
3312 resumeSession: true,
3313 })
3314
David Benjamin760b1dd2015-05-15 23:33:48 -04003315 // Server parses a V2ClientHello.
3316 tests = append(tests, testCase{
3317 testType: serverTest,
3318 name: "SendV2ClientHello",
3319 config: Config{
3320 // Choose a cipher suite that does not involve
3321 // elliptic curves, so no extensions are
3322 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003323 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003324 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3325 Bugs: ProtocolBugs{
3326 SendV2ClientHello: true,
3327 },
3328 },
3329 })
3330
3331 // Client sends a Channel ID.
3332 tests = append(tests, testCase{
3333 name: "ChannelID-Client",
3334 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003335 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003336 RequestChannelID: true,
3337 },
Adam Langley7c803a62015-06-15 15:35:05 -07003338 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003339 resumeSession: true,
3340 expectChannelID: true,
3341 })
3342
3343 // Server accepts a Channel ID.
3344 tests = append(tests, testCase{
3345 testType: serverTest,
3346 name: "ChannelID-Server",
3347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 MaxVersion: VersionTLS12,
3349 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003350 },
3351 flags: []string{
3352 "-expect-channel-id",
3353 base64.StdEncoding.EncodeToString(channelIDBytes),
3354 },
3355 resumeSession: true,
3356 expectChannelID: true,
3357 })
David Benjamin30789da2015-08-29 22:56:45 -04003358
David Benjaminf8fcdf32016-06-08 15:56:13 -04003359 // Channel ID and NPN at the same time, to ensure their relative
3360 // ordering is correct.
3361 tests = append(tests, testCase{
3362 name: "ChannelID-NPN-Client",
3363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003364 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003365 RequestChannelID: true,
3366 NextProtos: []string{"foo"},
3367 },
3368 flags: []string{
3369 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3370 "-select-next-proto", "foo",
3371 },
3372 resumeSession: true,
3373 expectChannelID: true,
3374 expectedNextProto: "foo",
3375 expectedNextProtoType: npn,
3376 })
3377 tests = append(tests, testCase{
3378 testType: serverTest,
3379 name: "ChannelID-NPN-Server",
3380 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003381 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003382 ChannelID: channelIDKey,
3383 NextProtos: []string{"bar"},
3384 },
3385 flags: []string{
3386 "-expect-channel-id",
3387 base64.StdEncoding.EncodeToString(channelIDBytes),
3388 "-advertise-npn", "\x03foo\x03bar\x03baz",
3389 "-expect-next-proto", "bar",
3390 },
3391 resumeSession: true,
3392 expectChannelID: true,
3393 expectedNextProto: "bar",
3394 expectedNextProtoType: npn,
3395 })
3396
David Benjamin30789da2015-08-29 22:56:45 -04003397 // Bidirectional shutdown with the runner initiating.
3398 tests = append(tests, testCase{
3399 name: "Shutdown-Runner",
3400 config: Config{
3401 Bugs: ProtocolBugs{
3402 ExpectCloseNotify: true,
3403 },
3404 },
3405 flags: []string{"-check-close-notify"},
3406 })
3407
3408 // Bidirectional shutdown with the shim initiating. The runner,
3409 // in the meantime, sends garbage before the close_notify which
3410 // the shim must ignore.
3411 tests = append(tests, testCase{
3412 name: "Shutdown-Shim",
3413 config: Config{
3414 Bugs: ProtocolBugs{
3415 ExpectCloseNotify: true,
3416 },
3417 },
3418 shimShutsDown: true,
3419 sendEmptyRecords: 1,
3420 sendWarningAlerts: 1,
3421 flags: []string{"-check-close-notify"},
3422 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003423 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003424 // TODO(davidben): DTLS 1.3 will want a similar thing for
3425 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003426 tests = append(tests, testCase{
3427 name: "SkipHelloVerifyRequest",
3428 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003429 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003430 Bugs: ProtocolBugs{
3431 SkipHelloVerifyRequest: true,
3432 },
3433 },
3434 })
3435 }
3436
David Benjamin760b1dd2015-05-15 23:33:48 -04003437 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003438 test.protocol = config.protocol
3439 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003440 test.name += "-DTLS"
3441 }
David Benjamin582ba042016-07-07 12:33:25 -07003442 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003443 test.name += "-Async"
3444 test.flags = append(test.flags, "-async")
3445 } else {
3446 test.name += "-Sync"
3447 }
David Benjamin582ba042016-07-07 12:33:25 -07003448 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003449 test.name += "-SplitHandshakeRecords"
3450 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003451 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003452 test.config.Bugs.MaxPacketLength = 256
3453 test.flags = append(test.flags, "-mtu", "256")
3454 }
3455 }
David Benjamin582ba042016-07-07 12:33:25 -07003456 if config.packHandshakeFlight {
3457 test.name += "-PackHandshakeFlight"
3458 test.config.Bugs.PackHandshakeFlight = true
3459 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003460 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003461 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003462}
3463
Adam Langley524e7172015-02-20 16:04:00 -08003464func addDDoSCallbackTests() {
3465 // DDoS callback.
3466
3467 for _, resume := range []bool{false, true} {
3468 suffix := "Resume"
3469 if resume {
3470 suffix = "No" + suffix
3471 }
3472
David Benjamin4c3ddf72016-06-29 18:13:53 -04003473 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3474
Adam Langley524e7172015-02-20 16:04:00 -08003475 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003476 testType: serverTest,
3477 name: "Server-DDoS-OK-" + suffix,
3478 config: Config{
3479 MaxVersion: VersionTLS12,
3480 },
Adam Langley524e7172015-02-20 16:04:00 -08003481 flags: []string{"-install-ddos-callback"},
3482 resumeSession: resume,
3483 })
3484
3485 failFlag := "-fail-ddos-callback"
3486 if resume {
3487 failFlag = "-fail-second-ddos-callback"
3488 }
3489 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003490 testType: serverTest,
3491 name: "Server-DDoS-Reject-" + suffix,
3492 config: Config{
3493 MaxVersion: VersionTLS12,
3494 },
Adam Langley524e7172015-02-20 16:04:00 -08003495 flags: []string{"-install-ddos-callback", failFlag},
3496 resumeSession: resume,
3497 shouldFail: true,
3498 expectedError: ":CONNECTION_REJECTED:",
3499 })
3500 }
3501}
3502
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003503func addVersionNegotiationTests() {
3504 for i, shimVers := range tlsVersions {
3505 // Assemble flags to disable all newer versions on the shim.
3506 var flags []string
3507 for _, vers := range tlsVersions[i+1:] {
3508 flags = append(flags, vers.flag)
3509 }
3510
3511 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003512 protocols := []protocol{tls}
3513 if runnerVers.hasDTLS && shimVers.hasDTLS {
3514 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003515 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003516 for _, protocol := range protocols {
3517 expectedVersion := shimVers.version
3518 if runnerVers.version < shimVers.version {
3519 expectedVersion = runnerVers.version
3520 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003521
David Benjamin8b8c0062014-11-23 02:47:52 -05003522 suffix := shimVers.name + "-" + runnerVers.name
3523 if protocol == dtls {
3524 suffix += "-DTLS"
3525 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003526
David Benjamin1eb367c2014-12-12 18:17:51 -05003527 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3528
David Benjamin1e29a6b2014-12-10 02:27:24 -05003529 clientVers := shimVers.version
3530 if clientVers > VersionTLS10 {
3531 clientVers = VersionTLS10
3532 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003533 serverVers := expectedVersion
3534 if expectedVersion >= VersionTLS13 {
3535 serverVers = VersionTLS10
3536 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003537 testCases = append(testCases, testCase{
3538 protocol: protocol,
3539 testType: clientTest,
3540 name: "VersionNegotiation-Client-" + suffix,
3541 config: Config{
3542 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003543 Bugs: ProtocolBugs{
3544 ExpectInitialRecordVersion: clientVers,
3545 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003546 },
3547 flags: flags,
3548 expectedVersion: expectedVersion,
3549 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003550 testCases = append(testCases, testCase{
3551 protocol: protocol,
3552 testType: clientTest,
3553 name: "VersionNegotiation-Client2-" + suffix,
3554 config: Config{
3555 MaxVersion: runnerVers.version,
3556 Bugs: ProtocolBugs{
3557 ExpectInitialRecordVersion: clientVers,
3558 },
3559 },
3560 flags: []string{"-max-version", shimVersFlag},
3561 expectedVersion: expectedVersion,
3562 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003563
3564 testCases = append(testCases, testCase{
3565 protocol: protocol,
3566 testType: serverTest,
3567 name: "VersionNegotiation-Server-" + suffix,
3568 config: Config{
3569 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003570 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003571 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003572 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003573 },
3574 flags: flags,
3575 expectedVersion: expectedVersion,
3576 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003577 testCases = append(testCases, testCase{
3578 protocol: protocol,
3579 testType: serverTest,
3580 name: "VersionNegotiation-Server2-" + suffix,
3581 config: Config{
3582 MaxVersion: runnerVers.version,
3583 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003584 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003585 },
3586 },
3587 flags: []string{"-max-version", shimVersFlag},
3588 expectedVersion: expectedVersion,
3589 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003590 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003591 }
3592 }
David Benjamin95c69562016-06-29 18:15:03 -04003593
3594 // Test for version tolerance.
3595 testCases = append(testCases, testCase{
3596 testType: serverTest,
3597 name: "MinorVersionTolerance",
3598 config: Config{
3599 Bugs: ProtocolBugs{
3600 SendClientVersion: 0x03ff,
3601 },
3602 },
3603 expectedVersion: VersionTLS13,
3604 })
3605 testCases = append(testCases, testCase{
3606 testType: serverTest,
3607 name: "MajorVersionTolerance",
3608 config: Config{
3609 Bugs: ProtocolBugs{
3610 SendClientVersion: 0x0400,
3611 },
3612 },
3613 expectedVersion: VersionTLS13,
3614 })
3615 testCases = append(testCases, testCase{
3616 protocol: dtls,
3617 testType: serverTest,
3618 name: "MinorVersionTolerance-DTLS",
3619 config: Config{
3620 Bugs: ProtocolBugs{
3621 SendClientVersion: 0x03ff,
3622 },
3623 },
3624 expectedVersion: VersionTLS12,
3625 })
3626 testCases = append(testCases, testCase{
3627 protocol: dtls,
3628 testType: serverTest,
3629 name: "MajorVersionTolerance-DTLS",
3630 config: Config{
3631 Bugs: ProtocolBugs{
3632 SendClientVersion: 0x0400,
3633 },
3634 },
3635 expectedVersion: VersionTLS12,
3636 })
3637
3638 // Test that versions below 3.0 are rejected.
3639 testCases = append(testCases, testCase{
3640 testType: serverTest,
3641 name: "VersionTooLow",
3642 config: Config{
3643 Bugs: ProtocolBugs{
3644 SendClientVersion: 0x0200,
3645 },
3646 },
3647 shouldFail: true,
3648 expectedError: ":UNSUPPORTED_PROTOCOL:",
3649 })
3650 testCases = append(testCases, testCase{
3651 protocol: dtls,
3652 testType: serverTest,
3653 name: "VersionTooLow-DTLS",
3654 config: Config{
3655 Bugs: ProtocolBugs{
3656 // 0x0201 is the lowest version expressable in
3657 // DTLS.
3658 SendClientVersion: 0x0201,
3659 },
3660 },
3661 shouldFail: true,
3662 expectedError: ":UNSUPPORTED_PROTOCOL:",
3663 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003664
3665 // Test TLS 1.3's downgrade signal.
3666 testCases = append(testCases, testCase{
3667 name: "Downgrade-TLS12-Client",
3668 config: Config{
3669 Bugs: ProtocolBugs{
3670 NegotiateVersion: VersionTLS12,
3671 },
3672 },
3673 shouldFail: true,
3674 expectedError: ":DOWNGRADE_DETECTED:",
3675 })
3676 testCases = append(testCases, testCase{
3677 testType: serverTest,
3678 name: "Downgrade-TLS12-Server",
3679 config: Config{
3680 Bugs: ProtocolBugs{
3681 SendClientVersion: VersionTLS12,
3682 },
3683 },
3684 shouldFail: true,
3685 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3686 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003687}
3688
David Benjaminaccb4542014-12-12 23:44:33 -05003689func addMinimumVersionTests() {
3690 for i, shimVers := range tlsVersions {
3691 // Assemble flags to disable all older versions on the shim.
3692 var flags []string
3693 for _, vers := range tlsVersions[:i] {
3694 flags = append(flags, vers.flag)
3695 }
3696
3697 for _, runnerVers := range tlsVersions {
3698 protocols := []protocol{tls}
3699 if runnerVers.hasDTLS && shimVers.hasDTLS {
3700 protocols = append(protocols, dtls)
3701 }
3702 for _, protocol := range protocols {
3703 suffix := shimVers.name + "-" + runnerVers.name
3704 if protocol == dtls {
3705 suffix += "-DTLS"
3706 }
3707 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3708
David Benjaminaccb4542014-12-12 23:44:33 -05003709 var expectedVersion uint16
3710 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003711 var expectedClientError, expectedServerError string
3712 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003713 if runnerVers.version >= shimVers.version {
3714 expectedVersion = runnerVers.version
3715 } else {
3716 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003717 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3718 expectedServerLocalError = "remote error: protocol version not supported"
3719 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3720 // If the client's minimum version is TLS 1.3 and the runner's
3721 // maximum is below TLS 1.2, the runner will fail to select a
3722 // cipher before the shim rejects the selected version.
3723 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3724 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3725 } else {
3726 expectedClientError = expectedServerError
3727 expectedClientLocalError = expectedServerLocalError
3728 }
David Benjaminaccb4542014-12-12 23:44:33 -05003729 }
3730
3731 testCases = append(testCases, testCase{
3732 protocol: protocol,
3733 testType: clientTest,
3734 name: "MinimumVersion-Client-" + suffix,
3735 config: Config{
3736 MaxVersion: runnerVers.version,
3737 },
David Benjamin87909c02014-12-13 01:55:01 -05003738 flags: flags,
3739 expectedVersion: expectedVersion,
3740 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003741 expectedError: expectedClientError,
3742 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003743 })
3744 testCases = append(testCases, testCase{
3745 protocol: protocol,
3746 testType: clientTest,
3747 name: "MinimumVersion-Client2-" + suffix,
3748 config: Config{
3749 MaxVersion: runnerVers.version,
3750 },
David Benjamin87909c02014-12-13 01:55:01 -05003751 flags: []string{"-min-version", shimVersFlag},
3752 expectedVersion: expectedVersion,
3753 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003754 expectedError: expectedClientError,
3755 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003756 })
3757
3758 testCases = append(testCases, testCase{
3759 protocol: protocol,
3760 testType: serverTest,
3761 name: "MinimumVersion-Server-" + suffix,
3762 config: Config{
3763 MaxVersion: runnerVers.version,
3764 },
David Benjamin87909c02014-12-13 01:55:01 -05003765 flags: flags,
3766 expectedVersion: expectedVersion,
3767 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003768 expectedError: expectedServerError,
3769 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003770 })
3771 testCases = append(testCases, testCase{
3772 protocol: protocol,
3773 testType: serverTest,
3774 name: "MinimumVersion-Server2-" + suffix,
3775 config: Config{
3776 MaxVersion: runnerVers.version,
3777 },
David Benjamin87909c02014-12-13 01:55:01 -05003778 flags: []string{"-min-version", shimVersFlag},
3779 expectedVersion: expectedVersion,
3780 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003781 expectedError: expectedServerError,
3782 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003783 })
3784 }
3785 }
3786 }
3787}
3788
David Benjamine78bfde2014-09-06 12:45:15 -04003789func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003790 // TODO(davidben): Extensions, where applicable, all move their server
3791 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3792 // tests for both. Also test interaction with 0-RTT when implemented.
3793
David Benjamine78bfde2014-09-06 12:45:15 -04003794 testCases = append(testCases, testCase{
3795 testType: clientTest,
3796 name: "DuplicateExtensionClient",
3797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003798 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003799 Bugs: ProtocolBugs{
3800 DuplicateExtension: true,
3801 },
3802 },
3803 shouldFail: true,
3804 expectedLocalError: "remote error: error decoding message",
3805 })
3806 testCases = append(testCases, testCase{
3807 testType: serverTest,
3808 name: "DuplicateExtensionServer",
3809 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003810 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003811 Bugs: ProtocolBugs{
3812 DuplicateExtension: true,
3813 },
3814 },
3815 shouldFail: true,
3816 expectedLocalError: "remote error: error decoding message",
3817 })
3818 testCases = append(testCases, testCase{
3819 testType: clientTest,
3820 name: "ServerNameExtensionClient",
3821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003822 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003823 Bugs: ProtocolBugs{
3824 ExpectServerName: "example.com",
3825 },
3826 },
3827 flags: []string{"-host-name", "example.com"},
3828 })
3829 testCases = append(testCases, testCase{
3830 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003831 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003832 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003833 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003834 Bugs: ProtocolBugs{
3835 ExpectServerName: "mismatch.com",
3836 },
3837 },
3838 flags: []string{"-host-name", "example.com"},
3839 shouldFail: true,
3840 expectedLocalError: "tls: unexpected server name",
3841 })
3842 testCases = append(testCases, testCase{
3843 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003844 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003845 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003846 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003847 Bugs: ProtocolBugs{
3848 ExpectServerName: "missing.com",
3849 },
3850 },
3851 shouldFail: true,
3852 expectedLocalError: "tls: unexpected server name",
3853 })
3854 testCases = append(testCases, testCase{
3855 testType: serverTest,
3856 name: "ServerNameExtensionServer",
3857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003858 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003859 ServerName: "example.com",
3860 },
3861 flags: []string{"-expect-server-name", "example.com"},
3862 resumeSession: true,
3863 })
David Benjaminae2888f2014-09-06 12:58:58 -04003864 testCases = append(testCases, testCase{
3865 testType: clientTest,
3866 name: "ALPNClient",
3867 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003868 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003869 NextProtos: []string{"foo"},
3870 },
3871 flags: []string{
3872 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3873 "-expect-alpn", "foo",
3874 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003875 expectedNextProto: "foo",
3876 expectedNextProtoType: alpn,
3877 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003878 })
3879 testCases = append(testCases, testCase{
3880 testType: serverTest,
3881 name: "ALPNServer",
3882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003884 NextProtos: []string{"foo", "bar", "baz"},
3885 },
3886 flags: []string{
3887 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3888 "-select-alpn", "foo",
3889 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003890 expectedNextProto: "foo",
3891 expectedNextProtoType: alpn,
3892 resumeSession: true,
3893 })
David Benjamin594e7d22016-03-17 17:49:56 -04003894 testCases = append(testCases, testCase{
3895 testType: serverTest,
3896 name: "ALPNServer-Decline",
3897 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003898 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003899 NextProtos: []string{"foo", "bar", "baz"},
3900 },
3901 flags: []string{"-decline-alpn"},
3902 expectNoNextProto: true,
3903 resumeSession: true,
3904 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003905 // Test that the server prefers ALPN over NPN.
3906 testCases = append(testCases, testCase{
3907 testType: serverTest,
3908 name: "ALPNServer-Preferred",
3909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003910 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003911 NextProtos: []string{"foo", "bar", "baz"},
3912 },
3913 flags: []string{
3914 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3915 "-select-alpn", "foo",
3916 "-advertise-npn", "\x03foo\x03bar\x03baz",
3917 },
3918 expectedNextProto: "foo",
3919 expectedNextProtoType: alpn,
3920 resumeSession: true,
3921 })
3922 testCases = append(testCases, testCase{
3923 testType: serverTest,
3924 name: "ALPNServer-Preferred-Swapped",
3925 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003926 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003927 NextProtos: []string{"foo", "bar", "baz"},
3928 Bugs: ProtocolBugs{
3929 SwapNPNAndALPN: true,
3930 },
3931 },
3932 flags: []string{
3933 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3934 "-select-alpn", "foo",
3935 "-advertise-npn", "\x03foo\x03bar\x03baz",
3936 },
3937 expectedNextProto: "foo",
3938 expectedNextProtoType: alpn,
3939 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003940 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003941 var emptyString string
3942 testCases = append(testCases, testCase{
3943 testType: clientTest,
3944 name: "ALPNClient-EmptyProtocolName",
3945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003946 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003947 NextProtos: []string{""},
3948 Bugs: ProtocolBugs{
3949 // A server returning an empty ALPN protocol
3950 // should be rejected.
3951 ALPNProtocol: &emptyString,
3952 },
3953 },
3954 flags: []string{
3955 "-advertise-alpn", "\x03foo",
3956 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003957 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003958 expectedError: ":PARSE_TLSEXT:",
3959 })
3960 testCases = append(testCases, testCase{
3961 testType: serverTest,
3962 name: "ALPNServer-EmptyProtocolName",
3963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003965 // A ClientHello containing an empty ALPN protocol
3966 // should be rejected.
3967 NextProtos: []string{"foo", "", "baz"},
3968 },
3969 flags: []string{
3970 "-select-alpn", "foo",
3971 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003972 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003973 expectedError: ":PARSE_TLSEXT:",
3974 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003975 // Test that negotiating both NPN and ALPN is forbidden.
3976 testCases = append(testCases, testCase{
3977 name: "NegotiateALPNAndNPN",
3978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003980 NextProtos: []string{"foo", "bar", "baz"},
3981 Bugs: ProtocolBugs{
3982 NegotiateALPNAndNPN: true,
3983 },
3984 },
3985 flags: []string{
3986 "-advertise-alpn", "\x03foo",
3987 "-select-next-proto", "foo",
3988 },
3989 shouldFail: true,
3990 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3991 })
3992 testCases = append(testCases, testCase{
3993 name: "NegotiateALPNAndNPN-Swapped",
3994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003995 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003996 NextProtos: []string{"foo", "bar", "baz"},
3997 Bugs: ProtocolBugs{
3998 NegotiateALPNAndNPN: true,
3999 SwapNPNAndALPN: true,
4000 },
4001 },
4002 flags: []string{
4003 "-advertise-alpn", "\x03foo",
4004 "-select-next-proto", "foo",
4005 },
4006 shouldFail: true,
4007 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4008 })
David Benjamin091c4b92015-10-26 13:33:21 -04004009 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4010 testCases = append(testCases, testCase{
4011 name: "DisableNPN",
4012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004013 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04004014 NextProtos: []string{"foo"},
4015 },
4016 flags: []string{
4017 "-select-next-proto", "foo",
4018 "-disable-npn",
4019 },
4020 expectNoNextProto: true,
4021 })
Adam Langley38311732014-10-16 19:04:35 -07004022 // Resume with a corrupt ticket.
4023 testCases = append(testCases, testCase{
4024 testType: serverTest,
4025 name: "CorruptTicket",
4026 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004027 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004028 Bugs: ProtocolBugs{
4029 CorruptTicket: true,
4030 },
4031 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004032 resumeSession: true,
4033 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07004034 })
David Benjamind98452d2015-06-16 14:16:23 -04004035 // Test the ticket callback, with and without renewal.
4036 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004037 testType: serverTest,
4038 name: "TicketCallback",
4039 config: Config{
4040 MaxVersion: VersionTLS12,
4041 },
David Benjamind98452d2015-06-16 14:16:23 -04004042 resumeSession: true,
4043 flags: []string{"-use-ticket-callback"},
4044 })
4045 testCases = append(testCases, testCase{
4046 testType: serverTest,
4047 name: "TicketCallback-Renew",
4048 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004049 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004050 Bugs: ProtocolBugs{
4051 ExpectNewTicket: true,
4052 },
4053 },
4054 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4055 resumeSession: true,
4056 })
Adam Langley38311732014-10-16 19:04:35 -07004057 // Resume with an oversized session id.
4058 testCases = append(testCases, testCase{
4059 testType: serverTest,
4060 name: "OversizedSessionId",
4061 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004062 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004063 Bugs: ProtocolBugs{
4064 OversizedSessionId: true,
4065 },
4066 },
4067 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004068 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004069 expectedError: ":DECODE_ERROR:",
4070 })
David Benjaminca6c8262014-11-15 19:06:08 -05004071 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4072 // are ignored.
4073 testCases = append(testCases, testCase{
4074 protocol: dtls,
4075 name: "SRTP-Client",
4076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004077 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004078 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4079 },
4080 flags: []string{
4081 "-srtp-profiles",
4082 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4083 },
4084 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4085 })
4086 testCases = append(testCases, testCase{
4087 protocol: dtls,
4088 testType: serverTest,
4089 name: "SRTP-Server",
4090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004091 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004092 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4093 },
4094 flags: []string{
4095 "-srtp-profiles",
4096 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4097 },
4098 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4099 })
4100 // Test that the MKI is ignored.
4101 testCases = append(testCases, testCase{
4102 protocol: dtls,
4103 testType: serverTest,
4104 name: "SRTP-Server-IgnoreMKI",
4105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004106 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004107 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4108 Bugs: ProtocolBugs{
4109 SRTPMasterKeyIdentifer: "bogus",
4110 },
4111 },
4112 flags: []string{
4113 "-srtp-profiles",
4114 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4115 },
4116 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4117 })
4118 // Test that SRTP isn't negotiated on the server if there were
4119 // no matching profiles.
4120 testCases = append(testCases, testCase{
4121 protocol: dtls,
4122 testType: serverTest,
4123 name: "SRTP-Server-NoMatch",
4124 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004125 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004126 SRTPProtectionProfiles: []uint16{100, 101, 102},
4127 },
4128 flags: []string{
4129 "-srtp-profiles",
4130 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4131 },
4132 expectedSRTPProtectionProfile: 0,
4133 })
4134 // Test that the server returning an invalid SRTP profile is
4135 // flagged as an error by the client.
4136 testCases = append(testCases, testCase{
4137 protocol: dtls,
4138 name: "SRTP-Client-NoMatch",
4139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004140 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004141 Bugs: ProtocolBugs{
4142 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4143 },
4144 },
4145 flags: []string{
4146 "-srtp-profiles",
4147 "SRTP_AES128_CM_SHA1_80",
4148 },
4149 shouldFail: true,
4150 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4151 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004152 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004153 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004154 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004155 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004156 config: Config{
4157 MaxVersion: VersionTLS12,
4158 },
David Benjamin61f95272014-11-25 01:55:35 -05004159 flags: []string{
4160 "-enable-signed-cert-timestamps",
4161 "-expect-signed-cert-timestamps",
4162 base64.StdEncoding.EncodeToString(testSCTList),
4163 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004164 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004165 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004166 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004167 name: "SendSCTListOnResume",
4168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004169 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004170 Bugs: ProtocolBugs{
4171 SendSCTListOnResume: []byte("bogus"),
4172 },
4173 },
4174 flags: []string{
4175 "-enable-signed-cert-timestamps",
4176 "-expect-signed-cert-timestamps",
4177 base64.StdEncoding.EncodeToString(testSCTList),
4178 },
4179 resumeSession: true,
4180 })
4181 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004182 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004183 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004184 config: Config{
4185 MaxVersion: VersionTLS12,
4186 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004187 flags: []string{
4188 "-signed-cert-timestamps",
4189 base64.StdEncoding.EncodeToString(testSCTList),
4190 },
4191 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004192 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004193 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004194
Paul Lietar4fac72e2015-09-09 13:44:55 +01004195 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004196 testType: clientTest,
4197 name: "ClientHelloPadding",
4198 config: Config{
4199 Bugs: ProtocolBugs{
4200 RequireClientHelloSize: 512,
4201 },
4202 },
4203 // This hostname just needs to be long enough to push the
4204 // ClientHello into F5's danger zone between 256 and 511 bytes
4205 // long.
4206 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4207 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004208
4209 // Extensions should not function in SSL 3.0.
4210 testCases = append(testCases, testCase{
4211 testType: serverTest,
4212 name: "SSLv3Extensions-NoALPN",
4213 config: Config{
4214 MaxVersion: VersionSSL30,
4215 NextProtos: []string{"foo", "bar", "baz"},
4216 },
4217 flags: []string{
4218 "-select-alpn", "foo",
4219 },
4220 expectNoNextProto: true,
4221 })
4222
4223 // Test session tickets separately as they follow a different codepath.
4224 testCases = append(testCases, testCase{
4225 testType: serverTest,
4226 name: "SSLv3Extensions-NoTickets",
4227 config: Config{
4228 MaxVersion: VersionSSL30,
4229 Bugs: ProtocolBugs{
4230 // Historically, session tickets in SSL 3.0
4231 // failed in different ways depending on whether
4232 // the client supported renegotiation_info.
4233 NoRenegotiationInfo: true,
4234 },
4235 },
4236 resumeSession: true,
4237 })
4238 testCases = append(testCases, testCase{
4239 testType: serverTest,
4240 name: "SSLv3Extensions-NoTickets2",
4241 config: Config{
4242 MaxVersion: VersionSSL30,
4243 },
4244 resumeSession: true,
4245 })
4246
4247 // But SSL 3.0 does send and process renegotiation_info.
4248 testCases = append(testCases, testCase{
4249 testType: serverTest,
4250 name: "SSLv3Extensions-RenegotiationInfo",
4251 config: Config{
4252 MaxVersion: VersionSSL30,
4253 Bugs: ProtocolBugs{
4254 RequireRenegotiationInfo: true,
4255 },
4256 },
4257 })
4258 testCases = append(testCases, testCase{
4259 testType: serverTest,
4260 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4261 config: Config{
4262 MaxVersion: VersionSSL30,
4263 Bugs: ProtocolBugs{
4264 NoRenegotiationInfo: true,
4265 SendRenegotiationSCSV: true,
4266 RequireRenegotiationInfo: true,
4267 },
4268 },
4269 })
David Benjamine78bfde2014-09-06 12:45:15 -04004270}
4271
David Benjamin01fe8202014-09-24 15:21:44 -04004272func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004273 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004274 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004275 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4276 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4277 // TLS 1.3 only shares ciphers with TLS 1.2, so
4278 // we skip certain combinations and use a
4279 // different cipher to test with.
4280 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4281 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4282 continue
4283 }
4284 }
4285
David Benjamin8b8c0062014-11-23 02:47:52 -05004286 protocols := []protocol{tls}
4287 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4288 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004289 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004290 for _, protocol := range protocols {
4291 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4292 if protocol == dtls {
4293 suffix += "-DTLS"
4294 }
4295
David Benjaminece3de92015-03-16 18:02:20 -04004296 if sessionVers.version == resumeVers.version {
4297 testCases = append(testCases, testCase{
4298 protocol: protocol,
4299 name: "Resume-Client" + suffix,
4300 resumeSession: true,
4301 config: Config{
4302 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004303 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004304 },
David Benjaminece3de92015-03-16 18:02:20 -04004305 expectedVersion: sessionVers.version,
4306 expectedResumeVersion: resumeVers.version,
4307 })
4308 } else {
4309 testCases = append(testCases, testCase{
4310 protocol: protocol,
4311 name: "Resume-Client-Mismatch" + suffix,
4312 resumeSession: true,
4313 config: Config{
4314 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004315 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004316 },
David Benjaminece3de92015-03-16 18:02:20 -04004317 expectedVersion: sessionVers.version,
4318 resumeConfig: &Config{
4319 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004320 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004321 Bugs: ProtocolBugs{
4322 AllowSessionVersionMismatch: true,
4323 },
4324 },
4325 expectedResumeVersion: resumeVers.version,
4326 shouldFail: true,
4327 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4328 })
4329 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004330
4331 testCases = append(testCases, testCase{
4332 protocol: protocol,
4333 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004334 resumeSession: true,
4335 config: Config{
4336 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004337 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004338 },
4339 expectedVersion: sessionVers.version,
4340 resumeConfig: &Config{
4341 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004342 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004343 },
4344 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004345 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004346 expectedResumeVersion: resumeVers.version,
4347 })
4348
David Benjamin8b8c0062014-11-23 02:47:52 -05004349 testCases = append(testCases, testCase{
4350 protocol: protocol,
4351 testType: serverTest,
4352 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004353 resumeSession: true,
4354 config: Config{
4355 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004356 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004357 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004358 expectedVersion: sessionVers.version,
4359 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004360 resumeConfig: &Config{
4361 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004362 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004363 },
4364 expectedResumeVersion: resumeVers.version,
4365 })
4366 }
David Benjamin01fe8202014-09-24 15:21:44 -04004367 }
4368 }
David Benjaminece3de92015-03-16 18:02:20 -04004369
Nick Harper1fd39d82016-06-14 18:14:35 -07004370 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004371 testCases = append(testCases, testCase{
4372 name: "Resume-Client-CipherMismatch",
4373 resumeSession: true,
4374 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004375 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004376 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4377 },
4378 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004379 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004380 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4381 Bugs: ProtocolBugs{
4382 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4383 },
4384 },
4385 shouldFail: true,
4386 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4387 })
David Benjamin01fe8202014-09-24 15:21:44 -04004388}
4389
Adam Langley2ae77d22014-10-28 17:29:33 -07004390func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004391 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004392 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004393 testType: serverTest,
4394 name: "Renegotiate-Server-Forbidden",
4395 config: Config{
4396 MaxVersion: VersionTLS12,
4397 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004398 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004399 shouldFail: true,
4400 expectedError: ":NO_RENEGOTIATION:",
4401 expectedLocalError: "remote error: no renegotiation",
4402 })
Adam Langley5021b222015-06-12 18:27:58 -07004403 // The server shouldn't echo the renegotiation extension unless
4404 // requested by the client.
4405 testCases = append(testCases, testCase{
4406 testType: serverTest,
4407 name: "Renegotiate-Server-NoExt",
4408 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004409 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004410 Bugs: ProtocolBugs{
4411 NoRenegotiationInfo: true,
4412 RequireRenegotiationInfo: true,
4413 },
4414 },
4415 shouldFail: true,
4416 expectedLocalError: "renegotiation extension missing",
4417 })
4418 // The renegotiation SCSV should be sufficient for the server to echo
4419 // the extension.
4420 testCases = append(testCases, testCase{
4421 testType: serverTest,
4422 name: "Renegotiate-Server-NoExt-SCSV",
4423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004424 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004425 Bugs: ProtocolBugs{
4426 NoRenegotiationInfo: true,
4427 SendRenegotiationSCSV: true,
4428 RequireRenegotiationInfo: true,
4429 },
4430 },
4431 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004432 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004433 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004435 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004436 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004437 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004438 },
4439 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004440 renegotiate: 1,
4441 flags: []string{
4442 "-renegotiate-freely",
4443 "-expect-total-renegotiations", "1",
4444 },
David Benjamincdea40c2015-03-19 14:09:43 -04004445 })
4446 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004447 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004448 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004450 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004451 Bugs: ProtocolBugs{
4452 EmptyRenegotiationInfo: true,
4453 },
4454 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004455 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004456 shouldFail: true,
4457 expectedError: ":RENEGOTIATION_MISMATCH:",
4458 })
4459 testCases = append(testCases, testCase{
4460 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004461 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004463 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004464 Bugs: ProtocolBugs{
4465 BadRenegotiationInfo: true,
4466 },
4467 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004468 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004469 shouldFail: true,
4470 expectedError: ":RENEGOTIATION_MISMATCH:",
4471 })
4472 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004473 name: "Renegotiate-Client-Downgrade",
4474 renegotiate: 1,
4475 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004476 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004477 Bugs: ProtocolBugs{
4478 NoRenegotiationInfoAfterInitial: true,
4479 },
4480 },
4481 flags: []string{"-renegotiate-freely"},
4482 shouldFail: true,
4483 expectedError: ":RENEGOTIATION_MISMATCH:",
4484 })
4485 testCases = append(testCases, testCase{
4486 name: "Renegotiate-Client-Upgrade",
4487 renegotiate: 1,
4488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004489 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004490 Bugs: ProtocolBugs{
4491 NoRenegotiationInfoInInitial: true,
4492 },
4493 },
4494 flags: []string{"-renegotiate-freely"},
4495 shouldFail: true,
4496 expectedError: ":RENEGOTIATION_MISMATCH:",
4497 })
4498 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004499 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004500 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004501 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004502 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004503 Bugs: ProtocolBugs{
4504 NoRenegotiationInfo: true,
4505 },
4506 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004507 flags: []string{
4508 "-renegotiate-freely",
4509 "-expect-total-renegotiations", "1",
4510 },
David Benjamincff0b902015-05-15 23:09:47 -04004511 })
4512 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004513 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004514 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004515 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004516 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004517 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4518 },
4519 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004520 flags: []string{
4521 "-renegotiate-freely",
4522 "-expect-total-renegotiations", "1",
4523 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004524 })
4525 testCases = append(testCases, testCase{
4526 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004527 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004528 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004529 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004530 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4531 },
4532 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004533 flags: []string{
4534 "-renegotiate-freely",
4535 "-expect-total-renegotiations", "1",
4536 },
David Benjaminb16346b2015-04-08 19:16:58 -04004537 })
4538 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004539 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004540 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004541 config: Config{
4542 MaxVersion: VersionTLS10,
4543 Bugs: ProtocolBugs{
4544 RequireSameRenegoClientVersion: true,
4545 },
4546 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004547 flags: []string{
4548 "-renegotiate-freely",
4549 "-expect-total-renegotiations", "1",
4550 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004551 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004552 testCases = append(testCases, testCase{
4553 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004554 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004555 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004556 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004557 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4558 NextProtos: []string{"foo"},
4559 },
4560 flags: []string{
4561 "-false-start",
4562 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004563 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004564 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004565 },
4566 shimWritesFirst: true,
4567 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004568
4569 // Client-side renegotiation controls.
4570 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004571 name: "Renegotiate-Client-Forbidden-1",
4572 config: Config{
4573 MaxVersion: VersionTLS12,
4574 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004575 renegotiate: 1,
4576 shouldFail: true,
4577 expectedError: ":NO_RENEGOTIATION:",
4578 expectedLocalError: "remote error: no renegotiation",
4579 })
4580 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004581 name: "Renegotiate-Client-Once-1",
4582 config: Config{
4583 MaxVersion: VersionTLS12,
4584 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004585 renegotiate: 1,
4586 flags: []string{
4587 "-renegotiate-once",
4588 "-expect-total-renegotiations", "1",
4589 },
4590 })
4591 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004592 name: "Renegotiate-Client-Freely-1",
4593 config: Config{
4594 MaxVersion: VersionTLS12,
4595 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004596 renegotiate: 1,
4597 flags: []string{
4598 "-renegotiate-freely",
4599 "-expect-total-renegotiations", "1",
4600 },
4601 })
4602 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004603 name: "Renegotiate-Client-Once-2",
4604 config: Config{
4605 MaxVersion: VersionTLS12,
4606 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004607 renegotiate: 2,
4608 flags: []string{"-renegotiate-once"},
4609 shouldFail: true,
4610 expectedError: ":NO_RENEGOTIATION:",
4611 expectedLocalError: "remote error: no renegotiation",
4612 })
4613 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004614 name: "Renegotiate-Client-Freely-2",
4615 config: Config{
4616 MaxVersion: VersionTLS12,
4617 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004618 renegotiate: 2,
4619 flags: []string{
4620 "-renegotiate-freely",
4621 "-expect-total-renegotiations", "2",
4622 },
4623 })
Adam Langley27a0d082015-11-03 13:34:10 -08004624 testCases = append(testCases, testCase{
4625 name: "Renegotiate-Client-NoIgnore",
4626 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004627 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004628 Bugs: ProtocolBugs{
4629 SendHelloRequestBeforeEveryAppDataRecord: true,
4630 },
4631 },
4632 shouldFail: true,
4633 expectedError: ":NO_RENEGOTIATION:",
4634 })
4635 testCases = append(testCases, testCase{
4636 name: "Renegotiate-Client-Ignore",
4637 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004638 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004639 Bugs: ProtocolBugs{
4640 SendHelloRequestBeforeEveryAppDataRecord: true,
4641 },
4642 },
4643 flags: []string{
4644 "-renegotiate-ignore",
4645 "-expect-total-renegotiations", "0",
4646 },
4647 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004648
David Benjamin397c8e62016-07-08 14:14:36 -07004649 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004650 testCases = append(testCases, testCase{
4651 name: "StrayHelloRequest",
4652 config: Config{
4653 MaxVersion: VersionTLS12,
4654 Bugs: ProtocolBugs{
4655 SendHelloRequestBeforeEveryHandshakeMessage: true,
4656 },
4657 },
4658 })
4659 testCases = append(testCases, testCase{
4660 name: "StrayHelloRequest-Packed",
4661 config: Config{
4662 MaxVersion: VersionTLS12,
4663 Bugs: ProtocolBugs{
4664 PackHandshakeFlight: true,
4665 SendHelloRequestBeforeEveryHandshakeMessage: true,
4666 },
4667 },
4668 })
4669
David Benjamin397c8e62016-07-08 14:14:36 -07004670 // Renegotiation is forbidden in TLS 1.3.
4671 testCases = append(testCases, testCase{
4672 name: "Renegotiate-Client-TLS13",
4673 config: Config{
4674 MaxVersion: VersionTLS13,
4675 },
4676 renegotiate: 1,
4677 flags: []string{
4678 "-renegotiate-freely",
4679 },
4680 shouldFail: true,
4681 expectedError: ":NO_RENEGOTIATION:",
4682 })
4683
4684 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4685 testCases = append(testCases, testCase{
4686 name: "StrayHelloRequest-TLS13",
4687 config: Config{
4688 MaxVersion: VersionTLS13,
4689 Bugs: ProtocolBugs{
4690 SendHelloRequestBeforeEveryHandshakeMessage: true,
4691 },
4692 },
4693 shouldFail: true,
4694 expectedError: ":UNEXPECTED_MESSAGE:",
4695 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004696}
4697
David Benjamin5e961c12014-11-07 01:48:35 -05004698func addDTLSReplayTests() {
4699 // Test that sequence number replays are detected.
4700 testCases = append(testCases, testCase{
4701 protocol: dtls,
4702 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004703 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004704 replayWrites: true,
4705 })
4706
David Benjamin8e6db492015-07-25 18:29:23 -04004707 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004708 // than the retransmit window.
4709 testCases = append(testCases, testCase{
4710 protocol: dtls,
4711 name: "DTLS-Replay-LargeGaps",
4712 config: Config{
4713 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004714 SequenceNumberMapping: func(in uint64) uint64 {
4715 return in * 127
4716 },
David Benjamin5e961c12014-11-07 01:48:35 -05004717 },
4718 },
David Benjamin8e6db492015-07-25 18:29:23 -04004719 messageCount: 200,
4720 replayWrites: true,
4721 })
4722
4723 // Test the incoming sequence number changing non-monotonically.
4724 testCases = append(testCases, testCase{
4725 protocol: dtls,
4726 name: "DTLS-Replay-NonMonotonic",
4727 config: Config{
4728 Bugs: ProtocolBugs{
4729 SequenceNumberMapping: func(in uint64) uint64 {
4730 return in ^ 31
4731 },
4732 },
4733 },
4734 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004735 replayWrites: true,
4736 })
4737}
4738
Nick Harper60edffd2016-06-21 15:19:24 -07004739var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004740 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004741 id signatureAlgorithm
4742 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004743}{
Nick Harper60edffd2016-06-21 15:19:24 -07004744 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4745 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4746 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4747 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004748 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07004749 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4750 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4751 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004752 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
4753 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
4754 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin000800a2014-11-14 01:43:59 -05004755}
4756
Nick Harper60edffd2016-06-21 15:19:24 -07004757const fakeSigAlg1 signatureAlgorithm = 0x2a01
4758const fakeSigAlg2 signatureAlgorithm = 0xff01
4759
4760func addSignatureAlgorithmTests() {
4761 // Make sure each signature algorithm works. Include some fake values in
4762 // the list and ensure they're ignored.
4763 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07004764 for _, ver := range tlsVersions {
4765 if ver.version < VersionTLS12 {
4766 continue
4767 }
Nick Harper60edffd2016-06-21 15:19:24 -07004768
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004769 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07004770 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004771 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
4772 shouldFail = true
4773 }
4774 // RSA-PSS does not exist in TLS 1.2.
4775 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
4776 shouldFail = true
4777 }
4778
4779 var signError, verifyError string
4780 if shouldFail {
4781 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
4782 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07004783 }
David Benjamin000800a2014-11-14 01:43:59 -05004784
David Benjamin1fb125c2016-07-08 18:52:12 -07004785 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05004786
David Benjamin7a41d372016-07-09 11:21:54 -07004787 testCases = append(testCases, testCase{
4788 name: "SigningHash-ClientAuth-Sign" + suffix,
4789 config: Config{
4790 MaxVersion: ver.version,
4791 ClientAuth: RequireAnyClientCert,
4792 VerifySignatureAlgorithms: []signatureAlgorithm{
4793 fakeSigAlg1,
4794 alg.id,
4795 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07004796 },
David Benjamin7a41d372016-07-09 11:21:54 -07004797 },
4798 flags: []string{
4799 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4800 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4801 "-enable-all-curves",
4802 },
4803 shouldFail: shouldFail,
4804 expectedError: signError,
4805 expectedPeerSignatureAlgorithm: alg.id,
4806 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004807
David Benjamin7a41d372016-07-09 11:21:54 -07004808 testCases = append(testCases, testCase{
4809 testType: serverTest,
4810 name: "SigningHash-ClientAuth-Verify" + suffix,
4811 config: Config{
4812 MaxVersion: ver.version,
4813 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4814 SignSignatureAlgorithms: []signatureAlgorithm{
4815 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004816 },
David Benjamin7a41d372016-07-09 11:21:54 -07004817 Bugs: ProtocolBugs{
4818 SkipECDSACurveCheck: shouldFail,
4819 IgnoreSignatureVersionChecks: shouldFail,
4820 // The client won't advertise 1.3-only algorithms after
4821 // version negotiation.
4822 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004823 },
David Benjamin7a41d372016-07-09 11:21:54 -07004824 },
4825 flags: []string{
4826 "-require-any-client-certificate",
4827 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4828 "-enable-all-curves",
4829 },
4830 shouldFail: shouldFail,
4831 expectedError: verifyError,
4832 })
David Benjamin1fb125c2016-07-08 18:52:12 -07004833
4834 testCases = append(testCases, testCase{
4835 testType: serverTest,
4836 name: "SigningHash-ServerKeyExchange-Sign" + suffix,
4837 config: Config{
4838 MaxVersion: ver.version,
4839 CipherSuites: []uint16{
4840 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4841 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4842 },
David Benjamin7a41d372016-07-09 11:21:54 -07004843 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004844 fakeSigAlg1,
4845 alg.id,
4846 fakeSigAlg2,
4847 },
4848 },
4849 flags: []string{
4850 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4851 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4852 "-enable-all-curves",
4853 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004854 shouldFail: shouldFail,
4855 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004856 expectedPeerSignatureAlgorithm: alg.id,
4857 })
4858
4859 testCases = append(testCases, testCase{
4860 name: "SigningHash-ServerKeyExchange-Verify" + suffix,
4861 config: Config{
4862 MaxVersion: ver.version,
4863 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4864 CipherSuites: []uint16{
4865 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4866 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4867 },
David Benjamin7a41d372016-07-09 11:21:54 -07004868 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004869 alg.id,
4870 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004871 Bugs: ProtocolBugs{
4872 SkipECDSACurveCheck: shouldFail,
4873 IgnoreSignatureVersionChecks: shouldFail,
4874 },
David Benjamin1fb125c2016-07-08 18:52:12 -07004875 },
4876 flags: []string{
4877 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4878 "-enable-all-curves",
4879 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004880 shouldFail: shouldFail,
4881 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004882 })
4883 }
David Benjamin000800a2014-11-14 01:43:59 -05004884 }
4885
Nick Harper60edffd2016-06-21 15:19:24 -07004886 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004887 //
4888 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004889 testCases = append(testCases, testCase{
4890 name: "SigningHash-ClientAuth-SignatureType",
4891 config: Config{
4892 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004893 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07004894 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004895 signatureECDSAWithP521AndSHA512,
4896 signatureRSAPKCS1WithSHA384,
4897 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004898 },
4899 },
4900 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004901 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4902 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004903 },
Nick Harper60edffd2016-06-21 15:19:24 -07004904 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004905 })
4906
4907 testCases = append(testCases, testCase{
4908 testType: serverTest,
4909 name: "SigningHash-ServerKeyExchange-SignatureType",
4910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004911 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004913 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004914 signatureECDSAWithP521AndSHA512,
4915 signatureRSAPKCS1WithSHA384,
4916 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004917 },
4918 },
Nick Harper60edffd2016-06-21 15:19:24 -07004919 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004920 })
4921
David Benjamina95e9f32016-07-08 16:28:04 -07004922 // Test that signature verification takes the key type into account.
4923 //
4924 // TODO(davidben): Test this in TLS 1.3.
4925 testCases = append(testCases, testCase{
4926 testType: serverTest,
4927 name: "Verify-ClientAuth-SignatureType",
4928 config: Config{
4929 MaxVersion: VersionTLS12,
4930 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004931 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004932 signatureRSAPKCS1WithSHA256,
4933 },
4934 Bugs: ProtocolBugs{
4935 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4936 },
4937 },
4938 flags: []string{
4939 "-require-any-client-certificate",
4940 },
4941 shouldFail: true,
4942 expectedError: ":WRONG_SIGNATURE_TYPE:",
4943 })
4944
4945 testCases = append(testCases, testCase{
4946 name: "Verify-ServerKeyExchange-SignatureType",
4947 config: Config{
4948 MaxVersion: VersionTLS12,
4949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004950 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004951 signatureRSAPKCS1WithSHA256,
4952 },
4953 Bugs: ProtocolBugs{
4954 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4955 },
4956 },
4957 shouldFail: true,
4958 expectedError: ":WRONG_SIGNATURE_TYPE:",
4959 })
4960
David Benjamin51dd7d62016-07-08 16:07:01 -07004961 // Test that, if the list is missing, the peer falls back to SHA-1 in
4962 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004963 testCases = append(testCases, testCase{
4964 name: "SigningHash-ClientAuth-Fallback",
4965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004966 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004967 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004968 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004969 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004970 },
4971 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004972 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004973 },
4974 },
4975 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004976 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4977 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004978 },
4979 })
4980
4981 testCases = append(testCases, testCase{
4982 testType: serverTest,
4983 name: "SigningHash-ServerKeyExchange-Fallback",
4984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004985 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004986 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004987 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004988 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004989 },
4990 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004991 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004992 },
4993 },
4994 })
David Benjamin72dc7832015-03-16 17:49:43 -04004995
David Benjamin51dd7d62016-07-08 16:07:01 -07004996 testCases = append(testCases, testCase{
4997 name: "SigningHash-ClientAuth-Fallback-TLS13",
4998 config: Config{
4999 MaxVersion: VersionTLS13,
5000 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005001 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005002 signatureRSAPKCS1WithSHA1,
5003 },
5004 Bugs: ProtocolBugs{
5005 NoSignatureAlgorithms: true,
5006 },
5007 },
5008 flags: []string{
5009 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5010 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5011 },
5012 shouldFail: true,
5013 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5014 })
5015
5016 testCases = append(testCases, testCase{
5017 testType: serverTest,
5018 name: "SigningHash-ServerKeyExchange-Fallback-TLS13",
5019 config: Config{
5020 MaxVersion: VersionTLS13,
5021 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005022 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005023 signatureRSAPKCS1WithSHA1,
5024 },
5025 Bugs: ProtocolBugs{
5026 NoSignatureAlgorithms: true,
5027 },
5028 },
5029 shouldFail: true,
5030 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5031 })
5032
David Benjamin72dc7832015-03-16 17:49:43 -04005033 // Test that hash preferences are enforced. BoringSSL defaults to
5034 // rejecting MD5 signatures.
5035 testCases = append(testCases, testCase{
5036 testType: serverTest,
5037 name: "SigningHash-ClientAuth-Enforced",
5038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005039 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005040 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005041 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005042 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005043 // Advertise SHA-1 so the handshake will
5044 // proceed, but the shim's preferences will be
5045 // ignored in CertificateVerify generation, so
5046 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005047 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005048 },
5049 Bugs: ProtocolBugs{
5050 IgnorePeerSignatureAlgorithmPreferences: true,
5051 },
5052 },
5053 flags: []string{"-require-any-client-certificate"},
5054 shouldFail: true,
5055 expectedError: ":WRONG_SIGNATURE_TYPE:",
5056 })
5057
5058 testCases = append(testCases, testCase{
5059 name: "SigningHash-ServerKeyExchange-Enforced",
5060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005061 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005062 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005063 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005064 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005065 },
5066 Bugs: ProtocolBugs{
5067 IgnorePeerSignatureAlgorithmPreferences: true,
5068 },
5069 },
5070 shouldFail: true,
5071 expectedError: ":WRONG_SIGNATURE_TYPE:",
5072 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005073
5074 // Test that the agreed upon digest respects the client preferences and
5075 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005076 //
5077 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04005078 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005079 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005081 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005082 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005083 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005084 signatureRSAPKCS1WithSHA512,
5085 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005086 },
5087 },
5088 flags: []string{
5089 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5090 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5091 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005092 digestPrefs: "SHA256",
5093 shouldFail: true,
5094 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005095 })
5096 testCases = append(testCases, testCase{
5097 name: "Agree-Digest-SHA256",
5098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005099 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005100 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005101 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005102 signatureRSAPKCS1WithSHA1,
5103 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005104 },
5105 },
5106 flags: []string{
5107 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5108 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5109 },
Nick Harper60edffd2016-06-21 15:19:24 -07005110 digestPrefs: "SHA256,SHA1",
5111 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005112 })
5113 testCases = append(testCases, testCase{
5114 name: "Agree-Digest-SHA1",
5115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005116 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005117 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005118 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005119 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005120 },
5121 },
5122 flags: []string{
5123 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5124 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5125 },
Nick Harper60edffd2016-06-21 15:19:24 -07005126 digestPrefs: "SHA512,SHA256,SHA1",
5127 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005128 })
5129 testCases = append(testCases, testCase{
5130 name: "Agree-Digest-Default",
5131 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005132 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005133 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005134 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005135 signatureRSAPKCS1WithSHA256,
5136 signatureECDSAWithP256AndSHA256,
5137 signatureRSAPKCS1WithSHA1,
5138 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005139 },
5140 },
5141 flags: []string{
5142 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5143 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5144 },
Nick Harper60edffd2016-06-21 15:19:24 -07005145 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005146 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005147
5148 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5149 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005150 testCases = append(testCases, testCase{
5151 name: "CheckLeafCurve",
5152 config: Config{
5153 MaxVersion: VersionTLS12,
5154 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005155 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005156 },
5157 flags: []string{"-p384-only"},
5158 shouldFail: true,
5159 expectedError: ":BAD_ECC_CERT:",
5160 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005161
5162 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5163 testCases = append(testCases, testCase{
5164 name: "CheckLeafCurve-TLS13",
5165 config: Config{
5166 MaxVersion: VersionTLS13,
5167 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5168 Certificates: []Certificate{ecdsaP256Certificate},
5169 },
5170 flags: []string{"-p384-only"},
5171 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005172
5173 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5174 testCases = append(testCases, testCase{
5175 name: "ECDSACurveMismatch-Verify-TLS12",
5176 config: Config{
5177 MaxVersion: VersionTLS12,
5178 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5179 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005180 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005181 signatureECDSAWithP384AndSHA384,
5182 },
5183 },
5184 })
5185
5186 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5187 testCases = append(testCases, testCase{
5188 name: "ECDSACurveMismatch-Verify-TLS13",
5189 config: Config{
5190 MaxVersion: VersionTLS13,
5191 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5192 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005193 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005194 signatureECDSAWithP384AndSHA384,
5195 },
5196 Bugs: ProtocolBugs{
5197 SkipECDSACurveCheck: true,
5198 },
5199 },
5200 shouldFail: true,
5201 expectedError: ":WRONG_SIGNATURE_TYPE:",
5202 })
5203
5204 // Signature algorithm selection in TLS 1.3 should take the curve into
5205 // account.
5206 testCases = append(testCases, testCase{
5207 testType: serverTest,
5208 name: "ECDSACurveMismatch-Sign-TLS13",
5209 config: Config{
5210 MaxVersion: VersionTLS13,
5211 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005212 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005213 signatureECDSAWithP384AndSHA384,
5214 signatureECDSAWithP256AndSHA256,
5215 },
5216 },
5217 flags: []string{
5218 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5219 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5220 },
5221 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5222 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005223
5224 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5225 // server does not attempt to sign in that case.
5226 testCases = append(testCases, testCase{
5227 testType: serverTest,
5228 name: "RSA-PSS-Large",
5229 config: Config{
5230 MaxVersion: VersionTLS13,
5231 VerifySignatureAlgorithms: []signatureAlgorithm{
5232 signatureRSAPSSWithSHA512,
5233 },
5234 },
5235 flags: []string{
5236 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5237 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5238 },
5239 shouldFail: true,
5240 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5241 })
David Benjamin000800a2014-11-14 01:43:59 -05005242}
5243
David Benjamin83f90402015-01-27 01:09:43 -05005244// timeouts is the retransmit schedule for BoringSSL. It doubles and
5245// caps at 60 seconds. On the 13th timeout, it gives up.
5246var timeouts = []time.Duration{
5247 1 * time.Second,
5248 2 * time.Second,
5249 4 * time.Second,
5250 8 * time.Second,
5251 16 * time.Second,
5252 32 * time.Second,
5253 60 * time.Second,
5254 60 * time.Second,
5255 60 * time.Second,
5256 60 * time.Second,
5257 60 * time.Second,
5258 60 * time.Second,
5259 60 * time.Second,
5260}
5261
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005262// shortTimeouts is an alternate set of timeouts which would occur if the
5263// initial timeout duration was set to 250ms.
5264var shortTimeouts = []time.Duration{
5265 250 * time.Millisecond,
5266 500 * time.Millisecond,
5267 1 * time.Second,
5268 2 * time.Second,
5269 4 * time.Second,
5270 8 * time.Second,
5271 16 * time.Second,
5272 32 * time.Second,
5273 60 * time.Second,
5274 60 * time.Second,
5275 60 * time.Second,
5276 60 * time.Second,
5277 60 * time.Second,
5278}
5279
David Benjamin83f90402015-01-27 01:09:43 -05005280func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005281 // These tests work by coordinating some behavior on both the shim and
5282 // the runner.
5283 //
5284 // TimeoutSchedule configures the runner to send a series of timeout
5285 // opcodes to the shim (see packetAdaptor) immediately before reading
5286 // each peer handshake flight N. The timeout opcode both simulates a
5287 // timeout in the shim and acts as a synchronization point to help the
5288 // runner bracket each handshake flight.
5289 //
5290 // We assume the shim does not read from the channel eagerly. It must
5291 // first wait until it has sent flight N and is ready to receive
5292 // handshake flight N+1. At this point, it will process the timeout
5293 // opcode. It must then immediately respond with a timeout ACK and act
5294 // as if the shim was idle for the specified amount of time.
5295 //
5296 // The runner then drops all packets received before the ACK and
5297 // continues waiting for flight N. This ordering results in one attempt
5298 // at sending flight N to be dropped. For the test to complete, the
5299 // shim must send flight N again, testing that the shim implements DTLS
5300 // retransmit on a timeout.
5301
David Benjamin4c3ddf72016-06-29 18:13:53 -04005302 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5303 // likely be more epochs to cross and the final message's retransmit may
5304 // be more complex.
5305
David Benjamin585d7a42016-06-02 14:58:00 -04005306 for _, async := range []bool{true, false} {
5307 var tests []testCase
5308
5309 // Test that this is indeed the timeout schedule. Stress all
5310 // four patterns of handshake.
5311 for i := 1; i < len(timeouts); i++ {
5312 number := strconv.Itoa(i)
5313 tests = append(tests, testCase{
5314 protocol: dtls,
5315 name: "DTLS-Retransmit-Client-" + number,
5316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005317 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005318 Bugs: ProtocolBugs{
5319 TimeoutSchedule: timeouts[:i],
5320 },
5321 },
5322 resumeSession: true,
5323 })
5324 tests = append(tests, testCase{
5325 protocol: dtls,
5326 testType: serverTest,
5327 name: "DTLS-Retransmit-Server-" + number,
5328 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005329 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005330 Bugs: ProtocolBugs{
5331 TimeoutSchedule: timeouts[:i],
5332 },
5333 },
5334 resumeSession: true,
5335 })
5336 }
5337
5338 // Test that exceeding the timeout schedule hits a read
5339 // timeout.
5340 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005341 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005342 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005343 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005344 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005345 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005346 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005347 },
5348 },
5349 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005350 shouldFail: true,
5351 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005352 })
David Benjamin585d7a42016-06-02 14:58:00 -04005353
5354 if async {
5355 // Test that timeout handling has a fudge factor, due to API
5356 // problems.
5357 tests = append(tests, testCase{
5358 protocol: dtls,
5359 name: "DTLS-Retransmit-Fudge",
5360 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005361 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005362 Bugs: ProtocolBugs{
5363 TimeoutSchedule: []time.Duration{
5364 timeouts[0] - 10*time.Millisecond,
5365 },
5366 },
5367 },
5368 resumeSession: true,
5369 })
5370 }
5371
5372 // Test that the final Finished retransmitting isn't
5373 // duplicated if the peer badly fragments everything.
5374 tests = append(tests, testCase{
5375 testType: serverTest,
5376 protocol: dtls,
5377 name: "DTLS-Retransmit-Fragmented",
5378 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005379 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005380 Bugs: ProtocolBugs{
5381 TimeoutSchedule: []time.Duration{timeouts[0]},
5382 MaxHandshakeRecordLength: 2,
5383 },
5384 },
5385 })
5386
5387 // Test the timeout schedule when a shorter initial timeout duration is set.
5388 tests = append(tests, testCase{
5389 protocol: dtls,
5390 name: "DTLS-Retransmit-Short-Client",
5391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005392 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005393 Bugs: ProtocolBugs{
5394 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5395 },
5396 },
5397 resumeSession: true,
5398 flags: []string{"-initial-timeout-duration-ms", "250"},
5399 })
5400 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005401 protocol: dtls,
5402 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005403 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005404 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005405 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005406 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005407 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005408 },
5409 },
5410 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005411 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005412 })
David Benjamin585d7a42016-06-02 14:58:00 -04005413
5414 for _, test := range tests {
5415 if async {
5416 test.name += "-Async"
5417 test.flags = append(test.flags, "-async")
5418 }
5419
5420 testCases = append(testCases, test)
5421 }
David Benjamin83f90402015-01-27 01:09:43 -05005422 }
David Benjamin83f90402015-01-27 01:09:43 -05005423}
5424
David Benjaminc565ebb2015-04-03 04:06:36 -04005425func addExportKeyingMaterialTests() {
5426 for _, vers := range tlsVersions {
5427 if vers.version == VersionSSL30 {
5428 continue
5429 }
5430 testCases = append(testCases, testCase{
5431 name: "ExportKeyingMaterial-" + vers.name,
5432 config: Config{
5433 MaxVersion: vers.version,
5434 },
5435 exportKeyingMaterial: 1024,
5436 exportLabel: "label",
5437 exportContext: "context",
5438 useExportContext: true,
5439 })
5440 testCases = append(testCases, testCase{
5441 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5442 config: Config{
5443 MaxVersion: vers.version,
5444 },
5445 exportKeyingMaterial: 1024,
5446 })
5447 testCases = append(testCases, testCase{
5448 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5449 config: Config{
5450 MaxVersion: vers.version,
5451 },
5452 exportKeyingMaterial: 1024,
5453 useExportContext: true,
5454 })
5455 testCases = append(testCases, testCase{
5456 name: "ExportKeyingMaterial-Small-" + vers.name,
5457 config: Config{
5458 MaxVersion: vers.version,
5459 },
5460 exportKeyingMaterial: 1,
5461 exportLabel: "label",
5462 exportContext: "context",
5463 useExportContext: true,
5464 })
5465 }
5466 testCases = append(testCases, testCase{
5467 name: "ExportKeyingMaterial-SSL3",
5468 config: Config{
5469 MaxVersion: VersionSSL30,
5470 },
5471 exportKeyingMaterial: 1024,
5472 exportLabel: "label",
5473 exportContext: "context",
5474 useExportContext: true,
5475 shouldFail: true,
5476 expectedError: "failed to export keying material",
5477 })
5478}
5479
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005480func addTLSUniqueTests() {
5481 for _, isClient := range []bool{false, true} {
5482 for _, isResumption := range []bool{false, true} {
5483 for _, hasEMS := range []bool{false, true} {
5484 var suffix string
5485 if isResumption {
5486 suffix = "Resume-"
5487 } else {
5488 suffix = "Full-"
5489 }
5490
5491 if hasEMS {
5492 suffix += "EMS-"
5493 } else {
5494 suffix += "NoEMS-"
5495 }
5496
5497 if isClient {
5498 suffix += "Client"
5499 } else {
5500 suffix += "Server"
5501 }
5502
5503 test := testCase{
5504 name: "TLSUnique-" + suffix,
5505 testTLSUnique: true,
5506 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005507 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005508 Bugs: ProtocolBugs{
5509 NoExtendedMasterSecret: !hasEMS,
5510 },
5511 },
5512 }
5513
5514 if isResumption {
5515 test.resumeSession = true
5516 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005517 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005518 Bugs: ProtocolBugs{
5519 NoExtendedMasterSecret: !hasEMS,
5520 },
5521 }
5522 }
5523
5524 if isResumption && !hasEMS {
5525 test.shouldFail = true
5526 test.expectedError = "failed to get tls-unique"
5527 }
5528
5529 testCases = append(testCases, test)
5530 }
5531 }
5532 }
5533}
5534
Adam Langley09505632015-07-30 18:10:13 -07005535func addCustomExtensionTests() {
5536 expectedContents := "custom extension"
5537 emptyString := ""
5538
David Benjamin4c3ddf72016-06-29 18:13:53 -04005539 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005540 for _, isClient := range []bool{false, true} {
5541 suffix := "Server"
5542 flag := "-enable-server-custom-extension"
5543 testType := serverTest
5544 if isClient {
5545 suffix = "Client"
5546 flag = "-enable-client-custom-extension"
5547 testType = clientTest
5548 }
5549
5550 testCases = append(testCases, testCase{
5551 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005552 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005554 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005555 Bugs: ProtocolBugs{
5556 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005557 ExpectedCustomExtension: &expectedContents,
5558 },
5559 },
5560 flags: []string{flag},
5561 })
5562
5563 // If the parse callback fails, the handshake should also fail.
5564 testCases = append(testCases, testCase{
5565 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005566 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005568 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005569 Bugs: ProtocolBugs{
5570 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005571 ExpectedCustomExtension: &expectedContents,
5572 },
5573 },
David Benjamin399e7c92015-07-30 23:01:27 -04005574 flags: []string{flag},
5575 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005576 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5577 })
5578
5579 // If the add callback fails, the handshake should also fail.
5580 testCases = append(testCases, testCase{
5581 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005582 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005583 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005584 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005585 Bugs: ProtocolBugs{
5586 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005587 ExpectedCustomExtension: &expectedContents,
5588 },
5589 },
David Benjamin399e7c92015-07-30 23:01:27 -04005590 flags: []string{flag, "-custom-extension-fail-add"},
5591 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005592 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5593 })
5594
5595 // If the add callback returns zero, no extension should be
5596 // added.
5597 skipCustomExtension := expectedContents
5598 if isClient {
5599 // For the case where the client skips sending the
5600 // custom extension, the server must not “echo” it.
5601 skipCustomExtension = ""
5602 }
5603 testCases = append(testCases, testCase{
5604 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005605 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005607 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005608 Bugs: ProtocolBugs{
5609 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005610 ExpectedCustomExtension: &emptyString,
5611 },
5612 },
5613 flags: []string{flag, "-custom-extension-skip"},
5614 })
5615 }
5616
5617 // The custom extension add callback should not be called if the client
5618 // doesn't send the extension.
5619 testCases = append(testCases, testCase{
5620 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005621 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005622 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005623 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005624 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005625 ExpectedCustomExtension: &emptyString,
5626 },
5627 },
5628 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5629 })
Adam Langley2deb9842015-08-07 11:15:37 -07005630
5631 // Test an unknown extension from the server.
5632 testCases = append(testCases, testCase{
5633 testType: clientTest,
5634 name: "UnknownExtension-Client",
5635 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005636 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005637 Bugs: ProtocolBugs{
5638 CustomExtension: expectedContents,
5639 },
5640 },
5641 shouldFail: true,
5642 expectedError: ":UNEXPECTED_EXTENSION:",
5643 })
Adam Langley09505632015-07-30 18:10:13 -07005644}
5645
David Benjaminb36a3952015-12-01 18:53:13 -05005646func addRSAClientKeyExchangeTests() {
5647 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5648 testCases = append(testCases, testCase{
5649 testType: serverTest,
5650 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5651 config: Config{
5652 // Ensure the ClientHello version and final
5653 // version are different, to detect if the
5654 // server uses the wrong one.
5655 MaxVersion: VersionTLS11,
5656 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5657 Bugs: ProtocolBugs{
5658 BadRSAClientKeyExchange: bad,
5659 },
5660 },
5661 shouldFail: true,
5662 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5663 })
5664 }
5665}
5666
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005667var testCurves = []struct {
5668 name string
5669 id CurveID
5670}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005671 {"P-256", CurveP256},
5672 {"P-384", CurveP384},
5673 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005674 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005675}
5676
5677func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005678 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005679 for _, curve := range testCurves {
5680 testCases = append(testCases, testCase{
5681 name: "CurveTest-Client-" + curve.name,
5682 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005683 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005684 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5685 CurvePreferences: []CurveID{curve.id},
5686 },
5687 flags: []string{"-enable-all-curves"},
5688 })
5689 testCases = append(testCases, testCase{
5690 testType: serverTest,
5691 name: "CurveTest-Server-" + curve.name,
5692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005693 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5695 CurvePreferences: []CurveID{curve.id},
5696 },
5697 flags: []string{"-enable-all-curves"},
5698 })
5699 }
David Benjamin241ae832016-01-15 03:04:54 -05005700
5701 // The server must be tolerant to bogus curves.
5702 const bogusCurve = 0x1234
5703 testCases = append(testCases, testCase{
5704 testType: serverTest,
5705 name: "UnknownCurve",
5706 config: Config{
5707 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5708 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5709 },
5710 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005711
5712 // The server must not consider ECDHE ciphers when there are no
5713 // supported curves.
5714 testCases = append(testCases, testCase{
5715 testType: serverTest,
5716 name: "NoSupportedCurves",
5717 config: Config{
5718 // TODO(davidben): Add a TLS 1.3 version of this.
5719 MaxVersion: VersionTLS12,
5720 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5721 Bugs: ProtocolBugs{
5722 NoSupportedCurves: true,
5723 },
5724 },
5725 shouldFail: true,
5726 expectedError: ":NO_SHARED_CIPHER:",
5727 })
5728
5729 // The server must fall back to another cipher when there are no
5730 // supported curves.
5731 testCases = append(testCases, testCase{
5732 testType: serverTest,
5733 name: "NoCommonCurves",
5734 config: Config{
5735 MaxVersion: VersionTLS12,
5736 CipherSuites: []uint16{
5737 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5738 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5739 },
5740 CurvePreferences: []CurveID{CurveP224},
5741 },
5742 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5743 })
5744
5745 // The client must reject bogus curves and disabled curves.
5746 testCases = append(testCases, testCase{
5747 name: "BadECDHECurve",
5748 config: Config{
5749 // TODO(davidben): Add a TLS 1.3 version of this.
5750 MaxVersion: VersionTLS12,
5751 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5752 Bugs: ProtocolBugs{
5753 SendCurve: bogusCurve,
5754 },
5755 },
5756 shouldFail: true,
5757 expectedError: ":WRONG_CURVE:",
5758 })
5759
5760 testCases = append(testCases, testCase{
5761 name: "UnsupportedCurve",
5762 config: Config{
5763 // TODO(davidben): Add a TLS 1.3 version of this.
5764 MaxVersion: VersionTLS12,
5765 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5766 CurvePreferences: []CurveID{CurveP256},
5767 Bugs: ProtocolBugs{
5768 IgnorePeerCurvePreferences: true,
5769 },
5770 },
5771 flags: []string{"-p384-only"},
5772 shouldFail: true,
5773 expectedError: ":WRONG_CURVE:",
5774 })
5775
5776 // Test invalid curve points.
5777 testCases = append(testCases, testCase{
5778 name: "InvalidECDHPoint-Client",
5779 config: Config{
5780 // TODO(davidben): Add a TLS 1.3 version of this test.
5781 MaxVersion: VersionTLS12,
5782 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5783 CurvePreferences: []CurveID{CurveP256},
5784 Bugs: ProtocolBugs{
5785 InvalidECDHPoint: true,
5786 },
5787 },
5788 shouldFail: true,
5789 expectedError: ":INVALID_ENCODING:",
5790 })
5791 testCases = append(testCases, testCase{
5792 testType: serverTest,
5793 name: "InvalidECDHPoint-Server",
5794 config: Config{
5795 // TODO(davidben): Add a TLS 1.3 version of this test.
5796 MaxVersion: VersionTLS12,
5797 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5798 CurvePreferences: []CurveID{CurveP256},
5799 Bugs: ProtocolBugs{
5800 InvalidECDHPoint: true,
5801 },
5802 },
5803 shouldFail: true,
5804 expectedError: ":INVALID_ENCODING:",
5805 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005806}
5807
Matt Braithwaite54217e42016-06-13 13:03:47 -07005808func addCECPQ1Tests() {
5809 testCases = append(testCases, testCase{
5810 testType: clientTest,
5811 name: "CECPQ1-Client-BadX25519Part",
5812 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005813 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005814 MinVersion: VersionTLS12,
5815 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5816 Bugs: ProtocolBugs{
5817 CECPQ1BadX25519Part: true,
5818 },
5819 },
5820 flags: []string{"-cipher", "kCECPQ1"},
5821 shouldFail: true,
5822 expectedLocalError: "local error: bad record MAC",
5823 })
5824 testCases = append(testCases, testCase{
5825 testType: clientTest,
5826 name: "CECPQ1-Client-BadNewhopePart",
5827 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005828 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005829 MinVersion: VersionTLS12,
5830 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5831 Bugs: ProtocolBugs{
5832 CECPQ1BadNewhopePart: true,
5833 },
5834 },
5835 flags: []string{"-cipher", "kCECPQ1"},
5836 shouldFail: true,
5837 expectedLocalError: "local error: bad record MAC",
5838 })
5839 testCases = append(testCases, testCase{
5840 testType: serverTest,
5841 name: "CECPQ1-Server-BadX25519Part",
5842 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005843 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005844 MinVersion: VersionTLS12,
5845 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5846 Bugs: ProtocolBugs{
5847 CECPQ1BadX25519Part: true,
5848 },
5849 },
5850 flags: []string{"-cipher", "kCECPQ1"},
5851 shouldFail: true,
5852 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5853 })
5854 testCases = append(testCases, testCase{
5855 testType: serverTest,
5856 name: "CECPQ1-Server-BadNewhopePart",
5857 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005858 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005859 MinVersion: VersionTLS12,
5860 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5861 Bugs: ProtocolBugs{
5862 CECPQ1BadNewhopePart: true,
5863 },
5864 },
5865 flags: []string{"-cipher", "kCECPQ1"},
5866 shouldFail: true,
5867 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5868 })
5869}
5870
David Benjamin4cc36ad2015-12-19 14:23:26 -05005871func addKeyExchangeInfoTests() {
5872 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005873 name: "KeyExchangeInfo-DHE-Client",
5874 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005875 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005876 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5877 Bugs: ProtocolBugs{
5878 // This is a 1234-bit prime number, generated
5879 // with:
5880 // openssl gendh 1234 | openssl asn1parse -i
5881 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5882 },
5883 },
David Benjamin9e68f192016-06-30 14:55:33 -04005884 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005885 })
5886 testCases = append(testCases, testCase{
5887 testType: serverTest,
5888 name: "KeyExchangeInfo-DHE-Server",
5889 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005890 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005891 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5892 },
5893 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005894 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005895 })
5896
Nick Harper1fd39d82016-06-14 18:14:35 -07005897 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5898 // handshake is separate.
5899
David Benjamin4cc36ad2015-12-19 14:23:26 -05005900 testCases = append(testCases, testCase{
5901 name: "KeyExchangeInfo-ECDHE-Client",
5902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005903 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5905 CurvePreferences: []CurveID{CurveX25519},
5906 },
David Benjamin9e68f192016-06-30 14:55:33 -04005907 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005908 })
5909 testCases = append(testCases, testCase{
5910 testType: serverTest,
5911 name: "KeyExchangeInfo-ECDHE-Server",
5912 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005913 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005914 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5915 CurvePreferences: []CurveID{CurveX25519},
5916 },
David Benjamin9e68f192016-06-30 14:55:33 -04005917 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005918 })
5919}
5920
David Benjaminc9ae27c2016-06-24 22:56:37 -04005921func addTLS13RecordTests() {
5922 testCases = append(testCases, testCase{
5923 name: "TLS13-RecordPadding",
5924 config: Config{
5925 MaxVersion: VersionTLS13,
5926 MinVersion: VersionTLS13,
5927 Bugs: ProtocolBugs{
5928 RecordPadding: 10,
5929 },
5930 },
5931 })
5932
5933 testCases = append(testCases, testCase{
5934 name: "TLS13-EmptyRecords",
5935 config: Config{
5936 MaxVersion: VersionTLS13,
5937 MinVersion: VersionTLS13,
5938 Bugs: ProtocolBugs{
5939 OmitRecordContents: true,
5940 },
5941 },
5942 shouldFail: true,
5943 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5944 })
5945
5946 testCases = append(testCases, testCase{
5947 name: "TLS13-OnlyPadding",
5948 config: Config{
5949 MaxVersion: VersionTLS13,
5950 MinVersion: VersionTLS13,
5951 Bugs: ProtocolBugs{
5952 OmitRecordContents: true,
5953 RecordPadding: 10,
5954 },
5955 },
5956 shouldFail: true,
5957 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5958 })
5959
5960 testCases = append(testCases, testCase{
5961 name: "TLS13-WrongOuterRecord",
5962 config: Config{
5963 MaxVersion: VersionTLS13,
5964 MinVersion: VersionTLS13,
5965 Bugs: ProtocolBugs{
5966 OuterRecordType: recordTypeHandshake,
5967 },
5968 },
5969 shouldFail: true,
5970 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5971 })
5972}
5973
David Benjamin82261be2016-07-07 14:32:50 -07005974func addChangeCipherSpecTests() {
5975 // Test missing ChangeCipherSpecs.
5976 testCases = append(testCases, testCase{
5977 name: "SkipChangeCipherSpec-Client",
5978 config: Config{
5979 MaxVersion: VersionTLS12,
5980 Bugs: ProtocolBugs{
5981 SkipChangeCipherSpec: true,
5982 },
5983 },
5984 shouldFail: true,
5985 expectedError: ":UNEXPECTED_RECORD:",
5986 })
5987 testCases = append(testCases, testCase{
5988 testType: serverTest,
5989 name: "SkipChangeCipherSpec-Server",
5990 config: Config{
5991 MaxVersion: VersionTLS12,
5992 Bugs: ProtocolBugs{
5993 SkipChangeCipherSpec: true,
5994 },
5995 },
5996 shouldFail: true,
5997 expectedError: ":UNEXPECTED_RECORD:",
5998 })
5999 testCases = append(testCases, testCase{
6000 testType: serverTest,
6001 name: "SkipChangeCipherSpec-Server-NPN",
6002 config: Config{
6003 MaxVersion: VersionTLS12,
6004 NextProtos: []string{"bar"},
6005 Bugs: ProtocolBugs{
6006 SkipChangeCipherSpec: true,
6007 },
6008 },
6009 flags: []string{
6010 "-advertise-npn", "\x03foo\x03bar\x03baz",
6011 },
6012 shouldFail: true,
6013 expectedError: ":UNEXPECTED_RECORD:",
6014 })
6015
6016 // Test synchronization between the handshake and ChangeCipherSpec.
6017 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6018 // rejected. Test both with and without handshake packing to handle both
6019 // when the partial post-CCS message is in its own record and when it is
6020 // attached to the pre-CCS message.
6021 //
6022 // TODO(davidben): Fix and test DTLS as well.
6023 for _, packed := range []bool{false, true} {
6024 var suffix string
6025 if packed {
6026 suffix = "-Packed"
6027 }
6028
6029 testCases = append(testCases, testCase{
6030 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6031 config: Config{
6032 MaxVersion: VersionTLS12,
6033 Bugs: ProtocolBugs{
6034 FragmentAcrossChangeCipherSpec: true,
6035 PackHandshakeFlight: packed,
6036 },
6037 },
6038 shouldFail: true,
6039 expectedError: ":UNEXPECTED_RECORD:",
6040 })
6041 testCases = append(testCases, testCase{
6042 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6043 config: Config{
6044 MaxVersion: VersionTLS12,
6045 },
6046 resumeSession: true,
6047 resumeConfig: &Config{
6048 MaxVersion: VersionTLS12,
6049 Bugs: ProtocolBugs{
6050 FragmentAcrossChangeCipherSpec: true,
6051 PackHandshakeFlight: packed,
6052 },
6053 },
6054 shouldFail: true,
6055 expectedError: ":UNEXPECTED_RECORD:",
6056 })
6057 testCases = append(testCases, testCase{
6058 testType: serverTest,
6059 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6060 config: Config{
6061 MaxVersion: VersionTLS12,
6062 Bugs: ProtocolBugs{
6063 FragmentAcrossChangeCipherSpec: true,
6064 PackHandshakeFlight: packed,
6065 },
6066 },
6067 shouldFail: true,
6068 expectedError: ":UNEXPECTED_RECORD:",
6069 })
6070 testCases = append(testCases, testCase{
6071 testType: serverTest,
6072 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6073 config: Config{
6074 MaxVersion: VersionTLS12,
6075 },
6076 resumeSession: true,
6077 resumeConfig: &Config{
6078 MaxVersion: VersionTLS12,
6079 Bugs: ProtocolBugs{
6080 FragmentAcrossChangeCipherSpec: true,
6081 PackHandshakeFlight: packed,
6082 },
6083 },
6084 shouldFail: true,
6085 expectedError: ":UNEXPECTED_RECORD:",
6086 })
6087 testCases = append(testCases, testCase{
6088 testType: serverTest,
6089 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6090 config: Config{
6091 MaxVersion: VersionTLS12,
6092 NextProtos: []string{"bar"},
6093 Bugs: ProtocolBugs{
6094 FragmentAcrossChangeCipherSpec: true,
6095 PackHandshakeFlight: packed,
6096 },
6097 },
6098 flags: []string{
6099 "-advertise-npn", "\x03foo\x03bar\x03baz",
6100 },
6101 shouldFail: true,
6102 expectedError: ":UNEXPECTED_RECORD:",
6103 })
6104 }
6105
6106 // Test that early ChangeCipherSpecs are handled correctly.
6107 testCases = append(testCases, testCase{
6108 testType: serverTest,
6109 name: "EarlyChangeCipherSpec-server-1",
6110 config: Config{
6111 MaxVersion: VersionTLS12,
6112 Bugs: ProtocolBugs{
6113 EarlyChangeCipherSpec: 1,
6114 },
6115 },
6116 shouldFail: true,
6117 expectedError: ":UNEXPECTED_RECORD:",
6118 })
6119 testCases = append(testCases, testCase{
6120 testType: serverTest,
6121 name: "EarlyChangeCipherSpec-server-2",
6122 config: Config{
6123 MaxVersion: VersionTLS12,
6124 Bugs: ProtocolBugs{
6125 EarlyChangeCipherSpec: 2,
6126 },
6127 },
6128 shouldFail: true,
6129 expectedError: ":UNEXPECTED_RECORD:",
6130 })
6131 testCases = append(testCases, testCase{
6132 protocol: dtls,
6133 name: "StrayChangeCipherSpec",
6134 config: Config{
6135 // TODO(davidben): Once DTLS 1.3 exists, test
6136 // that stray ChangeCipherSpec messages are
6137 // rejected.
6138 MaxVersion: VersionTLS12,
6139 Bugs: ProtocolBugs{
6140 StrayChangeCipherSpec: true,
6141 },
6142 },
6143 })
6144
6145 // Test that the contents of ChangeCipherSpec are checked.
6146 testCases = append(testCases, testCase{
6147 name: "BadChangeCipherSpec-1",
6148 config: Config{
6149 MaxVersion: VersionTLS12,
6150 Bugs: ProtocolBugs{
6151 BadChangeCipherSpec: []byte{2},
6152 },
6153 },
6154 shouldFail: true,
6155 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6156 })
6157 testCases = append(testCases, testCase{
6158 name: "BadChangeCipherSpec-2",
6159 config: Config{
6160 MaxVersion: VersionTLS12,
6161 Bugs: ProtocolBugs{
6162 BadChangeCipherSpec: []byte{1, 1},
6163 },
6164 },
6165 shouldFail: true,
6166 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6167 })
6168 testCases = append(testCases, testCase{
6169 protocol: dtls,
6170 name: "BadChangeCipherSpec-DTLS-1",
6171 config: Config{
6172 MaxVersion: VersionTLS12,
6173 Bugs: ProtocolBugs{
6174 BadChangeCipherSpec: []byte{2},
6175 },
6176 },
6177 shouldFail: true,
6178 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6179 })
6180 testCases = append(testCases, testCase{
6181 protocol: dtls,
6182 name: "BadChangeCipherSpec-DTLS-2",
6183 config: Config{
6184 MaxVersion: VersionTLS12,
6185 Bugs: ProtocolBugs{
6186 BadChangeCipherSpec: []byte{1, 1},
6187 },
6188 },
6189 shouldFail: true,
6190 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6191 })
6192}
6193
Adam Langley7c803a62015-06-15 15:35:05 -07006194func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006195 defer wg.Done()
6196
6197 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006198 var err error
6199
6200 if *mallocTest < 0 {
6201 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006202 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006203 } else {
6204 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6205 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006206 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006207 if err != nil {
6208 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6209 }
6210 break
6211 }
6212 }
6213 }
Adam Langley95c29f32014-06-20 12:00:00 -07006214 statusChan <- statusMsg{test: test, err: err}
6215 }
6216}
6217
6218type statusMsg struct {
6219 test *testCase
6220 started bool
6221 err error
6222}
6223
David Benjamin5f237bc2015-02-11 17:14:15 -05006224func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006225 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006226
David Benjamin5f237bc2015-02-11 17:14:15 -05006227 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006228 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006229 if !*pipe {
6230 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006231 var erase string
6232 for i := 0; i < lineLen; i++ {
6233 erase += "\b \b"
6234 }
6235 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006236 }
6237
Adam Langley95c29f32014-06-20 12:00:00 -07006238 if msg.started {
6239 started++
6240 } else {
6241 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006242
6243 if msg.err != nil {
6244 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6245 failed++
6246 testOutput.addResult(msg.test.name, "FAIL")
6247 } else {
6248 if *pipe {
6249 // Print each test instead of a status line.
6250 fmt.Printf("PASSED (%s)\n", msg.test.name)
6251 }
6252 testOutput.addResult(msg.test.name, "PASS")
6253 }
Adam Langley95c29f32014-06-20 12:00:00 -07006254 }
6255
David Benjamin5f237bc2015-02-11 17:14:15 -05006256 if !*pipe {
6257 // Print a new status line.
6258 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6259 lineLen = len(line)
6260 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006261 }
Adam Langley95c29f32014-06-20 12:00:00 -07006262 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006263
6264 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006265}
6266
6267func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006268 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006269 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006270 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006271
Adam Langley7c803a62015-06-15 15:35:05 -07006272 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006273 addCipherSuiteTests()
6274 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006275 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006276 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006277 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006278 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006279 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006280 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006281 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006282 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006283 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006284 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006285 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006286 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006287 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006288 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006289 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006290 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006291 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006292 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006293 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006294 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006295 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006296 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006297 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006298
6299 var wg sync.WaitGroup
6300
Adam Langley7c803a62015-06-15 15:35:05 -07006301 statusChan := make(chan statusMsg, *numWorkers)
6302 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006303 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006304
David Benjamin025b3d32014-07-01 19:53:04 -04006305 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006306
Adam Langley7c803a62015-06-15 15:35:05 -07006307 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006308 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006309 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006310 }
6311
David Benjamin270f0a72016-03-17 14:41:36 -04006312 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006313 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006314 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006315 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006316 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006317 }
6318 }
David Benjamin270f0a72016-03-17 14:41:36 -04006319 if !foundTest {
6320 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6321 os.Exit(1)
6322 }
Adam Langley95c29f32014-06-20 12:00:00 -07006323
6324 close(testChan)
6325 wg.Wait()
6326 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006327 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006328
6329 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006330
6331 if *jsonOutput != "" {
6332 if err := testOutput.writeTo(*jsonOutput); err != nil {
6333 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6334 }
6335 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006336
6337 if !testOutput.allPassed {
6338 os.Exit(1)
6339 }
Adam Langley95c29f32014-06-20 12:00:00 -07006340}