blob: e5494bab5952cce66ca02994fdea9d9a1f2746ab [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070024 "flag"
25 "fmt"
26 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070027 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070028 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "net"
30 "os"
31 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040032 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040033 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080034 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070035 "strings"
36 "sync"
37 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050038 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070039)
40
Adam Langley69a01602014-11-17 17:26:55 -080041var (
David Benjamin5f237bc2015-02-11 17:14:15 -050042 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
43 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050044 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050045 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
46 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
47 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
48 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
49 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070050 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
51 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
52 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
53 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050054 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050055 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin01784b42016-06-07 18:00:52 -040056 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
David Benjamin2e045a92016-06-08 13:09:56 -040057 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
Adam Langley69a01602014-11-17 17:26:55 -080058)
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin33863262016-07-08 17:20:12 -070060type testCert int
61
David Benjamin025b3d32014-07-01 19:53:04 -040062const (
David Benjamin33863262016-07-08 17:20:12 -070063 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040064 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070065 testCertECDSAP256
66 testCertECDSAP384
67 testCertECDSAP521
68)
69
70const (
71 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040072 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070073 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
74 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
75 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040076)
77
78const (
David Benjamina08e49d2014-08-24 01:46:07 -040079 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040080 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -070081 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
82 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
83 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040084 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040085)
86
David Benjamin7944a9f2016-07-12 22:27:01 -040087var (
88 rsaCertificate Certificate
89 rsa1024Certificate Certificate
90 ecdsaP256Certificate Certificate
91 ecdsaP384Certificate Certificate
92 ecdsaP521Certificate Certificate
93)
David Benjamin33863262016-07-08 17:20:12 -070094
95var testCerts = []struct {
96 id testCert
97 certFile, keyFile string
98 cert *Certificate
99}{
100 {
101 id: testCertRSA,
102 certFile: rsaCertificateFile,
103 keyFile: rsaKeyFile,
104 cert: &rsaCertificate,
105 },
106 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400107 id: testCertRSA1024,
108 certFile: rsa1024CertificateFile,
109 keyFile: rsa1024KeyFile,
110 cert: &rsa1024Certificate,
111 },
112 {
David Benjamin33863262016-07-08 17:20:12 -0700113 id: testCertECDSAP256,
114 certFile: ecdsaP256CertificateFile,
115 keyFile: ecdsaP256KeyFile,
116 cert: &ecdsaP256Certificate,
117 },
118 {
119 id: testCertECDSAP384,
120 certFile: ecdsaP384CertificateFile,
121 keyFile: ecdsaP384KeyFile,
122 cert: &ecdsaP384Certificate,
123 },
124 {
125 id: testCertECDSAP521,
126 certFile: ecdsaP521CertificateFile,
127 keyFile: ecdsaP521KeyFile,
128 cert: &ecdsaP521Certificate,
129 },
130}
131
David Benjamina08e49d2014-08-24 01:46:07 -0400132var channelIDKey *ecdsa.PrivateKey
133var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700134
David Benjamin61f95272014-11-25 01:55:35 -0500135var testOCSPResponse = []byte{1, 2, 3, 4}
136var testSCTList = []byte{5, 6, 7, 8}
137
Adam Langley95c29f32014-06-20 12:00:00 -0700138func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700139 for i := range testCerts {
140 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
141 if err != nil {
142 panic(err)
143 }
144 cert.OCSPStaple = testOCSPResponse
145 cert.SignedCertificateTimestampList = testSCTList
146 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700147 }
David Benjamina08e49d2014-08-24 01:46:07 -0400148
Adam Langley7c803a62015-06-15 15:35:05 -0700149 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400150 if err != nil {
151 panic(err)
152 }
153 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
154 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
155 panic("bad key type")
156 }
157 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
158 if err != nil {
159 panic(err)
160 }
161 if channelIDKey.Curve != elliptic.P256() {
162 panic("bad curve")
163 }
164
165 channelIDBytes = make([]byte, 64)
166 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
167 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700168}
169
David Benjamin33863262016-07-08 17:20:12 -0700170func getRunnerCertificate(t testCert) Certificate {
171 for _, cert := range testCerts {
172 if cert.id == t {
173 return *cert.cert
174 }
175 }
176 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700177}
178
David Benjamin33863262016-07-08 17:20:12 -0700179func getShimCertificate(t testCert) string {
180 for _, cert := range testCerts {
181 if cert.id == t {
182 return cert.certFile
183 }
184 }
185 panic("Unknown test certificate")
186}
187
188func getShimKey(t testCert) string {
189 for _, cert := range testCerts {
190 if cert.id == t {
191 return cert.keyFile
192 }
193 }
194 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700195}
196
David Benjamin025b3d32014-07-01 19:53:04 -0400197type testType int
198
199const (
200 clientTest testType = iota
201 serverTest
202)
203
David Benjamin6fd297b2014-08-11 18:43:38 -0400204type protocol int
205
206const (
207 tls protocol = iota
208 dtls
209)
210
David Benjaminfc7b0862014-09-06 13:21:53 -0400211const (
212 alpn = 1
213 npn = 2
214)
215
Adam Langley95c29f32014-06-20 12:00:00 -0700216type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400217 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400218 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700219 name string
220 config Config
221 shouldFail bool
222 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700223 // expectedLocalError, if not empty, contains a substring that must be
224 // found in the local error.
225 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400226 // expectedVersion, if non-zero, specifies the TLS version that must be
227 // negotiated.
228 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400229 // expectedResumeVersion, if non-zero, specifies the TLS version that
230 // must be negotiated on resumption. If zero, expectedVersion is used.
231 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400232 // expectedCipher, if non-zero, specifies the TLS cipher suite that
233 // should be negotiated.
234 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400235 // expectChannelID controls whether the connection should have
236 // negotiated a Channel ID with channelIDKey.
237 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400238 // expectedNextProto controls whether the connection should
239 // negotiate a next protocol via NPN or ALPN.
240 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400241 // expectNoNextProto, if true, means that no next protocol should be
242 // negotiated.
243 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400244 // expectedNextProtoType, if non-zero, is the expected next
245 // protocol negotiation mechanism.
246 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500247 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
248 // should be negotiated. If zero, none should be negotiated.
249 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100250 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
251 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100252 // expectedSCTList, if not nil, is the expected SCT list to be received.
253 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700254 // expectedPeerSignatureAlgorithm, if not zero, is the signature
255 // algorithm that the peer should have used in the handshake.
256 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700257 // messageLen is the length, in bytes, of the test message that will be
258 // sent.
259 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400260 // messageCount is the number of test messages that will be sent.
261 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400262 // digestPrefs is the list of digest preferences from the client.
263 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400264 // certFile is the path to the certificate to use for the server.
265 certFile string
266 // keyFile is the path to the private key to use for the server.
267 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400268 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400269 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400270 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700271 // expectResumeRejected, if true, specifies that the attempted
272 // resumption must be rejected by the client. This is only valid for a
273 // serverTest.
274 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400275 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500276 // resumption. Unless newSessionsOnResume is set,
277 // SessionTicketKey, ServerSessionCache, and
278 // ClientSessionCache are copied from the initial connection's
279 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400280 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500281 // newSessionsOnResume, if true, will cause resumeConfig to
282 // use a different session resumption context.
283 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400284 // noSessionCache, if true, will cause the server to run without a
285 // session cache.
286 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400287 // sendPrefix sends a prefix on the socket before actually performing a
288 // handshake.
289 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400290 // shimWritesFirst controls whether the shim sends an initial "hello"
291 // message before doing a roundtrip with the runner.
292 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400293 // shimShutsDown, if true, runs a test where the shim shuts down the
294 // connection immediately after the handshake rather than echoing
295 // messages from the runner.
296 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400297 // renegotiate indicates the number of times the connection should be
298 // renegotiated during the exchange.
299 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700300 // renegotiateCiphers is a list of ciphersuite ids that will be
301 // switched in just before renegotiation.
302 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500303 // replayWrites, if true, configures the underlying transport
304 // to replay every write it makes in DTLS tests.
305 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500306 // damageFirstWrite, if true, configures the underlying transport to
307 // damage the final byte of the first application data write.
308 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400309 // exportKeyingMaterial, if non-zero, configures the test to exchange
310 // keying material and verify they match.
311 exportKeyingMaterial int
312 exportLabel string
313 exportContext string
314 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400315 // flags, if not empty, contains a list of command-line flags that will
316 // be passed to the shim program.
317 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700318 // testTLSUnique, if true, causes the shim to send the tls-unique value
319 // which will be compared against the expected value.
320 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400321 // sendEmptyRecords is the number of consecutive empty records to send
322 // before and after the test message.
323 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400324 // sendWarningAlerts is the number of consecutive warning alerts to send
325 // before and after the test message.
326 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400327 // expectMessageDropped, if true, means the test message is expected to
328 // be dropped by the client rather than echoed back.
329 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700330}
331
Adam Langley7c803a62015-06-15 15:35:05 -0700332var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700333
David Benjamin9867b7d2016-03-01 23:25:48 -0500334func writeTranscript(test *testCase, isResume bool, data []byte) {
335 if len(data) == 0 {
336 return
337 }
338
339 protocol := "tls"
340 if test.protocol == dtls {
341 protocol = "dtls"
342 }
343
344 side := "client"
345 if test.testType == serverTest {
346 side = "server"
347 }
348
349 dir := path.Join(*transcriptDir, protocol, side)
350 if err := os.MkdirAll(dir, 0755); err != nil {
351 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
352 return
353 }
354
355 name := test.name
356 if isResume {
357 name += "-Resume"
358 } else {
359 name += "-Normal"
360 }
361
362 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
363 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
364 }
365}
366
David Benjamin3ed59772016-03-08 12:50:21 -0500367// A timeoutConn implements an idle timeout on each Read and Write operation.
368type timeoutConn struct {
369 net.Conn
370 timeout time.Duration
371}
372
373func (t *timeoutConn) Read(b []byte) (int, error) {
374 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
375 return 0, err
376 }
377 return t.Conn.Read(b)
378}
379
380func (t *timeoutConn) Write(b []byte) (int, error) {
381 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
382 return 0, err
383 }
384 return t.Conn.Write(b)
385}
386
David Benjamin8e6db492015-07-25 18:29:23 -0400387func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400388 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500389
David Benjamin6fd297b2014-08-11 18:43:38 -0400390 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500391 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
392 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500393 }
394
David Benjamin9867b7d2016-03-01 23:25:48 -0500395 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500396 local, peer := "client", "server"
397 if test.testType == clientTest {
398 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500399 }
David Benjaminebda9b32015-11-02 15:33:18 -0500400 connDebug := &recordingConn{
401 Conn: conn,
402 isDatagram: test.protocol == dtls,
403 local: local,
404 peer: peer,
405 }
406 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500407 if *flagDebug {
408 defer connDebug.WriteTo(os.Stdout)
409 }
410 if len(*transcriptDir) != 0 {
411 defer func() {
412 writeTranscript(test, isResume, connDebug.Transcript())
413 }()
414 }
David Benjaminebda9b32015-11-02 15:33:18 -0500415
416 if config.Bugs.PacketAdaptor != nil {
417 config.Bugs.PacketAdaptor.debug = connDebug
418 }
419 }
420
421 if test.replayWrites {
422 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400423 }
424
David Benjamin3ed59772016-03-08 12:50:21 -0500425 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500426 if test.damageFirstWrite {
427 connDamage = newDamageAdaptor(conn)
428 conn = connDamage
429 }
430
David Benjamin6fd297b2014-08-11 18:43:38 -0400431 if test.sendPrefix != "" {
432 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
433 return err
434 }
David Benjamin98e882e2014-08-08 13:24:34 -0400435 }
436
David Benjamin1d5c83e2014-07-22 19:20:02 -0400437 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400438 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400439 if test.protocol == dtls {
440 tlsConn = DTLSServer(conn, config)
441 } else {
442 tlsConn = Server(conn, config)
443 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400444 } else {
445 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400446 if test.protocol == dtls {
447 tlsConn = DTLSClient(conn, config)
448 } else {
449 tlsConn = Client(conn, config)
450 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400451 }
David Benjamin30789da2015-08-29 22:56:45 -0400452 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400453
Adam Langley95c29f32014-06-20 12:00:00 -0700454 if err := tlsConn.Handshake(); err != nil {
455 return err
456 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700457
David Benjamin01fe8202014-09-24 15:21:44 -0400458 // TODO(davidben): move all per-connection expectations into a dedicated
459 // expectations struct that can be specified separately for the two
460 // legs.
461 expectedVersion := test.expectedVersion
462 if isResume && test.expectedResumeVersion != 0 {
463 expectedVersion = test.expectedResumeVersion
464 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700465 connState := tlsConn.ConnectionState()
466 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400467 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400468 }
469
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700470 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400471 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
472 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700473 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
474 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
475 }
David Benjamin90da8c82015-04-20 14:57:57 -0400476
David Benjamina08e49d2014-08-24 01:46:07 -0400477 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700478 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400479 if channelID == nil {
480 return fmt.Errorf("no channel ID negotiated")
481 }
482 if channelID.Curve != channelIDKey.Curve ||
483 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
484 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
485 return fmt.Errorf("incorrect channel ID")
486 }
487 }
488
David Benjaminae2888f2014-09-06 12:58:58 -0400489 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700490 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400491 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
492 }
493 }
494
David Benjaminc7ce9772015-10-09 19:32:41 -0400495 if test.expectNoNextProto {
496 if actual := connState.NegotiatedProtocol; actual != "" {
497 return fmt.Errorf("got unexpected next proto %s", actual)
498 }
499 }
500
David Benjaminfc7b0862014-09-06 13:21:53 -0400501 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700502 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400503 return fmt.Errorf("next proto type mismatch")
504 }
505 }
506
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700507 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500508 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
509 }
510
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100511 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
512 return fmt.Errorf("OCSP Response mismatch")
513 }
514
Paul Lietar4fac72e2015-09-09 13:44:55 +0100515 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
516 return fmt.Errorf("SCT list mismatch")
517 }
518
Nick Harper60edffd2016-06-21 15:19:24 -0700519 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
520 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400521 }
522
David Benjaminc565ebb2015-04-03 04:06:36 -0400523 if test.exportKeyingMaterial > 0 {
524 actual := make([]byte, test.exportKeyingMaterial)
525 if _, err := io.ReadFull(tlsConn, actual); err != nil {
526 return err
527 }
528 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
529 if err != nil {
530 return err
531 }
532 if !bytes.Equal(actual, expected) {
533 return fmt.Errorf("keying material mismatch")
534 }
535 }
536
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700537 if test.testTLSUnique {
538 var peersValue [12]byte
539 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
540 return err
541 }
542 expected := tlsConn.ConnectionState().TLSUnique
543 if !bytes.Equal(peersValue[:], expected) {
544 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
545 }
546 }
547
David Benjamine58c4f52014-08-24 03:47:07 -0400548 if test.shimWritesFirst {
549 var buf [5]byte
550 _, err := io.ReadFull(tlsConn, buf[:])
551 if err != nil {
552 return err
553 }
554 if string(buf[:]) != "hello" {
555 return fmt.Errorf("bad initial message")
556 }
557 }
558
David Benjamina8ebe222015-06-06 03:04:39 -0400559 for i := 0; i < test.sendEmptyRecords; i++ {
560 tlsConn.Write(nil)
561 }
562
David Benjamin24f346d2015-06-06 03:28:08 -0400563 for i := 0; i < test.sendWarningAlerts; i++ {
564 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
565 }
566
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400567 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700568 if test.renegotiateCiphers != nil {
569 config.CipherSuites = test.renegotiateCiphers
570 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400571 for i := 0; i < test.renegotiate; i++ {
572 if err := tlsConn.Renegotiate(); err != nil {
573 return err
574 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700575 }
576 } else if test.renegotiateCiphers != nil {
577 panic("renegotiateCiphers without renegotiate")
578 }
579
David Benjamin5fa3eba2015-01-22 16:35:40 -0500580 if test.damageFirstWrite {
581 connDamage.setDamage(true)
582 tlsConn.Write([]byte("DAMAGED WRITE"))
583 connDamage.setDamage(false)
584 }
585
David Benjamin8e6db492015-07-25 18:29:23 -0400586 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700587 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400588 if test.protocol == dtls {
589 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
590 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700591 // Read until EOF.
592 _, err := io.Copy(ioutil.Discard, tlsConn)
593 return err
594 }
David Benjamin4417d052015-04-05 04:17:25 -0400595 if messageLen == 0 {
596 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700597 }
Adam Langley95c29f32014-06-20 12:00:00 -0700598
David Benjamin8e6db492015-07-25 18:29:23 -0400599 messageCount := test.messageCount
600 if messageCount == 0 {
601 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400602 }
603
David Benjamin8e6db492015-07-25 18:29:23 -0400604 for j := 0; j < messageCount; j++ {
605 testMessage := make([]byte, messageLen)
606 for i := range testMessage {
607 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400608 }
David Benjamin8e6db492015-07-25 18:29:23 -0400609 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700610
David Benjamin8e6db492015-07-25 18:29:23 -0400611 for i := 0; i < test.sendEmptyRecords; i++ {
612 tlsConn.Write(nil)
613 }
614
615 for i := 0; i < test.sendWarningAlerts; i++ {
616 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
617 }
618
David Benjamin4f75aaf2015-09-01 16:53:10 -0400619 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400620 // The shim will not respond.
621 continue
622 }
623
David Benjamin8e6db492015-07-25 18:29:23 -0400624 buf := make([]byte, len(testMessage))
625 if test.protocol == dtls {
626 bufTmp := make([]byte, len(buf)+1)
627 n, err := tlsConn.Read(bufTmp)
628 if err != nil {
629 return err
630 }
631 if n != len(buf) {
632 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
633 }
634 copy(buf, bufTmp)
635 } else {
636 _, err := io.ReadFull(tlsConn, buf)
637 if err != nil {
638 return err
639 }
640 }
641
642 for i, v := range buf {
643 if v != testMessage[i]^0xff {
644 return fmt.Errorf("bad reply contents at byte %d", i)
645 }
Adam Langley95c29f32014-06-20 12:00:00 -0700646 }
647 }
648
649 return nil
650}
651
David Benjamin325b5c32014-07-01 19:40:31 -0400652func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
653 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700654 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400655 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700656 }
David Benjamin325b5c32014-07-01 19:40:31 -0400657 valgrindArgs = append(valgrindArgs, path)
658 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700659
David Benjamin325b5c32014-07-01 19:40:31 -0400660 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700661}
662
David Benjamin325b5c32014-07-01 19:40:31 -0400663func gdbOf(path string, args ...string) *exec.Cmd {
664 xtermArgs := []string{"-e", "gdb", "--args"}
665 xtermArgs = append(xtermArgs, path)
666 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700667
David Benjamin325b5c32014-07-01 19:40:31 -0400668 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700669}
670
David Benjamind16bf342015-12-18 00:53:12 -0500671func lldbOf(path string, args ...string) *exec.Cmd {
672 xtermArgs := []string{"-e", "lldb", "--"}
673 xtermArgs = append(xtermArgs, path)
674 xtermArgs = append(xtermArgs, args...)
675
676 return exec.Command("xterm", xtermArgs...)
677}
678
Adam Langley69a01602014-11-17 17:26:55 -0800679type moreMallocsError struct{}
680
681func (moreMallocsError) Error() string {
682 return "child process did not exhaust all allocation calls"
683}
684
685var errMoreMallocs = moreMallocsError{}
686
David Benjamin87c8a642015-02-21 01:54:29 -0500687// accept accepts a connection from listener, unless waitChan signals a process
688// exit first.
689func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
690 type connOrError struct {
691 conn net.Conn
692 err error
693 }
694 connChan := make(chan connOrError, 1)
695 go func() {
696 conn, err := listener.Accept()
697 connChan <- connOrError{conn, err}
698 close(connChan)
699 }()
700 select {
701 case result := <-connChan:
702 return result.conn, result.err
703 case childErr := <-waitChan:
704 waitChan <- childErr
705 return nil, fmt.Errorf("child exited early: %s", childErr)
706 }
707}
708
Adam Langley7c803a62015-06-15 15:35:05 -0700709func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700710 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
711 panic("Error expected without shouldFail in " + test.name)
712 }
713
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700714 if test.expectResumeRejected && !test.resumeSession {
715 panic("expectResumeRejected without resumeSession in " + test.name)
716 }
717
David Benjamin87c8a642015-02-21 01:54:29 -0500718 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
719 if err != nil {
720 panic(err)
721 }
722 defer func() {
723 if listener != nil {
724 listener.Close()
725 }
726 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700727
David Benjamin87c8a642015-02-21 01:54:29 -0500728 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400729 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400730 flags = append(flags, "-server")
731
David Benjamin025b3d32014-07-01 19:53:04 -0400732 flags = append(flags, "-key-file")
733 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700734 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400735 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700736 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400737 }
738
739 flags = append(flags, "-cert-file")
740 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700741 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400742 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700743 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400744 }
745 }
David Benjamin5a593af2014-08-11 19:51:50 -0400746
Steven Valdez0d62f262015-09-04 12:41:04 -0400747 if test.digestPrefs != "" {
748 flags = append(flags, "-digest-prefs")
749 flags = append(flags, test.digestPrefs)
750 }
751
David Benjamin6fd297b2014-08-11 18:43:38 -0400752 if test.protocol == dtls {
753 flags = append(flags, "-dtls")
754 }
755
David Benjamin5a593af2014-08-11 19:51:50 -0400756 if test.resumeSession {
757 flags = append(flags, "-resume")
758 }
759
David Benjamine58c4f52014-08-24 03:47:07 -0400760 if test.shimWritesFirst {
761 flags = append(flags, "-shim-writes-first")
762 }
763
David Benjamin30789da2015-08-29 22:56:45 -0400764 if test.shimShutsDown {
765 flags = append(flags, "-shim-shuts-down")
766 }
767
David Benjaminc565ebb2015-04-03 04:06:36 -0400768 if test.exportKeyingMaterial > 0 {
769 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
770 flags = append(flags, "-export-label", test.exportLabel)
771 flags = append(flags, "-export-context", test.exportContext)
772 if test.useExportContext {
773 flags = append(flags, "-use-export-context")
774 }
775 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700776 if test.expectResumeRejected {
777 flags = append(flags, "-expect-session-miss")
778 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400779
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700780 if test.testTLSUnique {
781 flags = append(flags, "-tls-unique")
782 }
783
David Benjamin025b3d32014-07-01 19:53:04 -0400784 flags = append(flags, test.flags...)
785
786 var shim *exec.Cmd
787 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700788 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700789 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700790 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500791 } else if *useLLDB {
792 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400793 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700794 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400795 }
David Benjamin025b3d32014-07-01 19:53:04 -0400796 shim.Stdin = os.Stdin
797 var stdoutBuf, stderrBuf bytes.Buffer
798 shim.Stdout = &stdoutBuf
799 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800800 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500801 shim.Env = os.Environ()
802 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800803 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400804 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800805 }
806 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
807 }
David Benjamin025b3d32014-07-01 19:53:04 -0400808
809 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700810 panic(err)
811 }
David Benjamin87c8a642015-02-21 01:54:29 -0500812 waitChan := make(chan error, 1)
813 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700814
815 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400816 if !test.noSessionCache {
817 config.ClientSessionCache = NewLRUClientSessionCache(1)
818 config.ServerSessionCache = NewLRUServerSessionCache(1)
819 }
David Benjamin025b3d32014-07-01 19:53:04 -0400820 if test.testType == clientTest {
821 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700822 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400823 }
David Benjamin87c8a642015-02-21 01:54:29 -0500824 } else {
825 // Supply a ServerName to ensure a constant session cache key,
826 // rather than falling back to net.Conn.RemoteAddr.
827 if len(config.ServerName) == 0 {
828 config.ServerName = "test"
829 }
David Benjamin025b3d32014-07-01 19:53:04 -0400830 }
David Benjaminf2b83632016-03-01 22:57:46 -0500831 if *fuzzer {
832 config.Bugs.NullAllCiphers = true
833 }
David Benjamin2e045a92016-06-08 13:09:56 -0400834 if *deterministic {
835 config.Rand = &deterministicRand{}
836 }
Adam Langley95c29f32014-06-20 12:00:00 -0700837
David Benjamin87c8a642015-02-21 01:54:29 -0500838 conn, err := acceptOrWait(listener, waitChan)
839 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400840 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500841 conn.Close()
842 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500843
David Benjamin1d5c83e2014-07-22 19:20:02 -0400844 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400845 var resumeConfig Config
846 if test.resumeConfig != nil {
847 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500848 if len(resumeConfig.ServerName) == 0 {
849 resumeConfig.ServerName = config.ServerName
850 }
David Benjamin01fe8202014-09-24 15:21:44 -0400851 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700852 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400853 }
David Benjaminba4594a2015-06-18 18:36:15 -0400854 if test.newSessionsOnResume {
855 if !test.noSessionCache {
856 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
857 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
858 }
859 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500860 resumeConfig.SessionTicketKey = config.SessionTicketKey
861 resumeConfig.ClientSessionCache = config.ClientSessionCache
862 resumeConfig.ServerSessionCache = config.ServerSessionCache
863 }
David Benjaminf2b83632016-03-01 22:57:46 -0500864 if *fuzzer {
865 resumeConfig.Bugs.NullAllCiphers = true
866 }
David Benjamin2e045a92016-06-08 13:09:56 -0400867 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400868 } else {
869 resumeConfig = config
870 }
David Benjamin87c8a642015-02-21 01:54:29 -0500871 var connResume net.Conn
872 connResume, err = acceptOrWait(listener, waitChan)
873 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400874 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500875 connResume.Close()
876 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400877 }
878
David Benjamin87c8a642015-02-21 01:54:29 -0500879 // Close the listener now. This is to avoid hangs should the shim try to
880 // open more connections than expected.
881 listener.Close()
882 listener = nil
883
884 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800885 if exitError, ok := childErr.(*exec.ExitError); ok {
886 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
887 return errMoreMallocs
888 }
889 }
Adam Langley95c29f32014-06-20 12:00:00 -0700890
David Benjamin9bea3492016-03-02 10:59:16 -0500891 // Account for Windows line endings.
892 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
893 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500894
895 // Separate the errors from the shim and those from tools like
896 // AddressSanitizer.
897 var extraStderr string
898 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
899 stderr = stderrParts[0]
900 extraStderr = stderrParts[1]
901 }
902
Adam Langley95c29f32014-06-20 12:00:00 -0700903 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400904 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700905 localError := "none"
906 if err != nil {
907 localError = err.Error()
908 }
909 if len(test.expectedLocalError) != 0 {
910 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
911 }
Adam Langley95c29f32014-06-20 12:00:00 -0700912
913 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700914 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700915 if childErr != nil {
916 childError = childErr.Error()
917 }
918
919 var msg string
920 switch {
921 case failed && !test.shouldFail:
922 msg = "unexpected failure"
923 case !failed && test.shouldFail:
924 msg = "unexpected success"
925 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700926 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700927 default:
928 panic("internal error")
929 }
930
David Benjaminc565ebb2015-04-03 04:06:36 -0400931 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700932 }
933
David Benjaminff3a1492016-03-02 10:12:06 -0500934 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
935 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700936 }
937
938 return nil
939}
940
941var tlsVersions = []struct {
942 name string
943 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400944 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500945 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700946}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500947 {"SSL3", VersionSSL30, "-no-ssl3", false},
948 {"TLS1", VersionTLS10, "-no-tls1", true},
949 {"TLS11", VersionTLS11, "-no-tls11", false},
950 {"TLS12", VersionTLS12, "-no-tls12", true},
Nick Harper1fd39d82016-06-14 18:14:35 -0700951 // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here.
952 {"FakeTLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700953}
954
955var testCipherSuites = []struct {
956 name string
957 id uint16
958}{
959 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400960 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700961 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400962 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400963 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700964 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400965 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400966 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
967 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400968 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400969 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
970 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400971 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
973 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400974 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
975 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700976 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400977 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500978 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500979 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700980 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700982 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400983 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400984 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700985 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400986 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500987 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500988 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700989 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700990 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
991 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
992 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
993 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400994 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
995 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700996 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
997 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500998 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400999 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1000 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001001 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001002 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001003 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001004 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001005}
1006
David Benjamin8b8c0062014-11-23 02:47:52 -05001007func hasComponent(suiteName, component string) bool {
1008 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1009}
1010
David Benjaminf7768e42014-08-31 02:06:47 -04001011func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001012 return hasComponent(suiteName, "GCM") ||
1013 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001014 hasComponent(suiteName, "SHA384") ||
1015 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001016}
1017
Nick Harper1fd39d82016-06-14 18:14:35 -07001018func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001019 // Only AEADs.
1020 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1021 return false
1022 }
1023 // No old CHACHA20_POLY1305.
1024 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1025 return false
1026 }
1027 // Must have ECDHE.
1028 // TODO(davidben,svaldez): Add pure PSK support.
1029 if !hasComponent(suiteName, "ECDHE") {
1030 return false
1031 }
1032 // TODO(davidben,svaldez): Add PSK support.
1033 if hasComponent(suiteName, "PSK") {
1034 return false
1035 }
1036 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001037}
1038
David Benjamin8b8c0062014-11-23 02:47:52 -05001039func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001040 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001041}
1042
Adam Langleya7997f12015-05-14 17:38:50 -07001043func bigFromHex(hex string) *big.Int {
1044 ret, ok := new(big.Int).SetString(hex, 16)
1045 if !ok {
1046 panic("failed to parse hex number 0x" + hex)
1047 }
1048 return ret
1049}
1050
Adam Langley7c803a62015-06-15 15:35:05 -07001051func addBasicTests() {
1052 basicTests := []testCase{
1053 {
1054 name: "BadRSASignature",
1055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001056 // TODO(davidben): Add a TLS 1.3 version of this.
1057 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001058 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1059 Bugs: ProtocolBugs{
1060 InvalidSKXSignature: true,
1061 },
1062 },
1063 shouldFail: true,
1064 expectedError: ":BAD_SIGNATURE:",
1065 },
1066 {
1067 name: "BadECDSASignature",
1068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001069 // TODO(davidben): Add a TLS 1.3 version of this.
1070 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001071 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1072 Bugs: ProtocolBugs{
1073 InvalidSKXSignature: true,
1074 },
David Benjamin33863262016-07-08 17:20:12 -07001075 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001076 },
1077 shouldFail: true,
1078 expectedError: ":BAD_SIGNATURE:",
1079 },
1080 {
David Benjamin6de0e532015-07-28 22:43:19 -04001081 testType: serverTest,
1082 name: "BadRSASignature-ClientAuth",
1083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001084 // TODO(davidben): Add a TLS 1.3 version of this.
1085 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001086 Bugs: ProtocolBugs{
1087 InvalidCertVerifySignature: true,
1088 },
David Benjamin33863262016-07-08 17:20:12 -07001089 Certificates: []Certificate{rsaCertificate},
David Benjamin6de0e532015-07-28 22:43:19 -04001090 },
1091 shouldFail: true,
1092 expectedError: ":BAD_SIGNATURE:",
1093 flags: []string{"-require-any-client-certificate"},
1094 },
1095 {
1096 testType: serverTest,
1097 name: "BadECDSASignature-ClientAuth",
1098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001099 // TODO(davidben): Add a TLS 1.3 version of this.
1100 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001101 Bugs: ProtocolBugs{
1102 InvalidCertVerifySignature: true,
1103 },
David Benjamin33863262016-07-08 17:20:12 -07001104 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin6de0e532015-07-28 22:43:19 -04001105 },
1106 shouldFail: true,
1107 expectedError: ":BAD_SIGNATURE:",
1108 flags: []string{"-require-any-client-certificate"},
1109 },
1110 {
Adam Langley7c803a62015-06-15 15:35:05 -07001111 name: "NoFallbackSCSV",
1112 config: Config{
1113 Bugs: ProtocolBugs{
1114 FailIfNotFallbackSCSV: true,
1115 },
1116 },
1117 shouldFail: true,
1118 expectedLocalError: "no fallback SCSV found",
1119 },
1120 {
1121 name: "SendFallbackSCSV",
1122 config: Config{
1123 Bugs: ProtocolBugs{
1124 FailIfNotFallbackSCSV: true,
1125 },
1126 },
1127 flags: []string{"-fallback-scsv"},
1128 },
1129 {
1130 name: "ClientCertificateTypes",
1131 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001132 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001133 ClientAuth: RequestClientCert,
1134 ClientCertificateTypes: []byte{
1135 CertTypeDSSSign,
1136 CertTypeRSASign,
1137 CertTypeECDSASign,
1138 },
1139 },
1140 flags: []string{
1141 "-expect-certificate-types",
1142 base64.StdEncoding.EncodeToString([]byte{
1143 CertTypeDSSSign,
1144 CertTypeRSASign,
1145 CertTypeECDSASign,
1146 }),
1147 },
1148 },
1149 {
Adam Langley7c803a62015-06-15 15:35:05 -07001150 name: "UnauthenticatedECDH",
1151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001152 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1154 Bugs: ProtocolBugs{
1155 UnauthenticatedECDH: true,
1156 },
1157 },
1158 shouldFail: true,
1159 expectedError: ":UNEXPECTED_MESSAGE:",
1160 },
1161 {
1162 name: "SkipCertificateStatus",
1163 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001164 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001165 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1166 Bugs: ProtocolBugs{
1167 SkipCertificateStatus: true,
1168 },
1169 },
1170 flags: []string{
1171 "-enable-ocsp-stapling",
1172 },
1173 },
1174 {
1175 name: "SkipServerKeyExchange",
1176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001177 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001178 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1179 Bugs: ProtocolBugs{
1180 SkipServerKeyExchange: true,
1181 },
1182 },
1183 shouldFail: true,
1184 expectedError: ":UNEXPECTED_MESSAGE:",
1185 },
1186 {
Adam Langley7c803a62015-06-15 15:35:05 -07001187 testType: serverTest,
1188 name: "Alert",
1189 config: Config{
1190 Bugs: ProtocolBugs{
1191 SendSpuriousAlert: alertRecordOverflow,
1192 },
1193 },
1194 shouldFail: true,
1195 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1196 },
1197 {
1198 protocol: dtls,
1199 testType: serverTest,
1200 name: "Alert-DTLS",
1201 config: Config{
1202 Bugs: ProtocolBugs{
1203 SendSpuriousAlert: alertRecordOverflow,
1204 },
1205 },
1206 shouldFail: true,
1207 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1208 },
1209 {
1210 testType: serverTest,
1211 name: "FragmentAlert",
1212 config: Config{
1213 Bugs: ProtocolBugs{
1214 FragmentAlert: true,
1215 SendSpuriousAlert: alertRecordOverflow,
1216 },
1217 },
1218 shouldFail: true,
1219 expectedError: ":BAD_ALERT:",
1220 },
1221 {
1222 protocol: dtls,
1223 testType: serverTest,
1224 name: "FragmentAlert-DTLS",
1225 config: Config{
1226 Bugs: ProtocolBugs{
1227 FragmentAlert: true,
1228 SendSpuriousAlert: alertRecordOverflow,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":BAD_ALERT:",
1233 },
1234 {
1235 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001236 name: "DoubleAlert",
1237 config: Config{
1238 Bugs: ProtocolBugs{
1239 DoubleAlert: true,
1240 SendSpuriousAlert: alertRecordOverflow,
1241 },
1242 },
1243 shouldFail: true,
1244 expectedError: ":BAD_ALERT:",
1245 },
1246 {
1247 protocol: dtls,
1248 testType: serverTest,
1249 name: "DoubleAlert-DTLS",
1250 config: Config{
1251 Bugs: ProtocolBugs{
1252 DoubleAlert: true,
1253 SendSpuriousAlert: alertRecordOverflow,
1254 },
1255 },
1256 shouldFail: true,
1257 expectedError: ":BAD_ALERT:",
1258 },
1259 {
Adam Langley7c803a62015-06-15 15:35:05 -07001260 name: "SkipNewSessionTicket",
1261 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001262 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001263 Bugs: ProtocolBugs{
1264 SkipNewSessionTicket: true,
1265 },
1266 },
1267 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001268 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001269 },
1270 {
1271 testType: serverTest,
1272 name: "FallbackSCSV",
1273 config: Config{
1274 MaxVersion: VersionTLS11,
1275 Bugs: ProtocolBugs{
1276 SendFallbackSCSV: true,
1277 },
1278 },
1279 shouldFail: true,
1280 expectedError: ":INAPPROPRIATE_FALLBACK:",
1281 },
1282 {
1283 testType: serverTest,
1284 name: "FallbackSCSV-VersionMatch",
1285 config: Config{
1286 Bugs: ProtocolBugs{
1287 SendFallbackSCSV: true,
1288 },
1289 },
1290 },
1291 {
1292 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001293 name: "FallbackSCSV-VersionMatch-TLS12",
1294 config: Config{
1295 MaxVersion: VersionTLS12,
1296 Bugs: ProtocolBugs{
1297 SendFallbackSCSV: true,
1298 },
1299 },
1300 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1301 },
1302 {
1303 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001304 name: "FragmentedClientVersion",
1305 config: Config{
1306 Bugs: ProtocolBugs{
1307 MaxHandshakeRecordLength: 1,
1308 FragmentClientVersion: true,
1309 },
1310 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001311 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001312 },
1313 {
Adam Langley7c803a62015-06-15 15:35:05 -07001314 testType: serverTest,
1315 name: "HttpGET",
1316 sendPrefix: "GET / HTTP/1.0\n",
1317 shouldFail: true,
1318 expectedError: ":HTTP_REQUEST:",
1319 },
1320 {
1321 testType: serverTest,
1322 name: "HttpPOST",
1323 sendPrefix: "POST / HTTP/1.0\n",
1324 shouldFail: true,
1325 expectedError: ":HTTP_REQUEST:",
1326 },
1327 {
1328 testType: serverTest,
1329 name: "HttpHEAD",
1330 sendPrefix: "HEAD / HTTP/1.0\n",
1331 shouldFail: true,
1332 expectedError: ":HTTP_REQUEST:",
1333 },
1334 {
1335 testType: serverTest,
1336 name: "HttpPUT",
1337 sendPrefix: "PUT / HTTP/1.0\n",
1338 shouldFail: true,
1339 expectedError: ":HTTP_REQUEST:",
1340 },
1341 {
1342 testType: serverTest,
1343 name: "HttpCONNECT",
1344 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1345 shouldFail: true,
1346 expectedError: ":HTTPS_PROXY_REQUEST:",
1347 },
1348 {
1349 testType: serverTest,
1350 name: "Garbage",
1351 sendPrefix: "blah",
1352 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001353 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001354 },
1355 {
Adam Langley7c803a62015-06-15 15:35:05 -07001356 name: "RSAEphemeralKey",
1357 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001358 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001359 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1360 Bugs: ProtocolBugs{
1361 RSAEphemeralKey: true,
1362 },
1363 },
1364 shouldFail: true,
1365 expectedError: ":UNEXPECTED_MESSAGE:",
1366 },
1367 {
1368 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001369 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001370 shouldFail: true,
1371 expectedError: ":WRONG_SSL_VERSION:",
1372 },
1373 {
1374 protocol: dtls,
1375 name: "DisableEverything-DTLS",
1376 flags: []string{"-no-tls12", "-no-tls1"},
1377 shouldFail: true,
1378 expectedError: ":WRONG_SSL_VERSION:",
1379 },
1380 {
Adam Langley7c803a62015-06-15 15:35:05 -07001381 protocol: dtls,
1382 testType: serverTest,
1383 name: "MTU",
1384 config: Config{
1385 Bugs: ProtocolBugs{
1386 MaxPacketLength: 256,
1387 },
1388 },
1389 flags: []string{"-mtu", "256"},
1390 },
1391 {
1392 protocol: dtls,
1393 testType: serverTest,
1394 name: "MTUExceeded",
1395 config: Config{
1396 Bugs: ProtocolBugs{
1397 MaxPacketLength: 255,
1398 },
1399 },
1400 flags: []string{"-mtu", "256"},
1401 shouldFail: true,
1402 expectedLocalError: "dtls: exceeded maximum packet length",
1403 },
1404 {
1405 name: "CertMismatchRSA",
1406 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001407 // TODO(davidben): Add a TLS 1.3 version of this test.
1408 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001409 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001410 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001411 Bugs: ProtocolBugs{
1412 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1417 },
1418 {
1419 name: "CertMismatchECDSA",
1420 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001421 // TODO(davidben): Add a TLS 1.3 version of this test.
1422 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001423 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001424 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001425 Bugs: ProtocolBugs{
1426 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1427 },
1428 },
1429 shouldFail: true,
1430 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1431 },
1432 {
1433 name: "EmptyCertificateList",
1434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001435 // TODO(davidben): Add a TLS 1.3 version of this test.
1436 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001437 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1438 Bugs: ProtocolBugs{
1439 EmptyCertificateList: true,
1440 },
1441 },
1442 shouldFail: true,
1443 expectedError: ":DECODE_ERROR:",
1444 },
1445 {
1446 name: "TLSFatalBadPackets",
1447 damageFirstWrite: true,
1448 shouldFail: true,
1449 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1450 },
1451 {
1452 protocol: dtls,
1453 name: "DTLSIgnoreBadPackets",
1454 damageFirstWrite: true,
1455 },
1456 {
1457 protocol: dtls,
1458 name: "DTLSIgnoreBadPackets-Async",
1459 damageFirstWrite: true,
1460 flags: []string{"-async"},
1461 },
1462 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001463 name: "AppDataBeforeHandshake",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":UNEXPECTED_RECORD:",
1471 },
1472 {
1473 name: "AppDataBeforeHandshake-Empty",
1474 config: Config{
1475 Bugs: ProtocolBugs{
1476 AppDataBeforeHandshake: []byte{},
1477 },
1478 },
1479 shouldFail: true,
1480 expectedError: ":UNEXPECTED_RECORD:",
1481 },
1482 {
1483 protocol: dtls,
1484 name: "AppDataBeforeHandshake-DTLS",
1485 config: Config{
1486 Bugs: ProtocolBugs{
1487 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1488 },
1489 },
1490 shouldFail: true,
1491 expectedError: ":UNEXPECTED_RECORD:",
1492 },
1493 {
1494 protocol: dtls,
1495 name: "AppDataBeforeHandshake-DTLS-Empty",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 AppDataBeforeHandshake: []byte{},
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":UNEXPECTED_RECORD:",
1503 },
1504 {
Adam Langley7c803a62015-06-15 15:35:05 -07001505 name: "AppDataAfterChangeCipherSpec",
1506 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001507 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001508 Bugs: ProtocolBugs{
1509 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1510 },
1511 },
1512 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001513 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001514 },
1515 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001516 name: "AppDataAfterChangeCipherSpec-Empty",
1517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001518 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001519 Bugs: ProtocolBugs{
1520 AppDataAfterChangeCipherSpec: []byte{},
1521 },
1522 },
1523 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001524 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001525 },
1526 {
Adam Langley7c803a62015-06-15 15:35:05 -07001527 protocol: dtls,
1528 name: "AppDataAfterChangeCipherSpec-DTLS",
1529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001530 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001531 Bugs: ProtocolBugs{
1532 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1533 },
1534 },
1535 // BoringSSL's DTLS implementation will drop the out-of-order
1536 // application data.
1537 },
1538 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001539 protocol: dtls,
1540 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001542 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001543 Bugs: ProtocolBugs{
1544 AppDataAfterChangeCipherSpec: []byte{},
1545 },
1546 },
1547 // BoringSSL's DTLS implementation will drop the out-of-order
1548 // application data.
1549 },
1550 {
Adam Langley7c803a62015-06-15 15:35:05 -07001551 name: "AlertAfterChangeCipherSpec",
1552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001553 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001554 Bugs: ProtocolBugs{
1555 AlertAfterChangeCipherSpec: alertRecordOverflow,
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1560 },
1561 {
1562 protocol: dtls,
1563 name: "AlertAfterChangeCipherSpec-DTLS",
1564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001565 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001566 Bugs: ProtocolBugs{
1567 AlertAfterChangeCipherSpec: alertRecordOverflow,
1568 },
1569 },
1570 shouldFail: true,
1571 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1572 },
1573 {
1574 protocol: dtls,
1575 name: "ReorderHandshakeFragments-Small-DTLS",
1576 config: Config{
1577 Bugs: ProtocolBugs{
1578 ReorderHandshakeFragments: true,
1579 // Small enough that every handshake message is
1580 // fragmented.
1581 MaxHandshakeRecordLength: 2,
1582 },
1583 },
1584 },
1585 {
1586 protocol: dtls,
1587 name: "ReorderHandshakeFragments-Large-DTLS",
1588 config: Config{
1589 Bugs: ProtocolBugs{
1590 ReorderHandshakeFragments: true,
1591 // Large enough that no handshake message is
1592 // fragmented.
1593 MaxHandshakeRecordLength: 2048,
1594 },
1595 },
1596 },
1597 {
1598 protocol: dtls,
1599 name: "MixCompleteMessageWithFragments-DTLS",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 ReorderHandshakeFragments: true,
1603 MixCompleteMessageWithFragments: true,
1604 MaxHandshakeRecordLength: 2,
1605 },
1606 },
1607 },
1608 {
1609 name: "SendInvalidRecordType",
1610 config: Config{
1611 Bugs: ProtocolBugs{
1612 SendInvalidRecordType: true,
1613 },
1614 },
1615 shouldFail: true,
1616 expectedError: ":UNEXPECTED_RECORD:",
1617 },
1618 {
1619 protocol: dtls,
1620 name: "SendInvalidRecordType-DTLS",
1621 config: Config{
1622 Bugs: ProtocolBugs{
1623 SendInvalidRecordType: true,
1624 },
1625 },
1626 shouldFail: true,
1627 expectedError: ":UNEXPECTED_RECORD:",
1628 },
1629 {
1630 name: "FalseStart-SkipServerSecondLeg",
1631 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001632 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001633 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1634 NextProtos: []string{"foo"},
1635 Bugs: ProtocolBugs{
1636 SkipNewSessionTicket: true,
1637 SkipChangeCipherSpec: true,
1638 SkipFinished: true,
1639 ExpectFalseStart: true,
1640 },
1641 },
1642 flags: []string{
1643 "-false-start",
1644 "-handshake-never-done",
1645 "-advertise-alpn", "\x03foo",
1646 },
1647 shimWritesFirst: true,
1648 shouldFail: true,
1649 expectedError: ":UNEXPECTED_RECORD:",
1650 },
1651 {
1652 name: "FalseStart-SkipServerSecondLeg-Implicit",
1653 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001654 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001655 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1656 NextProtos: []string{"foo"},
1657 Bugs: ProtocolBugs{
1658 SkipNewSessionTicket: true,
1659 SkipChangeCipherSpec: true,
1660 SkipFinished: true,
1661 },
1662 },
1663 flags: []string{
1664 "-implicit-handshake",
1665 "-false-start",
1666 "-handshake-never-done",
1667 "-advertise-alpn", "\x03foo",
1668 },
1669 shouldFail: true,
1670 expectedError: ":UNEXPECTED_RECORD:",
1671 },
1672 {
1673 testType: serverTest,
1674 name: "FailEarlyCallback",
1675 flags: []string{"-fail-early-callback"},
1676 shouldFail: true,
1677 expectedError: ":CONNECTION_REJECTED:",
1678 expectedLocalError: "remote error: access denied",
1679 },
1680 {
1681 name: "WrongMessageType",
1682 config: Config{
David Benjamin1edae6b2016-07-13 16:58:23 -04001683 MaxVersion: VersionTLS12,
1684 Bugs: ProtocolBugs{
1685 WrongCertificateMessageType: true,
1686 },
1687 },
1688 shouldFail: true,
1689 expectedError: ":UNEXPECTED_MESSAGE:",
1690 expectedLocalError: "remote error: unexpected message",
1691 },
1692 {
1693 name: "WrongMessageType-TLS13",
1694 config: Config{
Adam Langley7c803a62015-06-15 15:35:05 -07001695 Bugs: ProtocolBugs{
1696 WrongCertificateMessageType: true,
1697 },
1698 },
1699 shouldFail: true,
1700 expectedError: ":UNEXPECTED_MESSAGE:",
1701 expectedLocalError: "remote error: unexpected message",
1702 },
1703 {
1704 protocol: dtls,
1705 name: "WrongMessageType-DTLS",
1706 config: Config{
1707 Bugs: ProtocolBugs{
1708 WrongCertificateMessageType: true,
1709 },
1710 },
1711 shouldFail: true,
1712 expectedError: ":UNEXPECTED_MESSAGE:",
1713 expectedLocalError: "remote error: unexpected message",
1714 },
1715 {
1716 protocol: dtls,
1717 name: "FragmentMessageTypeMismatch-DTLS",
1718 config: Config{
1719 Bugs: ProtocolBugs{
1720 MaxHandshakeRecordLength: 2,
1721 FragmentMessageTypeMismatch: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":FRAGMENT_MISMATCH:",
1726 },
1727 {
1728 protocol: dtls,
1729 name: "FragmentMessageLengthMismatch-DTLS",
1730 config: Config{
1731 Bugs: ProtocolBugs{
1732 MaxHandshakeRecordLength: 2,
1733 FragmentMessageLengthMismatch: true,
1734 },
1735 },
1736 shouldFail: true,
1737 expectedError: ":FRAGMENT_MISMATCH:",
1738 },
1739 {
1740 protocol: dtls,
1741 name: "SplitFragments-Header-DTLS",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 SplitFragments: 2,
1745 },
1746 },
1747 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001748 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001749 },
1750 {
1751 protocol: dtls,
1752 name: "SplitFragments-Boundary-DTLS",
1753 config: Config{
1754 Bugs: ProtocolBugs{
1755 SplitFragments: dtlsRecordHeaderLen,
1756 },
1757 },
1758 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001759 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001760 },
1761 {
1762 protocol: dtls,
1763 name: "SplitFragments-Body-DTLS",
1764 config: Config{
1765 Bugs: ProtocolBugs{
1766 SplitFragments: dtlsRecordHeaderLen + 1,
1767 },
1768 },
1769 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001770 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001771 },
1772 {
1773 protocol: dtls,
1774 name: "SendEmptyFragments-DTLS",
1775 config: Config{
1776 Bugs: ProtocolBugs{
1777 SendEmptyFragments: true,
1778 },
1779 },
1780 },
1781 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001782 name: "BadFinished-Client",
1783 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001784 // TODO(davidben): Add a TLS 1.3 version of this.
1785 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 Bugs: ProtocolBugs{
1787 BadFinished: true,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":DIGEST_CHECK_FAILED:",
1792 },
1793 {
1794 testType: serverTest,
1795 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001797 // TODO(davidben): Add a TLS 1.3 version of this.
1798 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001799 Bugs: ProtocolBugs{
1800 BadFinished: true,
1801 },
1802 },
1803 shouldFail: true,
1804 expectedError: ":DIGEST_CHECK_FAILED:",
1805 },
1806 {
1807 name: "FalseStart-BadFinished",
1808 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001809 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1811 NextProtos: []string{"foo"},
1812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 ExpectFalseStart: true,
1815 },
1816 },
1817 flags: []string{
1818 "-false-start",
1819 "-handshake-never-done",
1820 "-advertise-alpn", "\x03foo",
1821 },
1822 shimWritesFirst: true,
1823 shouldFail: true,
1824 expectedError: ":DIGEST_CHECK_FAILED:",
1825 },
1826 {
1827 name: "NoFalseStart-NoALPN",
1828 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001829 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001830 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1831 Bugs: ProtocolBugs{
1832 ExpectFalseStart: true,
1833 AlertBeforeFalseStartTest: alertAccessDenied,
1834 },
1835 },
1836 flags: []string{
1837 "-false-start",
1838 },
1839 shimWritesFirst: true,
1840 shouldFail: true,
1841 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1842 expectedLocalError: "tls: peer did not false start: EOF",
1843 },
1844 {
1845 name: "NoFalseStart-NoAEAD",
1846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1849 NextProtos: []string{"foo"},
1850 Bugs: ProtocolBugs{
1851 ExpectFalseStart: true,
1852 AlertBeforeFalseStartTest: alertAccessDenied,
1853 },
1854 },
1855 flags: []string{
1856 "-false-start",
1857 "-advertise-alpn", "\x03foo",
1858 },
1859 shimWritesFirst: true,
1860 shouldFail: true,
1861 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1862 expectedLocalError: "tls: peer did not false start: EOF",
1863 },
1864 {
1865 name: "NoFalseStart-RSA",
1866 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001867 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001868 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1869 NextProtos: []string{"foo"},
1870 Bugs: ProtocolBugs{
1871 ExpectFalseStart: true,
1872 AlertBeforeFalseStartTest: alertAccessDenied,
1873 },
1874 },
1875 flags: []string{
1876 "-false-start",
1877 "-advertise-alpn", "\x03foo",
1878 },
1879 shimWritesFirst: true,
1880 shouldFail: true,
1881 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1882 expectedLocalError: "tls: peer did not false start: EOF",
1883 },
1884 {
1885 name: "NoFalseStart-DHE_RSA",
1886 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001887 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001888 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1889 NextProtos: []string{"foo"},
1890 Bugs: ProtocolBugs{
1891 ExpectFalseStart: true,
1892 AlertBeforeFalseStartTest: alertAccessDenied,
1893 },
1894 },
1895 flags: []string{
1896 "-false-start",
1897 "-advertise-alpn", "\x03foo",
1898 },
1899 shimWritesFirst: true,
1900 shouldFail: true,
1901 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1902 expectedLocalError: "tls: peer did not false start: EOF",
1903 },
1904 {
Adam Langley7c803a62015-06-15 15:35:05 -07001905 protocol: dtls,
1906 name: "SendSplitAlert-Sync",
1907 config: Config{
1908 Bugs: ProtocolBugs{
1909 SendSplitAlert: true,
1910 },
1911 },
1912 },
1913 {
1914 protocol: dtls,
1915 name: "SendSplitAlert-Async",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 SendSplitAlert: true,
1919 },
1920 },
1921 flags: []string{"-async"},
1922 },
1923 {
1924 protocol: dtls,
1925 name: "PackDTLSHandshake",
1926 config: Config{
1927 Bugs: ProtocolBugs{
1928 MaxHandshakeRecordLength: 2,
1929 PackHandshakeFragments: 20,
1930 PackHandshakeRecords: 200,
1931 },
1932 },
1933 },
1934 {
Adam Langley7c803a62015-06-15 15:35:05 -07001935 name: "SendEmptyRecords-Pass",
1936 sendEmptyRecords: 32,
1937 },
1938 {
1939 name: "SendEmptyRecords",
1940 sendEmptyRecords: 33,
1941 shouldFail: true,
1942 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1943 },
1944 {
1945 name: "SendEmptyRecords-Async",
1946 sendEmptyRecords: 33,
1947 flags: []string{"-async"},
1948 shouldFail: true,
1949 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1950 },
1951 {
1952 name: "SendWarningAlerts-Pass",
1953 sendWarningAlerts: 4,
1954 },
1955 {
1956 protocol: dtls,
1957 name: "SendWarningAlerts-DTLS-Pass",
1958 sendWarningAlerts: 4,
1959 },
1960 {
1961 name: "SendWarningAlerts",
1962 sendWarningAlerts: 5,
1963 shouldFail: true,
1964 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1965 },
1966 {
1967 name: "SendWarningAlerts-Async",
1968 sendWarningAlerts: 5,
1969 flags: []string{"-async"},
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1972 },
David Benjaminba4594a2015-06-18 18:36:15 -04001973 {
1974 name: "EmptySessionID",
1975 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001976 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001977 SessionTicketsDisabled: true,
1978 },
1979 noSessionCache: true,
1980 flags: []string{"-expect-no-session"},
1981 },
David Benjamin30789da2015-08-29 22:56:45 -04001982 {
1983 name: "Unclean-Shutdown",
1984 config: Config{
1985 Bugs: ProtocolBugs{
1986 NoCloseNotify: true,
1987 ExpectCloseNotify: true,
1988 },
1989 },
1990 shimShutsDown: true,
1991 flags: []string{"-check-close-notify"},
1992 shouldFail: true,
1993 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1994 },
1995 {
1996 name: "Unclean-Shutdown-Ignored",
1997 config: Config{
1998 Bugs: ProtocolBugs{
1999 NoCloseNotify: true,
2000 },
2001 },
2002 shimShutsDown: true,
2003 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002004 {
David Benjaminfa214e42016-05-10 17:03:10 -04002005 name: "Unclean-Shutdown-Alert",
2006 config: Config{
2007 Bugs: ProtocolBugs{
2008 SendAlertOnShutdown: alertDecompressionFailure,
2009 ExpectCloseNotify: true,
2010 },
2011 },
2012 shimShutsDown: true,
2013 flags: []string{"-check-close-notify"},
2014 shouldFail: true,
2015 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2016 },
2017 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002018 name: "LargePlaintext",
2019 config: Config{
2020 Bugs: ProtocolBugs{
2021 SendLargeRecords: true,
2022 },
2023 },
2024 messageLen: maxPlaintext + 1,
2025 shouldFail: true,
2026 expectedError: ":DATA_LENGTH_TOO_LONG:",
2027 },
2028 {
2029 protocol: dtls,
2030 name: "LargePlaintext-DTLS",
2031 config: Config{
2032 Bugs: ProtocolBugs{
2033 SendLargeRecords: true,
2034 },
2035 },
2036 messageLen: maxPlaintext + 1,
2037 shouldFail: true,
2038 expectedError: ":DATA_LENGTH_TOO_LONG:",
2039 },
2040 {
2041 name: "LargeCiphertext",
2042 config: Config{
2043 Bugs: ProtocolBugs{
2044 SendLargeRecords: true,
2045 },
2046 },
2047 messageLen: maxPlaintext * 2,
2048 shouldFail: true,
2049 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2050 },
2051 {
2052 protocol: dtls,
2053 name: "LargeCiphertext-DTLS",
2054 config: Config{
2055 Bugs: ProtocolBugs{
2056 SendLargeRecords: true,
2057 },
2058 },
2059 messageLen: maxPlaintext * 2,
2060 // Unlike the other four cases, DTLS drops records which
2061 // are invalid before authentication, so the connection
2062 // does not fail.
2063 expectMessageDropped: true,
2064 },
David Benjamindd6fed92015-10-23 17:41:12 -04002065 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002066 // In TLS 1.2 and below, empty NewSessionTicket messages
2067 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002068 name: "SendEmptySessionTicket",
2069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002070 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002071 Bugs: ProtocolBugs{
2072 SendEmptySessionTicket: true,
2073 FailIfSessionOffered: true,
2074 },
2075 },
2076 flags: []string{"-expect-no-session"},
2077 resumeSession: true,
2078 expectResumeRejected: true,
2079 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002080 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002081 name: "BadHelloRequest-1",
2082 renegotiate: 1,
2083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002084 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002085 Bugs: ProtocolBugs{
2086 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2087 },
2088 },
2089 flags: []string{
2090 "-renegotiate-freely",
2091 "-expect-total-renegotiations", "1",
2092 },
2093 shouldFail: true,
2094 expectedError: ":BAD_HELLO_REQUEST:",
2095 },
2096 {
2097 name: "BadHelloRequest-2",
2098 renegotiate: 1,
2099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002100 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002101 Bugs: ProtocolBugs{
2102 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2103 },
2104 },
2105 flags: []string{
2106 "-renegotiate-freely",
2107 "-expect-total-renegotiations", "1",
2108 },
2109 shouldFail: true,
2110 expectedError: ":BAD_HELLO_REQUEST:",
2111 },
David Benjaminef1b0092015-11-21 14:05:44 -05002112 {
2113 testType: serverTest,
2114 name: "SupportTicketsWithSessionID",
2115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002116 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002117 SessionTicketsDisabled: true,
2118 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 resumeConfig: &Config{
2120 MaxVersion: VersionTLS12,
2121 },
David Benjaminef1b0092015-11-21 14:05:44 -05002122 resumeSession: true,
2123 },
Adam Langley7c803a62015-06-15 15:35:05 -07002124 }
Adam Langley7c803a62015-06-15 15:35:05 -07002125 testCases = append(testCases, basicTests...)
2126}
2127
Adam Langley95c29f32014-06-20 12:00:00 -07002128func addCipherSuiteTests() {
2129 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002130 const psk = "12345"
2131 const pskIdentity = "luggage combo"
2132
Adam Langley95c29f32014-06-20 12:00:00 -07002133 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002134 var certFile string
2135 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002136 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002137 cert = ecdsaP256Certificate
2138 certFile = ecdsaP256CertificateFile
2139 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002140 } else {
David Benjamin33863262016-07-08 17:20:12 -07002141 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002142 certFile = rsaCertificateFile
2143 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002144 }
2145
David Benjamin48cae082014-10-27 01:06:24 -04002146 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002147 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002148 flags = append(flags,
2149 "-psk", psk,
2150 "-psk-identity", pskIdentity)
2151 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002152 if hasComponent(suite.name, "NULL") {
2153 // NULL ciphers must be explicitly enabled.
2154 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2155 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002156 if hasComponent(suite.name, "CECPQ1") {
2157 // CECPQ1 ciphers must be explicitly enabled.
2158 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2159 }
David Benjamin48cae082014-10-27 01:06:24 -04002160
Adam Langley95c29f32014-06-20 12:00:00 -07002161 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002162 for _, protocol := range []protocol{tls, dtls} {
2163 var prefix string
2164 if protocol == dtls {
2165 if !ver.hasDTLS {
2166 continue
2167 }
2168 prefix = "D"
2169 }
Adam Langley95c29f32014-06-20 12:00:00 -07002170
David Benjamin0407e762016-06-17 16:41:18 -04002171 var shouldServerFail, shouldClientFail bool
2172 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2173 // BoringSSL clients accept ECDHE on SSLv3, but
2174 // a BoringSSL server will never select it
2175 // because the extension is missing.
2176 shouldServerFail = true
2177 }
2178 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2179 shouldClientFail = true
2180 shouldServerFail = true
2181 }
David Benjamin54c217c2016-07-13 12:35:25 -04002182 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002183 shouldClientFail = true
2184 shouldServerFail = true
2185 }
David Benjamin0407e762016-06-17 16:41:18 -04002186 if !isDTLSCipher(suite.name) && protocol == dtls {
2187 shouldClientFail = true
2188 shouldServerFail = true
2189 }
David Benjamin4298d772015-12-19 00:18:25 -05002190
David Benjamin0407e762016-06-17 16:41:18 -04002191 var expectedServerError, expectedClientError string
2192 if shouldServerFail {
2193 expectedServerError = ":NO_SHARED_CIPHER:"
2194 }
2195 if shouldClientFail {
2196 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2197 }
David Benjamin025b3d32014-07-01 19:53:04 -04002198
David Benjamin9deb1172016-07-13 17:13:49 -04002199 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2200 resumeSession := ver.version < VersionTLS13
2201
David Benjamin6fd297b2014-08-11 18:43:38 -04002202 testCases = append(testCases, testCase{
2203 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002204 protocol: protocol,
2205
2206 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002207 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002208 MinVersion: ver.version,
2209 MaxVersion: ver.version,
2210 CipherSuites: []uint16{suite.id},
2211 Certificates: []Certificate{cert},
2212 PreSharedKey: []byte(psk),
2213 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002214 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002215 EnableAllCiphers: shouldServerFail,
2216 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002217 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002218 },
2219 certFile: certFile,
2220 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002221 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002222 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002223 shouldFail: shouldServerFail,
2224 expectedError: expectedServerError,
2225 })
2226
2227 testCases = append(testCases, testCase{
2228 testType: clientTest,
2229 protocol: protocol,
2230 name: prefix + ver.name + "-" + suite.name + "-client",
2231 config: Config{
2232 MinVersion: ver.version,
2233 MaxVersion: ver.version,
2234 CipherSuites: []uint16{suite.id},
2235 Certificates: []Certificate{cert},
2236 PreSharedKey: []byte(psk),
2237 PreSharedKeyIdentity: pskIdentity,
2238 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002239 EnableAllCiphers: shouldClientFail,
2240 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002241 },
2242 },
2243 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002244 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002245 shouldFail: shouldClientFail,
2246 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002247 })
David Benjamin2c99d282015-09-01 10:23:00 -04002248
Nick Harper1fd39d82016-06-14 18:14:35 -07002249 if !shouldClientFail {
2250 // Ensure the maximum record size is accepted.
2251 testCases = append(testCases, testCase{
2252 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2253 config: Config{
2254 MinVersion: ver.version,
2255 MaxVersion: ver.version,
2256 CipherSuites: []uint16{suite.id},
2257 Certificates: []Certificate{cert},
2258 PreSharedKey: []byte(psk),
2259 PreSharedKeyIdentity: pskIdentity,
2260 },
2261 flags: flags,
2262 messageLen: maxPlaintext,
2263 })
2264 }
2265 }
David Benjamin2c99d282015-09-01 10:23:00 -04002266 }
Adam Langley95c29f32014-06-20 12:00:00 -07002267 }
Adam Langleya7997f12015-05-14 17:38:50 -07002268
2269 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002270 name: "NoSharedCipher",
2271 config: Config{
2272 // TODO(davidben): Add a TLS 1.3 version of this test.
2273 MaxVersion: VersionTLS12,
2274 CipherSuites: []uint16{},
2275 },
2276 shouldFail: true,
2277 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2278 })
2279
2280 testCases = append(testCases, testCase{
2281 name: "UnsupportedCipherSuite",
2282 config: Config{
2283 MaxVersion: VersionTLS12,
2284 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2285 Bugs: ProtocolBugs{
2286 IgnorePeerCipherPreferences: true,
2287 },
2288 },
2289 flags: []string{"-cipher", "DEFAULT:!RC4"},
2290 shouldFail: true,
2291 expectedError: ":WRONG_CIPHER_RETURNED:",
2292 })
2293
2294 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002295 name: "WeakDH",
2296 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002297 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002298 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2299 Bugs: ProtocolBugs{
2300 // This is a 1023-bit prime number, generated
2301 // with:
2302 // openssl gendh 1023 | openssl asn1parse -i
2303 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2304 },
2305 },
2306 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002307 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002308 })
Adam Langleycef75832015-09-03 14:51:12 -07002309
David Benjamincd24a392015-11-11 13:23:05 -08002310 testCases = append(testCases, testCase{
2311 name: "SillyDH",
2312 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002313 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002314 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2315 Bugs: ProtocolBugs{
2316 // This is a 4097-bit prime number, generated
2317 // with:
2318 // openssl gendh 4097 | openssl asn1parse -i
2319 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2320 },
2321 },
2322 shouldFail: true,
2323 expectedError: ":DH_P_TOO_LONG:",
2324 })
2325
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002326 // This test ensures that Diffie-Hellman public values are padded with
2327 // zeros so that they're the same length as the prime. This is to avoid
2328 // hitting a bug in yaSSL.
2329 testCases = append(testCases, testCase{
2330 testType: serverTest,
2331 name: "DHPublicValuePadded",
2332 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002333 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002334 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2335 Bugs: ProtocolBugs{
2336 RequireDHPublicValueLen: (1025 + 7) / 8,
2337 },
2338 },
2339 flags: []string{"-use-sparse-dh-prime"},
2340 })
David Benjamincd24a392015-11-11 13:23:05 -08002341
David Benjamin241ae832016-01-15 03:04:54 -05002342 // The server must be tolerant to bogus ciphers.
2343 const bogusCipher = 0x1234
2344 testCases = append(testCases, testCase{
2345 testType: serverTest,
2346 name: "UnknownCipher",
2347 config: Config{
2348 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2349 },
2350 })
2351
Adam Langleycef75832015-09-03 14:51:12 -07002352 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2353 // 1.1 specific cipher suite settings. A server is setup with the given
2354 // cipher lists and then a connection is made for each member of
2355 // expectations. The cipher suite that the server selects must match
2356 // the specified one.
2357 var versionSpecificCiphersTest = []struct {
2358 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2359 // expectations is a map from TLS version to cipher suite id.
2360 expectations map[uint16]uint16
2361 }{
2362 {
2363 // Test that the null case (where no version-specific ciphers are set)
2364 // works as expected.
2365 "RC4-SHA:AES128-SHA", // default ciphers
2366 "", // no ciphers specifically for TLS ≥ 1.0
2367 "", // no ciphers specifically for TLS ≥ 1.1
2368 map[uint16]uint16{
2369 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2370 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2371 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2372 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2373 },
2374 },
2375 {
2376 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2377 // cipher.
2378 "RC4-SHA:AES128-SHA", // default
2379 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2380 "", // no ciphers specifically for TLS ≥ 1.1
2381 map[uint16]uint16{
2382 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2383 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2384 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2385 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2386 },
2387 },
2388 {
2389 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2390 // cipher.
2391 "RC4-SHA:AES128-SHA", // default
2392 "", // no ciphers specifically for TLS ≥ 1.0
2393 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2394 map[uint16]uint16{
2395 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2396 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2397 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2398 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2399 },
2400 },
2401 {
2402 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2403 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2404 "RC4-SHA:AES128-SHA", // default
2405 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2406 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2407 map[uint16]uint16{
2408 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2409 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2410 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2411 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2412 },
2413 },
2414 }
2415
2416 for i, test := range versionSpecificCiphersTest {
2417 for version, expectedCipherSuite := range test.expectations {
2418 flags := []string{"-cipher", test.ciphersDefault}
2419 if len(test.ciphersTLS10) > 0 {
2420 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2421 }
2422 if len(test.ciphersTLS11) > 0 {
2423 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2424 }
2425
2426 testCases = append(testCases, testCase{
2427 testType: serverTest,
2428 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2429 config: Config{
2430 MaxVersion: version,
2431 MinVersion: version,
2432 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2433 },
2434 flags: flags,
2435 expectedCipher: expectedCipherSuite,
2436 })
2437 }
2438 }
Adam Langley95c29f32014-06-20 12:00:00 -07002439}
2440
2441func addBadECDSASignatureTests() {
2442 for badR := BadValue(1); badR < NumBadValues; badR++ {
2443 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002444 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002445 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2446 config: Config{
2447 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002448 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002449 Bugs: ProtocolBugs{
2450 BadECDSAR: badR,
2451 BadECDSAS: badS,
2452 },
2453 },
2454 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002455 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002456 })
2457 }
2458 }
2459}
2460
Adam Langley80842bd2014-06-20 12:00:00 -07002461func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002462 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002463 name: "MaxCBCPadding",
2464 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002465 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002466 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2467 Bugs: ProtocolBugs{
2468 MaxPadding: true,
2469 },
2470 },
2471 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2472 })
David Benjamin025b3d32014-07-01 19:53:04 -04002473 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002474 name: "BadCBCPadding",
2475 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002476 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002477 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2478 Bugs: ProtocolBugs{
2479 PaddingFirstByteBad: true,
2480 },
2481 },
2482 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002483 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002484 })
2485 // OpenSSL previously had an issue where the first byte of padding in
2486 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002487 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002488 name: "BadCBCPadding255",
2489 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002490 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2492 Bugs: ProtocolBugs{
2493 MaxPadding: true,
2494 PaddingFirstByteBadIf255: true,
2495 },
2496 },
2497 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2498 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002499 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002500 })
2501}
2502
Kenny Root7fdeaf12014-08-05 15:23:37 -07002503func addCBCSplittingTests() {
2504 testCases = append(testCases, testCase{
2505 name: "CBCRecordSplitting",
2506 config: Config{
2507 MaxVersion: VersionTLS10,
2508 MinVersion: VersionTLS10,
2509 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2510 },
David Benjaminac8302a2015-09-01 17:18:15 -04002511 messageLen: -1, // read until EOF
2512 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002513 flags: []string{
2514 "-async",
2515 "-write-different-record-sizes",
2516 "-cbc-record-splitting",
2517 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002518 })
2519 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002520 name: "CBCRecordSplittingPartialWrite",
2521 config: Config{
2522 MaxVersion: VersionTLS10,
2523 MinVersion: VersionTLS10,
2524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2525 },
2526 messageLen: -1, // read until EOF
2527 flags: []string{
2528 "-async",
2529 "-write-different-record-sizes",
2530 "-cbc-record-splitting",
2531 "-partial-write",
2532 },
2533 })
2534}
2535
David Benjamin636293b2014-07-08 17:59:18 -04002536func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002537 // Add a dummy cert pool to stress certificate authority parsing.
2538 // TODO(davidben): Add tests that those values parse out correctly.
2539 certPool := x509.NewCertPool()
2540 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2541 if err != nil {
2542 panic(err)
2543 }
2544 certPool.AddCert(cert)
2545
David Benjamin636293b2014-07-08 17:59:18 -04002546 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002547 testCases = append(testCases, testCase{
2548 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002549 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002550 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002551 MinVersion: ver.version,
2552 MaxVersion: ver.version,
2553 ClientAuth: RequireAnyClientCert,
2554 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002555 },
2556 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002557 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2558 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002559 },
2560 })
2561 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002562 testType: serverTest,
2563 name: ver.name + "-Server-ClientAuth-RSA",
2564 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002565 MinVersion: ver.version,
2566 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002567 Certificates: []Certificate{rsaCertificate},
2568 },
2569 flags: []string{"-require-any-client-certificate"},
2570 })
David Benjamine098ec22014-08-27 23:13:20 -04002571 if ver.version != VersionSSL30 {
2572 testCases = append(testCases, testCase{
2573 testType: serverTest,
2574 name: ver.name + "-Server-ClientAuth-ECDSA",
2575 config: Config{
2576 MinVersion: ver.version,
2577 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002578 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002579 },
2580 flags: []string{"-require-any-client-certificate"},
2581 })
2582 testCases = append(testCases, testCase{
2583 testType: clientTest,
2584 name: ver.name + "-Client-ClientAuth-ECDSA",
2585 config: Config{
2586 MinVersion: ver.version,
2587 MaxVersion: ver.version,
2588 ClientAuth: RequireAnyClientCert,
2589 ClientCAs: certPool,
2590 },
2591 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002592 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2593 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002594 },
2595 })
2596 }
David Benjamin636293b2014-07-08 17:59:18 -04002597 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002598
Nick Harper1fd39d82016-06-14 18:14:35 -07002599 // TODO(davidben): These tests will need TLS 1.3 versions when the
2600 // handshake is separate.
2601
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002602 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002603 name: "NoClientCertificate",
2604 config: Config{
2605 MaxVersion: VersionTLS12,
2606 ClientAuth: RequireAnyClientCert,
2607 },
2608 shouldFail: true,
2609 expectedLocalError: "client didn't provide a certificate",
2610 })
2611
2612 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002613 testType: serverTest,
2614 name: "RequireAnyClientCertificate",
2615 config: Config{
2616 MaxVersion: VersionTLS12,
2617 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002618 flags: []string{"-require-any-client-certificate"},
2619 shouldFail: true,
2620 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2621 })
2622
2623 testCases = append(testCases, testCase{
2624 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002625 name: "RequireAnyClientCertificate-SSL3",
2626 config: Config{
2627 MaxVersion: VersionSSL30,
2628 },
2629 flags: []string{"-require-any-client-certificate"},
2630 shouldFail: true,
2631 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2632 })
2633
2634 testCases = append(testCases, testCase{
2635 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002636 name: "SkipClientCertificate",
2637 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002638 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002639 Bugs: ProtocolBugs{
2640 SkipClientCertificate: true,
2641 },
2642 },
2643 // Setting SSL_VERIFY_PEER allows anonymous clients.
2644 flags: []string{"-verify-peer"},
2645 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002646 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002647 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002648
2649 // Client auth is only legal in certificate-based ciphers.
2650 testCases = append(testCases, testCase{
2651 testType: clientTest,
2652 name: "ClientAuth-PSK",
2653 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002654 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002655 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2656 PreSharedKey: []byte("secret"),
2657 ClientAuth: RequireAnyClientCert,
2658 },
2659 flags: []string{
2660 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2661 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2662 "-psk", "secret",
2663 },
2664 shouldFail: true,
2665 expectedError: ":UNEXPECTED_MESSAGE:",
2666 })
2667 testCases = append(testCases, testCase{
2668 testType: clientTest,
2669 name: "ClientAuth-ECDHE_PSK",
2670 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002671 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002672 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2673 PreSharedKey: []byte("secret"),
2674 ClientAuth: RequireAnyClientCert,
2675 },
2676 flags: []string{
2677 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2678 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2679 "-psk", "secret",
2680 },
2681 shouldFail: true,
2682 expectedError: ":UNEXPECTED_MESSAGE:",
2683 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002684
2685 // Regression test for a bug where the client CA list, if explicitly
2686 // set to NULL, was mis-encoded.
2687 testCases = append(testCases, testCase{
2688 testType: serverTest,
2689 name: "Null-Client-CA-List",
2690 config: Config{
2691 MaxVersion: VersionTLS12,
2692 Certificates: []Certificate{rsaCertificate},
2693 },
2694 flags: []string{
2695 "-require-any-client-certificate",
2696 "-use-null-client-ca-list",
2697 },
2698 })
David Benjamin636293b2014-07-08 17:59:18 -04002699}
2700
Adam Langley75712922014-10-10 16:23:43 -07002701func addExtendedMasterSecretTests() {
2702 const expectEMSFlag = "-expect-extended-master-secret"
2703
2704 for _, with := range []bool{false, true} {
2705 prefix := "No"
2706 var flags []string
2707 if with {
2708 prefix = ""
2709 flags = []string{expectEMSFlag}
2710 }
2711
2712 for _, isClient := range []bool{false, true} {
2713 suffix := "-Server"
2714 testType := serverTest
2715 if isClient {
2716 suffix = "-Client"
2717 testType = clientTest
2718 }
2719
David Benjamin4c3ddf72016-06-29 18:13:53 -04002720 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2721 // test that the extension is irrelevant, but the API
2722 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002723 for _, ver := range tlsVersions {
2724 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.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002874 //
2875 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2876 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002877 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002878 name: "Basic-Client",
2879 config: Config{
2880 MaxVersion: VersionTLS12,
2881 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002882 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002883 // Ensure session tickets are used, not session IDs.
2884 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002885 })
2886 tests = append(tests, testCase{
2887 name: "Basic-Client-RenewTicket",
2888 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002889 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002890 Bugs: ProtocolBugs{
2891 RenewTicketOnResume: true,
2892 },
2893 },
David Benjaminba4594a2015-06-18 18:36:15 -04002894 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002895 resumeSession: true,
2896 })
2897 tests = append(tests, testCase{
2898 name: "Basic-Client-NoTicket",
2899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002900 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002901 SessionTicketsDisabled: true,
2902 },
2903 resumeSession: true,
2904 })
2905 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002906 name: "Basic-Client-Implicit",
2907 config: Config{
2908 MaxVersion: VersionTLS12,
2909 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002910 flags: []string{"-implicit-handshake"},
2911 resumeSession: true,
2912 })
2913 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002914 testType: serverTest,
2915 name: "Basic-Server",
2916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002917 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002918 Bugs: ProtocolBugs{
2919 RequireSessionTickets: true,
2920 },
2921 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002922 resumeSession: true,
2923 })
2924 tests = append(tests, testCase{
2925 testType: serverTest,
2926 name: "Basic-Server-NoTickets",
2927 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002928 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002929 SessionTicketsDisabled: true,
2930 },
2931 resumeSession: true,
2932 })
2933 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002934 testType: serverTest,
2935 name: "Basic-Server-Implicit",
2936 config: Config{
2937 MaxVersion: VersionTLS12,
2938 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002939 flags: []string{"-implicit-handshake"},
2940 resumeSession: true,
2941 })
2942 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002943 testType: serverTest,
2944 name: "Basic-Server-EarlyCallback",
2945 config: Config{
2946 MaxVersion: VersionTLS12,
2947 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002948 flags: []string{"-use-early-callback"},
2949 resumeSession: true,
2950 })
2951
2952 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002953 //
2954 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002955 tests = append(tests, testCase{
2956 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002957 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002959 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002960 ClientAuth: RequestClientCert,
2961 },
2962 })
2963 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002964 testType: serverTest,
2965 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002969 // Setting SSL_VERIFY_PEER allows anonymous clients.
2970 flags: []string{"-verify-peer"},
2971 })
David Benjamin582ba042016-07-07 12:33:25 -07002972 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002973 tests = append(tests, testCase{
2974 testType: clientTest,
2975 name: "ClientAuth-NoCertificate-Client-SSL3",
2976 config: Config{
2977 MaxVersion: VersionSSL30,
2978 ClientAuth: RequestClientCert,
2979 },
2980 })
2981 tests = append(tests, testCase{
2982 testType: serverTest,
2983 name: "ClientAuth-NoCertificate-Server-SSL3",
2984 config: Config{
2985 MaxVersion: VersionSSL30,
2986 },
2987 // Setting SSL_VERIFY_PEER allows anonymous clients.
2988 flags: []string{"-verify-peer"},
2989 })
2990 }
2991 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002992 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002993 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002995 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002996 ClientAuth: RequireAnyClientCert,
2997 },
2998 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002999 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3000 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003001 },
3002 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003003 tests = append(tests, testCase{
3004 testType: clientTest,
3005 name: "ClientAuth-ECDSA-Client",
3006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003007 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003008 ClientAuth: RequireAnyClientCert,
3009 },
3010 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003011 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3012 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003013 },
3014 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003015 tests = append(tests, testCase{
3016 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003017 name: "ClientAuth-NoCertificate-OldCallback",
3018 config: Config{
3019 MaxVersion: VersionTLS12,
3020 ClientAuth: RequestClientCert,
3021 },
3022 flags: []string{"-use-old-client-cert-callback"},
3023 })
3024 tests = append(tests, testCase{
3025 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003026 name: "ClientAuth-OldCallback",
3027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003028 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003029 ClientAuth: RequireAnyClientCert,
3030 },
3031 flags: []string{
3032 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3033 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3034 "-use-old-client-cert-callback",
3035 },
3036 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003037 tests = append(tests, testCase{
3038 testType: serverTest,
3039 name: "ClientAuth-Server",
3040 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003041 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003042 Certificates: []Certificate{rsaCertificate},
3043 },
3044 flags: []string{"-require-any-client-certificate"},
3045 })
3046
David Benjamin4c3ddf72016-06-29 18:13:53 -04003047 // Test each key exchange on the server side for async keys.
3048 //
3049 // TODO(davidben): Add TLS 1.3 versions of these.
3050 tests = append(tests, testCase{
3051 testType: serverTest,
3052 name: "Basic-Server-RSA",
3053 config: Config{
3054 MaxVersion: VersionTLS12,
3055 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3056 },
3057 flags: []string{
3058 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3059 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3060 },
3061 })
3062 tests = append(tests, testCase{
3063 testType: serverTest,
3064 name: "Basic-Server-ECDHE-RSA",
3065 config: Config{
3066 MaxVersion: VersionTLS12,
3067 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3068 },
3069 flags: []string{
3070 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3071 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3072 },
3073 })
3074 tests = append(tests, testCase{
3075 testType: serverTest,
3076 name: "Basic-Server-ECDHE-ECDSA",
3077 config: Config{
3078 MaxVersion: VersionTLS12,
3079 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3080 },
3081 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003082 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3083 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003084 },
3085 })
3086
David Benjamin760b1dd2015-05-15 23:33:48 -04003087 // No session ticket support; server doesn't send NewSessionTicket.
3088 tests = append(tests, testCase{
3089 name: "SessionTicketsDisabled-Client",
3090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003091 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003092 SessionTicketsDisabled: true,
3093 },
3094 })
3095 tests = append(tests, testCase{
3096 testType: serverTest,
3097 name: "SessionTicketsDisabled-Server",
3098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003099 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003100 SessionTicketsDisabled: true,
3101 },
3102 })
3103
3104 // Skip ServerKeyExchange in PSK key exchange if there's no
3105 // identity hint.
3106 tests = append(tests, testCase{
3107 name: "EmptyPSKHint-Client",
3108 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003109 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003110 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3111 PreSharedKey: []byte("secret"),
3112 },
3113 flags: []string{"-psk", "secret"},
3114 })
3115 tests = append(tests, testCase{
3116 testType: serverTest,
3117 name: "EmptyPSKHint-Server",
3118 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003119 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003120 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3121 PreSharedKey: []byte("secret"),
3122 },
3123 flags: []string{"-psk", "secret"},
3124 })
3125
David Benjamin4c3ddf72016-06-29 18:13:53 -04003126 // OCSP stapling tests.
3127 //
3128 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003129 tests = append(tests, testCase{
3130 testType: clientTest,
3131 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003132 config: Config{
3133 MaxVersion: VersionTLS12,
3134 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003135 flags: []string{
3136 "-enable-ocsp-stapling",
3137 "-expect-ocsp-response",
3138 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003139 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003140 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003141 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003142 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003143 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003144 testType: serverTest,
3145 name: "OCSPStapling-Server",
3146 config: Config{
3147 MaxVersion: VersionTLS12,
3148 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003149 expectedOCSPResponse: testOCSPResponse,
3150 flags: []string{
3151 "-ocsp-response",
3152 base64.StdEncoding.EncodeToString(testOCSPResponse),
3153 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003154 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003155 })
3156
David Benjamin4c3ddf72016-06-29 18:13:53 -04003157 // Certificate verification tests.
3158 //
3159 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003160 tests = append(tests, testCase{
3161 testType: clientTest,
3162 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003163 config: Config{
3164 MaxVersion: VersionTLS12,
3165 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003166 flags: []string{
3167 "-verify-peer",
3168 },
3169 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003170 tests = append(tests, testCase{
3171 testType: clientTest,
3172 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003173 config: Config{
3174 MaxVersion: VersionTLS12,
3175 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003176 flags: []string{
3177 "-verify-fail",
3178 "-verify-peer",
3179 },
3180 shouldFail: true,
3181 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3182 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003183 tests = append(tests, testCase{
3184 testType: clientTest,
3185 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003186 config: Config{
3187 MaxVersion: VersionTLS12,
3188 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003189 flags: []string{
3190 "-verify-fail",
3191 "-expect-verify-result",
3192 },
3193 })
3194
David Benjamin582ba042016-07-07 12:33:25 -07003195 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003196 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003197 name: "Renegotiate-Client",
3198 config: Config{
3199 MaxVersion: VersionTLS12,
3200 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003201 renegotiate: 1,
3202 flags: []string{
3203 "-renegotiate-freely",
3204 "-expect-total-renegotiations", "1",
3205 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003206 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003207
David Benjamin760b1dd2015-05-15 23:33:48 -04003208 // NPN on client and server; results in post-handshake message.
3209 tests = append(tests, testCase{
3210 name: "NPN-Client",
3211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003212 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003213 NextProtos: []string{"foo"},
3214 },
3215 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003216 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003217 expectedNextProto: "foo",
3218 expectedNextProtoType: npn,
3219 })
3220 tests = append(tests, testCase{
3221 testType: serverTest,
3222 name: "NPN-Server",
3223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003224 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003225 NextProtos: []string{"bar"},
3226 },
3227 flags: []string{
3228 "-advertise-npn", "\x03foo\x03bar\x03baz",
3229 "-expect-next-proto", "bar",
3230 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003231 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003232 expectedNextProto: "bar",
3233 expectedNextProtoType: npn,
3234 })
3235
3236 // TODO(davidben): Add tests for when False Start doesn't trigger.
3237
3238 // Client does False Start and negotiates NPN.
3239 tests = append(tests, testCase{
3240 name: "FalseStart",
3241 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003242 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003243 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3244 NextProtos: []string{"foo"},
3245 Bugs: ProtocolBugs{
3246 ExpectFalseStart: true,
3247 },
3248 },
3249 flags: []string{
3250 "-false-start",
3251 "-select-next-proto", "foo",
3252 },
3253 shimWritesFirst: true,
3254 resumeSession: true,
3255 })
3256
3257 // Client does False Start and negotiates ALPN.
3258 tests = append(tests, testCase{
3259 name: "FalseStart-ALPN",
3260 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003261 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003262 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3263 NextProtos: []string{"foo"},
3264 Bugs: ProtocolBugs{
3265 ExpectFalseStart: true,
3266 },
3267 },
3268 flags: []string{
3269 "-false-start",
3270 "-advertise-alpn", "\x03foo",
3271 },
3272 shimWritesFirst: true,
3273 resumeSession: true,
3274 })
3275
3276 // Client does False Start but doesn't explicitly call
3277 // SSL_connect.
3278 tests = append(tests, testCase{
3279 name: "FalseStart-Implicit",
3280 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003281 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003282 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3283 NextProtos: []string{"foo"},
3284 },
3285 flags: []string{
3286 "-implicit-handshake",
3287 "-false-start",
3288 "-advertise-alpn", "\x03foo",
3289 },
3290 })
3291
3292 // False Start without session tickets.
3293 tests = append(tests, testCase{
3294 name: "FalseStart-SessionTicketsDisabled",
3295 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003296 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003297 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3298 NextProtos: []string{"foo"},
3299 SessionTicketsDisabled: true,
3300 Bugs: ProtocolBugs{
3301 ExpectFalseStart: true,
3302 },
3303 },
3304 flags: []string{
3305 "-false-start",
3306 "-select-next-proto", "foo",
3307 },
3308 shimWritesFirst: true,
3309 })
3310
Adam Langleydf759b52016-07-11 15:24:37 -07003311 tests = append(tests, testCase{
3312 name: "FalseStart-CECPQ1",
3313 config: Config{
3314 MaxVersion: VersionTLS12,
3315 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3316 NextProtos: []string{"foo"},
3317 Bugs: ProtocolBugs{
3318 ExpectFalseStart: true,
3319 },
3320 },
3321 flags: []string{
3322 "-false-start",
3323 "-cipher", "DEFAULT:kCECPQ1",
3324 "-select-next-proto", "foo",
3325 },
3326 shimWritesFirst: true,
3327 resumeSession: true,
3328 })
3329
David Benjamin760b1dd2015-05-15 23:33:48 -04003330 // Server parses a V2ClientHello.
3331 tests = append(tests, testCase{
3332 testType: serverTest,
3333 name: "SendV2ClientHello",
3334 config: Config{
3335 // Choose a cipher suite that does not involve
3336 // elliptic curves, so no extensions are
3337 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003338 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003339 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3340 Bugs: ProtocolBugs{
3341 SendV2ClientHello: true,
3342 },
3343 },
3344 })
3345
3346 // Client sends a Channel ID.
3347 tests = append(tests, testCase{
3348 name: "ChannelID-Client",
3349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003350 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003351 RequestChannelID: true,
3352 },
Adam Langley7c803a62015-06-15 15:35:05 -07003353 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003354 resumeSession: true,
3355 expectChannelID: true,
3356 })
3357
3358 // Server accepts a Channel ID.
3359 tests = append(tests, testCase{
3360 testType: serverTest,
3361 name: "ChannelID-Server",
3362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003363 MaxVersion: VersionTLS12,
3364 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003365 },
3366 flags: []string{
3367 "-expect-channel-id",
3368 base64.StdEncoding.EncodeToString(channelIDBytes),
3369 },
3370 resumeSession: true,
3371 expectChannelID: true,
3372 })
David Benjamin30789da2015-08-29 22:56:45 -04003373
David Benjaminf8fcdf32016-06-08 15:56:13 -04003374 // Channel ID and NPN at the same time, to ensure their relative
3375 // ordering is correct.
3376 tests = append(tests, testCase{
3377 name: "ChannelID-NPN-Client",
3378 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003379 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003380 RequestChannelID: true,
3381 NextProtos: []string{"foo"},
3382 },
3383 flags: []string{
3384 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3385 "-select-next-proto", "foo",
3386 },
3387 resumeSession: true,
3388 expectChannelID: true,
3389 expectedNextProto: "foo",
3390 expectedNextProtoType: npn,
3391 })
3392 tests = append(tests, testCase{
3393 testType: serverTest,
3394 name: "ChannelID-NPN-Server",
3395 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003396 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003397 ChannelID: channelIDKey,
3398 NextProtos: []string{"bar"},
3399 },
3400 flags: []string{
3401 "-expect-channel-id",
3402 base64.StdEncoding.EncodeToString(channelIDBytes),
3403 "-advertise-npn", "\x03foo\x03bar\x03baz",
3404 "-expect-next-proto", "bar",
3405 },
3406 resumeSession: true,
3407 expectChannelID: true,
3408 expectedNextProto: "bar",
3409 expectedNextProtoType: npn,
3410 })
3411
David Benjamin30789da2015-08-29 22:56:45 -04003412 // Bidirectional shutdown with the runner initiating.
3413 tests = append(tests, testCase{
3414 name: "Shutdown-Runner",
3415 config: Config{
3416 Bugs: ProtocolBugs{
3417 ExpectCloseNotify: true,
3418 },
3419 },
3420 flags: []string{"-check-close-notify"},
3421 })
3422
3423 // Bidirectional shutdown with the shim initiating. The runner,
3424 // in the meantime, sends garbage before the close_notify which
3425 // the shim must ignore.
3426 tests = append(tests, testCase{
3427 name: "Shutdown-Shim",
3428 config: Config{
3429 Bugs: ProtocolBugs{
3430 ExpectCloseNotify: true,
3431 },
3432 },
3433 shimShutsDown: true,
3434 sendEmptyRecords: 1,
3435 sendWarningAlerts: 1,
3436 flags: []string{"-check-close-notify"},
3437 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003438 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003439 // TODO(davidben): DTLS 1.3 will want a similar thing for
3440 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003441 tests = append(tests, testCase{
3442 name: "SkipHelloVerifyRequest",
3443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003444 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003445 Bugs: ProtocolBugs{
3446 SkipHelloVerifyRequest: true,
3447 },
3448 },
3449 })
3450 }
3451
David Benjamin760b1dd2015-05-15 23:33:48 -04003452 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003453 test.protocol = config.protocol
3454 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003455 test.name += "-DTLS"
3456 }
David Benjamin582ba042016-07-07 12:33:25 -07003457 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003458 test.name += "-Async"
3459 test.flags = append(test.flags, "-async")
3460 } else {
3461 test.name += "-Sync"
3462 }
David Benjamin582ba042016-07-07 12:33:25 -07003463 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003464 test.name += "-SplitHandshakeRecords"
3465 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003466 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003467 test.config.Bugs.MaxPacketLength = 256
3468 test.flags = append(test.flags, "-mtu", "256")
3469 }
3470 }
David Benjamin582ba042016-07-07 12:33:25 -07003471 if config.packHandshakeFlight {
3472 test.name += "-PackHandshakeFlight"
3473 test.config.Bugs.PackHandshakeFlight = true
3474 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003475 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003476 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003477}
3478
Adam Langley524e7172015-02-20 16:04:00 -08003479func addDDoSCallbackTests() {
3480 // DDoS callback.
3481
3482 for _, resume := range []bool{false, true} {
3483 suffix := "Resume"
3484 if resume {
3485 suffix = "No" + suffix
3486 }
3487
David Benjamin4c3ddf72016-06-29 18:13:53 -04003488 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3489
Adam Langley524e7172015-02-20 16:04:00 -08003490 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003491 testType: serverTest,
3492 name: "Server-DDoS-OK-" + suffix,
3493 config: Config{
3494 MaxVersion: VersionTLS12,
3495 },
Adam Langley524e7172015-02-20 16:04:00 -08003496 flags: []string{"-install-ddos-callback"},
3497 resumeSession: resume,
3498 })
3499
3500 failFlag := "-fail-ddos-callback"
3501 if resume {
3502 failFlag = "-fail-second-ddos-callback"
3503 }
3504 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003505 testType: serverTest,
3506 name: "Server-DDoS-Reject-" + suffix,
3507 config: Config{
3508 MaxVersion: VersionTLS12,
3509 },
Adam Langley524e7172015-02-20 16:04:00 -08003510 flags: []string{"-install-ddos-callback", failFlag},
3511 resumeSession: resume,
3512 shouldFail: true,
3513 expectedError: ":CONNECTION_REJECTED:",
3514 })
3515 }
3516}
3517
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003518func addVersionNegotiationTests() {
3519 for i, shimVers := range tlsVersions {
3520 // Assemble flags to disable all newer versions on the shim.
3521 var flags []string
3522 for _, vers := range tlsVersions[i+1:] {
3523 flags = append(flags, vers.flag)
3524 }
3525
3526 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003527 protocols := []protocol{tls}
3528 if runnerVers.hasDTLS && shimVers.hasDTLS {
3529 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003530 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003531 for _, protocol := range protocols {
3532 expectedVersion := shimVers.version
3533 if runnerVers.version < shimVers.version {
3534 expectedVersion = runnerVers.version
3535 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003536
David Benjamin8b8c0062014-11-23 02:47:52 -05003537 suffix := shimVers.name + "-" + runnerVers.name
3538 if protocol == dtls {
3539 suffix += "-DTLS"
3540 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003541
David Benjamin1eb367c2014-12-12 18:17:51 -05003542 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3543
David Benjamin1e29a6b2014-12-10 02:27:24 -05003544 clientVers := shimVers.version
3545 if clientVers > VersionTLS10 {
3546 clientVers = VersionTLS10
3547 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003548 serverVers := expectedVersion
3549 if expectedVersion >= VersionTLS13 {
3550 serverVers = VersionTLS10
3551 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003552 testCases = append(testCases, testCase{
3553 protocol: protocol,
3554 testType: clientTest,
3555 name: "VersionNegotiation-Client-" + suffix,
3556 config: Config{
3557 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003558 Bugs: ProtocolBugs{
3559 ExpectInitialRecordVersion: clientVers,
3560 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003561 },
3562 flags: flags,
3563 expectedVersion: expectedVersion,
3564 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003565 testCases = append(testCases, testCase{
3566 protocol: protocol,
3567 testType: clientTest,
3568 name: "VersionNegotiation-Client2-" + suffix,
3569 config: Config{
3570 MaxVersion: runnerVers.version,
3571 Bugs: ProtocolBugs{
3572 ExpectInitialRecordVersion: clientVers,
3573 },
3574 },
3575 flags: []string{"-max-version", shimVersFlag},
3576 expectedVersion: expectedVersion,
3577 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003578
3579 testCases = append(testCases, testCase{
3580 protocol: protocol,
3581 testType: serverTest,
3582 name: "VersionNegotiation-Server-" + suffix,
3583 config: Config{
3584 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003585 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003586 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003587 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003588 },
3589 flags: flags,
3590 expectedVersion: expectedVersion,
3591 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003592 testCases = append(testCases, testCase{
3593 protocol: protocol,
3594 testType: serverTest,
3595 name: "VersionNegotiation-Server2-" + suffix,
3596 config: Config{
3597 MaxVersion: runnerVers.version,
3598 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003599 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003600 },
3601 },
3602 flags: []string{"-max-version", shimVersFlag},
3603 expectedVersion: expectedVersion,
3604 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003605 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003606 }
3607 }
David Benjamin95c69562016-06-29 18:15:03 -04003608
3609 // Test for version tolerance.
3610 testCases = append(testCases, testCase{
3611 testType: serverTest,
3612 name: "MinorVersionTolerance",
3613 config: Config{
3614 Bugs: ProtocolBugs{
3615 SendClientVersion: 0x03ff,
3616 },
3617 },
3618 expectedVersion: VersionTLS13,
3619 })
3620 testCases = append(testCases, testCase{
3621 testType: serverTest,
3622 name: "MajorVersionTolerance",
3623 config: Config{
3624 Bugs: ProtocolBugs{
3625 SendClientVersion: 0x0400,
3626 },
3627 },
3628 expectedVersion: VersionTLS13,
3629 })
3630 testCases = append(testCases, testCase{
3631 protocol: dtls,
3632 testType: serverTest,
3633 name: "MinorVersionTolerance-DTLS",
3634 config: Config{
3635 Bugs: ProtocolBugs{
3636 SendClientVersion: 0x03ff,
3637 },
3638 },
3639 expectedVersion: VersionTLS12,
3640 })
3641 testCases = append(testCases, testCase{
3642 protocol: dtls,
3643 testType: serverTest,
3644 name: "MajorVersionTolerance-DTLS",
3645 config: Config{
3646 Bugs: ProtocolBugs{
3647 SendClientVersion: 0x0400,
3648 },
3649 },
3650 expectedVersion: VersionTLS12,
3651 })
3652
3653 // Test that versions below 3.0 are rejected.
3654 testCases = append(testCases, testCase{
3655 testType: serverTest,
3656 name: "VersionTooLow",
3657 config: Config{
3658 Bugs: ProtocolBugs{
3659 SendClientVersion: 0x0200,
3660 },
3661 },
3662 shouldFail: true,
3663 expectedError: ":UNSUPPORTED_PROTOCOL:",
3664 })
3665 testCases = append(testCases, testCase{
3666 protocol: dtls,
3667 testType: serverTest,
3668 name: "VersionTooLow-DTLS",
3669 config: Config{
3670 Bugs: ProtocolBugs{
3671 // 0x0201 is the lowest version expressable in
3672 // DTLS.
3673 SendClientVersion: 0x0201,
3674 },
3675 },
3676 shouldFail: true,
3677 expectedError: ":UNSUPPORTED_PROTOCOL:",
3678 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003679
3680 // Test TLS 1.3's downgrade signal.
3681 testCases = append(testCases, testCase{
3682 name: "Downgrade-TLS12-Client",
3683 config: Config{
3684 Bugs: ProtocolBugs{
3685 NegotiateVersion: VersionTLS12,
3686 },
3687 },
3688 shouldFail: true,
3689 expectedError: ":DOWNGRADE_DETECTED:",
3690 })
3691 testCases = append(testCases, testCase{
3692 testType: serverTest,
3693 name: "Downgrade-TLS12-Server",
3694 config: Config{
3695 Bugs: ProtocolBugs{
3696 SendClientVersion: VersionTLS12,
3697 },
3698 },
3699 shouldFail: true,
3700 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3701 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003702}
3703
David Benjaminaccb4542014-12-12 23:44:33 -05003704func addMinimumVersionTests() {
3705 for i, shimVers := range tlsVersions {
3706 // Assemble flags to disable all older versions on the shim.
3707 var flags []string
3708 for _, vers := range tlsVersions[:i] {
3709 flags = append(flags, vers.flag)
3710 }
3711
3712 for _, runnerVers := range tlsVersions {
3713 protocols := []protocol{tls}
3714 if runnerVers.hasDTLS && shimVers.hasDTLS {
3715 protocols = append(protocols, dtls)
3716 }
3717 for _, protocol := range protocols {
3718 suffix := shimVers.name + "-" + runnerVers.name
3719 if protocol == dtls {
3720 suffix += "-DTLS"
3721 }
3722 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3723
David Benjaminaccb4542014-12-12 23:44:33 -05003724 var expectedVersion uint16
3725 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003726 var expectedClientError, expectedServerError string
3727 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003728 if runnerVers.version >= shimVers.version {
3729 expectedVersion = runnerVers.version
3730 } else {
3731 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003732 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3733 expectedServerLocalError = "remote error: protocol version not supported"
3734 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3735 // If the client's minimum version is TLS 1.3 and the runner's
3736 // maximum is below TLS 1.2, the runner will fail to select a
3737 // cipher before the shim rejects the selected version.
3738 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3739 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3740 } else {
3741 expectedClientError = expectedServerError
3742 expectedClientLocalError = expectedServerLocalError
3743 }
David Benjaminaccb4542014-12-12 23:44:33 -05003744 }
3745
3746 testCases = append(testCases, testCase{
3747 protocol: protocol,
3748 testType: clientTest,
3749 name: "MinimumVersion-Client-" + suffix,
3750 config: Config{
3751 MaxVersion: runnerVers.version,
3752 },
David Benjamin87909c02014-12-13 01:55:01 -05003753 flags: flags,
3754 expectedVersion: expectedVersion,
3755 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003756 expectedError: expectedClientError,
3757 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003758 })
3759 testCases = append(testCases, testCase{
3760 protocol: protocol,
3761 testType: clientTest,
3762 name: "MinimumVersion-Client2-" + suffix,
3763 config: Config{
3764 MaxVersion: runnerVers.version,
3765 },
David Benjamin87909c02014-12-13 01:55:01 -05003766 flags: []string{"-min-version", shimVersFlag},
3767 expectedVersion: expectedVersion,
3768 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003769 expectedError: expectedClientError,
3770 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003771 })
3772
3773 testCases = append(testCases, testCase{
3774 protocol: protocol,
3775 testType: serverTest,
3776 name: "MinimumVersion-Server-" + suffix,
3777 config: Config{
3778 MaxVersion: runnerVers.version,
3779 },
David Benjamin87909c02014-12-13 01:55:01 -05003780 flags: flags,
3781 expectedVersion: expectedVersion,
3782 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003783 expectedError: expectedServerError,
3784 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003785 })
3786 testCases = append(testCases, testCase{
3787 protocol: protocol,
3788 testType: serverTest,
3789 name: "MinimumVersion-Server2-" + suffix,
3790 config: Config{
3791 MaxVersion: runnerVers.version,
3792 },
David Benjamin87909c02014-12-13 01:55:01 -05003793 flags: []string{"-min-version", shimVersFlag},
3794 expectedVersion: expectedVersion,
3795 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003796 expectedError: expectedServerError,
3797 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003798 })
3799 }
3800 }
3801 }
3802}
3803
David Benjamine78bfde2014-09-06 12:45:15 -04003804func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003805 // TODO(davidben): Extensions, where applicable, all move their server
3806 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3807 // tests for both. Also test interaction with 0-RTT when implemented.
3808
David Benjamine78bfde2014-09-06 12:45:15 -04003809 testCases = append(testCases, testCase{
3810 testType: clientTest,
3811 name: "DuplicateExtensionClient",
3812 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003813 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003814 Bugs: ProtocolBugs{
3815 DuplicateExtension: true,
3816 },
3817 },
3818 shouldFail: true,
3819 expectedLocalError: "remote error: error decoding message",
3820 })
3821 testCases = append(testCases, testCase{
3822 testType: serverTest,
3823 name: "DuplicateExtensionServer",
3824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003825 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003826 Bugs: ProtocolBugs{
3827 DuplicateExtension: true,
3828 },
3829 },
3830 shouldFail: true,
3831 expectedLocalError: "remote error: error decoding message",
3832 })
3833 testCases = append(testCases, testCase{
3834 testType: clientTest,
3835 name: "ServerNameExtensionClient",
3836 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003837 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003838 Bugs: ProtocolBugs{
3839 ExpectServerName: "example.com",
3840 },
3841 },
3842 flags: []string{"-host-name", "example.com"},
3843 })
3844 testCases = append(testCases, testCase{
3845 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003846 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003848 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003849 Bugs: ProtocolBugs{
3850 ExpectServerName: "mismatch.com",
3851 },
3852 },
3853 flags: []string{"-host-name", "example.com"},
3854 shouldFail: true,
3855 expectedLocalError: "tls: unexpected server name",
3856 })
3857 testCases = append(testCases, testCase{
3858 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003859 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003860 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003861 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003862 Bugs: ProtocolBugs{
3863 ExpectServerName: "missing.com",
3864 },
3865 },
3866 shouldFail: true,
3867 expectedLocalError: "tls: unexpected server name",
3868 })
3869 testCases = append(testCases, testCase{
3870 testType: serverTest,
3871 name: "ServerNameExtensionServer",
3872 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003873 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003874 ServerName: "example.com",
3875 },
3876 flags: []string{"-expect-server-name", "example.com"},
3877 resumeSession: true,
3878 })
David Benjaminae2888f2014-09-06 12:58:58 -04003879 testCases = append(testCases, testCase{
3880 testType: clientTest,
3881 name: "ALPNClient",
3882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003883 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003884 NextProtos: []string{"foo"},
3885 },
3886 flags: []string{
3887 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3888 "-expect-alpn", "foo",
3889 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003890 expectedNextProto: "foo",
3891 expectedNextProtoType: alpn,
3892 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003893 })
3894 testCases = append(testCases, testCase{
3895 testType: serverTest,
3896 name: "ALPNServer",
3897 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003898 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003899 NextProtos: []string{"foo", "bar", "baz"},
3900 },
3901 flags: []string{
3902 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3903 "-select-alpn", "foo",
3904 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003905 expectedNextProto: "foo",
3906 expectedNextProtoType: alpn,
3907 resumeSession: true,
3908 })
David Benjamin594e7d22016-03-17 17:49:56 -04003909 testCases = append(testCases, testCase{
3910 testType: serverTest,
3911 name: "ALPNServer-Decline",
3912 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003913 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003914 NextProtos: []string{"foo", "bar", "baz"},
3915 },
3916 flags: []string{"-decline-alpn"},
3917 expectNoNextProto: true,
3918 resumeSession: true,
3919 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003920 // Test that the server prefers ALPN over NPN.
3921 testCases = append(testCases, testCase{
3922 testType: serverTest,
3923 name: "ALPNServer-Preferred",
3924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003925 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003926 NextProtos: []string{"foo", "bar", "baz"},
3927 },
3928 flags: []string{
3929 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3930 "-select-alpn", "foo",
3931 "-advertise-npn", "\x03foo\x03bar\x03baz",
3932 },
3933 expectedNextProto: "foo",
3934 expectedNextProtoType: alpn,
3935 resumeSession: true,
3936 })
3937 testCases = append(testCases, testCase{
3938 testType: serverTest,
3939 name: "ALPNServer-Preferred-Swapped",
3940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003941 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003942 NextProtos: []string{"foo", "bar", "baz"},
3943 Bugs: ProtocolBugs{
3944 SwapNPNAndALPN: true,
3945 },
3946 },
3947 flags: []string{
3948 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3949 "-select-alpn", "foo",
3950 "-advertise-npn", "\x03foo\x03bar\x03baz",
3951 },
3952 expectedNextProto: "foo",
3953 expectedNextProtoType: alpn,
3954 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003955 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003956 var emptyString string
3957 testCases = append(testCases, testCase{
3958 testType: clientTest,
3959 name: "ALPNClient-EmptyProtocolName",
3960 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003961 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003962 NextProtos: []string{""},
3963 Bugs: ProtocolBugs{
3964 // A server returning an empty ALPN protocol
3965 // should be rejected.
3966 ALPNProtocol: &emptyString,
3967 },
3968 },
3969 flags: []string{
3970 "-advertise-alpn", "\x03foo",
3971 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003972 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003973 expectedError: ":PARSE_TLSEXT:",
3974 })
3975 testCases = append(testCases, testCase{
3976 testType: serverTest,
3977 name: "ALPNServer-EmptyProtocolName",
3978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003980 // A ClientHello containing an empty ALPN protocol
3981 // should be rejected.
3982 NextProtos: []string{"foo", "", "baz"},
3983 },
3984 flags: []string{
3985 "-select-alpn", "foo",
3986 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003987 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003988 expectedError: ":PARSE_TLSEXT:",
3989 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003990 // Test that negotiating both NPN and ALPN is forbidden.
3991 testCases = append(testCases, testCase{
3992 name: "NegotiateALPNAndNPN",
3993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003994 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003995 NextProtos: []string{"foo", "bar", "baz"},
3996 Bugs: ProtocolBugs{
3997 NegotiateALPNAndNPN: true,
3998 },
3999 },
4000 flags: []string{
4001 "-advertise-alpn", "\x03foo",
4002 "-select-next-proto", "foo",
4003 },
4004 shouldFail: true,
4005 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4006 })
4007 testCases = append(testCases, testCase{
4008 name: "NegotiateALPNAndNPN-Swapped",
4009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004010 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04004011 NextProtos: []string{"foo", "bar", "baz"},
4012 Bugs: ProtocolBugs{
4013 NegotiateALPNAndNPN: true,
4014 SwapNPNAndALPN: true,
4015 },
4016 },
4017 flags: []string{
4018 "-advertise-alpn", "\x03foo",
4019 "-select-next-proto", "foo",
4020 },
4021 shouldFail: true,
4022 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4023 })
David Benjamin091c4b92015-10-26 13:33:21 -04004024 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4025 testCases = append(testCases, testCase{
4026 name: "DisableNPN",
4027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004028 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04004029 NextProtos: []string{"foo"},
4030 },
4031 flags: []string{
4032 "-select-next-proto", "foo",
4033 "-disable-npn",
4034 },
4035 expectNoNextProto: true,
4036 })
Adam Langley38311732014-10-16 19:04:35 -07004037 // Resume with a corrupt ticket.
4038 testCases = append(testCases, testCase{
4039 testType: serverTest,
4040 name: "CorruptTicket",
4041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004042 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004043 Bugs: ProtocolBugs{
4044 CorruptTicket: true,
4045 },
4046 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004047 resumeSession: true,
4048 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07004049 })
David Benjamind98452d2015-06-16 14:16:23 -04004050 // Test the ticket callback, with and without renewal.
4051 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004052 testType: serverTest,
4053 name: "TicketCallback",
4054 config: Config{
4055 MaxVersion: VersionTLS12,
4056 },
David Benjamind98452d2015-06-16 14:16:23 -04004057 resumeSession: true,
4058 flags: []string{"-use-ticket-callback"},
4059 })
4060 testCases = append(testCases, testCase{
4061 testType: serverTest,
4062 name: "TicketCallback-Renew",
4063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004064 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004065 Bugs: ProtocolBugs{
4066 ExpectNewTicket: true,
4067 },
4068 },
4069 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4070 resumeSession: true,
4071 })
Adam Langley38311732014-10-16 19:04:35 -07004072 // Resume with an oversized session id.
4073 testCases = append(testCases, testCase{
4074 testType: serverTest,
4075 name: "OversizedSessionId",
4076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004077 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004078 Bugs: ProtocolBugs{
4079 OversizedSessionId: true,
4080 },
4081 },
4082 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004083 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004084 expectedError: ":DECODE_ERROR:",
4085 })
David Benjaminca6c8262014-11-15 19:06:08 -05004086 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4087 // are ignored.
4088 testCases = append(testCases, testCase{
4089 protocol: dtls,
4090 name: "SRTP-Client",
4091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004092 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004093 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4094 },
4095 flags: []string{
4096 "-srtp-profiles",
4097 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4098 },
4099 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4100 })
4101 testCases = append(testCases, testCase{
4102 protocol: dtls,
4103 testType: serverTest,
4104 name: "SRTP-Server",
4105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004106 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004107 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4108 },
4109 flags: []string{
4110 "-srtp-profiles",
4111 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4112 },
4113 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4114 })
4115 // Test that the MKI is ignored.
4116 testCases = append(testCases, testCase{
4117 protocol: dtls,
4118 testType: serverTest,
4119 name: "SRTP-Server-IgnoreMKI",
4120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004121 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004122 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4123 Bugs: ProtocolBugs{
4124 SRTPMasterKeyIdentifer: "bogus",
4125 },
4126 },
4127 flags: []string{
4128 "-srtp-profiles",
4129 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4130 },
4131 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4132 })
4133 // Test that SRTP isn't negotiated on the server if there were
4134 // no matching profiles.
4135 testCases = append(testCases, testCase{
4136 protocol: dtls,
4137 testType: serverTest,
4138 name: "SRTP-Server-NoMatch",
4139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004140 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004141 SRTPProtectionProfiles: []uint16{100, 101, 102},
4142 },
4143 flags: []string{
4144 "-srtp-profiles",
4145 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4146 },
4147 expectedSRTPProtectionProfile: 0,
4148 })
4149 // Test that the server returning an invalid SRTP profile is
4150 // flagged as an error by the client.
4151 testCases = append(testCases, testCase{
4152 protocol: dtls,
4153 name: "SRTP-Client-NoMatch",
4154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004155 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004156 Bugs: ProtocolBugs{
4157 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4158 },
4159 },
4160 flags: []string{
4161 "-srtp-profiles",
4162 "SRTP_AES128_CM_SHA1_80",
4163 },
4164 shouldFail: true,
4165 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4166 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004167 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004168 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004169 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004170 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004171 config: Config{
4172 MaxVersion: VersionTLS12,
4173 },
David Benjamin61f95272014-11-25 01:55:35 -05004174 flags: []string{
4175 "-enable-signed-cert-timestamps",
4176 "-expect-signed-cert-timestamps",
4177 base64.StdEncoding.EncodeToString(testSCTList),
4178 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004179 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004180 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004181 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004182 name: "SendSCTListOnResume",
4183 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004184 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004185 Bugs: ProtocolBugs{
4186 SendSCTListOnResume: []byte("bogus"),
4187 },
4188 },
4189 flags: []string{
4190 "-enable-signed-cert-timestamps",
4191 "-expect-signed-cert-timestamps",
4192 base64.StdEncoding.EncodeToString(testSCTList),
4193 },
4194 resumeSession: true,
4195 })
4196 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004197 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004198 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004199 config: Config{
4200 MaxVersion: VersionTLS12,
4201 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004202 flags: []string{
4203 "-signed-cert-timestamps",
4204 base64.StdEncoding.EncodeToString(testSCTList),
4205 },
4206 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004207 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004208 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004209
Paul Lietar4fac72e2015-09-09 13:44:55 +01004210 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004211 testType: clientTest,
4212 name: "ClientHelloPadding",
4213 config: Config{
4214 Bugs: ProtocolBugs{
4215 RequireClientHelloSize: 512,
4216 },
4217 },
4218 // This hostname just needs to be long enough to push the
4219 // ClientHello into F5's danger zone between 256 and 511 bytes
4220 // long.
4221 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4222 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004223
4224 // Extensions should not function in SSL 3.0.
4225 testCases = append(testCases, testCase{
4226 testType: serverTest,
4227 name: "SSLv3Extensions-NoALPN",
4228 config: Config{
4229 MaxVersion: VersionSSL30,
4230 NextProtos: []string{"foo", "bar", "baz"},
4231 },
4232 flags: []string{
4233 "-select-alpn", "foo",
4234 },
4235 expectNoNextProto: true,
4236 })
4237
4238 // Test session tickets separately as they follow a different codepath.
4239 testCases = append(testCases, testCase{
4240 testType: serverTest,
4241 name: "SSLv3Extensions-NoTickets",
4242 config: Config{
4243 MaxVersion: VersionSSL30,
4244 Bugs: ProtocolBugs{
4245 // Historically, session tickets in SSL 3.0
4246 // failed in different ways depending on whether
4247 // the client supported renegotiation_info.
4248 NoRenegotiationInfo: true,
4249 },
4250 },
4251 resumeSession: true,
4252 })
4253 testCases = append(testCases, testCase{
4254 testType: serverTest,
4255 name: "SSLv3Extensions-NoTickets2",
4256 config: Config{
4257 MaxVersion: VersionSSL30,
4258 },
4259 resumeSession: true,
4260 })
4261
4262 // But SSL 3.0 does send and process renegotiation_info.
4263 testCases = append(testCases, testCase{
4264 testType: serverTest,
4265 name: "SSLv3Extensions-RenegotiationInfo",
4266 config: Config{
4267 MaxVersion: VersionSSL30,
4268 Bugs: ProtocolBugs{
4269 RequireRenegotiationInfo: true,
4270 },
4271 },
4272 })
4273 testCases = append(testCases, testCase{
4274 testType: serverTest,
4275 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4276 config: Config{
4277 MaxVersion: VersionSSL30,
4278 Bugs: ProtocolBugs{
4279 NoRenegotiationInfo: true,
4280 SendRenegotiationSCSV: true,
4281 RequireRenegotiationInfo: true,
4282 },
4283 },
4284 })
David Benjamine78bfde2014-09-06 12:45:15 -04004285}
4286
David Benjamin01fe8202014-09-24 15:21:44 -04004287func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004288 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004289 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4290 if sessionVers.version >= VersionTLS13 {
4291 continue
4292 }
David Benjamin01fe8202014-09-24 15:21:44 -04004293 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004294 if resumeVers.version >= VersionTLS13 {
4295 continue
4296 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004297 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4298 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4299 // TLS 1.3 only shares ciphers with TLS 1.2, so
4300 // we skip certain combinations and use a
4301 // different cipher to test with.
4302 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4303 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4304 continue
4305 }
4306 }
4307
David Benjamin8b8c0062014-11-23 02:47:52 -05004308 protocols := []protocol{tls}
4309 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4310 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004311 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004312 for _, protocol := range protocols {
4313 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4314 if protocol == dtls {
4315 suffix += "-DTLS"
4316 }
4317
David Benjaminece3de92015-03-16 18:02:20 -04004318 if sessionVers.version == resumeVers.version {
4319 testCases = append(testCases, testCase{
4320 protocol: protocol,
4321 name: "Resume-Client" + suffix,
4322 resumeSession: true,
4323 config: Config{
4324 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004325 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004326 },
David Benjaminece3de92015-03-16 18:02:20 -04004327 expectedVersion: sessionVers.version,
4328 expectedResumeVersion: resumeVers.version,
4329 })
4330 } else {
4331 testCases = append(testCases, testCase{
4332 protocol: protocol,
4333 name: "Resume-Client-Mismatch" + suffix,
4334 resumeSession: true,
4335 config: Config{
4336 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004337 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004338 },
David Benjaminece3de92015-03-16 18:02:20 -04004339 expectedVersion: sessionVers.version,
4340 resumeConfig: &Config{
4341 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004342 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004343 Bugs: ProtocolBugs{
4344 AllowSessionVersionMismatch: true,
4345 },
4346 },
4347 expectedResumeVersion: resumeVers.version,
4348 shouldFail: true,
4349 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4350 })
4351 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004352
4353 testCases = append(testCases, testCase{
4354 protocol: protocol,
4355 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004356 resumeSession: true,
4357 config: Config{
4358 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004359 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004360 },
4361 expectedVersion: sessionVers.version,
4362 resumeConfig: &Config{
4363 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004364 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004365 },
4366 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004367 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004368 expectedResumeVersion: resumeVers.version,
4369 })
4370
David Benjamin8b8c0062014-11-23 02:47:52 -05004371 testCases = append(testCases, testCase{
4372 protocol: protocol,
4373 testType: serverTest,
4374 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004375 resumeSession: true,
4376 config: Config{
4377 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004378 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004379 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004380 expectedVersion: sessionVers.version,
4381 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004382 resumeConfig: &Config{
4383 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004384 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004385 },
4386 expectedResumeVersion: resumeVers.version,
4387 })
4388 }
David Benjamin01fe8202014-09-24 15:21:44 -04004389 }
4390 }
David Benjaminece3de92015-03-16 18:02:20 -04004391
Nick Harper1fd39d82016-06-14 18:14:35 -07004392 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004393 testCases = append(testCases, testCase{
4394 name: "Resume-Client-CipherMismatch",
4395 resumeSession: true,
4396 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004397 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004398 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4399 },
4400 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004401 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004402 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4403 Bugs: ProtocolBugs{
4404 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4405 },
4406 },
4407 shouldFail: true,
4408 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4409 })
David Benjamin01fe8202014-09-24 15:21:44 -04004410}
4411
Adam Langley2ae77d22014-10-28 17:29:33 -07004412func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004413 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004414 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004415 testType: serverTest,
4416 name: "Renegotiate-Server-Forbidden",
4417 config: Config{
4418 MaxVersion: VersionTLS12,
4419 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004420 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004421 shouldFail: true,
4422 expectedError: ":NO_RENEGOTIATION:",
4423 expectedLocalError: "remote error: no renegotiation",
4424 })
Adam Langley5021b222015-06-12 18:27:58 -07004425 // The server shouldn't echo the renegotiation extension unless
4426 // requested by the client.
4427 testCases = append(testCases, testCase{
4428 testType: serverTest,
4429 name: "Renegotiate-Server-NoExt",
4430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004431 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004432 Bugs: ProtocolBugs{
4433 NoRenegotiationInfo: true,
4434 RequireRenegotiationInfo: true,
4435 },
4436 },
4437 shouldFail: true,
4438 expectedLocalError: "renegotiation extension missing",
4439 })
4440 // The renegotiation SCSV should be sufficient for the server to echo
4441 // the extension.
4442 testCases = append(testCases, testCase{
4443 testType: serverTest,
4444 name: "Renegotiate-Server-NoExt-SCSV",
4445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004446 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004447 Bugs: ProtocolBugs{
4448 NoRenegotiationInfo: true,
4449 SendRenegotiationSCSV: true,
4450 RequireRenegotiationInfo: true,
4451 },
4452 },
4453 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004454 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004455 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004457 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004458 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004459 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004460 },
4461 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004462 renegotiate: 1,
4463 flags: []string{
4464 "-renegotiate-freely",
4465 "-expect-total-renegotiations", "1",
4466 },
David Benjamincdea40c2015-03-19 14:09:43 -04004467 })
4468 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004469 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004470 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004472 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004473 Bugs: ProtocolBugs{
4474 EmptyRenegotiationInfo: true,
4475 },
4476 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004477 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004478 shouldFail: true,
4479 expectedError: ":RENEGOTIATION_MISMATCH:",
4480 })
4481 testCases = append(testCases, testCase{
4482 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004483 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004484 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004485 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004486 Bugs: ProtocolBugs{
4487 BadRenegotiationInfo: true,
4488 },
4489 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004490 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004491 shouldFail: true,
4492 expectedError: ":RENEGOTIATION_MISMATCH:",
4493 })
4494 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004495 name: "Renegotiate-Client-Downgrade",
4496 renegotiate: 1,
4497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004498 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004499 Bugs: ProtocolBugs{
4500 NoRenegotiationInfoAfterInitial: true,
4501 },
4502 },
4503 flags: []string{"-renegotiate-freely"},
4504 shouldFail: true,
4505 expectedError: ":RENEGOTIATION_MISMATCH:",
4506 })
4507 testCases = append(testCases, testCase{
4508 name: "Renegotiate-Client-Upgrade",
4509 renegotiate: 1,
4510 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004511 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004512 Bugs: ProtocolBugs{
4513 NoRenegotiationInfoInInitial: true,
4514 },
4515 },
4516 flags: []string{"-renegotiate-freely"},
4517 shouldFail: true,
4518 expectedError: ":RENEGOTIATION_MISMATCH:",
4519 })
4520 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004521 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004522 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004523 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004524 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004525 Bugs: ProtocolBugs{
4526 NoRenegotiationInfo: true,
4527 },
4528 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004529 flags: []string{
4530 "-renegotiate-freely",
4531 "-expect-total-renegotiations", "1",
4532 },
David Benjamincff0b902015-05-15 23:09:47 -04004533 })
4534 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004535 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004536 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004537 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004538 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004539 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4540 },
4541 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004542 flags: []string{
4543 "-renegotiate-freely",
4544 "-expect-total-renegotiations", "1",
4545 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004546 })
4547 testCases = append(testCases, testCase{
4548 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004549 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004550 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004551 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004552 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4553 },
4554 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004555 flags: []string{
4556 "-renegotiate-freely",
4557 "-expect-total-renegotiations", "1",
4558 },
David Benjaminb16346b2015-04-08 19:16:58 -04004559 })
4560 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004561 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004562 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004563 config: Config{
4564 MaxVersion: VersionTLS10,
4565 Bugs: ProtocolBugs{
4566 RequireSameRenegoClientVersion: true,
4567 },
4568 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004569 flags: []string{
4570 "-renegotiate-freely",
4571 "-expect-total-renegotiations", "1",
4572 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004573 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004574 testCases = append(testCases, testCase{
4575 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004576 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004577 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004578 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004579 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4580 NextProtos: []string{"foo"},
4581 },
4582 flags: []string{
4583 "-false-start",
4584 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004585 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004586 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004587 },
4588 shimWritesFirst: true,
4589 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004590
4591 // Client-side renegotiation controls.
4592 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004593 name: "Renegotiate-Client-Forbidden-1",
4594 config: Config{
4595 MaxVersion: VersionTLS12,
4596 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004597 renegotiate: 1,
4598 shouldFail: true,
4599 expectedError: ":NO_RENEGOTIATION:",
4600 expectedLocalError: "remote error: no renegotiation",
4601 })
4602 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004603 name: "Renegotiate-Client-Once-1",
4604 config: Config{
4605 MaxVersion: VersionTLS12,
4606 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004607 renegotiate: 1,
4608 flags: []string{
4609 "-renegotiate-once",
4610 "-expect-total-renegotiations", "1",
4611 },
4612 })
4613 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004614 name: "Renegotiate-Client-Freely-1",
4615 config: Config{
4616 MaxVersion: VersionTLS12,
4617 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004618 renegotiate: 1,
4619 flags: []string{
4620 "-renegotiate-freely",
4621 "-expect-total-renegotiations", "1",
4622 },
4623 })
4624 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004625 name: "Renegotiate-Client-Once-2",
4626 config: Config{
4627 MaxVersion: VersionTLS12,
4628 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004629 renegotiate: 2,
4630 flags: []string{"-renegotiate-once"},
4631 shouldFail: true,
4632 expectedError: ":NO_RENEGOTIATION:",
4633 expectedLocalError: "remote error: no renegotiation",
4634 })
4635 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004636 name: "Renegotiate-Client-Freely-2",
4637 config: Config{
4638 MaxVersion: VersionTLS12,
4639 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004640 renegotiate: 2,
4641 flags: []string{
4642 "-renegotiate-freely",
4643 "-expect-total-renegotiations", "2",
4644 },
4645 })
Adam Langley27a0d082015-11-03 13:34:10 -08004646 testCases = append(testCases, testCase{
4647 name: "Renegotiate-Client-NoIgnore",
4648 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004649 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004650 Bugs: ProtocolBugs{
4651 SendHelloRequestBeforeEveryAppDataRecord: true,
4652 },
4653 },
4654 shouldFail: true,
4655 expectedError: ":NO_RENEGOTIATION:",
4656 })
4657 testCases = append(testCases, testCase{
4658 name: "Renegotiate-Client-Ignore",
4659 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004660 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004661 Bugs: ProtocolBugs{
4662 SendHelloRequestBeforeEveryAppDataRecord: true,
4663 },
4664 },
4665 flags: []string{
4666 "-renegotiate-ignore",
4667 "-expect-total-renegotiations", "0",
4668 },
4669 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004670
David Benjamin397c8e62016-07-08 14:14:36 -07004671 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004672 testCases = append(testCases, testCase{
4673 name: "StrayHelloRequest",
4674 config: Config{
4675 MaxVersion: VersionTLS12,
4676 Bugs: ProtocolBugs{
4677 SendHelloRequestBeforeEveryHandshakeMessage: true,
4678 },
4679 },
4680 })
4681 testCases = append(testCases, testCase{
4682 name: "StrayHelloRequest-Packed",
4683 config: Config{
4684 MaxVersion: VersionTLS12,
4685 Bugs: ProtocolBugs{
4686 PackHandshakeFlight: true,
4687 SendHelloRequestBeforeEveryHandshakeMessage: true,
4688 },
4689 },
4690 })
4691
David Benjamin397c8e62016-07-08 14:14:36 -07004692 // Renegotiation is forbidden in TLS 1.3.
4693 testCases = append(testCases, testCase{
4694 name: "Renegotiate-Client-TLS13",
4695 config: Config{
4696 MaxVersion: VersionTLS13,
4697 },
4698 renegotiate: 1,
4699 flags: []string{
4700 "-renegotiate-freely",
4701 },
4702 shouldFail: true,
4703 expectedError: ":NO_RENEGOTIATION:",
4704 })
4705
4706 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4707 testCases = append(testCases, testCase{
4708 name: "StrayHelloRequest-TLS13",
4709 config: Config{
4710 MaxVersion: VersionTLS13,
4711 Bugs: ProtocolBugs{
4712 SendHelloRequestBeforeEveryHandshakeMessage: true,
4713 },
4714 },
4715 shouldFail: true,
4716 expectedError: ":UNEXPECTED_MESSAGE:",
4717 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004718}
4719
David Benjamin5e961c12014-11-07 01:48:35 -05004720func addDTLSReplayTests() {
4721 // Test that sequence number replays are detected.
4722 testCases = append(testCases, testCase{
4723 protocol: dtls,
4724 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004725 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004726 replayWrites: true,
4727 })
4728
David Benjamin8e6db492015-07-25 18:29:23 -04004729 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004730 // than the retransmit window.
4731 testCases = append(testCases, testCase{
4732 protocol: dtls,
4733 name: "DTLS-Replay-LargeGaps",
4734 config: Config{
4735 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004736 SequenceNumberMapping: func(in uint64) uint64 {
4737 return in * 127
4738 },
David Benjamin5e961c12014-11-07 01:48:35 -05004739 },
4740 },
David Benjamin8e6db492015-07-25 18:29:23 -04004741 messageCount: 200,
4742 replayWrites: true,
4743 })
4744
4745 // Test the incoming sequence number changing non-monotonically.
4746 testCases = append(testCases, testCase{
4747 protocol: dtls,
4748 name: "DTLS-Replay-NonMonotonic",
4749 config: Config{
4750 Bugs: ProtocolBugs{
4751 SequenceNumberMapping: func(in uint64) uint64 {
4752 return in ^ 31
4753 },
4754 },
4755 },
4756 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004757 replayWrites: true,
4758 })
4759}
4760
Nick Harper60edffd2016-06-21 15:19:24 -07004761var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004762 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004763 id signatureAlgorithm
4764 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004765}{
Nick Harper60edffd2016-06-21 15:19:24 -07004766 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4767 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4768 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4769 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004770 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07004771 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4772 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4773 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004774 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
4775 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
4776 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin000800a2014-11-14 01:43:59 -05004777}
4778
Nick Harper60edffd2016-06-21 15:19:24 -07004779const fakeSigAlg1 signatureAlgorithm = 0x2a01
4780const fakeSigAlg2 signatureAlgorithm = 0xff01
4781
4782func addSignatureAlgorithmTests() {
4783 // Make sure each signature algorithm works. Include some fake values in
4784 // the list and ensure they're ignored.
4785 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07004786 for _, ver := range tlsVersions {
4787 if ver.version < VersionTLS12 {
4788 continue
4789 }
Nick Harper60edffd2016-06-21 15:19:24 -07004790
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004791 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07004792 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004793 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
4794 shouldFail = true
4795 }
4796 // RSA-PSS does not exist in TLS 1.2.
4797 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
4798 shouldFail = true
4799 }
4800
4801 var signError, verifyError string
4802 if shouldFail {
4803 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
4804 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07004805 }
David Benjamin000800a2014-11-14 01:43:59 -05004806
David Benjamin1fb125c2016-07-08 18:52:12 -07004807 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05004808
David Benjamin7a41d372016-07-09 11:21:54 -07004809 testCases = append(testCases, testCase{
4810 name: "SigningHash-ClientAuth-Sign" + suffix,
4811 config: Config{
4812 MaxVersion: ver.version,
4813 ClientAuth: RequireAnyClientCert,
4814 VerifySignatureAlgorithms: []signatureAlgorithm{
4815 fakeSigAlg1,
4816 alg.id,
4817 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07004818 },
David Benjamin7a41d372016-07-09 11:21:54 -07004819 },
4820 flags: []string{
4821 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4822 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4823 "-enable-all-curves",
4824 },
4825 shouldFail: shouldFail,
4826 expectedError: signError,
4827 expectedPeerSignatureAlgorithm: alg.id,
4828 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004829
David Benjamin7a41d372016-07-09 11:21:54 -07004830 testCases = append(testCases, testCase{
4831 testType: serverTest,
4832 name: "SigningHash-ClientAuth-Verify" + suffix,
4833 config: Config{
4834 MaxVersion: ver.version,
4835 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4836 SignSignatureAlgorithms: []signatureAlgorithm{
4837 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004838 },
David Benjamin7a41d372016-07-09 11:21:54 -07004839 Bugs: ProtocolBugs{
4840 SkipECDSACurveCheck: shouldFail,
4841 IgnoreSignatureVersionChecks: shouldFail,
4842 // The client won't advertise 1.3-only algorithms after
4843 // version negotiation.
4844 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004845 },
David Benjamin7a41d372016-07-09 11:21:54 -07004846 },
4847 flags: []string{
4848 "-require-any-client-certificate",
4849 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4850 "-enable-all-curves",
4851 },
4852 shouldFail: shouldFail,
4853 expectedError: verifyError,
4854 })
David Benjamin1fb125c2016-07-08 18:52:12 -07004855
4856 testCases = append(testCases, testCase{
4857 testType: serverTest,
4858 name: "SigningHash-ServerKeyExchange-Sign" + suffix,
4859 config: Config{
4860 MaxVersion: ver.version,
4861 CipherSuites: []uint16{
4862 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4863 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4864 },
David Benjamin7a41d372016-07-09 11:21:54 -07004865 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004866 fakeSigAlg1,
4867 alg.id,
4868 fakeSigAlg2,
4869 },
4870 },
4871 flags: []string{
4872 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4873 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4874 "-enable-all-curves",
4875 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004876 shouldFail: shouldFail,
4877 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004878 expectedPeerSignatureAlgorithm: alg.id,
4879 })
4880
4881 testCases = append(testCases, testCase{
4882 name: "SigningHash-ServerKeyExchange-Verify" + suffix,
4883 config: Config{
4884 MaxVersion: ver.version,
4885 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4886 CipherSuites: []uint16{
4887 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4888 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4889 },
David Benjamin7a41d372016-07-09 11:21:54 -07004890 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004891 alg.id,
4892 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004893 Bugs: ProtocolBugs{
4894 SkipECDSACurveCheck: shouldFail,
4895 IgnoreSignatureVersionChecks: shouldFail,
4896 },
David Benjamin1fb125c2016-07-08 18:52:12 -07004897 },
4898 flags: []string{
4899 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4900 "-enable-all-curves",
4901 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004902 shouldFail: shouldFail,
4903 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004904 })
4905 }
David Benjamin000800a2014-11-14 01:43:59 -05004906 }
4907
Nick Harper60edffd2016-06-21 15:19:24 -07004908 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004909 //
4910 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004911 testCases = append(testCases, testCase{
4912 name: "SigningHash-ClientAuth-SignatureType",
4913 config: Config{
4914 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004915 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07004916 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004917 signatureECDSAWithP521AndSHA512,
4918 signatureRSAPKCS1WithSHA384,
4919 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004920 },
4921 },
4922 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004923 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4924 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004925 },
Nick Harper60edffd2016-06-21 15:19:24 -07004926 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004927 })
4928
4929 testCases = append(testCases, testCase{
4930 testType: serverTest,
4931 name: "SigningHash-ServerKeyExchange-SignatureType",
4932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004933 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004934 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004935 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004936 signatureECDSAWithP521AndSHA512,
4937 signatureRSAPKCS1WithSHA384,
4938 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004939 },
4940 },
Nick Harper60edffd2016-06-21 15:19:24 -07004941 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004942 })
4943
David Benjamina95e9f32016-07-08 16:28:04 -07004944 // Test that signature verification takes the key type into account.
4945 //
4946 // TODO(davidben): Test this in TLS 1.3.
4947 testCases = append(testCases, testCase{
4948 testType: serverTest,
4949 name: "Verify-ClientAuth-SignatureType",
4950 config: Config{
4951 MaxVersion: VersionTLS12,
4952 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004953 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004954 signatureRSAPKCS1WithSHA256,
4955 },
4956 Bugs: ProtocolBugs{
4957 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4958 },
4959 },
4960 flags: []string{
4961 "-require-any-client-certificate",
4962 },
4963 shouldFail: true,
4964 expectedError: ":WRONG_SIGNATURE_TYPE:",
4965 })
4966
4967 testCases = append(testCases, testCase{
4968 name: "Verify-ServerKeyExchange-SignatureType",
4969 config: Config{
4970 MaxVersion: VersionTLS12,
4971 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004972 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004973 signatureRSAPKCS1WithSHA256,
4974 },
4975 Bugs: ProtocolBugs{
4976 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4977 },
4978 },
4979 shouldFail: true,
4980 expectedError: ":WRONG_SIGNATURE_TYPE:",
4981 })
4982
David Benjamin51dd7d62016-07-08 16:07:01 -07004983 // Test that, if the list is missing, the peer falls back to SHA-1 in
4984 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004985 testCases = append(testCases, testCase{
4986 name: "SigningHash-ClientAuth-Fallback",
4987 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004988 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004989 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004990 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004991 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004992 },
4993 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004994 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004995 },
4996 },
4997 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004998 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4999 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005000 },
5001 })
5002
5003 testCases = append(testCases, testCase{
5004 testType: serverTest,
5005 name: "SigningHash-ServerKeyExchange-Fallback",
5006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005007 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005008 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005009 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005010 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005011 },
5012 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005013 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005014 },
5015 },
5016 })
David Benjamin72dc7832015-03-16 17:49:43 -04005017
David Benjamin51dd7d62016-07-08 16:07:01 -07005018 testCases = append(testCases, testCase{
5019 name: "SigningHash-ClientAuth-Fallback-TLS13",
5020 config: Config{
5021 MaxVersion: VersionTLS13,
5022 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005023 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005024 signatureRSAPKCS1WithSHA1,
5025 },
5026 Bugs: ProtocolBugs{
5027 NoSignatureAlgorithms: true,
5028 },
5029 },
5030 flags: []string{
5031 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5032 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5033 },
5034 shouldFail: true,
5035 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5036 })
5037
5038 testCases = append(testCases, testCase{
5039 testType: serverTest,
5040 name: "SigningHash-ServerKeyExchange-Fallback-TLS13",
5041 config: Config{
5042 MaxVersion: VersionTLS13,
5043 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005044 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005045 signatureRSAPKCS1WithSHA1,
5046 },
5047 Bugs: ProtocolBugs{
5048 NoSignatureAlgorithms: true,
5049 },
5050 },
5051 shouldFail: true,
5052 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5053 })
5054
David Benjamin72dc7832015-03-16 17:49:43 -04005055 // Test that hash preferences are enforced. BoringSSL defaults to
5056 // rejecting MD5 signatures.
5057 testCases = append(testCases, testCase{
5058 testType: serverTest,
5059 name: "SigningHash-ClientAuth-Enforced",
5060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005061 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005062 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005063 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005064 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005065 // Advertise SHA-1 so the handshake will
5066 // proceed, but the shim's preferences will be
5067 // ignored in CertificateVerify generation, so
5068 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005069 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005070 },
5071 Bugs: ProtocolBugs{
5072 IgnorePeerSignatureAlgorithmPreferences: true,
5073 },
5074 },
5075 flags: []string{"-require-any-client-certificate"},
5076 shouldFail: true,
5077 expectedError: ":WRONG_SIGNATURE_TYPE:",
5078 })
5079
5080 testCases = append(testCases, testCase{
5081 name: "SigningHash-ServerKeyExchange-Enforced",
5082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005083 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005084 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005085 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005086 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005087 },
5088 Bugs: ProtocolBugs{
5089 IgnorePeerSignatureAlgorithmPreferences: true,
5090 },
5091 },
5092 shouldFail: true,
5093 expectedError: ":WRONG_SIGNATURE_TYPE:",
5094 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005095
5096 // Test that the agreed upon digest respects the client preferences and
5097 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005098 //
5099 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04005100 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005101 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005102 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005103 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005104 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005105 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005106 signatureRSAPKCS1WithSHA512,
5107 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005108 },
5109 },
5110 flags: []string{
5111 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5112 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5113 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005114 digestPrefs: "SHA256",
5115 shouldFail: true,
5116 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005117 })
5118 testCases = append(testCases, testCase{
5119 name: "Agree-Digest-SHA256",
5120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005121 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005122 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005123 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005124 signatureRSAPKCS1WithSHA1,
5125 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005126 },
5127 },
5128 flags: []string{
5129 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5130 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5131 },
Nick Harper60edffd2016-06-21 15:19:24 -07005132 digestPrefs: "SHA256,SHA1",
5133 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005134 })
5135 testCases = append(testCases, testCase{
5136 name: "Agree-Digest-SHA1",
5137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005138 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005139 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005140 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005141 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005142 },
5143 },
5144 flags: []string{
5145 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5146 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5147 },
Nick Harper60edffd2016-06-21 15:19:24 -07005148 digestPrefs: "SHA512,SHA256,SHA1",
5149 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005150 })
5151 testCases = append(testCases, testCase{
5152 name: "Agree-Digest-Default",
5153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005154 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005155 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005156 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005157 signatureRSAPKCS1WithSHA256,
5158 signatureECDSAWithP256AndSHA256,
5159 signatureRSAPKCS1WithSHA1,
5160 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005161 },
5162 },
5163 flags: []string{
5164 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5165 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5166 },
Nick Harper60edffd2016-06-21 15:19:24 -07005167 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005168 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005169
5170 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5171 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005172 testCases = append(testCases, testCase{
5173 name: "CheckLeafCurve",
5174 config: Config{
5175 MaxVersion: VersionTLS12,
5176 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005177 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005178 },
5179 flags: []string{"-p384-only"},
5180 shouldFail: true,
5181 expectedError: ":BAD_ECC_CERT:",
5182 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005183
5184 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5185 testCases = append(testCases, testCase{
5186 name: "CheckLeafCurve-TLS13",
5187 config: Config{
5188 MaxVersion: VersionTLS13,
5189 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5190 Certificates: []Certificate{ecdsaP256Certificate},
5191 },
5192 flags: []string{"-p384-only"},
5193 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005194
5195 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5196 testCases = append(testCases, testCase{
5197 name: "ECDSACurveMismatch-Verify-TLS12",
5198 config: Config{
5199 MaxVersion: VersionTLS12,
5200 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5201 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005202 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005203 signatureECDSAWithP384AndSHA384,
5204 },
5205 },
5206 })
5207
5208 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5209 testCases = append(testCases, testCase{
5210 name: "ECDSACurveMismatch-Verify-TLS13",
5211 config: Config{
5212 MaxVersion: VersionTLS13,
5213 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5214 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005215 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005216 signatureECDSAWithP384AndSHA384,
5217 },
5218 Bugs: ProtocolBugs{
5219 SkipECDSACurveCheck: true,
5220 },
5221 },
5222 shouldFail: true,
5223 expectedError: ":WRONG_SIGNATURE_TYPE:",
5224 })
5225
5226 // Signature algorithm selection in TLS 1.3 should take the curve into
5227 // account.
5228 testCases = append(testCases, testCase{
5229 testType: serverTest,
5230 name: "ECDSACurveMismatch-Sign-TLS13",
5231 config: Config{
5232 MaxVersion: VersionTLS13,
5233 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005234 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005235 signatureECDSAWithP384AndSHA384,
5236 signatureECDSAWithP256AndSHA256,
5237 },
5238 },
5239 flags: []string{
5240 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5241 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5242 },
5243 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5244 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005245
5246 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5247 // server does not attempt to sign in that case.
5248 testCases = append(testCases, testCase{
5249 testType: serverTest,
5250 name: "RSA-PSS-Large",
5251 config: Config{
5252 MaxVersion: VersionTLS13,
5253 VerifySignatureAlgorithms: []signatureAlgorithm{
5254 signatureRSAPSSWithSHA512,
5255 },
5256 },
5257 flags: []string{
5258 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5259 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5260 },
5261 shouldFail: true,
5262 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5263 })
David Benjamin000800a2014-11-14 01:43:59 -05005264}
5265
David Benjamin83f90402015-01-27 01:09:43 -05005266// timeouts is the retransmit schedule for BoringSSL. It doubles and
5267// caps at 60 seconds. On the 13th timeout, it gives up.
5268var timeouts = []time.Duration{
5269 1 * time.Second,
5270 2 * time.Second,
5271 4 * time.Second,
5272 8 * time.Second,
5273 16 * time.Second,
5274 32 * time.Second,
5275 60 * time.Second,
5276 60 * time.Second,
5277 60 * time.Second,
5278 60 * time.Second,
5279 60 * time.Second,
5280 60 * time.Second,
5281 60 * time.Second,
5282}
5283
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005284// shortTimeouts is an alternate set of timeouts which would occur if the
5285// initial timeout duration was set to 250ms.
5286var shortTimeouts = []time.Duration{
5287 250 * time.Millisecond,
5288 500 * time.Millisecond,
5289 1 * time.Second,
5290 2 * time.Second,
5291 4 * time.Second,
5292 8 * time.Second,
5293 16 * time.Second,
5294 32 * time.Second,
5295 60 * time.Second,
5296 60 * time.Second,
5297 60 * time.Second,
5298 60 * time.Second,
5299 60 * time.Second,
5300}
5301
David Benjamin83f90402015-01-27 01:09:43 -05005302func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005303 // These tests work by coordinating some behavior on both the shim and
5304 // the runner.
5305 //
5306 // TimeoutSchedule configures the runner to send a series of timeout
5307 // opcodes to the shim (see packetAdaptor) immediately before reading
5308 // each peer handshake flight N. The timeout opcode both simulates a
5309 // timeout in the shim and acts as a synchronization point to help the
5310 // runner bracket each handshake flight.
5311 //
5312 // We assume the shim does not read from the channel eagerly. It must
5313 // first wait until it has sent flight N and is ready to receive
5314 // handshake flight N+1. At this point, it will process the timeout
5315 // opcode. It must then immediately respond with a timeout ACK and act
5316 // as if the shim was idle for the specified amount of time.
5317 //
5318 // The runner then drops all packets received before the ACK and
5319 // continues waiting for flight N. This ordering results in one attempt
5320 // at sending flight N to be dropped. For the test to complete, the
5321 // shim must send flight N again, testing that the shim implements DTLS
5322 // retransmit on a timeout.
5323
David Benjamin4c3ddf72016-06-29 18:13:53 -04005324 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5325 // likely be more epochs to cross and the final message's retransmit may
5326 // be more complex.
5327
David Benjamin585d7a42016-06-02 14:58:00 -04005328 for _, async := range []bool{true, false} {
5329 var tests []testCase
5330
5331 // Test that this is indeed the timeout schedule. Stress all
5332 // four patterns of handshake.
5333 for i := 1; i < len(timeouts); i++ {
5334 number := strconv.Itoa(i)
5335 tests = append(tests, testCase{
5336 protocol: dtls,
5337 name: "DTLS-Retransmit-Client-" + number,
5338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005339 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005340 Bugs: ProtocolBugs{
5341 TimeoutSchedule: timeouts[:i],
5342 },
5343 },
5344 resumeSession: true,
5345 })
5346 tests = append(tests, testCase{
5347 protocol: dtls,
5348 testType: serverTest,
5349 name: "DTLS-Retransmit-Server-" + number,
5350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005351 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005352 Bugs: ProtocolBugs{
5353 TimeoutSchedule: timeouts[:i],
5354 },
5355 },
5356 resumeSession: true,
5357 })
5358 }
5359
5360 // Test that exceeding the timeout schedule hits a read
5361 // timeout.
5362 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005363 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005364 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005365 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005366 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005367 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005368 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005369 },
5370 },
5371 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005372 shouldFail: true,
5373 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005374 })
David Benjamin585d7a42016-06-02 14:58:00 -04005375
5376 if async {
5377 // Test that timeout handling has a fudge factor, due to API
5378 // problems.
5379 tests = append(tests, testCase{
5380 protocol: dtls,
5381 name: "DTLS-Retransmit-Fudge",
5382 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005383 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005384 Bugs: ProtocolBugs{
5385 TimeoutSchedule: []time.Duration{
5386 timeouts[0] - 10*time.Millisecond,
5387 },
5388 },
5389 },
5390 resumeSession: true,
5391 })
5392 }
5393
5394 // Test that the final Finished retransmitting isn't
5395 // duplicated if the peer badly fragments everything.
5396 tests = append(tests, testCase{
5397 testType: serverTest,
5398 protocol: dtls,
5399 name: "DTLS-Retransmit-Fragmented",
5400 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005401 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005402 Bugs: ProtocolBugs{
5403 TimeoutSchedule: []time.Duration{timeouts[0]},
5404 MaxHandshakeRecordLength: 2,
5405 },
5406 },
5407 })
5408
5409 // Test the timeout schedule when a shorter initial timeout duration is set.
5410 tests = append(tests, testCase{
5411 protocol: dtls,
5412 name: "DTLS-Retransmit-Short-Client",
5413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005414 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005415 Bugs: ProtocolBugs{
5416 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5417 },
5418 },
5419 resumeSession: true,
5420 flags: []string{"-initial-timeout-duration-ms", "250"},
5421 })
5422 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005423 protocol: dtls,
5424 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005425 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005426 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005427 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005428 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005429 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005430 },
5431 },
5432 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005433 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005434 })
David Benjamin585d7a42016-06-02 14:58:00 -04005435
5436 for _, test := range tests {
5437 if async {
5438 test.name += "-Async"
5439 test.flags = append(test.flags, "-async")
5440 }
5441
5442 testCases = append(testCases, test)
5443 }
David Benjamin83f90402015-01-27 01:09:43 -05005444 }
David Benjamin83f90402015-01-27 01:09:43 -05005445}
5446
David Benjaminc565ebb2015-04-03 04:06:36 -04005447func addExportKeyingMaterialTests() {
5448 for _, vers := range tlsVersions {
5449 if vers.version == VersionSSL30 {
5450 continue
5451 }
5452 testCases = append(testCases, testCase{
5453 name: "ExportKeyingMaterial-" + vers.name,
5454 config: Config{
5455 MaxVersion: vers.version,
5456 },
5457 exportKeyingMaterial: 1024,
5458 exportLabel: "label",
5459 exportContext: "context",
5460 useExportContext: true,
5461 })
5462 testCases = append(testCases, testCase{
5463 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5464 config: Config{
5465 MaxVersion: vers.version,
5466 },
5467 exportKeyingMaterial: 1024,
5468 })
5469 testCases = append(testCases, testCase{
5470 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5471 config: Config{
5472 MaxVersion: vers.version,
5473 },
5474 exportKeyingMaterial: 1024,
5475 useExportContext: true,
5476 })
5477 testCases = append(testCases, testCase{
5478 name: "ExportKeyingMaterial-Small-" + vers.name,
5479 config: Config{
5480 MaxVersion: vers.version,
5481 },
5482 exportKeyingMaterial: 1,
5483 exportLabel: "label",
5484 exportContext: "context",
5485 useExportContext: true,
5486 })
5487 }
5488 testCases = append(testCases, testCase{
5489 name: "ExportKeyingMaterial-SSL3",
5490 config: Config{
5491 MaxVersion: VersionSSL30,
5492 },
5493 exportKeyingMaterial: 1024,
5494 exportLabel: "label",
5495 exportContext: "context",
5496 useExportContext: true,
5497 shouldFail: true,
5498 expectedError: "failed to export keying material",
5499 })
5500}
5501
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005502func addTLSUniqueTests() {
5503 for _, isClient := range []bool{false, true} {
5504 for _, isResumption := range []bool{false, true} {
5505 for _, hasEMS := range []bool{false, true} {
5506 var suffix string
5507 if isResumption {
5508 suffix = "Resume-"
5509 } else {
5510 suffix = "Full-"
5511 }
5512
5513 if hasEMS {
5514 suffix += "EMS-"
5515 } else {
5516 suffix += "NoEMS-"
5517 }
5518
5519 if isClient {
5520 suffix += "Client"
5521 } else {
5522 suffix += "Server"
5523 }
5524
5525 test := testCase{
5526 name: "TLSUnique-" + suffix,
5527 testTLSUnique: true,
5528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005529 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005530 Bugs: ProtocolBugs{
5531 NoExtendedMasterSecret: !hasEMS,
5532 },
5533 },
5534 }
5535
5536 if isResumption {
5537 test.resumeSession = true
5538 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005539 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005540 Bugs: ProtocolBugs{
5541 NoExtendedMasterSecret: !hasEMS,
5542 },
5543 }
5544 }
5545
5546 if isResumption && !hasEMS {
5547 test.shouldFail = true
5548 test.expectedError = "failed to get tls-unique"
5549 }
5550
5551 testCases = append(testCases, test)
5552 }
5553 }
5554 }
5555}
5556
Adam Langley09505632015-07-30 18:10:13 -07005557func addCustomExtensionTests() {
5558 expectedContents := "custom extension"
5559 emptyString := ""
5560
David Benjamin4c3ddf72016-06-29 18:13:53 -04005561 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005562 for _, isClient := range []bool{false, true} {
5563 suffix := "Server"
5564 flag := "-enable-server-custom-extension"
5565 testType := serverTest
5566 if isClient {
5567 suffix = "Client"
5568 flag = "-enable-client-custom-extension"
5569 testType = clientTest
5570 }
5571
5572 testCases = append(testCases, testCase{
5573 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005574 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005575 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005576 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005577 Bugs: ProtocolBugs{
5578 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005579 ExpectedCustomExtension: &expectedContents,
5580 },
5581 },
5582 flags: []string{flag},
5583 })
5584
5585 // If the parse callback fails, the handshake should also fail.
5586 testCases = append(testCases, testCase{
5587 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005588 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005589 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005590 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005591 Bugs: ProtocolBugs{
5592 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005593 ExpectedCustomExtension: &expectedContents,
5594 },
5595 },
David Benjamin399e7c92015-07-30 23:01:27 -04005596 flags: []string{flag},
5597 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005598 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5599 })
5600
5601 // If the add callback fails, the handshake should also fail.
5602 testCases = append(testCases, testCase{
5603 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005604 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005605 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005606 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005607 Bugs: ProtocolBugs{
5608 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005609 ExpectedCustomExtension: &expectedContents,
5610 },
5611 },
David Benjamin399e7c92015-07-30 23:01:27 -04005612 flags: []string{flag, "-custom-extension-fail-add"},
5613 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005614 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5615 })
5616
5617 // If the add callback returns zero, no extension should be
5618 // added.
5619 skipCustomExtension := expectedContents
5620 if isClient {
5621 // For the case where the client skips sending the
5622 // custom extension, the server must not “echo” it.
5623 skipCustomExtension = ""
5624 }
5625 testCases = append(testCases, testCase{
5626 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005627 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005628 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005629 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005630 Bugs: ProtocolBugs{
5631 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005632 ExpectedCustomExtension: &emptyString,
5633 },
5634 },
5635 flags: []string{flag, "-custom-extension-skip"},
5636 })
5637 }
5638
5639 // The custom extension add callback should not be called if the client
5640 // doesn't send the extension.
5641 testCases = append(testCases, testCase{
5642 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005643 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005644 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005645 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005646 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005647 ExpectedCustomExtension: &emptyString,
5648 },
5649 },
5650 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5651 })
Adam Langley2deb9842015-08-07 11:15:37 -07005652
5653 // Test an unknown extension from the server.
5654 testCases = append(testCases, testCase{
5655 testType: clientTest,
5656 name: "UnknownExtension-Client",
5657 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005658 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005659 Bugs: ProtocolBugs{
5660 CustomExtension: expectedContents,
5661 },
5662 },
5663 shouldFail: true,
5664 expectedError: ":UNEXPECTED_EXTENSION:",
5665 })
Adam Langley09505632015-07-30 18:10:13 -07005666}
5667
David Benjaminb36a3952015-12-01 18:53:13 -05005668func addRSAClientKeyExchangeTests() {
5669 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5670 testCases = append(testCases, testCase{
5671 testType: serverTest,
5672 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5673 config: Config{
5674 // Ensure the ClientHello version and final
5675 // version are different, to detect if the
5676 // server uses the wrong one.
5677 MaxVersion: VersionTLS11,
5678 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5679 Bugs: ProtocolBugs{
5680 BadRSAClientKeyExchange: bad,
5681 },
5682 },
5683 shouldFail: true,
5684 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5685 })
5686 }
5687}
5688
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005689var testCurves = []struct {
5690 name string
5691 id CurveID
5692}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005693 {"P-256", CurveP256},
5694 {"P-384", CurveP384},
5695 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005696 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005697}
5698
5699func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005700 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005701 for _, curve := range testCurves {
5702 testCases = append(testCases, testCase{
5703 name: "CurveTest-Client-" + curve.name,
5704 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005705 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005706 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5707 CurvePreferences: []CurveID{curve.id},
5708 },
5709 flags: []string{"-enable-all-curves"},
5710 })
5711 testCases = append(testCases, testCase{
5712 testType: serverTest,
5713 name: "CurveTest-Server-" + curve.name,
5714 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005715 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005716 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5717 CurvePreferences: []CurveID{curve.id},
5718 },
5719 flags: []string{"-enable-all-curves"},
5720 })
5721 }
David Benjamin241ae832016-01-15 03:04:54 -05005722
5723 // The server must be tolerant to bogus curves.
5724 const bogusCurve = 0x1234
5725 testCases = append(testCases, testCase{
5726 testType: serverTest,
5727 name: "UnknownCurve",
5728 config: Config{
5729 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5730 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5731 },
5732 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005733
5734 // The server must not consider ECDHE ciphers when there are no
5735 // supported curves.
5736 testCases = append(testCases, testCase{
5737 testType: serverTest,
5738 name: "NoSupportedCurves",
5739 config: Config{
5740 // TODO(davidben): Add a TLS 1.3 version of this.
5741 MaxVersion: VersionTLS12,
5742 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5743 Bugs: ProtocolBugs{
5744 NoSupportedCurves: true,
5745 },
5746 },
5747 shouldFail: true,
5748 expectedError: ":NO_SHARED_CIPHER:",
5749 })
5750
5751 // The server must fall back to another cipher when there are no
5752 // supported curves.
5753 testCases = append(testCases, testCase{
5754 testType: serverTest,
5755 name: "NoCommonCurves",
5756 config: Config{
5757 MaxVersion: VersionTLS12,
5758 CipherSuites: []uint16{
5759 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5760 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5761 },
5762 CurvePreferences: []CurveID{CurveP224},
5763 },
5764 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5765 })
5766
5767 // The client must reject bogus curves and disabled curves.
5768 testCases = append(testCases, testCase{
5769 name: "BadECDHECurve",
5770 config: Config{
5771 // TODO(davidben): Add a TLS 1.3 version of this.
5772 MaxVersion: VersionTLS12,
5773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5774 Bugs: ProtocolBugs{
5775 SendCurve: bogusCurve,
5776 },
5777 },
5778 shouldFail: true,
5779 expectedError: ":WRONG_CURVE:",
5780 })
5781
5782 testCases = append(testCases, testCase{
5783 name: "UnsupportedCurve",
5784 config: Config{
5785 // TODO(davidben): Add a TLS 1.3 version of this.
5786 MaxVersion: VersionTLS12,
5787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5788 CurvePreferences: []CurveID{CurveP256},
5789 Bugs: ProtocolBugs{
5790 IgnorePeerCurvePreferences: true,
5791 },
5792 },
5793 flags: []string{"-p384-only"},
5794 shouldFail: true,
5795 expectedError: ":WRONG_CURVE:",
5796 })
5797
5798 // Test invalid curve points.
5799 testCases = append(testCases, testCase{
5800 name: "InvalidECDHPoint-Client",
5801 config: Config{
5802 // TODO(davidben): Add a TLS 1.3 version of this test.
5803 MaxVersion: VersionTLS12,
5804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5805 CurvePreferences: []CurveID{CurveP256},
5806 Bugs: ProtocolBugs{
5807 InvalidECDHPoint: true,
5808 },
5809 },
5810 shouldFail: true,
5811 expectedError: ":INVALID_ENCODING:",
5812 })
5813 testCases = append(testCases, testCase{
5814 testType: serverTest,
5815 name: "InvalidECDHPoint-Server",
5816 config: Config{
5817 // TODO(davidben): Add a TLS 1.3 version of this test.
5818 MaxVersion: VersionTLS12,
5819 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5820 CurvePreferences: []CurveID{CurveP256},
5821 Bugs: ProtocolBugs{
5822 InvalidECDHPoint: true,
5823 },
5824 },
5825 shouldFail: true,
5826 expectedError: ":INVALID_ENCODING:",
5827 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005828}
5829
Matt Braithwaite54217e42016-06-13 13:03:47 -07005830func addCECPQ1Tests() {
5831 testCases = append(testCases, testCase{
5832 testType: clientTest,
5833 name: "CECPQ1-Client-BadX25519Part",
5834 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005835 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005836 MinVersion: VersionTLS12,
5837 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5838 Bugs: ProtocolBugs{
5839 CECPQ1BadX25519Part: true,
5840 },
5841 },
5842 flags: []string{"-cipher", "kCECPQ1"},
5843 shouldFail: true,
5844 expectedLocalError: "local error: bad record MAC",
5845 })
5846 testCases = append(testCases, testCase{
5847 testType: clientTest,
5848 name: "CECPQ1-Client-BadNewhopePart",
5849 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005850 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005851 MinVersion: VersionTLS12,
5852 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5853 Bugs: ProtocolBugs{
5854 CECPQ1BadNewhopePart: true,
5855 },
5856 },
5857 flags: []string{"-cipher", "kCECPQ1"},
5858 shouldFail: true,
5859 expectedLocalError: "local error: bad record MAC",
5860 })
5861 testCases = append(testCases, testCase{
5862 testType: serverTest,
5863 name: "CECPQ1-Server-BadX25519Part",
5864 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005865 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005866 MinVersion: VersionTLS12,
5867 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5868 Bugs: ProtocolBugs{
5869 CECPQ1BadX25519Part: true,
5870 },
5871 },
5872 flags: []string{"-cipher", "kCECPQ1"},
5873 shouldFail: true,
5874 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5875 })
5876 testCases = append(testCases, testCase{
5877 testType: serverTest,
5878 name: "CECPQ1-Server-BadNewhopePart",
5879 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005880 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005881 MinVersion: VersionTLS12,
5882 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5883 Bugs: ProtocolBugs{
5884 CECPQ1BadNewhopePart: true,
5885 },
5886 },
5887 flags: []string{"-cipher", "kCECPQ1"},
5888 shouldFail: true,
5889 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5890 })
5891}
5892
David Benjamin4cc36ad2015-12-19 14:23:26 -05005893func addKeyExchangeInfoTests() {
5894 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005895 name: "KeyExchangeInfo-DHE-Client",
5896 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005897 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005898 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5899 Bugs: ProtocolBugs{
5900 // This is a 1234-bit prime number, generated
5901 // with:
5902 // openssl gendh 1234 | openssl asn1parse -i
5903 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5904 },
5905 },
David Benjamin9e68f192016-06-30 14:55:33 -04005906 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005907 })
5908 testCases = append(testCases, testCase{
5909 testType: serverTest,
5910 name: "KeyExchangeInfo-DHE-Server",
5911 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005912 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005913 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5914 },
5915 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005916 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005917 })
5918
Nick Harper1fd39d82016-06-14 18:14:35 -07005919 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5920 // handshake is separate.
5921
David Benjamin4cc36ad2015-12-19 14:23:26 -05005922 testCases = append(testCases, testCase{
5923 name: "KeyExchangeInfo-ECDHE-Client",
5924 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005925 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005926 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5927 CurvePreferences: []CurveID{CurveX25519},
5928 },
David Benjamin9e68f192016-06-30 14:55:33 -04005929 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005930 })
5931 testCases = append(testCases, testCase{
5932 testType: serverTest,
5933 name: "KeyExchangeInfo-ECDHE-Server",
5934 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005935 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005936 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5937 CurvePreferences: []CurveID{CurveX25519},
5938 },
David Benjamin9e68f192016-06-30 14:55:33 -04005939 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005940 })
5941}
5942
David Benjaminc9ae27c2016-06-24 22:56:37 -04005943func addTLS13RecordTests() {
5944 testCases = append(testCases, testCase{
5945 name: "TLS13-RecordPadding",
5946 config: Config{
5947 MaxVersion: VersionTLS13,
5948 MinVersion: VersionTLS13,
5949 Bugs: ProtocolBugs{
5950 RecordPadding: 10,
5951 },
5952 },
5953 })
5954
5955 testCases = append(testCases, testCase{
5956 name: "TLS13-EmptyRecords",
5957 config: Config{
5958 MaxVersion: VersionTLS13,
5959 MinVersion: VersionTLS13,
5960 Bugs: ProtocolBugs{
5961 OmitRecordContents: true,
5962 },
5963 },
5964 shouldFail: true,
5965 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5966 })
5967
5968 testCases = append(testCases, testCase{
5969 name: "TLS13-OnlyPadding",
5970 config: Config{
5971 MaxVersion: VersionTLS13,
5972 MinVersion: VersionTLS13,
5973 Bugs: ProtocolBugs{
5974 OmitRecordContents: true,
5975 RecordPadding: 10,
5976 },
5977 },
5978 shouldFail: true,
5979 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5980 })
5981
5982 testCases = append(testCases, testCase{
5983 name: "TLS13-WrongOuterRecord",
5984 config: Config{
5985 MaxVersion: VersionTLS13,
5986 MinVersion: VersionTLS13,
5987 Bugs: ProtocolBugs{
5988 OuterRecordType: recordTypeHandshake,
5989 },
5990 },
5991 shouldFail: true,
5992 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5993 })
5994}
5995
David Benjamin82261be2016-07-07 14:32:50 -07005996func addChangeCipherSpecTests() {
5997 // Test missing ChangeCipherSpecs.
5998 testCases = append(testCases, testCase{
5999 name: "SkipChangeCipherSpec-Client",
6000 config: Config{
6001 MaxVersion: VersionTLS12,
6002 Bugs: ProtocolBugs{
6003 SkipChangeCipherSpec: true,
6004 },
6005 },
6006 shouldFail: true,
6007 expectedError: ":UNEXPECTED_RECORD:",
6008 })
6009 testCases = append(testCases, testCase{
6010 testType: serverTest,
6011 name: "SkipChangeCipherSpec-Server",
6012 config: Config{
6013 MaxVersion: VersionTLS12,
6014 Bugs: ProtocolBugs{
6015 SkipChangeCipherSpec: true,
6016 },
6017 },
6018 shouldFail: true,
6019 expectedError: ":UNEXPECTED_RECORD:",
6020 })
6021 testCases = append(testCases, testCase{
6022 testType: serverTest,
6023 name: "SkipChangeCipherSpec-Server-NPN",
6024 config: Config{
6025 MaxVersion: VersionTLS12,
6026 NextProtos: []string{"bar"},
6027 Bugs: ProtocolBugs{
6028 SkipChangeCipherSpec: true,
6029 },
6030 },
6031 flags: []string{
6032 "-advertise-npn", "\x03foo\x03bar\x03baz",
6033 },
6034 shouldFail: true,
6035 expectedError: ":UNEXPECTED_RECORD:",
6036 })
6037
6038 // Test synchronization between the handshake and ChangeCipherSpec.
6039 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6040 // rejected. Test both with and without handshake packing to handle both
6041 // when the partial post-CCS message is in its own record and when it is
6042 // attached to the pre-CCS message.
6043 //
6044 // TODO(davidben): Fix and test DTLS as well.
6045 for _, packed := range []bool{false, true} {
6046 var suffix string
6047 if packed {
6048 suffix = "-Packed"
6049 }
6050
6051 testCases = append(testCases, testCase{
6052 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6053 config: Config{
6054 MaxVersion: VersionTLS12,
6055 Bugs: ProtocolBugs{
6056 FragmentAcrossChangeCipherSpec: true,
6057 PackHandshakeFlight: packed,
6058 },
6059 },
6060 shouldFail: true,
6061 expectedError: ":UNEXPECTED_RECORD:",
6062 })
6063 testCases = append(testCases, testCase{
6064 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6065 config: Config{
6066 MaxVersion: VersionTLS12,
6067 },
6068 resumeSession: true,
6069 resumeConfig: &Config{
6070 MaxVersion: VersionTLS12,
6071 Bugs: ProtocolBugs{
6072 FragmentAcrossChangeCipherSpec: true,
6073 PackHandshakeFlight: packed,
6074 },
6075 },
6076 shouldFail: true,
6077 expectedError: ":UNEXPECTED_RECORD:",
6078 })
6079 testCases = append(testCases, testCase{
6080 testType: serverTest,
6081 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6082 config: Config{
6083 MaxVersion: VersionTLS12,
6084 Bugs: ProtocolBugs{
6085 FragmentAcrossChangeCipherSpec: true,
6086 PackHandshakeFlight: packed,
6087 },
6088 },
6089 shouldFail: true,
6090 expectedError: ":UNEXPECTED_RECORD:",
6091 })
6092 testCases = append(testCases, testCase{
6093 testType: serverTest,
6094 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6095 config: Config{
6096 MaxVersion: VersionTLS12,
6097 },
6098 resumeSession: true,
6099 resumeConfig: &Config{
6100 MaxVersion: VersionTLS12,
6101 Bugs: ProtocolBugs{
6102 FragmentAcrossChangeCipherSpec: true,
6103 PackHandshakeFlight: packed,
6104 },
6105 },
6106 shouldFail: true,
6107 expectedError: ":UNEXPECTED_RECORD:",
6108 })
6109 testCases = append(testCases, testCase{
6110 testType: serverTest,
6111 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6112 config: Config{
6113 MaxVersion: VersionTLS12,
6114 NextProtos: []string{"bar"},
6115 Bugs: ProtocolBugs{
6116 FragmentAcrossChangeCipherSpec: true,
6117 PackHandshakeFlight: packed,
6118 },
6119 },
6120 flags: []string{
6121 "-advertise-npn", "\x03foo\x03bar\x03baz",
6122 },
6123 shouldFail: true,
6124 expectedError: ":UNEXPECTED_RECORD:",
6125 })
6126 }
6127
6128 // Test that early ChangeCipherSpecs are handled correctly.
6129 testCases = append(testCases, testCase{
6130 testType: serverTest,
6131 name: "EarlyChangeCipherSpec-server-1",
6132 config: Config{
6133 MaxVersion: VersionTLS12,
6134 Bugs: ProtocolBugs{
6135 EarlyChangeCipherSpec: 1,
6136 },
6137 },
6138 shouldFail: true,
6139 expectedError: ":UNEXPECTED_RECORD:",
6140 })
6141 testCases = append(testCases, testCase{
6142 testType: serverTest,
6143 name: "EarlyChangeCipherSpec-server-2",
6144 config: Config{
6145 MaxVersion: VersionTLS12,
6146 Bugs: ProtocolBugs{
6147 EarlyChangeCipherSpec: 2,
6148 },
6149 },
6150 shouldFail: true,
6151 expectedError: ":UNEXPECTED_RECORD:",
6152 })
6153 testCases = append(testCases, testCase{
6154 protocol: dtls,
6155 name: "StrayChangeCipherSpec",
6156 config: Config{
6157 // TODO(davidben): Once DTLS 1.3 exists, test
6158 // that stray ChangeCipherSpec messages are
6159 // rejected.
6160 MaxVersion: VersionTLS12,
6161 Bugs: ProtocolBugs{
6162 StrayChangeCipherSpec: true,
6163 },
6164 },
6165 })
6166
6167 // Test that the contents of ChangeCipherSpec are checked.
6168 testCases = append(testCases, testCase{
6169 name: "BadChangeCipherSpec-1",
6170 config: Config{
6171 MaxVersion: VersionTLS12,
6172 Bugs: ProtocolBugs{
6173 BadChangeCipherSpec: []byte{2},
6174 },
6175 },
6176 shouldFail: true,
6177 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6178 })
6179 testCases = append(testCases, testCase{
6180 name: "BadChangeCipherSpec-2",
6181 config: Config{
6182 MaxVersion: VersionTLS12,
6183 Bugs: ProtocolBugs{
6184 BadChangeCipherSpec: []byte{1, 1},
6185 },
6186 },
6187 shouldFail: true,
6188 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6189 })
6190 testCases = append(testCases, testCase{
6191 protocol: dtls,
6192 name: "BadChangeCipherSpec-DTLS-1",
6193 config: Config{
6194 MaxVersion: VersionTLS12,
6195 Bugs: ProtocolBugs{
6196 BadChangeCipherSpec: []byte{2},
6197 },
6198 },
6199 shouldFail: true,
6200 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6201 })
6202 testCases = append(testCases, testCase{
6203 protocol: dtls,
6204 name: "BadChangeCipherSpec-DTLS-2",
6205 config: Config{
6206 MaxVersion: VersionTLS12,
6207 Bugs: ProtocolBugs{
6208 BadChangeCipherSpec: []byte{1, 1},
6209 },
6210 },
6211 shouldFail: true,
6212 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6213 })
6214}
6215
Adam Langley7c803a62015-06-15 15:35:05 -07006216func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006217 defer wg.Done()
6218
6219 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006220 var err error
6221
6222 if *mallocTest < 0 {
6223 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006224 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006225 } else {
6226 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6227 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006228 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006229 if err != nil {
6230 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6231 }
6232 break
6233 }
6234 }
6235 }
Adam Langley95c29f32014-06-20 12:00:00 -07006236 statusChan <- statusMsg{test: test, err: err}
6237 }
6238}
6239
6240type statusMsg struct {
6241 test *testCase
6242 started bool
6243 err error
6244}
6245
David Benjamin5f237bc2015-02-11 17:14:15 -05006246func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006247 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006248
David Benjamin5f237bc2015-02-11 17:14:15 -05006249 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006250 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006251 if !*pipe {
6252 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006253 var erase string
6254 for i := 0; i < lineLen; i++ {
6255 erase += "\b \b"
6256 }
6257 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006258 }
6259
Adam Langley95c29f32014-06-20 12:00:00 -07006260 if msg.started {
6261 started++
6262 } else {
6263 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006264
6265 if msg.err != nil {
6266 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6267 failed++
6268 testOutput.addResult(msg.test.name, "FAIL")
6269 } else {
6270 if *pipe {
6271 // Print each test instead of a status line.
6272 fmt.Printf("PASSED (%s)\n", msg.test.name)
6273 }
6274 testOutput.addResult(msg.test.name, "PASS")
6275 }
Adam Langley95c29f32014-06-20 12:00:00 -07006276 }
6277
David Benjamin5f237bc2015-02-11 17:14:15 -05006278 if !*pipe {
6279 // Print a new status line.
6280 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6281 lineLen = len(line)
6282 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006283 }
Adam Langley95c29f32014-06-20 12:00:00 -07006284 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006285
6286 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006287}
6288
6289func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006290 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006291 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006292 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006293
Adam Langley7c803a62015-06-15 15:35:05 -07006294 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006295 addCipherSuiteTests()
6296 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006297 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006298 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006299 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006300 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006301 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006302 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006303 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006304 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006305 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006306 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006307 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006308 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006309 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006310 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006311 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006312 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006313 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006314 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006315 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006316 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006317 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006318 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006319 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006320
6321 var wg sync.WaitGroup
6322
Adam Langley7c803a62015-06-15 15:35:05 -07006323 statusChan := make(chan statusMsg, *numWorkers)
6324 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006325 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006326
David Benjamin025b3d32014-07-01 19:53:04 -04006327 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006328
Adam Langley7c803a62015-06-15 15:35:05 -07006329 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006330 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006331 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006332 }
6333
David Benjamin270f0a72016-03-17 14:41:36 -04006334 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006335 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006336 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006337 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006338 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006339 }
6340 }
David Benjamin270f0a72016-03-17 14:41:36 -04006341 if !foundTest {
6342 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6343 os.Exit(1)
6344 }
Adam Langley95c29f32014-06-20 12:00:00 -07006345
6346 close(testChan)
6347 wg.Wait()
6348 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006349 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006350
6351 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006352
6353 if *jsonOutput != "" {
6354 if err := testOutput.writeTo(*jsonOutput); err != nil {
6355 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6356 }
6357 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006358
6359 if !testOutput.allPassed {
6360 os.Exit(1)
6361 }
Adam Langley95c29f32014-06-20 12:00:00 -07006362}