blob: 8ad996269701af78a8910a98b4185409817f2955 [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
Steven Valdez5440fe02016-07-18 12:40:30 -0400257 // expectedCurveID, if not zero, is the curve that the handshake should
258 // have used.
259 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700260 // messageLen is the length, in bytes, of the test message that will be
261 // sent.
262 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400263 // messageCount is the number of test messages that will be sent.
264 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400265 // certFile is the path to the certificate to use for the server.
266 certFile string
267 // keyFile is the path to the private key to use for the server.
268 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400269 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400270 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400271 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700272 // expectResumeRejected, if true, specifies that the attempted
273 // resumption must be rejected by the client. This is only valid for a
274 // serverTest.
275 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400276 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500277 // resumption. Unless newSessionsOnResume is set,
278 // SessionTicketKey, ServerSessionCache, and
279 // ClientSessionCache are copied from the initial connection's
280 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400281 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500282 // newSessionsOnResume, if true, will cause resumeConfig to
283 // use a different session resumption context.
284 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400285 // noSessionCache, if true, will cause the server to run without a
286 // session cache.
287 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400288 // sendPrefix sends a prefix on the socket before actually performing a
289 // handshake.
290 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400291 // shimWritesFirst controls whether the shim sends an initial "hello"
292 // message before doing a roundtrip with the runner.
293 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400294 // shimShutsDown, if true, runs a test where the shim shuts down the
295 // connection immediately after the handshake rather than echoing
296 // messages from the runner.
297 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400298 // renegotiate indicates the number of times the connection should be
299 // renegotiated during the exchange.
300 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700301 // renegotiateCiphers is a list of ciphersuite ids that will be
302 // switched in just before renegotiation.
303 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500304 // replayWrites, if true, configures the underlying transport
305 // to replay every write it makes in DTLS tests.
306 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500307 // damageFirstWrite, if true, configures the underlying transport to
308 // damage the final byte of the first application data write.
309 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400310 // exportKeyingMaterial, if non-zero, configures the test to exchange
311 // keying material and verify they match.
312 exportKeyingMaterial int
313 exportLabel string
314 exportContext string
315 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400316 // flags, if not empty, contains a list of command-line flags that will
317 // be passed to the shim program.
318 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700319 // testTLSUnique, if true, causes the shim to send the tls-unique value
320 // which will be compared against the expected value.
321 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400322 // sendEmptyRecords is the number of consecutive empty records to send
323 // before and after the test message.
324 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400325 // sendWarningAlerts is the number of consecutive warning alerts to send
326 // before and after the test message.
327 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400328 // expectMessageDropped, if true, means the test message is expected to
329 // be dropped by the client rather than echoed back.
330 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700331}
332
Adam Langley7c803a62015-06-15 15:35:05 -0700333var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700334
David Benjamin9867b7d2016-03-01 23:25:48 -0500335func writeTranscript(test *testCase, isResume bool, data []byte) {
336 if len(data) == 0 {
337 return
338 }
339
340 protocol := "tls"
341 if test.protocol == dtls {
342 protocol = "dtls"
343 }
344
345 side := "client"
346 if test.testType == serverTest {
347 side = "server"
348 }
349
350 dir := path.Join(*transcriptDir, protocol, side)
351 if err := os.MkdirAll(dir, 0755); err != nil {
352 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
353 return
354 }
355
356 name := test.name
357 if isResume {
358 name += "-Resume"
359 } else {
360 name += "-Normal"
361 }
362
363 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
364 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
365 }
366}
367
David Benjamin3ed59772016-03-08 12:50:21 -0500368// A timeoutConn implements an idle timeout on each Read and Write operation.
369type timeoutConn struct {
370 net.Conn
371 timeout time.Duration
372}
373
374func (t *timeoutConn) Read(b []byte) (int, error) {
375 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
376 return 0, err
377 }
378 return t.Conn.Read(b)
379}
380
381func (t *timeoutConn) Write(b []byte) (int, error) {
382 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
383 return 0, err
384 }
385 return t.Conn.Write(b)
386}
387
David Benjamin8e6db492015-07-25 18:29:23 -0400388func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400389 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500390
David Benjamin6fd297b2014-08-11 18:43:38 -0400391 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500392 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
393 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500394 }
395
David Benjamin9867b7d2016-03-01 23:25:48 -0500396 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500397 local, peer := "client", "server"
398 if test.testType == clientTest {
399 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500400 }
David Benjaminebda9b32015-11-02 15:33:18 -0500401 connDebug := &recordingConn{
402 Conn: conn,
403 isDatagram: test.protocol == dtls,
404 local: local,
405 peer: peer,
406 }
407 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500408 if *flagDebug {
409 defer connDebug.WriteTo(os.Stdout)
410 }
411 if len(*transcriptDir) != 0 {
412 defer func() {
413 writeTranscript(test, isResume, connDebug.Transcript())
414 }()
415 }
David Benjaminebda9b32015-11-02 15:33:18 -0500416
417 if config.Bugs.PacketAdaptor != nil {
418 config.Bugs.PacketAdaptor.debug = connDebug
419 }
420 }
421
422 if test.replayWrites {
423 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400424 }
425
David Benjamin3ed59772016-03-08 12:50:21 -0500426 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500427 if test.damageFirstWrite {
428 connDamage = newDamageAdaptor(conn)
429 conn = connDamage
430 }
431
David Benjamin6fd297b2014-08-11 18:43:38 -0400432 if test.sendPrefix != "" {
433 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
434 return err
435 }
David Benjamin98e882e2014-08-08 13:24:34 -0400436 }
437
David Benjamin1d5c83e2014-07-22 19:20:02 -0400438 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400439 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400440 if test.protocol == dtls {
441 tlsConn = DTLSServer(conn, config)
442 } else {
443 tlsConn = Server(conn, config)
444 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400445 } else {
446 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400447 if test.protocol == dtls {
448 tlsConn = DTLSClient(conn, config)
449 } else {
450 tlsConn = Client(conn, config)
451 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400452 }
David Benjamin30789da2015-08-29 22:56:45 -0400453 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400454
Adam Langley95c29f32014-06-20 12:00:00 -0700455 if err := tlsConn.Handshake(); err != nil {
456 return err
457 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700458
David Benjamin01fe8202014-09-24 15:21:44 -0400459 // TODO(davidben): move all per-connection expectations into a dedicated
460 // expectations struct that can be specified separately for the two
461 // legs.
462 expectedVersion := test.expectedVersion
463 if isResume && test.expectedResumeVersion != 0 {
464 expectedVersion = test.expectedResumeVersion
465 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700466 connState := tlsConn.ConnectionState()
467 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400468 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400469 }
470
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700471 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400472 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
473 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700474 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
475 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
476 }
David Benjamin90da8c82015-04-20 14:57:57 -0400477
David Benjamina08e49d2014-08-24 01:46:07 -0400478 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700479 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400480 if channelID == nil {
481 return fmt.Errorf("no channel ID negotiated")
482 }
483 if channelID.Curve != channelIDKey.Curve ||
484 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
485 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
486 return fmt.Errorf("incorrect channel ID")
487 }
488 }
489
David Benjaminae2888f2014-09-06 12:58:58 -0400490 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700491 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400492 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
493 }
494 }
495
David Benjaminc7ce9772015-10-09 19:32:41 -0400496 if test.expectNoNextProto {
497 if actual := connState.NegotiatedProtocol; actual != "" {
498 return fmt.Errorf("got unexpected next proto %s", actual)
499 }
500 }
501
David Benjaminfc7b0862014-09-06 13:21:53 -0400502 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700503 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400504 return fmt.Errorf("next proto type mismatch")
505 }
506 }
507
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700508 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500509 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
510 }
511
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100512 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300513 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100514 }
515
Paul Lietar4fac72e2015-09-09 13:44:55 +0100516 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
517 return fmt.Errorf("SCT list mismatch")
518 }
519
Nick Harper60edffd2016-06-21 15:19:24 -0700520 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
521 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400522 }
523
Steven Valdez5440fe02016-07-18 12:40:30 -0400524 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
525 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
526 }
527
David Benjaminc565ebb2015-04-03 04:06:36 -0400528 if test.exportKeyingMaterial > 0 {
529 actual := make([]byte, test.exportKeyingMaterial)
530 if _, err := io.ReadFull(tlsConn, actual); err != nil {
531 return err
532 }
533 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
534 if err != nil {
535 return err
536 }
537 if !bytes.Equal(actual, expected) {
538 return fmt.Errorf("keying material mismatch")
539 }
540 }
541
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700542 if test.testTLSUnique {
543 var peersValue [12]byte
544 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
545 return err
546 }
547 expected := tlsConn.ConnectionState().TLSUnique
548 if !bytes.Equal(peersValue[:], expected) {
549 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
550 }
551 }
552
David Benjamine58c4f52014-08-24 03:47:07 -0400553 if test.shimWritesFirst {
554 var buf [5]byte
555 _, err := io.ReadFull(tlsConn, buf[:])
556 if err != nil {
557 return err
558 }
559 if string(buf[:]) != "hello" {
560 return fmt.Errorf("bad initial message")
561 }
562 }
563
David Benjamina8ebe222015-06-06 03:04:39 -0400564 for i := 0; i < test.sendEmptyRecords; i++ {
565 tlsConn.Write(nil)
566 }
567
David Benjamin24f346d2015-06-06 03:28:08 -0400568 for i := 0; i < test.sendWarningAlerts; i++ {
569 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
570 }
571
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400572 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700573 if test.renegotiateCiphers != nil {
574 config.CipherSuites = test.renegotiateCiphers
575 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400576 for i := 0; i < test.renegotiate; i++ {
577 if err := tlsConn.Renegotiate(); err != nil {
578 return err
579 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700580 }
581 } else if test.renegotiateCiphers != nil {
582 panic("renegotiateCiphers without renegotiate")
583 }
584
David Benjamin5fa3eba2015-01-22 16:35:40 -0500585 if test.damageFirstWrite {
586 connDamage.setDamage(true)
587 tlsConn.Write([]byte("DAMAGED WRITE"))
588 connDamage.setDamage(false)
589 }
590
David Benjamin8e6db492015-07-25 18:29:23 -0400591 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700592 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400593 if test.protocol == dtls {
594 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
595 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700596 // Read until EOF.
597 _, err := io.Copy(ioutil.Discard, tlsConn)
598 return err
599 }
David Benjamin4417d052015-04-05 04:17:25 -0400600 if messageLen == 0 {
601 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700602 }
Adam Langley95c29f32014-06-20 12:00:00 -0700603
David Benjamin8e6db492015-07-25 18:29:23 -0400604 messageCount := test.messageCount
605 if messageCount == 0 {
606 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400607 }
608
David Benjamin8e6db492015-07-25 18:29:23 -0400609 for j := 0; j < messageCount; j++ {
610 testMessage := make([]byte, messageLen)
611 for i := range testMessage {
612 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400613 }
David Benjamin8e6db492015-07-25 18:29:23 -0400614 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700615
David Benjamin8e6db492015-07-25 18:29:23 -0400616 for i := 0; i < test.sendEmptyRecords; i++ {
617 tlsConn.Write(nil)
618 }
619
620 for i := 0; i < test.sendWarningAlerts; i++ {
621 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
622 }
623
David Benjamin4f75aaf2015-09-01 16:53:10 -0400624 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400625 // The shim will not respond.
626 continue
627 }
628
David Benjamin8e6db492015-07-25 18:29:23 -0400629 buf := make([]byte, len(testMessage))
630 if test.protocol == dtls {
631 bufTmp := make([]byte, len(buf)+1)
632 n, err := tlsConn.Read(bufTmp)
633 if err != nil {
634 return err
635 }
636 if n != len(buf) {
637 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
638 }
639 copy(buf, bufTmp)
640 } else {
641 _, err := io.ReadFull(tlsConn, buf)
642 if err != nil {
643 return err
644 }
645 }
646
647 for i, v := range buf {
648 if v != testMessage[i]^0xff {
649 return fmt.Errorf("bad reply contents at byte %d", i)
650 }
Adam Langley95c29f32014-06-20 12:00:00 -0700651 }
652 }
653
654 return nil
655}
656
David Benjamin325b5c32014-07-01 19:40:31 -0400657func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
658 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700659 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400660 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700661 }
David Benjamin325b5c32014-07-01 19:40:31 -0400662 valgrindArgs = append(valgrindArgs, path)
663 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700664
David Benjamin325b5c32014-07-01 19:40:31 -0400665 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700666}
667
David Benjamin325b5c32014-07-01 19:40:31 -0400668func gdbOf(path string, args ...string) *exec.Cmd {
669 xtermArgs := []string{"-e", "gdb", "--args"}
670 xtermArgs = append(xtermArgs, path)
671 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700672
David Benjamin325b5c32014-07-01 19:40:31 -0400673 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700674}
675
David Benjamind16bf342015-12-18 00:53:12 -0500676func lldbOf(path string, args ...string) *exec.Cmd {
677 xtermArgs := []string{"-e", "lldb", "--"}
678 xtermArgs = append(xtermArgs, path)
679 xtermArgs = append(xtermArgs, args...)
680
681 return exec.Command("xterm", xtermArgs...)
682}
683
Adam Langley69a01602014-11-17 17:26:55 -0800684type moreMallocsError struct{}
685
686func (moreMallocsError) Error() string {
687 return "child process did not exhaust all allocation calls"
688}
689
690var errMoreMallocs = moreMallocsError{}
691
David Benjamin87c8a642015-02-21 01:54:29 -0500692// accept accepts a connection from listener, unless waitChan signals a process
693// exit first.
694func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
695 type connOrError struct {
696 conn net.Conn
697 err error
698 }
699 connChan := make(chan connOrError, 1)
700 go func() {
701 conn, err := listener.Accept()
702 connChan <- connOrError{conn, err}
703 close(connChan)
704 }()
705 select {
706 case result := <-connChan:
707 return result.conn, result.err
708 case childErr := <-waitChan:
709 waitChan <- childErr
710 return nil, fmt.Errorf("child exited early: %s", childErr)
711 }
712}
713
Adam Langley7c803a62015-06-15 15:35:05 -0700714func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700715 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
716 panic("Error expected without shouldFail in " + test.name)
717 }
718
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700719 if test.expectResumeRejected && !test.resumeSession {
720 panic("expectResumeRejected without resumeSession in " + test.name)
721 }
722
David Benjamin87c8a642015-02-21 01:54:29 -0500723 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
724 if err != nil {
725 panic(err)
726 }
727 defer func() {
728 if listener != nil {
729 listener.Close()
730 }
731 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700732
David Benjamin87c8a642015-02-21 01:54:29 -0500733 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400734 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400735 flags = append(flags, "-server")
736
David Benjamin025b3d32014-07-01 19:53:04 -0400737 flags = append(flags, "-key-file")
738 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700739 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400740 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700741 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400742 }
743
744 flags = append(flags, "-cert-file")
745 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700746 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400747 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700748 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400749 }
750 }
David Benjamin5a593af2014-08-11 19:51:50 -0400751
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},
Steven Valdez143e8b32016-07-11 13:19:03 -0400951 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700952}
953
954var testCipherSuites = []struct {
955 name string
956 id uint16
957}{
958 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400959 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700960 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400961 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400962 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700963 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400964 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400965 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
966 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400967 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400968 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
969 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400970 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700971 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
972 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400973 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
974 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700975 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400976 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500977 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500978 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700979 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700980 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400982 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400983 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700984 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400985 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500986 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500987 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700988 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700989 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
990 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
991 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
992 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400993 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
994 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700995 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
996 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500997 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400998 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
999 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001000 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001001 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001002 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001003 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001004}
1005
David Benjamin8b8c0062014-11-23 02:47:52 -05001006func hasComponent(suiteName, component string) bool {
1007 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1008}
1009
David Benjaminf7768e42014-08-31 02:06:47 -04001010func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001011 return hasComponent(suiteName, "GCM") ||
1012 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001013 hasComponent(suiteName, "SHA384") ||
1014 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001015}
1016
Nick Harper1fd39d82016-06-14 18:14:35 -07001017func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001018 // Only AEADs.
1019 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1020 return false
1021 }
1022 // No old CHACHA20_POLY1305.
1023 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1024 return false
1025 }
1026 // Must have ECDHE.
1027 // TODO(davidben,svaldez): Add pure PSK support.
1028 if !hasComponent(suiteName, "ECDHE") {
1029 return false
1030 }
1031 // TODO(davidben,svaldez): Add PSK support.
1032 if hasComponent(suiteName, "PSK") {
1033 return false
1034 }
1035 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001036}
1037
David Benjamin8b8c0062014-11-23 02:47:52 -05001038func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001039 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001040}
1041
Adam Langleya7997f12015-05-14 17:38:50 -07001042func bigFromHex(hex string) *big.Int {
1043 ret, ok := new(big.Int).SetString(hex, 16)
1044 if !ok {
1045 panic("failed to parse hex number 0x" + hex)
1046 }
1047 return ret
1048}
1049
Adam Langley7c803a62015-06-15 15:35:05 -07001050func addBasicTests() {
1051 basicTests := []testCase{
1052 {
Adam Langley7c803a62015-06-15 15:35:05 -07001053 name: "NoFallbackSCSV",
1054 config: Config{
1055 Bugs: ProtocolBugs{
1056 FailIfNotFallbackSCSV: true,
1057 },
1058 },
1059 shouldFail: true,
1060 expectedLocalError: "no fallback SCSV found",
1061 },
1062 {
1063 name: "SendFallbackSCSV",
1064 config: Config{
1065 Bugs: ProtocolBugs{
1066 FailIfNotFallbackSCSV: true,
1067 },
1068 },
1069 flags: []string{"-fallback-scsv"},
1070 },
1071 {
1072 name: "ClientCertificateTypes",
1073 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001074 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001075 ClientAuth: RequestClientCert,
1076 ClientCertificateTypes: []byte{
1077 CertTypeDSSSign,
1078 CertTypeRSASign,
1079 CertTypeECDSASign,
1080 },
1081 },
1082 flags: []string{
1083 "-expect-certificate-types",
1084 base64.StdEncoding.EncodeToString([]byte{
1085 CertTypeDSSSign,
1086 CertTypeRSASign,
1087 CertTypeECDSASign,
1088 }),
1089 },
1090 },
1091 {
Adam Langley7c803a62015-06-15 15:35:05 -07001092 name: "UnauthenticatedECDH",
1093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001094 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001095 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1096 Bugs: ProtocolBugs{
1097 UnauthenticatedECDH: true,
1098 },
1099 },
1100 shouldFail: true,
1101 expectedError: ":UNEXPECTED_MESSAGE:",
1102 },
1103 {
1104 name: "SkipCertificateStatus",
1105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001106 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001107 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1108 Bugs: ProtocolBugs{
1109 SkipCertificateStatus: true,
1110 },
1111 },
1112 flags: []string{
1113 "-enable-ocsp-stapling",
1114 },
1115 },
1116 {
1117 name: "SkipServerKeyExchange",
1118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001119 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001120 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1121 Bugs: ProtocolBugs{
1122 SkipServerKeyExchange: true,
1123 },
1124 },
1125 shouldFail: true,
1126 expectedError: ":UNEXPECTED_MESSAGE:",
1127 },
1128 {
Adam Langley7c803a62015-06-15 15:35:05 -07001129 testType: serverTest,
1130 name: "Alert",
1131 config: Config{
1132 Bugs: ProtocolBugs{
1133 SendSpuriousAlert: alertRecordOverflow,
1134 },
1135 },
1136 shouldFail: true,
1137 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1138 },
1139 {
1140 protocol: dtls,
1141 testType: serverTest,
1142 name: "Alert-DTLS",
1143 config: Config{
1144 Bugs: ProtocolBugs{
1145 SendSpuriousAlert: alertRecordOverflow,
1146 },
1147 },
1148 shouldFail: true,
1149 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1150 },
1151 {
1152 testType: serverTest,
1153 name: "FragmentAlert",
1154 config: Config{
1155 Bugs: ProtocolBugs{
1156 FragmentAlert: true,
1157 SendSpuriousAlert: alertRecordOverflow,
1158 },
1159 },
1160 shouldFail: true,
1161 expectedError: ":BAD_ALERT:",
1162 },
1163 {
1164 protocol: dtls,
1165 testType: serverTest,
1166 name: "FragmentAlert-DTLS",
1167 config: Config{
1168 Bugs: ProtocolBugs{
1169 FragmentAlert: true,
1170 SendSpuriousAlert: alertRecordOverflow,
1171 },
1172 },
1173 shouldFail: true,
1174 expectedError: ":BAD_ALERT:",
1175 },
1176 {
1177 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001178 name: "DoubleAlert",
1179 config: Config{
1180 Bugs: ProtocolBugs{
1181 DoubleAlert: true,
1182 SendSpuriousAlert: alertRecordOverflow,
1183 },
1184 },
1185 shouldFail: true,
1186 expectedError: ":BAD_ALERT:",
1187 },
1188 {
1189 protocol: dtls,
1190 testType: serverTest,
1191 name: "DoubleAlert-DTLS",
1192 config: Config{
1193 Bugs: ProtocolBugs{
1194 DoubleAlert: true,
1195 SendSpuriousAlert: alertRecordOverflow,
1196 },
1197 },
1198 shouldFail: true,
1199 expectedError: ":BAD_ALERT:",
1200 },
1201 {
Adam Langley7c803a62015-06-15 15:35:05 -07001202 name: "SkipNewSessionTicket",
1203 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001204 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001205 Bugs: ProtocolBugs{
1206 SkipNewSessionTicket: true,
1207 },
1208 },
1209 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001210 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001211 },
1212 {
1213 testType: serverTest,
1214 name: "FallbackSCSV",
1215 config: Config{
1216 MaxVersion: VersionTLS11,
1217 Bugs: ProtocolBugs{
1218 SendFallbackSCSV: true,
1219 },
1220 },
1221 shouldFail: true,
1222 expectedError: ":INAPPROPRIATE_FALLBACK:",
1223 },
1224 {
1225 testType: serverTest,
1226 name: "FallbackSCSV-VersionMatch",
1227 config: Config{
1228 Bugs: ProtocolBugs{
1229 SendFallbackSCSV: true,
1230 },
1231 },
1232 },
1233 {
1234 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001235 name: "FallbackSCSV-VersionMatch-TLS12",
1236 config: Config{
1237 MaxVersion: VersionTLS12,
1238 Bugs: ProtocolBugs{
1239 SendFallbackSCSV: true,
1240 },
1241 },
1242 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1243 },
1244 {
1245 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001246 name: "FragmentedClientVersion",
1247 config: Config{
1248 Bugs: ProtocolBugs{
1249 MaxHandshakeRecordLength: 1,
1250 FragmentClientVersion: true,
1251 },
1252 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001253 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001254 },
1255 {
Adam Langley7c803a62015-06-15 15:35:05 -07001256 testType: serverTest,
1257 name: "HttpGET",
1258 sendPrefix: "GET / HTTP/1.0\n",
1259 shouldFail: true,
1260 expectedError: ":HTTP_REQUEST:",
1261 },
1262 {
1263 testType: serverTest,
1264 name: "HttpPOST",
1265 sendPrefix: "POST / HTTP/1.0\n",
1266 shouldFail: true,
1267 expectedError: ":HTTP_REQUEST:",
1268 },
1269 {
1270 testType: serverTest,
1271 name: "HttpHEAD",
1272 sendPrefix: "HEAD / HTTP/1.0\n",
1273 shouldFail: true,
1274 expectedError: ":HTTP_REQUEST:",
1275 },
1276 {
1277 testType: serverTest,
1278 name: "HttpPUT",
1279 sendPrefix: "PUT / HTTP/1.0\n",
1280 shouldFail: true,
1281 expectedError: ":HTTP_REQUEST:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "HttpCONNECT",
1286 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1287 shouldFail: true,
1288 expectedError: ":HTTPS_PROXY_REQUEST:",
1289 },
1290 {
1291 testType: serverTest,
1292 name: "Garbage",
1293 sendPrefix: "blah",
1294 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001295 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001296 },
1297 {
Adam Langley7c803a62015-06-15 15:35:05 -07001298 name: "RSAEphemeralKey",
1299 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001300 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001301 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1302 Bugs: ProtocolBugs{
1303 RSAEphemeralKey: true,
1304 },
1305 },
1306 shouldFail: true,
1307 expectedError: ":UNEXPECTED_MESSAGE:",
1308 },
1309 {
1310 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001311 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001312 shouldFail: true,
1313 expectedError: ":WRONG_SSL_VERSION:",
1314 },
1315 {
1316 protocol: dtls,
1317 name: "DisableEverything-DTLS",
1318 flags: []string{"-no-tls12", "-no-tls1"},
1319 shouldFail: true,
1320 expectedError: ":WRONG_SSL_VERSION:",
1321 },
1322 {
Adam Langley7c803a62015-06-15 15:35:05 -07001323 protocol: dtls,
1324 testType: serverTest,
1325 name: "MTU",
1326 config: Config{
1327 Bugs: ProtocolBugs{
1328 MaxPacketLength: 256,
1329 },
1330 },
1331 flags: []string{"-mtu", "256"},
1332 },
1333 {
1334 protocol: dtls,
1335 testType: serverTest,
1336 name: "MTUExceeded",
1337 config: Config{
1338 Bugs: ProtocolBugs{
1339 MaxPacketLength: 255,
1340 },
1341 },
1342 flags: []string{"-mtu", "256"},
1343 shouldFail: true,
1344 expectedLocalError: "dtls: exceeded maximum packet length",
1345 },
1346 {
1347 name: "CertMismatchRSA",
1348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001349 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001350 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001351 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001352 Bugs: ProtocolBugs{
1353 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1354 },
1355 },
1356 shouldFail: true,
1357 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1358 },
1359 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001360 name: "CertMismatchRSA-TLS13",
1361 config: Config{
1362 MaxVersion: VersionTLS13,
1363 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1364 Certificates: []Certificate{ecdsaP256Certificate},
1365 Bugs: ProtocolBugs{
1366 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1367 },
1368 },
1369 shouldFail: true,
1370 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1371 },
1372 {
Adam Langley7c803a62015-06-15 15:35:05 -07001373 name: "CertMismatchECDSA",
1374 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001375 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001377 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001378 Bugs: ProtocolBugs{
1379 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1380 },
1381 },
1382 shouldFail: true,
1383 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1384 },
1385 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001386 name: "CertMismatchECDSA-TLS13",
1387 config: Config{
1388 MaxVersion: VersionTLS13,
1389 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1390 Certificates: []Certificate{rsaCertificate},
1391 Bugs: ProtocolBugs{
1392 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1393 },
1394 },
1395 shouldFail: true,
1396 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1397 },
1398 {
Adam Langley7c803a62015-06-15 15:35:05 -07001399 name: "EmptyCertificateList",
1400 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001401 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001402 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1403 Bugs: ProtocolBugs{
1404 EmptyCertificateList: true,
1405 },
1406 },
1407 shouldFail: true,
1408 expectedError: ":DECODE_ERROR:",
1409 },
1410 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001411 name: "EmptyCertificateList-TLS13",
1412 config: Config{
1413 MaxVersion: VersionTLS13,
1414 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1415 Bugs: ProtocolBugs{
1416 EmptyCertificateList: true,
1417 },
1418 },
1419 shouldFail: true,
1420 expectedError: ":DECODE_ERROR:",
1421 },
1422 {
Adam Langley7c803a62015-06-15 15:35:05 -07001423 name: "TLSFatalBadPackets",
1424 damageFirstWrite: true,
1425 shouldFail: true,
1426 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1427 },
1428 {
1429 protocol: dtls,
1430 name: "DTLSIgnoreBadPackets",
1431 damageFirstWrite: true,
1432 },
1433 {
1434 protocol: dtls,
1435 name: "DTLSIgnoreBadPackets-Async",
1436 damageFirstWrite: true,
1437 flags: []string{"-async"},
1438 },
1439 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001440 name: "AppDataBeforeHandshake",
1441 config: Config{
1442 Bugs: ProtocolBugs{
1443 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1444 },
1445 },
1446 shouldFail: true,
1447 expectedError: ":UNEXPECTED_RECORD:",
1448 },
1449 {
1450 name: "AppDataBeforeHandshake-Empty",
1451 config: Config{
1452 Bugs: ProtocolBugs{
1453 AppDataBeforeHandshake: []byte{},
1454 },
1455 },
1456 shouldFail: true,
1457 expectedError: ":UNEXPECTED_RECORD:",
1458 },
1459 {
1460 protocol: dtls,
1461 name: "AppDataBeforeHandshake-DTLS",
1462 config: Config{
1463 Bugs: ProtocolBugs{
1464 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1465 },
1466 },
1467 shouldFail: true,
1468 expectedError: ":UNEXPECTED_RECORD:",
1469 },
1470 {
1471 protocol: dtls,
1472 name: "AppDataBeforeHandshake-DTLS-Empty",
1473 config: Config{
1474 Bugs: ProtocolBugs{
1475 AppDataBeforeHandshake: []byte{},
1476 },
1477 },
1478 shouldFail: true,
1479 expectedError: ":UNEXPECTED_RECORD:",
1480 },
1481 {
Adam Langley7c803a62015-06-15 15:35:05 -07001482 name: "AppDataAfterChangeCipherSpec",
1483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001484 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001485 Bugs: ProtocolBugs{
1486 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1487 },
1488 },
1489 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001490 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001491 },
1492 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001493 name: "AppDataAfterChangeCipherSpec-Empty",
1494 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001495 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001496 Bugs: ProtocolBugs{
1497 AppDataAfterChangeCipherSpec: []byte{},
1498 },
1499 },
1500 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001501 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001502 },
1503 {
Adam Langley7c803a62015-06-15 15:35:05 -07001504 protocol: dtls,
1505 name: "AppDataAfterChangeCipherSpec-DTLS",
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 // BoringSSL's DTLS implementation will drop the out-of-order
1513 // application data.
1514 },
1515 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001516 protocol: dtls,
1517 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1518 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001519 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001520 Bugs: ProtocolBugs{
1521 AppDataAfterChangeCipherSpec: []byte{},
1522 },
1523 },
1524 // BoringSSL's DTLS implementation will drop the out-of-order
1525 // application data.
1526 },
1527 {
Adam Langley7c803a62015-06-15 15:35:05 -07001528 name: "AlertAfterChangeCipherSpec",
1529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001530 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001531 Bugs: ProtocolBugs{
1532 AlertAfterChangeCipherSpec: alertRecordOverflow,
1533 },
1534 },
1535 shouldFail: true,
1536 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1537 },
1538 {
1539 protocol: dtls,
1540 name: "AlertAfterChangeCipherSpec-DTLS",
1541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001542 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001543 Bugs: ProtocolBugs{
1544 AlertAfterChangeCipherSpec: alertRecordOverflow,
1545 },
1546 },
1547 shouldFail: true,
1548 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1549 },
1550 {
1551 protocol: dtls,
1552 name: "ReorderHandshakeFragments-Small-DTLS",
1553 config: Config{
1554 Bugs: ProtocolBugs{
1555 ReorderHandshakeFragments: true,
1556 // Small enough that every handshake message is
1557 // fragmented.
1558 MaxHandshakeRecordLength: 2,
1559 },
1560 },
1561 },
1562 {
1563 protocol: dtls,
1564 name: "ReorderHandshakeFragments-Large-DTLS",
1565 config: Config{
1566 Bugs: ProtocolBugs{
1567 ReorderHandshakeFragments: true,
1568 // Large enough that no handshake message is
1569 // fragmented.
1570 MaxHandshakeRecordLength: 2048,
1571 },
1572 },
1573 },
1574 {
1575 protocol: dtls,
1576 name: "MixCompleteMessageWithFragments-DTLS",
1577 config: Config{
1578 Bugs: ProtocolBugs{
1579 ReorderHandshakeFragments: true,
1580 MixCompleteMessageWithFragments: true,
1581 MaxHandshakeRecordLength: 2,
1582 },
1583 },
1584 },
1585 {
1586 name: "SendInvalidRecordType",
1587 config: Config{
1588 Bugs: ProtocolBugs{
1589 SendInvalidRecordType: true,
1590 },
1591 },
1592 shouldFail: true,
1593 expectedError: ":UNEXPECTED_RECORD:",
1594 },
1595 {
1596 protocol: dtls,
1597 name: "SendInvalidRecordType-DTLS",
1598 config: Config{
1599 Bugs: ProtocolBugs{
1600 SendInvalidRecordType: true,
1601 },
1602 },
1603 shouldFail: true,
1604 expectedError: ":UNEXPECTED_RECORD:",
1605 },
1606 {
1607 name: "FalseStart-SkipServerSecondLeg",
1608 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001609 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001610 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1611 NextProtos: []string{"foo"},
1612 Bugs: ProtocolBugs{
1613 SkipNewSessionTicket: true,
1614 SkipChangeCipherSpec: true,
1615 SkipFinished: true,
1616 ExpectFalseStart: true,
1617 },
1618 },
1619 flags: []string{
1620 "-false-start",
1621 "-handshake-never-done",
1622 "-advertise-alpn", "\x03foo",
1623 },
1624 shimWritesFirst: true,
1625 shouldFail: true,
1626 expectedError: ":UNEXPECTED_RECORD:",
1627 },
1628 {
1629 name: "FalseStart-SkipServerSecondLeg-Implicit",
1630 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001631 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001632 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1633 NextProtos: []string{"foo"},
1634 Bugs: ProtocolBugs{
1635 SkipNewSessionTicket: true,
1636 SkipChangeCipherSpec: true,
1637 SkipFinished: true,
1638 },
1639 },
1640 flags: []string{
1641 "-implicit-handshake",
1642 "-false-start",
1643 "-handshake-never-done",
1644 "-advertise-alpn", "\x03foo",
1645 },
1646 shouldFail: true,
1647 expectedError: ":UNEXPECTED_RECORD:",
1648 },
1649 {
1650 testType: serverTest,
1651 name: "FailEarlyCallback",
1652 flags: []string{"-fail-early-callback"},
1653 shouldFail: true,
1654 expectedError: ":CONNECTION_REJECTED:",
1655 expectedLocalError: "remote error: access denied",
1656 },
1657 {
Adam Langley7c803a62015-06-15 15:35:05 -07001658 protocol: dtls,
1659 name: "FragmentMessageTypeMismatch-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 MaxHandshakeRecordLength: 2,
1663 FragmentMessageTypeMismatch: true,
1664 },
1665 },
1666 shouldFail: true,
1667 expectedError: ":FRAGMENT_MISMATCH:",
1668 },
1669 {
1670 protocol: dtls,
1671 name: "FragmentMessageLengthMismatch-DTLS",
1672 config: Config{
1673 Bugs: ProtocolBugs{
1674 MaxHandshakeRecordLength: 2,
1675 FragmentMessageLengthMismatch: true,
1676 },
1677 },
1678 shouldFail: true,
1679 expectedError: ":FRAGMENT_MISMATCH:",
1680 },
1681 {
1682 protocol: dtls,
1683 name: "SplitFragments-Header-DTLS",
1684 config: Config{
1685 Bugs: ProtocolBugs{
1686 SplitFragments: 2,
1687 },
1688 },
1689 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001690 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001691 },
1692 {
1693 protocol: dtls,
1694 name: "SplitFragments-Boundary-DTLS",
1695 config: Config{
1696 Bugs: ProtocolBugs{
1697 SplitFragments: dtlsRecordHeaderLen,
1698 },
1699 },
1700 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001701 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001702 },
1703 {
1704 protocol: dtls,
1705 name: "SplitFragments-Body-DTLS",
1706 config: Config{
1707 Bugs: ProtocolBugs{
1708 SplitFragments: dtlsRecordHeaderLen + 1,
1709 },
1710 },
1711 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001712 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001713 },
1714 {
1715 protocol: dtls,
1716 name: "SendEmptyFragments-DTLS",
1717 config: Config{
1718 Bugs: ProtocolBugs{
1719 SendEmptyFragments: true,
1720 },
1721 },
1722 },
1723 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001724 name: "BadFinished-Client",
1725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001726 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001727 Bugs: ProtocolBugs{
1728 BadFinished: true,
1729 },
1730 },
1731 shouldFail: true,
1732 expectedError: ":DIGEST_CHECK_FAILED:",
1733 },
1734 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001735 name: "BadFinished-Client-TLS13",
1736 config: Config{
1737 MaxVersion: VersionTLS13,
1738 Bugs: ProtocolBugs{
1739 BadFinished: true,
1740 },
1741 },
1742 shouldFail: true,
1743 expectedError: ":DIGEST_CHECK_FAILED:",
1744 },
1745 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001746 testType: serverTest,
1747 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001748 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001749 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001750 Bugs: ProtocolBugs{
1751 BadFinished: true,
1752 },
1753 },
1754 shouldFail: true,
1755 expectedError: ":DIGEST_CHECK_FAILED:",
1756 },
1757 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001758 testType: serverTest,
1759 name: "BadFinished-Server-TLS13",
1760 config: Config{
1761 MaxVersion: VersionTLS13,
1762 Bugs: ProtocolBugs{
1763 BadFinished: true,
1764 },
1765 },
1766 shouldFail: true,
1767 expectedError: ":DIGEST_CHECK_FAILED:",
1768 },
1769 {
Adam Langley7c803a62015-06-15 15:35:05 -07001770 name: "FalseStart-BadFinished",
1771 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001772 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1774 NextProtos: []string{"foo"},
1775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 ExpectFalseStart: true,
1778 },
1779 },
1780 flags: []string{
1781 "-false-start",
1782 "-handshake-never-done",
1783 "-advertise-alpn", "\x03foo",
1784 },
1785 shimWritesFirst: true,
1786 shouldFail: true,
1787 expectedError: ":DIGEST_CHECK_FAILED:",
1788 },
1789 {
1790 name: "NoFalseStart-NoALPN",
1791 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001792 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001793 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1794 Bugs: ProtocolBugs{
1795 ExpectFalseStart: true,
1796 AlertBeforeFalseStartTest: alertAccessDenied,
1797 },
1798 },
1799 flags: []string{
1800 "-false-start",
1801 },
1802 shimWritesFirst: true,
1803 shouldFail: true,
1804 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1805 expectedLocalError: "tls: peer did not false start: EOF",
1806 },
1807 {
1808 name: "NoFalseStart-NoAEAD",
1809 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001810 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001811 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1812 NextProtos: []string{"foo"},
1813 Bugs: ProtocolBugs{
1814 ExpectFalseStart: true,
1815 AlertBeforeFalseStartTest: alertAccessDenied,
1816 },
1817 },
1818 flags: []string{
1819 "-false-start",
1820 "-advertise-alpn", "\x03foo",
1821 },
1822 shimWritesFirst: true,
1823 shouldFail: true,
1824 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1825 expectedLocalError: "tls: peer did not false start: EOF",
1826 },
1827 {
1828 name: "NoFalseStart-RSA",
1829 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001830 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001831 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1832 NextProtos: []string{"foo"},
1833 Bugs: ProtocolBugs{
1834 ExpectFalseStart: true,
1835 AlertBeforeFalseStartTest: alertAccessDenied,
1836 },
1837 },
1838 flags: []string{
1839 "-false-start",
1840 "-advertise-alpn", "\x03foo",
1841 },
1842 shimWritesFirst: true,
1843 shouldFail: true,
1844 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1845 expectedLocalError: "tls: peer did not false start: EOF",
1846 },
1847 {
1848 name: "NoFalseStart-DHE_RSA",
1849 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001850 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001851 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1852 NextProtos: []string{"foo"},
1853 Bugs: ProtocolBugs{
1854 ExpectFalseStart: true,
1855 AlertBeforeFalseStartTest: alertAccessDenied,
1856 },
1857 },
1858 flags: []string{
1859 "-false-start",
1860 "-advertise-alpn", "\x03foo",
1861 },
1862 shimWritesFirst: true,
1863 shouldFail: true,
1864 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1865 expectedLocalError: "tls: peer did not false start: EOF",
1866 },
1867 {
Adam Langley7c803a62015-06-15 15:35:05 -07001868 protocol: dtls,
1869 name: "SendSplitAlert-Sync",
1870 config: Config{
1871 Bugs: ProtocolBugs{
1872 SendSplitAlert: true,
1873 },
1874 },
1875 },
1876 {
1877 protocol: dtls,
1878 name: "SendSplitAlert-Async",
1879 config: Config{
1880 Bugs: ProtocolBugs{
1881 SendSplitAlert: true,
1882 },
1883 },
1884 flags: []string{"-async"},
1885 },
1886 {
1887 protocol: dtls,
1888 name: "PackDTLSHandshake",
1889 config: Config{
1890 Bugs: ProtocolBugs{
1891 MaxHandshakeRecordLength: 2,
1892 PackHandshakeFragments: 20,
1893 PackHandshakeRecords: 200,
1894 },
1895 },
1896 },
1897 {
Adam Langley7c803a62015-06-15 15:35:05 -07001898 name: "SendEmptyRecords-Pass",
1899 sendEmptyRecords: 32,
1900 },
1901 {
1902 name: "SendEmptyRecords",
1903 sendEmptyRecords: 33,
1904 shouldFail: true,
1905 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1906 },
1907 {
1908 name: "SendEmptyRecords-Async",
1909 sendEmptyRecords: 33,
1910 flags: []string{"-async"},
1911 shouldFail: true,
1912 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1913 },
1914 {
1915 name: "SendWarningAlerts-Pass",
1916 sendWarningAlerts: 4,
1917 },
1918 {
1919 protocol: dtls,
1920 name: "SendWarningAlerts-DTLS-Pass",
1921 sendWarningAlerts: 4,
1922 },
1923 {
1924 name: "SendWarningAlerts",
1925 sendWarningAlerts: 5,
1926 shouldFail: true,
1927 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1928 },
1929 {
1930 name: "SendWarningAlerts-Async",
1931 sendWarningAlerts: 5,
1932 flags: []string{"-async"},
1933 shouldFail: true,
1934 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1935 },
David Benjaminba4594a2015-06-18 18:36:15 -04001936 {
1937 name: "EmptySessionID",
1938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001939 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001940 SessionTicketsDisabled: true,
1941 },
1942 noSessionCache: true,
1943 flags: []string{"-expect-no-session"},
1944 },
David Benjamin30789da2015-08-29 22:56:45 -04001945 {
1946 name: "Unclean-Shutdown",
1947 config: Config{
1948 Bugs: ProtocolBugs{
1949 NoCloseNotify: true,
1950 ExpectCloseNotify: true,
1951 },
1952 },
1953 shimShutsDown: true,
1954 flags: []string{"-check-close-notify"},
1955 shouldFail: true,
1956 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1957 },
1958 {
1959 name: "Unclean-Shutdown-Ignored",
1960 config: Config{
1961 Bugs: ProtocolBugs{
1962 NoCloseNotify: true,
1963 },
1964 },
1965 shimShutsDown: true,
1966 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001967 {
David Benjaminfa214e42016-05-10 17:03:10 -04001968 name: "Unclean-Shutdown-Alert",
1969 config: Config{
1970 Bugs: ProtocolBugs{
1971 SendAlertOnShutdown: alertDecompressionFailure,
1972 ExpectCloseNotify: true,
1973 },
1974 },
1975 shimShutsDown: true,
1976 flags: []string{"-check-close-notify"},
1977 shouldFail: true,
1978 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1979 },
1980 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001981 name: "LargePlaintext",
1982 config: Config{
1983 Bugs: ProtocolBugs{
1984 SendLargeRecords: true,
1985 },
1986 },
1987 messageLen: maxPlaintext + 1,
1988 shouldFail: true,
1989 expectedError: ":DATA_LENGTH_TOO_LONG:",
1990 },
1991 {
1992 protocol: dtls,
1993 name: "LargePlaintext-DTLS",
1994 config: Config{
1995 Bugs: ProtocolBugs{
1996 SendLargeRecords: true,
1997 },
1998 },
1999 messageLen: maxPlaintext + 1,
2000 shouldFail: true,
2001 expectedError: ":DATA_LENGTH_TOO_LONG:",
2002 },
2003 {
2004 name: "LargeCiphertext",
2005 config: Config{
2006 Bugs: ProtocolBugs{
2007 SendLargeRecords: true,
2008 },
2009 },
2010 messageLen: maxPlaintext * 2,
2011 shouldFail: true,
2012 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2013 },
2014 {
2015 protocol: dtls,
2016 name: "LargeCiphertext-DTLS",
2017 config: Config{
2018 Bugs: ProtocolBugs{
2019 SendLargeRecords: true,
2020 },
2021 },
2022 messageLen: maxPlaintext * 2,
2023 // Unlike the other four cases, DTLS drops records which
2024 // are invalid before authentication, so the connection
2025 // does not fail.
2026 expectMessageDropped: true,
2027 },
David Benjamindd6fed92015-10-23 17:41:12 -04002028 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002029 // In TLS 1.2 and below, empty NewSessionTicket messages
2030 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002031 name: "SendEmptySessionTicket",
2032 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002033 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002034 Bugs: ProtocolBugs{
2035 SendEmptySessionTicket: true,
2036 FailIfSessionOffered: true,
2037 },
2038 },
2039 flags: []string{"-expect-no-session"},
2040 resumeSession: true,
2041 expectResumeRejected: true,
2042 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002043 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002044 name: "BadHelloRequest-1",
2045 renegotiate: 1,
2046 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002047 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002048 Bugs: ProtocolBugs{
2049 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2050 },
2051 },
2052 flags: []string{
2053 "-renegotiate-freely",
2054 "-expect-total-renegotiations", "1",
2055 },
2056 shouldFail: true,
2057 expectedError: ":BAD_HELLO_REQUEST:",
2058 },
2059 {
2060 name: "BadHelloRequest-2",
2061 renegotiate: 1,
2062 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002063 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002064 Bugs: ProtocolBugs{
2065 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2066 },
2067 },
2068 flags: []string{
2069 "-renegotiate-freely",
2070 "-expect-total-renegotiations", "1",
2071 },
2072 shouldFail: true,
2073 expectedError: ":BAD_HELLO_REQUEST:",
2074 },
David Benjaminef1b0092015-11-21 14:05:44 -05002075 {
2076 testType: serverTest,
2077 name: "SupportTicketsWithSessionID",
2078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002079 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002080 SessionTicketsDisabled: true,
2081 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002082 resumeConfig: &Config{
2083 MaxVersion: VersionTLS12,
2084 },
David Benjaminef1b0092015-11-21 14:05:44 -05002085 resumeSession: true,
2086 },
Adam Langley7c803a62015-06-15 15:35:05 -07002087 }
Adam Langley7c803a62015-06-15 15:35:05 -07002088 testCases = append(testCases, basicTests...)
2089}
2090
Adam Langley95c29f32014-06-20 12:00:00 -07002091func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002092 const bogusCipher = 0xfe00
2093
Adam Langley95c29f32014-06-20 12:00:00 -07002094 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002095 const psk = "12345"
2096 const pskIdentity = "luggage combo"
2097
Adam Langley95c29f32014-06-20 12:00:00 -07002098 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002099 var certFile string
2100 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002101 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002102 cert = ecdsaP256Certificate
2103 certFile = ecdsaP256CertificateFile
2104 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002105 } else {
David Benjamin33863262016-07-08 17:20:12 -07002106 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002107 certFile = rsaCertificateFile
2108 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002109 }
2110
David Benjamin48cae082014-10-27 01:06:24 -04002111 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002112 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002113 flags = append(flags,
2114 "-psk", psk,
2115 "-psk-identity", pskIdentity)
2116 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002117 if hasComponent(suite.name, "NULL") {
2118 // NULL ciphers must be explicitly enabled.
2119 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2120 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002121 if hasComponent(suite.name, "CECPQ1") {
2122 // CECPQ1 ciphers must be explicitly enabled.
2123 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2124 }
David Benjamin48cae082014-10-27 01:06:24 -04002125
Adam Langley95c29f32014-06-20 12:00:00 -07002126 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002127 for _, protocol := range []protocol{tls, dtls} {
2128 var prefix string
2129 if protocol == dtls {
2130 if !ver.hasDTLS {
2131 continue
2132 }
2133 prefix = "D"
2134 }
Adam Langley95c29f32014-06-20 12:00:00 -07002135
David Benjamin0407e762016-06-17 16:41:18 -04002136 var shouldServerFail, shouldClientFail bool
2137 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2138 // BoringSSL clients accept ECDHE on SSLv3, but
2139 // a BoringSSL server will never select it
2140 // because the extension is missing.
2141 shouldServerFail = true
2142 }
2143 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2144 shouldClientFail = true
2145 shouldServerFail = true
2146 }
David Benjamin54c217c2016-07-13 12:35:25 -04002147 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002148 shouldClientFail = true
2149 shouldServerFail = true
2150 }
David Benjamin0407e762016-06-17 16:41:18 -04002151 if !isDTLSCipher(suite.name) && protocol == dtls {
2152 shouldClientFail = true
2153 shouldServerFail = true
2154 }
David Benjamin4298d772015-12-19 00:18:25 -05002155
David Benjamin0407e762016-06-17 16:41:18 -04002156 var expectedServerError, expectedClientError string
2157 if shouldServerFail {
2158 expectedServerError = ":NO_SHARED_CIPHER:"
2159 }
2160 if shouldClientFail {
2161 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2162 }
David Benjamin025b3d32014-07-01 19:53:04 -04002163
David Benjamin9deb1172016-07-13 17:13:49 -04002164 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2165 resumeSession := ver.version < VersionTLS13
2166
David Benjamin6fd297b2014-08-11 18:43:38 -04002167 testCases = append(testCases, testCase{
2168 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002169 protocol: protocol,
2170
2171 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002172 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002173 MinVersion: ver.version,
2174 MaxVersion: ver.version,
2175 CipherSuites: []uint16{suite.id},
2176 Certificates: []Certificate{cert},
2177 PreSharedKey: []byte(psk),
2178 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002179 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002180 EnableAllCiphers: shouldServerFail,
2181 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002182 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002183 },
2184 certFile: certFile,
2185 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002186 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002187 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002188 shouldFail: shouldServerFail,
2189 expectedError: expectedServerError,
2190 })
2191
2192 testCases = append(testCases, testCase{
2193 testType: clientTest,
2194 protocol: protocol,
2195 name: prefix + ver.name + "-" + suite.name + "-client",
2196 config: Config{
2197 MinVersion: ver.version,
2198 MaxVersion: ver.version,
2199 CipherSuites: []uint16{suite.id},
2200 Certificates: []Certificate{cert},
2201 PreSharedKey: []byte(psk),
2202 PreSharedKeyIdentity: pskIdentity,
2203 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002204 EnableAllCiphers: shouldClientFail,
2205 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002206 },
2207 },
2208 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002209 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002210 shouldFail: shouldClientFail,
2211 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002212 })
David Benjamin2c99d282015-09-01 10:23:00 -04002213
Nick Harper1fd39d82016-06-14 18:14:35 -07002214 if !shouldClientFail {
2215 // Ensure the maximum record size is accepted.
2216 testCases = append(testCases, testCase{
2217 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2218 config: Config{
2219 MinVersion: ver.version,
2220 MaxVersion: ver.version,
2221 CipherSuites: []uint16{suite.id},
2222 Certificates: []Certificate{cert},
2223 PreSharedKey: []byte(psk),
2224 PreSharedKeyIdentity: pskIdentity,
2225 },
2226 flags: flags,
2227 messageLen: maxPlaintext,
2228 })
2229 }
2230 }
David Benjamin2c99d282015-09-01 10:23:00 -04002231 }
Adam Langley95c29f32014-06-20 12:00:00 -07002232 }
Adam Langleya7997f12015-05-14 17:38:50 -07002233
2234 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002235 name: "NoSharedCipher",
2236 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002237 MaxVersion: VersionTLS12,
2238 CipherSuites: []uint16{},
2239 },
2240 shouldFail: true,
2241 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2242 })
2243
2244 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002245 name: "NoSharedCipher-TLS13",
2246 config: Config{
2247 MaxVersion: VersionTLS13,
2248 CipherSuites: []uint16{},
2249 },
2250 shouldFail: true,
2251 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2252 })
2253
2254 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002255 name: "UnsupportedCipherSuite",
2256 config: Config{
2257 MaxVersion: VersionTLS12,
2258 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2259 Bugs: ProtocolBugs{
2260 IgnorePeerCipherPreferences: true,
2261 },
2262 },
2263 flags: []string{"-cipher", "DEFAULT:!RC4"},
2264 shouldFail: true,
2265 expectedError: ":WRONG_CIPHER_RETURNED:",
2266 })
2267
2268 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002269 name: "ServerHelloBogusCipher",
2270 config: Config{
2271 MaxVersion: VersionTLS12,
2272 Bugs: ProtocolBugs{
2273 SendCipherSuite: bogusCipher,
2274 },
2275 },
2276 shouldFail: true,
2277 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2278 })
2279 testCases = append(testCases, testCase{
2280 name: "ServerHelloBogusCipher-TLS13",
2281 config: Config{
2282 MaxVersion: VersionTLS13,
2283 Bugs: ProtocolBugs{
2284 SendCipherSuite: bogusCipher,
2285 },
2286 },
2287 shouldFail: true,
2288 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2289 })
2290
2291 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002292 name: "WeakDH",
2293 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002294 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002295 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2296 Bugs: ProtocolBugs{
2297 // This is a 1023-bit prime number, generated
2298 // with:
2299 // openssl gendh 1023 | openssl asn1parse -i
2300 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2301 },
2302 },
2303 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002304 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002305 })
Adam Langleycef75832015-09-03 14:51:12 -07002306
David Benjamincd24a392015-11-11 13:23:05 -08002307 testCases = append(testCases, testCase{
2308 name: "SillyDH",
2309 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002310 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002311 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2312 Bugs: ProtocolBugs{
2313 // This is a 4097-bit prime number, generated
2314 // with:
2315 // openssl gendh 4097 | openssl asn1parse -i
2316 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2317 },
2318 },
2319 shouldFail: true,
2320 expectedError: ":DH_P_TOO_LONG:",
2321 })
2322
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002323 // This test ensures that Diffie-Hellman public values are padded with
2324 // zeros so that they're the same length as the prime. This is to avoid
2325 // hitting a bug in yaSSL.
2326 testCases = append(testCases, testCase{
2327 testType: serverTest,
2328 name: "DHPublicValuePadded",
2329 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002330 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002331 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2332 Bugs: ProtocolBugs{
2333 RequireDHPublicValueLen: (1025 + 7) / 8,
2334 },
2335 },
2336 flags: []string{"-use-sparse-dh-prime"},
2337 })
David Benjamincd24a392015-11-11 13:23:05 -08002338
David Benjamin241ae832016-01-15 03:04:54 -05002339 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002340 testCases = append(testCases, testCase{
2341 testType: serverTest,
2342 name: "UnknownCipher",
2343 config: Config{
2344 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2345 },
2346 })
2347
Adam Langleycef75832015-09-03 14:51:12 -07002348 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2349 // 1.1 specific cipher suite settings. A server is setup with the given
2350 // cipher lists and then a connection is made for each member of
2351 // expectations. The cipher suite that the server selects must match
2352 // the specified one.
2353 var versionSpecificCiphersTest = []struct {
2354 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2355 // expectations is a map from TLS version to cipher suite id.
2356 expectations map[uint16]uint16
2357 }{
2358 {
2359 // Test that the null case (where no version-specific ciphers are set)
2360 // works as expected.
2361 "RC4-SHA:AES128-SHA", // default ciphers
2362 "", // no ciphers specifically for TLS ≥ 1.0
2363 "", // no ciphers specifically for TLS ≥ 1.1
2364 map[uint16]uint16{
2365 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2366 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2367 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2368 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2369 },
2370 },
2371 {
2372 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2373 // cipher.
2374 "RC4-SHA:AES128-SHA", // default
2375 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2376 "", // no ciphers specifically for TLS ≥ 1.1
2377 map[uint16]uint16{
2378 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2379 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2380 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2381 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2382 },
2383 },
2384 {
2385 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2386 // cipher.
2387 "RC4-SHA:AES128-SHA", // default
2388 "", // no ciphers specifically for TLS ≥ 1.0
2389 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2390 map[uint16]uint16{
2391 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2392 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2393 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2394 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2395 },
2396 },
2397 {
2398 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2399 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2400 "RC4-SHA:AES128-SHA", // default
2401 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2402 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2403 map[uint16]uint16{
2404 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2405 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2406 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2407 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2408 },
2409 },
2410 }
2411
2412 for i, test := range versionSpecificCiphersTest {
2413 for version, expectedCipherSuite := range test.expectations {
2414 flags := []string{"-cipher", test.ciphersDefault}
2415 if len(test.ciphersTLS10) > 0 {
2416 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2417 }
2418 if len(test.ciphersTLS11) > 0 {
2419 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2420 }
2421
2422 testCases = append(testCases, testCase{
2423 testType: serverTest,
2424 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2425 config: Config{
2426 MaxVersion: version,
2427 MinVersion: version,
2428 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2429 },
2430 flags: flags,
2431 expectedCipher: expectedCipherSuite,
2432 })
2433 }
2434 }
Adam Langley95c29f32014-06-20 12:00:00 -07002435}
2436
2437func addBadECDSASignatureTests() {
2438 for badR := BadValue(1); badR < NumBadValues; badR++ {
2439 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002440 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002441 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2442 config: Config{
2443 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002444 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002445 Bugs: ProtocolBugs{
2446 BadECDSAR: badR,
2447 BadECDSAS: badS,
2448 },
2449 },
2450 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002451 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002452 })
2453 }
2454 }
2455}
2456
Adam Langley80842bd2014-06-20 12:00:00 -07002457func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002458 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002459 name: "MaxCBCPadding",
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 MaxPadding: true,
2465 },
2466 },
2467 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2468 })
David Benjamin025b3d32014-07-01 19:53:04 -04002469 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002470 name: "BadCBCPadding",
2471 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002472 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002473 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2474 Bugs: ProtocolBugs{
2475 PaddingFirstByteBad: true,
2476 },
2477 },
2478 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002479 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002480 })
2481 // OpenSSL previously had an issue where the first byte of padding in
2482 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002483 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002484 name: "BadCBCPadding255",
2485 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002486 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002487 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2488 Bugs: ProtocolBugs{
2489 MaxPadding: true,
2490 PaddingFirstByteBadIf255: true,
2491 },
2492 },
2493 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2494 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002495 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002496 })
2497}
2498
Kenny Root7fdeaf12014-08-05 15:23:37 -07002499func addCBCSplittingTests() {
2500 testCases = append(testCases, testCase{
2501 name: "CBCRecordSplitting",
2502 config: Config{
2503 MaxVersion: VersionTLS10,
2504 MinVersion: VersionTLS10,
2505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2506 },
David Benjaminac8302a2015-09-01 17:18:15 -04002507 messageLen: -1, // read until EOF
2508 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002509 flags: []string{
2510 "-async",
2511 "-write-different-record-sizes",
2512 "-cbc-record-splitting",
2513 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002514 })
2515 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002516 name: "CBCRecordSplittingPartialWrite",
2517 config: Config{
2518 MaxVersion: VersionTLS10,
2519 MinVersion: VersionTLS10,
2520 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2521 },
2522 messageLen: -1, // read until EOF
2523 flags: []string{
2524 "-async",
2525 "-write-different-record-sizes",
2526 "-cbc-record-splitting",
2527 "-partial-write",
2528 },
2529 })
2530}
2531
David Benjamin636293b2014-07-08 17:59:18 -04002532func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002533 // Add a dummy cert pool to stress certificate authority parsing.
2534 // TODO(davidben): Add tests that those values parse out correctly.
2535 certPool := x509.NewCertPool()
2536 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2537 if err != nil {
2538 panic(err)
2539 }
2540 certPool.AddCert(cert)
2541
David Benjamin636293b2014-07-08 17:59:18 -04002542 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002543 testCases = append(testCases, testCase{
2544 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002545 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002546 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002547 MinVersion: ver.version,
2548 MaxVersion: ver.version,
2549 ClientAuth: RequireAnyClientCert,
2550 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002551 },
2552 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002553 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2554 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002555 },
2556 })
2557 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002558 testType: serverTest,
2559 name: ver.name + "-Server-ClientAuth-RSA",
2560 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002561 MinVersion: ver.version,
2562 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002563 Certificates: []Certificate{rsaCertificate},
2564 },
2565 flags: []string{"-require-any-client-certificate"},
2566 })
David Benjamine098ec22014-08-27 23:13:20 -04002567 if ver.version != VersionSSL30 {
2568 testCases = append(testCases, testCase{
2569 testType: serverTest,
2570 name: ver.name + "-Server-ClientAuth-ECDSA",
2571 config: Config{
2572 MinVersion: ver.version,
2573 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002574 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002575 },
2576 flags: []string{"-require-any-client-certificate"},
2577 })
2578 testCases = append(testCases, testCase{
2579 testType: clientTest,
2580 name: ver.name + "-Client-ClientAuth-ECDSA",
2581 config: Config{
2582 MinVersion: ver.version,
2583 MaxVersion: ver.version,
2584 ClientAuth: RequireAnyClientCert,
2585 ClientCAs: certPool,
2586 },
2587 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002588 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2589 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002590 },
2591 })
2592 }
David Benjamin636293b2014-07-08 17:59:18 -04002593 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002594
2595 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002596 name: "NoClientCertificate",
2597 config: Config{
2598 MaxVersion: VersionTLS12,
2599 ClientAuth: RequireAnyClientCert,
2600 },
2601 shouldFail: true,
2602 expectedLocalError: "client didn't provide a certificate",
2603 })
2604
2605 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002606 name: "NoClientCertificate-TLS13",
2607 config: Config{
2608 MaxVersion: VersionTLS13,
2609 ClientAuth: RequireAnyClientCert,
2610 },
2611 shouldFail: true,
2612 expectedLocalError: "client didn't provide a certificate",
2613 })
2614
2615 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002616 testType: serverTest,
2617 name: "RequireAnyClientCertificate",
2618 config: Config{
2619 MaxVersion: VersionTLS12,
2620 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002621 flags: []string{"-require-any-client-certificate"},
2622 shouldFail: true,
2623 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2624 })
2625
2626 testCases = append(testCases, testCase{
2627 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002628 name: "RequireAnyClientCertificate-TLS13",
2629 config: Config{
2630 MaxVersion: VersionTLS13,
2631 },
2632 flags: []string{"-require-any-client-certificate"},
2633 shouldFail: true,
2634 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2635 })
2636
2637 testCases = append(testCases, testCase{
2638 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002639 name: "RequireAnyClientCertificate-SSL3",
2640 config: Config{
2641 MaxVersion: VersionSSL30,
2642 },
2643 flags: []string{"-require-any-client-certificate"},
2644 shouldFail: true,
2645 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2646 })
2647
2648 testCases = append(testCases, testCase{
2649 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002650 name: "SkipClientCertificate",
2651 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002652 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002653 Bugs: ProtocolBugs{
2654 SkipClientCertificate: true,
2655 },
2656 },
2657 // Setting SSL_VERIFY_PEER allows anonymous clients.
2658 flags: []string{"-verify-peer"},
2659 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002660 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002661 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002662
Steven Valdez143e8b32016-07-11 13:19:03 -04002663 testCases = append(testCases, testCase{
2664 testType: serverTest,
2665 name: "SkipClientCertificate-TLS13",
2666 config: Config{
2667 MaxVersion: VersionTLS13,
2668 Bugs: ProtocolBugs{
2669 SkipClientCertificate: true,
2670 },
2671 },
2672 // Setting SSL_VERIFY_PEER allows anonymous clients.
2673 flags: []string{"-verify-peer"},
2674 shouldFail: true,
2675 expectedError: ":UNEXPECTED_MESSAGE:",
2676 })
2677
David Benjaminc032dfa2016-05-12 14:54:57 -04002678 // Client auth is only legal in certificate-based ciphers.
2679 testCases = append(testCases, testCase{
2680 testType: clientTest,
2681 name: "ClientAuth-PSK",
2682 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002683 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002684 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2685 PreSharedKey: []byte("secret"),
2686 ClientAuth: RequireAnyClientCert,
2687 },
2688 flags: []string{
2689 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2690 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2691 "-psk", "secret",
2692 },
2693 shouldFail: true,
2694 expectedError: ":UNEXPECTED_MESSAGE:",
2695 })
2696 testCases = append(testCases, testCase{
2697 testType: clientTest,
2698 name: "ClientAuth-ECDHE_PSK",
2699 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002700 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002701 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2702 PreSharedKey: []byte("secret"),
2703 ClientAuth: RequireAnyClientCert,
2704 },
2705 flags: []string{
2706 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2707 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2708 "-psk", "secret",
2709 },
2710 shouldFail: true,
2711 expectedError: ":UNEXPECTED_MESSAGE:",
2712 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002713
2714 // Regression test for a bug where the client CA list, if explicitly
2715 // set to NULL, was mis-encoded.
2716 testCases = append(testCases, testCase{
2717 testType: serverTest,
2718 name: "Null-Client-CA-List",
2719 config: Config{
2720 MaxVersion: VersionTLS12,
2721 Certificates: []Certificate{rsaCertificate},
2722 },
2723 flags: []string{
2724 "-require-any-client-certificate",
2725 "-use-null-client-ca-list",
2726 },
2727 })
David Benjamin636293b2014-07-08 17:59:18 -04002728}
2729
Adam Langley75712922014-10-10 16:23:43 -07002730func addExtendedMasterSecretTests() {
2731 const expectEMSFlag = "-expect-extended-master-secret"
2732
2733 for _, with := range []bool{false, true} {
2734 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002735 if with {
2736 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002737 }
2738
2739 for _, isClient := range []bool{false, true} {
2740 suffix := "-Server"
2741 testType := serverTest
2742 if isClient {
2743 suffix = "-Client"
2744 testType = clientTest
2745 }
2746
2747 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002748 // In TLS 1.3, the extension is irrelevant and
2749 // always reports as enabled.
2750 var flags []string
2751 if with || ver.version >= VersionTLS13 {
2752 flags = []string{expectEMSFlag}
2753 }
2754
Adam Langley75712922014-10-10 16:23:43 -07002755 test := testCase{
2756 testType: testType,
2757 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2758 config: Config{
2759 MinVersion: ver.version,
2760 MaxVersion: ver.version,
2761 Bugs: ProtocolBugs{
2762 NoExtendedMasterSecret: !with,
2763 RequireExtendedMasterSecret: with,
2764 },
2765 },
David Benjamin48cae082014-10-27 01:06:24 -04002766 flags: flags,
2767 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002768 }
2769 if test.shouldFail {
2770 test.expectedLocalError = "extended master secret required but not supported by peer"
2771 }
2772 testCases = append(testCases, test)
2773 }
2774 }
2775 }
2776
Adam Langleyba5934b2015-06-02 10:50:35 -07002777 for _, isClient := range []bool{false, true} {
2778 for _, supportedInFirstConnection := range []bool{false, true} {
2779 for _, supportedInResumeConnection := range []bool{false, true} {
2780 boolToWord := func(b bool) string {
2781 if b {
2782 return "Yes"
2783 }
2784 return "No"
2785 }
2786 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2787 if isClient {
2788 suffix += "Client"
2789 } else {
2790 suffix += "Server"
2791 }
2792
2793 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002794 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002795 Bugs: ProtocolBugs{
2796 RequireExtendedMasterSecret: true,
2797 },
2798 }
2799
2800 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002801 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002802 Bugs: ProtocolBugs{
2803 NoExtendedMasterSecret: true,
2804 },
2805 }
2806
2807 test := testCase{
2808 name: "ExtendedMasterSecret-" + suffix,
2809 resumeSession: true,
2810 }
2811
2812 if !isClient {
2813 test.testType = serverTest
2814 }
2815
2816 if supportedInFirstConnection {
2817 test.config = supportedConfig
2818 } else {
2819 test.config = noSupportConfig
2820 }
2821
2822 if supportedInResumeConnection {
2823 test.resumeConfig = &supportedConfig
2824 } else {
2825 test.resumeConfig = &noSupportConfig
2826 }
2827
2828 switch suffix {
2829 case "YesToYes-Client", "YesToYes-Server":
2830 // When a session is resumed, it should
2831 // still be aware that its master
2832 // secret was generated via EMS and
2833 // thus it's safe to use tls-unique.
2834 test.flags = []string{expectEMSFlag}
2835 case "NoToYes-Server":
2836 // If an original connection did not
2837 // contain EMS, but a resumption
2838 // handshake does, then a server should
2839 // not resume the session.
2840 test.expectResumeRejected = true
2841 case "YesToNo-Server":
2842 // Resuming an EMS session without the
2843 // EMS extension should cause the
2844 // server to abort the connection.
2845 test.shouldFail = true
2846 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2847 case "NoToYes-Client":
2848 // A client should abort a connection
2849 // where the server resumed a non-EMS
2850 // session but echoed the EMS
2851 // extension.
2852 test.shouldFail = true
2853 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2854 case "YesToNo-Client":
2855 // A client should abort a connection
2856 // where the server didn't echo EMS
2857 // when the session used it.
2858 test.shouldFail = true
2859 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2860 }
2861
2862 testCases = append(testCases, test)
2863 }
2864 }
2865 }
Adam Langley75712922014-10-10 16:23:43 -07002866}
2867
David Benjamin582ba042016-07-07 12:33:25 -07002868type stateMachineTestConfig struct {
2869 protocol protocol
2870 async bool
2871 splitHandshake, packHandshakeFlight bool
2872}
2873
David Benjamin43ec06f2014-08-05 02:28:57 -04002874// Adds tests that try to cover the range of the handshake state machine, under
2875// various conditions. Some of these are redundant with other tests, but they
2876// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002877func addAllStateMachineCoverageTests() {
2878 for _, async := range []bool{false, true} {
2879 for _, protocol := range []protocol{tls, dtls} {
2880 addStateMachineCoverageTests(stateMachineTestConfig{
2881 protocol: protocol,
2882 async: async,
2883 })
2884 addStateMachineCoverageTests(stateMachineTestConfig{
2885 protocol: protocol,
2886 async: async,
2887 splitHandshake: true,
2888 })
2889 if protocol == tls {
2890 addStateMachineCoverageTests(stateMachineTestConfig{
2891 protocol: protocol,
2892 async: async,
2893 packHandshakeFlight: true,
2894 })
2895 }
2896 }
2897 }
2898}
2899
2900func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002901 var tests []testCase
2902
2903 // Basic handshake, with resumption. Client and server,
2904 // session ID and session ticket.
2905 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002906 name: "Basic-Client",
2907 config: Config{
2908 MaxVersion: VersionTLS12,
2909 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002910 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002911 // Ensure session tickets are used, not session IDs.
2912 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002913 })
2914 tests = append(tests, testCase{
2915 name: "Basic-Client-RenewTicket",
2916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002917 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002918 Bugs: ProtocolBugs{
2919 RenewTicketOnResume: true,
2920 },
2921 },
David Benjaminba4594a2015-06-18 18:36:15 -04002922 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002923 resumeSession: true,
2924 })
2925 tests = append(tests, testCase{
2926 name: "Basic-Client-NoTicket",
2927 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002928 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002929 SessionTicketsDisabled: true,
2930 },
2931 resumeSession: true,
2932 })
2933 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002934 name: "Basic-Client-Implicit",
2935 config: Config{
2936 MaxVersion: VersionTLS12,
2937 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002938 flags: []string{"-implicit-handshake"},
2939 resumeSession: true,
2940 })
2941 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002942 testType: serverTest,
2943 name: "Basic-Server",
2944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002945 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002946 Bugs: ProtocolBugs{
2947 RequireSessionTickets: true,
2948 },
2949 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002950 resumeSession: true,
2951 })
2952 tests = append(tests, testCase{
2953 testType: serverTest,
2954 name: "Basic-Server-NoTickets",
2955 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002956 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002957 SessionTicketsDisabled: true,
2958 },
2959 resumeSession: true,
2960 })
2961 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002962 testType: serverTest,
2963 name: "Basic-Server-Implicit",
2964 config: Config{
2965 MaxVersion: VersionTLS12,
2966 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002967 flags: []string{"-implicit-handshake"},
2968 resumeSession: true,
2969 })
2970 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002971 testType: serverTest,
2972 name: "Basic-Server-EarlyCallback",
2973 config: Config{
2974 MaxVersion: VersionTLS12,
2975 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002976 flags: []string{"-use-early-callback"},
2977 resumeSession: true,
2978 })
2979
Steven Valdez143e8b32016-07-11 13:19:03 -04002980 // TLS 1.3 basic handshake shapes.
2981 tests = append(tests, testCase{
2982 name: "TLS13-1RTT-Client",
2983 config: Config{
2984 MaxVersion: VersionTLS13,
2985 },
2986 })
2987 tests = append(tests, testCase{
2988 testType: serverTest,
2989 name: "TLS13-1RTT-Server",
2990 config: Config{
2991 MaxVersion: VersionTLS13,
2992 },
2993 })
2994
David Benjamin760b1dd2015-05-15 23:33:48 -04002995 // TLS client auth.
2996 tests = append(tests, testCase{
2997 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002998 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003000 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003001 ClientAuth: RequestClientCert,
3002 },
3003 })
3004 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003005 testType: serverTest,
3006 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003007 config: Config{
3008 MaxVersion: VersionTLS12,
3009 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003010 // Setting SSL_VERIFY_PEER allows anonymous clients.
3011 flags: []string{"-verify-peer"},
3012 })
David Benjamin582ba042016-07-07 12:33:25 -07003013 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003014 tests = append(tests, testCase{
3015 testType: clientTest,
3016 name: "ClientAuth-NoCertificate-Client-SSL3",
3017 config: Config{
3018 MaxVersion: VersionSSL30,
3019 ClientAuth: RequestClientCert,
3020 },
3021 })
3022 tests = append(tests, testCase{
3023 testType: serverTest,
3024 name: "ClientAuth-NoCertificate-Server-SSL3",
3025 config: Config{
3026 MaxVersion: VersionSSL30,
3027 },
3028 // Setting SSL_VERIFY_PEER allows anonymous clients.
3029 flags: []string{"-verify-peer"},
3030 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003031 tests = append(tests, testCase{
3032 testType: clientTest,
3033 name: "ClientAuth-NoCertificate-Client-TLS13",
3034 config: Config{
3035 MaxVersion: VersionTLS13,
3036 ClientAuth: RequestClientCert,
3037 },
3038 })
3039 tests = append(tests, testCase{
3040 testType: serverTest,
3041 name: "ClientAuth-NoCertificate-Server-TLS13",
3042 config: Config{
3043 MaxVersion: VersionTLS13,
3044 },
3045 // Setting SSL_VERIFY_PEER allows anonymous clients.
3046 flags: []string{"-verify-peer"},
3047 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003048 }
3049 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003050 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003051 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003052 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003053 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003054 ClientAuth: RequireAnyClientCert,
3055 },
3056 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003057 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3058 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003059 },
3060 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003061 tests = append(tests, testCase{
3062 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003063 name: "ClientAuth-RSA-Client-TLS13",
3064 config: Config{
3065 MaxVersion: VersionTLS13,
3066 ClientAuth: RequireAnyClientCert,
3067 },
3068 flags: []string{
3069 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3070 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3071 },
3072 })
3073 tests = append(tests, testCase{
3074 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003075 name: "ClientAuth-ECDSA-Client",
3076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003077 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003078 ClientAuth: RequireAnyClientCert,
3079 },
3080 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003081 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3082 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003083 },
3084 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003085 tests = append(tests, testCase{
3086 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003087 name: "ClientAuth-ECDSA-Client-TLS13",
3088 config: Config{
3089 MaxVersion: VersionTLS13,
3090 ClientAuth: RequireAnyClientCert,
3091 },
3092 flags: []string{
3093 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3094 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3095 },
3096 })
3097 tests = append(tests, testCase{
3098 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003099 name: "ClientAuth-NoCertificate-OldCallback",
3100 config: Config{
3101 MaxVersion: VersionTLS12,
3102 ClientAuth: RequestClientCert,
3103 },
3104 flags: []string{"-use-old-client-cert-callback"},
3105 })
3106 tests = append(tests, testCase{
3107 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003108 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3109 config: Config{
3110 MaxVersion: VersionTLS13,
3111 ClientAuth: RequestClientCert,
3112 },
3113 flags: []string{"-use-old-client-cert-callback"},
3114 })
3115 tests = append(tests, testCase{
3116 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003117 name: "ClientAuth-OldCallback",
3118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003119 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003120 ClientAuth: RequireAnyClientCert,
3121 },
3122 flags: []string{
3123 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3124 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3125 "-use-old-client-cert-callback",
3126 },
3127 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003128 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003129 testType: clientTest,
3130 name: "ClientAuth-OldCallback-TLS13",
3131 config: Config{
3132 MaxVersion: VersionTLS13,
3133 ClientAuth: RequireAnyClientCert,
3134 },
3135 flags: []string{
3136 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3137 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3138 "-use-old-client-cert-callback",
3139 },
3140 })
3141 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003142 testType: serverTest,
3143 name: "ClientAuth-Server",
3144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003145 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003146 Certificates: []Certificate{rsaCertificate},
3147 },
3148 flags: []string{"-require-any-client-certificate"},
3149 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003150 tests = append(tests, testCase{
3151 testType: serverTest,
3152 name: "ClientAuth-Server-TLS13",
3153 config: Config{
3154 MaxVersion: VersionTLS13,
3155 Certificates: []Certificate{rsaCertificate},
3156 },
3157 flags: []string{"-require-any-client-certificate"},
3158 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003159
David Benjamin4c3ddf72016-06-29 18:13:53 -04003160 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003161 tests = append(tests, testCase{
3162 testType: serverTest,
3163 name: "Basic-Server-RSA",
3164 config: Config{
3165 MaxVersion: VersionTLS12,
3166 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3167 },
3168 flags: []string{
3169 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3170 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3171 },
3172 })
3173 tests = append(tests, testCase{
3174 testType: serverTest,
3175 name: "Basic-Server-ECDHE-RSA",
3176 config: Config{
3177 MaxVersion: VersionTLS12,
3178 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3179 },
3180 flags: []string{
3181 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3182 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3183 },
3184 })
3185 tests = append(tests, testCase{
3186 testType: serverTest,
3187 name: "Basic-Server-ECDHE-ECDSA",
3188 config: Config{
3189 MaxVersion: VersionTLS12,
3190 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3191 },
3192 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003193 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3194 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003195 },
3196 })
3197
David Benjamin760b1dd2015-05-15 23:33:48 -04003198 // No session ticket support; server doesn't send NewSessionTicket.
3199 tests = append(tests, testCase{
3200 name: "SessionTicketsDisabled-Client",
3201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003202 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003203 SessionTicketsDisabled: true,
3204 },
3205 })
3206 tests = append(tests, testCase{
3207 testType: serverTest,
3208 name: "SessionTicketsDisabled-Server",
3209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003210 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003211 SessionTicketsDisabled: true,
3212 },
3213 })
3214
3215 // Skip ServerKeyExchange in PSK key exchange if there's no
3216 // identity hint.
3217 tests = append(tests, testCase{
3218 name: "EmptyPSKHint-Client",
3219 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003220 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003221 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3222 PreSharedKey: []byte("secret"),
3223 },
3224 flags: []string{"-psk", "secret"},
3225 })
3226 tests = append(tests, testCase{
3227 testType: serverTest,
3228 name: "EmptyPSKHint-Server",
3229 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003230 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003231 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3232 PreSharedKey: []byte("secret"),
3233 },
3234 flags: []string{"-psk", "secret"},
3235 })
3236
David Benjamin4c3ddf72016-06-29 18:13:53 -04003237 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003238 tests = append(tests, testCase{
3239 testType: clientTest,
3240 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003241 config: Config{
3242 MaxVersion: VersionTLS12,
3243 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003244 flags: []string{
3245 "-enable-ocsp-stapling",
3246 "-expect-ocsp-response",
3247 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003248 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003249 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003250 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003251 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003252 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003253 testType: serverTest,
3254 name: "OCSPStapling-Server",
3255 config: Config{
3256 MaxVersion: VersionTLS12,
3257 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003258 expectedOCSPResponse: testOCSPResponse,
3259 flags: []string{
3260 "-ocsp-response",
3261 base64.StdEncoding.EncodeToString(testOCSPResponse),
3262 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003263 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003264 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003265 tests = append(tests, testCase{
3266 testType: clientTest,
3267 name: "OCSPStapling-Client-TLS13",
3268 config: Config{
3269 MaxVersion: VersionTLS13,
3270 },
3271 flags: []string{
3272 "-enable-ocsp-stapling",
3273 "-expect-ocsp-response",
3274 base64.StdEncoding.EncodeToString(testOCSPResponse),
3275 "-verify-peer",
3276 },
3277 // TODO(davidben): Enable this when resumption is implemented
3278 // in TLS 1.3.
3279 resumeSession: false,
3280 })
3281 tests = append(tests, testCase{
3282 testType: serverTest,
3283 name: "OCSPStapling-Server-TLS13",
3284 config: Config{
3285 MaxVersion: VersionTLS13,
3286 },
3287 expectedOCSPResponse: testOCSPResponse,
3288 flags: []string{
3289 "-ocsp-response",
3290 base64.StdEncoding.EncodeToString(testOCSPResponse),
3291 },
3292 // TODO(davidben): Enable this when resumption is implemented
3293 // in TLS 1.3.
3294 resumeSession: false,
3295 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003296
David Benjamin4c3ddf72016-06-29 18:13:53 -04003297 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003298 for _, vers := range tlsVersions {
3299 if config.protocol == dtls && !vers.hasDTLS {
3300 continue
3301 }
3302 tests = append(tests, testCase{
3303 testType: clientTest,
3304 name: "CertificateVerificationSucceed-" + vers.name,
3305 config: Config{
3306 MaxVersion: vers.version,
3307 },
3308 flags: []string{
3309 "-verify-peer",
3310 },
3311 })
3312 tests = append(tests, testCase{
3313 testType: clientTest,
3314 name: "CertificateVerificationFail-" + vers.name,
3315 config: Config{
3316 MaxVersion: vers.version,
3317 },
3318 flags: []string{
3319 "-verify-fail",
3320 "-verify-peer",
3321 },
3322 shouldFail: true,
3323 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3324 })
3325 tests = append(tests, testCase{
3326 testType: clientTest,
3327 name: "CertificateVerificationSoftFail-" + vers.name,
3328 config: Config{
3329 MaxVersion: vers.version,
3330 },
3331 flags: []string{
3332 "-verify-fail",
3333 "-expect-verify-result",
3334 },
3335 })
3336 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003337
David Benjamin1d4f4c02016-07-26 18:03:08 -04003338 tests = append(tests, testCase{
3339 name: "ShimSendAlert",
3340 flags: []string{"-send-alert"},
3341 shimWritesFirst: true,
3342 shouldFail: true,
3343 expectedLocalError: "remote error: decompression failure",
3344 })
3345
David Benjamin582ba042016-07-07 12:33:25 -07003346 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003347 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 name: "Renegotiate-Client",
3349 config: Config{
3350 MaxVersion: VersionTLS12,
3351 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003352 renegotiate: 1,
3353 flags: []string{
3354 "-renegotiate-freely",
3355 "-expect-total-renegotiations", "1",
3356 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003357 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003358
David Benjamin760b1dd2015-05-15 23:33:48 -04003359 // NPN on client and server; results in post-handshake message.
3360 tests = append(tests, testCase{
3361 name: "NPN-Client",
3362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003363 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003364 NextProtos: []string{"foo"},
3365 },
3366 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003367 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003368 expectedNextProto: "foo",
3369 expectedNextProtoType: npn,
3370 })
3371 tests = append(tests, testCase{
3372 testType: serverTest,
3373 name: "NPN-Server",
3374 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003375 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003376 NextProtos: []string{"bar"},
3377 },
3378 flags: []string{
3379 "-advertise-npn", "\x03foo\x03bar\x03baz",
3380 "-expect-next-proto", "bar",
3381 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003382 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003383 expectedNextProto: "bar",
3384 expectedNextProtoType: npn,
3385 })
3386
3387 // TODO(davidben): Add tests for when False Start doesn't trigger.
3388
3389 // Client does False Start and negotiates NPN.
3390 tests = append(tests, testCase{
3391 name: "FalseStart",
3392 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003393 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003394 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3395 NextProtos: []string{"foo"},
3396 Bugs: ProtocolBugs{
3397 ExpectFalseStart: true,
3398 },
3399 },
3400 flags: []string{
3401 "-false-start",
3402 "-select-next-proto", "foo",
3403 },
3404 shimWritesFirst: true,
3405 resumeSession: true,
3406 })
3407
3408 // Client does False Start and negotiates ALPN.
3409 tests = append(tests, testCase{
3410 name: "FalseStart-ALPN",
3411 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003412 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3414 NextProtos: []string{"foo"},
3415 Bugs: ProtocolBugs{
3416 ExpectFalseStart: true,
3417 },
3418 },
3419 flags: []string{
3420 "-false-start",
3421 "-advertise-alpn", "\x03foo",
3422 },
3423 shimWritesFirst: true,
3424 resumeSession: true,
3425 })
3426
3427 // Client does False Start but doesn't explicitly call
3428 // SSL_connect.
3429 tests = append(tests, testCase{
3430 name: "FalseStart-Implicit",
3431 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003432 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003433 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3434 NextProtos: []string{"foo"},
3435 },
3436 flags: []string{
3437 "-implicit-handshake",
3438 "-false-start",
3439 "-advertise-alpn", "\x03foo",
3440 },
3441 })
3442
3443 // False Start without session tickets.
3444 tests = append(tests, testCase{
3445 name: "FalseStart-SessionTicketsDisabled",
3446 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003447 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3449 NextProtos: []string{"foo"},
3450 SessionTicketsDisabled: true,
3451 Bugs: ProtocolBugs{
3452 ExpectFalseStart: true,
3453 },
3454 },
3455 flags: []string{
3456 "-false-start",
3457 "-select-next-proto", "foo",
3458 },
3459 shimWritesFirst: true,
3460 })
3461
Adam Langleydf759b52016-07-11 15:24:37 -07003462 tests = append(tests, testCase{
3463 name: "FalseStart-CECPQ1",
3464 config: Config{
3465 MaxVersion: VersionTLS12,
3466 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3467 NextProtos: []string{"foo"},
3468 Bugs: ProtocolBugs{
3469 ExpectFalseStart: true,
3470 },
3471 },
3472 flags: []string{
3473 "-false-start",
3474 "-cipher", "DEFAULT:kCECPQ1",
3475 "-select-next-proto", "foo",
3476 },
3477 shimWritesFirst: true,
3478 resumeSession: true,
3479 })
3480
David Benjamin760b1dd2015-05-15 23:33:48 -04003481 // Server parses a V2ClientHello.
3482 tests = append(tests, testCase{
3483 testType: serverTest,
3484 name: "SendV2ClientHello",
3485 config: Config{
3486 // Choose a cipher suite that does not involve
3487 // elliptic curves, so no extensions are
3488 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003489 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003490 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3491 Bugs: ProtocolBugs{
3492 SendV2ClientHello: true,
3493 },
3494 },
3495 })
3496
3497 // Client sends a Channel ID.
3498 tests = append(tests, testCase{
3499 name: "ChannelID-Client",
3500 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003501 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003502 RequestChannelID: true,
3503 },
Adam Langley7c803a62015-06-15 15:35:05 -07003504 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003505 resumeSession: true,
3506 expectChannelID: true,
3507 })
3508
3509 // Server accepts a Channel ID.
3510 tests = append(tests, testCase{
3511 testType: serverTest,
3512 name: "ChannelID-Server",
3513 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003514 MaxVersion: VersionTLS12,
3515 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003516 },
3517 flags: []string{
3518 "-expect-channel-id",
3519 base64.StdEncoding.EncodeToString(channelIDBytes),
3520 },
3521 resumeSession: true,
3522 expectChannelID: true,
3523 })
David Benjamin30789da2015-08-29 22:56:45 -04003524
David Benjaminf8fcdf32016-06-08 15:56:13 -04003525 // Channel ID and NPN at the same time, to ensure their relative
3526 // ordering is correct.
3527 tests = append(tests, testCase{
3528 name: "ChannelID-NPN-Client",
3529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003530 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003531 RequestChannelID: true,
3532 NextProtos: []string{"foo"},
3533 },
3534 flags: []string{
3535 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3536 "-select-next-proto", "foo",
3537 },
3538 resumeSession: true,
3539 expectChannelID: true,
3540 expectedNextProto: "foo",
3541 expectedNextProtoType: npn,
3542 })
3543 tests = append(tests, testCase{
3544 testType: serverTest,
3545 name: "ChannelID-NPN-Server",
3546 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003547 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003548 ChannelID: channelIDKey,
3549 NextProtos: []string{"bar"},
3550 },
3551 flags: []string{
3552 "-expect-channel-id",
3553 base64.StdEncoding.EncodeToString(channelIDBytes),
3554 "-advertise-npn", "\x03foo\x03bar\x03baz",
3555 "-expect-next-proto", "bar",
3556 },
3557 resumeSession: true,
3558 expectChannelID: true,
3559 expectedNextProto: "bar",
3560 expectedNextProtoType: npn,
3561 })
3562
David Benjamin30789da2015-08-29 22:56:45 -04003563 // Bidirectional shutdown with the runner initiating.
3564 tests = append(tests, testCase{
3565 name: "Shutdown-Runner",
3566 config: Config{
3567 Bugs: ProtocolBugs{
3568 ExpectCloseNotify: true,
3569 },
3570 },
3571 flags: []string{"-check-close-notify"},
3572 })
3573
3574 // Bidirectional shutdown with the shim initiating. The runner,
3575 // in the meantime, sends garbage before the close_notify which
3576 // the shim must ignore.
3577 tests = append(tests, testCase{
3578 name: "Shutdown-Shim",
3579 config: Config{
3580 Bugs: ProtocolBugs{
3581 ExpectCloseNotify: true,
3582 },
3583 },
3584 shimShutsDown: true,
3585 sendEmptyRecords: 1,
3586 sendWarningAlerts: 1,
3587 flags: []string{"-check-close-notify"},
3588 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003589 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003590 // TODO(davidben): DTLS 1.3 will want a similar thing for
3591 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003592 tests = append(tests, testCase{
3593 name: "SkipHelloVerifyRequest",
3594 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003595 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003596 Bugs: ProtocolBugs{
3597 SkipHelloVerifyRequest: true,
3598 },
3599 },
3600 })
3601 }
3602
David Benjamin760b1dd2015-05-15 23:33:48 -04003603 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003604 test.protocol = config.protocol
3605 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003606 test.name += "-DTLS"
3607 }
David Benjamin582ba042016-07-07 12:33:25 -07003608 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003609 test.name += "-Async"
3610 test.flags = append(test.flags, "-async")
3611 } else {
3612 test.name += "-Sync"
3613 }
David Benjamin582ba042016-07-07 12:33:25 -07003614 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003615 test.name += "-SplitHandshakeRecords"
3616 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003617 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003618 test.config.Bugs.MaxPacketLength = 256
3619 test.flags = append(test.flags, "-mtu", "256")
3620 }
3621 }
David Benjamin582ba042016-07-07 12:33:25 -07003622 if config.packHandshakeFlight {
3623 test.name += "-PackHandshakeFlight"
3624 test.config.Bugs.PackHandshakeFlight = true
3625 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003626 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003627 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003628}
3629
Adam Langley524e7172015-02-20 16:04:00 -08003630func addDDoSCallbackTests() {
3631 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003632 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003633 for _, resume := range []bool{false, true} {
3634 suffix := "Resume"
3635 if resume {
3636 suffix = "No" + suffix
3637 }
3638
3639 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003640 testType: serverTest,
3641 name: "Server-DDoS-OK-" + suffix,
3642 config: Config{
3643 MaxVersion: VersionTLS12,
3644 },
Adam Langley524e7172015-02-20 16:04:00 -08003645 flags: []string{"-install-ddos-callback"},
3646 resumeSession: resume,
3647 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003648 if !resume {
3649 testCases = append(testCases, testCase{
3650 testType: serverTest,
3651 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3652 config: Config{
3653 MaxVersion: VersionTLS13,
3654 },
3655 flags: []string{"-install-ddos-callback"},
3656 resumeSession: resume,
3657 })
3658 }
Adam Langley524e7172015-02-20 16:04:00 -08003659
3660 failFlag := "-fail-ddos-callback"
3661 if resume {
3662 failFlag = "-fail-second-ddos-callback"
3663 }
3664 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003665 testType: serverTest,
3666 name: "Server-DDoS-Reject-" + suffix,
3667 config: Config{
3668 MaxVersion: VersionTLS12,
3669 },
Adam Langley524e7172015-02-20 16:04:00 -08003670 flags: []string{"-install-ddos-callback", failFlag},
3671 resumeSession: resume,
3672 shouldFail: true,
3673 expectedError: ":CONNECTION_REJECTED:",
3674 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003675 if !resume {
3676 testCases = append(testCases, testCase{
3677 testType: serverTest,
3678 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3679 config: Config{
3680 MaxVersion: VersionTLS13,
3681 },
3682 flags: []string{"-install-ddos-callback", failFlag},
3683 resumeSession: resume,
3684 shouldFail: true,
3685 expectedError: ":CONNECTION_REJECTED:",
3686 })
3687 }
Adam Langley524e7172015-02-20 16:04:00 -08003688 }
3689}
3690
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003691func addVersionNegotiationTests() {
3692 for i, shimVers := range tlsVersions {
3693 // Assemble flags to disable all newer versions on the shim.
3694 var flags []string
3695 for _, vers := range tlsVersions[i+1:] {
3696 flags = append(flags, vers.flag)
3697 }
3698
3699 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003700 protocols := []protocol{tls}
3701 if runnerVers.hasDTLS && shimVers.hasDTLS {
3702 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003703 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003704 for _, protocol := range protocols {
3705 expectedVersion := shimVers.version
3706 if runnerVers.version < shimVers.version {
3707 expectedVersion = runnerVers.version
3708 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003709
David Benjamin8b8c0062014-11-23 02:47:52 -05003710 suffix := shimVers.name + "-" + runnerVers.name
3711 if protocol == dtls {
3712 suffix += "-DTLS"
3713 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003714
David Benjamin1eb367c2014-12-12 18:17:51 -05003715 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3716
David Benjamin1e29a6b2014-12-10 02:27:24 -05003717 clientVers := shimVers.version
3718 if clientVers > VersionTLS10 {
3719 clientVers = VersionTLS10
3720 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003721 serverVers := expectedVersion
3722 if expectedVersion >= VersionTLS13 {
3723 serverVers = VersionTLS10
3724 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003725 testCases = append(testCases, testCase{
3726 protocol: protocol,
3727 testType: clientTest,
3728 name: "VersionNegotiation-Client-" + suffix,
3729 config: Config{
3730 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003731 Bugs: ProtocolBugs{
3732 ExpectInitialRecordVersion: clientVers,
3733 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003734 },
3735 flags: flags,
3736 expectedVersion: expectedVersion,
3737 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003738 testCases = append(testCases, testCase{
3739 protocol: protocol,
3740 testType: clientTest,
3741 name: "VersionNegotiation-Client2-" + suffix,
3742 config: Config{
3743 MaxVersion: runnerVers.version,
3744 Bugs: ProtocolBugs{
3745 ExpectInitialRecordVersion: clientVers,
3746 },
3747 },
3748 flags: []string{"-max-version", shimVersFlag},
3749 expectedVersion: expectedVersion,
3750 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003751
3752 testCases = append(testCases, testCase{
3753 protocol: protocol,
3754 testType: serverTest,
3755 name: "VersionNegotiation-Server-" + suffix,
3756 config: Config{
3757 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003758 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003759 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003760 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003761 },
3762 flags: flags,
3763 expectedVersion: expectedVersion,
3764 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003765 testCases = append(testCases, testCase{
3766 protocol: protocol,
3767 testType: serverTest,
3768 name: "VersionNegotiation-Server2-" + suffix,
3769 config: Config{
3770 MaxVersion: runnerVers.version,
3771 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003772 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003773 },
3774 },
3775 flags: []string{"-max-version", shimVersFlag},
3776 expectedVersion: expectedVersion,
3777 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003778 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003779 }
3780 }
David Benjamin95c69562016-06-29 18:15:03 -04003781
3782 // Test for version tolerance.
3783 testCases = append(testCases, testCase{
3784 testType: serverTest,
3785 name: "MinorVersionTolerance",
3786 config: Config{
3787 Bugs: ProtocolBugs{
3788 SendClientVersion: 0x03ff,
3789 },
3790 },
3791 expectedVersion: VersionTLS13,
3792 })
3793 testCases = append(testCases, testCase{
3794 testType: serverTest,
3795 name: "MajorVersionTolerance",
3796 config: Config{
3797 Bugs: ProtocolBugs{
3798 SendClientVersion: 0x0400,
3799 },
3800 },
3801 expectedVersion: VersionTLS13,
3802 })
3803 testCases = append(testCases, testCase{
3804 protocol: dtls,
3805 testType: serverTest,
3806 name: "MinorVersionTolerance-DTLS",
3807 config: Config{
3808 Bugs: ProtocolBugs{
3809 SendClientVersion: 0x03ff,
3810 },
3811 },
3812 expectedVersion: VersionTLS12,
3813 })
3814 testCases = append(testCases, testCase{
3815 protocol: dtls,
3816 testType: serverTest,
3817 name: "MajorVersionTolerance-DTLS",
3818 config: Config{
3819 Bugs: ProtocolBugs{
3820 SendClientVersion: 0x0400,
3821 },
3822 },
3823 expectedVersion: VersionTLS12,
3824 })
3825
3826 // Test that versions below 3.0 are rejected.
3827 testCases = append(testCases, testCase{
3828 testType: serverTest,
3829 name: "VersionTooLow",
3830 config: Config{
3831 Bugs: ProtocolBugs{
3832 SendClientVersion: 0x0200,
3833 },
3834 },
3835 shouldFail: true,
3836 expectedError: ":UNSUPPORTED_PROTOCOL:",
3837 })
3838 testCases = append(testCases, testCase{
3839 protocol: dtls,
3840 testType: serverTest,
3841 name: "VersionTooLow-DTLS",
3842 config: Config{
3843 Bugs: ProtocolBugs{
3844 // 0x0201 is the lowest version expressable in
3845 // DTLS.
3846 SendClientVersion: 0x0201,
3847 },
3848 },
3849 shouldFail: true,
3850 expectedError: ":UNSUPPORTED_PROTOCOL:",
3851 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003852
3853 // Test TLS 1.3's downgrade signal.
3854 testCases = append(testCases, testCase{
3855 name: "Downgrade-TLS12-Client",
3856 config: Config{
3857 Bugs: ProtocolBugs{
3858 NegotiateVersion: VersionTLS12,
3859 },
3860 },
3861 shouldFail: true,
3862 expectedError: ":DOWNGRADE_DETECTED:",
3863 })
3864 testCases = append(testCases, testCase{
3865 testType: serverTest,
3866 name: "Downgrade-TLS12-Server",
3867 config: Config{
3868 Bugs: ProtocolBugs{
3869 SendClientVersion: VersionTLS12,
3870 },
3871 },
3872 shouldFail: true,
3873 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3874 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02003875
3876 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
3877 // behave correctly when both real maximum and fallback versions are
3878 // set.
3879 testCases = append(testCases, testCase{
3880 name: "Downgrade-TLS12-Client-Fallback",
3881 config: Config{
3882 Bugs: ProtocolBugs{
3883 FailIfNotFallbackSCSV: true,
3884 },
3885 },
3886 flags: []string{
3887 "-max-version", strconv.Itoa(VersionTLS13),
3888 "-fallback-version", strconv.Itoa(VersionTLS12),
3889 },
3890 shouldFail: true,
3891 expectedError: ":DOWNGRADE_DETECTED:",
3892 })
3893 testCases = append(testCases, testCase{
3894 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
3895 flags: []string{
3896 "-max-version", strconv.Itoa(VersionTLS12),
3897 "-fallback-version", strconv.Itoa(VersionTLS12),
3898 },
3899 })
3900
3901 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
3902 // just have such connections fail than risk getting confused because we
3903 // didn't sent the 1.3 ClientHello.)
3904 testCases = append(testCases, testCase{
3905 name: "Downgrade-TLS12-Fallback-CheckVersion",
3906 config: Config{
3907 Bugs: ProtocolBugs{
3908 NegotiateVersion: VersionTLS13,
3909 FailIfNotFallbackSCSV: true,
3910 },
3911 },
3912 flags: []string{
3913 "-max-version", strconv.Itoa(VersionTLS13),
3914 "-fallback-version", strconv.Itoa(VersionTLS12),
3915 },
3916 shouldFail: true,
3917 expectedError: ":UNSUPPORTED_PROTOCOL:",
3918 })
3919
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003920}
3921
David Benjaminaccb4542014-12-12 23:44:33 -05003922func addMinimumVersionTests() {
3923 for i, shimVers := range tlsVersions {
3924 // Assemble flags to disable all older versions on the shim.
3925 var flags []string
3926 for _, vers := range tlsVersions[:i] {
3927 flags = append(flags, vers.flag)
3928 }
3929
3930 for _, runnerVers := range tlsVersions {
3931 protocols := []protocol{tls}
3932 if runnerVers.hasDTLS && shimVers.hasDTLS {
3933 protocols = append(protocols, dtls)
3934 }
3935 for _, protocol := range protocols {
3936 suffix := shimVers.name + "-" + runnerVers.name
3937 if protocol == dtls {
3938 suffix += "-DTLS"
3939 }
3940 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3941
David Benjaminaccb4542014-12-12 23:44:33 -05003942 var expectedVersion uint16
3943 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003944 var expectedClientError, expectedServerError string
3945 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003946 if runnerVers.version >= shimVers.version {
3947 expectedVersion = runnerVers.version
3948 } else {
3949 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003950 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3951 expectedServerLocalError = "remote error: protocol version not supported"
3952 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3953 // If the client's minimum version is TLS 1.3 and the runner's
3954 // maximum is below TLS 1.2, the runner will fail to select a
3955 // cipher before the shim rejects the selected version.
3956 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3957 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3958 } else {
3959 expectedClientError = expectedServerError
3960 expectedClientLocalError = expectedServerLocalError
3961 }
David Benjaminaccb4542014-12-12 23:44:33 -05003962 }
3963
3964 testCases = append(testCases, testCase{
3965 protocol: protocol,
3966 testType: clientTest,
3967 name: "MinimumVersion-Client-" + suffix,
3968 config: Config{
3969 MaxVersion: runnerVers.version,
3970 },
David Benjamin87909c02014-12-13 01:55:01 -05003971 flags: flags,
3972 expectedVersion: expectedVersion,
3973 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003974 expectedError: expectedClientError,
3975 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003976 })
3977 testCases = append(testCases, testCase{
3978 protocol: protocol,
3979 testType: clientTest,
3980 name: "MinimumVersion-Client2-" + suffix,
3981 config: Config{
3982 MaxVersion: runnerVers.version,
3983 },
David Benjamin87909c02014-12-13 01:55:01 -05003984 flags: []string{"-min-version", shimVersFlag},
3985 expectedVersion: expectedVersion,
3986 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003987 expectedError: expectedClientError,
3988 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003989 })
3990
3991 testCases = append(testCases, testCase{
3992 protocol: protocol,
3993 testType: serverTest,
3994 name: "MinimumVersion-Server-" + suffix,
3995 config: Config{
3996 MaxVersion: runnerVers.version,
3997 },
David Benjamin87909c02014-12-13 01:55:01 -05003998 flags: flags,
3999 expectedVersion: expectedVersion,
4000 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004001 expectedError: expectedServerError,
4002 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004003 })
4004 testCases = append(testCases, testCase{
4005 protocol: protocol,
4006 testType: serverTest,
4007 name: "MinimumVersion-Server2-" + suffix,
4008 config: Config{
4009 MaxVersion: runnerVers.version,
4010 },
David Benjamin87909c02014-12-13 01:55:01 -05004011 flags: []string{"-min-version", shimVersFlag},
4012 expectedVersion: expectedVersion,
4013 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004014 expectedError: expectedServerError,
4015 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004016 })
4017 }
4018 }
4019 }
4020}
4021
David Benjamine78bfde2014-09-06 12:45:15 -04004022func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004023 // TODO(davidben): Extensions, where applicable, all move their server
4024 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4025 // tests for both. Also test interaction with 0-RTT when implemented.
4026
David Benjamin97d17d92016-07-14 16:12:00 -04004027 // Repeat extensions tests all versions except SSL 3.0.
4028 for _, ver := range tlsVersions {
4029 if ver.version == VersionSSL30 {
4030 continue
4031 }
4032
4033 // TODO(davidben): Implement resumption in TLS 1.3.
4034 resumeSession := ver.version < VersionTLS13
4035
4036 // Test that duplicate extensions are rejected.
4037 testCases = append(testCases, testCase{
4038 testType: clientTest,
4039 name: "DuplicateExtensionClient-" + ver.name,
4040 config: Config{
4041 MaxVersion: ver.version,
4042 Bugs: ProtocolBugs{
4043 DuplicateExtension: true,
4044 },
David Benjamine78bfde2014-09-06 12:45:15 -04004045 },
David Benjamin97d17d92016-07-14 16:12:00 -04004046 shouldFail: true,
4047 expectedLocalError: "remote error: error decoding message",
4048 })
4049 testCases = append(testCases, testCase{
4050 testType: serverTest,
4051 name: "DuplicateExtensionServer-" + ver.name,
4052 config: Config{
4053 MaxVersion: ver.version,
4054 Bugs: ProtocolBugs{
4055 DuplicateExtension: true,
4056 },
David Benjamine78bfde2014-09-06 12:45:15 -04004057 },
David Benjamin97d17d92016-07-14 16:12:00 -04004058 shouldFail: true,
4059 expectedLocalError: "remote error: error decoding message",
4060 })
4061
4062 // Test SNI.
4063 testCases = append(testCases, testCase{
4064 testType: clientTest,
4065 name: "ServerNameExtensionClient-" + ver.name,
4066 config: Config{
4067 MaxVersion: ver.version,
4068 Bugs: ProtocolBugs{
4069 ExpectServerName: "example.com",
4070 },
David Benjamine78bfde2014-09-06 12:45:15 -04004071 },
David Benjamin97d17d92016-07-14 16:12:00 -04004072 flags: []string{"-host-name", "example.com"},
4073 })
4074 testCases = append(testCases, testCase{
4075 testType: clientTest,
4076 name: "ServerNameExtensionClientMismatch-" + ver.name,
4077 config: Config{
4078 MaxVersion: ver.version,
4079 Bugs: ProtocolBugs{
4080 ExpectServerName: "mismatch.com",
4081 },
David Benjamine78bfde2014-09-06 12:45:15 -04004082 },
David Benjamin97d17d92016-07-14 16:12:00 -04004083 flags: []string{"-host-name", "example.com"},
4084 shouldFail: true,
4085 expectedLocalError: "tls: unexpected server name",
4086 })
4087 testCases = append(testCases, testCase{
4088 testType: clientTest,
4089 name: "ServerNameExtensionClientMissing-" + ver.name,
4090 config: Config{
4091 MaxVersion: ver.version,
4092 Bugs: ProtocolBugs{
4093 ExpectServerName: "missing.com",
4094 },
David Benjamine78bfde2014-09-06 12:45:15 -04004095 },
David Benjamin97d17d92016-07-14 16:12:00 -04004096 shouldFail: true,
4097 expectedLocalError: "tls: unexpected server name",
4098 })
4099 testCases = append(testCases, testCase{
4100 testType: serverTest,
4101 name: "ServerNameExtensionServer-" + ver.name,
4102 config: Config{
4103 MaxVersion: ver.version,
4104 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004105 },
David Benjamin97d17d92016-07-14 16:12:00 -04004106 flags: []string{"-expect-server-name", "example.com"},
4107 resumeSession: resumeSession,
4108 })
4109
4110 // Test ALPN.
4111 testCases = append(testCases, testCase{
4112 testType: clientTest,
4113 name: "ALPNClient-" + ver.name,
4114 config: Config{
4115 MaxVersion: ver.version,
4116 NextProtos: []string{"foo"},
4117 },
4118 flags: []string{
4119 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4120 "-expect-alpn", "foo",
4121 },
4122 expectedNextProto: "foo",
4123 expectedNextProtoType: alpn,
4124 resumeSession: resumeSession,
4125 })
4126 testCases = append(testCases, testCase{
4127 testType: serverTest,
4128 name: "ALPNServer-" + ver.name,
4129 config: Config{
4130 MaxVersion: ver.version,
4131 NextProtos: []string{"foo", "bar", "baz"},
4132 },
4133 flags: []string{
4134 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4135 "-select-alpn", "foo",
4136 },
4137 expectedNextProto: "foo",
4138 expectedNextProtoType: alpn,
4139 resumeSession: resumeSession,
4140 })
4141 testCases = append(testCases, testCase{
4142 testType: serverTest,
4143 name: "ALPNServer-Decline-" + ver.name,
4144 config: Config{
4145 MaxVersion: ver.version,
4146 NextProtos: []string{"foo", "bar", "baz"},
4147 },
4148 flags: []string{"-decline-alpn"},
4149 expectNoNextProto: true,
4150 resumeSession: resumeSession,
4151 })
4152
4153 var emptyString string
4154 testCases = append(testCases, testCase{
4155 testType: clientTest,
4156 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4157 config: Config{
4158 MaxVersion: ver.version,
4159 NextProtos: []string{""},
4160 Bugs: ProtocolBugs{
4161 // A server returning an empty ALPN protocol
4162 // should be rejected.
4163 ALPNProtocol: &emptyString,
4164 },
4165 },
4166 flags: []string{
4167 "-advertise-alpn", "\x03foo",
4168 },
4169 shouldFail: true,
4170 expectedError: ":PARSE_TLSEXT:",
4171 })
4172 testCases = append(testCases, testCase{
4173 testType: serverTest,
4174 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4175 config: Config{
4176 MaxVersion: ver.version,
4177 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004178 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004179 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004180 },
David Benjamin97d17d92016-07-14 16:12:00 -04004181 flags: []string{
4182 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004183 },
David Benjamin97d17d92016-07-14 16:12:00 -04004184 shouldFail: true,
4185 expectedError: ":PARSE_TLSEXT:",
4186 })
4187
4188 // Test NPN and the interaction with ALPN.
4189 if ver.version < VersionTLS13 {
4190 // Test that the server prefers ALPN over NPN.
4191 testCases = append(testCases, testCase{
4192 testType: serverTest,
4193 name: "ALPNServer-Preferred-" + ver.name,
4194 config: Config{
4195 MaxVersion: ver.version,
4196 NextProtos: []string{"foo", "bar", "baz"},
4197 },
4198 flags: []string{
4199 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4200 "-select-alpn", "foo",
4201 "-advertise-npn", "\x03foo\x03bar\x03baz",
4202 },
4203 expectedNextProto: "foo",
4204 expectedNextProtoType: alpn,
4205 resumeSession: resumeSession,
4206 })
4207 testCases = append(testCases, testCase{
4208 testType: serverTest,
4209 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4210 config: Config{
4211 MaxVersion: ver.version,
4212 NextProtos: []string{"foo", "bar", "baz"},
4213 Bugs: ProtocolBugs{
4214 SwapNPNAndALPN: true,
4215 },
4216 },
4217 flags: []string{
4218 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4219 "-select-alpn", "foo",
4220 "-advertise-npn", "\x03foo\x03bar\x03baz",
4221 },
4222 expectedNextProto: "foo",
4223 expectedNextProtoType: alpn,
4224 resumeSession: resumeSession,
4225 })
4226
4227 // Test that negotiating both NPN and ALPN is forbidden.
4228 testCases = append(testCases, testCase{
4229 name: "NegotiateALPNAndNPN-" + ver.name,
4230 config: Config{
4231 MaxVersion: ver.version,
4232 NextProtos: []string{"foo", "bar", "baz"},
4233 Bugs: ProtocolBugs{
4234 NegotiateALPNAndNPN: true,
4235 },
4236 },
4237 flags: []string{
4238 "-advertise-alpn", "\x03foo",
4239 "-select-next-proto", "foo",
4240 },
4241 shouldFail: true,
4242 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4243 })
4244 testCases = append(testCases, testCase{
4245 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4246 config: Config{
4247 MaxVersion: ver.version,
4248 NextProtos: []string{"foo", "bar", "baz"},
4249 Bugs: ProtocolBugs{
4250 NegotiateALPNAndNPN: true,
4251 SwapNPNAndALPN: true,
4252 },
4253 },
4254 flags: []string{
4255 "-advertise-alpn", "\x03foo",
4256 "-select-next-proto", "foo",
4257 },
4258 shouldFail: true,
4259 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4260 })
4261
4262 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4263 testCases = append(testCases, testCase{
4264 name: "DisableNPN-" + ver.name,
4265 config: Config{
4266 MaxVersion: ver.version,
4267 NextProtos: []string{"foo"},
4268 },
4269 flags: []string{
4270 "-select-next-proto", "foo",
4271 "-disable-npn",
4272 },
4273 expectNoNextProto: true,
4274 })
4275 }
4276
4277 // Test ticket behavior.
4278 //
4279 // TODO(davidben): Add TLS 1.3 versions of these.
4280 if ver.version < VersionTLS13 {
4281 // Resume with a corrupt ticket.
4282 testCases = append(testCases, testCase{
4283 testType: serverTest,
4284 name: "CorruptTicket-" + ver.name,
4285 config: Config{
4286 MaxVersion: ver.version,
4287 Bugs: ProtocolBugs{
4288 CorruptTicket: true,
4289 },
4290 },
4291 resumeSession: true,
4292 expectResumeRejected: true,
4293 })
4294 // Test the ticket callback, with and without renewal.
4295 testCases = append(testCases, testCase{
4296 testType: serverTest,
4297 name: "TicketCallback-" + ver.name,
4298 config: Config{
4299 MaxVersion: ver.version,
4300 },
4301 resumeSession: true,
4302 flags: []string{"-use-ticket-callback"},
4303 })
4304 testCases = append(testCases, testCase{
4305 testType: serverTest,
4306 name: "TicketCallback-Renew-" + ver.name,
4307 config: Config{
4308 MaxVersion: ver.version,
4309 Bugs: ProtocolBugs{
4310 ExpectNewTicket: true,
4311 },
4312 },
4313 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4314 resumeSession: true,
4315 })
4316
4317 // Resume with an oversized session id.
4318 testCases = append(testCases, testCase{
4319 testType: serverTest,
4320 name: "OversizedSessionId-" + ver.name,
4321 config: Config{
4322 MaxVersion: ver.version,
4323 Bugs: ProtocolBugs{
4324 OversizedSessionId: true,
4325 },
4326 },
4327 resumeSession: true,
4328 shouldFail: true,
4329 expectedError: ":DECODE_ERROR:",
4330 })
4331 }
4332
4333 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4334 // are ignored.
4335 if ver.hasDTLS {
4336 testCases = append(testCases, testCase{
4337 protocol: dtls,
4338 name: "SRTP-Client-" + ver.name,
4339 config: Config{
4340 MaxVersion: ver.version,
4341 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4342 },
4343 flags: []string{
4344 "-srtp-profiles",
4345 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4346 },
4347 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4348 })
4349 testCases = append(testCases, testCase{
4350 protocol: dtls,
4351 testType: serverTest,
4352 name: "SRTP-Server-" + ver.name,
4353 config: Config{
4354 MaxVersion: ver.version,
4355 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4356 },
4357 flags: []string{
4358 "-srtp-profiles",
4359 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4360 },
4361 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4362 })
4363 // Test that the MKI is ignored.
4364 testCases = append(testCases, testCase{
4365 protocol: dtls,
4366 testType: serverTest,
4367 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4368 config: Config{
4369 MaxVersion: ver.version,
4370 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4371 Bugs: ProtocolBugs{
4372 SRTPMasterKeyIdentifer: "bogus",
4373 },
4374 },
4375 flags: []string{
4376 "-srtp-profiles",
4377 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4378 },
4379 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4380 })
4381 // Test that SRTP isn't negotiated on the server if there were
4382 // no matching profiles.
4383 testCases = append(testCases, testCase{
4384 protocol: dtls,
4385 testType: serverTest,
4386 name: "SRTP-Server-NoMatch-" + ver.name,
4387 config: Config{
4388 MaxVersion: ver.version,
4389 SRTPProtectionProfiles: []uint16{100, 101, 102},
4390 },
4391 flags: []string{
4392 "-srtp-profiles",
4393 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4394 },
4395 expectedSRTPProtectionProfile: 0,
4396 })
4397 // Test that the server returning an invalid SRTP profile is
4398 // flagged as an error by the client.
4399 testCases = append(testCases, testCase{
4400 protocol: dtls,
4401 name: "SRTP-Client-NoMatch-" + ver.name,
4402 config: Config{
4403 MaxVersion: ver.version,
4404 Bugs: ProtocolBugs{
4405 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4406 },
4407 },
4408 flags: []string{
4409 "-srtp-profiles",
4410 "SRTP_AES128_CM_SHA1_80",
4411 },
4412 shouldFail: true,
4413 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4414 })
4415 }
4416
4417 // Test SCT list.
4418 testCases = append(testCases, testCase{
4419 name: "SignedCertificateTimestampList-Client-" + ver.name,
4420 testType: clientTest,
4421 config: Config{
4422 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004423 },
David Benjamin97d17d92016-07-14 16:12:00 -04004424 flags: []string{
4425 "-enable-signed-cert-timestamps",
4426 "-expect-signed-cert-timestamps",
4427 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004428 },
David Benjamin97d17d92016-07-14 16:12:00 -04004429 resumeSession: resumeSession,
4430 })
4431 testCases = append(testCases, testCase{
4432 name: "SendSCTListOnResume-" + ver.name,
4433 config: Config{
4434 MaxVersion: ver.version,
4435 Bugs: ProtocolBugs{
4436 SendSCTListOnResume: []byte("bogus"),
4437 },
David Benjamind98452d2015-06-16 14:16:23 -04004438 },
David Benjamin97d17d92016-07-14 16:12:00 -04004439 flags: []string{
4440 "-enable-signed-cert-timestamps",
4441 "-expect-signed-cert-timestamps",
4442 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004443 },
David Benjamin97d17d92016-07-14 16:12:00 -04004444 resumeSession: resumeSession,
4445 })
4446 testCases = append(testCases, testCase{
4447 name: "SignedCertificateTimestampList-Server-" + ver.name,
4448 testType: serverTest,
4449 config: Config{
4450 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004451 },
David Benjamin97d17d92016-07-14 16:12:00 -04004452 flags: []string{
4453 "-signed-cert-timestamps",
4454 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004455 },
David Benjamin97d17d92016-07-14 16:12:00 -04004456 expectedSCTList: testSCTList,
4457 resumeSession: resumeSession,
4458 })
4459 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460
Paul Lietar4fac72e2015-09-09 13:44:55 +01004461 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004462 testType: clientTest,
4463 name: "ClientHelloPadding",
4464 config: Config{
4465 Bugs: ProtocolBugs{
4466 RequireClientHelloSize: 512,
4467 },
4468 },
4469 // This hostname just needs to be long enough to push the
4470 // ClientHello into F5's danger zone between 256 and 511 bytes
4471 // long.
4472 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4473 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004474
4475 // Extensions should not function in SSL 3.0.
4476 testCases = append(testCases, testCase{
4477 testType: serverTest,
4478 name: "SSLv3Extensions-NoALPN",
4479 config: Config{
4480 MaxVersion: VersionSSL30,
4481 NextProtos: []string{"foo", "bar", "baz"},
4482 },
4483 flags: []string{
4484 "-select-alpn", "foo",
4485 },
4486 expectNoNextProto: true,
4487 })
4488
4489 // Test session tickets separately as they follow a different codepath.
4490 testCases = append(testCases, testCase{
4491 testType: serverTest,
4492 name: "SSLv3Extensions-NoTickets",
4493 config: Config{
4494 MaxVersion: VersionSSL30,
4495 Bugs: ProtocolBugs{
4496 // Historically, session tickets in SSL 3.0
4497 // failed in different ways depending on whether
4498 // the client supported renegotiation_info.
4499 NoRenegotiationInfo: true,
4500 },
4501 },
4502 resumeSession: true,
4503 })
4504 testCases = append(testCases, testCase{
4505 testType: serverTest,
4506 name: "SSLv3Extensions-NoTickets2",
4507 config: Config{
4508 MaxVersion: VersionSSL30,
4509 },
4510 resumeSession: true,
4511 })
4512
4513 // But SSL 3.0 does send and process renegotiation_info.
4514 testCases = append(testCases, testCase{
4515 testType: serverTest,
4516 name: "SSLv3Extensions-RenegotiationInfo",
4517 config: Config{
4518 MaxVersion: VersionSSL30,
4519 Bugs: ProtocolBugs{
4520 RequireRenegotiationInfo: true,
4521 },
4522 },
4523 })
4524 testCases = append(testCases, testCase{
4525 testType: serverTest,
4526 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4527 config: Config{
4528 MaxVersion: VersionSSL30,
4529 Bugs: ProtocolBugs{
4530 NoRenegotiationInfo: true,
4531 SendRenegotiationSCSV: true,
4532 RequireRenegotiationInfo: true,
4533 },
4534 },
4535 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004536
4537 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4538 // in ServerHello.
4539 testCases = append(testCases, testCase{
4540 name: "NPN-Forbidden-TLS13",
4541 config: Config{
4542 MaxVersion: VersionTLS13,
4543 NextProtos: []string{"foo"},
4544 Bugs: ProtocolBugs{
4545 NegotiateNPNAtAllVersions: true,
4546 },
4547 },
4548 flags: []string{"-select-next-proto", "foo"},
4549 shouldFail: true,
4550 expectedError: ":ERROR_PARSING_EXTENSION:",
4551 })
4552 testCases = append(testCases, testCase{
4553 name: "EMS-Forbidden-TLS13",
4554 config: Config{
4555 MaxVersion: VersionTLS13,
4556 Bugs: ProtocolBugs{
4557 NegotiateEMSAtAllVersions: true,
4558 },
4559 },
4560 shouldFail: true,
4561 expectedError: ":ERROR_PARSING_EXTENSION:",
4562 })
4563 testCases = append(testCases, testCase{
4564 name: "RenegotiationInfo-Forbidden-TLS13",
4565 config: Config{
4566 MaxVersion: VersionTLS13,
4567 Bugs: ProtocolBugs{
4568 NegotiateRenegotiationInfoAtAllVersions: true,
4569 },
4570 },
4571 shouldFail: true,
4572 expectedError: ":ERROR_PARSING_EXTENSION:",
4573 })
4574 testCases = append(testCases, testCase{
4575 name: "ChannelID-Forbidden-TLS13",
4576 config: Config{
4577 MaxVersion: VersionTLS13,
4578 RequestChannelID: true,
4579 Bugs: ProtocolBugs{
4580 NegotiateChannelIDAtAllVersions: true,
4581 },
4582 },
4583 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4584 shouldFail: true,
4585 expectedError: ":ERROR_PARSING_EXTENSION:",
4586 })
4587 testCases = append(testCases, testCase{
4588 name: "Ticket-Forbidden-TLS13",
4589 config: Config{
4590 MaxVersion: VersionTLS12,
4591 },
4592 resumeConfig: &Config{
4593 MaxVersion: VersionTLS13,
4594 Bugs: ProtocolBugs{
4595 AdvertiseTicketExtension: true,
4596 },
4597 },
4598 resumeSession: true,
4599 shouldFail: true,
4600 expectedError: ":ERROR_PARSING_EXTENSION:",
4601 })
4602
4603 // Test that illegal extensions in TLS 1.3 are declined by the server if
4604 // offered in ClientHello. The runner's server will fail if this occurs,
4605 // so we exercise the offering path. (EMS and Renegotiation Info are
4606 // implicit in every test.)
4607 testCases = append(testCases, testCase{
4608 testType: serverTest,
4609 name: "ChannelID-Declined-TLS13",
4610 config: Config{
4611 MaxVersion: VersionTLS13,
4612 ChannelID: channelIDKey,
4613 },
4614 flags: []string{"-enable-channel-id"},
4615 })
4616 testCases = append(testCases, testCase{
4617 testType: serverTest,
4618 name: "NPN-Server",
4619 config: Config{
4620 MaxVersion: VersionTLS13,
4621 NextProtos: []string{"bar"},
4622 },
4623 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4624 })
David Benjamine78bfde2014-09-06 12:45:15 -04004625}
4626
David Benjamin01fe8202014-09-24 15:21:44 -04004627func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004628 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004629 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4630 if sessionVers.version >= VersionTLS13 {
4631 continue
4632 }
David Benjamin01fe8202014-09-24 15:21:44 -04004633 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004634 if resumeVers.version >= VersionTLS13 {
4635 continue
4636 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004637 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4638 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4639 // TLS 1.3 only shares ciphers with TLS 1.2, so
4640 // we skip certain combinations and use a
4641 // different cipher to test with.
4642 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4643 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4644 continue
4645 }
4646 }
4647
David Benjamin8b8c0062014-11-23 02:47:52 -05004648 protocols := []protocol{tls}
4649 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4650 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004651 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004652 for _, protocol := range protocols {
4653 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4654 if protocol == dtls {
4655 suffix += "-DTLS"
4656 }
4657
David Benjaminece3de92015-03-16 18:02:20 -04004658 if sessionVers.version == resumeVers.version {
4659 testCases = append(testCases, testCase{
4660 protocol: protocol,
4661 name: "Resume-Client" + suffix,
4662 resumeSession: true,
4663 config: Config{
4664 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004665 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004666 },
David Benjaminece3de92015-03-16 18:02:20 -04004667 expectedVersion: sessionVers.version,
4668 expectedResumeVersion: resumeVers.version,
4669 })
4670 } else {
4671 testCases = append(testCases, testCase{
4672 protocol: protocol,
4673 name: "Resume-Client-Mismatch" + suffix,
4674 resumeSession: true,
4675 config: Config{
4676 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004677 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004678 },
David Benjaminece3de92015-03-16 18:02:20 -04004679 expectedVersion: sessionVers.version,
4680 resumeConfig: &Config{
4681 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004682 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004683 Bugs: ProtocolBugs{
4684 AllowSessionVersionMismatch: true,
4685 },
4686 },
4687 expectedResumeVersion: resumeVers.version,
4688 shouldFail: true,
4689 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4690 })
4691 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004692
4693 testCases = append(testCases, testCase{
4694 protocol: protocol,
4695 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004696 resumeSession: true,
4697 config: Config{
4698 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004699 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004700 },
4701 expectedVersion: sessionVers.version,
4702 resumeConfig: &Config{
4703 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004704 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004705 },
4706 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004707 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004708 expectedResumeVersion: resumeVers.version,
4709 })
4710
David Benjamin8b8c0062014-11-23 02:47:52 -05004711 testCases = append(testCases, testCase{
4712 protocol: protocol,
4713 testType: serverTest,
4714 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004715 resumeSession: true,
4716 config: Config{
4717 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004718 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004719 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004720 expectedVersion: sessionVers.version,
4721 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004722 resumeConfig: &Config{
4723 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004724 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004725 },
4726 expectedResumeVersion: resumeVers.version,
4727 })
4728 }
David Benjamin01fe8202014-09-24 15:21:44 -04004729 }
4730 }
David Benjaminece3de92015-03-16 18:02:20 -04004731
Nick Harper1fd39d82016-06-14 18:14:35 -07004732 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004733 testCases = append(testCases, testCase{
4734 name: "Resume-Client-CipherMismatch",
4735 resumeSession: true,
4736 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004737 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004738 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4739 },
4740 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004741 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004742 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4743 Bugs: ProtocolBugs{
4744 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4745 },
4746 },
4747 shouldFail: true,
4748 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4749 })
David Benjamin01fe8202014-09-24 15:21:44 -04004750}
4751
Adam Langley2ae77d22014-10-28 17:29:33 -07004752func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004753 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004754 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004755 testType: serverTest,
4756 name: "Renegotiate-Server-Forbidden",
4757 config: Config{
4758 MaxVersion: VersionTLS12,
4759 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004760 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004761 shouldFail: true,
4762 expectedError: ":NO_RENEGOTIATION:",
4763 expectedLocalError: "remote error: no renegotiation",
4764 })
Adam Langley5021b222015-06-12 18:27:58 -07004765 // The server shouldn't echo the renegotiation extension unless
4766 // requested by the client.
4767 testCases = append(testCases, testCase{
4768 testType: serverTest,
4769 name: "Renegotiate-Server-NoExt",
4770 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004771 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004772 Bugs: ProtocolBugs{
4773 NoRenegotiationInfo: true,
4774 RequireRenegotiationInfo: true,
4775 },
4776 },
4777 shouldFail: true,
4778 expectedLocalError: "renegotiation extension missing",
4779 })
4780 // The renegotiation SCSV should be sufficient for the server to echo
4781 // the extension.
4782 testCases = append(testCases, testCase{
4783 testType: serverTest,
4784 name: "Renegotiate-Server-NoExt-SCSV",
4785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004786 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004787 Bugs: ProtocolBugs{
4788 NoRenegotiationInfo: true,
4789 SendRenegotiationSCSV: true,
4790 RequireRenegotiationInfo: true,
4791 },
4792 },
4793 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004794 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004795 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004797 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004798 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004799 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004800 },
4801 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004802 renegotiate: 1,
4803 flags: []string{
4804 "-renegotiate-freely",
4805 "-expect-total-renegotiations", "1",
4806 },
David Benjamincdea40c2015-03-19 14:09:43 -04004807 })
4808 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004809 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004810 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004811 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004812 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004813 Bugs: ProtocolBugs{
4814 EmptyRenegotiationInfo: true,
4815 },
4816 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004817 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004818 shouldFail: true,
4819 expectedError: ":RENEGOTIATION_MISMATCH:",
4820 })
4821 testCases = append(testCases, testCase{
4822 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004823 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004825 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004826 Bugs: ProtocolBugs{
4827 BadRenegotiationInfo: true,
4828 },
4829 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004830 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004831 shouldFail: true,
4832 expectedError: ":RENEGOTIATION_MISMATCH:",
4833 })
4834 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004835 name: "Renegotiate-Client-Downgrade",
4836 renegotiate: 1,
4837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004838 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004839 Bugs: ProtocolBugs{
4840 NoRenegotiationInfoAfterInitial: true,
4841 },
4842 },
4843 flags: []string{"-renegotiate-freely"},
4844 shouldFail: true,
4845 expectedError: ":RENEGOTIATION_MISMATCH:",
4846 })
4847 testCases = append(testCases, testCase{
4848 name: "Renegotiate-Client-Upgrade",
4849 renegotiate: 1,
4850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004851 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004852 Bugs: ProtocolBugs{
4853 NoRenegotiationInfoInInitial: true,
4854 },
4855 },
4856 flags: []string{"-renegotiate-freely"},
4857 shouldFail: true,
4858 expectedError: ":RENEGOTIATION_MISMATCH:",
4859 })
4860 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004861 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004862 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004864 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004865 Bugs: ProtocolBugs{
4866 NoRenegotiationInfo: true,
4867 },
4868 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004869 flags: []string{
4870 "-renegotiate-freely",
4871 "-expect-total-renegotiations", "1",
4872 },
David Benjamincff0b902015-05-15 23:09:47 -04004873 })
4874 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004875 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004876 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004877 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004878 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004879 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4880 },
4881 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004882 flags: []string{
4883 "-renegotiate-freely",
4884 "-expect-total-renegotiations", "1",
4885 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004886 })
4887 testCases = append(testCases, testCase{
4888 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004889 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004891 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4893 },
4894 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004895 flags: []string{
4896 "-renegotiate-freely",
4897 "-expect-total-renegotiations", "1",
4898 },
David Benjaminb16346b2015-04-08 19:16:58 -04004899 })
4900 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004901 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004902 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004903 config: Config{
4904 MaxVersion: VersionTLS10,
4905 Bugs: ProtocolBugs{
4906 RequireSameRenegoClientVersion: true,
4907 },
4908 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004909 flags: []string{
4910 "-renegotiate-freely",
4911 "-expect-total-renegotiations", "1",
4912 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004913 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004914 testCases = append(testCases, testCase{
4915 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004916 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004917 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004918 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004919 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4920 NextProtos: []string{"foo"},
4921 },
4922 flags: []string{
4923 "-false-start",
4924 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004925 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004926 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004927 },
4928 shimWritesFirst: true,
4929 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004930
4931 // Client-side renegotiation controls.
4932 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004933 name: "Renegotiate-Client-Forbidden-1",
4934 config: Config{
4935 MaxVersion: VersionTLS12,
4936 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004937 renegotiate: 1,
4938 shouldFail: true,
4939 expectedError: ":NO_RENEGOTIATION:",
4940 expectedLocalError: "remote error: no renegotiation",
4941 })
4942 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004943 name: "Renegotiate-Client-Once-1",
4944 config: Config{
4945 MaxVersion: VersionTLS12,
4946 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004947 renegotiate: 1,
4948 flags: []string{
4949 "-renegotiate-once",
4950 "-expect-total-renegotiations", "1",
4951 },
4952 })
4953 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004954 name: "Renegotiate-Client-Freely-1",
4955 config: Config{
4956 MaxVersion: VersionTLS12,
4957 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004958 renegotiate: 1,
4959 flags: []string{
4960 "-renegotiate-freely",
4961 "-expect-total-renegotiations", "1",
4962 },
4963 })
4964 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004965 name: "Renegotiate-Client-Once-2",
4966 config: Config{
4967 MaxVersion: VersionTLS12,
4968 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004969 renegotiate: 2,
4970 flags: []string{"-renegotiate-once"},
4971 shouldFail: true,
4972 expectedError: ":NO_RENEGOTIATION:",
4973 expectedLocalError: "remote error: no renegotiation",
4974 })
4975 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004976 name: "Renegotiate-Client-Freely-2",
4977 config: Config{
4978 MaxVersion: VersionTLS12,
4979 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004980 renegotiate: 2,
4981 flags: []string{
4982 "-renegotiate-freely",
4983 "-expect-total-renegotiations", "2",
4984 },
4985 })
Adam Langley27a0d082015-11-03 13:34:10 -08004986 testCases = append(testCases, testCase{
4987 name: "Renegotiate-Client-NoIgnore",
4988 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004989 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004990 Bugs: ProtocolBugs{
4991 SendHelloRequestBeforeEveryAppDataRecord: true,
4992 },
4993 },
4994 shouldFail: true,
4995 expectedError: ":NO_RENEGOTIATION:",
4996 })
4997 testCases = append(testCases, testCase{
4998 name: "Renegotiate-Client-Ignore",
4999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005000 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005001 Bugs: ProtocolBugs{
5002 SendHelloRequestBeforeEveryAppDataRecord: true,
5003 },
5004 },
5005 flags: []string{
5006 "-renegotiate-ignore",
5007 "-expect-total-renegotiations", "0",
5008 },
5009 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005010
David Benjamin397c8e62016-07-08 14:14:36 -07005011 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005012 testCases = append(testCases, testCase{
5013 name: "StrayHelloRequest",
5014 config: Config{
5015 MaxVersion: VersionTLS12,
5016 Bugs: ProtocolBugs{
5017 SendHelloRequestBeforeEveryHandshakeMessage: true,
5018 },
5019 },
5020 })
5021 testCases = append(testCases, testCase{
5022 name: "StrayHelloRequest-Packed",
5023 config: Config{
5024 MaxVersion: VersionTLS12,
5025 Bugs: ProtocolBugs{
5026 PackHandshakeFlight: true,
5027 SendHelloRequestBeforeEveryHandshakeMessage: true,
5028 },
5029 },
5030 })
5031
David Benjamin12d2c482016-07-24 10:56:51 -04005032 // Test renegotiation works if HelloRequest and server Finished come in
5033 // the same record.
5034 testCases = append(testCases, testCase{
5035 name: "Renegotiate-Client-Packed",
5036 config: Config{
5037 MaxVersion: VersionTLS12,
5038 Bugs: ProtocolBugs{
5039 PackHandshakeFlight: true,
5040 PackHelloRequestWithFinished: true,
5041 },
5042 },
5043 renegotiate: 1,
5044 flags: []string{
5045 "-renegotiate-freely",
5046 "-expect-total-renegotiations", "1",
5047 },
5048 })
5049
David Benjamin397c8e62016-07-08 14:14:36 -07005050 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04005051 //
5052 // TODO(davidben): This test current asserts that we ignore
5053 // HelloRequests, but we actually should hard reject them. Fix this
5054 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07005055 testCases = append(testCases, testCase{
5056 name: "Renegotiate-Client-TLS13",
5057 config: Config{
5058 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005059 Bugs: ProtocolBugs{
5060 SendHelloRequestBeforeEveryAppDataRecord: true,
5061 },
David Benjamin397c8e62016-07-08 14:14:36 -07005062 },
David Benjamin397c8e62016-07-08 14:14:36 -07005063 flags: []string{
5064 "-renegotiate-freely",
5065 },
David Benjamin397c8e62016-07-08 14:14:36 -07005066 })
5067
5068 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5069 testCases = append(testCases, testCase{
5070 name: "StrayHelloRequest-TLS13",
5071 config: Config{
5072 MaxVersion: VersionTLS13,
5073 Bugs: ProtocolBugs{
5074 SendHelloRequestBeforeEveryHandshakeMessage: true,
5075 },
5076 },
5077 shouldFail: true,
5078 expectedError: ":UNEXPECTED_MESSAGE:",
5079 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005080}
5081
David Benjamin5e961c12014-11-07 01:48:35 -05005082func addDTLSReplayTests() {
5083 // Test that sequence number replays are detected.
5084 testCases = append(testCases, testCase{
5085 protocol: dtls,
5086 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005087 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005088 replayWrites: true,
5089 })
5090
David Benjamin8e6db492015-07-25 18:29:23 -04005091 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005092 // than the retransmit window.
5093 testCases = append(testCases, testCase{
5094 protocol: dtls,
5095 name: "DTLS-Replay-LargeGaps",
5096 config: Config{
5097 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005098 SequenceNumberMapping: func(in uint64) uint64 {
5099 return in * 127
5100 },
David Benjamin5e961c12014-11-07 01:48:35 -05005101 },
5102 },
David Benjamin8e6db492015-07-25 18:29:23 -04005103 messageCount: 200,
5104 replayWrites: true,
5105 })
5106
5107 // Test the incoming sequence number changing non-monotonically.
5108 testCases = append(testCases, testCase{
5109 protocol: dtls,
5110 name: "DTLS-Replay-NonMonotonic",
5111 config: Config{
5112 Bugs: ProtocolBugs{
5113 SequenceNumberMapping: func(in uint64) uint64 {
5114 return in ^ 31
5115 },
5116 },
5117 },
5118 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005119 replayWrites: true,
5120 })
5121}
5122
Nick Harper60edffd2016-06-21 15:19:24 -07005123var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005124 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005125 id signatureAlgorithm
5126 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005127}{
Nick Harper60edffd2016-06-21 15:19:24 -07005128 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5129 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5130 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5131 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005132 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005133 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5134 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5135 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005136 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5137 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5138 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005139 // Tests for key types prior to TLS 1.2.
5140 {"RSA", 0, testCertRSA},
5141 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005142}
5143
Nick Harper60edffd2016-06-21 15:19:24 -07005144const fakeSigAlg1 signatureAlgorithm = 0x2a01
5145const fakeSigAlg2 signatureAlgorithm = 0xff01
5146
5147func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005148 // Not all ciphers involve a signature. Advertise a list which gives all
5149 // versions a signing cipher.
5150 signingCiphers := []uint16{
5151 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5152 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5153 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5154 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5155 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5156 }
5157
David Benjaminca3d5452016-07-14 12:51:01 -04005158 var allAlgorithms []signatureAlgorithm
5159 for _, alg := range testSignatureAlgorithms {
5160 if alg.id != 0 {
5161 allAlgorithms = append(allAlgorithms, alg.id)
5162 }
5163 }
5164
Nick Harper60edffd2016-06-21 15:19:24 -07005165 // Make sure each signature algorithm works. Include some fake values in
5166 // the list and ensure they're ignored.
5167 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005168 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005169 if (ver.version < VersionTLS12) != (alg.id == 0) {
5170 continue
5171 }
5172
5173 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5174 // or remove it in C.
5175 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005176 continue
5177 }
Nick Harper60edffd2016-06-21 15:19:24 -07005178
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005179 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005180 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005181 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5182 shouldFail = true
5183 }
5184 // RSA-PSS does not exist in TLS 1.2.
5185 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5186 shouldFail = true
5187 }
5188
5189 var signError, verifyError string
5190 if shouldFail {
5191 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5192 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005193 }
David Benjamin000800a2014-11-14 01:43:59 -05005194
David Benjamin1fb125c2016-07-08 18:52:12 -07005195 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005196
David Benjamin7a41d372016-07-09 11:21:54 -07005197 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005198 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005199 config: Config{
5200 MaxVersion: ver.version,
5201 ClientAuth: RequireAnyClientCert,
5202 VerifySignatureAlgorithms: []signatureAlgorithm{
5203 fakeSigAlg1,
5204 alg.id,
5205 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005206 },
David Benjamin7a41d372016-07-09 11:21:54 -07005207 },
5208 flags: []string{
5209 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5210 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5211 "-enable-all-curves",
5212 },
5213 shouldFail: shouldFail,
5214 expectedError: signError,
5215 expectedPeerSignatureAlgorithm: alg.id,
5216 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005217
David Benjamin7a41d372016-07-09 11:21:54 -07005218 testCases = append(testCases, testCase{
5219 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005220 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005221 config: Config{
5222 MaxVersion: ver.version,
5223 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5224 SignSignatureAlgorithms: []signatureAlgorithm{
5225 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005226 },
David Benjamin7a41d372016-07-09 11:21:54 -07005227 Bugs: ProtocolBugs{
5228 SkipECDSACurveCheck: shouldFail,
5229 IgnoreSignatureVersionChecks: shouldFail,
5230 // The client won't advertise 1.3-only algorithms after
5231 // version negotiation.
5232 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005233 },
David Benjamin7a41d372016-07-09 11:21:54 -07005234 },
5235 flags: []string{
5236 "-require-any-client-certificate",
5237 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5238 "-enable-all-curves",
5239 },
5240 shouldFail: shouldFail,
5241 expectedError: verifyError,
5242 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005243
5244 testCases = append(testCases, testCase{
5245 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005246 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005247 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005248 MaxVersion: ver.version,
5249 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005250 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005251 fakeSigAlg1,
5252 alg.id,
5253 fakeSigAlg2,
5254 },
5255 },
5256 flags: []string{
5257 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5258 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5259 "-enable-all-curves",
5260 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005261 shouldFail: shouldFail,
5262 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005263 expectedPeerSignatureAlgorithm: alg.id,
5264 })
5265
5266 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005267 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005268 config: Config{
5269 MaxVersion: ver.version,
5270 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005271 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005272 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005273 alg.id,
5274 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005275 Bugs: ProtocolBugs{
5276 SkipECDSACurveCheck: shouldFail,
5277 IgnoreSignatureVersionChecks: shouldFail,
5278 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005279 },
5280 flags: []string{
5281 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5282 "-enable-all-curves",
5283 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005284 shouldFail: shouldFail,
5285 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005286 })
David Benjamin5208fd42016-07-13 21:43:25 -04005287
5288 if !shouldFail {
5289 testCases = append(testCases, testCase{
5290 testType: serverTest,
5291 name: "ClientAuth-InvalidSignature" + suffix,
5292 config: Config{
5293 MaxVersion: ver.version,
5294 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5295 SignSignatureAlgorithms: []signatureAlgorithm{
5296 alg.id,
5297 },
5298 Bugs: ProtocolBugs{
5299 InvalidSignature: true,
5300 },
5301 },
5302 flags: []string{
5303 "-require-any-client-certificate",
5304 "-enable-all-curves",
5305 },
5306 shouldFail: true,
5307 expectedError: ":BAD_SIGNATURE:",
5308 })
5309
5310 testCases = append(testCases, testCase{
5311 name: "ServerAuth-InvalidSignature" + suffix,
5312 config: Config{
5313 MaxVersion: ver.version,
5314 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5315 CipherSuites: signingCiphers,
5316 SignSignatureAlgorithms: []signatureAlgorithm{
5317 alg.id,
5318 },
5319 Bugs: ProtocolBugs{
5320 InvalidSignature: true,
5321 },
5322 },
5323 flags: []string{"-enable-all-curves"},
5324 shouldFail: true,
5325 expectedError: ":BAD_SIGNATURE:",
5326 })
5327 }
David Benjaminca3d5452016-07-14 12:51:01 -04005328
5329 if ver.version >= VersionTLS12 && !shouldFail {
5330 testCases = append(testCases, testCase{
5331 name: "ClientAuth-Sign-Negotiate" + suffix,
5332 config: Config{
5333 MaxVersion: ver.version,
5334 ClientAuth: RequireAnyClientCert,
5335 VerifySignatureAlgorithms: allAlgorithms,
5336 },
5337 flags: []string{
5338 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5339 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5340 "-enable-all-curves",
5341 "-signing-prefs", strconv.Itoa(int(alg.id)),
5342 },
5343 expectedPeerSignatureAlgorithm: alg.id,
5344 })
5345
5346 testCases = append(testCases, testCase{
5347 testType: serverTest,
5348 name: "ServerAuth-Sign-Negotiate" + suffix,
5349 config: Config{
5350 MaxVersion: ver.version,
5351 CipherSuites: signingCiphers,
5352 VerifySignatureAlgorithms: allAlgorithms,
5353 },
5354 flags: []string{
5355 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5356 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5357 "-enable-all-curves",
5358 "-signing-prefs", strconv.Itoa(int(alg.id)),
5359 },
5360 expectedPeerSignatureAlgorithm: alg.id,
5361 })
5362 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005363 }
David Benjamin000800a2014-11-14 01:43:59 -05005364 }
5365
Nick Harper60edffd2016-06-21 15:19:24 -07005366 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005367 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005368 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005369 config: Config{
5370 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005371 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005372 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005373 signatureECDSAWithP521AndSHA512,
5374 signatureRSAPKCS1WithSHA384,
5375 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005376 },
5377 },
5378 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005379 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5380 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005381 },
Nick Harper60edffd2016-06-21 15:19:24 -07005382 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005383 })
5384
5385 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005386 name: "ClientAuth-SignatureType-TLS13",
5387 config: Config{
5388 ClientAuth: RequireAnyClientCert,
5389 MaxVersion: VersionTLS13,
5390 VerifySignatureAlgorithms: []signatureAlgorithm{
5391 signatureECDSAWithP521AndSHA512,
5392 signatureRSAPKCS1WithSHA384,
5393 signatureRSAPSSWithSHA384,
5394 signatureECDSAWithSHA1,
5395 },
5396 },
5397 flags: []string{
5398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5400 },
5401 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5402 })
5403
5404 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005405 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005406 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005408 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005410 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005411 signatureECDSAWithP521AndSHA512,
5412 signatureRSAPKCS1WithSHA384,
5413 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005414 },
5415 },
Nick Harper60edffd2016-06-21 15:19:24 -07005416 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005417 })
5418
Steven Valdez143e8b32016-07-11 13:19:03 -04005419 testCases = append(testCases, testCase{
5420 testType: serverTest,
5421 name: "ServerAuth-SignatureType-TLS13",
5422 config: Config{
5423 MaxVersion: VersionTLS13,
5424 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5425 VerifySignatureAlgorithms: []signatureAlgorithm{
5426 signatureECDSAWithP521AndSHA512,
5427 signatureRSAPKCS1WithSHA384,
5428 signatureRSAPSSWithSHA384,
5429 signatureECDSAWithSHA1,
5430 },
5431 },
5432 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5433 })
5434
David Benjamina95e9f32016-07-08 16:28:04 -07005435 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005436 testCases = append(testCases, testCase{
5437 testType: serverTest,
5438 name: "Verify-ClientAuth-SignatureType",
5439 config: Config{
5440 MaxVersion: VersionTLS12,
5441 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005442 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005443 signatureRSAPKCS1WithSHA256,
5444 },
5445 Bugs: ProtocolBugs{
5446 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5447 },
5448 },
5449 flags: []string{
5450 "-require-any-client-certificate",
5451 },
5452 shouldFail: true,
5453 expectedError: ":WRONG_SIGNATURE_TYPE:",
5454 })
5455
5456 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005457 testType: serverTest,
5458 name: "Verify-ClientAuth-SignatureType-TLS13",
5459 config: Config{
5460 MaxVersion: VersionTLS13,
5461 Certificates: []Certificate{rsaCertificate},
5462 SignSignatureAlgorithms: []signatureAlgorithm{
5463 signatureRSAPSSWithSHA256,
5464 },
5465 Bugs: ProtocolBugs{
5466 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5467 },
5468 },
5469 flags: []string{
5470 "-require-any-client-certificate",
5471 },
5472 shouldFail: true,
5473 expectedError: ":WRONG_SIGNATURE_TYPE:",
5474 })
5475
5476 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005477 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005478 config: Config{
5479 MaxVersion: VersionTLS12,
5480 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005481 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005482 signatureRSAPKCS1WithSHA256,
5483 },
5484 Bugs: ProtocolBugs{
5485 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5486 },
5487 },
5488 shouldFail: true,
5489 expectedError: ":WRONG_SIGNATURE_TYPE:",
5490 })
5491
Steven Valdez143e8b32016-07-11 13:19:03 -04005492 testCases = append(testCases, testCase{
5493 name: "Verify-ServerAuth-SignatureType-TLS13",
5494 config: Config{
5495 MaxVersion: VersionTLS13,
5496 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5497 SignSignatureAlgorithms: []signatureAlgorithm{
5498 signatureRSAPSSWithSHA256,
5499 },
5500 Bugs: ProtocolBugs{
5501 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5502 },
5503 },
5504 shouldFail: true,
5505 expectedError: ":WRONG_SIGNATURE_TYPE:",
5506 })
5507
David Benjamin51dd7d62016-07-08 16:07:01 -07005508 // Test that, if the list is missing, the peer falls back to SHA-1 in
5509 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005510 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005511 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005512 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005513 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005514 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005515 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005516 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005517 },
5518 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005519 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005520 },
5521 },
5522 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005523 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5524 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005525 },
5526 })
5527
5528 testCases = append(testCases, testCase{
5529 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005530 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005532 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005533 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005534 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005535 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005536 },
5537 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005538 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005539 },
5540 },
5541 })
David Benjamin72dc7832015-03-16 17:49:43 -04005542
David Benjamin51dd7d62016-07-08 16:07:01 -07005543 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005544 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005545 config: Config{
5546 MaxVersion: VersionTLS13,
5547 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005548 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005549 signatureRSAPKCS1WithSHA1,
5550 },
5551 Bugs: ProtocolBugs{
5552 NoSignatureAlgorithms: true,
5553 },
5554 },
5555 flags: []string{
5556 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5557 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5558 },
5559 shouldFail: true,
5560 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5561 })
5562
5563 testCases = append(testCases, testCase{
5564 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005565 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005566 config: Config{
5567 MaxVersion: VersionTLS13,
5568 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005569 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005570 signatureRSAPKCS1WithSHA1,
5571 },
5572 Bugs: ProtocolBugs{
5573 NoSignatureAlgorithms: true,
5574 },
5575 },
5576 shouldFail: true,
5577 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5578 })
5579
David Benjaminb62d2872016-07-18 14:55:02 +02005580 // Test that hash preferences are enforced. BoringSSL does not implement
5581 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005582 testCases = append(testCases, testCase{
5583 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005584 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005586 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005587 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005588 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005589 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005590 },
5591 Bugs: ProtocolBugs{
5592 IgnorePeerSignatureAlgorithmPreferences: true,
5593 },
5594 },
5595 flags: []string{"-require-any-client-certificate"},
5596 shouldFail: true,
5597 expectedError: ":WRONG_SIGNATURE_TYPE:",
5598 })
5599
5600 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005601 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005602 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005603 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005604 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005605 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005606 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005607 },
5608 Bugs: ProtocolBugs{
5609 IgnorePeerSignatureAlgorithmPreferences: true,
5610 },
5611 },
5612 shouldFail: true,
5613 expectedError: ":WRONG_SIGNATURE_TYPE:",
5614 })
David Benjaminb62d2872016-07-18 14:55:02 +02005615 testCases = append(testCases, testCase{
5616 testType: serverTest,
5617 name: "ClientAuth-Enforced-TLS13",
5618 config: Config{
5619 MaxVersion: VersionTLS13,
5620 Certificates: []Certificate{rsaCertificate},
5621 SignSignatureAlgorithms: []signatureAlgorithm{
5622 signatureRSAPKCS1WithMD5,
5623 },
5624 Bugs: ProtocolBugs{
5625 IgnorePeerSignatureAlgorithmPreferences: true,
5626 IgnoreSignatureVersionChecks: true,
5627 },
5628 },
5629 flags: []string{"-require-any-client-certificate"},
5630 shouldFail: true,
5631 expectedError: ":WRONG_SIGNATURE_TYPE:",
5632 })
5633
5634 testCases = append(testCases, testCase{
5635 name: "ServerAuth-Enforced-TLS13",
5636 config: Config{
5637 MaxVersion: VersionTLS13,
5638 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5639 SignSignatureAlgorithms: []signatureAlgorithm{
5640 signatureRSAPKCS1WithMD5,
5641 },
5642 Bugs: ProtocolBugs{
5643 IgnorePeerSignatureAlgorithmPreferences: true,
5644 IgnoreSignatureVersionChecks: true,
5645 },
5646 },
5647 shouldFail: true,
5648 expectedError: ":WRONG_SIGNATURE_TYPE:",
5649 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005650
5651 // Test that the agreed upon digest respects the client preferences and
5652 // the server digests.
5653 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005654 name: "NoCommonAlgorithms-Digests",
5655 config: Config{
5656 MaxVersion: VersionTLS12,
5657 ClientAuth: RequireAnyClientCert,
5658 VerifySignatureAlgorithms: []signatureAlgorithm{
5659 signatureRSAPKCS1WithSHA512,
5660 signatureRSAPKCS1WithSHA1,
5661 },
5662 },
5663 flags: []string{
5664 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5665 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5666 "-digest-prefs", "SHA256",
5667 },
5668 shouldFail: true,
5669 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5670 })
5671 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005672 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005673 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005674 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005675 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005676 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005677 signatureRSAPKCS1WithSHA512,
5678 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005679 },
5680 },
5681 flags: []string{
5682 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5683 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005684 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005685 },
David Benjaminca3d5452016-07-14 12:51:01 -04005686 shouldFail: true,
5687 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5688 })
5689 testCases = append(testCases, testCase{
5690 name: "NoCommonAlgorithms-TLS13",
5691 config: Config{
5692 MaxVersion: VersionTLS13,
5693 ClientAuth: RequireAnyClientCert,
5694 VerifySignatureAlgorithms: []signatureAlgorithm{
5695 signatureRSAPSSWithSHA512,
5696 signatureRSAPSSWithSHA384,
5697 },
5698 },
5699 flags: []string{
5700 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5701 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5702 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5703 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005704 shouldFail: true,
5705 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005706 })
5707 testCases = append(testCases, testCase{
5708 name: "Agree-Digest-SHA256",
5709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005710 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005711 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005712 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005713 signatureRSAPKCS1WithSHA1,
5714 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005715 },
5716 },
5717 flags: []string{
5718 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5719 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005720 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005721 },
Nick Harper60edffd2016-06-21 15:19:24 -07005722 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005723 })
5724 testCases = append(testCases, testCase{
5725 name: "Agree-Digest-SHA1",
5726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005727 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005728 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005729 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005730 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005731 },
5732 },
5733 flags: []string{
5734 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5735 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005736 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005737 },
Nick Harper60edffd2016-06-21 15:19:24 -07005738 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005739 })
5740 testCases = append(testCases, testCase{
5741 name: "Agree-Digest-Default",
5742 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005743 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005744 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005745 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005746 signatureRSAPKCS1WithSHA256,
5747 signatureECDSAWithP256AndSHA256,
5748 signatureRSAPKCS1WithSHA1,
5749 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005750 },
5751 },
5752 flags: []string{
5753 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5754 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5755 },
Nick Harper60edffd2016-06-21 15:19:24 -07005756 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005757 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005758
David Benjaminca3d5452016-07-14 12:51:01 -04005759 // Test that the signing preference list may include extra algorithms
5760 // without negotiation problems.
5761 testCases = append(testCases, testCase{
5762 testType: serverTest,
5763 name: "FilterExtraAlgorithms",
5764 config: Config{
5765 MaxVersion: VersionTLS12,
5766 VerifySignatureAlgorithms: []signatureAlgorithm{
5767 signatureRSAPKCS1WithSHA256,
5768 },
5769 },
5770 flags: []string{
5771 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5772 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5773 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5774 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5775 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5776 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5777 },
5778 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5779 })
5780
David Benjamin4c3ddf72016-06-29 18:13:53 -04005781 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5782 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005783 testCases = append(testCases, testCase{
5784 name: "CheckLeafCurve",
5785 config: Config{
5786 MaxVersion: VersionTLS12,
5787 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005788 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005789 },
5790 flags: []string{"-p384-only"},
5791 shouldFail: true,
5792 expectedError: ":BAD_ECC_CERT:",
5793 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005794
5795 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5796 testCases = append(testCases, testCase{
5797 name: "CheckLeafCurve-TLS13",
5798 config: Config{
5799 MaxVersion: VersionTLS13,
5800 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5801 Certificates: []Certificate{ecdsaP256Certificate},
5802 },
5803 flags: []string{"-p384-only"},
5804 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005805
5806 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5807 testCases = append(testCases, testCase{
5808 name: "ECDSACurveMismatch-Verify-TLS12",
5809 config: Config{
5810 MaxVersion: VersionTLS12,
5811 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5812 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005813 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005814 signatureECDSAWithP384AndSHA384,
5815 },
5816 },
5817 })
5818
5819 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5820 testCases = append(testCases, testCase{
5821 name: "ECDSACurveMismatch-Verify-TLS13",
5822 config: Config{
5823 MaxVersion: VersionTLS13,
5824 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5825 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005826 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005827 signatureECDSAWithP384AndSHA384,
5828 },
5829 Bugs: ProtocolBugs{
5830 SkipECDSACurveCheck: true,
5831 },
5832 },
5833 shouldFail: true,
5834 expectedError: ":WRONG_SIGNATURE_TYPE:",
5835 })
5836
5837 // Signature algorithm selection in TLS 1.3 should take the curve into
5838 // account.
5839 testCases = append(testCases, testCase{
5840 testType: serverTest,
5841 name: "ECDSACurveMismatch-Sign-TLS13",
5842 config: Config{
5843 MaxVersion: VersionTLS13,
5844 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005845 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005846 signatureECDSAWithP384AndSHA384,
5847 signatureECDSAWithP256AndSHA256,
5848 },
5849 },
5850 flags: []string{
5851 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5852 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5853 },
5854 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5855 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005856
5857 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5858 // server does not attempt to sign in that case.
5859 testCases = append(testCases, testCase{
5860 testType: serverTest,
5861 name: "RSA-PSS-Large",
5862 config: Config{
5863 MaxVersion: VersionTLS13,
5864 VerifySignatureAlgorithms: []signatureAlgorithm{
5865 signatureRSAPSSWithSHA512,
5866 },
5867 },
5868 flags: []string{
5869 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5870 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5871 },
5872 shouldFail: true,
5873 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5874 })
David Benjamin000800a2014-11-14 01:43:59 -05005875}
5876
David Benjamin83f90402015-01-27 01:09:43 -05005877// timeouts is the retransmit schedule for BoringSSL. It doubles and
5878// caps at 60 seconds. On the 13th timeout, it gives up.
5879var timeouts = []time.Duration{
5880 1 * time.Second,
5881 2 * time.Second,
5882 4 * time.Second,
5883 8 * time.Second,
5884 16 * time.Second,
5885 32 * time.Second,
5886 60 * time.Second,
5887 60 * time.Second,
5888 60 * time.Second,
5889 60 * time.Second,
5890 60 * time.Second,
5891 60 * time.Second,
5892 60 * time.Second,
5893}
5894
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005895// shortTimeouts is an alternate set of timeouts which would occur if the
5896// initial timeout duration was set to 250ms.
5897var shortTimeouts = []time.Duration{
5898 250 * time.Millisecond,
5899 500 * time.Millisecond,
5900 1 * time.Second,
5901 2 * time.Second,
5902 4 * time.Second,
5903 8 * time.Second,
5904 16 * time.Second,
5905 32 * time.Second,
5906 60 * time.Second,
5907 60 * time.Second,
5908 60 * time.Second,
5909 60 * time.Second,
5910 60 * time.Second,
5911}
5912
David Benjamin83f90402015-01-27 01:09:43 -05005913func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005914 // These tests work by coordinating some behavior on both the shim and
5915 // the runner.
5916 //
5917 // TimeoutSchedule configures the runner to send a series of timeout
5918 // opcodes to the shim (see packetAdaptor) immediately before reading
5919 // each peer handshake flight N. The timeout opcode both simulates a
5920 // timeout in the shim and acts as a synchronization point to help the
5921 // runner bracket each handshake flight.
5922 //
5923 // We assume the shim does not read from the channel eagerly. It must
5924 // first wait until it has sent flight N and is ready to receive
5925 // handshake flight N+1. At this point, it will process the timeout
5926 // opcode. It must then immediately respond with a timeout ACK and act
5927 // as if the shim was idle for the specified amount of time.
5928 //
5929 // The runner then drops all packets received before the ACK and
5930 // continues waiting for flight N. This ordering results in one attempt
5931 // at sending flight N to be dropped. For the test to complete, the
5932 // shim must send flight N again, testing that the shim implements DTLS
5933 // retransmit on a timeout.
5934
Steven Valdez143e8b32016-07-11 13:19:03 -04005935 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04005936 // likely be more epochs to cross and the final message's retransmit may
5937 // be more complex.
5938
David Benjamin585d7a42016-06-02 14:58:00 -04005939 for _, async := range []bool{true, false} {
5940 var tests []testCase
5941
5942 // Test that this is indeed the timeout schedule. Stress all
5943 // four patterns of handshake.
5944 for i := 1; i < len(timeouts); i++ {
5945 number := strconv.Itoa(i)
5946 tests = append(tests, testCase{
5947 protocol: dtls,
5948 name: "DTLS-Retransmit-Client-" + number,
5949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005950 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005951 Bugs: ProtocolBugs{
5952 TimeoutSchedule: timeouts[:i],
5953 },
5954 },
5955 resumeSession: true,
5956 })
5957 tests = append(tests, testCase{
5958 protocol: dtls,
5959 testType: serverTest,
5960 name: "DTLS-Retransmit-Server-" + number,
5961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005962 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005963 Bugs: ProtocolBugs{
5964 TimeoutSchedule: timeouts[:i],
5965 },
5966 },
5967 resumeSession: true,
5968 })
5969 }
5970
5971 // Test that exceeding the timeout schedule hits a read
5972 // timeout.
5973 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005974 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005975 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005977 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005978 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005979 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005980 },
5981 },
5982 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005983 shouldFail: true,
5984 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005985 })
David Benjamin585d7a42016-06-02 14:58:00 -04005986
5987 if async {
5988 // Test that timeout handling has a fudge factor, due to API
5989 // problems.
5990 tests = append(tests, testCase{
5991 protocol: dtls,
5992 name: "DTLS-Retransmit-Fudge",
5993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005994 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005995 Bugs: ProtocolBugs{
5996 TimeoutSchedule: []time.Duration{
5997 timeouts[0] - 10*time.Millisecond,
5998 },
5999 },
6000 },
6001 resumeSession: true,
6002 })
6003 }
6004
6005 // Test that the final Finished retransmitting isn't
6006 // duplicated if the peer badly fragments everything.
6007 tests = append(tests, testCase{
6008 testType: serverTest,
6009 protocol: dtls,
6010 name: "DTLS-Retransmit-Fragmented",
6011 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006012 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006013 Bugs: ProtocolBugs{
6014 TimeoutSchedule: []time.Duration{timeouts[0]},
6015 MaxHandshakeRecordLength: 2,
6016 },
6017 },
6018 })
6019
6020 // Test the timeout schedule when a shorter initial timeout duration is set.
6021 tests = append(tests, testCase{
6022 protocol: dtls,
6023 name: "DTLS-Retransmit-Short-Client",
6024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006025 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006026 Bugs: ProtocolBugs{
6027 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6028 },
6029 },
6030 resumeSession: true,
6031 flags: []string{"-initial-timeout-duration-ms", "250"},
6032 })
6033 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006034 protocol: dtls,
6035 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006036 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006037 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006038 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006039 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006040 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006041 },
6042 },
6043 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006044 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006045 })
David Benjamin585d7a42016-06-02 14:58:00 -04006046
6047 for _, test := range tests {
6048 if async {
6049 test.name += "-Async"
6050 test.flags = append(test.flags, "-async")
6051 }
6052
6053 testCases = append(testCases, test)
6054 }
David Benjamin83f90402015-01-27 01:09:43 -05006055 }
David Benjamin83f90402015-01-27 01:09:43 -05006056}
6057
David Benjaminc565ebb2015-04-03 04:06:36 -04006058func addExportKeyingMaterialTests() {
6059 for _, vers := range tlsVersions {
6060 if vers.version == VersionSSL30 {
6061 continue
6062 }
6063 testCases = append(testCases, testCase{
6064 name: "ExportKeyingMaterial-" + vers.name,
6065 config: Config{
6066 MaxVersion: vers.version,
6067 },
6068 exportKeyingMaterial: 1024,
6069 exportLabel: "label",
6070 exportContext: "context",
6071 useExportContext: true,
6072 })
6073 testCases = append(testCases, testCase{
6074 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6075 config: Config{
6076 MaxVersion: vers.version,
6077 },
6078 exportKeyingMaterial: 1024,
6079 })
6080 testCases = append(testCases, testCase{
6081 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6082 config: Config{
6083 MaxVersion: vers.version,
6084 },
6085 exportKeyingMaterial: 1024,
6086 useExportContext: true,
6087 })
6088 testCases = append(testCases, testCase{
6089 name: "ExportKeyingMaterial-Small-" + vers.name,
6090 config: Config{
6091 MaxVersion: vers.version,
6092 },
6093 exportKeyingMaterial: 1,
6094 exportLabel: "label",
6095 exportContext: "context",
6096 useExportContext: true,
6097 })
6098 }
6099 testCases = append(testCases, testCase{
6100 name: "ExportKeyingMaterial-SSL3",
6101 config: Config{
6102 MaxVersion: VersionSSL30,
6103 },
6104 exportKeyingMaterial: 1024,
6105 exportLabel: "label",
6106 exportContext: "context",
6107 useExportContext: true,
6108 shouldFail: true,
6109 expectedError: "failed to export keying material",
6110 })
6111}
6112
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006113func addTLSUniqueTests() {
6114 for _, isClient := range []bool{false, true} {
6115 for _, isResumption := range []bool{false, true} {
6116 for _, hasEMS := range []bool{false, true} {
6117 var suffix string
6118 if isResumption {
6119 suffix = "Resume-"
6120 } else {
6121 suffix = "Full-"
6122 }
6123
6124 if hasEMS {
6125 suffix += "EMS-"
6126 } else {
6127 suffix += "NoEMS-"
6128 }
6129
6130 if isClient {
6131 suffix += "Client"
6132 } else {
6133 suffix += "Server"
6134 }
6135
6136 test := testCase{
6137 name: "TLSUnique-" + suffix,
6138 testTLSUnique: true,
6139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006140 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006141 Bugs: ProtocolBugs{
6142 NoExtendedMasterSecret: !hasEMS,
6143 },
6144 },
6145 }
6146
6147 if isResumption {
6148 test.resumeSession = true
6149 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006150 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006151 Bugs: ProtocolBugs{
6152 NoExtendedMasterSecret: !hasEMS,
6153 },
6154 }
6155 }
6156
6157 if isResumption && !hasEMS {
6158 test.shouldFail = true
6159 test.expectedError = "failed to get tls-unique"
6160 }
6161
6162 testCases = append(testCases, test)
6163 }
6164 }
6165 }
6166}
6167
Adam Langley09505632015-07-30 18:10:13 -07006168func addCustomExtensionTests() {
6169 expectedContents := "custom extension"
6170 emptyString := ""
6171
6172 for _, isClient := range []bool{false, true} {
6173 suffix := "Server"
6174 flag := "-enable-server-custom-extension"
6175 testType := serverTest
6176 if isClient {
6177 suffix = "Client"
6178 flag = "-enable-client-custom-extension"
6179 testType = clientTest
6180 }
6181
6182 testCases = append(testCases, testCase{
6183 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006184 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006186 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006187 Bugs: ProtocolBugs{
6188 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006189 ExpectedCustomExtension: &expectedContents,
6190 },
6191 },
6192 flags: []string{flag},
6193 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006194 testCases = append(testCases, testCase{
6195 testType: testType,
6196 name: "CustomExtensions-" + suffix + "-TLS13",
6197 config: Config{
6198 MaxVersion: VersionTLS13,
6199 Bugs: ProtocolBugs{
6200 CustomExtension: expectedContents,
6201 ExpectedCustomExtension: &expectedContents,
6202 },
6203 },
6204 flags: []string{flag},
6205 })
Adam Langley09505632015-07-30 18:10:13 -07006206
6207 // If the parse callback fails, the handshake should also fail.
6208 testCases = append(testCases, testCase{
6209 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006210 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006212 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006213 Bugs: ProtocolBugs{
6214 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006215 ExpectedCustomExtension: &expectedContents,
6216 },
6217 },
David Benjamin399e7c92015-07-30 23:01:27 -04006218 flags: []string{flag},
6219 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006220 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6221 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006222 testCases = append(testCases, testCase{
6223 testType: testType,
6224 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6225 config: Config{
6226 MaxVersion: VersionTLS13,
6227 Bugs: ProtocolBugs{
6228 CustomExtension: expectedContents + "foo",
6229 ExpectedCustomExtension: &expectedContents,
6230 },
6231 },
6232 flags: []string{flag},
6233 shouldFail: true,
6234 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6235 })
Adam Langley09505632015-07-30 18:10:13 -07006236
6237 // If the add callback fails, the handshake should also fail.
6238 testCases = append(testCases, testCase{
6239 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006240 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006241 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006242 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006243 Bugs: ProtocolBugs{
6244 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006245 ExpectedCustomExtension: &expectedContents,
6246 },
6247 },
David Benjamin399e7c92015-07-30 23:01:27 -04006248 flags: []string{flag, "-custom-extension-fail-add"},
6249 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006250 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6251 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006252 testCases = append(testCases, testCase{
6253 testType: testType,
6254 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6255 config: Config{
6256 MaxVersion: VersionTLS13,
6257 Bugs: ProtocolBugs{
6258 CustomExtension: expectedContents,
6259 ExpectedCustomExtension: &expectedContents,
6260 },
6261 },
6262 flags: []string{flag, "-custom-extension-fail-add"},
6263 shouldFail: true,
6264 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6265 })
Adam Langley09505632015-07-30 18:10:13 -07006266
6267 // If the add callback returns zero, no extension should be
6268 // added.
6269 skipCustomExtension := expectedContents
6270 if isClient {
6271 // For the case where the client skips sending the
6272 // custom extension, the server must not “echo” it.
6273 skipCustomExtension = ""
6274 }
6275 testCases = append(testCases, testCase{
6276 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006277 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006279 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006280 Bugs: ProtocolBugs{
6281 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006282 ExpectedCustomExtension: &emptyString,
6283 },
6284 },
6285 flags: []string{flag, "-custom-extension-skip"},
6286 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006287 testCases = append(testCases, testCase{
6288 testType: testType,
6289 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6290 config: Config{
6291 MaxVersion: VersionTLS13,
6292 Bugs: ProtocolBugs{
6293 CustomExtension: skipCustomExtension,
6294 ExpectedCustomExtension: &emptyString,
6295 },
6296 },
6297 flags: []string{flag, "-custom-extension-skip"},
6298 })
Adam Langley09505632015-07-30 18:10:13 -07006299 }
6300
6301 // The custom extension add callback should not be called if the client
6302 // doesn't send the extension.
6303 testCases = append(testCases, testCase{
6304 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006305 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006307 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006308 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006309 ExpectedCustomExtension: &emptyString,
6310 },
6311 },
6312 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6313 })
Adam Langley2deb9842015-08-07 11:15:37 -07006314
Steven Valdez143e8b32016-07-11 13:19:03 -04006315 testCases = append(testCases, testCase{
6316 testType: serverTest,
6317 name: "CustomExtensions-NotCalled-Server-TLS13",
6318 config: Config{
6319 MaxVersion: VersionTLS13,
6320 Bugs: ProtocolBugs{
6321 ExpectedCustomExtension: &emptyString,
6322 },
6323 },
6324 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6325 })
6326
Adam Langley2deb9842015-08-07 11:15:37 -07006327 // Test an unknown extension from the server.
6328 testCases = append(testCases, testCase{
6329 testType: clientTest,
6330 name: "UnknownExtension-Client",
6331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006332 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006333 Bugs: ProtocolBugs{
6334 CustomExtension: expectedContents,
6335 },
6336 },
6337 shouldFail: true,
6338 expectedError: ":UNEXPECTED_EXTENSION:",
6339 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006340 testCases = append(testCases, testCase{
6341 testType: clientTest,
6342 name: "UnknownExtension-Client-TLS13",
6343 config: Config{
6344 MaxVersion: VersionTLS13,
6345 Bugs: ProtocolBugs{
6346 CustomExtension: expectedContents,
6347 },
6348 },
6349 shouldFail: true,
6350 expectedError: ":UNEXPECTED_EXTENSION:",
6351 })
Adam Langley09505632015-07-30 18:10:13 -07006352}
6353
David Benjaminb36a3952015-12-01 18:53:13 -05006354func addRSAClientKeyExchangeTests() {
6355 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6356 testCases = append(testCases, testCase{
6357 testType: serverTest,
6358 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6359 config: Config{
6360 // Ensure the ClientHello version and final
6361 // version are different, to detect if the
6362 // server uses the wrong one.
6363 MaxVersion: VersionTLS11,
6364 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6365 Bugs: ProtocolBugs{
6366 BadRSAClientKeyExchange: bad,
6367 },
6368 },
6369 shouldFail: true,
6370 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6371 })
6372 }
6373}
6374
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006375var testCurves = []struct {
6376 name string
6377 id CurveID
6378}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006379 {"P-256", CurveP256},
6380 {"P-384", CurveP384},
6381 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006382 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006383}
6384
Steven Valdez5440fe02016-07-18 12:40:30 -04006385const bogusCurve = 0x1234
6386
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006387func addCurveTests() {
6388 for _, curve := range testCurves {
6389 testCases = append(testCases, testCase{
6390 name: "CurveTest-Client-" + curve.name,
6391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006392 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006393 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6394 CurvePreferences: []CurveID{curve.id},
6395 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006396 flags: []string{"-enable-all-curves"},
6397 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006398 })
6399 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006400 name: "CurveTest-Client-" + curve.name + "-TLS13",
6401 config: Config{
6402 MaxVersion: VersionTLS13,
6403 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6404 CurvePreferences: []CurveID{curve.id},
6405 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006406 flags: []string{"-enable-all-curves"},
6407 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006408 })
6409 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006410 testType: serverTest,
6411 name: "CurveTest-Server-" + curve.name,
6412 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006413 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006414 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6415 CurvePreferences: []CurveID{curve.id},
6416 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006417 flags: []string{"-enable-all-curves"},
6418 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006419 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006420 testCases = append(testCases, testCase{
6421 testType: serverTest,
6422 name: "CurveTest-Server-" + curve.name + "-TLS13",
6423 config: Config{
6424 MaxVersion: VersionTLS13,
6425 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6426 CurvePreferences: []CurveID{curve.id},
6427 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006428 flags: []string{"-enable-all-curves"},
6429 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006430 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006431 }
David Benjamin241ae832016-01-15 03:04:54 -05006432
6433 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006434 testCases = append(testCases, testCase{
6435 testType: serverTest,
6436 name: "UnknownCurve",
6437 config: Config{
6438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6439 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6440 },
6441 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006442
6443 // The server must not consider ECDHE ciphers when there are no
6444 // supported curves.
6445 testCases = append(testCases, testCase{
6446 testType: serverTest,
6447 name: "NoSupportedCurves",
6448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006449 MaxVersion: VersionTLS12,
6450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6451 Bugs: ProtocolBugs{
6452 NoSupportedCurves: true,
6453 },
6454 },
6455 shouldFail: true,
6456 expectedError: ":NO_SHARED_CIPHER:",
6457 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006458 testCases = append(testCases, testCase{
6459 testType: serverTest,
6460 name: "NoSupportedCurves-TLS13",
6461 config: Config{
6462 MaxVersion: VersionTLS13,
6463 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6464 Bugs: ProtocolBugs{
6465 NoSupportedCurves: true,
6466 },
6467 },
6468 shouldFail: true,
6469 expectedError: ":NO_SHARED_CIPHER:",
6470 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006471
6472 // The server must fall back to another cipher when there are no
6473 // supported curves.
6474 testCases = append(testCases, testCase{
6475 testType: serverTest,
6476 name: "NoCommonCurves",
6477 config: Config{
6478 MaxVersion: VersionTLS12,
6479 CipherSuites: []uint16{
6480 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6481 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6482 },
6483 CurvePreferences: []CurveID{CurveP224},
6484 },
6485 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6486 })
6487
6488 // The client must reject bogus curves and disabled curves.
6489 testCases = append(testCases, testCase{
6490 name: "BadECDHECurve",
6491 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006492 MaxVersion: VersionTLS12,
6493 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6494 Bugs: ProtocolBugs{
6495 SendCurve: bogusCurve,
6496 },
6497 },
6498 shouldFail: true,
6499 expectedError: ":WRONG_CURVE:",
6500 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006501 testCases = append(testCases, testCase{
6502 name: "BadECDHECurve-TLS13",
6503 config: Config{
6504 MaxVersion: VersionTLS13,
6505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6506 Bugs: ProtocolBugs{
6507 SendCurve: bogusCurve,
6508 },
6509 },
6510 shouldFail: true,
6511 expectedError: ":WRONG_CURVE:",
6512 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006513
6514 testCases = append(testCases, testCase{
6515 name: "UnsupportedCurve",
6516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006517 MaxVersion: VersionTLS12,
6518 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6519 CurvePreferences: []CurveID{CurveP256},
6520 Bugs: ProtocolBugs{
6521 IgnorePeerCurvePreferences: true,
6522 },
6523 },
6524 flags: []string{"-p384-only"},
6525 shouldFail: true,
6526 expectedError: ":WRONG_CURVE:",
6527 })
6528
David Benjamin4f921572016-07-17 14:20:10 +02006529 testCases = append(testCases, testCase{
6530 // TODO(davidben): Add a TLS 1.3 version where
6531 // HelloRetryRequest requests an unsupported curve.
6532 name: "UnsupportedCurve-ServerHello-TLS13",
6533 config: Config{
6534 MaxVersion: VersionTLS12,
6535 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6536 CurvePreferences: []CurveID{CurveP384},
6537 Bugs: ProtocolBugs{
6538 SendCurve: CurveP256,
6539 },
6540 },
6541 flags: []string{"-p384-only"},
6542 shouldFail: true,
6543 expectedError: ":WRONG_CURVE:",
6544 })
6545
David Benjamin4c3ddf72016-06-29 18:13:53 -04006546 // Test invalid curve points.
6547 testCases = append(testCases, testCase{
6548 name: "InvalidECDHPoint-Client",
6549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006550 MaxVersion: VersionTLS12,
6551 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6552 CurvePreferences: []CurveID{CurveP256},
6553 Bugs: ProtocolBugs{
6554 InvalidECDHPoint: true,
6555 },
6556 },
6557 shouldFail: true,
6558 expectedError: ":INVALID_ENCODING:",
6559 })
6560 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006561 name: "InvalidECDHPoint-Client-TLS13",
6562 config: Config{
6563 MaxVersion: VersionTLS13,
6564 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6565 CurvePreferences: []CurveID{CurveP256},
6566 Bugs: ProtocolBugs{
6567 InvalidECDHPoint: true,
6568 },
6569 },
6570 shouldFail: true,
6571 expectedError: ":INVALID_ENCODING:",
6572 })
6573 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006574 testType: serverTest,
6575 name: "InvalidECDHPoint-Server",
6576 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006577 MaxVersion: VersionTLS12,
6578 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6579 CurvePreferences: []CurveID{CurveP256},
6580 Bugs: ProtocolBugs{
6581 InvalidECDHPoint: true,
6582 },
6583 },
6584 shouldFail: true,
6585 expectedError: ":INVALID_ENCODING:",
6586 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006587 testCases = append(testCases, testCase{
6588 testType: serverTest,
6589 name: "InvalidECDHPoint-Server-TLS13",
6590 config: Config{
6591 MaxVersion: VersionTLS13,
6592 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6593 CurvePreferences: []CurveID{CurveP256},
6594 Bugs: ProtocolBugs{
6595 InvalidECDHPoint: true,
6596 },
6597 },
6598 shouldFail: true,
6599 expectedError: ":INVALID_ENCODING:",
6600 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006601}
6602
Matt Braithwaite54217e42016-06-13 13:03:47 -07006603func addCECPQ1Tests() {
6604 testCases = append(testCases, testCase{
6605 testType: clientTest,
6606 name: "CECPQ1-Client-BadX25519Part",
6607 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006608 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006609 MinVersion: VersionTLS12,
6610 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6611 Bugs: ProtocolBugs{
6612 CECPQ1BadX25519Part: true,
6613 },
6614 },
6615 flags: []string{"-cipher", "kCECPQ1"},
6616 shouldFail: true,
6617 expectedLocalError: "local error: bad record MAC",
6618 })
6619 testCases = append(testCases, testCase{
6620 testType: clientTest,
6621 name: "CECPQ1-Client-BadNewhopePart",
6622 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006623 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006624 MinVersion: VersionTLS12,
6625 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6626 Bugs: ProtocolBugs{
6627 CECPQ1BadNewhopePart: true,
6628 },
6629 },
6630 flags: []string{"-cipher", "kCECPQ1"},
6631 shouldFail: true,
6632 expectedLocalError: "local error: bad record MAC",
6633 })
6634 testCases = append(testCases, testCase{
6635 testType: serverTest,
6636 name: "CECPQ1-Server-BadX25519Part",
6637 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006638 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006639 MinVersion: VersionTLS12,
6640 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6641 Bugs: ProtocolBugs{
6642 CECPQ1BadX25519Part: true,
6643 },
6644 },
6645 flags: []string{"-cipher", "kCECPQ1"},
6646 shouldFail: true,
6647 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6648 })
6649 testCases = append(testCases, testCase{
6650 testType: serverTest,
6651 name: "CECPQ1-Server-BadNewhopePart",
6652 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006653 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006654 MinVersion: VersionTLS12,
6655 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6656 Bugs: ProtocolBugs{
6657 CECPQ1BadNewhopePart: true,
6658 },
6659 },
6660 flags: []string{"-cipher", "kCECPQ1"},
6661 shouldFail: true,
6662 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6663 })
6664}
6665
David Benjamin4cc36ad2015-12-19 14:23:26 -05006666func addKeyExchangeInfoTests() {
6667 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006668 name: "KeyExchangeInfo-DHE-Client",
6669 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006670 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006671 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6672 Bugs: ProtocolBugs{
6673 // This is a 1234-bit prime number, generated
6674 // with:
6675 // openssl gendh 1234 | openssl asn1parse -i
6676 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6677 },
6678 },
David Benjamin9e68f192016-06-30 14:55:33 -04006679 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006680 })
6681 testCases = append(testCases, testCase{
6682 testType: serverTest,
6683 name: "KeyExchangeInfo-DHE-Server",
6684 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006685 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006686 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6687 },
6688 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006689 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006690 })
6691
6692 testCases = append(testCases, testCase{
6693 name: "KeyExchangeInfo-ECDHE-Client",
6694 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006695 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006696 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6697 CurvePreferences: []CurveID{CurveX25519},
6698 },
David Benjamin9e68f192016-06-30 14:55:33 -04006699 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006700 })
6701 testCases = append(testCases, testCase{
6702 testType: serverTest,
6703 name: "KeyExchangeInfo-ECDHE-Server",
6704 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006705 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006706 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6707 CurvePreferences: []CurveID{CurveX25519},
6708 },
David Benjamin9e68f192016-06-30 14:55:33 -04006709 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006710 })
6711}
6712
David Benjaminc9ae27c2016-06-24 22:56:37 -04006713func addTLS13RecordTests() {
6714 testCases = append(testCases, testCase{
6715 name: "TLS13-RecordPadding",
6716 config: Config{
6717 MaxVersion: VersionTLS13,
6718 MinVersion: VersionTLS13,
6719 Bugs: ProtocolBugs{
6720 RecordPadding: 10,
6721 },
6722 },
6723 })
6724
6725 testCases = append(testCases, testCase{
6726 name: "TLS13-EmptyRecords",
6727 config: Config{
6728 MaxVersion: VersionTLS13,
6729 MinVersion: VersionTLS13,
6730 Bugs: ProtocolBugs{
6731 OmitRecordContents: true,
6732 },
6733 },
6734 shouldFail: true,
6735 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6736 })
6737
6738 testCases = append(testCases, testCase{
6739 name: "TLS13-OnlyPadding",
6740 config: Config{
6741 MaxVersion: VersionTLS13,
6742 MinVersion: VersionTLS13,
6743 Bugs: ProtocolBugs{
6744 OmitRecordContents: true,
6745 RecordPadding: 10,
6746 },
6747 },
6748 shouldFail: true,
6749 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6750 })
6751
6752 testCases = append(testCases, testCase{
6753 name: "TLS13-WrongOuterRecord",
6754 config: Config{
6755 MaxVersion: VersionTLS13,
6756 MinVersion: VersionTLS13,
6757 Bugs: ProtocolBugs{
6758 OuterRecordType: recordTypeHandshake,
6759 },
6760 },
6761 shouldFail: true,
6762 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6763 })
6764}
6765
David Benjamin82261be2016-07-07 14:32:50 -07006766func addChangeCipherSpecTests() {
6767 // Test missing ChangeCipherSpecs.
6768 testCases = append(testCases, testCase{
6769 name: "SkipChangeCipherSpec-Client",
6770 config: Config{
6771 MaxVersion: VersionTLS12,
6772 Bugs: ProtocolBugs{
6773 SkipChangeCipherSpec: true,
6774 },
6775 },
6776 shouldFail: true,
6777 expectedError: ":UNEXPECTED_RECORD:",
6778 })
6779 testCases = append(testCases, testCase{
6780 testType: serverTest,
6781 name: "SkipChangeCipherSpec-Server",
6782 config: Config{
6783 MaxVersion: VersionTLS12,
6784 Bugs: ProtocolBugs{
6785 SkipChangeCipherSpec: true,
6786 },
6787 },
6788 shouldFail: true,
6789 expectedError: ":UNEXPECTED_RECORD:",
6790 })
6791 testCases = append(testCases, testCase{
6792 testType: serverTest,
6793 name: "SkipChangeCipherSpec-Server-NPN",
6794 config: Config{
6795 MaxVersion: VersionTLS12,
6796 NextProtos: []string{"bar"},
6797 Bugs: ProtocolBugs{
6798 SkipChangeCipherSpec: true,
6799 },
6800 },
6801 flags: []string{
6802 "-advertise-npn", "\x03foo\x03bar\x03baz",
6803 },
6804 shouldFail: true,
6805 expectedError: ":UNEXPECTED_RECORD:",
6806 })
6807
6808 // Test synchronization between the handshake and ChangeCipherSpec.
6809 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6810 // rejected. Test both with and without handshake packing to handle both
6811 // when the partial post-CCS message is in its own record and when it is
6812 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006813 for _, packed := range []bool{false, true} {
6814 var suffix string
6815 if packed {
6816 suffix = "-Packed"
6817 }
6818
6819 testCases = append(testCases, testCase{
6820 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6821 config: Config{
6822 MaxVersion: VersionTLS12,
6823 Bugs: ProtocolBugs{
6824 FragmentAcrossChangeCipherSpec: true,
6825 PackHandshakeFlight: packed,
6826 },
6827 },
6828 shouldFail: true,
6829 expectedError: ":UNEXPECTED_RECORD:",
6830 })
6831 testCases = append(testCases, testCase{
6832 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6833 config: Config{
6834 MaxVersion: VersionTLS12,
6835 },
6836 resumeSession: true,
6837 resumeConfig: &Config{
6838 MaxVersion: VersionTLS12,
6839 Bugs: ProtocolBugs{
6840 FragmentAcrossChangeCipherSpec: true,
6841 PackHandshakeFlight: packed,
6842 },
6843 },
6844 shouldFail: true,
6845 expectedError: ":UNEXPECTED_RECORD:",
6846 })
6847 testCases = append(testCases, testCase{
6848 testType: serverTest,
6849 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6850 config: Config{
6851 MaxVersion: VersionTLS12,
6852 Bugs: ProtocolBugs{
6853 FragmentAcrossChangeCipherSpec: true,
6854 PackHandshakeFlight: packed,
6855 },
6856 },
6857 shouldFail: true,
6858 expectedError: ":UNEXPECTED_RECORD:",
6859 })
6860 testCases = append(testCases, testCase{
6861 testType: serverTest,
6862 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6863 config: Config{
6864 MaxVersion: VersionTLS12,
6865 },
6866 resumeSession: true,
6867 resumeConfig: &Config{
6868 MaxVersion: VersionTLS12,
6869 Bugs: ProtocolBugs{
6870 FragmentAcrossChangeCipherSpec: true,
6871 PackHandshakeFlight: packed,
6872 },
6873 },
6874 shouldFail: true,
6875 expectedError: ":UNEXPECTED_RECORD:",
6876 })
6877 testCases = append(testCases, testCase{
6878 testType: serverTest,
6879 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6880 config: Config{
6881 MaxVersion: VersionTLS12,
6882 NextProtos: []string{"bar"},
6883 Bugs: ProtocolBugs{
6884 FragmentAcrossChangeCipherSpec: true,
6885 PackHandshakeFlight: packed,
6886 },
6887 },
6888 flags: []string{
6889 "-advertise-npn", "\x03foo\x03bar\x03baz",
6890 },
6891 shouldFail: true,
6892 expectedError: ":UNEXPECTED_RECORD:",
6893 })
6894 }
6895
David Benjamin61672812016-07-14 23:10:43 -04006896 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6897 // messages in the handshake queue. Do this by testing the server
6898 // reading the client Finished, reversing the flight so Finished comes
6899 // first.
6900 testCases = append(testCases, testCase{
6901 protocol: dtls,
6902 testType: serverTest,
6903 name: "SendUnencryptedFinished-DTLS",
6904 config: Config{
6905 MaxVersion: VersionTLS12,
6906 Bugs: ProtocolBugs{
6907 SendUnencryptedFinished: true,
6908 ReverseHandshakeFragments: true,
6909 },
6910 },
6911 shouldFail: true,
6912 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6913 })
6914
Steven Valdez143e8b32016-07-11 13:19:03 -04006915 // Test synchronization between encryption changes and the handshake in
6916 // TLS 1.3, where ChangeCipherSpec is implicit.
6917 testCases = append(testCases, testCase{
6918 name: "PartialEncryptedExtensionsWithServerHello",
6919 config: Config{
6920 MaxVersion: VersionTLS13,
6921 Bugs: ProtocolBugs{
6922 PartialEncryptedExtensionsWithServerHello: true,
6923 },
6924 },
6925 shouldFail: true,
6926 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6927 })
6928 testCases = append(testCases, testCase{
6929 testType: serverTest,
6930 name: "PartialClientFinishedWithClientHello",
6931 config: Config{
6932 MaxVersion: VersionTLS13,
6933 Bugs: ProtocolBugs{
6934 PartialClientFinishedWithClientHello: true,
6935 },
6936 },
6937 shouldFail: true,
6938 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6939 })
6940
David Benjamin82261be2016-07-07 14:32:50 -07006941 // Test that early ChangeCipherSpecs are handled correctly.
6942 testCases = append(testCases, testCase{
6943 testType: serverTest,
6944 name: "EarlyChangeCipherSpec-server-1",
6945 config: Config{
6946 MaxVersion: VersionTLS12,
6947 Bugs: ProtocolBugs{
6948 EarlyChangeCipherSpec: 1,
6949 },
6950 },
6951 shouldFail: true,
6952 expectedError: ":UNEXPECTED_RECORD:",
6953 })
6954 testCases = append(testCases, testCase{
6955 testType: serverTest,
6956 name: "EarlyChangeCipherSpec-server-2",
6957 config: Config{
6958 MaxVersion: VersionTLS12,
6959 Bugs: ProtocolBugs{
6960 EarlyChangeCipherSpec: 2,
6961 },
6962 },
6963 shouldFail: true,
6964 expectedError: ":UNEXPECTED_RECORD:",
6965 })
6966 testCases = append(testCases, testCase{
6967 protocol: dtls,
6968 name: "StrayChangeCipherSpec",
6969 config: Config{
6970 // TODO(davidben): Once DTLS 1.3 exists, test
6971 // that stray ChangeCipherSpec messages are
6972 // rejected.
6973 MaxVersion: VersionTLS12,
6974 Bugs: ProtocolBugs{
6975 StrayChangeCipherSpec: true,
6976 },
6977 },
6978 })
6979
6980 // Test that the contents of ChangeCipherSpec are checked.
6981 testCases = append(testCases, testCase{
6982 name: "BadChangeCipherSpec-1",
6983 config: Config{
6984 MaxVersion: VersionTLS12,
6985 Bugs: ProtocolBugs{
6986 BadChangeCipherSpec: []byte{2},
6987 },
6988 },
6989 shouldFail: true,
6990 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6991 })
6992 testCases = append(testCases, testCase{
6993 name: "BadChangeCipherSpec-2",
6994 config: Config{
6995 MaxVersion: VersionTLS12,
6996 Bugs: ProtocolBugs{
6997 BadChangeCipherSpec: []byte{1, 1},
6998 },
6999 },
7000 shouldFail: true,
7001 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7002 })
7003 testCases = append(testCases, testCase{
7004 protocol: dtls,
7005 name: "BadChangeCipherSpec-DTLS-1",
7006 config: Config{
7007 MaxVersion: VersionTLS12,
7008 Bugs: ProtocolBugs{
7009 BadChangeCipherSpec: []byte{2},
7010 },
7011 },
7012 shouldFail: true,
7013 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7014 })
7015 testCases = append(testCases, testCase{
7016 protocol: dtls,
7017 name: "BadChangeCipherSpec-DTLS-2",
7018 config: Config{
7019 MaxVersion: VersionTLS12,
7020 Bugs: ProtocolBugs{
7021 BadChangeCipherSpec: []byte{1, 1},
7022 },
7023 },
7024 shouldFail: true,
7025 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7026 })
7027}
7028
David Benjamin0b8d5da2016-07-15 00:39:56 -04007029func addWrongMessageTypeTests() {
7030 for _, protocol := range []protocol{tls, dtls} {
7031 var suffix string
7032 if protocol == dtls {
7033 suffix = "-DTLS"
7034 }
7035
7036 testCases = append(testCases, testCase{
7037 protocol: protocol,
7038 testType: serverTest,
7039 name: "WrongMessageType-ClientHello" + suffix,
7040 config: Config{
7041 MaxVersion: VersionTLS12,
7042 Bugs: ProtocolBugs{
7043 SendWrongMessageType: typeClientHello,
7044 },
7045 },
7046 shouldFail: true,
7047 expectedError: ":UNEXPECTED_MESSAGE:",
7048 expectedLocalError: "remote error: unexpected message",
7049 })
7050
7051 if protocol == dtls {
7052 testCases = append(testCases, testCase{
7053 protocol: protocol,
7054 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7055 config: Config{
7056 MaxVersion: VersionTLS12,
7057 Bugs: ProtocolBugs{
7058 SendWrongMessageType: typeHelloVerifyRequest,
7059 },
7060 },
7061 shouldFail: true,
7062 expectedError: ":UNEXPECTED_MESSAGE:",
7063 expectedLocalError: "remote error: unexpected message",
7064 })
7065 }
7066
7067 testCases = append(testCases, testCase{
7068 protocol: protocol,
7069 name: "WrongMessageType-ServerHello" + suffix,
7070 config: Config{
7071 MaxVersion: VersionTLS12,
7072 Bugs: ProtocolBugs{
7073 SendWrongMessageType: typeServerHello,
7074 },
7075 },
7076 shouldFail: true,
7077 expectedError: ":UNEXPECTED_MESSAGE:",
7078 expectedLocalError: "remote error: unexpected message",
7079 })
7080
7081 testCases = append(testCases, testCase{
7082 protocol: protocol,
7083 name: "WrongMessageType-ServerCertificate" + suffix,
7084 config: Config{
7085 MaxVersion: VersionTLS12,
7086 Bugs: ProtocolBugs{
7087 SendWrongMessageType: typeCertificate,
7088 },
7089 },
7090 shouldFail: true,
7091 expectedError: ":UNEXPECTED_MESSAGE:",
7092 expectedLocalError: "remote error: unexpected message",
7093 })
7094
7095 testCases = append(testCases, testCase{
7096 protocol: protocol,
7097 name: "WrongMessageType-CertificateStatus" + suffix,
7098 config: Config{
7099 MaxVersion: VersionTLS12,
7100 Bugs: ProtocolBugs{
7101 SendWrongMessageType: typeCertificateStatus,
7102 },
7103 },
7104 flags: []string{"-enable-ocsp-stapling"},
7105 shouldFail: true,
7106 expectedError: ":UNEXPECTED_MESSAGE:",
7107 expectedLocalError: "remote error: unexpected message",
7108 })
7109
7110 testCases = append(testCases, testCase{
7111 protocol: protocol,
7112 name: "WrongMessageType-ServerKeyExchange" + suffix,
7113 config: Config{
7114 MaxVersion: VersionTLS12,
7115 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7116 Bugs: ProtocolBugs{
7117 SendWrongMessageType: typeServerKeyExchange,
7118 },
7119 },
7120 shouldFail: true,
7121 expectedError: ":UNEXPECTED_MESSAGE:",
7122 expectedLocalError: "remote error: unexpected message",
7123 })
7124
7125 testCases = append(testCases, testCase{
7126 protocol: protocol,
7127 name: "WrongMessageType-CertificateRequest" + suffix,
7128 config: Config{
7129 MaxVersion: VersionTLS12,
7130 ClientAuth: RequireAnyClientCert,
7131 Bugs: ProtocolBugs{
7132 SendWrongMessageType: typeCertificateRequest,
7133 },
7134 },
7135 shouldFail: true,
7136 expectedError: ":UNEXPECTED_MESSAGE:",
7137 expectedLocalError: "remote error: unexpected message",
7138 })
7139
7140 testCases = append(testCases, testCase{
7141 protocol: protocol,
7142 name: "WrongMessageType-ServerHelloDone" + suffix,
7143 config: Config{
7144 MaxVersion: VersionTLS12,
7145 Bugs: ProtocolBugs{
7146 SendWrongMessageType: typeServerHelloDone,
7147 },
7148 },
7149 shouldFail: true,
7150 expectedError: ":UNEXPECTED_MESSAGE:",
7151 expectedLocalError: "remote error: unexpected message",
7152 })
7153
7154 testCases = append(testCases, testCase{
7155 testType: serverTest,
7156 protocol: protocol,
7157 name: "WrongMessageType-ClientCertificate" + suffix,
7158 config: Config{
7159 Certificates: []Certificate{rsaCertificate},
7160 MaxVersion: VersionTLS12,
7161 Bugs: ProtocolBugs{
7162 SendWrongMessageType: typeCertificate,
7163 },
7164 },
7165 flags: []string{"-require-any-client-certificate"},
7166 shouldFail: true,
7167 expectedError: ":UNEXPECTED_MESSAGE:",
7168 expectedLocalError: "remote error: unexpected message",
7169 })
7170
7171 testCases = append(testCases, testCase{
7172 testType: serverTest,
7173 protocol: protocol,
7174 name: "WrongMessageType-CertificateVerify" + suffix,
7175 config: Config{
7176 Certificates: []Certificate{rsaCertificate},
7177 MaxVersion: VersionTLS12,
7178 Bugs: ProtocolBugs{
7179 SendWrongMessageType: typeCertificateVerify,
7180 },
7181 },
7182 flags: []string{"-require-any-client-certificate"},
7183 shouldFail: true,
7184 expectedError: ":UNEXPECTED_MESSAGE:",
7185 expectedLocalError: "remote error: unexpected message",
7186 })
7187
7188 testCases = append(testCases, testCase{
7189 testType: serverTest,
7190 protocol: protocol,
7191 name: "WrongMessageType-ClientKeyExchange" + suffix,
7192 config: Config{
7193 MaxVersion: VersionTLS12,
7194 Bugs: ProtocolBugs{
7195 SendWrongMessageType: typeClientKeyExchange,
7196 },
7197 },
7198 shouldFail: true,
7199 expectedError: ":UNEXPECTED_MESSAGE:",
7200 expectedLocalError: "remote error: unexpected message",
7201 })
7202
7203 if protocol != dtls {
7204 testCases = append(testCases, testCase{
7205 testType: serverTest,
7206 protocol: protocol,
7207 name: "WrongMessageType-NextProtocol" + suffix,
7208 config: Config{
7209 MaxVersion: VersionTLS12,
7210 NextProtos: []string{"bar"},
7211 Bugs: ProtocolBugs{
7212 SendWrongMessageType: typeNextProtocol,
7213 },
7214 },
7215 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7216 shouldFail: true,
7217 expectedError: ":UNEXPECTED_MESSAGE:",
7218 expectedLocalError: "remote error: unexpected message",
7219 })
7220
7221 testCases = append(testCases, testCase{
7222 testType: serverTest,
7223 protocol: protocol,
7224 name: "WrongMessageType-ChannelID" + suffix,
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 ChannelID: channelIDKey,
7228 Bugs: ProtocolBugs{
7229 SendWrongMessageType: typeChannelID,
7230 },
7231 },
7232 flags: []string{
7233 "-expect-channel-id",
7234 base64.StdEncoding.EncodeToString(channelIDBytes),
7235 },
7236 shouldFail: true,
7237 expectedError: ":UNEXPECTED_MESSAGE:",
7238 expectedLocalError: "remote error: unexpected message",
7239 })
7240 }
7241
7242 testCases = append(testCases, testCase{
7243 testType: serverTest,
7244 protocol: protocol,
7245 name: "WrongMessageType-ClientFinished" + suffix,
7246 config: Config{
7247 MaxVersion: VersionTLS12,
7248 Bugs: ProtocolBugs{
7249 SendWrongMessageType: typeFinished,
7250 },
7251 },
7252 shouldFail: true,
7253 expectedError: ":UNEXPECTED_MESSAGE:",
7254 expectedLocalError: "remote error: unexpected message",
7255 })
7256
7257 testCases = append(testCases, testCase{
7258 protocol: protocol,
7259 name: "WrongMessageType-NewSessionTicket" + suffix,
7260 config: Config{
7261 MaxVersion: VersionTLS12,
7262 Bugs: ProtocolBugs{
7263 SendWrongMessageType: typeNewSessionTicket,
7264 },
7265 },
7266 shouldFail: true,
7267 expectedError: ":UNEXPECTED_MESSAGE:",
7268 expectedLocalError: "remote error: unexpected message",
7269 })
7270
7271 testCases = append(testCases, testCase{
7272 protocol: protocol,
7273 name: "WrongMessageType-ServerFinished" + suffix,
7274 config: Config{
7275 MaxVersion: VersionTLS12,
7276 Bugs: ProtocolBugs{
7277 SendWrongMessageType: typeFinished,
7278 },
7279 },
7280 shouldFail: true,
7281 expectedError: ":UNEXPECTED_MESSAGE:",
7282 expectedLocalError: "remote error: unexpected message",
7283 })
7284
7285 }
7286}
7287
Steven Valdez143e8b32016-07-11 13:19:03 -04007288func addTLS13WrongMessageTypeTests() {
7289 testCases = append(testCases, testCase{
7290 testType: serverTest,
7291 name: "WrongMessageType-TLS13-ClientHello",
7292 config: Config{
7293 MaxVersion: VersionTLS13,
7294 Bugs: ProtocolBugs{
7295 SendWrongMessageType: typeClientHello,
7296 },
7297 },
7298 shouldFail: true,
7299 expectedError: ":UNEXPECTED_MESSAGE:",
7300 expectedLocalError: "remote error: unexpected message",
7301 })
7302
7303 testCases = append(testCases, testCase{
7304 name: "WrongMessageType-TLS13-ServerHello",
7305 config: Config{
7306 MaxVersion: VersionTLS13,
7307 Bugs: ProtocolBugs{
7308 SendWrongMessageType: typeServerHello,
7309 },
7310 },
7311 shouldFail: true,
7312 expectedError: ":UNEXPECTED_MESSAGE:",
7313 // The alert comes in with the wrong encryption.
7314 expectedLocalError: "local error: bad record MAC",
7315 })
7316
7317 testCases = append(testCases, testCase{
7318 name: "WrongMessageType-TLS13-EncryptedExtensions",
7319 config: Config{
7320 MaxVersion: VersionTLS13,
7321 Bugs: ProtocolBugs{
7322 SendWrongMessageType: typeEncryptedExtensions,
7323 },
7324 },
7325 shouldFail: true,
7326 expectedError: ":UNEXPECTED_MESSAGE:",
7327 expectedLocalError: "remote error: unexpected message",
7328 })
7329
7330 testCases = append(testCases, testCase{
7331 name: "WrongMessageType-TLS13-CertificateRequest",
7332 config: Config{
7333 MaxVersion: VersionTLS13,
7334 ClientAuth: RequireAnyClientCert,
7335 Bugs: ProtocolBugs{
7336 SendWrongMessageType: typeCertificateRequest,
7337 },
7338 },
7339 shouldFail: true,
7340 expectedError: ":UNEXPECTED_MESSAGE:",
7341 expectedLocalError: "remote error: unexpected message",
7342 })
7343
7344 testCases = append(testCases, testCase{
7345 name: "WrongMessageType-TLS13-ServerCertificate",
7346 config: Config{
7347 MaxVersion: VersionTLS13,
7348 Bugs: ProtocolBugs{
7349 SendWrongMessageType: typeCertificate,
7350 },
7351 },
7352 shouldFail: true,
7353 expectedError: ":UNEXPECTED_MESSAGE:",
7354 expectedLocalError: "remote error: unexpected message",
7355 })
7356
7357 testCases = append(testCases, testCase{
7358 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7359 config: Config{
7360 MaxVersion: VersionTLS13,
7361 Bugs: ProtocolBugs{
7362 SendWrongMessageType: typeCertificateVerify,
7363 },
7364 },
7365 shouldFail: true,
7366 expectedError: ":UNEXPECTED_MESSAGE:",
7367 expectedLocalError: "remote error: unexpected message",
7368 })
7369
7370 testCases = append(testCases, testCase{
7371 name: "WrongMessageType-TLS13-ServerFinished",
7372 config: Config{
7373 MaxVersion: VersionTLS13,
7374 Bugs: ProtocolBugs{
7375 SendWrongMessageType: typeFinished,
7376 },
7377 },
7378 shouldFail: true,
7379 expectedError: ":UNEXPECTED_MESSAGE:",
7380 expectedLocalError: "remote error: unexpected message",
7381 })
7382
7383 testCases = append(testCases, testCase{
7384 testType: serverTest,
7385 name: "WrongMessageType-TLS13-ClientCertificate",
7386 config: Config{
7387 Certificates: []Certificate{rsaCertificate},
7388 MaxVersion: VersionTLS13,
7389 Bugs: ProtocolBugs{
7390 SendWrongMessageType: typeCertificate,
7391 },
7392 },
7393 flags: []string{"-require-any-client-certificate"},
7394 shouldFail: true,
7395 expectedError: ":UNEXPECTED_MESSAGE:",
7396 expectedLocalError: "remote error: unexpected message",
7397 })
7398
7399 testCases = append(testCases, testCase{
7400 testType: serverTest,
7401 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7402 config: Config{
7403 Certificates: []Certificate{rsaCertificate},
7404 MaxVersion: VersionTLS13,
7405 Bugs: ProtocolBugs{
7406 SendWrongMessageType: typeCertificateVerify,
7407 },
7408 },
7409 flags: []string{"-require-any-client-certificate"},
7410 shouldFail: true,
7411 expectedError: ":UNEXPECTED_MESSAGE:",
7412 expectedLocalError: "remote error: unexpected message",
7413 })
7414
7415 testCases = append(testCases, testCase{
7416 testType: serverTest,
7417 name: "WrongMessageType-TLS13-ClientFinished",
7418 config: Config{
7419 MaxVersion: VersionTLS13,
7420 Bugs: ProtocolBugs{
7421 SendWrongMessageType: typeFinished,
7422 },
7423 },
7424 shouldFail: true,
7425 expectedError: ":UNEXPECTED_MESSAGE:",
7426 expectedLocalError: "remote error: unexpected message",
7427 })
7428}
7429
7430func addTLS13HandshakeTests() {
7431 testCases = append(testCases, testCase{
7432 testType: clientTest,
7433 name: "MissingKeyShare-Client",
7434 config: Config{
7435 MaxVersion: VersionTLS13,
7436 Bugs: ProtocolBugs{
7437 MissingKeyShare: true,
7438 },
7439 },
7440 shouldFail: true,
7441 expectedError: ":MISSING_KEY_SHARE:",
7442 })
7443
7444 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007445 testType: serverTest,
7446 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007447 config: Config{
7448 MaxVersion: VersionTLS13,
7449 Bugs: ProtocolBugs{
7450 MissingKeyShare: true,
7451 },
7452 },
7453 shouldFail: true,
7454 expectedError: ":MISSING_KEY_SHARE:",
7455 })
7456
7457 testCases = append(testCases, testCase{
7458 testType: clientTest,
7459 name: "ClientHelloMissingKeyShare",
7460 config: Config{
7461 MaxVersion: VersionTLS13,
7462 Bugs: ProtocolBugs{
7463 MissingKeyShare: true,
7464 },
7465 },
7466 shouldFail: true,
7467 expectedError: ":MISSING_KEY_SHARE:",
7468 })
7469
7470 testCases = append(testCases, testCase{
7471 testType: clientTest,
7472 name: "MissingKeyShare",
7473 config: Config{
7474 MaxVersion: VersionTLS13,
7475 Bugs: ProtocolBugs{
7476 MissingKeyShare: true,
7477 },
7478 },
7479 shouldFail: true,
7480 expectedError: ":MISSING_KEY_SHARE:",
7481 })
7482
7483 testCases = append(testCases, testCase{
7484 testType: serverTest,
7485 name: "DuplicateKeyShares",
7486 config: Config{
7487 MaxVersion: VersionTLS13,
7488 Bugs: ProtocolBugs{
7489 DuplicateKeyShares: true,
7490 },
7491 },
7492 })
7493
7494 testCases = append(testCases, testCase{
7495 testType: clientTest,
7496 name: "EmptyEncryptedExtensions",
7497 config: Config{
7498 MaxVersion: VersionTLS13,
7499 Bugs: ProtocolBugs{
7500 EmptyEncryptedExtensions: true,
7501 },
7502 },
7503 shouldFail: true,
7504 expectedLocalError: "remote error: error decoding message",
7505 })
7506
7507 testCases = append(testCases, testCase{
7508 testType: clientTest,
7509 name: "EncryptedExtensionsWithKeyShare",
7510 config: Config{
7511 MaxVersion: VersionTLS13,
7512 Bugs: ProtocolBugs{
7513 EncryptedExtensionsWithKeyShare: true,
7514 },
7515 },
7516 shouldFail: true,
7517 expectedLocalError: "remote error: unsupported extension",
7518 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007519
7520 testCases = append(testCases, testCase{
7521 testType: serverTest,
7522 name: "SendHelloRetryRequest",
7523 config: Config{
7524 MaxVersion: VersionTLS13,
7525 // Require a HelloRetryRequest for every curve.
7526 DefaultCurves: []CurveID{},
7527 },
7528 expectedCurveID: CurveX25519,
7529 })
7530
7531 testCases = append(testCases, testCase{
7532 testType: serverTest,
7533 name: "SendHelloRetryRequest-2",
7534 config: Config{
7535 MaxVersion: VersionTLS13,
7536 DefaultCurves: []CurveID{CurveP384},
7537 },
7538 // Although the ClientHello did not predict our preferred curve,
7539 // we always select it whether it is predicted or not.
7540 expectedCurveID: CurveX25519,
7541 })
7542
7543 testCases = append(testCases, testCase{
7544 name: "UnknownCurve-HelloRetryRequest",
7545 config: Config{
7546 MaxVersion: VersionTLS13,
7547 // P-384 requires HelloRetryRequest in BoringSSL.
7548 CurvePreferences: []CurveID{CurveP384},
7549 Bugs: ProtocolBugs{
7550 SendHelloRetryRequestCurve: bogusCurve,
7551 },
7552 },
7553 shouldFail: true,
7554 expectedError: ":WRONG_CURVE:",
7555 })
7556
7557 testCases = append(testCases, testCase{
7558 name: "DisabledCurve-HelloRetryRequest",
7559 config: Config{
7560 MaxVersion: VersionTLS13,
7561 CurvePreferences: []CurveID{CurveP256},
7562 Bugs: ProtocolBugs{
7563 IgnorePeerCurvePreferences: true,
7564 },
7565 },
7566 flags: []string{"-p384-only"},
7567 shouldFail: true,
7568 expectedError: ":WRONG_CURVE:",
7569 })
7570
7571 testCases = append(testCases, testCase{
7572 name: "UnnecessaryHelloRetryRequest",
7573 config: Config{
7574 MaxVersion: VersionTLS13,
7575 Bugs: ProtocolBugs{
7576 UnnecessaryHelloRetryRequest: true,
7577 },
7578 },
7579 shouldFail: true,
7580 expectedError: ":WRONG_CURVE:",
7581 })
7582
7583 testCases = append(testCases, testCase{
7584 name: "SecondHelloRetryRequest",
7585 config: Config{
7586 MaxVersion: VersionTLS13,
7587 // P-384 requires HelloRetryRequest in BoringSSL.
7588 CurvePreferences: []CurveID{CurveP384},
7589 Bugs: ProtocolBugs{
7590 SecondHelloRetryRequest: true,
7591 },
7592 },
7593 shouldFail: true,
7594 expectedError: ":UNEXPECTED_MESSAGE:",
7595 })
7596
7597 testCases = append(testCases, testCase{
7598 testType: serverTest,
7599 name: "SecondClientHelloMissingKeyShare",
7600 config: Config{
7601 MaxVersion: VersionTLS13,
7602 DefaultCurves: []CurveID{},
7603 Bugs: ProtocolBugs{
7604 SecondClientHelloMissingKeyShare: true,
7605 },
7606 },
7607 shouldFail: true,
7608 expectedError: ":MISSING_KEY_SHARE:",
7609 })
7610
7611 testCases = append(testCases, testCase{
7612 testType: serverTest,
7613 name: "SecondClientHelloWrongCurve",
7614 config: Config{
7615 MaxVersion: VersionTLS13,
7616 DefaultCurves: []CurveID{},
7617 Bugs: ProtocolBugs{
7618 MisinterpretHelloRetryRequestCurve: CurveP521,
7619 },
7620 },
7621 shouldFail: true,
7622 expectedError: ":WRONG_CURVE:",
7623 })
7624
7625 testCases = append(testCases, testCase{
7626 name: "HelloRetryRequestVersionMismatch",
7627 config: Config{
7628 MaxVersion: VersionTLS13,
7629 // P-384 requires HelloRetryRequest in BoringSSL.
7630 CurvePreferences: []CurveID{CurveP384},
7631 Bugs: ProtocolBugs{
7632 SendServerHelloVersion: 0x0305,
7633 },
7634 },
7635 shouldFail: true,
7636 expectedError: ":WRONG_VERSION_NUMBER:",
7637 })
7638
7639 testCases = append(testCases, testCase{
7640 name: "HelloRetryRequestCurveMismatch",
7641 config: Config{
7642 MaxVersion: VersionTLS13,
7643 // P-384 requires HelloRetryRequest in BoringSSL.
7644 CurvePreferences: []CurveID{CurveP384},
7645 Bugs: ProtocolBugs{
7646 // Send P-384 (correct) in the HelloRetryRequest.
7647 SendHelloRetryRequestCurve: CurveP384,
7648 // But send P-256 in the ServerHello.
7649 SendCurve: CurveP256,
7650 },
7651 },
7652 shouldFail: true,
7653 expectedError: ":WRONG_CURVE:",
7654 })
7655
7656 // Test the server selecting a curve that requires a HelloRetryRequest
7657 // without sending it.
7658 testCases = append(testCases, testCase{
7659 name: "SkipHelloRetryRequest",
7660 config: Config{
7661 MaxVersion: VersionTLS13,
7662 // P-384 requires HelloRetryRequest in BoringSSL.
7663 CurvePreferences: []CurveID{CurveP384},
7664 Bugs: ProtocolBugs{
7665 SkipHelloRetryRequest: true,
7666 },
7667 },
7668 shouldFail: true,
7669 expectedError: ":WRONG_CURVE:",
7670 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007671}
7672
Adam Langley7c803a62015-06-15 15:35:05 -07007673func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007674 defer wg.Done()
7675
7676 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007677 var err error
7678
7679 if *mallocTest < 0 {
7680 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007681 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007682 } else {
7683 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7684 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007685 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007686 if err != nil {
7687 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7688 }
7689 break
7690 }
7691 }
7692 }
Adam Langley95c29f32014-06-20 12:00:00 -07007693 statusChan <- statusMsg{test: test, err: err}
7694 }
7695}
7696
7697type statusMsg struct {
7698 test *testCase
7699 started bool
7700 err error
7701}
7702
David Benjamin5f237bc2015-02-11 17:14:15 -05007703func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07007704 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007705
David Benjamin5f237bc2015-02-11 17:14:15 -05007706 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007707 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007708 if !*pipe {
7709 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007710 var erase string
7711 for i := 0; i < lineLen; i++ {
7712 erase += "\b \b"
7713 }
7714 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007715 }
7716
Adam Langley95c29f32014-06-20 12:00:00 -07007717 if msg.started {
7718 started++
7719 } else {
7720 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007721
7722 if msg.err != nil {
7723 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7724 failed++
7725 testOutput.addResult(msg.test.name, "FAIL")
7726 } else {
7727 if *pipe {
7728 // Print each test instead of a status line.
7729 fmt.Printf("PASSED (%s)\n", msg.test.name)
7730 }
7731 testOutput.addResult(msg.test.name, "PASS")
7732 }
Adam Langley95c29f32014-06-20 12:00:00 -07007733 }
7734
David Benjamin5f237bc2015-02-11 17:14:15 -05007735 if !*pipe {
7736 // Print a new status line.
7737 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
7738 lineLen = len(line)
7739 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007740 }
Adam Langley95c29f32014-06-20 12:00:00 -07007741 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007742
7743 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007744}
7745
7746func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007747 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007748 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007749 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007750
Adam Langley7c803a62015-06-15 15:35:05 -07007751 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007752 addCipherSuiteTests()
7753 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007754 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007755 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007756 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007757 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007758 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007759 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007760 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007761 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007762 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007763 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007764 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007765 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007766 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007767 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007768 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007769 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007770 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007771 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007772 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007773 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007774 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007775 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007776 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007777 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007778 addTLS13WrongMessageTypeTests()
7779 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007780
7781 var wg sync.WaitGroup
7782
Adam Langley7c803a62015-06-15 15:35:05 -07007783 statusChan := make(chan statusMsg, *numWorkers)
7784 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007785 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007786
David Benjamin025b3d32014-07-01 19:53:04 -04007787 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007788
Adam Langley7c803a62015-06-15 15:35:05 -07007789 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007790 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007791 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007792 }
7793
David Benjamin270f0a72016-03-17 14:41:36 -04007794 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007795 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07007796 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04007797 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007798 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007799 }
7800 }
David Benjamin270f0a72016-03-17 14:41:36 -04007801 if !foundTest {
7802 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
7803 os.Exit(1)
7804 }
Adam Langley95c29f32014-06-20 12:00:00 -07007805
7806 close(testChan)
7807 wg.Wait()
7808 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007809 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007810
7811 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007812
7813 if *jsonOutput != "" {
7814 if err := testOutput.writeTo(*jsonOutput); err != nil {
7815 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7816 }
7817 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007818
7819 if !testOutput.allPassed {
7820 os.Exit(1)
7821 }
Adam Langley95c29f32014-06-20 12:00:00 -07007822}