blob: 3531909ff00421e8531792b823209430e7bfd867 [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
64 testCertECDSAP256
65 testCertECDSAP384
66 testCertECDSAP521
67)
68
69const (
70 rsaCertificateFile = "cert.pem"
71 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
72 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
73 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040074)
75
76const (
David Benjamina08e49d2014-08-24 01:46:07 -040077 rsaKeyFile = "key.pem"
David Benjamin33863262016-07-08 17:20:12 -070078 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
79 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
80 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040081 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040082)
83
David Benjamin33863262016-07-08 17:20:12 -070084var rsaCertificate, ecdsaP256Certificate, ecdsaP384Certificate, ecdsaP521Certificate Certificate
85
86var testCerts = []struct {
87 id testCert
88 certFile, keyFile string
89 cert *Certificate
90}{
91 {
92 id: testCertRSA,
93 certFile: rsaCertificateFile,
94 keyFile: rsaKeyFile,
95 cert: &rsaCertificate,
96 },
97 {
98 id: testCertECDSAP256,
99 certFile: ecdsaP256CertificateFile,
100 keyFile: ecdsaP256KeyFile,
101 cert: &ecdsaP256Certificate,
102 },
103 {
104 id: testCertECDSAP384,
105 certFile: ecdsaP384CertificateFile,
106 keyFile: ecdsaP384KeyFile,
107 cert: &ecdsaP384Certificate,
108 },
109 {
110 id: testCertECDSAP521,
111 certFile: ecdsaP521CertificateFile,
112 keyFile: ecdsaP521KeyFile,
113 cert: &ecdsaP521Certificate,
114 },
115}
116
David Benjamina08e49d2014-08-24 01:46:07 -0400117var channelIDKey *ecdsa.PrivateKey
118var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700119
David Benjamin61f95272014-11-25 01:55:35 -0500120var testOCSPResponse = []byte{1, 2, 3, 4}
121var testSCTList = []byte{5, 6, 7, 8}
122
Adam Langley95c29f32014-06-20 12:00:00 -0700123func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700124 for i := range testCerts {
125 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
126 if err != nil {
127 panic(err)
128 }
129 cert.OCSPStaple = testOCSPResponse
130 cert.SignedCertificateTimestampList = testSCTList
131 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700132 }
David Benjamina08e49d2014-08-24 01:46:07 -0400133
Adam Langley7c803a62015-06-15 15:35:05 -0700134 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400135 if err != nil {
136 panic(err)
137 }
138 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
139 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
140 panic("bad key type")
141 }
142 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
143 if err != nil {
144 panic(err)
145 }
146 if channelIDKey.Curve != elliptic.P256() {
147 panic("bad curve")
148 }
149
150 channelIDBytes = make([]byte, 64)
151 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
152 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700153}
154
David Benjamin33863262016-07-08 17:20:12 -0700155func getRunnerCertificate(t testCert) Certificate {
156 for _, cert := range testCerts {
157 if cert.id == t {
158 return *cert.cert
159 }
160 }
161 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700162}
163
David Benjamin33863262016-07-08 17:20:12 -0700164func getShimCertificate(t testCert) string {
165 for _, cert := range testCerts {
166 if cert.id == t {
167 return cert.certFile
168 }
169 }
170 panic("Unknown test certificate")
171}
172
173func getShimKey(t testCert) string {
174 for _, cert := range testCerts {
175 if cert.id == t {
176 return cert.keyFile
177 }
178 }
179 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700180}
181
David Benjamin025b3d32014-07-01 19:53:04 -0400182type testType int
183
184const (
185 clientTest testType = iota
186 serverTest
187)
188
David Benjamin6fd297b2014-08-11 18:43:38 -0400189type protocol int
190
191const (
192 tls protocol = iota
193 dtls
194)
195
David Benjaminfc7b0862014-09-06 13:21:53 -0400196const (
197 alpn = 1
198 npn = 2
199)
200
Adam Langley95c29f32014-06-20 12:00:00 -0700201type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400202 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400203 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700204 name string
205 config Config
206 shouldFail bool
207 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700208 // expectedLocalError, if not empty, contains a substring that must be
209 // found in the local error.
210 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400211 // expectedVersion, if non-zero, specifies the TLS version that must be
212 // negotiated.
213 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400214 // expectedResumeVersion, if non-zero, specifies the TLS version that
215 // must be negotiated on resumption. If zero, expectedVersion is used.
216 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400217 // expectedCipher, if non-zero, specifies the TLS cipher suite that
218 // should be negotiated.
219 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400220 // expectChannelID controls whether the connection should have
221 // negotiated a Channel ID with channelIDKey.
222 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400223 // expectedNextProto controls whether the connection should
224 // negotiate a next protocol via NPN or ALPN.
225 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400226 // expectNoNextProto, if true, means that no next protocol should be
227 // negotiated.
228 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400229 // expectedNextProtoType, if non-zero, is the expected next
230 // protocol negotiation mechanism.
231 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500232 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
233 // should be negotiated. If zero, none should be negotiated.
234 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100235 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
236 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100237 // expectedSCTList, if not nil, is the expected SCT list to be received.
238 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700239 // expectedPeerSignatureAlgorithm, if not zero, is the signature
240 // algorithm that the peer should have used in the handshake.
241 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700242 // messageLen is the length, in bytes, of the test message that will be
243 // sent.
244 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400245 // messageCount is the number of test messages that will be sent.
246 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400247 // digestPrefs is the list of digest preferences from the client.
248 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400249 // certFile is the path to the certificate to use for the server.
250 certFile string
251 // keyFile is the path to the private key to use for the server.
252 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400253 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400255 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700256 // expectResumeRejected, if true, specifies that the attempted
257 // resumption must be rejected by the client. This is only valid for a
258 // serverTest.
259 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400260 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500261 // resumption. Unless newSessionsOnResume is set,
262 // SessionTicketKey, ServerSessionCache, and
263 // ClientSessionCache are copied from the initial connection's
264 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400265 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500266 // newSessionsOnResume, if true, will cause resumeConfig to
267 // use a different session resumption context.
268 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400269 // noSessionCache, if true, will cause the server to run without a
270 // session cache.
271 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400272 // sendPrefix sends a prefix on the socket before actually performing a
273 // handshake.
274 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400275 // shimWritesFirst controls whether the shim sends an initial "hello"
276 // message before doing a roundtrip with the runner.
277 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400278 // shimShutsDown, if true, runs a test where the shim shuts down the
279 // connection immediately after the handshake rather than echoing
280 // messages from the runner.
281 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400282 // renegotiate indicates the number of times the connection should be
283 // renegotiated during the exchange.
284 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700285 // renegotiateCiphers is a list of ciphersuite ids that will be
286 // switched in just before renegotiation.
287 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500288 // replayWrites, if true, configures the underlying transport
289 // to replay every write it makes in DTLS tests.
290 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500291 // damageFirstWrite, if true, configures the underlying transport to
292 // damage the final byte of the first application data write.
293 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400294 // exportKeyingMaterial, if non-zero, configures the test to exchange
295 // keying material and verify they match.
296 exportKeyingMaterial int
297 exportLabel string
298 exportContext string
299 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400300 // flags, if not empty, contains a list of command-line flags that will
301 // be passed to the shim program.
302 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700303 // testTLSUnique, if true, causes the shim to send the tls-unique value
304 // which will be compared against the expected value.
305 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400306 // sendEmptyRecords is the number of consecutive empty records to send
307 // before and after the test message.
308 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400309 // sendWarningAlerts is the number of consecutive warning alerts to send
310 // before and after the test message.
311 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400312 // expectMessageDropped, if true, means the test message is expected to
313 // be dropped by the client rather than echoed back.
314 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700315}
316
Adam Langley7c803a62015-06-15 15:35:05 -0700317var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700318
David Benjamin9867b7d2016-03-01 23:25:48 -0500319func writeTranscript(test *testCase, isResume bool, data []byte) {
320 if len(data) == 0 {
321 return
322 }
323
324 protocol := "tls"
325 if test.protocol == dtls {
326 protocol = "dtls"
327 }
328
329 side := "client"
330 if test.testType == serverTest {
331 side = "server"
332 }
333
334 dir := path.Join(*transcriptDir, protocol, side)
335 if err := os.MkdirAll(dir, 0755); err != nil {
336 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
337 return
338 }
339
340 name := test.name
341 if isResume {
342 name += "-Resume"
343 } else {
344 name += "-Normal"
345 }
346
347 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
348 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
349 }
350}
351
David Benjamin3ed59772016-03-08 12:50:21 -0500352// A timeoutConn implements an idle timeout on each Read and Write operation.
353type timeoutConn struct {
354 net.Conn
355 timeout time.Duration
356}
357
358func (t *timeoutConn) Read(b []byte) (int, error) {
359 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
360 return 0, err
361 }
362 return t.Conn.Read(b)
363}
364
365func (t *timeoutConn) Write(b []byte) (int, error) {
366 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
367 return 0, err
368 }
369 return t.Conn.Write(b)
370}
371
David Benjamin8e6db492015-07-25 18:29:23 -0400372func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400373 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500374
David Benjamin6fd297b2014-08-11 18:43:38 -0400375 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500376 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
377 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500378 }
379
David Benjamin9867b7d2016-03-01 23:25:48 -0500380 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500381 local, peer := "client", "server"
382 if test.testType == clientTest {
383 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500384 }
David Benjaminebda9b32015-11-02 15:33:18 -0500385 connDebug := &recordingConn{
386 Conn: conn,
387 isDatagram: test.protocol == dtls,
388 local: local,
389 peer: peer,
390 }
391 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500392 if *flagDebug {
393 defer connDebug.WriteTo(os.Stdout)
394 }
395 if len(*transcriptDir) != 0 {
396 defer func() {
397 writeTranscript(test, isResume, connDebug.Transcript())
398 }()
399 }
David Benjaminebda9b32015-11-02 15:33:18 -0500400
401 if config.Bugs.PacketAdaptor != nil {
402 config.Bugs.PacketAdaptor.debug = connDebug
403 }
404 }
405
406 if test.replayWrites {
407 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400408 }
409
David Benjamin3ed59772016-03-08 12:50:21 -0500410 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500411 if test.damageFirstWrite {
412 connDamage = newDamageAdaptor(conn)
413 conn = connDamage
414 }
415
David Benjamin6fd297b2014-08-11 18:43:38 -0400416 if test.sendPrefix != "" {
417 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
418 return err
419 }
David Benjamin98e882e2014-08-08 13:24:34 -0400420 }
421
David Benjamin1d5c83e2014-07-22 19:20:02 -0400422 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400423 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400424 if test.protocol == dtls {
425 tlsConn = DTLSServer(conn, config)
426 } else {
427 tlsConn = Server(conn, config)
428 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400429 } else {
430 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400431 if test.protocol == dtls {
432 tlsConn = DTLSClient(conn, config)
433 } else {
434 tlsConn = Client(conn, config)
435 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400436 }
David Benjamin30789da2015-08-29 22:56:45 -0400437 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400438
Adam Langley95c29f32014-06-20 12:00:00 -0700439 if err := tlsConn.Handshake(); err != nil {
440 return err
441 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700442
David Benjamin01fe8202014-09-24 15:21:44 -0400443 // TODO(davidben): move all per-connection expectations into a dedicated
444 // expectations struct that can be specified separately for the two
445 // legs.
446 expectedVersion := test.expectedVersion
447 if isResume && test.expectedResumeVersion != 0 {
448 expectedVersion = test.expectedResumeVersion
449 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700450 connState := tlsConn.ConnectionState()
451 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400452 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400453 }
454
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700455 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400456 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
457 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700458 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
459 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
460 }
David Benjamin90da8c82015-04-20 14:57:57 -0400461
David Benjamina08e49d2014-08-24 01:46:07 -0400462 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700463 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400464 if channelID == nil {
465 return fmt.Errorf("no channel ID negotiated")
466 }
467 if channelID.Curve != channelIDKey.Curve ||
468 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
469 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
470 return fmt.Errorf("incorrect channel ID")
471 }
472 }
473
David Benjaminae2888f2014-09-06 12:58:58 -0400474 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700475 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400476 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
477 }
478 }
479
David Benjaminc7ce9772015-10-09 19:32:41 -0400480 if test.expectNoNextProto {
481 if actual := connState.NegotiatedProtocol; actual != "" {
482 return fmt.Errorf("got unexpected next proto %s", actual)
483 }
484 }
485
David Benjaminfc7b0862014-09-06 13:21:53 -0400486 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700487 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400488 return fmt.Errorf("next proto type mismatch")
489 }
490 }
491
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700492 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500493 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
494 }
495
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100496 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
497 return fmt.Errorf("OCSP Response mismatch")
498 }
499
Paul Lietar4fac72e2015-09-09 13:44:55 +0100500 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
501 return fmt.Errorf("SCT list mismatch")
502 }
503
Nick Harper60edffd2016-06-21 15:19:24 -0700504 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
505 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400506 }
507
David Benjaminc565ebb2015-04-03 04:06:36 -0400508 if test.exportKeyingMaterial > 0 {
509 actual := make([]byte, test.exportKeyingMaterial)
510 if _, err := io.ReadFull(tlsConn, actual); err != nil {
511 return err
512 }
513 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
514 if err != nil {
515 return err
516 }
517 if !bytes.Equal(actual, expected) {
518 return fmt.Errorf("keying material mismatch")
519 }
520 }
521
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700522 if test.testTLSUnique {
523 var peersValue [12]byte
524 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
525 return err
526 }
527 expected := tlsConn.ConnectionState().TLSUnique
528 if !bytes.Equal(peersValue[:], expected) {
529 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
530 }
531 }
532
David Benjamine58c4f52014-08-24 03:47:07 -0400533 if test.shimWritesFirst {
534 var buf [5]byte
535 _, err := io.ReadFull(tlsConn, buf[:])
536 if err != nil {
537 return err
538 }
539 if string(buf[:]) != "hello" {
540 return fmt.Errorf("bad initial message")
541 }
542 }
543
David Benjamina8ebe222015-06-06 03:04:39 -0400544 for i := 0; i < test.sendEmptyRecords; i++ {
545 tlsConn.Write(nil)
546 }
547
David Benjamin24f346d2015-06-06 03:28:08 -0400548 for i := 0; i < test.sendWarningAlerts; i++ {
549 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
550 }
551
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400552 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700553 if test.renegotiateCiphers != nil {
554 config.CipherSuites = test.renegotiateCiphers
555 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400556 for i := 0; i < test.renegotiate; i++ {
557 if err := tlsConn.Renegotiate(); err != nil {
558 return err
559 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700560 }
561 } else if test.renegotiateCiphers != nil {
562 panic("renegotiateCiphers without renegotiate")
563 }
564
David Benjamin5fa3eba2015-01-22 16:35:40 -0500565 if test.damageFirstWrite {
566 connDamage.setDamage(true)
567 tlsConn.Write([]byte("DAMAGED WRITE"))
568 connDamage.setDamage(false)
569 }
570
David Benjamin8e6db492015-07-25 18:29:23 -0400571 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700572 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400573 if test.protocol == dtls {
574 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
575 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700576 // Read until EOF.
577 _, err := io.Copy(ioutil.Discard, tlsConn)
578 return err
579 }
David Benjamin4417d052015-04-05 04:17:25 -0400580 if messageLen == 0 {
581 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700582 }
Adam Langley95c29f32014-06-20 12:00:00 -0700583
David Benjamin8e6db492015-07-25 18:29:23 -0400584 messageCount := test.messageCount
585 if messageCount == 0 {
586 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400587 }
588
David Benjamin8e6db492015-07-25 18:29:23 -0400589 for j := 0; j < messageCount; j++ {
590 testMessage := make([]byte, messageLen)
591 for i := range testMessage {
592 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400593 }
David Benjamin8e6db492015-07-25 18:29:23 -0400594 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700595
David Benjamin8e6db492015-07-25 18:29:23 -0400596 for i := 0; i < test.sendEmptyRecords; i++ {
597 tlsConn.Write(nil)
598 }
599
600 for i := 0; i < test.sendWarningAlerts; i++ {
601 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
602 }
603
David Benjamin4f75aaf2015-09-01 16:53:10 -0400604 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400605 // The shim will not respond.
606 continue
607 }
608
David Benjamin8e6db492015-07-25 18:29:23 -0400609 buf := make([]byte, len(testMessage))
610 if test.protocol == dtls {
611 bufTmp := make([]byte, len(buf)+1)
612 n, err := tlsConn.Read(bufTmp)
613 if err != nil {
614 return err
615 }
616 if n != len(buf) {
617 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
618 }
619 copy(buf, bufTmp)
620 } else {
621 _, err := io.ReadFull(tlsConn, buf)
622 if err != nil {
623 return err
624 }
625 }
626
627 for i, v := range buf {
628 if v != testMessage[i]^0xff {
629 return fmt.Errorf("bad reply contents at byte %d", i)
630 }
Adam Langley95c29f32014-06-20 12:00:00 -0700631 }
632 }
633
634 return nil
635}
636
David Benjamin325b5c32014-07-01 19:40:31 -0400637func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
638 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700639 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400640 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700641 }
David Benjamin325b5c32014-07-01 19:40:31 -0400642 valgrindArgs = append(valgrindArgs, path)
643 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700644
David Benjamin325b5c32014-07-01 19:40:31 -0400645 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700646}
647
David Benjamin325b5c32014-07-01 19:40:31 -0400648func gdbOf(path string, args ...string) *exec.Cmd {
649 xtermArgs := []string{"-e", "gdb", "--args"}
650 xtermArgs = append(xtermArgs, path)
651 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700652
David Benjamin325b5c32014-07-01 19:40:31 -0400653 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700654}
655
David Benjamind16bf342015-12-18 00:53:12 -0500656func lldbOf(path string, args ...string) *exec.Cmd {
657 xtermArgs := []string{"-e", "lldb", "--"}
658 xtermArgs = append(xtermArgs, path)
659 xtermArgs = append(xtermArgs, args...)
660
661 return exec.Command("xterm", xtermArgs...)
662}
663
Adam Langley69a01602014-11-17 17:26:55 -0800664type moreMallocsError struct{}
665
666func (moreMallocsError) Error() string {
667 return "child process did not exhaust all allocation calls"
668}
669
670var errMoreMallocs = moreMallocsError{}
671
David Benjamin87c8a642015-02-21 01:54:29 -0500672// accept accepts a connection from listener, unless waitChan signals a process
673// exit first.
674func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
675 type connOrError struct {
676 conn net.Conn
677 err error
678 }
679 connChan := make(chan connOrError, 1)
680 go func() {
681 conn, err := listener.Accept()
682 connChan <- connOrError{conn, err}
683 close(connChan)
684 }()
685 select {
686 case result := <-connChan:
687 return result.conn, result.err
688 case childErr := <-waitChan:
689 waitChan <- childErr
690 return nil, fmt.Errorf("child exited early: %s", childErr)
691 }
692}
693
Adam Langley7c803a62015-06-15 15:35:05 -0700694func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700695 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
696 panic("Error expected without shouldFail in " + test.name)
697 }
698
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700699 if test.expectResumeRejected && !test.resumeSession {
700 panic("expectResumeRejected without resumeSession in " + test.name)
701 }
702
David Benjamin87c8a642015-02-21 01:54:29 -0500703 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
704 if err != nil {
705 panic(err)
706 }
707 defer func() {
708 if listener != nil {
709 listener.Close()
710 }
711 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700712
David Benjamin87c8a642015-02-21 01:54:29 -0500713 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400714 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400715 flags = append(flags, "-server")
716
David Benjamin025b3d32014-07-01 19:53:04 -0400717 flags = append(flags, "-key-file")
718 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700719 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400720 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700721 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400722 }
723
724 flags = append(flags, "-cert-file")
725 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700726 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400727 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700728 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400729 }
730 }
David Benjamin5a593af2014-08-11 19:51:50 -0400731
Steven Valdez0d62f262015-09-04 12:41:04 -0400732 if test.digestPrefs != "" {
733 flags = append(flags, "-digest-prefs")
734 flags = append(flags, test.digestPrefs)
735 }
736
David Benjamin6fd297b2014-08-11 18:43:38 -0400737 if test.protocol == dtls {
738 flags = append(flags, "-dtls")
739 }
740
David Benjamin5a593af2014-08-11 19:51:50 -0400741 if test.resumeSession {
742 flags = append(flags, "-resume")
743 }
744
David Benjamine58c4f52014-08-24 03:47:07 -0400745 if test.shimWritesFirst {
746 flags = append(flags, "-shim-writes-first")
747 }
748
David Benjamin30789da2015-08-29 22:56:45 -0400749 if test.shimShutsDown {
750 flags = append(flags, "-shim-shuts-down")
751 }
752
David Benjaminc565ebb2015-04-03 04:06:36 -0400753 if test.exportKeyingMaterial > 0 {
754 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
755 flags = append(flags, "-export-label", test.exportLabel)
756 flags = append(flags, "-export-context", test.exportContext)
757 if test.useExportContext {
758 flags = append(flags, "-use-export-context")
759 }
760 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700761 if test.expectResumeRejected {
762 flags = append(flags, "-expect-session-miss")
763 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400764
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700765 if test.testTLSUnique {
766 flags = append(flags, "-tls-unique")
767 }
768
David Benjamin025b3d32014-07-01 19:53:04 -0400769 flags = append(flags, test.flags...)
770
771 var shim *exec.Cmd
772 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700773 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700774 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700775 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500776 } else if *useLLDB {
777 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400778 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700779 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400780 }
David Benjamin025b3d32014-07-01 19:53:04 -0400781 shim.Stdin = os.Stdin
782 var stdoutBuf, stderrBuf bytes.Buffer
783 shim.Stdout = &stdoutBuf
784 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800785 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500786 shim.Env = os.Environ()
787 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800788 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400789 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800790 }
791 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
792 }
David Benjamin025b3d32014-07-01 19:53:04 -0400793
794 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700795 panic(err)
796 }
David Benjamin87c8a642015-02-21 01:54:29 -0500797 waitChan := make(chan error, 1)
798 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700799
800 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400801 if !test.noSessionCache {
802 config.ClientSessionCache = NewLRUClientSessionCache(1)
803 config.ServerSessionCache = NewLRUServerSessionCache(1)
804 }
David Benjamin025b3d32014-07-01 19:53:04 -0400805 if test.testType == clientTest {
806 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700807 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400808 }
David Benjamin87c8a642015-02-21 01:54:29 -0500809 } else {
810 // Supply a ServerName to ensure a constant session cache key,
811 // rather than falling back to net.Conn.RemoteAddr.
812 if len(config.ServerName) == 0 {
813 config.ServerName = "test"
814 }
David Benjamin025b3d32014-07-01 19:53:04 -0400815 }
David Benjaminf2b83632016-03-01 22:57:46 -0500816 if *fuzzer {
817 config.Bugs.NullAllCiphers = true
818 }
David Benjamin2e045a92016-06-08 13:09:56 -0400819 if *deterministic {
820 config.Rand = &deterministicRand{}
821 }
Adam Langley95c29f32014-06-20 12:00:00 -0700822
David Benjamin87c8a642015-02-21 01:54:29 -0500823 conn, err := acceptOrWait(listener, waitChan)
824 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400825 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500826 conn.Close()
827 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500828
David Benjamin1d5c83e2014-07-22 19:20:02 -0400829 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400830 var resumeConfig Config
831 if test.resumeConfig != nil {
832 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500833 if len(resumeConfig.ServerName) == 0 {
834 resumeConfig.ServerName = config.ServerName
835 }
David Benjamin01fe8202014-09-24 15:21:44 -0400836 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700837 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400838 }
David Benjaminba4594a2015-06-18 18:36:15 -0400839 if test.newSessionsOnResume {
840 if !test.noSessionCache {
841 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
842 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
843 }
844 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500845 resumeConfig.SessionTicketKey = config.SessionTicketKey
846 resumeConfig.ClientSessionCache = config.ClientSessionCache
847 resumeConfig.ServerSessionCache = config.ServerSessionCache
848 }
David Benjaminf2b83632016-03-01 22:57:46 -0500849 if *fuzzer {
850 resumeConfig.Bugs.NullAllCiphers = true
851 }
David Benjamin2e045a92016-06-08 13:09:56 -0400852 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400853 } else {
854 resumeConfig = config
855 }
David Benjamin87c8a642015-02-21 01:54:29 -0500856 var connResume net.Conn
857 connResume, err = acceptOrWait(listener, waitChan)
858 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400859 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500860 connResume.Close()
861 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400862 }
863
David Benjamin87c8a642015-02-21 01:54:29 -0500864 // Close the listener now. This is to avoid hangs should the shim try to
865 // open more connections than expected.
866 listener.Close()
867 listener = nil
868
869 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800870 if exitError, ok := childErr.(*exec.ExitError); ok {
871 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
872 return errMoreMallocs
873 }
874 }
Adam Langley95c29f32014-06-20 12:00:00 -0700875
David Benjamin9bea3492016-03-02 10:59:16 -0500876 // Account for Windows line endings.
877 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
878 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500879
880 // Separate the errors from the shim and those from tools like
881 // AddressSanitizer.
882 var extraStderr string
883 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
884 stderr = stderrParts[0]
885 extraStderr = stderrParts[1]
886 }
887
Adam Langley95c29f32014-06-20 12:00:00 -0700888 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400889 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700890 localError := "none"
891 if err != nil {
892 localError = err.Error()
893 }
894 if len(test.expectedLocalError) != 0 {
895 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
896 }
Adam Langley95c29f32014-06-20 12:00:00 -0700897
898 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700899 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700900 if childErr != nil {
901 childError = childErr.Error()
902 }
903
904 var msg string
905 switch {
906 case failed && !test.shouldFail:
907 msg = "unexpected failure"
908 case !failed && test.shouldFail:
909 msg = "unexpected success"
910 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700911 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700912 default:
913 panic("internal error")
914 }
915
David Benjaminc565ebb2015-04-03 04:06:36 -0400916 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 -0700917 }
918
David Benjaminff3a1492016-03-02 10:12:06 -0500919 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
920 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700921 }
922
923 return nil
924}
925
926var tlsVersions = []struct {
927 name string
928 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400929 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500930 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700931}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500932 {"SSL3", VersionSSL30, "-no-ssl3", false},
933 {"TLS1", VersionTLS10, "-no-tls1", true},
934 {"TLS11", VersionTLS11, "-no-tls11", false},
935 {"TLS12", VersionTLS12, "-no-tls12", true},
Nick Harper1fd39d82016-06-14 18:14:35 -0700936 // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here.
937 {"FakeTLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700938}
939
940var testCipherSuites = []struct {
941 name string
942 id uint16
943}{
944 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400945 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700946 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400947 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400948 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700949 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400950 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400951 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
952 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400953 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400954 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
955 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400956 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700957 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
958 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400959 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
960 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700961 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400962 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500963 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500964 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700965 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700966 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700967 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400968 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400969 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700970 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400971 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500972 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500973 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700974 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700975 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
976 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
977 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
978 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400979 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
980 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700981 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
982 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500983 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400984 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
985 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400986 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700987 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400988 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700989 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700990}
991
David Benjamin8b8c0062014-11-23 02:47:52 -0500992func hasComponent(suiteName, component string) bool {
993 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
994}
995
David Benjaminf7768e42014-08-31 02:06:47 -0400996func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500997 return hasComponent(suiteName, "GCM") ||
998 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400999 hasComponent(suiteName, "SHA384") ||
1000 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001001}
1002
Nick Harper1fd39d82016-06-14 18:14:35 -07001003func isTLS13Suite(suiteName string) bool {
1004 return (hasComponent(suiteName, "GCM") || hasComponent(suiteName, "POLY1305")) && hasComponent(suiteName, "ECDHE") && !hasComponent(suiteName, "OLD")
1005}
1006
David Benjamin8b8c0062014-11-23 02:47:52 -05001007func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001008 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001009}
1010
Adam Langleya7997f12015-05-14 17:38:50 -07001011func bigFromHex(hex string) *big.Int {
1012 ret, ok := new(big.Int).SetString(hex, 16)
1013 if !ok {
1014 panic("failed to parse hex number 0x" + hex)
1015 }
1016 return ret
1017}
1018
Adam Langley7c803a62015-06-15 15:35:05 -07001019func addBasicTests() {
1020 basicTests := []testCase{
1021 {
1022 name: "BadRSASignature",
1023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001024 // TODO(davidben): Add a TLS 1.3 version of this.
1025 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1027 Bugs: ProtocolBugs{
1028 InvalidSKXSignature: true,
1029 },
1030 },
1031 shouldFail: true,
1032 expectedError: ":BAD_SIGNATURE:",
1033 },
1034 {
1035 name: "BadECDSASignature",
1036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001037 // TODO(davidben): Add a TLS 1.3 version of this.
1038 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001039 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1040 Bugs: ProtocolBugs{
1041 InvalidSKXSignature: true,
1042 },
David Benjamin33863262016-07-08 17:20:12 -07001043 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001044 },
1045 shouldFail: true,
1046 expectedError: ":BAD_SIGNATURE:",
1047 },
1048 {
David Benjamin6de0e532015-07-28 22:43:19 -04001049 testType: serverTest,
1050 name: "BadRSASignature-ClientAuth",
1051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001052 // TODO(davidben): Add a TLS 1.3 version of this.
1053 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001054 Bugs: ProtocolBugs{
1055 InvalidCertVerifySignature: true,
1056 },
David Benjamin33863262016-07-08 17:20:12 -07001057 Certificates: []Certificate{rsaCertificate},
David Benjamin6de0e532015-07-28 22:43:19 -04001058 },
1059 shouldFail: true,
1060 expectedError: ":BAD_SIGNATURE:",
1061 flags: []string{"-require-any-client-certificate"},
1062 },
1063 {
1064 testType: serverTest,
1065 name: "BadECDSASignature-ClientAuth",
1066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001067 // TODO(davidben): Add a TLS 1.3 version of this.
1068 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001069 Bugs: ProtocolBugs{
1070 InvalidCertVerifySignature: true,
1071 },
David Benjamin33863262016-07-08 17:20:12 -07001072 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin6de0e532015-07-28 22:43:19 -04001073 },
1074 shouldFail: true,
1075 expectedError: ":BAD_SIGNATURE:",
1076 flags: []string{"-require-any-client-certificate"},
1077 },
1078 {
Adam Langley7c803a62015-06-15 15:35:05 -07001079 name: "NoFallbackSCSV",
1080 config: Config{
1081 Bugs: ProtocolBugs{
1082 FailIfNotFallbackSCSV: true,
1083 },
1084 },
1085 shouldFail: true,
1086 expectedLocalError: "no fallback SCSV found",
1087 },
1088 {
1089 name: "SendFallbackSCSV",
1090 config: Config{
1091 Bugs: ProtocolBugs{
1092 FailIfNotFallbackSCSV: true,
1093 },
1094 },
1095 flags: []string{"-fallback-scsv"},
1096 },
1097 {
1098 name: "ClientCertificateTypes",
1099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001100 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001101 ClientAuth: RequestClientCert,
1102 ClientCertificateTypes: []byte{
1103 CertTypeDSSSign,
1104 CertTypeRSASign,
1105 CertTypeECDSASign,
1106 },
1107 },
1108 flags: []string{
1109 "-expect-certificate-types",
1110 base64.StdEncoding.EncodeToString([]byte{
1111 CertTypeDSSSign,
1112 CertTypeRSASign,
1113 CertTypeECDSASign,
1114 }),
1115 },
1116 },
1117 {
Adam Langley7c803a62015-06-15 15:35:05 -07001118 name: "UnauthenticatedECDH",
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 UnauthenticatedECDH: true,
1124 },
1125 },
1126 shouldFail: true,
1127 expectedError: ":UNEXPECTED_MESSAGE:",
1128 },
1129 {
1130 name: "SkipCertificateStatus",
1131 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001132 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001133 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1134 Bugs: ProtocolBugs{
1135 SkipCertificateStatus: true,
1136 },
1137 },
1138 flags: []string{
1139 "-enable-ocsp-stapling",
1140 },
1141 },
1142 {
1143 name: "SkipServerKeyExchange",
1144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001145 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001146 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1147 Bugs: ProtocolBugs{
1148 SkipServerKeyExchange: true,
1149 },
1150 },
1151 shouldFail: true,
1152 expectedError: ":UNEXPECTED_MESSAGE:",
1153 },
1154 {
Adam Langley7c803a62015-06-15 15:35:05 -07001155 testType: serverTest,
1156 name: "Alert",
1157 config: Config{
1158 Bugs: ProtocolBugs{
1159 SendSpuriousAlert: alertRecordOverflow,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1164 },
1165 {
1166 protocol: dtls,
1167 testType: serverTest,
1168 name: "Alert-DTLS",
1169 config: Config{
1170 Bugs: ProtocolBugs{
1171 SendSpuriousAlert: alertRecordOverflow,
1172 },
1173 },
1174 shouldFail: true,
1175 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1176 },
1177 {
1178 testType: serverTest,
1179 name: "FragmentAlert",
1180 config: Config{
1181 Bugs: ProtocolBugs{
1182 FragmentAlert: true,
1183 SendSpuriousAlert: alertRecordOverflow,
1184 },
1185 },
1186 shouldFail: true,
1187 expectedError: ":BAD_ALERT:",
1188 },
1189 {
1190 protocol: dtls,
1191 testType: serverTest,
1192 name: "FragmentAlert-DTLS",
1193 config: Config{
1194 Bugs: ProtocolBugs{
1195 FragmentAlert: true,
1196 SendSpuriousAlert: alertRecordOverflow,
1197 },
1198 },
1199 shouldFail: true,
1200 expectedError: ":BAD_ALERT:",
1201 },
1202 {
1203 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001204 name: "DoubleAlert",
1205 config: Config{
1206 Bugs: ProtocolBugs{
1207 DoubleAlert: true,
1208 SendSpuriousAlert: alertRecordOverflow,
1209 },
1210 },
1211 shouldFail: true,
1212 expectedError: ":BAD_ALERT:",
1213 },
1214 {
1215 protocol: dtls,
1216 testType: serverTest,
1217 name: "DoubleAlert-DTLS",
1218 config: Config{
1219 Bugs: ProtocolBugs{
1220 DoubleAlert: true,
1221 SendSpuriousAlert: alertRecordOverflow,
1222 },
1223 },
1224 shouldFail: true,
1225 expectedError: ":BAD_ALERT:",
1226 },
1227 {
Adam Langley7c803a62015-06-15 15:35:05 -07001228 name: "SkipNewSessionTicket",
1229 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001230 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001231 Bugs: ProtocolBugs{
1232 SkipNewSessionTicket: true,
1233 },
1234 },
1235 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001236 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001237 },
1238 {
1239 testType: serverTest,
1240 name: "FallbackSCSV",
1241 config: Config{
1242 MaxVersion: VersionTLS11,
1243 Bugs: ProtocolBugs{
1244 SendFallbackSCSV: true,
1245 },
1246 },
1247 shouldFail: true,
1248 expectedError: ":INAPPROPRIATE_FALLBACK:",
1249 },
1250 {
1251 testType: serverTest,
1252 name: "FallbackSCSV-VersionMatch",
1253 config: Config{
1254 Bugs: ProtocolBugs{
1255 SendFallbackSCSV: true,
1256 },
1257 },
1258 },
1259 {
1260 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001261 name: "FallbackSCSV-VersionMatch-TLS12",
1262 config: Config{
1263 MaxVersion: VersionTLS12,
1264 Bugs: ProtocolBugs{
1265 SendFallbackSCSV: true,
1266 },
1267 },
1268 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1269 },
1270 {
1271 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001272 name: "FragmentedClientVersion",
1273 config: Config{
1274 Bugs: ProtocolBugs{
1275 MaxHandshakeRecordLength: 1,
1276 FragmentClientVersion: true,
1277 },
1278 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001279 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001280 },
1281 {
Adam Langley7c803a62015-06-15 15:35:05 -07001282 testType: serverTest,
1283 name: "HttpGET",
1284 sendPrefix: "GET / HTTP/1.0\n",
1285 shouldFail: true,
1286 expectedError: ":HTTP_REQUEST:",
1287 },
1288 {
1289 testType: serverTest,
1290 name: "HttpPOST",
1291 sendPrefix: "POST / HTTP/1.0\n",
1292 shouldFail: true,
1293 expectedError: ":HTTP_REQUEST:",
1294 },
1295 {
1296 testType: serverTest,
1297 name: "HttpHEAD",
1298 sendPrefix: "HEAD / HTTP/1.0\n",
1299 shouldFail: true,
1300 expectedError: ":HTTP_REQUEST:",
1301 },
1302 {
1303 testType: serverTest,
1304 name: "HttpPUT",
1305 sendPrefix: "PUT / HTTP/1.0\n",
1306 shouldFail: true,
1307 expectedError: ":HTTP_REQUEST:",
1308 },
1309 {
1310 testType: serverTest,
1311 name: "HttpCONNECT",
1312 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1313 shouldFail: true,
1314 expectedError: ":HTTPS_PROXY_REQUEST:",
1315 },
1316 {
1317 testType: serverTest,
1318 name: "Garbage",
1319 sendPrefix: "blah",
1320 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001321 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001322 },
1323 {
Adam Langley7c803a62015-06-15 15:35:05 -07001324 name: "RSAEphemeralKey",
1325 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001326 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001327 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1328 Bugs: ProtocolBugs{
1329 RSAEphemeralKey: true,
1330 },
1331 },
1332 shouldFail: true,
1333 expectedError: ":UNEXPECTED_MESSAGE:",
1334 },
1335 {
1336 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001337 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001338 shouldFail: true,
1339 expectedError: ":WRONG_SSL_VERSION:",
1340 },
1341 {
1342 protocol: dtls,
1343 name: "DisableEverything-DTLS",
1344 flags: []string{"-no-tls12", "-no-tls1"},
1345 shouldFail: true,
1346 expectedError: ":WRONG_SSL_VERSION:",
1347 },
1348 {
Adam Langley7c803a62015-06-15 15:35:05 -07001349 protocol: dtls,
1350 testType: serverTest,
1351 name: "MTU",
1352 config: Config{
1353 Bugs: ProtocolBugs{
1354 MaxPacketLength: 256,
1355 },
1356 },
1357 flags: []string{"-mtu", "256"},
1358 },
1359 {
1360 protocol: dtls,
1361 testType: serverTest,
1362 name: "MTUExceeded",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 MaxPacketLength: 255,
1366 },
1367 },
1368 flags: []string{"-mtu", "256"},
1369 shouldFail: true,
1370 expectedLocalError: "dtls: exceeded maximum packet length",
1371 },
1372 {
1373 name: "CertMismatchRSA",
1374 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001375 // TODO(davidben): Add a TLS 1.3 version of this test.
1376 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001377 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001378 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001379 Bugs: ProtocolBugs{
1380 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1381 },
1382 },
1383 shouldFail: true,
1384 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1385 },
1386 {
1387 name: "CertMismatchECDSA",
1388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001389 // TODO(davidben): Add a TLS 1.3 version of this test.
1390 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001391 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001392 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001393 Bugs: ProtocolBugs{
1394 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1395 },
1396 },
1397 shouldFail: true,
1398 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1399 },
1400 {
1401 name: "EmptyCertificateList",
1402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001403 // TODO(davidben): Add a TLS 1.3 version of this test.
1404 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001405 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1406 Bugs: ProtocolBugs{
1407 EmptyCertificateList: true,
1408 },
1409 },
1410 shouldFail: true,
1411 expectedError: ":DECODE_ERROR:",
1412 },
1413 {
1414 name: "TLSFatalBadPackets",
1415 damageFirstWrite: true,
1416 shouldFail: true,
1417 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1418 },
1419 {
1420 protocol: dtls,
1421 name: "DTLSIgnoreBadPackets",
1422 damageFirstWrite: true,
1423 },
1424 {
1425 protocol: dtls,
1426 name: "DTLSIgnoreBadPackets-Async",
1427 damageFirstWrite: true,
1428 flags: []string{"-async"},
1429 },
1430 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001431 name: "AppDataBeforeHandshake",
1432 config: Config{
1433 Bugs: ProtocolBugs{
1434 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":UNEXPECTED_RECORD:",
1439 },
1440 {
1441 name: "AppDataBeforeHandshake-Empty",
1442 config: Config{
1443 Bugs: ProtocolBugs{
1444 AppDataBeforeHandshake: []byte{},
1445 },
1446 },
1447 shouldFail: true,
1448 expectedError: ":UNEXPECTED_RECORD:",
1449 },
1450 {
1451 protocol: dtls,
1452 name: "AppDataBeforeHandshake-DTLS",
1453 config: Config{
1454 Bugs: ProtocolBugs{
1455 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1456 },
1457 },
1458 shouldFail: true,
1459 expectedError: ":UNEXPECTED_RECORD:",
1460 },
1461 {
1462 protocol: dtls,
1463 name: "AppDataBeforeHandshake-DTLS-Empty",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 AppDataBeforeHandshake: []byte{},
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":UNEXPECTED_RECORD:",
1471 },
1472 {
Adam Langley7c803a62015-06-15 15:35:05 -07001473 name: "AppDataAfterChangeCipherSpec",
1474 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001475 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001476 Bugs: ProtocolBugs{
1477 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1478 },
1479 },
1480 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001481 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001482 },
1483 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001484 name: "AppDataAfterChangeCipherSpec-Empty",
1485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001486 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001487 Bugs: ProtocolBugs{
1488 AppDataAfterChangeCipherSpec: []byte{},
1489 },
1490 },
1491 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001492 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001493 },
1494 {
Adam Langley7c803a62015-06-15 15:35:05 -07001495 protocol: dtls,
1496 name: "AppDataAfterChangeCipherSpec-DTLS",
1497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001498 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001499 Bugs: ProtocolBugs{
1500 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1501 },
1502 },
1503 // BoringSSL's DTLS implementation will drop the out-of-order
1504 // application data.
1505 },
1506 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001507 protocol: dtls,
1508 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1509 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001510 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001511 Bugs: ProtocolBugs{
1512 AppDataAfterChangeCipherSpec: []byte{},
1513 },
1514 },
1515 // BoringSSL's DTLS implementation will drop the out-of-order
1516 // application data.
1517 },
1518 {
Adam Langley7c803a62015-06-15 15:35:05 -07001519 name: "AlertAfterChangeCipherSpec",
1520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001521 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001522 Bugs: ProtocolBugs{
1523 AlertAfterChangeCipherSpec: alertRecordOverflow,
1524 },
1525 },
1526 shouldFail: true,
1527 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1528 },
1529 {
1530 protocol: dtls,
1531 name: "AlertAfterChangeCipherSpec-DTLS",
1532 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001533 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001534 Bugs: ProtocolBugs{
1535 AlertAfterChangeCipherSpec: alertRecordOverflow,
1536 },
1537 },
1538 shouldFail: true,
1539 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1540 },
1541 {
1542 protocol: dtls,
1543 name: "ReorderHandshakeFragments-Small-DTLS",
1544 config: Config{
1545 Bugs: ProtocolBugs{
1546 ReorderHandshakeFragments: true,
1547 // Small enough that every handshake message is
1548 // fragmented.
1549 MaxHandshakeRecordLength: 2,
1550 },
1551 },
1552 },
1553 {
1554 protocol: dtls,
1555 name: "ReorderHandshakeFragments-Large-DTLS",
1556 config: Config{
1557 Bugs: ProtocolBugs{
1558 ReorderHandshakeFragments: true,
1559 // Large enough that no handshake message is
1560 // fragmented.
1561 MaxHandshakeRecordLength: 2048,
1562 },
1563 },
1564 },
1565 {
1566 protocol: dtls,
1567 name: "MixCompleteMessageWithFragments-DTLS",
1568 config: Config{
1569 Bugs: ProtocolBugs{
1570 ReorderHandshakeFragments: true,
1571 MixCompleteMessageWithFragments: true,
1572 MaxHandshakeRecordLength: 2,
1573 },
1574 },
1575 },
1576 {
1577 name: "SendInvalidRecordType",
1578 config: Config{
1579 Bugs: ProtocolBugs{
1580 SendInvalidRecordType: true,
1581 },
1582 },
1583 shouldFail: true,
1584 expectedError: ":UNEXPECTED_RECORD:",
1585 },
1586 {
1587 protocol: dtls,
1588 name: "SendInvalidRecordType-DTLS",
1589 config: Config{
1590 Bugs: ProtocolBugs{
1591 SendInvalidRecordType: true,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":UNEXPECTED_RECORD:",
1596 },
1597 {
1598 name: "FalseStart-SkipServerSecondLeg",
1599 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001600 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001601 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1602 NextProtos: []string{"foo"},
1603 Bugs: ProtocolBugs{
1604 SkipNewSessionTicket: true,
1605 SkipChangeCipherSpec: true,
1606 SkipFinished: true,
1607 ExpectFalseStart: true,
1608 },
1609 },
1610 flags: []string{
1611 "-false-start",
1612 "-handshake-never-done",
1613 "-advertise-alpn", "\x03foo",
1614 },
1615 shimWritesFirst: true,
1616 shouldFail: true,
1617 expectedError: ":UNEXPECTED_RECORD:",
1618 },
1619 {
1620 name: "FalseStart-SkipServerSecondLeg-Implicit",
1621 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001622 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1624 NextProtos: []string{"foo"},
1625 Bugs: ProtocolBugs{
1626 SkipNewSessionTicket: true,
1627 SkipChangeCipherSpec: true,
1628 SkipFinished: true,
1629 },
1630 },
1631 flags: []string{
1632 "-implicit-handshake",
1633 "-false-start",
1634 "-handshake-never-done",
1635 "-advertise-alpn", "\x03foo",
1636 },
1637 shouldFail: true,
1638 expectedError: ":UNEXPECTED_RECORD:",
1639 },
1640 {
1641 testType: serverTest,
1642 name: "FailEarlyCallback",
1643 flags: []string{"-fail-early-callback"},
1644 shouldFail: true,
1645 expectedError: ":CONNECTION_REJECTED:",
1646 expectedLocalError: "remote error: access denied",
1647 },
1648 {
1649 name: "WrongMessageType",
1650 config: Config{
1651 Bugs: ProtocolBugs{
1652 WrongCertificateMessageType: true,
1653 },
1654 },
1655 shouldFail: true,
1656 expectedError: ":UNEXPECTED_MESSAGE:",
1657 expectedLocalError: "remote error: unexpected message",
1658 },
1659 {
1660 protocol: dtls,
1661 name: "WrongMessageType-DTLS",
1662 config: Config{
1663 Bugs: ProtocolBugs{
1664 WrongCertificateMessageType: true,
1665 },
1666 },
1667 shouldFail: true,
1668 expectedError: ":UNEXPECTED_MESSAGE:",
1669 expectedLocalError: "remote error: unexpected message",
1670 },
1671 {
1672 protocol: dtls,
1673 name: "FragmentMessageTypeMismatch-DTLS",
1674 config: Config{
1675 Bugs: ProtocolBugs{
1676 MaxHandshakeRecordLength: 2,
1677 FragmentMessageTypeMismatch: true,
1678 },
1679 },
1680 shouldFail: true,
1681 expectedError: ":FRAGMENT_MISMATCH:",
1682 },
1683 {
1684 protocol: dtls,
1685 name: "FragmentMessageLengthMismatch-DTLS",
1686 config: Config{
1687 Bugs: ProtocolBugs{
1688 MaxHandshakeRecordLength: 2,
1689 FragmentMessageLengthMismatch: true,
1690 },
1691 },
1692 shouldFail: true,
1693 expectedError: ":FRAGMENT_MISMATCH:",
1694 },
1695 {
1696 protocol: dtls,
1697 name: "SplitFragments-Header-DTLS",
1698 config: Config{
1699 Bugs: ProtocolBugs{
1700 SplitFragments: 2,
1701 },
1702 },
1703 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001704 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001705 },
1706 {
1707 protocol: dtls,
1708 name: "SplitFragments-Boundary-DTLS",
1709 config: Config{
1710 Bugs: ProtocolBugs{
1711 SplitFragments: dtlsRecordHeaderLen,
1712 },
1713 },
1714 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001715 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001716 },
1717 {
1718 protocol: dtls,
1719 name: "SplitFragments-Body-DTLS",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 SplitFragments: dtlsRecordHeaderLen + 1,
1723 },
1724 },
1725 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001726 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001727 },
1728 {
1729 protocol: dtls,
1730 name: "SendEmptyFragments-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 SendEmptyFragments: true,
1734 },
1735 },
1736 },
1737 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001738 name: "BadFinished-Client",
1739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001740 // TODO(davidben): Add a TLS 1.3 version of this.
1741 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001742 Bugs: ProtocolBugs{
1743 BadFinished: true,
1744 },
1745 },
1746 shouldFail: true,
1747 expectedError: ":DIGEST_CHECK_FAILED:",
1748 },
1749 {
1750 testType: serverTest,
1751 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001753 // TODO(davidben): Add a TLS 1.3 version of this.
1754 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001755 Bugs: ProtocolBugs{
1756 BadFinished: true,
1757 },
1758 },
1759 shouldFail: true,
1760 expectedError: ":DIGEST_CHECK_FAILED:",
1761 },
1762 {
1763 name: "FalseStart-BadFinished",
1764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001765 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1767 NextProtos: []string{"foo"},
1768 Bugs: ProtocolBugs{
1769 BadFinished: true,
1770 ExpectFalseStart: true,
1771 },
1772 },
1773 flags: []string{
1774 "-false-start",
1775 "-handshake-never-done",
1776 "-advertise-alpn", "\x03foo",
1777 },
1778 shimWritesFirst: true,
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
1783 name: "NoFalseStart-NoALPN",
1784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001785 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1787 Bugs: ProtocolBugs{
1788 ExpectFalseStart: true,
1789 AlertBeforeFalseStartTest: alertAccessDenied,
1790 },
1791 },
1792 flags: []string{
1793 "-false-start",
1794 },
1795 shimWritesFirst: true,
1796 shouldFail: true,
1797 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1798 expectedLocalError: "tls: peer did not false start: EOF",
1799 },
1800 {
1801 name: "NoFalseStart-NoAEAD",
1802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001803 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1805 NextProtos: []string{"foo"},
1806 Bugs: ProtocolBugs{
1807 ExpectFalseStart: true,
1808 AlertBeforeFalseStartTest: alertAccessDenied,
1809 },
1810 },
1811 flags: []string{
1812 "-false-start",
1813 "-advertise-alpn", "\x03foo",
1814 },
1815 shimWritesFirst: true,
1816 shouldFail: true,
1817 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1818 expectedLocalError: "tls: peer did not false start: EOF",
1819 },
1820 {
1821 name: "NoFalseStart-RSA",
1822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001823 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001824 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1825 NextProtos: []string{"foo"},
1826 Bugs: ProtocolBugs{
1827 ExpectFalseStart: true,
1828 AlertBeforeFalseStartTest: alertAccessDenied,
1829 },
1830 },
1831 flags: []string{
1832 "-false-start",
1833 "-advertise-alpn", "\x03foo",
1834 },
1835 shimWritesFirst: true,
1836 shouldFail: true,
1837 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1838 expectedLocalError: "tls: peer did not false start: EOF",
1839 },
1840 {
1841 name: "NoFalseStart-DHE_RSA",
1842 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001843 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001844 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1845 NextProtos: []string{"foo"},
1846 Bugs: ProtocolBugs{
1847 ExpectFalseStart: true,
1848 AlertBeforeFalseStartTest: alertAccessDenied,
1849 },
1850 },
1851 flags: []string{
1852 "-false-start",
1853 "-advertise-alpn", "\x03foo",
1854 },
1855 shimWritesFirst: true,
1856 shouldFail: true,
1857 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1858 expectedLocalError: "tls: peer did not false start: EOF",
1859 },
1860 {
Adam Langley7c803a62015-06-15 15:35:05 -07001861 protocol: dtls,
1862 name: "SendSplitAlert-Sync",
1863 config: Config{
1864 Bugs: ProtocolBugs{
1865 SendSplitAlert: true,
1866 },
1867 },
1868 },
1869 {
1870 protocol: dtls,
1871 name: "SendSplitAlert-Async",
1872 config: Config{
1873 Bugs: ProtocolBugs{
1874 SendSplitAlert: true,
1875 },
1876 },
1877 flags: []string{"-async"},
1878 },
1879 {
1880 protocol: dtls,
1881 name: "PackDTLSHandshake",
1882 config: Config{
1883 Bugs: ProtocolBugs{
1884 MaxHandshakeRecordLength: 2,
1885 PackHandshakeFragments: 20,
1886 PackHandshakeRecords: 200,
1887 },
1888 },
1889 },
1890 {
Adam Langley7c803a62015-06-15 15:35:05 -07001891 name: "SendEmptyRecords-Pass",
1892 sendEmptyRecords: 32,
1893 },
1894 {
1895 name: "SendEmptyRecords",
1896 sendEmptyRecords: 33,
1897 shouldFail: true,
1898 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1899 },
1900 {
1901 name: "SendEmptyRecords-Async",
1902 sendEmptyRecords: 33,
1903 flags: []string{"-async"},
1904 shouldFail: true,
1905 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1906 },
1907 {
1908 name: "SendWarningAlerts-Pass",
1909 sendWarningAlerts: 4,
1910 },
1911 {
1912 protocol: dtls,
1913 name: "SendWarningAlerts-DTLS-Pass",
1914 sendWarningAlerts: 4,
1915 },
1916 {
1917 name: "SendWarningAlerts",
1918 sendWarningAlerts: 5,
1919 shouldFail: true,
1920 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1921 },
1922 {
1923 name: "SendWarningAlerts-Async",
1924 sendWarningAlerts: 5,
1925 flags: []string{"-async"},
1926 shouldFail: true,
1927 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1928 },
David Benjaminba4594a2015-06-18 18:36:15 -04001929 {
1930 name: "EmptySessionID",
1931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001932 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001933 SessionTicketsDisabled: true,
1934 },
1935 noSessionCache: true,
1936 flags: []string{"-expect-no-session"},
1937 },
David Benjamin30789da2015-08-29 22:56:45 -04001938 {
1939 name: "Unclean-Shutdown",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 NoCloseNotify: true,
1943 ExpectCloseNotify: true,
1944 },
1945 },
1946 shimShutsDown: true,
1947 flags: []string{"-check-close-notify"},
1948 shouldFail: true,
1949 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1950 },
1951 {
1952 name: "Unclean-Shutdown-Ignored",
1953 config: Config{
1954 Bugs: ProtocolBugs{
1955 NoCloseNotify: true,
1956 },
1957 },
1958 shimShutsDown: true,
1959 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001960 {
David Benjaminfa214e42016-05-10 17:03:10 -04001961 name: "Unclean-Shutdown-Alert",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 SendAlertOnShutdown: alertDecompressionFailure,
1965 ExpectCloseNotify: true,
1966 },
1967 },
1968 shimShutsDown: true,
1969 flags: []string{"-check-close-notify"},
1970 shouldFail: true,
1971 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1972 },
1973 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001974 name: "LargePlaintext",
1975 config: Config{
1976 Bugs: ProtocolBugs{
1977 SendLargeRecords: true,
1978 },
1979 },
1980 messageLen: maxPlaintext + 1,
1981 shouldFail: true,
1982 expectedError: ":DATA_LENGTH_TOO_LONG:",
1983 },
1984 {
1985 protocol: dtls,
1986 name: "LargePlaintext-DTLS",
1987 config: Config{
1988 Bugs: ProtocolBugs{
1989 SendLargeRecords: true,
1990 },
1991 },
1992 messageLen: maxPlaintext + 1,
1993 shouldFail: true,
1994 expectedError: ":DATA_LENGTH_TOO_LONG:",
1995 },
1996 {
1997 name: "LargeCiphertext",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SendLargeRecords: true,
2001 },
2002 },
2003 messageLen: maxPlaintext * 2,
2004 shouldFail: true,
2005 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2006 },
2007 {
2008 protocol: dtls,
2009 name: "LargeCiphertext-DTLS",
2010 config: Config{
2011 Bugs: ProtocolBugs{
2012 SendLargeRecords: true,
2013 },
2014 },
2015 messageLen: maxPlaintext * 2,
2016 // Unlike the other four cases, DTLS drops records which
2017 // are invalid before authentication, so the connection
2018 // does not fail.
2019 expectMessageDropped: true,
2020 },
David Benjamindd6fed92015-10-23 17:41:12 -04002021 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002022 // In TLS 1.2 and below, empty NewSessionTicket messages
2023 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002024 name: "SendEmptySessionTicket",
2025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002026 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002027 Bugs: ProtocolBugs{
2028 SendEmptySessionTicket: true,
2029 FailIfSessionOffered: true,
2030 },
2031 },
2032 flags: []string{"-expect-no-session"},
2033 resumeSession: true,
2034 expectResumeRejected: true,
2035 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002036 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002037 name: "BadHelloRequest-1",
2038 renegotiate: 1,
2039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002040 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002041 Bugs: ProtocolBugs{
2042 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2043 },
2044 },
2045 flags: []string{
2046 "-renegotiate-freely",
2047 "-expect-total-renegotiations", "1",
2048 },
2049 shouldFail: true,
2050 expectedError: ":BAD_HELLO_REQUEST:",
2051 },
2052 {
2053 name: "BadHelloRequest-2",
2054 renegotiate: 1,
2055 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002056 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002057 Bugs: ProtocolBugs{
2058 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2059 },
2060 },
2061 flags: []string{
2062 "-renegotiate-freely",
2063 "-expect-total-renegotiations", "1",
2064 },
2065 shouldFail: true,
2066 expectedError: ":BAD_HELLO_REQUEST:",
2067 },
David Benjaminef1b0092015-11-21 14:05:44 -05002068 {
2069 testType: serverTest,
2070 name: "SupportTicketsWithSessionID",
2071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002072 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002073 SessionTicketsDisabled: true,
2074 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002075 resumeConfig: &Config{
2076 MaxVersion: VersionTLS12,
2077 },
David Benjaminef1b0092015-11-21 14:05:44 -05002078 resumeSession: true,
2079 },
Adam Langley7c803a62015-06-15 15:35:05 -07002080 }
Adam Langley7c803a62015-06-15 15:35:05 -07002081 testCases = append(testCases, basicTests...)
2082}
2083
Adam Langley95c29f32014-06-20 12:00:00 -07002084func addCipherSuiteTests() {
2085 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002086 const psk = "12345"
2087 const pskIdentity = "luggage combo"
2088
Adam Langley95c29f32014-06-20 12:00:00 -07002089 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002090 var certFile string
2091 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002092 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002093 cert = ecdsaP256Certificate
2094 certFile = ecdsaP256CertificateFile
2095 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002096 } else {
David Benjamin33863262016-07-08 17:20:12 -07002097 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002098 certFile = rsaCertificateFile
2099 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002100 }
2101
David Benjamin48cae082014-10-27 01:06:24 -04002102 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002103 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002104 flags = append(flags,
2105 "-psk", psk,
2106 "-psk-identity", pskIdentity)
2107 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002108 if hasComponent(suite.name, "NULL") {
2109 // NULL ciphers must be explicitly enabled.
2110 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2111 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002112 if hasComponent(suite.name, "CECPQ1") {
2113 // CECPQ1 ciphers must be explicitly enabled.
2114 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2115 }
David Benjamin48cae082014-10-27 01:06:24 -04002116
Adam Langley95c29f32014-06-20 12:00:00 -07002117 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002118 for _, protocol := range []protocol{tls, dtls} {
2119 var prefix string
2120 if protocol == dtls {
2121 if !ver.hasDTLS {
2122 continue
2123 }
2124 prefix = "D"
2125 }
Adam Langley95c29f32014-06-20 12:00:00 -07002126
David Benjamin0407e762016-06-17 16:41:18 -04002127 var shouldServerFail, shouldClientFail bool
2128 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2129 // BoringSSL clients accept ECDHE on SSLv3, but
2130 // a BoringSSL server will never select it
2131 // because the extension is missing.
2132 shouldServerFail = true
2133 }
2134 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2135 shouldClientFail = true
2136 shouldServerFail = true
2137 }
Nick Harper1fd39d82016-06-14 18:14:35 -07002138 if !isTLS13Suite(suite.name) && ver.version == VersionTLS13 {
2139 shouldClientFail = true
2140 shouldServerFail = true
2141 }
David Benjamin0407e762016-06-17 16:41:18 -04002142 if !isDTLSCipher(suite.name) && protocol == dtls {
2143 shouldClientFail = true
2144 shouldServerFail = true
2145 }
David Benjamin4298d772015-12-19 00:18:25 -05002146
David Benjamin0407e762016-06-17 16:41:18 -04002147 var expectedServerError, expectedClientError string
2148 if shouldServerFail {
2149 expectedServerError = ":NO_SHARED_CIPHER:"
2150 }
2151 if shouldClientFail {
2152 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2153 }
David Benjamin025b3d32014-07-01 19:53:04 -04002154
David Benjamin6fd297b2014-08-11 18:43:38 -04002155 testCases = append(testCases, testCase{
2156 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002157 protocol: protocol,
2158
2159 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002160 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002161 MinVersion: ver.version,
2162 MaxVersion: ver.version,
2163 CipherSuites: []uint16{suite.id},
2164 Certificates: []Certificate{cert},
2165 PreSharedKey: []byte(psk),
2166 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002167 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002168 EnableAllCiphers: shouldServerFail,
2169 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002170 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002171 },
2172 certFile: certFile,
2173 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002174 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002175 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002176 shouldFail: shouldServerFail,
2177 expectedError: expectedServerError,
2178 })
2179
2180 testCases = append(testCases, testCase{
2181 testType: clientTest,
2182 protocol: protocol,
2183 name: prefix + ver.name + "-" + suite.name + "-client",
2184 config: Config{
2185 MinVersion: ver.version,
2186 MaxVersion: ver.version,
2187 CipherSuites: []uint16{suite.id},
2188 Certificates: []Certificate{cert},
2189 PreSharedKey: []byte(psk),
2190 PreSharedKeyIdentity: pskIdentity,
2191 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002192 EnableAllCiphers: shouldClientFail,
2193 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002194 },
2195 },
2196 flags: flags,
2197 resumeSession: true,
2198 shouldFail: shouldClientFail,
2199 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002200 })
David Benjamin2c99d282015-09-01 10:23:00 -04002201
Nick Harper1fd39d82016-06-14 18:14:35 -07002202 if !shouldClientFail {
2203 // Ensure the maximum record size is accepted.
2204 testCases = append(testCases, testCase{
2205 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2206 config: Config{
2207 MinVersion: ver.version,
2208 MaxVersion: ver.version,
2209 CipherSuites: []uint16{suite.id},
2210 Certificates: []Certificate{cert},
2211 PreSharedKey: []byte(psk),
2212 PreSharedKeyIdentity: pskIdentity,
2213 },
2214 flags: flags,
2215 messageLen: maxPlaintext,
2216 })
2217 }
2218 }
David Benjamin2c99d282015-09-01 10:23:00 -04002219 }
Adam Langley95c29f32014-06-20 12:00:00 -07002220 }
Adam Langleya7997f12015-05-14 17:38:50 -07002221
2222 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002223 name: "NoSharedCipher",
2224 config: Config{
2225 // TODO(davidben): Add a TLS 1.3 version of this test.
2226 MaxVersion: VersionTLS12,
2227 CipherSuites: []uint16{},
2228 },
2229 shouldFail: true,
2230 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2231 })
2232
2233 testCases = append(testCases, testCase{
2234 name: "UnsupportedCipherSuite",
2235 config: Config{
2236 MaxVersion: VersionTLS12,
2237 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2238 Bugs: ProtocolBugs{
2239 IgnorePeerCipherPreferences: true,
2240 },
2241 },
2242 flags: []string{"-cipher", "DEFAULT:!RC4"},
2243 shouldFail: true,
2244 expectedError: ":WRONG_CIPHER_RETURNED:",
2245 })
2246
2247 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002248 name: "WeakDH",
2249 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002250 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002251 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2252 Bugs: ProtocolBugs{
2253 // This is a 1023-bit prime number, generated
2254 // with:
2255 // openssl gendh 1023 | openssl asn1parse -i
2256 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2257 },
2258 },
2259 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002260 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002261 })
Adam Langleycef75832015-09-03 14:51:12 -07002262
David Benjamincd24a392015-11-11 13:23:05 -08002263 testCases = append(testCases, testCase{
2264 name: "SillyDH",
2265 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002266 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002267 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2268 Bugs: ProtocolBugs{
2269 // This is a 4097-bit prime number, generated
2270 // with:
2271 // openssl gendh 4097 | openssl asn1parse -i
2272 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2273 },
2274 },
2275 shouldFail: true,
2276 expectedError: ":DH_P_TOO_LONG:",
2277 })
2278
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002279 // This test ensures that Diffie-Hellman public values are padded with
2280 // zeros so that they're the same length as the prime. This is to avoid
2281 // hitting a bug in yaSSL.
2282 testCases = append(testCases, testCase{
2283 testType: serverTest,
2284 name: "DHPublicValuePadded",
2285 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002286 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002287 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2288 Bugs: ProtocolBugs{
2289 RequireDHPublicValueLen: (1025 + 7) / 8,
2290 },
2291 },
2292 flags: []string{"-use-sparse-dh-prime"},
2293 })
David Benjamincd24a392015-11-11 13:23:05 -08002294
David Benjamin241ae832016-01-15 03:04:54 -05002295 // The server must be tolerant to bogus ciphers.
2296 const bogusCipher = 0x1234
2297 testCases = append(testCases, testCase{
2298 testType: serverTest,
2299 name: "UnknownCipher",
2300 config: Config{
2301 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2302 },
2303 })
2304
Adam Langleycef75832015-09-03 14:51:12 -07002305 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2306 // 1.1 specific cipher suite settings. A server is setup with the given
2307 // cipher lists and then a connection is made for each member of
2308 // expectations. The cipher suite that the server selects must match
2309 // the specified one.
2310 var versionSpecificCiphersTest = []struct {
2311 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2312 // expectations is a map from TLS version to cipher suite id.
2313 expectations map[uint16]uint16
2314 }{
2315 {
2316 // Test that the null case (where no version-specific ciphers are set)
2317 // works as expected.
2318 "RC4-SHA:AES128-SHA", // default ciphers
2319 "", // no ciphers specifically for TLS ≥ 1.0
2320 "", // no ciphers specifically for TLS ≥ 1.1
2321 map[uint16]uint16{
2322 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2323 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2324 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2325 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2326 },
2327 },
2328 {
2329 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2330 // cipher.
2331 "RC4-SHA:AES128-SHA", // default
2332 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2333 "", // no ciphers specifically for TLS ≥ 1.1
2334 map[uint16]uint16{
2335 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2336 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2337 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2338 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2339 },
2340 },
2341 {
2342 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2343 // cipher.
2344 "RC4-SHA:AES128-SHA", // default
2345 "", // no ciphers specifically for TLS ≥ 1.0
2346 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2347 map[uint16]uint16{
2348 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2349 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2350 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2351 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2352 },
2353 },
2354 {
2355 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2356 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2357 "RC4-SHA:AES128-SHA", // default
2358 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2359 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2360 map[uint16]uint16{
2361 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2362 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2363 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2364 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2365 },
2366 },
2367 }
2368
2369 for i, test := range versionSpecificCiphersTest {
2370 for version, expectedCipherSuite := range test.expectations {
2371 flags := []string{"-cipher", test.ciphersDefault}
2372 if len(test.ciphersTLS10) > 0 {
2373 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2374 }
2375 if len(test.ciphersTLS11) > 0 {
2376 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2377 }
2378
2379 testCases = append(testCases, testCase{
2380 testType: serverTest,
2381 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2382 config: Config{
2383 MaxVersion: version,
2384 MinVersion: version,
2385 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2386 },
2387 flags: flags,
2388 expectedCipher: expectedCipherSuite,
2389 })
2390 }
2391 }
Adam Langley95c29f32014-06-20 12:00:00 -07002392}
2393
2394func addBadECDSASignatureTests() {
2395 for badR := BadValue(1); badR < NumBadValues; badR++ {
2396 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002397 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002398 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2399 config: Config{
2400 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002401 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002402 Bugs: ProtocolBugs{
2403 BadECDSAR: badR,
2404 BadECDSAS: badS,
2405 },
2406 },
2407 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002408 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002409 })
2410 }
2411 }
2412}
2413
Adam Langley80842bd2014-06-20 12:00:00 -07002414func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002415 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002416 name: "MaxCBCPadding",
2417 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002418 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002419 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2420 Bugs: ProtocolBugs{
2421 MaxPadding: true,
2422 },
2423 },
2424 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2425 })
David Benjamin025b3d32014-07-01 19:53:04 -04002426 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002427 name: "BadCBCPadding",
2428 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002429 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002430 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2431 Bugs: ProtocolBugs{
2432 PaddingFirstByteBad: true,
2433 },
2434 },
2435 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002436 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002437 })
2438 // OpenSSL previously had an issue where the first byte of padding in
2439 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002440 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002441 name: "BadCBCPadding255",
2442 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002443 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2445 Bugs: ProtocolBugs{
2446 MaxPadding: true,
2447 PaddingFirstByteBadIf255: true,
2448 },
2449 },
2450 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2451 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002452 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002453 })
2454}
2455
Kenny Root7fdeaf12014-08-05 15:23:37 -07002456func addCBCSplittingTests() {
2457 testCases = append(testCases, testCase{
2458 name: "CBCRecordSplitting",
2459 config: Config{
2460 MaxVersion: VersionTLS10,
2461 MinVersion: VersionTLS10,
2462 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2463 },
David Benjaminac8302a2015-09-01 17:18:15 -04002464 messageLen: -1, // read until EOF
2465 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002466 flags: []string{
2467 "-async",
2468 "-write-different-record-sizes",
2469 "-cbc-record-splitting",
2470 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002471 })
2472 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002473 name: "CBCRecordSplittingPartialWrite",
2474 config: Config{
2475 MaxVersion: VersionTLS10,
2476 MinVersion: VersionTLS10,
2477 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2478 },
2479 messageLen: -1, // read until EOF
2480 flags: []string{
2481 "-async",
2482 "-write-different-record-sizes",
2483 "-cbc-record-splitting",
2484 "-partial-write",
2485 },
2486 })
2487}
2488
David Benjamin636293b2014-07-08 17:59:18 -04002489func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002490 // Add a dummy cert pool to stress certificate authority parsing.
2491 // TODO(davidben): Add tests that those values parse out correctly.
2492 certPool := x509.NewCertPool()
2493 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2494 if err != nil {
2495 panic(err)
2496 }
2497 certPool.AddCert(cert)
2498
David Benjamin636293b2014-07-08 17:59:18 -04002499 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002500 testCases = append(testCases, testCase{
2501 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002502 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002503 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002504 MinVersion: ver.version,
2505 MaxVersion: ver.version,
2506 ClientAuth: RequireAnyClientCert,
2507 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002508 },
2509 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002510 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2511 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002512 },
2513 })
2514 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002515 testType: serverTest,
2516 name: ver.name + "-Server-ClientAuth-RSA",
2517 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002518 MinVersion: ver.version,
2519 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002520 Certificates: []Certificate{rsaCertificate},
2521 },
2522 flags: []string{"-require-any-client-certificate"},
2523 })
David Benjamine098ec22014-08-27 23:13:20 -04002524 if ver.version != VersionSSL30 {
2525 testCases = append(testCases, testCase{
2526 testType: serverTest,
2527 name: ver.name + "-Server-ClientAuth-ECDSA",
2528 config: Config{
2529 MinVersion: ver.version,
2530 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002531 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002532 },
2533 flags: []string{"-require-any-client-certificate"},
2534 })
2535 testCases = append(testCases, testCase{
2536 testType: clientTest,
2537 name: ver.name + "-Client-ClientAuth-ECDSA",
2538 config: Config{
2539 MinVersion: ver.version,
2540 MaxVersion: ver.version,
2541 ClientAuth: RequireAnyClientCert,
2542 ClientCAs: certPool,
2543 },
2544 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002545 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2546 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002547 },
2548 })
2549 }
David Benjamin636293b2014-07-08 17:59:18 -04002550 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002551
Nick Harper1fd39d82016-06-14 18:14:35 -07002552 // TODO(davidben): These tests will need TLS 1.3 versions when the
2553 // handshake is separate.
2554
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002555 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002556 name: "NoClientCertificate",
2557 config: Config{
2558 MaxVersion: VersionTLS12,
2559 ClientAuth: RequireAnyClientCert,
2560 },
2561 shouldFail: true,
2562 expectedLocalError: "client didn't provide a certificate",
2563 })
2564
2565 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002566 testType: serverTest,
2567 name: "RequireAnyClientCertificate",
2568 config: Config{
2569 MaxVersion: VersionTLS12,
2570 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002571 flags: []string{"-require-any-client-certificate"},
2572 shouldFail: true,
2573 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2574 })
2575
2576 testCases = append(testCases, testCase{
2577 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002578 name: "RequireAnyClientCertificate-SSL3",
2579 config: Config{
2580 MaxVersion: VersionSSL30,
2581 },
2582 flags: []string{"-require-any-client-certificate"},
2583 shouldFail: true,
2584 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2585 })
2586
2587 testCases = append(testCases, testCase{
2588 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002589 name: "SkipClientCertificate",
2590 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002591 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002592 Bugs: ProtocolBugs{
2593 SkipClientCertificate: true,
2594 },
2595 },
2596 // Setting SSL_VERIFY_PEER allows anonymous clients.
2597 flags: []string{"-verify-peer"},
2598 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002599 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002600 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002601
2602 // Client auth is only legal in certificate-based ciphers.
2603 testCases = append(testCases, testCase{
2604 testType: clientTest,
2605 name: "ClientAuth-PSK",
2606 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002607 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002608 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2609 PreSharedKey: []byte("secret"),
2610 ClientAuth: RequireAnyClientCert,
2611 },
2612 flags: []string{
2613 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2614 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2615 "-psk", "secret",
2616 },
2617 shouldFail: true,
2618 expectedError: ":UNEXPECTED_MESSAGE:",
2619 })
2620 testCases = append(testCases, testCase{
2621 testType: clientTest,
2622 name: "ClientAuth-ECDHE_PSK",
2623 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002624 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002625 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2626 PreSharedKey: []byte("secret"),
2627 ClientAuth: RequireAnyClientCert,
2628 },
2629 flags: []string{
2630 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2631 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2632 "-psk", "secret",
2633 },
2634 shouldFail: true,
2635 expectedError: ":UNEXPECTED_MESSAGE:",
2636 })
David Benjamin636293b2014-07-08 17:59:18 -04002637}
2638
Adam Langley75712922014-10-10 16:23:43 -07002639func addExtendedMasterSecretTests() {
2640 const expectEMSFlag = "-expect-extended-master-secret"
2641
2642 for _, with := range []bool{false, true} {
2643 prefix := "No"
2644 var flags []string
2645 if with {
2646 prefix = ""
2647 flags = []string{expectEMSFlag}
2648 }
2649
2650 for _, isClient := range []bool{false, true} {
2651 suffix := "-Server"
2652 testType := serverTest
2653 if isClient {
2654 suffix = "-Client"
2655 testType = clientTest
2656 }
2657
David Benjamin4c3ddf72016-06-29 18:13:53 -04002658 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2659 // test that the extension is irrelevant, but the API
2660 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002661 for _, ver := range tlsVersions {
2662 test := testCase{
2663 testType: testType,
2664 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2665 config: Config{
2666 MinVersion: ver.version,
2667 MaxVersion: ver.version,
2668 Bugs: ProtocolBugs{
2669 NoExtendedMasterSecret: !with,
2670 RequireExtendedMasterSecret: with,
2671 },
2672 },
David Benjamin48cae082014-10-27 01:06:24 -04002673 flags: flags,
2674 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002675 }
2676 if test.shouldFail {
2677 test.expectedLocalError = "extended master secret required but not supported by peer"
2678 }
2679 testCases = append(testCases, test)
2680 }
2681 }
2682 }
2683
Adam Langleyba5934b2015-06-02 10:50:35 -07002684 for _, isClient := range []bool{false, true} {
2685 for _, supportedInFirstConnection := range []bool{false, true} {
2686 for _, supportedInResumeConnection := range []bool{false, true} {
2687 boolToWord := func(b bool) string {
2688 if b {
2689 return "Yes"
2690 }
2691 return "No"
2692 }
2693 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2694 if isClient {
2695 suffix += "Client"
2696 } else {
2697 suffix += "Server"
2698 }
2699
2700 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002701 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002702 Bugs: ProtocolBugs{
2703 RequireExtendedMasterSecret: true,
2704 },
2705 }
2706
2707 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002708 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002709 Bugs: ProtocolBugs{
2710 NoExtendedMasterSecret: true,
2711 },
2712 }
2713
2714 test := testCase{
2715 name: "ExtendedMasterSecret-" + suffix,
2716 resumeSession: true,
2717 }
2718
2719 if !isClient {
2720 test.testType = serverTest
2721 }
2722
2723 if supportedInFirstConnection {
2724 test.config = supportedConfig
2725 } else {
2726 test.config = noSupportConfig
2727 }
2728
2729 if supportedInResumeConnection {
2730 test.resumeConfig = &supportedConfig
2731 } else {
2732 test.resumeConfig = &noSupportConfig
2733 }
2734
2735 switch suffix {
2736 case "YesToYes-Client", "YesToYes-Server":
2737 // When a session is resumed, it should
2738 // still be aware that its master
2739 // secret was generated via EMS and
2740 // thus it's safe to use tls-unique.
2741 test.flags = []string{expectEMSFlag}
2742 case "NoToYes-Server":
2743 // If an original connection did not
2744 // contain EMS, but a resumption
2745 // handshake does, then a server should
2746 // not resume the session.
2747 test.expectResumeRejected = true
2748 case "YesToNo-Server":
2749 // Resuming an EMS session without the
2750 // EMS extension should cause the
2751 // server to abort the connection.
2752 test.shouldFail = true
2753 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2754 case "NoToYes-Client":
2755 // A client should abort a connection
2756 // where the server resumed a non-EMS
2757 // session but echoed the EMS
2758 // extension.
2759 test.shouldFail = true
2760 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2761 case "YesToNo-Client":
2762 // A client should abort a connection
2763 // where the server didn't echo EMS
2764 // when the session used it.
2765 test.shouldFail = true
2766 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2767 }
2768
2769 testCases = append(testCases, test)
2770 }
2771 }
2772 }
Adam Langley75712922014-10-10 16:23:43 -07002773}
2774
David Benjamin582ba042016-07-07 12:33:25 -07002775type stateMachineTestConfig struct {
2776 protocol protocol
2777 async bool
2778 splitHandshake, packHandshakeFlight bool
2779}
2780
David Benjamin43ec06f2014-08-05 02:28:57 -04002781// Adds tests that try to cover the range of the handshake state machine, under
2782// various conditions. Some of these are redundant with other tests, but they
2783// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002784func addAllStateMachineCoverageTests() {
2785 for _, async := range []bool{false, true} {
2786 for _, protocol := range []protocol{tls, dtls} {
2787 addStateMachineCoverageTests(stateMachineTestConfig{
2788 protocol: protocol,
2789 async: async,
2790 })
2791 addStateMachineCoverageTests(stateMachineTestConfig{
2792 protocol: protocol,
2793 async: async,
2794 splitHandshake: true,
2795 })
2796 if protocol == tls {
2797 addStateMachineCoverageTests(stateMachineTestConfig{
2798 protocol: protocol,
2799 async: async,
2800 packHandshakeFlight: true,
2801 })
2802 }
2803 }
2804 }
2805}
2806
2807func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002808 var tests []testCase
2809
2810 // Basic handshake, with resumption. Client and server,
2811 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002812 //
2813 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2814 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002815 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002816 name: "Basic-Client",
2817 config: Config{
2818 MaxVersion: VersionTLS12,
2819 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002820 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002821 // Ensure session tickets are used, not session IDs.
2822 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002823 })
2824 tests = append(tests, testCase{
2825 name: "Basic-Client-RenewTicket",
2826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002827 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002828 Bugs: ProtocolBugs{
2829 RenewTicketOnResume: true,
2830 },
2831 },
David Benjaminba4594a2015-06-18 18:36:15 -04002832 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002833 resumeSession: true,
2834 })
2835 tests = append(tests, testCase{
2836 name: "Basic-Client-NoTicket",
2837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002838 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002839 SessionTicketsDisabled: true,
2840 },
2841 resumeSession: true,
2842 })
2843 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002844 name: "Basic-Client-Implicit",
2845 config: Config{
2846 MaxVersion: VersionTLS12,
2847 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002848 flags: []string{"-implicit-handshake"},
2849 resumeSession: true,
2850 })
2851 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002852 testType: serverTest,
2853 name: "Basic-Server",
2854 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002855 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002856 Bugs: ProtocolBugs{
2857 RequireSessionTickets: true,
2858 },
2859 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002860 resumeSession: true,
2861 })
2862 tests = append(tests, testCase{
2863 testType: serverTest,
2864 name: "Basic-Server-NoTickets",
2865 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002866 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002867 SessionTicketsDisabled: true,
2868 },
2869 resumeSession: true,
2870 })
2871 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002872 testType: serverTest,
2873 name: "Basic-Server-Implicit",
2874 config: Config{
2875 MaxVersion: VersionTLS12,
2876 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002877 flags: []string{"-implicit-handshake"},
2878 resumeSession: true,
2879 })
2880 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002881 testType: serverTest,
2882 name: "Basic-Server-EarlyCallback",
2883 config: Config{
2884 MaxVersion: VersionTLS12,
2885 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002886 flags: []string{"-use-early-callback"},
2887 resumeSession: true,
2888 })
2889
2890 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002891 //
2892 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002893 tests = append(tests, testCase{
2894 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002895 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002897 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002898 ClientAuth: RequestClientCert,
2899 },
2900 })
2901 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002902 testType: serverTest,
2903 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002904 config: Config{
2905 MaxVersion: VersionTLS12,
2906 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002907 // Setting SSL_VERIFY_PEER allows anonymous clients.
2908 flags: []string{"-verify-peer"},
2909 })
David Benjamin582ba042016-07-07 12:33:25 -07002910 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002911 tests = append(tests, testCase{
2912 testType: clientTest,
2913 name: "ClientAuth-NoCertificate-Client-SSL3",
2914 config: Config{
2915 MaxVersion: VersionSSL30,
2916 ClientAuth: RequestClientCert,
2917 },
2918 })
2919 tests = append(tests, testCase{
2920 testType: serverTest,
2921 name: "ClientAuth-NoCertificate-Server-SSL3",
2922 config: Config{
2923 MaxVersion: VersionSSL30,
2924 },
2925 // Setting SSL_VERIFY_PEER allows anonymous clients.
2926 flags: []string{"-verify-peer"},
2927 })
2928 }
2929 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002930 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002931 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002933 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002934 ClientAuth: RequireAnyClientCert,
2935 },
2936 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002937 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2938 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002939 },
2940 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002941 tests = append(tests, testCase{
2942 testType: clientTest,
2943 name: "ClientAuth-ECDSA-Client",
2944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002945 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002946 ClientAuth: RequireAnyClientCert,
2947 },
2948 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002949 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2950 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002951 },
2952 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002953 tests = append(tests, testCase{
2954 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04002955 name: "ClientAuth-NoCertificate-OldCallback",
2956 config: Config{
2957 MaxVersion: VersionTLS12,
2958 ClientAuth: RequestClientCert,
2959 },
2960 flags: []string{"-use-old-client-cert-callback"},
2961 })
2962 tests = append(tests, testCase{
2963 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002964 name: "ClientAuth-OldCallback",
2965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002966 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002967 ClientAuth: RequireAnyClientCert,
2968 },
2969 flags: []string{
2970 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2971 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2972 "-use-old-client-cert-callback",
2973 },
2974 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002975 tests = append(tests, testCase{
2976 testType: serverTest,
2977 name: "ClientAuth-Server",
2978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002979 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002980 Certificates: []Certificate{rsaCertificate},
2981 },
2982 flags: []string{"-require-any-client-certificate"},
2983 })
2984
David Benjamin4c3ddf72016-06-29 18:13:53 -04002985 // Test each key exchange on the server side for async keys.
2986 //
2987 // TODO(davidben): Add TLS 1.3 versions of these.
2988 tests = append(tests, testCase{
2989 testType: serverTest,
2990 name: "Basic-Server-RSA",
2991 config: Config{
2992 MaxVersion: VersionTLS12,
2993 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2994 },
2995 flags: []string{
2996 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2997 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2998 },
2999 })
3000 tests = append(tests, testCase{
3001 testType: serverTest,
3002 name: "Basic-Server-ECDHE-RSA",
3003 config: Config{
3004 MaxVersion: VersionTLS12,
3005 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3006 },
3007 flags: []string{
3008 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3009 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3010 },
3011 })
3012 tests = append(tests, testCase{
3013 testType: serverTest,
3014 name: "Basic-Server-ECDHE-ECDSA",
3015 config: Config{
3016 MaxVersion: VersionTLS12,
3017 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3018 },
3019 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003020 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3021 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003022 },
3023 })
3024
David Benjamin760b1dd2015-05-15 23:33:48 -04003025 // No session ticket support; server doesn't send NewSessionTicket.
3026 tests = append(tests, testCase{
3027 name: "SessionTicketsDisabled-Client",
3028 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003029 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003030 SessionTicketsDisabled: true,
3031 },
3032 })
3033 tests = append(tests, testCase{
3034 testType: serverTest,
3035 name: "SessionTicketsDisabled-Server",
3036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003037 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003038 SessionTicketsDisabled: true,
3039 },
3040 })
3041
3042 // Skip ServerKeyExchange in PSK key exchange if there's no
3043 // identity hint.
3044 tests = append(tests, testCase{
3045 name: "EmptyPSKHint-Client",
3046 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003047 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003048 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3049 PreSharedKey: []byte("secret"),
3050 },
3051 flags: []string{"-psk", "secret"},
3052 })
3053 tests = append(tests, testCase{
3054 testType: serverTest,
3055 name: "EmptyPSKHint-Server",
3056 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003057 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003058 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3059 PreSharedKey: []byte("secret"),
3060 },
3061 flags: []string{"-psk", "secret"},
3062 })
3063
David Benjamin4c3ddf72016-06-29 18:13:53 -04003064 // OCSP stapling tests.
3065 //
3066 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003067 tests = append(tests, testCase{
3068 testType: clientTest,
3069 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003070 config: Config{
3071 MaxVersion: VersionTLS12,
3072 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003073 flags: []string{
3074 "-enable-ocsp-stapling",
3075 "-expect-ocsp-response",
3076 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003077 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003078 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003079 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003080 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003081 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003082 testType: serverTest,
3083 name: "OCSPStapling-Server",
3084 config: Config{
3085 MaxVersion: VersionTLS12,
3086 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003087 expectedOCSPResponse: testOCSPResponse,
3088 flags: []string{
3089 "-ocsp-response",
3090 base64.StdEncoding.EncodeToString(testOCSPResponse),
3091 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003092 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003093 })
3094
David Benjamin4c3ddf72016-06-29 18:13:53 -04003095 // Certificate verification tests.
3096 //
3097 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003098 tests = append(tests, testCase{
3099 testType: clientTest,
3100 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003101 config: Config{
3102 MaxVersion: VersionTLS12,
3103 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003104 flags: []string{
3105 "-verify-peer",
3106 },
3107 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003108 tests = append(tests, testCase{
3109 testType: clientTest,
3110 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003111 config: Config{
3112 MaxVersion: VersionTLS12,
3113 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003114 flags: []string{
3115 "-verify-fail",
3116 "-verify-peer",
3117 },
3118 shouldFail: true,
3119 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3120 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003121 tests = append(tests, testCase{
3122 testType: clientTest,
3123 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003124 config: Config{
3125 MaxVersion: VersionTLS12,
3126 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003127 flags: []string{
3128 "-verify-fail",
3129 "-expect-verify-result",
3130 },
3131 })
3132
David Benjamin582ba042016-07-07 12:33:25 -07003133 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003134 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003135 name: "Renegotiate-Client",
3136 config: Config{
3137 MaxVersion: VersionTLS12,
3138 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003139 renegotiate: 1,
3140 flags: []string{
3141 "-renegotiate-freely",
3142 "-expect-total-renegotiations", "1",
3143 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003144 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003145
David Benjamin760b1dd2015-05-15 23:33:48 -04003146 // NPN on client and server; results in post-handshake message.
3147 tests = append(tests, testCase{
3148 name: "NPN-Client",
3149 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003150 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003151 NextProtos: []string{"foo"},
3152 },
3153 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003154 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003155 expectedNextProto: "foo",
3156 expectedNextProtoType: npn,
3157 })
3158 tests = append(tests, testCase{
3159 testType: serverTest,
3160 name: "NPN-Server",
3161 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003162 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003163 NextProtos: []string{"bar"},
3164 },
3165 flags: []string{
3166 "-advertise-npn", "\x03foo\x03bar\x03baz",
3167 "-expect-next-proto", "bar",
3168 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003169 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003170 expectedNextProto: "bar",
3171 expectedNextProtoType: npn,
3172 })
3173
3174 // TODO(davidben): Add tests for when False Start doesn't trigger.
3175
3176 // Client does False Start and negotiates NPN.
3177 tests = append(tests, testCase{
3178 name: "FalseStart",
3179 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003180 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003181 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3182 NextProtos: []string{"foo"},
3183 Bugs: ProtocolBugs{
3184 ExpectFalseStart: true,
3185 },
3186 },
3187 flags: []string{
3188 "-false-start",
3189 "-select-next-proto", "foo",
3190 },
3191 shimWritesFirst: true,
3192 resumeSession: true,
3193 })
3194
3195 // Client does False Start and negotiates ALPN.
3196 tests = append(tests, testCase{
3197 name: "FalseStart-ALPN",
3198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003199 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3201 NextProtos: []string{"foo"},
3202 Bugs: ProtocolBugs{
3203 ExpectFalseStart: true,
3204 },
3205 },
3206 flags: []string{
3207 "-false-start",
3208 "-advertise-alpn", "\x03foo",
3209 },
3210 shimWritesFirst: true,
3211 resumeSession: true,
3212 })
3213
3214 // Client does False Start but doesn't explicitly call
3215 // SSL_connect.
3216 tests = append(tests, testCase{
3217 name: "FalseStart-Implicit",
3218 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003219 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003220 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3221 NextProtos: []string{"foo"},
3222 },
3223 flags: []string{
3224 "-implicit-handshake",
3225 "-false-start",
3226 "-advertise-alpn", "\x03foo",
3227 },
3228 })
3229
3230 // False Start without session tickets.
3231 tests = append(tests, testCase{
3232 name: "FalseStart-SessionTicketsDisabled",
3233 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003234 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003235 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3236 NextProtos: []string{"foo"},
3237 SessionTicketsDisabled: true,
3238 Bugs: ProtocolBugs{
3239 ExpectFalseStart: true,
3240 },
3241 },
3242 flags: []string{
3243 "-false-start",
3244 "-select-next-proto", "foo",
3245 },
3246 shimWritesFirst: true,
3247 })
3248
Adam Langleydf759b52016-07-11 15:24:37 -07003249 tests = append(tests, testCase{
3250 name: "FalseStart-CECPQ1",
3251 config: Config{
3252 MaxVersion: VersionTLS12,
3253 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3254 NextProtos: []string{"foo"},
3255 Bugs: ProtocolBugs{
3256 ExpectFalseStart: true,
3257 },
3258 },
3259 flags: []string{
3260 "-false-start",
3261 "-cipher", "DEFAULT:kCECPQ1",
3262 "-select-next-proto", "foo",
3263 },
3264 shimWritesFirst: true,
3265 resumeSession: true,
3266 })
3267
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 // Server parses a V2ClientHello.
3269 tests = append(tests, testCase{
3270 testType: serverTest,
3271 name: "SendV2ClientHello",
3272 config: Config{
3273 // Choose a cipher suite that does not involve
3274 // elliptic curves, so no extensions are
3275 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003276 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003277 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3278 Bugs: ProtocolBugs{
3279 SendV2ClientHello: true,
3280 },
3281 },
3282 })
3283
3284 // Client sends a Channel ID.
3285 tests = append(tests, testCase{
3286 name: "ChannelID-Client",
3287 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003288 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003289 RequestChannelID: true,
3290 },
Adam Langley7c803a62015-06-15 15:35:05 -07003291 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003292 resumeSession: true,
3293 expectChannelID: true,
3294 })
3295
3296 // Server accepts a Channel ID.
3297 tests = append(tests, testCase{
3298 testType: serverTest,
3299 name: "ChannelID-Server",
3300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003301 MaxVersion: VersionTLS12,
3302 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003303 },
3304 flags: []string{
3305 "-expect-channel-id",
3306 base64.StdEncoding.EncodeToString(channelIDBytes),
3307 },
3308 resumeSession: true,
3309 expectChannelID: true,
3310 })
David Benjamin30789da2015-08-29 22:56:45 -04003311
David Benjaminf8fcdf32016-06-08 15:56:13 -04003312 // Channel ID and NPN at the same time, to ensure their relative
3313 // ordering is correct.
3314 tests = append(tests, testCase{
3315 name: "ChannelID-NPN-Client",
3316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003317 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003318 RequestChannelID: true,
3319 NextProtos: []string{"foo"},
3320 },
3321 flags: []string{
3322 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3323 "-select-next-proto", "foo",
3324 },
3325 resumeSession: true,
3326 expectChannelID: true,
3327 expectedNextProto: "foo",
3328 expectedNextProtoType: npn,
3329 })
3330 tests = append(tests, testCase{
3331 testType: serverTest,
3332 name: "ChannelID-NPN-Server",
3333 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003334 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003335 ChannelID: channelIDKey,
3336 NextProtos: []string{"bar"},
3337 },
3338 flags: []string{
3339 "-expect-channel-id",
3340 base64.StdEncoding.EncodeToString(channelIDBytes),
3341 "-advertise-npn", "\x03foo\x03bar\x03baz",
3342 "-expect-next-proto", "bar",
3343 },
3344 resumeSession: true,
3345 expectChannelID: true,
3346 expectedNextProto: "bar",
3347 expectedNextProtoType: npn,
3348 })
3349
David Benjamin30789da2015-08-29 22:56:45 -04003350 // Bidirectional shutdown with the runner initiating.
3351 tests = append(tests, testCase{
3352 name: "Shutdown-Runner",
3353 config: Config{
3354 Bugs: ProtocolBugs{
3355 ExpectCloseNotify: true,
3356 },
3357 },
3358 flags: []string{"-check-close-notify"},
3359 })
3360
3361 // Bidirectional shutdown with the shim initiating. The runner,
3362 // in the meantime, sends garbage before the close_notify which
3363 // the shim must ignore.
3364 tests = append(tests, testCase{
3365 name: "Shutdown-Shim",
3366 config: Config{
3367 Bugs: ProtocolBugs{
3368 ExpectCloseNotify: true,
3369 },
3370 },
3371 shimShutsDown: true,
3372 sendEmptyRecords: 1,
3373 sendWarningAlerts: 1,
3374 flags: []string{"-check-close-notify"},
3375 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003376 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003377 // TODO(davidben): DTLS 1.3 will want a similar thing for
3378 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003379 tests = append(tests, testCase{
3380 name: "SkipHelloVerifyRequest",
3381 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003382 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003383 Bugs: ProtocolBugs{
3384 SkipHelloVerifyRequest: true,
3385 },
3386 },
3387 })
3388 }
3389
David Benjamin760b1dd2015-05-15 23:33:48 -04003390 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003391 test.protocol = config.protocol
3392 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003393 test.name += "-DTLS"
3394 }
David Benjamin582ba042016-07-07 12:33:25 -07003395 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003396 test.name += "-Async"
3397 test.flags = append(test.flags, "-async")
3398 } else {
3399 test.name += "-Sync"
3400 }
David Benjamin582ba042016-07-07 12:33:25 -07003401 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003402 test.name += "-SplitHandshakeRecords"
3403 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003404 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003405 test.config.Bugs.MaxPacketLength = 256
3406 test.flags = append(test.flags, "-mtu", "256")
3407 }
3408 }
David Benjamin582ba042016-07-07 12:33:25 -07003409 if config.packHandshakeFlight {
3410 test.name += "-PackHandshakeFlight"
3411 test.config.Bugs.PackHandshakeFlight = true
3412 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003413 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003414 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003415}
3416
Adam Langley524e7172015-02-20 16:04:00 -08003417func addDDoSCallbackTests() {
3418 // DDoS callback.
3419
3420 for _, resume := range []bool{false, true} {
3421 suffix := "Resume"
3422 if resume {
3423 suffix = "No" + suffix
3424 }
3425
David Benjamin4c3ddf72016-06-29 18:13:53 -04003426 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3427
Adam Langley524e7172015-02-20 16:04:00 -08003428 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003429 testType: serverTest,
3430 name: "Server-DDoS-OK-" + suffix,
3431 config: Config{
3432 MaxVersion: VersionTLS12,
3433 },
Adam Langley524e7172015-02-20 16:04:00 -08003434 flags: []string{"-install-ddos-callback"},
3435 resumeSession: resume,
3436 })
3437
3438 failFlag := "-fail-ddos-callback"
3439 if resume {
3440 failFlag = "-fail-second-ddos-callback"
3441 }
3442 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003443 testType: serverTest,
3444 name: "Server-DDoS-Reject-" + suffix,
3445 config: Config{
3446 MaxVersion: VersionTLS12,
3447 },
Adam Langley524e7172015-02-20 16:04:00 -08003448 flags: []string{"-install-ddos-callback", failFlag},
3449 resumeSession: resume,
3450 shouldFail: true,
3451 expectedError: ":CONNECTION_REJECTED:",
3452 })
3453 }
3454}
3455
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003456func addVersionNegotiationTests() {
3457 for i, shimVers := range tlsVersions {
3458 // Assemble flags to disable all newer versions on the shim.
3459 var flags []string
3460 for _, vers := range tlsVersions[i+1:] {
3461 flags = append(flags, vers.flag)
3462 }
3463
3464 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003465 protocols := []protocol{tls}
3466 if runnerVers.hasDTLS && shimVers.hasDTLS {
3467 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003468 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003469 for _, protocol := range protocols {
3470 expectedVersion := shimVers.version
3471 if runnerVers.version < shimVers.version {
3472 expectedVersion = runnerVers.version
3473 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003474
David Benjamin8b8c0062014-11-23 02:47:52 -05003475 suffix := shimVers.name + "-" + runnerVers.name
3476 if protocol == dtls {
3477 suffix += "-DTLS"
3478 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003479
David Benjamin1eb367c2014-12-12 18:17:51 -05003480 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3481
David Benjamin1e29a6b2014-12-10 02:27:24 -05003482 clientVers := shimVers.version
3483 if clientVers > VersionTLS10 {
3484 clientVers = VersionTLS10
3485 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003486 serverVers := expectedVersion
3487 if expectedVersion >= VersionTLS13 {
3488 serverVers = VersionTLS10
3489 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003490 testCases = append(testCases, testCase{
3491 protocol: protocol,
3492 testType: clientTest,
3493 name: "VersionNegotiation-Client-" + suffix,
3494 config: Config{
3495 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003496 Bugs: ProtocolBugs{
3497 ExpectInitialRecordVersion: clientVers,
3498 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003499 },
3500 flags: flags,
3501 expectedVersion: expectedVersion,
3502 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003503 testCases = append(testCases, testCase{
3504 protocol: protocol,
3505 testType: clientTest,
3506 name: "VersionNegotiation-Client2-" + suffix,
3507 config: Config{
3508 MaxVersion: runnerVers.version,
3509 Bugs: ProtocolBugs{
3510 ExpectInitialRecordVersion: clientVers,
3511 },
3512 },
3513 flags: []string{"-max-version", shimVersFlag},
3514 expectedVersion: expectedVersion,
3515 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003516
3517 testCases = append(testCases, testCase{
3518 protocol: protocol,
3519 testType: serverTest,
3520 name: "VersionNegotiation-Server-" + suffix,
3521 config: Config{
3522 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003523 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003524 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003525 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003526 },
3527 flags: flags,
3528 expectedVersion: expectedVersion,
3529 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003530 testCases = append(testCases, testCase{
3531 protocol: protocol,
3532 testType: serverTest,
3533 name: "VersionNegotiation-Server2-" + suffix,
3534 config: Config{
3535 MaxVersion: runnerVers.version,
3536 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003537 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003538 },
3539 },
3540 flags: []string{"-max-version", shimVersFlag},
3541 expectedVersion: expectedVersion,
3542 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003543 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003544 }
3545 }
David Benjamin95c69562016-06-29 18:15:03 -04003546
3547 // Test for version tolerance.
3548 testCases = append(testCases, testCase{
3549 testType: serverTest,
3550 name: "MinorVersionTolerance",
3551 config: Config{
3552 Bugs: ProtocolBugs{
3553 SendClientVersion: 0x03ff,
3554 },
3555 },
3556 expectedVersion: VersionTLS13,
3557 })
3558 testCases = append(testCases, testCase{
3559 testType: serverTest,
3560 name: "MajorVersionTolerance",
3561 config: Config{
3562 Bugs: ProtocolBugs{
3563 SendClientVersion: 0x0400,
3564 },
3565 },
3566 expectedVersion: VersionTLS13,
3567 })
3568 testCases = append(testCases, testCase{
3569 protocol: dtls,
3570 testType: serverTest,
3571 name: "MinorVersionTolerance-DTLS",
3572 config: Config{
3573 Bugs: ProtocolBugs{
3574 SendClientVersion: 0x03ff,
3575 },
3576 },
3577 expectedVersion: VersionTLS12,
3578 })
3579 testCases = append(testCases, testCase{
3580 protocol: dtls,
3581 testType: serverTest,
3582 name: "MajorVersionTolerance-DTLS",
3583 config: Config{
3584 Bugs: ProtocolBugs{
3585 SendClientVersion: 0x0400,
3586 },
3587 },
3588 expectedVersion: VersionTLS12,
3589 })
3590
3591 // Test that versions below 3.0 are rejected.
3592 testCases = append(testCases, testCase{
3593 testType: serverTest,
3594 name: "VersionTooLow",
3595 config: Config{
3596 Bugs: ProtocolBugs{
3597 SendClientVersion: 0x0200,
3598 },
3599 },
3600 shouldFail: true,
3601 expectedError: ":UNSUPPORTED_PROTOCOL:",
3602 })
3603 testCases = append(testCases, testCase{
3604 protocol: dtls,
3605 testType: serverTest,
3606 name: "VersionTooLow-DTLS",
3607 config: Config{
3608 Bugs: ProtocolBugs{
3609 // 0x0201 is the lowest version expressable in
3610 // DTLS.
3611 SendClientVersion: 0x0201,
3612 },
3613 },
3614 shouldFail: true,
3615 expectedError: ":UNSUPPORTED_PROTOCOL:",
3616 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003617
3618 // Test TLS 1.3's downgrade signal.
3619 testCases = append(testCases, testCase{
3620 name: "Downgrade-TLS12-Client",
3621 config: Config{
3622 Bugs: ProtocolBugs{
3623 NegotiateVersion: VersionTLS12,
3624 },
3625 },
3626 shouldFail: true,
3627 expectedError: ":DOWNGRADE_DETECTED:",
3628 })
3629 testCases = append(testCases, testCase{
3630 testType: serverTest,
3631 name: "Downgrade-TLS12-Server",
3632 config: Config{
3633 Bugs: ProtocolBugs{
3634 SendClientVersion: VersionTLS12,
3635 },
3636 },
3637 shouldFail: true,
3638 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3639 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003640}
3641
David Benjaminaccb4542014-12-12 23:44:33 -05003642func addMinimumVersionTests() {
3643 for i, shimVers := range tlsVersions {
3644 // Assemble flags to disable all older versions on the shim.
3645 var flags []string
3646 for _, vers := range tlsVersions[:i] {
3647 flags = append(flags, vers.flag)
3648 }
3649
3650 for _, runnerVers := range tlsVersions {
3651 protocols := []protocol{tls}
3652 if runnerVers.hasDTLS && shimVers.hasDTLS {
3653 protocols = append(protocols, dtls)
3654 }
3655 for _, protocol := range protocols {
3656 suffix := shimVers.name + "-" + runnerVers.name
3657 if protocol == dtls {
3658 suffix += "-DTLS"
3659 }
3660 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3661
David Benjaminaccb4542014-12-12 23:44:33 -05003662 var expectedVersion uint16
3663 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003664 var expectedClientError, expectedServerError string
3665 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003666 if runnerVers.version >= shimVers.version {
3667 expectedVersion = runnerVers.version
3668 } else {
3669 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003670 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3671 expectedServerLocalError = "remote error: protocol version not supported"
3672 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3673 // If the client's minimum version is TLS 1.3 and the runner's
3674 // maximum is below TLS 1.2, the runner will fail to select a
3675 // cipher before the shim rejects the selected version.
3676 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3677 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3678 } else {
3679 expectedClientError = expectedServerError
3680 expectedClientLocalError = expectedServerLocalError
3681 }
David Benjaminaccb4542014-12-12 23:44:33 -05003682 }
3683
3684 testCases = append(testCases, testCase{
3685 protocol: protocol,
3686 testType: clientTest,
3687 name: "MinimumVersion-Client-" + suffix,
3688 config: Config{
3689 MaxVersion: runnerVers.version,
3690 },
David Benjamin87909c02014-12-13 01:55:01 -05003691 flags: flags,
3692 expectedVersion: expectedVersion,
3693 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003694 expectedError: expectedClientError,
3695 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003696 })
3697 testCases = append(testCases, testCase{
3698 protocol: protocol,
3699 testType: clientTest,
3700 name: "MinimumVersion-Client2-" + suffix,
3701 config: Config{
3702 MaxVersion: runnerVers.version,
3703 },
David Benjamin87909c02014-12-13 01:55:01 -05003704 flags: []string{"-min-version", shimVersFlag},
3705 expectedVersion: expectedVersion,
3706 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003707 expectedError: expectedClientError,
3708 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003709 })
3710
3711 testCases = append(testCases, testCase{
3712 protocol: protocol,
3713 testType: serverTest,
3714 name: "MinimumVersion-Server-" + suffix,
3715 config: Config{
3716 MaxVersion: runnerVers.version,
3717 },
David Benjamin87909c02014-12-13 01:55:01 -05003718 flags: flags,
3719 expectedVersion: expectedVersion,
3720 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003721 expectedError: expectedServerError,
3722 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003723 })
3724 testCases = append(testCases, testCase{
3725 protocol: protocol,
3726 testType: serverTest,
3727 name: "MinimumVersion-Server2-" + suffix,
3728 config: Config{
3729 MaxVersion: runnerVers.version,
3730 },
David Benjamin87909c02014-12-13 01:55:01 -05003731 flags: []string{"-min-version", shimVersFlag},
3732 expectedVersion: expectedVersion,
3733 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003734 expectedError: expectedServerError,
3735 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003736 })
3737 }
3738 }
3739 }
3740}
3741
David Benjamine78bfde2014-09-06 12:45:15 -04003742func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003743 // TODO(davidben): Extensions, where applicable, all move their server
3744 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3745 // tests for both. Also test interaction with 0-RTT when implemented.
3746
David Benjamine78bfde2014-09-06 12:45:15 -04003747 testCases = append(testCases, testCase{
3748 testType: clientTest,
3749 name: "DuplicateExtensionClient",
3750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003751 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003752 Bugs: ProtocolBugs{
3753 DuplicateExtension: true,
3754 },
3755 },
3756 shouldFail: true,
3757 expectedLocalError: "remote error: error decoding message",
3758 })
3759 testCases = append(testCases, testCase{
3760 testType: serverTest,
3761 name: "DuplicateExtensionServer",
3762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003763 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003764 Bugs: ProtocolBugs{
3765 DuplicateExtension: true,
3766 },
3767 },
3768 shouldFail: true,
3769 expectedLocalError: "remote error: error decoding message",
3770 })
3771 testCases = append(testCases, testCase{
3772 testType: clientTest,
3773 name: "ServerNameExtensionClient",
3774 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003775 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003776 Bugs: ProtocolBugs{
3777 ExpectServerName: "example.com",
3778 },
3779 },
3780 flags: []string{"-host-name", "example.com"},
3781 })
3782 testCases = append(testCases, testCase{
3783 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003784 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003786 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003787 Bugs: ProtocolBugs{
3788 ExpectServerName: "mismatch.com",
3789 },
3790 },
3791 flags: []string{"-host-name", "example.com"},
3792 shouldFail: true,
3793 expectedLocalError: "tls: unexpected server name",
3794 })
3795 testCases = append(testCases, testCase{
3796 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003797 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003799 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003800 Bugs: ProtocolBugs{
3801 ExpectServerName: "missing.com",
3802 },
3803 },
3804 shouldFail: true,
3805 expectedLocalError: "tls: unexpected server name",
3806 })
3807 testCases = append(testCases, testCase{
3808 testType: serverTest,
3809 name: "ServerNameExtensionServer",
3810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003811 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003812 ServerName: "example.com",
3813 },
3814 flags: []string{"-expect-server-name", "example.com"},
3815 resumeSession: true,
3816 })
David Benjaminae2888f2014-09-06 12:58:58 -04003817 testCases = append(testCases, testCase{
3818 testType: clientTest,
3819 name: "ALPNClient",
3820 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003821 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003822 NextProtos: []string{"foo"},
3823 },
3824 flags: []string{
3825 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3826 "-expect-alpn", "foo",
3827 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003828 expectedNextProto: "foo",
3829 expectedNextProtoType: alpn,
3830 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003831 })
3832 testCases = append(testCases, testCase{
3833 testType: serverTest,
3834 name: "ALPNServer",
3835 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003836 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003837 NextProtos: []string{"foo", "bar", "baz"},
3838 },
3839 flags: []string{
3840 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3841 "-select-alpn", "foo",
3842 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003843 expectedNextProto: "foo",
3844 expectedNextProtoType: alpn,
3845 resumeSession: true,
3846 })
David Benjamin594e7d22016-03-17 17:49:56 -04003847 testCases = append(testCases, testCase{
3848 testType: serverTest,
3849 name: "ALPNServer-Decline",
3850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003851 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003852 NextProtos: []string{"foo", "bar", "baz"},
3853 },
3854 flags: []string{"-decline-alpn"},
3855 expectNoNextProto: true,
3856 resumeSession: true,
3857 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003858 // Test that the server prefers ALPN over NPN.
3859 testCases = append(testCases, testCase{
3860 testType: serverTest,
3861 name: "ALPNServer-Preferred",
3862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003863 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003864 NextProtos: []string{"foo", "bar", "baz"},
3865 },
3866 flags: []string{
3867 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3868 "-select-alpn", "foo",
3869 "-advertise-npn", "\x03foo\x03bar\x03baz",
3870 },
3871 expectedNextProto: "foo",
3872 expectedNextProtoType: alpn,
3873 resumeSession: true,
3874 })
3875 testCases = append(testCases, testCase{
3876 testType: serverTest,
3877 name: "ALPNServer-Preferred-Swapped",
3878 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003879 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003880 NextProtos: []string{"foo", "bar", "baz"},
3881 Bugs: ProtocolBugs{
3882 SwapNPNAndALPN: true,
3883 },
3884 },
3885 flags: []string{
3886 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3887 "-select-alpn", "foo",
3888 "-advertise-npn", "\x03foo\x03bar\x03baz",
3889 },
3890 expectedNextProto: "foo",
3891 expectedNextProtoType: alpn,
3892 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003893 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003894 var emptyString string
3895 testCases = append(testCases, testCase{
3896 testType: clientTest,
3897 name: "ALPNClient-EmptyProtocolName",
3898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003899 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003900 NextProtos: []string{""},
3901 Bugs: ProtocolBugs{
3902 // A server returning an empty ALPN protocol
3903 // should be rejected.
3904 ALPNProtocol: &emptyString,
3905 },
3906 },
3907 flags: []string{
3908 "-advertise-alpn", "\x03foo",
3909 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003910 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003911 expectedError: ":PARSE_TLSEXT:",
3912 })
3913 testCases = append(testCases, testCase{
3914 testType: serverTest,
3915 name: "ALPNServer-EmptyProtocolName",
3916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003917 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003918 // A ClientHello containing an empty ALPN protocol
3919 // should be rejected.
3920 NextProtos: []string{"foo", "", "baz"},
3921 },
3922 flags: []string{
3923 "-select-alpn", "foo",
3924 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003925 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003926 expectedError: ":PARSE_TLSEXT:",
3927 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003928 // Test that negotiating both NPN and ALPN is forbidden.
3929 testCases = append(testCases, testCase{
3930 name: "NegotiateALPNAndNPN",
3931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003932 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003933 NextProtos: []string{"foo", "bar", "baz"},
3934 Bugs: ProtocolBugs{
3935 NegotiateALPNAndNPN: true,
3936 },
3937 },
3938 flags: []string{
3939 "-advertise-alpn", "\x03foo",
3940 "-select-next-proto", "foo",
3941 },
3942 shouldFail: true,
3943 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3944 })
3945 testCases = append(testCases, testCase{
3946 name: "NegotiateALPNAndNPN-Swapped",
3947 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003948 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003949 NextProtos: []string{"foo", "bar", "baz"},
3950 Bugs: ProtocolBugs{
3951 NegotiateALPNAndNPN: true,
3952 SwapNPNAndALPN: true,
3953 },
3954 },
3955 flags: []string{
3956 "-advertise-alpn", "\x03foo",
3957 "-select-next-proto", "foo",
3958 },
3959 shouldFail: true,
3960 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3961 })
David Benjamin091c4b92015-10-26 13:33:21 -04003962 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3963 testCases = append(testCases, testCase{
3964 name: "DisableNPN",
3965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003966 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04003967 NextProtos: []string{"foo"},
3968 },
3969 flags: []string{
3970 "-select-next-proto", "foo",
3971 "-disable-npn",
3972 },
3973 expectNoNextProto: true,
3974 })
Adam Langley38311732014-10-16 19:04:35 -07003975 // Resume with a corrupt ticket.
3976 testCases = append(testCases, testCase{
3977 testType: serverTest,
3978 name: "CorruptTicket",
3979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003980 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003981 Bugs: ProtocolBugs{
3982 CorruptTicket: true,
3983 },
3984 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003985 resumeSession: true,
3986 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003987 })
David Benjamind98452d2015-06-16 14:16:23 -04003988 // Test the ticket callback, with and without renewal.
3989 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003990 testType: serverTest,
3991 name: "TicketCallback",
3992 config: Config{
3993 MaxVersion: VersionTLS12,
3994 },
David Benjamind98452d2015-06-16 14:16:23 -04003995 resumeSession: true,
3996 flags: []string{"-use-ticket-callback"},
3997 })
3998 testCases = append(testCases, testCase{
3999 testType: serverTest,
4000 name: "TicketCallback-Renew",
4001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004002 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004003 Bugs: ProtocolBugs{
4004 ExpectNewTicket: true,
4005 },
4006 },
4007 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4008 resumeSession: true,
4009 })
Adam Langley38311732014-10-16 19:04:35 -07004010 // Resume with an oversized session id.
4011 testCases = append(testCases, testCase{
4012 testType: serverTest,
4013 name: "OversizedSessionId",
4014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004015 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004016 Bugs: ProtocolBugs{
4017 OversizedSessionId: true,
4018 },
4019 },
4020 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004021 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004022 expectedError: ":DECODE_ERROR:",
4023 })
David Benjaminca6c8262014-11-15 19:06:08 -05004024 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4025 // are ignored.
4026 testCases = append(testCases, testCase{
4027 protocol: dtls,
4028 name: "SRTP-Client",
4029 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004030 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004031 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4032 },
4033 flags: []string{
4034 "-srtp-profiles",
4035 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4036 },
4037 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4038 })
4039 testCases = append(testCases, testCase{
4040 protocol: dtls,
4041 testType: serverTest,
4042 name: "SRTP-Server",
4043 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004044 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004045 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4046 },
4047 flags: []string{
4048 "-srtp-profiles",
4049 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4050 },
4051 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4052 })
4053 // Test that the MKI is ignored.
4054 testCases = append(testCases, testCase{
4055 protocol: dtls,
4056 testType: serverTest,
4057 name: "SRTP-Server-IgnoreMKI",
4058 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004059 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004060 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4061 Bugs: ProtocolBugs{
4062 SRTPMasterKeyIdentifer: "bogus",
4063 },
4064 },
4065 flags: []string{
4066 "-srtp-profiles",
4067 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4068 },
4069 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4070 })
4071 // Test that SRTP isn't negotiated on the server if there were
4072 // no matching profiles.
4073 testCases = append(testCases, testCase{
4074 protocol: dtls,
4075 testType: serverTest,
4076 name: "SRTP-Server-NoMatch",
4077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004078 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004079 SRTPProtectionProfiles: []uint16{100, 101, 102},
4080 },
4081 flags: []string{
4082 "-srtp-profiles",
4083 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4084 },
4085 expectedSRTPProtectionProfile: 0,
4086 })
4087 // Test that the server returning an invalid SRTP profile is
4088 // flagged as an error by the client.
4089 testCases = append(testCases, testCase{
4090 protocol: dtls,
4091 name: "SRTP-Client-NoMatch",
4092 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004093 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004094 Bugs: ProtocolBugs{
4095 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4096 },
4097 },
4098 flags: []string{
4099 "-srtp-profiles",
4100 "SRTP_AES128_CM_SHA1_80",
4101 },
4102 shouldFail: true,
4103 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4104 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004105 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004106 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004107 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004108 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004109 config: Config{
4110 MaxVersion: VersionTLS12,
4111 },
David Benjamin61f95272014-11-25 01:55:35 -05004112 flags: []string{
4113 "-enable-signed-cert-timestamps",
4114 "-expect-signed-cert-timestamps",
4115 base64.StdEncoding.EncodeToString(testSCTList),
4116 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004117 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004118 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004119 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004120 name: "SendSCTListOnResume",
4121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004122 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004123 Bugs: ProtocolBugs{
4124 SendSCTListOnResume: []byte("bogus"),
4125 },
4126 },
4127 flags: []string{
4128 "-enable-signed-cert-timestamps",
4129 "-expect-signed-cert-timestamps",
4130 base64.StdEncoding.EncodeToString(testSCTList),
4131 },
4132 resumeSession: true,
4133 })
4134 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004135 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004136 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004137 config: Config{
4138 MaxVersion: VersionTLS12,
4139 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004140 flags: []string{
4141 "-signed-cert-timestamps",
4142 base64.StdEncoding.EncodeToString(testSCTList),
4143 },
4144 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004145 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004146 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004147
Paul Lietar4fac72e2015-09-09 13:44:55 +01004148 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004149 testType: clientTest,
4150 name: "ClientHelloPadding",
4151 config: Config{
4152 Bugs: ProtocolBugs{
4153 RequireClientHelloSize: 512,
4154 },
4155 },
4156 // This hostname just needs to be long enough to push the
4157 // ClientHello into F5's danger zone between 256 and 511 bytes
4158 // long.
4159 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4160 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004161
4162 // Extensions should not function in SSL 3.0.
4163 testCases = append(testCases, testCase{
4164 testType: serverTest,
4165 name: "SSLv3Extensions-NoALPN",
4166 config: Config{
4167 MaxVersion: VersionSSL30,
4168 NextProtos: []string{"foo", "bar", "baz"},
4169 },
4170 flags: []string{
4171 "-select-alpn", "foo",
4172 },
4173 expectNoNextProto: true,
4174 })
4175
4176 // Test session tickets separately as they follow a different codepath.
4177 testCases = append(testCases, testCase{
4178 testType: serverTest,
4179 name: "SSLv3Extensions-NoTickets",
4180 config: Config{
4181 MaxVersion: VersionSSL30,
4182 Bugs: ProtocolBugs{
4183 // Historically, session tickets in SSL 3.0
4184 // failed in different ways depending on whether
4185 // the client supported renegotiation_info.
4186 NoRenegotiationInfo: true,
4187 },
4188 },
4189 resumeSession: true,
4190 })
4191 testCases = append(testCases, testCase{
4192 testType: serverTest,
4193 name: "SSLv3Extensions-NoTickets2",
4194 config: Config{
4195 MaxVersion: VersionSSL30,
4196 },
4197 resumeSession: true,
4198 })
4199
4200 // But SSL 3.0 does send and process renegotiation_info.
4201 testCases = append(testCases, testCase{
4202 testType: serverTest,
4203 name: "SSLv3Extensions-RenegotiationInfo",
4204 config: Config{
4205 MaxVersion: VersionSSL30,
4206 Bugs: ProtocolBugs{
4207 RequireRenegotiationInfo: true,
4208 },
4209 },
4210 })
4211 testCases = append(testCases, testCase{
4212 testType: serverTest,
4213 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4214 config: Config{
4215 MaxVersion: VersionSSL30,
4216 Bugs: ProtocolBugs{
4217 NoRenegotiationInfo: true,
4218 SendRenegotiationSCSV: true,
4219 RequireRenegotiationInfo: true,
4220 },
4221 },
4222 })
David Benjamine78bfde2014-09-06 12:45:15 -04004223}
4224
David Benjamin01fe8202014-09-24 15:21:44 -04004225func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004226 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004227 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004228 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4229 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4230 // TLS 1.3 only shares ciphers with TLS 1.2, so
4231 // we skip certain combinations and use a
4232 // different cipher to test with.
4233 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4234 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4235 continue
4236 }
4237 }
4238
David Benjamin8b8c0062014-11-23 02:47:52 -05004239 protocols := []protocol{tls}
4240 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4241 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004242 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004243 for _, protocol := range protocols {
4244 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4245 if protocol == dtls {
4246 suffix += "-DTLS"
4247 }
4248
David Benjaminece3de92015-03-16 18:02:20 -04004249 if sessionVers.version == resumeVers.version {
4250 testCases = append(testCases, testCase{
4251 protocol: protocol,
4252 name: "Resume-Client" + suffix,
4253 resumeSession: true,
4254 config: Config{
4255 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004256 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004257 },
David Benjaminece3de92015-03-16 18:02:20 -04004258 expectedVersion: sessionVers.version,
4259 expectedResumeVersion: resumeVers.version,
4260 })
4261 } else {
4262 testCases = append(testCases, testCase{
4263 protocol: protocol,
4264 name: "Resume-Client-Mismatch" + 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 resumeConfig: &Config{
4272 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004273 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004274 Bugs: ProtocolBugs{
4275 AllowSessionVersionMismatch: true,
4276 },
4277 },
4278 expectedResumeVersion: resumeVers.version,
4279 shouldFail: true,
4280 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4281 })
4282 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004283
4284 testCases = append(testCases, testCase{
4285 protocol: protocol,
4286 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004287 resumeSession: true,
4288 config: Config{
4289 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004290 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004291 },
4292 expectedVersion: sessionVers.version,
4293 resumeConfig: &Config{
4294 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004295 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004296 },
4297 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004298 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004299 expectedResumeVersion: resumeVers.version,
4300 })
4301
David Benjamin8b8c0062014-11-23 02:47:52 -05004302 testCases = append(testCases, testCase{
4303 protocol: protocol,
4304 testType: serverTest,
4305 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004306 resumeSession: true,
4307 config: Config{
4308 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004309 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004310 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004311 expectedVersion: sessionVers.version,
4312 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004313 resumeConfig: &Config{
4314 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004315 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004316 },
4317 expectedResumeVersion: resumeVers.version,
4318 })
4319 }
David Benjamin01fe8202014-09-24 15:21:44 -04004320 }
4321 }
David Benjaminece3de92015-03-16 18:02:20 -04004322
Nick Harper1fd39d82016-06-14 18:14:35 -07004323 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004324 testCases = append(testCases, testCase{
4325 name: "Resume-Client-CipherMismatch",
4326 resumeSession: true,
4327 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004328 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004329 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4330 },
4331 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004332 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004333 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4334 Bugs: ProtocolBugs{
4335 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4336 },
4337 },
4338 shouldFail: true,
4339 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4340 })
David Benjamin01fe8202014-09-24 15:21:44 -04004341}
4342
Adam Langley2ae77d22014-10-28 17:29:33 -07004343func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004344 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004345 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004346 testType: serverTest,
4347 name: "Renegotiate-Server-Forbidden",
4348 config: Config{
4349 MaxVersion: VersionTLS12,
4350 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004351 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004352 shouldFail: true,
4353 expectedError: ":NO_RENEGOTIATION:",
4354 expectedLocalError: "remote error: no renegotiation",
4355 })
Adam Langley5021b222015-06-12 18:27:58 -07004356 // The server shouldn't echo the renegotiation extension unless
4357 // requested by the client.
4358 testCases = append(testCases, testCase{
4359 testType: serverTest,
4360 name: "Renegotiate-Server-NoExt",
4361 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004362 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004363 Bugs: ProtocolBugs{
4364 NoRenegotiationInfo: true,
4365 RequireRenegotiationInfo: true,
4366 },
4367 },
4368 shouldFail: true,
4369 expectedLocalError: "renegotiation extension missing",
4370 })
4371 // The renegotiation SCSV should be sufficient for the server to echo
4372 // the extension.
4373 testCases = append(testCases, testCase{
4374 testType: serverTest,
4375 name: "Renegotiate-Server-NoExt-SCSV",
4376 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004377 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004378 Bugs: ProtocolBugs{
4379 NoRenegotiationInfo: true,
4380 SendRenegotiationSCSV: true,
4381 RequireRenegotiationInfo: true,
4382 },
4383 },
4384 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004385 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004386 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004387 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004388 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004389 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004390 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004391 },
4392 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004393 renegotiate: 1,
4394 flags: []string{
4395 "-renegotiate-freely",
4396 "-expect-total-renegotiations", "1",
4397 },
David Benjamincdea40c2015-03-19 14:09:43 -04004398 })
4399 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004400 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004401 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004403 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004404 Bugs: ProtocolBugs{
4405 EmptyRenegotiationInfo: true,
4406 },
4407 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004408 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004409 shouldFail: true,
4410 expectedError: ":RENEGOTIATION_MISMATCH:",
4411 })
4412 testCases = append(testCases, testCase{
4413 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004414 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004415 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004416 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004417 Bugs: ProtocolBugs{
4418 BadRenegotiationInfo: true,
4419 },
4420 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004421 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004422 shouldFail: true,
4423 expectedError: ":RENEGOTIATION_MISMATCH:",
4424 })
4425 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004426 name: "Renegotiate-Client-Downgrade",
4427 renegotiate: 1,
4428 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004429 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004430 Bugs: ProtocolBugs{
4431 NoRenegotiationInfoAfterInitial: true,
4432 },
4433 },
4434 flags: []string{"-renegotiate-freely"},
4435 shouldFail: true,
4436 expectedError: ":RENEGOTIATION_MISMATCH:",
4437 })
4438 testCases = append(testCases, testCase{
4439 name: "Renegotiate-Client-Upgrade",
4440 renegotiate: 1,
4441 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004442 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004443 Bugs: ProtocolBugs{
4444 NoRenegotiationInfoInInitial: true,
4445 },
4446 },
4447 flags: []string{"-renegotiate-freely"},
4448 shouldFail: true,
4449 expectedError: ":RENEGOTIATION_MISMATCH:",
4450 })
4451 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004452 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004453 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004454 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004455 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004456 Bugs: ProtocolBugs{
4457 NoRenegotiationInfo: true,
4458 },
4459 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004460 flags: []string{
4461 "-renegotiate-freely",
4462 "-expect-total-renegotiations", "1",
4463 },
David Benjamincff0b902015-05-15 23:09:47 -04004464 })
4465 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004466 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004467 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004468 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004469 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004470 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4471 },
4472 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004473 flags: []string{
4474 "-renegotiate-freely",
4475 "-expect-total-renegotiations", "1",
4476 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004477 })
4478 testCases = append(testCases, testCase{
4479 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004480 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004481 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004482 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004483 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4484 },
4485 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004486 flags: []string{
4487 "-renegotiate-freely",
4488 "-expect-total-renegotiations", "1",
4489 },
David Benjaminb16346b2015-04-08 19:16:58 -04004490 })
4491 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004492 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004493 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004494 config: Config{
4495 MaxVersion: VersionTLS10,
4496 Bugs: ProtocolBugs{
4497 RequireSameRenegoClientVersion: true,
4498 },
4499 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004500 flags: []string{
4501 "-renegotiate-freely",
4502 "-expect-total-renegotiations", "1",
4503 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004504 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004505 testCases = append(testCases, testCase{
4506 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004507 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004508 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004509 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004510 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4511 NextProtos: []string{"foo"},
4512 },
4513 flags: []string{
4514 "-false-start",
4515 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004516 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004517 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004518 },
4519 shimWritesFirst: true,
4520 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004521
4522 // Client-side renegotiation controls.
4523 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004524 name: "Renegotiate-Client-Forbidden-1",
4525 config: Config{
4526 MaxVersion: VersionTLS12,
4527 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004528 renegotiate: 1,
4529 shouldFail: true,
4530 expectedError: ":NO_RENEGOTIATION:",
4531 expectedLocalError: "remote error: no renegotiation",
4532 })
4533 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004534 name: "Renegotiate-Client-Once-1",
4535 config: Config{
4536 MaxVersion: VersionTLS12,
4537 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004538 renegotiate: 1,
4539 flags: []string{
4540 "-renegotiate-once",
4541 "-expect-total-renegotiations", "1",
4542 },
4543 })
4544 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004545 name: "Renegotiate-Client-Freely-1",
4546 config: Config{
4547 MaxVersion: VersionTLS12,
4548 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004549 renegotiate: 1,
4550 flags: []string{
4551 "-renegotiate-freely",
4552 "-expect-total-renegotiations", "1",
4553 },
4554 })
4555 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004556 name: "Renegotiate-Client-Once-2",
4557 config: Config{
4558 MaxVersion: VersionTLS12,
4559 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004560 renegotiate: 2,
4561 flags: []string{"-renegotiate-once"},
4562 shouldFail: true,
4563 expectedError: ":NO_RENEGOTIATION:",
4564 expectedLocalError: "remote error: no renegotiation",
4565 })
4566 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004567 name: "Renegotiate-Client-Freely-2",
4568 config: Config{
4569 MaxVersion: VersionTLS12,
4570 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004571 renegotiate: 2,
4572 flags: []string{
4573 "-renegotiate-freely",
4574 "-expect-total-renegotiations", "2",
4575 },
4576 })
Adam Langley27a0d082015-11-03 13:34:10 -08004577 testCases = append(testCases, testCase{
4578 name: "Renegotiate-Client-NoIgnore",
4579 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004580 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004581 Bugs: ProtocolBugs{
4582 SendHelloRequestBeforeEveryAppDataRecord: true,
4583 },
4584 },
4585 shouldFail: true,
4586 expectedError: ":NO_RENEGOTIATION:",
4587 })
4588 testCases = append(testCases, testCase{
4589 name: "Renegotiate-Client-Ignore",
4590 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004591 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004592 Bugs: ProtocolBugs{
4593 SendHelloRequestBeforeEveryAppDataRecord: true,
4594 },
4595 },
4596 flags: []string{
4597 "-renegotiate-ignore",
4598 "-expect-total-renegotiations", "0",
4599 },
4600 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004601
David Benjamin397c8e62016-07-08 14:14:36 -07004602 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004603 testCases = append(testCases, testCase{
4604 name: "StrayHelloRequest",
4605 config: Config{
4606 MaxVersion: VersionTLS12,
4607 Bugs: ProtocolBugs{
4608 SendHelloRequestBeforeEveryHandshakeMessage: true,
4609 },
4610 },
4611 })
4612 testCases = append(testCases, testCase{
4613 name: "StrayHelloRequest-Packed",
4614 config: Config{
4615 MaxVersion: VersionTLS12,
4616 Bugs: ProtocolBugs{
4617 PackHandshakeFlight: true,
4618 SendHelloRequestBeforeEveryHandshakeMessage: true,
4619 },
4620 },
4621 })
4622
David Benjamin397c8e62016-07-08 14:14:36 -07004623 // Renegotiation is forbidden in TLS 1.3.
4624 testCases = append(testCases, testCase{
4625 name: "Renegotiate-Client-TLS13",
4626 config: Config{
4627 MaxVersion: VersionTLS13,
4628 },
4629 renegotiate: 1,
4630 flags: []string{
4631 "-renegotiate-freely",
4632 },
4633 shouldFail: true,
4634 expectedError: ":NO_RENEGOTIATION:",
4635 })
4636
4637 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4638 testCases = append(testCases, testCase{
4639 name: "StrayHelloRequest-TLS13",
4640 config: Config{
4641 MaxVersion: VersionTLS13,
4642 Bugs: ProtocolBugs{
4643 SendHelloRequestBeforeEveryHandshakeMessage: true,
4644 },
4645 },
4646 shouldFail: true,
4647 expectedError: ":UNEXPECTED_MESSAGE:",
4648 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004649}
4650
David Benjamin5e961c12014-11-07 01:48:35 -05004651func addDTLSReplayTests() {
4652 // Test that sequence number replays are detected.
4653 testCases = append(testCases, testCase{
4654 protocol: dtls,
4655 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004656 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004657 replayWrites: true,
4658 })
4659
David Benjamin8e6db492015-07-25 18:29:23 -04004660 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004661 // than the retransmit window.
4662 testCases = append(testCases, testCase{
4663 protocol: dtls,
4664 name: "DTLS-Replay-LargeGaps",
4665 config: Config{
4666 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004667 SequenceNumberMapping: func(in uint64) uint64 {
4668 return in * 127
4669 },
David Benjamin5e961c12014-11-07 01:48:35 -05004670 },
4671 },
David Benjamin8e6db492015-07-25 18:29:23 -04004672 messageCount: 200,
4673 replayWrites: true,
4674 })
4675
4676 // Test the incoming sequence number changing non-monotonically.
4677 testCases = append(testCases, testCase{
4678 protocol: dtls,
4679 name: "DTLS-Replay-NonMonotonic",
4680 config: Config{
4681 Bugs: ProtocolBugs{
4682 SequenceNumberMapping: func(in uint64) uint64 {
4683 return in ^ 31
4684 },
4685 },
4686 },
4687 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004688 replayWrites: true,
4689 })
4690}
4691
Nick Harper60edffd2016-06-21 15:19:24 -07004692var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004693 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004694 id signatureAlgorithm
4695 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004696}{
Nick Harper60edffd2016-06-21 15:19:24 -07004697 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4698 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4699 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4700 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004701 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07004702 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4703 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4704 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004705 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
4706 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
4707 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin000800a2014-11-14 01:43:59 -05004708}
4709
Nick Harper60edffd2016-06-21 15:19:24 -07004710const fakeSigAlg1 signatureAlgorithm = 0x2a01
4711const fakeSigAlg2 signatureAlgorithm = 0xff01
4712
4713func addSignatureAlgorithmTests() {
4714 // Make sure each signature algorithm works. Include some fake values in
4715 // the list and ensure they're ignored.
4716 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07004717 for _, ver := range tlsVersions {
4718 if ver.version < VersionTLS12 {
4719 continue
4720 }
Nick Harper60edffd2016-06-21 15:19:24 -07004721
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004722 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07004723 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004724 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
4725 shouldFail = true
4726 }
4727 // RSA-PSS does not exist in TLS 1.2.
4728 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
4729 shouldFail = true
4730 }
4731
4732 var signError, verifyError string
4733 if shouldFail {
4734 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
4735 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07004736 }
David Benjamin000800a2014-11-14 01:43:59 -05004737
David Benjamin1fb125c2016-07-08 18:52:12 -07004738 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05004739
David Benjamin7a41d372016-07-09 11:21:54 -07004740 testCases = append(testCases, testCase{
4741 name: "SigningHash-ClientAuth-Sign" + suffix,
4742 config: Config{
4743 MaxVersion: ver.version,
4744 ClientAuth: RequireAnyClientCert,
4745 VerifySignatureAlgorithms: []signatureAlgorithm{
4746 fakeSigAlg1,
4747 alg.id,
4748 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07004749 },
David Benjamin7a41d372016-07-09 11:21:54 -07004750 },
4751 flags: []string{
4752 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4753 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4754 "-enable-all-curves",
4755 },
4756 shouldFail: shouldFail,
4757 expectedError: signError,
4758 expectedPeerSignatureAlgorithm: alg.id,
4759 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004760
David Benjamin7a41d372016-07-09 11:21:54 -07004761 testCases = append(testCases, testCase{
4762 testType: serverTest,
4763 name: "SigningHash-ClientAuth-Verify" + suffix,
4764 config: Config{
4765 MaxVersion: ver.version,
4766 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4767 SignSignatureAlgorithms: []signatureAlgorithm{
4768 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004769 },
David Benjamin7a41d372016-07-09 11:21:54 -07004770 Bugs: ProtocolBugs{
4771 SkipECDSACurveCheck: shouldFail,
4772 IgnoreSignatureVersionChecks: shouldFail,
4773 // The client won't advertise 1.3-only algorithms after
4774 // version negotiation.
4775 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004776 },
David Benjamin7a41d372016-07-09 11:21:54 -07004777 },
4778 flags: []string{
4779 "-require-any-client-certificate",
4780 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4781 "-enable-all-curves",
4782 },
4783 shouldFail: shouldFail,
4784 expectedError: verifyError,
4785 })
David Benjamin1fb125c2016-07-08 18:52:12 -07004786
4787 testCases = append(testCases, testCase{
4788 testType: serverTest,
4789 name: "SigningHash-ServerKeyExchange-Sign" + suffix,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 CipherSuites: []uint16{
4793 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4794 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4795 },
David Benjamin7a41d372016-07-09 11:21:54 -07004796 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004797 fakeSigAlg1,
4798 alg.id,
4799 fakeSigAlg2,
4800 },
4801 },
4802 flags: []string{
4803 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4804 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4805 "-enable-all-curves",
4806 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004807 shouldFail: shouldFail,
4808 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004809 expectedPeerSignatureAlgorithm: alg.id,
4810 })
4811
4812 testCases = append(testCases, testCase{
4813 name: "SigningHash-ServerKeyExchange-Verify" + suffix,
4814 config: Config{
4815 MaxVersion: ver.version,
4816 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4817 CipherSuites: []uint16{
4818 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4819 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4820 },
David Benjamin7a41d372016-07-09 11:21:54 -07004821 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07004822 alg.id,
4823 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004824 Bugs: ProtocolBugs{
4825 SkipECDSACurveCheck: shouldFail,
4826 IgnoreSignatureVersionChecks: shouldFail,
4827 },
David Benjamin1fb125c2016-07-08 18:52:12 -07004828 },
4829 flags: []string{
4830 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4831 "-enable-all-curves",
4832 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04004833 shouldFail: shouldFail,
4834 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07004835 })
4836 }
David Benjamin000800a2014-11-14 01:43:59 -05004837 }
4838
Nick Harper60edffd2016-06-21 15:19:24 -07004839 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004840 //
4841 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004842 testCases = append(testCases, testCase{
4843 name: "SigningHash-ClientAuth-SignatureType",
4844 config: Config{
4845 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004846 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07004847 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004848 signatureECDSAWithP521AndSHA512,
4849 signatureRSAPKCS1WithSHA384,
4850 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004851 },
4852 },
4853 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004854 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4855 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004856 },
Nick Harper60edffd2016-06-21 15:19:24 -07004857 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004858 })
4859
4860 testCases = append(testCases, testCase{
4861 testType: serverTest,
4862 name: "SigningHash-ServerKeyExchange-SignatureType",
4863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004864 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004865 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004866 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004867 signatureECDSAWithP521AndSHA512,
4868 signatureRSAPKCS1WithSHA384,
4869 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004870 },
4871 },
Nick Harper60edffd2016-06-21 15:19:24 -07004872 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004873 })
4874
David Benjamina95e9f32016-07-08 16:28:04 -07004875 // Test that signature verification takes the key type into account.
4876 //
4877 // TODO(davidben): Test this in TLS 1.3.
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "Verify-ClientAuth-SignatureType",
4881 config: Config{
4882 MaxVersion: VersionTLS12,
4883 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004884 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004885 signatureRSAPKCS1WithSHA256,
4886 },
4887 Bugs: ProtocolBugs{
4888 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4889 },
4890 },
4891 flags: []string{
4892 "-require-any-client-certificate",
4893 },
4894 shouldFail: true,
4895 expectedError: ":WRONG_SIGNATURE_TYPE:",
4896 })
4897
4898 testCases = append(testCases, testCase{
4899 name: "Verify-ServerKeyExchange-SignatureType",
4900 config: Config{
4901 MaxVersion: VersionTLS12,
4902 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004903 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07004904 signatureRSAPKCS1WithSHA256,
4905 },
4906 Bugs: ProtocolBugs{
4907 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4908 },
4909 },
4910 shouldFail: true,
4911 expectedError: ":WRONG_SIGNATURE_TYPE:",
4912 })
4913
David Benjamin51dd7d62016-07-08 16:07:01 -07004914 // Test that, if the list is missing, the peer falls back to SHA-1 in
4915 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004916 testCases = append(testCases, testCase{
4917 name: "SigningHash-ClientAuth-Fallback",
4918 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004919 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004920 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004921 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004922 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004923 },
4924 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004925 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004926 },
4927 },
4928 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004929 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4930 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004931 },
4932 })
4933
4934 testCases = append(testCases, testCase{
4935 testType: serverTest,
4936 name: "SigningHash-ServerKeyExchange-Fallback",
4937 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004938 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004940 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004941 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004942 },
4943 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004944 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004945 },
4946 },
4947 })
David Benjamin72dc7832015-03-16 17:49:43 -04004948
David Benjamin51dd7d62016-07-08 16:07:01 -07004949 testCases = append(testCases, testCase{
4950 name: "SigningHash-ClientAuth-Fallback-TLS13",
4951 config: Config{
4952 MaxVersion: VersionTLS13,
4953 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07004954 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07004955 signatureRSAPKCS1WithSHA1,
4956 },
4957 Bugs: ProtocolBugs{
4958 NoSignatureAlgorithms: true,
4959 },
4960 },
4961 flags: []string{
4962 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4963 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4964 },
4965 shouldFail: true,
4966 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
4967 })
4968
4969 testCases = append(testCases, testCase{
4970 testType: serverTest,
4971 name: "SigningHash-ServerKeyExchange-Fallback-TLS13",
4972 config: Config{
4973 MaxVersion: VersionTLS13,
4974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07004975 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07004976 signatureRSAPKCS1WithSHA1,
4977 },
4978 Bugs: ProtocolBugs{
4979 NoSignatureAlgorithms: true,
4980 },
4981 },
4982 shouldFail: true,
4983 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
4984 })
4985
David Benjamin72dc7832015-03-16 17:49:43 -04004986 // Test that hash preferences are enforced. BoringSSL defaults to
4987 // rejecting MD5 signatures.
4988 testCases = append(testCases, testCase{
4989 testType: serverTest,
4990 name: "SigningHash-ClientAuth-Enforced",
4991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004992 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004993 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07004994 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07004995 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004996 // Advertise SHA-1 so the handshake will
4997 // proceed, but the shim's preferences will be
4998 // ignored in CertificateVerify generation, so
4999 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07005000 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04005001 },
5002 Bugs: ProtocolBugs{
5003 IgnorePeerSignatureAlgorithmPreferences: true,
5004 },
5005 },
5006 flags: []string{"-require-any-client-certificate"},
5007 shouldFail: true,
5008 expectedError: ":WRONG_SIGNATURE_TYPE:",
5009 })
5010
5011 testCases = append(testCases, testCase{
5012 name: "SigningHash-ServerKeyExchange-Enforced",
5013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005014 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005015 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005016 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005017 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005018 },
5019 Bugs: ProtocolBugs{
5020 IgnorePeerSignatureAlgorithmPreferences: true,
5021 },
5022 },
5023 shouldFail: true,
5024 expectedError: ":WRONG_SIGNATURE_TYPE:",
5025 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005026
5027 // Test that the agreed upon digest respects the client preferences and
5028 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005029 //
5030 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04005031 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005032 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005034 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005035 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005036 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005037 signatureRSAPKCS1WithSHA512,
5038 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005039 },
5040 },
5041 flags: []string{
5042 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5043 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5044 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005045 digestPrefs: "SHA256",
5046 shouldFail: true,
5047 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005048 })
5049 testCases = append(testCases, testCase{
5050 name: "Agree-Digest-SHA256",
5051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005052 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005053 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005054 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005055 signatureRSAPKCS1WithSHA1,
5056 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005057 },
5058 },
5059 flags: []string{
5060 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5061 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5062 },
Nick Harper60edffd2016-06-21 15:19:24 -07005063 digestPrefs: "SHA256,SHA1",
5064 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005065 })
5066 testCases = append(testCases, testCase{
5067 name: "Agree-Digest-SHA1",
5068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005069 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005070 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005071 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005072 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005073 },
5074 },
5075 flags: []string{
5076 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5077 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5078 },
Nick Harper60edffd2016-06-21 15:19:24 -07005079 digestPrefs: "SHA512,SHA256,SHA1",
5080 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005081 })
5082 testCases = append(testCases, testCase{
5083 name: "Agree-Digest-Default",
5084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005085 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005086 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005087 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005088 signatureRSAPKCS1WithSHA256,
5089 signatureECDSAWithP256AndSHA256,
5090 signatureRSAPKCS1WithSHA1,
5091 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005092 },
5093 },
5094 flags: []string{
5095 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5096 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5097 },
Nick Harper60edffd2016-06-21 15:19:24 -07005098 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005099 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005100
5101 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5102 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005103 testCases = append(testCases, testCase{
5104 name: "CheckLeafCurve",
5105 config: Config{
5106 MaxVersion: VersionTLS12,
5107 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005108 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005109 },
5110 flags: []string{"-p384-only"},
5111 shouldFail: true,
5112 expectedError: ":BAD_ECC_CERT:",
5113 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005114
5115 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5116 testCases = append(testCases, testCase{
5117 name: "CheckLeafCurve-TLS13",
5118 config: Config{
5119 MaxVersion: VersionTLS13,
5120 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5121 Certificates: []Certificate{ecdsaP256Certificate},
5122 },
5123 flags: []string{"-p384-only"},
5124 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005125
5126 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5127 testCases = append(testCases, testCase{
5128 name: "ECDSACurveMismatch-Verify-TLS12",
5129 config: Config{
5130 MaxVersion: VersionTLS12,
5131 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5132 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005133 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005134 signatureECDSAWithP384AndSHA384,
5135 },
5136 },
5137 })
5138
5139 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5140 testCases = append(testCases, testCase{
5141 name: "ECDSACurveMismatch-Verify-TLS13",
5142 config: Config{
5143 MaxVersion: VersionTLS13,
5144 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5145 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005146 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005147 signatureECDSAWithP384AndSHA384,
5148 },
5149 Bugs: ProtocolBugs{
5150 SkipECDSACurveCheck: true,
5151 },
5152 },
5153 shouldFail: true,
5154 expectedError: ":WRONG_SIGNATURE_TYPE:",
5155 })
5156
5157 // Signature algorithm selection in TLS 1.3 should take the curve into
5158 // account.
5159 testCases = append(testCases, testCase{
5160 testType: serverTest,
5161 name: "ECDSACurveMismatch-Sign-TLS13",
5162 config: Config{
5163 MaxVersion: VersionTLS13,
5164 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005165 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005166 signatureECDSAWithP384AndSHA384,
5167 signatureECDSAWithP256AndSHA256,
5168 },
5169 },
5170 flags: []string{
5171 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5172 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5173 },
5174 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5175 })
David Benjamin000800a2014-11-14 01:43:59 -05005176}
5177
David Benjamin83f90402015-01-27 01:09:43 -05005178// timeouts is the retransmit schedule for BoringSSL. It doubles and
5179// caps at 60 seconds. On the 13th timeout, it gives up.
5180var timeouts = []time.Duration{
5181 1 * time.Second,
5182 2 * time.Second,
5183 4 * time.Second,
5184 8 * time.Second,
5185 16 * time.Second,
5186 32 * time.Second,
5187 60 * time.Second,
5188 60 * time.Second,
5189 60 * time.Second,
5190 60 * time.Second,
5191 60 * time.Second,
5192 60 * time.Second,
5193 60 * time.Second,
5194}
5195
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005196// shortTimeouts is an alternate set of timeouts which would occur if the
5197// initial timeout duration was set to 250ms.
5198var shortTimeouts = []time.Duration{
5199 250 * time.Millisecond,
5200 500 * time.Millisecond,
5201 1 * time.Second,
5202 2 * time.Second,
5203 4 * time.Second,
5204 8 * time.Second,
5205 16 * time.Second,
5206 32 * time.Second,
5207 60 * time.Second,
5208 60 * time.Second,
5209 60 * time.Second,
5210 60 * time.Second,
5211 60 * time.Second,
5212}
5213
David Benjamin83f90402015-01-27 01:09:43 -05005214func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005215 // These tests work by coordinating some behavior on both the shim and
5216 // the runner.
5217 //
5218 // TimeoutSchedule configures the runner to send a series of timeout
5219 // opcodes to the shim (see packetAdaptor) immediately before reading
5220 // each peer handshake flight N. The timeout opcode both simulates a
5221 // timeout in the shim and acts as a synchronization point to help the
5222 // runner bracket each handshake flight.
5223 //
5224 // We assume the shim does not read from the channel eagerly. It must
5225 // first wait until it has sent flight N and is ready to receive
5226 // handshake flight N+1. At this point, it will process the timeout
5227 // opcode. It must then immediately respond with a timeout ACK and act
5228 // as if the shim was idle for the specified amount of time.
5229 //
5230 // The runner then drops all packets received before the ACK and
5231 // continues waiting for flight N. This ordering results in one attempt
5232 // at sending flight N to be dropped. For the test to complete, the
5233 // shim must send flight N again, testing that the shim implements DTLS
5234 // retransmit on a timeout.
5235
David Benjamin4c3ddf72016-06-29 18:13:53 -04005236 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5237 // likely be more epochs to cross and the final message's retransmit may
5238 // be more complex.
5239
David Benjamin585d7a42016-06-02 14:58:00 -04005240 for _, async := range []bool{true, false} {
5241 var tests []testCase
5242
5243 // Test that this is indeed the timeout schedule. Stress all
5244 // four patterns of handshake.
5245 for i := 1; i < len(timeouts); i++ {
5246 number := strconv.Itoa(i)
5247 tests = append(tests, testCase{
5248 protocol: dtls,
5249 name: "DTLS-Retransmit-Client-" + number,
5250 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005251 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005252 Bugs: ProtocolBugs{
5253 TimeoutSchedule: timeouts[:i],
5254 },
5255 },
5256 resumeSession: true,
5257 })
5258 tests = append(tests, testCase{
5259 protocol: dtls,
5260 testType: serverTest,
5261 name: "DTLS-Retransmit-Server-" + number,
5262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005263 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005264 Bugs: ProtocolBugs{
5265 TimeoutSchedule: timeouts[:i],
5266 },
5267 },
5268 resumeSession: true,
5269 })
5270 }
5271
5272 // Test that exceeding the timeout schedule hits a read
5273 // timeout.
5274 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005275 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005276 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005277 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005278 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005279 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005280 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005281 },
5282 },
5283 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005284 shouldFail: true,
5285 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005286 })
David Benjamin585d7a42016-06-02 14:58:00 -04005287
5288 if async {
5289 // Test that timeout handling has a fudge factor, due to API
5290 // problems.
5291 tests = append(tests, testCase{
5292 protocol: dtls,
5293 name: "DTLS-Retransmit-Fudge",
5294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005295 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005296 Bugs: ProtocolBugs{
5297 TimeoutSchedule: []time.Duration{
5298 timeouts[0] - 10*time.Millisecond,
5299 },
5300 },
5301 },
5302 resumeSession: true,
5303 })
5304 }
5305
5306 // Test that the final Finished retransmitting isn't
5307 // duplicated if the peer badly fragments everything.
5308 tests = append(tests, testCase{
5309 testType: serverTest,
5310 protocol: dtls,
5311 name: "DTLS-Retransmit-Fragmented",
5312 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005313 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005314 Bugs: ProtocolBugs{
5315 TimeoutSchedule: []time.Duration{timeouts[0]},
5316 MaxHandshakeRecordLength: 2,
5317 },
5318 },
5319 })
5320
5321 // Test the timeout schedule when a shorter initial timeout duration is set.
5322 tests = append(tests, testCase{
5323 protocol: dtls,
5324 name: "DTLS-Retransmit-Short-Client",
5325 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005326 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005327 Bugs: ProtocolBugs{
5328 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5329 },
5330 },
5331 resumeSession: true,
5332 flags: []string{"-initial-timeout-duration-ms", "250"},
5333 })
5334 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005335 protocol: dtls,
5336 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005337 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005339 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005340 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005341 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005342 },
5343 },
5344 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005345 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005346 })
David Benjamin585d7a42016-06-02 14:58:00 -04005347
5348 for _, test := range tests {
5349 if async {
5350 test.name += "-Async"
5351 test.flags = append(test.flags, "-async")
5352 }
5353
5354 testCases = append(testCases, test)
5355 }
David Benjamin83f90402015-01-27 01:09:43 -05005356 }
David Benjamin83f90402015-01-27 01:09:43 -05005357}
5358
David Benjaminc565ebb2015-04-03 04:06:36 -04005359func addExportKeyingMaterialTests() {
5360 for _, vers := range tlsVersions {
5361 if vers.version == VersionSSL30 {
5362 continue
5363 }
5364 testCases = append(testCases, testCase{
5365 name: "ExportKeyingMaterial-" + vers.name,
5366 config: Config{
5367 MaxVersion: vers.version,
5368 },
5369 exportKeyingMaterial: 1024,
5370 exportLabel: "label",
5371 exportContext: "context",
5372 useExportContext: true,
5373 })
5374 testCases = append(testCases, testCase{
5375 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5376 config: Config{
5377 MaxVersion: vers.version,
5378 },
5379 exportKeyingMaterial: 1024,
5380 })
5381 testCases = append(testCases, testCase{
5382 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5383 config: Config{
5384 MaxVersion: vers.version,
5385 },
5386 exportKeyingMaterial: 1024,
5387 useExportContext: true,
5388 })
5389 testCases = append(testCases, testCase{
5390 name: "ExportKeyingMaterial-Small-" + vers.name,
5391 config: Config{
5392 MaxVersion: vers.version,
5393 },
5394 exportKeyingMaterial: 1,
5395 exportLabel: "label",
5396 exportContext: "context",
5397 useExportContext: true,
5398 })
5399 }
5400 testCases = append(testCases, testCase{
5401 name: "ExportKeyingMaterial-SSL3",
5402 config: Config{
5403 MaxVersion: VersionSSL30,
5404 },
5405 exportKeyingMaterial: 1024,
5406 exportLabel: "label",
5407 exportContext: "context",
5408 useExportContext: true,
5409 shouldFail: true,
5410 expectedError: "failed to export keying material",
5411 })
5412}
5413
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005414func addTLSUniqueTests() {
5415 for _, isClient := range []bool{false, true} {
5416 for _, isResumption := range []bool{false, true} {
5417 for _, hasEMS := range []bool{false, true} {
5418 var suffix string
5419 if isResumption {
5420 suffix = "Resume-"
5421 } else {
5422 suffix = "Full-"
5423 }
5424
5425 if hasEMS {
5426 suffix += "EMS-"
5427 } else {
5428 suffix += "NoEMS-"
5429 }
5430
5431 if isClient {
5432 suffix += "Client"
5433 } else {
5434 suffix += "Server"
5435 }
5436
5437 test := testCase{
5438 name: "TLSUnique-" + suffix,
5439 testTLSUnique: true,
5440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005441 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005442 Bugs: ProtocolBugs{
5443 NoExtendedMasterSecret: !hasEMS,
5444 },
5445 },
5446 }
5447
5448 if isResumption {
5449 test.resumeSession = true
5450 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005451 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005452 Bugs: ProtocolBugs{
5453 NoExtendedMasterSecret: !hasEMS,
5454 },
5455 }
5456 }
5457
5458 if isResumption && !hasEMS {
5459 test.shouldFail = true
5460 test.expectedError = "failed to get tls-unique"
5461 }
5462
5463 testCases = append(testCases, test)
5464 }
5465 }
5466 }
5467}
5468
Adam Langley09505632015-07-30 18:10:13 -07005469func addCustomExtensionTests() {
5470 expectedContents := "custom extension"
5471 emptyString := ""
5472
David Benjamin4c3ddf72016-06-29 18:13:53 -04005473 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005474 for _, isClient := range []bool{false, true} {
5475 suffix := "Server"
5476 flag := "-enable-server-custom-extension"
5477 testType := serverTest
5478 if isClient {
5479 suffix = "Client"
5480 flag = "-enable-client-custom-extension"
5481 testType = clientTest
5482 }
5483
5484 testCases = append(testCases, testCase{
5485 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005486 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005487 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005488 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005489 Bugs: ProtocolBugs{
5490 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005491 ExpectedCustomExtension: &expectedContents,
5492 },
5493 },
5494 flags: []string{flag},
5495 })
5496
5497 // If the parse callback fails, the handshake should also fail.
5498 testCases = append(testCases, testCase{
5499 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005500 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005501 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005502 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005503 Bugs: ProtocolBugs{
5504 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005505 ExpectedCustomExtension: &expectedContents,
5506 },
5507 },
David Benjamin399e7c92015-07-30 23:01:27 -04005508 flags: []string{flag},
5509 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005510 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5511 })
5512
5513 // If the add callback fails, the handshake should also fail.
5514 testCases = append(testCases, testCase{
5515 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005516 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005518 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005519 Bugs: ProtocolBugs{
5520 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005521 ExpectedCustomExtension: &expectedContents,
5522 },
5523 },
David Benjamin399e7c92015-07-30 23:01:27 -04005524 flags: []string{flag, "-custom-extension-fail-add"},
5525 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005526 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5527 })
5528
5529 // If the add callback returns zero, no extension should be
5530 // added.
5531 skipCustomExtension := expectedContents
5532 if isClient {
5533 // For the case where the client skips sending the
5534 // custom extension, the server must not “echo” it.
5535 skipCustomExtension = ""
5536 }
5537 testCases = append(testCases, testCase{
5538 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005539 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005540 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005541 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005542 Bugs: ProtocolBugs{
5543 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005544 ExpectedCustomExtension: &emptyString,
5545 },
5546 },
5547 flags: []string{flag, "-custom-extension-skip"},
5548 })
5549 }
5550
5551 // The custom extension add callback should not be called if the client
5552 // doesn't send the extension.
5553 testCases = append(testCases, testCase{
5554 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005555 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005557 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005558 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005559 ExpectedCustomExtension: &emptyString,
5560 },
5561 },
5562 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5563 })
Adam Langley2deb9842015-08-07 11:15:37 -07005564
5565 // Test an unknown extension from the server.
5566 testCases = append(testCases, testCase{
5567 testType: clientTest,
5568 name: "UnknownExtension-Client",
5569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005570 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005571 Bugs: ProtocolBugs{
5572 CustomExtension: expectedContents,
5573 },
5574 },
5575 shouldFail: true,
5576 expectedError: ":UNEXPECTED_EXTENSION:",
5577 })
Adam Langley09505632015-07-30 18:10:13 -07005578}
5579
David Benjaminb36a3952015-12-01 18:53:13 -05005580func addRSAClientKeyExchangeTests() {
5581 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5582 testCases = append(testCases, testCase{
5583 testType: serverTest,
5584 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5585 config: Config{
5586 // Ensure the ClientHello version and final
5587 // version are different, to detect if the
5588 // server uses the wrong one.
5589 MaxVersion: VersionTLS11,
5590 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5591 Bugs: ProtocolBugs{
5592 BadRSAClientKeyExchange: bad,
5593 },
5594 },
5595 shouldFail: true,
5596 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5597 })
5598 }
5599}
5600
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005601var testCurves = []struct {
5602 name string
5603 id CurveID
5604}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005605 {"P-256", CurveP256},
5606 {"P-384", CurveP384},
5607 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005608 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005609}
5610
5611func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005612 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005613 for _, curve := range testCurves {
5614 testCases = append(testCases, testCase{
5615 name: "CurveTest-Client-" + curve.name,
5616 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005617 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005618 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5619 CurvePreferences: []CurveID{curve.id},
5620 },
5621 flags: []string{"-enable-all-curves"},
5622 })
5623 testCases = append(testCases, testCase{
5624 testType: serverTest,
5625 name: "CurveTest-Server-" + curve.name,
5626 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005627 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005628 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5629 CurvePreferences: []CurveID{curve.id},
5630 },
5631 flags: []string{"-enable-all-curves"},
5632 })
5633 }
David Benjamin241ae832016-01-15 03:04:54 -05005634
5635 // The server must be tolerant to bogus curves.
5636 const bogusCurve = 0x1234
5637 testCases = append(testCases, testCase{
5638 testType: serverTest,
5639 name: "UnknownCurve",
5640 config: Config{
5641 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5642 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5643 },
5644 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005645
5646 // The server must not consider ECDHE ciphers when there are no
5647 // supported curves.
5648 testCases = append(testCases, testCase{
5649 testType: serverTest,
5650 name: "NoSupportedCurves",
5651 config: Config{
5652 // TODO(davidben): Add a TLS 1.3 version of this.
5653 MaxVersion: VersionTLS12,
5654 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5655 Bugs: ProtocolBugs{
5656 NoSupportedCurves: true,
5657 },
5658 },
5659 shouldFail: true,
5660 expectedError: ":NO_SHARED_CIPHER:",
5661 })
5662
5663 // The server must fall back to another cipher when there are no
5664 // supported curves.
5665 testCases = append(testCases, testCase{
5666 testType: serverTest,
5667 name: "NoCommonCurves",
5668 config: Config{
5669 MaxVersion: VersionTLS12,
5670 CipherSuites: []uint16{
5671 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5672 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5673 },
5674 CurvePreferences: []CurveID{CurveP224},
5675 },
5676 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5677 })
5678
5679 // The client must reject bogus curves and disabled curves.
5680 testCases = append(testCases, testCase{
5681 name: "BadECDHECurve",
5682 config: Config{
5683 // TODO(davidben): Add a TLS 1.3 version of this.
5684 MaxVersion: VersionTLS12,
5685 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5686 Bugs: ProtocolBugs{
5687 SendCurve: bogusCurve,
5688 },
5689 },
5690 shouldFail: true,
5691 expectedError: ":WRONG_CURVE:",
5692 })
5693
5694 testCases = append(testCases, testCase{
5695 name: "UnsupportedCurve",
5696 config: Config{
5697 // TODO(davidben): Add a TLS 1.3 version of this.
5698 MaxVersion: VersionTLS12,
5699 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5700 CurvePreferences: []CurveID{CurveP256},
5701 Bugs: ProtocolBugs{
5702 IgnorePeerCurvePreferences: true,
5703 },
5704 },
5705 flags: []string{"-p384-only"},
5706 shouldFail: true,
5707 expectedError: ":WRONG_CURVE:",
5708 })
5709
5710 // Test invalid curve points.
5711 testCases = append(testCases, testCase{
5712 name: "InvalidECDHPoint-Client",
5713 config: Config{
5714 // TODO(davidben): Add a TLS 1.3 version of this test.
5715 MaxVersion: VersionTLS12,
5716 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5717 CurvePreferences: []CurveID{CurveP256},
5718 Bugs: ProtocolBugs{
5719 InvalidECDHPoint: true,
5720 },
5721 },
5722 shouldFail: true,
5723 expectedError: ":INVALID_ENCODING:",
5724 })
5725 testCases = append(testCases, testCase{
5726 testType: serverTest,
5727 name: "InvalidECDHPoint-Server",
5728 config: Config{
5729 // TODO(davidben): Add a TLS 1.3 version of this test.
5730 MaxVersion: VersionTLS12,
5731 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5732 CurvePreferences: []CurveID{CurveP256},
5733 Bugs: ProtocolBugs{
5734 InvalidECDHPoint: true,
5735 },
5736 },
5737 shouldFail: true,
5738 expectedError: ":INVALID_ENCODING:",
5739 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005740}
5741
Matt Braithwaite54217e42016-06-13 13:03:47 -07005742func addCECPQ1Tests() {
5743 testCases = append(testCases, testCase{
5744 testType: clientTest,
5745 name: "CECPQ1-Client-BadX25519Part",
5746 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005747 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005748 MinVersion: VersionTLS12,
5749 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5750 Bugs: ProtocolBugs{
5751 CECPQ1BadX25519Part: true,
5752 },
5753 },
5754 flags: []string{"-cipher", "kCECPQ1"},
5755 shouldFail: true,
5756 expectedLocalError: "local error: bad record MAC",
5757 })
5758 testCases = append(testCases, testCase{
5759 testType: clientTest,
5760 name: "CECPQ1-Client-BadNewhopePart",
5761 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005762 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005763 MinVersion: VersionTLS12,
5764 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5765 Bugs: ProtocolBugs{
5766 CECPQ1BadNewhopePart: true,
5767 },
5768 },
5769 flags: []string{"-cipher", "kCECPQ1"},
5770 shouldFail: true,
5771 expectedLocalError: "local error: bad record MAC",
5772 })
5773 testCases = append(testCases, testCase{
5774 testType: serverTest,
5775 name: "CECPQ1-Server-BadX25519Part",
5776 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005777 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005778 MinVersion: VersionTLS12,
5779 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5780 Bugs: ProtocolBugs{
5781 CECPQ1BadX25519Part: true,
5782 },
5783 },
5784 flags: []string{"-cipher", "kCECPQ1"},
5785 shouldFail: true,
5786 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5787 })
5788 testCases = append(testCases, testCase{
5789 testType: serverTest,
5790 name: "CECPQ1-Server-BadNewhopePart",
5791 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005792 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005793 MinVersion: VersionTLS12,
5794 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5795 Bugs: ProtocolBugs{
5796 CECPQ1BadNewhopePart: true,
5797 },
5798 },
5799 flags: []string{"-cipher", "kCECPQ1"},
5800 shouldFail: true,
5801 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5802 })
5803}
5804
David Benjamin4cc36ad2015-12-19 14:23:26 -05005805func addKeyExchangeInfoTests() {
5806 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005807 name: "KeyExchangeInfo-DHE-Client",
5808 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005809 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005810 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5811 Bugs: ProtocolBugs{
5812 // This is a 1234-bit prime number, generated
5813 // with:
5814 // openssl gendh 1234 | openssl asn1parse -i
5815 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5816 },
5817 },
David Benjamin9e68f192016-06-30 14:55:33 -04005818 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005819 })
5820 testCases = append(testCases, testCase{
5821 testType: serverTest,
5822 name: "KeyExchangeInfo-DHE-Server",
5823 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005824 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005825 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5826 },
5827 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005828 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005829 })
5830
Nick Harper1fd39d82016-06-14 18:14:35 -07005831 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5832 // handshake is separate.
5833
David Benjamin4cc36ad2015-12-19 14:23:26 -05005834 testCases = append(testCases, testCase{
5835 name: "KeyExchangeInfo-ECDHE-Client",
5836 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005837 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5839 CurvePreferences: []CurveID{CurveX25519},
5840 },
David Benjamin9e68f192016-06-30 14:55:33 -04005841 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005842 })
5843 testCases = append(testCases, testCase{
5844 testType: serverTest,
5845 name: "KeyExchangeInfo-ECDHE-Server",
5846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005847 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5849 CurvePreferences: []CurveID{CurveX25519},
5850 },
David Benjamin9e68f192016-06-30 14:55:33 -04005851 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005852 })
5853}
5854
David Benjaminc9ae27c2016-06-24 22:56:37 -04005855func addTLS13RecordTests() {
5856 testCases = append(testCases, testCase{
5857 name: "TLS13-RecordPadding",
5858 config: Config{
5859 MaxVersion: VersionTLS13,
5860 MinVersion: VersionTLS13,
5861 Bugs: ProtocolBugs{
5862 RecordPadding: 10,
5863 },
5864 },
5865 })
5866
5867 testCases = append(testCases, testCase{
5868 name: "TLS13-EmptyRecords",
5869 config: Config{
5870 MaxVersion: VersionTLS13,
5871 MinVersion: VersionTLS13,
5872 Bugs: ProtocolBugs{
5873 OmitRecordContents: true,
5874 },
5875 },
5876 shouldFail: true,
5877 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5878 })
5879
5880 testCases = append(testCases, testCase{
5881 name: "TLS13-OnlyPadding",
5882 config: Config{
5883 MaxVersion: VersionTLS13,
5884 MinVersion: VersionTLS13,
5885 Bugs: ProtocolBugs{
5886 OmitRecordContents: true,
5887 RecordPadding: 10,
5888 },
5889 },
5890 shouldFail: true,
5891 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5892 })
5893
5894 testCases = append(testCases, testCase{
5895 name: "TLS13-WrongOuterRecord",
5896 config: Config{
5897 MaxVersion: VersionTLS13,
5898 MinVersion: VersionTLS13,
5899 Bugs: ProtocolBugs{
5900 OuterRecordType: recordTypeHandshake,
5901 },
5902 },
5903 shouldFail: true,
5904 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5905 })
5906}
5907
David Benjamin82261be2016-07-07 14:32:50 -07005908func addChangeCipherSpecTests() {
5909 // Test missing ChangeCipherSpecs.
5910 testCases = append(testCases, testCase{
5911 name: "SkipChangeCipherSpec-Client",
5912 config: Config{
5913 MaxVersion: VersionTLS12,
5914 Bugs: ProtocolBugs{
5915 SkipChangeCipherSpec: true,
5916 },
5917 },
5918 shouldFail: true,
5919 expectedError: ":UNEXPECTED_RECORD:",
5920 })
5921 testCases = append(testCases, testCase{
5922 testType: serverTest,
5923 name: "SkipChangeCipherSpec-Server",
5924 config: Config{
5925 MaxVersion: VersionTLS12,
5926 Bugs: ProtocolBugs{
5927 SkipChangeCipherSpec: true,
5928 },
5929 },
5930 shouldFail: true,
5931 expectedError: ":UNEXPECTED_RECORD:",
5932 })
5933 testCases = append(testCases, testCase{
5934 testType: serverTest,
5935 name: "SkipChangeCipherSpec-Server-NPN",
5936 config: Config{
5937 MaxVersion: VersionTLS12,
5938 NextProtos: []string{"bar"},
5939 Bugs: ProtocolBugs{
5940 SkipChangeCipherSpec: true,
5941 },
5942 },
5943 flags: []string{
5944 "-advertise-npn", "\x03foo\x03bar\x03baz",
5945 },
5946 shouldFail: true,
5947 expectedError: ":UNEXPECTED_RECORD:",
5948 })
5949
5950 // Test synchronization between the handshake and ChangeCipherSpec.
5951 // Partial post-CCS handshake messages before ChangeCipherSpec should be
5952 // rejected. Test both with and without handshake packing to handle both
5953 // when the partial post-CCS message is in its own record and when it is
5954 // attached to the pre-CCS message.
5955 //
5956 // TODO(davidben): Fix and test DTLS as well.
5957 for _, packed := range []bool{false, true} {
5958 var suffix string
5959 if packed {
5960 suffix = "-Packed"
5961 }
5962
5963 testCases = append(testCases, testCase{
5964 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
5965 config: Config{
5966 MaxVersion: VersionTLS12,
5967 Bugs: ProtocolBugs{
5968 FragmentAcrossChangeCipherSpec: true,
5969 PackHandshakeFlight: packed,
5970 },
5971 },
5972 shouldFail: true,
5973 expectedError: ":UNEXPECTED_RECORD:",
5974 })
5975 testCases = append(testCases, testCase{
5976 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
5977 config: Config{
5978 MaxVersion: VersionTLS12,
5979 },
5980 resumeSession: true,
5981 resumeConfig: &Config{
5982 MaxVersion: VersionTLS12,
5983 Bugs: ProtocolBugs{
5984 FragmentAcrossChangeCipherSpec: true,
5985 PackHandshakeFlight: packed,
5986 },
5987 },
5988 shouldFail: true,
5989 expectedError: ":UNEXPECTED_RECORD:",
5990 })
5991 testCases = append(testCases, testCase{
5992 testType: serverTest,
5993 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
5994 config: Config{
5995 MaxVersion: VersionTLS12,
5996 Bugs: ProtocolBugs{
5997 FragmentAcrossChangeCipherSpec: true,
5998 PackHandshakeFlight: packed,
5999 },
6000 },
6001 shouldFail: true,
6002 expectedError: ":UNEXPECTED_RECORD:",
6003 })
6004 testCases = append(testCases, testCase{
6005 testType: serverTest,
6006 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6007 config: Config{
6008 MaxVersion: VersionTLS12,
6009 },
6010 resumeSession: true,
6011 resumeConfig: &Config{
6012 MaxVersion: VersionTLS12,
6013 Bugs: ProtocolBugs{
6014 FragmentAcrossChangeCipherSpec: true,
6015 PackHandshakeFlight: packed,
6016 },
6017 },
6018 shouldFail: true,
6019 expectedError: ":UNEXPECTED_RECORD:",
6020 })
6021 testCases = append(testCases, testCase{
6022 testType: serverTest,
6023 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6024 config: Config{
6025 MaxVersion: VersionTLS12,
6026 NextProtos: []string{"bar"},
6027 Bugs: ProtocolBugs{
6028 FragmentAcrossChangeCipherSpec: true,
6029 PackHandshakeFlight: packed,
6030 },
6031 },
6032 flags: []string{
6033 "-advertise-npn", "\x03foo\x03bar\x03baz",
6034 },
6035 shouldFail: true,
6036 expectedError: ":UNEXPECTED_RECORD:",
6037 })
6038 }
6039
6040 // Test that early ChangeCipherSpecs are handled correctly.
6041 testCases = append(testCases, testCase{
6042 testType: serverTest,
6043 name: "EarlyChangeCipherSpec-server-1",
6044 config: Config{
6045 MaxVersion: VersionTLS12,
6046 Bugs: ProtocolBugs{
6047 EarlyChangeCipherSpec: 1,
6048 },
6049 },
6050 shouldFail: true,
6051 expectedError: ":UNEXPECTED_RECORD:",
6052 })
6053 testCases = append(testCases, testCase{
6054 testType: serverTest,
6055 name: "EarlyChangeCipherSpec-server-2",
6056 config: Config{
6057 MaxVersion: VersionTLS12,
6058 Bugs: ProtocolBugs{
6059 EarlyChangeCipherSpec: 2,
6060 },
6061 },
6062 shouldFail: true,
6063 expectedError: ":UNEXPECTED_RECORD:",
6064 })
6065 testCases = append(testCases, testCase{
6066 protocol: dtls,
6067 name: "StrayChangeCipherSpec",
6068 config: Config{
6069 // TODO(davidben): Once DTLS 1.3 exists, test
6070 // that stray ChangeCipherSpec messages are
6071 // rejected.
6072 MaxVersion: VersionTLS12,
6073 Bugs: ProtocolBugs{
6074 StrayChangeCipherSpec: true,
6075 },
6076 },
6077 })
6078
6079 // Test that the contents of ChangeCipherSpec are checked.
6080 testCases = append(testCases, testCase{
6081 name: "BadChangeCipherSpec-1",
6082 config: Config{
6083 MaxVersion: VersionTLS12,
6084 Bugs: ProtocolBugs{
6085 BadChangeCipherSpec: []byte{2},
6086 },
6087 },
6088 shouldFail: true,
6089 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6090 })
6091 testCases = append(testCases, testCase{
6092 name: "BadChangeCipherSpec-2",
6093 config: Config{
6094 MaxVersion: VersionTLS12,
6095 Bugs: ProtocolBugs{
6096 BadChangeCipherSpec: []byte{1, 1},
6097 },
6098 },
6099 shouldFail: true,
6100 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6101 })
6102 testCases = append(testCases, testCase{
6103 protocol: dtls,
6104 name: "BadChangeCipherSpec-DTLS-1",
6105 config: Config{
6106 MaxVersion: VersionTLS12,
6107 Bugs: ProtocolBugs{
6108 BadChangeCipherSpec: []byte{2},
6109 },
6110 },
6111 shouldFail: true,
6112 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6113 })
6114 testCases = append(testCases, testCase{
6115 protocol: dtls,
6116 name: "BadChangeCipherSpec-DTLS-2",
6117 config: Config{
6118 MaxVersion: VersionTLS12,
6119 Bugs: ProtocolBugs{
6120 BadChangeCipherSpec: []byte{1, 1},
6121 },
6122 },
6123 shouldFail: true,
6124 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6125 })
6126}
6127
Adam Langley7c803a62015-06-15 15:35:05 -07006128func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006129 defer wg.Done()
6130
6131 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006132 var err error
6133
6134 if *mallocTest < 0 {
6135 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006136 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006137 } else {
6138 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6139 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006140 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006141 if err != nil {
6142 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6143 }
6144 break
6145 }
6146 }
6147 }
Adam Langley95c29f32014-06-20 12:00:00 -07006148 statusChan <- statusMsg{test: test, err: err}
6149 }
6150}
6151
6152type statusMsg struct {
6153 test *testCase
6154 started bool
6155 err error
6156}
6157
David Benjamin5f237bc2015-02-11 17:14:15 -05006158func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006159 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006160
David Benjamin5f237bc2015-02-11 17:14:15 -05006161 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006162 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006163 if !*pipe {
6164 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006165 var erase string
6166 for i := 0; i < lineLen; i++ {
6167 erase += "\b \b"
6168 }
6169 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006170 }
6171
Adam Langley95c29f32014-06-20 12:00:00 -07006172 if msg.started {
6173 started++
6174 } else {
6175 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006176
6177 if msg.err != nil {
6178 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6179 failed++
6180 testOutput.addResult(msg.test.name, "FAIL")
6181 } else {
6182 if *pipe {
6183 // Print each test instead of a status line.
6184 fmt.Printf("PASSED (%s)\n", msg.test.name)
6185 }
6186 testOutput.addResult(msg.test.name, "PASS")
6187 }
Adam Langley95c29f32014-06-20 12:00:00 -07006188 }
6189
David Benjamin5f237bc2015-02-11 17:14:15 -05006190 if !*pipe {
6191 // Print a new status line.
6192 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6193 lineLen = len(line)
6194 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006195 }
Adam Langley95c29f32014-06-20 12:00:00 -07006196 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006197
6198 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006199}
6200
6201func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006202 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006203 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006204 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006205
Adam Langley7c803a62015-06-15 15:35:05 -07006206 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006207 addCipherSuiteTests()
6208 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006209 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006210 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006211 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006212 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006213 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006214 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006215 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006216 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006217 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006218 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006219 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006220 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006221 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006222 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006223 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006224 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006225 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006226 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006227 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006228 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006229 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006230 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006231 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006232
6233 var wg sync.WaitGroup
6234
Adam Langley7c803a62015-06-15 15:35:05 -07006235 statusChan := make(chan statusMsg, *numWorkers)
6236 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006237 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006238
David Benjamin025b3d32014-07-01 19:53:04 -04006239 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006240
Adam Langley7c803a62015-06-15 15:35:05 -07006241 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006242 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006243 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006244 }
6245
David Benjamin270f0a72016-03-17 14:41:36 -04006246 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006247 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006248 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006249 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006250 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006251 }
6252 }
David Benjamin270f0a72016-03-17 14:41:36 -04006253 if !foundTest {
6254 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6255 os.Exit(1)
6256 }
Adam Langley95c29f32014-06-20 12:00:00 -07006257
6258 close(testChan)
6259 wg.Wait()
6260 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006261 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006262
6263 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006264
6265 if *jsonOutput != "" {
6266 if err := testOutput.writeTo(*jsonOutput); err != nil {
6267 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6268 }
6269 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006270
6271 if !testOutput.allPassed {
6272 os.Exit(1)
6273 }
Adam Langley95c29f32014-06-20 12:00:00 -07006274}