blob: 35fe585ed75916c0018ec1c4b208397db1c95463 [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"
EKR842ae6c2016-07-27 09:22:05 +020024 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070025 "flag"
26 "fmt"
27 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070028 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070029 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070030 "net"
31 "os"
32 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040033 "path"
David Benjamin17e12922016-07-28 18:04:43 -040034 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040035 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080036 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070037 "strings"
38 "sync"
39 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050040 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070041)
42
Adam Langley69a01602014-11-17 17:26:55 -080043var (
EKR842ae6c2016-07-27 09:22:05 +020044 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
45 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
46 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
47 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
48 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
49 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.")
50 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
51 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040052 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020053 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
54 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
55 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
56 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
57 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
58 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
59 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
60 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
Adam Langley69a01602014-11-17 17:26:55 -080061)
Adam Langley95c29f32014-06-20 12:00:00 -070062
David Benjamin33863262016-07-08 17:20:12 -070063type testCert int
64
David Benjamin025b3d32014-07-01 19:53:04 -040065const (
David Benjamin33863262016-07-08 17:20:12 -070066 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040067 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070068 testCertECDSAP256
69 testCertECDSAP384
70 testCertECDSAP521
71)
72
73const (
74 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040075 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070076 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
77 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
78 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040079)
80
81const (
David Benjamina08e49d2014-08-24 01:46:07 -040082 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040083 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -070084 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
85 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
86 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -040087 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040088)
89
David Benjamin7944a9f2016-07-12 22:27:01 -040090var (
91 rsaCertificate Certificate
92 rsa1024Certificate Certificate
93 ecdsaP256Certificate Certificate
94 ecdsaP384Certificate Certificate
95 ecdsaP521Certificate Certificate
96)
David Benjamin33863262016-07-08 17:20:12 -070097
98var testCerts = []struct {
99 id testCert
100 certFile, keyFile string
101 cert *Certificate
102}{
103 {
104 id: testCertRSA,
105 certFile: rsaCertificateFile,
106 keyFile: rsaKeyFile,
107 cert: &rsaCertificate,
108 },
109 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400110 id: testCertRSA1024,
111 certFile: rsa1024CertificateFile,
112 keyFile: rsa1024KeyFile,
113 cert: &rsa1024Certificate,
114 },
115 {
David Benjamin33863262016-07-08 17:20:12 -0700116 id: testCertECDSAP256,
117 certFile: ecdsaP256CertificateFile,
118 keyFile: ecdsaP256KeyFile,
119 cert: &ecdsaP256Certificate,
120 },
121 {
122 id: testCertECDSAP384,
123 certFile: ecdsaP384CertificateFile,
124 keyFile: ecdsaP384KeyFile,
125 cert: &ecdsaP384Certificate,
126 },
127 {
128 id: testCertECDSAP521,
129 certFile: ecdsaP521CertificateFile,
130 keyFile: ecdsaP521KeyFile,
131 cert: &ecdsaP521Certificate,
132 },
133}
134
David Benjamina08e49d2014-08-24 01:46:07 -0400135var channelIDKey *ecdsa.PrivateKey
136var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700137
David Benjamin61f95272014-11-25 01:55:35 -0500138var testOCSPResponse = []byte{1, 2, 3, 4}
139var testSCTList = []byte{5, 6, 7, 8}
140
Adam Langley95c29f32014-06-20 12:00:00 -0700141func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700142 for i := range testCerts {
143 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
144 if err != nil {
145 panic(err)
146 }
147 cert.OCSPStaple = testOCSPResponse
148 cert.SignedCertificateTimestampList = testSCTList
149 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700150 }
David Benjamina08e49d2014-08-24 01:46:07 -0400151
Adam Langley7c803a62015-06-15 15:35:05 -0700152 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400153 if err != nil {
154 panic(err)
155 }
156 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
157 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
158 panic("bad key type")
159 }
160 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
161 if err != nil {
162 panic(err)
163 }
164 if channelIDKey.Curve != elliptic.P256() {
165 panic("bad curve")
166 }
167
168 channelIDBytes = make([]byte, 64)
169 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
170 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700171}
172
David Benjamin33863262016-07-08 17:20:12 -0700173func getRunnerCertificate(t testCert) Certificate {
174 for _, cert := range testCerts {
175 if cert.id == t {
176 return *cert.cert
177 }
178 }
179 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700180}
181
David Benjamin33863262016-07-08 17:20:12 -0700182func getShimCertificate(t testCert) string {
183 for _, cert := range testCerts {
184 if cert.id == t {
185 return cert.certFile
186 }
187 }
188 panic("Unknown test certificate")
189}
190
191func getShimKey(t testCert) string {
192 for _, cert := range testCerts {
193 if cert.id == t {
194 return cert.keyFile
195 }
196 }
197 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700198}
199
David Benjamin025b3d32014-07-01 19:53:04 -0400200type testType int
201
202const (
203 clientTest testType = iota
204 serverTest
205)
206
David Benjamin6fd297b2014-08-11 18:43:38 -0400207type protocol int
208
209const (
210 tls protocol = iota
211 dtls
212)
213
David Benjaminfc7b0862014-09-06 13:21:53 -0400214const (
215 alpn = 1
216 npn = 2
217)
218
Adam Langley95c29f32014-06-20 12:00:00 -0700219type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400220 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400221 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700222 name string
223 config Config
224 shouldFail bool
225 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700226 // expectedLocalError, if not empty, contains a substring that must be
227 // found in the local error.
228 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400229 // expectedVersion, if non-zero, specifies the TLS version that must be
230 // negotiated.
231 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400232 // expectedResumeVersion, if non-zero, specifies the TLS version that
233 // must be negotiated on resumption. If zero, expectedVersion is used.
234 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400235 // expectedCipher, if non-zero, specifies the TLS cipher suite that
236 // should be negotiated.
237 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400238 // expectChannelID controls whether the connection should have
239 // negotiated a Channel ID with channelIDKey.
240 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400241 // expectedNextProto controls whether the connection should
242 // negotiate a next protocol via NPN or ALPN.
243 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400244 // expectNoNextProto, if true, means that no next protocol should be
245 // negotiated.
246 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400247 // expectedNextProtoType, if non-zero, is the expected next
248 // protocol negotiation mechanism.
249 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500250 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
251 // should be negotiated. If zero, none should be negotiated.
252 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100253 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
254 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100255 // expectedSCTList, if not nil, is the expected SCT list to be received.
256 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700257 // expectedPeerSignatureAlgorithm, if not zero, is the signature
258 // algorithm that the peer should have used in the handshake.
259 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400260 // expectedCurveID, if not zero, is the curve that the handshake should
261 // have used.
262 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700263 // messageLen is the length, in bytes, of the test message that will be
264 // sent.
265 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400266 // messageCount is the number of test messages that will be sent.
267 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400268 // certFile is the path to the certificate to use for the server.
269 certFile string
270 // keyFile is the path to the private key to use for the server.
271 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400272 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400273 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400274 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700275 // expectResumeRejected, if true, specifies that the attempted
276 // resumption must be rejected by the client. This is only valid for a
277 // serverTest.
278 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400279 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500280 // resumption. Unless newSessionsOnResume is set,
281 // SessionTicketKey, ServerSessionCache, and
282 // ClientSessionCache are copied from the initial connection's
283 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400284 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500285 // newSessionsOnResume, if true, will cause resumeConfig to
286 // use a different session resumption context.
287 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400288 // noSessionCache, if true, will cause the server to run without a
289 // session cache.
290 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400291 // sendPrefix sends a prefix on the socket before actually performing a
292 // handshake.
293 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400294 // shimWritesFirst controls whether the shim sends an initial "hello"
295 // message before doing a roundtrip with the runner.
296 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400297 // shimShutsDown, if true, runs a test where the shim shuts down the
298 // connection immediately after the handshake rather than echoing
299 // messages from the runner.
300 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400301 // renegotiate indicates the number of times the connection should be
302 // renegotiated during the exchange.
303 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400304 // sendHalfHelloRequest, if true, causes the server to send half a
305 // HelloRequest when the handshake completes.
306 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700307 // renegotiateCiphers is a list of ciphersuite ids that will be
308 // switched in just before renegotiation.
309 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500310 // replayWrites, if true, configures the underlying transport
311 // to replay every write it makes in DTLS tests.
312 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500313 // damageFirstWrite, if true, configures the underlying transport to
314 // damage the final byte of the first application data write.
315 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400316 // exportKeyingMaterial, if non-zero, configures the test to exchange
317 // keying material and verify they match.
318 exportKeyingMaterial int
319 exportLabel string
320 exportContext string
321 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400322 // flags, if not empty, contains a list of command-line flags that will
323 // be passed to the shim program.
324 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700325 // testTLSUnique, if true, causes the shim to send the tls-unique value
326 // which will be compared against the expected value.
327 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400328 // sendEmptyRecords is the number of consecutive empty records to send
329 // before and after the test message.
330 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400331 // sendWarningAlerts is the number of consecutive warning alerts to send
332 // before and after the test message.
333 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400334 // expectMessageDropped, if true, means the test message is expected to
335 // be dropped by the client rather than echoed back.
336 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700337}
338
Adam Langley7c803a62015-06-15 15:35:05 -0700339var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700340
David Benjamin9867b7d2016-03-01 23:25:48 -0500341func writeTranscript(test *testCase, isResume bool, data []byte) {
342 if len(data) == 0 {
343 return
344 }
345
346 protocol := "tls"
347 if test.protocol == dtls {
348 protocol = "dtls"
349 }
350
351 side := "client"
352 if test.testType == serverTest {
353 side = "server"
354 }
355
356 dir := path.Join(*transcriptDir, protocol, side)
357 if err := os.MkdirAll(dir, 0755); err != nil {
358 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
359 return
360 }
361
362 name := test.name
363 if isResume {
364 name += "-Resume"
365 } else {
366 name += "-Normal"
367 }
368
369 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
370 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
371 }
372}
373
David Benjamin3ed59772016-03-08 12:50:21 -0500374// A timeoutConn implements an idle timeout on each Read and Write operation.
375type timeoutConn struct {
376 net.Conn
377 timeout time.Duration
378}
379
380func (t *timeoutConn) Read(b []byte) (int, error) {
381 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
382 return 0, err
383 }
384 return t.Conn.Read(b)
385}
386
387func (t *timeoutConn) Write(b []byte) (int, error) {
388 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
389 return 0, err
390 }
391 return t.Conn.Write(b)
392}
393
David Benjamin8e6db492015-07-25 18:29:23 -0400394func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400395 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500396
David Benjamin6fd297b2014-08-11 18:43:38 -0400397 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500398 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
399 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500400 }
401
David Benjamin9867b7d2016-03-01 23:25:48 -0500402 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500403 local, peer := "client", "server"
404 if test.testType == clientTest {
405 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500406 }
David Benjaminebda9b32015-11-02 15:33:18 -0500407 connDebug := &recordingConn{
408 Conn: conn,
409 isDatagram: test.protocol == dtls,
410 local: local,
411 peer: peer,
412 }
413 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500414 if *flagDebug {
415 defer connDebug.WriteTo(os.Stdout)
416 }
417 if len(*transcriptDir) != 0 {
418 defer func() {
419 writeTranscript(test, isResume, connDebug.Transcript())
420 }()
421 }
David Benjaminebda9b32015-11-02 15:33:18 -0500422
423 if config.Bugs.PacketAdaptor != nil {
424 config.Bugs.PacketAdaptor.debug = connDebug
425 }
426 }
427
428 if test.replayWrites {
429 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400430 }
431
David Benjamin3ed59772016-03-08 12:50:21 -0500432 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500433 if test.damageFirstWrite {
434 connDamage = newDamageAdaptor(conn)
435 conn = connDamage
436 }
437
David Benjamin6fd297b2014-08-11 18:43:38 -0400438 if test.sendPrefix != "" {
439 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
440 return err
441 }
David Benjamin98e882e2014-08-08 13:24:34 -0400442 }
443
David Benjamin1d5c83e2014-07-22 19:20:02 -0400444 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400445 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400446 if test.protocol == dtls {
447 tlsConn = DTLSServer(conn, config)
448 } else {
449 tlsConn = Server(conn, config)
450 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400451 } else {
452 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400453 if test.protocol == dtls {
454 tlsConn = DTLSClient(conn, config)
455 } else {
456 tlsConn = Client(conn, config)
457 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400458 }
David Benjamin30789da2015-08-29 22:56:45 -0400459 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400460
Adam Langley95c29f32014-06-20 12:00:00 -0700461 if err := tlsConn.Handshake(); err != nil {
462 return err
463 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700464
David Benjamin01fe8202014-09-24 15:21:44 -0400465 // TODO(davidben): move all per-connection expectations into a dedicated
466 // expectations struct that can be specified separately for the two
467 // legs.
468 expectedVersion := test.expectedVersion
469 if isResume && test.expectedResumeVersion != 0 {
470 expectedVersion = test.expectedResumeVersion
471 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700472 connState := tlsConn.ConnectionState()
473 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400474 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400475 }
476
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700477 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400478 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
479 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700480 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
481 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
482 }
David Benjamin90da8c82015-04-20 14:57:57 -0400483
David Benjamina08e49d2014-08-24 01:46:07 -0400484 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700485 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400486 if channelID == nil {
487 return fmt.Errorf("no channel ID negotiated")
488 }
489 if channelID.Curve != channelIDKey.Curve ||
490 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
491 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
492 return fmt.Errorf("incorrect channel ID")
493 }
494 }
495
David Benjaminae2888f2014-09-06 12:58:58 -0400496 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700497 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400498 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
499 }
500 }
501
David Benjaminc7ce9772015-10-09 19:32:41 -0400502 if test.expectNoNextProto {
503 if actual := connState.NegotiatedProtocol; actual != "" {
504 return fmt.Errorf("got unexpected next proto %s", actual)
505 }
506 }
507
David Benjaminfc7b0862014-09-06 13:21:53 -0400508 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700509 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400510 return fmt.Errorf("next proto type mismatch")
511 }
512 }
513
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700514 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500515 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
516 }
517
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100518 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300519 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100520 }
521
Paul Lietar4fac72e2015-09-09 13:44:55 +0100522 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
523 return fmt.Errorf("SCT list mismatch")
524 }
525
Nick Harper60edffd2016-06-21 15:19:24 -0700526 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
527 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400528 }
529
Steven Valdez5440fe02016-07-18 12:40:30 -0400530 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
531 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
532 }
533
David Benjaminc565ebb2015-04-03 04:06:36 -0400534 if test.exportKeyingMaterial > 0 {
535 actual := make([]byte, test.exportKeyingMaterial)
536 if _, err := io.ReadFull(tlsConn, actual); err != nil {
537 return err
538 }
539 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
540 if err != nil {
541 return err
542 }
543 if !bytes.Equal(actual, expected) {
544 return fmt.Errorf("keying material mismatch")
545 }
546 }
547
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700548 if test.testTLSUnique {
549 var peersValue [12]byte
550 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
551 return err
552 }
553 expected := tlsConn.ConnectionState().TLSUnique
554 if !bytes.Equal(peersValue[:], expected) {
555 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
556 }
557 }
558
David Benjamine58c4f52014-08-24 03:47:07 -0400559 if test.shimWritesFirst {
560 var buf [5]byte
561 _, err := io.ReadFull(tlsConn, buf[:])
562 if err != nil {
563 return err
564 }
565 if string(buf[:]) != "hello" {
566 return fmt.Errorf("bad initial message")
567 }
568 }
569
David Benjamina8ebe222015-06-06 03:04:39 -0400570 for i := 0; i < test.sendEmptyRecords; i++ {
571 tlsConn.Write(nil)
572 }
573
David Benjamin24f346d2015-06-06 03:28:08 -0400574 for i := 0; i < test.sendWarningAlerts; i++ {
575 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
576 }
577
David Benjamin47921102016-07-28 11:29:18 -0400578 if test.sendHalfHelloRequest {
579 tlsConn.SendHalfHelloRequest()
580 }
581
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400582 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700583 if test.renegotiateCiphers != nil {
584 config.CipherSuites = test.renegotiateCiphers
585 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400586 for i := 0; i < test.renegotiate; i++ {
587 if err := tlsConn.Renegotiate(); err != nil {
588 return err
589 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700590 }
591 } else if test.renegotiateCiphers != nil {
592 panic("renegotiateCiphers without renegotiate")
593 }
594
David Benjamin5fa3eba2015-01-22 16:35:40 -0500595 if test.damageFirstWrite {
596 connDamage.setDamage(true)
597 tlsConn.Write([]byte("DAMAGED WRITE"))
598 connDamage.setDamage(false)
599 }
600
David Benjamin8e6db492015-07-25 18:29:23 -0400601 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700602 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400603 if test.protocol == dtls {
604 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
605 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700606 // Read until EOF.
607 _, err := io.Copy(ioutil.Discard, tlsConn)
608 return err
609 }
David Benjamin4417d052015-04-05 04:17:25 -0400610 if messageLen == 0 {
611 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700612 }
Adam Langley95c29f32014-06-20 12:00:00 -0700613
David Benjamin8e6db492015-07-25 18:29:23 -0400614 messageCount := test.messageCount
615 if messageCount == 0 {
616 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400617 }
618
David Benjamin8e6db492015-07-25 18:29:23 -0400619 for j := 0; j < messageCount; j++ {
620 testMessage := make([]byte, messageLen)
621 for i := range testMessage {
622 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400623 }
David Benjamin8e6db492015-07-25 18:29:23 -0400624 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700625
David Benjamin8e6db492015-07-25 18:29:23 -0400626 for i := 0; i < test.sendEmptyRecords; i++ {
627 tlsConn.Write(nil)
628 }
629
630 for i := 0; i < test.sendWarningAlerts; i++ {
631 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
632 }
633
David Benjamin4f75aaf2015-09-01 16:53:10 -0400634 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400635 // The shim will not respond.
636 continue
637 }
638
David Benjamin8e6db492015-07-25 18:29:23 -0400639 buf := make([]byte, len(testMessage))
640 if test.protocol == dtls {
641 bufTmp := make([]byte, len(buf)+1)
642 n, err := tlsConn.Read(bufTmp)
643 if err != nil {
644 return err
645 }
646 if n != len(buf) {
647 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
648 }
649 copy(buf, bufTmp)
650 } else {
651 _, err := io.ReadFull(tlsConn, buf)
652 if err != nil {
653 return err
654 }
655 }
656
657 for i, v := range buf {
658 if v != testMessage[i]^0xff {
659 return fmt.Errorf("bad reply contents at byte %d", i)
660 }
Adam Langley95c29f32014-06-20 12:00:00 -0700661 }
662 }
663
664 return nil
665}
666
David Benjamin325b5c32014-07-01 19:40:31 -0400667func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
668 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700669 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400670 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700671 }
David Benjamin325b5c32014-07-01 19:40:31 -0400672 valgrindArgs = append(valgrindArgs, path)
673 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700674
David Benjamin325b5c32014-07-01 19:40:31 -0400675 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700676}
677
David Benjamin325b5c32014-07-01 19:40:31 -0400678func gdbOf(path string, args ...string) *exec.Cmd {
679 xtermArgs := []string{"-e", "gdb", "--args"}
680 xtermArgs = append(xtermArgs, path)
681 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700682
David Benjamin325b5c32014-07-01 19:40:31 -0400683 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700684}
685
David Benjamind16bf342015-12-18 00:53:12 -0500686func lldbOf(path string, args ...string) *exec.Cmd {
687 xtermArgs := []string{"-e", "lldb", "--"}
688 xtermArgs = append(xtermArgs, path)
689 xtermArgs = append(xtermArgs, args...)
690
691 return exec.Command("xterm", xtermArgs...)
692}
693
EKR842ae6c2016-07-27 09:22:05 +0200694var (
695 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
696 errUnimplemented = errors.New("child process does not implement needed flags")
697)
Adam Langley69a01602014-11-17 17:26:55 -0800698
David Benjamin87c8a642015-02-21 01:54:29 -0500699// accept accepts a connection from listener, unless waitChan signals a process
700// exit first.
701func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
702 type connOrError struct {
703 conn net.Conn
704 err error
705 }
706 connChan := make(chan connOrError, 1)
707 go func() {
708 conn, err := listener.Accept()
709 connChan <- connOrError{conn, err}
710 close(connChan)
711 }()
712 select {
713 case result := <-connChan:
714 return result.conn, result.err
715 case childErr := <-waitChan:
716 waitChan <- childErr
717 return nil, fmt.Errorf("child exited early: %s", childErr)
718 }
719}
720
Adam Langley7c803a62015-06-15 15:35:05 -0700721func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700722 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
723 panic("Error expected without shouldFail in " + test.name)
724 }
725
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700726 if test.expectResumeRejected && !test.resumeSession {
727 panic("expectResumeRejected without resumeSession in " + test.name)
728 }
729
David Benjamin87c8a642015-02-21 01:54:29 -0500730 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
731 if err != nil {
732 panic(err)
733 }
734 defer func() {
735 if listener != nil {
736 listener.Close()
737 }
738 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700739
David Benjamin87c8a642015-02-21 01:54:29 -0500740 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400741 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400742 flags = append(flags, "-server")
743
David Benjamin025b3d32014-07-01 19:53:04 -0400744 flags = append(flags, "-key-file")
745 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700746 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400747 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700748 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400749 }
750
751 flags = append(flags, "-cert-file")
752 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700753 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400754 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700755 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400756 }
757 }
David Benjamin5a593af2014-08-11 19:51:50 -0400758
David Benjamin6fd297b2014-08-11 18:43:38 -0400759 if test.protocol == dtls {
760 flags = append(flags, "-dtls")
761 }
762
David Benjamin5a593af2014-08-11 19:51:50 -0400763 if test.resumeSession {
764 flags = append(flags, "-resume")
765 }
766
David Benjamine58c4f52014-08-24 03:47:07 -0400767 if test.shimWritesFirst {
768 flags = append(flags, "-shim-writes-first")
769 }
770
David Benjamin30789da2015-08-29 22:56:45 -0400771 if test.shimShutsDown {
772 flags = append(flags, "-shim-shuts-down")
773 }
774
David Benjaminc565ebb2015-04-03 04:06:36 -0400775 if test.exportKeyingMaterial > 0 {
776 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
777 flags = append(flags, "-export-label", test.exportLabel)
778 flags = append(flags, "-export-context", test.exportContext)
779 if test.useExportContext {
780 flags = append(flags, "-use-export-context")
781 }
782 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700783 if test.expectResumeRejected {
784 flags = append(flags, "-expect-session-miss")
785 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400786
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700787 if test.testTLSUnique {
788 flags = append(flags, "-tls-unique")
789 }
790
David Benjamin025b3d32014-07-01 19:53:04 -0400791 flags = append(flags, test.flags...)
792
793 var shim *exec.Cmd
794 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700795 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700796 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700797 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500798 } else if *useLLDB {
799 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400800 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700801 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400802 }
David Benjamin025b3d32014-07-01 19:53:04 -0400803 shim.Stdin = os.Stdin
804 var stdoutBuf, stderrBuf bytes.Buffer
805 shim.Stdout = &stdoutBuf
806 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800807 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500808 shim.Env = os.Environ()
809 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800810 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400811 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800812 }
813 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
814 }
David Benjamin025b3d32014-07-01 19:53:04 -0400815
816 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700817 panic(err)
818 }
David Benjamin87c8a642015-02-21 01:54:29 -0500819 waitChan := make(chan error, 1)
820 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700821
822 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400823 if !test.noSessionCache {
824 config.ClientSessionCache = NewLRUClientSessionCache(1)
825 config.ServerSessionCache = NewLRUServerSessionCache(1)
826 }
David Benjamin025b3d32014-07-01 19:53:04 -0400827 if test.testType == clientTest {
828 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700829 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400830 }
David Benjamin87c8a642015-02-21 01:54:29 -0500831 } else {
832 // Supply a ServerName to ensure a constant session cache key,
833 // rather than falling back to net.Conn.RemoteAddr.
834 if len(config.ServerName) == 0 {
835 config.ServerName = "test"
836 }
David Benjamin025b3d32014-07-01 19:53:04 -0400837 }
David Benjaminf2b83632016-03-01 22:57:46 -0500838 if *fuzzer {
839 config.Bugs.NullAllCiphers = true
840 }
David Benjamin2e045a92016-06-08 13:09:56 -0400841 if *deterministic {
842 config.Rand = &deterministicRand{}
843 }
Adam Langley95c29f32014-06-20 12:00:00 -0700844
David Benjamin87c8a642015-02-21 01:54:29 -0500845 conn, err := acceptOrWait(listener, waitChan)
846 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400847 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500848 conn.Close()
849 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500850
David Benjamin1d5c83e2014-07-22 19:20:02 -0400851 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400852 var resumeConfig Config
853 if test.resumeConfig != nil {
854 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500855 if len(resumeConfig.ServerName) == 0 {
856 resumeConfig.ServerName = config.ServerName
857 }
David Benjamin01fe8202014-09-24 15:21:44 -0400858 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700859 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400860 }
David Benjaminba4594a2015-06-18 18:36:15 -0400861 if test.newSessionsOnResume {
862 if !test.noSessionCache {
863 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
864 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
865 }
866 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500867 resumeConfig.SessionTicketKey = config.SessionTicketKey
868 resumeConfig.ClientSessionCache = config.ClientSessionCache
869 resumeConfig.ServerSessionCache = config.ServerSessionCache
870 }
David Benjaminf2b83632016-03-01 22:57:46 -0500871 if *fuzzer {
872 resumeConfig.Bugs.NullAllCiphers = true
873 }
David Benjamin2e045a92016-06-08 13:09:56 -0400874 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400875 } else {
876 resumeConfig = config
877 }
David Benjamin87c8a642015-02-21 01:54:29 -0500878 var connResume net.Conn
879 connResume, err = acceptOrWait(listener, waitChan)
880 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400881 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500882 connResume.Close()
883 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400884 }
885
David Benjamin87c8a642015-02-21 01:54:29 -0500886 // Close the listener now. This is to avoid hangs should the shim try to
887 // open more connections than expected.
888 listener.Close()
889 listener = nil
890
891 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800892 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200893 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
894 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800895 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200896 case 89:
897 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800898 }
899 }
Adam Langley95c29f32014-06-20 12:00:00 -0700900
David Benjamin9bea3492016-03-02 10:59:16 -0500901 // Account for Windows line endings.
902 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
903 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500904
905 // Separate the errors from the shim and those from tools like
906 // AddressSanitizer.
907 var extraStderr string
908 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
909 stderr = stderrParts[0]
910 extraStderr = stderrParts[1]
911 }
912
Adam Langley95c29f32014-06-20 12:00:00 -0700913 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400914 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700915 localError := "none"
916 if err != nil {
917 localError = err.Error()
918 }
919 if len(test.expectedLocalError) != 0 {
920 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
921 }
Adam Langley95c29f32014-06-20 12:00:00 -0700922
923 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700924 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700925 if childErr != nil {
926 childError = childErr.Error()
927 }
928
929 var msg string
930 switch {
931 case failed && !test.shouldFail:
932 msg = "unexpected failure"
933 case !failed && test.shouldFail:
934 msg = "unexpected success"
935 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700936 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700937 default:
938 panic("internal error")
939 }
940
David Benjaminc565ebb2015-04-03 04:06:36 -0400941 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 -0700942 }
943
David Benjaminff3a1492016-03-02 10:12:06 -0500944 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
945 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700946 }
947
948 return nil
949}
950
951var tlsVersions = []struct {
952 name string
953 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400954 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500955 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700956}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500957 {"SSL3", VersionSSL30, "-no-ssl3", false},
958 {"TLS1", VersionTLS10, "-no-tls1", true},
959 {"TLS11", VersionTLS11, "-no-tls11", false},
960 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400961 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700962}
963
964var testCipherSuites = []struct {
965 name string
966 id uint16
967}{
968 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400969 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700970 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400971 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400972 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700973 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400974 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400975 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
976 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400977 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400978 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
979 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400980 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700981 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
982 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400983 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
984 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700985 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400986 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500987 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500988 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700989 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700990 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700991 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400992 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400993 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700994 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400995 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500996 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500997 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700998 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700999 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1000 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1001 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1002 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001003 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1004 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001005 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1006 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001007 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001008 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1009 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001010 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001011 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001012 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001013 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001014}
1015
David Benjamin8b8c0062014-11-23 02:47:52 -05001016func hasComponent(suiteName, component string) bool {
1017 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1018}
1019
David Benjaminf7768e42014-08-31 02:06:47 -04001020func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001021 return hasComponent(suiteName, "GCM") ||
1022 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001023 hasComponent(suiteName, "SHA384") ||
1024 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001025}
1026
Nick Harper1fd39d82016-06-14 18:14:35 -07001027func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001028 // Only AEADs.
1029 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1030 return false
1031 }
1032 // No old CHACHA20_POLY1305.
1033 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1034 return false
1035 }
1036 // Must have ECDHE.
1037 // TODO(davidben,svaldez): Add pure PSK support.
1038 if !hasComponent(suiteName, "ECDHE") {
1039 return false
1040 }
1041 // TODO(davidben,svaldez): Add PSK support.
1042 if hasComponent(suiteName, "PSK") {
1043 return false
1044 }
1045 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001046}
1047
David Benjamin8b8c0062014-11-23 02:47:52 -05001048func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001049 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001050}
1051
Adam Langleya7997f12015-05-14 17:38:50 -07001052func bigFromHex(hex string) *big.Int {
1053 ret, ok := new(big.Int).SetString(hex, 16)
1054 if !ok {
1055 panic("failed to parse hex number 0x" + hex)
1056 }
1057 return ret
1058}
1059
Adam Langley7c803a62015-06-15 15:35:05 -07001060func addBasicTests() {
1061 basicTests := []testCase{
1062 {
Adam Langley7c803a62015-06-15 15:35:05 -07001063 name: "NoFallbackSCSV",
1064 config: Config{
1065 Bugs: ProtocolBugs{
1066 FailIfNotFallbackSCSV: true,
1067 },
1068 },
1069 shouldFail: true,
1070 expectedLocalError: "no fallback SCSV found",
1071 },
1072 {
1073 name: "SendFallbackSCSV",
1074 config: Config{
1075 Bugs: ProtocolBugs{
1076 FailIfNotFallbackSCSV: true,
1077 },
1078 },
1079 flags: []string{"-fallback-scsv"},
1080 },
1081 {
1082 name: "ClientCertificateTypes",
1083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001084 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001085 ClientAuth: RequestClientCert,
1086 ClientCertificateTypes: []byte{
1087 CertTypeDSSSign,
1088 CertTypeRSASign,
1089 CertTypeECDSASign,
1090 },
1091 },
1092 flags: []string{
1093 "-expect-certificate-types",
1094 base64.StdEncoding.EncodeToString([]byte{
1095 CertTypeDSSSign,
1096 CertTypeRSASign,
1097 CertTypeECDSASign,
1098 }),
1099 },
1100 },
1101 {
Adam Langley7c803a62015-06-15 15:35:05 -07001102 name: "UnauthenticatedECDH",
1103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001104 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001105 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1106 Bugs: ProtocolBugs{
1107 UnauthenticatedECDH: true,
1108 },
1109 },
1110 shouldFail: true,
1111 expectedError: ":UNEXPECTED_MESSAGE:",
1112 },
1113 {
1114 name: "SkipCertificateStatus",
1115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001116 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1118 Bugs: ProtocolBugs{
1119 SkipCertificateStatus: true,
1120 },
1121 },
1122 flags: []string{
1123 "-enable-ocsp-stapling",
1124 },
1125 },
1126 {
1127 name: "SkipServerKeyExchange",
1128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001129 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001130 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1131 Bugs: ProtocolBugs{
1132 SkipServerKeyExchange: true,
1133 },
1134 },
1135 shouldFail: true,
1136 expectedError: ":UNEXPECTED_MESSAGE:",
1137 },
1138 {
Adam Langley7c803a62015-06-15 15:35:05 -07001139 testType: serverTest,
1140 name: "Alert",
1141 config: Config{
1142 Bugs: ProtocolBugs{
1143 SendSpuriousAlert: alertRecordOverflow,
1144 },
1145 },
1146 shouldFail: true,
1147 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1148 },
1149 {
1150 protocol: dtls,
1151 testType: serverTest,
1152 name: "Alert-DTLS",
1153 config: Config{
1154 Bugs: ProtocolBugs{
1155 SendSpuriousAlert: alertRecordOverflow,
1156 },
1157 },
1158 shouldFail: true,
1159 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1160 },
1161 {
1162 testType: serverTest,
1163 name: "FragmentAlert",
1164 config: Config{
1165 Bugs: ProtocolBugs{
1166 FragmentAlert: true,
1167 SendSpuriousAlert: alertRecordOverflow,
1168 },
1169 },
1170 shouldFail: true,
1171 expectedError: ":BAD_ALERT:",
1172 },
1173 {
1174 protocol: dtls,
1175 testType: serverTest,
1176 name: "FragmentAlert-DTLS",
1177 config: Config{
1178 Bugs: ProtocolBugs{
1179 FragmentAlert: true,
1180 SendSpuriousAlert: alertRecordOverflow,
1181 },
1182 },
1183 shouldFail: true,
1184 expectedError: ":BAD_ALERT:",
1185 },
1186 {
1187 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001188 name: "DoubleAlert",
1189 config: Config{
1190 Bugs: ProtocolBugs{
1191 DoubleAlert: true,
1192 SendSpuriousAlert: alertRecordOverflow,
1193 },
1194 },
1195 shouldFail: true,
1196 expectedError: ":BAD_ALERT:",
1197 },
1198 {
1199 protocol: dtls,
1200 testType: serverTest,
1201 name: "DoubleAlert-DTLS",
1202 config: Config{
1203 Bugs: ProtocolBugs{
1204 DoubleAlert: true,
1205 SendSpuriousAlert: alertRecordOverflow,
1206 },
1207 },
1208 shouldFail: true,
1209 expectedError: ":BAD_ALERT:",
1210 },
1211 {
Adam Langley7c803a62015-06-15 15:35:05 -07001212 name: "SkipNewSessionTicket",
1213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001214 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001215 Bugs: ProtocolBugs{
1216 SkipNewSessionTicket: true,
1217 },
1218 },
1219 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001220 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001221 },
1222 {
1223 testType: serverTest,
1224 name: "FallbackSCSV",
1225 config: Config{
1226 MaxVersion: VersionTLS11,
1227 Bugs: ProtocolBugs{
1228 SendFallbackSCSV: true,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":INAPPROPRIATE_FALLBACK:",
1233 },
1234 {
1235 testType: serverTest,
1236 name: "FallbackSCSV-VersionMatch",
1237 config: Config{
1238 Bugs: ProtocolBugs{
1239 SendFallbackSCSV: true,
1240 },
1241 },
1242 },
1243 {
1244 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001245 name: "FallbackSCSV-VersionMatch-TLS12",
1246 config: Config{
1247 MaxVersion: VersionTLS12,
1248 Bugs: ProtocolBugs{
1249 SendFallbackSCSV: true,
1250 },
1251 },
1252 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1253 },
1254 {
1255 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001256 name: "FragmentedClientVersion",
1257 config: Config{
1258 Bugs: ProtocolBugs{
1259 MaxHandshakeRecordLength: 1,
1260 FragmentClientVersion: true,
1261 },
1262 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001263 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001264 },
1265 {
Adam Langley7c803a62015-06-15 15:35:05 -07001266 testType: serverTest,
1267 name: "HttpGET",
1268 sendPrefix: "GET / HTTP/1.0\n",
1269 shouldFail: true,
1270 expectedError: ":HTTP_REQUEST:",
1271 },
1272 {
1273 testType: serverTest,
1274 name: "HttpPOST",
1275 sendPrefix: "POST / HTTP/1.0\n",
1276 shouldFail: true,
1277 expectedError: ":HTTP_REQUEST:",
1278 },
1279 {
1280 testType: serverTest,
1281 name: "HttpHEAD",
1282 sendPrefix: "HEAD / HTTP/1.0\n",
1283 shouldFail: true,
1284 expectedError: ":HTTP_REQUEST:",
1285 },
1286 {
1287 testType: serverTest,
1288 name: "HttpPUT",
1289 sendPrefix: "PUT / HTTP/1.0\n",
1290 shouldFail: true,
1291 expectedError: ":HTTP_REQUEST:",
1292 },
1293 {
1294 testType: serverTest,
1295 name: "HttpCONNECT",
1296 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1297 shouldFail: true,
1298 expectedError: ":HTTPS_PROXY_REQUEST:",
1299 },
1300 {
1301 testType: serverTest,
1302 name: "Garbage",
1303 sendPrefix: "blah",
1304 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001305 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001306 },
1307 {
Adam Langley7c803a62015-06-15 15:35:05 -07001308 name: "RSAEphemeralKey",
1309 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001310 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001311 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1312 Bugs: ProtocolBugs{
1313 RSAEphemeralKey: true,
1314 },
1315 },
1316 shouldFail: true,
1317 expectedError: ":UNEXPECTED_MESSAGE:",
1318 },
1319 {
1320 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001321 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001322 shouldFail: true,
1323 expectedError: ":WRONG_SSL_VERSION:",
1324 },
1325 {
1326 protocol: dtls,
1327 name: "DisableEverything-DTLS",
1328 flags: []string{"-no-tls12", "-no-tls1"},
1329 shouldFail: true,
1330 expectedError: ":WRONG_SSL_VERSION:",
1331 },
1332 {
Adam Langley7c803a62015-06-15 15:35:05 -07001333 protocol: dtls,
1334 testType: serverTest,
1335 name: "MTU",
1336 config: Config{
1337 Bugs: ProtocolBugs{
1338 MaxPacketLength: 256,
1339 },
1340 },
1341 flags: []string{"-mtu", "256"},
1342 },
1343 {
1344 protocol: dtls,
1345 testType: serverTest,
1346 name: "MTUExceeded",
1347 config: Config{
1348 Bugs: ProtocolBugs{
1349 MaxPacketLength: 255,
1350 },
1351 },
1352 flags: []string{"-mtu", "256"},
1353 shouldFail: true,
1354 expectedLocalError: "dtls: exceeded maximum packet length",
1355 },
1356 {
1357 name: "CertMismatchRSA",
1358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001359 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001360 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001361 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001362 Bugs: ProtocolBugs{
1363 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1364 },
1365 },
1366 shouldFail: true,
1367 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1368 },
1369 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001370 name: "CertMismatchRSA-TLS13",
1371 config: Config{
1372 MaxVersion: VersionTLS13,
1373 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1374 Certificates: []Certificate{ecdsaP256Certificate},
1375 Bugs: ProtocolBugs{
1376 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1377 },
1378 },
1379 shouldFail: true,
1380 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1381 },
1382 {
Adam Langley7c803a62015-06-15 15:35:05 -07001383 name: "CertMismatchECDSA",
1384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001385 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001386 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001387 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001388 Bugs: ProtocolBugs{
1389 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1394 },
1395 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001396 name: "CertMismatchECDSA-TLS13",
1397 config: Config{
1398 MaxVersion: VersionTLS13,
1399 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1400 Certificates: []Certificate{rsaCertificate},
1401 Bugs: ProtocolBugs{
1402 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1403 },
1404 },
1405 shouldFail: true,
1406 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1407 },
1408 {
Adam Langley7c803a62015-06-15 15:35:05 -07001409 name: "EmptyCertificateList",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1413 Bugs: ProtocolBugs{
1414 EmptyCertificateList: true,
1415 },
1416 },
1417 shouldFail: true,
1418 expectedError: ":DECODE_ERROR:",
1419 },
1420 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001421 name: "EmptyCertificateList-TLS13",
1422 config: Config{
1423 MaxVersion: VersionTLS13,
1424 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1425 Bugs: ProtocolBugs{
1426 EmptyCertificateList: true,
1427 },
1428 },
1429 shouldFail: true,
1430 expectedError: ":DECODE_ERROR:",
1431 },
1432 {
Adam Langley7c803a62015-06-15 15:35:05 -07001433 name: "TLSFatalBadPackets",
1434 damageFirstWrite: true,
1435 shouldFail: true,
1436 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1437 },
1438 {
1439 protocol: dtls,
1440 name: "DTLSIgnoreBadPackets",
1441 damageFirstWrite: true,
1442 },
1443 {
1444 protocol: dtls,
1445 name: "DTLSIgnoreBadPackets-Async",
1446 damageFirstWrite: true,
1447 flags: []string{"-async"},
1448 },
1449 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001450 name: "AppDataBeforeHandshake",
1451 config: Config{
1452 Bugs: ProtocolBugs{
1453 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1454 },
1455 },
1456 shouldFail: true,
1457 expectedError: ":UNEXPECTED_RECORD:",
1458 },
1459 {
1460 name: "AppDataBeforeHandshake-Empty",
1461 config: Config{
1462 Bugs: ProtocolBugs{
1463 AppDataBeforeHandshake: []byte{},
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":UNEXPECTED_RECORD:",
1468 },
1469 {
1470 protocol: dtls,
1471 name: "AppDataBeforeHandshake-DTLS",
1472 config: Config{
1473 Bugs: ProtocolBugs{
1474 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1475 },
1476 },
1477 shouldFail: true,
1478 expectedError: ":UNEXPECTED_RECORD:",
1479 },
1480 {
1481 protocol: dtls,
1482 name: "AppDataBeforeHandshake-DTLS-Empty",
1483 config: Config{
1484 Bugs: ProtocolBugs{
1485 AppDataBeforeHandshake: []byte{},
1486 },
1487 },
1488 shouldFail: true,
1489 expectedError: ":UNEXPECTED_RECORD:",
1490 },
1491 {
Adam Langley7c803a62015-06-15 15:35:05 -07001492 name: "AppDataAfterChangeCipherSpec",
1493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001494 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001495 Bugs: ProtocolBugs{
1496 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1497 },
1498 },
1499 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001500 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001501 },
1502 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001503 name: "AppDataAfterChangeCipherSpec-Empty",
1504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001505 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001506 Bugs: ProtocolBugs{
1507 AppDataAfterChangeCipherSpec: []byte{},
1508 },
1509 },
1510 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001511 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001512 },
1513 {
Adam Langley7c803a62015-06-15 15:35:05 -07001514 protocol: dtls,
1515 name: "AppDataAfterChangeCipherSpec-DTLS",
1516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001517 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001518 Bugs: ProtocolBugs{
1519 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1520 },
1521 },
1522 // BoringSSL's DTLS implementation will drop the out-of-order
1523 // application data.
1524 },
1525 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001526 protocol: dtls,
1527 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001529 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001530 Bugs: ProtocolBugs{
1531 AppDataAfterChangeCipherSpec: []byte{},
1532 },
1533 },
1534 // BoringSSL's DTLS implementation will drop the out-of-order
1535 // application data.
1536 },
1537 {
Adam Langley7c803a62015-06-15 15:35:05 -07001538 name: "AlertAfterChangeCipherSpec",
1539 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001540 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001541 Bugs: ProtocolBugs{
1542 AlertAfterChangeCipherSpec: alertRecordOverflow,
1543 },
1544 },
1545 shouldFail: true,
1546 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1547 },
1548 {
1549 protocol: dtls,
1550 name: "AlertAfterChangeCipherSpec-DTLS",
1551 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001552 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001553 Bugs: ProtocolBugs{
1554 AlertAfterChangeCipherSpec: alertRecordOverflow,
1555 },
1556 },
1557 shouldFail: true,
1558 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1559 },
1560 {
1561 protocol: dtls,
1562 name: "ReorderHandshakeFragments-Small-DTLS",
1563 config: Config{
1564 Bugs: ProtocolBugs{
1565 ReorderHandshakeFragments: true,
1566 // Small enough that every handshake message is
1567 // fragmented.
1568 MaxHandshakeRecordLength: 2,
1569 },
1570 },
1571 },
1572 {
1573 protocol: dtls,
1574 name: "ReorderHandshakeFragments-Large-DTLS",
1575 config: Config{
1576 Bugs: ProtocolBugs{
1577 ReorderHandshakeFragments: true,
1578 // Large enough that no handshake message is
1579 // fragmented.
1580 MaxHandshakeRecordLength: 2048,
1581 },
1582 },
1583 },
1584 {
1585 protocol: dtls,
1586 name: "MixCompleteMessageWithFragments-DTLS",
1587 config: Config{
1588 Bugs: ProtocolBugs{
1589 ReorderHandshakeFragments: true,
1590 MixCompleteMessageWithFragments: true,
1591 MaxHandshakeRecordLength: 2,
1592 },
1593 },
1594 },
1595 {
1596 name: "SendInvalidRecordType",
1597 config: Config{
1598 Bugs: ProtocolBugs{
1599 SendInvalidRecordType: true,
1600 },
1601 },
1602 shouldFail: true,
1603 expectedError: ":UNEXPECTED_RECORD:",
1604 },
1605 {
1606 protocol: dtls,
1607 name: "SendInvalidRecordType-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 SendInvalidRecordType: true,
1611 },
1612 },
1613 shouldFail: true,
1614 expectedError: ":UNEXPECTED_RECORD:",
1615 },
1616 {
1617 name: "FalseStart-SkipServerSecondLeg",
1618 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001619 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001620 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1621 NextProtos: []string{"foo"},
1622 Bugs: ProtocolBugs{
1623 SkipNewSessionTicket: true,
1624 SkipChangeCipherSpec: true,
1625 SkipFinished: true,
1626 ExpectFalseStart: true,
1627 },
1628 },
1629 flags: []string{
1630 "-false-start",
1631 "-handshake-never-done",
1632 "-advertise-alpn", "\x03foo",
1633 },
1634 shimWritesFirst: true,
1635 shouldFail: true,
1636 expectedError: ":UNEXPECTED_RECORD:",
1637 },
1638 {
1639 name: "FalseStart-SkipServerSecondLeg-Implicit",
1640 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001641 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001642 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1643 NextProtos: []string{"foo"},
1644 Bugs: ProtocolBugs{
1645 SkipNewSessionTicket: true,
1646 SkipChangeCipherSpec: true,
1647 SkipFinished: true,
1648 },
1649 },
1650 flags: []string{
1651 "-implicit-handshake",
1652 "-false-start",
1653 "-handshake-never-done",
1654 "-advertise-alpn", "\x03foo",
1655 },
1656 shouldFail: true,
1657 expectedError: ":UNEXPECTED_RECORD:",
1658 },
1659 {
1660 testType: serverTest,
1661 name: "FailEarlyCallback",
1662 flags: []string{"-fail-early-callback"},
1663 shouldFail: true,
1664 expectedError: ":CONNECTION_REJECTED:",
1665 expectedLocalError: "remote error: access denied",
1666 },
1667 {
Adam Langley7c803a62015-06-15 15:35:05 -07001668 protocol: dtls,
1669 name: "FragmentMessageTypeMismatch-DTLS",
1670 config: Config{
1671 Bugs: ProtocolBugs{
1672 MaxHandshakeRecordLength: 2,
1673 FragmentMessageTypeMismatch: true,
1674 },
1675 },
1676 shouldFail: true,
1677 expectedError: ":FRAGMENT_MISMATCH:",
1678 },
1679 {
1680 protocol: dtls,
1681 name: "FragmentMessageLengthMismatch-DTLS",
1682 config: Config{
1683 Bugs: ProtocolBugs{
1684 MaxHandshakeRecordLength: 2,
1685 FragmentMessageLengthMismatch: true,
1686 },
1687 },
1688 shouldFail: true,
1689 expectedError: ":FRAGMENT_MISMATCH:",
1690 },
1691 {
1692 protocol: dtls,
1693 name: "SplitFragments-Header-DTLS",
1694 config: Config{
1695 Bugs: ProtocolBugs{
1696 SplitFragments: 2,
1697 },
1698 },
1699 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001700 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
1703 protocol: dtls,
1704 name: "SplitFragments-Boundary-DTLS",
1705 config: Config{
1706 Bugs: ProtocolBugs{
1707 SplitFragments: dtlsRecordHeaderLen,
1708 },
1709 },
1710 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001711 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001712 },
1713 {
1714 protocol: dtls,
1715 name: "SplitFragments-Body-DTLS",
1716 config: Config{
1717 Bugs: ProtocolBugs{
1718 SplitFragments: dtlsRecordHeaderLen + 1,
1719 },
1720 },
1721 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001722 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001723 },
1724 {
1725 protocol: dtls,
1726 name: "SendEmptyFragments-DTLS",
1727 config: Config{
1728 Bugs: ProtocolBugs{
1729 SendEmptyFragments: true,
1730 },
1731 },
1732 },
1733 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001734 name: "BadFinished-Client",
1735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001736 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001737 Bugs: ProtocolBugs{
1738 BadFinished: true,
1739 },
1740 },
1741 shouldFail: true,
1742 expectedError: ":DIGEST_CHECK_FAILED:",
1743 },
1744 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001745 name: "BadFinished-Client-TLS13",
1746 config: Config{
1747 MaxVersion: VersionTLS13,
1748 Bugs: ProtocolBugs{
1749 BadFinished: true,
1750 },
1751 },
1752 shouldFail: true,
1753 expectedError: ":DIGEST_CHECK_FAILED:",
1754 },
1755 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001756 testType: serverTest,
1757 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001758 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001759 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001760 Bugs: ProtocolBugs{
1761 BadFinished: true,
1762 },
1763 },
1764 shouldFail: true,
1765 expectedError: ":DIGEST_CHECK_FAILED:",
1766 },
1767 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001768 testType: serverTest,
1769 name: "BadFinished-Server-TLS13",
1770 config: Config{
1771 MaxVersion: VersionTLS13,
1772 Bugs: ProtocolBugs{
1773 BadFinished: true,
1774 },
1775 },
1776 shouldFail: true,
1777 expectedError: ":DIGEST_CHECK_FAILED:",
1778 },
1779 {
Adam Langley7c803a62015-06-15 15:35:05 -07001780 name: "FalseStart-BadFinished",
1781 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001782 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1784 NextProtos: []string{"foo"},
1785 Bugs: ProtocolBugs{
1786 BadFinished: true,
1787 ExpectFalseStart: true,
1788 },
1789 },
1790 flags: []string{
1791 "-false-start",
1792 "-handshake-never-done",
1793 "-advertise-alpn", "\x03foo",
1794 },
1795 shimWritesFirst: true,
1796 shouldFail: true,
1797 expectedError: ":DIGEST_CHECK_FAILED:",
1798 },
1799 {
1800 name: "NoFalseStart-NoALPN",
1801 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001802 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1804 Bugs: ProtocolBugs{
1805 ExpectFalseStart: true,
1806 AlertBeforeFalseStartTest: alertAccessDenied,
1807 },
1808 },
1809 flags: []string{
1810 "-false-start",
1811 },
1812 shimWritesFirst: true,
1813 shouldFail: true,
1814 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1815 expectedLocalError: "tls: peer did not false start: EOF",
1816 },
1817 {
1818 name: "NoFalseStart-NoAEAD",
1819 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001820 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1822 NextProtos: []string{"foo"},
1823 Bugs: ProtocolBugs{
1824 ExpectFalseStart: true,
1825 AlertBeforeFalseStartTest: alertAccessDenied,
1826 },
1827 },
1828 flags: []string{
1829 "-false-start",
1830 "-advertise-alpn", "\x03foo",
1831 },
1832 shimWritesFirst: true,
1833 shouldFail: true,
1834 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1835 expectedLocalError: "tls: peer did not false start: EOF",
1836 },
1837 {
1838 name: "NoFalseStart-RSA",
1839 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001840 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001841 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1842 NextProtos: []string{"foo"},
1843 Bugs: ProtocolBugs{
1844 ExpectFalseStart: true,
1845 AlertBeforeFalseStartTest: alertAccessDenied,
1846 },
1847 },
1848 flags: []string{
1849 "-false-start",
1850 "-advertise-alpn", "\x03foo",
1851 },
1852 shimWritesFirst: true,
1853 shouldFail: true,
1854 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1855 expectedLocalError: "tls: peer did not false start: EOF",
1856 },
1857 {
1858 name: "NoFalseStart-DHE_RSA",
1859 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001860 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001861 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1862 NextProtos: []string{"foo"},
1863 Bugs: ProtocolBugs{
1864 ExpectFalseStart: true,
1865 AlertBeforeFalseStartTest: alertAccessDenied,
1866 },
1867 },
1868 flags: []string{
1869 "-false-start",
1870 "-advertise-alpn", "\x03foo",
1871 },
1872 shimWritesFirst: true,
1873 shouldFail: true,
1874 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1875 expectedLocalError: "tls: peer did not false start: EOF",
1876 },
1877 {
Adam Langley7c803a62015-06-15 15:35:05 -07001878 protocol: dtls,
1879 name: "SendSplitAlert-Sync",
1880 config: Config{
1881 Bugs: ProtocolBugs{
1882 SendSplitAlert: true,
1883 },
1884 },
1885 },
1886 {
1887 protocol: dtls,
1888 name: "SendSplitAlert-Async",
1889 config: Config{
1890 Bugs: ProtocolBugs{
1891 SendSplitAlert: true,
1892 },
1893 },
1894 flags: []string{"-async"},
1895 },
1896 {
1897 protocol: dtls,
1898 name: "PackDTLSHandshake",
1899 config: Config{
1900 Bugs: ProtocolBugs{
1901 MaxHandshakeRecordLength: 2,
1902 PackHandshakeFragments: 20,
1903 PackHandshakeRecords: 200,
1904 },
1905 },
1906 },
1907 {
Adam Langley7c803a62015-06-15 15:35:05 -07001908 name: "SendEmptyRecords-Pass",
1909 sendEmptyRecords: 32,
1910 },
1911 {
1912 name: "SendEmptyRecords",
1913 sendEmptyRecords: 33,
1914 shouldFail: true,
1915 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1916 },
1917 {
1918 name: "SendEmptyRecords-Async",
1919 sendEmptyRecords: 33,
1920 flags: []string{"-async"},
1921 shouldFail: true,
1922 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1923 },
1924 {
1925 name: "SendWarningAlerts-Pass",
1926 sendWarningAlerts: 4,
1927 },
1928 {
1929 protocol: dtls,
1930 name: "SendWarningAlerts-DTLS-Pass",
1931 sendWarningAlerts: 4,
1932 },
1933 {
1934 name: "SendWarningAlerts",
1935 sendWarningAlerts: 5,
1936 shouldFail: true,
1937 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1938 },
1939 {
1940 name: "SendWarningAlerts-Async",
1941 sendWarningAlerts: 5,
1942 flags: []string{"-async"},
1943 shouldFail: true,
1944 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1945 },
David Benjaminba4594a2015-06-18 18:36:15 -04001946 {
1947 name: "EmptySessionID",
1948 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001949 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001950 SessionTicketsDisabled: true,
1951 },
1952 noSessionCache: true,
1953 flags: []string{"-expect-no-session"},
1954 },
David Benjamin30789da2015-08-29 22:56:45 -04001955 {
1956 name: "Unclean-Shutdown",
1957 config: Config{
1958 Bugs: ProtocolBugs{
1959 NoCloseNotify: true,
1960 ExpectCloseNotify: true,
1961 },
1962 },
1963 shimShutsDown: true,
1964 flags: []string{"-check-close-notify"},
1965 shouldFail: true,
1966 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1967 },
1968 {
1969 name: "Unclean-Shutdown-Ignored",
1970 config: Config{
1971 Bugs: ProtocolBugs{
1972 NoCloseNotify: true,
1973 },
1974 },
1975 shimShutsDown: true,
1976 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001977 {
David Benjaminfa214e42016-05-10 17:03:10 -04001978 name: "Unclean-Shutdown-Alert",
1979 config: Config{
1980 Bugs: ProtocolBugs{
1981 SendAlertOnShutdown: alertDecompressionFailure,
1982 ExpectCloseNotify: true,
1983 },
1984 },
1985 shimShutsDown: true,
1986 flags: []string{"-check-close-notify"},
1987 shouldFail: true,
1988 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1989 },
1990 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001991 name: "LargePlaintext",
1992 config: Config{
1993 Bugs: ProtocolBugs{
1994 SendLargeRecords: true,
1995 },
1996 },
1997 messageLen: maxPlaintext + 1,
1998 shouldFail: true,
1999 expectedError: ":DATA_LENGTH_TOO_LONG:",
2000 },
2001 {
2002 protocol: dtls,
2003 name: "LargePlaintext-DTLS",
2004 config: Config{
2005 Bugs: ProtocolBugs{
2006 SendLargeRecords: true,
2007 },
2008 },
2009 messageLen: maxPlaintext + 1,
2010 shouldFail: true,
2011 expectedError: ":DATA_LENGTH_TOO_LONG:",
2012 },
2013 {
2014 name: "LargeCiphertext",
2015 config: Config{
2016 Bugs: ProtocolBugs{
2017 SendLargeRecords: true,
2018 },
2019 },
2020 messageLen: maxPlaintext * 2,
2021 shouldFail: true,
2022 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2023 },
2024 {
2025 protocol: dtls,
2026 name: "LargeCiphertext-DTLS",
2027 config: Config{
2028 Bugs: ProtocolBugs{
2029 SendLargeRecords: true,
2030 },
2031 },
2032 messageLen: maxPlaintext * 2,
2033 // Unlike the other four cases, DTLS drops records which
2034 // are invalid before authentication, so the connection
2035 // does not fail.
2036 expectMessageDropped: true,
2037 },
David Benjamindd6fed92015-10-23 17:41:12 -04002038 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002039 // In TLS 1.2 and below, empty NewSessionTicket messages
2040 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002041 name: "SendEmptySessionTicket",
2042 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002043 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002044 Bugs: ProtocolBugs{
2045 SendEmptySessionTicket: true,
2046 FailIfSessionOffered: true,
2047 },
2048 },
2049 flags: []string{"-expect-no-session"},
2050 resumeSession: true,
2051 expectResumeRejected: true,
2052 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002053 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002054 name: "BadHelloRequest-1",
2055 renegotiate: 1,
2056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002057 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002058 Bugs: ProtocolBugs{
2059 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2060 },
2061 },
2062 flags: []string{
2063 "-renegotiate-freely",
2064 "-expect-total-renegotiations", "1",
2065 },
2066 shouldFail: true,
2067 expectedError: ":BAD_HELLO_REQUEST:",
2068 },
2069 {
2070 name: "BadHelloRequest-2",
2071 renegotiate: 1,
2072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002073 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002074 Bugs: ProtocolBugs{
2075 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2076 },
2077 },
2078 flags: []string{
2079 "-renegotiate-freely",
2080 "-expect-total-renegotiations", "1",
2081 },
2082 shouldFail: true,
2083 expectedError: ":BAD_HELLO_REQUEST:",
2084 },
David Benjaminef1b0092015-11-21 14:05:44 -05002085 {
2086 testType: serverTest,
2087 name: "SupportTicketsWithSessionID",
2088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002089 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002090 SessionTicketsDisabled: true,
2091 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002092 resumeConfig: &Config{
2093 MaxVersion: VersionTLS12,
2094 },
David Benjaminef1b0092015-11-21 14:05:44 -05002095 resumeSession: true,
2096 },
David Benjamin02edcd02016-07-27 17:40:37 -04002097 {
2098 protocol: dtls,
2099 name: "DTLS-SendExtraFinished",
2100 config: Config{
2101 Bugs: ProtocolBugs{
2102 SendExtraFinished: true,
2103 },
2104 },
2105 shouldFail: true,
2106 expectedError: ":UNEXPECTED_RECORD:",
2107 },
2108 {
2109 protocol: dtls,
2110 name: "DTLS-SendExtraFinished-Reordered",
2111 config: Config{
2112 Bugs: ProtocolBugs{
2113 MaxHandshakeRecordLength: 2,
2114 ReorderHandshakeFragments: true,
2115 SendExtraFinished: true,
2116 },
2117 },
2118 shouldFail: true,
2119 expectedError: ":UNEXPECTED_RECORD:",
2120 },
Adam Langley7c803a62015-06-15 15:35:05 -07002121 }
Adam Langley7c803a62015-06-15 15:35:05 -07002122 testCases = append(testCases, basicTests...)
2123}
2124
Adam Langley95c29f32014-06-20 12:00:00 -07002125func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002126 const bogusCipher = 0xfe00
2127
Adam Langley95c29f32014-06-20 12:00:00 -07002128 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002129 const psk = "12345"
2130 const pskIdentity = "luggage combo"
2131
Adam Langley95c29f32014-06-20 12:00:00 -07002132 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002133 var certFile string
2134 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002135 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002136 cert = ecdsaP256Certificate
2137 certFile = ecdsaP256CertificateFile
2138 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002139 } else {
David Benjamin33863262016-07-08 17:20:12 -07002140 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002141 certFile = rsaCertificateFile
2142 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002143 }
2144
David Benjamin48cae082014-10-27 01:06:24 -04002145 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002146 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002147 flags = append(flags,
2148 "-psk", psk,
2149 "-psk-identity", pskIdentity)
2150 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002151 if hasComponent(suite.name, "NULL") {
2152 // NULL ciphers must be explicitly enabled.
2153 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2154 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002155 if hasComponent(suite.name, "CECPQ1") {
2156 // CECPQ1 ciphers must be explicitly enabled.
2157 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2158 }
David Benjamin48cae082014-10-27 01:06:24 -04002159
Adam Langley95c29f32014-06-20 12:00:00 -07002160 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002161 for _, protocol := range []protocol{tls, dtls} {
2162 var prefix string
2163 if protocol == dtls {
2164 if !ver.hasDTLS {
2165 continue
2166 }
2167 prefix = "D"
2168 }
Adam Langley95c29f32014-06-20 12:00:00 -07002169
David Benjamin0407e762016-06-17 16:41:18 -04002170 var shouldServerFail, shouldClientFail bool
2171 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2172 // BoringSSL clients accept ECDHE on SSLv3, but
2173 // a BoringSSL server will never select it
2174 // because the extension is missing.
2175 shouldServerFail = true
2176 }
2177 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2178 shouldClientFail = true
2179 shouldServerFail = true
2180 }
David Benjamin54c217c2016-07-13 12:35:25 -04002181 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002182 shouldClientFail = true
2183 shouldServerFail = true
2184 }
David Benjamin0407e762016-06-17 16:41:18 -04002185 if !isDTLSCipher(suite.name) && protocol == dtls {
2186 shouldClientFail = true
2187 shouldServerFail = true
2188 }
David Benjamin4298d772015-12-19 00:18:25 -05002189
David Benjamin0407e762016-06-17 16:41:18 -04002190 var expectedServerError, expectedClientError string
2191 if shouldServerFail {
2192 expectedServerError = ":NO_SHARED_CIPHER:"
2193 }
2194 if shouldClientFail {
2195 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2196 }
David Benjamin025b3d32014-07-01 19:53:04 -04002197
David Benjamin9deb1172016-07-13 17:13:49 -04002198 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2199 resumeSession := ver.version < VersionTLS13
2200
David Benjamin6fd297b2014-08-11 18:43:38 -04002201 testCases = append(testCases, testCase{
2202 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002203 protocol: protocol,
2204
2205 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002206 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002207 MinVersion: ver.version,
2208 MaxVersion: ver.version,
2209 CipherSuites: []uint16{suite.id},
2210 Certificates: []Certificate{cert},
2211 PreSharedKey: []byte(psk),
2212 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002213 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002214 EnableAllCiphers: shouldServerFail,
2215 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002216 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002217 },
2218 certFile: certFile,
2219 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002220 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002221 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002222 shouldFail: shouldServerFail,
2223 expectedError: expectedServerError,
2224 })
2225
2226 testCases = append(testCases, testCase{
2227 testType: clientTest,
2228 protocol: protocol,
2229 name: prefix + ver.name + "-" + suite.name + "-client",
2230 config: Config{
2231 MinVersion: ver.version,
2232 MaxVersion: ver.version,
2233 CipherSuites: []uint16{suite.id},
2234 Certificates: []Certificate{cert},
2235 PreSharedKey: []byte(psk),
2236 PreSharedKeyIdentity: pskIdentity,
2237 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002238 EnableAllCiphers: shouldClientFail,
2239 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002240 },
2241 },
2242 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002243 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002244 shouldFail: shouldClientFail,
2245 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002246 })
David Benjamin2c99d282015-09-01 10:23:00 -04002247
Nick Harper1fd39d82016-06-14 18:14:35 -07002248 if !shouldClientFail {
2249 // Ensure the maximum record size is accepted.
2250 testCases = append(testCases, testCase{
2251 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2252 config: Config{
2253 MinVersion: ver.version,
2254 MaxVersion: ver.version,
2255 CipherSuites: []uint16{suite.id},
2256 Certificates: []Certificate{cert},
2257 PreSharedKey: []byte(psk),
2258 PreSharedKeyIdentity: pskIdentity,
2259 },
2260 flags: flags,
2261 messageLen: maxPlaintext,
2262 })
2263 }
2264 }
David Benjamin2c99d282015-09-01 10:23:00 -04002265 }
Adam Langley95c29f32014-06-20 12:00:00 -07002266 }
Adam Langleya7997f12015-05-14 17:38:50 -07002267
2268 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002269 name: "NoSharedCipher",
2270 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002271 MaxVersion: VersionTLS12,
2272 CipherSuites: []uint16{},
2273 },
2274 shouldFail: true,
2275 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2276 })
2277
2278 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002279 name: "NoSharedCipher-TLS13",
2280 config: Config{
2281 MaxVersion: VersionTLS13,
2282 CipherSuites: []uint16{},
2283 },
2284 shouldFail: true,
2285 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2286 })
2287
2288 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002289 name: "UnsupportedCipherSuite",
2290 config: Config{
2291 MaxVersion: VersionTLS12,
2292 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2293 Bugs: ProtocolBugs{
2294 IgnorePeerCipherPreferences: true,
2295 },
2296 },
2297 flags: []string{"-cipher", "DEFAULT:!RC4"},
2298 shouldFail: true,
2299 expectedError: ":WRONG_CIPHER_RETURNED:",
2300 })
2301
2302 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002303 name: "ServerHelloBogusCipher",
2304 config: Config{
2305 MaxVersion: VersionTLS12,
2306 Bugs: ProtocolBugs{
2307 SendCipherSuite: bogusCipher,
2308 },
2309 },
2310 shouldFail: true,
2311 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2312 })
2313 testCases = append(testCases, testCase{
2314 name: "ServerHelloBogusCipher-TLS13",
2315 config: Config{
2316 MaxVersion: VersionTLS13,
2317 Bugs: ProtocolBugs{
2318 SendCipherSuite: bogusCipher,
2319 },
2320 },
2321 shouldFail: true,
2322 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2323 })
2324
2325 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002326 name: "WeakDH",
2327 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002328 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002329 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2330 Bugs: ProtocolBugs{
2331 // This is a 1023-bit prime number, generated
2332 // with:
2333 // openssl gendh 1023 | openssl asn1parse -i
2334 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2335 },
2336 },
2337 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002338 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002339 })
Adam Langleycef75832015-09-03 14:51:12 -07002340
David Benjamincd24a392015-11-11 13:23:05 -08002341 testCases = append(testCases, testCase{
2342 name: "SillyDH",
2343 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002344 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002345 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2346 Bugs: ProtocolBugs{
2347 // This is a 4097-bit prime number, generated
2348 // with:
2349 // openssl gendh 4097 | openssl asn1parse -i
2350 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2351 },
2352 },
2353 shouldFail: true,
2354 expectedError: ":DH_P_TOO_LONG:",
2355 })
2356
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002357 // This test ensures that Diffie-Hellman public values are padded with
2358 // zeros so that they're the same length as the prime. This is to avoid
2359 // hitting a bug in yaSSL.
2360 testCases = append(testCases, testCase{
2361 testType: serverTest,
2362 name: "DHPublicValuePadded",
2363 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002364 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002365 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2366 Bugs: ProtocolBugs{
2367 RequireDHPublicValueLen: (1025 + 7) / 8,
2368 },
2369 },
2370 flags: []string{"-use-sparse-dh-prime"},
2371 })
David Benjamincd24a392015-11-11 13:23:05 -08002372
David Benjamin241ae832016-01-15 03:04:54 -05002373 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002374 testCases = append(testCases, testCase{
2375 testType: serverTest,
2376 name: "UnknownCipher",
2377 config: Config{
2378 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2379 },
2380 })
2381
Adam Langleycef75832015-09-03 14:51:12 -07002382 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2383 // 1.1 specific cipher suite settings. A server is setup with the given
2384 // cipher lists and then a connection is made for each member of
2385 // expectations. The cipher suite that the server selects must match
2386 // the specified one.
2387 var versionSpecificCiphersTest = []struct {
2388 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2389 // expectations is a map from TLS version to cipher suite id.
2390 expectations map[uint16]uint16
2391 }{
2392 {
2393 // Test that the null case (where no version-specific ciphers are set)
2394 // works as expected.
2395 "RC4-SHA:AES128-SHA", // default ciphers
2396 "", // no ciphers specifically for TLS ≥ 1.0
2397 "", // no ciphers specifically for TLS ≥ 1.1
2398 map[uint16]uint16{
2399 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2400 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2401 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2402 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2403 },
2404 },
2405 {
2406 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2407 // cipher.
2408 "RC4-SHA:AES128-SHA", // default
2409 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2410 "", // no ciphers specifically for TLS ≥ 1.1
2411 map[uint16]uint16{
2412 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2413 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2414 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2415 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2416 },
2417 },
2418 {
2419 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2420 // cipher.
2421 "RC4-SHA:AES128-SHA", // default
2422 "", // no ciphers specifically for TLS ≥ 1.0
2423 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2424 map[uint16]uint16{
2425 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2426 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2427 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2428 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2429 },
2430 },
2431 {
2432 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2433 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2434 "RC4-SHA:AES128-SHA", // default
2435 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2436 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2437 map[uint16]uint16{
2438 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2439 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2440 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2441 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2442 },
2443 },
2444 }
2445
2446 for i, test := range versionSpecificCiphersTest {
2447 for version, expectedCipherSuite := range test.expectations {
2448 flags := []string{"-cipher", test.ciphersDefault}
2449 if len(test.ciphersTLS10) > 0 {
2450 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2451 }
2452 if len(test.ciphersTLS11) > 0 {
2453 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2454 }
2455
2456 testCases = append(testCases, testCase{
2457 testType: serverTest,
2458 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2459 config: Config{
2460 MaxVersion: version,
2461 MinVersion: version,
2462 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2463 },
2464 flags: flags,
2465 expectedCipher: expectedCipherSuite,
2466 })
2467 }
2468 }
Adam Langley95c29f32014-06-20 12:00:00 -07002469}
2470
2471func addBadECDSASignatureTests() {
2472 for badR := BadValue(1); badR < NumBadValues; badR++ {
2473 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002474 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002475 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2476 config: Config{
2477 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002478 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002479 Bugs: ProtocolBugs{
2480 BadECDSAR: badR,
2481 BadECDSAS: badS,
2482 },
2483 },
2484 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002485 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002486 })
2487 }
2488 }
2489}
2490
Adam Langley80842bd2014-06-20 12:00:00 -07002491func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002492 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002493 name: "MaxCBCPadding",
2494 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002495 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002496 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2497 Bugs: ProtocolBugs{
2498 MaxPadding: true,
2499 },
2500 },
2501 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2502 })
David Benjamin025b3d32014-07-01 19:53:04 -04002503 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002504 name: "BadCBCPadding",
2505 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002506 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002507 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2508 Bugs: ProtocolBugs{
2509 PaddingFirstByteBad: true,
2510 },
2511 },
2512 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002513 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002514 })
2515 // OpenSSL previously had an issue where the first byte of padding in
2516 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002517 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002518 name: "BadCBCPadding255",
2519 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002520 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002521 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2522 Bugs: ProtocolBugs{
2523 MaxPadding: true,
2524 PaddingFirstByteBadIf255: true,
2525 },
2526 },
2527 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2528 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002529 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002530 })
2531}
2532
Kenny Root7fdeaf12014-08-05 15:23:37 -07002533func addCBCSplittingTests() {
2534 testCases = append(testCases, testCase{
2535 name: "CBCRecordSplitting",
2536 config: Config{
2537 MaxVersion: VersionTLS10,
2538 MinVersion: VersionTLS10,
2539 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2540 },
David Benjaminac8302a2015-09-01 17:18:15 -04002541 messageLen: -1, // read until EOF
2542 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002543 flags: []string{
2544 "-async",
2545 "-write-different-record-sizes",
2546 "-cbc-record-splitting",
2547 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002548 })
2549 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002550 name: "CBCRecordSplittingPartialWrite",
2551 config: Config{
2552 MaxVersion: VersionTLS10,
2553 MinVersion: VersionTLS10,
2554 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2555 },
2556 messageLen: -1, // read until EOF
2557 flags: []string{
2558 "-async",
2559 "-write-different-record-sizes",
2560 "-cbc-record-splitting",
2561 "-partial-write",
2562 },
2563 })
2564}
2565
David Benjamin636293b2014-07-08 17:59:18 -04002566func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002567 // Add a dummy cert pool to stress certificate authority parsing.
2568 // TODO(davidben): Add tests that those values parse out correctly.
2569 certPool := x509.NewCertPool()
2570 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2571 if err != nil {
2572 panic(err)
2573 }
2574 certPool.AddCert(cert)
2575
David Benjamin636293b2014-07-08 17:59:18 -04002576 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002577 testCases = append(testCases, testCase{
2578 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002579 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002580 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002581 MinVersion: ver.version,
2582 MaxVersion: ver.version,
2583 ClientAuth: RequireAnyClientCert,
2584 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002585 },
2586 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002587 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2588 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002589 },
2590 })
2591 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002592 testType: serverTest,
2593 name: ver.name + "-Server-ClientAuth-RSA",
2594 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002595 MinVersion: ver.version,
2596 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002597 Certificates: []Certificate{rsaCertificate},
2598 },
2599 flags: []string{"-require-any-client-certificate"},
2600 })
David Benjamine098ec22014-08-27 23:13:20 -04002601 if ver.version != VersionSSL30 {
2602 testCases = append(testCases, testCase{
2603 testType: serverTest,
2604 name: ver.name + "-Server-ClientAuth-ECDSA",
2605 config: Config{
2606 MinVersion: ver.version,
2607 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002608 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002609 },
2610 flags: []string{"-require-any-client-certificate"},
2611 })
2612 testCases = append(testCases, testCase{
2613 testType: clientTest,
2614 name: ver.name + "-Client-ClientAuth-ECDSA",
2615 config: Config{
2616 MinVersion: ver.version,
2617 MaxVersion: ver.version,
2618 ClientAuth: RequireAnyClientCert,
2619 ClientCAs: certPool,
2620 },
2621 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002622 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2623 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002624 },
2625 })
2626 }
David Benjamin636293b2014-07-08 17:59:18 -04002627 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002628
2629 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002630 name: "NoClientCertificate",
2631 config: Config{
2632 MaxVersion: VersionTLS12,
2633 ClientAuth: RequireAnyClientCert,
2634 },
2635 shouldFail: true,
2636 expectedLocalError: "client didn't provide a certificate",
2637 })
2638
2639 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002640 name: "NoClientCertificate-TLS13",
2641 config: Config{
2642 MaxVersion: VersionTLS13,
2643 ClientAuth: RequireAnyClientCert,
2644 },
2645 shouldFail: true,
2646 expectedLocalError: "client didn't provide a certificate",
2647 })
2648
2649 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002650 testType: serverTest,
2651 name: "RequireAnyClientCertificate",
2652 config: Config{
2653 MaxVersion: VersionTLS12,
2654 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002655 flags: []string{"-require-any-client-certificate"},
2656 shouldFail: true,
2657 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2658 })
2659
2660 testCases = append(testCases, testCase{
2661 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002662 name: "RequireAnyClientCertificate-TLS13",
2663 config: Config{
2664 MaxVersion: VersionTLS13,
2665 },
2666 flags: []string{"-require-any-client-certificate"},
2667 shouldFail: true,
2668 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2669 })
2670
2671 testCases = append(testCases, testCase{
2672 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002673 name: "RequireAnyClientCertificate-SSL3",
2674 config: Config{
2675 MaxVersion: VersionSSL30,
2676 },
2677 flags: []string{"-require-any-client-certificate"},
2678 shouldFail: true,
2679 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2680 })
2681
2682 testCases = append(testCases, testCase{
2683 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002684 name: "SkipClientCertificate",
2685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002686 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002687 Bugs: ProtocolBugs{
2688 SkipClientCertificate: true,
2689 },
2690 },
2691 // Setting SSL_VERIFY_PEER allows anonymous clients.
2692 flags: []string{"-verify-peer"},
2693 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002694 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002695 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002696
Steven Valdez143e8b32016-07-11 13:19:03 -04002697 testCases = append(testCases, testCase{
2698 testType: serverTest,
2699 name: "SkipClientCertificate-TLS13",
2700 config: Config{
2701 MaxVersion: VersionTLS13,
2702 Bugs: ProtocolBugs{
2703 SkipClientCertificate: true,
2704 },
2705 },
2706 // Setting SSL_VERIFY_PEER allows anonymous clients.
2707 flags: []string{"-verify-peer"},
2708 shouldFail: true,
2709 expectedError: ":UNEXPECTED_MESSAGE:",
2710 })
2711
David Benjaminc032dfa2016-05-12 14:54:57 -04002712 // Client auth is only legal in certificate-based ciphers.
2713 testCases = append(testCases, testCase{
2714 testType: clientTest,
2715 name: "ClientAuth-PSK",
2716 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002717 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002718 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2719 PreSharedKey: []byte("secret"),
2720 ClientAuth: RequireAnyClientCert,
2721 },
2722 flags: []string{
2723 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2724 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2725 "-psk", "secret",
2726 },
2727 shouldFail: true,
2728 expectedError: ":UNEXPECTED_MESSAGE:",
2729 })
2730 testCases = append(testCases, testCase{
2731 testType: clientTest,
2732 name: "ClientAuth-ECDHE_PSK",
2733 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002734 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002735 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2736 PreSharedKey: []byte("secret"),
2737 ClientAuth: RequireAnyClientCert,
2738 },
2739 flags: []string{
2740 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2741 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2742 "-psk", "secret",
2743 },
2744 shouldFail: true,
2745 expectedError: ":UNEXPECTED_MESSAGE:",
2746 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002747
2748 // Regression test for a bug where the client CA list, if explicitly
2749 // set to NULL, was mis-encoded.
2750 testCases = append(testCases, testCase{
2751 testType: serverTest,
2752 name: "Null-Client-CA-List",
2753 config: Config{
2754 MaxVersion: VersionTLS12,
2755 Certificates: []Certificate{rsaCertificate},
2756 },
2757 flags: []string{
2758 "-require-any-client-certificate",
2759 "-use-null-client-ca-list",
2760 },
2761 })
David Benjamin636293b2014-07-08 17:59:18 -04002762}
2763
Adam Langley75712922014-10-10 16:23:43 -07002764func addExtendedMasterSecretTests() {
2765 const expectEMSFlag = "-expect-extended-master-secret"
2766
2767 for _, with := range []bool{false, true} {
2768 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002769 if with {
2770 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002771 }
2772
2773 for _, isClient := range []bool{false, true} {
2774 suffix := "-Server"
2775 testType := serverTest
2776 if isClient {
2777 suffix = "-Client"
2778 testType = clientTest
2779 }
2780
2781 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002782 // In TLS 1.3, the extension is irrelevant and
2783 // always reports as enabled.
2784 var flags []string
2785 if with || ver.version >= VersionTLS13 {
2786 flags = []string{expectEMSFlag}
2787 }
2788
Adam Langley75712922014-10-10 16:23:43 -07002789 test := testCase{
2790 testType: testType,
2791 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2792 config: Config{
2793 MinVersion: ver.version,
2794 MaxVersion: ver.version,
2795 Bugs: ProtocolBugs{
2796 NoExtendedMasterSecret: !with,
2797 RequireExtendedMasterSecret: with,
2798 },
2799 },
David Benjamin48cae082014-10-27 01:06:24 -04002800 flags: flags,
2801 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002802 }
2803 if test.shouldFail {
2804 test.expectedLocalError = "extended master secret required but not supported by peer"
2805 }
2806 testCases = append(testCases, test)
2807 }
2808 }
2809 }
2810
Adam Langleyba5934b2015-06-02 10:50:35 -07002811 for _, isClient := range []bool{false, true} {
2812 for _, supportedInFirstConnection := range []bool{false, true} {
2813 for _, supportedInResumeConnection := range []bool{false, true} {
2814 boolToWord := func(b bool) string {
2815 if b {
2816 return "Yes"
2817 }
2818 return "No"
2819 }
2820 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2821 if isClient {
2822 suffix += "Client"
2823 } else {
2824 suffix += "Server"
2825 }
2826
2827 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002828 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002829 Bugs: ProtocolBugs{
2830 RequireExtendedMasterSecret: true,
2831 },
2832 }
2833
2834 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002835 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002836 Bugs: ProtocolBugs{
2837 NoExtendedMasterSecret: true,
2838 },
2839 }
2840
2841 test := testCase{
2842 name: "ExtendedMasterSecret-" + suffix,
2843 resumeSession: true,
2844 }
2845
2846 if !isClient {
2847 test.testType = serverTest
2848 }
2849
2850 if supportedInFirstConnection {
2851 test.config = supportedConfig
2852 } else {
2853 test.config = noSupportConfig
2854 }
2855
2856 if supportedInResumeConnection {
2857 test.resumeConfig = &supportedConfig
2858 } else {
2859 test.resumeConfig = &noSupportConfig
2860 }
2861
2862 switch suffix {
2863 case "YesToYes-Client", "YesToYes-Server":
2864 // When a session is resumed, it should
2865 // still be aware that its master
2866 // secret was generated via EMS and
2867 // thus it's safe to use tls-unique.
2868 test.flags = []string{expectEMSFlag}
2869 case "NoToYes-Server":
2870 // If an original connection did not
2871 // contain EMS, but a resumption
2872 // handshake does, then a server should
2873 // not resume the session.
2874 test.expectResumeRejected = true
2875 case "YesToNo-Server":
2876 // Resuming an EMS session without the
2877 // EMS extension should cause the
2878 // server to abort the connection.
2879 test.shouldFail = true
2880 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2881 case "NoToYes-Client":
2882 // A client should abort a connection
2883 // where the server resumed a non-EMS
2884 // session but echoed the EMS
2885 // extension.
2886 test.shouldFail = true
2887 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2888 case "YesToNo-Client":
2889 // A client should abort a connection
2890 // where the server didn't echo EMS
2891 // when the session used it.
2892 test.shouldFail = true
2893 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2894 }
2895
2896 testCases = append(testCases, test)
2897 }
2898 }
2899 }
Adam Langley75712922014-10-10 16:23:43 -07002900}
2901
David Benjamin582ba042016-07-07 12:33:25 -07002902type stateMachineTestConfig struct {
2903 protocol protocol
2904 async bool
2905 splitHandshake, packHandshakeFlight bool
2906}
2907
David Benjamin43ec06f2014-08-05 02:28:57 -04002908// Adds tests that try to cover the range of the handshake state machine, under
2909// various conditions. Some of these are redundant with other tests, but they
2910// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002911func addAllStateMachineCoverageTests() {
2912 for _, async := range []bool{false, true} {
2913 for _, protocol := range []protocol{tls, dtls} {
2914 addStateMachineCoverageTests(stateMachineTestConfig{
2915 protocol: protocol,
2916 async: async,
2917 })
2918 addStateMachineCoverageTests(stateMachineTestConfig{
2919 protocol: protocol,
2920 async: async,
2921 splitHandshake: true,
2922 })
2923 if protocol == tls {
2924 addStateMachineCoverageTests(stateMachineTestConfig{
2925 protocol: protocol,
2926 async: async,
2927 packHandshakeFlight: true,
2928 })
2929 }
2930 }
2931 }
2932}
2933
2934func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002935 var tests []testCase
2936
2937 // Basic handshake, with resumption. Client and server,
2938 // session ID and session ticket.
2939 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002940 name: "Basic-Client",
2941 config: Config{
2942 MaxVersion: VersionTLS12,
2943 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002944 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002945 // Ensure session tickets are used, not session IDs.
2946 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002947 })
2948 tests = append(tests, testCase{
2949 name: "Basic-Client-RenewTicket",
2950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002951 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002952 Bugs: ProtocolBugs{
2953 RenewTicketOnResume: true,
2954 },
2955 },
David Benjaminba4594a2015-06-18 18:36:15 -04002956 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002957 resumeSession: true,
2958 })
2959 tests = append(tests, testCase{
2960 name: "Basic-Client-NoTicket",
2961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002962 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002963 SessionTicketsDisabled: true,
2964 },
2965 resumeSession: true,
2966 })
2967 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002968 name: "Basic-Client-Implicit",
2969 config: Config{
2970 MaxVersion: VersionTLS12,
2971 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002972 flags: []string{"-implicit-handshake"},
2973 resumeSession: true,
2974 })
2975 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002976 testType: serverTest,
2977 name: "Basic-Server",
2978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002979 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002980 Bugs: ProtocolBugs{
2981 RequireSessionTickets: true,
2982 },
2983 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002984 resumeSession: true,
2985 })
2986 tests = append(tests, testCase{
2987 testType: serverTest,
2988 name: "Basic-Server-NoTickets",
2989 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002990 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002991 SessionTicketsDisabled: true,
2992 },
2993 resumeSession: true,
2994 })
2995 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002996 testType: serverTest,
2997 name: "Basic-Server-Implicit",
2998 config: Config{
2999 MaxVersion: VersionTLS12,
3000 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003001 flags: []string{"-implicit-handshake"},
3002 resumeSession: true,
3003 })
3004 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003005 testType: serverTest,
3006 name: "Basic-Server-EarlyCallback",
3007 config: Config{
3008 MaxVersion: VersionTLS12,
3009 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003010 flags: []string{"-use-early-callback"},
3011 resumeSession: true,
3012 })
3013
Steven Valdez143e8b32016-07-11 13:19:03 -04003014 // TLS 1.3 basic handshake shapes.
3015 tests = append(tests, testCase{
3016 name: "TLS13-1RTT-Client",
3017 config: Config{
3018 MaxVersion: VersionTLS13,
3019 },
3020 })
3021 tests = append(tests, testCase{
3022 testType: serverTest,
3023 name: "TLS13-1RTT-Server",
3024 config: Config{
3025 MaxVersion: VersionTLS13,
3026 },
3027 })
3028
David Benjamin760b1dd2015-05-15 23:33:48 -04003029 // TLS client auth.
3030 tests = append(tests, testCase{
3031 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003032 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003034 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003035 ClientAuth: RequestClientCert,
3036 },
3037 })
3038 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003039 testType: serverTest,
3040 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003041 config: Config{
3042 MaxVersion: VersionTLS12,
3043 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003044 // Setting SSL_VERIFY_PEER allows anonymous clients.
3045 flags: []string{"-verify-peer"},
3046 })
David Benjamin582ba042016-07-07 12:33:25 -07003047 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003048 tests = append(tests, testCase{
3049 testType: clientTest,
3050 name: "ClientAuth-NoCertificate-Client-SSL3",
3051 config: Config{
3052 MaxVersion: VersionSSL30,
3053 ClientAuth: RequestClientCert,
3054 },
3055 })
3056 tests = append(tests, testCase{
3057 testType: serverTest,
3058 name: "ClientAuth-NoCertificate-Server-SSL3",
3059 config: Config{
3060 MaxVersion: VersionSSL30,
3061 },
3062 // Setting SSL_VERIFY_PEER allows anonymous clients.
3063 flags: []string{"-verify-peer"},
3064 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003065 tests = append(tests, testCase{
3066 testType: clientTest,
3067 name: "ClientAuth-NoCertificate-Client-TLS13",
3068 config: Config{
3069 MaxVersion: VersionTLS13,
3070 ClientAuth: RequestClientCert,
3071 },
3072 })
3073 tests = append(tests, testCase{
3074 testType: serverTest,
3075 name: "ClientAuth-NoCertificate-Server-TLS13",
3076 config: Config{
3077 MaxVersion: VersionTLS13,
3078 },
3079 // Setting SSL_VERIFY_PEER allows anonymous clients.
3080 flags: []string{"-verify-peer"},
3081 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003082 }
3083 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003084 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003085 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003087 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003088 ClientAuth: RequireAnyClientCert,
3089 },
3090 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003093 },
3094 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003095 tests = append(tests, testCase{
3096 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003097 name: "ClientAuth-RSA-Client-TLS13",
3098 config: Config{
3099 MaxVersion: VersionTLS13,
3100 ClientAuth: RequireAnyClientCert,
3101 },
3102 flags: []string{
3103 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3104 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3105 },
3106 })
3107 tests = append(tests, testCase{
3108 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003109 name: "ClientAuth-ECDSA-Client",
3110 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003111 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003112 ClientAuth: RequireAnyClientCert,
3113 },
3114 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003115 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3116 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003117 },
3118 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003119 tests = append(tests, testCase{
3120 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003121 name: "ClientAuth-ECDSA-Client-TLS13",
3122 config: Config{
3123 MaxVersion: VersionTLS13,
3124 ClientAuth: RequireAnyClientCert,
3125 },
3126 flags: []string{
3127 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3128 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3129 },
3130 })
3131 tests = append(tests, testCase{
3132 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003133 name: "ClientAuth-NoCertificate-OldCallback",
3134 config: Config{
3135 MaxVersion: VersionTLS12,
3136 ClientAuth: RequestClientCert,
3137 },
3138 flags: []string{"-use-old-client-cert-callback"},
3139 })
3140 tests = append(tests, testCase{
3141 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003142 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3143 config: Config{
3144 MaxVersion: VersionTLS13,
3145 ClientAuth: RequestClientCert,
3146 },
3147 flags: []string{"-use-old-client-cert-callback"},
3148 })
3149 tests = append(tests, testCase{
3150 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003151 name: "ClientAuth-OldCallback",
3152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003153 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003154 ClientAuth: RequireAnyClientCert,
3155 },
3156 flags: []string{
3157 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3158 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3159 "-use-old-client-cert-callback",
3160 },
3161 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003162 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003163 testType: clientTest,
3164 name: "ClientAuth-OldCallback-TLS13",
3165 config: Config{
3166 MaxVersion: VersionTLS13,
3167 ClientAuth: RequireAnyClientCert,
3168 },
3169 flags: []string{
3170 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3171 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3172 "-use-old-client-cert-callback",
3173 },
3174 })
3175 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003176 testType: serverTest,
3177 name: "ClientAuth-Server",
3178 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003179 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003180 Certificates: []Certificate{rsaCertificate},
3181 },
3182 flags: []string{"-require-any-client-certificate"},
3183 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003184 tests = append(tests, testCase{
3185 testType: serverTest,
3186 name: "ClientAuth-Server-TLS13",
3187 config: Config{
3188 MaxVersion: VersionTLS13,
3189 Certificates: []Certificate{rsaCertificate},
3190 },
3191 flags: []string{"-require-any-client-certificate"},
3192 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003193
David Benjamin4c3ddf72016-06-29 18:13:53 -04003194 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003195 tests = append(tests, testCase{
3196 testType: serverTest,
3197 name: "Basic-Server-RSA",
3198 config: Config{
3199 MaxVersion: VersionTLS12,
3200 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3201 },
3202 flags: []string{
3203 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3204 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3205 },
3206 })
3207 tests = append(tests, testCase{
3208 testType: serverTest,
3209 name: "Basic-Server-ECDHE-RSA",
3210 config: Config{
3211 MaxVersion: VersionTLS12,
3212 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3213 },
3214 flags: []string{
3215 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3216 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3217 },
3218 })
3219 tests = append(tests, testCase{
3220 testType: serverTest,
3221 name: "Basic-Server-ECDHE-ECDSA",
3222 config: Config{
3223 MaxVersion: VersionTLS12,
3224 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3225 },
3226 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003227 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3228 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003229 },
3230 })
3231
David Benjamin760b1dd2015-05-15 23:33:48 -04003232 // No session ticket support; server doesn't send NewSessionTicket.
3233 tests = append(tests, testCase{
3234 name: "SessionTicketsDisabled-Client",
3235 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003236 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003237 SessionTicketsDisabled: true,
3238 },
3239 })
3240 tests = append(tests, testCase{
3241 testType: serverTest,
3242 name: "SessionTicketsDisabled-Server",
3243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003244 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003245 SessionTicketsDisabled: true,
3246 },
3247 })
3248
3249 // Skip ServerKeyExchange in PSK key exchange if there's no
3250 // identity hint.
3251 tests = append(tests, testCase{
3252 name: "EmptyPSKHint-Client",
3253 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003254 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003255 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3256 PreSharedKey: []byte("secret"),
3257 },
3258 flags: []string{"-psk", "secret"},
3259 })
3260 tests = append(tests, testCase{
3261 testType: serverTest,
3262 name: "EmptyPSKHint-Server",
3263 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003264 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003265 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3266 PreSharedKey: []byte("secret"),
3267 },
3268 flags: []string{"-psk", "secret"},
3269 })
3270
David Benjamin4c3ddf72016-06-29 18:13:53 -04003271 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003272 tests = append(tests, testCase{
3273 testType: clientTest,
3274 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003275 config: Config{
3276 MaxVersion: VersionTLS12,
3277 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003278 flags: []string{
3279 "-enable-ocsp-stapling",
3280 "-expect-ocsp-response",
3281 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003282 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003283 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003284 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003285 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003286 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003287 testType: serverTest,
3288 name: "OCSPStapling-Server",
3289 config: Config{
3290 MaxVersion: VersionTLS12,
3291 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003292 expectedOCSPResponse: testOCSPResponse,
3293 flags: []string{
3294 "-ocsp-response",
3295 base64.StdEncoding.EncodeToString(testOCSPResponse),
3296 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003297 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003298 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003299 tests = append(tests, testCase{
3300 testType: clientTest,
3301 name: "OCSPStapling-Client-TLS13",
3302 config: Config{
3303 MaxVersion: VersionTLS13,
3304 },
3305 flags: []string{
3306 "-enable-ocsp-stapling",
3307 "-expect-ocsp-response",
3308 base64.StdEncoding.EncodeToString(testOCSPResponse),
3309 "-verify-peer",
3310 },
3311 // TODO(davidben): Enable this when resumption is implemented
3312 // in TLS 1.3.
3313 resumeSession: false,
3314 })
3315 tests = append(tests, testCase{
3316 testType: serverTest,
3317 name: "OCSPStapling-Server-TLS13",
3318 config: Config{
3319 MaxVersion: VersionTLS13,
3320 },
3321 expectedOCSPResponse: testOCSPResponse,
3322 flags: []string{
3323 "-ocsp-response",
3324 base64.StdEncoding.EncodeToString(testOCSPResponse),
3325 },
3326 // TODO(davidben): Enable this when resumption is implemented
3327 // in TLS 1.3.
3328 resumeSession: false,
3329 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003330
David Benjamin4c3ddf72016-06-29 18:13:53 -04003331 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003332 for _, vers := range tlsVersions {
3333 if config.protocol == dtls && !vers.hasDTLS {
3334 continue
3335 }
3336 tests = append(tests, testCase{
3337 testType: clientTest,
3338 name: "CertificateVerificationSucceed-" + vers.name,
3339 config: Config{
3340 MaxVersion: vers.version,
3341 },
3342 flags: []string{
3343 "-verify-peer",
3344 },
3345 })
3346 tests = append(tests, testCase{
3347 testType: clientTest,
3348 name: "CertificateVerificationFail-" + vers.name,
3349 config: Config{
3350 MaxVersion: vers.version,
3351 },
3352 flags: []string{
3353 "-verify-fail",
3354 "-verify-peer",
3355 },
3356 shouldFail: true,
3357 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3358 })
3359 tests = append(tests, testCase{
3360 testType: clientTest,
3361 name: "CertificateVerificationSoftFail-" + vers.name,
3362 config: Config{
3363 MaxVersion: vers.version,
3364 },
3365 flags: []string{
3366 "-verify-fail",
3367 "-expect-verify-result",
3368 },
3369 })
3370 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003371
David Benjamin1d4f4c02016-07-26 18:03:08 -04003372 tests = append(tests, testCase{
3373 name: "ShimSendAlert",
3374 flags: []string{"-send-alert"},
3375 shimWritesFirst: true,
3376 shouldFail: true,
3377 expectedLocalError: "remote error: decompression failure",
3378 })
3379
David Benjamin582ba042016-07-07 12:33:25 -07003380 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003381 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003382 name: "Renegotiate-Client",
3383 config: Config{
3384 MaxVersion: VersionTLS12,
3385 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003386 renegotiate: 1,
3387 flags: []string{
3388 "-renegotiate-freely",
3389 "-expect-total-renegotiations", "1",
3390 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003391 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003392
David Benjamin47921102016-07-28 11:29:18 -04003393 tests = append(tests, testCase{
3394 name: "SendHalfHelloRequest",
3395 config: Config{
3396 MaxVersion: VersionTLS12,
3397 Bugs: ProtocolBugs{
3398 PackHelloRequestWithFinished: config.packHandshakeFlight,
3399 },
3400 },
3401 sendHalfHelloRequest: true,
3402 flags: []string{"-renegotiate-ignore"},
3403 shouldFail: true,
3404 expectedError: ":UNEXPECTED_RECORD:",
3405 })
3406
David Benjamin760b1dd2015-05-15 23:33:48 -04003407 // NPN on client and server; results in post-handshake message.
3408 tests = append(tests, testCase{
3409 name: "NPN-Client",
3410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003412 NextProtos: []string{"foo"},
3413 },
3414 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003415 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003416 expectedNextProto: "foo",
3417 expectedNextProtoType: npn,
3418 })
3419 tests = append(tests, testCase{
3420 testType: serverTest,
3421 name: "NPN-Server",
3422 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003423 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003424 NextProtos: []string{"bar"},
3425 },
3426 flags: []string{
3427 "-advertise-npn", "\x03foo\x03bar\x03baz",
3428 "-expect-next-proto", "bar",
3429 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003430 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003431 expectedNextProto: "bar",
3432 expectedNextProtoType: npn,
3433 })
3434
3435 // TODO(davidben): Add tests for when False Start doesn't trigger.
3436
3437 // Client does False Start and negotiates NPN.
3438 tests = append(tests, testCase{
3439 name: "FalseStart",
3440 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003441 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003442 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3443 NextProtos: []string{"foo"},
3444 Bugs: ProtocolBugs{
3445 ExpectFalseStart: true,
3446 },
3447 },
3448 flags: []string{
3449 "-false-start",
3450 "-select-next-proto", "foo",
3451 },
3452 shimWritesFirst: true,
3453 resumeSession: true,
3454 })
3455
3456 // Client does False Start and negotiates ALPN.
3457 tests = append(tests, testCase{
3458 name: "FalseStart-ALPN",
3459 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003460 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003461 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3462 NextProtos: []string{"foo"},
3463 Bugs: ProtocolBugs{
3464 ExpectFalseStart: true,
3465 },
3466 },
3467 flags: []string{
3468 "-false-start",
3469 "-advertise-alpn", "\x03foo",
3470 },
3471 shimWritesFirst: true,
3472 resumeSession: true,
3473 })
3474
3475 // Client does False Start but doesn't explicitly call
3476 // SSL_connect.
3477 tests = append(tests, testCase{
3478 name: "FalseStart-Implicit",
3479 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003480 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003481 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3482 NextProtos: []string{"foo"},
3483 },
3484 flags: []string{
3485 "-implicit-handshake",
3486 "-false-start",
3487 "-advertise-alpn", "\x03foo",
3488 },
3489 })
3490
3491 // False Start without session tickets.
3492 tests = append(tests, testCase{
3493 name: "FalseStart-SessionTicketsDisabled",
3494 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003495 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003496 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3497 NextProtos: []string{"foo"},
3498 SessionTicketsDisabled: true,
3499 Bugs: ProtocolBugs{
3500 ExpectFalseStart: true,
3501 },
3502 },
3503 flags: []string{
3504 "-false-start",
3505 "-select-next-proto", "foo",
3506 },
3507 shimWritesFirst: true,
3508 })
3509
Adam Langleydf759b52016-07-11 15:24:37 -07003510 tests = append(tests, testCase{
3511 name: "FalseStart-CECPQ1",
3512 config: Config{
3513 MaxVersion: VersionTLS12,
3514 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3515 NextProtos: []string{"foo"},
3516 Bugs: ProtocolBugs{
3517 ExpectFalseStart: true,
3518 },
3519 },
3520 flags: []string{
3521 "-false-start",
3522 "-cipher", "DEFAULT:kCECPQ1",
3523 "-select-next-proto", "foo",
3524 },
3525 shimWritesFirst: true,
3526 resumeSession: true,
3527 })
3528
David Benjamin760b1dd2015-05-15 23:33:48 -04003529 // Server parses a V2ClientHello.
3530 tests = append(tests, testCase{
3531 testType: serverTest,
3532 name: "SendV2ClientHello",
3533 config: Config{
3534 // Choose a cipher suite that does not involve
3535 // elliptic curves, so no extensions are
3536 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003537 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003538 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3539 Bugs: ProtocolBugs{
3540 SendV2ClientHello: true,
3541 },
3542 },
3543 })
3544
3545 // Client sends a Channel ID.
3546 tests = append(tests, testCase{
3547 name: "ChannelID-Client",
3548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003549 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003550 RequestChannelID: true,
3551 },
Adam Langley7c803a62015-06-15 15:35:05 -07003552 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003553 resumeSession: true,
3554 expectChannelID: true,
3555 })
3556
3557 // Server accepts a Channel ID.
3558 tests = append(tests, testCase{
3559 testType: serverTest,
3560 name: "ChannelID-Server",
3561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003562 MaxVersion: VersionTLS12,
3563 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003564 },
3565 flags: []string{
3566 "-expect-channel-id",
3567 base64.StdEncoding.EncodeToString(channelIDBytes),
3568 },
3569 resumeSession: true,
3570 expectChannelID: true,
3571 })
David Benjamin30789da2015-08-29 22:56:45 -04003572
David Benjaminf8fcdf32016-06-08 15:56:13 -04003573 // Channel ID and NPN at the same time, to ensure their relative
3574 // ordering is correct.
3575 tests = append(tests, testCase{
3576 name: "ChannelID-NPN-Client",
3577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003579 RequestChannelID: true,
3580 NextProtos: []string{"foo"},
3581 },
3582 flags: []string{
3583 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3584 "-select-next-proto", "foo",
3585 },
3586 resumeSession: true,
3587 expectChannelID: true,
3588 expectedNextProto: "foo",
3589 expectedNextProtoType: npn,
3590 })
3591 tests = append(tests, testCase{
3592 testType: serverTest,
3593 name: "ChannelID-NPN-Server",
3594 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003595 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003596 ChannelID: channelIDKey,
3597 NextProtos: []string{"bar"},
3598 },
3599 flags: []string{
3600 "-expect-channel-id",
3601 base64.StdEncoding.EncodeToString(channelIDBytes),
3602 "-advertise-npn", "\x03foo\x03bar\x03baz",
3603 "-expect-next-proto", "bar",
3604 },
3605 resumeSession: true,
3606 expectChannelID: true,
3607 expectedNextProto: "bar",
3608 expectedNextProtoType: npn,
3609 })
3610
David Benjamin30789da2015-08-29 22:56:45 -04003611 // Bidirectional shutdown with the runner initiating.
3612 tests = append(tests, testCase{
3613 name: "Shutdown-Runner",
3614 config: Config{
3615 Bugs: ProtocolBugs{
3616 ExpectCloseNotify: true,
3617 },
3618 },
3619 flags: []string{"-check-close-notify"},
3620 })
3621
3622 // Bidirectional shutdown with the shim initiating. The runner,
3623 // in the meantime, sends garbage before the close_notify which
3624 // the shim must ignore.
3625 tests = append(tests, testCase{
3626 name: "Shutdown-Shim",
3627 config: Config{
3628 Bugs: ProtocolBugs{
3629 ExpectCloseNotify: true,
3630 },
3631 },
3632 shimShutsDown: true,
3633 sendEmptyRecords: 1,
3634 sendWarningAlerts: 1,
3635 flags: []string{"-check-close-notify"},
3636 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003637 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003638 // TODO(davidben): DTLS 1.3 will want a similar thing for
3639 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003640 tests = append(tests, testCase{
3641 name: "SkipHelloVerifyRequest",
3642 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003643 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003644 Bugs: ProtocolBugs{
3645 SkipHelloVerifyRequest: true,
3646 },
3647 },
3648 })
3649 }
3650
David Benjamin760b1dd2015-05-15 23:33:48 -04003651 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003652 test.protocol = config.protocol
3653 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003654 test.name += "-DTLS"
3655 }
David Benjamin582ba042016-07-07 12:33:25 -07003656 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003657 test.name += "-Async"
3658 test.flags = append(test.flags, "-async")
3659 } else {
3660 test.name += "-Sync"
3661 }
David Benjamin582ba042016-07-07 12:33:25 -07003662 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003663 test.name += "-SplitHandshakeRecords"
3664 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003665 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003666 test.config.Bugs.MaxPacketLength = 256
3667 test.flags = append(test.flags, "-mtu", "256")
3668 }
3669 }
David Benjamin582ba042016-07-07 12:33:25 -07003670 if config.packHandshakeFlight {
3671 test.name += "-PackHandshakeFlight"
3672 test.config.Bugs.PackHandshakeFlight = true
3673 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003674 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003675 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003676}
3677
Adam Langley524e7172015-02-20 16:04:00 -08003678func addDDoSCallbackTests() {
3679 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003680 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003681 for _, resume := range []bool{false, true} {
3682 suffix := "Resume"
3683 if resume {
3684 suffix = "No" + suffix
3685 }
3686
3687 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003688 testType: serverTest,
3689 name: "Server-DDoS-OK-" + suffix,
3690 config: Config{
3691 MaxVersion: VersionTLS12,
3692 },
Adam Langley524e7172015-02-20 16:04:00 -08003693 flags: []string{"-install-ddos-callback"},
3694 resumeSession: resume,
3695 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003696 if !resume {
3697 testCases = append(testCases, testCase{
3698 testType: serverTest,
3699 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3700 config: Config{
3701 MaxVersion: VersionTLS13,
3702 },
3703 flags: []string{"-install-ddos-callback"},
3704 resumeSession: resume,
3705 })
3706 }
Adam Langley524e7172015-02-20 16:04:00 -08003707
3708 failFlag := "-fail-ddos-callback"
3709 if resume {
3710 failFlag = "-fail-second-ddos-callback"
3711 }
3712 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003713 testType: serverTest,
3714 name: "Server-DDoS-Reject-" + suffix,
3715 config: Config{
3716 MaxVersion: VersionTLS12,
3717 },
Adam Langley524e7172015-02-20 16:04:00 -08003718 flags: []string{"-install-ddos-callback", failFlag},
3719 resumeSession: resume,
3720 shouldFail: true,
3721 expectedError: ":CONNECTION_REJECTED:",
3722 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003723 if !resume {
3724 testCases = append(testCases, testCase{
3725 testType: serverTest,
3726 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3727 config: Config{
3728 MaxVersion: VersionTLS13,
3729 },
3730 flags: []string{"-install-ddos-callback", failFlag},
3731 resumeSession: resume,
3732 shouldFail: true,
3733 expectedError: ":CONNECTION_REJECTED:",
3734 })
3735 }
Adam Langley524e7172015-02-20 16:04:00 -08003736 }
3737}
3738
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003739func addVersionNegotiationTests() {
3740 for i, shimVers := range tlsVersions {
3741 // Assemble flags to disable all newer versions on the shim.
3742 var flags []string
3743 for _, vers := range tlsVersions[i+1:] {
3744 flags = append(flags, vers.flag)
3745 }
3746
3747 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003748 protocols := []protocol{tls}
3749 if runnerVers.hasDTLS && shimVers.hasDTLS {
3750 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003751 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003752 for _, protocol := range protocols {
3753 expectedVersion := shimVers.version
3754 if runnerVers.version < shimVers.version {
3755 expectedVersion = runnerVers.version
3756 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003757
David Benjamin8b8c0062014-11-23 02:47:52 -05003758 suffix := shimVers.name + "-" + runnerVers.name
3759 if protocol == dtls {
3760 suffix += "-DTLS"
3761 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003762
David Benjamin1eb367c2014-12-12 18:17:51 -05003763 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3764
David Benjamin1e29a6b2014-12-10 02:27:24 -05003765 clientVers := shimVers.version
3766 if clientVers > VersionTLS10 {
3767 clientVers = VersionTLS10
3768 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003769 serverVers := expectedVersion
3770 if expectedVersion >= VersionTLS13 {
3771 serverVers = VersionTLS10
3772 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003773 testCases = append(testCases, testCase{
3774 protocol: protocol,
3775 testType: clientTest,
3776 name: "VersionNegotiation-Client-" + suffix,
3777 config: Config{
3778 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003779 Bugs: ProtocolBugs{
3780 ExpectInitialRecordVersion: clientVers,
3781 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003782 },
3783 flags: flags,
3784 expectedVersion: expectedVersion,
3785 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003786 testCases = append(testCases, testCase{
3787 protocol: protocol,
3788 testType: clientTest,
3789 name: "VersionNegotiation-Client2-" + suffix,
3790 config: Config{
3791 MaxVersion: runnerVers.version,
3792 Bugs: ProtocolBugs{
3793 ExpectInitialRecordVersion: clientVers,
3794 },
3795 },
3796 flags: []string{"-max-version", shimVersFlag},
3797 expectedVersion: expectedVersion,
3798 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003799
3800 testCases = append(testCases, testCase{
3801 protocol: protocol,
3802 testType: serverTest,
3803 name: "VersionNegotiation-Server-" + suffix,
3804 config: Config{
3805 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003806 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003807 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003808 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003809 },
3810 flags: flags,
3811 expectedVersion: expectedVersion,
3812 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003813 testCases = append(testCases, testCase{
3814 protocol: protocol,
3815 testType: serverTest,
3816 name: "VersionNegotiation-Server2-" + suffix,
3817 config: Config{
3818 MaxVersion: runnerVers.version,
3819 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003820 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003821 },
3822 },
3823 flags: []string{"-max-version", shimVersFlag},
3824 expectedVersion: expectedVersion,
3825 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003826 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003827 }
3828 }
David Benjamin95c69562016-06-29 18:15:03 -04003829
3830 // Test for version tolerance.
3831 testCases = append(testCases, testCase{
3832 testType: serverTest,
3833 name: "MinorVersionTolerance",
3834 config: Config{
3835 Bugs: ProtocolBugs{
3836 SendClientVersion: 0x03ff,
3837 },
3838 },
3839 expectedVersion: VersionTLS13,
3840 })
3841 testCases = append(testCases, testCase{
3842 testType: serverTest,
3843 name: "MajorVersionTolerance",
3844 config: Config{
3845 Bugs: ProtocolBugs{
3846 SendClientVersion: 0x0400,
3847 },
3848 },
3849 expectedVersion: VersionTLS13,
3850 })
3851 testCases = append(testCases, testCase{
3852 protocol: dtls,
3853 testType: serverTest,
3854 name: "MinorVersionTolerance-DTLS",
3855 config: Config{
3856 Bugs: ProtocolBugs{
3857 SendClientVersion: 0x03ff,
3858 },
3859 },
3860 expectedVersion: VersionTLS12,
3861 })
3862 testCases = append(testCases, testCase{
3863 protocol: dtls,
3864 testType: serverTest,
3865 name: "MajorVersionTolerance-DTLS",
3866 config: Config{
3867 Bugs: ProtocolBugs{
3868 SendClientVersion: 0x0400,
3869 },
3870 },
3871 expectedVersion: VersionTLS12,
3872 })
3873
3874 // Test that versions below 3.0 are rejected.
3875 testCases = append(testCases, testCase{
3876 testType: serverTest,
3877 name: "VersionTooLow",
3878 config: Config{
3879 Bugs: ProtocolBugs{
3880 SendClientVersion: 0x0200,
3881 },
3882 },
3883 shouldFail: true,
3884 expectedError: ":UNSUPPORTED_PROTOCOL:",
3885 })
3886 testCases = append(testCases, testCase{
3887 protocol: dtls,
3888 testType: serverTest,
3889 name: "VersionTooLow-DTLS",
3890 config: Config{
3891 Bugs: ProtocolBugs{
3892 // 0x0201 is the lowest version expressable in
3893 // DTLS.
3894 SendClientVersion: 0x0201,
3895 },
3896 },
3897 shouldFail: true,
3898 expectedError: ":UNSUPPORTED_PROTOCOL:",
3899 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04003900
3901 // Test TLS 1.3's downgrade signal.
3902 testCases = append(testCases, testCase{
3903 name: "Downgrade-TLS12-Client",
3904 config: Config{
3905 Bugs: ProtocolBugs{
3906 NegotiateVersion: VersionTLS12,
3907 },
3908 },
3909 shouldFail: true,
3910 expectedError: ":DOWNGRADE_DETECTED:",
3911 })
3912 testCases = append(testCases, testCase{
3913 testType: serverTest,
3914 name: "Downgrade-TLS12-Server",
3915 config: Config{
3916 Bugs: ProtocolBugs{
3917 SendClientVersion: VersionTLS12,
3918 },
3919 },
3920 shouldFail: true,
3921 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
3922 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02003923
3924 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
3925 // behave correctly when both real maximum and fallback versions are
3926 // set.
3927 testCases = append(testCases, testCase{
3928 name: "Downgrade-TLS12-Client-Fallback",
3929 config: Config{
3930 Bugs: ProtocolBugs{
3931 FailIfNotFallbackSCSV: true,
3932 },
3933 },
3934 flags: []string{
3935 "-max-version", strconv.Itoa(VersionTLS13),
3936 "-fallback-version", strconv.Itoa(VersionTLS12),
3937 },
3938 shouldFail: true,
3939 expectedError: ":DOWNGRADE_DETECTED:",
3940 })
3941 testCases = append(testCases, testCase{
3942 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
3943 flags: []string{
3944 "-max-version", strconv.Itoa(VersionTLS12),
3945 "-fallback-version", strconv.Itoa(VersionTLS12),
3946 },
3947 })
3948
3949 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
3950 // just have such connections fail than risk getting confused because we
3951 // didn't sent the 1.3 ClientHello.)
3952 testCases = append(testCases, testCase{
3953 name: "Downgrade-TLS12-Fallback-CheckVersion",
3954 config: Config{
3955 Bugs: ProtocolBugs{
3956 NegotiateVersion: VersionTLS13,
3957 FailIfNotFallbackSCSV: true,
3958 },
3959 },
3960 flags: []string{
3961 "-max-version", strconv.Itoa(VersionTLS13),
3962 "-fallback-version", strconv.Itoa(VersionTLS12),
3963 },
3964 shouldFail: true,
3965 expectedError: ":UNSUPPORTED_PROTOCOL:",
3966 })
3967
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003968}
3969
David Benjaminaccb4542014-12-12 23:44:33 -05003970func addMinimumVersionTests() {
3971 for i, shimVers := range tlsVersions {
3972 // Assemble flags to disable all older versions on the shim.
3973 var flags []string
3974 for _, vers := range tlsVersions[:i] {
3975 flags = append(flags, vers.flag)
3976 }
3977
3978 for _, runnerVers := range tlsVersions {
3979 protocols := []protocol{tls}
3980 if runnerVers.hasDTLS && shimVers.hasDTLS {
3981 protocols = append(protocols, dtls)
3982 }
3983 for _, protocol := range protocols {
3984 suffix := shimVers.name + "-" + runnerVers.name
3985 if protocol == dtls {
3986 suffix += "-DTLS"
3987 }
3988 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3989
David Benjaminaccb4542014-12-12 23:44:33 -05003990 var expectedVersion uint16
3991 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003992 var expectedClientError, expectedServerError string
3993 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003994 if runnerVers.version >= shimVers.version {
3995 expectedVersion = runnerVers.version
3996 } else {
3997 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003998 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3999 expectedServerLocalError = "remote error: protocol version not supported"
4000 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4001 // If the client's minimum version is TLS 1.3 and the runner's
4002 // maximum is below TLS 1.2, the runner will fail to select a
4003 // cipher before the shim rejects the selected version.
4004 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4005 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4006 } else {
4007 expectedClientError = expectedServerError
4008 expectedClientLocalError = expectedServerLocalError
4009 }
David Benjaminaccb4542014-12-12 23:44:33 -05004010 }
4011
4012 testCases = append(testCases, testCase{
4013 protocol: protocol,
4014 testType: clientTest,
4015 name: "MinimumVersion-Client-" + suffix,
4016 config: Config{
4017 MaxVersion: runnerVers.version,
4018 },
David Benjamin87909c02014-12-13 01:55:01 -05004019 flags: flags,
4020 expectedVersion: expectedVersion,
4021 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004022 expectedError: expectedClientError,
4023 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004024 })
4025 testCases = append(testCases, testCase{
4026 protocol: protocol,
4027 testType: clientTest,
4028 name: "MinimumVersion-Client2-" + suffix,
4029 config: Config{
4030 MaxVersion: runnerVers.version,
4031 },
David Benjamin87909c02014-12-13 01:55:01 -05004032 flags: []string{"-min-version", shimVersFlag},
4033 expectedVersion: expectedVersion,
4034 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004035 expectedError: expectedClientError,
4036 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004037 })
4038
4039 testCases = append(testCases, testCase{
4040 protocol: protocol,
4041 testType: serverTest,
4042 name: "MinimumVersion-Server-" + suffix,
4043 config: Config{
4044 MaxVersion: runnerVers.version,
4045 },
David Benjamin87909c02014-12-13 01:55:01 -05004046 flags: flags,
4047 expectedVersion: expectedVersion,
4048 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004049 expectedError: expectedServerError,
4050 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004051 })
4052 testCases = append(testCases, testCase{
4053 protocol: protocol,
4054 testType: serverTest,
4055 name: "MinimumVersion-Server2-" + suffix,
4056 config: Config{
4057 MaxVersion: runnerVers.version,
4058 },
David Benjamin87909c02014-12-13 01:55:01 -05004059 flags: []string{"-min-version", shimVersFlag},
4060 expectedVersion: expectedVersion,
4061 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004062 expectedError: expectedServerError,
4063 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004064 })
4065 }
4066 }
4067 }
4068}
4069
David Benjamine78bfde2014-09-06 12:45:15 -04004070func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004071 // TODO(davidben): Extensions, where applicable, all move their server
4072 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4073 // tests for both. Also test interaction with 0-RTT when implemented.
4074
David Benjamin97d17d92016-07-14 16:12:00 -04004075 // Repeat extensions tests all versions except SSL 3.0.
4076 for _, ver := range tlsVersions {
4077 if ver.version == VersionSSL30 {
4078 continue
4079 }
4080
4081 // TODO(davidben): Implement resumption in TLS 1.3.
4082 resumeSession := ver.version < VersionTLS13
4083
4084 // Test that duplicate extensions are rejected.
4085 testCases = append(testCases, testCase{
4086 testType: clientTest,
4087 name: "DuplicateExtensionClient-" + ver.name,
4088 config: Config{
4089 MaxVersion: ver.version,
4090 Bugs: ProtocolBugs{
4091 DuplicateExtension: true,
4092 },
David Benjamine78bfde2014-09-06 12:45:15 -04004093 },
David Benjamin97d17d92016-07-14 16:12:00 -04004094 shouldFail: true,
4095 expectedLocalError: "remote error: error decoding message",
4096 })
4097 testCases = append(testCases, testCase{
4098 testType: serverTest,
4099 name: "DuplicateExtensionServer-" + ver.name,
4100 config: Config{
4101 MaxVersion: ver.version,
4102 Bugs: ProtocolBugs{
4103 DuplicateExtension: true,
4104 },
David Benjamine78bfde2014-09-06 12:45:15 -04004105 },
David Benjamin97d17d92016-07-14 16:12:00 -04004106 shouldFail: true,
4107 expectedLocalError: "remote error: error decoding message",
4108 })
4109
4110 // Test SNI.
4111 testCases = append(testCases, testCase{
4112 testType: clientTest,
4113 name: "ServerNameExtensionClient-" + ver.name,
4114 config: Config{
4115 MaxVersion: ver.version,
4116 Bugs: ProtocolBugs{
4117 ExpectServerName: "example.com",
4118 },
David Benjamine78bfde2014-09-06 12:45:15 -04004119 },
David Benjamin97d17d92016-07-14 16:12:00 -04004120 flags: []string{"-host-name", "example.com"},
4121 })
4122 testCases = append(testCases, testCase{
4123 testType: clientTest,
4124 name: "ServerNameExtensionClientMismatch-" + ver.name,
4125 config: Config{
4126 MaxVersion: ver.version,
4127 Bugs: ProtocolBugs{
4128 ExpectServerName: "mismatch.com",
4129 },
David Benjamine78bfde2014-09-06 12:45:15 -04004130 },
David Benjamin97d17d92016-07-14 16:12:00 -04004131 flags: []string{"-host-name", "example.com"},
4132 shouldFail: true,
4133 expectedLocalError: "tls: unexpected server name",
4134 })
4135 testCases = append(testCases, testCase{
4136 testType: clientTest,
4137 name: "ServerNameExtensionClientMissing-" + ver.name,
4138 config: Config{
4139 MaxVersion: ver.version,
4140 Bugs: ProtocolBugs{
4141 ExpectServerName: "missing.com",
4142 },
David Benjamine78bfde2014-09-06 12:45:15 -04004143 },
David Benjamin97d17d92016-07-14 16:12:00 -04004144 shouldFail: true,
4145 expectedLocalError: "tls: unexpected server name",
4146 })
4147 testCases = append(testCases, testCase{
4148 testType: serverTest,
4149 name: "ServerNameExtensionServer-" + ver.name,
4150 config: Config{
4151 MaxVersion: ver.version,
4152 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004153 },
David Benjamin97d17d92016-07-14 16:12:00 -04004154 flags: []string{"-expect-server-name", "example.com"},
4155 resumeSession: resumeSession,
4156 })
4157
4158 // Test ALPN.
4159 testCases = append(testCases, testCase{
4160 testType: clientTest,
4161 name: "ALPNClient-" + ver.name,
4162 config: Config{
4163 MaxVersion: ver.version,
4164 NextProtos: []string{"foo"},
4165 },
4166 flags: []string{
4167 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4168 "-expect-alpn", "foo",
4169 },
4170 expectedNextProto: "foo",
4171 expectedNextProtoType: alpn,
4172 resumeSession: resumeSession,
4173 })
4174 testCases = append(testCases, testCase{
4175 testType: serverTest,
4176 name: "ALPNServer-" + ver.name,
4177 config: Config{
4178 MaxVersion: ver.version,
4179 NextProtos: []string{"foo", "bar", "baz"},
4180 },
4181 flags: []string{
4182 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4183 "-select-alpn", "foo",
4184 },
4185 expectedNextProto: "foo",
4186 expectedNextProtoType: alpn,
4187 resumeSession: resumeSession,
4188 })
4189 testCases = append(testCases, testCase{
4190 testType: serverTest,
4191 name: "ALPNServer-Decline-" + ver.name,
4192 config: Config{
4193 MaxVersion: ver.version,
4194 NextProtos: []string{"foo", "bar", "baz"},
4195 },
4196 flags: []string{"-decline-alpn"},
4197 expectNoNextProto: true,
4198 resumeSession: resumeSession,
4199 })
4200
4201 var emptyString string
4202 testCases = append(testCases, testCase{
4203 testType: clientTest,
4204 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4205 config: Config{
4206 MaxVersion: ver.version,
4207 NextProtos: []string{""},
4208 Bugs: ProtocolBugs{
4209 // A server returning an empty ALPN protocol
4210 // should be rejected.
4211 ALPNProtocol: &emptyString,
4212 },
4213 },
4214 flags: []string{
4215 "-advertise-alpn", "\x03foo",
4216 },
4217 shouldFail: true,
4218 expectedError: ":PARSE_TLSEXT:",
4219 })
4220 testCases = append(testCases, testCase{
4221 testType: serverTest,
4222 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4223 config: Config{
4224 MaxVersion: ver.version,
4225 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004226 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004227 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004228 },
David Benjamin97d17d92016-07-14 16:12:00 -04004229 flags: []string{
4230 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004231 },
David Benjamin97d17d92016-07-14 16:12:00 -04004232 shouldFail: true,
4233 expectedError: ":PARSE_TLSEXT:",
4234 })
4235
4236 // Test NPN and the interaction with ALPN.
4237 if ver.version < VersionTLS13 {
4238 // Test that the server prefers ALPN over NPN.
4239 testCases = append(testCases, testCase{
4240 testType: serverTest,
4241 name: "ALPNServer-Preferred-" + ver.name,
4242 config: Config{
4243 MaxVersion: ver.version,
4244 NextProtos: []string{"foo", "bar", "baz"},
4245 },
4246 flags: []string{
4247 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4248 "-select-alpn", "foo",
4249 "-advertise-npn", "\x03foo\x03bar\x03baz",
4250 },
4251 expectedNextProto: "foo",
4252 expectedNextProtoType: alpn,
4253 resumeSession: resumeSession,
4254 })
4255 testCases = append(testCases, testCase{
4256 testType: serverTest,
4257 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4258 config: Config{
4259 MaxVersion: ver.version,
4260 NextProtos: []string{"foo", "bar", "baz"},
4261 Bugs: ProtocolBugs{
4262 SwapNPNAndALPN: true,
4263 },
4264 },
4265 flags: []string{
4266 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4267 "-select-alpn", "foo",
4268 "-advertise-npn", "\x03foo\x03bar\x03baz",
4269 },
4270 expectedNextProto: "foo",
4271 expectedNextProtoType: alpn,
4272 resumeSession: resumeSession,
4273 })
4274
4275 // Test that negotiating both NPN and ALPN is forbidden.
4276 testCases = append(testCases, testCase{
4277 name: "NegotiateALPNAndNPN-" + ver.name,
4278 config: Config{
4279 MaxVersion: ver.version,
4280 NextProtos: []string{"foo", "bar", "baz"},
4281 Bugs: ProtocolBugs{
4282 NegotiateALPNAndNPN: true,
4283 },
4284 },
4285 flags: []string{
4286 "-advertise-alpn", "\x03foo",
4287 "-select-next-proto", "foo",
4288 },
4289 shouldFail: true,
4290 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4291 })
4292 testCases = append(testCases, testCase{
4293 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4294 config: Config{
4295 MaxVersion: ver.version,
4296 NextProtos: []string{"foo", "bar", "baz"},
4297 Bugs: ProtocolBugs{
4298 NegotiateALPNAndNPN: true,
4299 SwapNPNAndALPN: true,
4300 },
4301 },
4302 flags: []string{
4303 "-advertise-alpn", "\x03foo",
4304 "-select-next-proto", "foo",
4305 },
4306 shouldFail: true,
4307 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4308 })
4309
4310 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4311 testCases = append(testCases, testCase{
4312 name: "DisableNPN-" + ver.name,
4313 config: Config{
4314 MaxVersion: ver.version,
4315 NextProtos: []string{"foo"},
4316 },
4317 flags: []string{
4318 "-select-next-proto", "foo",
4319 "-disable-npn",
4320 },
4321 expectNoNextProto: true,
4322 })
4323 }
4324
4325 // Test ticket behavior.
4326 //
4327 // TODO(davidben): Add TLS 1.3 versions of these.
4328 if ver.version < VersionTLS13 {
4329 // Resume with a corrupt ticket.
4330 testCases = append(testCases, testCase{
4331 testType: serverTest,
4332 name: "CorruptTicket-" + ver.name,
4333 config: Config{
4334 MaxVersion: ver.version,
4335 Bugs: ProtocolBugs{
4336 CorruptTicket: true,
4337 },
4338 },
4339 resumeSession: true,
4340 expectResumeRejected: true,
4341 })
4342 // Test the ticket callback, with and without renewal.
4343 testCases = append(testCases, testCase{
4344 testType: serverTest,
4345 name: "TicketCallback-" + ver.name,
4346 config: Config{
4347 MaxVersion: ver.version,
4348 },
4349 resumeSession: true,
4350 flags: []string{"-use-ticket-callback"},
4351 })
4352 testCases = append(testCases, testCase{
4353 testType: serverTest,
4354 name: "TicketCallback-Renew-" + ver.name,
4355 config: Config{
4356 MaxVersion: ver.version,
4357 Bugs: ProtocolBugs{
4358 ExpectNewTicket: true,
4359 },
4360 },
4361 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4362 resumeSession: true,
4363 })
4364
4365 // Resume with an oversized session id.
4366 testCases = append(testCases, testCase{
4367 testType: serverTest,
4368 name: "OversizedSessionId-" + ver.name,
4369 config: Config{
4370 MaxVersion: ver.version,
4371 Bugs: ProtocolBugs{
4372 OversizedSessionId: true,
4373 },
4374 },
4375 resumeSession: true,
4376 shouldFail: true,
4377 expectedError: ":DECODE_ERROR:",
4378 })
4379 }
4380
4381 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4382 // are ignored.
4383 if ver.hasDTLS {
4384 testCases = append(testCases, testCase{
4385 protocol: dtls,
4386 name: "SRTP-Client-" + ver.name,
4387 config: Config{
4388 MaxVersion: ver.version,
4389 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4390 },
4391 flags: []string{
4392 "-srtp-profiles",
4393 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4394 },
4395 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4396 })
4397 testCases = append(testCases, testCase{
4398 protocol: dtls,
4399 testType: serverTest,
4400 name: "SRTP-Server-" + ver.name,
4401 config: Config{
4402 MaxVersion: ver.version,
4403 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4404 },
4405 flags: []string{
4406 "-srtp-profiles",
4407 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4408 },
4409 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4410 })
4411 // Test that the MKI is ignored.
4412 testCases = append(testCases, testCase{
4413 protocol: dtls,
4414 testType: serverTest,
4415 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4416 config: Config{
4417 MaxVersion: ver.version,
4418 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4419 Bugs: ProtocolBugs{
4420 SRTPMasterKeyIdentifer: "bogus",
4421 },
4422 },
4423 flags: []string{
4424 "-srtp-profiles",
4425 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4426 },
4427 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4428 })
4429 // Test that SRTP isn't negotiated on the server if there were
4430 // no matching profiles.
4431 testCases = append(testCases, testCase{
4432 protocol: dtls,
4433 testType: serverTest,
4434 name: "SRTP-Server-NoMatch-" + ver.name,
4435 config: Config{
4436 MaxVersion: ver.version,
4437 SRTPProtectionProfiles: []uint16{100, 101, 102},
4438 },
4439 flags: []string{
4440 "-srtp-profiles",
4441 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4442 },
4443 expectedSRTPProtectionProfile: 0,
4444 })
4445 // Test that the server returning an invalid SRTP profile is
4446 // flagged as an error by the client.
4447 testCases = append(testCases, testCase{
4448 protocol: dtls,
4449 name: "SRTP-Client-NoMatch-" + ver.name,
4450 config: Config{
4451 MaxVersion: ver.version,
4452 Bugs: ProtocolBugs{
4453 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4454 },
4455 },
4456 flags: []string{
4457 "-srtp-profiles",
4458 "SRTP_AES128_CM_SHA1_80",
4459 },
4460 shouldFail: true,
4461 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4462 })
4463 }
4464
4465 // Test SCT list.
4466 testCases = append(testCases, testCase{
4467 name: "SignedCertificateTimestampList-Client-" + ver.name,
4468 testType: clientTest,
4469 config: Config{
4470 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004471 },
David Benjamin97d17d92016-07-14 16:12:00 -04004472 flags: []string{
4473 "-enable-signed-cert-timestamps",
4474 "-expect-signed-cert-timestamps",
4475 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004476 },
David Benjamin97d17d92016-07-14 16:12:00 -04004477 resumeSession: resumeSession,
4478 })
4479 testCases = append(testCases, testCase{
4480 name: "SendSCTListOnResume-" + ver.name,
4481 config: Config{
4482 MaxVersion: ver.version,
4483 Bugs: ProtocolBugs{
4484 SendSCTListOnResume: []byte("bogus"),
4485 },
David Benjamind98452d2015-06-16 14:16:23 -04004486 },
David Benjamin97d17d92016-07-14 16:12:00 -04004487 flags: []string{
4488 "-enable-signed-cert-timestamps",
4489 "-expect-signed-cert-timestamps",
4490 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004491 },
David Benjamin97d17d92016-07-14 16:12:00 -04004492 resumeSession: resumeSession,
4493 })
4494 testCases = append(testCases, testCase{
4495 name: "SignedCertificateTimestampList-Server-" + ver.name,
4496 testType: serverTest,
4497 config: Config{
4498 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004499 },
David Benjamin97d17d92016-07-14 16:12:00 -04004500 flags: []string{
4501 "-signed-cert-timestamps",
4502 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004503 },
David Benjamin97d17d92016-07-14 16:12:00 -04004504 expectedSCTList: testSCTList,
4505 resumeSession: resumeSession,
4506 })
4507 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004508
Paul Lietar4fac72e2015-09-09 13:44:55 +01004509 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004510 testType: clientTest,
4511 name: "ClientHelloPadding",
4512 config: Config{
4513 Bugs: ProtocolBugs{
4514 RequireClientHelloSize: 512,
4515 },
4516 },
4517 // This hostname just needs to be long enough to push the
4518 // ClientHello into F5's danger zone between 256 and 511 bytes
4519 // long.
4520 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4521 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004522
4523 // Extensions should not function in SSL 3.0.
4524 testCases = append(testCases, testCase{
4525 testType: serverTest,
4526 name: "SSLv3Extensions-NoALPN",
4527 config: Config{
4528 MaxVersion: VersionSSL30,
4529 NextProtos: []string{"foo", "bar", "baz"},
4530 },
4531 flags: []string{
4532 "-select-alpn", "foo",
4533 },
4534 expectNoNextProto: true,
4535 })
4536
4537 // Test session tickets separately as they follow a different codepath.
4538 testCases = append(testCases, testCase{
4539 testType: serverTest,
4540 name: "SSLv3Extensions-NoTickets",
4541 config: Config{
4542 MaxVersion: VersionSSL30,
4543 Bugs: ProtocolBugs{
4544 // Historically, session tickets in SSL 3.0
4545 // failed in different ways depending on whether
4546 // the client supported renegotiation_info.
4547 NoRenegotiationInfo: true,
4548 },
4549 },
4550 resumeSession: true,
4551 })
4552 testCases = append(testCases, testCase{
4553 testType: serverTest,
4554 name: "SSLv3Extensions-NoTickets2",
4555 config: Config{
4556 MaxVersion: VersionSSL30,
4557 },
4558 resumeSession: true,
4559 })
4560
4561 // But SSL 3.0 does send and process renegotiation_info.
4562 testCases = append(testCases, testCase{
4563 testType: serverTest,
4564 name: "SSLv3Extensions-RenegotiationInfo",
4565 config: Config{
4566 MaxVersion: VersionSSL30,
4567 Bugs: ProtocolBugs{
4568 RequireRenegotiationInfo: true,
4569 },
4570 },
4571 })
4572 testCases = append(testCases, testCase{
4573 testType: serverTest,
4574 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4575 config: Config{
4576 MaxVersion: VersionSSL30,
4577 Bugs: ProtocolBugs{
4578 NoRenegotiationInfo: true,
4579 SendRenegotiationSCSV: true,
4580 RequireRenegotiationInfo: true,
4581 },
4582 },
4583 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004584
4585 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4586 // in ServerHello.
4587 testCases = append(testCases, testCase{
4588 name: "NPN-Forbidden-TLS13",
4589 config: Config{
4590 MaxVersion: VersionTLS13,
4591 NextProtos: []string{"foo"},
4592 Bugs: ProtocolBugs{
4593 NegotiateNPNAtAllVersions: true,
4594 },
4595 },
4596 flags: []string{"-select-next-proto", "foo"},
4597 shouldFail: true,
4598 expectedError: ":ERROR_PARSING_EXTENSION:",
4599 })
4600 testCases = append(testCases, testCase{
4601 name: "EMS-Forbidden-TLS13",
4602 config: Config{
4603 MaxVersion: VersionTLS13,
4604 Bugs: ProtocolBugs{
4605 NegotiateEMSAtAllVersions: true,
4606 },
4607 },
4608 shouldFail: true,
4609 expectedError: ":ERROR_PARSING_EXTENSION:",
4610 })
4611 testCases = append(testCases, testCase{
4612 name: "RenegotiationInfo-Forbidden-TLS13",
4613 config: Config{
4614 MaxVersion: VersionTLS13,
4615 Bugs: ProtocolBugs{
4616 NegotiateRenegotiationInfoAtAllVersions: true,
4617 },
4618 },
4619 shouldFail: true,
4620 expectedError: ":ERROR_PARSING_EXTENSION:",
4621 })
4622 testCases = append(testCases, testCase{
4623 name: "ChannelID-Forbidden-TLS13",
4624 config: Config{
4625 MaxVersion: VersionTLS13,
4626 RequestChannelID: true,
4627 Bugs: ProtocolBugs{
4628 NegotiateChannelIDAtAllVersions: true,
4629 },
4630 },
4631 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4632 shouldFail: true,
4633 expectedError: ":ERROR_PARSING_EXTENSION:",
4634 })
4635 testCases = append(testCases, testCase{
4636 name: "Ticket-Forbidden-TLS13",
4637 config: Config{
4638 MaxVersion: VersionTLS12,
4639 },
4640 resumeConfig: &Config{
4641 MaxVersion: VersionTLS13,
4642 Bugs: ProtocolBugs{
4643 AdvertiseTicketExtension: true,
4644 },
4645 },
4646 resumeSession: true,
4647 shouldFail: true,
4648 expectedError: ":ERROR_PARSING_EXTENSION:",
4649 })
4650
4651 // Test that illegal extensions in TLS 1.3 are declined by the server if
4652 // offered in ClientHello. The runner's server will fail if this occurs,
4653 // so we exercise the offering path. (EMS and Renegotiation Info are
4654 // implicit in every test.)
4655 testCases = append(testCases, testCase{
4656 testType: serverTest,
4657 name: "ChannelID-Declined-TLS13",
4658 config: Config{
4659 MaxVersion: VersionTLS13,
4660 ChannelID: channelIDKey,
4661 },
4662 flags: []string{"-enable-channel-id"},
4663 })
4664 testCases = append(testCases, testCase{
4665 testType: serverTest,
4666 name: "NPN-Server",
4667 config: Config{
4668 MaxVersion: VersionTLS13,
4669 NextProtos: []string{"bar"},
4670 },
4671 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4672 })
David Benjamine78bfde2014-09-06 12:45:15 -04004673}
4674
David Benjamin01fe8202014-09-24 15:21:44 -04004675func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004676 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004677 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4678 if sessionVers.version >= VersionTLS13 {
4679 continue
4680 }
David Benjamin01fe8202014-09-24 15:21:44 -04004681 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004682 if resumeVers.version >= VersionTLS13 {
4683 continue
4684 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004685 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4686 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4687 // TLS 1.3 only shares ciphers with TLS 1.2, so
4688 // we skip certain combinations and use a
4689 // different cipher to test with.
4690 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4691 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4692 continue
4693 }
4694 }
4695
David Benjamin8b8c0062014-11-23 02:47:52 -05004696 protocols := []protocol{tls}
4697 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4698 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004699 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004700 for _, protocol := range protocols {
4701 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4702 if protocol == dtls {
4703 suffix += "-DTLS"
4704 }
4705
David Benjaminece3de92015-03-16 18:02:20 -04004706 if sessionVers.version == resumeVers.version {
4707 testCases = append(testCases, testCase{
4708 protocol: protocol,
4709 name: "Resume-Client" + suffix,
4710 resumeSession: true,
4711 config: Config{
4712 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004713 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004714 },
David Benjaminece3de92015-03-16 18:02:20 -04004715 expectedVersion: sessionVers.version,
4716 expectedResumeVersion: resumeVers.version,
4717 })
4718 } else {
4719 testCases = append(testCases, testCase{
4720 protocol: protocol,
4721 name: "Resume-Client-Mismatch" + suffix,
4722 resumeSession: true,
4723 config: Config{
4724 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004725 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004726 },
David Benjaminece3de92015-03-16 18:02:20 -04004727 expectedVersion: sessionVers.version,
4728 resumeConfig: &Config{
4729 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004730 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004731 Bugs: ProtocolBugs{
4732 AllowSessionVersionMismatch: true,
4733 },
4734 },
4735 expectedResumeVersion: resumeVers.version,
4736 shouldFail: true,
4737 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4738 })
4739 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004740
4741 testCases = append(testCases, testCase{
4742 protocol: protocol,
4743 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004744 resumeSession: true,
4745 config: Config{
4746 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004747 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004748 },
4749 expectedVersion: sessionVers.version,
4750 resumeConfig: &Config{
4751 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004752 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004753 },
4754 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004755 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004756 expectedResumeVersion: resumeVers.version,
4757 })
4758
David Benjamin8b8c0062014-11-23 02:47:52 -05004759 testCases = append(testCases, testCase{
4760 protocol: protocol,
4761 testType: serverTest,
4762 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004763 resumeSession: true,
4764 config: Config{
4765 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004766 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004767 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004768 expectedVersion: sessionVers.version,
4769 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004770 resumeConfig: &Config{
4771 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004772 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004773 },
4774 expectedResumeVersion: resumeVers.version,
4775 })
4776 }
David Benjamin01fe8202014-09-24 15:21:44 -04004777 }
4778 }
David Benjaminece3de92015-03-16 18:02:20 -04004779
Nick Harper1fd39d82016-06-14 18:14:35 -07004780 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004781 testCases = append(testCases, testCase{
4782 name: "Resume-Client-CipherMismatch",
4783 resumeSession: true,
4784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004785 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004786 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4787 },
4788 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004789 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004790 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4791 Bugs: ProtocolBugs{
4792 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4793 },
4794 },
4795 shouldFail: true,
4796 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4797 })
David Benjamin01fe8202014-09-24 15:21:44 -04004798}
4799
Adam Langley2ae77d22014-10-28 17:29:33 -07004800func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004801 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004802 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004803 testType: serverTest,
4804 name: "Renegotiate-Server-Forbidden",
4805 config: Config{
4806 MaxVersion: VersionTLS12,
4807 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004808 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004809 shouldFail: true,
4810 expectedError: ":NO_RENEGOTIATION:",
4811 expectedLocalError: "remote error: no renegotiation",
4812 })
Adam Langley5021b222015-06-12 18:27:58 -07004813 // The server shouldn't echo the renegotiation extension unless
4814 // requested by the client.
4815 testCases = append(testCases, testCase{
4816 testType: serverTest,
4817 name: "Renegotiate-Server-NoExt",
4818 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004819 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004820 Bugs: ProtocolBugs{
4821 NoRenegotiationInfo: true,
4822 RequireRenegotiationInfo: true,
4823 },
4824 },
4825 shouldFail: true,
4826 expectedLocalError: "renegotiation extension missing",
4827 })
4828 // The renegotiation SCSV should be sufficient for the server to echo
4829 // the extension.
4830 testCases = append(testCases, testCase{
4831 testType: serverTest,
4832 name: "Renegotiate-Server-NoExt-SCSV",
4833 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004834 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004835 Bugs: ProtocolBugs{
4836 NoRenegotiationInfo: true,
4837 SendRenegotiationSCSV: true,
4838 RequireRenegotiationInfo: true,
4839 },
4840 },
4841 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004842 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004843 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004845 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004846 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004847 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004848 },
4849 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004850 renegotiate: 1,
4851 flags: []string{
4852 "-renegotiate-freely",
4853 "-expect-total-renegotiations", "1",
4854 },
David Benjamincdea40c2015-03-19 14:09:43 -04004855 })
4856 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004857 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004858 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004859 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004860 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004861 Bugs: ProtocolBugs{
4862 EmptyRenegotiationInfo: true,
4863 },
4864 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004865 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004866 shouldFail: true,
4867 expectedError: ":RENEGOTIATION_MISMATCH:",
4868 })
4869 testCases = append(testCases, testCase{
4870 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004871 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004872 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004873 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004874 Bugs: ProtocolBugs{
4875 BadRenegotiationInfo: true,
4876 },
4877 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004878 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004879 shouldFail: true,
4880 expectedError: ":RENEGOTIATION_MISMATCH:",
4881 })
4882 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004883 name: "Renegotiate-Client-Downgrade",
4884 renegotiate: 1,
4885 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004886 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004887 Bugs: ProtocolBugs{
4888 NoRenegotiationInfoAfterInitial: true,
4889 },
4890 },
4891 flags: []string{"-renegotiate-freely"},
4892 shouldFail: true,
4893 expectedError: ":RENEGOTIATION_MISMATCH:",
4894 })
4895 testCases = append(testCases, testCase{
4896 name: "Renegotiate-Client-Upgrade",
4897 renegotiate: 1,
4898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004899 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004900 Bugs: ProtocolBugs{
4901 NoRenegotiationInfoInInitial: true,
4902 },
4903 },
4904 flags: []string{"-renegotiate-freely"},
4905 shouldFail: true,
4906 expectedError: ":RENEGOTIATION_MISMATCH:",
4907 })
4908 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004909 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004910 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004912 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004913 Bugs: ProtocolBugs{
4914 NoRenegotiationInfo: true,
4915 },
4916 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004917 flags: []string{
4918 "-renegotiate-freely",
4919 "-expect-total-renegotiations", "1",
4920 },
David Benjamincff0b902015-05-15 23:09:47 -04004921 })
4922 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004923 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004924 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004925 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004926 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004927 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4928 },
4929 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004930 flags: []string{
4931 "-renegotiate-freely",
4932 "-expect-total-renegotiations", "1",
4933 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004934 })
4935 testCases = append(testCases, testCase{
4936 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004937 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004938 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004939 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004940 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4941 },
4942 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004943 flags: []string{
4944 "-renegotiate-freely",
4945 "-expect-total-renegotiations", "1",
4946 },
David Benjaminb16346b2015-04-08 19:16:58 -04004947 })
4948 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004949 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004950 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004951 config: Config{
4952 MaxVersion: VersionTLS10,
4953 Bugs: ProtocolBugs{
4954 RequireSameRenegoClientVersion: true,
4955 },
4956 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004957 flags: []string{
4958 "-renegotiate-freely",
4959 "-expect-total-renegotiations", "1",
4960 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004961 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004962 testCases = append(testCases, testCase{
4963 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004964 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004965 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004966 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4968 NextProtos: []string{"foo"},
4969 },
4970 flags: []string{
4971 "-false-start",
4972 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004973 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004974 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004975 },
4976 shimWritesFirst: true,
4977 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004978
4979 // Client-side renegotiation controls.
4980 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004981 name: "Renegotiate-Client-Forbidden-1",
4982 config: Config{
4983 MaxVersion: VersionTLS12,
4984 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004985 renegotiate: 1,
4986 shouldFail: true,
4987 expectedError: ":NO_RENEGOTIATION:",
4988 expectedLocalError: "remote error: no renegotiation",
4989 })
4990 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004991 name: "Renegotiate-Client-Once-1",
4992 config: Config{
4993 MaxVersion: VersionTLS12,
4994 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004995 renegotiate: 1,
4996 flags: []string{
4997 "-renegotiate-once",
4998 "-expect-total-renegotiations", "1",
4999 },
5000 })
5001 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005002 name: "Renegotiate-Client-Freely-1",
5003 config: Config{
5004 MaxVersion: VersionTLS12,
5005 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005006 renegotiate: 1,
5007 flags: []string{
5008 "-renegotiate-freely",
5009 "-expect-total-renegotiations", "1",
5010 },
5011 })
5012 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005013 name: "Renegotiate-Client-Once-2",
5014 config: Config{
5015 MaxVersion: VersionTLS12,
5016 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005017 renegotiate: 2,
5018 flags: []string{"-renegotiate-once"},
5019 shouldFail: true,
5020 expectedError: ":NO_RENEGOTIATION:",
5021 expectedLocalError: "remote error: no renegotiation",
5022 })
5023 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005024 name: "Renegotiate-Client-Freely-2",
5025 config: Config{
5026 MaxVersion: VersionTLS12,
5027 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005028 renegotiate: 2,
5029 flags: []string{
5030 "-renegotiate-freely",
5031 "-expect-total-renegotiations", "2",
5032 },
5033 })
Adam Langley27a0d082015-11-03 13:34:10 -08005034 testCases = append(testCases, testCase{
5035 name: "Renegotiate-Client-NoIgnore",
5036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005037 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005038 Bugs: ProtocolBugs{
5039 SendHelloRequestBeforeEveryAppDataRecord: true,
5040 },
5041 },
5042 shouldFail: true,
5043 expectedError: ":NO_RENEGOTIATION:",
5044 })
5045 testCases = append(testCases, testCase{
5046 name: "Renegotiate-Client-Ignore",
5047 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005048 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005049 Bugs: ProtocolBugs{
5050 SendHelloRequestBeforeEveryAppDataRecord: true,
5051 },
5052 },
5053 flags: []string{
5054 "-renegotiate-ignore",
5055 "-expect-total-renegotiations", "0",
5056 },
5057 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005058
David Benjamin397c8e62016-07-08 14:14:36 -07005059 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005060 testCases = append(testCases, testCase{
5061 name: "StrayHelloRequest",
5062 config: Config{
5063 MaxVersion: VersionTLS12,
5064 Bugs: ProtocolBugs{
5065 SendHelloRequestBeforeEveryHandshakeMessage: true,
5066 },
5067 },
5068 })
5069 testCases = append(testCases, testCase{
5070 name: "StrayHelloRequest-Packed",
5071 config: Config{
5072 MaxVersion: VersionTLS12,
5073 Bugs: ProtocolBugs{
5074 PackHandshakeFlight: true,
5075 SendHelloRequestBeforeEveryHandshakeMessage: true,
5076 },
5077 },
5078 })
5079
David Benjamin12d2c482016-07-24 10:56:51 -04005080 // Test renegotiation works if HelloRequest and server Finished come in
5081 // the same record.
5082 testCases = append(testCases, testCase{
5083 name: "Renegotiate-Client-Packed",
5084 config: Config{
5085 MaxVersion: VersionTLS12,
5086 Bugs: ProtocolBugs{
5087 PackHandshakeFlight: true,
5088 PackHelloRequestWithFinished: true,
5089 },
5090 },
5091 renegotiate: 1,
5092 flags: []string{
5093 "-renegotiate-freely",
5094 "-expect-total-renegotiations", "1",
5095 },
5096 })
5097
David Benjamin397c8e62016-07-08 14:14:36 -07005098 // Renegotiation is forbidden in TLS 1.3.
Steven Valdez143e8b32016-07-11 13:19:03 -04005099 //
5100 // TODO(davidben): This test current asserts that we ignore
5101 // HelloRequests, but we actually should hard reject them. Fix this
5102 // test once we actually parse post-handshake messages.
David Benjamin397c8e62016-07-08 14:14:36 -07005103 testCases = append(testCases, testCase{
5104 name: "Renegotiate-Client-TLS13",
5105 config: Config{
5106 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005107 Bugs: ProtocolBugs{
5108 SendHelloRequestBeforeEveryAppDataRecord: true,
5109 },
David Benjamin397c8e62016-07-08 14:14:36 -07005110 },
David Benjamin397c8e62016-07-08 14:14:36 -07005111 flags: []string{
5112 "-renegotiate-freely",
5113 },
David Benjamin397c8e62016-07-08 14:14:36 -07005114 })
5115
5116 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5117 testCases = append(testCases, testCase{
5118 name: "StrayHelloRequest-TLS13",
5119 config: Config{
5120 MaxVersion: VersionTLS13,
5121 Bugs: ProtocolBugs{
5122 SendHelloRequestBeforeEveryHandshakeMessage: true,
5123 },
5124 },
5125 shouldFail: true,
5126 expectedError: ":UNEXPECTED_MESSAGE:",
5127 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005128}
5129
David Benjamin5e961c12014-11-07 01:48:35 -05005130func addDTLSReplayTests() {
5131 // Test that sequence number replays are detected.
5132 testCases = append(testCases, testCase{
5133 protocol: dtls,
5134 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005135 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005136 replayWrites: true,
5137 })
5138
David Benjamin8e6db492015-07-25 18:29:23 -04005139 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005140 // than the retransmit window.
5141 testCases = append(testCases, testCase{
5142 protocol: dtls,
5143 name: "DTLS-Replay-LargeGaps",
5144 config: Config{
5145 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005146 SequenceNumberMapping: func(in uint64) uint64 {
5147 return in * 127
5148 },
David Benjamin5e961c12014-11-07 01:48:35 -05005149 },
5150 },
David Benjamin8e6db492015-07-25 18:29:23 -04005151 messageCount: 200,
5152 replayWrites: true,
5153 })
5154
5155 // Test the incoming sequence number changing non-monotonically.
5156 testCases = append(testCases, testCase{
5157 protocol: dtls,
5158 name: "DTLS-Replay-NonMonotonic",
5159 config: Config{
5160 Bugs: ProtocolBugs{
5161 SequenceNumberMapping: func(in uint64) uint64 {
5162 return in ^ 31
5163 },
5164 },
5165 },
5166 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005167 replayWrites: true,
5168 })
5169}
5170
Nick Harper60edffd2016-06-21 15:19:24 -07005171var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005172 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005173 id signatureAlgorithm
5174 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005175}{
Nick Harper60edffd2016-06-21 15:19:24 -07005176 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5177 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5178 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5179 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005180 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005181 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5182 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5183 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005184 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5185 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5186 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005187 // Tests for key types prior to TLS 1.2.
5188 {"RSA", 0, testCertRSA},
5189 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005190}
5191
Nick Harper60edffd2016-06-21 15:19:24 -07005192const fakeSigAlg1 signatureAlgorithm = 0x2a01
5193const fakeSigAlg2 signatureAlgorithm = 0xff01
5194
5195func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005196 // Not all ciphers involve a signature. Advertise a list which gives all
5197 // versions a signing cipher.
5198 signingCiphers := []uint16{
5199 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5200 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5201 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5202 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5203 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5204 }
5205
David Benjaminca3d5452016-07-14 12:51:01 -04005206 var allAlgorithms []signatureAlgorithm
5207 for _, alg := range testSignatureAlgorithms {
5208 if alg.id != 0 {
5209 allAlgorithms = append(allAlgorithms, alg.id)
5210 }
5211 }
5212
Nick Harper60edffd2016-06-21 15:19:24 -07005213 // Make sure each signature algorithm works. Include some fake values in
5214 // the list and ensure they're ignored.
5215 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005216 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005217 if (ver.version < VersionTLS12) != (alg.id == 0) {
5218 continue
5219 }
5220
5221 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5222 // or remove it in C.
5223 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005224 continue
5225 }
Nick Harper60edffd2016-06-21 15:19:24 -07005226
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005227 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005228 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005229 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5230 shouldFail = true
5231 }
5232 // RSA-PSS does not exist in TLS 1.2.
5233 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5234 shouldFail = true
5235 }
5236
5237 var signError, verifyError string
5238 if shouldFail {
5239 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5240 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005241 }
David Benjamin000800a2014-11-14 01:43:59 -05005242
David Benjamin1fb125c2016-07-08 18:52:12 -07005243 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005244
David Benjamin7a41d372016-07-09 11:21:54 -07005245 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005246 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005247 config: Config{
5248 MaxVersion: ver.version,
5249 ClientAuth: RequireAnyClientCert,
5250 VerifySignatureAlgorithms: []signatureAlgorithm{
5251 fakeSigAlg1,
5252 alg.id,
5253 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005254 },
David Benjamin7a41d372016-07-09 11:21:54 -07005255 },
5256 flags: []string{
5257 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5258 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5259 "-enable-all-curves",
5260 },
5261 shouldFail: shouldFail,
5262 expectedError: signError,
5263 expectedPeerSignatureAlgorithm: alg.id,
5264 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005265
David Benjamin7a41d372016-07-09 11:21:54 -07005266 testCases = append(testCases, testCase{
5267 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005268 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005269 config: Config{
5270 MaxVersion: ver.version,
5271 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5272 SignSignatureAlgorithms: []signatureAlgorithm{
5273 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005274 },
David Benjamin7a41d372016-07-09 11:21:54 -07005275 Bugs: ProtocolBugs{
5276 SkipECDSACurveCheck: shouldFail,
5277 IgnoreSignatureVersionChecks: shouldFail,
5278 // The client won't advertise 1.3-only algorithms after
5279 // version negotiation.
5280 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005281 },
David Benjamin7a41d372016-07-09 11:21:54 -07005282 },
5283 flags: []string{
5284 "-require-any-client-certificate",
5285 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5286 "-enable-all-curves",
5287 },
5288 shouldFail: shouldFail,
5289 expectedError: verifyError,
5290 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005291
5292 testCases = append(testCases, testCase{
5293 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005294 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005295 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005296 MaxVersion: ver.version,
5297 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005298 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005299 fakeSigAlg1,
5300 alg.id,
5301 fakeSigAlg2,
5302 },
5303 },
5304 flags: []string{
5305 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5306 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5307 "-enable-all-curves",
5308 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005309 shouldFail: shouldFail,
5310 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005311 expectedPeerSignatureAlgorithm: alg.id,
5312 })
5313
5314 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005315 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005316 config: Config{
5317 MaxVersion: ver.version,
5318 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005319 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005320 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005321 alg.id,
5322 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005323 Bugs: ProtocolBugs{
5324 SkipECDSACurveCheck: shouldFail,
5325 IgnoreSignatureVersionChecks: shouldFail,
5326 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005327 },
5328 flags: []string{
5329 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5330 "-enable-all-curves",
5331 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005332 shouldFail: shouldFail,
5333 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005334 })
David Benjamin5208fd42016-07-13 21:43:25 -04005335
5336 if !shouldFail {
5337 testCases = append(testCases, testCase{
5338 testType: serverTest,
5339 name: "ClientAuth-InvalidSignature" + suffix,
5340 config: Config{
5341 MaxVersion: ver.version,
5342 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5343 SignSignatureAlgorithms: []signatureAlgorithm{
5344 alg.id,
5345 },
5346 Bugs: ProtocolBugs{
5347 InvalidSignature: true,
5348 },
5349 },
5350 flags: []string{
5351 "-require-any-client-certificate",
5352 "-enable-all-curves",
5353 },
5354 shouldFail: true,
5355 expectedError: ":BAD_SIGNATURE:",
5356 })
5357
5358 testCases = append(testCases, testCase{
5359 name: "ServerAuth-InvalidSignature" + suffix,
5360 config: Config{
5361 MaxVersion: ver.version,
5362 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5363 CipherSuites: signingCiphers,
5364 SignSignatureAlgorithms: []signatureAlgorithm{
5365 alg.id,
5366 },
5367 Bugs: ProtocolBugs{
5368 InvalidSignature: true,
5369 },
5370 },
5371 flags: []string{"-enable-all-curves"},
5372 shouldFail: true,
5373 expectedError: ":BAD_SIGNATURE:",
5374 })
5375 }
David Benjaminca3d5452016-07-14 12:51:01 -04005376
5377 if ver.version >= VersionTLS12 && !shouldFail {
5378 testCases = append(testCases, testCase{
5379 name: "ClientAuth-Sign-Negotiate" + suffix,
5380 config: Config{
5381 MaxVersion: ver.version,
5382 ClientAuth: RequireAnyClientCert,
5383 VerifySignatureAlgorithms: allAlgorithms,
5384 },
5385 flags: []string{
5386 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5387 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5388 "-enable-all-curves",
5389 "-signing-prefs", strconv.Itoa(int(alg.id)),
5390 },
5391 expectedPeerSignatureAlgorithm: alg.id,
5392 })
5393
5394 testCases = append(testCases, testCase{
5395 testType: serverTest,
5396 name: "ServerAuth-Sign-Negotiate" + suffix,
5397 config: Config{
5398 MaxVersion: ver.version,
5399 CipherSuites: signingCiphers,
5400 VerifySignatureAlgorithms: allAlgorithms,
5401 },
5402 flags: []string{
5403 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5404 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5405 "-enable-all-curves",
5406 "-signing-prefs", strconv.Itoa(int(alg.id)),
5407 },
5408 expectedPeerSignatureAlgorithm: alg.id,
5409 })
5410 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005411 }
David Benjamin000800a2014-11-14 01:43:59 -05005412 }
5413
Nick Harper60edffd2016-06-21 15:19:24 -07005414 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005415 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005416 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005417 config: Config{
5418 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005419 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005420 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005421 signatureECDSAWithP521AndSHA512,
5422 signatureRSAPKCS1WithSHA384,
5423 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005424 },
5425 },
5426 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005427 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5428 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005429 },
Nick Harper60edffd2016-06-21 15:19:24 -07005430 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005431 })
5432
5433 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005434 name: "ClientAuth-SignatureType-TLS13",
5435 config: Config{
5436 ClientAuth: RequireAnyClientCert,
5437 MaxVersion: VersionTLS13,
5438 VerifySignatureAlgorithms: []signatureAlgorithm{
5439 signatureECDSAWithP521AndSHA512,
5440 signatureRSAPKCS1WithSHA384,
5441 signatureRSAPSSWithSHA384,
5442 signatureECDSAWithSHA1,
5443 },
5444 },
5445 flags: []string{
5446 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5447 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5448 },
5449 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5450 })
5451
5452 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005453 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005454 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005456 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005458 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005459 signatureECDSAWithP521AndSHA512,
5460 signatureRSAPKCS1WithSHA384,
5461 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005462 },
5463 },
Nick Harper60edffd2016-06-21 15:19:24 -07005464 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005465 })
5466
Steven Valdez143e8b32016-07-11 13:19:03 -04005467 testCases = append(testCases, testCase{
5468 testType: serverTest,
5469 name: "ServerAuth-SignatureType-TLS13",
5470 config: Config{
5471 MaxVersion: VersionTLS13,
5472 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5473 VerifySignatureAlgorithms: []signatureAlgorithm{
5474 signatureECDSAWithP521AndSHA512,
5475 signatureRSAPKCS1WithSHA384,
5476 signatureRSAPSSWithSHA384,
5477 signatureECDSAWithSHA1,
5478 },
5479 },
5480 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5481 })
5482
David Benjamina95e9f32016-07-08 16:28:04 -07005483 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005484 testCases = append(testCases, testCase{
5485 testType: serverTest,
5486 name: "Verify-ClientAuth-SignatureType",
5487 config: Config{
5488 MaxVersion: VersionTLS12,
5489 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005490 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005491 signatureRSAPKCS1WithSHA256,
5492 },
5493 Bugs: ProtocolBugs{
5494 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5495 },
5496 },
5497 flags: []string{
5498 "-require-any-client-certificate",
5499 },
5500 shouldFail: true,
5501 expectedError: ":WRONG_SIGNATURE_TYPE:",
5502 })
5503
5504 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005505 testType: serverTest,
5506 name: "Verify-ClientAuth-SignatureType-TLS13",
5507 config: Config{
5508 MaxVersion: VersionTLS13,
5509 Certificates: []Certificate{rsaCertificate},
5510 SignSignatureAlgorithms: []signatureAlgorithm{
5511 signatureRSAPSSWithSHA256,
5512 },
5513 Bugs: ProtocolBugs{
5514 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5515 },
5516 },
5517 flags: []string{
5518 "-require-any-client-certificate",
5519 },
5520 shouldFail: true,
5521 expectedError: ":WRONG_SIGNATURE_TYPE:",
5522 })
5523
5524 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005525 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005526 config: Config{
5527 MaxVersion: VersionTLS12,
5528 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005529 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005530 signatureRSAPKCS1WithSHA256,
5531 },
5532 Bugs: ProtocolBugs{
5533 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5534 },
5535 },
5536 shouldFail: true,
5537 expectedError: ":WRONG_SIGNATURE_TYPE:",
5538 })
5539
Steven Valdez143e8b32016-07-11 13:19:03 -04005540 testCases = append(testCases, testCase{
5541 name: "Verify-ServerAuth-SignatureType-TLS13",
5542 config: Config{
5543 MaxVersion: VersionTLS13,
5544 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5545 SignSignatureAlgorithms: []signatureAlgorithm{
5546 signatureRSAPSSWithSHA256,
5547 },
5548 Bugs: ProtocolBugs{
5549 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5550 },
5551 },
5552 shouldFail: true,
5553 expectedError: ":WRONG_SIGNATURE_TYPE:",
5554 })
5555
David Benjamin51dd7d62016-07-08 16:07:01 -07005556 // Test that, if the list is missing, the peer falls back to SHA-1 in
5557 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005558 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005559 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005560 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005561 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005562 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005563 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005564 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005565 },
5566 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005567 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005568 },
5569 },
5570 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005571 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5572 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005573 },
5574 })
5575
5576 testCases = append(testCases, testCase{
5577 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005578 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005579 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005580 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005581 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005582 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005583 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005584 },
5585 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005586 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005587 },
5588 },
5589 })
David Benjamin72dc7832015-03-16 17:49:43 -04005590
David Benjamin51dd7d62016-07-08 16:07:01 -07005591 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005592 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005593 config: Config{
5594 MaxVersion: VersionTLS13,
5595 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005596 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005597 signatureRSAPKCS1WithSHA1,
5598 },
5599 Bugs: ProtocolBugs{
5600 NoSignatureAlgorithms: true,
5601 },
5602 },
5603 flags: []string{
5604 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5605 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5606 },
5607 shouldFail: true,
5608 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5609 })
5610
5611 testCases = append(testCases, testCase{
5612 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005613 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005614 config: Config{
5615 MaxVersion: VersionTLS13,
5616 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005617 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005618 signatureRSAPKCS1WithSHA1,
5619 },
5620 Bugs: ProtocolBugs{
5621 NoSignatureAlgorithms: true,
5622 },
5623 },
5624 shouldFail: true,
5625 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5626 })
5627
David Benjaminb62d2872016-07-18 14:55:02 +02005628 // Test that hash preferences are enforced. BoringSSL does not implement
5629 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005630 testCases = append(testCases, testCase{
5631 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005632 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005633 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005634 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005635 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005636 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005637 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005638 },
5639 Bugs: ProtocolBugs{
5640 IgnorePeerSignatureAlgorithmPreferences: true,
5641 },
5642 },
5643 flags: []string{"-require-any-client-certificate"},
5644 shouldFail: true,
5645 expectedError: ":WRONG_SIGNATURE_TYPE:",
5646 })
5647
5648 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005649 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005650 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005651 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005652 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005653 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005654 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005655 },
5656 Bugs: ProtocolBugs{
5657 IgnorePeerSignatureAlgorithmPreferences: true,
5658 },
5659 },
5660 shouldFail: true,
5661 expectedError: ":WRONG_SIGNATURE_TYPE:",
5662 })
David Benjaminb62d2872016-07-18 14:55:02 +02005663 testCases = append(testCases, testCase{
5664 testType: serverTest,
5665 name: "ClientAuth-Enforced-TLS13",
5666 config: Config{
5667 MaxVersion: VersionTLS13,
5668 Certificates: []Certificate{rsaCertificate},
5669 SignSignatureAlgorithms: []signatureAlgorithm{
5670 signatureRSAPKCS1WithMD5,
5671 },
5672 Bugs: ProtocolBugs{
5673 IgnorePeerSignatureAlgorithmPreferences: true,
5674 IgnoreSignatureVersionChecks: true,
5675 },
5676 },
5677 flags: []string{"-require-any-client-certificate"},
5678 shouldFail: true,
5679 expectedError: ":WRONG_SIGNATURE_TYPE:",
5680 })
5681
5682 testCases = append(testCases, testCase{
5683 name: "ServerAuth-Enforced-TLS13",
5684 config: Config{
5685 MaxVersion: VersionTLS13,
5686 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5687 SignSignatureAlgorithms: []signatureAlgorithm{
5688 signatureRSAPKCS1WithMD5,
5689 },
5690 Bugs: ProtocolBugs{
5691 IgnorePeerSignatureAlgorithmPreferences: true,
5692 IgnoreSignatureVersionChecks: true,
5693 },
5694 },
5695 shouldFail: true,
5696 expectedError: ":WRONG_SIGNATURE_TYPE:",
5697 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005698
5699 // Test that the agreed upon digest respects the client preferences and
5700 // the server digests.
5701 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005702 name: "NoCommonAlgorithms-Digests",
5703 config: Config{
5704 MaxVersion: VersionTLS12,
5705 ClientAuth: RequireAnyClientCert,
5706 VerifySignatureAlgorithms: []signatureAlgorithm{
5707 signatureRSAPKCS1WithSHA512,
5708 signatureRSAPKCS1WithSHA1,
5709 },
5710 },
5711 flags: []string{
5712 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5713 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5714 "-digest-prefs", "SHA256",
5715 },
5716 shouldFail: true,
5717 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5718 })
5719 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005720 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005722 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005723 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005724 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005725 signatureRSAPKCS1WithSHA512,
5726 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005727 },
5728 },
5729 flags: []string{
5730 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5731 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005732 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005733 },
David Benjaminca3d5452016-07-14 12:51:01 -04005734 shouldFail: true,
5735 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5736 })
5737 testCases = append(testCases, testCase{
5738 name: "NoCommonAlgorithms-TLS13",
5739 config: Config{
5740 MaxVersion: VersionTLS13,
5741 ClientAuth: RequireAnyClientCert,
5742 VerifySignatureAlgorithms: []signatureAlgorithm{
5743 signatureRSAPSSWithSHA512,
5744 signatureRSAPSSWithSHA384,
5745 },
5746 },
5747 flags: []string{
5748 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5749 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5750 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5751 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005752 shouldFail: true,
5753 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005754 })
5755 testCases = append(testCases, testCase{
5756 name: "Agree-Digest-SHA256",
5757 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005758 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005759 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005760 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005761 signatureRSAPKCS1WithSHA1,
5762 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005763 },
5764 },
5765 flags: []string{
5766 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5767 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005768 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005769 },
Nick Harper60edffd2016-06-21 15:19:24 -07005770 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005771 })
5772 testCases = append(testCases, testCase{
5773 name: "Agree-Digest-SHA1",
5774 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005775 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005776 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005777 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005778 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005779 },
5780 },
5781 flags: []string{
5782 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5783 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005784 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005785 },
Nick Harper60edffd2016-06-21 15:19:24 -07005786 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005787 })
5788 testCases = append(testCases, testCase{
5789 name: "Agree-Digest-Default",
5790 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005791 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005792 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005793 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005794 signatureRSAPKCS1WithSHA256,
5795 signatureECDSAWithP256AndSHA256,
5796 signatureRSAPKCS1WithSHA1,
5797 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005798 },
5799 },
5800 flags: []string{
5801 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5802 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5803 },
Nick Harper60edffd2016-06-21 15:19:24 -07005804 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005805 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005806
David Benjaminca3d5452016-07-14 12:51:01 -04005807 // Test that the signing preference list may include extra algorithms
5808 // without negotiation problems.
5809 testCases = append(testCases, testCase{
5810 testType: serverTest,
5811 name: "FilterExtraAlgorithms",
5812 config: Config{
5813 MaxVersion: VersionTLS12,
5814 VerifySignatureAlgorithms: []signatureAlgorithm{
5815 signatureRSAPKCS1WithSHA256,
5816 },
5817 },
5818 flags: []string{
5819 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5820 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5821 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
5822 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
5823 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
5824 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
5825 },
5826 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
5827 })
5828
David Benjamin4c3ddf72016-06-29 18:13:53 -04005829 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5830 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04005831 testCases = append(testCases, testCase{
5832 name: "CheckLeafCurve",
5833 config: Config{
5834 MaxVersion: VersionTLS12,
5835 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07005836 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04005837 },
5838 flags: []string{"-p384-only"},
5839 shouldFail: true,
5840 expectedError: ":BAD_ECC_CERT:",
5841 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07005842
5843 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
5844 testCases = append(testCases, testCase{
5845 name: "CheckLeafCurve-TLS13",
5846 config: Config{
5847 MaxVersion: VersionTLS13,
5848 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5849 Certificates: []Certificate{ecdsaP256Certificate},
5850 },
5851 flags: []string{"-p384-only"},
5852 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005853
5854 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
5855 testCases = append(testCases, testCase{
5856 name: "ECDSACurveMismatch-Verify-TLS12",
5857 config: Config{
5858 MaxVersion: VersionTLS12,
5859 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5860 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005861 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005862 signatureECDSAWithP384AndSHA384,
5863 },
5864 },
5865 })
5866
5867 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
5868 testCases = append(testCases, testCase{
5869 name: "ECDSACurveMismatch-Verify-TLS13",
5870 config: Config{
5871 MaxVersion: VersionTLS13,
5872 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5873 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005874 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005875 signatureECDSAWithP384AndSHA384,
5876 },
5877 Bugs: ProtocolBugs{
5878 SkipECDSACurveCheck: true,
5879 },
5880 },
5881 shouldFail: true,
5882 expectedError: ":WRONG_SIGNATURE_TYPE:",
5883 })
5884
5885 // Signature algorithm selection in TLS 1.3 should take the curve into
5886 // account.
5887 testCases = append(testCases, testCase{
5888 testType: serverTest,
5889 name: "ECDSACurveMismatch-Sign-TLS13",
5890 config: Config{
5891 MaxVersion: VersionTLS13,
5892 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005893 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005894 signatureECDSAWithP384AndSHA384,
5895 signatureECDSAWithP256AndSHA256,
5896 },
5897 },
5898 flags: []string{
5899 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
5900 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
5901 },
5902 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5903 })
David Benjamin7944a9f2016-07-12 22:27:01 -04005904
5905 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
5906 // server does not attempt to sign in that case.
5907 testCases = append(testCases, testCase{
5908 testType: serverTest,
5909 name: "RSA-PSS-Large",
5910 config: Config{
5911 MaxVersion: VersionTLS13,
5912 VerifySignatureAlgorithms: []signatureAlgorithm{
5913 signatureRSAPSSWithSHA512,
5914 },
5915 },
5916 flags: []string{
5917 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
5918 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
5919 },
5920 shouldFail: true,
5921 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5922 })
David Benjamin000800a2014-11-14 01:43:59 -05005923}
5924
David Benjamin83f90402015-01-27 01:09:43 -05005925// timeouts is the retransmit schedule for BoringSSL. It doubles and
5926// caps at 60 seconds. On the 13th timeout, it gives up.
5927var timeouts = []time.Duration{
5928 1 * time.Second,
5929 2 * time.Second,
5930 4 * time.Second,
5931 8 * time.Second,
5932 16 * time.Second,
5933 32 * time.Second,
5934 60 * time.Second,
5935 60 * time.Second,
5936 60 * time.Second,
5937 60 * time.Second,
5938 60 * time.Second,
5939 60 * time.Second,
5940 60 * time.Second,
5941}
5942
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005943// shortTimeouts is an alternate set of timeouts which would occur if the
5944// initial timeout duration was set to 250ms.
5945var shortTimeouts = []time.Duration{
5946 250 * time.Millisecond,
5947 500 * time.Millisecond,
5948 1 * time.Second,
5949 2 * time.Second,
5950 4 * time.Second,
5951 8 * time.Second,
5952 16 * time.Second,
5953 32 * time.Second,
5954 60 * time.Second,
5955 60 * time.Second,
5956 60 * time.Second,
5957 60 * time.Second,
5958 60 * time.Second,
5959}
5960
David Benjamin83f90402015-01-27 01:09:43 -05005961func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005962 // These tests work by coordinating some behavior on both the shim and
5963 // the runner.
5964 //
5965 // TimeoutSchedule configures the runner to send a series of timeout
5966 // opcodes to the shim (see packetAdaptor) immediately before reading
5967 // each peer handshake flight N. The timeout opcode both simulates a
5968 // timeout in the shim and acts as a synchronization point to help the
5969 // runner bracket each handshake flight.
5970 //
5971 // We assume the shim does not read from the channel eagerly. It must
5972 // first wait until it has sent flight N and is ready to receive
5973 // handshake flight N+1. At this point, it will process the timeout
5974 // opcode. It must then immediately respond with a timeout ACK and act
5975 // as if the shim was idle for the specified amount of time.
5976 //
5977 // The runner then drops all packets received before the ACK and
5978 // continues waiting for flight N. This ordering results in one attempt
5979 // at sending flight N to be dropped. For the test to complete, the
5980 // shim must send flight N again, testing that the shim implements DTLS
5981 // retransmit on a timeout.
5982
Steven Valdez143e8b32016-07-11 13:19:03 -04005983 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04005984 // likely be more epochs to cross and the final message's retransmit may
5985 // be more complex.
5986
David Benjamin585d7a42016-06-02 14:58:00 -04005987 for _, async := range []bool{true, false} {
5988 var tests []testCase
5989
5990 // Test that this is indeed the timeout schedule. Stress all
5991 // four patterns of handshake.
5992 for i := 1; i < len(timeouts); i++ {
5993 number := strconv.Itoa(i)
5994 tests = append(tests, testCase{
5995 protocol: dtls,
5996 name: "DTLS-Retransmit-Client-" + number,
5997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005998 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005999 Bugs: ProtocolBugs{
6000 TimeoutSchedule: timeouts[:i],
6001 },
6002 },
6003 resumeSession: true,
6004 })
6005 tests = append(tests, testCase{
6006 protocol: dtls,
6007 testType: serverTest,
6008 name: "DTLS-Retransmit-Server-" + number,
6009 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006010 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006011 Bugs: ProtocolBugs{
6012 TimeoutSchedule: timeouts[:i],
6013 },
6014 },
6015 resumeSession: true,
6016 })
6017 }
6018
6019 // Test that exceeding the timeout schedule hits a read
6020 // timeout.
6021 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006022 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006023 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006025 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006026 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006027 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006028 },
6029 },
6030 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006031 shouldFail: true,
6032 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006033 })
David Benjamin585d7a42016-06-02 14:58:00 -04006034
6035 if async {
6036 // Test that timeout handling has a fudge factor, due to API
6037 // problems.
6038 tests = append(tests, testCase{
6039 protocol: dtls,
6040 name: "DTLS-Retransmit-Fudge",
6041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006042 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006043 Bugs: ProtocolBugs{
6044 TimeoutSchedule: []time.Duration{
6045 timeouts[0] - 10*time.Millisecond,
6046 },
6047 },
6048 },
6049 resumeSession: true,
6050 })
6051 }
6052
6053 // Test that the final Finished retransmitting isn't
6054 // duplicated if the peer badly fragments everything.
6055 tests = append(tests, testCase{
6056 testType: serverTest,
6057 protocol: dtls,
6058 name: "DTLS-Retransmit-Fragmented",
6059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006060 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006061 Bugs: ProtocolBugs{
6062 TimeoutSchedule: []time.Duration{timeouts[0]},
6063 MaxHandshakeRecordLength: 2,
6064 },
6065 },
6066 })
6067
6068 // Test the timeout schedule when a shorter initial timeout duration is set.
6069 tests = append(tests, testCase{
6070 protocol: dtls,
6071 name: "DTLS-Retransmit-Short-Client",
6072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006073 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006074 Bugs: ProtocolBugs{
6075 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6076 },
6077 },
6078 resumeSession: true,
6079 flags: []string{"-initial-timeout-duration-ms", "250"},
6080 })
6081 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006082 protocol: dtls,
6083 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006084 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006086 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006087 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006088 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006089 },
6090 },
6091 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006092 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006093 })
David Benjamin585d7a42016-06-02 14:58:00 -04006094
6095 for _, test := range tests {
6096 if async {
6097 test.name += "-Async"
6098 test.flags = append(test.flags, "-async")
6099 }
6100
6101 testCases = append(testCases, test)
6102 }
David Benjamin83f90402015-01-27 01:09:43 -05006103 }
David Benjamin83f90402015-01-27 01:09:43 -05006104}
6105
David Benjaminc565ebb2015-04-03 04:06:36 -04006106func addExportKeyingMaterialTests() {
6107 for _, vers := range tlsVersions {
6108 if vers.version == VersionSSL30 {
6109 continue
6110 }
6111 testCases = append(testCases, testCase{
6112 name: "ExportKeyingMaterial-" + vers.name,
6113 config: Config{
6114 MaxVersion: vers.version,
6115 },
6116 exportKeyingMaterial: 1024,
6117 exportLabel: "label",
6118 exportContext: "context",
6119 useExportContext: true,
6120 })
6121 testCases = append(testCases, testCase{
6122 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6123 config: Config{
6124 MaxVersion: vers.version,
6125 },
6126 exportKeyingMaterial: 1024,
6127 })
6128 testCases = append(testCases, testCase{
6129 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6130 config: Config{
6131 MaxVersion: vers.version,
6132 },
6133 exportKeyingMaterial: 1024,
6134 useExportContext: true,
6135 })
6136 testCases = append(testCases, testCase{
6137 name: "ExportKeyingMaterial-Small-" + vers.name,
6138 config: Config{
6139 MaxVersion: vers.version,
6140 },
6141 exportKeyingMaterial: 1,
6142 exportLabel: "label",
6143 exportContext: "context",
6144 useExportContext: true,
6145 })
6146 }
6147 testCases = append(testCases, testCase{
6148 name: "ExportKeyingMaterial-SSL3",
6149 config: Config{
6150 MaxVersion: VersionSSL30,
6151 },
6152 exportKeyingMaterial: 1024,
6153 exportLabel: "label",
6154 exportContext: "context",
6155 useExportContext: true,
6156 shouldFail: true,
6157 expectedError: "failed to export keying material",
6158 })
6159}
6160
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006161func addTLSUniqueTests() {
6162 for _, isClient := range []bool{false, true} {
6163 for _, isResumption := range []bool{false, true} {
6164 for _, hasEMS := range []bool{false, true} {
6165 var suffix string
6166 if isResumption {
6167 suffix = "Resume-"
6168 } else {
6169 suffix = "Full-"
6170 }
6171
6172 if hasEMS {
6173 suffix += "EMS-"
6174 } else {
6175 suffix += "NoEMS-"
6176 }
6177
6178 if isClient {
6179 suffix += "Client"
6180 } else {
6181 suffix += "Server"
6182 }
6183
6184 test := testCase{
6185 name: "TLSUnique-" + suffix,
6186 testTLSUnique: true,
6187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006188 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006189 Bugs: ProtocolBugs{
6190 NoExtendedMasterSecret: !hasEMS,
6191 },
6192 },
6193 }
6194
6195 if isResumption {
6196 test.resumeSession = true
6197 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006198 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006199 Bugs: ProtocolBugs{
6200 NoExtendedMasterSecret: !hasEMS,
6201 },
6202 }
6203 }
6204
6205 if isResumption && !hasEMS {
6206 test.shouldFail = true
6207 test.expectedError = "failed to get tls-unique"
6208 }
6209
6210 testCases = append(testCases, test)
6211 }
6212 }
6213 }
6214}
6215
Adam Langley09505632015-07-30 18:10:13 -07006216func addCustomExtensionTests() {
6217 expectedContents := "custom extension"
6218 emptyString := ""
6219
6220 for _, isClient := range []bool{false, true} {
6221 suffix := "Server"
6222 flag := "-enable-server-custom-extension"
6223 testType := serverTest
6224 if isClient {
6225 suffix = "Client"
6226 flag = "-enable-client-custom-extension"
6227 testType = clientTest
6228 }
6229
6230 testCases = append(testCases, testCase{
6231 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006232 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006233 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006234 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006235 Bugs: ProtocolBugs{
6236 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006237 ExpectedCustomExtension: &expectedContents,
6238 },
6239 },
6240 flags: []string{flag},
6241 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006242 testCases = append(testCases, testCase{
6243 testType: testType,
6244 name: "CustomExtensions-" + suffix + "-TLS13",
6245 config: Config{
6246 MaxVersion: VersionTLS13,
6247 Bugs: ProtocolBugs{
6248 CustomExtension: expectedContents,
6249 ExpectedCustomExtension: &expectedContents,
6250 },
6251 },
6252 flags: []string{flag},
6253 })
Adam Langley09505632015-07-30 18:10:13 -07006254
6255 // If the parse callback fails, the handshake should also fail.
6256 testCases = append(testCases, testCase{
6257 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006258 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006259 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006260 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006261 Bugs: ProtocolBugs{
6262 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006263 ExpectedCustomExtension: &expectedContents,
6264 },
6265 },
David Benjamin399e7c92015-07-30 23:01:27 -04006266 flags: []string{flag},
6267 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006268 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6269 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006270 testCases = append(testCases, testCase{
6271 testType: testType,
6272 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6273 config: Config{
6274 MaxVersion: VersionTLS13,
6275 Bugs: ProtocolBugs{
6276 CustomExtension: expectedContents + "foo",
6277 ExpectedCustomExtension: &expectedContents,
6278 },
6279 },
6280 flags: []string{flag},
6281 shouldFail: true,
6282 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6283 })
Adam Langley09505632015-07-30 18:10:13 -07006284
6285 // If the add callback fails, the handshake should also fail.
6286 testCases = append(testCases, testCase{
6287 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006288 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006289 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006290 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006291 Bugs: ProtocolBugs{
6292 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006293 ExpectedCustomExtension: &expectedContents,
6294 },
6295 },
David Benjamin399e7c92015-07-30 23:01:27 -04006296 flags: []string{flag, "-custom-extension-fail-add"},
6297 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006298 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6299 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006300 testCases = append(testCases, testCase{
6301 testType: testType,
6302 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6303 config: Config{
6304 MaxVersion: VersionTLS13,
6305 Bugs: ProtocolBugs{
6306 CustomExtension: expectedContents,
6307 ExpectedCustomExtension: &expectedContents,
6308 },
6309 },
6310 flags: []string{flag, "-custom-extension-fail-add"},
6311 shouldFail: true,
6312 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6313 })
Adam Langley09505632015-07-30 18:10:13 -07006314
6315 // If the add callback returns zero, no extension should be
6316 // added.
6317 skipCustomExtension := expectedContents
6318 if isClient {
6319 // For the case where the client skips sending the
6320 // custom extension, the server must not “echo” it.
6321 skipCustomExtension = ""
6322 }
6323 testCases = append(testCases, testCase{
6324 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006325 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006326 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006327 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006328 Bugs: ProtocolBugs{
6329 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006330 ExpectedCustomExtension: &emptyString,
6331 },
6332 },
6333 flags: []string{flag, "-custom-extension-skip"},
6334 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006335 testCases = append(testCases, testCase{
6336 testType: testType,
6337 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6338 config: Config{
6339 MaxVersion: VersionTLS13,
6340 Bugs: ProtocolBugs{
6341 CustomExtension: skipCustomExtension,
6342 ExpectedCustomExtension: &emptyString,
6343 },
6344 },
6345 flags: []string{flag, "-custom-extension-skip"},
6346 })
Adam Langley09505632015-07-30 18:10:13 -07006347 }
6348
6349 // The custom extension add callback should not be called if the client
6350 // doesn't send the extension.
6351 testCases = append(testCases, testCase{
6352 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006353 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006354 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006355 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006356 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006357 ExpectedCustomExtension: &emptyString,
6358 },
6359 },
6360 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6361 })
Adam Langley2deb9842015-08-07 11:15:37 -07006362
Steven Valdez143e8b32016-07-11 13:19:03 -04006363 testCases = append(testCases, testCase{
6364 testType: serverTest,
6365 name: "CustomExtensions-NotCalled-Server-TLS13",
6366 config: Config{
6367 MaxVersion: VersionTLS13,
6368 Bugs: ProtocolBugs{
6369 ExpectedCustomExtension: &emptyString,
6370 },
6371 },
6372 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6373 })
6374
Adam Langley2deb9842015-08-07 11:15:37 -07006375 // Test an unknown extension from the server.
6376 testCases = append(testCases, testCase{
6377 testType: clientTest,
6378 name: "UnknownExtension-Client",
6379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006380 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006381 Bugs: ProtocolBugs{
6382 CustomExtension: expectedContents,
6383 },
6384 },
6385 shouldFail: true,
6386 expectedError: ":UNEXPECTED_EXTENSION:",
6387 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006388 testCases = append(testCases, testCase{
6389 testType: clientTest,
6390 name: "UnknownExtension-Client-TLS13",
6391 config: Config{
6392 MaxVersion: VersionTLS13,
6393 Bugs: ProtocolBugs{
6394 CustomExtension: expectedContents,
6395 },
6396 },
6397 shouldFail: true,
6398 expectedError: ":UNEXPECTED_EXTENSION:",
6399 })
Adam Langley09505632015-07-30 18:10:13 -07006400}
6401
David Benjaminb36a3952015-12-01 18:53:13 -05006402func addRSAClientKeyExchangeTests() {
6403 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6404 testCases = append(testCases, testCase{
6405 testType: serverTest,
6406 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6407 config: Config{
6408 // Ensure the ClientHello version and final
6409 // version are different, to detect if the
6410 // server uses the wrong one.
6411 MaxVersion: VersionTLS11,
6412 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6413 Bugs: ProtocolBugs{
6414 BadRSAClientKeyExchange: bad,
6415 },
6416 },
6417 shouldFail: true,
6418 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6419 })
6420 }
6421}
6422
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006423var testCurves = []struct {
6424 name string
6425 id CurveID
6426}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006427 {"P-256", CurveP256},
6428 {"P-384", CurveP384},
6429 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006430 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006431}
6432
Steven Valdez5440fe02016-07-18 12:40:30 -04006433const bogusCurve = 0x1234
6434
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006435func addCurveTests() {
6436 for _, curve := range testCurves {
6437 testCases = append(testCases, testCase{
6438 name: "CurveTest-Client-" + curve.name,
6439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006440 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006441 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6442 CurvePreferences: []CurveID{curve.id},
6443 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006444 flags: []string{"-enable-all-curves"},
6445 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006446 })
6447 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006448 name: "CurveTest-Client-" + curve.name + "-TLS13",
6449 config: Config{
6450 MaxVersion: VersionTLS13,
6451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6452 CurvePreferences: []CurveID{curve.id},
6453 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006454 flags: []string{"-enable-all-curves"},
6455 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006456 })
6457 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006458 testType: serverTest,
6459 name: "CurveTest-Server-" + curve.name,
6460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006461 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006462 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6463 CurvePreferences: []CurveID{curve.id},
6464 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006465 flags: []string{"-enable-all-curves"},
6466 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006467 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006468 testCases = append(testCases, testCase{
6469 testType: serverTest,
6470 name: "CurveTest-Server-" + curve.name + "-TLS13",
6471 config: Config{
6472 MaxVersion: VersionTLS13,
6473 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6474 CurvePreferences: []CurveID{curve.id},
6475 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006476 flags: []string{"-enable-all-curves"},
6477 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006478 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006479 }
David Benjamin241ae832016-01-15 03:04:54 -05006480
6481 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006482 testCases = append(testCases, testCase{
6483 testType: serverTest,
6484 name: "UnknownCurve",
6485 config: Config{
6486 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6487 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6488 },
6489 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006490
6491 // The server must not consider ECDHE ciphers when there are no
6492 // supported curves.
6493 testCases = append(testCases, testCase{
6494 testType: serverTest,
6495 name: "NoSupportedCurves",
6496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006497 MaxVersion: VersionTLS12,
6498 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6499 Bugs: ProtocolBugs{
6500 NoSupportedCurves: true,
6501 },
6502 },
6503 shouldFail: true,
6504 expectedError: ":NO_SHARED_CIPHER:",
6505 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006506 testCases = append(testCases, testCase{
6507 testType: serverTest,
6508 name: "NoSupportedCurves-TLS13",
6509 config: Config{
6510 MaxVersion: VersionTLS13,
6511 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6512 Bugs: ProtocolBugs{
6513 NoSupportedCurves: true,
6514 },
6515 },
6516 shouldFail: true,
6517 expectedError: ":NO_SHARED_CIPHER:",
6518 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006519
6520 // The server must fall back to another cipher when there are no
6521 // supported curves.
6522 testCases = append(testCases, testCase{
6523 testType: serverTest,
6524 name: "NoCommonCurves",
6525 config: Config{
6526 MaxVersion: VersionTLS12,
6527 CipherSuites: []uint16{
6528 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6529 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6530 },
6531 CurvePreferences: []CurveID{CurveP224},
6532 },
6533 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6534 })
6535
6536 // The client must reject bogus curves and disabled curves.
6537 testCases = append(testCases, testCase{
6538 name: "BadECDHECurve",
6539 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006540 MaxVersion: VersionTLS12,
6541 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6542 Bugs: ProtocolBugs{
6543 SendCurve: bogusCurve,
6544 },
6545 },
6546 shouldFail: true,
6547 expectedError: ":WRONG_CURVE:",
6548 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006549 testCases = append(testCases, testCase{
6550 name: "BadECDHECurve-TLS13",
6551 config: Config{
6552 MaxVersion: VersionTLS13,
6553 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6554 Bugs: ProtocolBugs{
6555 SendCurve: bogusCurve,
6556 },
6557 },
6558 shouldFail: true,
6559 expectedError: ":WRONG_CURVE:",
6560 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006561
6562 testCases = append(testCases, testCase{
6563 name: "UnsupportedCurve",
6564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006565 MaxVersion: VersionTLS12,
6566 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6567 CurvePreferences: []CurveID{CurveP256},
6568 Bugs: ProtocolBugs{
6569 IgnorePeerCurvePreferences: true,
6570 },
6571 },
6572 flags: []string{"-p384-only"},
6573 shouldFail: true,
6574 expectedError: ":WRONG_CURVE:",
6575 })
6576
David Benjamin4f921572016-07-17 14:20:10 +02006577 testCases = append(testCases, testCase{
6578 // TODO(davidben): Add a TLS 1.3 version where
6579 // HelloRetryRequest requests an unsupported curve.
6580 name: "UnsupportedCurve-ServerHello-TLS13",
6581 config: Config{
6582 MaxVersion: VersionTLS12,
6583 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6584 CurvePreferences: []CurveID{CurveP384},
6585 Bugs: ProtocolBugs{
6586 SendCurve: CurveP256,
6587 },
6588 },
6589 flags: []string{"-p384-only"},
6590 shouldFail: true,
6591 expectedError: ":WRONG_CURVE:",
6592 })
6593
David Benjamin4c3ddf72016-06-29 18:13:53 -04006594 // Test invalid curve points.
6595 testCases = append(testCases, testCase{
6596 name: "InvalidECDHPoint-Client",
6597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006598 MaxVersion: VersionTLS12,
6599 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6600 CurvePreferences: []CurveID{CurveP256},
6601 Bugs: ProtocolBugs{
6602 InvalidECDHPoint: true,
6603 },
6604 },
6605 shouldFail: true,
6606 expectedError: ":INVALID_ENCODING:",
6607 })
6608 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006609 name: "InvalidECDHPoint-Client-TLS13",
6610 config: Config{
6611 MaxVersion: VersionTLS13,
6612 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6613 CurvePreferences: []CurveID{CurveP256},
6614 Bugs: ProtocolBugs{
6615 InvalidECDHPoint: true,
6616 },
6617 },
6618 shouldFail: true,
6619 expectedError: ":INVALID_ENCODING:",
6620 })
6621 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006622 testType: serverTest,
6623 name: "InvalidECDHPoint-Server",
6624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006625 MaxVersion: VersionTLS12,
6626 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6627 CurvePreferences: []CurveID{CurveP256},
6628 Bugs: ProtocolBugs{
6629 InvalidECDHPoint: true,
6630 },
6631 },
6632 shouldFail: true,
6633 expectedError: ":INVALID_ENCODING:",
6634 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006635 testCases = append(testCases, testCase{
6636 testType: serverTest,
6637 name: "InvalidECDHPoint-Server-TLS13",
6638 config: Config{
6639 MaxVersion: VersionTLS13,
6640 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6641 CurvePreferences: []CurveID{CurveP256},
6642 Bugs: ProtocolBugs{
6643 InvalidECDHPoint: true,
6644 },
6645 },
6646 shouldFail: true,
6647 expectedError: ":INVALID_ENCODING:",
6648 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006649}
6650
Matt Braithwaite54217e42016-06-13 13:03:47 -07006651func addCECPQ1Tests() {
6652 testCases = append(testCases, testCase{
6653 testType: clientTest,
6654 name: "CECPQ1-Client-BadX25519Part",
6655 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006656 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006657 MinVersion: VersionTLS12,
6658 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6659 Bugs: ProtocolBugs{
6660 CECPQ1BadX25519Part: true,
6661 },
6662 },
6663 flags: []string{"-cipher", "kCECPQ1"},
6664 shouldFail: true,
6665 expectedLocalError: "local error: bad record MAC",
6666 })
6667 testCases = append(testCases, testCase{
6668 testType: clientTest,
6669 name: "CECPQ1-Client-BadNewhopePart",
6670 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006671 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006672 MinVersion: VersionTLS12,
6673 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6674 Bugs: ProtocolBugs{
6675 CECPQ1BadNewhopePart: true,
6676 },
6677 },
6678 flags: []string{"-cipher", "kCECPQ1"},
6679 shouldFail: true,
6680 expectedLocalError: "local error: bad record MAC",
6681 })
6682 testCases = append(testCases, testCase{
6683 testType: serverTest,
6684 name: "CECPQ1-Server-BadX25519Part",
6685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006686 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006687 MinVersion: VersionTLS12,
6688 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6689 Bugs: ProtocolBugs{
6690 CECPQ1BadX25519Part: true,
6691 },
6692 },
6693 flags: []string{"-cipher", "kCECPQ1"},
6694 shouldFail: true,
6695 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6696 })
6697 testCases = append(testCases, testCase{
6698 testType: serverTest,
6699 name: "CECPQ1-Server-BadNewhopePart",
6700 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006701 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006702 MinVersion: VersionTLS12,
6703 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6704 Bugs: ProtocolBugs{
6705 CECPQ1BadNewhopePart: true,
6706 },
6707 },
6708 flags: []string{"-cipher", "kCECPQ1"},
6709 shouldFail: true,
6710 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6711 })
6712}
6713
David Benjamin4cc36ad2015-12-19 14:23:26 -05006714func addKeyExchangeInfoTests() {
6715 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006716 name: "KeyExchangeInfo-DHE-Client",
6717 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006718 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006719 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6720 Bugs: ProtocolBugs{
6721 // This is a 1234-bit prime number, generated
6722 // with:
6723 // openssl gendh 1234 | openssl asn1parse -i
6724 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6725 },
6726 },
David Benjamin9e68f192016-06-30 14:55:33 -04006727 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006728 })
6729 testCases = append(testCases, testCase{
6730 testType: serverTest,
6731 name: "KeyExchangeInfo-DHE-Server",
6732 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006733 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006734 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6735 },
6736 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006737 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006738 })
6739
6740 testCases = append(testCases, testCase{
6741 name: "KeyExchangeInfo-ECDHE-Client",
6742 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006743 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006744 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6745 CurvePreferences: []CurveID{CurveX25519},
6746 },
David Benjamin9e68f192016-06-30 14:55:33 -04006747 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006748 })
6749 testCases = append(testCases, testCase{
6750 testType: serverTest,
6751 name: "KeyExchangeInfo-ECDHE-Server",
6752 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006753 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006754 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6755 CurvePreferences: []CurveID{CurveX25519},
6756 },
David Benjamin9e68f192016-06-30 14:55:33 -04006757 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006758 })
6759}
6760
David Benjaminc9ae27c2016-06-24 22:56:37 -04006761func addTLS13RecordTests() {
6762 testCases = append(testCases, testCase{
6763 name: "TLS13-RecordPadding",
6764 config: Config{
6765 MaxVersion: VersionTLS13,
6766 MinVersion: VersionTLS13,
6767 Bugs: ProtocolBugs{
6768 RecordPadding: 10,
6769 },
6770 },
6771 })
6772
6773 testCases = append(testCases, testCase{
6774 name: "TLS13-EmptyRecords",
6775 config: Config{
6776 MaxVersion: VersionTLS13,
6777 MinVersion: VersionTLS13,
6778 Bugs: ProtocolBugs{
6779 OmitRecordContents: true,
6780 },
6781 },
6782 shouldFail: true,
6783 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6784 })
6785
6786 testCases = append(testCases, testCase{
6787 name: "TLS13-OnlyPadding",
6788 config: Config{
6789 MaxVersion: VersionTLS13,
6790 MinVersion: VersionTLS13,
6791 Bugs: ProtocolBugs{
6792 OmitRecordContents: true,
6793 RecordPadding: 10,
6794 },
6795 },
6796 shouldFail: true,
6797 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6798 })
6799
6800 testCases = append(testCases, testCase{
6801 name: "TLS13-WrongOuterRecord",
6802 config: Config{
6803 MaxVersion: VersionTLS13,
6804 MinVersion: VersionTLS13,
6805 Bugs: ProtocolBugs{
6806 OuterRecordType: recordTypeHandshake,
6807 },
6808 },
6809 shouldFail: true,
6810 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
6811 })
6812}
6813
David Benjamin82261be2016-07-07 14:32:50 -07006814func addChangeCipherSpecTests() {
6815 // Test missing ChangeCipherSpecs.
6816 testCases = append(testCases, testCase{
6817 name: "SkipChangeCipherSpec-Client",
6818 config: Config{
6819 MaxVersion: VersionTLS12,
6820 Bugs: ProtocolBugs{
6821 SkipChangeCipherSpec: true,
6822 },
6823 },
6824 shouldFail: true,
6825 expectedError: ":UNEXPECTED_RECORD:",
6826 })
6827 testCases = append(testCases, testCase{
6828 testType: serverTest,
6829 name: "SkipChangeCipherSpec-Server",
6830 config: Config{
6831 MaxVersion: VersionTLS12,
6832 Bugs: ProtocolBugs{
6833 SkipChangeCipherSpec: true,
6834 },
6835 },
6836 shouldFail: true,
6837 expectedError: ":UNEXPECTED_RECORD:",
6838 })
6839 testCases = append(testCases, testCase{
6840 testType: serverTest,
6841 name: "SkipChangeCipherSpec-Server-NPN",
6842 config: Config{
6843 MaxVersion: VersionTLS12,
6844 NextProtos: []string{"bar"},
6845 Bugs: ProtocolBugs{
6846 SkipChangeCipherSpec: true,
6847 },
6848 },
6849 flags: []string{
6850 "-advertise-npn", "\x03foo\x03bar\x03baz",
6851 },
6852 shouldFail: true,
6853 expectedError: ":UNEXPECTED_RECORD:",
6854 })
6855
6856 // Test synchronization between the handshake and ChangeCipherSpec.
6857 // Partial post-CCS handshake messages before ChangeCipherSpec should be
6858 // rejected. Test both with and without handshake packing to handle both
6859 // when the partial post-CCS message is in its own record and when it is
6860 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07006861 for _, packed := range []bool{false, true} {
6862 var suffix string
6863 if packed {
6864 suffix = "-Packed"
6865 }
6866
6867 testCases = append(testCases, testCase{
6868 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
6869 config: Config{
6870 MaxVersion: VersionTLS12,
6871 Bugs: ProtocolBugs{
6872 FragmentAcrossChangeCipherSpec: true,
6873 PackHandshakeFlight: packed,
6874 },
6875 },
6876 shouldFail: true,
6877 expectedError: ":UNEXPECTED_RECORD:",
6878 })
6879 testCases = append(testCases, testCase{
6880 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
6881 config: Config{
6882 MaxVersion: VersionTLS12,
6883 },
6884 resumeSession: true,
6885 resumeConfig: &Config{
6886 MaxVersion: VersionTLS12,
6887 Bugs: ProtocolBugs{
6888 FragmentAcrossChangeCipherSpec: true,
6889 PackHandshakeFlight: packed,
6890 },
6891 },
6892 shouldFail: true,
6893 expectedError: ":UNEXPECTED_RECORD:",
6894 })
6895 testCases = append(testCases, testCase{
6896 testType: serverTest,
6897 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
6898 config: Config{
6899 MaxVersion: VersionTLS12,
6900 Bugs: ProtocolBugs{
6901 FragmentAcrossChangeCipherSpec: true,
6902 PackHandshakeFlight: packed,
6903 },
6904 },
6905 shouldFail: true,
6906 expectedError: ":UNEXPECTED_RECORD:",
6907 })
6908 testCases = append(testCases, testCase{
6909 testType: serverTest,
6910 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
6911 config: Config{
6912 MaxVersion: VersionTLS12,
6913 },
6914 resumeSession: true,
6915 resumeConfig: &Config{
6916 MaxVersion: VersionTLS12,
6917 Bugs: ProtocolBugs{
6918 FragmentAcrossChangeCipherSpec: true,
6919 PackHandshakeFlight: packed,
6920 },
6921 },
6922 shouldFail: true,
6923 expectedError: ":UNEXPECTED_RECORD:",
6924 })
6925 testCases = append(testCases, testCase{
6926 testType: serverTest,
6927 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
6928 config: Config{
6929 MaxVersion: VersionTLS12,
6930 NextProtos: []string{"bar"},
6931 Bugs: ProtocolBugs{
6932 FragmentAcrossChangeCipherSpec: true,
6933 PackHandshakeFlight: packed,
6934 },
6935 },
6936 flags: []string{
6937 "-advertise-npn", "\x03foo\x03bar\x03baz",
6938 },
6939 shouldFail: true,
6940 expectedError: ":UNEXPECTED_RECORD:",
6941 })
6942 }
6943
David Benjamin61672812016-07-14 23:10:43 -04006944 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
6945 // messages in the handshake queue. Do this by testing the server
6946 // reading the client Finished, reversing the flight so Finished comes
6947 // first.
6948 testCases = append(testCases, testCase{
6949 protocol: dtls,
6950 testType: serverTest,
6951 name: "SendUnencryptedFinished-DTLS",
6952 config: Config{
6953 MaxVersion: VersionTLS12,
6954 Bugs: ProtocolBugs{
6955 SendUnencryptedFinished: true,
6956 ReverseHandshakeFragments: true,
6957 },
6958 },
6959 shouldFail: true,
6960 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6961 })
6962
Steven Valdez143e8b32016-07-11 13:19:03 -04006963 // Test synchronization between encryption changes and the handshake in
6964 // TLS 1.3, where ChangeCipherSpec is implicit.
6965 testCases = append(testCases, testCase{
6966 name: "PartialEncryptedExtensionsWithServerHello",
6967 config: Config{
6968 MaxVersion: VersionTLS13,
6969 Bugs: ProtocolBugs{
6970 PartialEncryptedExtensionsWithServerHello: true,
6971 },
6972 },
6973 shouldFail: true,
6974 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6975 })
6976 testCases = append(testCases, testCase{
6977 testType: serverTest,
6978 name: "PartialClientFinishedWithClientHello",
6979 config: Config{
6980 MaxVersion: VersionTLS13,
6981 Bugs: ProtocolBugs{
6982 PartialClientFinishedWithClientHello: true,
6983 },
6984 },
6985 shouldFail: true,
6986 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
6987 })
6988
David Benjamin82261be2016-07-07 14:32:50 -07006989 // Test that early ChangeCipherSpecs are handled correctly.
6990 testCases = append(testCases, testCase{
6991 testType: serverTest,
6992 name: "EarlyChangeCipherSpec-server-1",
6993 config: Config{
6994 MaxVersion: VersionTLS12,
6995 Bugs: ProtocolBugs{
6996 EarlyChangeCipherSpec: 1,
6997 },
6998 },
6999 shouldFail: true,
7000 expectedError: ":UNEXPECTED_RECORD:",
7001 })
7002 testCases = append(testCases, testCase{
7003 testType: serverTest,
7004 name: "EarlyChangeCipherSpec-server-2",
7005 config: Config{
7006 MaxVersion: VersionTLS12,
7007 Bugs: ProtocolBugs{
7008 EarlyChangeCipherSpec: 2,
7009 },
7010 },
7011 shouldFail: true,
7012 expectedError: ":UNEXPECTED_RECORD:",
7013 })
7014 testCases = append(testCases, testCase{
7015 protocol: dtls,
7016 name: "StrayChangeCipherSpec",
7017 config: Config{
7018 // TODO(davidben): Once DTLS 1.3 exists, test
7019 // that stray ChangeCipherSpec messages are
7020 // rejected.
7021 MaxVersion: VersionTLS12,
7022 Bugs: ProtocolBugs{
7023 StrayChangeCipherSpec: true,
7024 },
7025 },
7026 })
7027
7028 // Test that the contents of ChangeCipherSpec are checked.
7029 testCases = append(testCases, testCase{
7030 name: "BadChangeCipherSpec-1",
7031 config: Config{
7032 MaxVersion: VersionTLS12,
7033 Bugs: ProtocolBugs{
7034 BadChangeCipherSpec: []byte{2},
7035 },
7036 },
7037 shouldFail: true,
7038 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7039 })
7040 testCases = append(testCases, testCase{
7041 name: "BadChangeCipherSpec-2",
7042 config: Config{
7043 MaxVersion: VersionTLS12,
7044 Bugs: ProtocolBugs{
7045 BadChangeCipherSpec: []byte{1, 1},
7046 },
7047 },
7048 shouldFail: true,
7049 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7050 })
7051 testCases = append(testCases, testCase{
7052 protocol: dtls,
7053 name: "BadChangeCipherSpec-DTLS-1",
7054 config: Config{
7055 MaxVersion: VersionTLS12,
7056 Bugs: ProtocolBugs{
7057 BadChangeCipherSpec: []byte{2},
7058 },
7059 },
7060 shouldFail: true,
7061 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7062 })
7063 testCases = append(testCases, testCase{
7064 protocol: dtls,
7065 name: "BadChangeCipherSpec-DTLS-2",
7066 config: Config{
7067 MaxVersion: VersionTLS12,
7068 Bugs: ProtocolBugs{
7069 BadChangeCipherSpec: []byte{1, 1},
7070 },
7071 },
7072 shouldFail: true,
7073 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7074 })
7075}
7076
David Benjamin0b8d5da2016-07-15 00:39:56 -04007077func addWrongMessageTypeTests() {
7078 for _, protocol := range []protocol{tls, dtls} {
7079 var suffix string
7080 if protocol == dtls {
7081 suffix = "-DTLS"
7082 }
7083
7084 testCases = append(testCases, testCase{
7085 protocol: protocol,
7086 testType: serverTest,
7087 name: "WrongMessageType-ClientHello" + suffix,
7088 config: Config{
7089 MaxVersion: VersionTLS12,
7090 Bugs: ProtocolBugs{
7091 SendWrongMessageType: typeClientHello,
7092 },
7093 },
7094 shouldFail: true,
7095 expectedError: ":UNEXPECTED_MESSAGE:",
7096 expectedLocalError: "remote error: unexpected message",
7097 })
7098
7099 if protocol == dtls {
7100 testCases = append(testCases, testCase{
7101 protocol: protocol,
7102 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7103 config: Config{
7104 MaxVersion: VersionTLS12,
7105 Bugs: ProtocolBugs{
7106 SendWrongMessageType: typeHelloVerifyRequest,
7107 },
7108 },
7109 shouldFail: true,
7110 expectedError: ":UNEXPECTED_MESSAGE:",
7111 expectedLocalError: "remote error: unexpected message",
7112 })
7113 }
7114
7115 testCases = append(testCases, testCase{
7116 protocol: protocol,
7117 name: "WrongMessageType-ServerHello" + suffix,
7118 config: Config{
7119 MaxVersion: VersionTLS12,
7120 Bugs: ProtocolBugs{
7121 SendWrongMessageType: typeServerHello,
7122 },
7123 },
7124 shouldFail: true,
7125 expectedError: ":UNEXPECTED_MESSAGE:",
7126 expectedLocalError: "remote error: unexpected message",
7127 })
7128
7129 testCases = append(testCases, testCase{
7130 protocol: protocol,
7131 name: "WrongMessageType-ServerCertificate" + suffix,
7132 config: Config{
7133 MaxVersion: VersionTLS12,
7134 Bugs: ProtocolBugs{
7135 SendWrongMessageType: typeCertificate,
7136 },
7137 },
7138 shouldFail: true,
7139 expectedError: ":UNEXPECTED_MESSAGE:",
7140 expectedLocalError: "remote error: unexpected message",
7141 })
7142
7143 testCases = append(testCases, testCase{
7144 protocol: protocol,
7145 name: "WrongMessageType-CertificateStatus" + suffix,
7146 config: Config{
7147 MaxVersion: VersionTLS12,
7148 Bugs: ProtocolBugs{
7149 SendWrongMessageType: typeCertificateStatus,
7150 },
7151 },
7152 flags: []string{"-enable-ocsp-stapling"},
7153 shouldFail: true,
7154 expectedError: ":UNEXPECTED_MESSAGE:",
7155 expectedLocalError: "remote error: unexpected message",
7156 })
7157
7158 testCases = append(testCases, testCase{
7159 protocol: protocol,
7160 name: "WrongMessageType-ServerKeyExchange" + suffix,
7161 config: Config{
7162 MaxVersion: VersionTLS12,
7163 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7164 Bugs: ProtocolBugs{
7165 SendWrongMessageType: typeServerKeyExchange,
7166 },
7167 },
7168 shouldFail: true,
7169 expectedError: ":UNEXPECTED_MESSAGE:",
7170 expectedLocalError: "remote error: unexpected message",
7171 })
7172
7173 testCases = append(testCases, testCase{
7174 protocol: protocol,
7175 name: "WrongMessageType-CertificateRequest" + suffix,
7176 config: Config{
7177 MaxVersion: VersionTLS12,
7178 ClientAuth: RequireAnyClientCert,
7179 Bugs: ProtocolBugs{
7180 SendWrongMessageType: typeCertificateRequest,
7181 },
7182 },
7183 shouldFail: true,
7184 expectedError: ":UNEXPECTED_MESSAGE:",
7185 expectedLocalError: "remote error: unexpected message",
7186 })
7187
7188 testCases = append(testCases, testCase{
7189 protocol: protocol,
7190 name: "WrongMessageType-ServerHelloDone" + suffix,
7191 config: Config{
7192 MaxVersion: VersionTLS12,
7193 Bugs: ProtocolBugs{
7194 SendWrongMessageType: typeServerHelloDone,
7195 },
7196 },
7197 shouldFail: true,
7198 expectedError: ":UNEXPECTED_MESSAGE:",
7199 expectedLocalError: "remote error: unexpected message",
7200 })
7201
7202 testCases = append(testCases, testCase{
7203 testType: serverTest,
7204 protocol: protocol,
7205 name: "WrongMessageType-ClientCertificate" + suffix,
7206 config: Config{
7207 Certificates: []Certificate{rsaCertificate},
7208 MaxVersion: VersionTLS12,
7209 Bugs: ProtocolBugs{
7210 SendWrongMessageType: typeCertificate,
7211 },
7212 },
7213 flags: []string{"-require-any-client-certificate"},
7214 shouldFail: true,
7215 expectedError: ":UNEXPECTED_MESSAGE:",
7216 expectedLocalError: "remote error: unexpected message",
7217 })
7218
7219 testCases = append(testCases, testCase{
7220 testType: serverTest,
7221 protocol: protocol,
7222 name: "WrongMessageType-CertificateVerify" + suffix,
7223 config: Config{
7224 Certificates: []Certificate{rsaCertificate},
7225 MaxVersion: VersionTLS12,
7226 Bugs: ProtocolBugs{
7227 SendWrongMessageType: typeCertificateVerify,
7228 },
7229 },
7230 flags: []string{"-require-any-client-certificate"},
7231 shouldFail: true,
7232 expectedError: ":UNEXPECTED_MESSAGE:",
7233 expectedLocalError: "remote error: unexpected message",
7234 })
7235
7236 testCases = append(testCases, testCase{
7237 testType: serverTest,
7238 protocol: protocol,
7239 name: "WrongMessageType-ClientKeyExchange" + suffix,
7240 config: Config{
7241 MaxVersion: VersionTLS12,
7242 Bugs: ProtocolBugs{
7243 SendWrongMessageType: typeClientKeyExchange,
7244 },
7245 },
7246 shouldFail: true,
7247 expectedError: ":UNEXPECTED_MESSAGE:",
7248 expectedLocalError: "remote error: unexpected message",
7249 })
7250
7251 if protocol != dtls {
7252 testCases = append(testCases, testCase{
7253 testType: serverTest,
7254 protocol: protocol,
7255 name: "WrongMessageType-NextProtocol" + suffix,
7256 config: Config{
7257 MaxVersion: VersionTLS12,
7258 NextProtos: []string{"bar"},
7259 Bugs: ProtocolBugs{
7260 SendWrongMessageType: typeNextProtocol,
7261 },
7262 },
7263 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7264 shouldFail: true,
7265 expectedError: ":UNEXPECTED_MESSAGE:",
7266 expectedLocalError: "remote error: unexpected message",
7267 })
7268
7269 testCases = append(testCases, testCase{
7270 testType: serverTest,
7271 protocol: protocol,
7272 name: "WrongMessageType-ChannelID" + suffix,
7273 config: Config{
7274 MaxVersion: VersionTLS12,
7275 ChannelID: channelIDKey,
7276 Bugs: ProtocolBugs{
7277 SendWrongMessageType: typeChannelID,
7278 },
7279 },
7280 flags: []string{
7281 "-expect-channel-id",
7282 base64.StdEncoding.EncodeToString(channelIDBytes),
7283 },
7284 shouldFail: true,
7285 expectedError: ":UNEXPECTED_MESSAGE:",
7286 expectedLocalError: "remote error: unexpected message",
7287 })
7288 }
7289
7290 testCases = append(testCases, testCase{
7291 testType: serverTest,
7292 protocol: protocol,
7293 name: "WrongMessageType-ClientFinished" + suffix,
7294 config: Config{
7295 MaxVersion: VersionTLS12,
7296 Bugs: ProtocolBugs{
7297 SendWrongMessageType: typeFinished,
7298 },
7299 },
7300 shouldFail: true,
7301 expectedError: ":UNEXPECTED_MESSAGE:",
7302 expectedLocalError: "remote error: unexpected message",
7303 })
7304
7305 testCases = append(testCases, testCase{
7306 protocol: protocol,
7307 name: "WrongMessageType-NewSessionTicket" + suffix,
7308 config: Config{
7309 MaxVersion: VersionTLS12,
7310 Bugs: ProtocolBugs{
7311 SendWrongMessageType: typeNewSessionTicket,
7312 },
7313 },
7314 shouldFail: true,
7315 expectedError: ":UNEXPECTED_MESSAGE:",
7316 expectedLocalError: "remote error: unexpected message",
7317 })
7318
7319 testCases = append(testCases, testCase{
7320 protocol: protocol,
7321 name: "WrongMessageType-ServerFinished" + suffix,
7322 config: Config{
7323 MaxVersion: VersionTLS12,
7324 Bugs: ProtocolBugs{
7325 SendWrongMessageType: typeFinished,
7326 },
7327 },
7328 shouldFail: true,
7329 expectedError: ":UNEXPECTED_MESSAGE:",
7330 expectedLocalError: "remote error: unexpected message",
7331 })
7332
7333 }
7334}
7335
Steven Valdez143e8b32016-07-11 13:19:03 -04007336func addTLS13WrongMessageTypeTests() {
7337 testCases = append(testCases, testCase{
7338 testType: serverTest,
7339 name: "WrongMessageType-TLS13-ClientHello",
7340 config: Config{
7341 MaxVersion: VersionTLS13,
7342 Bugs: ProtocolBugs{
7343 SendWrongMessageType: typeClientHello,
7344 },
7345 },
7346 shouldFail: true,
7347 expectedError: ":UNEXPECTED_MESSAGE:",
7348 expectedLocalError: "remote error: unexpected message",
7349 })
7350
7351 testCases = append(testCases, testCase{
7352 name: "WrongMessageType-TLS13-ServerHello",
7353 config: Config{
7354 MaxVersion: VersionTLS13,
7355 Bugs: ProtocolBugs{
7356 SendWrongMessageType: typeServerHello,
7357 },
7358 },
7359 shouldFail: true,
7360 expectedError: ":UNEXPECTED_MESSAGE:",
7361 // The alert comes in with the wrong encryption.
7362 expectedLocalError: "local error: bad record MAC",
7363 })
7364
7365 testCases = append(testCases, testCase{
7366 name: "WrongMessageType-TLS13-EncryptedExtensions",
7367 config: Config{
7368 MaxVersion: VersionTLS13,
7369 Bugs: ProtocolBugs{
7370 SendWrongMessageType: typeEncryptedExtensions,
7371 },
7372 },
7373 shouldFail: true,
7374 expectedError: ":UNEXPECTED_MESSAGE:",
7375 expectedLocalError: "remote error: unexpected message",
7376 })
7377
7378 testCases = append(testCases, testCase{
7379 name: "WrongMessageType-TLS13-CertificateRequest",
7380 config: Config{
7381 MaxVersion: VersionTLS13,
7382 ClientAuth: RequireAnyClientCert,
7383 Bugs: ProtocolBugs{
7384 SendWrongMessageType: typeCertificateRequest,
7385 },
7386 },
7387 shouldFail: true,
7388 expectedError: ":UNEXPECTED_MESSAGE:",
7389 expectedLocalError: "remote error: unexpected message",
7390 })
7391
7392 testCases = append(testCases, testCase{
7393 name: "WrongMessageType-TLS13-ServerCertificate",
7394 config: Config{
7395 MaxVersion: VersionTLS13,
7396 Bugs: ProtocolBugs{
7397 SendWrongMessageType: typeCertificate,
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":UNEXPECTED_MESSAGE:",
7402 expectedLocalError: "remote error: unexpected message",
7403 })
7404
7405 testCases = append(testCases, testCase{
7406 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7407 config: Config{
7408 MaxVersion: VersionTLS13,
7409 Bugs: ProtocolBugs{
7410 SendWrongMessageType: typeCertificateVerify,
7411 },
7412 },
7413 shouldFail: true,
7414 expectedError: ":UNEXPECTED_MESSAGE:",
7415 expectedLocalError: "remote error: unexpected message",
7416 })
7417
7418 testCases = append(testCases, testCase{
7419 name: "WrongMessageType-TLS13-ServerFinished",
7420 config: Config{
7421 MaxVersion: VersionTLS13,
7422 Bugs: ProtocolBugs{
7423 SendWrongMessageType: typeFinished,
7424 },
7425 },
7426 shouldFail: true,
7427 expectedError: ":UNEXPECTED_MESSAGE:",
7428 expectedLocalError: "remote error: unexpected message",
7429 })
7430
7431 testCases = append(testCases, testCase{
7432 testType: serverTest,
7433 name: "WrongMessageType-TLS13-ClientCertificate",
7434 config: Config{
7435 Certificates: []Certificate{rsaCertificate},
7436 MaxVersion: VersionTLS13,
7437 Bugs: ProtocolBugs{
7438 SendWrongMessageType: typeCertificate,
7439 },
7440 },
7441 flags: []string{"-require-any-client-certificate"},
7442 shouldFail: true,
7443 expectedError: ":UNEXPECTED_MESSAGE:",
7444 expectedLocalError: "remote error: unexpected message",
7445 })
7446
7447 testCases = append(testCases, testCase{
7448 testType: serverTest,
7449 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7450 config: Config{
7451 Certificates: []Certificate{rsaCertificate},
7452 MaxVersion: VersionTLS13,
7453 Bugs: ProtocolBugs{
7454 SendWrongMessageType: typeCertificateVerify,
7455 },
7456 },
7457 flags: []string{"-require-any-client-certificate"},
7458 shouldFail: true,
7459 expectedError: ":UNEXPECTED_MESSAGE:",
7460 expectedLocalError: "remote error: unexpected message",
7461 })
7462
7463 testCases = append(testCases, testCase{
7464 testType: serverTest,
7465 name: "WrongMessageType-TLS13-ClientFinished",
7466 config: Config{
7467 MaxVersion: VersionTLS13,
7468 Bugs: ProtocolBugs{
7469 SendWrongMessageType: typeFinished,
7470 },
7471 },
7472 shouldFail: true,
7473 expectedError: ":UNEXPECTED_MESSAGE:",
7474 expectedLocalError: "remote error: unexpected message",
7475 })
7476}
7477
7478func addTLS13HandshakeTests() {
7479 testCases = append(testCases, testCase{
7480 testType: clientTest,
7481 name: "MissingKeyShare-Client",
7482 config: Config{
7483 MaxVersion: VersionTLS13,
7484 Bugs: ProtocolBugs{
7485 MissingKeyShare: true,
7486 },
7487 },
7488 shouldFail: true,
7489 expectedError: ":MISSING_KEY_SHARE:",
7490 })
7491
7492 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007493 testType: serverTest,
7494 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007495 config: Config{
7496 MaxVersion: VersionTLS13,
7497 Bugs: ProtocolBugs{
7498 MissingKeyShare: true,
7499 },
7500 },
7501 shouldFail: true,
7502 expectedError: ":MISSING_KEY_SHARE:",
7503 })
7504
7505 testCases = append(testCases, testCase{
7506 testType: clientTest,
7507 name: "ClientHelloMissingKeyShare",
7508 config: Config{
7509 MaxVersion: VersionTLS13,
7510 Bugs: ProtocolBugs{
7511 MissingKeyShare: true,
7512 },
7513 },
7514 shouldFail: true,
7515 expectedError: ":MISSING_KEY_SHARE:",
7516 })
7517
7518 testCases = append(testCases, testCase{
7519 testType: clientTest,
7520 name: "MissingKeyShare",
7521 config: Config{
7522 MaxVersion: VersionTLS13,
7523 Bugs: ProtocolBugs{
7524 MissingKeyShare: true,
7525 },
7526 },
7527 shouldFail: true,
7528 expectedError: ":MISSING_KEY_SHARE:",
7529 })
7530
7531 testCases = append(testCases, testCase{
7532 testType: serverTest,
7533 name: "DuplicateKeyShares",
7534 config: Config{
7535 MaxVersion: VersionTLS13,
7536 Bugs: ProtocolBugs{
7537 DuplicateKeyShares: true,
7538 },
7539 },
7540 })
7541
7542 testCases = append(testCases, testCase{
7543 testType: clientTest,
7544 name: "EmptyEncryptedExtensions",
7545 config: Config{
7546 MaxVersion: VersionTLS13,
7547 Bugs: ProtocolBugs{
7548 EmptyEncryptedExtensions: true,
7549 },
7550 },
7551 shouldFail: true,
7552 expectedLocalError: "remote error: error decoding message",
7553 })
7554
7555 testCases = append(testCases, testCase{
7556 testType: clientTest,
7557 name: "EncryptedExtensionsWithKeyShare",
7558 config: Config{
7559 MaxVersion: VersionTLS13,
7560 Bugs: ProtocolBugs{
7561 EncryptedExtensionsWithKeyShare: true,
7562 },
7563 },
7564 shouldFail: true,
7565 expectedLocalError: "remote error: unsupported extension",
7566 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007567
7568 testCases = append(testCases, testCase{
7569 testType: serverTest,
7570 name: "SendHelloRetryRequest",
7571 config: Config{
7572 MaxVersion: VersionTLS13,
7573 // Require a HelloRetryRequest for every curve.
7574 DefaultCurves: []CurveID{},
7575 },
7576 expectedCurveID: CurveX25519,
7577 })
7578
7579 testCases = append(testCases, testCase{
7580 testType: serverTest,
7581 name: "SendHelloRetryRequest-2",
7582 config: Config{
7583 MaxVersion: VersionTLS13,
7584 DefaultCurves: []CurveID{CurveP384},
7585 },
7586 // Although the ClientHello did not predict our preferred curve,
7587 // we always select it whether it is predicted or not.
7588 expectedCurveID: CurveX25519,
7589 })
7590
7591 testCases = append(testCases, testCase{
7592 name: "UnknownCurve-HelloRetryRequest",
7593 config: Config{
7594 MaxVersion: VersionTLS13,
7595 // P-384 requires HelloRetryRequest in BoringSSL.
7596 CurvePreferences: []CurveID{CurveP384},
7597 Bugs: ProtocolBugs{
7598 SendHelloRetryRequestCurve: bogusCurve,
7599 },
7600 },
7601 shouldFail: true,
7602 expectedError: ":WRONG_CURVE:",
7603 })
7604
7605 testCases = append(testCases, testCase{
7606 name: "DisabledCurve-HelloRetryRequest",
7607 config: Config{
7608 MaxVersion: VersionTLS13,
7609 CurvePreferences: []CurveID{CurveP256},
7610 Bugs: ProtocolBugs{
7611 IgnorePeerCurvePreferences: true,
7612 },
7613 },
7614 flags: []string{"-p384-only"},
7615 shouldFail: true,
7616 expectedError: ":WRONG_CURVE:",
7617 })
7618
7619 testCases = append(testCases, testCase{
7620 name: "UnnecessaryHelloRetryRequest",
7621 config: Config{
7622 MaxVersion: VersionTLS13,
7623 Bugs: ProtocolBugs{
7624 UnnecessaryHelloRetryRequest: true,
7625 },
7626 },
7627 shouldFail: true,
7628 expectedError: ":WRONG_CURVE:",
7629 })
7630
7631 testCases = append(testCases, testCase{
7632 name: "SecondHelloRetryRequest",
7633 config: Config{
7634 MaxVersion: VersionTLS13,
7635 // P-384 requires HelloRetryRequest in BoringSSL.
7636 CurvePreferences: []CurveID{CurveP384},
7637 Bugs: ProtocolBugs{
7638 SecondHelloRetryRequest: true,
7639 },
7640 },
7641 shouldFail: true,
7642 expectedError: ":UNEXPECTED_MESSAGE:",
7643 })
7644
7645 testCases = append(testCases, testCase{
7646 testType: serverTest,
7647 name: "SecondClientHelloMissingKeyShare",
7648 config: Config{
7649 MaxVersion: VersionTLS13,
7650 DefaultCurves: []CurveID{},
7651 Bugs: ProtocolBugs{
7652 SecondClientHelloMissingKeyShare: true,
7653 },
7654 },
7655 shouldFail: true,
7656 expectedError: ":MISSING_KEY_SHARE:",
7657 })
7658
7659 testCases = append(testCases, testCase{
7660 testType: serverTest,
7661 name: "SecondClientHelloWrongCurve",
7662 config: Config{
7663 MaxVersion: VersionTLS13,
7664 DefaultCurves: []CurveID{},
7665 Bugs: ProtocolBugs{
7666 MisinterpretHelloRetryRequestCurve: CurveP521,
7667 },
7668 },
7669 shouldFail: true,
7670 expectedError: ":WRONG_CURVE:",
7671 })
7672
7673 testCases = append(testCases, testCase{
7674 name: "HelloRetryRequestVersionMismatch",
7675 config: Config{
7676 MaxVersion: VersionTLS13,
7677 // P-384 requires HelloRetryRequest in BoringSSL.
7678 CurvePreferences: []CurveID{CurveP384},
7679 Bugs: ProtocolBugs{
7680 SendServerHelloVersion: 0x0305,
7681 },
7682 },
7683 shouldFail: true,
7684 expectedError: ":WRONG_VERSION_NUMBER:",
7685 })
7686
7687 testCases = append(testCases, testCase{
7688 name: "HelloRetryRequestCurveMismatch",
7689 config: Config{
7690 MaxVersion: VersionTLS13,
7691 // P-384 requires HelloRetryRequest in BoringSSL.
7692 CurvePreferences: []CurveID{CurveP384},
7693 Bugs: ProtocolBugs{
7694 // Send P-384 (correct) in the HelloRetryRequest.
7695 SendHelloRetryRequestCurve: CurveP384,
7696 // But send P-256 in the ServerHello.
7697 SendCurve: CurveP256,
7698 },
7699 },
7700 shouldFail: true,
7701 expectedError: ":WRONG_CURVE:",
7702 })
7703
7704 // Test the server selecting a curve that requires a HelloRetryRequest
7705 // without sending it.
7706 testCases = append(testCases, testCase{
7707 name: "SkipHelloRetryRequest",
7708 config: Config{
7709 MaxVersion: VersionTLS13,
7710 // P-384 requires HelloRetryRequest in BoringSSL.
7711 CurvePreferences: []CurveID{CurveP384},
7712 Bugs: ProtocolBugs{
7713 SkipHelloRetryRequest: true,
7714 },
7715 },
7716 shouldFail: true,
7717 expectedError: ":WRONG_CURVE:",
7718 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007719}
7720
Adam Langley7c803a62015-06-15 15:35:05 -07007721func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007722 defer wg.Done()
7723
7724 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007725 var err error
7726
7727 if *mallocTest < 0 {
7728 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007729 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007730 } else {
7731 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7732 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007733 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007734 if err != nil {
7735 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7736 }
7737 break
7738 }
7739 }
7740 }
Adam Langley95c29f32014-06-20 12:00:00 -07007741 statusChan <- statusMsg{test: test, err: err}
7742 }
7743}
7744
7745type statusMsg struct {
7746 test *testCase
7747 started bool
7748 err error
7749}
7750
David Benjamin5f237bc2015-02-11 17:14:15 -05007751func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02007752 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007753
David Benjamin5f237bc2015-02-11 17:14:15 -05007754 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007755 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007756 if !*pipe {
7757 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007758 var erase string
7759 for i := 0; i < lineLen; i++ {
7760 erase += "\b \b"
7761 }
7762 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007763 }
7764
Adam Langley95c29f32014-06-20 12:00:00 -07007765 if msg.started {
7766 started++
7767 } else {
7768 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05007769
7770 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02007771 if msg.err == errUnimplemented {
7772 if *pipe {
7773 // Print each test instead of a status line.
7774 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
7775 }
7776 unimplemented++
7777 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
7778 } else {
7779 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
7780 failed++
7781 testOutput.addResult(msg.test.name, "FAIL")
7782 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007783 } else {
7784 if *pipe {
7785 // Print each test instead of a status line.
7786 fmt.Printf("PASSED (%s)\n", msg.test.name)
7787 }
7788 testOutput.addResult(msg.test.name, "PASS")
7789 }
Adam Langley95c29f32014-06-20 12:00:00 -07007790 }
7791
David Benjamin5f237bc2015-02-11 17:14:15 -05007792 if !*pipe {
7793 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02007794 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05007795 lineLen = len(line)
7796 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07007797 }
Adam Langley95c29f32014-06-20 12:00:00 -07007798 }
David Benjamin5f237bc2015-02-11 17:14:15 -05007799
7800 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07007801}
7802
7803func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07007804 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07007805 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07007806 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07007807
Adam Langley7c803a62015-06-15 15:35:05 -07007808 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007809 addCipherSuiteTests()
7810 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07007811 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07007812 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04007813 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08007814 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04007815 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05007816 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04007817 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04007818 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07007819 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07007820 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05007821 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07007822 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05007823 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04007824 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007825 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07007826 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05007827 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007828 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07007829 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05007830 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04007831 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07007832 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07007833 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04007834 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04007835 addTLS13WrongMessageTypeTests()
7836 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07007837
7838 var wg sync.WaitGroup
7839
Adam Langley7c803a62015-06-15 15:35:05 -07007840 statusChan := make(chan statusMsg, *numWorkers)
7841 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05007842 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07007843
David Benjamin025b3d32014-07-01 19:53:04 -04007844 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07007845
Adam Langley7c803a62015-06-15 15:35:05 -07007846 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07007847 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07007848 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07007849 }
7850
David Benjamin270f0a72016-03-17 14:41:36 -04007851 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04007852 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04007853 matched := true
7854 if len(*testToRun) != 0 {
7855 var err error
7856 matched, err = filepath.Match(*testToRun, testCases[i].name)
7857 if err != nil {
7858 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
7859 os.Exit(1)
7860 }
7861 }
7862
7863 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04007864 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04007865 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07007866 }
7867 }
David Benjamin17e12922016-07-28 18:04:43 -04007868
David Benjamin270f0a72016-03-17 14:41:36 -04007869 if !foundTest {
David Benjamin17e12922016-07-28 18:04:43 -04007870 fmt.Fprintf(os.Stderr, "No tests matched %q\n", *testToRun)
David Benjamin270f0a72016-03-17 14:41:36 -04007871 os.Exit(1)
7872 }
Adam Langley95c29f32014-06-20 12:00:00 -07007873
7874 close(testChan)
7875 wg.Wait()
7876 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05007877 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07007878
7879 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05007880
7881 if *jsonOutput != "" {
7882 if err := testOutput.writeTo(*jsonOutput); err != nil {
7883 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
7884 }
7885 }
David Benjamin2ab7a862015-04-04 17:02:18 -04007886
EKR842ae6c2016-07-27 09:22:05 +02007887 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
7888 os.Exit(1)
7889 }
7890
7891 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04007892 os.Exit(1)
7893 }
Adam Langley95c29f32014-06-20 12:00:00 -07007894}