blob: 5bbf57d3ed49d60f77bf7fa24983de621722fb7e [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 {
Adam Langley7c803a62015-06-15 15:35:05 -07001054 name: "NoFallbackSCSV",
1055 config: Config{
1056 Bugs: ProtocolBugs{
1057 FailIfNotFallbackSCSV: true,
1058 },
1059 },
1060 shouldFail: true,
1061 expectedLocalError: "no fallback SCSV found",
1062 },
1063 {
1064 name: "SendFallbackSCSV",
1065 config: Config{
1066 Bugs: ProtocolBugs{
1067 FailIfNotFallbackSCSV: true,
1068 },
1069 },
1070 flags: []string{"-fallback-scsv"},
1071 },
1072 {
1073 name: "ClientCertificateTypes",
1074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001075 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001076 ClientAuth: RequestClientCert,
1077 ClientCertificateTypes: []byte{
1078 CertTypeDSSSign,
1079 CertTypeRSASign,
1080 CertTypeECDSASign,
1081 },
1082 },
1083 flags: []string{
1084 "-expect-certificate-types",
1085 base64.StdEncoding.EncodeToString([]byte{
1086 CertTypeDSSSign,
1087 CertTypeRSASign,
1088 CertTypeECDSASign,
1089 }),
1090 },
1091 },
1092 {
Adam Langley7c803a62015-06-15 15:35:05 -07001093 name: "UnauthenticatedECDH",
1094 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001095 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001096 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1097 Bugs: ProtocolBugs{
1098 UnauthenticatedECDH: true,
1099 },
1100 },
1101 shouldFail: true,
1102 expectedError: ":UNEXPECTED_MESSAGE:",
1103 },
1104 {
1105 name: "SkipCertificateStatus",
1106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001107 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001108 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1109 Bugs: ProtocolBugs{
1110 SkipCertificateStatus: true,
1111 },
1112 },
1113 flags: []string{
1114 "-enable-ocsp-stapling",
1115 },
1116 },
1117 {
1118 name: "SkipServerKeyExchange",
1119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001120 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001121 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1122 Bugs: ProtocolBugs{
1123 SkipServerKeyExchange: true,
1124 },
1125 },
1126 shouldFail: true,
1127 expectedError: ":UNEXPECTED_MESSAGE:",
1128 },
1129 {
Adam Langley7c803a62015-06-15 15:35:05 -07001130 testType: serverTest,
1131 name: "Alert",
1132 config: Config{
1133 Bugs: ProtocolBugs{
1134 SendSpuriousAlert: alertRecordOverflow,
1135 },
1136 },
1137 shouldFail: true,
1138 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1139 },
1140 {
1141 protocol: dtls,
1142 testType: serverTest,
1143 name: "Alert-DTLS",
1144 config: Config{
1145 Bugs: ProtocolBugs{
1146 SendSpuriousAlert: alertRecordOverflow,
1147 },
1148 },
1149 shouldFail: true,
1150 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1151 },
1152 {
1153 testType: serverTest,
1154 name: "FragmentAlert",
1155 config: Config{
1156 Bugs: ProtocolBugs{
1157 FragmentAlert: true,
1158 SendSpuriousAlert: alertRecordOverflow,
1159 },
1160 },
1161 shouldFail: true,
1162 expectedError: ":BAD_ALERT:",
1163 },
1164 {
1165 protocol: dtls,
1166 testType: serverTest,
1167 name: "FragmentAlert-DTLS",
1168 config: Config{
1169 Bugs: ProtocolBugs{
1170 FragmentAlert: true,
1171 SendSpuriousAlert: alertRecordOverflow,
1172 },
1173 },
1174 shouldFail: true,
1175 expectedError: ":BAD_ALERT:",
1176 },
1177 {
1178 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001179 name: "DoubleAlert",
1180 config: Config{
1181 Bugs: ProtocolBugs{
1182 DoubleAlert: true,
1183 SendSpuriousAlert: alertRecordOverflow,
1184 },
1185 },
1186 shouldFail: true,
1187 expectedError: ":BAD_ALERT:",
1188 },
1189 {
1190 protocol: dtls,
1191 testType: serverTest,
1192 name: "DoubleAlert-DTLS",
1193 config: Config{
1194 Bugs: ProtocolBugs{
1195 DoubleAlert: true,
1196 SendSpuriousAlert: alertRecordOverflow,
1197 },
1198 },
1199 shouldFail: true,
1200 expectedError: ":BAD_ALERT:",
1201 },
1202 {
Adam Langley7c803a62015-06-15 15:35:05 -07001203 name: "SkipNewSessionTicket",
1204 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001205 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001206 Bugs: ProtocolBugs{
1207 SkipNewSessionTicket: true,
1208 },
1209 },
1210 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001211 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001212 },
1213 {
1214 testType: serverTest,
1215 name: "FallbackSCSV",
1216 config: Config{
1217 MaxVersion: VersionTLS11,
1218 Bugs: ProtocolBugs{
1219 SendFallbackSCSV: true,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":INAPPROPRIATE_FALLBACK:",
1224 },
1225 {
1226 testType: serverTest,
1227 name: "FallbackSCSV-VersionMatch",
1228 config: Config{
1229 Bugs: ProtocolBugs{
1230 SendFallbackSCSV: true,
1231 },
1232 },
1233 },
1234 {
1235 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001236 name: "FallbackSCSV-VersionMatch-TLS12",
1237 config: Config{
1238 MaxVersion: VersionTLS12,
1239 Bugs: ProtocolBugs{
1240 SendFallbackSCSV: true,
1241 },
1242 },
1243 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1244 },
1245 {
1246 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001247 name: "FragmentedClientVersion",
1248 config: Config{
1249 Bugs: ProtocolBugs{
1250 MaxHandshakeRecordLength: 1,
1251 FragmentClientVersion: true,
1252 },
1253 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001254 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001255 },
1256 {
Adam Langley7c803a62015-06-15 15:35:05 -07001257 testType: serverTest,
1258 name: "HttpGET",
1259 sendPrefix: "GET / HTTP/1.0\n",
1260 shouldFail: true,
1261 expectedError: ":HTTP_REQUEST:",
1262 },
1263 {
1264 testType: serverTest,
1265 name: "HttpPOST",
1266 sendPrefix: "POST / HTTP/1.0\n",
1267 shouldFail: true,
1268 expectedError: ":HTTP_REQUEST:",
1269 },
1270 {
1271 testType: serverTest,
1272 name: "HttpHEAD",
1273 sendPrefix: "HEAD / HTTP/1.0\n",
1274 shouldFail: true,
1275 expectedError: ":HTTP_REQUEST:",
1276 },
1277 {
1278 testType: serverTest,
1279 name: "HttpPUT",
1280 sendPrefix: "PUT / HTTP/1.0\n",
1281 shouldFail: true,
1282 expectedError: ":HTTP_REQUEST:",
1283 },
1284 {
1285 testType: serverTest,
1286 name: "HttpCONNECT",
1287 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1288 shouldFail: true,
1289 expectedError: ":HTTPS_PROXY_REQUEST:",
1290 },
1291 {
1292 testType: serverTest,
1293 name: "Garbage",
1294 sendPrefix: "blah",
1295 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001296 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001297 },
1298 {
Adam Langley7c803a62015-06-15 15:35:05 -07001299 name: "RSAEphemeralKey",
1300 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001301 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001302 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1303 Bugs: ProtocolBugs{
1304 RSAEphemeralKey: true,
1305 },
1306 },
1307 shouldFail: true,
1308 expectedError: ":UNEXPECTED_MESSAGE:",
1309 },
1310 {
1311 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001312 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001313 shouldFail: true,
1314 expectedError: ":WRONG_SSL_VERSION:",
1315 },
1316 {
1317 protocol: dtls,
1318 name: "DisableEverything-DTLS",
1319 flags: []string{"-no-tls12", "-no-tls1"},
1320 shouldFail: true,
1321 expectedError: ":WRONG_SSL_VERSION:",
1322 },
1323 {
Adam Langley7c803a62015-06-15 15:35:05 -07001324 protocol: dtls,
1325 testType: serverTest,
1326 name: "MTU",
1327 config: Config{
1328 Bugs: ProtocolBugs{
1329 MaxPacketLength: 256,
1330 },
1331 },
1332 flags: []string{"-mtu", "256"},
1333 },
1334 {
1335 protocol: dtls,
1336 testType: serverTest,
1337 name: "MTUExceeded",
1338 config: Config{
1339 Bugs: ProtocolBugs{
1340 MaxPacketLength: 255,
1341 },
1342 },
1343 flags: []string{"-mtu", "256"},
1344 shouldFail: true,
1345 expectedLocalError: "dtls: exceeded maximum packet length",
1346 },
1347 {
1348 name: "CertMismatchRSA",
1349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001350 // TODO(davidben): Add a TLS 1.3 version of this test.
1351 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001352 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001353 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001354 Bugs: ProtocolBugs{
1355 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1356 },
1357 },
1358 shouldFail: true,
1359 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1360 },
1361 {
1362 name: "CertMismatchECDSA",
1363 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001364 // TODO(davidben): Add a TLS 1.3 version of this test.
1365 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001366 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001367 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001368 Bugs: ProtocolBugs{
1369 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1370 },
1371 },
1372 shouldFail: true,
1373 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1374 },
1375 {
1376 name: "EmptyCertificateList",
1377 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001378 // TODO(davidben): Add a TLS 1.3 version of this test.
1379 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001380 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1381 Bugs: ProtocolBugs{
1382 EmptyCertificateList: true,
1383 },
1384 },
1385 shouldFail: true,
1386 expectedError: ":DECODE_ERROR:",
1387 },
1388 {
1389 name: "TLSFatalBadPackets",
1390 damageFirstWrite: true,
1391 shouldFail: true,
1392 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1393 },
1394 {
1395 protocol: dtls,
1396 name: "DTLSIgnoreBadPackets",
1397 damageFirstWrite: true,
1398 },
1399 {
1400 protocol: dtls,
1401 name: "DTLSIgnoreBadPackets-Async",
1402 damageFirstWrite: true,
1403 flags: []string{"-async"},
1404 },
1405 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001406 name: "AppDataBeforeHandshake",
1407 config: Config{
1408 Bugs: ProtocolBugs{
1409 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1410 },
1411 },
1412 shouldFail: true,
1413 expectedError: ":UNEXPECTED_RECORD:",
1414 },
1415 {
1416 name: "AppDataBeforeHandshake-Empty",
1417 config: Config{
1418 Bugs: ProtocolBugs{
1419 AppDataBeforeHandshake: []byte{},
1420 },
1421 },
1422 shouldFail: true,
1423 expectedError: ":UNEXPECTED_RECORD:",
1424 },
1425 {
1426 protocol: dtls,
1427 name: "AppDataBeforeHandshake-DTLS",
1428 config: Config{
1429 Bugs: ProtocolBugs{
1430 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1431 },
1432 },
1433 shouldFail: true,
1434 expectedError: ":UNEXPECTED_RECORD:",
1435 },
1436 {
1437 protocol: dtls,
1438 name: "AppDataBeforeHandshake-DTLS-Empty",
1439 config: Config{
1440 Bugs: ProtocolBugs{
1441 AppDataBeforeHandshake: []byte{},
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":UNEXPECTED_RECORD:",
1446 },
1447 {
Adam Langley7c803a62015-06-15 15:35:05 -07001448 name: "AppDataAfterChangeCipherSpec",
1449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001450 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001451 Bugs: ProtocolBugs{
1452 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1453 },
1454 },
1455 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001456 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001457 },
1458 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001459 name: "AppDataAfterChangeCipherSpec-Empty",
1460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001461 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001462 Bugs: ProtocolBugs{
1463 AppDataAfterChangeCipherSpec: []byte{},
1464 },
1465 },
1466 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001467 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001468 },
1469 {
Adam Langley7c803a62015-06-15 15:35:05 -07001470 protocol: dtls,
1471 name: "AppDataAfterChangeCipherSpec-DTLS",
1472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001473 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001474 Bugs: ProtocolBugs{
1475 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1476 },
1477 },
1478 // BoringSSL's DTLS implementation will drop the out-of-order
1479 // application data.
1480 },
1481 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001482 protocol: dtls,
1483 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1484 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001485 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001486 Bugs: ProtocolBugs{
1487 AppDataAfterChangeCipherSpec: []byte{},
1488 },
1489 },
1490 // BoringSSL's DTLS implementation will drop the out-of-order
1491 // application data.
1492 },
1493 {
Adam Langley7c803a62015-06-15 15:35:05 -07001494 name: "AlertAfterChangeCipherSpec",
1495 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001496 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001497 Bugs: ProtocolBugs{
1498 AlertAfterChangeCipherSpec: alertRecordOverflow,
1499 },
1500 },
1501 shouldFail: true,
1502 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1503 },
1504 {
1505 protocol: dtls,
1506 name: "AlertAfterChangeCipherSpec-DTLS",
1507 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001508 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001509 Bugs: ProtocolBugs{
1510 AlertAfterChangeCipherSpec: alertRecordOverflow,
1511 },
1512 },
1513 shouldFail: true,
1514 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1515 },
1516 {
1517 protocol: dtls,
1518 name: "ReorderHandshakeFragments-Small-DTLS",
1519 config: Config{
1520 Bugs: ProtocolBugs{
1521 ReorderHandshakeFragments: true,
1522 // Small enough that every handshake message is
1523 // fragmented.
1524 MaxHandshakeRecordLength: 2,
1525 },
1526 },
1527 },
1528 {
1529 protocol: dtls,
1530 name: "ReorderHandshakeFragments-Large-DTLS",
1531 config: Config{
1532 Bugs: ProtocolBugs{
1533 ReorderHandshakeFragments: true,
1534 // Large enough that no handshake message is
1535 // fragmented.
1536 MaxHandshakeRecordLength: 2048,
1537 },
1538 },
1539 },
1540 {
1541 protocol: dtls,
1542 name: "MixCompleteMessageWithFragments-DTLS",
1543 config: Config{
1544 Bugs: ProtocolBugs{
1545 ReorderHandshakeFragments: true,
1546 MixCompleteMessageWithFragments: true,
1547 MaxHandshakeRecordLength: 2,
1548 },
1549 },
1550 },
1551 {
1552 name: "SendInvalidRecordType",
1553 config: Config{
1554 Bugs: ProtocolBugs{
1555 SendInvalidRecordType: true,
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":UNEXPECTED_RECORD:",
1560 },
1561 {
1562 protocol: dtls,
1563 name: "SendInvalidRecordType-DTLS",
1564 config: Config{
1565 Bugs: ProtocolBugs{
1566 SendInvalidRecordType: true,
1567 },
1568 },
1569 shouldFail: true,
1570 expectedError: ":UNEXPECTED_RECORD:",
1571 },
1572 {
1573 name: "FalseStart-SkipServerSecondLeg",
1574 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001575 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001576 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1577 NextProtos: []string{"foo"},
1578 Bugs: ProtocolBugs{
1579 SkipNewSessionTicket: true,
1580 SkipChangeCipherSpec: true,
1581 SkipFinished: true,
1582 ExpectFalseStart: true,
1583 },
1584 },
1585 flags: []string{
1586 "-false-start",
1587 "-handshake-never-done",
1588 "-advertise-alpn", "\x03foo",
1589 },
1590 shimWritesFirst: true,
1591 shouldFail: true,
1592 expectedError: ":UNEXPECTED_RECORD:",
1593 },
1594 {
1595 name: "FalseStart-SkipServerSecondLeg-Implicit",
1596 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001597 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001598 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1599 NextProtos: []string{"foo"},
1600 Bugs: ProtocolBugs{
1601 SkipNewSessionTicket: true,
1602 SkipChangeCipherSpec: true,
1603 SkipFinished: true,
1604 },
1605 },
1606 flags: []string{
1607 "-implicit-handshake",
1608 "-false-start",
1609 "-handshake-never-done",
1610 "-advertise-alpn", "\x03foo",
1611 },
1612 shouldFail: true,
1613 expectedError: ":UNEXPECTED_RECORD:",
1614 },
1615 {
1616 testType: serverTest,
1617 name: "FailEarlyCallback",
1618 flags: []string{"-fail-early-callback"},
1619 shouldFail: true,
1620 expectedError: ":CONNECTION_REJECTED:",
1621 expectedLocalError: "remote error: access denied",
1622 },
1623 {
1624 name: "WrongMessageType",
1625 config: Config{
David Benjamin1edae6b2016-07-13 16:58:23 -04001626 MaxVersion: VersionTLS12,
1627 Bugs: ProtocolBugs{
1628 WrongCertificateMessageType: true,
1629 },
1630 },
1631 shouldFail: true,
1632 expectedError: ":UNEXPECTED_MESSAGE:",
1633 expectedLocalError: "remote error: unexpected message",
1634 },
1635 {
1636 name: "WrongMessageType-TLS13",
1637 config: Config{
Adam Langley7c803a62015-06-15 15:35:05 -07001638 Bugs: ProtocolBugs{
1639 WrongCertificateMessageType: true,
1640 },
1641 },
1642 shouldFail: true,
1643 expectedError: ":UNEXPECTED_MESSAGE:",
1644 expectedLocalError: "remote error: unexpected message",
1645 },
1646 {
1647 protocol: dtls,
1648 name: "WrongMessageType-DTLS",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 WrongCertificateMessageType: true,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":UNEXPECTED_MESSAGE:",
1656 expectedLocalError: "remote error: unexpected message",
1657 },
1658 {
1659 protocol: dtls,
1660 name: "FragmentMessageTypeMismatch-DTLS",
1661 config: Config{
1662 Bugs: ProtocolBugs{
1663 MaxHandshakeRecordLength: 2,
1664 FragmentMessageTypeMismatch: true,
1665 },
1666 },
1667 shouldFail: true,
1668 expectedError: ":FRAGMENT_MISMATCH:",
1669 },
1670 {
1671 protocol: dtls,
1672 name: "FragmentMessageLengthMismatch-DTLS",
1673 config: Config{
1674 Bugs: ProtocolBugs{
1675 MaxHandshakeRecordLength: 2,
1676 FragmentMessageLengthMismatch: true,
1677 },
1678 },
1679 shouldFail: true,
1680 expectedError: ":FRAGMENT_MISMATCH:",
1681 },
1682 {
1683 protocol: dtls,
1684 name: "SplitFragments-Header-DTLS",
1685 config: Config{
1686 Bugs: ProtocolBugs{
1687 SplitFragments: 2,
1688 },
1689 },
1690 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001691 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001692 },
1693 {
1694 protocol: dtls,
1695 name: "SplitFragments-Boundary-DTLS",
1696 config: Config{
1697 Bugs: ProtocolBugs{
1698 SplitFragments: dtlsRecordHeaderLen,
1699 },
1700 },
1701 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001702 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001703 },
1704 {
1705 protocol: dtls,
1706 name: "SplitFragments-Body-DTLS",
1707 config: Config{
1708 Bugs: ProtocolBugs{
1709 SplitFragments: dtlsRecordHeaderLen + 1,
1710 },
1711 },
1712 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001713 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001714 },
1715 {
1716 protocol: dtls,
1717 name: "SendEmptyFragments-DTLS",
1718 config: Config{
1719 Bugs: ProtocolBugs{
1720 SendEmptyFragments: true,
1721 },
1722 },
1723 },
1724 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001725 name: "BadFinished-Client",
1726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001727 // TODO(davidben): Add a TLS 1.3 version of this.
1728 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001729 Bugs: ProtocolBugs{
1730 BadFinished: true,
1731 },
1732 },
1733 shouldFail: true,
1734 expectedError: ":DIGEST_CHECK_FAILED:",
1735 },
1736 {
1737 testType: serverTest,
1738 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001740 // TODO(davidben): Add a TLS 1.3 version of this.
1741 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001742 Bugs: ProtocolBugs{
1743 BadFinished: true,
1744 },
1745 },
1746 shouldFail: true,
1747 expectedError: ":DIGEST_CHECK_FAILED:",
1748 },
1749 {
1750 name: "FalseStart-BadFinished",
1751 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001752 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001753 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1754 NextProtos: []string{"foo"},
1755 Bugs: ProtocolBugs{
1756 BadFinished: true,
1757 ExpectFalseStart: true,
1758 },
1759 },
1760 flags: []string{
1761 "-false-start",
1762 "-handshake-never-done",
1763 "-advertise-alpn", "\x03foo",
1764 },
1765 shimWritesFirst: true,
1766 shouldFail: true,
1767 expectedError: ":DIGEST_CHECK_FAILED:",
1768 },
1769 {
1770 name: "NoFalseStart-NoALPN",
1771 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001772 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1774 Bugs: ProtocolBugs{
1775 ExpectFalseStart: true,
1776 AlertBeforeFalseStartTest: alertAccessDenied,
1777 },
1778 },
1779 flags: []string{
1780 "-false-start",
1781 },
1782 shimWritesFirst: true,
1783 shouldFail: true,
1784 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1785 expectedLocalError: "tls: peer did not false start: EOF",
1786 },
1787 {
1788 name: "NoFalseStart-NoAEAD",
1789 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001790 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001791 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1792 NextProtos: []string{"foo"},
1793 Bugs: ProtocolBugs{
1794 ExpectFalseStart: true,
1795 AlertBeforeFalseStartTest: alertAccessDenied,
1796 },
1797 },
1798 flags: []string{
1799 "-false-start",
1800 "-advertise-alpn", "\x03foo",
1801 },
1802 shimWritesFirst: true,
1803 shouldFail: true,
1804 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1805 expectedLocalError: "tls: peer did not false start: EOF",
1806 },
1807 {
1808 name: "NoFalseStart-RSA",
1809 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001810 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001811 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1812 NextProtos: []string{"foo"},
1813 Bugs: ProtocolBugs{
1814 ExpectFalseStart: true,
1815 AlertBeforeFalseStartTest: alertAccessDenied,
1816 },
1817 },
1818 flags: []string{
1819 "-false-start",
1820 "-advertise-alpn", "\x03foo",
1821 },
1822 shimWritesFirst: true,
1823 shouldFail: true,
1824 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1825 expectedLocalError: "tls: peer did not false start: EOF",
1826 },
1827 {
1828 name: "NoFalseStart-DHE_RSA",
1829 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001830 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001831 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1832 NextProtos: []string{"foo"},
1833 Bugs: ProtocolBugs{
1834 ExpectFalseStart: true,
1835 AlertBeforeFalseStartTest: alertAccessDenied,
1836 },
1837 },
1838 flags: []string{
1839 "-false-start",
1840 "-advertise-alpn", "\x03foo",
1841 },
1842 shimWritesFirst: true,
1843 shouldFail: true,
1844 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1845 expectedLocalError: "tls: peer did not false start: EOF",
1846 },
1847 {
Adam Langley7c803a62015-06-15 15:35:05 -07001848 protocol: dtls,
1849 name: "SendSplitAlert-Sync",
1850 config: Config{
1851 Bugs: ProtocolBugs{
1852 SendSplitAlert: true,
1853 },
1854 },
1855 },
1856 {
1857 protocol: dtls,
1858 name: "SendSplitAlert-Async",
1859 config: Config{
1860 Bugs: ProtocolBugs{
1861 SendSplitAlert: true,
1862 },
1863 },
1864 flags: []string{"-async"},
1865 },
1866 {
1867 protocol: dtls,
1868 name: "PackDTLSHandshake",
1869 config: Config{
1870 Bugs: ProtocolBugs{
1871 MaxHandshakeRecordLength: 2,
1872 PackHandshakeFragments: 20,
1873 PackHandshakeRecords: 200,
1874 },
1875 },
1876 },
1877 {
Adam Langley7c803a62015-06-15 15:35:05 -07001878 name: "SendEmptyRecords-Pass",
1879 sendEmptyRecords: 32,
1880 },
1881 {
1882 name: "SendEmptyRecords",
1883 sendEmptyRecords: 33,
1884 shouldFail: true,
1885 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1886 },
1887 {
1888 name: "SendEmptyRecords-Async",
1889 sendEmptyRecords: 33,
1890 flags: []string{"-async"},
1891 shouldFail: true,
1892 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1893 },
1894 {
1895 name: "SendWarningAlerts-Pass",
1896 sendWarningAlerts: 4,
1897 },
1898 {
1899 protocol: dtls,
1900 name: "SendWarningAlerts-DTLS-Pass",
1901 sendWarningAlerts: 4,
1902 },
1903 {
1904 name: "SendWarningAlerts",
1905 sendWarningAlerts: 5,
1906 shouldFail: true,
1907 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1908 },
1909 {
1910 name: "SendWarningAlerts-Async",
1911 sendWarningAlerts: 5,
1912 flags: []string{"-async"},
1913 shouldFail: true,
1914 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1915 },
David Benjaminba4594a2015-06-18 18:36:15 -04001916 {
1917 name: "EmptySessionID",
1918 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001919 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001920 SessionTicketsDisabled: true,
1921 },
1922 noSessionCache: true,
1923 flags: []string{"-expect-no-session"},
1924 },
David Benjamin30789da2015-08-29 22:56:45 -04001925 {
1926 name: "Unclean-Shutdown",
1927 config: Config{
1928 Bugs: ProtocolBugs{
1929 NoCloseNotify: true,
1930 ExpectCloseNotify: true,
1931 },
1932 },
1933 shimShutsDown: true,
1934 flags: []string{"-check-close-notify"},
1935 shouldFail: true,
1936 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1937 },
1938 {
1939 name: "Unclean-Shutdown-Ignored",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 NoCloseNotify: true,
1943 },
1944 },
1945 shimShutsDown: true,
1946 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001947 {
David Benjaminfa214e42016-05-10 17:03:10 -04001948 name: "Unclean-Shutdown-Alert",
1949 config: Config{
1950 Bugs: ProtocolBugs{
1951 SendAlertOnShutdown: alertDecompressionFailure,
1952 ExpectCloseNotify: true,
1953 },
1954 },
1955 shimShutsDown: true,
1956 flags: []string{"-check-close-notify"},
1957 shouldFail: true,
1958 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1959 },
1960 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001961 name: "LargePlaintext",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 SendLargeRecords: true,
1965 },
1966 },
1967 messageLen: maxPlaintext + 1,
1968 shouldFail: true,
1969 expectedError: ":DATA_LENGTH_TOO_LONG:",
1970 },
1971 {
1972 protocol: dtls,
1973 name: "LargePlaintext-DTLS",
1974 config: Config{
1975 Bugs: ProtocolBugs{
1976 SendLargeRecords: true,
1977 },
1978 },
1979 messageLen: maxPlaintext + 1,
1980 shouldFail: true,
1981 expectedError: ":DATA_LENGTH_TOO_LONG:",
1982 },
1983 {
1984 name: "LargeCiphertext",
1985 config: Config{
1986 Bugs: ProtocolBugs{
1987 SendLargeRecords: true,
1988 },
1989 },
1990 messageLen: maxPlaintext * 2,
1991 shouldFail: true,
1992 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1993 },
1994 {
1995 protocol: dtls,
1996 name: "LargeCiphertext-DTLS",
1997 config: Config{
1998 Bugs: ProtocolBugs{
1999 SendLargeRecords: true,
2000 },
2001 },
2002 messageLen: maxPlaintext * 2,
2003 // Unlike the other four cases, DTLS drops records which
2004 // are invalid before authentication, so the connection
2005 // does not fail.
2006 expectMessageDropped: true,
2007 },
David Benjamindd6fed92015-10-23 17:41:12 -04002008 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002009 // In TLS 1.2 and below, empty NewSessionTicket messages
2010 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002011 name: "SendEmptySessionTicket",
2012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002013 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002014 Bugs: ProtocolBugs{
2015 SendEmptySessionTicket: true,
2016 FailIfSessionOffered: true,
2017 },
2018 },
2019 flags: []string{"-expect-no-session"},
2020 resumeSession: true,
2021 expectResumeRejected: true,
2022 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002023 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002024 name: "BadHelloRequest-1",
2025 renegotiate: 1,
2026 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002027 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002028 Bugs: ProtocolBugs{
2029 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2030 },
2031 },
2032 flags: []string{
2033 "-renegotiate-freely",
2034 "-expect-total-renegotiations", "1",
2035 },
2036 shouldFail: true,
2037 expectedError: ":BAD_HELLO_REQUEST:",
2038 },
2039 {
2040 name: "BadHelloRequest-2",
2041 renegotiate: 1,
2042 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002043 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002044 Bugs: ProtocolBugs{
2045 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2046 },
2047 },
2048 flags: []string{
2049 "-renegotiate-freely",
2050 "-expect-total-renegotiations", "1",
2051 },
2052 shouldFail: true,
2053 expectedError: ":BAD_HELLO_REQUEST:",
2054 },
David Benjaminef1b0092015-11-21 14:05:44 -05002055 {
2056 testType: serverTest,
2057 name: "SupportTicketsWithSessionID",
2058 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002059 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002060 SessionTicketsDisabled: true,
2061 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002062 resumeConfig: &Config{
2063 MaxVersion: VersionTLS12,
2064 },
David Benjaminef1b0092015-11-21 14:05:44 -05002065 resumeSession: true,
2066 },
Adam Langley7c803a62015-06-15 15:35:05 -07002067 }
Adam Langley7c803a62015-06-15 15:35:05 -07002068 testCases = append(testCases, basicTests...)
2069}
2070
Adam Langley95c29f32014-06-20 12:00:00 -07002071func addCipherSuiteTests() {
2072 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002073 const psk = "12345"
2074 const pskIdentity = "luggage combo"
2075
Adam Langley95c29f32014-06-20 12:00:00 -07002076 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002077 var certFile string
2078 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002079 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002080 cert = ecdsaP256Certificate
2081 certFile = ecdsaP256CertificateFile
2082 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002083 } else {
David Benjamin33863262016-07-08 17:20:12 -07002084 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002085 certFile = rsaCertificateFile
2086 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002087 }
2088
David Benjamin48cae082014-10-27 01:06:24 -04002089 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002090 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002091 flags = append(flags,
2092 "-psk", psk,
2093 "-psk-identity", pskIdentity)
2094 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002095 if hasComponent(suite.name, "NULL") {
2096 // NULL ciphers must be explicitly enabled.
2097 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2098 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002099 if hasComponent(suite.name, "CECPQ1") {
2100 // CECPQ1 ciphers must be explicitly enabled.
2101 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2102 }
David Benjamin48cae082014-10-27 01:06:24 -04002103
Adam Langley95c29f32014-06-20 12:00:00 -07002104 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002105 for _, protocol := range []protocol{tls, dtls} {
2106 var prefix string
2107 if protocol == dtls {
2108 if !ver.hasDTLS {
2109 continue
2110 }
2111 prefix = "D"
2112 }
Adam Langley95c29f32014-06-20 12:00:00 -07002113
David Benjamin0407e762016-06-17 16:41:18 -04002114 var shouldServerFail, shouldClientFail bool
2115 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2116 // BoringSSL clients accept ECDHE on SSLv3, but
2117 // a BoringSSL server will never select it
2118 // because the extension is missing.
2119 shouldServerFail = true
2120 }
2121 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2122 shouldClientFail = true
2123 shouldServerFail = true
2124 }
David Benjamin54c217c2016-07-13 12:35:25 -04002125 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002126 shouldClientFail = true
2127 shouldServerFail = true
2128 }
David Benjamin0407e762016-06-17 16:41:18 -04002129 if !isDTLSCipher(suite.name) && protocol == dtls {
2130 shouldClientFail = true
2131 shouldServerFail = true
2132 }
David Benjamin4298d772015-12-19 00:18:25 -05002133
David Benjamin0407e762016-06-17 16:41:18 -04002134 var expectedServerError, expectedClientError string
2135 if shouldServerFail {
2136 expectedServerError = ":NO_SHARED_CIPHER:"
2137 }
2138 if shouldClientFail {
2139 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2140 }
David Benjamin025b3d32014-07-01 19:53:04 -04002141
David Benjamin9deb1172016-07-13 17:13:49 -04002142 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2143 resumeSession := ver.version < VersionTLS13
2144
David Benjamin6fd297b2014-08-11 18:43:38 -04002145 testCases = append(testCases, testCase{
2146 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002147 protocol: protocol,
2148
2149 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002150 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002151 MinVersion: ver.version,
2152 MaxVersion: ver.version,
2153 CipherSuites: []uint16{suite.id},
2154 Certificates: []Certificate{cert},
2155 PreSharedKey: []byte(psk),
2156 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002157 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002158 EnableAllCiphers: shouldServerFail,
2159 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002160 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002161 },
2162 certFile: certFile,
2163 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002164 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002165 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002166 shouldFail: shouldServerFail,
2167 expectedError: expectedServerError,
2168 })
2169
2170 testCases = append(testCases, testCase{
2171 testType: clientTest,
2172 protocol: protocol,
2173 name: prefix + ver.name + "-" + suite.name + "-client",
2174 config: Config{
2175 MinVersion: ver.version,
2176 MaxVersion: ver.version,
2177 CipherSuites: []uint16{suite.id},
2178 Certificates: []Certificate{cert},
2179 PreSharedKey: []byte(psk),
2180 PreSharedKeyIdentity: pskIdentity,
2181 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002182 EnableAllCiphers: shouldClientFail,
2183 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002184 },
2185 },
2186 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002187 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002188 shouldFail: shouldClientFail,
2189 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002190 })
David Benjamin2c99d282015-09-01 10:23:00 -04002191
Nick Harper1fd39d82016-06-14 18:14:35 -07002192 if !shouldClientFail {
2193 // Ensure the maximum record size is accepted.
2194 testCases = append(testCases, testCase{
2195 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2196 config: Config{
2197 MinVersion: ver.version,
2198 MaxVersion: ver.version,
2199 CipherSuites: []uint16{suite.id},
2200 Certificates: []Certificate{cert},
2201 PreSharedKey: []byte(psk),
2202 PreSharedKeyIdentity: pskIdentity,
2203 },
2204 flags: flags,
2205 messageLen: maxPlaintext,
2206 })
2207 }
2208 }
David Benjamin2c99d282015-09-01 10:23:00 -04002209 }
Adam Langley95c29f32014-06-20 12:00:00 -07002210 }
Adam Langleya7997f12015-05-14 17:38:50 -07002211
2212 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002213 name: "NoSharedCipher",
2214 config: Config{
2215 // TODO(davidben): Add a TLS 1.3 version of this test.
2216 MaxVersion: VersionTLS12,
2217 CipherSuites: []uint16{},
2218 },
2219 shouldFail: true,
2220 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2221 })
2222
2223 testCases = append(testCases, testCase{
2224 name: "UnsupportedCipherSuite",
2225 config: Config{
2226 MaxVersion: VersionTLS12,
2227 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2228 Bugs: ProtocolBugs{
2229 IgnorePeerCipherPreferences: true,
2230 },
2231 },
2232 flags: []string{"-cipher", "DEFAULT:!RC4"},
2233 shouldFail: true,
2234 expectedError: ":WRONG_CIPHER_RETURNED:",
2235 })
2236
2237 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002238 name: "WeakDH",
2239 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002240 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002241 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2242 Bugs: ProtocolBugs{
2243 // This is a 1023-bit prime number, generated
2244 // with:
2245 // openssl gendh 1023 | openssl asn1parse -i
2246 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2247 },
2248 },
2249 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002250 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002251 })
Adam Langleycef75832015-09-03 14:51:12 -07002252
David Benjamincd24a392015-11-11 13:23:05 -08002253 testCases = append(testCases, testCase{
2254 name: "SillyDH",
2255 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002256 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002257 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2258 Bugs: ProtocolBugs{
2259 // This is a 4097-bit prime number, generated
2260 // with:
2261 // openssl gendh 4097 | openssl asn1parse -i
2262 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2263 },
2264 },
2265 shouldFail: true,
2266 expectedError: ":DH_P_TOO_LONG:",
2267 })
2268
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002269 // This test ensures that Diffie-Hellman public values are padded with
2270 // zeros so that they're the same length as the prime. This is to avoid
2271 // hitting a bug in yaSSL.
2272 testCases = append(testCases, testCase{
2273 testType: serverTest,
2274 name: "DHPublicValuePadded",
2275 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002276 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002277 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2278 Bugs: ProtocolBugs{
2279 RequireDHPublicValueLen: (1025 + 7) / 8,
2280 },
2281 },
2282 flags: []string{"-use-sparse-dh-prime"},
2283 })
David Benjamincd24a392015-11-11 13:23:05 -08002284
David Benjamin241ae832016-01-15 03:04:54 -05002285 // The server must be tolerant to bogus ciphers.
2286 const bogusCipher = 0x1234
2287 testCases = append(testCases, testCase{
2288 testType: serverTest,
2289 name: "UnknownCipher",
2290 config: Config{
2291 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2292 },
2293 })
2294
Adam Langleycef75832015-09-03 14:51:12 -07002295 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2296 // 1.1 specific cipher suite settings. A server is setup with the given
2297 // cipher lists and then a connection is made for each member of
2298 // expectations. The cipher suite that the server selects must match
2299 // the specified one.
2300 var versionSpecificCiphersTest = []struct {
2301 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2302 // expectations is a map from TLS version to cipher suite id.
2303 expectations map[uint16]uint16
2304 }{
2305 {
2306 // Test that the null case (where no version-specific ciphers are set)
2307 // works as expected.
2308 "RC4-SHA:AES128-SHA", // default ciphers
2309 "", // no ciphers specifically for TLS ≥ 1.0
2310 "", // no ciphers specifically for TLS ≥ 1.1
2311 map[uint16]uint16{
2312 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2313 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2314 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2315 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2316 },
2317 },
2318 {
2319 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2320 // cipher.
2321 "RC4-SHA:AES128-SHA", // default
2322 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2323 "", // no ciphers specifically for TLS ≥ 1.1
2324 map[uint16]uint16{
2325 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2326 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2327 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2328 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2329 },
2330 },
2331 {
2332 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2333 // cipher.
2334 "RC4-SHA:AES128-SHA", // default
2335 "", // no ciphers specifically for TLS ≥ 1.0
2336 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2337 map[uint16]uint16{
2338 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2339 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2340 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2341 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2342 },
2343 },
2344 {
2345 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2346 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2347 "RC4-SHA:AES128-SHA", // default
2348 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2349 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2350 map[uint16]uint16{
2351 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2352 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2353 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2354 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2355 },
2356 },
2357 }
2358
2359 for i, test := range versionSpecificCiphersTest {
2360 for version, expectedCipherSuite := range test.expectations {
2361 flags := []string{"-cipher", test.ciphersDefault}
2362 if len(test.ciphersTLS10) > 0 {
2363 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2364 }
2365 if len(test.ciphersTLS11) > 0 {
2366 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2367 }
2368
2369 testCases = append(testCases, testCase{
2370 testType: serverTest,
2371 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2372 config: Config{
2373 MaxVersion: version,
2374 MinVersion: version,
2375 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2376 },
2377 flags: flags,
2378 expectedCipher: expectedCipherSuite,
2379 })
2380 }
2381 }
Adam Langley95c29f32014-06-20 12:00:00 -07002382}
2383
2384func addBadECDSASignatureTests() {
2385 for badR := BadValue(1); badR < NumBadValues; badR++ {
2386 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002387 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002388 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2389 config: Config{
2390 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002391 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002392 Bugs: ProtocolBugs{
2393 BadECDSAR: badR,
2394 BadECDSAS: badS,
2395 },
2396 },
2397 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002398 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002399 })
2400 }
2401 }
2402}
2403
Adam Langley80842bd2014-06-20 12:00:00 -07002404func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002405 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002406 name: "MaxCBCPadding",
2407 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002408 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2410 Bugs: ProtocolBugs{
2411 MaxPadding: true,
2412 },
2413 },
2414 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2415 })
David Benjamin025b3d32014-07-01 19:53:04 -04002416 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002417 name: "BadCBCPadding",
2418 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002419 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002420 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2421 Bugs: ProtocolBugs{
2422 PaddingFirstByteBad: true,
2423 },
2424 },
2425 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002426 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002427 })
2428 // OpenSSL previously had an issue where the first byte of padding in
2429 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002430 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002431 name: "BadCBCPadding255",
2432 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002433 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002434 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2435 Bugs: ProtocolBugs{
2436 MaxPadding: true,
2437 PaddingFirstByteBadIf255: true,
2438 },
2439 },
2440 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2441 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002442 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002443 })
2444}
2445
Kenny Root7fdeaf12014-08-05 15:23:37 -07002446func addCBCSplittingTests() {
2447 testCases = append(testCases, testCase{
2448 name: "CBCRecordSplitting",
2449 config: Config{
2450 MaxVersion: VersionTLS10,
2451 MinVersion: VersionTLS10,
2452 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2453 },
David Benjaminac8302a2015-09-01 17:18:15 -04002454 messageLen: -1, // read until EOF
2455 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002456 flags: []string{
2457 "-async",
2458 "-write-different-record-sizes",
2459 "-cbc-record-splitting",
2460 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002461 })
2462 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002463 name: "CBCRecordSplittingPartialWrite",
2464 config: Config{
2465 MaxVersion: VersionTLS10,
2466 MinVersion: VersionTLS10,
2467 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2468 },
2469 messageLen: -1, // read until EOF
2470 flags: []string{
2471 "-async",
2472 "-write-different-record-sizes",
2473 "-cbc-record-splitting",
2474 "-partial-write",
2475 },
2476 })
2477}
2478
David Benjamin636293b2014-07-08 17:59:18 -04002479func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002480 // Add a dummy cert pool to stress certificate authority parsing.
2481 // TODO(davidben): Add tests that those values parse out correctly.
2482 certPool := x509.NewCertPool()
2483 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2484 if err != nil {
2485 panic(err)
2486 }
2487 certPool.AddCert(cert)
2488
David Benjamin636293b2014-07-08 17:59:18 -04002489 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002490 testCases = append(testCases, testCase{
2491 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002492 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002493 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002494 MinVersion: ver.version,
2495 MaxVersion: ver.version,
2496 ClientAuth: RequireAnyClientCert,
2497 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002498 },
2499 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002500 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2501 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002502 },
2503 })
2504 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002505 testType: serverTest,
2506 name: ver.name + "-Server-ClientAuth-RSA",
2507 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002508 MinVersion: ver.version,
2509 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002510 Certificates: []Certificate{rsaCertificate},
2511 },
2512 flags: []string{"-require-any-client-certificate"},
2513 })
David Benjamine098ec22014-08-27 23:13:20 -04002514 if ver.version != VersionSSL30 {
2515 testCases = append(testCases, testCase{
2516 testType: serverTest,
2517 name: ver.name + "-Server-ClientAuth-ECDSA",
2518 config: Config{
2519 MinVersion: ver.version,
2520 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002521 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002522 },
2523 flags: []string{"-require-any-client-certificate"},
2524 })
2525 testCases = append(testCases, testCase{
2526 testType: clientTest,
2527 name: ver.name + "-Client-ClientAuth-ECDSA",
2528 config: Config{
2529 MinVersion: ver.version,
2530 MaxVersion: ver.version,
2531 ClientAuth: RequireAnyClientCert,
2532 ClientCAs: certPool,
2533 },
2534 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002535 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2536 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002537 },
2538 })
2539 }
David Benjamin636293b2014-07-08 17:59:18 -04002540 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002541
Nick Harper1fd39d82016-06-14 18:14:35 -07002542 // TODO(davidben): These tests will need TLS 1.3 versions when the
2543 // handshake is separate.
2544
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002545 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002546 name: "NoClientCertificate",
2547 config: Config{
2548 MaxVersion: VersionTLS12,
2549 ClientAuth: RequireAnyClientCert,
2550 },
2551 shouldFail: true,
2552 expectedLocalError: "client didn't provide a certificate",
2553 })
2554
2555 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002556 testType: serverTest,
2557 name: "RequireAnyClientCertificate",
2558 config: Config{
2559 MaxVersion: VersionTLS12,
2560 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002561 flags: []string{"-require-any-client-certificate"},
2562 shouldFail: true,
2563 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2564 })
2565
2566 testCases = append(testCases, testCase{
2567 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002568 name: "RequireAnyClientCertificate-SSL3",
2569 config: Config{
2570 MaxVersion: VersionSSL30,
2571 },
2572 flags: []string{"-require-any-client-certificate"},
2573 shouldFail: true,
2574 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2575 })
2576
2577 testCases = append(testCases, testCase{
2578 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002579 name: "SkipClientCertificate",
2580 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002581 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002582 Bugs: ProtocolBugs{
2583 SkipClientCertificate: true,
2584 },
2585 },
2586 // Setting SSL_VERIFY_PEER allows anonymous clients.
2587 flags: []string{"-verify-peer"},
2588 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002589 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002590 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002591
2592 // Client auth is only legal in certificate-based ciphers.
2593 testCases = append(testCases, testCase{
2594 testType: clientTest,
2595 name: "ClientAuth-PSK",
2596 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002597 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002598 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2599 PreSharedKey: []byte("secret"),
2600 ClientAuth: RequireAnyClientCert,
2601 },
2602 flags: []string{
2603 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2604 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2605 "-psk", "secret",
2606 },
2607 shouldFail: true,
2608 expectedError: ":UNEXPECTED_MESSAGE:",
2609 })
2610 testCases = append(testCases, testCase{
2611 testType: clientTest,
2612 name: "ClientAuth-ECDHE_PSK",
2613 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002614 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002615 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2616 PreSharedKey: []byte("secret"),
2617 ClientAuth: RequireAnyClientCert,
2618 },
2619 flags: []string{
2620 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2621 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2622 "-psk", "secret",
2623 },
2624 shouldFail: true,
2625 expectedError: ":UNEXPECTED_MESSAGE:",
2626 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002627
2628 // Regression test for a bug where the client CA list, if explicitly
2629 // set to NULL, was mis-encoded.
2630 testCases = append(testCases, testCase{
2631 testType: serverTest,
2632 name: "Null-Client-CA-List",
2633 config: Config{
2634 MaxVersion: VersionTLS12,
2635 Certificates: []Certificate{rsaCertificate},
2636 },
2637 flags: []string{
2638 "-require-any-client-certificate",
2639 "-use-null-client-ca-list",
2640 },
2641 })
David Benjamin636293b2014-07-08 17:59:18 -04002642}
2643
Adam Langley75712922014-10-10 16:23:43 -07002644func addExtendedMasterSecretTests() {
2645 const expectEMSFlag = "-expect-extended-master-secret"
2646
2647 for _, with := range []bool{false, true} {
2648 prefix := "No"
2649 var flags []string
2650 if with {
2651 prefix = ""
2652 flags = []string{expectEMSFlag}
2653 }
2654
2655 for _, isClient := range []bool{false, true} {
2656 suffix := "-Server"
2657 testType := serverTest
2658 if isClient {
2659 suffix = "-Client"
2660 testType = clientTest
2661 }
2662
David Benjamin4c3ddf72016-06-29 18:13:53 -04002663 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2664 // test that the extension is irrelevant, but the API
2665 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002666 for _, ver := range tlsVersions {
2667 test := testCase{
2668 testType: testType,
2669 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2670 config: Config{
2671 MinVersion: ver.version,
2672 MaxVersion: ver.version,
2673 Bugs: ProtocolBugs{
2674 NoExtendedMasterSecret: !with,
2675 RequireExtendedMasterSecret: with,
2676 },
2677 },
David Benjamin48cae082014-10-27 01:06:24 -04002678 flags: flags,
2679 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002680 }
2681 if test.shouldFail {
2682 test.expectedLocalError = "extended master secret required but not supported by peer"
2683 }
2684 testCases = append(testCases, test)
2685 }
2686 }
2687 }
2688
Adam Langleyba5934b2015-06-02 10:50:35 -07002689 for _, isClient := range []bool{false, true} {
2690 for _, supportedInFirstConnection := range []bool{false, true} {
2691 for _, supportedInResumeConnection := range []bool{false, true} {
2692 boolToWord := func(b bool) string {
2693 if b {
2694 return "Yes"
2695 }
2696 return "No"
2697 }
2698 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2699 if isClient {
2700 suffix += "Client"
2701 } else {
2702 suffix += "Server"
2703 }
2704
2705 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002706 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002707 Bugs: ProtocolBugs{
2708 RequireExtendedMasterSecret: true,
2709 },
2710 }
2711
2712 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002713 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002714 Bugs: ProtocolBugs{
2715 NoExtendedMasterSecret: true,
2716 },
2717 }
2718
2719 test := testCase{
2720 name: "ExtendedMasterSecret-" + suffix,
2721 resumeSession: true,
2722 }
2723
2724 if !isClient {
2725 test.testType = serverTest
2726 }
2727
2728 if supportedInFirstConnection {
2729 test.config = supportedConfig
2730 } else {
2731 test.config = noSupportConfig
2732 }
2733
2734 if supportedInResumeConnection {
2735 test.resumeConfig = &supportedConfig
2736 } else {
2737 test.resumeConfig = &noSupportConfig
2738 }
2739
2740 switch suffix {
2741 case "YesToYes-Client", "YesToYes-Server":
2742 // When a session is resumed, it should
2743 // still be aware that its master
2744 // secret was generated via EMS and
2745 // thus it's safe to use tls-unique.
2746 test.flags = []string{expectEMSFlag}
2747 case "NoToYes-Server":
2748 // If an original connection did not
2749 // contain EMS, but a resumption
2750 // handshake does, then a server should
2751 // not resume the session.
2752 test.expectResumeRejected = true
2753 case "YesToNo-Server":
2754 // Resuming an EMS session without the
2755 // EMS extension should cause the
2756 // server to abort the connection.
2757 test.shouldFail = true
2758 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2759 case "NoToYes-Client":
2760 // A client should abort a connection
2761 // where the server resumed a non-EMS
2762 // session but echoed the EMS
2763 // extension.
2764 test.shouldFail = true
2765 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2766 case "YesToNo-Client":
2767 // A client should abort a connection
2768 // where the server didn't echo EMS
2769 // when the session used it.
2770 test.shouldFail = true
2771 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2772 }
2773
2774 testCases = append(testCases, test)
2775 }
2776 }
2777 }
Adam Langley75712922014-10-10 16:23:43 -07002778}
2779
David Benjamin582ba042016-07-07 12:33:25 -07002780type stateMachineTestConfig struct {
2781 protocol protocol
2782 async bool
2783 splitHandshake, packHandshakeFlight bool
2784}
2785
David Benjamin43ec06f2014-08-05 02:28:57 -04002786// Adds tests that try to cover the range of the handshake state machine, under
2787// various conditions. Some of these are redundant with other tests, but they
2788// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002789func addAllStateMachineCoverageTests() {
2790 for _, async := range []bool{false, true} {
2791 for _, protocol := range []protocol{tls, dtls} {
2792 addStateMachineCoverageTests(stateMachineTestConfig{
2793 protocol: protocol,
2794 async: async,
2795 })
2796 addStateMachineCoverageTests(stateMachineTestConfig{
2797 protocol: protocol,
2798 async: async,
2799 splitHandshake: true,
2800 })
2801 if protocol == tls {
2802 addStateMachineCoverageTests(stateMachineTestConfig{
2803 protocol: protocol,
2804 async: async,
2805 packHandshakeFlight: true,
2806 })
2807 }
2808 }
2809 }
2810}
2811
2812func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002813 var tests []testCase
2814
2815 // Basic handshake, with resumption. Client and server,
2816 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002817 //
2818 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2819 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002820 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002821 name: "Basic-Client",
2822 config: Config{
2823 MaxVersion: VersionTLS12,
2824 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002825 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002826 // Ensure session tickets are used, not session IDs.
2827 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002828 })
2829 tests = append(tests, testCase{
2830 name: "Basic-Client-RenewTicket",
2831 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002832 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002833 Bugs: ProtocolBugs{
2834 RenewTicketOnResume: true,
2835 },
2836 },
David Benjaminba4594a2015-06-18 18:36:15 -04002837 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002838 resumeSession: true,
2839 })
2840 tests = append(tests, testCase{
2841 name: "Basic-Client-NoTicket",
2842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002843 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002844 SessionTicketsDisabled: true,
2845 },
2846 resumeSession: true,
2847 })
2848 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002849 name: "Basic-Client-Implicit",
2850 config: Config{
2851 MaxVersion: VersionTLS12,
2852 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002853 flags: []string{"-implicit-handshake"},
2854 resumeSession: true,
2855 })
2856 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002857 testType: serverTest,
2858 name: "Basic-Server",
2859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002860 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002861 Bugs: ProtocolBugs{
2862 RequireSessionTickets: true,
2863 },
2864 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002865 resumeSession: true,
2866 })
2867 tests = append(tests, testCase{
2868 testType: serverTest,
2869 name: "Basic-Server-NoTickets",
2870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002871 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002872 SessionTicketsDisabled: true,
2873 },
2874 resumeSession: true,
2875 })
2876 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002877 testType: serverTest,
2878 name: "Basic-Server-Implicit",
2879 config: Config{
2880 MaxVersion: VersionTLS12,
2881 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002882 flags: []string{"-implicit-handshake"},
2883 resumeSession: true,
2884 })
2885 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002886 testType: serverTest,
2887 name: "Basic-Server-EarlyCallback",
2888 config: Config{
2889 MaxVersion: VersionTLS12,
2890 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002891 flags: []string{"-use-early-callback"},
2892 resumeSession: true,
2893 })
2894
2895 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002896 //
2897 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002898 tests = append(tests, testCase{
2899 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002900 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002901 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002902 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002903 ClientAuth: RequestClientCert,
2904 },
2905 })
2906 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002907 testType: serverTest,
2908 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002909 config: Config{
2910 MaxVersion: VersionTLS12,
2911 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002912 // Setting SSL_VERIFY_PEER allows anonymous clients.
2913 flags: []string{"-verify-peer"},
2914 })
David Benjamin582ba042016-07-07 12:33:25 -07002915 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002916 tests = append(tests, testCase{
2917 testType: clientTest,
2918 name: "ClientAuth-NoCertificate-Client-SSL3",
2919 config: Config{
2920 MaxVersion: VersionSSL30,
2921 ClientAuth: RequestClientCert,
2922 },
2923 })
2924 tests = append(tests, testCase{
2925 testType: serverTest,
2926 name: "ClientAuth-NoCertificate-Server-SSL3",
2927 config: Config{
2928 MaxVersion: VersionSSL30,
2929 },
2930 // Setting SSL_VERIFY_PEER allows anonymous clients.
2931 flags: []string{"-verify-peer"},
2932 })
2933 }
2934 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002935 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002936 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002937 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002938 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002939 ClientAuth: RequireAnyClientCert,
2940 },
2941 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002942 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2943 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002944 },
2945 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002946 tests = append(tests, testCase{
2947 testType: clientTest,
2948 name: "ClientAuth-ECDSA-Client",
2949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002950 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002951 ClientAuth: RequireAnyClientCert,
2952 },
2953 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002954 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2955 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002956 },
2957 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002958 tests = append(tests, testCase{
2959 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04002960 name: "ClientAuth-NoCertificate-OldCallback",
2961 config: Config{
2962 MaxVersion: VersionTLS12,
2963 ClientAuth: RequestClientCert,
2964 },
2965 flags: []string{"-use-old-client-cert-callback"},
2966 })
2967 tests = append(tests, testCase{
2968 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002969 name: "ClientAuth-OldCallback",
2970 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002971 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002972 ClientAuth: RequireAnyClientCert,
2973 },
2974 flags: []string{
2975 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2976 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2977 "-use-old-client-cert-callback",
2978 },
2979 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002980 tests = append(tests, testCase{
2981 testType: serverTest,
2982 name: "ClientAuth-Server",
2983 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002984 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002985 Certificates: []Certificate{rsaCertificate},
2986 },
2987 flags: []string{"-require-any-client-certificate"},
2988 })
2989
David Benjamin4c3ddf72016-06-29 18:13:53 -04002990 // Test each key exchange on the server side for async keys.
2991 //
2992 // TODO(davidben): Add TLS 1.3 versions of these.
2993 tests = append(tests, testCase{
2994 testType: serverTest,
2995 name: "Basic-Server-RSA",
2996 config: Config{
2997 MaxVersion: VersionTLS12,
2998 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2999 },
3000 flags: []string{
3001 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3002 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3003 },
3004 })
3005 tests = append(tests, testCase{
3006 testType: serverTest,
3007 name: "Basic-Server-ECDHE-RSA",
3008 config: Config{
3009 MaxVersion: VersionTLS12,
3010 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3011 },
3012 flags: []string{
3013 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3014 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3015 },
3016 })
3017 tests = append(tests, testCase{
3018 testType: serverTest,
3019 name: "Basic-Server-ECDHE-ECDSA",
3020 config: Config{
3021 MaxVersion: VersionTLS12,
3022 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3023 },
3024 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003025 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3026 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003027 },
3028 })
3029
David Benjamin760b1dd2015-05-15 23:33:48 -04003030 // No session ticket support; server doesn't send NewSessionTicket.
3031 tests = append(tests, testCase{
3032 name: "SessionTicketsDisabled-Client",
3033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003034 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003035 SessionTicketsDisabled: true,
3036 },
3037 })
3038 tests = append(tests, testCase{
3039 testType: serverTest,
3040 name: "SessionTicketsDisabled-Server",
3041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003042 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003043 SessionTicketsDisabled: true,
3044 },
3045 })
3046
3047 // Skip ServerKeyExchange in PSK key exchange if there's no
3048 // identity hint.
3049 tests = append(tests, testCase{
3050 name: "EmptyPSKHint-Client",
3051 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003052 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003053 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3054 PreSharedKey: []byte("secret"),
3055 },
3056 flags: []string{"-psk", "secret"},
3057 })
3058 tests = append(tests, testCase{
3059 testType: serverTest,
3060 name: "EmptyPSKHint-Server",
3061 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003062 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003063 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3064 PreSharedKey: []byte("secret"),
3065 },
3066 flags: []string{"-psk", "secret"},
3067 })
3068
David Benjamin4c3ddf72016-06-29 18:13:53 -04003069 // OCSP stapling tests.
3070 //
3071 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003072 tests = append(tests, testCase{
3073 testType: clientTest,
3074 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003075 config: Config{
3076 MaxVersion: VersionTLS12,
3077 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003078 flags: []string{
3079 "-enable-ocsp-stapling",
3080 "-expect-ocsp-response",
3081 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003082 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003083 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003084 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003085 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003086 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003087 testType: serverTest,
3088 name: "OCSPStapling-Server",
3089 config: Config{
3090 MaxVersion: VersionTLS12,
3091 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003092 expectedOCSPResponse: testOCSPResponse,
3093 flags: []string{
3094 "-ocsp-response",
3095 base64.StdEncoding.EncodeToString(testOCSPResponse),
3096 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003097 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003098 })
3099
David Benjamin4c3ddf72016-06-29 18:13:53 -04003100 // Certificate verification tests.
3101 //
3102 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003103 tests = append(tests, testCase{
3104 testType: clientTest,
3105 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003106 config: Config{
3107 MaxVersion: VersionTLS12,
3108 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003109 flags: []string{
3110 "-verify-peer",
3111 },
3112 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003113 tests = append(tests, testCase{
3114 testType: clientTest,
3115 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003116 config: Config{
3117 MaxVersion: VersionTLS12,
3118 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003119 flags: []string{
3120 "-verify-fail",
3121 "-verify-peer",
3122 },
3123 shouldFail: true,
3124 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3125 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003126 tests = append(tests, testCase{
3127 testType: clientTest,
3128 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003129 config: Config{
3130 MaxVersion: VersionTLS12,
3131 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003132 flags: []string{
3133 "-verify-fail",
3134 "-expect-verify-result",
3135 },
3136 })
3137
David Benjamin582ba042016-07-07 12:33:25 -07003138 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003139 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003140 name: "Renegotiate-Client",
3141 config: Config{
3142 MaxVersion: VersionTLS12,
3143 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003144 renegotiate: 1,
3145 flags: []string{
3146 "-renegotiate-freely",
3147 "-expect-total-renegotiations", "1",
3148 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003149 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003150
David Benjamin760b1dd2015-05-15 23:33:48 -04003151 // NPN on client and server; results in post-handshake message.
3152 tests = append(tests, testCase{
3153 name: "NPN-Client",
3154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003155 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003156 NextProtos: []string{"foo"},
3157 },
3158 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003159 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003160 expectedNextProto: "foo",
3161 expectedNextProtoType: npn,
3162 })
3163 tests = append(tests, testCase{
3164 testType: serverTest,
3165 name: "NPN-Server",
3166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003167 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003168 NextProtos: []string{"bar"},
3169 },
3170 flags: []string{
3171 "-advertise-npn", "\x03foo\x03bar\x03baz",
3172 "-expect-next-proto", "bar",
3173 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003174 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003175 expectedNextProto: "bar",
3176 expectedNextProtoType: npn,
3177 })
3178
3179 // TODO(davidben): Add tests for when False Start doesn't trigger.
3180
3181 // Client does False Start and negotiates NPN.
3182 tests = append(tests, testCase{
3183 name: "FalseStart",
3184 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003185 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003186 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3187 NextProtos: []string{"foo"},
3188 Bugs: ProtocolBugs{
3189 ExpectFalseStart: true,
3190 },
3191 },
3192 flags: []string{
3193 "-false-start",
3194 "-select-next-proto", "foo",
3195 },
3196 shimWritesFirst: true,
3197 resumeSession: true,
3198 })
3199
3200 // Client does False Start and negotiates ALPN.
3201 tests = append(tests, testCase{
3202 name: "FalseStart-ALPN",
3203 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003204 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003205 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3206 NextProtos: []string{"foo"},
3207 Bugs: ProtocolBugs{
3208 ExpectFalseStart: true,
3209 },
3210 },
3211 flags: []string{
3212 "-false-start",
3213 "-advertise-alpn", "\x03foo",
3214 },
3215 shimWritesFirst: true,
3216 resumeSession: true,
3217 })
3218
3219 // Client does False Start but doesn't explicitly call
3220 // SSL_connect.
3221 tests = append(tests, testCase{
3222 name: "FalseStart-Implicit",
3223 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003224 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003225 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3226 NextProtos: []string{"foo"},
3227 },
3228 flags: []string{
3229 "-implicit-handshake",
3230 "-false-start",
3231 "-advertise-alpn", "\x03foo",
3232 },
3233 })
3234
3235 // False Start without session tickets.
3236 tests = append(tests, testCase{
3237 name: "FalseStart-SessionTicketsDisabled",
3238 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003239 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003240 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3241 NextProtos: []string{"foo"},
3242 SessionTicketsDisabled: true,
3243 Bugs: ProtocolBugs{
3244 ExpectFalseStart: true,
3245 },
3246 },
3247 flags: []string{
3248 "-false-start",
3249 "-select-next-proto", "foo",
3250 },
3251 shimWritesFirst: true,
3252 })
3253
Adam Langleydf759b52016-07-11 15:24:37 -07003254 tests = append(tests, testCase{
3255 name: "FalseStart-CECPQ1",
3256 config: Config{
3257 MaxVersion: VersionTLS12,
3258 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3259 NextProtos: []string{"foo"},
3260 Bugs: ProtocolBugs{
3261 ExpectFalseStart: true,
3262 },
3263 },
3264 flags: []string{
3265 "-false-start",
3266 "-cipher", "DEFAULT:kCECPQ1",
3267 "-select-next-proto", "foo",
3268 },
3269 shimWritesFirst: true,
3270 resumeSession: true,
3271 })
3272
David Benjamin760b1dd2015-05-15 23:33:48 -04003273 // Server parses a V2ClientHello.
3274 tests = append(tests, testCase{
3275 testType: serverTest,
3276 name: "SendV2ClientHello",
3277 config: Config{
3278 // Choose a cipher suite that does not involve
3279 // elliptic curves, so no extensions are
3280 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003281 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003282 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3283 Bugs: ProtocolBugs{
3284 SendV2ClientHello: true,
3285 },
3286 },
3287 })
3288
3289 // Client sends a Channel ID.
3290 tests = append(tests, testCase{
3291 name: "ChannelID-Client",
3292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003293 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003294 RequestChannelID: true,
3295 },
Adam Langley7c803a62015-06-15 15:35:05 -07003296 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003297 resumeSession: true,
3298 expectChannelID: true,
3299 })
3300
3301 // Server accepts a Channel ID.
3302 tests = append(tests, testCase{
3303 testType: serverTest,
3304 name: "ChannelID-Server",
3305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003306 MaxVersion: VersionTLS12,
3307 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003308 },
3309 flags: []string{
3310 "-expect-channel-id",
3311 base64.StdEncoding.EncodeToString(channelIDBytes),
3312 },
3313 resumeSession: true,
3314 expectChannelID: true,
3315 })
David Benjamin30789da2015-08-29 22:56:45 -04003316
David Benjaminf8fcdf32016-06-08 15:56:13 -04003317 // Channel ID and NPN at the same time, to ensure their relative
3318 // ordering is correct.
3319 tests = append(tests, testCase{
3320 name: "ChannelID-NPN-Client",
3321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003322 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003323 RequestChannelID: true,
3324 NextProtos: []string{"foo"},
3325 },
3326 flags: []string{
3327 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3328 "-select-next-proto", "foo",
3329 },
3330 resumeSession: true,
3331 expectChannelID: true,
3332 expectedNextProto: "foo",
3333 expectedNextProtoType: npn,
3334 })
3335 tests = append(tests, testCase{
3336 testType: serverTest,
3337 name: "ChannelID-NPN-Server",
3338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003339 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003340 ChannelID: channelIDKey,
3341 NextProtos: []string{"bar"},
3342 },
3343 flags: []string{
3344 "-expect-channel-id",
3345 base64.StdEncoding.EncodeToString(channelIDBytes),
3346 "-advertise-npn", "\x03foo\x03bar\x03baz",
3347 "-expect-next-proto", "bar",
3348 },
3349 resumeSession: true,
3350 expectChannelID: true,
3351 expectedNextProto: "bar",
3352 expectedNextProtoType: npn,
3353 })
3354
David Benjamin30789da2015-08-29 22:56:45 -04003355 // Bidirectional shutdown with the runner initiating.
3356 tests = append(tests, testCase{
3357 name: "Shutdown-Runner",
3358 config: Config{
3359 Bugs: ProtocolBugs{
3360 ExpectCloseNotify: true,
3361 },
3362 },
3363 flags: []string{"-check-close-notify"},
3364 })
3365
3366 // Bidirectional shutdown with the shim initiating. The runner,
3367 // in the meantime, sends garbage before the close_notify which
3368 // the shim must ignore.
3369 tests = append(tests, testCase{
3370 name: "Shutdown-Shim",
3371 config: Config{
3372 Bugs: ProtocolBugs{
3373 ExpectCloseNotify: true,
3374 },
3375 },
3376 shimShutsDown: true,
3377 sendEmptyRecords: 1,
3378 sendWarningAlerts: 1,
3379 flags: []string{"-check-close-notify"},
3380 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003381 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003382 // TODO(davidben): DTLS 1.3 will want a similar thing for
3383 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003384 tests = append(tests, testCase{
3385 name: "SkipHelloVerifyRequest",
3386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003387 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003388 Bugs: ProtocolBugs{
3389 SkipHelloVerifyRequest: true,
3390 },
3391 },
3392 })
3393 }
3394
David Benjamin760b1dd2015-05-15 23:33:48 -04003395 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003396 test.protocol = config.protocol
3397 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003398 test.name += "-DTLS"
3399 }
David Benjamin582ba042016-07-07 12:33:25 -07003400 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003401 test.name += "-Async"
3402 test.flags = append(test.flags, "-async")
3403 } else {
3404 test.name += "-Sync"
3405 }
David Benjamin582ba042016-07-07 12:33:25 -07003406 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003407 test.name += "-SplitHandshakeRecords"
3408 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003409 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003410 test.config.Bugs.MaxPacketLength = 256
3411 test.flags = append(test.flags, "-mtu", "256")
3412 }
3413 }
David Benjamin582ba042016-07-07 12:33:25 -07003414 if config.packHandshakeFlight {
3415 test.name += "-PackHandshakeFlight"
3416 test.config.Bugs.PackHandshakeFlight = true
3417 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003418 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003419 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003420}
3421
Adam Langley524e7172015-02-20 16:04:00 -08003422func addDDoSCallbackTests() {
3423 // DDoS callback.
3424
3425 for _, resume := range []bool{false, true} {
3426 suffix := "Resume"
3427 if resume {
3428 suffix = "No" + suffix
3429 }
3430
David Benjamin4c3ddf72016-06-29 18:13:53 -04003431 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3432
Adam Langley524e7172015-02-20 16:04:00 -08003433 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003434 testType: serverTest,
3435 name: "Server-DDoS-OK-" + suffix,
3436 config: Config{
3437 MaxVersion: VersionTLS12,
3438 },
Adam Langley524e7172015-02-20 16:04:00 -08003439 flags: []string{"-install-ddos-callback"},
3440 resumeSession: resume,
3441 })
3442
3443 failFlag := "-fail-ddos-callback"
3444 if resume {
3445 failFlag = "-fail-second-ddos-callback"
3446 }
3447 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003448 testType: serverTest,
3449 name: "Server-DDoS-Reject-" + suffix,
3450 config: Config{
3451 MaxVersion: VersionTLS12,
3452 },
Adam Langley524e7172015-02-20 16:04:00 -08003453 flags: []string{"-install-ddos-callback", failFlag},
3454 resumeSession: resume,
3455 shouldFail: true,
3456 expectedError: ":CONNECTION_REJECTED:",
3457 })
3458 }
3459}
3460
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003461func addVersionNegotiationTests() {
3462 for i, shimVers := range tlsVersions {
3463 // Assemble flags to disable all newer versions on the shim.
3464 var flags []string
3465 for _, vers := range tlsVersions[i+1:] {
3466 flags = append(flags, vers.flag)
3467 }
3468
3469 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003470 protocols := []protocol{tls}
3471 if runnerVers.hasDTLS && shimVers.hasDTLS {
3472 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003473 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003474 for _, protocol := range protocols {
3475 expectedVersion := shimVers.version
3476 if runnerVers.version < shimVers.version {
3477 expectedVersion = runnerVers.version
3478 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003479
David Benjamin8b8c0062014-11-23 02:47:52 -05003480 suffix := shimVers.name + "-" + runnerVers.name
3481 if protocol == dtls {
3482 suffix += "-DTLS"
3483 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003484
David Benjamin1eb367c2014-12-12 18:17:51 -05003485 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3486
David Benjamin1e29a6b2014-12-10 02:27:24 -05003487 clientVers := shimVers.version
3488 if clientVers > VersionTLS10 {
3489 clientVers = VersionTLS10
3490 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003491 serverVers := expectedVersion
3492 if expectedVersion >= VersionTLS13 {
3493 serverVers = VersionTLS10
3494 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003495 testCases = append(testCases, testCase{
3496 protocol: protocol,
3497 testType: clientTest,
3498 name: "VersionNegotiation-Client-" + suffix,
3499 config: Config{
3500 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003501 Bugs: ProtocolBugs{
3502 ExpectInitialRecordVersion: clientVers,
3503 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003504 },
3505 flags: flags,
3506 expectedVersion: expectedVersion,
3507 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003508 testCases = append(testCases, testCase{
3509 protocol: protocol,
3510 testType: clientTest,
3511 name: "VersionNegotiation-Client2-" + suffix,
3512 config: Config{
3513 MaxVersion: runnerVers.version,
3514 Bugs: ProtocolBugs{
3515 ExpectInitialRecordVersion: clientVers,
3516 },
3517 },
3518 flags: []string{"-max-version", shimVersFlag},
3519 expectedVersion: expectedVersion,
3520 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003521
3522 testCases = append(testCases, testCase{
3523 protocol: protocol,
3524 testType: serverTest,
3525 name: "VersionNegotiation-Server-" + suffix,
3526 config: Config{
3527 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003528 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003529 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003530 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003531 },
3532 flags: flags,
3533 expectedVersion: expectedVersion,
3534 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003535 testCases = append(testCases, testCase{
3536 protocol: protocol,
3537 testType: serverTest,
3538 name: "VersionNegotiation-Server2-" + suffix,
3539 config: Config{
3540 MaxVersion: runnerVers.version,
3541 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003542 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003543 },
3544 },
3545 flags: []string{"-max-version", shimVersFlag},
3546 expectedVersion: expectedVersion,
3547 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003548 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003549 }
3550 }
David Benjamin95c69562016-06-29 18:15:03 -04003551
3552 // Test for version tolerance.
3553 testCases = append(testCases, testCase{
3554 testType: serverTest,
3555 name: "MinorVersionTolerance",
3556 config: Config{
3557 Bugs: ProtocolBugs{
3558 SendClientVersion: 0x03ff,
3559 },
3560 },
3561 expectedVersion: VersionTLS13,
3562 })
3563 testCases = append(testCases, testCase{
3564 testType: serverTest,
3565 name: "MajorVersionTolerance",
3566 config: Config{
3567 Bugs: ProtocolBugs{
3568 SendClientVersion: 0x0400,
3569 },
3570 },
3571 expectedVersion: VersionTLS13,
3572 })
3573 testCases = append(testCases, testCase{
3574 protocol: dtls,
3575 testType: serverTest,
3576 name: "MinorVersionTolerance-DTLS",
3577 config: Config{
3578 Bugs: ProtocolBugs{
3579 SendClientVersion: 0x03ff,
3580 },
3581 },
3582 expectedVersion: VersionTLS12,
3583 })
3584 testCases = append(testCases, testCase{
3585 protocol: dtls,
3586 testType: serverTest,
3587 name: "MajorVersionTolerance-DTLS",
3588 config: Config{
3589 Bugs: ProtocolBugs{
3590 SendClientVersion: 0x0400,
3591 },
3592 },
3593 expectedVersion: VersionTLS12,
3594 })
3595
3596 // Test that versions below 3.0 are rejected.
3597 testCases = append(testCases, testCase{
3598 testType: serverTest,
3599 name: "VersionTooLow",
3600 config: Config{
3601 Bugs: ProtocolBugs{
3602 SendClientVersion: 0x0200,
3603 },
3604 },
3605 shouldFail: true,
3606 expectedError: ":UNSUPPORTED_PROTOCOL:",
3607 })
3608 testCases = append(testCases, testCase{
3609 protocol: dtls,
3610 testType: serverTest,
3611 name: "VersionTooLow-DTLS",
3612 config: Config{
3613 Bugs: ProtocolBugs{
3614 // 0x0201 is the lowest version expressable in
3615 // DTLS.
3616 SendClientVersion: 0x0201,
3617 },
3618 },
3619 shouldFail: true,
3620 expectedError: ":UNSUPPORTED_PROTOCOL:",
3621 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003622
3623 // Test TLS 1.3's downgrade signal.
3624 testCases = append(testCases, testCase{
3625 name: "Downgrade-TLS12-Client",
3626 config: Config{
3627 Bugs: ProtocolBugs{
3628 NegotiateVersion: VersionTLS12,
3629 },
3630 },
3631 shouldFail: true,
3632 expectedError: ":DOWNGRADE_DETECTED:",
3633 })
3634 testCases = append(testCases, testCase{
3635 testType: serverTest,
3636 name: "Downgrade-TLS12-Server",
3637 config: Config{
3638 Bugs: ProtocolBugs{
3639 SendClientVersion: VersionTLS12,
3640 },
3641 },
3642 shouldFail: true,
3643 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3644 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003645}
3646
David Benjaminaccb4542014-12-12 23:44:33 -05003647func addMinimumVersionTests() {
3648 for i, shimVers := range tlsVersions {
3649 // Assemble flags to disable all older versions on the shim.
3650 var flags []string
3651 for _, vers := range tlsVersions[:i] {
3652 flags = append(flags, vers.flag)
3653 }
3654
3655 for _, runnerVers := range tlsVersions {
3656 protocols := []protocol{tls}
3657 if runnerVers.hasDTLS && shimVers.hasDTLS {
3658 protocols = append(protocols, dtls)
3659 }
3660 for _, protocol := range protocols {
3661 suffix := shimVers.name + "-" + runnerVers.name
3662 if protocol == dtls {
3663 suffix += "-DTLS"
3664 }
3665 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3666
David Benjaminaccb4542014-12-12 23:44:33 -05003667 var expectedVersion uint16
3668 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003669 var expectedClientError, expectedServerError string
3670 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003671 if runnerVers.version >= shimVers.version {
3672 expectedVersion = runnerVers.version
3673 } else {
3674 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003675 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3676 expectedServerLocalError = "remote error: protocol version not supported"
3677 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3678 // If the client's minimum version is TLS 1.3 and the runner's
3679 // maximum is below TLS 1.2, the runner will fail to select a
3680 // cipher before the shim rejects the selected version.
3681 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3682 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3683 } else {
3684 expectedClientError = expectedServerError
3685 expectedClientLocalError = expectedServerLocalError
3686 }
David Benjaminaccb4542014-12-12 23:44:33 -05003687 }
3688
3689 testCases = append(testCases, testCase{
3690 protocol: protocol,
3691 testType: clientTest,
3692 name: "MinimumVersion-Client-" + suffix,
3693 config: Config{
3694 MaxVersion: runnerVers.version,
3695 },
David Benjamin87909c02014-12-13 01:55:01 -05003696 flags: flags,
3697 expectedVersion: expectedVersion,
3698 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003699 expectedError: expectedClientError,
3700 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003701 })
3702 testCases = append(testCases, testCase{
3703 protocol: protocol,
3704 testType: clientTest,
3705 name: "MinimumVersion-Client2-" + suffix,
3706 config: Config{
3707 MaxVersion: runnerVers.version,
3708 },
David Benjamin87909c02014-12-13 01:55:01 -05003709 flags: []string{"-min-version", shimVersFlag},
3710 expectedVersion: expectedVersion,
3711 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003712 expectedError: expectedClientError,
3713 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003714 })
3715
3716 testCases = append(testCases, testCase{
3717 protocol: protocol,
3718 testType: serverTest,
3719 name: "MinimumVersion-Server-" + suffix,
3720 config: Config{
3721 MaxVersion: runnerVers.version,
3722 },
David Benjamin87909c02014-12-13 01:55:01 -05003723 flags: flags,
3724 expectedVersion: expectedVersion,
3725 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003726 expectedError: expectedServerError,
3727 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003728 })
3729 testCases = append(testCases, testCase{
3730 protocol: protocol,
3731 testType: serverTest,
3732 name: "MinimumVersion-Server2-" + suffix,
3733 config: Config{
3734 MaxVersion: runnerVers.version,
3735 },
David Benjamin87909c02014-12-13 01:55:01 -05003736 flags: []string{"-min-version", shimVersFlag},
3737 expectedVersion: expectedVersion,
3738 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003739 expectedError: expectedServerError,
3740 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003741 })
3742 }
3743 }
3744 }
3745}
3746
David Benjamine78bfde2014-09-06 12:45:15 -04003747func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003748 // TODO(davidben): Extensions, where applicable, all move their server
3749 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3750 // tests for both. Also test interaction with 0-RTT when implemented.
3751
David Benjamine78bfde2014-09-06 12:45:15 -04003752 testCases = append(testCases, testCase{
3753 testType: clientTest,
3754 name: "DuplicateExtensionClient",
3755 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003756 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003757 Bugs: ProtocolBugs{
3758 DuplicateExtension: true,
3759 },
3760 },
3761 shouldFail: true,
3762 expectedLocalError: "remote error: error decoding message",
3763 })
3764 testCases = append(testCases, testCase{
3765 testType: serverTest,
3766 name: "DuplicateExtensionServer",
3767 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003768 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003769 Bugs: ProtocolBugs{
3770 DuplicateExtension: true,
3771 },
3772 },
3773 shouldFail: true,
3774 expectedLocalError: "remote error: error decoding message",
3775 })
3776 testCases = append(testCases, testCase{
3777 testType: clientTest,
3778 name: "ServerNameExtensionClient",
3779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003780 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003781 Bugs: ProtocolBugs{
3782 ExpectServerName: "example.com",
3783 },
3784 },
3785 flags: []string{"-host-name", "example.com"},
3786 })
3787 testCases = append(testCases, testCase{
3788 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003789 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003790 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003791 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003792 Bugs: ProtocolBugs{
3793 ExpectServerName: "mismatch.com",
3794 },
3795 },
3796 flags: []string{"-host-name", "example.com"},
3797 shouldFail: true,
3798 expectedLocalError: "tls: unexpected server name",
3799 })
3800 testCases = append(testCases, testCase{
3801 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003802 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003803 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003804 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003805 Bugs: ProtocolBugs{
3806 ExpectServerName: "missing.com",
3807 },
3808 },
3809 shouldFail: true,
3810 expectedLocalError: "tls: unexpected server name",
3811 })
3812 testCases = append(testCases, testCase{
3813 testType: serverTest,
3814 name: "ServerNameExtensionServer",
3815 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003816 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003817 ServerName: "example.com",
3818 },
3819 flags: []string{"-expect-server-name", "example.com"},
3820 resumeSession: true,
3821 })
David Benjaminae2888f2014-09-06 12:58:58 -04003822 testCases = append(testCases, testCase{
3823 testType: clientTest,
3824 name: "ALPNClient",
3825 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003826 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003827 NextProtos: []string{"foo"},
3828 },
3829 flags: []string{
3830 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3831 "-expect-alpn", "foo",
3832 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003833 expectedNextProto: "foo",
3834 expectedNextProtoType: alpn,
3835 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003836 })
3837 testCases = append(testCases, testCase{
3838 testType: serverTest,
3839 name: "ALPNServer",
3840 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003841 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003842 NextProtos: []string{"foo", "bar", "baz"},
3843 },
3844 flags: []string{
3845 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3846 "-select-alpn", "foo",
3847 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003848 expectedNextProto: "foo",
3849 expectedNextProtoType: alpn,
3850 resumeSession: true,
3851 })
David Benjamin594e7d22016-03-17 17:49:56 -04003852 testCases = append(testCases, testCase{
3853 testType: serverTest,
3854 name: "ALPNServer-Decline",
3855 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003856 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003857 NextProtos: []string{"foo", "bar", "baz"},
3858 },
3859 flags: []string{"-decline-alpn"},
3860 expectNoNextProto: true,
3861 resumeSession: true,
3862 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003863 // Test that the server prefers ALPN over NPN.
3864 testCases = append(testCases, testCase{
3865 testType: serverTest,
3866 name: "ALPNServer-Preferred",
3867 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003868 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003869 NextProtos: []string{"foo", "bar", "baz"},
3870 },
3871 flags: []string{
3872 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3873 "-select-alpn", "foo",
3874 "-advertise-npn", "\x03foo\x03bar\x03baz",
3875 },
3876 expectedNextProto: "foo",
3877 expectedNextProtoType: alpn,
3878 resumeSession: true,
3879 })
3880 testCases = append(testCases, testCase{
3881 testType: serverTest,
3882 name: "ALPNServer-Preferred-Swapped",
3883 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003884 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003885 NextProtos: []string{"foo", "bar", "baz"},
3886 Bugs: ProtocolBugs{
3887 SwapNPNAndALPN: true,
3888 },
3889 },
3890 flags: []string{
3891 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3892 "-select-alpn", "foo",
3893 "-advertise-npn", "\x03foo\x03bar\x03baz",
3894 },
3895 expectedNextProto: "foo",
3896 expectedNextProtoType: alpn,
3897 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003898 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003899 var emptyString string
3900 testCases = append(testCases, testCase{
3901 testType: clientTest,
3902 name: "ALPNClient-EmptyProtocolName",
3903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003904 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003905 NextProtos: []string{""},
3906 Bugs: ProtocolBugs{
3907 // A server returning an empty ALPN protocol
3908 // should be rejected.
3909 ALPNProtocol: &emptyString,
3910 },
3911 },
3912 flags: []string{
3913 "-advertise-alpn", "\x03foo",
3914 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003915 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003916 expectedError: ":PARSE_TLSEXT:",
3917 })
3918 testCases = append(testCases, testCase{
3919 testType: serverTest,
3920 name: "ALPNServer-EmptyProtocolName",
3921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003922 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003923 // A ClientHello containing an empty ALPN protocol
3924 // should be rejected.
3925 NextProtos: []string{"foo", "", "baz"},
3926 },
3927 flags: []string{
3928 "-select-alpn", "foo",
3929 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003930 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003931 expectedError: ":PARSE_TLSEXT:",
3932 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003933 // Test that negotiating both NPN and ALPN is forbidden.
3934 testCases = append(testCases, testCase{
3935 name: "NegotiateALPNAndNPN",
3936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003937 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003938 NextProtos: []string{"foo", "bar", "baz"},
3939 Bugs: ProtocolBugs{
3940 NegotiateALPNAndNPN: true,
3941 },
3942 },
3943 flags: []string{
3944 "-advertise-alpn", "\x03foo",
3945 "-select-next-proto", "foo",
3946 },
3947 shouldFail: true,
3948 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3949 })
3950 testCases = append(testCases, testCase{
3951 name: "NegotiateALPNAndNPN-Swapped",
3952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003953 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003954 NextProtos: []string{"foo", "bar", "baz"},
3955 Bugs: ProtocolBugs{
3956 NegotiateALPNAndNPN: true,
3957 SwapNPNAndALPN: true,
3958 },
3959 },
3960 flags: []string{
3961 "-advertise-alpn", "\x03foo",
3962 "-select-next-proto", "foo",
3963 },
3964 shouldFail: true,
3965 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3966 })
David Benjamin091c4b92015-10-26 13:33:21 -04003967 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3968 testCases = append(testCases, testCase{
3969 name: "DisableNPN",
3970 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003971 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04003972 NextProtos: []string{"foo"},
3973 },
3974 flags: []string{
3975 "-select-next-proto", "foo",
3976 "-disable-npn",
3977 },
3978 expectNoNextProto: true,
3979 })
Adam Langley38311732014-10-16 19:04:35 -07003980 // Resume with a corrupt ticket.
3981 testCases = append(testCases, testCase{
3982 testType: serverTest,
3983 name: "CorruptTicket",
3984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003985 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003986 Bugs: ProtocolBugs{
3987 CorruptTicket: true,
3988 },
3989 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003990 resumeSession: true,
3991 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003992 })
David Benjamind98452d2015-06-16 14:16:23 -04003993 // Test the ticket callback, with and without renewal.
3994 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003995 testType: serverTest,
3996 name: "TicketCallback",
3997 config: Config{
3998 MaxVersion: VersionTLS12,
3999 },
David Benjamind98452d2015-06-16 14:16:23 -04004000 resumeSession: true,
4001 flags: []string{"-use-ticket-callback"},
4002 })
4003 testCases = append(testCases, testCase{
4004 testType: serverTest,
4005 name: "TicketCallback-Renew",
4006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004007 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004008 Bugs: ProtocolBugs{
4009 ExpectNewTicket: true,
4010 },
4011 },
4012 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4013 resumeSession: true,
4014 })
Adam Langley38311732014-10-16 19:04:35 -07004015 // Resume with an oversized session id.
4016 testCases = append(testCases, testCase{
4017 testType: serverTest,
4018 name: "OversizedSessionId",
4019 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004020 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004021 Bugs: ProtocolBugs{
4022 OversizedSessionId: true,
4023 },
4024 },
4025 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004026 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004027 expectedError: ":DECODE_ERROR:",
4028 })
David Benjaminca6c8262014-11-15 19:06:08 -05004029 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4030 // are ignored.
4031 testCases = append(testCases, testCase{
4032 protocol: dtls,
4033 name: "SRTP-Client",
4034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004035 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004036 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4037 },
4038 flags: []string{
4039 "-srtp-profiles",
4040 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4041 },
4042 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4043 })
4044 testCases = append(testCases, testCase{
4045 protocol: dtls,
4046 testType: serverTest,
4047 name: "SRTP-Server",
4048 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004049 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004050 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4051 },
4052 flags: []string{
4053 "-srtp-profiles",
4054 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4055 },
4056 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4057 })
4058 // Test that the MKI is ignored.
4059 testCases = append(testCases, testCase{
4060 protocol: dtls,
4061 testType: serverTest,
4062 name: "SRTP-Server-IgnoreMKI",
4063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004064 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004065 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4066 Bugs: ProtocolBugs{
4067 SRTPMasterKeyIdentifer: "bogus",
4068 },
4069 },
4070 flags: []string{
4071 "-srtp-profiles",
4072 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4073 },
4074 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4075 })
4076 // Test that SRTP isn't negotiated on the server if there were
4077 // no matching profiles.
4078 testCases = append(testCases, testCase{
4079 protocol: dtls,
4080 testType: serverTest,
4081 name: "SRTP-Server-NoMatch",
4082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004083 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004084 SRTPProtectionProfiles: []uint16{100, 101, 102},
4085 },
4086 flags: []string{
4087 "-srtp-profiles",
4088 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4089 },
4090 expectedSRTPProtectionProfile: 0,
4091 })
4092 // Test that the server returning an invalid SRTP profile is
4093 // flagged as an error by the client.
4094 testCases = append(testCases, testCase{
4095 protocol: dtls,
4096 name: "SRTP-Client-NoMatch",
4097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004098 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004099 Bugs: ProtocolBugs{
4100 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4101 },
4102 },
4103 flags: []string{
4104 "-srtp-profiles",
4105 "SRTP_AES128_CM_SHA1_80",
4106 },
4107 shouldFail: true,
4108 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4109 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004110 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004111 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004112 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004113 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004114 config: Config{
4115 MaxVersion: VersionTLS12,
4116 },
David Benjamin61f95272014-11-25 01:55:35 -05004117 flags: []string{
4118 "-enable-signed-cert-timestamps",
4119 "-expect-signed-cert-timestamps",
4120 base64.StdEncoding.EncodeToString(testSCTList),
4121 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004122 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004123 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004124 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004125 name: "SendSCTListOnResume",
4126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004127 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004128 Bugs: ProtocolBugs{
4129 SendSCTListOnResume: []byte("bogus"),
4130 },
4131 },
4132 flags: []string{
4133 "-enable-signed-cert-timestamps",
4134 "-expect-signed-cert-timestamps",
4135 base64.StdEncoding.EncodeToString(testSCTList),
4136 },
4137 resumeSession: true,
4138 })
4139 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004140 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004141 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004142 config: Config{
4143 MaxVersion: VersionTLS12,
4144 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004145 flags: []string{
4146 "-signed-cert-timestamps",
4147 base64.StdEncoding.EncodeToString(testSCTList),
4148 },
4149 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004150 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004151 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004152
Paul Lietar4fac72e2015-09-09 13:44:55 +01004153 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004154 testType: clientTest,
4155 name: "ClientHelloPadding",
4156 config: Config{
4157 Bugs: ProtocolBugs{
4158 RequireClientHelloSize: 512,
4159 },
4160 },
4161 // This hostname just needs to be long enough to push the
4162 // ClientHello into F5's danger zone between 256 and 511 bytes
4163 // long.
4164 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4165 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004166
4167 // Extensions should not function in SSL 3.0.
4168 testCases = append(testCases, testCase{
4169 testType: serverTest,
4170 name: "SSLv3Extensions-NoALPN",
4171 config: Config{
4172 MaxVersion: VersionSSL30,
4173 NextProtos: []string{"foo", "bar", "baz"},
4174 },
4175 flags: []string{
4176 "-select-alpn", "foo",
4177 },
4178 expectNoNextProto: true,
4179 })
4180
4181 // Test session tickets separately as they follow a different codepath.
4182 testCases = append(testCases, testCase{
4183 testType: serverTest,
4184 name: "SSLv3Extensions-NoTickets",
4185 config: Config{
4186 MaxVersion: VersionSSL30,
4187 Bugs: ProtocolBugs{
4188 // Historically, session tickets in SSL 3.0
4189 // failed in different ways depending on whether
4190 // the client supported renegotiation_info.
4191 NoRenegotiationInfo: true,
4192 },
4193 },
4194 resumeSession: true,
4195 })
4196 testCases = append(testCases, testCase{
4197 testType: serverTest,
4198 name: "SSLv3Extensions-NoTickets2",
4199 config: Config{
4200 MaxVersion: VersionSSL30,
4201 },
4202 resumeSession: true,
4203 })
4204
4205 // But SSL 3.0 does send and process renegotiation_info.
4206 testCases = append(testCases, testCase{
4207 testType: serverTest,
4208 name: "SSLv3Extensions-RenegotiationInfo",
4209 config: Config{
4210 MaxVersion: VersionSSL30,
4211 Bugs: ProtocolBugs{
4212 RequireRenegotiationInfo: true,
4213 },
4214 },
4215 })
4216 testCases = append(testCases, testCase{
4217 testType: serverTest,
4218 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4219 config: Config{
4220 MaxVersion: VersionSSL30,
4221 Bugs: ProtocolBugs{
4222 NoRenegotiationInfo: true,
4223 SendRenegotiationSCSV: true,
4224 RequireRenegotiationInfo: true,
4225 },
4226 },
4227 })
David Benjamine78bfde2014-09-06 12:45:15 -04004228}
4229
David Benjamin01fe8202014-09-24 15:21:44 -04004230func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004231 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004232 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4233 if sessionVers.version >= VersionTLS13 {
4234 continue
4235 }
David Benjamin01fe8202014-09-24 15:21:44 -04004236 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004237 if resumeVers.version >= VersionTLS13 {
4238 continue
4239 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004240 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4241 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4242 // TLS 1.3 only shares ciphers with TLS 1.2, so
4243 // we skip certain combinations and use a
4244 // different cipher to test with.
4245 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4246 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4247 continue
4248 }
4249 }
4250
David Benjamin8b8c0062014-11-23 02:47:52 -05004251 protocols := []protocol{tls}
4252 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4253 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004254 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004255 for _, protocol := range protocols {
4256 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4257 if protocol == dtls {
4258 suffix += "-DTLS"
4259 }
4260
David Benjaminece3de92015-03-16 18:02:20 -04004261 if sessionVers.version == resumeVers.version {
4262 testCases = append(testCases, testCase{
4263 protocol: protocol,
4264 name: "Resume-Client" + suffix,
4265 resumeSession: true,
4266 config: Config{
4267 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004268 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004269 },
David Benjaminece3de92015-03-16 18:02:20 -04004270 expectedVersion: sessionVers.version,
4271 expectedResumeVersion: resumeVers.version,
4272 })
4273 } else {
4274 testCases = append(testCases, testCase{
4275 protocol: protocol,
4276 name: "Resume-Client-Mismatch" + suffix,
4277 resumeSession: true,
4278 config: Config{
4279 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004280 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004281 },
David Benjaminece3de92015-03-16 18:02:20 -04004282 expectedVersion: sessionVers.version,
4283 resumeConfig: &Config{
4284 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004285 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004286 Bugs: ProtocolBugs{
4287 AllowSessionVersionMismatch: true,
4288 },
4289 },
4290 expectedResumeVersion: resumeVers.version,
4291 shouldFail: true,
4292 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4293 })
4294 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004295
4296 testCases = append(testCases, testCase{
4297 protocol: protocol,
4298 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004299 resumeSession: true,
4300 config: Config{
4301 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004302 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004303 },
4304 expectedVersion: sessionVers.version,
4305 resumeConfig: &Config{
4306 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004307 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004308 },
4309 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004310 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004311 expectedResumeVersion: resumeVers.version,
4312 })
4313
David Benjamin8b8c0062014-11-23 02:47:52 -05004314 testCases = append(testCases, testCase{
4315 protocol: protocol,
4316 testType: serverTest,
4317 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004318 resumeSession: true,
4319 config: Config{
4320 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004321 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004322 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004323 expectedVersion: sessionVers.version,
4324 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004325 resumeConfig: &Config{
4326 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004327 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004328 },
4329 expectedResumeVersion: resumeVers.version,
4330 })
4331 }
David Benjamin01fe8202014-09-24 15:21:44 -04004332 }
4333 }
David Benjaminece3de92015-03-16 18:02:20 -04004334
Nick Harper1fd39d82016-06-14 18:14:35 -07004335 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004336 testCases = append(testCases, testCase{
4337 name: "Resume-Client-CipherMismatch",
4338 resumeSession: true,
4339 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004340 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004341 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4342 },
4343 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004344 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004345 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4346 Bugs: ProtocolBugs{
4347 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4348 },
4349 },
4350 shouldFail: true,
4351 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4352 })
David Benjamin01fe8202014-09-24 15:21:44 -04004353}
4354
Adam Langley2ae77d22014-10-28 17:29:33 -07004355func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004356 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004357 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004358 testType: serverTest,
4359 name: "Renegotiate-Server-Forbidden",
4360 config: Config{
4361 MaxVersion: VersionTLS12,
4362 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004363 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004364 shouldFail: true,
4365 expectedError: ":NO_RENEGOTIATION:",
4366 expectedLocalError: "remote error: no renegotiation",
4367 })
Adam Langley5021b222015-06-12 18:27:58 -07004368 // The server shouldn't echo the renegotiation extension unless
4369 // requested by the client.
4370 testCases = append(testCases, testCase{
4371 testType: serverTest,
4372 name: "Renegotiate-Server-NoExt",
4373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004374 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004375 Bugs: ProtocolBugs{
4376 NoRenegotiationInfo: true,
4377 RequireRenegotiationInfo: true,
4378 },
4379 },
4380 shouldFail: true,
4381 expectedLocalError: "renegotiation extension missing",
4382 })
4383 // The renegotiation SCSV should be sufficient for the server to echo
4384 // the extension.
4385 testCases = append(testCases, testCase{
4386 testType: serverTest,
4387 name: "Renegotiate-Server-NoExt-SCSV",
4388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004389 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004390 Bugs: ProtocolBugs{
4391 NoRenegotiationInfo: true,
4392 SendRenegotiationSCSV: true,
4393 RequireRenegotiationInfo: true,
4394 },
4395 },
4396 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004397 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004398 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004399 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004400 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004401 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004402 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004403 },
4404 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004405 renegotiate: 1,
4406 flags: []string{
4407 "-renegotiate-freely",
4408 "-expect-total-renegotiations", "1",
4409 },
David Benjamincdea40c2015-03-19 14:09:43 -04004410 })
4411 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004412 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004413 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004415 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004416 Bugs: ProtocolBugs{
4417 EmptyRenegotiationInfo: true,
4418 },
4419 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004420 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004421 shouldFail: true,
4422 expectedError: ":RENEGOTIATION_MISMATCH:",
4423 })
4424 testCases = append(testCases, testCase{
4425 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004426 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004428 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004429 Bugs: ProtocolBugs{
4430 BadRenegotiationInfo: true,
4431 },
4432 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004433 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004434 shouldFail: true,
4435 expectedError: ":RENEGOTIATION_MISMATCH:",
4436 })
4437 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004438 name: "Renegotiate-Client-Downgrade",
4439 renegotiate: 1,
4440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004441 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004442 Bugs: ProtocolBugs{
4443 NoRenegotiationInfoAfterInitial: true,
4444 },
4445 },
4446 flags: []string{"-renegotiate-freely"},
4447 shouldFail: true,
4448 expectedError: ":RENEGOTIATION_MISMATCH:",
4449 })
4450 testCases = append(testCases, testCase{
4451 name: "Renegotiate-Client-Upgrade",
4452 renegotiate: 1,
4453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004454 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004455 Bugs: ProtocolBugs{
4456 NoRenegotiationInfoInInitial: true,
4457 },
4458 },
4459 flags: []string{"-renegotiate-freely"},
4460 shouldFail: true,
4461 expectedError: ":RENEGOTIATION_MISMATCH:",
4462 })
4463 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004464 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004465 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004467 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004468 Bugs: ProtocolBugs{
4469 NoRenegotiationInfo: true,
4470 },
4471 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004472 flags: []string{
4473 "-renegotiate-freely",
4474 "-expect-total-renegotiations", "1",
4475 },
David Benjamincff0b902015-05-15 23:09:47 -04004476 })
4477 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004478 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004479 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004480 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004481 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004482 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4483 },
4484 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004485 flags: []string{
4486 "-renegotiate-freely",
4487 "-expect-total-renegotiations", "1",
4488 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004489 })
4490 testCases = append(testCases, testCase{
4491 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004492 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004493 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004494 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004495 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4496 },
4497 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004498 flags: []string{
4499 "-renegotiate-freely",
4500 "-expect-total-renegotiations", "1",
4501 },
David Benjaminb16346b2015-04-08 19:16:58 -04004502 })
4503 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004504 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004505 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004506 config: Config{
4507 MaxVersion: VersionTLS10,
4508 Bugs: ProtocolBugs{
4509 RequireSameRenegoClientVersion: true,
4510 },
4511 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004512 flags: []string{
4513 "-renegotiate-freely",
4514 "-expect-total-renegotiations", "1",
4515 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004516 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004517 testCases = append(testCases, testCase{
4518 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004519 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004520 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004521 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004522 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4523 NextProtos: []string{"foo"},
4524 },
4525 flags: []string{
4526 "-false-start",
4527 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004528 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004529 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004530 },
4531 shimWritesFirst: true,
4532 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004533
4534 // Client-side renegotiation controls.
4535 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004536 name: "Renegotiate-Client-Forbidden-1",
4537 config: Config{
4538 MaxVersion: VersionTLS12,
4539 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004540 renegotiate: 1,
4541 shouldFail: true,
4542 expectedError: ":NO_RENEGOTIATION:",
4543 expectedLocalError: "remote error: no renegotiation",
4544 })
4545 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004546 name: "Renegotiate-Client-Once-1",
4547 config: Config{
4548 MaxVersion: VersionTLS12,
4549 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004550 renegotiate: 1,
4551 flags: []string{
4552 "-renegotiate-once",
4553 "-expect-total-renegotiations", "1",
4554 },
4555 })
4556 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004557 name: "Renegotiate-Client-Freely-1",
4558 config: Config{
4559 MaxVersion: VersionTLS12,
4560 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004561 renegotiate: 1,
4562 flags: []string{
4563 "-renegotiate-freely",
4564 "-expect-total-renegotiations", "1",
4565 },
4566 })
4567 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004568 name: "Renegotiate-Client-Once-2",
4569 config: Config{
4570 MaxVersion: VersionTLS12,
4571 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004572 renegotiate: 2,
4573 flags: []string{"-renegotiate-once"},
4574 shouldFail: true,
4575 expectedError: ":NO_RENEGOTIATION:",
4576 expectedLocalError: "remote error: no renegotiation",
4577 })
4578 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004579 name: "Renegotiate-Client-Freely-2",
4580 config: Config{
4581 MaxVersion: VersionTLS12,
4582 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004583 renegotiate: 2,
4584 flags: []string{
4585 "-renegotiate-freely",
4586 "-expect-total-renegotiations", "2",
4587 },
4588 })
Adam Langley27a0d082015-11-03 13:34:10 -08004589 testCases = append(testCases, testCase{
4590 name: "Renegotiate-Client-NoIgnore",
4591 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004592 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004593 Bugs: ProtocolBugs{
4594 SendHelloRequestBeforeEveryAppDataRecord: true,
4595 },
4596 },
4597 shouldFail: true,
4598 expectedError: ":NO_RENEGOTIATION:",
4599 })
4600 testCases = append(testCases, testCase{
4601 name: "Renegotiate-Client-Ignore",
4602 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004603 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004604 Bugs: ProtocolBugs{
4605 SendHelloRequestBeforeEveryAppDataRecord: true,
4606 },
4607 },
4608 flags: []string{
4609 "-renegotiate-ignore",
4610 "-expect-total-renegotiations", "0",
4611 },
4612 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004613
David Benjamin397c8e62016-07-08 14:14:36 -07004614 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004615 testCases = append(testCases, testCase{
4616 name: "StrayHelloRequest",
4617 config: Config{
4618 MaxVersion: VersionTLS12,
4619 Bugs: ProtocolBugs{
4620 SendHelloRequestBeforeEveryHandshakeMessage: true,
4621 },
4622 },
4623 })
4624 testCases = append(testCases, testCase{
4625 name: "StrayHelloRequest-Packed",
4626 config: Config{
4627 MaxVersion: VersionTLS12,
4628 Bugs: ProtocolBugs{
4629 PackHandshakeFlight: true,
4630 SendHelloRequestBeforeEveryHandshakeMessage: true,
4631 },
4632 },
4633 })
4634
David Benjamin397c8e62016-07-08 14:14:36 -07004635 // Renegotiation is forbidden in TLS 1.3.
4636 testCases = append(testCases, testCase{
4637 name: "Renegotiate-Client-TLS13",
4638 config: Config{
4639 MaxVersion: VersionTLS13,
4640 },
4641 renegotiate: 1,
4642 flags: []string{
4643 "-renegotiate-freely",
4644 },
4645 shouldFail: true,
4646 expectedError: ":NO_RENEGOTIATION:",
4647 })
4648
4649 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4650 testCases = append(testCases, testCase{
4651 name: "StrayHelloRequest-TLS13",
4652 config: Config{
4653 MaxVersion: VersionTLS13,
4654 Bugs: ProtocolBugs{
4655 SendHelloRequestBeforeEveryHandshakeMessage: true,
4656 },
4657 },
4658 shouldFail: true,
4659 expectedError: ":UNEXPECTED_MESSAGE:",
4660 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004661}
4662
David Benjamin5e961c12014-11-07 01:48:35 -05004663func addDTLSReplayTests() {
4664 // Test that sequence number replays are detected.
4665 testCases = append(testCases, testCase{
4666 protocol: dtls,
4667 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004668 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004669 replayWrites: true,
4670 })
4671
David Benjamin8e6db492015-07-25 18:29:23 -04004672 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004673 // than the retransmit window.
4674 testCases = append(testCases, testCase{
4675 protocol: dtls,
4676 name: "DTLS-Replay-LargeGaps",
4677 config: Config{
4678 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004679 SequenceNumberMapping: func(in uint64) uint64 {
4680 return in * 127
4681 },
David Benjamin5e961c12014-11-07 01:48:35 -05004682 },
4683 },
David Benjamin8e6db492015-07-25 18:29:23 -04004684 messageCount: 200,
4685 replayWrites: true,
4686 })
4687
4688 // Test the incoming sequence number changing non-monotonically.
4689 testCases = append(testCases, testCase{
4690 protocol: dtls,
4691 name: "DTLS-Replay-NonMonotonic",
4692 config: Config{
4693 Bugs: ProtocolBugs{
4694 SequenceNumberMapping: func(in uint64) uint64 {
4695 return in ^ 31
4696 },
4697 },
4698 },
4699 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004700 replayWrites: true,
4701 })
4702}
4703
Nick Harper60edffd2016-06-21 15:19:24 -07004704var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004705 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004706 id signatureAlgorithm
4707 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004708}{
Nick Harper60edffd2016-06-21 15:19:24 -07004709 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4710 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4711 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4712 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004713 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07004714 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4715 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4716 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004717 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
4718 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
4719 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04004720 // Tests for key types prior to TLS 1.2.
4721 {"RSA", 0, testCertRSA},
4722 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05004723}
4724
Nick Harper60edffd2016-06-21 15:19:24 -07004725const fakeSigAlg1 signatureAlgorithm = 0x2a01
4726const fakeSigAlg2 signatureAlgorithm = 0xff01
4727
4728func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04004729 // Not all ciphers involve a signature. Advertise a list which gives all
4730 // versions a signing cipher.
4731 signingCiphers := []uint16{
4732 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4733 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4734 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
4735 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
4736 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
4737 }
4738
Nick Harper60edffd2016-06-21 15:19:24 -07004739 // Make sure each signature algorithm works. Include some fake values in
4740 // the list and ensure they're ignored.
4741 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07004742 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04004743 if (ver.version < VersionTLS12) != (alg.id == 0) {
4744 continue
4745 }
4746
4747 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
4748 // or remove it in C.
4749 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07004750 continue
4751 }
Nick Harper60edffd2016-06-21 15:19:24 -07004752
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004753 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07004754 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004755 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
4756 shouldFail = true
4757 }
4758 // RSA-PSS does not exist in TLS 1.2.
4759 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
4760 shouldFail = true
4761 }
4762
4763 var signError, verifyError string
4764 if shouldFail {
4765 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
4766 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07004767 }
David Benjamin000800a2014-11-14 01:43:59 -05004768
David Benjamin1fb125c2016-07-08 18:52:12 -07004769 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05004770
David Benjamin7a41d372016-07-09 11:21:54 -07004771 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004772 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07004773 config: Config{
4774 MaxVersion: ver.version,
4775 ClientAuth: RequireAnyClientCert,
4776 VerifySignatureAlgorithms: []signatureAlgorithm{
4777 fakeSigAlg1,
4778 alg.id,
4779 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07004780 },
David Benjamin7a41d372016-07-09 11:21:54 -07004781 },
4782 flags: []string{
4783 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4784 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4785 "-enable-all-curves",
4786 },
4787 shouldFail: shouldFail,
4788 expectedError: signError,
4789 expectedPeerSignatureAlgorithm: alg.id,
4790 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004791
David Benjamin7a41d372016-07-09 11:21:54 -07004792 testCases = append(testCases, testCase{
4793 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04004794 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07004795 config: Config{
4796 MaxVersion: ver.version,
4797 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4798 SignSignatureAlgorithms: []signatureAlgorithm{
4799 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004800 },
David Benjamin7a41d372016-07-09 11:21:54 -07004801 Bugs: ProtocolBugs{
4802 SkipECDSACurveCheck: shouldFail,
4803 IgnoreSignatureVersionChecks: shouldFail,
4804 // The client won't advertise 1.3-only algorithms after
4805 // version negotiation.
4806 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004807 },
David Benjamin7a41d372016-07-09 11:21:54 -07004808 },
4809 flags: []string{
4810 "-require-any-client-certificate",
4811 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4812 "-enable-all-curves",
4813 },
4814 shouldFail: shouldFail,
4815 expectedError: verifyError,
4816 })
David Benjamin1fb125c2016-07-08 18:52:12 -07004817
4818 testCases = append(testCases, testCase{
4819 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04004820 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07004821 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04004822 MaxVersion: ver.version,
4823 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07004824 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004825 fakeSigAlg1,
4826 alg.id,
4827 fakeSigAlg2,
4828 },
4829 },
4830 flags: []string{
4831 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4832 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4833 "-enable-all-curves",
4834 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004835 shouldFail: shouldFail,
4836 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004837 expectedPeerSignatureAlgorithm: alg.id,
4838 })
4839
4840 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004841 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07004842 config: Config{
4843 MaxVersion: ver.version,
4844 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04004845 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07004846 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004847 alg.id,
4848 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004849 Bugs: ProtocolBugs{
4850 SkipECDSACurveCheck: shouldFail,
4851 IgnoreSignatureVersionChecks: shouldFail,
4852 },
David Benjamin1fb125c2016-07-08 18:52:12 -07004853 },
4854 flags: []string{
4855 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4856 "-enable-all-curves",
4857 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004858 shouldFail: shouldFail,
4859 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004860 })
David Benjamin5208fd42016-07-13 21:43:25 -04004861
4862 if !shouldFail {
4863 testCases = append(testCases, testCase{
4864 testType: serverTest,
4865 name: "ClientAuth-InvalidSignature" + suffix,
4866 config: Config{
4867 MaxVersion: ver.version,
4868 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4869 SignSignatureAlgorithms: []signatureAlgorithm{
4870 alg.id,
4871 },
4872 Bugs: ProtocolBugs{
4873 InvalidSignature: true,
4874 },
4875 },
4876 flags: []string{
4877 "-require-any-client-certificate",
4878 "-enable-all-curves",
4879 },
4880 shouldFail: true,
4881 expectedError: ":BAD_SIGNATURE:",
4882 })
4883
4884 testCases = append(testCases, testCase{
4885 name: "ServerAuth-InvalidSignature" + suffix,
4886 config: Config{
4887 MaxVersion: ver.version,
4888 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4889 CipherSuites: signingCiphers,
4890 SignSignatureAlgorithms: []signatureAlgorithm{
4891 alg.id,
4892 },
4893 Bugs: ProtocolBugs{
4894 InvalidSignature: true,
4895 },
4896 },
4897 flags: []string{"-enable-all-curves"},
4898 shouldFail: true,
4899 expectedError: ":BAD_SIGNATURE:",
4900 })
4901 }
David Benjamin1fb125c2016-07-08 18:52:12 -07004902 }
David Benjamin000800a2014-11-14 01:43:59 -05004903 }
4904
Nick Harper60edffd2016-06-21 15:19:24 -07004905 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004906 //
4907 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004908 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004909 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05004910 config: Config{
4911 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004912 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07004913 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004914 signatureECDSAWithP521AndSHA512,
4915 signatureRSAPKCS1WithSHA384,
4916 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004917 },
4918 },
4919 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004920 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4921 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004922 },
Nick Harper60edffd2016-06-21 15:19:24 -07004923 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004924 })
4925
4926 testCases = append(testCases, testCase{
4927 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04004928 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05004929 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004930 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004932 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004933 signatureECDSAWithP521AndSHA512,
4934 signatureRSAPKCS1WithSHA384,
4935 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004936 },
4937 },
Nick Harper60edffd2016-06-21 15:19:24 -07004938 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004939 })
4940
David Benjamina95e9f32016-07-08 16:28:04 -07004941 // Test that signature verification takes the key type into account.
4942 //
4943 // TODO(davidben): Test this in TLS 1.3.
4944 testCases = append(testCases, testCase{
4945 testType: serverTest,
4946 name: "Verify-ClientAuth-SignatureType",
4947 config: Config{
4948 MaxVersion: VersionTLS12,
4949 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004950 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004951 signatureRSAPKCS1WithSHA256,
4952 },
4953 Bugs: ProtocolBugs{
4954 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4955 },
4956 },
4957 flags: []string{
4958 "-require-any-client-certificate",
4959 },
4960 shouldFail: true,
4961 expectedError: ":WRONG_SIGNATURE_TYPE:",
4962 })
4963
4964 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004965 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07004966 config: Config{
4967 MaxVersion: VersionTLS12,
4968 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004969 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004970 signatureRSAPKCS1WithSHA256,
4971 },
4972 Bugs: ProtocolBugs{
4973 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4974 },
4975 },
4976 shouldFail: true,
4977 expectedError: ":WRONG_SIGNATURE_TYPE:",
4978 })
4979
David Benjamin51dd7d62016-07-08 16:07:01 -07004980 // Test that, if the list is missing, the peer falls back to SHA-1 in
4981 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004982 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04004983 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05004984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004985 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004986 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004987 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004988 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004989 },
4990 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004991 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004992 },
4993 },
4994 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004995 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4996 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004997 },
4998 })
4999
5000 testCases = append(testCases, testCase{
5001 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005002 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005003 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005004 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005005 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005006 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005007 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005008 },
5009 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005010 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005011 },
5012 },
5013 })
David Benjamin72dc7832015-03-16 17:49:43 -04005014
David Benjamin51dd7d62016-07-08 16:07:01 -07005015 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005016 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005017 config: Config{
5018 MaxVersion: VersionTLS13,
5019 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005020 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005021 signatureRSAPKCS1WithSHA1,
5022 },
5023 Bugs: ProtocolBugs{
5024 NoSignatureAlgorithms: true,
5025 },
5026 },
5027 flags: []string{
5028 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5029 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5030 },
5031 shouldFail: true,
5032 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5033 })
5034
5035 testCases = append(testCases, testCase{
5036 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005037 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005038 config: Config{
5039 MaxVersion: VersionTLS13,
5040 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005041 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005042 signatureRSAPKCS1WithSHA1,
5043 },
5044 Bugs: ProtocolBugs{
5045 NoSignatureAlgorithms: true,
5046 },
5047 },
5048 shouldFail: true,
5049 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5050 })
5051
David Benjamin72dc7832015-03-16 17:49:43 -04005052 // Test that hash preferences are enforced. BoringSSL defaults to
5053 // rejecting MD5 signatures.
5054 testCases = append(testCases, testCase{
5055 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005056 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005058 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005059 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005060 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005061 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005062 // Advertise SHA-1 so the handshake will
5063 // proceed, but the shim's preferences will be
5064 // ignored in CertificateVerify generation, so
5065 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005066 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005067 },
5068 Bugs: ProtocolBugs{
5069 IgnorePeerSignatureAlgorithmPreferences: true,
5070 },
5071 },
5072 flags: []string{"-require-any-client-certificate"},
5073 shouldFail: true,
5074 expectedError: ":WRONG_SIGNATURE_TYPE:",
5075 })
5076
5077 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005078 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005079 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005080 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005081 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005082 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005083 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005084 },
5085 Bugs: ProtocolBugs{
5086 IgnorePeerSignatureAlgorithmPreferences: true,
5087 },
5088 },
5089 shouldFail: true,
5090 expectedError: ":WRONG_SIGNATURE_TYPE:",
5091 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005092
5093 // Test that the agreed upon digest respects the client preferences and
5094 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005095 //
5096 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04005097 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005098 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005100 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005101 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005102 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005103 signatureRSAPKCS1WithSHA512,
5104 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005105 },
5106 },
5107 flags: []string{
5108 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5109 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5110 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005111 digestPrefs: "SHA256",
5112 shouldFail: true,
5113 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005114 })
5115 testCases = append(testCases, testCase{
5116 name: "Agree-Digest-SHA256",
5117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005118 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005119 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005120 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005121 signatureRSAPKCS1WithSHA1,
5122 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005123 },
5124 },
5125 flags: []string{
5126 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5127 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5128 },
Nick Harper60edffd2016-06-21 15:19:24 -07005129 digestPrefs: "SHA256,SHA1",
5130 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005131 })
5132 testCases = append(testCases, testCase{
5133 name: "Agree-Digest-SHA1",
5134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005135 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005136 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005137 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005138 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005139 },
5140 },
5141 flags: []string{
5142 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5143 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5144 },
Nick Harper60edffd2016-06-21 15:19:24 -07005145 digestPrefs: "SHA512,SHA256,SHA1",
5146 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005147 })
5148 testCases = append(testCases, testCase{
5149 name: "Agree-Digest-Default",
5150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005151 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005152 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005153 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005154 signatureRSAPKCS1WithSHA256,
5155 signatureECDSAWithP256AndSHA256,
5156 signatureRSAPKCS1WithSHA1,
5157 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005158 },
5159 },
5160 flags: []string{
5161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5163 },
Nick Harper60edffd2016-06-21 15:19:24 -07005164 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005165 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005166
5167 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5168 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005169 testCases = append(testCases, testCase{
5170 name: "CheckLeafCurve",
5171 config: Config{
5172 MaxVersion: VersionTLS12,
5173 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005174 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005175 },
5176 flags: []string{"-p384-only"},
5177 shouldFail: true,
5178 expectedError: ":BAD_ECC_CERT:",
5179 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005180
5181 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5182 testCases = append(testCases, testCase{
5183 name: "CheckLeafCurve-TLS13",
5184 config: Config{
5185 MaxVersion: VersionTLS13,
5186 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5187 Certificates: []Certificate{ecdsaP256Certificate},
5188 },
5189 flags: []string{"-p384-only"},
5190 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005191
5192 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5193 testCases = append(testCases, testCase{
5194 name: "ECDSACurveMismatch-Verify-TLS12",
5195 config: Config{
5196 MaxVersion: VersionTLS12,
5197 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5198 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005199 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005200 signatureECDSAWithP384AndSHA384,
5201 },
5202 },
5203 })
5204
5205 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5206 testCases = append(testCases, testCase{
5207 name: "ECDSACurveMismatch-Verify-TLS13",
5208 config: Config{
5209 MaxVersion: VersionTLS13,
5210 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5211 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005212 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005213 signatureECDSAWithP384AndSHA384,
5214 },
5215 Bugs: ProtocolBugs{
5216 SkipECDSACurveCheck: true,
5217 },
5218 },
5219 shouldFail: true,
5220 expectedError: ":WRONG_SIGNATURE_TYPE:",
5221 })
5222
5223 // Signature algorithm selection in TLS 1.3 should take the curve into
5224 // account.
5225 testCases = append(testCases, testCase{
5226 testType: serverTest,
5227 name: "ECDSACurveMismatch-Sign-TLS13",
5228 config: Config{
5229 MaxVersion: VersionTLS13,
5230 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005231 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005232 signatureECDSAWithP384AndSHA384,
5233 signatureECDSAWithP256AndSHA256,
5234 },
5235 },
5236 flags: []string{
5237 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5238 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5239 },
5240 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5241 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005242
5243 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5244 // server does not attempt to sign in that case.
5245 testCases = append(testCases, testCase{
5246 testType: serverTest,
5247 name: "RSA-PSS-Large",
5248 config: Config{
5249 MaxVersion: VersionTLS13,
5250 VerifySignatureAlgorithms: []signatureAlgorithm{
5251 signatureRSAPSSWithSHA512,
5252 },
5253 },
5254 flags: []string{
5255 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5256 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5257 },
5258 shouldFail: true,
5259 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5260 })
David Benjamin000800a2014-11-14 01:43:59 -05005261}
5262
David Benjamin83f90402015-01-27 01:09:43 -05005263// timeouts is the retransmit schedule for BoringSSL. It doubles and
5264// caps at 60 seconds. On the 13th timeout, it gives up.
5265var timeouts = []time.Duration{
5266 1 * time.Second,
5267 2 * time.Second,
5268 4 * time.Second,
5269 8 * time.Second,
5270 16 * time.Second,
5271 32 * time.Second,
5272 60 * time.Second,
5273 60 * time.Second,
5274 60 * time.Second,
5275 60 * time.Second,
5276 60 * time.Second,
5277 60 * time.Second,
5278 60 * time.Second,
5279}
5280
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005281// shortTimeouts is an alternate set of timeouts which would occur if the
5282// initial timeout duration was set to 250ms.
5283var shortTimeouts = []time.Duration{
5284 250 * time.Millisecond,
5285 500 * time.Millisecond,
5286 1 * time.Second,
5287 2 * time.Second,
5288 4 * time.Second,
5289 8 * time.Second,
5290 16 * time.Second,
5291 32 * time.Second,
5292 60 * time.Second,
5293 60 * time.Second,
5294 60 * time.Second,
5295 60 * time.Second,
5296 60 * time.Second,
5297}
5298
David Benjamin83f90402015-01-27 01:09:43 -05005299func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005300 // These tests work by coordinating some behavior on both the shim and
5301 // the runner.
5302 //
5303 // TimeoutSchedule configures the runner to send a series of timeout
5304 // opcodes to the shim (see packetAdaptor) immediately before reading
5305 // each peer handshake flight N. The timeout opcode both simulates a
5306 // timeout in the shim and acts as a synchronization point to help the
5307 // runner bracket each handshake flight.
5308 //
5309 // We assume the shim does not read from the channel eagerly. It must
5310 // first wait until it has sent flight N and is ready to receive
5311 // handshake flight N+1. At this point, it will process the timeout
5312 // opcode. It must then immediately respond with a timeout ACK and act
5313 // as if the shim was idle for the specified amount of time.
5314 //
5315 // The runner then drops all packets received before the ACK and
5316 // continues waiting for flight N. This ordering results in one attempt
5317 // at sending flight N to be dropped. For the test to complete, the
5318 // shim must send flight N again, testing that the shim implements DTLS
5319 // retransmit on a timeout.
5320
David Benjamin4c3ddf72016-06-29 18:13:53 -04005321 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5322 // likely be more epochs to cross and the final message's retransmit may
5323 // be more complex.
5324
David Benjamin585d7a42016-06-02 14:58:00 -04005325 for _, async := range []bool{true, false} {
5326 var tests []testCase
5327
5328 // Test that this is indeed the timeout schedule. Stress all
5329 // four patterns of handshake.
5330 for i := 1; i < len(timeouts); i++ {
5331 number := strconv.Itoa(i)
5332 tests = append(tests, testCase{
5333 protocol: dtls,
5334 name: "DTLS-Retransmit-Client-" + number,
5335 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005336 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005337 Bugs: ProtocolBugs{
5338 TimeoutSchedule: timeouts[:i],
5339 },
5340 },
5341 resumeSession: true,
5342 })
5343 tests = append(tests, testCase{
5344 protocol: dtls,
5345 testType: serverTest,
5346 name: "DTLS-Retransmit-Server-" + number,
5347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005348 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005349 Bugs: ProtocolBugs{
5350 TimeoutSchedule: timeouts[:i],
5351 },
5352 },
5353 resumeSession: true,
5354 })
5355 }
5356
5357 // Test that exceeding the timeout schedule hits a read
5358 // timeout.
5359 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005360 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005361 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005363 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005364 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005365 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005366 },
5367 },
5368 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005369 shouldFail: true,
5370 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005371 })
David Benjamin585d7a42016-06-02 14:58:00 -04005372
5373 if async {
5374 // Test that timeout handling has a fudge factor, due to API
5375 // problems.
5376 tests = append(tests, testCase{
5377 protocol: dtls,
5378 name: "DTLS-Retransmit-Fudge",
5379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005380 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005381 Bugs: ProtocolBugs{
5382 TimeoutSchedule: []time.Duration{
5383 timeouts[0] - 10*time.Millisecond,
5384 },
5385 },
5386 },
5387 resumeSession: true,
5388 })
5389 }
5390
5391 // Test that the final Finished retransmitting isn't
5392 // duplicated if the peer badly fragments everything.
5393 tests = append(tests, testCase{
5394 testType: serverTest,
5395 protocol: dtls,
5396 name: "DTLS-Retransmit-Fragmented",
5397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005398 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005399 Bugs: ProtocolBugs{
5400 TimeoutSchedule: []time.Duration{timeouts[0]},
5401 MaxHandshakeRecordLength: 2,
5402 },
5403 },
5404 })
5405
5406 // Test the timeout schedule when a shorter initial timeout duration is set.
5407 tests = append(tests, testCase{
5408 protocol: dtls,
5409 name: "DTLS-Retransmit-Short-Client",
5410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005411 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005412 Bugs: ProtocolBugs{
5413 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5414 },
5415 },
5416 resumeSession: true,
5417 flags: []string{"-initial-timeout-duration-ms", "250"},
5418 })
5419 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005420 protocol: dtls,
5421 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005422 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005424 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005425 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005426 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005427 },
5428 },
5429 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005430 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005431 })
David Benjamin585d7a42016-06-02 14:58:00 -04005432
5433 for _, test := range tests {
5434 if async {
5435 test.name += "-Async"
5436 test.flags = append(test.flags, "-async")
5437 }
5438
5439 testCases = append(testCases, test)
5440 }
David Benjamin83f90402015-01-27 01:09:43 -05005441 }
David Benjamin83f90402015-01-27 01:09:43 -05005442}
5443
David Benjaminc565ebb2015-04-03 04:06:36 -04005444func addExportKeyingMaterialTests() {
5445 for _, vers := range tlsVersions {
5446 if vers.version == VersionSSL30 {
5447 continue
5448 }
5449 testCases = append(testCases, testCase{
5450 name: "ExportKeyingMaterial-" + vers.name,
5451 config: Config{
5452 MaxVersion: vers.version,
5453 },
5454 exportKeyingMaterial: 1024,
5455 exportLabel: "label",
5456 exportContext: "context",
5457 useExportContext: true,
5458 })
5459 testCases = append(testCases, testCase{
5460 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5461 config: Config{
5462 MaxVersion: vers.version,
5463 },
5464 exportKeyingMaterial: 1024,
5465 })
5466 testCases = append(testCases, testCase{
5467 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5468 config: Config{
5469 MaxVersion: vers.version,
5470 },
5471 exportKeyingMaterial: 1024,
5472 useExportContext: true,
5473 })
5474 testCases = append(testCases, testCase{
5475 name: "ExportKeyingMaterial-Small-" + vers.name,
5476 config: Config{
5477 MaxVersion: vers.version,
5478 },
5479 exportKeyingMaterial: 1,
5480 exportLabel: "label",
5481 exportContext: "context",
5482 useExportContext: true,
5483 })
5484 }
5485 testCases = append(testCases, testCase{
5486 name: "ExportKeyingMaterial-SSL3",
5487 config: Config{
5488 MaxVersion: VersionSSL30,
5489 },
5490 exportKeyingMaterial: 1024,
5491 exportLabel: "label",
5492 exportContext: "context",
5493 useExportContext: true,
5494 shouldFail: true,
5495 expectedError: "failed to export keying material",
5496 })
5497}
5498
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005499func addTLSUniqueTests() {
5500 for _, isClient := range []bool{false, true} {
5501 for _, isResumption := range []bool{false, true} {
5502 for _, hasEMS := range []bool{false, true} {
5503 var suffix string
5504 if isResumption {
5505 suffix = "Resume-"
5506 } else {
5507 suffix = "Full-"
5508 }
5509
5510 if hasEMS {
5511 suffix += "EMS-"
5512 } else {
5513 suffix += "NoEMS-"
5514 }
5515
5516 if isClient {
5517 suffix += "Client"
5518 } else {
5519 suffix += "Server"
5520 }
5521
5522 test := testCase{
5523 name: "TLSUnique-" + suffix,
5524 testTLSUnique: true,
5525 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005526 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005527 Bugs: ProtocolBugs{
5528 NoExtendedMasterSecret: !hasEMS,
5529 },
5530 },
5531 }
5532
5533 if isResumption {
5534 test.resumeSession = true
5535 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005536 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005537 Bugs: ProtocolBugs{
5538 NoExtendedMasterSecret: !hasEMS,
5539 },
5540 }
5541 }
5542
5543 if isResumption && !hasEMS {
5544 test.shouldFail = true
5545 test.expectedError = "failed to get tls-unique"
5546 }
5547
5548 testCases = append(testCases, test)
5549 }
5550 }
5551 }
5552}
5553
Adam Langley09505632015-07-30 18:10:13 -07005554func addCustomExtensionTests() {
5555 expectedContents := "custom extension"
5556 emptyString := ""
5557
David Benjamin4c3ddf72016-06-29 18:13:53 -04005558 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005559 for _, isClient := range []bool{false, true} {
5560 suffix := "Server"
5561 flag := "-enable-server-custom-extension"
5562 testType := serverTest
5563 if isClient {
5564 suffix = "Client"
5565 flag = "-enable-client-custom-extension"
5566 testType = clientTest
5567 }
5568
5569 testCases = append(testCases, testCase{
5570 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005571 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005572 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005573 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005574 Bugs: ProtocolBugs{
5575 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005576 ExpectedCustomExtension: &expectedContents,
5577 },
5578 },
5579 flags: []string{flag},
5580 })
5581
5582 // If the parse callback fails, the handshake should also fail.
5583 testCases = append(testCases, testCase{
5584 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005585 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005586 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005587 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005588 Bugs: ProtocolBugs{
5589 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005590 ExpectedCustomExtension: &expectedContents,
5591 },
5592 },
David Benjamin399e7c92015-07-30 23:01:27 -04005593 flags: []string{flag},
5594 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005595 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5596 })
5597
5598 // If the add callback fails, the handshake should also fail.
5599 testCases = append(testCases, testCase{
5600 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005601 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005602 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005603 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005604 Bugs: ProtocolBugs{
5605 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005606 ExpectedCustomExtension: &expectedContents,
5607 },
5608 },
David Benjamin399e7c92015-07-30 23:01:27 -04005609 flags: []string{flag, "-custom-extension-fail-add"},
5610 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005611 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5612 })
5613
5614 // If the add callback returns zero, no extension should be
5615 // added.
5616 skipCustomExtension := expectedContents
5617 if isClient {
5618 // For the case where the client skips sending the
5619 // custom extension, the server must not “echo” it.
5620 skipCustomExtension = ""
5621 }
5622 testCases = append(testCases, testCase{
5623 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005624 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005625 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005626 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005627 Bugs: ProtocolBugs{
5628 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005629 ExpectedCustomExtension: &emptyString,
5630 },
5631 },
5632 flags: []string{flag, "-custom-extension-skip"},
5633 })
5634 }
5635
5636 // The custom extension add callback should not be called if the client
5637 // doesn't send the extension.
5638 testCases = append(testCases, testCase{
5639 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005640 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005641 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005642 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005643 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005644 ExpectedCustomExtension: &emptyString,
5645 },
5646 },
5647 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5648 })
Adam Langley2deb9842015-08-07 11:15:37 -07005649
5650 // Test an unknown extension from the server.
5651 testCases = append(testCases, testCase{
5652 testType: clientTest,
5653 name: "UnknownExtension-Client",
5654 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005655 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005656 Bugs: ProtocolBugs{
5657 CustomExtension: expectedContents,
5658 },
5659 },
5660 shouldFail: true,
5661 expectedError: ":UNEXPECTED_EXTENSION:",
5662 })
Adam Langley09505632015-07-30 18:10:13 -07005663}
5664
David Benjaminb36a3952015-12-01 18:53:13 -05005665func addRSAClientKeyExchangeTests() {
5666 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5667 testCases = append(testCases, testCase{
5668 testType: serverTest,
5669 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5670 config: Config{
5671 // Ensure the ClientHello version and final
5672 // version are different, to detect if the
5673 // server uses the wrong one.
5674 MaxVersion: VersionTLS11,
5675 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5676 Bugs: ProtocolBugs{
5677 BadRSAClientKeyExchange: bad,
5678 },
5679 },
5680 shouldFail: true,
5681 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5682 })
5683 }
5684}
5685
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005686var testCurves = []struct {
5687 name string
5688 id CurveID
5689}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005690 {"P-256", CurveP256},
5691 {"P-384", CurveP384},
5692 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005693 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005694}
5695
5696func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005697 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005698 for _, curve := range testCurves {
5699 testCases = append(testCases, testCase{
5700 name: "CurveTest-Client-" + curve.name,
5701 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005702 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005703 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5704 CurvePreferences: []CurveID{curve.id},
5705 },
5706 flags: []string{"-enable-all-curves"},
5707 })
5708 testCases = append(testCases, testCase{
5709 testType: serverTest,
5710 name: "CurveTest-Server-" + curve.name,
5711 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005712 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005713 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5714 CurvePreferences: []CurveID{curve.id},
5715 },
5716 flags: []string{"-enable-all-curves"},
5717 })
5718 }
David Benjamin241ae832016-01-15 03:04:54 -05005719
5720 // The server must be tolerant to bogus curves.
5721 const bogusCurve = 0x1234
5722 testCases = append(testCases, testCase{
5723 testType: serverTest,
5724 name: "UnknownCurve",
5725 config: Config{
5726 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5727 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5728 },
5729 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005730
5731 // The server must not consider ECDHE ciphers when there are no
5732 // supported curves.
5733 testCases = append(testCases, testCase{
5734 testType: serverTest,
5735 name: "NoSupportedCurves",
5736 config: Config{
5737 // TODO(davidben): Add a TLS 1.3 version of this.
5738 MaxVersion: VersionTLS12,
5739 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5740 Bugs: ProtocolBugs{
5741 NoSupportedCurves: true,
5742 },
5743 },
5744 shouldFail: true,
5745 expectedError: ":NO_SHARED_CIPHER:",
5746 })
5747
5748 // The server must fall back to another cipher when there are no
5749 // supported curves.
5750 testCases = append(testCases, testCase{
5751 testType: serverTest,
5752 name: "NoCommonCurves",
5753 config: Config{
5754 MaxVersion: VersionTLS12,
5755 CipherSuites: []uint16{
5756 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5757 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5758 },
5759 CurvePreferences: []CurveID{CurveP224},
5760 },
5761 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5762 })
5763
5764 // The client must reject bogus curves and disabled curves.
5765 testCases = append(testCases, testCase{
5766 name: "BadECDHECurve",
5767 config: Config{
5768 // TODO(davidben): Add a TLS 1.3 version of this.
5769 MaxVersion: VersionTLS12,
5770 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5771 Bugs: ProtocolBugs{
5772 SendCurve: bogusCurve,
5773 },
5774 },
5775 shouldFail: true,
5776 expectedError: ":WRONG_CURVE:",
5777 })
5778
5779 testCases = append(testCases, testCase{
5780 name: "UnsupportedCurve",
5781 config: Config{
5782 // TODO(davidben): Add a TLS 1.3 version of this.
5783 MaxVersion: VersionTLS12,
5784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5785 CurvePreferences: []CurveID{CurveP256},
5786 Bugs: ProtocolBugs{
5787 IgnorePeerCurvePreferences: true,
5788 },
5789 },
5790 flags: []string{"-p384-only"},
5791 shouldFail: true,
5792 expectedError: ":WRONG_CURVE:",
5793 })
5794
5795 // Test invalid curve points.
5796 testCases = append(testCases, testCase{
5797 name: "InvalidECDHPoint-Client",
5798 config: Config{
5799 // TODO(davidben): Add a TLS 1.3 version of this test.
5800 MaxVersion: VersionTLS12,
5801 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5802 CurvePreferences: []CurveID{CurveP256},
5803 Bugs: ProtocolBugs{
5804 InvalidECDHPoint: true,
5805 },
5806 },
5807 shouldFail: true,
5808 expectedError: ":INVALID_ENCODING:",
5809 })
5810 testCases = append(testCases, testCase{
5811 testType: serverTest,
5812 name: "InvalidECDHPoint-Server",
5813 config: Config{
5814 // TODO(davidben): Add a TLS 1.3 version of this test.
5815 MaxVersion: VersionTLS12,
5816 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5817 CurvePreferences: []CurveID{CurveP256},
5818 Bugs: ProtocolBugs{
5819 InvalidECDHPoint: true,
5820 },
5821 },
5822 shouldFail: true,
5823 expectedError: ":INVALID_ENCODING:",
5824 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005825}
5826
Matt Braithwaite54217e42016-06-13 13:03:47 -07005827func addCECPQ1Tests() {
5828 testCases = append(testCases, testCase{
5829 testType: clientTest,
5830 name: "CECPQ1-Client-BadX25519Part",
5831 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005832 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005833 MinVersion: VersionTLS12,
5834 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5835 Bugs: ProtocolBugs{
5836 CECPQ1BadX25519Part: true,
5837 },
5838 },
5839 flags: []string{"-cipher", "kCECPQ1"},
5840 shouldFail: true,
5841 expectedLocalError: "local error: bad record MAC",
5842 })
5843 testCases = append(testCases, testCase{
5844 testType: clientTest,
5845 name: "CECPQ1-Client-BadNewhopePart",
5846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005847 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005848 MinVersion: VersionTLS12,
5849 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5850 Bugs: ProtocolBugs{
5851 CECPQ1BadNewhopePart: true,
5852 },
5853 },
5854 flags: []string{"-cipher", "kCECPQ1"},
5855 shouldFail: true,
5856 expectedLocalError: "local error: bad record MAC",
5857 })
5858 testCases = append(testCases, testCase{
5859 testType: serverTest,
5860 name: "CECPQ1-Server-BadX25519Part",
5861 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005862 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005863 MinVersion: VersionTLS12,
5864 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5865 Bugs: ProtocolBugs{
5866 CECPQ1BadX25519Part: true,
5867 },
5868 },
5869 flags: []string{"-cipher", "kCECPQ1"},
5870 shouldFail: true,
5871 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5872 })
5873 testCases = append(testCases, testCase{
5874 testType: serverTest,
5875 name: "CECPQ1-Server-BadNewhopePart",
5876 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005877 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005878 MinVersion: VersionTLS12,
5879 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5880 Bugs: ProtocolBugs{
5881 CECPQ1BadNewhopePart: true,
5882 },
5883 },
5884 flags: []string{"-cipher", "kCECPQ1"},
5885 shouldFail: true,
5886 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5887 })
5888}
5889
David Benjamin4cc36ad2015-12-19 14:23:26 -05005890func addKeyExchangeInfoTests() {
5891 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005892 name: "KeyExchangeInfo-DHE-Client",
5893 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005894 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005895 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5896 Bugs: ProtocolBugs{
5897 // This is a 1234-bit prime number, generated
5898 // with:
5899 // openssl gendh 1234 | openssl asn1parse -i
5900 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5901 },
5902 },
David Benjamin9e68f192016-06-30 14:55:33 -04005903 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005904 })
5905 testCases = append(testCases, testCase{
5906 testType: serverTest,
5907 name: "KeyExchangeInfo-DHE-Server",
5908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005909 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005910 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5911 },
5912 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005913 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005914 })
5915
Nick Harper1fd39d82016-06-14 18:14:35 -07005916 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5917 // handshake is separate.
5918
David Benjamin4cc36ad2015-12-19 14:23:26 -05005919 testCases = append(testCases, testCase{
5920 name: "KeyExchangeInfo-ECDHE-Client",
5921 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005922 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005923 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5924 CurvePreferences: []CurveID{CurveX25519},
5925 },
David Benjamin9e68f192016-06-30 14:55:33 -04005926 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005927 })
5928 testCases = append(testCases, testCase{
5929 testType: serverTest,
5930 name: "KeyExchangeInfo-ECDHE-Server",
5931 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005932 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5934 CurvePreferences: []CurveID{CurveX25519},
5935 },
David Benjamin9e68f192016-06-30 14:55:33 -04005936 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005937 })
5938}
5939
David Benjaminc9ae27c2016-06-24 22:56:37 -04005940func addTLS13RecordTests() {
5941 testCases = append(testCases, testCase{
5942 name: "TLS13-RecordPadding",
5943 config: Config{
5944 MaxVersion: VersionTLS13,
5945 MinVersion: VersionTLS13,
5946 Bugs: ProtocolBugs{
5947 RecordPadding: 10,
5948 },
5949 },
5950 })
5951
5952 testCases = append(testCases, testCase{
5953 name: "TLS13-EmptyRecords",
5954 config: Config{
5955 MaxVersion: VersionTLS13,
5956 MinVersion: VersionTLS13,
5957 Bugs: ProtocolBugs{
5958 OmitRecordContents: true,
5959 },
5960 },
5961 shouldFail: true,
5962 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5963 })
5964
5965 testCases = append(testCases, testCase{
5966 name: "TLS13-OnlyPadding",
5967 config: Config{
5968 MaxVersion: VersionTLS13,
5969 MinVersion: VersionTLS13,
5970 Bugs: ProtocolBugs{
5971 OmitRecordContents: true,
5972 RecordPadding: 10,
5973 },
5974 },
5975 shouldFail: true,
5976 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5977 })
5978
5979 testCases = append(testCases, testCase{
5980 name: "TLS13-WrongOuterRecord",
5981 config: Config{
5982 MaxVersion: VersionTLS13,
5983 MinVersion: VersionTLS13,
5984 Bugs: ProtocolBugs{
5985 OuterRecordType: recordTypeHandshake,
5986 },
5987 },
5988 shouldFail: true,
5989 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5990 })
5991}
5992
David Benjamin82261be2016-07-07 14:32:50 -07005993func addChangeCipherSpecTests() {
5994 // Test missing ChangeCipherSpecs.
5995 testCases = append(testCases, testCase{
5996 name: "SkipChangeCipherSpec-Client",
5997 config: Config{
5998 MaxVersion: VersionTLS12,
5999 Bugs: ProtocolBugs{
6000 SkipChangeCipherSpec: true,
6001 },
6002 },
6003 shouldFail: true,
6004 expectedError: ":UNEXPECTED_RECORD:",
6005 })
6006 testCases = append(testCases, testCase{
6007 testType: serverTest,
6008 name: "SkipChangeCipherSpec-Server",
6009 config: Config{
6010 MaxVersion: VersionTLS12,
6011 Bugs: ProtocolBugs{
6012 SkipChangeCipherSpec: true,
6013 },
6014 },
6015 shouldFail: true,
6016 expectedError: ":UNEXPECTED_RECORD:",
6017 })
6018 testCases = append(testCases, testCase{
6019 testType: serverTest,
6020 name: "SkipChangeCipherSpec-Server-NPN",
6021 config: Config{
6022 MaxVersion: VersionTLS12,
6023 NextProtos: []string{"bar"},
6024 Bugs: ProtocolBugs{
6025 SkipChangeCipherSpec: true,
6026 },
6027 },
6028 flags: []string{
6029 "-advertise-npn", "\x03foo\x03bar\x03baz",
6030 },
6031 shouldFail: true,
6032 expectedError: ":UNEXPECTED_RECORD:",
6033 })
6034
6035 // Test synchronization between the handshake and ChangeCipherSpec.
6036 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6037 // rejected. Test both with and without handshake packing to handle both
6038 // when the partial post-CCS message is in its own record and when it is
6039 // attached to the pre-CCS message.
6040 //
6041 // TODO(davidben): Fix and test DTLS as well.
6042 for _, packed := range []bool{false, true} {
6043 var suffix string
6044 if packed {
6045 suffix = "-Packed"
6046 }
6047
6048 testCases = append(testCases, testCase{
6049 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6050 config: Config{
6051 MaxVersion: VersionTLS12,
6052 Bugs: ProtocolBugs{
6053 FragmentAcrossChangeCipherSpec: true,
6054 PackHandshakeFlight: packed,
6055 },
6056 },
6057 shouldFail: true,
6058 expectedError: ":UNEXPECTED_RECORD:",
6059 })
6060 testCases = append(testCases, testCase{
6061 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6062 config: Config{
6063 MaxVersion: VersionTLS12,
6064 },
6065 resumeSession: true,
6066 resumeConfig: &Config{
6067 MaxVersion: VersionTLS12,
6068 Bugs: ProtocolBugs{
6069 FragmentAcrossChangeCipherSpec: true,
6070 PackHandshakeFlight: packed,
6071 },
6072 },
6073 shouldFail: true,
6074 expectedError: ":UNEXPECTED_RECORD:",
6075 })
6076 testCases = append(testCases, testCase{
6077 testType: serverTest,
6078 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6079 config: Config{
6080 MaxVersion: VersionTLS12,
6081 Bugs: ProtocolBugs{
6082 FragmentAcrossChangeCipherSpec: true,
6083 PackHandshakeFlight: packed,
6084 },
6085 },
6086 shouldFail: true,
6087 expectedError: ":UNEXPECTED_RECORD:",
6088 })
6089 testCases = append(testCases, testCase{
6090 testType: serverTest,
6091 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6092 config: Config{
6093 MaxVersion: VersionTLS12,
6094 },
6095 resumeSession: true,
6096 resumeConfig: &Config{
6097 MaxVersion: VersionTLS12,
6098 Bugs: ProtocolBugs{
6099 FragmentAcrossChangeCipherSpec: true,
6100 PackHandshakeFlight: packed,
6101 },
6102 },
6103 shouldFail: true,
6104 expectedError: ":UNEXPECTED_RECORD:",
6105 })
6106 testCases = append(testCases, testCase{
6107 testType: serverTest,
6108 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6109 config: Config{
6110 MaxVersion: VersionTLS12,
6111 NextProtos: []string{"bar"},
6112 Bugs: ProtocolBugs{
6113 FragmentAcrossChangeCipherSpec: true,
6114 PackHandshakeFlight: packed,
6115 },
6116 },
6117 flags: []string{
6118 "-advertise-npn", "\x03foo\x03bar\x03baz",
6119 },
6120 shouldFail: true,
6121 expectedError: ":UNEXPECTED_RECORD:",
6122 })
6123 }
6124
6125 // Test that early ChangeCipherSpecs are handled correctly.
6126 testCases = append(testCases, testCase{
6127 testType: serverTest,
6128 name: "EarlyChangeCipherSpec-server-1",
6129 config: Config{
6130 MaxVersion: VersionTLS12,
6131 Bugs: ProtocolBugs{
6132 EarlyChangeCipherSpec: 1,
6133 },
6134 },
6135 shouldFail: true,
6136 expectedError: ":UNEXPECTED_RECORD:",
6137 })
6138 testCases = append(testCases, testCase{
6139 testType: serverTest,
6140 name: "EarlyChangeCipherSpec-server-2",
6141 config: Config{
6142 MaxVersion: VersionTLS12,
6143 Bugs: ProtocolBugs{
6144 EarlyChangeCipherSpec: 2,
6145 },
6146 },
6147 shouldFail: true,
6148 expectedError: ":UNEXPECTED_RECORD:",
6149 })
6150 testCases = append(testCases, testCase{
6151 protocol: dtls,
6152 name: "StrayChangeCipherSpec",
6153 config: Config{
6154 // TODO(davidben): Once DTLS 1.3 exists, test
6155 // that stray ChangeCipherSpec messages are
6156 // rejected.
6157 MaxVersion: VersionTLS12,
6158 Bugs: ProtocolBugs{
6159 StrayChangeCipherSpec: true,
6160 },
6161 },
6162 })
6163
6164 // Test that the contents of ChangeCipherSpec are checked.
6165 testCases = append(testCases, testCase{
6166 name: "BadChangeCipherSpec-1",
6167 config: Config{
6168 MaxVersion: VersionTLS12,
6169 Bugs: ProtocolBugs{
6170 BadChangeCipherSpec: []byte{2},
6171 },
6172 },
6173 shouldFail: true,
6174 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6175 })
6176 testCases = append(testCases, testCase{
6177 name: "BadChangeCipherSpec-2",
6178 config: Config{
6179 MaxVersion: VersionTLS12,
6180 Bugs: ProtocolBugs{
6181 BadChangeCipherSpec: []byte{1, 1},
6182 },
6183 },
6184 shouldFail: true,
6185 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6186 })
6187 testCases = append(testCases, testCase{
6188 protocol: dtls,
6189 name: "BadChangeCipherSpec-DTLS-1",
6190 config: Config{
6191 MaxVersion: VersionTLS12,
6192 Bugs: ProtocolBugs{
6193 BadChangeCipherSpec: []byte{2},
6194 },
6195 },
6196 shouldFail: true,
6197 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6198 })
6199 testCases = append(testCases, testCase{
6200 protocol: dtls,
6201 name: "BadChangeCipherSpec-DTLS-2",
6202 config: Config{
6203 MaxVersion: VersionTLS12,
6204 Bugs: ProtocolBugs{
6205 BadChangeCipherSpec: []byte{1, 1},
6206 },
6207 },
6208 shouldFail: true,
6209 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6210 })
6211}
6212
Adam Langley7c803a62015-06-15 15:35:05 -07006213func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006214 defer wg.Done()
6215
6216 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006217 var err error
6218
6219 if *mallocTest < 0 {
6220 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006221 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006222 } else {
6223 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6224 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006225 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006226 if err != nil {
6227 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6228 }
6229 break
6230 }
6231 }
6232 }
Adam Langley95c29f32014-06-20 12:00:00 -07006233 statusChan <- statusMsg{test: test, err: err}
6234 }
6235}
6236
6237type statusMsg struct {
6238 test *testCase
6239 started bool
6240 err error
6241}
6242
David Benjamin5f237bc2015-02-11 17:14:15 -05006243func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006244 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006245
David Benjamin5f237bc2015-02-11 17:14:15 -05006246 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006247 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006248 if !*pipe {
6249 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006250 var erase string
6251 for i := 0; i < lineLen; i++ {
6252 erase += "\b \b"
6253 }
6254 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006255 }
6256
Adam Langley95c29f32014-06-20 12:00:00 -07006257 if msg.started {
6258 started++
6259 } else {
6260 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006261
6262 if msg.err != nil {
6263 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6264 failed++
6265 testOutput.addResult(msg.test.name, "FAIL")
6266 } else {
6267 if *pipe {
6268 // Print each test instead of a status line.
6269 fmt.Printf("PASSED (%s)\n", msg.test.name)
6270 }
6271 testOutput.addResult(msg.test.name, "PASS")
6272 }
Adam Langley95c29f32014-06-20 12:00:00 -07006273 }
6274
David Benjamin5f237bc2015-02-11 17:14:15 -05006275 if !*pipe {
6276 // Print a new status line.
6277 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6278 lineLen = len(line)
6279 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006280 }
Adam Langley95c29f32014-06-20 12:00:00 -07006281 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006282
6283 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006284}
6285
6286func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006287 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006288 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006289 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006290
Adam Langley7c803a62015-06-15 15:35:05 -07006291 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006292 addCipherSuiteTests()
6293 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006294 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006295 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006296 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006297 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006298 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006299 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006300 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006301 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006302 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006303 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006304 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006305 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006306 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006307 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006308 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006309 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006310 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006311 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006312 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006313 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006314 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006315 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006316 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006317
6318 var wg sync.WaitGroup
6319
Adam Langley7c803a62015-06-15 15:35:05 -07006320 statusChan := make(chan statusMsg, *numWorkers)
6321 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006322 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006323
David Benjamin025b3d32014-07-01 19:53:04 -04006324 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006325
Adam Langley7c803a62015-06-15 15:35:05 -07006326 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006327 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006328 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006329 }
6330
David Benjamin270f0a72016-03-17 14:41:36 -04006331 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006332 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006333 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006334 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006335 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006336 }
6337 }
David Benjamin270f0a72016-03-17 14:41:36 -04006338 if !foundTest {
6339 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6340 os.Exit(1)
6341 }
Adam Langley95c29f32014-06-20 12:00:00 -07006342
6343 close(testChan)
6344 wg.Wait()
6345 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006346 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006347
6348 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006349
6350 if *jsonOutput != "" {
6351 if err := testOutput.writeTo(*jsonOutput); err != nil {
6352 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6353 }
6354 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006355
6356 if !testOutput.allPassed {
6357 os.Exit(1)
6358 }
Adam Langley95c29f32014-06-20 12:00:00 -07006359}