blob: 5e424cac0aa88c2f759103a3c90b0630c50f0530 [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 Benjamin7e2e6cf2014-08-07 17:44:24 -04003617}
3618
David Benjaminaccb4542014-12-12 23:44:33 -05003619func addMinimumVersionTests() {
3620 for i, shimVers := range tlsVersions {
3621 // Assemble flags to disable all older versions on the shim.
3622 var flags []string
3623 for _, vers := range tlsVersions[:i] {
3624 flags = append(flags, vers.flag)
3625 }
3626
3627 for _, runnerVers := range tlsVersions {
3628 protocols := []protocol{tls}
3629 if runnerVers.hasDTLS && shimVers.hasDTLS {
3630 protocols = append(protocols, dtls)
3631 }
3632 for _, protocol := range protocols {
3633 suffix := shimVers.name + "-" + runnerVers.name
3634 if protocol == dtls {
3635 suffix += "-DTLS"
3636 }
3637 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3638
David Benjaminaccb4542014-12-12 23:44:33 -05003639 var expectedVersion uint16
3640 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003641 var expectedClientError, expectedServerError string
3642 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003643 if runnerVers.version >= shimVers.version {
3644 expectedVersion = runnerVers.version
3645 } else {
3646 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003647 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3648 expectedServerLocalError = "remote error: protocol version not supported"
3649 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3650 // If the client's minimum version is TLS 1.3 and the runner's
3651 // maximum is below TLS 1.2, the runner will fail to select a
3652 // cipher before the shim rejects the selected version.
3653 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3654 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3655 } else {
3656 expectedClientError = expectedServerError
3657 expectedClientLocalError = expectedServerLocalError
3658 }
David Benjaminaccb4542014-12-12 23:44:33 -05003659 }
3660
3661 testCases = append(testCases, testCase{
3662 protocol: protocol,
3663 testType: clientTest,
3664 name: "MinimumVersion-Client-" + suffix,
3665 config: Config{
3666 MaxVersion: runnerVers.version,
3667 },
David Benjamin87909c02014-12-13 01:55:01 -05003668 flags: flags,
3669 expectedVersion: expectedVersion,
3670 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003671 expectedError: expectedClientError,
3672 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003673 })
3674 testCases = append(testCases, testCase{
3675 protocol: protocol,
3676 testType: clientTest,
3677 name: "MinimumVersion-Client2-" + suffix,
3678 config: Config{
3679 MaxVersion: runnerVers.version,
3680 },
David Benjamin87909c02014-12-13 01:55:01 -05003681 flags: []string{"-min-version", shimVersFlag},
3682 expectedVersion: expectedVersion,
3683 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003684 expectedError: expectedClientError,
3685 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003686 })
3687
3688 testCases = append(testCases, testCase{
3689 protocol: protocol,
3690 testType: serverTest,
3691 name: "MinimumVersion-Server-" + suffix,
3692 config: Config{
3693 MaxVersion: runnerVers.version,
3694 },
David Benjamin87909c02014-12-13 01:55:01 -05003695 flags: flags,
3696 expectedVersion: expectedVersion,
3697 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003698 expectedError: expectedServerError,
3699 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003700 })
3701 testCases = append(testCases, testCase{
3702 protocol: protocol,
3703 testType: serverTest,
3704 name: "MinimumVersion-Server2-" + suffix,
3705 config: Config{
3706 MaxVersion: runnerVers.version,
3707 },
David Benjamin87909c02014-12-13 01:55:01 -05003708 flags: []string{"-min-version", shimVersFlag},
3709 expectedVersion: expectedVersion,
3710 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003711 expectedError: expectedServerError,
3712 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003713 })
3714 }
3715 }
3716 }
3717}
3718
David Benjamine78bfde2014-09-06 12:45:15 -04003719func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003720 // TODO(davidben): Extensions, where applicable, all move their server
3721 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3722 // tests for both. Also test interaction with 0-RTT when implemented.
3723
David Benjamine78bfde2014-09-06 12:45:15 -04003724 testCases = append(testCases, testCase{
3725 testType: clientTest,
3726 name: "DuplicateExtensionClient",
3727 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003728 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003729 Bugs: ProtocolBugs{
3730 DuplicateExtension: true,
3731 },
3732 },
3733 shouldFail: true,
3734 expectedLocalError: "remote error: error decoding message",
3735 })
3736 testCases = append(testCases, testCase{
3737 testType: serverTest,
3738 name: "DuplicateExtensionServer",
3739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003740 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003741 Bugs: ProtocolBugs{
3742 DuplicateExtension: true,
3743 },
3744 },
3745 shouldFail: true,
3746 expectedLocalError: "remote error: error decoding message",
3747 })
3748 testCases = append(testCases, testCase{
3749 testType: clientTest,
3750 name: "ServerNameExtensionClient",
3751 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003752 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003753 Bugs: ProtocolBugs{
3754 ExpectServerName: "example.com",
3755 },
3756 },
3757 flags: []string{"-host-name", "example.com"},
3758 })
3759 testCases = append(testCases, testCase{
3760 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003761 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003763 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003764 Bugs: ProtocolBugs{
3765 ExpectServerName: "mismatch.com",
3766 },
3767 },
3768 flags: []string{"-host-name", "example.com"},
3769 shouldFail: true,
3770 expectedLocalError: "tls: unexpected server name",
3771 })
3772 testCases = append(testCases, testCase{
3773 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003774 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003775 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003776 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003777 Bugs: ProtocolBugs{
3778 ExpectServerName: "missing.com",
3779 },
3780 },
3781 shouldFail: true,
3782 expectedLocalError: "tls: unexpected server name",
3783 })
3784 testCases = append(testCases, testCase{
3785 testType: serverTest,
3786 name: "ServerNameExtensionServer",
3787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003788 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003789 ServerName: "example.com",
3790 },
3791 flags: []string{"-expect-server-name", "example.com"},
3792 resumeSession: true,
3793 })
David Benjaminae2888f2014-09-06 12:58:58 -04003794 testCases = append(testCases, testCase{
3795 testType: clientTest,
3796 name: "ALPNClient",
3797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003798 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003799 NextProtos: []string{"foo"},
3800 },
3801 flags: []string{
3802 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3803 "-expect-alpn", "foo",
3804 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003805 expectedNextProto: "foo",
3806 expectedNextProtoType: alpn,
3807 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003808 })
3809 testCases = append(testCases, testCase{
3810 testType: serverTest,
3811 name: "ALPNServer",
3812 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003813 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003814 NextProtos: []string{"foo", "bar", "baz"},
3815 },
3816 flags: []string{
3817 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3818 "-select-alpn", "foo",
3819 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003820 expectedNextProto: "foo",
3821 expectedNextProtoType: alpn,
3822 resumeSession: true,
3823 })
David Benjamin594e7d22016-03-17 17:49:56 -04003824 testCases = append(testCases, testCase{
3825 testType: serverTest,
3826 name: "ALPNServer-Decline",
3827 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003828 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003829 NextProtos: []string{"foo", "bar", "baz"},
3830 },
3831 flags: []string{"-decline-alpn"},
3832 expectNoNextProto: true,
3833 resumeSession: true,
3834 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003835 // Test that the server prefers ALPN over NPN.
3836 testCases = append(testCases, testCase{
3837 testType: serverTest,
3838 name: "ALPNServer-Preferred",
3839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003840 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003841 NextProtos: []string{"foo", "bar", "baz"},
3842 },
3843 flags: []string{
3844 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3845 "-select-alpn", "foo",
3846 "-advertise-npn", "\x03foo\x03bar\x03baz",
3847 },
3848 expectedNextProto: "foo",
3849 expectedNextProtoType: alpn,
3850 resumeSession: true,
3851 })
3852 testCases = append(testCases, testCase{
3853 testType: serverTest,
3854 name: "ALPNServer-Preferred-Swapped",
3855 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003856 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003857 NextProtos: []string{"foo", "bar", "baz"},
3858 Bugs: ProtocolBugs{
3859 SwapNPNAndALPN: true,
3860 },
3861 },
3862 flags: []string{
3863 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3864 "-select-alpn", "foo",
3865 "-advertise-npn", "\x03foo\x03bar\x03baz",
3866 },
3867 expectedNextProto: "foo",
3868 expectedNextProtoType: alpn,
3869 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003870 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003871 var emptyString string
3872 testCases = append(testCases, testCase{
3873 testType: clientTest,
3874 name: "ALPNClient-EmptyProtocolName",
3875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003876 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003877 NextProtos: []string{""},
3878 Bugs: ProtocolBugs{
3879 // A server returning an empty ALPN protocol
3880 // should be rejected.
3881 ALPNProtocol: &emptyString,
3882 },
3883 },
3884 flags: []string{
3885 "-advertise-alpn", "\x03foo",
3886 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003887 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003888 expectedError: ":PARSE_TLSEXT:",
3889 })
3890 testCases = append(testCases, testCase{
3891 testType: serverTest,
3892 name: "ALPNServer-EmptyProtocolName",
3893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003894 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003895 // A ClientHello containing an empty ALPN protocol
3896 // should be rejected.
3897 NextProtos: []string{"foo", "", "baz"},
3898 },
3899 flags: []string{
3900 "-select-alpn", "foo",
3901 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003902 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003903 expectedError: ":PARSE_TLSEXT:",
3904 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003905 // Test that negotiating both NPN and ALPN is forbidden.
3906 testCases = append(testCases, testCase{
3907 name: "NegotiateALPNAndNPN",
3908 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003909 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003910 NextProtos: []string{"foo", "bar", "baz"},
3911 Bugs: ProtocolBugs{
3912 NegotiateALPNAndNPN: true,
3913 },
3914 },
3915 flags: []string{
3916 "-advertise-alpn", "\x03foo",
3917 "-select-next-proto", "foo",
3918 },
3919 shouldFail: true,
3920 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3921 })
3922 testCases = append(testCases, testCase{
3923 name: "NegotiateALPNAndNPN-Swapped",
3924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003925 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003926 NextProtos: []string{"foo", "bar", "baz"},
3927 Bugs: ProtocolBugs{
3928 NegotiateALPNAndNPN: true,
3929 SwapNPNAndALPN: true,
3930 },
3931 },
3932 flags: []string{
3933 "-advertise-alpn", "\x03foo",
3934 "-select-next-proto", "foo",
3935 },
3936 shouldFail: true,
3937 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3938 })
David Benjamin091c4b92015-10-26 13:33:21 -04003939 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3940 testCases = append(testCases, testCase{
3941 name: "DisableNPN",
3942 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003943 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04003944 NextProtos: []string{"foo"},
3945 },
3946 flags: []string{
3947 "-select-next-proto", "foo",
3948 "-disable-npn",
3949 },
3950 expectNoNextProto: true,
3951 })
Adam Langley38311732014-10-16 19:04:35 -07003952 // Resume with a corrupt ticket.
3953 testCases = append(testCases, testCase{
3954 testType: serverTest,
3955 name: "CorruptTicket",
3956 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003957 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003958 Bugs: ProtocolBugs{
3959 CorruptTicket: true,
3960 },
3961 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003962 resumeSession: true,
3963 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003964 })
David Benjamind98452d2015-06-16 14:16:23 -04003965 // Test the ticket callback, with and without renewal.
3966 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003967 testType: serverTest,
3968 name: "TicketCallback",
3969 config: Config{
3970 MaxVersion: VersionTLS12,
3971 },
David Benjamind98452d2015-06-16 14:16:23 -04003972 resumeSession: true,
3973 flags: []string{"-use-ticket-callback"},
3974 })
3975 testCases = append(testCases, testCase{
3976 testType: serverTest,
3977 name: "TicketCallback-Renew",
3978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04003980 Bugs: ProtocolBugs{
3981 ExpectNewTicket: true,
3982 },
3983 },
3984 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3985 resumeSession: true,
3986 })
Adam Langley38311732014-10-16 19:04:35 -07003987 // Resume with an oversized session id.
3988 testCases = append(testCases, testCase{
3989 testType: serverTest,
3990 name: "OversizedSessionId",
3991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003992 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003993 Bugs: ProtocolBugs{
3994 OversizedSessionId: true,
3995 },
3996 },
3997 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003998 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003999 expectedError: ":DECODE_ERROR:",
4000 })
David Benjaminca6c8262014-11-15 19:06:08 -05004001 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4002 // are ignored.
4003 testCases = append(testCases, testCase{
4004 protocol: dtls,
4005 name: "SRTP-Client",
4006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004007 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004008 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4009 },
4010 flags: []string{
4011 "-srtp-profiles",
4012 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4013 },
4014 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4015 })
4016 testCases = append(testCases, testCase{
4017 protocol: dtls,
4018 testType: serverTest,
4019 name: "SRTP-Server",
4020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004021 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004022 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4023 },
4024 flags: []string{
4025 "-srtp-profiles",
4026 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4027 },
4028 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4029 })
4030 // Test that the MKI is ignored.
4031 testCases = append(testCases, testCase{
4032 protocol: dtls,
4033 testType: serverTest,
4034 name: "SRTP-Server-IgnoreMKI",
4035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004036 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004037 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4038 Bugs: ProtocolBugs{
4039 SRTPMasterKeyIdentifer: "bogus",
4040 },
4041 },
4042 flags: []string{
4043 "-srtp-profiles",
4044 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4045 },
4046 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4047 })
4048 // Test that SRTP isn't negotiated on the server if there were
4049 // no matching profiles.
4050 testCases = append(testCases, testCase{
4051 protocol: dtls,
4052 testType: serverTest,
4053 name: "SRTP-Server-NoMatch",
4054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004055 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004056 SRTPProtectionProfiles: []uint16{100, 101, 102},
4057 },
4058 flags: []string{
4059 "-srtp-profiles",
4060 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4061 },
4062 expectedSRTPProtectionProfile: 0,
4063 })
4064 // Test that the server returning an invalid SRTP profile is
4065 // flagged as an error by the client.
4066 testCases = append(testCases, testCase{
4067 protocol: dtls,
4068 name: "SRTP-Client-NoMatch",
4069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004070 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004071 Bugs: ProtocolBugs{
4072 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4073 },
4074 },
4075 flags: []string{
4076 "-srtp-profiles",
4077 "SRTP_AES128_CM_SHA1_80",
4078 },
4079 shouldFail: true,
4080 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4081 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004082 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004083 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004084 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004085 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004086 config: Config{
4087 MaxVersion: VersionTLS12,
4088 },
David Benjamin61f95272014-11-25 01:55:35 -05004089 flags: []string{
4090 "-enable-signed-cert-timestamps",
4091 "-expect-signed-cert-timestamps",
4092 base64.StdEncoding.EncodeToString(testSCTList),
4093 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004094 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004095 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004096 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004097 name: "SendSCTListOnResume",
4098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004099 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004100 Bugs: ProtocolBugs{
4101 SendSCTListOnResume: []byte("bogus"),
4102 },
4103 },
4104 flags: []string{
4105 "-enable-signed-cert-timestamps",
4106 "-expect-signed-cert-timestamps",
4107 base64.StdEncoding.EncodeToString(testSCTList),
4108 },
4109 resumeSession: true,
4110 })
4111 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004112 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004113 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004114 config: Config{
4115 MaxVersion: VersionTLS12,
4116 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004117 flags: []string{
4118 "-signed-cert-timestamps",
4119 base64.StdEncoding.EncodeToString(testSCTList),
4120 },
4121 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004122 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004123 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004124
Paul Lietar4fac72e2015-09-09 13:44:55 +01004125 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004126 testType: clientTest,
4127 name: "ClientHelloPadding",
4128 config: Config{
4129 Bugs: ProtocolBugs{
4130 RequireClientHelloSize: 512,
4131 },
4132 },
4133 // This hostname just needs to be long enough to push the
4134 // ClientHello into F5's danger zone between 256 and 511 bytes
4135 // long.
4136 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4137 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004138
4139 // Extensions should not function in SSL 3.0.
4140 testCases = append(testCases, testCase{
4141 testType: serverTest,
4142 name: "SSLv3Extensions-NoALPN",
4143 config: Config{
4144 MaxVersion: VersionSSL30,
4145 NextProtos: []string{"foo", "bar", "baz"},
4146 },
4147 flags: []string{
4148 "-select-alpn", "foo",
4149 },
4150 expectNoNextProto: true,
4151 })
4152
4153 // Test session tickets separately as they follow a different codepath.
4154 testCases = append(testCases, testCase{
4155 testType: serverTest,
4156 name: "SSLv3Extensions-NoTickets",
4157 config: Config{
4158 MaxVersion: VersionSSL30,
4159 Bugs: ProtocolBugs{
4160 // Historically, session tickets in SSL 3.0
4161 // failed in different ways depending on whether
4162 // the client supported renegotiation_info.
4163 NoRenegotiationInfo: true,
4164 },
4165 },
4166 resumeSession: true,
4167 })
4168 testCases = append(testCases, testCase{
4169 testType: serverTest,
4170 name: "SSLv3Extensions-NoTickets2",
4171 config: Config{
4172 MaxVersion: VersionSSL30,
4173 },
4174 resumeSession: true,
4175 })
4176
4177 // But SSL 3.0 does send and process renegotiation_info.
4178 testCases = append(testCases, testCase{
4179 testType: serverTest,
4180 name: "SSLv3Extensions-RenegotiationInfo",
4181 config: Config{
4182 MaxVersion: VersionSSL30,
4183 Bugs: ProtocolBugs{
4184 RequireRenegotiationInfo: true,
4185 },
4186 },
4187 })
4188 testCases = append(testCases, testCase{
4189 testType: serverTest,
4190 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4191 config: Config{
4192 MaxVersion: VersionSSL30,
4193 Bugs: ProtocolBugs{
4194 NoRenegotiationInfo: true,
4195 SendRenegotiationSCSV: true,
4196 RequireRenegotiationInfo: true,
4197 },
4198 },
4199 })
David Benjamine78bfde2014-09-06 12:45:15 -04004200}
4201
David Benjamin01fe8202014-09-24 15:21:44 -04004202func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004203 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004204 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004205 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4206 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4207 // TLS 1.3 only shares ciphers with TLS 1.2, so
4208 // we skip certain combinations and use a
4209 // different cipher to test with.
4210 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4211 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4212 continue
4213 }
4214 }
4215
David Benjamin8b8c0062014-11-23 02:47:52 -05004216 protocols := []protocol{tls}
4217 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4218 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004219 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004220 for _, protocol := range protocols {
4221 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4222 if protocol == dtls {
4223 suffix += "-DTLS"
4224 }
4225
David Benjaminece3de92015-03-16 18:02:20 -04004226 if sessionVers.version == resumeVers.version {
4227 testCases = append(testCases, testCase{
4228 protocol: protocol,
4229 name: "Resume-Client" + suffix,
4230 resumeSession: true,
4231 config: Config{
4232 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004233 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004234 },
David Benjaminece3de92015-03-16 18:02:20 -04004235 expectedVersion: sessionVers.version,
4236 expectedResumeVersion: resumeVers.version,
4237 })
4238 } else {
4239 testCases = append(testCases, testCase{
4240 protocol: protocol,
4241 name: "Resume-Client-Mismatch" + suffix,
4242 resumeSession: true,
4243 config: Config{
4244 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004245 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004246 },
David Benjaminece3de92015-03-16 18:02:20 -04004247 expectedVersion: sessionVers.version,
4248 resumeConfig: &Config{
4249 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004250 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004251 Bugs: ProtocolBugs{
4252 AllowSessionVersionMismatch: true,
4253 },
4254 },
4255 expectedResumeVersion: resumeVers.version,
4256 shouldFail: true,
4257 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4258 })
4259 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004260
4261 testCases = append(testCases, testCase{
4262 protocol: protocol,
4263 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004264 resumeSession: true,
4265 config: Config{
4266 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004267 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004268 },
4269 expectedVersion: sessionVers.version,
4270 resumeConfig: &Config{
4271 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004272 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004273 },
4274 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004275 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004276 expectedResumeVersion: resumeVers.version,
4277 })
4278
David Benjamin8b8c0062014-11-23 02:47:52 -05004279 testCases = append(testCases, testCase{
4280 protocol: protocol,
4281 testType: serverTest,
4282 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004283 resumeSession: true,
4284 config: Config{
4285 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004286 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004287 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004288 expectedVersion: sessionVers.version,
4289 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004290 resumeConfig: &Config{
4291 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004292 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004293 },
4294 expectedResumeVersion: resumeVers.version,
4295 })
4296 }
David Benjamin01fe8202014-09-24 15:21:44 -04004297 }
4298 }
David Benjaminece3de92015-03-16 18:02:20 -04004299
Nick Harper1fd39d82016-06-14 18:14:35 -07004300 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004301 testCases = append(testCases, testCase{
4302 name: "Resume-Client-CipherMismatch",
4303 resumeSession: true,
4304 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004305 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004306 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4307 },
4308 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004309 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004310 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4311 Bugs: ProtocolBugs{
4312 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4313 },
4314 },
4315 shouldFail: true,
4316 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4317 })
David Benjamin01fe8202014-09-24 15:21:44 -04004318}
4319
Adam Langley2ae77d22014-10-28 17:29:33 -07004320func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004321 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004322 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004323 testType: serverTest,
4324 name: "Renegotiate-Server-Forbidden",
4325 config: Config{
4326 MaxVersion: VersionTLS12,
4327 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004328 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004329 shouldFail: true,
4330 expectedError: ":NO_RENEGOTIATION:",
4331 expectedLocalError: "remote error: no renegotiation",
4332 })
Adam Langley5021b222015-06-12 18:27:58 -07004333 // The server shouldn't echo the renegotiation extension unless
4334 // requested by the client.
4335 testCases = append(testCases, testCase{
4336 testType: serverTest,
4337 name: "Renegotiate-Server-NoExt",
4338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004339 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004340 Bugs: ProtocolBugs{
4341 NoRenegotiationInfo: true,
4342 RequireRenegotiationInfo: true,
4343 },
4344 },
4345 shouldFail: true,
4346 expectedLocalError: "renegotiation extension missing",
4347 })
4348 // The renegotiation SCSV should be sufficient for the server to echo
4349 // the extension.
4350 testCases = append(testCases, testCase{
4351 testType: serverTest,
4352 name: "Renegotiate-Server-NoExt-SCSV",
4353 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004354 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004355 Bugs: ProtocolBugs{
4356 NoRenegotiationInfo: true,
4357 SendRenegotiationSCSV: true,
4358 RequireRenegotiationInfo: true,
4359 },
4360 },
4361 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004362 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004363 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004364 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004365 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004366 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004367 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004368 },
4369 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004370 renegotiate: 1,
4371 flags: []string{
4372 "-renegotiate-freely",
4373 "-expect-total-renegotiations", "1",
4374 },
David Benjamincdea40c2015-03-19 14:09:43 -04004375 })
4376 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004377 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004378 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004380 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004381 Bugs: ProtocolBugs{
4382 EmptyRenegotiationInfo: true,
4383 },
4384 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004385 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004386 shouldFail: true,
4387 expectedError: ":RENEGOTIATION_MISMATCH:",
4388 })
4389 testCases = append(testCases, testCase{
4390 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004391 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004392 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004393 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004394 Bugs: ProtocolBugs{
4395 BadRenegotiationInfo: true,
4396 },
4397 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004398 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004399 shouldFail: true,
4400 expectedError: ":RENEGOTIATION_MISMATCH:",
4401 })
4402 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004403 name: "Renegotiate-Client-Downgrade",
4404 renegotiate: 1,
4405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004406 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004407 Bugs: ProtocolBugs{
4408 NoRenegotiationInfoAfterInitial: true,
4409 },
4410 },
4411 flags: []string{"-renegotiate-freely"},
4412 shouldFail: true,
4413 expectedError: ":RENEGOTIATION_MISMATCH:",
4414 })
4415 testCases = append(testCases, testCase{
4416 name: "Renegotiate-Client-Upgrade",
4417 renegotiate: 1,
4418 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004419 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004420 Bugs: ProtocolBugs{
4421 NoRenegotiationInfoInInitial: true,
4422 },
4423 },
4424 flags: []string{"-renegotiate-freely"},
4425 shouldFail: true,
4426 expectedError: ":RENEGOTIATION_MISMATCH:",
4427 })
4428 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004429 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004430 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004432 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004433 Bugs: ProtocolBugs{
4434 NoRenegotiationInfo: true,
4435 },
4436 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004437 flags: []string{
4438 "-renegotiate-freely",
4439 "-expect-total-renegotiations", "1",
4440 },
David Benjamincff0b902015-05-15 23:09:47 -04004441 })
4442 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004443 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004444 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004445 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004446 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004447 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4448 },
4449 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004450 flags: []string{
4451 "-renegotiate-freely",
4452 "-expect-total-renegotiations", "1",
4453 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004454 })
4455 testCases = append(testCases, testCase{
4456 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004457 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004458 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004459 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004460 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4461 },
4462 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004463 flags: []string{
4464 "-renegotiate-freely",
4465 "-expect-total-renegotiations", "1",
4466 },
David Benjaminb16346b2015-04-08 19:16:58 -04004467 })
4468 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004469 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004470 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004471 config: Config{
4472 MaxVersion: VersionTLS10,
4473 Bugs: ProtocolBugs{
4474 RequireSameRenegoClientVersion: true,
4475 },
4476 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004477 flags: []string{
4478 "-renegotiate-freely",
4479 "-expect-total-renegotiations", "1",
4480 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004481 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004482 testCases = append(testCases, testCase{
4483 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004484 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004485 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004486 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004487 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4488 NextProtos: []string{"foo"},
4489 },
4490 flags: []string{
4491 "-false-start",
4492 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004493 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004494 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004495 },
4496 shimWritesFirst: true,
4497 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004498
4499 // Client-side renegotiation controls.
4500 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004501 name: "Renegotiate-Client-Forbidden-1",
4502 config: Config{
4503 MaxVersion: VersionTLS12,
4504 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004505 renegotiate: 1,
4506 shouldFail: true,
4507 expectedError: ":NO_RENEGOTIATION:",
4508 expectedLocalError: "remote error: no renegotiation",
4509 })
4510 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004511 name: "Renegotiate-Client-Once-1",
4512 config: Config{
4513 MaxVersion: VersionTLS12,
4514 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004515 renegotiate: 1,
4516 flags: []string{
4517 "-renegotiate-once",
4518 "-expect-total-renegotiations", "1",
4519 },
4520 })
4521 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004522 name: "Renegotiate-Client-Freely-1",
4523 config: Config{
4524 MaxVersion: VersionTLS12,
4525 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004526 renegotiate: 1,
4527 flags: []string{
4528 "-renegotiate-freely",
4529 "-expect-total-renegotiations", "1",
4530 },
4531 })
4532 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004533 name: "Renegotiate-Client-Once-2",
4534 config: Config{
4535 MaxVersion: VersionTLS12,
4536 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004537 renegotiate: 2,
4538 flags: []string{"-renegotiate-once"},
4539 shouldFail: true,
4540 expectedError: ":NO_RENEGOTIATION:",
4541 expectedLocalError: "remote error: no renegotiation",
4542 })
4543 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004544 name: "Renegotiate-Client-Freely-2",
4545 config: Config{
4546 MaxVersion: VersionTLS12,
4547 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004548 renegotiate: 2,
4549 flags: []string{
4550 "-renegotiate-freely",
4551 "-expect-total-renegotiations", "2",
4552 },
4553 })
Adam Langley27a0d082015-11-03 13:34:10 -08004554 testCases = append(testCases, testCase{
4555 name: "Renegotiate-Client-NoIgnore",
4556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004557 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004558 Bugs: ProtocolBugs{
4559 SendHelloRequestBeforeEveryAppDataRecord: true,
4560 },
4561 },
4562 shouldFail: true,
4563 expectedError: ":NO_RENEGOTIATION:",
4564 })
4565 testCases = append(testCases, testCase{
4566 name: "Renegotiate-Client-Ignore",
4567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004568 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004569 Bugs: ProtocolBugs{
4570 SendHelloRequestBeforeEveryAppDataRecord: true,
4571 },
4572 },
4573 flags: []string{
4574 "-renegotiate-ignore",
4575 "-expect-total-renegotiations", "0",
4576 },
4577 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004578
David Benjamin397c8e62016-07-08 14:14:36 -07004579 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004580 testCases = append(testCases, testCase{
4581 name: "StrayHelloRequest",
4582 config: Config{
4583 MaxVersion: VersionTLS12,
4584 Bugs: ProtocolBugs{
4585 SendHelloRequestBeforeEveryHandshakeMessage: true,
4586 },
4587 },
4588 })
4589 testCases = append(testCases, testCase{
4590 name: "StrayHelloRequest-Packed",
4591 config: Config{
4592 MaxVersion: VersionTLS12,
4593 Bugs: ProtocolBugs{
4594 PackHandshakeFlight: true,
4595 SendHelloRequestBeforeEveryHandshakeMessage: true,
4596 },
4597 },
4598 })
4599
David Benjamin397c8e62016-07-08 14:14:36 -07004600 // Renegotiation is forbidden in TLS 1.3.
4601 testCases = append(testCases, testCase{
4602 name: "Renegotiate-Client-TLS13",
4603 config: Config{
4604 MaxVersion: VersionTLS13,
4605 },
4606 renegotiate: 1,
4607 flags: []string{
4608 "-renegotiate-freely",
4609 },
4610 shouldFail: true,
4611 expectedError: ":NO_RENEGOTIATION:",
4612 })
4613
4614 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4615 testCases = append(testCases, testCase{
4616 name: "StrayHelloRequest-TLS13",
4617 config: Config{
4618 MaxVersion: VersionTLS13,
4619 Bugs: ProtocolBugs{
4620 SendHelloRequestBeforeEveryHandshakeMessage: true,
4621 },
4622 },
4623 shouldFail: true,
4624 expectedError: ":UNEXPECTED_MESSAGE:",
4625 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004626}
4627
David Benjamin5e961c12014-11-07 01:48:35 -05004628func addDTLSReplayTests() {
4629 // Test that sequence number replays are detected.
4630 testCases = append(testCases, testCase{
4631 protocol: dtls,
4632 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004633 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004634 replayWrites: true,
4635 })
4636
David Benjamin8e6db492015-07-25 18:29:23 -04004637 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004638 // than the retransmit window.
4639 testCases = append(testCases, testCase{
4640 protocol: dtls,
4641 name: "DTLS-Replay-LargeGaps",
4642 config: Config{
4643 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004644 SequenceNumberMapping: func(in uint64) uint64 {
4645 return in * 127
4646 },
David Benjamin5e961c12014-11-07 01:48:35 -05004647 },
4648 },
David Benjamin8e6db492015-07-25 18:29:23 -04004649 messageCount: 200,
4650 replayWrites: true,
4651 })
4652
4653 // Test the incoming sequence number changing non-monotonically.
4654 testCases = append(testCases, testCase{
4655 protocol: dtls,
4656 name: "DTLS-Replay-NonMonotonic",
4657 config: Config{
4658 Bugs: ProtocolBugs{
4659 SequenceNumberMapping: func(in uint64) uint64 {
4660 return in ^ 31
4661 },
4662 },
4663 },
4664 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004665 replayWrites: true,
4666 })
4667}
4668
Nick Harper60edffd2016-06-21 15:19:24 -07004669var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004670 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004671 id signatureAlgorithm
4672 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004673}{
Nick Harper60edffd2016-06-21 15:19:24 -07004674 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4675 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4676 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4677 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07004678 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
4679 // TODO(davidben): Enforce curve matching in TLS 1.3 and test.
4680 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
4681 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
4682 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
David Benjamin000800a2014-11-14 01:43:59 -05004683}
4684
Nick Harper60edffd2016-06-21 15:19:24 -07004685const fakeSigAlg1 signatureAlgorithm = 0x2a01
4686const fakeSigAlg2 signatureAlgorithm = 0xff01
4687
4688func addSignatureAlgorithmTests() {
4689 // Make sure each signature algorithm works. Include some fake values in
4690 // the list and ensure they're ignored.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004691 //
4692 // TODO(davidben): Test each of these against both TLS 1.2 and TLS 1.3.
Nick Harper60edffd2016-06-21 15:19:24 -07004693 for _, alg := range testSignatureAlgorithms {
David Benjamin000800a2014-11-14 01:43:59 -05004694 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004695 name: "SigningHash-ClientAuth-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004696 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004697 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004698 // SignatureAlgorithms is shared, so we must
4699 // configure a matching server certificate too.
4700 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4701 ClientAuth: RequireAnyClientCert,
4702 SignatureAlgorithms: []signatureAlgorithm{
4703 fakeSigAlg1,
4704 alg.id,
4705 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004706 },
4707 },
4708 flags: []string{
Nick Harper60edffd2016-06-21 15:19:24 -07004709 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4710 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
David Benjamin33863262016-07-08 17:20:12 -07004711 "-enable-all-curves",
Nick Harper60edffd2016-06-21 15:19:24 -07004712 },
4713 expectedPeerSignatureAlgorithm: alg.id,
4714 })
4715
4716 testCases = append(testCases, testCase{
4717 testType: serverTest,
4718 name: "SigningHash-ClientAuth-Verify-" + alg.name,
4719 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004720 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004721 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4722 SignatureAlgorithms: []signatureAlgorithm{
4723 alg.id,
4724 },
4725 },
4726 flags: []string{
4727 "-require-any-client-certificate",
4728 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4729 // SignatureAlgorithms is shared, so we must
4730 // configure a matching server certificate too.
4731 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4732 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
David Benjamin33863262016-07-08 17:20:12 -07004733 "-enable-all-curves",
David Benjamin000800a2014-11-14 01:43:59 -05004734 },
4735 })
4736
4737 testCases = append(testCases, testCase{
4738 testType: serverTest,
Nick Harper60edffd2016-06-21 15:19:24 -07004739 name: "SigningHash-ServerKeyExchange-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004740 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004741 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004742 CipherSuites: []uint16{
4743 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4744 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4745 },
4746 SignatureAlgorithms: []signatureAlgorithm{
4747 fakeSigAlg1,
4748 alg.id,
4749 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004750 },
4751 },
Nick Harper60edffd2016-06-21 15:19:24 -07004752 flags: []string{
4753 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4754 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
David Benjamin33863262016-07-08 17:20:12 -07004755 "-enable-all-curves",
Nick Harper60edffd2016-06-21 15:19:24 -07004756 },
4757 expectedPeerSignatureAlgorithm: alg.id,
David Benjamin000800a2014-11-14 01:43:59 -05004758 })
David Benjamin6e807652015-11-02 12:02:20 -05004759
4760 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004761 name: "SigningHash-ServerKeyExchange-Verify-" + alg.name,
David Benjamin6e807652015-11-02 12:02:20 -05004762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004763 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004764 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4765 CipherSuites: []uint16{
4766 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4767 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4768 },
4769 SignatureAlgorithms: []signatureAlgorithm{
4770 alg.id,
David Benjamin6e807652015-11-02 12:02:20 -05004771 },
4772 },
David Benjamin33863262016-07-08 17:20:12 -07004773 flags: []string{
4774 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4775 "-enable-all-curves",
4776 },
David Benjamin6e807652015-11-02 12:02:20 -05004777 })
David Benjamin000800a2014-11-14 01:43:59 -05004778 }
4779
Nick Harper60edffd2016-06-21 15:19:24 -07004780 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004781 //
4782 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004783 testCases = append(testCases, testCase{
4784 name: "SigningHash-ClientAuth-SignatureType",
4785 config: Config{
4786 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004787 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004788 SignatureAlgorithms: []signatureAlgorithm{
4789 signatureECDSAWithP521AndSHA512,
4790 signatureRSAPKCS1WithSHA384,
4791 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004792 },
4793 },
4794 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004795 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4796 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004797 },
Nick Harper60edffd2016-06-21 15:19:24 -07004798 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004799 })
4800
4801 testCases = append(testCases, testCase{
4802 testType: serverTest,
4803 name: "SigningHash-ServerKeyExchange-SignatureType",
4804 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004805 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004807 SignatureAlgorithms: []signatureAlgorithm{
4808 signatureECDSAWithP521AndSHA512,
4809 signatureRSAPKCS1WithSHA384,
4810 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004811 },
4812 },
Nick Harper60edffd2016-06-21 15:19:24 -07004813 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004814 })
4815
David Benjamina95e9f32016-07-08 16:28:04 -07004816 // Test that signature verification takes the key type into account.
4817 //
4818 // TODO(davidben): Test this in TLS 1.3.
4819 testCases = append(testCases, testCase{
4820 testType: serverTest,
4821 name: "Verify-ClientAuth-SignatureType",
4822 config: Config{
4823 MaxVersion: VersionTLS12,
4824 Certificates: []Certificate{rsaCertificate},
4825 SignatureAlgorithms: []signatureAlgorithm{
4826 signatureRSAPKCS1WithSHA256,
4827 },
4828 Bugs: ProtocolBugs{
4829 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4830 },
4831 },
4832 flags: []string{
4833 "-require-any-client-certificate",
4834 },
4835 shouldFail: true,
4836 expectedError: ":WRONG_SIGNATURE_TYPE:",
4837 })
4838
4839 testCases = append(testCases, testCase{
4840 name: "Verify-ServerKeyExchange-SignatureType",
4841 config: Config{
4842 MaxVersion: VersionTLS12,
4843 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4844 SignatureAlgorithms: []signatureAlgorithm{
4845 signatureRSAPKCS1WithSHA256,
4846 },
4847 Bugs: ProtocolBugs{
4848 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
4849 },
4850 },
4851 shouldFail: true,
4852 expectedError: ":WRONG_SIGNATURE_TYPE:",
4853 })
4854
David Benjamin51dd7d62016-07-08 16:07:01 -07004855 // Test that, if the list is missing, the peer falls back to SHA-1 in
4856 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004857 testCases = append(testCases, testCase{
4858 name: "SigningHash-ClientAuth-Fallback",
4859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004860 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004861 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004862 SignatureAlgorithms: []signatureAlgorithm{
4863 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004864 },
4865 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004866 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004867 },
4868 },
4869 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004870 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4871 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004872 },
4873 })
4874
4875 testCases = append(testCases, testCase{
4876 testType: serverTest,
4877 name: "SigningHash-ServerKeyExchange-Fallback",
4878 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004879 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004880 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004881 SignatureAlgorithms: []signatureAlgorithm{
4882 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004883 },
4884 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004885 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004886 },
4887 },
4888 })
David Benjamin72dc7832015-03-16 17:49:43 -04004889
David Benjamin51dd7d62016-07-08 16:07:01 -07004890 testCases = append(testCases, testCase{
4891 name: "SigningHash-ClientAuth-Fallback-TLS13",
4892 config: Config{
4893 MaxVersion: VersionTLS13,
4894 ClientAuth: RequireAnyClientCert,
4895 SignatureAlgorithms: []signatureAlgorithm{
4896 signatureRSAPKCS1WithSHA1,
4897 },
4898 Bugs: ProtocolBugs{
4899 NoSignatureAlgorithms: true,
4900 },
4901 },
4902 flags: []string{
4903 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4904 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4905 },
4906 shouldFail: true,
4907 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
4908 })
4909
4910 testCases = append(testCases, testCase{
4911 testType: serverTest,
4912 name: "SigningHash-ServerKeyExchange-Fallback-TLS13",
4913 config: Config{
4914 MaxVersion: VersionTLS13,
4915 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4916 SignatureAlgorithms: []signatureAlgorithm{
4917 signatureRSAPKCS1WithSHA1,
4918 },
4919 Bugs: ProtocolBugs{
4920 NoSignatureAlgorithms: true,
4921 },
4922 },
4923 shouldFail: true,
4924 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
4925 })
4926
David Benjamin72dc7832015-03-16 17:49:43 -04004927 // Test that hash preferences are enforced. BoringSSL defaults to
4928 // rejecting MD5 signatures.
4929 testCases = append(testCases, testCase{
4930 testType: serverTest,
4931 name: "SigningHash-ClientAuth-Enforced",
4932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004933 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004934 Certificates: []Certificate{rsaCertificate},
Nick Harper60edffd2016-06-21 15:19:24 -07004935 SignatureAlgorithms: []signatureAlgorithm{
4936 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004937 // Advertise SHA-1 so the handshake will
4938 // proceed, but the shim's preferences will be
4939 // ignored in CertificateVerify generation, so
4940 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07004941 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04004942 },
4943 Bugs: ProtocolBugs{
4944 IgnorePeerSignatureAlgorithmPreferences: true,
4945 },
4946 },
4947 flags: []string{"-require-any-client-certificate"},
4948 shouldFail: true,
4949 expectedError: ":WRONG_SIGNATURE_TYPE:",
4950 })
4951
4952 testCases = append(testCases, testCase{
4953 name: "SigningHash-ServerKeyExchange-Enforced",
4954 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004955 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004956 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004957 SignatureAlgorithms: []signatureAlgorithm{
4958 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004959 },
4960 Bugs: ProtocolBugs{
4961 IgnorePeerSignatureAlgorithmPreferences: true,
4962 },
4963 },
4964 shouldFail: true,
4965 expectedError: ":WRONG_SIGNATURE_TYPE:",
4966 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004967
4968 // Test that the agreed upon digest respects the client preferences and
4969 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004970 //
4971 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04004972 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07004973 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04004974 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004975 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004976 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004977 SignatureAlgorithms: []signatureAlgorithm{
4978 signatureRSAPKCS1WithSHA512,
4979 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004980 },
4981 },
4982 flags: []string{
4983 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4984 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4985 },
David Benjaminea9a0d52016-07-08 15:52:59 -07004986 digestPrefs: "SHA256",
4987 shouldFail: true,
4988 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04004989 })
4990 testCases = append(testCases, testCase{
4991 name: "Agree-Digest-SHA256",
4992 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004993 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004994 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004995 SignatureAlgorithms: []signatureAlgorithm{
4996 signatureRSAPKCS1WithSHA1,
4997 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004998 },
4999 },
5000 flags: []string{
5001 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5002 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5003 },
Nick Harper60edffd2016-06-21 15:19:24 -07005004 digestPrefs: "SHA256,SHA1",
5005 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005006 })
5007 testCases = append(testCases, testCase{
5008 name: "Agree-Digest-SHA1",
5009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005010 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005011 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07005012 SignatureAlgorithms: []signatureAlgorithm{
5013 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005014 },
5015 },
5016 flags: []string{
5017 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5018 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5019 },
Nick Harper60edffd2016-06-21 15:19:24 -07005020 digestPrefs: "SHA512,SHA256,SHA1",
5021 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005022 })
5023 testCases = append(testCases, testCase{
5024 name: "Agree-Digest-Default",
5025 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005026 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005027 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07005028 SignatureAlgorithms: []signatureAlgorithm{
5029 signatureRSAPKCS1WithSHA256,
5030 signatureECDSAWithP256AndSHA256,
5031 signatureRSAPKCS1WithSHA1,
5032 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005033 },
5034 },
5035 flags: []string{
5036 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5037 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5038 },
Nick Harper60edffd2016-06-21 15:19:24 -07005039 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005040 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005041
5042 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5043 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005044 testCases = append(testCases, testCase{
5045 name: "CheckLeafCurve",
5046 config: Config{
5047 MaxVersion: VersionTLS12,
5048 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005049 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005050 },
5051 flags: []string{"-p384-only"},
5052 shouldFail: true,
5053 expectedError: ":BAD_ECC_CERT:",
5054 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005055
5056 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5057 testCases = append(testCases, testCase{
5058 name: "CheckLeafCurve-TLS13",
5059 config: Config{
5060 MaxVersion: VersionTLS13,
5061 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5062 Certificates: []Certificate{ecdsaP256Certificate},
5063 },
5064 flags: []string{"-p384-only"},
5065 })
David Benjamin000800a2014-11-14 01:43:59 -05005066}
5067
David Benjamin83f90402015-01-27 01:09:43 -05005068// timeouts is the retransmit schedule for BoringSSL. It doubles and
5069// caps at 60 seconds. On the 13th timeout, it gives up.
5070var timeouts = []time.Duration{
5071 1 * time.Second,
5072 2 * time.Second,
5073 4 * time.Second,
5074 8 * time.Second,
5075 16 * time.Second,
5076 32 * time.Second,
5077 60 * time.Second,
5078 60 * time.Second,
5079 60 * time.Second,
5080 60 * time.Second,
5081 60 * time.Second,
5082 60 * time.Second,
5083 60 * time.Second,
5084}
5085
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005086// shortTimeouts is an alternate set of timeouts which would occur if the
5087// initial timeout duration was set to 250ms.
5088var shortTimeouts = []time.Duration{
5089 250 * time.Millisecond,
5090 500 * time.Millisecond,
5091 1 * time.Second,
5092 2 * time.Second,
5093 4 * time.Second,
5094 8 * time.Second,
5095 16 * time.Second,
5096 32 * time.Second,
5097 60 * time.Second,
5098 60 * time.Second,
5099 60 * time.Second,
5100 60 * time.Second,
5101 60 * time.Second,
5102}
5103
David Benjamin83f90402015-01-27 01:09:43 -05005104func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005105 // These tests work by coordinating some behavior on both the shim and
5106 // the runner.
5107 //
5108 // TimeoutSchedule configures the runner to send a series of timeout
5109 // opcodes to the shim (see packetAdaptor) immediately before reading
5110 // each peer handshake flight N. The timeout opcode both simulates a
5111 // timeout in the shim and acts as a synchronization point to help the
5112 // runner bracket each handshake flight.
5113 //
5114 // We assume the shim does not read from the channel eagerly. It must
5115 // first wait until it has sent flight N and is ready to receive
5116 // handshake flight N+1. At this point, it will process the timeout
5117 // opcode. It must then immediately respond with a timeout ACK and act
5118 // as if the shim was idle for the specified amount of time.
5119 //
5120 // The runner then drops all packets received before the ACK and
5121 // continues waiting for flight N. This ordering results in one attempt
5122 // at sending flight N to be dropped. For the test to complete, the
5123 // shim must send flight N again, testing that the shim implements DTLS
5124 // retransmit on a timeout.
5125
David Benjamin4c3ddf72016-06-29 18:13:53 -04005126 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5127 // likely be more epochs to cross and the final message's retransmit may
5128 // be more complex.
5129
David Benjamin585d7a42016-06-02 14:58:00 -04005130 for _, async := range []bool{true, false} {
5131 var tests []testCase
5132
5133 // Test that this is indeed the timeout schedule. Stress all
5134 // four patterns of handshake.
5135 for i := 1; i < len(timeouts); i++ {
5136 number := strconv.Itoa(i)
5137 tests = append(tests, testCase{
5138 protocol: dtls,
5139 name: "DTLS-Retransmit-Client-" + number,
5140 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005141 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005142 Bugs: ProtocolBugs{
5143 TimeoutSchedule: timeouts[:i],
5144 },
5145 },
5146 resumeSession: true,
5147 })
5148 tests = append(tests, testCase{
5149 protocol: dtls,
5150 testType: serverTest,
5151 name: "DTLS-Retransmit-Server-" + number,
5152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005153 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005154 Bugs: ProtocolBugs{
5155 TimeoutSchedule: timeouts[:i],
5156 },
5157 },
5158 resumeSession: true,
5159 })
5160 }
5161
5162 // Test that exceeding the timeout schedule hits a read
5163 // timeout.
5164 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005165 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005166 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005168 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005169 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005170 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005171 },
5172 },
5173 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005174 shouldFail: true,
5175 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005176 })
David Benjamin585d7a42016-06-02 14:58:00 -04005177
5178 if async {
5179 // Test that timeout handling has a fudge factor, due to API
5180 // problems.
5181 tests = append(tests, testCase{
5182 protocol: dtls,
5183 name: "DTLS-Retransmit-Fudge",
5184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005185 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005186 Bugs: ProtocolBugs{
5187 TimeoutSchedule: []time.Duration{
5188 timeouts[0] - 10*time.Millisecond,
5189 },
5190 },
5191 },
5192 resumeSession: true,
5193 })
5194 }
5195
5196 // Test that the final Finished retransmitting isn't
5197 // duplicated if the peer badly fragments everything.
5198 tests = append(tests, testCase{
5199 testType: serverTest,
5200 protocol: dtls,
5201 name: "DTLS-Retransmit-Fragmented",
5202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005203 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005204 Bugs: ProtocolBugs{
5205 TimeoutSchedule: []time.Duration{timeouts[0]},
5206 MaxHandshakeRecordLength: 2,
5207 },
5208 },
5209 })
5210
5211 // Test the timeout schedule when a shorter initial timeout duration is set.
5212 tests = append(tests, testCase{
5213 protocol: dtls,
5214 name: "DTLS-Retransmit-Short-Client",
5215 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005216 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005217 Bugs: ProtocolBugs{
5218 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5219 },
5220 },
5221 resumeSession: true,
5222 flags: []string{"-initial-timeout-duration-ms", "250"},
5223 })
5224 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005225 protocol: dtls,
5226 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005227 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005229 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005230 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005231 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005232 },
5233 },
5234 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005235 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005236 })
David Benjamin585d7a42016-06-02 14:58:00 -04005237
5238 for _, test := range tests {
5239 if async {
5240 test.name += "-Async"
5241 test.flags = append(test.flags, "-async")
5242 }
5243
5244 testCases = append(testCases, test)
5245 }
David Benjamin83f90402015-01-27 01:09:43 -05005246 }
David Benjamin83f90402015-01-27 01:09:43 -05005247}
5248
David Benjaminc565ebb2015-04-03 04:06:36 -04005249func addExportKeyingMaterialTests() {
5250 for _, vers := range tlsVersions {
5251 if vers.version == VersionSSL30 {
5252 continue
5253 }
5254 testCases = append(testCases, testCase{
5255 name: "ExportKeyingMaterial-" + vers.name,
5256 config: Config{
5257 MaxVersion: vers.version,
5258 },
5259 exportKeyingMaterial: 1024,
5260 exportLabel: "label",
5261 exportContext: "context",
5262 useExportContext: true,
5263 })
5264 testCases = append(testCases, testCase{
5265 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5266 config: Config{
5267 MaxVersion: vers.version,
5268 },
5269 exportKeyingMaterial: 1024,
5270 })
5271 testCases = append(testCases, testCase{
5272 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5273 config: Config{
5274 MaxVersion: vers.version,
5275 },
5276 exportKeyingMaterial: 1024,
5277 useExportContext: true,
5278 })
5279 testCases = append(testCases, testCase{
5280 name: "ExportKeyingMaterial-Small-" + vers.name,
5281 config: Config{
5282 MaxVersion: vers.version,
5283 },
5284 exportKeyingMaterial: 1,
5285 exportLabel: "label",
5286 exportContext: "context",
5287 useExportContext: true,
5288 })
5289 }
5290 testCases = append(testCases, testCase{
5291 name: "ExportKeyingMaterial-SSL3",
5292 config: Config{
5293 MaxVersion: VersionSSL30,
5294 },
5295 exportKeyingMaterial: 1024,
5296 exportLabel: "label",
5297 exportContext: "context",
5298 useExportContext: true,
5299 shouldFail: true,
5300 expectedError: "failed to export keying material",
5301 })
5302}
5303
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005304func addTLSUniqueTests() {
5305 for _, isClient := range []bool{false, true} {
5306 for _, isResumption := range []bool{false, true} {
5307 for _, hasEMS := range []bool{false, true} {
5308 var suffix string
5309 if isResumption {
5310 suffix = "Resume-"
5311 } else {
5312 suffix = "Full-"
5313 }
5314
5315 if hasEMS {
5316 suffix += "EMS-"
5317 } else {
5318 suffix += "NoEMS-"
5319 }
5320
5321 if isClient {
5322 suffix += "Client"
5323 } else {
5324 suffix += "Server"
5325 }
5326
5327 test := testCase{
5328 name: "TLSUnique-" + suffix,
5329 testTLSUnique: true,
5330 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005331 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005332 Bugs: ProtocolBugs{
5333 NoExtendedMasterSecret: !hasEMS,
5334 },
5335 },
5336 }
5337
5338 if isResumption {
5339 test.resumeSession = true
5340 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005341 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005342 Bugs: ProtocolBugs{
5343 NoExtendedMasterSecret: !hasEMS,
5344 },
5345 }
5346 }
5347
5348 if isResumption && !hasEMS {
5349 test.shouldFail = true
5350 test.expectedError = "failed to get tls-unique"
5351 }
5352
5353 testCases = append(testCases, test)
5354 }
5355 }
5356 }
5357}
5358
Adam Langley09505632015-07-30 18:10:13 -07005359func addCustomExtensionTests() {
5360 expectedContents := "custom extension"
5361 emptyString := ""
5362
David Benjamin4c3ddf72016-06-29 18:13:53 -04005363 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005364 for _, isClient := range []bool{false, true} {
5365 suffix := "Server"
5366 flag := "-enable-server-custom-extension"
5367 testType := serverTest
5368 if isClient {
5369 suffix = "Client"
5370 flag = "-enable-client-custom-extension"
5371 testType = clientTest
5372 }
5373
5374 testCases = append(testCases, testCase{
5375 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005376 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005377 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005378 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005379 Bugs: ProtocolBugs{
5380 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005381 ExpectedCustomExtension: &expectedContents,
5382 },
5383 },
5384 flags: []string{flag},
5385 })
5386
5387 // If the parse callback fails, the handshake should also fail.
5388 testCases = append(testCases, testCase{
5389 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005390 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005392 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005393 Bugs: ProtocolBugs{
5394 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005395 ExpectedCustomExtension: &expectedContents,
5396 },
5397 },
David Benjamin399e7c92015-07-30 23:01:27 -04005398 flags: []string{flag},
5399 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005400 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5401 })
5402
5403 // If the add callback fails, the handshake should also fail.
5404 testCases = append(testCases, testCase{
5405 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005406 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005408 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005409 Bugs: ProtocolBugs{
5410 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005411 ExpectedCustomExtension: &expectedContents,
5412 },
5413 },
David Benjamin399e7c92015-07-30 23:01:27 -04005414 flags: []string{flag, "-custom-extension-fail-add"},
5415 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005416 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5417 })
5418
5419 // If the add callback returns zero, no extension should be
5420 // added.
5421 skipCustomExtension := expectedContents
5422 if isClient {
5423 // For the case where the client skips sending the
5424 // custom extension, the server must not “echo” it.
5425 skipCustomExtension = ""
5426 }
5427 testCases = append(testCases, testCase{
5428 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005429 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005431 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005432 Bugs: ProtocolBugs{
5433 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005434 ExpectedCustomExtension: &emptyString,
5435 },
5436 },
5437 flags: []string{flag, "-custom-extension-skip"},
5438 })
5439 }
5440
5441 // The custom extension add callback should not be called if the client
5442 // doesn't send the extension.
5443 testCases = append(testCases, testCase{
5444 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005445 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005446 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005447 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005448 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005449 ExpectedCustomExtension: &emptyString,
5450 },
5451 },
5452 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5453 })
Adam Langley2deb9842015-08-07 11:15:37 -07005454
5455 // Test an unknown extension from the server.
5456 testCases = append(testCases, testCase{
5457 testType: clientTest,
5458 name: "UnknownExtension-Client",
5459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005460 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005461 Bugs: ProtocolBugs{
5462 CustomExtension: expectedContents,
5463 },
5464 },
5465 shouldFail: true,
5466 expectedError: ":UNEXPECTED_EXTENSION:",
5467 })
Adam Langley09505632015-07-30 18:10:13 -07005468}
5469
David Benjaminb36a3952015-12-01 18:53:13 -05005470func addRSAClientKeyExchangeTests() {
5471 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5472 testCases = append(testCases, testCase{
5473 testType: serverTest,
5474 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5475 config: Config{
5476 // Ensure the ClientHello version and final
5477 // version are different, to detect if the
5478 // server uses the wrong one.
5479 MaxVersion: VersionTLS11,
5480 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5481 Bugs: ProtocolBugs{
5482 BadRSAClientKeyExchange: bad,
5483 },
5484 },
5485 shouldFail: true,
5486 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5487 })
5488 }
5489}
5490
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005491var testCurves = []struct {
5492 name string
5493 id CurveID
5494}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005495 {"P-256", CurveP256},
5496 {"P-384", CurveP384},
5497 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005498 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005499}
5500
5501func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005502 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005503 for _, curve := range testCurves {
5504 testCases = append(testCases, testCase{
5505 name: "CurveTest-Client-" + curve.name,
5506 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005507 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005508 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5509 CurvePreferences: []CurveID{curve.id},
5510 },
5511 flags: []string{"-enable-all-curves"},
5512 })
5513 testCases = append(testCases, testCase{
5514 testType: serverTest,
5515 name: "CurveTest-Server-" + curve.name,
5516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005517 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005518 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5519 CurvePreferences: []CurveID{curve.id},
5520 },
5521 flags: []string{"-enable-all-curves"},
5522 })
5523 }
David Benjamin241ae832016-01-15 03:04:54 -05005524
5525 // The server must be tolerant to bogus curves.
5526 const bogusCurve = 0x1234
5527 testCases = append(testCases, testCase{
5528 testType: serverTest,
5529 name: "UnknownCurve",
5530 config: Config{
5531 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5532 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5533 },
5534 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005535
5536 // The server must not consider ECDHE ciphers when there are no
5537 // supported curves.
5538 testCases = append(testCases, testCase{
5539 testType: serverTest,
5540 name: "NoSupportedCurves",
5541 config: Config{
5542 // TODO(davidben): Add a TLS 1.3 version of this.
5543 MaxVersion: VersionTLS12,
5544 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5545 Bugs: ProtocolBugs{
5546 NoSupportedCurves: true,
5547 },
5548 },
5549 shouldFail: true,
5550 expectedError: ":NO_SHARED_CIPHER:",
5551 })
5552
5553 // The server must fall back to another cipher when there are no
5554 // supported curves.
5555 testCases = append(testCases, testCase{
5556 testType: serverTest,
5557 name: "NoCommonCurves",
5558 config: Config{
5559 MaxVersion: VersionTLS12,
5560 CipherSuites: []uint16{
5561 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5562 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5563 },
5564 CurvePreferences: []CurveID{CurveP224},
5565 },
5566 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5567 })
5568
5569 // The client must reject bogus curves and disabled curves.
5570 testCases = append(testCases, testCase{
5571 name: "BadECDHECurve",
5572 config: Config{
5573 // TODO(davidben): Add a TLS 1.3 version of this.
5574 MaxVersion: VersionTLS12,
5575 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5576 Bugs: ProtocolBugs{
5577 SendCurve: bogusCurve,
5578 },
5579 },
5580 shouldFail: true,
5581 expectedError: ":WRONG_CURVE:",
5582 })
5583
5584 testCases = append(testCases, testCase{
5585 name: "UnsupportedCurve",
5586 config: Config{
5587 // TODO(davidben): Add a TLS 1.3 version of this.
5588 MaxVersion: VersionTLS12,
5589 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5590 CurvePreferences: []CurveID{CurveP256},
5591 Bugs: ProtocolBugs{
5592 IgnorePeerCurvePreferences: true,
5593 },
5594 },
5595 flags: []string{"-p384-only"},
5596 shouldFail: true,
5597 expectedError: ":WRONG_CURVE:",
5598 })
5599
5600 // Test invalid curve points.
5601 testCases = append(testCases, testCase{
5602 name: "InvalidECDHPoint-Client",
5603 config: Config{
5604 // TODO(davidben): Add a TLS 1.3 version of this test.
5605 MaxVersion: VersionTLS12,
5606 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5607 CurvePreferences: []CurveID{CurveP256},
5608 Bugs: ProtocolBugs{
5609 InvalidECDHPoint: true,
5610 },
5611 },
5612 shouldFail: true,
5613 expectedError: ":INVALID_ENCODING:",
5614 })
5615 testCases = append(testCases, testCase{
5616 testType: serverTest,
5617 name: "InvalidECDHPoint-Server",
5618 config: Config{
5619 // TODO(davidben): Add a TLS 1.3 version of this test.
5620 MaxVersion: VersionTLS12,
5621 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5622 CurvePreferences: []CurveID{CurveP256},
5623 Bugs: ProtocolBugs{
5624 InvalidECDHPoint: true,
5625 },
5626 },
5627 shouldFail: true,
5628 expectedError: ":INVALID_ENCODING:",
5629 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005630}
5631
Matt Braithwaite54217e42016-06-13 13:03:47 -07005632func addCECPQ1Tests() {
5633 testCases = append(testCases, testCase{
5634 testType: clientTest,
5635 name: "CECPQ1-Client-BadX25519Part",
5636 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005637 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005638 MinVersion: VersionTLS12,
5639 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5640 Bugs: ProtocolBugs{
5641 CECPQ1BadX25519Part: true,
5642 },
5643 },
5644 flags: []string{"-cipher", "kCECPQ1"},
5645 shouldFail: true,
5646 expectedLocalError: "local error: bad record MAC",
5647 })
5648 testCases = append(testCases, testCase{
5649 testType: clientTest,
5650 name: "CECPQ1-Client-BadNewhopePart",
5651 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005652 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005653 MinVersion: VersionTLS12,
5654 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5655 Bugs: ProtocolBugs{
5656 CECPQ1BadNewhopePart: true,
5657 },
5658 },
5659 flags: []string{"-cipher", "kCECPQ1"},
5660 shouldFail: true,
5661 expectedLocalError: "local error: bad record MAC",
5662 })
5663 testCases = append(testCases, testCase{
5664 testType: serverTest,
5665 name: "CECPQ1-Server-BadX25519Part",
5666 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005667 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005668 MinVersion: VersionTLS12,
5669 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5670 Bugs: ProtocolBugs{
5671 CECPQ1BadX25519Part: true,
5672 },
5673 },
5674 flags: []string{"-cipher", "kCECPQ1"},
5675 shouldFail: true,
5676 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5677 })
5678 testCases = append(testCases, testCase{
5679 testType: serverTest,
5680 name: "CECPQ1-Server-BadNewhopePart",
5681 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005682 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005683 MinVersion: VersionTLS12,
5684 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5685 Bugs: ProtocolBugs{
5686 CECPQ1BadNewhopePart: true,
5687 },
5688 },
5689 flags: []string{"-cipher", "kCECPQ1"},
5690 shouldFail: true,
5691 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5692 })
5693}
5694
David Benjamin4cc36ad2015-12-19 14:23:26 -05005695func addKeyExchangeInfoTests() {
5696 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005697 name: "KeyExchangeInfo-DHE-Client",
5698 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005699 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005700 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5701 Bugs: ProtocolBugs{
5702 // This is a 1234-bit prime number, generated
5703 // with:
5704 // openssl gendh 1234 | openssl asn1parse -i
5705 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5706 },
5707 },
David Benjamin9e68f192016-06-30 14:55:33 -04005708 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005709 })
5710 testCases = append(testCases, testCase{
5711 testType: serverTest,
5712 name: "KeyExchangeInfo-DHE-Server",
5713 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005714 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005715 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5716 },
5717 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005718 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005719 })
5720
Nick Harper1fd39d82016-06-14 18:14:35 -07005721 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5722 // handshake is separate.
5723
David Benjamin4cc36ad2015-12-19 14:23:26 -05005724 testCases = append(testCases, testCase{
5725 name: "KeyExchangeInfo-ECDHE-Client",
5726 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005727 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5729 CurvePreferences: []CurveID{CurveX25519},
5730 },
David Benjamin9e68f192016-06-30 14:55:33 -04005731 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005732 })
5733 testCases = append(testCases, testCase{
5734 testType: serverTest,
5735 name: "KeyExchangeInfo-ECDHE-Server",
5736 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005737 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005738 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5739 CurvePreferences: []CurveID{CurveX25519},
5740 },
David Benjamin9e68f192016-06-30 14:55:33 -04005741 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005742 })
5743}
5744
David Benjaminc9ae27c2016-06-24 22:56:37 -04005745func addTLS13RecordTests() {
5746 testCases = append(testCases, testCase{
5747 name: "TLS13-RecordPadding",
5748 config: Config{
5749 MaxVersion: VersionTLS13,
5750 MinVersion: VersionTLS13,
5751 Bugs: ProtocolBugs{
5752 RecordPadding: 10,
5753 },
5754 },
5755 })
5756
5757 testCases = append(testCases, testCase{
5758 name: "TLS13-EmptyRecords",
5759 config: Config{
5760 MaxVersion: VersionTLS13,
5761 MinVersion: VersionTLS13,
5762 Bugs: ProtocolBugs{
5763 OmitRecordContents: true,
5764 },
5765 },
5766 shouldFail: true,
5767 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5768 })
5769
5770 testCases = append(testCases, testCase{
5771 name: "TLS13-OnlyPadding",
5772 config: Config{
5773 MaxVersion: VersionTLS13,
5774 MinVersion: VersionTLS13,
5775 Bugs: ProtocolBugs{
5776 OmitRecordContents: true,
5777 RecordPadding: 10,
5778 },
5779 },
5780 shouldFail: true,
5781 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5782 })
5783
5784 testCases = append(testCases, testCase{
5785 name: "TLS13-WrongOuterRecord",
5786 config: Config{
5787 MaxVersion: VersionTLS13,
5788 MinVersion: VersionTLS13,
5789 Bugs: ProtocolBugs{
5790 OuterRecordType: recordTypeHandshake,
5791 },
5792 },
5793 shouldFail: true,
5794 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5795 })
5796}
5797
David Benjamin82261be2016-07-07 14:32:50 -07005798func addChangeCipherSpecTests() {
5799 // Test missing ChangeCipherSpecs.
5800 testCases = append(testCases, testCase{
5801 name: "SkipChangeCipherSpec-Client",
5802 config: Config{
5803 MaxVersion: VersionTLS12,
5804 Bugs: ProtocolBugs{
5805 SkipChangeCipherSpec: true,
5806 },
5807 },
5808 shouldFail: true,
5809 expectedError: ":UNEXPECTED_RECORD:",
5810 })
5811 testCases = append(testCases, testCase{
5812 testType: serverTest,
5813 name: "SkipChangeCipherSpec-Server",
5814 config: Config{
5815 MaxVersion: VersionTLS12,
5816 Bugs: ProtocolBugs{
5817 SkipChangeCipherSpec: true,
5818 },
5819 },
5820 shouldFail: true,
5821 expectedError: ":UNEXPECTED_RECORD:",
5822 })
5823 testCases = append(testCases, testCase{
5824 testType: serverTest,
5825 name: "SkipChangeCipherSpec-Server-NPN",
5826 config: Config{
5827 MaxVersion: VersionTLS12,
5828 NextProtos: []string{"bar"},
5829 Bugs: ProtocolBugs{
5830 SkipChangeCipherSpec: true,
5831 },
5832 },
5833 flags: []string{
5834 "-advertise-npn", "\x03foo\x03bar\x03baz",
5835 },
5836 shouldFail: true,
5837 expectedError: ":UNEXPECTED_RECORD:",
5838 })
5839
5840 // Test synchronization between the handshake and ChangeCipherSpec.
5841 // Partial post-CCS handshake messages before ChangeCipherSpec should be
5842 // rejected. Test both with and without handshake packing to handle both
5843 // when the partial post-CCS message is in its own record and when it is
5844 // attached to the pre-CCS message.
5845 //
5846 // TODO(davidben): Fix and test DTLS as well.
5847 for _, packed := range []bool{false, true} {
5848 var suffix string
5849 if packed {
5850 suffix = "-Packed"
5851 }
5852
5853 testCases = append(testCases, testCase{
5854 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
5855 config: Config{
5856 MaxVersion: VersionTLS12,
5857 Bugs: ProtocolBugs{
5858 FragmentAcrossChangeCipherSpec: true,
5859 PackHandshakeFlight: packed,
5860 },
5861 },
5862 shouldFail: true,
5863 expectedError: ":UNEXPECTED_RECORD:",
5864 })
5865 testCases = append(testCases, testCase{
5866 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
5867 config: Config{
5868 MaxVersion: VersionTLS12,
5869 },
5870 resumeSession: true,
5871 resumeConfig: &Config{
5872 MaxVersion: VersionTLS12,
5873 Bugs: ProtocolBugs{
5874 FragmentAcrossChangeCipherSpec: true,
5875 PackHandshakeFlight: packed,
5876 },
5877 },
5878 shouldFail: true,
5879 expectedError: ":UNEXPECTED_RECORD:",
5880 })
5881 testCases = append(testCases, testCase{
5882 testType: serverTest,
5883 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
5884 config: Config{
5885 MaxVersion: VersionTLS12,
5886 Bugs: ProtocolBugs{
5887 FragmentAcrossChangeCipherSpec: true,
5888 PackHandshakeFlight: packed,
5889 },
5890 },
5891 shouldFail: true,
5892 expectedError: ":UNEXPECTED_RECORD:",
5893 })
5894 testCases = append(testCases, testCase{
5895 testType: serverTest,
5896 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
5897 config: Config{
5898 MaxVersion: VersionTLS12,
5899 },
5900 resumeSession: true,
5901 resumeConfig: &Config{
5902 MaxVersion: VersionTLS12,
5903 Bugs: ProtocolBugs{
5904 FragmentAcrossChangeCipherSpec: true,
5905 PackHandshakeFlight: packed,
5906 },
5907 },
5908 shouldFail: true,
5909 expectedError: ":UNEXPECTED_RECORD:",
5910 })
5911 testCases = append(testCases, testCase{
5912 testType: serverTest,
5913 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
5914 config: Config{
5915 MaxVersion: VersionTLS12,
5916 NextProtos: []string{"bar"},
5917 Bugs: ProtocolBugs{
5918 FragmentAcrossChangeCipherSpec: true,
5919 PackHandshakeFlight: packed,
5920 },
5921 },
5922 flags: []string{
5923 "-advertise-npn", "\x03foo\x03bar\x03baz",
5924 },
5925 shouldFail: true,
5926 expectedError: ":UNEXPECTED_RECORD:",
5927 })
5928 }
5929
5930 // Test that early ChangeCipherSpecs are handled correctly.
5931 testCases = append(testCases, testCase{
5932 testType: serverTest,
5933 name: "EarlyChangeCipherSpec-server-1",
5934 config: Config{
5935 MaxVersion: VersionTLS12,
5936 Bugs: ProtocolBugs{
5937 EarlyChangeCipherSpec: 1,
5938 },
5939 },
5940 shouldFail: true,
5941 expectedError: ":UNEXPECTED_RECORD:",
5942 })
5943 testCases = append(testCases, testCase{
5944 testType: serverTest,
5945 name: "EarlyChangeCipherSpec-server-2",
5946 config: Config{
5947 MaxVersion: VersionTLS12,
5948 Bugs: ProtocolBugs{
5949 EarlyChangeCipherSpec: 2,
5950 },
5951 },
5952 shouldFail: true,
5953 expectedError: ":UNEXPECTED_RECORD:",
5954 })
5955 testCases = append(testCases, testCase{
5956 protocol: dtls,
5957 name: "StrayChangeCipherSpec",
5958 config: Config{
5959 // TODO(davidben): Once DTLS 1.3 exists, test
5960 // that stray ChangeCipherSpec messages are
5961 // rejected.
5962 MaxVersion: VersionTLS12,
5963 Bugs: ProtocolBugs{
5964 StrayChangeCipherSpec: true,
5965 },
5966 },
5967 })
5968
5969 // Test that the contents of ChangeCipherSpec are checked.
5970 testCases = append(testCases, testCase{
5971 name: "BadChangeCipherSpec-1",
5972 config: Config{
5973 MaxVersion: VersionTLS12,
5974 Bugs: ProtocolBugs{
5975 BadChangeCipherSpec: []byte{2},
5976 },
5977 },
5978 shouldFail: true,
5979 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5980 })
5981 testCases = append(testCases, testCase{
5982 name: "BadChangeCipherSpec-2",
5983 config: Config{
5984 MaxVersion: VersionTLS12,
5985 Bugs: ProtocolBugs{
5986 BadChangeCipherSpec: []byte{1, 1},
5987 },
5988 },
5989 shouldFail: true,
5990 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5991 })
5992 testCases = append(testCases, testCase{
5993 protocol: dtls,
5994 name: "BadChangeCipherSpec-DTLS-1",
5995 config: Config{
5996 MaxVersion: VersionTLS12,
5997 Bugs: ProtocolBugs{
5998 BadChangeCipherSpec: []byte{2},
5999 },
6000 },
6001 shouldFail: true,
6002 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6003 })
6004 testCases = append(testCases, testCase{
6005 protocol: dtls,
6006 name: "BadChangeCipherSpec-DTLS-2",
6007 config: Config{
6008 MaxVersion: VersionTLS12,
6009 Bugs: ProtocolBugs{
6010 BadChangeCipherSpec: []byte{1, 1},
6011 },
6012 },
6013 shouldFail: true,
6014 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
6015 })
6016}
6017
Adam Langley7c803a62015-06-15 15:35:05 -07006018func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07006019 defer wg.Done()
6020
6021 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08006022 var err error
6023
6024 if *mallocTest < 0 {
6025 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006026 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08006027 } else {
6028 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
6029 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07006030 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08006031 if err != nil {
6032 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
6033 }
6034 break
6035 }
6036 }
6037 }
Adam Langley95c29f32014-06-20 12:00:00 -07006038 statusChan <- statusMsg{test: test, err: err}
6039 }
6040}
6041
6042type statusMsg struct {
6043 test *testCase
6044 started bool
6045 err error
6046}
6047
David Benjamin5f237bc2015-02-11 17:14:15 -05006048func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07006049 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07006050
David Benjamin5f237bc2015-02-11 17:14:15 -05006051 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07006052 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05006053 if !*pipe {
6054 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05006055 var erase string
6056 for i := 0; i < lineLen; i++ {
6057 erase += "\b \b"
6058 }
6059 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05006060 }
6061
Adam Langley95c29f32014-06-20 12:00:00 -07006062 if msg.started {
6063 started++
6064 } else {
6065 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006066
6067 if msg.err != nil {
6068 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6069 failed++
6070 testOutput.addResult(msg.test.name, "FAIL")
6071 } else {
6072 if *pipe {
6073 // Print each test instead of a status line.
6074 fmt.Printf("PASSED (%s)\n", msg.test.name)
6075 }
6076 testOutput.addResult(msg.test.name, "PASS")
6077 }
Adam Langley95c29f32014-06-20 12:00:00 -07006078 }
6079
David Benjamin5f237bc2015-02-11 17:14:15 -05006080 if !*pipe {
6081 // Print a new status line.
6082 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6083 lineLen = len(line)
6084 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006085 }
Adam Langley95c29f32014-06-20 12:00:00 -07006086 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006087
6088 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006089}
6090
6091func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006092 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006093 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07006094 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07006095
Adam Langley7c803a62015-06-15 15:35:05 -07006096 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006097 addCipherSuiteTests()
6098 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006099 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006100 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006101 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006102 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006103 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006104 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006105 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006106 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006107 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006108 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006109 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006110 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006111 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006112 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006113 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006114 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006115 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006116 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006117 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006118 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006119 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006120 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006121 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006122
6123 var wg sync.WaitGroup
6124
Adam Langley7c803a62015-06-15 15:35:05 -07006125 statusChan := make(chan statusMsg, *numWorkers)
6126 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006127 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006128
David Benjamin025b3d32014-07-01 19:53:04 -04006129 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006130
Adam Langley7c803a62015-06-15 15:35:05 -07006131 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006132 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006133 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006134 }
6135
David Benjamin270f0a72016-03-17 14:41:36 -04006136 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006137 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006138 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006139 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006140 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006141 }
6142 }
David Benjamin270f0a72016-03-17 14:41:36 -04006143 if !foundTest {
6144 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6145 os.Exit(1)
6146 }
Adam Langley95c29f32014-06-20 12:00:00 -07006147
6148 close(testChan)
6149 wg.Wait()
6150 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006151 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006152
6153 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006154
6155 if *jsonOutput != "" {
6156 if err := testOutput.writeTo(*jsonOutput); err != nil {
6157 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6158 }
6159 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006160
6161 if !testOutput.allPassed {
6162 os.Exit(1)
6163 }
Adam Langley95c29f32014-06-20 12:00:00 -07006164}