blob: 4f9861f3023b4b9824cd6ca828ff34b807f3e9ad [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{
1683 Bugs: ProtocolBugs{
1684 WrongCertificateMessageType: true,
1685 },
1686 },
1687 shouldFail: true,
1688 expectedError: ":UNEXPECTED_MESSAGE:",
1689 expectedLocalError: "remote error: unexpected message",
1690 },
1691 {
1692 protocol: dtls,
1693 name: "WrongMessageType-DTLS",
1694 config: Config{
1695 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: "FragmentMessageTypeMismatch-DTLS",
1706 config: Config{
1707 Bugs: ProtocolBugs{
1708 MaxHandshakeRecordLength: 2,
1709 FragmentMessageTypeMismatch: true,
1710 },
1711 },
1712 shouldFail: true,
1713 expectedError: ":FRAGMENT_MISMATCH:",
1714 },
1715 {
1716 protocol: dtls,
1717 name: "FragmentMessageLengthMismatch-DTLS",
1718 config: Config{
1719 Bugs: ProtocolBugs{
1720 MaxHandshakeRecordLength: 2,
1721 FragmentMessageLengthMismatch: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":FRAGMENT_MISMATCH:",
1726 },
1727 {
1728 protocol: dtls,
1729 name: "SplitFragments-Header-DTLS",
1730 config: Config{
1731 Bugs: ProtocolBugs{
1732 SplitFragments: 2,
1733 },
1734 },
1735 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001736 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001737 },
1738 {
1739 protocol: dtls,
1740 name: "SplitFragments-Boundary-DTLS",
1741 config: Config{
1742 Bugs: ProtocolBugs{
1743 SplitFragments: dtlsRecordHeaderLen,
1744 },
1745 },
1746 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001747 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001748 },
1749 {
1750 protocol: dtls,
1751 name: "SplitFragments-Body-DTLS",
1752 config: Config{
1753 Bugs: ProtocolBugs{
1754 SplitFragments: dtlsRecordHeaderLen + 1,
1755 },
1756 },
1757 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001758 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001759 },
1760 {
1761 protocol: dtls,
1762 name: "SendEmptyFragments-DTLS",
1763 config: Config{
1764 Bugs: ProtocolBugs{
1765 SendEmptyFragments: true,
1766 },
1767 },
1768 },
1769 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001770 name: "BadFinished-Client",
1771 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001772 // TODO(davidben): Add a TLS 1.3 version of this.
1773 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001774 Bugs: ProtocolBugs{
1775 BadFinished: true,
1776 },
1777 },
1778 shouldFail: true,
1779 expectedError: ":DIGEST_CHECK_FAILED:",
1780 },
1781 {
1782 testType: serverTest,
1783 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001785 // TODO(davidben): Add a TLS 1.3 version of this.
1786 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001787 Bugs: ProtocolBugs{
1788 BadFinished: true,
1789 },
1790 },
1791 shouldFail: true,
1792 expectedError: ":DIGEST_CHECK_FAILED:",
1793 },
1794 {
1795 name: "FalseStart-BadFinished",
1796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001797 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1799 NextProtos: []string{"foo"},
1800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 ExpectFalseStart: true,
1803 },
1804 },
1805 flags: []string{
1806 "-false-start",
1807 "-handshake-never-done",
1808 "-advertise-alpn", "\x03foo",
1809 },
1810 shimWritesFirst: true,
1811 shouldFail: true,
1812 expectedError: ":DIGEST_CHECK_FAILED:",
1813 },
1814 {
1815 name: "NoFalseStart-NoALPN",
1816 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001817 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1819 Bugs: ProtocolBugs{
1820 ExpectFalseStart: true,
1821 AlertBeforeFalseStartTest: alertAccessDenied,
1822 },
1823 },
1824 flags: []string{
1825 "-false-start",
1826 },
1827 shimWritesFirst: true,
1828 shouldFail: true,
1829 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1830 expectedLocalError: "tls: peer did not false start: EOF",
1831 },
1832 {
1833 name: "NoFalseStart-NoAEAD",
1834 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001835 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1837 NextProtos: []string{"foo"},
1838 Bugs: ProtocolBugs{
1839 ExpectFalseStart: true,
1840 AlertBeforeFalseStartTest: alertAccessDenied,
1841 },
1842 },
1843 flags: []string{
1844 "-false-start",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1850 expectedLocalError: "tls: peer did not false start: EOF",
1851 },
1852 {
1853 name: "NoFalseStart-RSA",
1854 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001855 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001856 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1857 NextProtos: []string{"foo"},
1858 Bugs: ProtocolBugs{
1859 ExpectFalseStart: true,
1860 AlertBeforeFalseStartTest: alertAccessDenied,
1861 },
1862 },
1863 flags: []string{
1864 "-false-start",
1865 "-advertise-alpn", "\x03foo",
1866 },
1867 shimWritesFirst: true,
1868 shouldFail: true,
1869 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1870 expectedLocalError: "tls: peer did not false start: EOF",
1871 },
1872 {
1873 name: "NoFalseStart-DHE_RSA",
1874 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001875 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001876 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1877 NextProtos: []string{"foo"},
1878 Bugs: ProtocolBugs{
1879 ExpectFalseStart: true,
1880 AlertBeforeFalseStartTest: alertAccessDenied,
1881 },
1882 },
1883 flags: []string{
1884 "-false-start",
1885 "-advertise-alpn", "\x03foo",
1886 },
1887 shimWritesFirst: true,
1888 shouldFail: true,
1889 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1890 expectedLocalError: "tls: peer did not false start: EOF",
1891 },
1892 {
Adam Langley7c803a62015-06-15 15:35:05 -07001893 protocol: dtls,
1894 name: "SendSplitAlert-Sync",
1895 config: Config{
1896 Bugs: ProtocolBugs{
1897 SendSplitAlert: true,
1898 },
1899 },
1900 },
1901 {
1902 protocol: dtls,
1903 name: "SendSplitAlert-Async",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 SendSplitAlert: true,
1907 },
1908 },
1909 flags: []string{"-async"},
1910 },
1911 {
1912 protocol: dtls,
1913 name: "PackDTLSHandshake",
1914 config: Config{
1915 Bugs: ProtocolBugs{
1916 MaxHandshakeRecordLength: 2,
1917 PackHandshakeFragments: 20,
1918 PackHandshakeRecords: 200,
1919 },
1920 },
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 name: "SendEmptyRecords-Pass",
1924 sendEmptyRecords: 32,
1925 },
1926 {
1927 name: "SendEmptyRecords",
1928 sendEmptyRecords: 33,
1929 shouldFail: true,
1930 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1931 },
1932 {
1933 name: "SendEmptyRecords-Async",
1934 sendEmptyRecords: 33,
1935 flags: []string{"-async"},
1936 shouldFail: true,
1937 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1938 },
1939 {
1940 name: "SendWarningAlerts-Pass",
1941 sendWarningAlerts: 4,
1942 },
1943 {
1944 protocol: dtls,
1945 name: "SendWarningAlerts-DTLS-Pass",
1946 sendWarningAlerts: 4,
1947 },
1948 {
1949 name: "SendWarningAlerts",
1950 sendWarningAlerts: 5,
1951 shouldFail: true,
1952 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1953 },
1954 {
1955 name: "SendWarningAlerts-Async",
1956 sendWarningAlerts: 5,
1957 flags: []string{"-async"},
1958 shouldFail: true,
1959 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1960 },
David Benjaminba4594a2015-06-18 18:36:15 -04001961 {
1962 name: "EmptySessionID",
1963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001964 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001965 SessionTicketsDisabled: true,
1966 },
1967 noSessionCache: true,
1968 flags: []string{"-expect-no-session"},
1969 },
David Benjamin30789da2015-08-29 22:56:45 -04001970 {
1971 name: "Unclean-Shutdown",
1972 config: Config{
1973 Bugs: ProtocolBugs{
1974 NoCloseNotify: true,
1975 ExpectCloseNotify: true,
1976 },
1977 },
1978 shimShutsDown: true,
1979 flags: []string{"-check-close-notify"},
1980 shouldFail: true,
1981 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1982 },
1983 {
1984 name: "Unclean-Shutdown-Ignored",
1985 config: Config{
1986 Bugs: ProtocolBugs{
1987 NoCloseNotify: true,
1988 },
1989 },
1990 shimShutsDown: true,
1991 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001992 {
David Benjaminfa214e42016-05-10 17:03:10 -04001993 name: "Unclean-Shutdown-Alert",
1994 config: Config{
1995 Bugs: ProtocolBugs{
1996 SendAlertOnShutdown: alertDecompressionFailure,
1997 ExpectCloseNotify: true,
1998 },
1999 },
2000 shimShutsDown: true,
2001 flags: []string{"-check-close-notify"},
2002 shouldFail: true,
2003 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2004 },
2005 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002006 name: "LargePlaintext",
2007 config: Config{
2008 Bugs: ProtocolBugs{
2009 SendLargeRecords: true,
2010 },
2011 },
2012 messageLen: maxPlaintext + 1,
2013 shouldFail: true,
2014 expectedError: ":DATA_LENGTH_TOO_LONG:",
2015 },
2016 {
2017 protocol: dtls,
2018 name: "LargePlaintext-DTLS",
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 name: "LargeCiphertext",
2030 config: Config{
2031 Bugs: ProtocolBugs{
2032 SendLargeRecords: true,
2033 },
2034 },
2035 messageLen: maxPlaintext * 2,
2036 shouldFail: true,
2037 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2038 },
2039 {
2040 protocol: dtls,
2041 name: "LargeCiphertext-DTLS",
2042 config: Config{
2043 Bugs: ProtocolBugs{
2044 SendLargeRecords: true,
2045 },
2046 },
2047 messageLen: maxPlaintext * 2,
2048 // Unlike the other four cases, DTLS drops records which
2049 // are invalid before authentication, so the connection
2050 // does not fail.
2051 expectMessageDropped: true,
2052 },
David Benjamindd6fed92015-10-23 17:41:12 -04002053 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002054 // In TLS 1.2 and below, empty NewSessionTicket messages
2055 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002056 name: "SendEmptySessionTicket",
2057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002058 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002059 Bugs: ProtocolBugs{
2060 SendEmptySessionTicket: true,
2061 FailIfSessionOffered: true,
2062 },
2063 },
2064 flags: []string{"-expect-no-session"},
2065 resumeSession: true,
2066 expectResumeRejected: true,
2067 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002068 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002069 name: "BadHelloRequest-1",
2070 renegotiate: 1,
2071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002072 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002073 Bugs: ProtocolBugs{
2074 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2075 },
2076 },
2077 flags: []string{
2078 "-renegotiate-freely",
2079 "-expect-total-renegotiations", "1",
2080 },
2081 shouldFail: true,
2082 expectedError: ":BAD_HELLO_REQUEST:",
2083 },
2084 {
2085 name: "BadHelloRequest-2",
2086 renegotiate: 1,
2087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002088 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002089 Bugs: ProtocolBugs{
2090 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2091 },
2092 },
2093 flags: []string{
2094 "-renegotiate-freely",
2095 "-expect-total-renegotiations", "1",
2096 },
2097 shouldFail: true,
2098 expectedError: ":BAD_HELLO_REQUEST:",
2099 },
David Benjaminef1b0092015-11-21 14:05:44 -05002100 {
2101 testType: serverTest,
2102 name: "SupportTicketsWithSessionID",
2103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002104 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002105 SessionTicketsDisabled: true,
2106 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002107 resumeConfig: &Config{
2108 MaxVersion: VersionTLS12,
2109 },
David Benjaminef1b0092015-11-21 14:05:44 -05002110 resumeSession: true,
2111 },
Adam Langley7c803a62015-06-15 15:35:05 -07002112 }
Adam Langley7c803a62015-06-15 15:35:05 -07002113 testCases = append(testCases, basicTests...)
2114}
2115
Adam Langley95c29f32014-06-20 12:00:00 -07002116func addCipherSuiteTests() {
2117 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002118 const psk = "12345"
2119 const pskIdentity = "luggage combo"
2120
Adam Langley95c29f32014-06-20 12:00:00 -07002121 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002122 var certFile string
2123 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002124 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002125 cert = ecdsaP256Certificate
2126 certFile = ecdsaP256CertificateFile
2127 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002128 } else {
David Benjamin33863262016-07-08 17:20:12 -07002129 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002130 certFile = rsaCertificateFile
2131 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002132 }
2133
David Benjamin48cae082014-10-27 01:06:24 -04002134 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002135 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002136 flags = append(flags,
2137 "-psk", psk,
2138 "-psk-identity", pskIdentity)
2139 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002140 if hasComponent(suite.name, "NULL") {
2141 // NULL ciphers must be explicitly enabled.
2142 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2143 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002144 if hasComponent(suite.name, "CECPQ1") {
2145 // CECPQ1 ciphers must be explicitly enabled.
2146 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2147 }
David Benjamin48cae082014-10-27 01:06:24 -04002148
Adam Langley95c29f32014-06-20 12:00:00 -07002149 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002150 for _, protocol := range []protocol{tls, dtls} {
2151 var prefix string
2152 if protocol == dtls {
2153 if !ver.hasDTLS {
2154 continue
2155 }
2156 prefix = "D"
2157 }
Adam Langley95c29f32014-06-20 12:00:00 -07002158
David Benjamin0407e762016-06-17 16:41:18 -04002159 var shouldServerFail, shouldClientFail bool
2160 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2161 // BoringSSL clients accept ECDHE on SSLv3, but
2162 // a BoringSSL server will never select it
2163 // because the extension is missing.
2164 shouldServerFail = true
2165 }
2166 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2167 shouldClientFail = true
2168 shouldServerFail = true
2169 }
David Benjamin54c217c2016-07-13 12:35:25 -04002170 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002171 shouldClientFail = true
2172 shouldServerFail = true
2173 }
David Benjamin0407e762016-06-17 16:41:18 -04002174 if !isDTLSCipher(suite.name) && protocol == dtls {
2175 shouldClientFail = true
2176 shouldServerFail = true
2177 }
David Benjamin4298d772015-12-19 00:18:25 -05002178
David Benjamin0407e762016-06-17 16:41:18 -04002179 var expectedServerError, expectedClientError string
2180 if shouldServerFail {
2181 expectedServerError = ":NO_SHARED_CIPHER:"
2182 }
2183 if shouldClientFail {
2184 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2185 }
David Benjamin025b3d32014-07-01 19:53:04 -04002186
David Benjamin6fd297b2014-08-11 18:43:38 -04002187 testCases = append(testCases, testCase{
2188 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002189 protocol: protocol,
2190
2191 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002192 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002193 MinVersion: ver.version,
2194 MaxVersion: ver.version,
2195 CipherSuites: []uint16{suite.id},
2196 Certificates: []Certificate{cert},
2197 PreSharedKey: []byte(psk),
2198 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002199 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002200 EnableAllCiphers: shouldServerFail,
2201 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002202 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002203 },
2204 certFile: certFile,
2205 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002206 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002207 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002208 shouldFail: shouldServerFail,
2209 expectedError: expectedServerError,
2210 })
2211
2212 testCases = append(testCases, testCase{
2213 testType: clientTest,
2214 protocol: protocol,
2215 name: prefix + ver.name + "-" + suite.name + "-client",
2216 config: Config{
2217 MinVersion: ver.version,
2218 MaxVersion: ver.version,
2219 CipherSuites: []uint16{suite.id},
2220 Certificates: []Certificate{cert},
2221 PreSharedKey: []byte(psk),
2222 PreSharedKeyIdentity: pskIdentity,
2223 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002224 EnableAllCiphers: shouldClientFail,
2225 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002226 },
2227 },
2228 flags: flags,
2229 resumeSession: true,
2230 shouldFail: shouldClientFail,
2231 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002232 })
David Benjamin2c99d282015-09-01 10:23:00 -04002233
Nick Harper1fd39d82016-06-14 18:14:35 -07002234 if !shouldClientFail {
2235 // Ensure the maximum record size is accepted.
2236 testCases = append(testCases, testCase{
2237 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2238 config: Config{
2239 MinVersion: ver.version,
2240 MaxVersion: ver.version,
2241 CipherSuites: []uint16{suite.id},
2242 Certificates: []Certificate{cert},
2243 PreSharedKey: []byte(psk),
2244 PreSharedKeyIdentity: pskIdentity,
2245 },
2246 flags: flags,
2247 messageLen: maxPlaintext,
2248 })
2249 }
2250 }
David Benjamin2c99d282015-09-01 10:23:00 -04002251 }
Adam Langley95c29f32014-06-20 12:00:00 -07002252 }
Adam Langleya7997f12015-05-14 17:38:50 -07002253
2254 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002255 name: "NoSharedCipher",
2256 config: Config{
2257 // TODO(davidben): Add a TLS 1.3 version of this test.
2258 MaxVersion: VersionTLS12,
2259 CipherSuites: []uint16{},
2260 },
2261 shouldFail: true,
2262 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2263 })
2264
2265 testCases = append(testCases, testCase{
2266 name: "UnsupportedCipherSuite",
2267 config: Config{
2268 MaxVersion: VersionTLS12,
2269 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2270 Bugs: ProtocolBugs{
2271 IgnorePeerCipherPreferences: true,
2272 },
2273 },
2274 flags: []string{"-cipher", "DEFAULT:!RC4"},
2275 shouldFail: true,
2276 expectedError: ":WRONG_CIPHER_RETURNED:",
2277 })
2278
2279 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002280 name: "WeakDH",
2281 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002282 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002283 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2284 Bugs: ProtocolBugs{
2285 // This is a 1023-bit prime number, generated
2286 // with:
2287 // openssl gendh 1023 | openssl asn1parse -i
2288 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2289 },
2290 },
2291 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002292 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002293 })
Adam Langleycef75832015-09-03 14:51:12 -07002294
David Benjamincd24a392015-11-11 13:23:05 -08002295 testCases = append(testCases, testCase{
2296 name: "SillyDH",
2297 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002298 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002299 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2300 Bugs: ProtocolBugs{
2301 // This is a 4097-bit prime number, generated
2302 // with:
2303 // openssl gendh 4097 | openssl asn1parse -i
2304 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2305 },
2306 },
2307 shouldFail: true,
2308 expectedError: ":DH_P_TOO_LONG:",
2309 })
2310
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002311 // This test ensures that Diffie-Hellman public values are padded with
2312 // zeros so that they're the same length as the prime. This is to avoid
2313 // hitting a bug in yaSSL.
2314 testCases = append(testCases, testCase{
2315 testType: serverTest,
2316 name: "DHPublicValuePadded",
2317 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002318 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002319 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2320 Bugs: ProtocolBugs{
2321 RequireDHPublicValueLen: (1025 + 7) / 8,
2322 },
2323 },
2324 flags: []string{"-use-sparse-dh-prime"},
2325 })
David Benjamincd24a392015-11-11 13:23:05 -08002326
David Benjamin241ae832016-01-15 03:04:54 -05002327 // The server must be tolerant to bogus ciphers.
2328 const bogusCipher = 0x1234
2329 testCases = append(testCases, testCase{
2330 testType: serverTest,
2331 name: "UnknownCipher",
2332 config: Config{
2333 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2334 },
2335 })
2336
Adam Langleycef75832015-09-03 14:51:12 -07002337 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2338 // 1.1 specific cipher suite settings. A server is setup with the given
2339 // cipher lists and then a connection is made for each member of
2340 // expectations. The cipher suite that the server selects must match
2341 // the specified one.
2342 var versionSpecificCiphersTest = []struct {
2343 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2344 // expectations is a map from TLS version to cipher suite id.
2345 expectations map[uint16]uint16
2346 }{
2347 {
2348 // Test that the null case (where no version-specific ciphers are set)
2349 // works as expected.
2350 "RC4-SHA:AES128-SHA", // default ciphers
2351 "", // no ciphers specifically for TLS ≥ 1.0
2352 "", // no ciphers specifically for TLS ≥ 1.1
2353 map[uint16]uint16{
2354 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2355 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2356 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2357 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2358 },
2359 },
2360 {
2361 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2362 // cipher.
2363 "RC4-SHA:AES128-SHA", // default
2364 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2365 "", // no ciphers specifically for TLS ≥ 1.1
2366 map[uint16]uint16{
2367 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2368 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2369 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2370 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2371 },
2372 },
2373 {
2374 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2375 // cipher.
2376 "RC4-SHA:AES128-SHA", // default
2377 "", // no ciphers specifically for TLS ≥ 1.0
2378 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2379 map[uint16]uint16{
2380 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2381 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2382 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2383 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2384 },
2385 },
2386 {
2387 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2388 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2389 "RC4-SHA:AES128-SHA", // default
2390 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2391 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2392 map[uint16]uint16{
2393 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2394 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2395 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2396 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2397 },
2398 },
2399 }
2400
2401 for i, test := range versionSpecificCiphersTest {
2402 for version, expectedCipherSuite := range test.expectations {
2403 flags := []string{"-cipher", test.ciphersDefault}
2404 if len(test.ciphersTLS10) > 0 {
2405 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2406 }
2407 if len(test.ciphersTLS11) > 0 {
2408 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2409 }
2410
2411 testCases = append(testCases, testCase{
2412 testType: serverTest,
2413 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2414 config: Config{
2415 MaxVersion: version,
2416 MinVersion: version,
2417 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2418 },
2419 flags: flags,
2420 expectedCipher: expectedCipherSuite,
2421 })
2422 }
2423 }
Adam Langley95c29f32014-06-20 12:00:00 -07002424}
2425
2426func addBadECDSASignatureTests() {
2427 for badR := BadValue(1); badR < NumBadValues; badR++ {
2428 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002429 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002430 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2431 config: Config{
2432 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002433 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002434 Bugs: ProtocolBugs{
2435 BadECDSAR: badR,
2436 BadECDSAS: badS,
2437 },
2438 },
2439 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002440 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002441 })
2442 }
2443 }
2444}
2445
Adam Langley80842bd2014-06-20 12:00:00 -07002446func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002447 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002448 name: "MaxCBCPadding",
2449 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002450 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2452 Bugs: ProtocolBugs{
2453 MaxPadding: true,
2454 },
2455 },
2456 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2457 })
David Benjamin025b3d32014-07-01 19:53:04 -04002458 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002459 name: "BadCBCPadding",
2460 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002461 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002462 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2463 Bugs: ProtocolBugs{
2464 PaddingFirstByteBad: true,
2465 },
2466 },
2467 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002468 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002469 })
2470 // OpenSSL previously had an issue where the first byte of padding in
2471 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002472 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002473 name: "BadCBCPadding255",
2474 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002475 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002476 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2477 Bugs: ProtocolBugs{
2478 MaxPadding: true,
2479 PaddingFirstByteBadIf255: true,
2480 },
2481 },
2482 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2483 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002484 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002485 })
2486}
2487
Kenny Root7fdeaf12014-08-05 15:23:37 -07002488func addCBCSplittingTests() {
2489 testCases = append(testCases, testCase{
2490 name: "CBCRecordSplitting",
2491 config: Config{
2492 MaxVersion: VersionTLS10,
2493 MinVersion: VersionTLS10,
2494 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2495 },
David Benjaminac8302a2015-09-01 17:18:15 -04002496 messageLen: -1, // read until EOF
2497 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002498 flags: []string{
2499 "-async",
2500 "-write-different-record-sizes",
2501 "-cbc-record-splitting",
2502 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002503 })
2504 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002505 name: "CBCRecordSplittingPartialWrite",
2506 config: Config{
2507 MaxVersion: VersionTLS10,
2508 MinVersion: VersionTLS10,
2509 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2510 },
2511 messageLen: -1, // read until EOF
2512 flags: []string{
2513 "-async",
2514 "-write-different-record-sizes",
2515 "-cbc-record-splitting",
2516 "-partial-write",
2517 },
2518 })
2519}
2520
David Benjamin636293b2014-07-08 17:59:18 -04002521func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002522 // Add a dummy cert pool to stress certificate authority parsing.
2523 // TODO(davidben): Add tests that those values parse out correctly.
2524 certPool := x509.NewCertPool()
2525 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2526 if err != nil {
2527 panic(err)
2528 }
2529 certPool.AddCert(cert)
2530
David Benjamin636293b2014-07-08 17:59:18 -04002531 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002532 testCases = append(testCases, testCase{
2533 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002534 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002535 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002536 MinVersion: ver.version,
2537 MaxVersion: ver.version,
2538 ClientAuth: RequireAnyClientCert,
2539 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002540 },
2541 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002542 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2543 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002544 },
2545 })
2546 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002547 testType: serverTest,
2548 name: ver.name + "-Server-ClientAuth-RSA",
2549 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002550 MinVersion: ver.version,
2551 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002552 Certificates: []Certificate{rsaCertificate},
2553 },
2554 flags: []string{"-require-any-client-certificate"},
2555 })
David Benjamine098ec22014-08-27 23:13:20 -04002556 if ver.version != VersionSSL30 {
2557 testCases = append(testCases, testCase{
2558 testType: serverTest,
2559 name: ver.name + "-Server-ClientAuth-ECDSA",
2560 config: Config{
2561 MinVersion: ver.version,
2562 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002563 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002564 },
2565 flags: []string{"-require-any-client-certificate"},
2566 })
2567 testCases = append(testCases, testCase{
2568 testType: clientTest,
2569 name: ver.name + "-Client-ClientAuth-ECDSA",
2570 config: Config{
2571 MinVersion: ver.version,
2572 MaxVersion: ver.version,
2573 ClientAuth: RequireAnyClientCert,
2574 ClientCAs: certPool,
2575 },
2576 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002577 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2578 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002579 },
2580 })
2581 }
David Benjamin636293b2014-07-08 17:59:18 -04002582 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002583
Nick Harper1fd39d82016-06-14 18:14:35 -07002584 // TODO(davidben): These tests will need TLS 1.3 versions when the
2585 // handshake is separate.
2586
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002587 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002588 name: "NoClientCertificate",
2589 config: Config{
2590 MaxVersion: VersionTLS12,
2591 ClientAuth: RequireAnyClientCert,
2592 },
2593 shouldFail: true,
2594 expectedLocalError: "client didn't provide a certificate",
2595 })
2596
2597 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002598 testType: serverTest,
2599 name: "RequireAnyClientCertificate",
2600 config: Config{
2601 MaxVersion: VersionTLS12,
2602 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002603 flags: []string{"-require-any-client-certificate"},
2604 shouldFail: true,
2605 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2606 })
2607
2608 testCases = append(testCases, testCase{
2609 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002610 name: "RequireAnyClientCertificate-SSL3",
2611 config: Config{
2612 MaxVersion: VersionSSL30,
2613 },
2614 flags: []string{"-require-any-client-certificate"},
2615 shouldFail: true,
2616 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2617 })
2618
2619 testCases = append(testCases, testCase{
2620 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002621 name: "SkipClientCertificate",
2622 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002623 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002624 Bugs: ProtocolBugs{
2625 SkipClientCertificate: true,
2626 },
2627 },
2628 // Setting SSL_VERIFY_PEER allows anonymous clients.
2629 flags: []string{"-verify-peer"},
2630 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002631 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002632 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002633
2634 // Client auth is only legal in certificate-based ciphers.
2635 testCases = append(testCases, testCase{
2636 testType: clientTest,
2637 name: "ClientAuth-PSK",
2638 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002639 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002640 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2641 PreSharedKey: []byte("secret"),
2642 ClientAuth: RequireAnyClientCert,
2643 },
2644 flags: []string{
2645 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2646 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2647 "-psk", "secret",
2648 },
2649 shouldFail: true,
2650 expectedError: ":UNEXPECTED_MESSAGE:",
2651 })
2652 testCases = append(testCases, testCase{
2653 testType: clientTest,
2654 name: "ClientAuth-ECDHE_PSK",
2655 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002656 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002657 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2658 PreSharedKey: []byte("secret"),
2659 ClientAuth: RequireAnyClientCert,
2660 },
2661 flags: []string{
2662 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2663 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2664 "-psk", "secret",
2665 },
2666 shouldFail: true,
2667 expectedError: ":UNEXPECTED_MESSAGE:",
2668 })
David Benjamin636293b2014-07-08 17:59:18 -04002669}
2670
Adam Langley75712922014-10-10 16:23:43 -07002671func addExtendedMasterSecretTests() {
2672 const expectEMSFlag = "-expect-extended-master-secret"
2673
2674 for _, with := range []bool{false, true} {
2675 prefix := "No"
2676 var flags []string
2677 if with {
2678 prefix = ""
2679 flags = []string{expectEMSFlag}
2680 }
2681
2682 for _, isClient := range []bool{false, true} {
2683 suffix := "-Server"
2684 testType := serverTest
2685 if isClient {
2686 suffix = "-Client"
2687 testType = clientTest
2688 }
2689
David Benjamin4c3ddf72016-06-29 18:13:53 -04002690 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2691 // test that the extension is irrelevant, but the API
2692 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002693 for _, ver := range tlsVersions {
2694 test := testCase{
2695 testType: testType,
2696 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2697 config: Config{
2698 MinVersion: ver.version,
2699 MaxVersion: ver.version,
2700 Bugs: ProtocolBugs{
2701 NoExtendedMasterSecret: !with,
2702 RequireExtendedMasterSecret: with,
2703 },
2704 },
David Benjamin48cae082014-10-27 01:06:24 -04002705 flags: flags,
2706 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002707 }
2708 if test.shouldFail {
2709 test.expectedLocalError = "extended master secret required but not supported by peer"
2710 }
2711 testCases = append(testCases, test)
2712 }
2713 }
2714 }
2715
Adam Langleyba5934b2015-06-02 10:50:35 -07002716 for _, isClient := range []bool{false, true} {
2717 for _, supportedInFirstConnection := range []bool{false, true} {
2718 for _, supportedInResumeConnection := range []bool{false, true} {
2719 boolToWord := func(b bool) string {
2720 if b {
2721 return "Yes"
2722 }
2723 return "No"
2724 }
2725 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2726 if isClient {
2727 suffix += "Client"
2728 } else {
2729 suffix += "Server"
2730 }
2731
2732 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002733 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002734 Bugs: ProtocolBugs{
2735 RequireExtendedMasterSecret: true,
2736 },
2737 }
2738
2739 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002740 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002741 Bugs: ProtocolBugs{
2742 NoExtendedMasterSecret: true,
2743 },
2744 }
2745
2746 test := testCase{
2747 name: "ExtendedMasterSecret-" + suffix,
2748 resumeSession: true,
2749 }
2750
2751 if !isClient {
2752 test.testType = serverTest
2753 }
2754
2755 if supportedInFirstConnection {
2756 test.config = supportedConfig
2757 } else {
2758 test.config = noSupportConfig
2759 }
2760
2761 if supportedInResumeConnection {
2762 test.resumeConfig = &supportedConfig
2763 } else {
2764 test.resumeConfig = &noSupportConfig
2765 }
2766
2767 switch suffix {
2768 case "YesToYes-Client", "YesToYes-Server":
2769 // When a session is resumed, it should
2770 // still be aware that its master
2771 // secret was generated via EMS and
2772 // thus it's safe to use tls-unique.
2773 test.flags = []string{expectEMSFlag}
2774 case "NoToYes-Server":
2775 // If an original connection did not
2776 // contain EMS, but a resumption
2777 // handshake does, then a server should
2778 // not resume the session.
2779 test.expectResumeRejected = true
2780 case "YesToNo-Server":
2781 // Resuming an EMS session without the
2782 // EMS extension should cause the
2783 // server to abort the connection.
2784 test.shouldFail = true
2785 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2786 case "NoToYes-Client":
2787 // A client should abort a connection
2788 // where the server resumed a non-EMS
2789 // session but echoed the EMS
2790 // extension.
2791 test.shouldFail = true
2792 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2793 case "YesToNo-Client":
2794 // A client should abort a connection
2795 // where the server didn't echo EMS
2796 // when the session used it.
2797 test.shouldFail = true
2798 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2799 }
2800
2801 testCases = append(testCases, test)
2802 }
2803 }
2804 }
Adam Langley75712922014-10-10 16:23:43 -07002805}
2806
David Benjamin582ba042016-07-07 12:33:25 -07002807type stateMachineTestConfig struct {
2808 protocol protocol
2809 async bool
2810 splitHandshake, packHandshakeFlight bool
2811}
2812
David Benjamin43ec06f2014-08-05 02:28:57 -04002813// Adds tests that try to cover the range of the handshake state machine, under
2814// various conditions. Some of these are redundant with other tests, but they
2815// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002816func addAllStateMachineCoverageTests() {
2817 for _, async := range []bool{false, true} {
2818 for _, protocol := range []protocol{tls, dtls} {
2819 addStateMachineCoverageTests(stateMachineTestConfig{
2820 protocol: protocol,
2821 async: async,
2822 })
2823 addStateMachineCoverageTests(stateMachineTestConfig{
2824 protocol: protocol,
2825 async: async,
2826 splitHandshake: true,
2827 })
2828 if protocol == tls {
2829 addStateMachineCoverageTests(stateMachineTestConfig{
2830 protocol: protocol,
2831 async: async,
2832 packHandshakeFlight: true,
2833 })
2834 }
2835 }
2836 }
2837}
2838
2839func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002840 var tests []testCase
2841
2842 // Basic handshake, with resumption. Client and server,
2843 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002844 //
2845 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2846 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002847 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002848 name: "Basic-Client",
2849 config: Config{
2850 MaxVersion: VersionTLS12,
2851 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002852 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002853 // Ensure session tickets are used, not session IDs.
2854 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002855 })
2856 tests = append(tests, testCase{
2857 name: "Basic-Client-RenewTicket",
2858 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002859 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002860 Bugs: ProtocolBugs{
2861 RenewTicketOnResume: true,
2862 },
2863 },
David Benjaminba4594a2015-06-18 18:36:15 -04002864 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002865 resumeSession: true,
2866 })
2867 tests = append(tests, testCase{
2868 name: "Basic-Client-NoTicket",
2869 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002870 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002871 SessionTicketsDisabled: true,
2872 },
2873 resumeSession: true,
2874 })
2875 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002876 name: "Basic-Client-Implicit",
2877 config: Config{
2878 MaxVersion: VersionTLS12,
2879 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002880 flags: []string{"-implicit-handshake"},
2881 resumeSession: true,
2882 })
2883 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002884 testType: serverTest,
2885 name: "Basic-Server",
2886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002887 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002888 Bugs: ProtocolBugs{
2889 RequireSessionTickets: true,
2890 },
2891 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002892 resumeSession: true,
2893 })
2894 tests = append(tests, testCase{
2895 testType: serverTest,
2896 name: "Basic-Server-NoTickets",
2897 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002898 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002899 SessionTicketsDisabled: true,
2900 },
2901 resumeSession: true,
2902 })
2903 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002904 testType: serverTest,
2905 name: "Basic-Server-Implicit",
2906 config: Config{
2907 MaxVersion: VersionTLS12,
2908 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002909 flags: []string{"-implicit-handshake"},
2910 resumeSession: true,
2911 })
2912 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002913 testType: serverTest,
2914 name: "Basic-Server-EarlyCallback",
2915 config: Config{
2916 MaxVersion: VersionTLS12,
2917 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002918 flags: []string{"-use-early-callback"},
2919 resumeSession: true,
2920 })
2921
2922 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002923 //
2924 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002925 tests = append(tests, testCase{
2926 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002927 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002929 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002930 ClientAuth: RequestClientCert,
2931 },
2932 })
2933 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002934 testType: serverTest,
2935 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002936 config: Config{
2937 MaxVersion: VersionTLS12,
2938 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002939 // Setting SSL_VERIFY_PEER allows anonymous clients.
2940 flags: []string{"-verify-peer"},
2941 })
David Benjamin582ba042016-07-07 12:33:25 -07002942 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002943 tests = append(tests, testCase{
2944 testType: clientTest,
2945 name: "ClientAuth-NoCertificate-Client-SSL3",
2946 config: Config{
2947 MaxVersion: VersionSSL30,
2948 ClientAuth: RequestClientCert,
2949 },
2950 })
2951 tests = append(tests, testCase{
2952 testType: serverTest,
2953 name: "ClientAuth-NoCertificate-Server-SSL3",
2954 config: Config{
2955 MaxVersion: VersionSSL30,
2956 },
2957 // Setting SSL_VERIFY_PEER allows anonymous clients.
2958 flags: []string{"-verify-peer"},
2959 })
2960 }
2961 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002962 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002963 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002965 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002966 ClientAuth: RequireAnyClientCert,
2967 },
2968 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002969 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2970 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002971 },
2972 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002973 tests = append(tests, testCase{
2974 testType: clientTest,
2975 name: "ClientAuth-ECDSA-Client",
2976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002977 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002978 ClientAuth: RequireAnyClientCert,
2979 },
2980 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002981 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2982 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002983 },
2984 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002985 tests = append(tests, testCase{
2986 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04002987 name: "ClientAuth-NoCertificate-OldCallback",
2988 config: Config{
2989 MaxVersion: VersionTLS12,
2990 ClientAuth: RequestClientCert,
2991 },
2992 flags: []string{"-use-old-client-cert-callback"},
2993 })
2994 tests = append(tests, testCase{
2995 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002996 name: "ClientAuth-OldCallback",
2997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002998 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002999 ClientAuth: RequireAnyClientCert,
3000 },
3001 flags: []string{
3002 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3003 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3004 "-use-old-client-cert-callback",
3005 },
3006 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003007 tests = append(tests, testCase{
3008 testType: serverTest,
3009 name: "ClientAuth-Server",
3010 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003011 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003012 Certificates: []Certificate{rsaCertificate},
3013 },
3014 flags: []string{"-require-any-client-certificate"},
3015 })
3016
David Benjamin4c3ddf72016-06-29 18:13:53 -04003017 // Test each key exchange on the server side for async keys.
3018 //
3019 // TODO(davidben): Add TLS 1.3 versions of these.
3020 tests = append(tests, testCase{
3021 testType: serverTest,
3022 name: "Basic-Server-RSA",
3023 config: Config{
3024 MaxVersion: VersionTLS12,
3025 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3026 },
3027 flags: []string{
3028 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3029 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3030 },
3031 })
3032 tests = append(tests, testCase{
3033 testType: serverTest,
3034 name: "Basic-Server-ECDHE-RSA",
3035 config: Config{
3036 MaxVersion: VersionTLS12,
3037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3038 },
3039 flags: []string{
3040 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3041 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3042 },
3043 })
3044 tests = append(tests, testCase{
3045 testType: serverTest,
3046 name: "Basic-Server-ECDHE-ECDSA",
3047 config: Config{
3048 MaxVersion: VersionTLS12,
3049 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3050 },
3051 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003052 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3053 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003054 },
3055 })
3056
David Benjamin760b1dd2015-05-15 23:33:48 -04003057 // No session ticket support; server doesn't send NewSessionTicket.
3058 tests = append(tests, testCase{
3059 name: "SessionTicketsDisabled-Client",
3060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003061 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003062 SessionTicketsDisabled: true,
3063 },
3064 })
3065 tests = append(tests, testCase{
3066 testType: serverTest,
3067 name: "SessionTicketsDisabled-Server",
3068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003069 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003070 SessionTicketsDisabled: true,
3071 },
3072 })
3073
3074 // Skip ServerKeyExchange in PSK key exchange if there's no
3075 // identity hint.
3076 tests = append(tests, testCase{
3077 name: "EmptyPSKHint-Client",
3078 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003079 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003080 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3081 PreSharedKey: []byte("secret"),
3082 },
3083 flags: []string{"-psk", "secret"},
3084 })
3085 tests = append(tests, testCase{
3086 testType: serverTest,
3087 name: "EmptyPSKHint-Server",
3088 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003089 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003090 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3091 PreSharedKey: []byte("secret"),
3092 },
3093 flags: []string{"-psk", "secret"},
3094 })
3095
David Benjamin4c3ddf72016-06-29 18:13:53 -04003096 // OCSP stapling tests.
3097 //
3098 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003099 tests = append(tests, testCase{
3100 testType: clientTest,
3101 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003102 config: Config{
3103 MaxVersion: VersionTLS12,
3104 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003105 flags: []string{
3106 "-enable-ocsp-stapling",
3107 "-expect-ocsp-response",
3108 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003109 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003110 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003111 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003112 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003113 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 testType: serverTest,
3115 name: "OCSPStapling-Server",
3116 config: Config{
3117 MaxVersion: VersionTLS12,
3118 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003119 expectedOCSPResponse: testOCSPResponse,
3120 flags: []string{
3121 "-ocsp-response",
3122 base64.StdEncoding.EncodeToString(testOCSPResponse),
3123 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003124 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003125 })
3126
David Benjamin4c3ddf72016-06-29 18:13:53 -04003127 // Certificate verification tests.
3128 //
3129 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003130 tests = append(tests, testCase{
3131 testType: clientTest,
3132 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003133 config: Config{
3134 MaxVersion: VersionTLS12,
3135 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003136 flags: []string{
3137 "-verify-peer",
3138 },
3139 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003140 tests = append(tests, testCase{
3141 testType: clientTest,
3142 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003143 config: Config{
3144 MaxVersion: VersionTLS12,
3145 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003146 flags: []string{
3147 "-verify-fail",
3148 "-verify-peer",
3149 },
3150 shouldFail: true,
3151 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3152 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003153 tests = append(tests, testCase{
3154 testType: clientTest,
3155 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003156 config: Config{
3157 MaxVersion: VersionTLS12,
3158 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003159 flags: []string{
3160 "-verify-fail",
3161 "-expect-verify-result",
3162 },
3163 })
3164
David Benjamin582ba042016-07-07 12:33:25 -07003165 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003166 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003167 name: "Renegotiate-Client",
3168 config: Config{
3169 MaxVersion: VersionTLS12,
3170 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003171 renegotiate: 1,
3172 flags: []string{
3173 "-renegotiate-freely",
3174 "-expect-total-renegotiations", "1",
3175 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003176 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003177
David Benjamin760b1dd2015-05-15 23:33:48 -04003178 // NPN on client and server; results in post-handshake message.
3179 tests = append(tests, testCase{
3180 name: "NPN-Client",
3181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003182 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003183 NextProtos: []string{"foo"},
3184 },
3185 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003186 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003187 expectedNextProto: "foo",
3188 expectedNextProtoType: npn,
3189 })
3190 tests = append(tests, testCase{
3191 testType: serverTest,
3192 name: "NPN-Server",
3193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003194 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003195 NextProtos: []string{"bar"},
3196 },
3197 flags: []string{
3198 "-advertise-npn", "\x03foo\x03bar\x03baz",
3199 "-expect-next-proto", "bar",
3200 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003201 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003202 expectedNextProto: "bar",
3203 expectedNextProtoType: npn,
3204 })
3205
3206 // TODO(davidben): Add tests for when False Start doesn't trigger.
3207
3208 // Client does False Start and negotiates NPN.
3209 tests = append(tests, testCase{
3210 name: "FalseStart",
3211 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003212 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003213 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3214 NextProtos: []string{"foo"},
3215 Bugs: ProtocolBugs{
3216 ExpectFalseStart: true,
3217 },
3218 },
3219 flags: []string{
3220 "-false-start",
3221 "-select-next-proto", "foo",
3222 },
3223 shimWritesFirst: true,
3224 resumeSession: true,
3225 })
3226
3227 // Client does False Start and negotiates ALPN.
3228 tests = append(tests, testCase{
3229 name: "FalseStart-ALPN",
3230 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003231 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003232 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3233 NextProtos: []string{"foo"},
3234 Bugs: ProtocolBugs{
3235 ExpectFalseStart: true,
3236 },
3237 },
3238 flags: []string{
3239 "-false-start",
3240 "-advertise-alpn", "\x03foo",
3241 },
3242 shimWritesFirst: true,
3243 resumeSession: true,
3244 })
3245
3246 // Client does False Start but doesn't explicitly call
3247 // SSL_connect.
3248 tests = append(tests, testCase{
3249 name: "FalseStart-Implicit",
3250 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003251 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003252 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3253 NextProtos: []string{"foo"},
3254 },
3255 flags: []string{
3256 "-implicit-handshake",
3257 "-false-start",
3258 "-advertise-alpn", "\x03foo",
3259 },
3260 })
3261
3262 // False Start without session tickets.
3263 tests = append(tests, testCase{
3264 name: "FalseStart-SessionTicketsDisabled",
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 SessionTicketsDisabled: true,
3270 Bugs: ProtocolBugs{
3271 ExpectFalseStart: true,
3272 },
3273 },
3274 flags: []string{
3275 "-false-start",
3276 "-select-next-proto", "foo",
3277 },
3278 shimWritesFirst: true,
3279 })
3280
Adam Langleydf759b52016-07-11 15:24:37 -07003281 tests = append(tests, testCase{
3282 name: "FalseStart-CECPQ1",
3283 config: Config{
3284 MaxVersion: VersionTLS12,
3285 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3286 NextProtos: []string{"foo"},
3287 Bugs: ProtocolBugs{
3288 ExpectFalseStart: true,
3289 },
3290 },
3291 flags: []string{
3292 "-false-start",
3293 "-cipher", "DEFAULT:kCECPQ1",
3294 "-select-next-proto", "foo",
3295 },
3296 shimWritesFirst: true,
3297 resumeSession: true,
3298 })
3299
David Benjamin760b1dd2015-05-15 23:33:48 -04003300 // Server parses a V2ClientHello.
3301 tests = append(tests, testCase{
3302 testType: serverTest,
3303 name: "SendV2ClientHello",
3304 config: Config{
3305 // Choose a cipher suite that does not involve
3306 // elliptic curves, so no extensions are
3307 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003308 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003309 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3310 Bugs: ProtocolBugs{
3311 SendV2ClientHello: true,
3312 },
3313 },
3314 })
3315
3316 // Client sends a Channel ID.
3317 tests = append(tests, testCase{
3318 name: "ChannelID-Client",
3319 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003320 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003321 RequestChannelID: true,
3322 },
Adam Langley7c803a62015-06-15 15:35:05 -07003323 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003324 resumeSession: true,
3325 expectChannelID: true,
3326 })
3327
3328 // Server accepts a Channel ID.
3329 tests = append(tests, testCase{
3330 testType: serverTest,
3331 name: "ChannelID-Server",
3332 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003333 MaxVersion: VersionTLS12,
3334 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003335 },
3336 flags: []string{
3337 "-expect-channel-id",
3338 base64.StdEncoding.EncodeToString(channelIDBytes),
3339 },
3340 resumeSession: true,
3341 expectChannelID: true,
3342 })
David Benjamin30789da2015-08-29 22:56:45 -04003343
David Benjaminf8fcdf32016-06-08 15:56:13 -04003344 // Channel ID and NPN at the same time, to ensure their relative
3345 // ordering is correct.
3346 tests = append(tests, testCase{
3347 name: "ChannelID-NPN-Client",
3348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003349 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003350 RequestChannelID: true,
3351 NextProtos: []string{"foo"},
3352 },
3353 flags: []string{
3354 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3355 "-select-next-proto", "foo",
3356 },
3357 resumeSession: true,
3358 expectChannelID: true,
3359 expectedNextProto: "foo",
3360 expectedNextProtoType: npn,
3361 })
3362 tests = append(tests, testCase{
3363 testType: serverTest,
3364 name: "ChannelID-NPN-Server",
3365 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003366 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003367 ChannelID: channelIDKey,
3368 NextProtos: []string{"bar"},
3369 },
3370 flags: []string{
3371 "-expect-channel-id",
3372 base64.StdEncoding.EncodeToString(channelIDBytes),
3373 "-advertise-npn", "\x03foo\x03bar\x03baz",
3374 "-expect-next-proto", "bar",
3375 },
3376 resumeSession: true,
3377 expectChannelID: true,
3378 expectedNextProto: "bar",
3379 expectedNextProtoType: npn,
3380 })
3381
David Benjamin30789da2015-08-29 22:56:45 -04003382 // Bidirectional shutdown with the runner initiating.
3383 tests = append(tests, testCase{
3384 name: "Shutdown-Runner",
3385 config: Config{
3386 Bugs: ProtocolBugs{
3387 ExpectCloseNotify: true,
3388 },
3389 },
3390 flags: []string{"-check-close-notify"},
3391 })
3392
3393 // Bidirectional shutdown with the shim initiating. The runner,
3394 // in the meantime, sends garbage before the close_notify which
3395 // the shim must ignore.
3396 tests = append(tests, testCase{
3397 name: "Shutdown-Shim",
3398 config: Config{
3399 Bugs: ProtocolBugs{
3400 ExpectCloseNotify: true,
3401 },
3402 },
3403 shimShutsDown: true,
3404 sendEmptyRecords: 1,
3405 sendWarningAlerts: 1,
3406 flags: []string{"-check-close-notify"},
3407 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003408 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003409 // TODO(davidben): DTLS 1.3 will want a similar thing for
3410 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003411 tests = append(tests, testCase{
3412 name: "SkipHelloVerifyRequest",
3413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003414 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003415 Bugs: ProtocolBugs{
3416 SkipHelloVerifyRequest: true,
3417 },
3418 },
3419 })
3420 }
3421
David Benjamin760b1dd2015-05-15 23:33:48 -04003422 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003423 test.protocol = config.protocol
3424 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003425 test.name += "-DTLS"
3426 }
David Benjamin582ba042016-07-07 12:33:25 -07003427 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003428 test.name += "-Async"
3429 test.flags = append(test.flags, "-async")
3430 } else {
3431 test.name += "-Sync"
3432 }
David Benjamin582ba042016-07-07 12:33:25 -07003433 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003434 test.name += "-SplitHandshakeRecords"
3435 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003436 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003437 test.config.Bugs.MaxPacketLength = 256
3438 test.flags = append(test.flags, "-mtu", "256")
3439 }
3440 }
David Benjamin582ba042016-07-07 12:33:25 -07003441 if config.packHandshakeFlight {
3442 test.name += "-PackHandshakeFlight"
3443 test.config.Bugs.PackHandshakeFlight = true
3444 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003445 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003446 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003447}
3448
Adam Langley524e7172015-02-20 16:04:00 -08003449func addDDoSCallbackTests() {
3450 // DDoS callback.
3451
3452 for _, resume := range []bool{false, true} {
3453 suffix := "Resume"
3454 if resume {
3455 suffix = "No" + suffix
3456 }
3457
David Benjamin4c3ddf72016-06-29 18:13:53 -04003458 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3459
Adam Langley524e7172015-02-20 16:04:00 -08003460 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003461 testType: serverTest,
3462 name: "Server-DDoS-OK-" + suffix,
3463 config: Config{
3464 MaxVersion: VersionTLS12,
3465 },
Adam Langley524e7172015-02-20 16:04:00 -08003466 flags: []string{"-install-ddos-callback"},
3467 resumeSession: resume,
3468 })
3469
3470 failFlag := "-fail-ddos-callback"
3471 if resume {
3472 failFlag = "-fail-second-ddos-callback"
3473 }
3474 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003475 testType: serverTest,
3476 name: "Server-DDoS-Reject-" + suffix,
3477 config: Config{
3478 MaxVersion: VersionTLS12,
3479 },
Adam Langley524e7172015-02-20 16:04:00 -08003480 flags: []string{"-install-ddos-callback", failFlag},
3481 resumeSession: resume,
3482 shouldFail: true,
3483 expectedError: ":CONNECTION_REJECTED:",
3484 })
3485 }
3486}
3487
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003488func addVersionNegotiationTests() {
3489 for i, shimVers := range tlsVersions {
3490 // Assemble flags to disable all newer versions on the shim.
3491 var flags []string
3492 for _, vers := range tlsVersions[i+1:] {
3493 flags = append(flags, vers.flag)
3494 }
3495
3496 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003497 protocols := []protocol{tls}
3498 if runnerVers.hasDTLS && shimVers.hasDTLS {
3499 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003500 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003501 for _, protocol := range protocols {
3502 expectedVersion := shimVers.version
3503 if runnerVers.version < shimVers.version {
3504 expectedVersion = runnerVers.version
3505 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003506
David Benjamin8b8c0062014-11-23 02:47:52 -05003507 suffix := shimVers.name + "-" + runnerVers.name
3508 if protocol == dtls {
3509 suffix += "-DTLS"
3510 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003511
David Benjamin1eb367c2014-12-12 18:17:51 -05003512 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3513
David Benjamin1e29a6b2014-12-10 02:27:24 -05003514 clientVers := shimVers.version
3515 if clientVers > VersionTLS10 {
3516 clientVers = VersionTLS10
3517 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003518 serverVers := expectedVersion
3519 if expectedVersion >= VersionTLS13 {
3520 serverVers = VersionTLS10
3521 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003522 testCases = append(testCases, testCase{
3523 protocol: protocol,
3524 testType: clientTest,
3525 name: "VersionNegotiation-Client-" + suffix,
3526 config: Config{
3527 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003528 Bugs: ProtocolBugs{
3529 ExpectInitialRecordVersion: clientVers,
3530 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003531 },
3532 flags: flags,
3533 expectedVersion: expectedVersion,
3534 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003535 testCases = append(testCases, testCase{
3536 protocol: protocol,
3537 testType: clientTest,
3538 name: "VersionNegotiation-Client2-" + suffix,
3539 config: Config{
3540 MaxVersion: runnerVers.version,
3541 Bugs: ProtocolBugs{
3542 ExpectInitialRecordVersion: clientVers,
3543 },
3544 },
3545 flags: []string{"-max-version", shimVersFlag},
3546 expectedVersion: expectedVersion,
3547 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003548
3549 testCases = append(testCases, testCase{
3550 protocol: protocol,
3551 testType: serverTest,
3552 name: "VersionNegotiation-Server-" + suffix,
3553 config: Config{
3554 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003555 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003556 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003557 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003558 },
3559 flags: flags,
3560 expectedVersion: expectedVersion,
3561 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003562 testCases = append(testCases, testCase{
3563 protocol: protocol,
3564 testType: serverTest,
3565 name: "VersionNegotiation-Server2-" + suffix,
3566 config: Config{
3567 MaxVersion: runnerVers.version,
3568 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003569 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003570 },
3571 },
3572 flags: []string{"-max-version", shimVersFlag},
3573 expectedVersion: expectedVersion,
3574 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003575 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003576 }
3577 }
David Benjamin95c69562016-06-29 18:15:03 -04003578
3579 // Test for version tolerance.
3580 testCases = append(testCases, testCase{
3581 testType: serverTest,
3582 name: "MinorVersionTolerance",
3583 config: Config{
3584 Bugs: ProtocolBugs{
3585 SendClientVersion: 0x03ff,
3586 },
3587 },
3588 expectedVersion: VersionTLS13,
3589 })
3590 testCases = append(testCases, testCase{
3591 testType: serverTest,
3592 name: "MajorVersionTolerance",
3593 config: Config{
3594 Bugs: ProtocolBugs{
3595 SendClientVersion: 0x0400,
3596 },
3597 },
3598 expectedVersion: VersionTLS13,
3599 })
3600 testCases = append(testCases, testCase{
3601 protocol: dtls,
3602 testType: serverTest,
3603 name: "MinorVersionTolerance-DTLS",
3604 config: Config{
3605 Bugs: ProtocolBugs{
3606 SendClientVersion: 0x03ff,
3607 },
3608 },
3609 expectedVersion: VersionTLS12,
3610 })
3611 testCases = append(testCases, testCase{
3612 protocol: dtls,
3613 testType: serverTest,
3614 name: "MajorVersionTolerance-DTLS",
3615 config: Config{
3616 Bugs: ProtocolBugs{
3617 SendClientVersion: 0x0400,
3618 },
3619 },
3620 expectedVersion: VersionTLS12,
3621 })
3622
3623 // Test that versions below 3.0 are rejected.
3624 testCases = append(testCases, testCase{
3625 testType: serverTest,
3626 name: "VersionTooLow",
3627 config: Config{
3628 Bugs: ProtocolBugs{
3629 SendClientVersion: 0x0200,
3630 },
3631 },
3632 shouldFail: true,
3633 expectedError: ":UNSUPPORTED_PROTOCOL:",
3634 })
3635 testCases = append(testCases, testCase{
3636 protocol: dtls,
3637 testType: serverTest,
3638 name: "VersionTooLow-DTLS",
3639 config: Config{
3640 Bugs: ProtocolBugs{
3641 // 0x0201 is the lowest version expressable in
3642 // DTLS.
3643 SendClientVersion: 0x0201,
3644 },
3645 },
3646 shouldFail: true,
3647 expectedError: ":UNSUPPORTED_PROTOCOL:",
3648 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003649
3650 // Test TLS 1.3's downgrade signal.
3651 testCases = append(testCases, testCase{
3652 name: "Downgrade-TLS12-Client",
3653 config: Config{
3654 Bugs: ProtocolBugs{
3655 NegotiateVersion: VersionTLS12,
3656 },
3657 },
3658 shouldFail: true,
3659 expectedError: ":DOWNGRADE_DETECTED:",
3660 })
3661 testCases = append(testCases, testCase{
3662 testType: serverTest,
3663 name: "Downgrade-TLS12-Server",
3664 config: Config{
3665 Bugs: ProtocolBugs{
3666 SendClientVersion: VersionTLS12,
3667 },
3668 },
3669 shouldFail: true,
3670 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3671 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003672}
3673
David Benjaminaccb4542014-12-12 23:44:33 -05003674func addMinimumVersionTests() {
3675 for i, shimVers := range tlsVersions {
3676 // Assemble flags to disable all older versions on the shim.
3677 var flags []string
3678 for _, vers := range tlsVersions[:i] {
3679 flags = append(flags, vers.flag)
3680 }
3681
3682 for _, runnerVers := range tlsVersions {
3683 protocols := []protocol{tls}
3684 if runnerVers.hasDTLS && shimVers.hasDTLS {
3685 protocols = append(protocols, dtls)
3686 }
3687 for _, protocol := range protocols {
3688 suffix := shimVers.name + "-" + runnerVers.name
3689 if protocol == dtls {
3690 suffix += "-DTLS"
3691 }
3692 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3693
David Benjaminaccb4542014-12-12 23:44:33 -05003694 var expectedVersion uint16
3695 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003696 var expectedClientError, expectedServerError string
3697 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003698 if runnerVers.version >= shimVers.version {
3699 expectedVersion = runnerVers.version
3700 } else {
3701 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003702 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3703 expectedServerLocalError = "remote error: protocol version not supported"
3704 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3705 // If the client's minimum version is TLS 1.3 and the runner's
3706 // maximum is below TLS 1.2, the runner will fail to select a
3707 // cipher before the shim rejects the selected version.
3708 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3709 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3710 } else {
3711 expectedClientError = expectedServerError
3712 expectedClientLocalError = expectedServerLocalError
3713 }
David Benjaminaccb4542014-12-12 23:44:33 -05003714 }
3715
3716 testCases = append(testCases, testCase{
3717 protocol: protocol,
3718 testType: clientTest,
3719 name: "MinimumVersion-Client-" + suffix,
3720 config: Config{
3721 MaxVersion: runnerVers.version,
3722 },
David Benjamin87909c02014-12-13 01:55:01 -05003723 flags: flags,
3724 expectedVersion: expectedVersion,
3725 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003726 expectedError: expectedClientError,
3727 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003728 })
3729 testCases = append(testCases, testCase{
3730 protocol: protocol,
3731 testType: clientTest,
3732 name: "MinimumVersion-Client2-" + suffix,
3733 config: Config{
3734 MaxVersion: runnerVers.version,
3735 },
David Benjamin87909c02014-12-13 01:55:01 -05003736 flags: []string{"-min-version", shimVersFlag},
3737 expectedVersion: expectedVersion,
3738 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003739 expectedError: expectedClientError,
3740 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003741 })
3742
3743 testCases = append(testCases, testCase{
3744 protocol: protocol,
3745 testType: serverTest,
3746 name: "MinimumVersion-Server-" + suffix,
3747 config: Config{
3748 MaxVersion: runnerVers.version,
3749 },
David Benjamin87909c02014-12-13 01:55:01 -05003750 flags: flags,
3751 expectedVersion: expectedVersion,
3752 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003753 expectedError: expectedServerError,
3754 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003755 })
3756 testCases = append(testCases, testCase{
3757 protocol: protocol,
3758 testType: serverTest,
3759 name: "MinimumVersion-Server2-" + suffix,
3760 config: Config{
3761 MaxVersion: runnerVers.version,
3762 },
David Benjamin87909c02014-12-13 01:55:01 -05003763 flags: []string{"-min-version", shimVersFlag},
3764 expectedVersion: expectedVersion,
3765 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003766 expectedError: expectedServerError,
3767 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003768 })
3769 }
3770 }
3771 }
3772}
3773
David Benjamine78bfde2014-09-06 12:45:15 -04003774func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003775 // TODO(davidben): Extensions, where applicable, all move their server
3776 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3777 // tests for both. Also test interaction with 0-RTT when implemented.
3778
David Benjamine78bfde2014-09-06 12:45:15 -04003779 testCases = append(testCases, testCase{
3780 testType: clientTest,
3781 name: "DuplicateExtensionClient",
3782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003784 Bugs: ProtocolBugs{
3785 DuplicateExtension: true,
3786 },
3787 },
3788 shouldFail: true,
3789 expectedLocalError: "remote error: error decoding message",
3790 })
3791 testCases = append(testCases, testCase{
3792 testType: serverTest,
3793 name: "DuplicateExtensionServer",
3794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003795 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003796 Bugs: ProtocolBugs{
3797 DuplicateExtension: true,
3798 },
3799 },
3800 shouldFail: true,
3801 expectedLocalError: "remote error: error decoding message",
3802 })
3803 testCases = append(testCases, testCase{
3804 testType: clientTest,
3805 name: "ServerNameExtensionClient",
3806 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003807 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003808 Bugs: ProtocolBugs{
3809 ExpectServerName: "example.com",
3810 },
3811 },
3812 flags: []string{"-host-name", "example.com"},
3813 })
3814 testCases = append(testCases, testCase{
3815 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003816 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003817 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003818 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003819 Bugs: ProtocolBugs{
3820 ExpectServerName: "mismatch.com",
3821 },
3822 },
3823 flags: []string{"-host-name", "example.com"},
3824 shouldFail: true,
3825 expectedLocalError: "tls: unexpected server name",
3826 })
3827 testCases = append(testCases, testCase{
3828 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003829 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003831 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003832 Bugs: ProtocolBugs{
3833 ExpectServerName: "missing.com",
3834 },
3835 },
3836 shouldFail: true,
3837 expectedLocalError: "tls: unexpected server name",
3838 })
3839 testCases = append(testCases, testCase{
3840 testType: serverTest,
3841 name: "ServerNameExtensionServer",
3842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003843 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003844 ServerName: "example.com",
3845 },
3846 flags: []string{"-expect-server-name", "example.com"},
3847 resumeSession: true,
3848 })
David Benjaminae2888f2014-09-06 12:58:58 -04003849 testCases = append(testCases, testCase{
3850 testType: clientTest,
3851 name: "ALPNClient",
3852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003853 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003854 NextProtos: []string{"foo"},
3855 },
3856 flags: []string{
3857 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3858 "-expect-alpn", "foo",
3859 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003860 expectedNextProto: "foo",
3861 expectedNextProtoType: alpn,
3862 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003863 })
3864 testCases = append(testCases, testCase{
3865 testType: serverTest,
3866 name: "ALPNServer",
3867 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003868 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003869 NextProtos: []string{"foo", "bar", "baz"},
3870 },
3871 flags: []string{
3872 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3873 "-select-alpn", "foo",
3874 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003875 expectedNextProto: "foo",
3876 expectedNextProtoType: alpn,
3877 resumeSession: true,
3878 })
David Benjamin594e7d22016-03-17 17:49:56 -04003879 testCases = append(testCases, testCase{
3880 testType: serverTest,
3881 name: "ALPNServer-Decline",
3882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003884 NextProtos: []string{"foo", "bar", "baz"},
3885 },
3886 flags: []string{"-decline-alpn"},
3887 expectNoNextProto: true,
3888 resumeSession: true,
3889 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003890 // Test that the server prefers ALPN over NPN.
3891 testCases = append(testCases, testCase{
3892 testType: serverTest,
3893 name: "ALPNServer-Preferred",
3894 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003895 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003896 NextProtos: []string{"foo", "bar", "baz"},
3897 },
3898 flags: []string{
3899 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3900 "-select-alpn", "foo",
3901 "-advertise-npn", "\x03foo\x03bar\x03baz",
3902 },
3903 expectedNextProto: "foo",
3904 expectedNextProtoType: alpn,
3905 resumeSession: true,
3906 })
3907 testCases = append(testCases, testCase{
3908 testType: serverTest,
3909 name: "ALPNServer-Preferred-Swapped",
3910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003911 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003912 NextProtos: []string{"foo", "bar", "baz"},
3913 Bugs: ProtocolBugs{
3914 SwapNPNAndALPN: true,
3915 },
3916 },
3917 flags: []string{
3918 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3919 "-select-alpn", "foo",
3920 "-advertise-npn", "\x03foo\x03bar\x03baz",
3921 },
3922 expectedNextProto: "foo",
3923 expectedNextProtoType: alpn,
3924 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003925 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003926 var emptyString string
3927 testCases = append(testCases, testCase{
3928 testType: clientTest,
3929 name: "ALPNClient-EmptyProtocolName",
3930 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003931 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003932 NextProtos: []string{""},
3933 Bugs: ProtocolBugs{
3934 // A server returning an empty ALPN protocol
3935 // should be rejected.
3936 ALPNProtocol: &emptyString,
3937 },
3938 },
3939 flags: []string{
3940 "-advertise-alpn", "\x03foo",
3941 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003942 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003943 expectedError: ":PARSE_TLSEXT:",
3944 })
3945 testCases = append(testCases, testCase{
3946 testType: serverTest,
3947 name: "ALPNServer-EmptyProtocolName",
3948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003949 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003950 // A ClientHello containing an empty ALPN protocol
3951 // should be rejected.
3952 NextProtos: []string{"foo", "", "baz"},
3953 },
3954 flags: []string{
3955 "-select-alpn", "foo",
3956 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003957 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003958 expectedError: ":PARSE_TLSEXT:",
3959 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003960 // Test that negotiating both NPN and ALPN is forbidden.
3961 testCases = append(testCases, testCase{
3962 name: "NegotiateALPNAndNPN",
3963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003965 NextProtos: []string{"foo", "bar", "baz"},
3966 Bugs: ProtocolBugs{
3967 NegotiateALPNAndNPN: true,
3968 },
3969 },
3970 flags: []string{
3971 "-advertise-alpn", "\x03foo",
3972 "-select-next-proto", "foo",
3973 },
3974 shouldFail: true,
3975 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3976 })
3977 testCases = append(testCases, testCase{
3978 name: "NegotiateALPNAndNPN-Swapped",
3979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003980 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003981 NextProtos: []string{"foo", "bar", "baz"},
3982 Bugs: ProtocolBugs{
3983 NegotiateALPNAndNPN: true,
3984 SwapNPNAndALPN: true,
3985 },
3986 },
3987 flags: []string{
3988 "-advertise-alpn", "\x03foo",
3989 "-select-next-proto", "foo",
3990 },
3991 shouldFail: true,
3992 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3993 })
David Benjamin091c4b92015-10-26 13:33:21 -04003994 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3995 testCases = append(testCases, testCase{
3996 name: "DisableNPN",
3997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003998 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04003999 NextProtos: []string{"foo"},
4000 },
4001 flags: []string{
4002 "-select-next-proto", "foo",
4003 "-disable-npn",
4004 },
4005 expectNoNextProto: true,
4006 })
Adam Langley38311732014-10-16 19:04:35 -07004007 // Resume with a corrupt ticket.
4008 testCases = append(testCases, testCase{
4009 testType: serverTest,
4010 name: "CorruptTicket",
4011 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004012 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004013 Bugs: ProtocolBugs{
4014 CorruptTicket: true,
4015 },
4016 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004017 resumeSession: true,
4018 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07004019 })
David Benjamind98452d2015-06-16 14:16:23 -04004020 // Test the ticket callback, with and without renewal.
4021 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004022 testType: serverTest,
4023 name: "TicketCallback",
4024 config: Config{
4025 MaxVersion: VersionTLS12,
4026 },
David Benjamind98452d2015-06-16 14:16:23 -04004027 resumeSession: true,
4028 flags: []string{"-use-ticket-callback"},
4029 })
4030 testCases = append(testCases, testCase{
4031 testType: serverTest,
4032 name: "TicketCallback-Renew",
4033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004034 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004035 Bugs: ProtocolBugs{
4036 ExpectNewTicket: true,
4037 },
4038 },
4039 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4040 resumeSession: true,
4041 })
Adam Langley38311732014-10-16 19:04:35 -07004042 // Resume with an oversized session id.
4043 testCases = append(testCases, testCase{
4044 testType: serverTest,
4045 name: "OversizedSessionId",
4046 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004047 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004048 Bugs: ProtocolBugs{
4049 OversizedSessionId: true,
4050 },
4051 },
4052 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004053 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004054 expectedError: ":DECODE_ERROR:",
4055 })
David Benjaminca6c8262014-11-15 19:06:08 -05004056 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4057 // are ignored.
4058 testCases = append(testCases, testCase{
4059 protocol: dtls,
4060 name: "SRTP-Client",
4061 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004062 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004063 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4064 },
4065 flags: []string{
4066 "-srtp-profiles",
4067 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4068 },
4069 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4070 })
4071 testCases = append(testCases, testCase{
4072 protocol: dtls,
4073 testType: serverTest,
4074 name: "SRTP-Server",
4075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004076 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004077 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4078 },
4079 flags: []string{
4080 "-srtp-profiles",
4081 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4082 },
4083 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4084 })
4085 // Test that the MKI is ignored.
4086 testCases = append(testCases, testCase{
4087 protocol: dtls,
4088 testType: serverTest,
4089 name: "SRTP-Server-IgnoreMKI",
4090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004091 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004092 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4093 Bugs: ProtocolBugs{
4094 SRTPMasterKeyIdentifer: "bogus",
4095 },
4096 },
4097 flags: []string{
4098 "-srtp-profiles",
4099 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4100 },
4101 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4102 })
4103 // Test that SRTP isn't negotiated on the server if there were
4104 // no matching profiles.
4105 testCases = append(testCases, testCase{
4106 protocol: dtls,
4107 testType: serverTest,
4108 name: "SRTP-Server-NoMatch",
4109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004110 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004111 SRTPProtectionProfiles: []uint16{100, 101, 102},
4112 },
4113 flags: []string{
4114 "-srtp-profiles",
4115 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4116 },
4117 expectedSRTPProtectionProfile: 0,
4118 })
4119 // Test that the server returning an invalid SRTP profile is
4120 // flagged as an error by the client.
4121 testCases = append(testCases, testCase{
4122 protocol: dtls,
4123 name: "SRTP-Client-NoMatch",
4124 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004125 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004126 Bugs: ProtocolBugs{
4127 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4128 },
4129 },
4130 flags: []string{
4131 "-srtp-profiles",
4132 "SRTP_AES128_CM_SHA1_80",
4133 },
4134 shouldFail: true,
4135 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4136 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004137 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004138 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004139 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004140 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004141 config: Config{
4142 MaxVersion: VersionTLS12,
4143 },
David Benjamin61f95272014-11-25 01:55:35 -05004144 flags: []string{
4145 "-enable-signed-cert-timestamps",
4146 "-expect-signed-cert-timestamps",
4147 base64.StdEncoding.EncodeToString(testSCTList),
4148 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004149 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004150 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004151 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004152 name: "SendSCTListOnResume",
4153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004154 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004155 Bugs: ProtocolBugs{
4156 SendSCTListOnResume: []byte("bogus"),
4157 },
4158 },
4159 flags: []string{
4160 "-enable-signed-cert-timestamps",
4161 "-expect-signed-cert-timestamps",
4162 base64.StdEncoding.EncodeToString(testSCTList),
4163 },
4164 resumeSession: true,
4165 })
4166 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004167 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004168 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004169 config: Config{
4170 MaxVersion: VersionTLS12,
4171 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004172 flags: []string{
4173 "-signed-cert-timestamps",
4174 base64.StdEncoding.EncodeToString(testSCTList),
4175 },
4176 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004177 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004178 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004179
Paul Lietar4fac72e2015-09-09 13:44:55 +01004180 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004181 testType: clientTest,
4182 name: "ClientHelloPadding",
4183 config: Config{
4184 Bugs: ProtocolBugs{
4185 RequireClientHelloSize: 512,
4186 },
4187 },
4188 // This hostname just needs to be long enough to push the
4189 // ClientHello into F5's danger zone between 256 and 511 bytes
4190 // long.
4191 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4192 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004193
4194 // Extensions should not function in SSL 3.0.
4195 testCases = append(testCases, testCase{
4196 testType: serverTest,
4197 name: "SSLv3Extensions-NoALPN",
4198 config: Config{
4199 MaxVersion: VersionSSL30,
4200 NextProtos: []string{"foo", "bar", "baz"},
4201 },
4202 flags: []string{
4203 "-select-alpn", "foo",
4204 },
4205 expectNoNextProto: true,
4206 })
4207
4208 // Test session tickets separately as they follow a different codepath.
4209 testCases = append(testCases, testCase{
4210 testType: serverTest,
4211 name: "SSLv3Extensions-NoTickets",
4212 config: Config{
4213 MaxVersion: VersionSSL30,
4214 Bugs: ProtocolBugs{
4215 // Historically, session tickets in SSL 3.0
4216 // failed in different ways depending on whether
4217 // the client supported renegotiation_info.
4218 NoRenegotiationInfo: true,
4219 },
4220 },
4221 resumeSession: true,
4222 })
4223 testCases = append(testCases, testCase{
4224 testType: serverTest,
4225 name: "SSLv3Extensions-NoTickets2",
4226 config: Config{
4227 MaxVersion: VersionSSL30,
4228 },
4229 resumeSession: true,
4230 })
4231
4232 // But SSL 3.0 does send and process renegotiation_info.
4233 testCases = append(testCases, testCase{
4234 testType: serverTest,
4235 name: "SSLv3Extensions-RenegotiationInfo",
4236 config: Config{
4237 MaxVersion: VersionSSL30,
4238 Bugs: ProtocolBugs{
4239 RequireRenegotiationInfo: true,
4240 },
4241 },
4242 })
4243 testCases = append(testCases, testCase{
4244 testType: serverTest,
4245 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4246 config: Config{
4247 MaxVersion: VersionSSL30,
4248 Bugs: ProtocolBugs{
4249 NoRenegotiationInfo: true,
4250 SendRenegotiationSCSV: true,
4251 RequireRenegotiationInfo: true,
4252 },
4253 },
4254 })
David Benjamine78bfde2014-09-06 12:45:15 -04004255}
4256
David Benjamin01fe8202014-09-24 15:21:44 -04004257func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004258 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004259 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004260 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4261 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4262 // TLS 1.3 only shares ciphers with TLS 1.2, so
4263 // we skip certain combinations and use a
4264 // different cipher to test with.
4265 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4266 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4267 continue
4268 }
4269 }
4270
David Benjamin8b8c0062014-11-23 02:47:52 -05004271 protocols := []protocol{tls}
4272 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4273 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004274 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004275 for _, protocol := range protocols {
4276 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4277 if protocol == dtls {
4278 suffix += "-DTLS"
4279 }
4280
David Benjaminece3de92015-03-16 18:02:20 -04004281 if sessionVers.version == resumeVers.version {
4282 testCases = append(testCases, testCase{
4283 protocol: protocol,
4284 name: "Resume-Client" + suffix,
4285 resumeSession: true,
4286 config: Config{
4287 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004288 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004289 },
David Benjaminece3de92015-03-16 18:02:20 -04004290 expectedVersion: sessionVers.version,
4291 expectedResumeVersion: resumeVers.version,
4292 })
4293 } else {
4294 testCases = append(testCases, testCase{
4295 protocol: protocol,
4296 name: "Resume-Client-Mismatch" + suffix,
4297 resumeSession: true,
4298 config: Config{
4299 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004300 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004301 },
David Benjaminece3de92015-03-16 18:02:20 -04004302 expectedVersion: sessionVers.version,
4303 resumeConfig: &Config{
4304 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004305 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004306 Bugs: ProtocolBugs{
4307 AllowSessionVersionMismatch: true,
4308 },
4309 },
4310 expectedResumeVersion: resumeVers.version,
4311 shouldFail: true,
4312 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4313 })
4314 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004315
4316 testCases = append(testCases, testCase{
4317 protocol: protocol,
4318 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004319 resumeSession: true,
4320 config: Config{
4321 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004322 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004323 },
4324 expectedVersion: sessionVers.version,
4325 resumeConfig: &Config{
4326 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004327 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004328 },
4329 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004330 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004331 expectedResumeVersion: resumeVers.version,
4332 })
4333
David Benjamin8b8c0062014-11-23 02:47:52 -05004334 testCases = append(testCases, testCase{
4335 protocol: protocol,
4336 testType: serverTest,
4337 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004338 resumeSession: true,
4339 config: Config{
4340 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004341 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004342 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004343 expectedVersion: sessionVers.version,
4344 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004345 resumeConfig: &Config{
4346 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004347 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004348 },
4349 expectedResumeVersion: resumeVers.version,
4350 })
4351 }
David Benjamin01fe8202014-09-24 15:21:44 -04004352 }
4353 }
David Benjaminece3de92015-03-16 18:02:20 -04004354
Nick Harper1fd39d82016-06-14 18:14:35 -07004355 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004356 testCases = append(testCases, testCase{
4357 name: "Resume-Client-CipherMismatch",
4358 resumeSession: true,
4359 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004360 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004361 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4362 },
4363 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004364 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004365 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4366 Bugs: ProtocolBugs{
4367 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4368 },
4369 },
4370 shouldFail: true,
4371 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4372 })
David Benjamin01fe8202014-09-24 15:21:44 -04004373}
4374
Adam Langley2ae77d22014-10-28 17:29:33 -07004375func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004376 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004377 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004378 testType: serverTest,
4379 name: "Renegotiate-Server-Forbidden",
4380 config: Config{
4381 MaxVersion: VersionTLS12,
4382 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004383 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004384 shouldFail: true,
4385 expectedError: ":NO_RENEGOTIATION:",
4386 expectedLocalError: "remote error: no renegotiation",
4387 })
Adam Langley5021b222015-06-12 18:27:58 -07004388 // The server shouldn't echo the renegotiation extension unless
4389 // requested by the client.
4390 testCases = append(testCases, testCase{
4391 testType: serverTest,
4392 name: "Renegotiate-Server-NoExt",
4393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004394 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004395 Bugs: ProtocolBugs{
4396 NoRenegotiationInfo: true,
4397 RequireRenegotiationInfo: true,
4398 },
4399 },
4400 shouldFail: true,
4401 expectedLocalError: "renegotiation extension missing",
4402 })
4403 // The renegotiation SCSV should be sufficient for the server to echo
4404 // the extension.
4405 testCases = append(testCases, testCase{
4406 testType: serverTest,
4407 name: "Renegotiate-Server-NoExt-SCSV",
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 SendRenegotiationSCSV: true,
4413 RequireRenegotiationInfo: true,
4414 },
4415 },
4416 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004417 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004418 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004420 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004421 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004422 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004423 },
4424 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004425 renegotiate: 1,
4426 flags: []string{
4427 "-renegotiate-freely",
4428 "-expect-total-renegotiations", "1",
4429 },
David Benjamincdea40c2015-03-19 14:09:43 -04004430 })
4431 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004432 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004433 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004435 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004436 Bugs: ProtocolBugs{
4437 EmptyRenegotiationInfo: true,
4438 },
4439 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004440 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004441 shouldFail: true,
4442 expectedError: ":RENEGOTIATION_MISMATCH:",
4443 })
4444 testCases = append(testCases, testCase{
4445 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004446 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004448 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004449 Bugs: ProtocolBugs{
4450 BadRenegotiationInfo: true,
4451 },
4452 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004453 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004454 shouldFail: true,
4455 expectedError: ":RENEGOTIATION_MISMATCH:",
4456 })
4457 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004458 name: "Renegotiate-Client-Downgrade",
4459 renegotiate: 1,
4460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004461 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004462 Bugs: ProtocolBugs{
4463 NoRenegotiationInfoAfterInitial: true,
4464 },
4465 },
4466 flags: []string{"-renegotiate-freely"},
4467 shouldFail: true,
4468 expectedError: ":RENEGOTIATION_MISMATCH:",
4469 })
4470 testCases = append(testCases, testCase{
4471 name: "Renegotiate-Client-Upgrade",
4472 renegotiate: 1,
4473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004474 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004475 Bugs: ProtocolBugs{
4476 NoRenegotiationInfoInInitial: true,
4477 },
4478 },
4479 flags: []string{"-renegotiate-freely"},
4480 shouldFail: true,
4481 expectedError: ":RENEGOTIATION_MISMATCH:",
4482 })
4483 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004484 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004485 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004486 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004487 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004488 Bugs: ProtocolBugs{
4489 NoRenegotiationInfo: true,
4490 },
4491 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004492 flags: []string{
4493 "-renegotiate-freely",
4494 "-expect-total-renegotiations", "1",
4495 },
David Benjamincff0b902015-05-15 23:09:47 -04004496 })
4497 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004498 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004499 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004500 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004501 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004502 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4503 },
4504 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004505 flags: []string{
4506 "-renegotiate-freely",
4507 "-expect-total-renegotiations", "1",
4508 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004509 })
4510 testCases = append(testCases, testCase{
4511 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004512 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004513 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004514 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004515 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4516 },
4517 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004518 flags: []string{
4519 "-renegotiate-freely",
4520 "-expect-total-renegotiations", "1",
4521 },
David Benjaminb16346b2015-04-08 19:16:58 -04004522 })
4523 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004524 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004525 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004526 config: Config{
4527 MaxVersion: VersionTLS10,
4528 Bugs: ProtocolBugs{
4529 RequireSameRenegoClientVersion: true,
4530 },
4531 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004532 flags: []string{
4533 "-renegotiate-freely",
4534 "-expect-total-renegotiations", "1",
4535 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004536 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004537 testCases = append(testCases, testCase{
4538 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004539 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004540 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004541 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004542 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4543 NextProtos: []string{"foo"},
4544 },
4545 flags: []string{
4546 "-false-start",
4547 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004548 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004549 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004550 },
4551 shimWritesFirst: true,
4552 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004553
4554 // Client-side renegotiation controls.
4555 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004556 name: "Renegotiate-Client-Forbidden-1",
4557 config: Config{
4558 MaxVersion: VersionTLS12,
4559 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004560 renegotiate: 1,
4561 shouldFail: true,
4562 expectedError: ":NO_RENEGOTIATION:",
4563 expectedLocalError: "remote error: no renegotiation",
4564 })
4565 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004566 name: "Renegotiate-Client-Once-1",
4567 config: Config{
4568 MaxVersion: VersionTLS12,
4569 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004570 renegotiate: 1,
4571 flags: []string{
4572 "-renegotiate-once",
4573 "-expect-total-renegotiations", "1",
4574 },
4575 })
4576 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004577 name: "Renegotiate-Client-Freely-1",
4578 config: Config{
4579 MaxVersion: VersionTLS12,
4580 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004581 renegotiate: 1,
4582 flags: []string{
4583 "-renegotiate-freely",
4584 "-expect-total-renegotiations", "1",
4585 },
4586 })
4587 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004588 name: "Renegotiate-Client-Once-2",
4589 config: Config{
4590 MaxVersion: VersionTLS12,
4591 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004592 renegotiate: 2,
4593 flags: []string{"-renegotiate-once"},
4594 shouldFail: true,
4595 expectedError: ":NO_RENEGOTIATION:",
4596 expectedLocalError: "remote error: no renegotiation",
4597 })
4598 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004599 name: "Renegotiate-Client-Freely-2",
4600 config: Config{
4601 MaxVersion: VersionTLS12,
4602 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004603 renegotiate: 2,
4604 flags: []string{
4605 "-renegotiate-freely",
4606 "-expect-total-renegotiations", "2",
4607 },
4608 })
Adam Langley27a0d082015-11-03 13:34:10 -08004609 testCases = append(testCases, testCase{
4610 name: "Renegotiate-Client-NoIgnore",
4611 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004612 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004613 Bugs: ProtocolBugs{
4614 SendHelloRequestBeforeEveryAppDataRecord: true,
4615 },
4616 },
4617 shouldFail: true,
4618 expectedError: ":NO_RENEGOTIATION:",
4619 })
4620 testCases = append(testCases, testCase{
4621 name: "Renegotiate-Client-Ignore",
4622 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004623 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004624 Bugs: ProtocolBugs{
4625 SendHelloRequestBeforeEveryAppDataRecord: true,
4626 },
4627 },
4628 flags: []string{
4629 "-renegotiate-ignore",
4630 "-expect-total-renegotiations", "0",
4631 },
4632 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004633
David Benjamin397c8e62016-07-08 14:14:36 -07004634 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004635 testCases = append(testCases, testCase{
4636 name: "StrayHelloRequest",
4637 config: Config{
4638 MaxVersion: VersionTLS12,
4639 Bugs: ProtocolBugs{
4640 SendHelloRequestBeforeEveryHandshakeMessage: true,
4641 },
4642 },
4643 })
4644 testCases = append(testCases, testCase{
4645 name: "StrayHelloRequest-Packed",
4646 config: Config{
4647 MaxVersion: VersionTLS12,
4648 Bugs: ProtocolBugs{
4649 PackHandshakeFlight: true,
4650 SendHelloRequestBeforeEveryHandshakeMessage: true,
4651 },
4652 },
4653 })
4654
David Benjamin397c8e62016-07-08 14:14:36 -07004655 // Renegotiation is forbidden in TLS 1.3.
4656 testCases = append(testCases, testCase{
4657 name: "Renegotiate-Client-TLS13",
4658 config: Config{
4659 MaxVersion: VersionTLS13,
4660 },
4661 renegotiate: 1,
4662 flags: []string{
4663 "-renegotiate-freely",
4664 },
4665 shouldFail: true,
4666 expectedError: ":NO_RENEGOTIATION:",
4667 })
4668
4669 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4670 testCases = append(testCases, testCase{
4671 name: "StrayHelloRequest-TLS13",
4672 config: Config{
4673 MaxVersion: VersionTLS13,
4674 Bugs: ProtocolBugs{
4675 SendHelloRequestBeforeEveryHandshakeMessage: true,
4676 },
4677 },
4678 shouldFail: true,
4679 expectedError: ":UNEXPECTED_MESSAGE:",
4680 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004681}
4682
David Benjamin5e961c12014-11-07 01:48:35 -05004683func addDTLSReplayTests() {
4684 // Test that sequence number replays are detected.
4685 testCases = append(testCases, testCase{
4686 protocol: dtls,
4687 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004688 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004689 replayWrites: true,
4690 })
4691
David Benjamin8e6db492015-07-25 18:29:23 -04004692 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004693 // than the retransmit window.
4694 testCases = append(testCases, testCase{
4695 protocol: dtls,
4696 name: "DTLS-Replay-LargeGaps",
4697 config: Config{
4698 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004699 SequenceNumberMapping: func(in uint64) uint64 {
4700 return in * 127
4701 },
David Benjamin5e961c12014-11-07 01:48:35 -05004702 },
4703 },
David Benjamin8e6db492015-07-25 18:29:23 -04004704 messageCount: 200,
4705 replayWrites: true,
4706 })
4707
4708 // Test the incoming sequence number changing non-monotonically.
4709 testCases = append(testCases, testCase{
4710 protocol: dtls,
4711 name: "DTLS-Replay-NonMonotonic",
4712 config: Config{
4713 Bugs: ProtocolBugs{
4714 SequenceNumberMapping: func(in uint64) uint64 {
4715 return in ^ 31
4716 },
4717 },
4718 },
4719 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004720 replayWrites: true,
4721 })
4722}
4723
Nick Harper60edffd2016-06-21 15:19:24 -07004724var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004725 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004726 id signatureAlgorithm
4727 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004728}{
Nick Harper60edffd2016-06-21 15:19:24 -07004729 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4730 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4731 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4732 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004733 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07004734 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4735 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4736 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004737 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
4738 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
4739 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin000800a2014-11-14 01:43:59 -05004740}
4741
Nick Harper60edffd2016-06-21 15:19:24 -07004742const fakeSigAlg1 signatureAlgorithm = 0x2a01
4743const fakeSigAlg2 signatureAlgorithm = 0xff01
4744
4745func addSignatureAlgorithmTests() {
4746 // Make sure each signature algorithm works. Include some fake values in
4747 // the list and ensure they're ignored.
4748 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07004749 for _, ver := range tlsVersions {
4750 if ver.version < VersionTLS12 {
4751 continue
4752 }
Nick Harper60edffd2016-06-21 15:19:24 -07004753
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004754 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07004755 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004756 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
4757 shouldFail = true
4758 }
4759 // RSA-PSS does not exist in TLS 1.2.
4760 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
4761 shouldFail = true
4762 }
4763
4764 var signError, verifyError string
4765 if shouldFail {
4766 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
4767 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07004768 }
David Benjamin000800a2014-11-14 01:43:59 -05004769
David Benjamin1fb125c2016-07-08 18:52:12 -07004770 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05004771
David Benjamin7a41d372016-07-09 11:21:54 -07004772 testCases = append(testCases, testCase{
4773 name: "SigningHash-ClientAuth-Sign" + suffix,
4774 config: Config{
4775 MaxVersion: ver.version,
4776 ClientAuth: RequireAnyClientCert,
4777 VerifySignatureAlgorithms: []signatureAlgorithm{
4778 fakeSigAlg1,
4779 alg.id,
4780 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07004781 },
David Benjamin7a41d372016-07-09 11:21:54 -07004782 },
4783 flags: []string{
4784 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4785 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4786 "-enable-all-curves",
4787 },
4788 shouldFail: shouldFail,
4789 expectedError: signError,
4790 expectedPeerSignatureAlgorithm: alg.id,
4791 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004792
David Benjamin7a41d372016-07-09 11:21:54 -07004793 testCases = append(testCases, testCase{
4794 testType: serverTest,
4795 name: "SigningHash-ClientAuth-Verify" + suffix,
4796 config: Config{
4797 MaxVersion: ver.version,
4798 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4799 SignSignatureAlgorithms: []signatureAlgorithm{
4800 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004801 },
David Benjamin7a41d372016-07-09 11:21:54 -07004802 Bugs: ProtocolBugs{
4803 SkipECDSACurveCheck: shouldFail,
4804 IgnoreSignatureVersionChecks: shouldFail,
4805 // The client won't advertise 1.3-only algorithms after
4806 // version negotiation.
4807 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004808 },
David Benjamin7a41d372016-07-09 11:21:54 -07004809 },
4810 flags: []string{
4811 "-require-any-client-certificate",
4812 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4813 "-enable-all-curves",
4814 },
4815 shouldFail: shouldFail,
4816 expectedError: verifyError,
4817 })
David Benjamin1fb125c2016-07-08 18:52:12 -07004818
4819 testCases = append(testCases, testCase{
4820 testType: serverTest,
4821 name: "SigningHash-ServerKeyExchange-Sign" + suffix,
4822 config: Config{
4823 MaxVersion: ver.version,
4824 CipherSuites: []uint16{
4825 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4826 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4827 },
David Benjamin7a41d372016-07-09 11:21:54 -07004828 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004829 fakeSigAlg1,
4830 alg.id,
4831 fakeSigAlg2,
4832 },
4833 },
4834 flags: []string{
4835 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4836 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4837 "-enable-all-curves",
4838 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004839 shouldFail: shouldFail,
4840 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004841 expectedPeerSignatureAlgorithm: alg.id,
4842 })
4843
4844 testCases = append(testCases, testCase{
4845 name: "SigningHash-ServerKeyExchange-Verify" + suffix,
4846 config: Config{
4847 MaxVersion: ver.version,
4848 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4849 CipherSuites: []uint16{
4850 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4851 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4852 },
David Benjamin7a41d372016-07-09 11:21:54 -07004853 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004854 alg.id,
4855 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004856 Bugs: ProtocolBugs{
4857 SkipECDSACurveCheck: shouldFail,
4858 IgnoreSignatureVersionChecks: shouldFail,
4859 },
David Benjamin1fb125c2016-07-08 18:52:12 -07004860 },
4861 flags: []string{
4862 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4863 "-enable-all-curves",
4864 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004865 shouldFail: shouldFail,
4866 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004867 })
4868 }
David Benjamin000800a2014-11-14 01:43:59 -05004869 }
4870
Nick Harper60edffd2016-06-21 15:19:24 -07004871 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004872 //
4873 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004874 testCases = append(testCases, testCase{
4875 name: "SigningHash-ClientAuth-SignatureType",
4876 config: Config{
4877 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004878 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07004879 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004880 signatureECDSAWithP521AndSHA512,
4881 signatureRSAPKCS1WithSHA384,
4882 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004883 },
4884 },
4885 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004886 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4887 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004888 },
Nick Harper60edffd2016-06-21 15:19:24 -07004889 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004890 })
4891
4892 testCases = append(testCases, testCase{
4893 testType: serverTest,
4894 name: "SigningHash-ServerKeyExchange-SignatureType",
4895 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004896 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004897 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004898 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004899 signatureECDSAWithP521AndSHA512,
4900 signatureRSAPKCS1WithSHA384,
4901 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004902 },
4903 },
Nick Harper60edffd2016-06-21 15:19:24 -07004904 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004905 })
4906
David Benjamina95e9f32016-07-08 16:28:04 -07004907 // Test that signature verification takes the key type into account.
4908 //
4909 // TODO(davidben): Test this in TLS 1.3.
4910 testCases = append(testCases, testCase{
4911 testType: serverTest,
4912 name: "Verify-ClientAuth-SignatureType",
4913 config: Config{
4914 MaxVersion: VersionTLS12,
4915 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004916 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004917 signatureRSAPKCS1WithSHA256,
4918 },
4919 Bugs: ProtocolBugs{
4920 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4921 },
4922 },
4923 flags: []string{
4924 "-require-any-client-certificate",
4925 },
4926 shouldFail: true,
4927 expectedError: ":WRONG_SIGNATURE_TYPE:",
4928 })
4929
4930 testCases = append(testCases, testCase{
4931 name: "Verify-ServerKeyExchange-SignatureType",
4932 config: Config{
4933 MaxVersion: VersionTLS12,
4934 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004935 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004936 signatureRSAPKCS1WithSHA256,
4937 },
4938 Bugs: ProtocolBugs{
4939 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4940 },
4941 },
4942 shouldFail: true,
4943 expectedError: ":WRONG_SIGNATURE_TYPE:",
4944 })
4945
David Benjamin51dd7d62016-07-08 16:07:01 -07004946 // Test that, if the list is missing, the peer falls back to SHA-1 in
4947 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004948 testCases = append(testCases, testCase{
4949 name: "SigningHash-ClientAuth-Fallback",
4950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004951 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004952 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004953 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004954 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004955 },
4956 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004957 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004958 },
4959 },
4960 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004961 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4962 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004963 },
4964 })
4965
4966 testCases = append(testCases, testCase{
4967 testType: serverTest,
4968 name: "SigningHash-ServerKeyExchange-Fallback",
4969 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004970 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004971 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004972 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004973 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004974 },
4975 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004976 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004977 },
4978 },
4979 })
David Benjamin72dc7832015-03-16 17:49:43 -04004980
David Benjamin51dd7d62016-07-08 16:07:01 -07004981 testCases = append(testCases, testCase{
4982 name: "SigningHash-ClientAuth-Fallback-TLS13",
4983 config: Config{
4984 MaxVersion: VersionTLS13,
4985 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004986 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07004987 signatureRSAPKCS1WithSHA1,
4988 },
4989 Bugs: ProtocolBugs{
4990 NoSignatureAlgorithms: true,
4991 },
4992 },
4993 flags: []string{
4994 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4995 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4996 },
4997 shouldFail: true,
4998 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
4999 })
5000
5001 testCases = append(testCases, testCase{
5002 testType: serverTest,
5003 name: "SigningHash-ServerKeyExchange-Fallback-TLS13",
5004 config: Config{
5005 MaxVersion: VersionTLS13,
5006 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005007 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005008 signatureRSAPKCS1WithSHA1,
5009 },
5010 Bugs: ProtocolBugs{
5011 NoSignatureAlgorithms: true,
5012 },
5013 },
5014 shouldFail: true,
5015 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5016 })
5017
David Benjamin72dc7832015-03-16 17:49:43 -04005018 // Test that hash preferences are enforced. BoringSSL defaults to
5019 // rejecting MD5 signatures.
5020 testCases = append(testCases, testCase{
5021 testType: serverTest,
5022 name: "SigningHash-ClientAuth-Enforced",
5023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005024 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005025 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005026 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005027 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005028 // Advertise SHA-1 so the handshake will
5029 // proceed, but the shim's preferences will be
5030 // ignored in CertificateVerify generation, so
5031 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005032 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005033 },
5034 Bugs: ProtocolBugs{
5035 IgnorePeerSignatureAlgorithmPreferences: true,
5036 },
5037 },
5038 flags: []string{"-require-any-client-certificate"},
5039 shouldFail: true,
5040 expectedError: ":WRONG_SIGNATURE_TYPE:",
5041 })
5042
5043 testCases = append(testCases, testCase{
5044 name: "SigningHash-ServerKeyExchange-Enforced",
5045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005046 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005048 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005049 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005050 },
5051 Bugs: ProtocolBugs{
5052 IgnorePeerSignatureAlgorithmPreferences: true,
5053 },
5054 },
5055 shouldFail: true,
5056 expectedError: ":WRONG_SIGNATURE_TYPE:",
5057 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005058
5059 // Test that the agreed upon digest respects the client preferences and
5060 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005061 //
5062 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04005063 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005064 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005065 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005066 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005067 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005068 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005069 signatureRSAPKCS1WithSHA512,
5070 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005071 },
5072 },
5073 flags: []string{
5074 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5075 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5076 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005077 digestPrefs: "SHA256",
5078 shouldFail: true,
5079 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005080 })
5081 testCases = append(testCases, testCase{
5082 name: "Agree-Digest-SHA256",
5083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005084 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005085 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005086 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005087 signatureRSAPKCS1WithSHA1,
5088 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005089 },
5090 },
5091 flags: []string{
5092 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5093 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5094 },
Nick Harper60edffd2016-06-21 15:19:24 -07005095 digestPrefs: "SHA256,SHA1",
5096 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005097 })
5098 testCases = append(testCases, testCase{
5099 name: "Agree-Digest-SHA1",
5100 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005101 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005102 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005103 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005104 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005105 },
5106 },
5107 flags: []string{
5108 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5109 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5110 },
Nick Harper60edffd2016-06-21 15:19:24 -07005111 digestPrefs: "SHA512,SHA256,SHA1",
5112 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005113 })
5114 testCases = append(testCases, testCase{
5115 name: "Agree-Digest-Default",
5116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005117 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005118 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005119 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005120 signatureRSAPKCS1WithSHA256,
5121 signatureECDSAWithP256AndSHA256,
5122 signatureRSAPKCS1WithSHA1,
5123 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005124 },
5125 },
5126 flags: []string{
5127 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5128 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5129 },
Nick Harper60edffd2016-06-21 15:19:24 -07005130 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005131 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005132
5133 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5134 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005135 testCases = append(testCases, testCase{
5136 name: "CheckLeafCurve",
5137 config: Config{
5138 MaxVersion: VersionTLS12,
5139 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005140 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005141 },
5142 flags: []string{"-p384-only"},
5143 shouldFail: true,
5144 expectedError: ":BAD_ECC_CERT:",
5145 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005146
5147 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5148 testCases = append(testCases, testCase{
5149 name: "CheckLeafCurve-TLS13",
5150 config: Config{
5151 MaxVersion: VersionTLS13,
5152 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5153 Certificates: []Certificate{ecdsaP256Certificate},
5154 },
5155 flags: []string{"-p384-only"},
5156 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005157
5158 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5159 testCases = append(testCases, testCase{
5160 name: "ECDSACurveMismatch-Verify-TLS12",
5161 config: Config{
5162 MaxVersion: VersionTLS12,
5163 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5164 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005165 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005166 signatureECDSAWithP384AndSHA384,
5167 },
5168 },
5169 })
5170
5171 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5172 testCases = append(testCases, testCase{
5173 name: "ECDSACurveMismatch-Verify-TLS13",
5174 config: Config{
5175 MaxVersion: VersionTLS13,
5176 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5177 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005178 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005179 signatureECDSAWithP384AndSHA384,
5180 },
5181 Bugs: ProtocolBugs{
5182 SkipECDSACurveCheck: true,
5183 },
5184 },
5185 shouldFail: true,
5186 expectedError: ":WRONG_SIGNATURE_TYPE:",
5187 })
5188
5189 // Signature algorithm selection in TLS 1.3 should take the curve into
5190 // account.
5191 testCases = append(testCases, testCase{
5192 testType: serverTest,
5193 name: "ECDSACurveMismatch-Sign-TLS13",
5194 config: Config{
5195 MaxVersion: VersionTLS13,
5196 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005197 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005198 signatureECDSAWithP384AndSHA384,
5199 signatureECDSAWithP256AndSHA256,
5200 },
5201 },
5202 flags: []string{
5203 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5204 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5205 },
5206 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5207 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005208
5209 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5210 // server does not attempt to sign in that case.
5211 testCases = append(testCases, testCase{
5212 testType: serverTest,
5213 name: "RSA-PSS-Large",
5214 config: Config{
5215 MaxVersion: VersionTLS13,
5216 VerifySignatureAlgorithms: []signatureAlgorithm{
5217 signatureRSAPSSWithSHA512,
5218 },
5219 },
5220 flags: []string{
5221 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5222 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5223 },
5224 shouldFail: true,
5225 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5226 })
David Benjamin000800a2014-11-14 01:43:59 -05005227}
5228
David Benjamin83f90402015-01-27 01:09:43 -05005229// timeouts is the retransmit schedule for BoringSSL. It doubles and
5230// caps at 60 seconds. On the 13th timeout, it gives up.
5231var timeouts = []time.Duration{
5232 1 * time.Second,
5233 2 * time.Second,
5234 4 * time.Second,
5235 8 * time.Second,
5236 16 * time.Second,
5237 32 * time.Second,
5238 60 * time.Second,
5239 60 * time.Second,
5240 60 * time.Second,
5241 60 * time.Second,
5242 60 * time.Second,
5243 60 * time.Second,
5244 60 * time.Second,
5245}
5246
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005247// shortTimeouts is an alternate set of timeouts which would occur if the
5248// initial timeout duration was set to 250ms.
5249var shortTimeouts = []time.Duration{
5250 250 * time.Millisecond,
5251 500 * time.Millisecond,
5252 1 * time.Second,
5253 2 * time.Second,
5254 4 * time.Second,
5255 8 * time.Second,
5256 16 * time.Second,
5257 32 * time.Second,
5258 60 * time.Second,
5259 60 * time.Second,
5260 60 * time.Second,
5261 60 * time.Second,
5262 60 * time.Second,
5263}
5264
David Benjamin83f90402015-01-27 01:09:43 -05005265func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005266 // These tests work by coordinating some behavior on both the shim and
5267 // the runner.
5268 //
5269 // TimeoutSchedule configures the runner to send a series of timeout
5270 // opcodes to the shim (see packetAdaptor) immediately before reading
5271 // each peer handshake flight N. The timeout opcode both simulates a
5272 // timeout in the shim and acts as a synchronization point to help the
5273 // runner bracket each handshake flight.
5274 //
5275 // We assume the shim does not read from the channel eagerly. It must
5276 // first wait until it has sent flight N and is ready to receive
5277 // handshake flight N+1. At this point, it will process the timeout
5278 // opcode. It must then immediately respond with a timeout ACK and act
5279 // as if the shim was idle for the specified amount of time.
5280 //
5281 // The runner then drops all packets received before the ACK and
5282 // continues waiting for flight N. This ordering results in one attempt
5283 // at sending flight N to be dropped. For the test to complete, the
5284 // shim must send flight N again, testing that the shim implements DTLS
5285 // retransmit on a timeout.
5286
David Benjamin4c3ddf72016-06-29 18:13:53 -04005287 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5288 // likely be more epochs to cross and the final message's retransmit may
5289 // be more complex.
5290
David Benjamin585d7a42016-06-02 14:58:00 -04005291 for _, async := range []bool{true, false} {
5292 var tests []testCase
5293
5294 // Test that this is indeed the timeout schedule. Stress all
5295 // four patterns of handshake.
5296 for i := 1; i < len(timeouts); i++ {
5297 number := strconv.Itoa(i)
5298 tests = append(tests, testCase{
5299 protocol: dtls,
5300 name: "DTLS-Retransmit-Client-" + number,
5301 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005302 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005303 Bugs: ProtocolBugs{
5304 TimeoutSchedule: timeouts[:i],
5305 },
5306 },
5307 resumeSession: true,
5308 })
5309 tests = append(tests, testCase{
5310 protocol: dtls,
5311 testType: serverTest,
5312 name: "DTLS-Retransmit-Server-" + number,
5313 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005314 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005315 Bugs: ProtocolBugs{
5316 TimeoutSchedule: timeouts[:i],
5317 },
5318 },
5319 resumeSession: true,
5320 })
5321 }
5322
5323 // Test that exceeding the timeout schedule hits a read
5324 // timeout.
5325 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005326 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005327 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005328 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005329 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005330 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005331 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005332 },
5333 },
5334 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005335 shouldFail: true,
5336 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005337 })
David Benjamin585d7a42016-06-02 14:58:00 -04005338
5339 if async {
5340 // Test that timeout handling has a fudge factor, due to API
5341 // problems.
5342 tests = append(tests, testCase{
5343 protocol: dtls,
5344 name: "DTLS-Retransmit-Fudge",
5345 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005346 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005347 Bugs: ProtocolBugs{
5348 TimeoutSchedule: []time.Duration{
5349 timeouts[0] - 10*time.Millisecond,
5350 },
5351 },
5352 },
5353 resumeSession: true,
5354 })
5355 }
5356
5357 // Test that the final Finished retransmitting isn't
5358 // duplicated if the peer badly fragments everything.
5359 tests = append(tests, testCase{
5360 testType: serverTest,
5361 protocol: dtls,
5362 name: "DTLS-Retransmit-Fragmented",
5363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005364 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005365 Bugs: ProtocolBugs{
5366 TimeoutSchedule: []time.Duration{timeouts[0]},
5367 MaxHandshakeRecordLength: 2,
5368 },
5369 },
5370 })
5371
5372 // Test the timeout schedule when a shorter initial timeout duration is set.
5373 tests = append(tests, testCase{
5374 protocol: dtls,
5375 name: "DTLS-Retransmit-Short-Client",
5376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005377 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005378 Bugs: ProtocolBugs{
5379 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5380 },
5381 },
5382 resumeSession: true,
5383 flags: []string{"-initial-timeout-duration-ms", "250"},
5384 })
5385 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005386 protocol: dtls,
5387 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005388 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005389 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005390 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005391 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005392 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005393 },
5394 },
5395 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005396 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005397 })
David Benjamin585d7a42016-06-02 14:58:00 -04005398
5399 for _, test := range tests {
5400 if async {
5401 test.name += "-Async"
5402 test.flags = append(test.flags, "-async")
5403 }
5404
5405 testCases = append(testCases, test)
5406 }
David Benjamin83f90402015-01-27 01:09:43 -05005407 }
David Benjamin83f90402015-01-27 01:09:43 -05005408}
5409
David Benjaminc565ebb2015-04-03 04:06:36 -04005410func addExportKeyingMaterialTests() {
5411 for _, vers := range tlsVersions {
5412 if vers.version == VersionSSL30 {
5413 continue
5414 }
5415 testCases = append(testCases, testCase{
5416 name: "ExportKeyingMaterial-" + vers.name,
5417 config: Config{
5418 MaxVersion: vers.version,
5419 },
5420 exportKeyingMaterial: 1024,
5421 exportLabel: "label",
5422 exportContext: "context",
5423 useExportContext: true,
5424 })
5425 testCases = append(testCases, testCase{
5426 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5427 config: Config{
5428 MaxVersion: vers.version,
5429 },
5430 exportKeyingMaterial: 1024,
5431 })
5432 testCases = append(testCases, testCase{
5433 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5434 config: Config{
5435 MaxVersion: vers.version,
5436 },
5437 exportKeyingMaterial: 1024,
5438 useExportContext: true,
5439 })
5440 testCases = append(testCases, testCase{
5441 name: "ExportKeyingMaterial-Small-" + vers.name,
5442 config: Config{
5443 MaxVersion: vers.version,
5444 },
5445 exportKeyingMaterial: 1,
5446 exportLabel: "label",
5447 exportContext: "context",
5448 useExportContext: true,
5449 })
5450 }
5451 testCases = append(testCases, testCase{
5452 name: "ExportKeyingMaterial-SSL3",
5453 config: Config{
5454 MaxVersion: VersionSSL30,
5455 },
5456 exportKeyingMaterial: 1024,
5457 exportLabel: "label",
5458 exportContext: "context",
5459 useExportContext: true,
5460 shouldFail: true,
5461 expectedError: "failed to export keying material",
5462 })
5463}
5464
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005465func addTLSUniqueTests() {
5466 for _, isClient := range []bool{false, true} {
5467 for _, isResumption := range []bool{false, true} {
5468 for _, hasEMS := range []bool{false, true} {
5469 var suffix string
5470 if isResumption {
5471 suffix = "Resume-"
5472 } else {
5473 suffix = "Full-"
5474 }
5475
5476 if hasEMS {
5477 suffix += "EMS-"
5478 } else {
5479 suffix += "NoEMS-"
5480 }
5481
5482 if isClient {
5483 suffix += "Client"
5484 } else {
5485 suffix += "Server"
5486 }
5487
5488 test := testCase{
5489 name: "TLSUnique-" + suffix,
5490 testTLSUnique: true,
5491 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005492 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005493 Bugs: ProtocolBugs{
5494 NoExtendedMasterSecret: !hasEMS,
5495 },
5496 },
5497 }
5498
5499 if isResumption {
5500 test.resumeSession = true
5501 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005502 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005503 Bugs: ProtocolBugs{
5504 NoExtendedMasterSecret: !hasEMS,
5505 },
5506 }
5507 }
5508
5509 if isResumption && !hasEMS {
5510 test.shouldFail = true
5511 test.expectedError = "failed to get tls-unique"
5512 }
5513
5514 testCases = append(testCases, test)
5515 }
5516 }
5517 }
5518}
5519
Adam Langley09505632015-07-30 18:10:13 -07005520func addCustomExtensionTests() {
5521 expectedContents := "custom extension"
5522 emptyString := ""
5523
David Benjamin4c3ddf72016-06-29 18:13:53 -04005524 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005525 for _, isClient := range []bool{false, true} {
5526 suffix := "Server"
5527 flag := "-enable-server-custom-extension"
5528 testType := serverTest
5529 if isClient {
5530 suffix = "Client"
5531 flag = "-enable-client-custom-extension"
5532 testType = clientTest
5533 }
5534
5535 testCases = append(testCases, testCase{
5536 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005537 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005538 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005539 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005540 Bugs: ProtocolBugs{
5541 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005542 ExpectedCustomExtension: &expectedContents,
5543 },
5544 },
5545 flags: []string{flag},
5546 })
5547
5548 // If the parse callback fails, the handshake should also fail.
5549 testCases = append(testCases, testCase{
5550 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005551 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005553 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005554 Bugs: ProtocolBugs{
5555 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005556 ExpectedCustomExtension: &expectedContents,
5557 },
5558 },
David Benjamin399e7c92015-07-30 23:01:27 -04005559 flags: []string{flag},
5560 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005561 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5562 })
5563
5564 // If the add callback fails, the handshake should also fail.
5565 testCases = append(testCases, testCase{
5566 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005567 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005569 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005570 Bugs: ProtocolBugs{
5571 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005572 ExpectedCustomExtension: &expectedContents,
5573 },
5574 },
David Benjamin399e7c92015-07-30 23:01:27 -04005575 flags: []string{flag, "-custom-extension-fail-add"},
5576 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005577 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5578 })
5579
5580 // If the add callback returns zero, no extension should be
5581 // added.
5582 skipCustomExtension := expectedContents
5583 if isClient {
5584 // For the case where the client skips sending the
5585 // custom extension, the server must not “echo” it.
5586 skipCustomExtension = ""
5587 }
5588 testCases = append(testCases, testCase{
5589 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005590 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005591 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005592 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005593 Bugs: ProtocolBugs{
5594 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005595 ExpectedCustomExtension: &emptyString,
5596 },
5597 },
5598 flags: []string{flag, "-custom-extension-skip"},
5599 })
5600 }
5601
5602 // The custom extension add callback should not be called if the client
5603 // doesn't send the extension.
5604 testCases = append(testCases, testCase{
5605 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005606 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005607 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005608 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005609 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005610 ExpectedCustomExtension: &emptyString,
5611 },
5612 },
5613 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5614 })
Adam Langley2deb9842015-08-07 11:15:37 -07005615
5616 // Test an unknown extension from the server.
5617 testCases = append(testCases, testCase{
5618 testType: clientTest,
5619 name: "UnknownExtension-Client",
5620 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005621 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005622 Bugs: ProtocolBugs{
5623 CustomExtension: expectedContents,
5624 },
5625 },
5626 shouldFail: true,
5627 expectedError: ":UNEXPECTED_EXTENSION:",
5628 })
Adam Langley09505632015-07-30 18:10:13 -07005629}
5630
David Benjaminb36a3952015-12-01 18:53:13 -05005631func addRSAClientKeyExchangeTests() {
5632 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5633 testCases = append(testCases, testCase{
5634 testType: serverTest,
5635 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5636 config: Config{
5637 // Ensure the ClientHello version and final
5638 // version are different, to detect if the
5639 // server uses the wrong one.
5640 MaxVersion: VersionTLS11,
5641 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5642 Bugs: ProtocolBugs{
5643 BadRSAClientKeyExchange: bad,
5644 },
5645 },
5646 shouldFail: true,
5647 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5648 })
5649 }
5650}
5651
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005652var testCurves = []struct {
5653 name string
5654 id CurveID
5655}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005656 {"P-256", CurveP256},
5657 {"P-384", CurveP384},
5658 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005659 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005660}
5661
5662func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005663 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005664 for _, curve := range testCurves {
5665 testCases = append(testCases, testCase{
5666 name: "CurveTest-Client-" + curve.name,
5667 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005668 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5670 CurvePreferences: []CurveID{curve.id},
5671 },
5672 flags: []string{"-enable-all-curves"},
5673 })
5674 testCases = append(testCases, testCase{
5675 testType: serverTest,
5676 name: "CurveTest-Server-" + curve.name,
5677 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005678 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005679 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5680 CurvePreferences: []CurveID{curve.id},
5681 },
5682 flags: []string{"-enable-all-curves"},
5683 })
5684 }
David Benjamin241ae832016-01-15 03:04:54 -05005685
5686 // The server must be tolerant to bogus curves.
5687 const bogusCurve = 0x1234
5688 testCases = append(testCases, testCase{
5689 testType: serverTest,
5690 name: "UnknownCurve",
5691 config: Config{
5692 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5693 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5694 },
5695 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005696
5697 // The server must not consider ECDHE ciphers when there are no
5698 // supported curves.
5699 testCases = append(testCases, testCase{
5700 testType: serverTest,
5701 name: "NoSupportedCurves",
5702 config: Config{
5703 // TODO(davidben): Add a TLS 1.3 version of this.
5704 MaxVersion: VersionTLS12,
5705 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5706 Bugs: ProtocolBugs{
5707 NoSupportedCurves: true,
5708 },
5709 },
5710 shouldFail: true,
5711 expectedError: ":NO_SHARED_CIPHER:",
5712 })
5713
5714 // The server must fall back to another cipher when there are no
5715 // supported curves.
5716 testCases = append(testCases, testCase{
5717 testType: serverTest,
5718 name: "NoCommonCurves",
5719 config: Config{
5720 MaxVersion: VersionTLS12,
5721 CipherSuites: []uint16{
5722 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5723 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5724 },
5725 CurvePreferences: []CurveID{CurveP224},
5726 },
5727 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5728 })
5729
5730 // The client must reject bogus curves and disabled curves.
5731 testCases = append(testCases, testCase{
5732 name: "BadECDHECurve",
5733 config: Config{
5734 // TODO(davidben): Add a TLS 1.3 version of this.
5735 MaxVersion: VersionTLS12,
5736 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5737 Bugs: ProtocolBugs{
5738 SendCurve: bogusCurve,
5739 },
5740 },
5741 shouldFail: true,
5742 expectedError: ":WRONG_CURVE:",
5743 })
5744
5745 testCases = append(testCases, testCase{
5746 name: "UnsupportedCurve",
5747 config: Config{
5748 // TODO(davidben): Add a TLS 1.3 version of this.
5749 MaxVersion: VersionTLS12,
5750 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5751 CurvePreferences: []CurveID{CurveP256},
5752 Bugs: ProtocolBugs{
5753 IgnorePeerCurvePreferences: true,
5754 },
5755 },
5756 flags: []string{"-p384-only"},
5757 shouldFail: true,
5758 expectedError: ":WRONG_CURVE:",
5759 })
5760
5761 // Test invalid curve points.
5762 testCases = append(testCases, testCase{
5763 name: "InvalidECDHPoint-Client",
5764 config: Config{
5765 // TODO(davidben): Add a TLS 1.3 version of this test.
5766 MaxVersion: VersionTLS12,
5767 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5768 CurvePreferences: []CurveID{CurveP256},
5769 Bugs: ProtocolBugs{
5770 InvalidECDHPoint: true,
5771 },
5772 },
5773 shouldFail: true,
5774 expectedError: ":INVALID_ENCODING:",
5775 })
5776 testCases = append(testCases, testCase{
5777 testType: serverTest,
5778 name: "InvalidECDHPoint-Server",
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 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005791}
5792
Matt Braithwaite54217e42016-06-13 13:03:47 -07005793func addCECPQ1Tests() {
5794 testCases = append(testCases, testCase{
5795 testType: clientTest,
5796 name: "CECPQ1-Client-BadX25519Part",
5797 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005798 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005799 MinVersion: VersionTLS12,
5800 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5801 Bugs: ProtocolBugs{
5802 CECPQ1BadX25519Part: true,
5803 },
5804 },
5805 flags: []string{"-cipher", "kCECPQ1"},
5806 shouldFail: true,
5807 expectedLocalError: "local error: bad record MAC",
5808 })
5809 testCases = append(testCases, testCase{
5810 testType: clientTest,
5811 name: "CECPQ1-Client-BadNewhopePart",
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 CECPQ1BadNewhopePart: 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: serverTest,
5826 name: "CECPQ1-Server-BadX25519Part",
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 CECPQ1BadX25519Part: true,
5833 },
5834 },
5835 flags: []string{"-cipher", "kCECPQ1"},
5836 shouldFail: true,
5837 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5838 })
5839 testCases = append(testCases, testCase{
5840 testType: serverTest,
5841 name: "CECPQ1-Server-BadNewhopePart",
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 CECPQ1BadNewhopePart: true,
5848 },
5849 },
5850 flags: []string{"-cipher", "kCECPQ1"},
5851 shouldFail: true,
5852 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5853 })
5854}
5855
David Benjamin4cc36ad2015-12-19 14:23:26 -05005856func addKeyExchangeInfoTests() {
5857 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005858 name: "KeyExchangeInfo-DHE-Client",
5859 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005860 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005861 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5862 Bugs: ProtocolBugs{
5863 // This is a 1234-bit prime number, generated
5864 // with:
5865 // openssl gendh 1234 | openssl asn1parse -i
5866 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5867 },
5868 },
David Benjamin9e68f192016-06-30 14:55:33 -04005869 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005870 })
5871 testCases = append(testCases, testCase{
5872 testType: serverTest,
5873 name: "KeyExchangeInfo-DHE-Server",
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 },
5878 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005879 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005880 })
5881
Nick Harper1fd39d82016-06-14 18:14:35 -07005882 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5883 // handshake is separate.
5884
David Benjamin4cc36ad2015-12-19 14:23:26 -05005885 testCases = append(testCases, testCase{
5886 name: "KeyExchangeInfo-ECDHE-Client",
5887 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005888 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005889 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5890 CurvePreferences: []CurveID{CurveX25519},
5891 },
David Benjamin9e68f192016-06-30 14:55:33 -04005892 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005893 })
5894 testCases = append(testCases, testCase{
5895 testType: serverTest,
5896 name: "KeyExchangeInfo-ECDHE-Server",
5897 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005898 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005899 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5900 CurvePreferences: []CurveID{CurveX25519},
5901 },
David Benjamin9e68f192016-06-30 14:55:33 -04005902 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005903 })
5904}
5905
David Benjaminc9ae27c2016-06-24 22:56:37 -04005906func addTLS13RecordTests() {
5907 testCases = append(testCases, testCase{
5908 name: "TLS13-RecordPadding",
5909 config: Config{
5910 MaxVersion: VersionTLS13,
5911 MinVersion: VersionTLS13,
5912 Bugs: ProtocolBugs{
5913 RecordPadding: 10,
5914 },
5915 },
5916 })
5917
5918 testCases = append(testCases, testCase{
5919 name: "TLS13-EmptyRecords",
5920 config: Config{
5921 MaxVersion: VersionTLS13,
5922 MinVersion: VersionTLS13,
5923 Bugs: ProtocolBugs{
5924 OmitRecordContents: true,
5925 },
5926 },
5927 shouldFail: true,
5928 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5929 })
5930
5931 testCases = append(testCases, testCase{
5932 name: "TLS13-OnlyPadding",
5933 config: Config{
5934 MaxVersion: VersionTLS13,
5935 MinVersion: VersionTLS13,
5936 Bugs: ProtocolBugs{
5937 OmitRecordContents: true,
5938 RecordPadding: 10,
5939 },
5940 },
5941 shouldFail: true,
5942 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5943 })
5944
5945 testCases = append(testCases, testCase{
5946 name: "TLS13-WrongOuterRecord",
5947 config: Config{
5948 MaxVersion: VersionTLS13,
5949 MinVersion: VersionTLS13,
5950 Bugs: ProtocolBugs{
5951 OuterRecordType: recordTypeHandshake,
5952 },
5953 },
5954 shouldFail: true,
5955 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5956 })
5957}
5958
David Benjamin82261be2016-07-07 14:32:50 -07005959func addChangeCipherSpecTests() {
5960 // Test missing ChangeCipherSpecs.
5961 testCases = append(testCases, testCase{
5962 name: "SkipChangeCipherSpec-Client",
5963 config: Config{
5964 MaxVersion: VersionTLS12,
5965 Bugs: ProtocolBugs{
5966 SkipChangeCipherSpec: true,
5967 },
5968 },
5969 shouldFail: true,
5970 expectedError: ":UNEXPECTED_RECORD:",
5971 })
5972 testCases = append(testCases, testCase{
5973 testType: serverTest,
5974 name: "SkipChangeCipherSpec-Server",
5975 config: Config{
5976 MaxVersion: VersionTLS12,
5977 Bugs: ProtocolBugs{
5978 SkipChangeCipherSpec: true,
5979 },
5980 },
5981 shouldFail: true,
5982 expectedError: ":UNEXPECTED_RECORD:",
5983 })
5984 testCases = append(testCases, testCase{
5985 testType: serverTest,
5986 name: "SkipChangeCipherSpec-Server-NPN",
5987 config: Config{
5988 MaxVersion: VersionTLS12,
5989 NextProtos: []string{"bar"},
5990 Bugs: ProtocolBugs{
5991 SkipChangeCipherSpec: true,
5992 },
5993 },
5994 flags: []string{
5995 "-advertise-npn", "\x03foo\x03bar\x03baz",
5996 },
5997 shouldFail: true,
5998 expectedError: ":UNEXPECTED_RECORD:",
5999 })
6000
6001 // Test synchronization between the handshake and ChangeCipherSpec.
6002 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6003 // rejected. Test both with and without handshake packing to handle both
6004 // when the partial post-CCS message is in its own record and when it is
6005 // attached to the pre-CCS message.
6006 //
6007 // TODO(davidben): Fix and test DTLS as well.
6008 for _, packed := range []bool{false, true} {
6009 var suffix string
6010 if packed {
6011 suffix = "-Packed"
6012 }
6013
6014 testCases = append(testCases, testCase{
6015 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6016 config: Config{
6017 MaxVersion: VersionTLS12,
6018 Bugs: ProtocolBugs{
6019 FragmentAcrossChangeCipherSpec: true,
6020 PackHandshakeFlight: packed,
6021 },
6022 },
6023 shouldFail: true,
6024 expectedError: ":UNEXPECTED_RECORD:",
6025 })
6026 testCases = append(testCases, testCase{
6027 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6028 config: Config{
6029 MaxVersion: VersionTLS12,
6030 },
6031 resumeSession: true,
6032 resumeConfig: &Config{
6033 MaxVersion: VersionTLS12,
6034 Bugs: ProtocolBugs{
6035 FragmentAcrossChangeCipherSpec: true,
6036 PackHandshakeFlight: packed,
6037 },
6038 },
6039 shouldFail: true,
6040 expectedError: ":UNEXPECTED_RECORD:",
6041 })
6042 testCases = append(testCases, testCase{
6043 testType: serverTest,
6044 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6045 config: Config{
6046 MaxVersion: VersionTLS12,
6047 Bugs: ProtocolBugs{
6048 FragmentAcrossChangeCipherSpec: true,
6049 PackHandshakeFlight: packed,
6050 },
6051 },
6052 shouldFail: true,
6053 expectedError: ":UNEXPECTED_RECORD:",
6054 })
6055 testCases = append(testCases, testCase{
6056 testType: serverTest,
6057 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6058 config: Config{
6059 MaxVersion: VersionTLS12,
6060 },
6061 resumeSession: true,
6062 resumeConfig: &Config{
6063 MaxVersion: VersionTLS12,
6064 Bugs: ProtocolBugs{
6065 FragmentAcrossChangeCipherSpec: true,
6066 PackHandshakeFlight: packed,
6067 },
6068 },
6069 shouldFail: true,
6070 expectedError: ":UNEXPECTED_RECORD:",
6071 })
6072 testCases = append(testCases, testCase{
6073 testType: serverTest,
6074 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6075 config: Config{
6076 MaxVersion: VersionTLS12,
6077 NextProtos: []string{"bar"},
6078 Bugs: ProtocolBugs{
6079 FragmentAcrossChangeCipherSpec: true,
6080 PackHandshakeFlight: packed,
6081 },
6082 },
6083 flags: []string{
6084 "-advertise-npn", "\x03foo\x03bar\x03baz",
6085 },
6086 shouldFail: true,
6087 expectedError: ":UNEXPECTED_RECORD:",
6088 })
6089 }
6090
6091 // Test that early ChangeCipherSpecs are handled correctly.
6092 testCases = append(testCases, testCase{
6093 testType: serverTest,
6094 name: "EarlyChangeCipherSpec-server-1",
6095 config: Config{
6096 MaxVersion: VersionTLS12,
6097 Bugs: ProtocolBugs{
6098 EarlyChangeCipherSpec: 1,
6099 },
6100 },
6101 shouldFail: true,
6102 expectedError: ":UNEXPECTED_RECORD:",
6103 })
6104 testCases = append(testCases, testCase{
6105 testType: serverTest,
6106 name: "EarlyChangeCipherSpec-server-2",
6107 config: Config{
6108 MaxVersion: VersionTLS12,
6109 Bugs: ProtocolBugs{
6110 EarlyChangeCipherSpec: 2,
6111 },
6112 },
6113 shouldFail: true,
6114 expectedError: ":UNEXPECTED_RECORD:",
6115 })
6116 testCases = append(testCases, testCase{
6117 protocol: dtls,
6118 name: "StrayChangeCipherSpec",
6119 config: Config{
6120 // TODO(davidben): Once DTLS 1.3 exists, test
6121 // that stray ChangeCipherSpec messages are
6122 // rejected.
6123 MaxVersion: VersionTLS12,
6124 Bugs: ProtocolBugs{
6125 StrayChangeCipherSpec: true,
6126 },
6127 },
6128 })
6129
6130 // Test that the contents of ChangeCipherSpec are checked.
6131 testCases = append(testCases, testCase{
6132 name: "BadChangeCipherSpec-1",
6133 config: Config{
6134 MaxVersion: VersionTLS12,
6135 Bugs: ProtocolBugs{
6136 BadChangeCipherSpec: []byte{2},
6137 },
6138 },
6139 shouldFail: true,
6140 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6141 })
6142 testCases = append(testCases, testCase{
6143 name: "BadChangeCipherSpec-2",
6144 config: Config{
6145 MaxVersion: VersionTLS12,
6146 Bugs: ProtocolBugs{
6147 BadChangeCipherSpec: []byte{1, 1},
6148 },
6149 },
6150 shouldFail: true,
6151 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6152 })
6153 testCases = append(testCases, testCase{
6154 protocol: dtls,
6155 name: "BadChangeCipherSpec-DTLS-1",
6156 config: Config{
6157 MaxVersion: VersionTLS12,
6158 Bugs: ProtocolBugs{
6159 BadChangeCipherSpec: []byte{2},
6160 },
6161 },
6162 shouldFail: true,
6163 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6164 })
6165 testCases = append(testCases, testCase{
6166 protocol: dtls,
6167 name: "BadChangeCipherSpec-DTLS-2",
6168 config: Config{
6169 MaxVersion: VersionTLS12,
6170 Bugs: ProtocolBugs{
6171 BadChangeCipherSpec: []byte{1, 1},
6172 },
6173 },
6174 shouldFail: true,
6175 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6176 })
6177}
6178
Adam Langley7c803a62015-06-15 15:35:05 -07006179func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006180 defer wg.Done()
6181
6182 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006183 var err error
6184
6185 if *mallocTest < 0 {
6186 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006187 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006188 } else {
6189 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6190 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006191 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006192 if err != nil {
6193 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6194 }
6195 break
6196 }
6197 }
6198 }
Adam Langley95c29f32014-06-20 12:00:00 -07006199 statusChan <- statusMsg{test: test, err: err}
6200 }
6201}
6202
6203type statusMsg struct {
6204 test *testCase
6205 started bool
6206 err error
6207}
6208
David Benjamin5f237bc2015-02-11 17:14:15 -05006209func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006210 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006211
David Benjamin5f237bc2015-02-11 17:14:15 -05006212 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006213 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006214 if !*pipe {
6215 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006216 var erase string
6217 for i := 0; i < lineLen; i++ {
6218 erase += "\b \b"
6219 }
6220 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006221 }
6222
Adam Langley95c29f32014-06-20 12:00:00 -07006223 if msg.started {
6224 started++
6225 } else {
6226 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006227
6228 if msg.err != nil {
6229 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6230 failed++
6231 testOutput.addResult(msg.test.name, "FAIL")
6232 } else {
6233 if *pipe {
6234 // Print each test instead of a status line.
6235 fmt.Printf("PASSED (%s)\n", msg.test.name)
6236 }
6237 testOutput.addResult(msg.test.name, "PASS")
6238 }
Adam Langley95c29f32014-06-20 12:00:00 -07006239 }
6240
David Benjamin5f237bc2015-02-11 17:14:15 -05006241 if !*pipe {
6242 // Print a new status line.
6243 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6244 lineLen = len(line)
6245 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006246 }
Adam Langley95c29f32014-06-20 12:00:00 -07006247 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006248
6249 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006250}
6251
6252func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006253 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006254 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006255 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006256
Adam Langley7c803a62015-06-15 15:35:05 -07006257 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006258 addCipherSuiteTests()
6259 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006260 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006261 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006262 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006263 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006264 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006265 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006266 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006267 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006268 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006269 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006270 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006271 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006272 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006273 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006274 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006275 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006276 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006277 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006278 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006279 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006280 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006281 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006282 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006283
6284 var wg sync.WaitGroup
6285
Adam Langley7c803a62015-06-15 15:35:05 -07006286 statusChan := make(chan statusMsg, *numWorkers)
6287 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006288 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006289
David Benjamin025b3d32014-07-01 19:53:04 -04006290 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006291
Adam Langley7c803a62015-06-15 15:35:05 -07006292 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006293 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006294 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006295 }
6296
David Benjamin270f0a72016-03-17 14:41:36 -04006297 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006298 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006299 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006300 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006301 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006302 }
6303 }
David Benjamin270f0a72016-03-17 14:41:36 -04006304 if !foundTest {
6305 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6306 os.Exit(1)
6307 }
Adam Langley95c29f32014-06-20 12:00:00 -07006308
6309 close(testChan)
6310 wg.Wait()
6311 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006312 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006313
6314 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006315
6316 if *jsonOutput != "" {
6317 if err := testOutput.writeTo(*jsonOutput); err != nil {
6318 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6319 }
6320 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006321
6322 if !testOutput.allPassed {
6323 os.Exit(1)
6324 }
Adam Langley95c29f32014-06-20 12:00:00 -07006325}