blob: c587f91b2381227d3034cef250b919e0d700af97 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070024 "flag"
25 "fmt"
26 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070027 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070028 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "net"
30 "os"
31 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040032 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040033 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080034 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070035 "strings"
36 "sync"
37 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050038 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070039)
40
Adam Langley69a01602014-11-17 17:26:55 -080041var (
David Benjamin5f237bc2015-02-11 17:14:15 -050042 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
43 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050044 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050045 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
46 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
47 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
48 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
49 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070050 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
51 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
52 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
53 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050054 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050055 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin01784b42016-06-07 18:00:52 -040056 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
David Benjamin2e045a92016-06-08 13:09:56 -040057 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
Adam Langley69a01602014-11-17 17:26:55 -080058)
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin33863262016-07-08 17:20:12 -070060type testCert int
61
David Benjamin025b3d32014-07-01 19:53:04 -040062const (
David Benjamin33863262016-07-08 17:20:12 -070063 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040064 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070065 testCertECDSAP256
66 testCertECDSAP384
67 testCertECDSAP521
68)
69
70const (
71 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040072 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070073 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
74 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
75 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040076)
77
78const (
David Benjamina08e49d2014-08-24 01:46:07 -040079 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040080 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -070081 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
82 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
83 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040084 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040085)
86
David Benjamin7944a9f2016-07-12 22:27:01 -040087var (
88 rsaCertificate Certificate
89 rsa1024Certificate Certificate
90 ecdsaP256Certificate Certificate
91 ecdsaP384Certificate Certificate
92 ecdsaP521Certificate Certificate
93)
David Benjamin33863262016-07-08 17:20:12 -070094
95var testCerts = []struct {
96 id testCert
97 certFile, keyFile string
98 cert *Certificate
99}{
100 {
101 id: testCertRSA,
102 certFile: rsaCertificateFile,
103 keyFile: rsaKeyFile,
104 cert: &rsaCertificate,
105 },
106 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400107 id: testCertRSA1024,
108 certFile: rsa1024CertificateFile,
109 keyFile: rsa1024KeyFile,
110 cert: &rsa1024Certificate,
111 },
112 {
David Benjamin33863262016-07-08 17:20:12 -0700113 id: testCertECDSAP256,
114 certFile: ecdsaP256CertificateFile,
115 keyFile: ecdsaP256KeyFile,
116 cert: &ecdsaP256Certificate,
117 },
118 {
119 id: testCertECDSAP384,
120 certFile: ecdsaP384CertificateFile,
121 keyFile: ecdsaP384KeyFile,
122 cert: &ecdsaP384Certificate,
123 },
124 {
125 id: testCertECDSAP521,
126 certFile: ecdsaP521CertificateFile,
127 keyFile: ecdsaP521KeyFile,
128 cert: &ecdsaP521Certificate,
129 },
130}
131
David Benjamina08e49d2014-08-24 01:46:07 -0400132var channelIDKey *ecdsa.PrivateKey
133var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700134
David Benjamin61f95272014-11-25 01:55:35 -0500135var testOCSPResponse = []byte{1, 2, 3, 4}
136var testSCTList = []byte{5, 6, 7, 8}
137
Adam Langley95c29f32014-06-20 12:00:00 -0700138func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700139 for i := range testCerts {
140 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
141 if err != nil {
142 panic(err)
143 }
144 cert.OCSPStaple = testOCSPResponse
145 cert.SignedCertificateTimestampList = testSCTList
146 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700147 }
David Benjamina08e49d2014-08-24 01:46:07 -0400148
Adam Langley7c803a62015-06-15 15:35:05 -0700149 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400150 if err != nil {
151 panic(err)
152 }
153 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
154 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
155 panic("bad key type")
156 }
157 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
158 if err != nil {
159 panic(err)
160 }
161 if channelIDKey.Curve != elliptic.P256() {
162 panic("bad curve")
163 }
164
165 channelIDBytes = make([]byte, 64)
166 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
167 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700168}
169
David Benjamin33863262016-07-08 17:20:12 -0700170func getRunnerCertificate(t testCert) Certificate {
171 for _, cert := range testCerts {
172 if cert.id == t {
173 return *cert.cert
174 }
175 }
176 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700177}
178
David Benjamin33863262016-07-08 17:20:12 -0700179func getShimCertificate(t testCert) string {
180 for _, cert := range testCerts {
181 if cert.id == t {
182 return cert.certFile
183 }
184 }
185 panic("Unknown test certificate")
186}
187
188func getShimKey(t testCert) string {
189 for _, cert := range testCerts {
190 if cert.id == t {
191 return cert.keyFile
192 }
193 }
194 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700195}
196
David Benjamin025b3d32014-07-01 19:53:04 -0400197type testType int
198
199const (
200 clientTest testType = iota
201 serverTest
202)
203
David Benjamin6fd297b2014-08-11 18:43:38 -0400204type protocol int
205
206const (
207 tls protocol = iota
208 dtls
209)
210
David Benjaminfc7b0862014-09-06 13:21:53 -0400211const (
212 alpn = 1
213 npn = 2
214)
215
Adam Langley95c29f32014-06-20 12:00:00 -0700216type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400217 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400218 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700219 name string
220 config Config
221 shouldFail bool
222 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700223 // expectedLocalError, if not empty, contains a substring that must be
224 // found in the local error.
225 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400226 // expectedVersion, if non-zero, specifies the TLS version that must be
227 // negotiated.
228 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400229 // expectedResumeVersion, if non-zero, specifies the TLS version that
230 // must be negotiated on resumption. If zero, expectedVersion is used.
231 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400232 // expectedCipher, if non-zero, specifies the TLS cipher suite that
233 // should be negotiated.
234 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400235 // expectChannelID controls whether the connection should have
236 // negotiated a Channel ID with channelIDKey.
237 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400238 // expectedNextProto controls whether the connection should
239 // negotiate a next protocol via NPN or ALPN.
240 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400241 // expectNoNextProto, if true, means that no next protocol should be
242 // negotiated.
243 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400244 // expectedNextProtoType, if non-zero, is the expected next
245 // protocol negotiation mechanism.
246 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500247 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
248 // should be negotiated. If zero, none should be negotiated.
249 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100250 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
251 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100252 // expectedSCTList, if not nil, is the expected SCT list to be received.
253 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700254 // expectedPeerSignatureAlgorithm, if not zero, is the signature
255 // algorithm that the peer should have used in the handshake.
256 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700257 // messageLen is the length, in bytes, of the test message that will be
258 // sent.
259 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400260 // messageCount is the number of test messages that will be sent.
261 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400262 // certFile is the path to the certificate to use for the server.
263 certFile string
264 // keyFile is the path to the private key to use for the server.
265 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400266 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400267 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400268 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700269 // expectResumeRejected, if true, specifies that the attempted
270 // resumption must be rejected by the client. This is only valid for a
271 // serverTest.
272 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400273 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500274 // resumption. Unless newSessionsOnResume is set,
275 // SessionTicketKey, ServerSessionCache, and
276 // ClientSessionCache are copied from the initial connection's
277 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400278 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500279 // newSessionsOnResume, if true, will cause resumeConfig to
280 // use a different session resumption context.
281 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400282 // noSessionCache, if true, will cause the server to run without a
283 // session cache.
284 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400285 // sendPrefix sends a prefix on the socket before actually performing a
286 // handshake.
287 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400288 // shimWritesFirst controls whether the shim sends an initial "hello"
289 // message before doing a roundtrip with the runner.
290 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400291 // shimShutsDown, if true, runs a test where the shim shuts down the
292 // connection immediately after the handshake rather than echoing
293 // messages from the runner.
294 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400295 // renegotiate indicates the number of times the connection should be
296 // renegotiated during the exchange.
297 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700298 // renegotiateCiphers is a list of ciphersuite ids that will be
299 // switched in just before renegotiation.
300 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500301 // replayWrites, if true, configures the underlying transport
302 // to replay every write it makes in DTLS tests.
303 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500304 // damageFirstWrite, if true, configures the underlying transport to
305 // damage the final byte of the first application data write.
306 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400307 // exportKeyingMaterial, if non-zero, configures the test to exchange
308 // keying material and verify they match.
309 exportKeyingMaterial int
310 exportLabel string
311 exportContext string
312 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400313 // flags, if not empty, contains a list of command-line flags that will
314 // be passed to the shim program.
315 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700316 // testTLSUnique, if true, causes the shim to send the tls-unique value
317 // which will be compared against the expected value.
318 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400319 // sendEmptyRecords is the number of consecutive empty records to send
320 // before and after the test message.
321 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400322 // sendWarningAlerts is the number of consecutive warning alerts to send
323 // before and after the test message.
324 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400325 // expectMessageDropped, if true, means the test message is expected to
326 // be dropped by the client rather than echoed back.
327 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700328}
329
Adam Langley7c803a62015-06-15 15:35:05 -0700330var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700331
David Benjamin9867b7d2016-03-01 23:25:48 -0500332func writeTranscript(test *testCase, isResume bool, data []byte) {
333 if len(data) == 0 {
334 return
335 }
336
337 protocol := "tls"
338 if test.protocol == dtls {
339 protocol = "dtls"
340 }
341
342 side := "client"
343 if test.testType == serverTest {
344 side = "server"
345 }
346
347 dir := path.Join(*transcriptDir, protocol, side)
348 if err := os.MkdirAll(dir, 0755); err != nil {
349 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
350 return
351 }
352
353 name := test.name
354 if isResume {
355 name += "-Resume"
356 } else {
357 name += "-Normal"
358 }
359
360 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
361 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
362 }
363}
364
David Benjamin3ed59772016-03-08 12:50:21 -0500365// A timeoutConn implements an idle timeout on each Read and Write operation.
366type timeoutConn struct {
367 net.Conn
368 timeout time.Duration
369}
370
371func (t *timeoutConn) Read(b []byte) (int, error) {
372 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
373 return 0, err
374 }
375 return t.Conn.Read(b)
376}
377
378func (t *timeoutConn) Write(b []byte) (int, error) {
379 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
380 return 0, err
381 }
382 return t.Conn.Write(b)
383}
384
David Benjamin8e6db492015-07-25 18:29:23 -0400385func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400386 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500387
David Benjamin6fd297b2014-08-11 18:43:38 -0400388 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500389 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
390 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500391 }
392
David Benjamin9867b7d2016-03-01 23:25:48 -0500393 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500394 local, peer := "client", "server"
395 if test.testType == clientTest {
396 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500397 }
David Benjaminebda9b32015-11-02 15:33:18 -0500398 connDebug := &recordingConn{
399 Conn: conn,
400 isDatagram: test.protocol == dtls,
401 local: local,
402 peer: peer,
403 }
404 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500405 if *flagDebug {
406 defer connDebug.WriteTo(os.Stdout)
407 }
408 if len(*transcriptDir) != 0 {
409 defer func() {
410 writeTranscript(test, isResume, connDebug.Transcript())
411 }()
412 }
David Benjaminebda9b32015-11-02 15:33:18 -0500413
414 if config.Bugs.PacketAdaptor != nil {
415 config.Bugs.PacketAdaptor.debug = connDebug
416 }
417 }
418
419 if test.replayWrites {
420 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400421 }
422
David Benjamin3ed59772016-03-08 12:50:21 -0500423 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 if test.damageFirstWrite {
425 connDamage = newDamageAdaptor(conn)
426 conn = connDamage
427 }
428
David Benjamin6fd297b2014-08-11 18:43:38 -0400429 if test.sendPrefix != "" {
430 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
431 return err
432 }
David Benjamin98e882e2014-08-08 13:24:34 -0400433 }
434
David Benjamin1d5c83e2014-07-22 19:20:02 -0400435 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400436 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400437 if test.protocol == dtls {
438 tlsConn = DTLSServer(conn, config)
439 } else {
440 tlsConn = Server(conn, config)
441 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400442 } else {
443 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400444 if test.protocol == dtls {
445 tlsConn = DTLSClient(conn, config)
446 } else {
447 tlsConn = Client(conn, config)
448 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400449 }
David Benjamin30789da2015-08-29 22:56:45 -0400450 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400451
Adam Langley95c29f32014-06-20 12:00:00 -0700452 if err := tlsConn.Handshake(); err != nil {
453 return err
454 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700455
David Benjamin01fe8202014-09-24 15:21:44 -0400456 // TODO(davidben): move all per-connection expectations into a dedicated
457 // expectations struct that can be specified separately for the two
458 // legs.
459 expectedVersion := test.expectedVersion
460 if isResume && test.expectedResumeVersion != 0 {
461 expectedVersion = test.expectedResumeVersion
462 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700463 connState := tlsConn.ConnectionState()
464 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400465 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400466 }
467
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700468 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400469 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
470 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700471 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
472 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
473 }
David Benjamin90da8c82015-04-20 14:57:57 -0400474
David Benjamina08e49d2014-08-24 01:46:07 -0400475 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700476 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400477 if channelID == nil {
478 return fmt.Errorf("no channel ID negotiated")
479 }
480 if channelID.Curve != channelIDKey.Curve ||
481 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
482 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
483 return fmt.Errorf("incorrect channel ID")
484 }
485 }
486
David Benjaminae2888f2014-09-06 12:58:58 -0400487 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700488 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400489 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
490 }
491 }
492
David Benjaminc7ce9772015-10-09 19:32:41 -0400493 if test.expectNoNextProto {
494 if actual := connState.NegotiatedProtocol; actual != "" {
495 return fmt.Errorf("got unexpected next proto %s", actual)
496 }
497 }
498
David Benjaminfc7b0862014-09-06 13:21:53 -0400499 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700500 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400501 return fmt.Errorf("next proto type mismatch")
502 }
503 }
504
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700505 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500506 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
507 }
508
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100509 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300510 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100511 }
512
Paul Lietar4fac72e2015-09-09 13:44:55 +0100513 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
514 return fmt.Errorf("SCT list mismatch")
515 }
516
Nick Harper60edffd2016-06-21 15:19:24 -0700517 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
518 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400519 }
520
David Benjaminc565ebb2015-04-03 04:06:36 -0400521 if test.exportKeyingMaterial > 0 {
522 actual := make([]byte, test.exportKeyingMaterial)
523 if _, err := io.ReadFull(tlsConn, actual); err != nil {
524 return err
525 }
526 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
527 if err != nil {
528 return err
529 }
530 if !bytes.Equal(actual, expected) {
531 return fmt.Errorf("keying material mismatch")
532 }
533 }
534
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700535 if test.testTLSUnique {
536 var peersValue [12]byte
537 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
538 return err
539 }
540 expected := tlsConn.ConnectionState().TLSUnique
541 if !bytes.Equal(peersValue[:], expected) {
542 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
543 }
544 }
545
David Benjamine58c4f52014-08-24 03:47:07 -0400546 if test.shimWritesFirst {
547 var buf [5]byte
548 _, err := io.ReadFull(tlsConn, buf[:])
549 if err != nil {
550 return err
551 }
552 if string(buf[:]) != "hello" {
553 return fmt.Errorf("bad initial message")
554 }
555 }
556
David Benjamina8ebe222015-06-06 03:04:39 -0400557 for i := 0; i < test.sendEmptyRecords; i++ {
558 tlsConn.Write(nil)
559 }
560
David Benjamin24f346d2015-06-06 03:28:08 -0400561 for i := 0; i < test.sendWarningAlerts; i++ {
562 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
563 }
564
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400565 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700566 if test.renegotiateCiphers != nil {
567 config.CipherSuites = test.renegotiateCiphers
568 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400569 for i := 0; i < test.renegotiate; i++ {
570 if err := tlsConn.Renegotiate(); err != nil {
571 return err
572 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700573 }
574 } else if test.renegotiateCiphers != nil {
575 panic("renegotiateCiphers without renegotiate")
576 }
577
David Benjamin5fa3eba2015-01-22 16:35:40 -0500578 if test.damageFirstWrite {
579 connDamage.setDamage(true)
580 tlsConn.Write([]byte("DAMAGED WRITE"))
581 connDamage.setDamage(false)
582 }
583
David Benjamin8e6db492015-07-25 18:29:23 -0400584 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700585 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400586 if test.protocol == dtls {
587 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
588 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700589 // Read until EOF.
590 _, err := io.Copy(ioutil.Discard, tlsConn)
591 return err
592 }
David Benjamin4417d052015-04-05 04:17:25 -0400593 if messageLen == 0 {
594 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700595 }
Adam Langley95c29f32014-06-20 12:00:00 -0700596
David Benjamin8e6db492015-07-25 18:29:23 -0400597 messageCount := test.messageCount
598 if messageCount == 0 {
599 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400600 }
601
David Benjamin8e6db492015-07-25 18:29:23 -0400602 for j := 0; j < messageCount; j++ {
603 testMessage := make([]byte, messageLen)
604 for i := range testMessage {
605 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400606 }
David Benjamin8e6db492015-07-25 18:29:23 -0400607 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700608
David Benjamin8e6db492015-07-25 18:29:23 -0400609 for i := 0; i < test.sendEmptyRecords; i++ {
610 tlsConn.Write(nil)
611 }
612
613 for i := 0; i < test.sendWarningAlerts; i++ {
614 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
615 }
616
David Benjamin4f75aaf2015-09-01 16:53:10 -0400617 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400618 // The shim will not respond.
619 continue
620 }
621
David Benjamin8e6db492015-07-25 18:29:23 -0400622 buf := make([]byte, len(testMessage))
623 if test.protocol == dtls {
624 bufTmp := make([]byte, len(buf)+1)
625 n, err := tlsConn.Read(bufTmp)
626 if err != nil {
627 return err
628 }
629 if n != len(buf) {
630 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
631 }
632 copy(buf, bufTmp)
633 } else {
634 _, err := io.ReadFull(tlsConn, buf)
635 if err != nil {
636 return err
637 }
638 }
639
640 for i, v := range buf {
641 if v != testMessage[i]^0xff {
642 return fmt.Errorf("bad reply contents at byte %d", i)
643 }
Adam Langley95c29f32014-06-20 12:00:00 -0700644 }
645 }
646
647 return nil
648}
649
David Benjamin325b5c32014-07-01 19:40:31 -0400650func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
651 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700652 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400653 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700654 }
David Benjamin325b5c32014-07-01 19:40:31 -0400655 valgrindArgs = append(valgrindArgs, path)
656 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700657
David Benjamin325b5c32014-07-01 19:40:31 -0400658 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700659}
660
David Benjamin325b5c32014-07-01 19:40:31 -0400661func gdbOf(path string, args ...string) *exec.Cmd {
662 xtermArgs := []string{"-e", "gdb", "--args"}
663 xtermArgs = append(xtermArgs, path)
664 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700665
David Benjamin325b5c32014-07-01 19:40:31 -0400666 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700667}
668
David Benjamind16bf342015-12-18 00:53:12 -0500669func lldbOf(path string, args ...string) *exec.Cmd {
670 xtermArgs := []string{"-e", "lldb", "--"}
671 xtermArgs = append(xtermArgs, path)
672 xtermArgs = append(xtermArgs, args...)
673
674 return exec.Command("xterm", xtermArgs...)
675}
676
Adam Langley69a01602014-11-17 17:26:55 -0800677type moreMallocsError struct{}
678
679func (moreMallocsError) Error() string {
680 return "child process did not exhaust all allocation calls"
681}
682
683var errMoreMallocs = moreMallocsError{}
684
David Benjamin87c8a642015-02-21 01:54:29 -0500685// accept accepts a connection from listener, unless waitChan signals a process
686// exit first.
687func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
688 type connOrError struct {
689 conn net.Conn
690 err error
691 }
692 connChan := make(chan connOrError, 1)
693 go func() {
694 conn, err := listener.Accept()
695 connChan <- connOrError{conn, err}
696 close(connChan)
697 }()
698 select {
699 case result := <-connChan:
700 return result.conn, result.err
701 case childErr := <-waitChan:
702 waitChan <- childErr
703 return nil, fmt.Errorf("child exited early: %s", childErr)
704 }
705}
706
Adam Langley7c803a62015-06-15 15:35:05 -0700707func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700708 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
709 panic("Error expected without shouldFail in " + test.name)
710 }
711
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700712 if test.expectResumeRejected && !test.resumeSession {
713 panic("expectResumeRejected without resumeSession in " + test.name)
714 }
715
David Benjamin87c8a642015-02-21 01:54:29 -0500716 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
717 if err != nil {
718 panic(err)
719 }
720 defer func() {
721 if listener != nil {
722 listener.Close()
723 }
724 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700725
David Benjamin87c8a642015-02-21 01:54:29 -0500726 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400727 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400728 flags = append(flags, "-server")
729
David Benjamin025b3d32014-07-01 19:53:04 -0400730 flags = append(flags, "-key-file")
731 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700732 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400733 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700734 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400735 }
736
737 flags = append(flags, "-cert-file")
738 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700739 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400740 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700741 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400742 }
743 }
David Benjamin5a593af2014-08-11 19:51:50 -0400744
David Benjamin6fd297b2014-08-11 18:43:38 -0400745 if test.protocol == dtls {
746 flags = append(flags, "-dtls")
747 }
748
David Benjamin5a593af2014-08-11 19:51:50 -0400749 if test.resumeSession {
750 flags = append(flags, "-resume")
751 }
752
David Benjamine58c4f52014-08-24 03:47:07 -0400753 if test.shimWritesFirst {
754 flags = append(flags, "-shim-writes-first")
755 }
756
David Benjamin30789da2015-08-29 22:56:45 -0400757 if test.shimShutsDown {
758 flags = append(flags, "-shim-shuts-down")
759 }
760
David Benjaminc565ebb2015-04-03 04:06:36 -0400761 if test.exportKeyingMaterial > 0 {
762 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
763 flags = append(flags, "-export-label", test.exportLabel)
764 flags = append(flags, "-export-context", test.exportContext)
765 if test.useExportContext {
766 flags = append(flags, "-use-export-context")
767 }
768 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700769 if test.expectResumeRejected {
770 flags = append(flags, "-expect-session-miss")
771 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400772
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700773 if test.testTLSUnique {
774 flags = append(flags, "-tls-unique")
775 }
776
David Benjamin025b3d32014-07-01 19:53:04 -0400777 flags = append(flags, test.flags...)
778
779 var shim *exec.Cmd
780 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700781 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700782 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700783 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500784 } else if *useLLDB {
785 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400786 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700787 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400788 }
David Benjamin025b3d32014-07-01 19:53:04 -0400789 shim.Stdin = os.Stdin
790 var stdoutBuf, stderrBuf bytes.Buffer
791 shim.Stdout = &stdoutBuf
792 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800793 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500794 shim.Env = os.Environ()
795 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800796 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400797 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800798 }
799 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
800 }
David Benjamin025b3d32014-07-01 19:53:04 -0400801
802 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700803 panic(err)
804 }
David Benjamin87c8a642015-02-21 01:54:29 -0500805 waitChan := make(chan error, 1)
806 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700807
808 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400809 if !test.noSessionCache {
810 config.ClientSessionCache = NewLRUClientSessionCache(1)
811 config.ServerSessionCache = NewLRUServerSessionCache(1)
812 }
David Benjamin025b3d32014-07-01 19:53:04 -0400813 if test.testType == clientTest {
814 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700815 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400816 }
David Benjamin87c8a642015-02-21 01:54:29 -0500817 } else {
818 // Supply a ServerName to ensure a constant session cache key,
819 // rather than falling back to net.Conn.RemoteAddr.
820 if len(config.ServerName) == 0 {
821 config.ServerName = "test"
822 }
David Benjamin025b3d32014-07-01 19:53:04 -0400823 }
David Benjaminf2b83632016-03-01 22:57:46 -0500824 if *fuzzer {
825 config.Bugs.NullAllCiphers = true
826 }
David Benjamin2e045a92016-06-08 13:09:56 -0400827 if *deterministic {
828 config.Rand = &deterministicRand{}
829 }
Adam Langley95c29f32014-06-20 12:00:00 -0700830
David Benjamin87c8a642015-02-21 01:54:29 -0500831 conn, err := acceptOrWait(listener, waitChan)
832 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400833 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500834 conn.Close()
835 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500836
David Benjamin1d5c83e2014-07-22 19:20:02 -0400837 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400838 var resumeConfig Config
839 if test.resumeConfig != nil {
840 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500841 if len(resumeConfig.ServerName) == 0 {
842 resumeConfig.ServerName = config.ServerName
843 }
David Benjamin01fe8202014-09-24 15:21:44 -0400844 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700845 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400846 }
David Benjaminba4594a2015-06-18 18:36:15 -0400847 if test.newSessionsOnResume {
848 if !test.noSessionCache {
849 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
850 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
851 }
852 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500853 resumeConfig.SessionTicketKey = config.SessionTicketKey
854 resumeConfig.ClientSessionCache = config.ClientSessionCache
855 resumeConfig.ServerSessionCache = config.ServerSessionCache
856 }
David Benjaminf2b83632016-03-01 22:57:46 -0500857 if *fuzzer {
858 resumeConfig.Bugs.NullAllCiphers = true
859 }
David Benjamin2e045a92016-06-08 13:09:56 -0400860 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400861 } else {
862 resumeConfig = config
863 }
David Benjamin87c8a642015-02-21 01:54:29 -0500864 var connResume net.Conn
865 connResume, err = acceptOrWait(listener, waitChan)
866 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400867 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500868 connResume.Close()
869 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400870 }
871
David Benjamin87c8a642015-02-21 01:54:29 -0500872 // Close the listener now. This is to avoid hangs should the shim try to
873 // open more connections than expected.
874 listener.Close()
875 listener = nil
876
877 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800878 if exitError, ok := childErr.(*exec.ExitError); ok {
879 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
880 return errMoreMallocs
881 }
882 }
Adam Langley95c29f32014-06-20 12:00:00 -0700883
David Benjamin9bea3492016-03-02 10:59:16 -0500884 // Account for Windows line endings.
885 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
886 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500887
888 // Separate the errors from the shim and those from tools like
889 // AddressSanitizer.
890 var extraStderr string
891 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
892 stderr = stderrParts[0]
893 extraStderr = stderrParts[1]
894 }
895
Adam Langley95c29f32014-06-20 12:00:00 -0700896 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400897 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700898 localError := "none"
899 if err != nil {
900 localError = err.Error()
901 }
902 if len(test.expectedLocalError) != 0 {
903 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
904 }
Adam Langley95c29f32014-06-20 12:00:00 -0700905
906 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700907 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700908 if childErr != nil {
909 childError = childErr.Error()
910 }
911
912 var msg string
913 switch {
914 case failed && !test.shouldFail:
915 msg = "unexpected failure"
916 case !failed && test.shouldFail:
917 msg = "unexpected success"
918 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700919 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700920 default:
921 panic("internal error")
922 }
923
David Benjaminc565ebb2015-04-03 04:06:36 -0400924 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700925 }
926
David Benjaminff3a1492016-03-02 10:12:06 -0500927 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
928 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700929 }
930
931 return nil
932}
933
934var tlsVersions = []struct {
935 name string
936 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400937 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500938 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700939}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500940 {"SSL3", VersionSSL30, "-no-ssl3", false},
941 {"TLS1", VersionTLS10, "-no-tls1", true},
942 {"TLS11", VersionTLS11, "-no-tls11", false},
943 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400944 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700945}
946
947var testCipherSuites = []struct {
948 name string
949 id uint16
950}{
951 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400952 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700953 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400954 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400955 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700956 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400957 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400958 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
959 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400960 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400961 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
962 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400963 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700964 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
965 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400966 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
967 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700968 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400969 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500970 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500971 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700973 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700974 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400975 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400976 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700977 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400978 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500979 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500980 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700982 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
983 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
984 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
985 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400986 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
987 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700988 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
989 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500990 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400991 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
992 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400993 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700994 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400995 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700996 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700997}
998
David Benjamin8b8c0062014-11-23 02:47:52 -0500999func hasComponent(suiteName, component string) bool {
1000 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1001}
1002
David Benjaminf7768e42014-08-31 02:06:47 -04001003func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001004 return hasComponent(suiteName, "GCM") ||
1005 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001006 hasComponent(suiteName, "SHA384") ||
1007 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001008}
1009
Nick Harper1fd39d82016-06-14 18:14:35 -07001010func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001011 // Only AEADs.
1012 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1013 return false
1014 }
1015 // No old CHACHA20_POLY1305.
1016 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1017 return false
1018 }
1019 // Must have ECDHE.
1020 // TODO(davidben,svaldez): Add pure PSK support.
1021 if !hasComponent(suiteName, "ECDHE") {
1022 return false
1023 }
1024 // TODO(davidben,svaldez): Add PSK support.
1025 if hasComponent(suiteName, "PSK") {
1026 return false
1027 }
1028 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001029}
1030
David Benjamin8b8c0062014-11-23 02:47:52 -05001031func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001032 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001033}
1034
Adam Langleya7997f12015-05-14 17:38:50 -07001035func bigFromHex(hex string) *big.Int {
1036 ret, ok := new(big.Int).SetString(hex, 16)
1037 if !ok {
1038 panic("failed to parse hex number 0x" + hex)
1039 }
1040 return ret
1041}
1042
Adam Langley7c803a62015-06-15 15:35:05 -07001043func addBasicTests() {
1044 basicTests := []testCase{
1045 {
Adam Langley7c803a62015-06-15 15:35:05 -07001046 name: "NoFallbackSCSV",
1047 config: Config{
1048 Bugs: ProtocolBugs{
1049 FailIfNotFallbackSCSV: true,
1050 },
1051 },
1052 shouldFail: true,
1053 expectedLocalError: "no fallback SCSV found",
1054 },
1055 {
1056 name: "SendFallbackSCSV",
1057 config: Config{
1058 Bugs: ProtocolBugs{
1059 FailIfNotFallbackSCSV: true,
1060 },
1061 },
1062 flags: []string{"-fallback-scsv"},
1063 },
1064 {
1065 name: "ClientCertificateTypes",
1066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001067 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001068 ClientAuth: RequestClientCert,
1069 ClientCertificateTypes: []byte{
1070 CertTypeDSSSign,
1071 CertTypeRSASign,
1072 CertTypeECDSASign,
1073 },
1074 },
1075 flags: []string{
1076 "-expect-certificate-types",
1077 base64.StdEncoding.EncodeToString([]byte{
1078 CertTypeDSSSign,
1079 CertTypeRSASign,
1080 CertTypeECDSASign,
1081 }),
1082 },
1083 },
1084 {
Adam Langley7c803a62015-06-15 15:35:05 -07001085 name: "UnauthenticatedECDH",
1086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001087 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001088 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1089 Bugs: ProtocolBugs{
1090 UnauthenticatedECDH: true,
1091 },
1092 },
1093 shouldFail: true,
1094 expectedError: ":UNEXPECTED_MESSAGE:",
1095 },
1096 {
1097 name: "SkipCertificateStatus",
1098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001099 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1101 Bugs: ProtocolBugs{
1102 SkipCertificateStatus: true,
1103 },
1104 },
1105 flags: []string{
1106 "-enable-ocsp-stapling",
1107 },
1108 },
1109 {
1110 name: "SkipServerKeyExchange",
1111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001112 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001113 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1114 Bugs: ProtocolBugs{
1115 SkipServerKeyExchange: true,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedError: ":UNEXPECTED_MESSAGE:",
1120 },
1121 {
Adam Langley7c803a62015-06-15 15:35:05 -07001122 testType: serverTest,
1123 name: "Alert",
1124 config: Config{
1125 Bugs: ProtocolBugs{
1126 SendSpuriousAlert: alertRecordOverflow,
1127 },
1128 },
1129 shouldFail: true,
1130 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1131 },
1132 {
1133 protocol: dtls,
1134 testType: serverTest,
1135 name: "Alert-DTLS",
1136 config: Config{
1137 Bugs: ProtocolBugs{
1138 SendSpuriousAlert: alertRecordOverflow,
1139 },
1140 },
1141 shouldFail: true,
1142 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1143 },
1144 {
1145 testType: serverTest,
1146 name: "FragmentAlert",
1147 config: Config{
1148 Bugs: ProtocolBugs{
1149 FragmentAlert: true,
1150 SendSpuriousAlert: alertRecordOverflow,
1151 },
1152 },
1153 shouldFail: true,
1154 expectedError: ":BAD_ALERT:",
1155 },
1156 {
1157 protocol: dtls,
1158 testType: serverTest,
1159 name: "FragmentAlert-DTLS",
1160 config: Config{
1161 Bugs: ProtocolBugs{
1162 FragmentAlert: true,
1163 SendSpuriousAlert: alertRecordOverflow,
1164 },
1165 },
1166 shouldFail: true,
1167 expectedError: ":BAD_ALERT:",
1168 },
1169 {
1170 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001171 name: "DoubleAlert",
1172 config: Config{
1173 Bugs: ProtocolBugs{
1174 DoubleAlert: true,
1175 SendSpuriousAlert: alertRecordOverflow,
1176 },
1177 },
1178 shouldFail: true,
1179 expectedError: ":BAD_ALERT:",
1180 },
1181 {
1182 protocol: dtls,
1183 testType: serverTest,
1184 name: "DoubleAlert-DTLS",
1185 config: Config{
1186 Bugs: ProtocolBugs{
1187 DoubleAlert: true,
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":BAD_ALERT:",
1193 },
1194 {
Adam Langley7c803a62015-06-15 15:35:05 -07001195 name: "SkipNewSessionTicket",
1196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001197 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001198 Bugs: ProtocolBugs{
1199 SkipNewSessionTicket: true,
1200 },
1201 },
1202 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001203 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001204 },
1205 {
1206 testType: serverTest,
1207 name: "FallbackSCSV",
1208 config: Config{
1209 MaxVersion: VersionTLS11,
1210 Bugs: ProtocolBugs{
1211 SendFallbackSCSV: true,
1212 },
1213 },
1214 shouldFail: true,
1215 expectedError: ":INAPPROPRIATE_FALLBACK:",
1216 },
1217 {
1218 testType: serverTest,
1219 name: "FallbackSCSV-VersionMatch",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 SendFallbackSCSV: true,
1223 },
1224 },
1225 },
1226 {
1227 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001228 name: "FallbackSCSV-VersionMatch-TLS12",
1229 config: Config{
1230 MaxVersion: VersionTLS12,
1231 Bugs: ProtocolBugs{
1232 SendFallbackSCSV: true,
1233 },
1234 },
1235 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1236 },
1237 {
1238 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001239 name: "FragmentedClientVersion",
1240 config: Config{
1241 Bugs: ProtocolBugs{
1242 MaxHandshakeRecordLength: 1,
1243 FragmentClientVersion: true,
1244 },
1245 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001246 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001247 },
1248 {
Adam Langley7c803a62015-06-15 15:35:05 -07001249 testType: serverTest,
1250 name: "HttpGET",
1251 sendPrefix: "GET / HTTP/1.0\n",
1252 shouldFail: true,
1253 expectedError: ":HTTP_REQUEST:",
1254 },
1255 {
1256 testType: serverTest,
1257 name: "HttpPOST",
1258 sendPrefix: "POST / HTTP/1.0\n",
1259 shouldFail: true,
1260 expectedError: ":HTTP_REQUEST:",
1261 },
1262 {
1263 testType: serverTest,
1264 name: "HttpHEAD",
1265 sendPrefix: "HEAD / HTTP/1.0\n",
1266 shouldFail: true,
1267 expectedError: ":HTTP_REQUEST:",
1268 },
1269 {
1270 testType: serverTest,
1271 name: "HttpPUT",
1272 sendPrefix: "PUT / HTTP/1.0\n",
1273 shouldFail: true,
1274 expectedError: ":HTTP_REQUEST:",
1275 },
1276 {
1277 testType: serverTest,
1278 name: "HttpCONNECT",
1279 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1280 shouldFail: true,
1281 expectedError: ":HTTPS_PROXY_REQUEST:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "Garbage",
1286 sendPrefix: "blah",
1287 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001288 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001289 },
1290 {
Adam Langley7c803a62015-06-15 15:35:05 -07001291 name: "RSAEphemeralKey",
1292 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001293 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001294 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1295 Bugs: ProtocolBugs{
1296 RSAEphemeralKey: true,
1297 },
1298 },
1299 shouldFail: true,
1300 expectedError: ":UNEXPECTED_MESSAGE:",
1301 },
1302 {
1303 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001304 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001305 shouldFail: true,
1306 expectedError: ":WRONG_SSL_VERSION:",
1307 },
1308 {
1309 protocol: dtls,
1310 name: "DisableEverything-DTLS",
1311 flags: []string{"-no-tls12", "-no-tls1"},
1312 shouldFail: true,
1313 expectedError: ":WRONG_SSL_VERSION:",
1314 },
1315 {
Adam Langley7c803a62015-06-15 15:35:05 -07001316 protocol: dtls,
1317 testType: serverTest,
1318 name: "MTU",
1319 config: Config{
1320 Bugs: ProtocolBugs{
1321 MaxPacketLength: 256,
1322 },
1323 },
1324 flags: []string{"-mtu", "256"},
1325 },
1326 {
1327 protocol: dtls,
1328 testType: serverTest,
1329 name: "MTUExceeded",
1330 config: Config{
1331 Bugs: ProtocolBugs{
1332 MaxPacketLength: 255,
1333 },
1334 },
1335 flags: []string{"-mtu", "256"},
1336 shouldFail: true,
1337 expectedLocalError: "dtls: exceeded maximum packet length",
1338 },
1339 {
1340 name: "CertMismatchRSA",
1341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001342 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001343 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001344 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001345 Bugs: ProtocolBugs{
1346 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1347 },
1348 },
1349 shouldFail: true,
1350 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1351 },
1352 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001353 name: "CertMismatchRSA-TLS13",
1354 config: Config{
1355 MaxVersion: VersionTLS13,
1356 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1357 Certificates: []Certificate{ecdsaP256Certificate},
1358 Bugs: ProtocolBugs{
1359 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1360 },
1361 },
1362 shouldFail: true,
1363 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1364 },
1365 {
Adam Langley7c803a62015-06-15 15:35:05 -07001366 name: "CertMismatchECDSA",
1367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001368 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001369 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001370 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001371 Bugs: ProtocolBugs{
1372 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1373 },
1374 },
1375 shouldFail: true,
1376 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1377 },
1378 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001379 name: "CertMismatchECDSA-TLS13",
1380 config: Config{
1381 MaxVersion: VersionTLS13,
1382 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1383 Certificates: []Certificate{rsaCertificate},
1384 Bugs: ProtocolBugs{
1385 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1386 },
1387 },
1388 shouldFail: true,
1389 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1390 },
1391 {
Adam Langley7c803a62015-06-15 15:35:05 -07001392 name: "EmptyCertificateList",
1393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001394 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001395 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1396 Bugs: ProtocolBugs{
1397 EmptyCertificateList: true,
1398 },
1399 },
1400 shouldFail: true,
1401 expectedError: ":DECODE_ERROR:",
1402 },
1403 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001404 name: "EmptyCertificateList-TLS13",
1405 config: Config{
1406 MaxVersion: VersionTLS13,
1407 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1408 Bugs: ProtocolBugs{
1409 EmptyCertificateList: true,
1410 },
1411 },
1412 shouldFail: true,
1413 expectedError: ":DECODE_ERROR:",
1414 },
1415 {
Adam Langley7c803a62015-06-15 15:35:05 -07001416 name: "TLSFatalBadPackets",
1417 damageFirstWrite: true,
1418 shouldFail: true,
1419 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1420 },
1421 {
1422 protocol: dtls,
1423 name: "DTLSIgnoreBadPackets",
1424 damageFirstWrite: true,
1425 },
1426 {
1427 protocol: dtls,
1428 name: "DTLSIgnoreBadPackets-Async",
1429 damageFirstWrite: true,
1430 flags: []string{"-async"},
1431 },
1432 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001433 name: "AppDataBeforeHandshake",
1434 config: Config{
1435 Bugs: ProtocolBugs{
1436 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1437 },
1438 },
1439 shouldFail: true,
1440 expectedError: ":UNEXPECTED_RECORD:",
1441 },
1442 {
1443 name: "AppDataBeforeHandshake-Empty",
1444 config: Config{
1445 Bugs: ProtocolBugs{
1446 AppDataBeforeHandshake: []byte{},
1447 },
1448 },
1449 shouldFail: true,
1450 expectedError: ":UNEXPECTED_RECORD:",
1451 },
1452 {
1453 protocol: dtls,
1454 name: "AppDataBeforeHandshake-DTLS",
1455 config: Config{
1456 Bugs: ProtocolBugs{
1457 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1458 },
1459 },
1460 shouldFail: true,
1461 expectedError: ":UNEXPECTED_RECORD:",
1462 },
1463 {
1464 protocol: dtls,
1465 name: "AppDataBeforeHandshake-DTLS-Empty",
1466 config: Config{
1467 Bugs: ProtocolBugs{
1468 AppDataBeforeHandshake: []byte{},
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":UNEXPECTED_RECORD:",
1473 },
1474 {
Adam Langley7c803a62015-06-15 15:35:05 -07001475 name: "AppDataAfterChangeCipherSpec",
1476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001477 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001478 Bugs: ProtocolBugs{
1479 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1480 },
1481 },
1482 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001483 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001484 },
1485 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001486 name: "AppDataAfterChangeCipherSpec-Empty",
1487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001488 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001489 Bugs: ProtocolBugs{
1490 AppDataAfterChangeCipherSpec: []byte{},
1491 },
1492 },
1493 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001494 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001495 },
1496 {
Adam Langley7c803a62015-06-15 15:35:05 -07001497 protocol: dtls,
1498 name: "AppDataAfterChangeCipherSpec-DTLS",
1499 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001500 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001501 Bugs: ProtocolBugs{
1502 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1503 },
1504 },
1505 // BoringSSL's DTLS implementation will drop the out-of-order
1506 // application data.
1507 },
1508 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001509 protocol: dtls,
1510 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1511 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001512 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001513 Bugs: ProtocolBugs{
1514 AppDataAfterChangeCipherSpec: []byte{},
1515 },
1516 },
1517 // BoringSSL's DTLS implementation will drop the out-of-order
1518 // application data.
1519 },
1520 {
Adam Langley7c803a62015-06-15 15:35:05 -07001521 name: "AlertAfterChangeCipherSpec",
1522 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001523 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001524 Bugs: ProtocolBugs{
1525 AlertAfterChangeCipherSpec: alertRecordOverflow,
1526 },
1527 },
1528 shouldFail: true,
1529 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1530 },
1531 {
1532 protocol: dtls,
1533 name: "AlertAfterChangeCipherSpec-DTLS",
1534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001535 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001536 Bugs: ProtocolBugs{
1537 AlertAfterChangeCipherSpec: alertRecordOverflow,
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1542 },
1543 {
1544 protocol: dtls,
1545 name: "ReorderHandshakeFragments-Small-DTLS",
1546 config: Config{
1547 Bugs: ProtocolBugs{
1548 ReorderHandshakeFragments: true,
1549 // Small enough that every handshake message is
1550 // fragmented.
1551 MaxHandshakeRecordLength: 2,
1552 },
1553 },
1554 },
1555 {
1556 protocol: dtls,
1557 name: "ReorderHandshakeFragments-Large-DTLS",
1558 config: Config{
1559 Bugs: ProtocolBugs{
1560 ReorderHandshakeFragments: true,
1561 // Large enough that no handshake message is
1562 // fragmented.
1563 MaxHandshakeRecordLength: 2048,
1564 },
1565 },
1566 },
1567 {
1568 protocol: dtls,
1569 name: "MixCompleteMessageWithFragments-DTLS",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 ReorderHandshakeFragments: true,
1573 MixCompleteMessageWithFragments: true,
1574 MaxHandshakeRecordLength: 2,
1575 },
1576 },
1577 },
1578 {
1579 name: "SendInvalidRecordType",
1580 config: Config{
1581 Bugs: ProtocolBugs{
1582 SendInvalidRecordType: true,
1583 },
1584 },
1585 shouldFail: true,
1586 expectedError: ":UNEXPECTED_RECORD:",
1587 },
1588 {
1589 protocol: dtls,
1590 name: "SendInvalidRecordType-DTLS",
1591 config: Config{
1592 Bugs: ProtocolBugs{
1593 SendInvalidRecordType: true,
1594 },
1595 },
1596 shouldFail: true,
1597 expectedError: ":UNEXPECTED_RECORD:",
1598 },
1599 {
1600 name: "FalseStart-SkipServerSecondLeg",
1601 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001602 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001603 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1604 NextProtos: []string{"foo"},
1605 Bugs: ProtocolBugs{
1606 SkipNewSessionTicket: true,
1607 SkipChangeCipherSpec: true,
1608 SkipFinished: true,
1609 ExpectFalseStart: true,
1610 },
1611 },
1612 flags: []string{
1613 "-false-start",
1614 "-handshake-never-done",
1615 "-advertise-alpn", "\x03foo",
1616 },
1617 shimWritesFirst: true,
1618 shouldFail: true,
1619 expectedError: ":UNEXPECTED_RECORD:",
1620 },
1621 {
1622 name: "FalseStart-SkipServerSecondLeg-Implicit",
1623 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001624 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1626 NextProtos: []string{"foo"},
1627 Bugs: ProtocolBugs{
1628 SkipNewSessionTicket: true,
1629 SkipChangeCipherSpec: true,
1630 SkipFinished: true,
1631 },
1632 },
1633 flags: []string{
1634 "-implicit-handshake",
1635 "-false-start",
1636 "-handshake-never-done",
1637 "-advertise-alpn", "\x03foo",
1638 },
1639 shouldFail: true,
1640 expectedError: ":UNEXPECTED_RECORD:",
1641 },
1642 {
1643 testType: serverTest,
1644 name: "FailEarlyCallback",
1645 flags: []string{"-fail-early-callback"},
1646 shouldFail: true,
1647 expectedError: ":CONNECTION_REJECTED:",
1648 expectedLocalError: "remote error: access denied",
1649 },
1650 {
Adam Langley7c803a62015-06-15 15:35:05 -07001651 protocol: dtls,
1652 name: "FragmentMessageTypeMismatch-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 MaxHandshakeRecordLength: 2,
1656 FragmentMessageTypeMismatch: true,
1657 },
1658 },
1659 shouldFail: true,
1660 expectedError: ":FRAGMENT_MISMATCH:",
1661 },
1662 {
1663 protocol: dtls,
1664 name: "FragmentMessageLengthMismatch-DTLS",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 MaxHandshakeRecordLength: 2,
1668 FragmentMessageLengthMismatch: true,
1669 },
1670 },
1671 shouldFail: true,
1672 expectedError: ":FRAGMENT_MISMATCH:",
1673 },
1674 {
1675 protocol: dtls,
1676 name: "SplitFragments-Header-DTLS",
1677 config: Config{
1678 Bugs: ProtocolBugs{
1679 SplitFragments: 2,
1680 },
1681 },
1682 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001683 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001684 },
1685 {
1686 protocol: dtls,
1687 name: "SplitFragments-Boundary-DTLS",
1688 config: Config{
1689 Bugs: ProtocolBugs{
1690 SplitFragments: dtlsRecordHeaderLen,
1691 },
1692 },
1693 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001694 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001695 },
1696 {
1697 protocol: dtls,
1698 name: "SplitFragments-Body-DTLS",
1699 config: Config{
1700 Bugs: ProtocolBugs{
1701 SplitFragments: dtlsRecordHeaderLen + 1,
1702 },
1703 },
1704 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001705 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001706 },
1707 {
1708 protocol: dtls,
1709 name: "SendEmptyFragments-DTLS",
1710 config: Config{
1711 Bugs: ProtocolBugs{
1712 SendEmptyFragments: true,
1713 },
1714 },
1715 },
1716 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001717 name: "BadFinished-Client",
1718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001719 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001720 Bugs: ProtocolBugs{
1721 BadFinished: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":DIGEST_CHECK_FAILED:",
1726 },
1727 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001728 name: "BadFinished-Client-TLS13",
1729 config: Config{
1730 MaxVersion: VersionTLS13,
1731 Bugs: ProtocolBugs{
1732 BadFinished: true,
1733 },
1734 },
1735 shouldFail: true,
1736 expectedError: ":DIGEST_CHECK_FAILED:",
1737 },
1738 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001739 testType: serverTest,
1740 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001741 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001742 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001743 Bugs: ProtocolBugs{
1744 BadFinished: true,
1745 },
1746 },
1747 shouldFail: true,
1748 expectedError: ":DIGEST_CHECK_FAILED:",
1749 },
1750 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001751 testType: serverTest,
1752 name: "BadFinished-Server-TLS13",
1753 config: Config{
1754 MaxVersion: VersionTLS13,
1755 Bugs: ProtocolBugs{
1756 BadFinished: true,
1757 },
1758 },
1759 shouldFail: true,
1760 expectedError: ":DIGEST_CHECK_FAILED:",
1761 },
1762 {
Adam Langley7c803a62015-06-15 15:35:05 -07001763 name: "FalseStart-BadFinished",
1764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001765 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1767 NextProtos: []string{"foo"},
1768 Bugs: ProtocolBugs{
1769 BadFinished: true,
1770 ExpectFalseStart: true,
1771 },
1772 },
1773 flags: []string{
1774 "-false-start",
1775 "-handshake-never-done",
1776 "-advertise-alpn", "\x03foo",
1777 },
1778 shimWritesFirst: true,
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
1783 name: "NoFalseStart-NoALPN",
1784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001785 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1787 Bugs: ProtocolBugs{
1788 ExpectFalseStart: true,
1789 AlertBeforeFalseStartTest: alertAccessDenied,
1790 },
1791 },
1792 flags: []string{
1793 "-false-start",
1794 },
1795 shimWritesFirst: true,
1796 shouldFail: true,
1797 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1798 expectedLocalError: "tls: peer did not false start: EOF",
1799 },
1800 {
1801 name: "NoFalseStart-NoAEAD",
1802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001803 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1805 NextProtos: []string{"foo"},
1806 Bugs: ProtocolBugs{
1807 ExpectFalseStart: true,
1808 AlertBeforeFalseStartTest: alertAccessDenied,
1809 },
1810 },
1811 flags: []string{
1812 "-false-start",
1813 "-advertise-alpn", "\x03foo",
1814 },
1815 shimWritesFirst: true,
1816 shouldFail: true,
1817 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1818 expectedLocalError: "tls: peer did not false start: EOF",
1819 },
1820 {
1821 name: "NoFalseStart-RSA",
1822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001823 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001824 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1825 NextProtos: []string{"foo"},
1826 Bugs: ProtocolBugs{
1827 ExpectFalseStart: true,
1828 AlertBeforeFalseStartTest: alertAccessDenied,
1829 },
1830 },
1831 flags: []string{
1832 "-false-start",
1833 "-advertise-alpn", "\x03foo",
1834 },
1835 shimWritesFirst: true,
1836 shouldFail: true,
1837 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1838 expectedLocalError: "tls: peer did not false start: EOF",
1839 },
1840 {
1841 name: "NoFalseStart-DHE_RSA",
1842 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001843 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001844 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1845 NextProtos: []string{"foo"},
1846 Bugs: ProtocolBugs{
1847 ExpectFalseStart: true,
1848 AlertBeforeFalseStartTest: alertAccessDenied,
1849 },
1850 },
1851 flags: []string{
1852 "-false-start",
1853 "-advertise-alpn", "\x03foo",
1854 },
1855 shimWritesFirst: true,
1856 shouldFail: true,
1857 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1858 expectedLocalError: "tls: peer did not false start: EOF",
1859 },
1860 {
Adam Langley7c803a62015-06-15 15:35:05 -07001861 protocol: dtls,
1862 name: "SendSplitAlert-Sync",
1863 config: Config{
1864 Bugs: ProtocolBugs{
1865 SendSplitAlert: true,
1866 },
1867 },
1868 },
1869 {
1870 protocol: dtls,
1871 name: "SendSplitAlert-Async",
1872 config: Config{
1873 Bugs: ProtocolBugs{
1874 SendSplitAlert: true,
1875 },
1876 },
1877 flags: []string{"-async"},
1878 },
1879 {
1880 protocol: dtls,
1881 name: "PackDTLSHandshake",
1882 config: Config{
1883 Bugs: ProtocolBugs{
1884 MaxHandshakeRecordLength: 2,
1885 PackHandshakeFragments: 20,
1886 PackHandshakeRecords: 200,
1887 },
1888 },
1889 },
1890 {
Adam Langley7c803a62015-06-15 15:35:05 -07001891 name: "SendEmptyRecords-Pass",
1892 sendEmptyRecords: 32,
1893 },
1894 {
1895 name: "SendEmptyRecords",
1896 sendEmptyRecords: 33,
1897 shouldFail: true,
1898 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1899 },
1900 {
1901 name: "SendEmptyRecords-Async",
1902 sendEmptyRecords: 33,
1903 flags: []string{"-async"},
1904 shouldFail: true,
1905 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1906 },
1907 {
1908 name: "SendWarningAlerts-Pass",
1909 sendWarningAlerts: 4,
1910 },
1911 {
1912 protocol: dtls,
1913 name: "SendWarningAlerts-DTLS-Pass",
1914 sendWarningAlerts: 4,
1915 },
1916 {
1917 name: "SendWarningAlerts",
1918 sendWarningAlerts: 5,
1919 shouldFail: true,
1920 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1921 },
1922 {
1923 name: "SendWarningAlerts-Async",
1924 sendWarningAlerts: 5,
1925 flags: []string{"-async"},
1926 shouldFail: true,
1927 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1928 },
David Benjaminba4594a2015-06-18 18:36:15 -04001929 {
1930 name: "EmptySessionID",
1931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001932 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001933 SessionTicketsDisabled: true,
1934 },
1935 noSessionCache: true,
1936 flags: []string{"-expect-no-session"},
1937 },
David Benjamin30789da2015-08-29 22:56:45 -04001938 {
1939 name: "Unclean-Shutdown",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 NoCloseNotify: true,
1943 ExpectCloseNotify: true,
1944 },
1945 },
1946 shimShutsDown: true,
1947 flags: []string{"-check-close-notify"},
1948 shouldFail: true,
1949 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1950 },
1951 {
1952 name: "Unclean-Shutdown-Ignored",
1953 config: Config{
1954 Bugs: ProtocolBugs{
1955 NoCloseNotify: true,
1956 },
1957 },
1958 shimShutsDown: true,
1959 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001960 {
David Benjaminfa214e42016-05-10 17:03:10 -04001961 name: "Unclean-Shutdown-Alert",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 SendAlertOnShutdown: alertDecompressionFailure,
1965 ExpectCloseNotify: true,
1966 },
1967 },
1968 shimShutsDown: true,
1969 flags: []string{"-check-close-notify"},
1970 shouldFail: true,
1971 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1972 },
1973 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001974 name: "LargePlaintext",
1975 config: Config{
1976 Bugs: ProtocolBugs{
1977 SendLargeRecords: true,
1978 },
1979 },
1980 messageLen: maxPlaintext + 1,
1981 shouldFail: true,
1982 expectedError: ":DATA_LENGTH_TOO_LONG:",
1983 },
1984 {
1985 protocol: dtls,
1986 name: "LargePlaintext-DTLS",
1987 config: Config{
1988 Bugs: ProtocolBugs{
1989 SendLargeRecords: true,
1990 },
1991 },
1992 messageLen: maxPlaintext + 1,
1993 shouldFail: true,
1994 expectedError: ":DATA_LENGTH_TOO_LONG:",
1995 },
1996 {
1997 name: "LargeCiphertext",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SendLargeRecords: true,
2001 },
2002 },
2003 messageLen: maxPlaintext * 2,
2004 shouldFail: true,
2005 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2006 },
2007 {
2008 protocol: dtls,
2009 name: "LargeCiphertext-DTLS",
2010 config: Config{
2011 Bugs: ProtocolBugs{
2012 SendLargeRecords: true,
2013 },
2014 },
2015 messageLen: maxPlaintext * 2,
2016 // Unlike the other four cases, DTLS drops records which
2017 // are invalid before authentication, so the connection
2018 // does not fail.
2019 expectMessageDropped: true,
2020 },
David Benjamindd6fed92015-10-23 17:41:12 -04002021 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002022 // In TLS 1.2 and below, empty NewSessionTicket messages
2023 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002024 name: "SendEmptySessionTicket",
2025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002026 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002027 Bugs: ProtocolBugs{
2028 SendEmptySessionTicket: true,
2029 FailIfSessionOffered: true,
2030 },
2031 },
2032 flags: []string{"-expect-no-session"},
2033 resumeSession: true,
2034 expectResumeRejected: true,
2035 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002036 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002037 name: "BadHelloRequest-1",
2038 renegotiate: 1,
2039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002040 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002041 Bugs: ProtocolBugs{
2042 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2043 },
2044 },
2045 flags: []string{
2046 "-renegotiate-freely",
2047 "-expect-total-renegotiations", "1",
2048 },
2049 shouldFail: true,
2050 expectedError: ":BAD_HELLO_REQUEST:",
2051 },
2052 {
2053 name: "BadHelloRequest-2",
2054 renegotiate: 1,
2055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002056 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002057 Bugs: ProtocolBugs{
2058 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2059 },
2060 },
2061 flags: []string{
2062 "-renegotiate-freely",
2063 "-expect-total-renegotiations", "1",
2064 },
2065 shouldFail: true,
2066 expectedError: ":BAD_HELLO_REQUEST:",
2067 },
David Benjaminef1b0092015-11-21 14:05:44 -05002068 {
2069 testType: serverTest,
2070 name: "SupportTicketsWithSessionID",
2071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002072 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002073 SessionTicketsDisabled: true,
2074 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002075 resumeConfig: &Config{
2076 MaxVersion: VersionTLS12,
2077 },
David Benjaminef1b0092015-11-21 14:05:44 -05002078 resumeSession: true,
2079 },
Adam Langley7c803a62015-06-15 15:35:05 -07002080 }
Adam Langley7c803a62015-06-15 15:35:05 -07002081 testCases = append(testCases, basicTests...)
2082}
2083
Adam Langley95c29f32014-06-20 12:00:00 -07002084func addCipherSuiteTests() {
2085 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002086 const psk = "12345"
2087 const pskIdentity = "luggage combo"
2088
Adam Langley95c29f32014-06-20 12:00:00 -07002089 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002090 var certFile string
2091 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002092 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002093 cert = ecdsaP256Certificate
2094 certFile = ecdsaP256CertificateFile
2095 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002096 } else {
David Benjamin33863262016-07-08 17:20:12 -07002097 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002098 certFile = rsaCertificateFile
2099 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002100 }
2101
David Benjamin48cae082014-10-27 01:06:24 -04002102 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002103 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002104 flags = append(flags,
2105 "-psk", psk,
2106 "-psk-identity", pskIdentity)
2107 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002108 if hasComponent(suite.name, "NULL") {
2109 // NULL ciphers must be explicitly enabled.
2110 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2111 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002112 if hasComponent(suite.name, "CECPQ1") {
2113 // CECPQ1 ciphers must be explicitly enabled.
2114 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2115 }
David Benjamin48cae082014-10-27 01:06:24 -04002116
Adam Langley95c29f32014-06-20 12:00:00 -07002117 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002118 for _, protocol := range []protocol{tls, dtls} {
2119 var prefix string
2120 if protocol == dtls {
2121 if !ver.hasDTLS {
2122 continue
2123 }
2124 prefix = "D"
2125 }
Adam Langley95c29f32014-06-20 12:00:00 -07002126
David Benjamin0407e762016-06-17 16:41:18 -04002127 var shouldServerFail, shouldClientFail bool
2128 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2129 // BoringSSL clients accept ECDHE on SSLv3, but
2130 // a BoringSSL server will never select it
2131 // because the extension is missing.
2132 shouldServerFail = true
2133 }
2134 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2135 shouldClientFail = true
2136 shouldServerFail = true
2137 }
David Benjamin54c217c2016-07-13 12:35:25 -04002138 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002139 shouldClientFail = true
2140 shouldServerFail = true
2141 }
David Benjamin0407e762016-06-17 16:41:18 -04002142 if !isDTLSCipher(suite.name) && protocol == dtls {
2143 shouldClientFail = true
2144 shouldServerFail = true
2145 }
David Benjamin4298d772015-12-19 00:18:25 -05002146
David Benjamin0407e762016-06-17 16:41:18 -04002147 var expectedServerError, expectedClientError string
2148 if shouldServerFail {
2149 expectedServerError = ":NO_SHARED_CIPHER:"
2150 }
2151 if shouldClientFail {
2152 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2153 }
David Benjamin025b3d32014-07-01 19:53:04 -04002154
David Benjamin9deb1172016-07-13 17:13:49 -04002155 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2156 resumeSession := ver.version < VersionTLS13
2157
David Benjamin6fd297b2014-08-11 18:43:38 -04002158 testCases = append(testCases, testCase{
2159 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002160 protocol: protocol,
2161
2162 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002163 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002164 MinVersion: ver.version,
2165 MaxVersion: ver.version,
2166 CipherSuites: []uint16{suite.id},
2167 Certificates: []Certificate{cert},
2168 PreSharedKey: []byte(psk),
2169 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002170 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002171 EnableAllCiphers: shouldServerFail,
2172 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002173 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002174 },
2175 certFile: certFile,
2176 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002177 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002178 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002179 shouldFail: shouldServerFail,
2180 expectedError: expectedServerError,
2181 })
2182
2183 testCases = append(testCases, testCase{
2184 testType: clientTest,
2185 protocol: protocol,
2186 name: prefix + ver.name + "-" + suite.name + "-client",
2187 config: Config{
2188 MinVersion: ver.version,
2189 MaxVersion: ver.version,
2190 CipherSuites: []uint16{suite.id},
2191 Certificates: []Certificate{cert},
2192 PreSharedKey: []byte(psk),
2193 PreSharedKeyIdentity: pskIdentity,
2194 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002195 EnableAllCiphers: shouldClientFail,
2196 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002197 },
2198 },
2199 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002200 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002201 shouldFail: shouldClientFail,
2202 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002203 })
David Benjamin2c99d282015-09-01 10:23:00 -04002204
Nick Harper1fd39d82016-06-14 18:14:35 -07002205 if !shouldClientFail {
2206 // Ensure the maximum record size is accepted.
2207 testCases = append(testCases, testCase{
2208 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2209 config: Config{
2210 MinVersion: ver.version,
2211 MaxVersion: ver.version,
2212 CipherSuites: []uint16{suite.id},
2213 Certificates: []Certificate{cert},
2214 PreSharedKey: []byte(psk),
2215 PreSharedKeyIdentity: pskIdentity,
2216 },
2217 flags: flags,
2218 messageLen: maxPlaintext,
2219 })
2220 }
2221 }
David Benjamin2c99d282015-09-01 10:23:00 -04002222 }
Adam Langley95c29f32014-06-20 12:00:00 -07002223 }
Adam Langleya7997f12015-05-14 17:38:50 -07002224
2225 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002226 name: "NoSharedCipher",
2227 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002228 MaxVersion: VersionTLS12,
2229 CipherSuites: []uint16{},
2230 },
2231 shouldFail: true,
2232 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2233 })
2234
2235 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002236 name: "NoSharedCipher-TLS13",
2237 config: Config{
2238 MaxVersion: VersionTLS13,
2239 CipherSuites: []uint16{},
2240 },
2241 shouldFail: true,
2242 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2243 })
2244
2245 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002246 name: "UnsupportedCipherSuite",
2247 config: Config{
2248 MaxVersion: VersionTLS12,
2249 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2250 Bugs: ProtocolBugs{
2251 IgnorePeerCipherPreferences: true,
2252 },
2253 },
2254 flags: []string{"-cipher", "DEFAULT:!RC4"},
2255 shouldFail: true,
2256 expectedError: ":WRONG_CIPHER_RETURNED:",
2257 })
2258
2259 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002260 name: "WeakDH",
2261 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002262 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002263 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2264 Bugs: ProtocolBugs{
2265 // This is a 1023-bit prime number, generated
2266 // with:
2267 // openssl gendh 1023 | openssl asn1parse -i
2268 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2269 },
2270 },
2271 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002272 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002273 })
Adam Langleycef75832015-09-03 14:51:12 -07002274
David Benjamincd24a392015-11-11 13:23:05 -08002275 testCases = append(testCases, testCase{
2276 name: "SillyDH",
2277 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002278 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002279 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2280 Bugs: ProtocolBugs{
2281 // This is a 4097-bit prime number, generated
2282 // with:
2283 // openssl gendh 4097 | openssl asn1parse -i
2284 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2285 },
2286 },
2287 shouldFail: true,
2288 expectedError: ":DH_P_TOO_LONG:",
2289 })
2290
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002291 // This test ensures that Diffie-Hellman public values are padded with
2292 // zeros so that they're the same length as the prime. This is to avoid
2293 // hitting a bug in yaSSL.
2294 testCases = append(testCases, testCase{
2295 testType: serverTest,
2296 name: "DHPublicValuePadded",
2297 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002298 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002299 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2300 Bugs: ProtocolBugs{
2301 RequireDHPublicValueLen: (1025 + 7) / 8,
2302 },
2303 },
2304 flags: []string{"-use-sparse-dh-prime"},
2305 })
David Benjamincd24a392015-11-11 13:23:05 -08002306
David Benjamin241ae832016-01-15 03:04:54 -05002307 // The server must be tolerant to bogus ciphers.
2308 const bogusCipher = 0x1234
2309 testCases = append(testCases, testCase{
2310 testType: serverTest,
2311 name: "UnknownCipher",
2312 config: Config{
2313 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2314 },
2315 })
2316
Adam Langleycef75832015-09-03 14:51:12 -07002317 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2318 // 1.1 specific cipher suite settings. A server is setup with the given
2319 // cipher lists and then a connection is made for each member of
2320 // expectations. The cipher suite that the server selects must match
2321 // the specified one.
2322 var versionSpecificCiphersTest = []struct {
2323 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2324 // expectations is a map from TLS version to cipher suite id.
2325 expectations map[uint16]uint16
2326 }{
2327 {
2328 // Test that the null case (where no version-specific ciphers are set)
2329 // works as expected.
2330 "RC4-SHA:AES128-SHA", // default ciphers
2331 "", // no ciphers specifically for TLS ≥ 1.0
2332 "", // no ciphers specifically for TLS ≥ 1.1
2333 map[uint16]uint16{
2334 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2335 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2336 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2337 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2338 },
2339 },
2340 {
2341 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2342 // cipher.
2343 "RC4-SHA:AES128-SHA", // default
2344 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2345 "", // no ciphers specifically for TLS ≥ 1.1
2346 map[uint16]uint16{
2347 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2348 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2349 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2350 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2351 },
2352 },
2353 {
2354 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2355 // cipher.
2356 "RC4-SHA:AES128-SHA", // default
2357 "", // no ciphers specifically for TLS ≥ 1.0
2358 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2359 map[uint16]uint16{
2360 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2361 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2362 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2363 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2364 },
2365 },
2366 {
2367 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2368 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2369 "RC4-SHA:AES128-SHA", // default
2370 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2371 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2372 map[uint16]uint16{
2373 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2374 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2375 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2376 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2377 },
2378 },
2379 }
2380
2381 for i, test := range versionSpecificCiphersTest {
2382 for version, expectedCipherSuite := range test.expectations {
2383 flags := []string{"-cipher", test.ciphersDefault}
2384 if len(test.ciphersTLS10) > 0 {
2385 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2386 }
2387 if len(test.ciphersTLS11) > 0 {
2388 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2389 }
2390
2391 testCases = append(testCases, testCase{
2392 testType: serverTest,
2393 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2394 config: Config{
2395 MaxVersion: version,
2396 MinVersion: version,
2397 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2398 },
2399 flags: flags,
2400 expectedCipher: expectedCipherSuite,
2401 })
2402 }
2403 }
Adam Langley95c29f32014-06-20 12:00:00 -07002404}
2405
2406func addBadECDSASignatureTests() {
2407 for badR := BadValue(1); badR < NumBadValues; badR++ {
2408 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002409 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002410 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2411 config: Config{
2412 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002413 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002414 Bugs: ProtocolBugs{
2415 BadECDSAR: badR,
2416 BadECDSAS: badS,
2417 },
2418 },
2419 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002420 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002421 })
2422 }
2423 }
2424}
2425
Adam Langley80842bd2014-06-20 12:00:00 -07002426func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002427 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002428 name: "MaxCBCPadding",
2429 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002430 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2432 Bugs: ProtocolBugs{
2433 MaxPadding: true,
2434 },
2435 },
2436 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2437 })
David Benjamin025b3d32014-07-01 19:53:04 -04002438 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002439 name: "BadCBCPadding",
2440 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002441 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002442 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2443 Bugs: ProtocolBugs{
2444 PaddingFirstByteBad: true,
2445 },
2446 },
2447 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002448 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002449 })
2450 // OpenSSL previously had an issue where the first byte of padding in
2451 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002452 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002453 name: "BadCBCPadding255",
2454 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002455 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002456 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2457 Bugs: ProtocolBugs{
2458 MaxPadding: true,
2459 PaddingFirstByteBadIf255: true,
2460 },
2461 },
2462 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2463 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002464 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002465 })
2466}
2467
Kenny Root7fdeaf12014-08-05 15:23:37 -07002468func addCBCSplittingTests() {
2469 testCases = append(testCases, testCase{
2470 name: "CBCRecordSplitting",
2471 config: Config{
2472 MaxVersion: VersionTLS10,
2473 MinVersion: VersionTLS10,
2474 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2475 },
David Benjaminac8302a2015-09-01 17:18:15 -04002476 messageLen: -1, // read until EOF
2477 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002478 flags: []string{
2479 "-async",
2480 "-write-different-record-sizes",
2481 "-cbc-record-splitting",
2482 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002483 })
2484 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002485 name: "CBCRecordSplittingPartialWrite",
2486 config: Config{
2487 MaxVersion: VersionTLS10,
2488 MinVersion: VersionTLS10,
2489 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2490 },
2491 messageLen: -1, // read until EOF
2492 flags: []string{
2493 "-async",
2494 "-write-different-record-sizes",
2495 "-cbc-record-splitting",
2496 "-partial-write",
2497 },
2498 })
2499}
2500
David Benjamin636293b2014-07-08 17:59:18 -04002501func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002502 // Add a dummy cert pool to stress certificate authority parsing.
2503 // TODO(davidben): Add tests that those values parse out correctly.
2504 certPool := x509.NewCertPool()
2505 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2506 if err != nil {
2507 panic(err)
2508 }
2509 certPool.AddCert(cert)
2510
David Benjamin636293b2014-07-08 17:59:18 -04002511 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002512 testCases = append(testCases, testCase{
2513 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002514 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002515 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002516 MinVersion: ver.version,
2517 MaxVersion: ver.version,
2518 ClientAuth: RequireAnyClientCert,
2519 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002520 },
2521 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002522 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2523 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002524 },
2525 })
2526 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002527 testType: serverTest,
2528 name: ver.name + "-Server-ClientAuth-RSA",
2529 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002530 MinVersion: ver.version,
2531 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002532 Certificates: []Certificate{rsaCertificate},
2533 },
2534 flags: []string{"-require-any-client-certificate"},
2535 })
David Benjamine098ec22014-08-27 23:13:20 -04002536 if ver.version != VersionSSL30 {
2537 testCases = append(testCases, testCase{
2538 testType: serverTest,
2539 name: ver.name + "-Server-ClientAuth-ECDSA",
2540 config: Config{
2541 MinVersion: ver.version,
2542 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002543 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002544 },
2545 flags: []string{"-require-any-client-certificate"},
2546 })
2547 testCases = append(testCases, testCase{
2548 testType: clientTest,
2549 name: ver.name + "-Client-ClientAuth-ECDSA",
2550 config: Config{
2551 MinVersion: ver.version,
2552 MaxVersion: ver.version,
2553 ClientAuth: RequireAnyClientCert,
2554 ClientCAs: certPool,
2555 },
2556 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002557 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2558 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002559 },
2560 })
2561 }
David Benjamin636293b2014-07-08 17:59:18 -04002562 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002563
2564 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002565 name: "NoClientCertificate",
2566 config: Config{
2567 MaxVersion: VersionTLS12,
2568 ClientAuth: RequireAnyClientCert,
2569 },
2570 shouldFail: true,
2571 expectedLocalError: "client didn't provide a certificate",
2572 })
2573
2574 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002575 name: "NoClientCertificate-TLS13",
2576 config: Config{
2577 MaxVersion: VersionTLS13,
2578 ClientAuth: RequireAnyClientCert,
2579 },
2580 shouldFail: true,
2581 expectedLocalError: "client didn't provide a certificate",
2582 })
2583
2584 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002585 testType: serverTest,
2586 name: "RequireAnyClientCertificate",
2587 config: Config{
2588 MaxVersion: VersionTLS12,
2589 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002590 flags: []string{"-require-any-client-certificate"},
2591 shouldFail: true,
2592 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2593 })
2594
2595 testCases = append(testCases, testCase{
2596 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002597 name: "RequireAnyClientCertificate-TLS13",
2598 config: Config{
2599 MaxVersion: VersionTLS13,
2600 },
2601 flags: []string{"-require-any-client-certificate"},
2602 shouldFail: true,
2603 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2604 })
2605
2606 testCases = append(testCases, testCase{
2607 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002608 name: "RequireAnyClientCertificate-SSL3",
2609 config: Config{
2610 MaxVersion: VersionSSL30,
2611 },
2612 flags: []string{"-require-any-client-certificate"},
2613 shouldFail: true,
2614 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2615 })
2616
2617 testCases = append(testCases, testCase{
2618 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002619 name: "SkipClientCertificate",
2620 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002621 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002622 Bugs: ProtocolBugs{
2623 SkipClientCertificate: true,
2624 },
2625 },
2626 // Setting SSL_VERIFY_PEER allows anonymous clients.
2627 flags: []string{"-verify-peer"},
2628 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002629 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002630 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002631
Steven Valdez143e8b32016-07-11 13:19:03 -04002632 testCases = append(testCases, testCase{
2633 testType: serverTest,
2634 name: "SkipClientCertificate-TLS13",
2635 config: Config{
2636 MaxVersion: VersionTLS13,
2637 Bugs: ProtocolBugs{
2638 SkipClientCertificate: true,
2639 },
2640 },
2641 // Setting SSL_VERIFY_PEER allows anonymous clients.
2642 flags: []string{"-verify-peer"},
2643 shouldFail: true,
2644 expectedError: ":UNEXPECTED_MESSAGE:",
2645 })
2646
David Benjaminc032dfa2016-05-12 14:54:57 -04002647 // Client auth is only legal in certificate-based ciphers.
2648 testCases = append(testCases, testCase{
2649 testType: clientTest,
2650 name: "ClientAuth-PSK",
2651 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002652 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002653 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2654 PreSharedKey: []byte("secret"),
2655 ClientAuth: RequireAnyClientCert,
2656 },
2657 flags: []string{
2658 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2659 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2660 "-psk", "secret",
2661 },
2662 shouldFail: true,
2663 expectedError: ":UNEXPECTED_MESSAGE:",
2664 })
2665 testCases = append(testCases, testCase{
2666 testType: clientTest,
2667 name: "ClientAuth-ECDHE_PSK",
2668 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002669 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002670 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2671 PreSharedKey: []byte("secret"),
2672 ClientAuth: RequireAnyClientCert,
2673 },
2674 flags: []string{
2675 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2676 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2677 "-psk", "secret",
2678 },
2679 shouldFail: true,
2680 expectedError: ":UNEXPECTED_MESSAGE:",
2681 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002682
2683 // Regression test for a bug where the client CA list, if explicitly
2684 // set to NULL, was mis-encoded.
2685 testCases = append(testCases, testCase{
2686 testType: serverTest,
2687 name: "Null-Client-CA-List",
2688 config: Config{
2689 MaxVersion: VersionTLS12,
2690 Certificates: []Certificate{rsaCertificate},
2691 },
2692 flags: []string{
2693 "-require-any-client-certificate",
2694 "-use-null-client-ca-list",
2695 },
2696 })
David Benjamin636293b2014-07-08 17:59:18 -04002697}
2698
Adam Langley75712922014-10-10 16:23:43 -07002699func addExtendedMasterSecretTests() {
2700 const expectEMSFlag = "-expect-extended-master-secret"
2701
2702 for _, with := range []bool{false, true} {
2703 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002704 if with {
2705 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002706 }
2707
2708 for _, isClient := range []bool{false, true} {
2709 suffix := "-Server"
2710 testType := serverTest
2711 if isClient {
2712 suffix = "-Client"
2713 testType = clientTest
2714 }
2715
2716 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002717 // In TLS 1.3, the extension is irrelevant and
2718 // always reports as enabled.
2719 var flags []string
2720 if with || ver.version >= VersionTLS13 {
2721 flags = []string{expectEMSFlag}
2722 }
2723
Adam Langley75712922014-10-10 16:23:43 -07002724 test := testCase{
2725 testType: testType,
2726 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2727 config: Config{
2728 MinVersion: ver.version,
2729 MaxVersion: ver.version,
2730 Bugs: ProtocolBugs{
2731 NoExtendedMasterSecret: !with,
2732 RequireExtendedMasterSecret: with,
2733 },
2734 },
David Benjamin48cae082014-10-27 01:06:24 -04002735 flags: flags,
2736 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002737 }
2738 if test.shouldFail {
2739 test.expectedLocalError = "extended master secret required but not supported by peer"
2740 }
2741 testCases = append(testCases, test)
2742 }
2743 }
2744 }
2745
Adam Langleyba5934b2015-06-02 10:50:35 -07002746 for _, isClient := range []bool{false, true} {
2747 for _, supportedInFirstConnection := range []bool{false, true} {
2748 for _, supportedInResumeConnection := range []bool{false, true} {
2749 boolToWord := func(b bool) string {
2750 if b {
2751 return "Yes"
2752 }
2753 return "No"
2754 }
2755 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2756 if isClient {
2757 suffix += "Client"
2758 } else {
2759 suffix += "Server"
2760 }
2761
2762 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002763 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002764 Bugs: ProtocolBugs{
2765 RequireExtendedMasterSecret: true,
2766 },
2767 }
2768
2769 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002770 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002771 Bugs: ProtocolBugs{
2772 NoExtendedMasterSecret: true,
2773 },
2774 }
2775
2776 test := testCase{
2777 name: "ExtendedMasterSecret-" + suffix,
2778 resumeSession: true,
2779 }
2780
2781 if !isClient {
2782 test.testType = serverTest
2783 }
2784
2785 if supportedInFirstConnection {
2786 test.config = supportedConfig
2787 } else {
2788 test.config = noSupportConfig
2789 }
2790
2791 if supportedInResumeConnection {
2792 test.resumeConfig = &supportedConfig
2793 } else {
2794 test.resumeConfig = &noSupportConfig
2795 }
2796
2797 switch suffix {
2798 case "YesToYes-Client", "YesToYes-Server":
2799 // When a session is resumed, it should
2800 // still be aware that its master
2801 // secret was generated via EMS and
2802 // thus it's safe to use tls-unique.
2803 test.flags = []string{expectEMSFlag}
2804 case "NoToYes-Server":
2805 // If an original connection did not
2806 // contain EMS, but a resumption
2807 // handshake does, then a server should
2808 // not resume the session.
2809 test.expectResumeRejected = true
2810 case "YesToNo-Server":
2811 // Resuming an EMS session without the
2812 // EMS extension should cause the
2813 // server to abort the connection.
2814 test.shouldFail = true
2815 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2816 case "NoToYes-Client":
2817 // A client should abort a connection
2818 // where the server resumed a non-EMS
2819 // session but echoed the EMS
2820 // extension.
2821 test.shouldFail = true
2822 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2823 case "YesToNo-Client":
2824 // A client should abort a connection
2825 // where the server didn't echo EMS
2826 // when the session used it.
2827 test.shouldFail = true
2828 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2829 }
2830
2831 testCases = append(testCases, test)
2832 }
2833 }
2834 }
Adam Langley75712922014-10-10 16:23:43 -07002835}
2836
David Benjamin582ba042016-07-07 12:33:25 -07002837type stateMachineTestConfig struct {
2838 protocol protocol
2839 async bool
2840 splitHandshake, packHandshakeFlight bool
2841}
2842
David Benjamin43ec06f2014-08-05 02:28:57 -04002843// Adds tests that try to cover the range of the handshake state machine, under
2844// various conditions. Some of these are redundant with other tests, but they
2845// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002846func addAllStateMachineCoverageTests() {
2847 for _, async := range []bool{false, true} {
2848 for _, protocol := range []protocol{tls, dtls} {
2849 addStateMachineCoverageTests(stateMachineTestConfig{
2850 protocol: protocol,
2851 async: async,
2852 })
2853 addStateMachineCoverageTests(stateMachineTestConfig{
2854 protocol: protocol,
2855 async: async,
2856 splitHandshake: true,
2857 })
2858 if protocol == tls {
2859 addStateMachineCoverageTests(stateMachineTestConfig{
2860 protocol: protocol,
2861 async: async,
2862 packHandshakeFlight: true,
2863 })
2864 }
2865 }
2866 }
2867}
2868
2869func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002870 var tests []testCase
2871
2872 // Basic handshake, with resumption. Client and server,
2873 // session ID and session ticket.
2874 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002875 name: "Basic-Client",
2876 config: Config{
2877 MaxVersion: VersionTLS12,
2878 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002879 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002880 // Ensure session tickets are used, not session IDs.
2881 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002882 })
2883 tests = append(tests, testCase{
2884 name: "Basic-Client-RenewTicket",
2885 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002886 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002887 Bugs: ProtocolBugs{
2888 RenewTicketOnResume: true,
2889 },
2890 },
David Benjaminba4594a2015-06-18 18:36:15 -04002891 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002892 resumeSession: true,
2893 })
2894 tests = append(tests, testCase{
2895 name: "Basic-Client-NoTicket",
2896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002897 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002898 SessionTicketsDisabled: true,
2899 },
2900 resumeSession: true,
2901 })
2902 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002903 name: "Basic-Client-Implicit",
2904 config: Config{
2905 MaxVersion: VersionTLS12,
2906 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002907 flags: []string{"-implicit-handshake"},
2908 resumeSession: true,
2909 })
2910 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002911 testType: serverTest,
2912 name: "Basic-Server",
2913 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002914 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002915 Bugs: ProtocolBugs{
2916 RequireSessionTickets: true,
2917 },
2918 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002919 resumeSession: true,
2920 })
2921 tests = append(tests, testCase{
2922 testType: serverTest,
2923 name: "Basic-Server-NoTickets",
2924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002925 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002926 SessionTicketsDisabled: true,
2927 },
2928 resumeSession: true,
2929 })
2930 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002931 testType: serverTest,
2932 name: "Basic-Server-Implicit",
2933 config: Config{
2934 MaxVersion: VersionTLS12,
2935 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002936 flags: []string{"-implicit-handshake"},
2937 resumeSession: true,
2938 })
2939 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002940 testType: serverTest,
2941 name: "Basic-Server-EarlyCallback",
2942 config: Config{
2943 MaxVersion: VersionTLS12,
2944 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002945 flags: []string{"-use-early-callback"},
2946 resumeSession: true,
2947 })
2948
Steven Valdez143e8b32016-07-11 13:19:03 -04002949 // TLS 1.3 basic handshake shapes.
2950 tests = append(tests, testCase{
2951 name: "TLS13-1RTT-Client",
2952 config: Config{
2953 MaxVersion: VersionTLS13,
2954 },
2955 })
2956 tests = append(tests, testCase{
2957 testType: serverTest,
2958 name: "TLS13-1RTT-Server",
2959 config: Config{
2960 MaxVersion: VersionTLS13,
2961 },
2962 })
2963
David Benjamin760b1dd2015-05-15 23:33:48 -04002964 // TLS client auth.
2965 tests = append(tests, testCase{
2966 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002967 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002969 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002970 ClientAuth: RequestClientCert,
2971 },
2972 })
2973 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002974 testType: serverTest,
2975 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002976 config: Config{
2977 MaxVersion: VersionTLS12,
2978 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002979 // Setting SSL_VERIFY_PEER allows anonymous clients.
2980 flags: []string{"-verify-peer"},
2981 })
David Benjamin582ba042016-07-07 12:33:25 -07002982 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002983 tests = append(tests, testCase{
2984 testType: clientTest,
2985 name: "ClientAuth-NoCertificate-Client-SSL3",
2986 config: Config{
2987 MaxVersion: VersionSSL30,
2988 ClientAuth: RequestClientCert,
2989 },
2990 })
2991 tests = append(tests, testCase{
2992 testType: serverTest,
2993 name: "ClientAuth-NoCertificate-Server-SSL3",
2994 config: Config{
2995 MaxVersion: VersionSSL30,
2996 },
2997 // Setting SSL_VERIFY_PEER allows anonymous clients.
2998 flags: []string{"-verify-peer"},
2999 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003000 tests = append(tests, testCase{
3001 testType: clientTest,
3002 name: "ClientAuth-NoCertificate-Client-TLS13",
3003 config: Config{
3004 MaxVersion: VersionTLS13,
3005 ClientAuth: RequestClientCert,
3006 },
3007 })
3008 tests = append(tests, testCase{
3009 testType: serverTest,
3010 name: "ClientAuth-NoCertificate-Server-TLS13",
3011 config: Config{
3012 MaxVersion: VersionTLS13,
3013 },
3014 // Setting SSL_VERIFY_PEER allows anonymous clients.
3015 flags: []string{"-verify-peer"},
3016 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003017 }
3018 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003019 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003020 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003022 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003023 ClientAuth: RequireAnyClientCert,
3024 },
3025 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003026 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3027 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003028 },
3029 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003030 tests = append(tests, testCase{
3031 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003032 name: "ClientAuth-RSA-Client-TLS13",
3033 config: Config{
3034 MaxVersion: VersionTLS13,
3035 ClientAuth: RequireAnyClientCert,
3036 },
3037 flags: []string{
3038 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3039 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3040 },
3041 })
3042 tests = append(tests, testCase{
3043 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003044 name: "ClientAuth-ECDSA-Client",
3045 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003046 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003047 ClientAuth: RequireAnyClientCert,
3048 },
3049 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003050 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3051 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003052 },
3053 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003054 tests = append(tests, testCase{
3055 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003056 name: "ClientAuth-ECDSA-Client-TLS13",
3057 config: Config{
3058 MaxVersion: VersionTLS13,
3059 ClientAuth: RequireAnyClientCert,
3060 },
3061 flags: []string{
3062 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3063 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3064 },
3065 })
3066 tests = append(tests, testCase{
3067 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003068 name: "ClientAuth-NoCertificate-OldCallback",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 ClientAuth: RequestClientCert,
3072 },
3073 flags: []string{"-use-old-client-cert-callback"},
3074 })
3075 tests = append(tests, testCase{
3076 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003077 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3078 config: Config{
3079 MaxVersion: VersionTLS13,
3080 ClientAuth: RequestClientCert,
3081 },
3082 flags: []string{"-use-old-client-cert-callback"},
3083 })
3084 tests = append(tests, testCase{
3085 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003086 name: "ClientAuth-OldCallback",
3087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003088 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003089 ClientAuth: RequireAnyClientCert,
3090 },
3091 flags: []string{
3092 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3093 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3094 "-use-old-client-cert-callback",
3095 },
3096 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003097 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003098 testType: clientTest,
3099 name: "ClientAuth-OldCallback-TLS13",
3100 config: Config{
3101 MaxVersion: VersionTLS13,
3102 ClientAuth: RequireAnyClientCert,
3103 },
3104 flags: []string{
3105 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3106 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3107 "-use-old-client-cert-callback",
3108 },
3109 })
3110 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003111 testType: serverTest,
3112 name: "ClientAuth-Server",
3113 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003115 Certificates: []Certificate{rsaCertificate},
3116 },
3117 flags: []string{"-require-any-client-certificate"},
3118 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003119 tests = append(tests, testCase{
3120 testType: serverTest,
3121 name: "ClientAuth-Server-TLS13",
3122 config: Config{
3123 MaxVersion: VersionTLS13,
3124 Certificates: []Certificate{rsaCertificate},
3125 },
3126 flags: []string{"-require-any-client-certificate"},
3127 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003128
David Benjamin4c3ddf72016-06-29 18:13:53 -04003129 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003130 tests = append(tests, testCase{
3131 testType: serverTest,
3132 name: "Basic-Server-RSA",
3133 config: Config{
3134 MaxVersion: VersionTLS12,
3135 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3136 },
3137 flags: []string{
3138 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3139 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3140 },
3141 })
3142 tests = append(tests, testCase{
3143 testType: serverTest,
3144 name: "Basic-Server-ECDHE-RSA",
3145 config: Config{
3146 MaxVersion: VersionTLS12,
3147 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3148 },
3149 flags: []string{
3150 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3151 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3152 },
3153 })
3154 tests = append(tests, testCase{
3155 testType: serverTest,
3156 name: "Basic-Server-ECDHE-ECDSA",
3157 config: Config{
3158 MaxVersion: VersionTLS12,
3159 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3160 },
3161 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003162 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3163 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003164 },
3165 })
3166
David Benjamin760b1dd2015-05-15 23:33:48 -04003167 // No session ticket support; server doesn't send NewSessionTicket.
3168 tests = append(tests, testCase{
3169 name: "SessionTicketsDisabled-Client",
3170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003171 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003172 SessionTicketsDisabled: true,
3173 },
3174 })
3175 tests = append(tests, testCase{
3176 testType: serverTest,
3177 name: "SessionTicketsDisabled-Server",
3178 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003179 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003180 SessionTicketsDisabled: true,
3181 },
3182 })
3183
3184 // Skip ServerKeyExchange in PSK key exchange if there's no
3185 // identity hint.
3186 tests = append(tests, testCase{
3187 name: "EmptyPSKHint-Client",
3188 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003189 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003190 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3191 PreSharedKey: []byte("secret"),
3192 },
3193 flags: []string{"-psk", "secret"},
3194 })
3195 tests = append(tests, testCase{
3196 testType: serverTest,
3197 name: "EmptyPSKHint-Server",
3198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003199 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003200 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3201 PreSharedKey: []byte("secret"),
3202 },
3203 flags: []string{"-psk", "secret"},
3204 })
3205
David Benjamin4c3ddf72016-06-29 18:13:53 -04003206 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003207 tests = append(tests, testCase{
3208 testType: clientTest,
3209 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003210 config: Config{
3211 MaxVersion: VersionTLS12,
3212 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003213 flags: []string{
3214 "-enable-ocsp-stapling",
3215 "-expect-ocsp-response",
3216 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003217 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003218 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003219 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003220 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003221 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003222 testType: serverTest,
3223 name: "OCSPStapling-Server",
3224 config: Config{
3225 MaxVersion: VersionTLS12,
3226 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003227 expectedOCSPResponse: testOCSPResponse,
3228 flags: []string{
3229 "-ocsp-response",
3230 base64.StdEncoding.EncodeToString(testOCSPResponse),
3231 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003232 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003233 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003234 tests = append(tests, testCase{
3235 testType: clientTest,
3236 name: "OCSPStapling-Client-TLS13",
3237 config: Config{
3238 MaxVersion: VersionTLS13,
3239 },
3240 flags: []string{
3241 "-enable-ocsp-stapling",
3242 "-expect-ocsp-response",
3243 base64.StdEncoding.EncodeToString(testOCSPResponse),
3244 "-verify-peer",
3245 },
3246 // TODO(davidben): Enable this when resumption is implemented
3247 // in TLS 1.3.
3248 resumeSession: false,
3249 })
3250 tests = append(tests, testCase{
3251 testType: serverTest,
3252 name: "OCSPStapling-Server-TLS13",
3253 config: Config{
3254 MaxVersion: VersionTLS13,
3255 },
3256 expectedOCSPResponse: testOCSPResponse,
3257 flags: []string{
3258 "-ocsp-response",
3259 base64.StdEncoding.EncodeToString(testOCSPResponse),
3260 },
3261 // TODO(davidben): Enable this when resumption is implemented
3262 // in TLS 1.3.
3263 resumeSession: false,
3264 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003265
David Benjamin4c3ddf72016-06-29 18:13:53 -04003266 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003267 for _, vers := range tlsVersions {
3268 if config.protocol == dtls && !vers.hasDTLS {
3269 continue
3270 }
3271 tests = append(tests, testCase{
3272 testType: clientTest,
3273 name: "CertificateVerificationSucceed-" + vers.name,
3274 config: Config{
3275 MaxVersion: vers.version,
3276 },
3277 flags: []string{
3278 "-verify-peer",
3279 },
3280 })
3281 tests = append(tests, testCase{
3282 testType: clientTest,
3283 name: "CertificateVerificationFail-" + vers.name,
3284 config: Config{
3285 MaxVersion: vers.version,
3286 },
3287 flags: []string{
3288 "-verify-fail",
3289 "-verify-peer",
3290 },
3291 shouldFail: true,
3292 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3293 })
3294 tests = append(tests, testCase{
3295 testType: clientTest,
3296 name: "CertificateVerificationSoftFail-" + vers.name,
3297 config: Config{
3298 MaxVersion: vers.version,
3299 },
3300 flags: []string{
3301 "-verify-fail",
3302 "-expect-verify-result",
3303 },
3304 })
3305 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003306
David Benjamin582ba042016-07-07 12:33:25 -07003307 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003308 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003309 name: "Renegotiate-Client",
3310 config: Config{
3311 MaxVersion: VersionTLS12,
3312 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003313 renegotiate: 1,
3314 flags: []string{
3315 "-renegotiate-freely",
3316 "-expect-total-renegotiations", "1",
3317 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003318 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003319
David Benjamin760b1dd2015-05-15 23:33:48 -04003320 // NPN on client and server; results in post-handshake message.
3321 tests = append(tests, testCase{
3322 name: "NPN-Client",
3323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003324 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003325 NextProtos: []string{"foo"},
3326 },
3327 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003328 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003329 expectedNextProto: "foo",
3330 expectedNextProtoType: npn,
3331 })
3332 tests = append(tests, testCase{
3333 testType: serverTest,
3334 name: "NPN-Server",
3335 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003336 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003337 NextProtos: []string{"bar"},
3338 },
3339 flags: []string{
3340 "-advertise-npn", "\x03foo\x03bar\x03baz",
3341 "-expect-next-proto", "bar",
3342 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003343 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003344 expectedNextProto: "bar",
3345 expectedNextProtoType: npn,
3346 })
3347
3348 // TODO(davidben): Add tests for when False Start doesn't trigger.
3349
3350 // Client does False Start and negotiates NPN.
3351 tests = append(tests, testCase{
3352 name: "FalseStart",
3353 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003354 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003355 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3356 NextProtos: []string{"foo"},
3357 Bugs: ProtocolBugs{
3358 ExpectFalseStart: true,
3359 },
3360 },
3361 flags: []string{
3362 "-false-start",
3363 "-select-next-proto", "foo",
3364 },
3365 shimWritesFirst: true,
3366 resumeSession: true,
3367 })
3368
3369 // Client does False Start and negotiates ALPN.
3370 tests = append(tests, testCase{
3371 name: "FalseStart-ALPN",
3372 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003373 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003374 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3375 NextProtos: []string{"foo"},
3376 Bugs: ProtocolBugs{
3377 ExpectFalseStart: true,
3378 },
3379 },
3380 flags: []string{
3381 "-false-start",
3382 "-advertise-alpn", "\x03foo",
3383 },
3384 shimWritesFirst: true,
3385 resumeSession: true,
3386 })
3387
3388 // Client does False Start but doesn't explicitly call
3389 // SSL_connect.
3390 tests = append(tests, testCase{
3391 name: "FalseStart-Implicit",
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 },
3397 flags: []string{
3398 "-implicit-handshake",
3399 "-false-start",
3400 "-advertise-alpn", "\x03foo",
3401 },
3402 })
3403
3404 // False Start without session tickets.
3405 tests = append(tests, testCase{
3406 name: "FalseStart-SessionTicketsDisabled",
3407 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003408 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3410 NextProtos: []string{"foo"},
3411 SessionTicketsDisabled: true,
3412 Bugs: ProtocolBugs{
3413 ExpectFalseStart: true,
3414 },
3415 },
3416 flags: []string{
3417 "-false-start",
3418 "-select-next-proto", "foo",
3419 },
3420 shimWritesFirst: true,
3421 })
3422
Adam Langleydf759b52016-07-11 15:24:37 -07003423 tests = append(tests, testCase{
3424 name: "FalseStart-CECPQ1",
3425 config: Config{
3426 MaxVersion: VersionTLS12,
3427 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3428 NextProtos: []string{"foo"},
3429 Bugs: ProtocolBugs{
3430 ExpectFalseStart: true,
3431 },
3432 },
3433 flags: []string{
3434 "-false-start",
3435 "-cipher", "DEFAULT:kCECPQ1",
3436 "-select-next-proto", "foo",
3437 },
3438 shimWritesFirst: true,
3439 resumeSession: true,
3440 })
3441
David Benjamin760b1dd2015-05-15 23:33:48 -04003442 // Server parses a V2ClientHello.
3443 tests = append(tests, testCase{
3444 testType: serverTest,
3445 name: "SendV2ClientHello",
3446 config: Config{
3447 // Choose a cipher suite that does not involve
3448 // elliptic curves, so no extensions are
3449 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003450 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003451 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3452 Bugs: ProtocolBugs{
3453 SendV2ClientHello: true,
3454 },
3455 },
3456 })
3457
3458 // Client sends a Channel ID.
3459 tests = append(tests, testCase{
3460 name: "ChannelID-Client",
3461 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003462 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003463 RequestChannelID: true,
3464 },
Adam Langley7c803a62015-06-15 15:35:05 -07003465 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003466 resumeSession: true,
3467 expectChannelID: true,
3468 })
3469
3470 // Server accepts a Channel ID.
3471 tests = append(tests, testCase{
3472 testType: serverTest,
3473 name: "ChannelID-Server",
3474 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003475 MaxVersion: VersionTLS12,
3476 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003477 },
3478 flags: []string{
3479 "-expect-channel-id",
3480 base64.StdEncoding.EncodeToString(channelIDBytes),
3481 },
3482 resumeSession: true,
3483 expectChannelID: true,
3484 })
David Benjamin30789da2015-08-29 22:56:45 -04003485
David Benjaminf8fcdf32016-06-08 15:56:13 -04003486 // Channel ID and NPN at the same time, to ensure their relative
3487 // ordering is correct.
3488 tests = append(tests, testCase{
3489 name: "ChannelID-NPN-Client",
3490 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003491 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003492 RequestChannelID: true,
3493 NextProtos: []string{"foo"},
3494 },
3495 flags: []string{
3496 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3497 "-select-next-proto", "foo",
3498 },
3499 resumeSession: true,
3500 expectChannelID: true,
3501 expectedNextProto: "foo",
3502 expectedNextProtoType: npn,
3503 })
3504 tests = append(tests, testCase{
3505 testType: serverTest,
3506 name: "ChannelID-NPN-Server",
3507 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003508 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003509 ChannelID: channelIDKey,
3510 NextProtos: []string{"bar"},
3511 },
3512 flags: []string{
3513 "-expect-channel-id",
3514 base64.StdEncoding.EncodeToString(channelIDBytes),
3515 "-advertise-npn", "\x03foo\x03bar\x03baz",
3516 "-expect-next-proto", "bar",
3517 },
3518 resumeSession: true,
3519 expectChannelID: true,
3520 expectedNextProto: "bar",
3521 expectedNextProtoType: npn,
3522 })
3523
David Benjamin30789da2015-08-29 22:56:45 -04003524 // Bidirectional shutdown with the runner initiating.
3525 tests = append(tests, testCase{
3526 name: "Shutdown-Runner",
3527 config: Config{
3528 Bugs: ProtocolBugs{
3529 ExpectCloseNotify: true,
3530 },
3531 },
3532 flags: []string{"-check-close-notify"},
3533 })
3534
3535 // Bidirectional shutdown with the shim initiating. The runner,
3536 // in the meantime, sends garbage before the close_notify which
3537 // the shim must ignore.
3538 tests = append(tests, testCase{
3539 name: "Shutdown-Shim",
3540 config: Config{
3541 Bugs: ProtocolBugs{
3542 ExpectCloseNotify: true,
3543 },
3544 },
3545 shimShutsDown: true,
3546 sendEmptyRecords: 1,
3547 sendWarningAlerts: 1,
3548 flags: []string{"-check-close-notify"},
3549 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003550 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003551 // TODO(davidben): DTLS 1.3 will want a similar thing for
3552 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003553 tests = append(tests, testCase{
3554 name: "SkipHelloVerifyRequest",
3555 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003556 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003557 Bugs: ProtocolBugs{
3558 SkipHelloVerifyRequest: true,
3559 },
3560 },
3561 })
3562 }
3563
David Benjamin760b1dd2015-05-15 23:33:48 -04003564 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003565 test.protocol = config.protocol
3566 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003567 test.name += "-DTLS"
3568 }
David Benjamin582ba042016-07-07 12:33:25 -07003569 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003570 test.name += "-Async"
3571 test.flags = append(test.flags, "-async")
3572 } else {
3573 test.name += "-Sync"
3574 }
David Benjamin582ba042016-07-07 12:33:25 -07003575 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003576 test.name += "-SplitHandshakeRecords"
3577 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003578 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003579 test.config.Bugs.MaxPacketLength = 256
3580 test.flags = append(test.flags, "-mtu", "256")
3581 }
3582 }
David Benjamin582ba042016-07-07 12:33:25 -07003583 if config.packHandshakeFlight {
3584 test.name += "-PackHandshakeFlight"
3585 test.config.Bugs.PackHandshakeFlight = true
3586 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003587 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003588 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003589}
3590
Adam Langley524e7172015-02-20 16:04:00 -08003591func addDDoSCallbackTests() {
3592 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003593 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003594 for _, resume := range []bool{false, true} {
3595 suffix := "Resume"
3596 if resume {
3597 suffix = "No" + suffix
3598 }
3599
3600 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003601 testType: serverTest,
3602 name: "Server-DDoS-OK-" + suffix,
3603 config: Config{
3604 MaxVersion: VersionTLS12,
3605 },
Adam Langley524e7172015-02-20 16:04:00 -08003606 flags: []string{"-install-ddos-callback"},
3607 resumeSession: resume,
3608 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003609 if !resume {
3610 testCases = append(testCases, testCase{
3611 testType: serverTest,
3612 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3613 config: Config{
3614 MaxVersion: VersionTLS13,
3615 },
3616 flags: []string{"-install-ddos-callback"},
3617 resumeSession: resume,
3618 })
3619 }
Adam Langley524e7172015-02-20 16:04:00 -08003620
3621 failFlag := "-fail-ddos-callback"
3622 if resume {
3623 failFlag = "-fail-second-ddos-callback"
3624 }
3625 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003626 testType: serverTest,
3627 name: "Server-DDoS-Reject-" + suffix,
3628 config: Config{
3629 MaxVersion: VersionTLS12,
3630 },
Adam Langley524e7172015-02-20 16:04:00 -08003631 flags: []string{"-install-ddos-callback", failFlag},
3632 resumeSession: resume,
3633 shouldFail: true,
3634 expectedError: ":CONNECTION_REJECTED:",
3635 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003636 if !resume {
3637 testCases = append(testCases, testCase{
3638 testType: serverTest,
3639 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3640 config: Config{
3641 MaxVersion: VersionTLS13,
3642 },
3643 flags: []string{"-install-ddos-callback", failFlag},
3644 resumeSession: resume,
3645 shouldFail: true,
3646 expectedError: ":CONNECTION_REJECTED:",
3647 })
3648 }
Adam Langley524e7172015-02-20 16:04:00 -08003649 }
3650}
3651
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003652func addVersionNegotiationTests() {
3653 for i, shimVers := range tlsVersions {
3654 // Assemble flags to disable all newer versions on the shim.
3655 var flags []string
3656 for _, vers := range tlsVersions[i+1:] {
3657 flags = append(flags, vers.flag)
3658 }
3659
3660 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003661 protocols := []protocol{tls}
3662 if runnerVers.hasDTLS && shimVers.hasDTLS {
3663 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003664 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003665 for _, protocol := range protocols {
3666 expectedVersion := shimVers.version
3667 if runnerVers.version < shimVers.version {
3668 expectedVersion = runnerVers.version
3669 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003670
David Benjamin8b8c0062014-11-23 02:47:52 -05003671 suffix := shimVers.name + "-" + runnerVers.name
3672 if protocol == dtls {
3673 suffix += "-DTLS"
3674 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003675
David Benjamin1eb367c2014-12-12 18:17:51 -05003676 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3677
David Benjamin1e29a6b2014-12-10 02:27:24 -05003678 clientVers := shimVers.version
3679 if clientVers > VersionTLS10 {
3680 clientVers = VersionTLS10
3681 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003682 serverVers := expectedVersion
3683 if expectedVersion >= VersionTLS13 {
3684 serverVers = VersionTLS10
3685 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003686 testCases = append(testCases, testCase{
3687 protocol: protocol,
3688 testType: clientTest,
3689 name: "VersionNegotiation-Client-" + suffix,
3690 config: Config{
3691 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003692 Bugs: ProtocolBugs{
3693 ExpectInitialRecordVersion: clientVers,
3694 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003695 },
3696 flags: flags,
3697 expectedVersion: expectedVersion,
3698 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003699 testCases = append(testCases, testCase{
3700 protocol: protocol,
3701 testType: clientTest,
3702 name: "VersionNegotiation-Client2-" + suffix,
3703 config: Config{
3704 MaxVersion: runnerVers.version,
3705 Bugs: ProtocolBugs{
3706 ExpectInitialRecordVersion: clientVers,
3707 },
3708 },
3709 flags: []string{"-max-version", shimVersFlag},
3710 expectedVersion: expectedVersion,
3711 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003712
3713 testCases = append(testCases, testCase{
3714 protocol: protocol,
3715 testType: serverTest,
3716 name: "VersionNegotiation-Server-" + suffix,
3717 config: Config{
3718 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003719 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003720 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003721 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003722 },
3723 flags: flags,
3724 expectedVersion: expectedVersion,
3725 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003726 testCases = append(testCases, testCase{
3727 protocol: protocol,
3728 testType: serverTest,
3729 name: "VersionNegotiation-Server2-" + suffix,
3730 config: Config{
3731 MaxVersion: runnerVers.version,
3732 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003733 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003734 },
3735 },
3736 flags: []string{"-max-version", shimVersFlag},
3737 expectedVersion: expectedVersion,
3738 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003739 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003740 }
3741 }
David Benjamin95c69562016-06-29 18:15:03 -04003742
3743 // Test for version tolerance.
3744 testCases = append(testCases, testCase{
3745 testType: serverTest,
3746 name: "MinorVersionTolerance",
3747 config: Config{
3748 Bugs: ProtocolBugs{
3749 SendClientVersion: 0x03ff,
3750 },
3751 },
3752 expectedVersion: VersionTLS13,
3753 })
3754 testCases = append(testCases, testCase{
3755 testType: serverTest,
3756 name: "MajorVersionTolerance",
3757 config: Config{
3758 Bugs: ProtocolBugs{
3759 SendClientVersion: 0x0400,
3760 },
3761 },
3762 expectedVersion: VersionTLS13,
3763 })
3764 testCases = append(testCases, testCase{
3765 protocol: dtls,
3766 testType: serverTest,
3767 name: "MinorVersionTolerance-DTLS",
3768 config: Config{
3769 Bugs: ProtocolBugs{
3770 SendClientVersion: 0x03ff,
3771 },
3772 },
3773 expectedVersion: VersionTLS12,
3774 })
3775 testCases = append(testCases, testCase{
3776 protocol: dtls,
3777 testType: serverTest,
3778 name: "MajorVersionTolerance-DTLS",
3779 config: Config{
3780 Bugs: ProtocolBugs{
3781 SendClientVersion: 0x0400,
3782 },
3783 },
3784 expectedVersion: VersionTLS12,
3785 })
3786
3787 // Test that versions below 3.0 are rejected.
3788 testCases = append(testCases, testCase{
3789 testType: serverTest,
3790 name: "VersionTooLow",
3791 config: Config{
3792 Bugs: ProtocolBugs{
3793 SendClientVersion: 0x0200,
3794 },
3795 },
3796 shouldFail: true,
3797 expectedError: ":UNSUPPORTED_PROTOCOL:",
3798 })
3799 testCases = append(testCases, testCase{
3800 protocol: dtls,
3801 testType: serverTest,
3802 name: "VersionTooLow-DTLS",
3803 config: Config{
3804 Bugs: ProtocolBugs{
3805 // 0x0201 is the lowest version expressable in
3806 // DTLS.
3807 SendClientVersion: 0x0201,
3808 },
3809 },
3810 shouldFail: true,
3811 expectedError: ":UNSUPPORTED_PROTOCOL:",
3812 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003813
3814 // Test TLS 1.3's downgrade signal.
3815 testCases = append(testCases, testCase{
3816 name: "Downgrade-TLS12-Client",
3817 config: Config{
3818 Bugs: ProtocolBugs{
3819 NegotiateVersion: VersionTLS12,
3820 },
3821 },
3822 shouldFail: true,
3823 expectedError: ":DOWNGRADE_DETECTED:",
3824 })
3825 testCases = append(testCases, testCase{
3826 testType: serverTest,
3827 name: "Downgrade-TLS12-Server",
3828 config: Config{
3829 Bugs: ProtocolBugs{
3830 SendClientVersion: VersionTLS12,
3831 },
3832 },
3833 shouldFail: true,
3834 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3835 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003836}
3837
David Benjaminaccb4542014-12-12 23:44:33 -05003838func addMinimumVersionTests() {
3839 for i, shimVers := range tlsVersions {
3840 // Assemble flags to disable all older versions on the shim.
3841 var flags []string
3842 for _, vers := range tlsVersions[:i] {
3843 flags = append(flags, vers.flag)
3844 }
3845
3846 for _, runnerVers := range tlsVersions {
3847 protocols := []protocol{tls}
3848 if runnerVers.hasDTLS && shimVers.hasDTLS {
3849 protocols = append(protocols, dtls)
3850 }
3851 for _, protocol := range protocols {
3852 suffix := shimVers.name + "-" + runnerVers.name
3853 if protocol == dtls {
3854 suffix += "-DTLS"
3855 }
3856 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3857
David Benjaminaccb4542014-12-12 23:44:33 -05003858 var expectedVersion uint16
3859 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003860 var expectedClientError, expectedServerError string
3861 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003862 if runnerVers.version >= shimVers.version {
3863 expectedVersion = runnerVers.version
3864 } else {
3865 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003866 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3867 expectedServerLocalError = "remote error: protocol version not supported"
3868 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3869 // If the client's minimum version is TLS 1.3 and the runner's
3870 // maximum is below TLS 1.2, the runner will fail to select a
3871 // cipher before the shim rejects the selected version.
3872 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3873 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3874 } else {
3875 expectedClientError = expectedServerError
3876 expectedClientLocalError = expectedServerLocalError
3877 }
David Benjaminaccb4542014-12-12 23:44:33 -05003878 }
3879
3880 testCases = append(testCases, testCase{
3881 protocol: protocol,
3882 testType: clientTest,
3883 name: "MinimumVersion-Client-" + suffix,
3884 config: Config{
3885 MaxVersion: runnerVers.version,
3886 },
David Benjamin87909c02014-12-13 01:55:01 -05003887 flags: flags,
3888 expectedVersion: expectedVersion,
3889 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003890 expectedError: expectedClientError,
3891 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003892 })
3893 testCases = append(testCases, testCase{
3894 protocol: protocol,
3895 testType: clientTest,
3896 name: "MinimumVersion-Client2-" + suffix,
3897 config: Config{
3898 MaxVersion: runnerVers.version,
3899 },
David Benjamin87909c02014-12-13 01:55:01 -05003900 flags: []string{"-min-version", shimVersFlag},
3901 expectedVersion: expectedVersion,
3902 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003903 expectedError: expectedClientError,
3904 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003905 })
3906
3907 testCases = append(testCases, testCase{
3908 protocol: protocol,
3909 testType: serverTest,
3910 name: "MinimumVersion-Server-" + suffix,
3911 config: Config{
3912 MaxVersion: runnerVers.version,
3913 },
David Benjamin87909c02014-12-13 01:55:01 -05003914 flags: flags,
3915 expectedVersion: expectedVersion,
3916 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003917 expectedError: expectedServerError,
3918 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003919 })
3920 testCases = append(testCases, testCase{
3921 protocol: protocol,
3922 testType: serverTest,
3923 name: "MinimumVersion-Server2-" + suffix,
3924 config: Config{
3925 MaxVersion: runnerVers.version,
3926 },
David Benjamin87909c02014-12-13 01:55:01 -05003927 flags: []string{"-min-version", shimVersFlag},
3928 expectedVersion: expectedVersion,
3929 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003930 expectedError: expectedServerError,
3931 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003932 })
3933 }
3934 }
3935 }
3936}
3937
David Benjamine78bfde2014-09-06 12:45:15 -04003938func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003939 // TODO(davidben): Extensions, where applicable, all move their server
3940 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3941 // tests for both. Also test interaction with 0-RTT when implemented.
3942
David Benjamin97d17d92016-07-14 16:12:00 -04003943 // Repeat extensions tests all versions except SSL 3.0.
3944 for _, ver := range tlsVersions {
3945 if ver.version == VersionSSL30 {
3946 continue
3947 }
3948
3949 // TODO(davidben): Implement resumption in TLS 1.3.
3950 resumeSession := ver.version < VersionTLS13
3951
3952 // Test that duplicate extensions are rejected.
3953 testCases = append(testCases, testCase{
3954 testType: clientTest,
3955 name: "DuplicateExtensionClient-" + ver.name,
3956 config: Config{
3957 MaxVersion: ver.version,
3958 Bugs: ProtocolBugs{
3959 DuplicateExtension: true,
3960 },
David Benjamine78bfde2014-09-06 12:45:15 -04003961 },
David Benjamin97d17d92016-07-14 16:12:00 -04003962 shouldFail: true,
3963 expectedLocalError: "remote error: error decoding message",
3964 })
3965 testCases = append(testCases, testCase{
3966 testType: serverTest,
3967 name: "DuplicateExtensionServer-" + ver.name,
3968 config: Config{
3969 MaxVersion: ver.version,
3970 Bugs: ProtocolBugs{
3971 DuplicateExtension: true,
3972 },
David Benjamine78bfde2014-09-06 12:45:15 -04003973 },
David Benjamin97d17d92016-07-14 16:12:00 -04003974 shouldFail: true,
3975 expectedLocalError: "remote error: error decoding message",
3976 })
3977
3978 // Test SNI.
3979 testCases = append(testCases, testCase{
3980 testType: clientTest,
3981 name: "ServerNameExtensionClient-" + ver.name,
3982 config: Config{
3983 MaxVersion: ver.version,
3984 Bugs: ProtocolBugs{
3985 ExpectServerName: "example.com",
3986 },
David Benjamine78bfde2014-09-06 12:45:15 -04003987 },
David Benjamin97d17d92016-07-14 16:12:00 -04003988 flags: []string{"-host-name", "example.com"},
3989 })
3990 testCases = append(testCases, testCase{
3991 testType: clientTest,
3992 name: "ServerNameExtensionClientMismatch-" + ver.name,
3993 config: Config{
3994 MaxVersion: ver.version,
3995 Bugs: ProtocolBugs{
3996 ExpectServerName: "mismatch.com",
3997 },
David Benjamine78bfde2014-09-06 12:45:15 -04003998 },
David Benjamin97d17d92016-07-14 16:12:00 -04003999 flags: []string{"-host-name", "example.com"},
4000 shouldFail: true,
4001 expectedLocalError: "tls: unexpected server name",
4002 })
4003 testCases = append(testCases, testCase{
4004 testType: clientTest,
4005 name: "ServerNameExtensionClientMissing-" + ver.name,
4006 config: Config{
4007 MaxVersion: ver.version,
4008 Bugs: ProtocolBugs{
4009 ExpectServerName: "missing.com",
4010 },
David Benjamine78bfde2014-09-06 12:45:15 -04004011 },
David Benjamin97d17d92016-07-14 16:12:00 -04004012 shouldFail: true,
4013 expectedLocalError: "tls: unexpected server name",
4014 })
4015 testCases = append(testCases, testCase{
4016 testType: serverTest,
4017 name: "ServerNameExtensionServer-" + ver.name,
4018 config: Config{
4019 MaxVersion: ver.version,
4020 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004021 },
David Benjamin97d17d92016-07-14 16:12:00 -04004022 flags: []string{"-expect-server-name", "example.com"},
4023 resumeSession: resumeSession,
4024 })
4025
4026 // Test ALPN.
4027 testCases = append(testCases, testCase{
4028 testType: clientTest,
4029 name: "ALPNClient-" + ver.name,
4030 config: Config{
4031 MaxVersion: ver.version,
4032 NextProtos: []string{"foo"},
4033 },
4034 flags: []string{
4035 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4036 "-expect-alpn", "foo",
4037 },
4038 expectedNextProto: "foo",
4039 expectedNextProtoType: alpn,
4040 resumeSession: resumeSession,
4041 })
4042 testCases = append(testCases, testCase{
4043 testType: serverTest,
4044 name: "ALPNServer-" + ver.name,
4045 config: Config{
4046 MaxVersion: ver.version,
4047 NextProtos: []string{"foo", "bar", "baz"},
4048 },
4049 flags: []string{
4050 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4051 "-select-alpn", "foo",
4052 },
4053 expectedNextProto: "foo",
4054 expectedNextProtoType: alpn,
4055 resumeSession: resumeSession,
4056 })
4057 testCases = append(testCases, testCase{
4058 testType: serverTest,
4059 name: "ALPNServer-Decline-" + ver.name,
4060 config: Config{
4061 MaxVersion: ver.version,
4062 NextProtos: []string{"foo", "bar", "baz"},
4063 },
4064 flags: []string{"-decline-alpn"},
4065 expectNoNextProto: true,
4066 resumeSession: resumeSession,
4067 })
4068
4069 var emptyString string
4070 testCases = append(testCases, testCase{
4071 testType: clientTest,
4072 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4073 config: Config{
4074 MaxVersion: ver.version,
4075 NextProtos: []string{""},
4076 Bugs: ProtocolBugs{
4077 // A server returning an empty ALPN protocol
4078 // should be rejected.
4079 ALPNProtocol: &emptyString,
4080 },
4081 },
4082 flags: []string{
4083 "-advertise-alpn", "\x03foo",
4084 },
4085 shouldFail: true,
4086 expectedError: ":PARSE_TLSEXT:",
4087 })
4088 testCases = append(testCases, testCase{
4089 testType: serverTest,
4090 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4091 config: Config{
4092 MaxVersion: ver.version,
4093 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004094 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004095 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004096 },
David Benjamin97d17d92016-07-14 16:12:00 -04004097 flags: []string{
4098 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004099 },
David Benjamin97d17d92016-07-14 16:12:00 -04004100 shouldFail: true,
4101 expectedError: ":PARSE_TLSEXT:",
4102 })
4103
4104 // Test NPN and the interaction with ALPN.
4105 if ver.version < VersionTLS13 {
4106 // Test that the server prefers ALPN over NPN.
4107 testCases = append(testCases, testCase{
4108 testType: serverTest,
4109 name: "ALPNServer-Preferred-" + ver.name,
4110 config: Config{
4111 MaxVersion: ver.version,
4112 NextProtos: []string{"foo", "bar", "baz"},
4113 },
4114 flags: []string{
4115 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4116 "-select-alpn", "foo",
4117 "-advertise-npn", "\x03foo\x03bar\x03baz",
4118 },
4119 expectedNextProto: "foo",
4120 expectedNextProtoType: alpn,
4121 resumeSession: resumeSession,
4122 })
4123 testCases = append(testCases, testCase{
4124 testType: serverTest,
4125 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4126 config: Config{
4127 MaxVersion: ver.version,
4128 NextProtos: []string{"foo", "bar", "baz"},
4129 Bugs: ProtocolBugs{
4130 SwapNPNAndALPN: true,
4131 },
4132 },
4133 flags: []string{
4134 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4135 "-select-alpn", "foo",
4136 "-advertise-npn", "\x03foo\x03bar\x03baz",
4137 },
4138 expectedNextProto: "foo",
4139 expectedNextProtoType: alpn,
4140 resumeSession: resumeSession,
4141 })
4142
4143 // Test that negotiating both NPN and ALPN is forbidden.
4144 testCases = append(testCases, testCase{
4145 name: "NegotiateALPNAndNPN-" + ver.name,
4146 config: Config{
4147 MaxVersion: ver.version,
4148 NextProtos: []string{"foo", "bar", "baz"},
4149 Bugs: ProtocolBugs{
4150 NegotiateALPNAndNPN: true,
4151 },
4152 },
4153 flags: []string{
4154 "-advertise-alpn", "\x03foo",
4155 "-select-next-proto", "foo",
4156 },
4157 shouldFail: true,
4158 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4159 })
4160 testCases = append(testCases, testCase{
4161 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4162 config: Config{
4163 MaxVersion: ver.version,
4164 NextProtos: []string{"foo", "bar", "baz"},
4165 Bugs: ProtocolBugs{
4166 NegotiateALPNAndNPN: true,
4167 SwapNPNAndALPN: true,
4168 },
4169 },
4170 flags: []string{
4171 "-advertise-alpn", "\x03foo",
4172 "-select-next-proto", "foo",
4173 },
4174 shouldFail: true,
4175 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4176 })
4177
4178 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4179 testCases = append(testCases, testCase{
4180 name: "DisableNPN-" + ver.name,
4181 config: Config{
4182 MaxVersion: ver.version,
4183 NextProtos: []string{"foo"},
4184 },
4185 flags: []string{
4186 "-select-next-proto", "foo",
4187 "-disable-npn",
4188 },
4189 expectNoNextProto: true,
4190 })
4191 }
4192
4193 // Test ticket behavior.
4194 //
4195 // TODO(davidben): Add TLS 1.3 versions of these.
4196 if ver.version < VersionTLS13 {
4197 // Resume with a corrupt ticket.
4198 testCases = append(testCases, testCase{
4199 testType: serverTest,
4200 name: "CorruptTicket-" + ver.name,
4201 config: Config{
4202 MaxVersion: ver.version,
4203 Bugs: ProtocolBugs{
4204 CorruptTicket: true,
4205 },
4206 },
4207 resumeSession: true,
4208 expectResumeRejected: true,
4209 })
4210 // Test the ticket callback, with and without renewal.
4211 testCases = append(testCases, testCase{
4212 testType: serverTest,
4213 name: "TicketCallback-" + ver.name,
4214 config: Config{
4215 MaxVersion: ver.version,
4216 },
4217 resumeSession: true,
4218 flags: []string{"-use-ticket-callback"},
4219 })
4220 testCases = append(testCases, testCase{
4221 testType: serverTest,
4222 name: "TicketCallback-Renew-" + ver.name,
4223 config: Config{
4224 MaxVersion: ver.version,
4225 Bugs: ProtocolBugs{
4226 ExpectNewTicket: true,
4227 },
4228 },
4229 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4230 resumeSession: true,
4231 })
4232
4233 // Resume with an oversized session id.
4234 testCases = append(testCases, testCase{
4235 testType: serverTest,
4236 name: "OversizedSessionId-" + ver.name,
4237 config: Config{
4238 MaxVersion: ver.version,
4239 Bugs: ProtocolBugs{
4240 OversizedSessionId: true,
4241 },
4242 },
4243 resumeSession: true,
4244 shouldFail: true,
4245 expectedError: ":DECODE_ERROR:",
4246 })
4247 }
4248
4249 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4250 // are ignored.
4251 if ver.hasDTLS {
4252 testCases = append(testCases, testCase{
4253 protocol: dtls,
4254 name: "SRTP-Client-" + ver.name,
4255 config: Config{
4256 MaxVersion: ver.version,
4257 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4258 },
4259 flags: []string{
4260 "-srtp-profiles",
4261 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4262 },
4263 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4264 })
4265 testCases = append(testCases, testCase{
4266 protocol: dtls,
4267 testType: serverTest,
4268 name: "SRTP-Server-" + ver.name,
4269 config: Config{
4270 MaxVersion: ver.version,
4271 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4272 },
4273 flags: []string{
4274 "-srtp-profiles",
4275 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4276 },
4277 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4278 })
4279 // Test that the MKI is ignored.
4280 testCases = append(testCases, testCase{
4281 protocol: dtls,
4282 testType: serverTest,
4283 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4284 config: Config{
4285 MaxVersion: ver.version,
4286 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4287 Bugs: ProtocolBugs{
4288 SRTPMasterKeyIdentifer: "bogus",
4289 },
4290 },
4291 flags: []string{
4292 "-srtp-profiles",
4293 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4294 },
4295 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4296 })
4297 // Test that SRTP isn't negotiated on the server if there were
4298 // no matching profiles.
4299 testCases = append(testCases, testCase{
4300 protocol: dtls,
4301 testType: serverTest,
4302 name: "SRTP-Server-NoMatch-" + ver.name,
4303 config: Config{
4304 MaxVersion: ver.version,
4305 SRTPProtectionProfiles: []uint16{100, 101, 102},
4306 },
4307 flags: []string{
4308 "-srtp-profiles",
4309 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4310 },
4311 expectedSRTPProtectionProfile: 0,
4312 })
4313 // Test that the server returning an invalid SRTP profile is
4314 // flagged as an error by the client.
4315 testCases = append(testCases, testCase{
4316 protocol: dtls,
4317 name: "SRTP-Client-NoMatch-" + ver.name,
4318 config: Config{
4319 MaxVersion: ver.version,
4320 Bugs: ProtocolBugs{
4321 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4322 },
4323 },
4324 flags: []string{
4325 "-srtp-profiles",
4326 "SRTP_AES128_CM_SHA1_80",
4327 },
4328 shouldFail: true,
4329 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4330 })
4331 }
4332
4333 // Test SCT list.
4334 testCases = append(testCases, testCase{
4335 name: "SignedCertificateTimestampList-Client-" + ver.name,
4336 testType: clientTest,
4337 config: Config{
4338 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004339 },
David Benjamin97d17d92016-07-14 16:12:00 -04004340 flags: []string{
4341 "-enable-signed-cert-timestamps",
4342 "-expect-signed-cert-timestamps",
4343 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004344 },
David Benjamin97d17d92016-07-14 16:12:00 -04004345 resumeSession: resumeSession,
4346 })
4347 testCases = append(testCases, testCase{
4348 name: "SendSCTListOnResume-" + ver.name,
4349 config: Config{
4350 MaxVersion: ver.version,
4351 Bugs: ProtocolBugs{
4352 SendSCTListOnResume: []byte("bogus"),
4353 },
David Benjamind98452d2015-06-16 14:16:23 -04004354 },
David Benjamin97d17d92016-07-14 16:12:00 -04004355 flags: []string{
4356 "-enable-signed-cert-timestamps",
4357 "-expect-signed-cert-timestamps",
4358 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004359 },
David Benjamin97d17d92016-07-14 16:12:00 -04004360 resumeSession: resumeSession,
4361 })
4362 testCases = append(testCases, testCase{
4363 name: "SignedCertificateTimestampList-Server-" + ver.name,
4364 testType: serverTest,
4365 config: Config{
4366 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004367 },
David Benjamin97d17d92016-07-14 16:12:00 -04004368 flags: []string{
4369 "-signed-cert-timestamps",
4370 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004371 },
David Benjamin97d17d92016-07-14 16:12:00 -04004372 expectedSCTList: testSCTList,
4373 resumeSession: resumeSession,
4374 })
4375 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004376
Paul Lietar4fac72e2015-09-09 13:44:55 +01004377 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004378 testType: clientTest,
4379 name: "ClientHelloPadding",
4380 config: Config{
4381 Bugs: ProtocolBugs{
4382 RequireClientHelloSize: 512,
4383 },
4384 },
4385 // This hostname just needs to be long enough to push the
4386 // ClientHello into F5's danger zone between 256 and 511 bytes
4387 // long.
4388 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4389 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004390
4391 // Extensions should not function in SSL 3.0.
4392 testCases = append(testCases, testCase{
4393 testType: serverTest,
4394 name: "SSLv3Extensions-NoALPN",
4395 config: Config{
4396 MaxVersion: VersionSSL30,
4397 NextProtos: []string{"foo", "bar", "baz"},
4398 },
4399 flags: []string{
4400 "-select-alpn", "foo",
4401 },
4402 expectNoNextProto: true,
4403 })
4404
4405 // Test session tickets separately as they follow a different codepath.
4406 testCases = append(testCases, testCase{
4407 testType: serverTest,
4408 name: "SSLv3Extensions-NoTickets",
4409 config: Config{
4410 MaxVersion: VersionSSL30,
4411 Bugs: ProtocolBugs{
4412 // Historically, session tickets in SSL 3.0
4413 // failed in different ways depending on whether
4414 // the client supported renegotiation_info.
4415 NoRenegotiationInfo: true,
4416 },
4417 },
4418 resumeSession: true,
4419 })
4420 testCases = append(testCases, testCase{
4421 testType: serverTest,
4422 name: "SSLv3Extensions-NoTickets2",
4423 config: Config{
4424 MaxVersion: VersionSSL30,
4425 },
4426 resumeSession: true,
4427 })
4428
4429 // But SSL 3.0 does send and process renegotiation_info.
4430 testCases = append(testCases, testCase{
4431 testType: serverTest,
4432 name: "SSLv3Extensions-RenegotiationInfo",
4433 config: Config{
4434 MaxVersion: VersionSSL30,
4435 Bugs: ProtocolBugs{
4436 RequireRenegotiationInfo: true,
4437 },
4438 },
4439 })
4440 testCases = append(testCases, testCase{
4441 testType: serverTest,
4442 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4443 config: Config{
4444 MaxVersion: VersionSSL30,
4445 Bugs: ProtocolBugs{
4446 NoRenegotiationInfo: true,
4447 SendRenegotiationSCSV: true,
4448 RequireRenegotiationInfo: true,
4449 },
4450 },
4451 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004452
4453 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4454 // in ServerHello.
4455 testCases = append(testCases, testCase{
4456 name: "NPN-Forbidden-TLS13",
4457 config: Config{
4458 MaxVersion: VersionTLS13,
4459 NextProtos: []string{"foo"},
4460 Bugs: ProtocolBugs{
4461 NegotiateNPNAtAllVersions: true,
4462 },
4463 },
4464 flags: []string{"-select-next-proto", "foo"},
4465 shouldFail: true,
4466 expectedError: ":ERROR_PARSING_EXTENSION:",
4467 })
4468 testCases = append(testCases, testCase{
4469 name: "EMS-Forbidden-TLS13",
4470 config: Config{
4471 MaxVersion: VersionTLS13,
4472 Bugs: ProtocolBugs{
4473 NegotiateEMSAtAllVersions: true,
4474 },
4475 },
4476 shouldFail: true,
4477 expectedError: ":ERROR_PARSING_EXTENSION:",
4478 })
4479 testCases = append(testCases, testCase{
4480 name: "RenegotiationInfo-Forbidden-TLS13",
4481 config: Config{
4482 MaxVersion: VersionTLS13,
4483 Bugs: ProtocolBugs{
4484 NegotiateRenegotiationInfoAtAllVersions: true,
4485 },
4486 },
4487 shouldFail: true,
4488 expectedError: ":ERROR_PARSING_EXTENSION:",
4489 })
4490 testCases = append(testCases, testCase{
4491 name: "ChannelID-Forbidden-TLS13",
4492 config: Config{
4493 MaxVersion: VersionTLS13,
4494 RequestChannelID: true,
4495 Bugs: ProtocolBugs{
4496 NegotiateChannelIDAtAllVersions: true,
4497 },
4498 },
4499 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4500 shouldFail: true,
4501 expectedError: ":ERROR_PARSING_EXTENSION:",
4502 })
4503 testCases = append(testCases, testCase{
4504 name: "Ticket-Forbidden-TLS13",
4505 config: Config{
4506 MaxVersion: VersionTLS12,
4507 },
4508 resumeConfig: &Config{
4509 MaxVersion: VersionTLS13,
4510 Bugs: ProtocolBugs{
4511 AdvertiseTicketExtension: true,
4512 },
4513 },
4514 resumeSession: true,
4515 shouldFail: true,
4516 expectedError: ":ERROR_PARSING_EXTENSION:",
4517 })
4518
4519 // Test that illegal extensions in TLS 1.3 are declined by the server if
4520 // offered in ClientHello. The runner's server will fail if this occurs,
4521 // so we exercise the offering path. (EMS and Renegotiation Info are
4522 // implicit in every test.)
4523 testCases = append(testCases, testCase{
4524 testType: serverTest,
4525 name: "ChannelID-Declined-TLS13",
4526 config: Config{
4527 MaxVersion: VersionTLS13,
4528 ChannelID: channelIDKey,
4529 },
4530 flags: []string{"-enable-channel-id"},
4531 })
4532 testCases = append(testCases, testCase{
4533 testType: serverTest,
4534 name: "NPN-Server",
4535 config: Config{
4536 MaxVersion: VersionTLS13,
4537 NextProtos: []string{"bar"},
4538 },
4539 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4540 })
David Benjamine78bfde2014-09-06 12:45:15 -04004541}
4542
David Benjamin01fe8202014-09-24 15:21:44 -04004543func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004544 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004545 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4546 if sessionVers.version >= VersionTLS13 {
4547 continue
4548 }
David Benjamin01fe8202014-09-24 15:21:44 -04004549 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004550 if resumeVers.version >= VersionTLS13 {
4551 continue
4552 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004553 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4554 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4555 // TLS 1.3 only shares ciphers with TLS 1.2, so
4556 // we skip certain combinations and use a
4557 // different cipher to test with.
4558 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4559 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4560 continue
4561 }
4562 }
4563
David Benjamin8b8c0062014-11-23 02:47:52 -05004564 protocols := []protocol{tls}
4565 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4566 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004567 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004568 for _, protocol := range protocols {
4569 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4570 if protocol == dtls {
4571 suffix += "-DTLS"
4572 }
4573
David Benjaminece3de92015-03-16 18:02:20 -04004574 if sessionVers.version == resumeVers.version {
4575 testCases = append(testCases, testCase{
4576 protocol: protocol,
4577 name: "Resume-Client" + suffix,
4578 resumeSession: true,
4579 config: Config{
4580 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004581 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004582 },
David Benjaminece3de92015-03-16 18:02:20 -04004583 expectedVersion: sessionVers.version,
4584 expectedResumeVersion: resumeVers.version,
4585 })
4586 } else {
4587 testCases = append(testCases, testCase{
4588 protocol: protocol,
4589 name: "Resume-Client-Mismatch" + suffix,
4590 resumeSession: true,
4591 config: Config{
4592 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004593 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004594 },
David Benjaminece3de92015-03-16 18:02:20 -04004595 expectedVersion: sessionVers.version,
4596 resumeConfig: &Config{
4597 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004598 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004599 Bugs: ProtocolBugs{
4600 AllowSessionVersionMismatch: true,
4601 },
4602 },
4603 expectedResumeVersion: resumeVers.version,
4604 shouldFail: true,
4605 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4606 })
4607 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004608
4609 testCases = append(testCases, testCase{
4610 protocol: protocol,
4611 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004612 resumeSession: true,
4613 config: Config{
4614 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004615 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004616 },
4617 expectedVersion: sessionVers.version,
4618 resumeConfig: &Config{
4619 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004620 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004621 },
4622 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004623 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004624 expectedResumeVersion: resumeVers.version,
4625 })
4626
David Benjamin8b8c0062014-11-23 02:47:52 -05004627 testCases = append(testCases, testCase{
4628 protocol: protocol,
4629 testType: serverTest,
4630 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004631 resumeSession: true,
4632 config: Config{
4633 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004634 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004635 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004636 expectedVersion: sessionVers.version,
4637 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004638 resumeConfig: &Config{
4639 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004640 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004641 },
4642 expectedResumeVersion: resumeVers.version,
4643 })
4644 }
David Benjamin01fe8202014-09-24 15:21:44 -04004645 }
4646 }
David Benjaminece3de92015-03-16 18:02:20 -04004647
Nick Harper1fd39d82016-06-14 18:14:35 -07004648 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004649 testCases = append(testCases, testCase{
4650 name: "Resume-Client-CipherMismatch",
4651 resumeSession: true,
4652 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004653 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004654 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4655 },
4656 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004657 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004658 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4659 Bugs: ProtocolBugs{
4660 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4661 },
4662 },
4663 shouldFail: true,
4664 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4665 })
David Benjamin01fe8202014-09-24 15:21:44 -04004666}
4667
Adam Langley2ae77d22014-10-28 17:29:33 -07004668func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004669 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004670 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004671 testType: serverTest,
4672 name: "Renegotiate-Server-Forbidden",
4673 config: Config{
4674 MaxVersion: VersionTLS12,
4675 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004676 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004677 shouldFail: true,
4678 expectedError: ":NO_RENEGOTIATION:",
4679 expectedLocalError: "remote error: no renegotiation",
4680 })
Adam Langley5021b222015-06-12 18:27:58 -07004681 // The server shouldn't echo the renegotiation extension unless
4682 // requested by the client.
4683 testCases = append(testCases, testCase{
4684 testType: serverTest,
4685 name: "Renegotiate-Server-NoExt",
4686 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004687 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004688 Bugs: ProtocolBugs{
4689 NoRenegotiationInfo: true,
4690 RequireRenegotiationInfo: true,
4691 },
4692 },
4693 shouldFail: true,
4694 expectedLocalError: "renegotiation extension missing",
4695 })
4696 // The renegotiation SCSV should be sufficient for the server to echo
4697 // the extension.
4698 testCases = append(testCases, testCase{
4699 testType: serverTest,
4700 name: "Renegotiate-Server-NoExt-SCSV",
4701 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004702 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004703 Bugs: ProtocolBugs{
4704 NoRenegotiationInfo: true,
4705 SendRenegotiationSCSV: true,
4706 RequireRenegotiationInfo: true,
4707 },
4708 },
4709 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004710 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004711 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004712 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004713 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004714 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004715 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004716 },
4717 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004718 renegotiate: 1,
4719 flags: []string{
4720 "-renegotiate-freely",
4721 "-expect-total-renegotiations", "1",
4722 },
David Benjamincdea40c2015-03-19 14:09:43 -04004723 })
4724 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004725 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004726 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004728 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004729 Bugs: ProtocolBugs{
4730 EmptyRenegotiationInfo: true,
4731 },
4732 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004733 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004734 shouldFail: true,
4735 expectedError: ":RENEGOTIATION_MISMATCH:",
4736 })
4737 testCases = append(testCases, testCase{
4738 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004739 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004740 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004741 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004742 Bugs: ProtocolBugs{
4743 BadRenegotiationInfo: true,
4744 },
4745 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004746 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004747 shouldFail: true,
4748 expectedError: ":RENEGOTIATION_MISMATCH:",
4749 })
4750 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004751 name: "Renegotiate-Client-Downgrade",
4752 renegotiate: 1,
4753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004754 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004755 Bugs: ProtocolBugs{
4756 NoRenegotiationInfoAfterInitial: true,
4757 },
4758 },
4759 flags: []string{"-renegotiate-freely"},
4760 shouldFail: true,
4761 expectedError: ":RENEGOTIATION_MISMATCH:",
4762 })
4763 testCases = append(testCases, testCase{
4764 name: "Renegotiate-Client-Upgrade",
4765 renegotiate: 1,
4766 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004767 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004768 Bugs: ProtocolBugs{
4769 NoRenegotiationInfoInInitial: true,
4770 },
4771 },
4772 flags: []string{"-renegotiate-freely"},
4773 shouldFail: true,
4774 expectedError: ":RENEGOTIATION_MISMATCH:",
4775 })
4776 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004777 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004778 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004780 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004781 Bugs: ProtocolBugs{
4782 NoRenegotiationInfo: true,
4783 },
4784 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004785 flags: []string{
4786 "-renegotiate-freely",
4787 "-expect-total-renegotiations", "1",
4788 },
David Benjamincff0b902015-05-15 23:09:47 -04004789 })
4790 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004791 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004792 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004793 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004794 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004795 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4796 },
4797 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004798 flags: []string{
4799 "-renegotiate-freely",
4800 "-expect-total-renegotiations", "1",
4801 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004802 })
4803 testCases = append(testCases, testCase{
4804 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004805 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004806 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004807 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004808 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4809 },
4810 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004811 flags: []string{
4812 "-renegotiate-freely",
4813 "-expect-total-renegotiations", "1",
4814 },
David Benjaminb16346b2015-04-08 19:16:58 -04004815 })
4816 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004817 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004818 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004819 config: Config{
4820 MaxVersion: VersionTLS10,
4821 Bugs: ProtocolBugs{
4822 RequireSameRenegoClientVersion: true,
4823 },
4824 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004825 flags: []string{
4826 "-renegotiate-freely",
4827 "-expect-total-renegotiations", "1",
4828 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004829 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004830 testCases = append(testCases, testCase{
4831 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004832 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004833 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004834 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4836 NextProtos: []string{"foo"},
4837 },
4838 flags: []string{
4839 "-false-start",
4840 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004841 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004842 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004843 },
4844 shimWritesFirst: true,
4845 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004846
4847 // Client-side renegotiation controls.
4848 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004849 name: "Renegotiate-Client-Forbidden-1",
4850 config: Config{
4851 MaxVersion: VersionTLS12,
4852 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004853 renegotiate: 1,
4854 shouldFail: true,
4855 expectedError: ":NO_RENEGOTIATION:",
4856 expectedLocalError: "remote error: no renegotiation",
4857 })
4858 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004859 name: "Renegotiate-Client-Once-1",
4860 config: Config{
4861 MaxVersion: VersionTLS12,
4862 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004863 renegotiate: 1,
4864 flags: []string{
4865 "-renegotiate-once",
4866 "-expect-total-renegotiations", "1",
4867 },
4868 })
4869 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004870 name: "Renegotiate-Client-Freely-1",
4871 config: Config{
4872 MaxVersion: VersionTLS12,
4873 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004874 renegotiate: 1,
4875 flags: []string{
4876 "-renegotiate-freely",
4877 "-expect-total-renegotiations", "1",
4878 },
4879 })
4880 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004881 name: "Renegotiate-Client-Once-2",
4882 config: Config{
4883 MaxVersion: VersionTLS12,
4884 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004885 renegotiate: 2,
4886 flags: []string{"-renegotiate-once"},
4887 shouldFail: true,
4888 expectedError: ":NO_RENEGOTIATION:",
4889 expectedLocalError: "remote error: no renegotiation",
4890 })
4891 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004892 name: "Renegotiate-Client-Freely-2",
4893 config: Config{
4894 MaxVersion: VersionTLS12,
4895 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004896 renegotiate: 2,
4897 flags: []string{
4898 "-renegotiate-freely",
4899 "-expect-total-renegotiations", "2",
4900 },
4901 })
Adam Langley27a0d082015-11-03 13:34:10 -08004902 testCases = append(testCases, testCase{
4903 name: "Renegotiate-Client-NoIgnore",
4904 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004905 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004906 Bugs: ProtocolBugs{
4907 SendHelloRequestBeforeEveryAppDataRecord: true,
4908 },
4909 },
4910 shouldFail: true,
4911 expectedError: ":NO_RENEGOTIATION:",
4912 })
4913 testCases = append(testCases, testCase{
4914 name: "Renegotiate-Client-Ignore",
4915 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004916 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004917 Bugs: ProtocolBugs{
4918 SendHelloRequestBeforeEveryAppDataRecord: true,
4919 },
4920 },
4921 flags: []string{
4922 "-renegotiate-ignore",
4923 "-expect-total-renegotiations", "0",
4924 },
4925 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004926
David Benjamin397c8e62016-07-08 14:14:36 -07004927 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004928 testCases = append(testCases, testCase{
4929 name: "StrayHelloRequest",
4930 config: Config{
4931 MaxVersion: VersionTLS12,
4932 Bugs: ProtocolBugs{
4933 SendHelloRequestBeforeEveryHandshakeMessage: true,
4934 },
4935 },
4936 })
4937 testCases = append(testCases, testCase{
4938 name: "StrayHelloRequest-Packed",
4939 config: Config{
4940 MaxVersion: VersionTLS12,
4941 Bugs: ProtocolBugs{
4942 PackHandshakeFlight: true,
4943 SendHelloRequestBeforeEveryHandshakeMessage: true,
4944 },
4945 },
4946 })
4947
David Benjamin397c8e62016-07-08 14:14:36 -07004948 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04004949 //
4950 // TODO(davidben): This test current asserts that we ignore
4951 // HelloRequests, but we actually should hard reject them. Fix this
4952 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07004953 testCases = append(testCases, testCase{
4954 name: "Renegotiate-Client-TLS13",
4955 config: Config{
4956 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04004957 Bugs: ProtocolBugs{
4958 SendHelloRequestBeforeEveryAppDataRecord: true,
4959 },
David Benjamin397c8e62016-07-08 14:14:36 -07004960 },
David Benjamin397c8e62016-07-08 14:14:36 -07004961 flags: []string{
4962 "-renegotiate-freely",
4963 },
David Benjamin397c8e62016-07-08 14:14:36 -07004964 })
4965
4966 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4967 testCases = append(testCases, testCase{
4968 name: "StrayHelloRequest-TLS13",
4969 config: Config{
4970 MaxVersion: VersionTLS13,
4971 Bugs: ProtocolBugs{
4972 SendHelloRequestBeforeEveryHandshakeMessage: true,
4973 },
4974 },
4975 shouldFail: true,
4976 expectedError: ":UNEXPECTED_MESSAGE:",
4977 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004978}
4979
David Benjamin5e961c12014-11-07 01:48:35 -05004980func addDTLSReplayTests() {
4981 // Test that sequence number replays are detected.
4982 testCases = append(testCases, testCase{
4983 protocol: dtls,
4984 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004985 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004986 replayWrites: true,
4987 })
4988
David Benjamin8e6db492015-07-25 18:29:23 -04004989 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004990 // than the retransmit window.
4991 testCases = append(testCases, testCase{
4992 protocol: dtls,
4993 name: "DTLS-Replay-LargeGaps",
4994 config: Config{
4995 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004996 SequenceNumberMapping: func(in uint64) uint64 {
4997 return in * 127
4998 },
David Benjamin5e961c12014-11-07 01:48:35 -05004999 },
5000 },
David Benjamin8e6db492015-07-25 18:29:23 -04005001 messageCount: 200,
5002 replayWrites: true,
5003 })
5004
5005 // Test the incoming sequence number changing non-monotonically.
5006 testCases = append(testCases, testCase{
5007 protocol: dtls,
5008 name: "DTLS-Replay-NonMonotonic",
5009 config: Config{
5010 Bugs: ProtocolBugs{
5011 SequenceNumberMapping: func(in uint64) uint64 {
5012 return in ^ 31
5013 },
5014 },
5015 },
5016 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005017 replayWrites: true,
5018 })
5019}
5020
Nick Harper60edffd2016-06-21 15:19:24 -07005021var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005022 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005023 id signatureAlgorithm
5024 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005025}{
Nick Harper60edffd2016-06-21 15:19:24 -07005026 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5027 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5028 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5029 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005030 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005031 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5032 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5033 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005034 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5035 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5036 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005037 // Tests for key types prior to TLS 1.2.
5038 {"RSA", 0, testCertRSA},
5039 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005040}
5041
Nick Harper60edffd2016-06-21 15:19:24 -07005042const fakeSigAlg1 signatureAlgorithm = 0x2a01
5043const fakeSigAlg2 signatureAlgorithm = 0xff01
5044
5045func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005046 // Not all ciphers involve a signature. Advertise a list which gives all
5047 // versions a signing cipher.
5048 signingCiphers := []uint16{
5049 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5050 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5051 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5052 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5053 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5054 }
5055
David Benjaminca3d5452016-07-14 12:51:01 -04005056 var allAlgorithms []signatureAlgorithm
5057 for _, alg := range testSignatureAlgorithms {
5058 if alg.id != 0 {
5059 allAlgorithms = append(allAlgorithms, alg.id)
5060 }
5061 }
5062
Nick Harper60edffd2016-06-21 15:19:24 -07005063 // Make sure each signature algorithm works. Include some fake values in
5064 // the list and ensure they're ignored.
5065 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005066 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005067 if (ver.version < VersionTLS12) != (alg.id == 0) {
5068 continue
5069 }
5070
5071 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5072 // or remove it in C.
5073 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005074 continue
5075 }
Nick Harper60edffd2016-06-21 15:19:24 -07005076
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005077 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005078 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005079 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5080 shouldFail = true
5081 }
5082 // RSA-PSS does not exist in TLS 1.2.
5083 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5084 shouldFail = true
5085 }
5086
5087 var signError, verifyError string
5088 if shouldFail {
5089 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5090 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005091 }
David Benjamin000800a2014-11-14 01:43:59 -05005092
David Benjamin1fb125c2016-07-08 18:52:12 -07005093 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005094
David Benjamin7a41d372016-07-09 11:21:54 -07005095 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005096 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005097 config: Config{
5098 MaxVersion: ver.version,
5099 ClientAuth: RequireAnyClientCert,
5100 VerifySignatureAlgorithms: []signatureAlgorithm{
5101 fakeSigAlg1,
5102 alg.id,
5103 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005104 },
David Benjamin7a41d372016-07-09 11:21:54 -07005105 },
5106 flags: []string{
5107 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5108 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5109 "-enable-all-curves",
5110 },
5111 shouldFail: shouldFail,
5112 expectedError: signError,
5113 expectedPeerSignatureAlgorithm: alg.id,
5114 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005115
David Benjamin7a41d372016-07-09 11:21:54 -07005116 testCases = append(testCases, testCase{
5117 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005118 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005119 config: Config{
5120 MaxVersion: ver.version,
5121 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5122 SignSignatureAlgorithms: []signatureAlgorithm{
5123 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005124 },
David Benjamin7a41d372016-07-09 11:21:54 -07005125 Bugs: ProtocolBugs{
5126 SkipECDSACurveCheck: shouldFail,
5127 IgnoreSignatureVersionChecks: shouldFail,
5128 // The client won't advertise 1.3-only algorithms after
5129 // version negotiation.
5130 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005131 },
David Benjamin7a41d372016-07-09 11:21:54 -07005132 },
5133 flags: []string{
5134 "-require-any-client-certificate",
5135 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5136 "-enable-all-curves",
5137 },
5138 shouldFail: shouldFail,
5139 expectedError: verifyError,
5140 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005141
5142 testCases = append(testCases, testCase{
5143 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005144 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005145 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005146 MaxVersion: ver.version,
5147 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005148 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005149 fakeSigAlg1,
5150 alg.id,
5151 fakeSigAlg2,
5152 },
5153 },
5154 flags: []string{
5155 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5156 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5157 "-enable-all-curves",
5158 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005159 shouldFail: shouldFail,
5160 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005161 expectedPeerSignatureAlgorithm: alg.id,
5162 })
5163
5164 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005165 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005166 config: Config{
5167 MaxVersion: ver.version,
5168 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005169 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005170 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005171 alg.id,
5172 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005173 Bugs: ProtocolBugs{
5174 SkipECDSACurveCheck: shouldFail,
5175 IgnoreSignatureVersionChecks: shouldFail,
5176 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005177 },
5178 flags: []string{
5179 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5180 "-enable-all-curves",
5181 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005182 shouldFail: shouldFail,
5183 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005184 })
David Benjamin5208fd42016-07-13 21:43:25 -04005185
5186 if !shouldFail {
5187 testCases = append(testCases, testCase{
5188 testType: serverTest,
5189 name: "ClientAuth-InvalidSignature" + suffix,
5190 config: Config{
5191 MaxVersion: ver.version,
5192 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5193 SignSignatureAlgorithms: []signatureAlgorithm{
5194 alg.id,
5195 },
5196 Bugs: ProtocolBugs{
5197 InvalidSignature: true,
5198 },
5199 },
5200 flags: []string{
5201 "-require-any-client-certificate",
5202 "-enable-all-curves",
5203 },
5204 shouldFail: true,
5205 expectedError: ":BAD_SIGNATURE:",
5206 })
5207
5208 testCases = append(testCases, testCase{
5209 name: "ServerAuth-InvalidSignature" + suffix,
5210 config: Config{
5211 MaxVersion: ver.version,
5212 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5213 CipherSuites: signingCiphers,
5214 SignSignatureAlgorithms: []signatureAlgorithm{
5215 alg.id,
5216 },
5217 Bugs: ProtocolBugs{
5218 InvalidSignature: true,
5219 },
5220 },
5221 flags: []string{"-enable-all-curves"},
5222 shouldFail: true,
5223 expectedError: ":BAD_SIGNATURE:",
5224 })
5225 }
David Benjaminca3d5452016-07-14 12:51:01 -04005226
5227 if ver.version >= VersionTLS12 && !shouldFail {
5228 testCases = append(testCases, testCase{
5229 name: "ClientAuth-Sign-Negotiate" + suffix,
5230 config: Config{
5231 MaxVersion: ver.version,
5232 ClientAuth: RequireAnyClientCert,
5233 VerifySignatureAlgorithms: allAlgorithms,
5234 },
5235 flags: []string{
5236 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5237 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5238 "-enable-all-curves",
5239 "-signing-prefs", strconv.Itoa(int(alg.id)),
5240 },
5241 expectedPeerSignatureAlgorithm: alg.id,
5242 })
5243
5244 testCases = append(testCases, testCase{
5245 testType: serverTest,
5246 name: "ServerAuth-Sign-Negotiate" + suffix,
5247 config: Config{
5248 MaxVersion: ver.version,
5249 CipherSuites: signingCiphers,
5250 VerifySignatureAlgorithms: allAlgorithms,
5251 },
5252 flags: []string{
5253 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5254 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5255 "-enable-all-curves",
5256 "-signing-prefs", strconv.Itoa(int(alg.id)),
5257 },
5258 expectedPeerSignatureAlgorithm: alg.id,
5259 })
5260 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005261 }
David Benjamin000800a2014-11-14 01:43:59 -05005262 }
5263
Nick Harper60edffd2016-06-21 15:19:24 -07005264 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005265 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005266 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005267 config: Config{
5268 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005269 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005270 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005271 signatureECDSAWithP521AndSHA512,
5272 signatureRSAPKCS1WithSHA384,
5273 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005274 },
5275 },
5276 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005277 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5278 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005279 },
Nick Harper60edffd2016-06-21 15:19:24 -07005280 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005281 })
5282
5283 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005284 name: "ClientAuth-SignatureType-TLS13",
5285 config: Config{
5286 ClientAuth: RequireAnyClientCert,
5287 MaxVersion: VersionTLS13,
5288 VerifySignatureAlgorithms: []signatureAlgorithm{
5289 signatureECDSAWithP521AndSHA512,
5290 signatureRSAPKCS1WithSHA384,
5291 signatureRSAPSSWithSHA384,
5292 signatureECDSAWithSHA1,
5293 },
5294 },
5295 flags: []string{
5296 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5297 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5298 },
5299 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5300 })
5301
5302 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005303 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005304 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005306 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005307 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005308 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005309 signatureECDSAWithP521AndSHA512,
5310 signatureRSAPKCS1WithSHA384,
5311 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005312 },
5313 },
Nick Harper60edffd2016-06-21 15:19:24 -07005314 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005315 })
5316
Steven Valdez143e8b32016-07-11 13:19:03 -04005317 testCases = append(testCases, testCase{
5318 testType: serverTest,
5319 name: "ServerAuth-SignatureType-TLS13",
5320 config: Config{
5321 MaxVersion: VersionTLS13,
5322 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5323 VerifySignatureAlgorithms: []signatureAlgorithm{
5324 signatureECDSAWithP521AndSHA512,
5325 signatureRSAPKCS1WithSHA384,
5326 signatureRSAPSSWithSHA384,
5327 signatureECDSAWithSHA1,
5328 },
5329 },
5330 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5331 })
5332
David Benjamina95e9f32016-07-08 16:28:04 -07005333 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005334 testCases = append(testCases, testCase{
5335 testType: serverTest,
5336 name: "Verify-ClientAuth-SignatureType",
5337 config: Config{
5338 MaxVersion: VersionTLS12,
5339 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005340 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005341 signatureRSAPKCS1WithSHA256,
5342 },
5343 Bugs: ProtocolBugs{
5344 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5345 },
5346 },
5347 flags: []string{
5348 "-require-any-client-certificate",
5349 },
5350 shouldFail: true,
5351 expectedError: ":WRONG_SIGNATURE_TYPE:",
5352 })
5353
5354 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005355 testType: serverTest,
5356 name: "Verify-ClientAuth-SignatureType-TLS13",
5357 config: Config{
5358 MaxVersion: VersionTLS13,
5359 Certificates: []Certificate{rsaCertificate},
5360 SignSignatureAlgorithms: []signatureAlgorithm{
5361 signatureRSAPSSWithSHA256,
5362 },
5363 Bugs: ProtocolBugs{
5364 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5365 },
5366 },
5367 flags: []string{
5368 "-require-any-client-certificate",
5369 },
5370 shouldFail: true,
5371 expectedError: ":WRONG_SIGNATURE_TYPE:",
5372 })
5373
5374 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005375 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005376 config: Config{
5377 MaxVersion: VersionTLS12,
5378 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005379 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005380 signatureRSAPKCS1WithSHA256,
5381 },
5382 Bugs: ProtocolBugs{
5383 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5384 },
5385 },
5386 shouldFail: true,
5387 expectedError: ":WRONG_SIGNATURE_TYPE:",
5388 })
5389
Steven Valdez143e8b32016-07-11 13:19:03 -04005390 testCases = append(testCases, testCase{
5391 name: "Verify-ServerAuth-SignatureType-TLS13",
5392 config: Config{
5393 MaxVersion: VersionTLS13,
5394 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5395 SignSignatureAlgorithms: []signatureAlgorithm{
5396 signatureRSAPSSWithSHA256,
5397 },
5398 Bugs: ProtocolBugs{
5399 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5400 },
5401 },
5402 shouldFail: true,
5403 expectedError: ":WRONG_SIGNATURE_TYPE:",
5404 })
5405
David Benjamin51dd7d62016-07-08 16:07:01 -07005406 // Test that, if the list is missing, the peer falls back to SHA-1 in
5407 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005408 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005409 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005411 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005412 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005413 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005414 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005415 },
5416 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005417 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005418 },
5419 },
5420 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005421 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5422 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005423 },
5424 })
5425
5426 testCases = append(testCases, testCase{
5427 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005428 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005430 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005432 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005433 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005434 },
5435 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005436 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005437 },
5438 },
5439 })
David Benjamin72dc7832015-03-16 17:49:43 -04005440
David Benjamin51dd7d62016-07-08 16:07:01 -07005441 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005442 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005443 config: Config{
5444 MaxVersion: VersionTLS13,
5445 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005446 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005447 signatureRSAPKCS1WithSHA1,
5448 },
5449 Bugs: ProtocolBugs{
5450 NoSignatureAlgorithms: true,
5451 },
5452 },
5453 flags: []string{
5454 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5455 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5456 },
5457 shouldFail: true,
5458 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5459 })
5460
5461 testCases = append(testCases, testCase{
5462 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005463 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005464 config: Config{
5465 MaxVersion: VersionTLS13,
5466 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005467 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005468 signatureRSAPKCS1WithSHA1,
5469 },
5470 Bugs: ProtocolBugs{
5471 NoSignatureAlgorithms: true,
5472 },
5473 },
5474 shouldFail: true,
5475 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5476 })
5477
David Benjaminb62d2872016-07-18 14:55:02 +02005478 // Test that hash preferences are enforced. BoringSSL does not implement
5479 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005480 testCases = append(testCases, testCase{
5481 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005482 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005484 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005485 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005486 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005487 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005488 },
5489 Bugs: ProtocolBugs{
5490 IgnorePeerSignatureAlgorithmPreferences: true,
5491 },
5492 },
5493 flags: []string{"-require-any-client-certificate"},
5494 shouldFail: true,
5495 expectedError: ":WRONG_SIGNATURE_TYPE:",
5496 })
5497
5498 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005499 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005500 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005501 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005502 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005503 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005504 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005505 },
5506 Bugs: ProtocolBugs{
5507 IgnorePeerSignatureAlgorithmPreferences: true,
5508 },
5509 },
5510 shouldFail: true,
5511 expectedError: ":WRONG_SIGNATURE_TYPE:",
5512 })
David Benjaminb62d2872016-07-18 14:55:02 +02005513 testCases = append(testCases, testCase{
5514 testType: serverTest,
5515 name: "ClientAuth-Enforced-TLS13",
5516 config: Config{
5517 MaxVersion: VersionTLS13,
5518 Certificates: []Certificate{rsaCertificate},
5519 SignSignatureAlgorithms: []signatureAlgorithm{
5520 signatureRSAPKCS1WithMD5,
5521 },
5522 Bugs: ProtocolBugs{
5523 IgnorePeerSignatureAlgorithmPreferences: true,
5524 IgnoreSignatureVersionChecks: true,
5525 },
5526 },
5527 flags: []string{"-require-any-client-certificate"},
5528 shouldFail: true,
5529 expectedError: ":WRONG_SIGNATURE_TYPE:",
5530 })
5531
5532 testCases = append(testCases, testCase{
5533 name: "ServerAuth-Enforced-TLS13",
5534 config: Config{
5535 MaxVersion: VersionTLS13,
5536 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5537 SignSignatureAlgorithms: []signatureAlgorithm{
5538 signatureRSAPKCS1WithMD5,
5539 },
5540 Bugs: ProtocolBugs{
5541 IgnorePeerSignatureAlgorithmPreferences: true,
5542 IgnoreSignatureVersionChecks: true,
5543 },
5544 },
5545 shouldFail: true,
5546 expectedError: ":WRONG_SIGNATURE_TYPE:",
5547 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005548
5549 // Test that the agreed upon digest respects the client preferences and
5550 // the server digests.
5551 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005552 name: "NoCommonAlgorithms-Digests",
5553 config: Config{
5554 MaxVersion: VersionTLS12,
5555 ClientAuth: RequireAnyClientCert,
5556 VerifySignatureAlgorithms: []signatureAlgorithm{
5557 signatureRSAPKCS1WithSHA512,
5558 signatureRSAPKCS1WithSHA1,
5559 },
5560 },
5561 flags: []string{
5562 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5563 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5564 "-digest-prefs", "SHA256",
5565 },
5566 shouldFail: true,
5567 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5568 })
5569 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005570 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005571 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005572 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005573 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005574 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005575 signatureRSAPKCS1WithSHA512,
5576 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005577 },
5578 },
5579 flags: []string{
5580 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5581 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005582 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005583 },
David Benjaminca3d5452016-07-14 12:51:01 -04005584 shouldFail: true,
5585 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5586 })
5587 testCases = append(testCases, testCase{
5588 name: "NoCommonAlgorithms-TLS13",
5589 config: Config{
5590 MaxVersion: VersionTLS13,
5591 ClientAuth: RequireAnyClientCert,
5592 VerifySignatureAlgorithms: []signatureAlgorithm{
5593 signatureRSAPSSWithSHA512,
5594 signatureRSAPSSWithSHA384,
5595 },
5596 },
5597 flags: []string{
5598 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5599 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5600 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5601 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005602 shouldFail: true,
5603 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005604 })
5605 testCases = append(testCases, testCase{
5606 name: "Agree-Digest-SHA256",
5607 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005608 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005609 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005610 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005611 signatureRSAPKCS1WithSHA1,
5612 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005613 },
5614 },
5615 flags: []string{
5616 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5617 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005618 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005619 },
Nick Harper60edffd2016-06-21 15:19:24 -07005620 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005621 })
5622 testCases = append(testCases, testCase{
5623 name: "Agree-Digest-SHA1",
5624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005625 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005626 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005627 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005628 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005629 },
5630 },
5631 flags: []string{
5632 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5633 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005634 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005635 },
Nick Harper60edffd2016-06-21 15:19:24 -07005636 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005637 })
5638 testCases = append(testCases, testCase{
5639 name: "Agree-Digest-Default",
5640 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005641 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005642 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005643 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005644 signatureRSAPKCS1WithSHA256,
5645 signatureECDSAWithP256AndSHA256,
5646 signatureRSAPKCS1WithSHA1,
5647 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005648 },
5649 },
5650 flags: []string{
5651 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5652 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5653 },
Nick Harper60edffd2016-06-21 15:19:24 -07005654 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005655 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005656
David Benjaminca3d5452016-07-14 12:51:01 -04005657 // Test that the signing preference list may include extra algorithms
5658 // without negotiation problems.
5659 testCases = append(testCases, testCase{
5660 testType: serverTest,
5661 name: "FilterExtraAlgorithms",
5662 config: Config{
5663 MaxVersion: VersionTLS12,
5664 VerifySignatureAlgorithms: []signatureAlgorithm{
5665 signatureRSAPKCS1WithSHA256,
5666 },
5667 },
5668 flags: []string{
5669 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5670 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5671 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5672 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5673 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5674 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5675 },
5676 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5677 })
5678
David Benjamin4c3ddf72016-06-29 18:13:53 -04005679 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5680 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005681 testCases = append(testCases, testCase{
5682 name: "CheckLeafCurve",
5683 config: Config{
5684 MaxVersion: VersionTLS12,
5685 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005686 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005687 },
5688 flags: []string{"-p384-only"},
5689 shouldFail: true,
5690 expectedError: ":BAD_ECC_CERT:",
5691 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005692
5693 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5694 testCases = append(testCases, testCase{
5695 name: "CheckLeafCurve-TLS13",
5696 config: Config{
5697 MaxVersion: VersionTLS13,
5698 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5699 Certificates: []Certificate{ecdsaP256Certificate},
5700 },
5701 flags: []string{"-p384-only"},
5702 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005703
5704 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5705 testCases = append(testCases, testCase{
5706 name: "ECDSACurveMismatch-Verify-TLS12",
5707 config: Config{
5708 MaxVersion: VersionTLS12,
5709 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5710 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005711 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005712 signatureECDSAWithP384AndSHA384,
5713 },
5714 },
5715 })
5716
5717 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5718 testCases = append(testCases, testCase{
5719 name: "ECDSACurveMismatch-Verify-TLS13",
5720 config: Config{
5721 MaxVersion: VersionTLS13,
5722 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5723 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005724 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005725 signatureECDSAWithP384AndSHA384,
5726 },
5727 Bugs: ProtocolBugs{
5728 SkipECDSACurveCheck: true,
5729 },
5730 },
5731 shouldFail: true,
5732 expectedError: ":WRONG_SIGNATURE_TYPE:",
5733 })
5734
5735 // Signature algorithm selection in TLS 1.3 should take the curve into
5736 // account.
5737 testCases = append(testCases, testCase{
5738 testType: serverTest,
5739 name: "ECDSACurveMismatch-Sign-TLS13",
5740 config: Config{
5741 MaxVersion: VersionTLS13,
5742 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005743 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005744 signatureECDSAWithP384AndSHA384,
5745 signatureECDSAWithP256AndSHA256,
5746 },
5747 },
5748 flags: []string{
5749 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5750 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5751 },
5752 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5753 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005754
5755 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5756 // server does not attempt to sign in that case.
5757 testCases = append(testCases, testCase{
5758 testType: serverTest,
5759 name: "RSA-PSS-Large",
5760 config: Config{
5761 MaxVersion: VersionTLS13,
5762 VerifySignatureAlgorithms: []signatureAlgorithm{
5763 signatureRSAPSSWithSHA512,
5764 },
5765 },
5766 flags: []string{
5767 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5768 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5769 },
5770 shouldFail: true,
5771 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5772 })
David Benjamin000800a2014-11-14 01:43:59 -05005773}
5774
David Benjamin83f90402015-01-27 01:09:43 -05005775// timeouts is the retransmit schedule for BoringSSL. It doubles and
5776// caps at 60 seconds. On the 13th timeout, it gives up.
5777var timeouts = []time.Duration{
5778 1 * time.Second,
5779 2 * time.Second,
5780 4 * time.Second,
5781 8 * time.Second,
5782 16 * time.Second,
5783 32 * time.Second,
5784 60 * time.Second,
5785 60 * time.Second,
5786 60 * time.Second,
5787 60 * time.Second,
5788 60 * time.Second,
5789 60 * time.Second,
5790 60 * time.Second,
5791}
5792
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005793// shortTimeouts is an alternate set of timeouts which would occur if the
5794// initial timeout duration was set to 250ms.
5795var shortTimeouts = []time.Duration{
5796 250 * time.Millisecond,
5797 500 * time.Millisecond,
5798 1 * time.Second,
5799 2 * time.Second,
5800 4 * time.Second,
5801 8 * time.Second,
5802 16 * time.Second,
5803 32 * time.Second,
5804 60 * time.Second,
5805 60 * time.Second,
5806 60 * time.Second,
5807 60 * time.Second,
5808 60 * time.Second,
5809}
5810
David Benjamin83f90402015-01-27 01:09:43 -05005811func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005812 // These tests work by coordinating some behavior on both the shim and
5813 // the runner.
5814 //
5815 // TimeoutSchedule configures the runner to send a series of timeout
5816 // opcodes to the shim (see packetAdaptor) immediately before reading
5817 // each peer handshake flight N. The timeout opcode both simulates a
5818 // timeout in the shim and acts as a synchronization point to help the
5819 // runner bracket each handshake flight.
5820 //
5821 // We assume the shim does not read from the channel eagerly. It must
5822 // first wait until it has sent flight N and is ready to receive
5823 // handshake flight N+1. At this point, it will process the timeout
5824 // opcode. It must then immediately respond with a timeout ACK and act
5825 // as if the shim was idle for the specified amount of time.
5826 //
5827 // The runner then drops all packets received before the ACK and
5828 // continues waiting for flight N. This ordering results in one attempt
5829 // at sending flight N to be dropped. For the test to complete, the
5830 // shim must send flight N again, testing that the shim implements DTLS
5831 // retransmit on a timeout.
5832
Steven Valdez143e8b32016-07-11 13:19:03 -04005833 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04005834 // likely be more epochs to cross and the final message's retransmit may
5835 // be more complex.
5836
David Benjamin585d7a42016-06-02 14:58:00 -04005837 for _, async := range []bool{true, false} {
5838 var tests []testCase
5839
5840 // Test that this is indeed the timeout schedule. Stress all
5841 // four patterns of handshake.
5842 for i := 1; i < len(timeouts); i++ {
5843 number := strconv.Itoa(i)
5844 tests = append(tests, testCase{
5845 protocol: dtls,
5846 name: "DTLS-Retransmit-Client-" + number,
5847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005848 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005849 Bugs: ProtocolBugs{
5850 TimeoutSchedule: timeouts[:i],
5851 },
5852 },
5853 resumeSession: true,
5854 })
5855 tests = append(tests, testCase{
5856 protocol: dtls,
5857 testType: serverTest,
5858 name: "DTLS-Retransmit-Server-" + number,
5859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005860 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005861 Bugs: ProtocolBugs{
5862 TimeoutSchedule: timeouts[:i],
5863 },
5864 },
5865 resumeSession: true,
5866 })
5867 }
5868
5869 // Test that exceeding the timeout schedule hits a read
5870 // timeout.
5871 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005872 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005873 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005875 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005876 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005877 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005878 },
5879 },
5880 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005881 shouldFail: true,
5882 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005883 })
David Benjamin585d7a42016-06-02 14:58:00 -04005884
5885 if async {
5886 // Test that timeout handling has a fudge factor, due to API
5887 // problems.
5888 tests = append(tests, testCase{
5889 protocol: dtls,
5890 name: "DTLS-Retransmit-Fudge",
5891 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005892 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005893 Bugs: ProtocolBugs{
5894 TimeoutSchedule: []time.Duration{
5895 timeouts[0] - 10*time.Millisecond,
5896 },
5897 },
5898 },
5899 resumeSession: true,
5900 })
5901 }
5902
5903 // Test that the final Finished retransmitting isn't
5904 // duplicated if the peer badly fragments everything.
5905 tests = append(tests, testCase{
5906 testType: serverTest,
5907 protocol: dtls,
5908 name: "DTLS-Retransmit-Fragmented",
5909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005910 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005911 Bugs: ProtocolBugs{
5912 TimeoutSchedule: []time.Duration{timeouts[0]},
5913 MaxHandshakeRecordLength: 2,
5914 },
5915 },
5916 })
5917
5918 // Test the timeout schedule when a shorter initial timeout duration is set.
5919 tests = append(tests, testCase{
5920 protocol: dtls,
5921 name: "DTLS-Retransmit-Short-Client",
5922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005923 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005924 Bugs: ProtocolBugs{
5925 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5926 },
5927 },
5928 resumeSession: true,
5929 flags: []string{"-initial-timeout-duration-ms", "250"},
5930 })
5931 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005932 protocol: dtls,
5933 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005934 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005935 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005936 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005937 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005938 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005939 },
5940 },
5941 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005942 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005943 })
David Benjamin585d7a42016-06-02 14:58:00 -04005944
5945 for _, test := range tests {
5946 if async {
5947 test.name += "-Async"
5948 test.flags = append(test.flags, "-async")
5949 }
5950
5951 testCases = append(testCases, test)
5952 }
David Benjamin83f90402015-01-27 01:09:43 -05005953 }
David Benjamin83f90402015-01-27 01:09:43 -05005954}
5955
David Benjaminc565ebb2015-04-03 04:06:36 -04005956func addExportKeyingMaterialTests() {
5957 for _, vers := range tlsVersions {
5958 if vers.version == VersionSSL30 {
5959 continue
5960 }
5961 testCases = append(testCases, testCase{
5962 name: "ExportKeyingMaterial-" + vers.name,
5963 config: Config{
5964 MaxVersion: vers.version,
5965 },
5966 exportKeyingMaterial: 1024,
5967 exportLabel: "label",
5968 exportContext: "context",
5969 useExportContext: true,
5970 })
5971 testCases = append(testCases, testCase{
5972 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5973 config: Config{
5974 MaxVersion: vers.version,
5975 },
5976 exportKeyingMaterial: 1024,
5977 })
5978 testCases = append(testCases, testCase{
5979 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5980 config: Config{
5981 MaxVersion: vers.version,
5982 },
5983 exportKeyingMaterial: 1024,
5984 useExportContext: true,
5985 })
5986 testCases = append(testCases, testCase{
5987 name: "ExportKeyingMaterial-Small-" + vers.name,
5988 config: Config{
5989 MaxVersion: vers.version,
5990 },
5991 exportKeyingMaterial: 1,
5992 exportLabel: "label",
5993 exportContext: "context",
5994 useExportContext: true,
5995 })
5996 }
5997 testCases = append(testCases, testCase{
5998 name: "ExportKeyingMaterial-SSL3",
5999 config: Config{
6000 MaxVersion: VersionSSL30,
6001 },
6002 exportKeyingMaterial: 1024,
6003 exportLabel: "label",
6004 exportContext: "context",
6005 useExportContext: true,
6006 shouldFail: true,
6007 expectedError: "failed to export keying material",
6008 })
6009}
6010
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006011func addTLSUniqueTests() {
6012 for _, isClient := range []bool{false, true} {
6013 for _, isResumption := range []bool{false, true} {
6014 for _, hasEMS := range []bool{false, true} {
6015 var suffix string
6016 if isResumption {
6017 suffix = "Resume-"
6018 } else {
6019 suffix = "Full-"
6020 }
6021
6022 if hasEMS {
6023 suffix += "EMS-"
6024 } else {
6025 suffix += "NoEMS-"
6026 }
6027
6028 if isClient {
6029 suffix += "Client"
6030 } else {
6031 suffix += "Server"
6032 }
6033
6034 test := testCase{
6035 name: "TLSUnique-" + suffix,
6036 testTLSUnique: true,
6037 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006038 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006039 Bugs: ProtocolBugs{
6040 NoExtendedMasterSecret: !hasEMS,
6041 },
6042 },
6043 }
6044
6045 if isResumption {
6046 test.resumeSession = true
6047 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006048 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006049 Bugs: ProtocolBugs{
6050 NoExtendedMasterSecret: !hasEMS,
6051 },
6052 }
6053 }
6054
6055 if isResumption && !hasEMS {
6056 test.shouldFail = true
6057 test.expectedError = "failed to get tls-unique"
6058 }
6059
6060 testCases = append(testCases, test)
6061 }
6062 }
6063 }
6064}
6065
Adam Langley09505632015-07-30 18:10:13 -07006066func addCustomExtensionTests() {
6067 expectedContents := "custom extension"
6068 emptyString := ""
6069
6070 for _, isClient := range []bool{false, true} {
6071 suffix := "Server"
6072 flag := "-enable-server-custom-extension"
6073 testType := serverTest
6074 if isClient {
6075 suffix = "Client"
6076 flag = "-enable-client-custom-extension"
6077 testType = clientTest
6078 }
6079
6080 testCases = append(testCases, testCase{
6081 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006082 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006084 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006085 Bugs: ProtocolBugs{
6086 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006087 ExpectedCustomExtension: &expectedContents,
6088 },
6089 },
6090 flags: []string{flag},
6091 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006092 testCases = append(testCases, testCase{
6093 testType: testType,
6094 name: "CustomExtensions-" + suffix + "-TLS13",
6095 config: Config{
6096 MaxVersion: VersionTLS13,
6097 Bugs: ProtocolBugs{
6098 CustomExtension: expectedContents,
6099 ExpectedCustomExtension: &expectedContents,
6100 },
6101 },
6102 flags: []string{flag},
6103 })
Adam Langley09505632015-07-30 18:10:13 -07006104
6105 // If the parse callback fails, the handshake should also fail.
6106 testCases = append(testCases, testCase{
6107 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006108 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006110 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006111 Bugs: ProtocolBugs{
6112 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006113 ExpectedCustomExtension: &expectedContents,
6114 },
6115 },
David Benjamin399e7c92015-07-30 23:01:27 -04006116 flags: []string{flag},
6117 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006118 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6119 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006120 testCases = append(testCases, testCase{
6121 testType: testType,
6122 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6123 config: Config{
6124 MaxVersion: VersionTLS13,
6125 Bugs: ProtocolBugs{
6126 CustomExtension: expectedContents + "foo",
6127 ExpectedCustomExtension: &expectedContents,
6128 },
6129 },
6130 flags: []string{flag},
6131 shouldFail: true,
6132 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6133 })
Adam Langley09505632015-07-30 18:10:13 -07006134
6135 // If the add callback fails, the handshake should also fail.
6136 testCases = append(testCases, testCase{
6137 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006138 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006140 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006141 Bugs: ProtocolBugs{
6142 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006143 ExpectedCustomExtension: &expectedContents,
6144 },
6145 },
David Benjamin399e7c92015-07-30 23:01:27 -04006146 flags: []string{flag, "-custom-extension-fail-add"},
6147 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006148 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6149 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006150 testCases = append(testCases, testCase{
6151 testType: testType,
6152 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6153 config: Config{
6154 MaxVersion: VersionTLS13,
6155 Bugs: ProtocolBugs{
6156 CustomExtension: expectedContents,
6157 ExpectedCustomExtension: &expectedContents,
6158 },
6159 },
6160 flags: []string{flag, "-custom-extension-fail-add"},
6161 shouldFail: true,
6162 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6163 })
Adam Langley09505632015-07-30 18:10:13 -07006164
6165 // If the add callback returns zero, no extension should be
6166 // added.
6167 skipCustomExtension := expectedContents
6168 if isClient {
6169 // For the case where the client skips sending the
6170 // custom extension, the server must not “echo” it.
6171 skipCustomExtension = ""
6172 }
6173 testCases = append(testCases, testCase{
6174 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006175 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006177 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006178 Bugs: ProtocolBugs{
6179 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006180 ExpectedCustomExtension: &emptyString,
6181 },
6182 },
6183 flags: []string{flag, "-custom-extension-skip"},
6184 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006185 testCases = append(testCases, testCase{
6186 testType: testType,
6187 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6188 config: Config{
6189 MaxVersion: VersionTLS13,
6190 Bugs: ProtocolBugs{
6191 CustomExtension: skipCustomExtension,
6192 ExpectedCustomExtension: &emptyString,
6193 },
6194 },
6195 flags: []string{flag, "-custom-extension-skip"},
6196 })
Adam Langley09505632015-07-30 18:10:13 -07006197 }
6198
6199 // The custom extension add callback should not be called if the client
6200 // doesn't send the extension.
6201 testCases = append(testCases, testCase{
6202 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006203 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006204 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006205 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006206 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006207 ExpectedCustomExtension: &emptyString,
6208 },
6209 },
6210 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6211 })
Adam Langley2deb9842015-08-07 11:15:37 -07006212
Steven Valdez143e8b32016-07-11 13:19:03 -04006213 testCases = append(testCases, testCase{
6214 testType: serverTest,
6215 name: "CustomExtensions-NotCalled-Server-TLS13",
6216 config: Config{
6217 MaxVersion: VersionTLS13,
6218 Bugs: ProtocolBugs{
6219 ExpectedCustomExtension: &emptyString,
6220 },
6221 },
6222 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6223 })
6224
Adam Langley2deb9842015-08-07 11:15:37 -07006225 // Test an unknown extension from the server.
6226 testCases = append(testCases, testCase{
6227 testType: clientTest,
6228 name: "UnknownExtension-Client",
6229 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006230 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006231 Bugs: ProtocolBugs{
6232 CustomExtension: expectedContents,
6233 },
6234 },
6235 shouldFail: true,
6236 expectedError: ":UNEXPECTED_EXTENSION:",
6237 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006238 testCases = append(testCases, testCase{
6239 testType: clientTest,
6240 name: "UnknownExtension-Client-TLS13",
6241 config: Config{
6242 MaxVersion: VersionTLS13,
6243 Bugs: ProtocolBugs{
6244 CustomExtension: expectedContents,
6245 },
6246 },
6247 shouldFail: true,
6248 expectedError: ":UNEXPECTED_EXTENSION:",
6249 })
Adam Langley09505632015-07-30 18:10:13 -07006250}
6251
David Benjaminb36a3952015-12-01 18:53:13 -05006252func addRSAClientKeyExchangeTests() {
6253 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6254 testCases = append(testCases, testCase{
6255 testType: serverTest,
6256 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6257 config: Config{
6258 // Ensure the ClientHello version and final
6259 // version are different, to detect if the
6260 // server uses the wrong one.
6261 MaxVersion: VersionTLS11,
6262 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6263 Bugs: ProtocolBugs{
6264 BadRSAClientKeyExchange: bad,
6265 },
6266 },
6267 shouldFail: true,
6268 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6269 })
6270 }
6271}
6272
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006273var testCurves = []struct {
6274 name string
6275 id CurveID
6276}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006277 {"P-256", CurveP256},
6278 {"P-384", CurveP384},
6279 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006280 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006281}
6282
6283func addCurveTests() {
6284 for _, curve := range testCurves {
6285 testCases = append(testCases, testCase{
6286 name: "CurveTest-Client-" + curve.name,
6287 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006288 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6290 CurvePreferences: []CurveID{curve.id},
6291 },
6292 flags: []string{"-enable-all-curves"},
6293 })
6294 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006295 name: "CurveTest-Client-" + curve.name + "-TLS13",
6296 config: Config{
6297 MaxVersion: VersionTLS13,
6298 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6299 CurvePreferences: []CurveID{curve.id},
6300 },
6301 flags: []string{"-enable-all-curves"},
6302 })
6303 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006304 testType: serverTest,
6305 name: "CurveTest-Server-" + curve.name,
6306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006307 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006308 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6309 CurvePreferences: []CurveID{curve.id},
6310 },
6311 flags: []string{"-enable-all-curves"},
6312 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006313 testCases = append(testCases, testCase{
6314 testType: serverTest,
6315 name: "CurveTest-Server-" + curve.name + "-TLS13",
6316 config: Config{
6317 MaxVersion: VersionTLS13,
6318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6319 CurvePreferences: []CurveID{curve.id},
6320 },
6321 flags: []string{"-enable-all-curves"},
6322 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006323 }
David Benjamin241ae832016-01-15 03:04:54 -05006324
6325 // The server must be tolerant to bogus curves.
6326 const bogusCurve = 0x1234
6327 testCases = append(testCases, testCase{
6328 testType: serverTest,
6329 name: "UnknownCurve",
6330 config: Config{
6331 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6332 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6333 },
6334 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006335
6336 // The server must not consider ECDHE ciphers when there are no
6337 // supported curves.
6338 testCases = append(testCases, testCase{
6339 testType: serverTest,
6340 name: "NoSupportedCurves",
6341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006342 MaxVersion: VersionTLS12,
6343 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6344 Bugs: ProtocolBugs{
6345 NoSupportedCurves: true,
6346 },
6347 },
6348 shouldFail: true,
6349 expectedError: ":NO_SHARED_CIPHER:",
6350 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006351 testCases = append(testCases, testCase{
6352 testType: serverTest,
6353 name: "NoSupportedCurves-TLS13",
6354 config: Config{
6355 MaxVersion: VersionTLS13,
6356 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6357 Bugs: ProtocolBugs{
6358 NoSupportedCurves: true,
6359 },
6360 },
6361 shouldFail: true,
6362 expectedError: ":NO_SHARED_CIPHER:",
6363 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006364
6365 // The server must fall back to another cipher when there are no
6366 // supported curves.
6367 testCases = append(testCases, testCase{
6368 testType: serverTest,
6369 name: "NoCommonCurves",
6370 config: Config{
6371 MaxVersion: VersionTLS12,
6372 CipherSuites: []uint16{
6373 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6374 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6375 },
6376 CurvePreferences: []CurveID{CurveP224},
6377 },
6378 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6379 })
6380
6381 // The client must reject bogus curves and disabled curves.
6382 testCases = append(testCases, testCase{
6383 name: "BadECDHECurve",
6384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006385 MaxVersion: VersionTLS12,
6386 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6387 Bugs: ProtocolBugs{
6388 SendCurve: bogusCurve,
6389 },
6390 },
6391 shouldFail: true,
6392 expectedError: ":WRONG_CURVE:",
6393 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006394 testCases = append(testCases, testCase{
6395 name: "BadECDHECurve-TLS13",
6396 config: Config{
6397 MaxVersion: VersionTLS13,
6398 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6399 Bugs: ProtocolBugs{
6400 SendCurve: bogusCurve,
6401 },
6402 },
6403 shouldFail: true,
6404 expectedError: ":WRONG_CURVE:",
6405 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006406
6407 testCases = append(testCases, testCase{
6408 name: "UnsupportedCurve",
6409 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006410 MaxVersion: VersionTLS12,
6411 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6412 CurvePreferences: []CurveID{CurveP256},
6413 Bugs: ProtocolBugs{
6414 IgnorePeerCurvePreferences: true,
6415 },
6416 },
6417 flags: []string{"-p384-only"},
6418 shouldFail: true,
6419 expectedError: ":WRONG_CURVE:",
6420 })
6421
David Benjamin4f921572016-07-17 14:20:10 +02006422 testCases = append(testCases, testCase{
6423 // TODO(davidben): Add a TLS 1.3 version where
6424 // HelloRetryRequest requests an unsupported curve.
6425 name: "UnsupportedCurve-ServerHello-TLS13",
6426 config: Config{
6427 MaxVersion: VersionTLS12,
6428 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6429 CurvePreferences: []CurveID{CurveP384},
6430 Bugs: ProtocolBugs{
6431 SendCurve: CurveP256,
6432 },
6433 },
6434 flags: []string{"-p384-only"},
6435 shouldFail: true,
6436 expectedError: ":WRONG_CURVE:",
6437 })
6438
David Benjamin4c3ddf72016-06-29 18:13:53 -04006439 // Test invalid curve points.
6440 testCases = append(testCases, testCase{
6441 name: "InvalidECDHPoint-Client",
6442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006443 MaxVersion: VersionTLS12,
6444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6445 CurvePreferences: []CurveID{CurveP256},
6446 Bugs: ProtocolBugs{
6447 InvalidECDHPoint: true,
6448 },
6449 },
6450 shouldFail: true,
6451 expectedError: ":INVALID_ENCODING:",
6452 })
6453 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006454 name: "InvalidECDHPoint-Client-TLS13",
6455 config: Config{
6456 MaxVersion: VersionTLS13,
6457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6458 CurvePreferences: []CurveID{CurveP256},
6459 Bugs: ProtocolBugs{
6460 InvalidECDHPoint: true,
6461 },
6462 },
6463 shouldFail: true,
6464 expectedError: ":INVALID_ENCODING:",
6465 })
6466 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006467 testType: serverTest,
6468 name: "InvalidECDHPoint-Server",
6469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006470 MaxVersion: VersionTLS12,
6471 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6472 CurvePreferences: []CurveID{CurveP256},
6473 Bugs: ProtocolBugs{
6474 InvalidECDHPoint: true,
6475 },
6476 },
6477 shouldFail: true,
6478 expectedError: ":INVALID_ENCODING:",
6479 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006480 testCases = append(testCases, testCase{
6481 testType: serverTest,
6482 name: "InvalidECDHPoint-Server-TLS13",
6483 config: Config{
6484 MaxVersion: VersionTLS13,
6485 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6486 CurvePreferences: []CurveID{CurveP256},
6487 Bugs: ProtocolBugs{
6488 InvalidECDHPoint: true,
6489 },
6490 },
6491 shouldFail: true,
6492 expectedError: ":INVALID_ENCODING:",
6493 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006494}
6495
Matt Braithwaite54217e42016-06-13 13:03:47 -07006496func addCECPQ1Tests() {
6497 testCases = append(testCases, testCase{
6498 testType: clientTest,
6499 name: "CECPQ1-Client-BadX25519Part",
6500 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006501 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006502 MinVersion: VersionTLS12,
6503 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6504 Bugs: ProtocolBugs{
6505 CECPQ1BadX25519Part: true,
6506 },
6507 },
6508 flags: []string{"-cipher", "kCECPQ1"},
6509 shouldFail: true,
6510 expectedLocalError: "local error: bad record MAC",
6511 })
6512 testCases = append(testCases, testCase{
6513 testType: clientTest,
6514 name: "CECPQ1-Client-BadNewhopePart",
6515 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006516 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006517 MinVersion: VersionTLS12,
6518 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6519 Bugs: ProtocolBugs{
6520 CECPQ1BadNewhopePart: true,
6521 },
6522 },
6523 flags: []string{"-cipher", "kCECPQ1"},
6524 shouldFail: true,
6525 expectedLocalError: "local error: bad record MAC",
6526 })
6527 testCases = append(testCases, testCase{
6528 testType: serverTest,
6529 name: "CECPQ1-Server-BadX25519Part",
6530 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006531 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006532 MinVersion: VersionTLS12,
6533 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6534 Bugs: ProtocolBugs{
6535 CECPQ1BadX25519Part: true,
6536 },
6537 },
6538 flags: []string{"-cipher", "kCECPQ1"},
6539 shouldFail: true,
6540 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6541 })
6542 testCases = append(testCases, testCase{
6543 testType: serverTest,
6544 name: "CECPQ1-Server-BadNewhopePart",
6545 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006546 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006547 MinVersion: VersionTLS12,
6548 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6549 Bugs: ProtocolBugs{
6550 CECPQ1BadNewhopePart: true,
6551 },
6552 },
6553 flags: []string{"-cipher", "kCECPQ1"},
6554 shouldFail: true,
6555 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6556 })
6557}
6558
David Benjamin4cc36ad2015-12-19 14:23:26 -05006559func addKeyExchangeInfoTests() {
6560 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006561 name: "KeyExchangeInfo-DHE-Client",
6562 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006563 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006564 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6565 Bugs: ProtocolBugs{
6566 // This is a 1234-bit prime number, generated
6567 // with:
6568 // openssl gendh 1234 | openssl asn1parse -i
6569 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6570 },
6571 },
David Benjamin9e68f192016-06-30 14:55:33 -04006572 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006573 })
6574 testCases = append(testCases, testCase{
6575 testType: serverTest,
6576 name: "KeyExchangeInfo-DHE-Server",
6577 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006578 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006579 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6580 },
6581 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006582 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006583 })
6584
6585 testCases = append(testCases, testCase{
6586 name: "KeyExchangeInfo-ECDHE-Client",
6587 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006588 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006589 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6590 CurvePreferences: []CurveID{CurveX25519},
6591 },
David Benjamin9e68f192016-06-30 14:55:33 -04006592 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006593 })
6594 testCases = append(testCases, testCase{
6595 testType: serverTest,
6596 name: "KeyExchangeInfo-ECDHE-Server",
6597 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006598 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006599 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6600 CurvePreferences: []CurveID{CurveX25519},
6601 },
David Benjamin9e68f192016-06-30 14:55:33 -04006602 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006603 })
6604}
6605
David Benjaminc9ae27c2016-06-24 22:56:37 -04006606func addTLS13RecordTests() {
6607 testCases = append(testCases, testCase{
6608 name: "TLS13-RecordPadding",
6609 config: Config{
6610 MaxVersion: VersionTLS13,
6611 MinVersion: VersionTLS13,
6612 Bugs: ProtocolBugs{
6613 RecordPadding: 10,
6614 },
6615 },
6616 })
6617
6618 testCases = append(testCases, testCase{
6619 name: "TLS13-EmptyRecords",
6620 config: Config{
6621 MaxVersion: VersionTLS13,
6622 MinVersion: VersionTLS13,
6623 Bugs: ProtocolBugs{
6624 OmitRecordContents: true,
6625 },
6626 },
6627 shouldFail: true,
6628 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6629 })
6630
6631 testCases = append(testCases, testCase{
6632 name: "TLS13-OnlyPadding",
6633 config: Config{
6634 MaxVersion: VersionTLS13,
6635 MinVersion: VersionTLS13,
6636 Bugs: ProtocolBugs{
6637 OmitRecordContents: true,
6638 RecordPadding: 10,
6639 },
6640 },
6641 shouldFail: true,
6642 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6643 })
6644
6645 testCases = append(testCases, testCase{
6646 name: "TLS13-WrongOuterRecord",
6647 config: Config{
6648 MaxVersion: VersionTLS13,
6649 MinVersion: VersionTLS13,
6650 Bugs: ProtocolBugs{
6651 OuterRecordType: recordTypeHandshake,
6652 },
6653 },
6654 shouldFail: true,
6655 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6656 })
6657}
6658
David Benjamin82261be2016-07-07 14:32:50 -07006659func addChangeCipherSpecTests() {
6660 // Test missing ChangeCipherSpecs.
6661 testCases = append(testCases, testCase{
6662 name: "SkipChangeCipherSpec-Client",
6663 config: Config{
6664 MaxVersion: VersionTLS12,
6665 Bugs: ProtocolBugs{
6666 SkipChangeCipherSpec: true,
6667 },
6668 },
6669 shouldFail: true,
6670 expectedError: ":UNEXPECTED_RECORD:",
6671 })
6672 testCases = append(testCases, testCase{
6673 testType: serverTest,
6674 name: "SkipChangeCipherSpec-Server",
6675 config: Config{
6676 MaxVersion: VersionTLS12,
6677 Bugs: ProtocolBugs{
6678 SkipChangeCipherSpec: true,
6679 },
6680 },
6681 shouldFail: true,
6682 expectedError: ":UNEXPECTED_RECORD:",
6683 })
6684 testCases = append(testCases, testCase{
6685 testType: serverTest,
6686 name: "SkipChangeCipherSpec-Server-NPN",
6687 config: Config{
6688 MaxVersion: VersionTLS12,
6689 NextProtos: []string{"bar"},
6690 Bugs: ProtocolBugs{
6691 SkipChangeCipherSpec: true,
6692 },
6693 },
6694 flags: []string{
6695 "-advertise-npn", "\x03foo\x03bar\x03baz",
6696 },
6697 shouldFail: true,
6698 expectedError: ":UNEXPECTED_RECORD:",
6699 })
6700
6701 // Test synchronization between the handshake and ChangeCipherSpec.
6702 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6703 // rejected. Test both with and without handshake packing to handle both
6704 // when the partial post-CCS message is in its own record and when it is
6705 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006706 for _, packed := range []bool{false, true} {
6707 var suffix string
6708 if packed {
6709 suffix = "-Packed"
6710 }
6711
6712 testCases = append(testCases, testCase{
6713 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6714 config: Config{
6715 MaxVersion: VersionTLS12,
6716 Bugs: ProtocolBugs{
6717 FragmentAcrossChangeCipherSpec: true,
6718 PackHandshakeFlight: packed,
6719 },
6720 },
6721 shouldFail: true,
6722 expectedError: ":UNEXPECTED_RECORD:",
6723 })
6724 testCases = append(testCases, testCase{
6725 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6726 config: Config{
6727 MaxVersion: VersionTLS12,
6728 },
6729 resumeSession: true,
6730 resumeConfig: &Config{
6731 MaxVersion: VersionTLS12,
6732 Bugs: ProtocolBugs{
6733 FragmentAcrossChangeCipherSpec: true,
6734 PackHandshakeFlight: packed,
6735 },
6736 },
6737 shouldFail: true,
6738 expectedError: ":UNEXPECTED_RECORD:",
6739 })
6740 testCases = append(testCases, testCase{
6741 testType: serverTest,
6742 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6743 config: Config{
6744 MaxVersion: VersionTLS12,
6745 Bugs: ProtocolBugs{
6746 FragmentAcrossChangeCipherSpec: true,
6747 PackHandshakeFlight: packed,
6748 },
6749 },
6750 shouldFail: true,
6751 expectedError: ":UNEXPECTED_RECORD:",
6752 })
6753 testCases = append(testCases, testCase{
6754 testType: serverTest,
6755 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6756 config: Config{
6757 MaxVersion: VersionTLS12,
6758 },
6759 resumeSession: true,
6760 resumeConfig: &Config{
6761 MaxVersion: VersionTLS12,
6762 Bugs: ProtocolBugs{
6763 FragmentAcrossChangeCipherSpec: true,
6764 PackHandshakeFlight: packed,
6765 },
6766 },
6767 shouldFail: true,
6768 expectedError: ":UNEXPECTED_RECORD:",
6769 })
6770 testCases = append(testCases, testCase{
6771 testType: serverTest,
6772 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6773 config: Config{
6774 MaxVersion: VersionTLS12,
6775 NextProtos: []string{"bar"},
6776 Bugs: ProtocolBugs{
6777 FragmentAcrossChangeCipherSpec: true,
6778 PackHandshakeFlight: packed,
6779 },
6780 },
6781 flags: []string{
6782 "-advertise-npn", "\x03foo\x03bar\x03baz",
6783 },
6784 shouldFail: true,
6785 expectedError: ":UNEXPECTED_RECORD:",
6786 })
6787 }
6788
David Benjamin61672812016-07-14 23:10:43 -04006789 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6790 // messages in the handshake queue. Do this by testing the server
6791 // reading the client Finished, reversing the flight so Finished comes
6792 // first.
6793 testCases = append(testCases, testCase{
6794 protocol: dtls,
6795 testType: serverTest,
6796 name: "SendUnencryptedFinished-DTLS",
6797 config: Config{
6798 MaxVersion: VersionTLS12,
6799 Bugs: ProtocolBugs{
6800 SendUnencryptedFinished: true,
6801 ReverseHandshakeFragments: true,
6802 },
6803 },
6804 shouldFail: true,
6805 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6806 })
6807
Steven Valdez143e8b32016-07-11 13:19:03 -04006808 // Test synchronization between encryption changes and the handshake in
6809 // TLS 1.3, where ChangeCipherSpec is implicit.
6810 testCases = append(testCases, testCase{
6811 name: "PartialEncryptedExtensionsWithServerHello",
6812 config: Config{
6813 MaxVersion: VersionTLS13,
6814 Bugs: ProtocolBugs{
6815 PartialEncryptedExtensionsWithServerHello: true,
6816 },
6817 },
6818 shouldFail: true,
6819 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6820 })
6821 testCases = append(testCases, testCase{
6822 testType: serverTest,
6823 name: "PartialClientFinishedWithClientHello",
6824 config: Config{
6825 MaxVersion: VersionTLS13,
6826 Bugs: ProtocolBugs{
6827 PartialClientFinishedWithClientHello: true,
6828 },
6829 },
6830 shouldFail: true,
6831 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6832 })
6833
David Benjamin82261be2016-07-07 14:32:50 -07006834 // Test that early ChangeCipherSpecs are handled correctly.
6835 testCases = append(testCases, testCase{
6836 testType: serverTest,
6837 name: "EarlyChangeCipherSpec-server-1",
6838 config: Config{
6839 MaxVersion: VersionTLS12,
6840 Bugs: ProtocolBugs{
6841 EarlyChangeCipherSpec: 1,
6842 },
6843 },
6844 shouldFail: true,
6845 expectedError: ":UNEXPECTED_RECORD:",
6846 })
6847 testCases = append(testCases, testCase{
6848 testType: serverTest,
6849 name: "EarlyChangeCipherSpec-server-2",
6850 config: Config{
6851 MaxVersion: VersionTLS12,
6852 Bugs: ProtocolBugs{
6853 EarlyChangeCipherSpec: 2,
6854 },
6855 },
6856 shouldFail: true,
6857 expectedError: ":UNEXPECTED_RECORD:",
6858 })
6859 testCases = append(testCases, testCase{
6860 protocol: dtls,
6861 name: "StrayChangeCipherSpec",
6862 config: Config{
6863 // TODO(davidben): Once DTLS 1.3 exists, test
6864 // that stray ChangeCipherSpec messages are
6865 // rejected.
6866 MaxVersion: VersionTLS12,
6867 Bugs: ProtocolBugs{
6868 StrayChangeCipherSpec: true,
6869 },
6870 },
6871 })
6872
6873 // Test that the contents of ChangeCipherSpec are checked.
6874 testCases = append(testCases, testCase{
6875 name: "BadChangeCipherSpec-1",
6876 config: Config{
6877 MaxVersion: VersionTLS12,
6878 Bugs: ProtocolBugs{
6879 BadChangeCipherSpec: []byte{2},
6880 },
6881 },
6882 shouldFail: true,
6883 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6884 })
6885 testCases = append(testCases, testCase{
6886 name: "BadChangeCipherSpec-2",
6887 config: Config{
6888 MaxVersion: VersionTLS12,
6889 Bugs: ProtocolBugs{
6890 BadChangeCipherSpec: []byte{1, 1},
6891 },
6892 },
6893 shouldFail: true,
6894 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6895 })
6896 testCases = append(testCases, testCase{
6897 protocol: dtls,
6898 name: "BadChangeCipherSpec-DTLS-1",
6899 config: Config{
6900 MaxVersion: VersionTLS12,
6901 Bugs: ProtocolBugs{
6902 BadChangeCipherSpec: []byte{2},
6903 },
6904 },
6905 shouldFail: true,
6906 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6907 })
6908 testCases = append(testCases, testCase{
6909 protocol: dtls,
6910 name: "BadChangeCipherSpec-DTLS-2",
6911 config: Config{
6912 MaxVersion: VersionTLS12,
6913 Bugs: ProtocolBugs{
6914 BadChangeCipherSpec: []byte{1, 1},
6915 },
6916 },
6917 shouldFail: true,
6918 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6919 })
6920}
6921
David Benjamin0b8d5da2016-07-15 00:39:56 -04006922func addWrongMessageTypeTests() {
6923 for _, protocol := range []protocol{tls, dtls} {
6924 var suffix string
6925 if protocol == dtls {
6926 suffix = "-DTLS"
6927 }
6928
6929 testCases = append(testCases, testCase{
6930 protocol: protocol,
6931 testType: serverTest,
6932 name: "WrongMessageType-ClientHello" + suffix,
6933 config: Config{
6934 MaxVersion: VersionTLS12,
6935 Bugs: ProtocolBugs{
6936 SendWrongMessageType: typeClientHello,
6937 },
6938 },
6939 shouldFail: true,
6940 expectedError: ":UNEXPECTED_MESSAGE:",
6941 expectedLocalError: "remote error: unexpected message",
6942 })
6943
6944 if protocol == dtls {
6945 testCases = append(testCases, testCase{
6946 protocol: protocol,
6947 name: "WrongMessageType-HelloVerifyRequest" + suffix,
6948 config: Config{
6949 MaxVersion: VersionTLS12,
6950 Bugs: ProtocolBugs{
6951 SendWrongMessageType: typeHelloVerifyRequest,
6952 },
6953 },
6954 shouldFail: true,
6955 expectedError: ":UNEXPECTED_MESSAGE:",
6956 expectedLocalError: "remote error: unexpected message",
6957 })
6958 }
6959
6960 testCases = append(testCases, testCase{
6961 protocol: protocol,
6962 name: "WrongMessageType-ServerHello" + suffix,
6963 config: Config{
6964 MaxVersion: VersionTLS12,
6965 Bugs: ProtocolBugs{
6966 SendWrongMessageType: typeServerHello,
6967 },
6968 },
6969 shouldFail: true,
6970 expectedError: ":UNEXPECTED_MESSAGE:",
6971 expectedLocalError: "remote error: unexpected message",
6972 })
6973
6974 testCases = append(testCases, testCase{
6975 protocol: protocol,
6976 name: "WrongMessageType-ServerCertificate" + suffix,
6977 config: Config{
6978 MaxVersion: VersionTLS12,
6979 Bugs: ProtocolBugs{
6980 SendWrongMessageType: typeCertificate,
6981 },
6982 },
6983 shouldFail: true,
6984 expectedError: ":UNEXPECTED_MESSAGE:",
6985 expectedLocalError: "remote error: unexpected message",
6986 })
6987
6988 testCases = append(testCases, testCase{
6989 protocol: protocol,
6990 name: "WrongMessageType-CertificateStatus" + suffix,
6991 config: Config{
6992 MaxVersion: VersionTLS12,
6993 Bugs: ProtocolBugs{
6994 SendWrongMessageType: typeCertificateStatus,
6995 },
6996 },
6997 flags: []string{"-enable-ocsp-stapling"},
6998 shouldFail: true,
6999 expectedError: ":UNEXPECTED_MESSAGE:",
7000 expectedLocalError: "remote error: unexpected message",
7001 })
7002
7003 testCases = append(testCases, testCase{
7004 protocol: protocol,
7005 name: "WrongMessageType-ServerKeyExchange" + suffix,
7006 config: Config{
7007 MaxVersion: VersionTLS12,
7008 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7009 Bugs: ProtocolBugs{
7010 SendWrongMessageType: typeServerKeyExchange,
7011 },
7012 },
7013 shouldFail: true,
7014 expectedError: ":UNEXPECTED_MESSAGE:",
7015 expectedLocalError: "remote error: unexpected message",
7016 })
7017
7018 testCases = append(testCases, testCase{
7019 protocol: protocol,
7020 name: "WrongMessageType-CertificateRequest" + suffix,
7021 config: Config{
7022 MaxVersion: VersionTLS12,
7023 ClientAuth: RequireAnyClientCert,
7024 Bugs: ProtocolBugs{
7025 SendWrongMessageType: typeCertificateRequest,
7026 },
7027 },
7028 shouldFail: true,
7029 expectedError: ":UNEXPECTED_MESSAGE:",
7030 expectedLocalError: "remote error: unexpected message",
7031 })
7032
7033 testCases = append(testCases, testCase{
7034 protocol: protocol,
7035 name: "WrongMessageType-ServerHelloDone" + suffix,
7036 config: Config{
7037 MaxVersion: VersionTLS12,
7038 Bugs: ProtocolBugs{
7039 SendWrongMessageType: typeServerHelloDone,
7040 },
7041 },
7042 shouldFail: true,
7043 expectedError: ":UNEXPECTED_MESSAGE:",
7044 expectedLocalError: "remote error: unexpected message",
7045 })
7046
7047 testCases = append(testCases, testCase{
7048 testType: serverTest,
7049 protocol: protocol,
7050 name: "WrongMessageType-ClientCertificate" + suffix,
7051 config: Config{
7052 Certificates: []Certificate{rsaCertificate},
7053 MaxVersion: VersionTLS12,
7054 Bugs: ProtocolBugs{
7055 SendWrongMessageType: typeCertificate,
7056 },
7057 },
7058 flags: []string{"-require-any-client-certificate"},
7059 shouldFail: true,
7060 expectedError: ":UNEXPECTED_MESSAGE:",
7061 expectedLocalError: "remote error: unexpected message",
7062 })
7063
7064 testCases = append(testCases, testCase{
7065 testType: serverTest,
7066 protocol: protocol,
7067 name: "WrongMessageType-CertificateVerify" + suffix,
7068 config: Config{
7069 Certificates: []Certificate{rsaCertificate},
7070 MaxVersion: VersionTLS12,
7071 Bugs: ProtocolBugs{
7072 SendWrongMessageType: typeCertificateVerify,
7073 },
7074 },
7075 flags: []string{"-require-any-client-certificate"},
7076 shouldFail: true,
7077 expectedError: ":UNEXPECTED_MESSAGE:",
7078 expectedLocalError: "remote error: unexpected message",
7079 })
7080
7081 testCases = append(testCases, testCase{
7082 testType: serverTest,
7083 protocol: protocol,
7084 name: "WrongMessageType-ClientKeyExchange" + suffix,
7085 config: Config{
7086 MaxVersion: VersionTLS12,
7087 Bugs: ProtocolBugs{
7088 SendWrongMessageType: typeClientKeyExchange,
7089 },
7090 },
7091 shouldFail: true,
7092 expectedError: ":UNEXPECTED_MESSAGE:",
7093 expectedLocalError: "remote error: unexpected message",
7094 })
7095
7096 if protocol != dtls {
7097 testCases = append(testCases, testCase{
7098 testType: serverTest,
7099 protocol: protocol,
7100 name: "WrongMessageType-NextProtocol" + suffix,
7101 config: Config{
7102 MaxVersion: VersionTLS12,
7103 NextProtos: []string{"bar"},
7104 Bugs: ProtocolBugs{
7105 SendWrongMessageType: typeNextProtocol,
7106 },
7107 },
7108 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7109 shouldFail: true,
7110 expectedError: ":UNEXPECTED_MESSAGE:",
7111 expectedLocalError: "remote error: unexpected message",
7112 })
7113
7114 testCases = append(testCases, testCase{
7115 testType: serverTest,
7116 protocol: protocol,
7117 name: "WrongMessageType-ChannelID" + suffix,
7118 config: Config{
7119 MaxVersion: VersionTLS12,
7120 ChannelID: channelIDKey,
7121 Bugs: ProtocolBugs{
7122 SendWrongMessageType: typeChannelID,
7123 },
7124 },
7125 flags: []string{
7126 "-expect-channel-id",
7127 base64.StdEncoding.EncodeToString(channelIDBytes),
7128 },
7129 shouldFail: true,
7130 expectedError: ":UNEXPECTED_MESSAGE:",
7131 expectedLocalError: "remote error: unexpected message",
7132 })
7133 }
7134
7135 testCases = append(testCases, testCase{
7136 testType: serverTest,
7137 protocol: protocol,
7138 name: "WrongMessageType-ClientFinished" + suffix,
7139 config: Config{
7140 MaxVersion: VersionTLS12,
7141 Bugs: ProtocolBugs{
7142 SendWrongMessageType: typeFinished,
7143 },
7144 },
7145 shouldFail: true,
7146 expectedError: ":UNEXPECTED_MESSAGE:",
7147 expectedLocalError: "remote error: unexpected message",
7148 })
7149
7150 testCases = append(testCases, testCase{
7151 protocol: protocol,
7152 name: "WrongMessageType-NewSessionTicket" + suffix,
7153 config: Config{
7154 MaxVersion: VersionTLS12,
7155 Bugs: ProtocolBugs{
7156 SendWrongMessageType: typeNewSessionTicket,
7157 },
7158 },
7159 shouldFail: true,
7160 expectedError: ":UNEXPECTED_MESSAGE:",
7161 expectedLocalError: "remote error: unexpected message",
7162 })
7163
7164 testCases = append(testCases, testCase{
7165 protocol: protocol,
7166 name: "WrongMessageType-ServerFinished" + suffix,
7167 config: Config{
7168 MaxVersion: VersionTLS12,
7169 Bugs: ProtocolBugs{
7170 SendWrongMessageType: typeFinished,
7171 },
7172 },
7173 shouldFail: true,
7174 expectedError: ":UNEXPECTED_MESSAGE:",
7175 expectedLocalError: "remote error: unexpected message",
7176 })
7177
7178 }
7179}
7180
Steven Valdez143e8b32016-07-11 13:19:03 -04007181func addTLS13WrongMessageTypeTests() {
7182 testCases = append(testCases, testCase{
7183 testType: serverTest,
7184 name: "WrongMessageType-TLS13-ClientHello",
7185 config: Config{
7186 MaxVersion: VersionTLS13,
7187 Bugs: ProtocolBugs{
7188 SendWrongMessageType: typeClientHello,
7189 },
7190 },
7191 shouldFail: true,
7192 expectedError: ":UNEXPECTED_MESSAGE:",
7193 expectedLocalError: "remote error: unexpected message",
7194 })
7195
7196 testCases = append(testCases, testCase{
7197 name: "WrongMessageType-TLS13-ServerHello",
7198 config: Config{
7199 MaxVersion: VersionTLS13,
7200 Bugs: ProtocolBugs{
7201 SendWrongMessageType: typeServerHello,
7202 },
7203 },
7204 shouldFail: true,
7205 expectedError: ":UNEXPECTED_MESSAGE:",
7206 // The alert comes in with the wrong encryption.
7207 expectedLocalError: "local error: bad record MAC",
7208 })
7209
7210 testCases = append(testCases, testCase{
7211 name: "WrongMessageType-TLS13-EncryptedExtensions",
7212 config: Config{
7213 MaxVersion: VersionTLS13,
7214 Bugs: ProtocolBugs{
7215 SendWrongMessageType: typeEncryptedExtensions,
7216 },
7217 },
7218 shouldFail: true,
7219 expectedError: ":UNEXPECTED_MESSAGE:",
7220 expectedLocalError: "remote error: unexpected message",
7221 })
7222
7223 testCases = append(testCases, testCase{
7224 name: "WrongMessageType-TLS13-CertificateRequest",
7225 config: Config{
7226 MaxVersion: VersionTLS13,
7227 ClientAuth: RequireAnyClientCert,
7228 Bugs: ProtocolBugs{
7229 SendWrongMessageType: typeCertificateRequest,
7230 },
7231 },
7232 shouldFail: true,
7233 expectedError: ":UNEXPECTED_MESSAGE:",
7234 expectedLocalError: "remote error: unexpected message",
7235 })
7236
7237 testCases = append(testCases, testCase{
7238 name: "WrongMessageType-TLS13-ServerCertificate",
7239 config: Config{
7240 MaxVersion: VersionTLS13,
7241 Bugs: ProtocolBugs{
7242 SendWrongMessageType: typeCertificate,
7243 },
7244 },
7245 shouldFail: true,
7246 expectedError: ":UNEXPECTED_MESSAGE:",
7247 expectedLocalError: "remote error: unexpected message",
7248 })
7249
7250 testCases = append(testCases, testCase{
7251 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7252 config: Config{
7253 MaxVersion: VersionTLS13,
7254 Bugs: ProtocolBugs{
7255 SendWrongMessageType: typeCertificateVerify,
7256 },
7257 },
7258 shouldFail: true,
7259 expectedError: ":UNEXPECTED_MESSAGE:",
7260 expectedLocalError: "remote error: unexpected message",
7261 })
7262
7263 testCases = append(testCases, testCase{
7264 name: "WrongMessageType-TLS13-ServerFinished",
7265 config: Config{
7266 MaxVersion: VersionTLS13,
7267 Bugs: ProtocolBugs{
7268 SendWrongMessageType: typeFinished,
7269 },
7270 },
7271 shouldFail: true,
7272 expectedError: ":UNEXPECTED_MESSAGE:",
7273 expectedLocalError: "remote error: unexpected message",
7274 })
7275
7276 testCases = append(testCases, testCase{
7277 testType: serverTest,
7278 name: "WrongMessageType-TLS13-ClientCertificate",
7279 config: Config{
7280 Certificates: []Certificate{rsaCertificate},
7281 MaxVersion: VersionTLS13,
7282 Bugs: ProtocolBugs{
7283 SendWrongMessageType: typeCertificate,
7284 },
7285 },
7286 flags: []string{"-require-any-client-certificate"},
7287 shouldFail: true,
7288 expectedError: ":UNEXPECTED_MESSAGE:",
7289 expectedLocalError: "remote error: unexpected message",
7290 })
7291
7292 testCases = append(testCases, testCase{
7293 testType: serverTest,
7294 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7295 config: Config{
7296 Certificates: []Certificate{rsaCertificate},
7297 MaxVersion: VersionTLS13,
7298 Bugs: ProtocolBugs{
7299 SendWrongMessageType: typeCertificateVerify,
7300 },
7301 },
7302 flags: []string{"-require-any-client-certificate"},
7303 shouldFail: true,
7304 expectedError: ":UNEXPECTED_MESSAGE:",
7305 expectedLocalError: "remote error: unexpected message",
7306 })
7307
7308 testCases = append(testCases, testCase{
7309 testType: serverTest,
7310 name: "WrongMessageType-TLS13-ClientFinished",
7311 config: Config{
7312 MaxVersion: VersionTLS13,
7313 Bugs: ProtocolBugs{
7314 SendWrongMessageType: typeFinished,
7315 },
7316 },
7317 shouldFail: true,
7318 expectedError: ":UNEXPECTED_MESSAGE:",
7319 expectedLocalError: "remote error: unexpected message",
7320 })
7321}
7322
7323func addTLS13HandshakeTests() {
7324 testCases = append(testCases, testCase{
7325 testType: clientTest,
7326 name: "MissingKeyShare-Client",
7327 config: Config{
7328 MaxVersion: VersionTLS13,
7329 Bugs: ProtocolBugs{
7330 MissingKeyShare: true,
7331 },
7332 },
7333 shouldFail: true,
7334 expectedError: ":MISSING_KEY_SHARE:",
7335 })
7336
7337 testCases = append(testCases, testCase{
7338 name: "MissingKeyShare-Server",
7339 config: Config{
7340 MaxVersion: VersionTLS13,
7341 Bugs: ProtocolBugs{
7342 MissingKeyShare: true,
7343 },
7344 },
7345 shouldFail: true,
7346 expectedError: ":MISSING_KEY_SHARE:",
7347 })
7348
7349 testCases = append(testCases, testCase{
7350 testType: clientTest,
7351 name: "ClientHelloMissingKeyShare",
7352 config: Config{
7353 MaxVersion: VersionTLS13,
7354 Bugs: ProtocolBugs{
7355 MissingKeyShare: true,
7356 },
7357 },
7358 shouldFail: true,
7359 expectedError: ":MISSING_KEY_SHARE:",
7360 })
7361
7362 testCases = append(testCases, testCase{
7363 testType: clientTest,
7364 name: "MissingKeyShare",
7365 config: Config{
7366 MaxVersion: VersionTLS13,
7367 Bugs: ProtocolBugs{
7368 MissingKeyShare: true,
7369 },
7370 },
7371 shouldFail: true,
7372 expectedError: ":MISSING_KEY_SHARE:",
7373 })
7374
7375 testCases = append(testCases, testCase{
7376 testType: serverTest,
7377 name: "DuplicateKeyShares",
7378 config: Config{
7379 MaxVersion: VersionTLS13,
7380 Bugs: ProtocolBugs{
7381 DuplicateKeyShares: true,
7382 },
7383 },
7384 })
7385
7386 testCases = append(testCases, testCase{
7387 testType: clientTest,
7388 name: "EmptyEncryptedExtensions",
7389 config: Config{
7390 MaxVersion: VersionTLS13,
7391 Bugs: ProtocolBugs{
7392 EmptyEncryptedExtensions: true,
7393 },
7394 },
7395 shouldFail: true,
7396 expectedLocalError: "remote error: error decoding message",
7397 })
7398
7399 testCases = append(testCases, testCase{
7400 testType: clientTest,
7401 name: "EncryptedExtensionsWithKeyShare",
7402 config: Config{
7403 MaxVersion: VersionTLS13,
7404 Bugs: ProtocolBugs{
7405 EncryptedExtensionsWithKeyShare: true,
7406 },
7407 },
7408 shouldFail: true,
7409 expectedLocalError: "remote error: unsupported extension",
7410 })
7411}
7412
Adam Langley7c803a62015-06-15 15:35:05 -07007413func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007414 defer wg.Done()
7415
7416 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007417 var err error
7418
7419 if *mallocTest < 0 {
7420 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007421 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007422 } else {
7423 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7424 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007425 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007426 if err != nil {
7427 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7428 }
7429 break
7430 }
7431 }
7432 }
Adam Langley95c29f32014-06-20 12:00:00 -07007433 statusChan <- statusMsg{test: test, err: err}
7434 }
7435}
7436
7437type statusMsg struct {
7438 test *testCase
7439 started bool
7440 err error
7441}
7442
David Benjamin5f237bc2015-02-11 17:14:15 -05007443func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07007444 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007445
David Benjamin5f237bc2015-02-11 17:14:15 -05007446 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007447 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007448 if !*pipe {
7449 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007450 var erase string
7451 for i := 0; i < lineLen; i++ {
7452 erase += "\b \b"
7453 }
7454 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007455 }
7456
Adam Langley95c29f32014-06-20 12:00:00 -07007457 if msg.started {
7458 started++
7459 } else {
7460 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007461
7462 if msg.err != nil {
7463 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7464 failed++
7465 testOutput.addResult(msg.test.name, "FAIL")
7466 } else {
7467 if *pipe {
7468 // Print each test instead of a status line.
7469 fmt.Printf("PASSED (%s)\n", msg.test.name)
7470 }
7471 testOutput.addResult(msg.test.name, "PASS")
7472 }
Adam Langley95c29f32014-06-20 12:00:00 -07007473 }
7474
David Benjamin5f237bc2015-02-11 17:14:15 -05007475 if !*pipe {
7476 // Print a new status line.
7477 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
7478 lineLen = len(line)
7479 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007480 }
Adam Langley95c29f32014-06-20 12:00:00 -07007481 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007482
7483 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007484}
7485
7486func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007487 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007488 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007489 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007490
Adam Langley7c803a62015-06-15 15:35:05 -07007491 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007492 addCipherSuiteTests()
7493 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007494 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007495 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007496 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007497 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007498 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007499 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007500 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007501 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007502 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007503 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007504 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007505 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007506 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007507 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007508 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007509 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007510 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007511 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007512 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007513 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007514 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007515 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007516 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007517 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007518 addTLS13WrongMessageTypeTests()
7519 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007520
7521 var wg sync.WaitGroup
7522
Adam Langley7c803a62015-06-15 15:35:05 -07007523 statusChan := make(chan statusMsg, *numWorkers)
7524 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007525 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007526
David Benjamin025b3d32014-07-01 19:53:04 -04007527 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007528
Adam Langley7c803a62015-06-15 15:35:05 -07007529 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007530 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007531 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007532 }
7533
David Benjamin270f0a72016-03-17 14:41:36 -04007534 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007535 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07007536 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04007537 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007538 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007539 }
7540 }
David Benjamin270f0a72016-03-17 14:41:36 -04007541 if !foundTest {
7542 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
7543 os.Exit(1)
7544 }
Adam Langley95c29f32014-06-20 12:00:00 -07007545
7546 close(testChan)
7547 wg.Wait()
7548 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007549 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007550
7551 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007552
7553 if *jsonOutput != "" {
7554 if err := testOutput.writeTo(*jsonOutput); err != nil {
7555 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7556 }
7557 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007558
7559 if !testOutput.allPassed {
7560 os.Exit(1)
7561 }
Adam Langley95c29f32014-06-20 12:00:00 -07007562}