blob: 09a6fccb44e00edca7ce29f80719ef91fa76dfd5 [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
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
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"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 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.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700297 // expectResumeRejected, if true, specifies that the attempted
298 // resumption must be rejected by the client. This is only valid for a
299 // serverTest.
300 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400301 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500302 // resumption. Unless newSessionsOnResume is set,
303 // SessionTicketKey, ServerSessionCache, and
304 // ClientSessionCache are copied from the initial connection's
305 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400306 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500307 // newSessionsOnResume, if true, will cause resumeConfig to
308 // use a different session resumption context.
309 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400310 // noSessionCache, if true, will cause the server to run without a
311 // session cache.
312 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400313 // sendPrefix sends a prefix on the socket before actually performing a
314 // handshake.
315 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400316 // shimWritesFirst controls whether the shim sends an initial "hello"
317 // message before doing a roundtrip with the runner.
318 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400319 // shimShutsDown, if true, runs a test where the shim shuts down the
320 // connection immediately after the handshake rather than echoing
321 // messages from the runner.
322 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400323 // renegotiate indicates the number of times the connection should be
324 // renegotiated during the exchange.
325 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400326 // sendHalfHelloRequest, if true, causes the server to send half a
327 // HelloRequest when the handshake completes.
328 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700329 // renegotiateCiphers is a list of ciphersuite ids that will be
330 // switched in just before renegotiation.
331 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500332 // replayWrites, if true, configures the underlying transport
333 // to replay every write it makes in DTLS tests.
334 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500335 // damageFirstWrite, if true, configures the underlying transport to
336 // damage the final byte of the first application data write.
337 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400338 // exportKeyingMaterial, if non-zero, configures the test to exchange
339 // keying material and verify they match.
340 exportKeyingMaterial int
341 exportLabel string
342 exportContext string
343 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400344 // flags, if not empty, contains a list of command-line flags that will
345 // be passed to the shim program.
346 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700347 // testTLSUnique, if true, causes the shim to send the tls-unique value
348 // which will be compared against the expected value.
349 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400350 // sendEmptyRecords is the number of consecutive empty records to send
351 // before and after the test message.
352 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400353 // sendWarningAlerts is the number of consecutive warning alerts to send
354 // before and after the test message.
355 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400356 // expectMessageDropped, if true, means the test message is expected to
357 // be dropped by the client rather than echoed back.
358 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700359}
360
Adam Langley7c803a62015-06-15 15:35:05 -0700361var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700362
David Benjamin9867b7d2016-03-01 23:25:48 -0500363func writeTranscript(test *testCase, isResume bool, data []byte) {
364 if len(data) == 0 {
365 return
366 }
367
368 protocol := "tls"
369 if test.protocol == dtls {
370 protocol = "dtls"
371 }
372
373 side := "client"
374 if test.testType == serverTest {
375 side = "server"
376 }
377
378 dir := path.Join(*transcriptDir, protocol, side)
379 if err := os.MkdirAll(dir, 0755); err != nil {
380 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
381 return
382 }
383
384 name := test.name
385 if isResume {
386 name += "-Resume"
387 } else {
388 name += "-Normal"
389 }
390
391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjamin8e6db492015-07-25 18:29:23 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400417 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500418
David Benjamin6fd297b2014-08-11 18:43:38 -0400419 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500420 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
421 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500422 }
423
David Benjamin9867b7d2016-03-01 23:25:48 -0500424 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500425 local, peer := "client", "server"
426 if test.testType == clientTest {
427 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500428 }
David Benjaminebda9b32015-11-02 15:33:18 -0500429 connDebug := &recordingConn{
430 Conn: conn,
431 isDatagram: test.protocol == dtls,
432 local: local,
433 peer: peer,
434 }
435 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500436 if *flagDebug {
437 defer connDebug.WriteTo(os.Stdout)
438 }
439 if len(*transcriptDir) != 0 {
440 defer func() {
441 writeTranscript(test, isResume, connDebug.Transcript())
442 }()
443 }
David Benjaminebda9b32015-11-02 15:33:18 -0500444
445 if config.Bugs.PacketAdaptor != nil {
446 config.Bugs.PacketAdaptor.debug = connDebug
447 }
448 }
449
450 if test.replayWrites {
451 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400452 }
453
David Benjamin3ed59772016-03-08 12:50:21 -0500454 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500455 if test.damageFirstWrite {
456 connDamage = newDamageAdaptor(conn)
457 conn = connDamage
458 }
459
David Benjamin6fd297b2014-08-11 18:43:38 -0400460 if test.sendPrefix != "" {
461 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
462 return err
463 }
David Benjamin98e882e2014-08-08 13:24:34 -0400464 }
465
David Benjamin1d5c83e2014-07-22 19:20:02 -0400466 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400467 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400468 if test.protocol == dtls {
469 tlsConn = DTLSServer(conn, config)
470 } else {
471 tlsConn = Server(conn, config)
472 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400473 } else {
474 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400475 if test.protocol == dtls {
476 tlsConn = DTLSClient(conn, config)
477 } else {
478 tlsConn = Client(conn, config)
479 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400480 }
David Benjamin30789da2015-08-29 22:56:45 -0400481 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400482
Adam Langley95c29f32014-06-20 12:00:00 -0700483 if err := tlsConn.Handshake(); err != nil {
484 return err
485 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700486
David Benjamin01fe8202014-09-24 15:21:44 -0400487 // TODO(davidben): move all per-connection expectations into a dedicated
488 // expectations struct that can be specified separately for the two
489 // legs.
490 expectedVersion := test.expectedVersion
491 if isResume && test.expectedResumeVersion != 0 {
492 expectedVersion = test.expectedResumeVersion
493 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700494 connState := tlsConn.ConnectionState()
495 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400496 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400497 }
498
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700499 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400500 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
501 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700502 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
503 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
504 }
David Benjamin90da8c82015-04-20 14:57:57 -0400505
David Benjamina08e49d2014-08-24 01:46:07 -0400506 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700507 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400508 if channelID == nil {
509 return fmt.Errorf("no channel ID negotiated")
510 }
511 if channelID.Curve != channelIDKey.Curve ||
512 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
513 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
514 return fmt.Errorf("incorrect channel ID")
515 }
516 }
517
David Benjaminae2888f2014-09-06 12:58:58 -0400518 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700519 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400520 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
521 }
522 }
523
David Benjaminc7ce9772015-10-09 19:32:41 -0400524 if test.expectNoNextProto {
525 if actual := connState.NegotiatedProtocol; actual != "" {
526 return fmt.Errorf("got unexpected next proto %s", actual)
527 }
528 }
529
David Benjaminfc7b0862014-09-06 13:21:53 -0400530 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700531 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400532 return fmt.Errorf("next proto type mismatch")
533 }
534 }
535
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700536 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500537 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
538 }
539
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100540 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300541 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100542 }
543
Paul Lietar4fac72e2015-09-09 13:44:55 +0100544 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
545 return fmt.Errorf("SCT list mismatch")
546 }
547
Nick Harper60edffd2016-06-21 15:19:24 -0700548 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
549 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400550 }
551
Steven Valdez5440fe02016-07-18 12:40:30 -0400552 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
553 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
554 }
555
David Benjaminc565ebb2015-04-03 04:06:36 -0400556 if test.exportKeyingMaterial > 0 {
557 actual := make([]byte, test.exportKeyingMaterial)
558 if _, err := io.ReadFull(tlsConn, actual); err != nil {
559 return err
560 }
561 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
562 if err != nil {
563 return err
564 }
565 if !bytes.Equal(actual, expected) {
566 return fmt.Errorf("keying material mismatch")
567 }
568 }
569
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700570 if test.testTLSUnique {
571 var peersValue [12]byte
572 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
573 return err
574 }
575 expected := tlsConn.ConnectionState().TLSUnique
576 if !bytes.Equal(peersValue[:], expected) {
577 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
578 }
579 }
580
David Benjamine58c4f52014-08-24 03:47:07 -0400581 if test.shimWritesFirst {
582 var buf [5]byte
583 _, err := io.ReadFull(tlsConn, buf[:])
584 if err != nil {
585 return err
586 }
587 if string(buf[:]) != "hello" {
588 return fmt.Errorf("bad initial message")
589 }
590 }
591
David Benjamina8ebe222015-06-06 03:04:39 -0400592 for i := 0; i < test.sendEmptyRecords; i++ {
593 tlsConn.Write(nil)
594 }
595
David Benjamin24f346d2015-06-06 03:28:08 -0400596 for i := 0; i < test.sendWarningAlerts; i++ {
597 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
598 }
599
David Benjamin47921102016-07-28 11:29:18 -0400600 if test.sendHalfHelloRequest {
601 tlsConn.SendHalfHelloRequest()
602 }
603
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400604 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700605 if test.renegotiateCiphers != nil {
606 config.CipherSuites = test.renegotiateCiphers
607 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400608 for i := 0; i < test.renegotiate; i++ {
609 if err := tlsConn.Renegotiate(); err != nil {
610 return err
611 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700612 }
613 } else if test.renegotiateCiphers != nil {
614 panic("renegotiateCiphers without renegotiate")
615 }
616
David Benjamin5fa3eba2015-01-22 16:35:40 -0500617 if test.damageFirstWrite {
618 connDamage.setDamage(true)
619 tlsConn.Write([]byte("DAMAGED WRITE"))
620 connDamage.setDamage(false)
621 }
622
David Benjamin8e6db492015-07-25 18:29:23 -0400623 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700624 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400625 if test.protocol == dtls {
626 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
627 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700628 // Read until EOF.
629 _, err := io.Copy(ioutil.Discard, tlsConn)
630 return err
631 }
David Benjamin4417d052015-04-05 04:17:25 -0400632 if messageLen == 0 {
633 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700634 }
Adam Langley95c29f32014-06-20 12:00:00 -0700635
David Benjamin8e6db492015-07-25 18:29:23 -0400636 messageCount := test.messageCount
637 if messageCount == 0 {
638 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400639 }
640
David Benjamin8e6db492015-07-25 18:29:23 -0400641 for j := 0; j < messageCount; j++ {
642 testMessage := make([]byte, messageLen)
643 for i := range testMessage {
644 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400645 }
David Benjamin8e6db492015-07-25 18:29:23 -0400646 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700647
David Benjamin8e6db492015-07-25 18:29:23 -0400648 for i := 0; i < test.sendEmptyRecords; i++ {
649 tlsConn.Write(nil)
650 }
651
652 for i := 0; i < test.sendWarningAlerts; i++ {
653 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
654 }
655
David Benjamin4f75aaf2015-09-01 16:53:10 -0400656 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400657 // The shim will not respond.
658 continue
659 }
660
David Benjamin8e6db492015-07-25 18:29:23 -0400661 buf := make([]byte, len(testMessage))
662 if test.protocol == dtls {
663 bufTmp := make([]byte, len(buf)+1)
664 n, err := tlsConn.Read(bufTmp)
665 if err != nil {
666 return err
667 }
668 if n != len(buf) {
669 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
670 }
671 copy(buf, bufTmp)
672 } else {
673 _, err := io.ReadFull(tlsConn, buf)
674 if err != nil {
675 return err
676 }
677 }
678
679 for i, v := range buf {
680 if v != testMessage[i]^0xff {
681 return fmt.Errorf("bad reply contents at byte %d", i)
682 }
Adam Langley95c29f32014-06-20 12:00:00 -0700683 }
684 }
685
686 return nil
687}
688
David Benjamin325b5c32014-07-01 19:40:31 -0400689func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
690 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700691 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400692 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700693 }
David Benjamin325b5c32014-07-01 19:40:31 -0400694 valgrindArgs = append(valgrindArgs, path)
695 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700696
David Benjamin325b5c32014-07-01 19:40:31 -0400697 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700698}
699
David Benjamin325b5c32014-07-01 19:40:31 -0400700func gdbOf(path string, args ...string) *exec.Cmd {
701 xtermArgs := []string{"-e", "gdb", "--args"}
702 xtermArgs = append(xtermArgs, path)
703 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700704
David Benjamin325b5c32014-07-01 19:40:31 -0400705 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700706}
707
David Benjamind16bf342015-12-18 00:53:12 -0500708func lldbOf(path string, args ...string) *exec.Cmd {
709 xtermArgs := []string{"-e", "lldb", "--"}
710 xtermArgs = append(xtermArgs, path)
711 xtermArgs = append(xtermArgs, args...)
712
713 return exec.Command("xterm", xtermArgs...)
714}
715
EKR842ae6c2016-07-27 09:22:05 +0200716var (
717 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
718 errUnimplemented = errors.New("child process does not implement needed flags")
719)
Adam Langley69a01602014-11-17 17:26:55 -0800720
David Benjamin87c8a642015-02-21 01:54:29 -0500721// accept accepts a connection from listener, unless waitChan signals a process
722// exit first.
723func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
724 type connOrError struct {
725 conn net.Conn
726 err error
727 }
728 connChan := make(chan connOrError, 1)
729 go func() {
730 conn, err := listener.Accept()
731 connChan <- connOrError{conn, err}
732 close(connChan)
733 }()
734 select {
735 case result := <-connChan:
736 return result.conn, result.err
737 case childErr := <-waitChan:
738 waitChan <- childErr
739 return nil, fmt.Errorf("child exited early: %s", childErr)
740 }
741}
742
EKRf71d7ed2016-08-06 13:25:12 -0700743func translateExpectedError(errorStr string) string {
744 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
745 return translated
746 }
747
748 if *looseErrors {
749 return ""
750 }
751
752 return errorStr
753}
754
Adam Langley7c803a62015-06-15 15:35:05 -0700755func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700756 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
757 panic("Error expected without shouldFail in " + test.name)
758 }
759
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700760 if test.expectResumeRejected && !test.resumeSession {
761 panic("expectResumeRejected without resumeSession in " + test.name)
762 }
763
David Benjamin87c8a642015-02-21 01:54:29 -0500764 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
765 if err != nil {
766 panic(err)
767 }
768 defer func() {
769 if listener != nil {
770 listener.Close()
771 }
772 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700773
David Benjamin87c8a642015-02-21 01:54:29 -0500774 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400775 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400776 flags = append(flags, "-server")
777
David Benjamin025b3d32014-07-01 19:53:04 -0400778 flags = append(flags, "-key-file")
779 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700780 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400781 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700782 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400783 }
784
785 flags = append(flags, "-cert-file")
786 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700787 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400788 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700789 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400790 }
791 }
David Benjamin5a593af2014-08-11 19:51:50 -0400792
David Benjamin6fd297b2014-08-11 18:43:38 -0400793 if test.protocol == dtls {
794 flags = append(flags, "-dtls")
795 }
796
David Benjamin5a593af2014-08-11 19:51:50 -0400797 if test.resumeSession {
798 flags = append(flags, "-resume")
799 }
800
David Benjamine58c4f52014-08-24 03:47:07 -0400801 if test.shimWritesFirst {
802 flags = append(flags, "-shim-writes-first")
803 }
804
David Benjamin30789da2015-08-29 22:56:45 -0400805 if test.shimShutsDown {
806 flags = append(flags, "-shim-shuts-down")
807 }
808
David Benjaminc565ebb2015-04-03 04:06:36 -0400809 if test.exportKeyingMaterial > 0 {
810 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
811 flags = append(flags, "-export-label", test.exportLabel)
812 flags = append(flags, "-export-context", test.exportContext)
813 if test.useExportContext {
814 flags = append(flags, "-use-export-context")
815 }
816 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700817 if test.expectResumeRejected {
818 flags = append(flags, "-expect-session-miss")
819 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400820
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700821 if test.testTLSUnique {
822 flags = append(flags, "-tls-unique")
823 }
824
David Benjamin025b3d32014-07-01 19:53:04 -0400825 flags = append(flags, test.flags...)
826
827 var shim *exec.Cmd
828 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700829 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700830 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700831 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500832 } else if *useLLDB {
833 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400834 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700835 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400836 }
David Benjamin025b3d32014-07-01 19:53:04 -0400837 shim.Stdin = os.Stdin
838 var stdoutBuf, stderrBuf bytes.Buffer
839 shim.Stdout = &stdoutBuf
840 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800841 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500842 shim.Env = os.Environ()
843 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800844 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400845 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800846 }
847 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
848 }
David Benjamin025b3d32014-07-01 19:53:04 -0400849
850 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700851 panic(err)
852 }
David Benjamin87c8a642015-02-21 01:54:29 -0500853 waitChan := make(chan error, 1)
854 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700855
856 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400857 if !test.noSessionCache {
858 config.ClientSessionCache = NewLRUClientSessionCache(1)
859 config.ServerSessionCache = NewLRUServerSessionCache(1)
860 }
David Benjamin025b3d32014-07-01 19:53:04 -0400861 if test.testType == clientTest {
862 if len(config.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700863 config.Certificates = []Certificate{rsaCertificate}
David Benjamin025b3d32014-07-01 19:53:04 -0400864 }
David Benjamin87c8a642015-02-21 01:54:29 -0500865 } else {
866 // Supply a ServerName to ensure a constant session cache key,
867 // rather than falling back to net.Conn.RemoteAddr.
868 if len(config.ServerName) == 0 {
869 config.ServerName = "test"
870 }
David Benjamin025b3d32014-07-01 19:53:04 -0400871 }
David Benjaminf2b83632016-03-01 22:57:46 -0500872 if *fuzzer {
873 config.Bugs.NullAllCiphers = true
874 }
David Benjamin2e045a92016-06-08 13:09:56 -0400875 if *deterministic {
876 config.Rand = &deterministicRand{}
877 }
Adam Langley95c29f32014-06-20 12:00:00 -0700878
David Benjamin87c8a642015-02-21 01:54:29 -0500879 conn, err := acceptOrWait(listener, waitChan)
880 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400881 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500882 conn.Close()
883 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500884
David Benjamin1d5c83e2014-07-22 19:20:02 -0400885 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400886 var resumeConfig Config
887 if test.resumeConfig != nil {
888 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500889 if len(resumeConfig.ServerName) == 0 {
890 resumeConfig.ServerName = config.ServerName
891 }
David Benjamin01fe8202014-09-24 15:21:44 -0400892 if len(resumeConfig.Certificates) == 0 {
David Benjamin33863262016-07-08 17:20:12 -0700893 resumeConfig.Certificates = []Certificate{rsaCertificate}
David Benjamin01fe8202014-09-24 15:21:44 -0400894 }
David Benjaminba4594a2015-06-18 18:36:15 -0400895 if test.newSessionsOnResume {
896 if !test.noSessionCache {
897 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
898 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
899 }
900 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500901 resumeConfig.SessionTicketKey = config.SessionTicketKey
902 resumeConfig.ClientSessionCache = config.ClientSessionCache
903 resumeConfig.ServerSessionCache = config.ServerSessionCache
904 }
David Benjaminf2b83632016-03-01 22:57:46 -0500905 if *fuzzer {
906 resumeConfig.Bugs.NullAllCiphers = true
907 }
David Benjamin2e045a92016-06-08 13:09:56 -0400908 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400909 } else {
910 resumeConfig = config
911 }
David Benjamin87c8a642015-02-21 01:54:29 -0500912 var connResume net.Conn
913 connResume, err = acceptOrWait(listener, waitChan)
914 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400915 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500916 connResume.Close()
917 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400918 }
919
David Benjamin87c8a642015-02-21 01:54:29 -0500920 // Close the listener now. This is to avoid hangs should the shim try to
921 // open more connections than expected.
922 listener.Close()
923 listener = nil
924
925 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800926 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200927 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
928 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800929 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200930 case 89:
931 return errUnimplemented
Adam Langley69a01602014-11-17 17:26:55 -0800932 }
933 }
Adam Langley95c29f32014-06-20 12:00:00 -0700934
David Benjamin9bea3492016-03-02 10:59:16 -0500935 // Account for Windows line endings.
936 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
937 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500938
939 // Separate the errors from the shim and those from tools like
940 // AddressSanitizer.
941 var extraStderr string
942 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
943 stderr = stderrParts[0]
944 extraStderr = stderrParts[1]
945 }
946
Adam Langley95c29f32014-06-20 12:00:00 -0700947 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700948 expectedError := translateExpectedError(test.expectedError)
949 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200950
Adam Langleyac61fa32014-06-23 12:03:11 -0700951 localError := "none"
952 if err != nil {
953 localError = err.Error()
954 }
955 if len(test.expectedLocalError) != 0 {
956 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
957 }
Adam Langley95c29f32014-06-20 12:00:00 -0700958
959 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700960 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700961 if childErr != nil {
962 childError = childErr.Error()
963 }
964
965 var msg string
966 switch {
967 case failed && !test.shouldFail:
968 msg = "unexpected failure"
969 case !failed && test.shouldFail:
970 msg = "unexpected success"
971 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700972 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700973 default:
974 panic("internal error")
975 }
976
David Benjaminc565ebb2015-04-03 04:06:36 -0400977 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 -0700978 }
979
David Benjaminff3a1492016-03-02 10:12:06 -0500980 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
981 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700982 }
983
984 return nil
985}
986
987var tlsVersions = []struct {
988 name string
989 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400990 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500991 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700992}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500993 {"SSL3", VersionSSL30, "-no-ssl3", false},
994 {"TLS1", VersionTLS10, "-no-tls1", true},
995 {"TLS11", VersionTLS11, "-no-tls11", false},
996 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -0400997 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700998}
999
1000var testCipherSuites = []struct {
1001 name string
1002 id uint16
1003}{
1004 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001005 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001006 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001007 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001008 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001009 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001010 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001011 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1012 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001013 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001014 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1015 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001016 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001017 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1018 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001019 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1020 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001021 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001022 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001023 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001024 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001025 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001026 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001028 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001029 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001030 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001031 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001032 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001033 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001034 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001035 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1036 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1037 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1038 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001039 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1040 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001041 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1042 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001043 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001044 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1045 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001046 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001048 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001049 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001050}
1051
David Benjamin8b8c0062014-11-23 02:47:52 -05001052func hasComponent(suiteName, component string) bool {
1053 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1054}
1055
David Benjaminf7768e42014-08-31 02:06:47 -04001056func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001057 return hasComponent(suiteName, "GCM") ||
1058 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001059 hasComponent(suiteName, "SHA384") ||
1060 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001061}
1062
Nick Harper1fd39d82016-06-14 18:14:35 -07001063func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001064 // Only AEADs.
1065 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1066 return false
1067 }
1068 // No old CHACHA20_POLY1305.
1069 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1070 return false
1071 }
1072 // Must have ECDHE.
1073 // TODO(davidben,svaldez): Add pure PSK support.
1074 if !hasComponent(suiteName, "ECDHE") {
1075 return false
1076 }
1077 // TODO(davidben,svaldez): Add PSK support.
1078 if hasComponent(suiteName, "PSK") {
1079 return false
1080 }
1081 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001082}
1083
David Benjamin8b8c0062014-11-23 02:47:52 -05001084func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001085 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001086}
1087
Adam Langleya7997f12015-05-14 17:38:50 -07001088func bigFromHex(hex string) *big.Int {
1089 ret, ok := new(big.Int).SetString(hex, 16)
1090 if !ok {
1091 panic("failed to parse hex number 0x" + hex)
1092 }
1093 return ret
1094}
1095
Adam Langley7c803a62015-06-15 15:35:05 -07001096func addBasicTests() {
1097 basicTests := []testCase{
1098 {
Adam Langley7c803a62015-06-15 15:35:05 -07001099 name: "NoFallbackSCSV",
1100 config: Config{
1101 Bugs: ProtocolBugs{
1102 FailIfNotFallbackSCSV: true,
1103 },
1104 },
1105 shouldFail: true,
1106 expectedLocalError: "no fallback SCSV found",
1107 },
1108 {
1109 name: "SendFallbackSCSV",
1110 config: Config{
1111 Bugs: ProtocolBugs{
1112 FailIfNotFallbackSCSV: true,
1113 },
1114 },
1115 flags: []string{"-fallback-scsv"},
1116 },
1117 {
1118 name: "ClientCertificateTypes",
1119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001120 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001121 ClientAuth: RequestClientCert,
1122 ClientCertificateTypes: []byte{
1123 CertTypeDSSSign,
1124 CertTypeRSASign,
1125 CertTypeECDSASign,
1126 },
1127 },
1128 flags: []string{
1129 "-expect-certificate-types",
1130 base64.StdEncoding.EncodeToString([]byte{
1131 CertTypeDSSSign,
1132 CertTypeRSASign,
1133 CertTypeECDSASign,
1134 }),
1135 },
1136 },
1137 {
Adam Langley7c803a62015-06-15 15:35:05 -07001138 name: "UnauthenticatedECDH",
1139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001140 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001141 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1142 Bugs: ProtocolBugs{
1143 UnauthenticatedECDH: true,
1144 },
1145 },
1146 shouldFail: true,
1147 expectedError: ":UNEXPECTED_MESSAGE:",
1148 },
1149 {
1150 name: "SkipCertificateStatus",
1151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001152 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1154 Bugs: ProtocolBugs{
1155 SkipCertificateStatus: true,
1156 },
1157 },
1158 flags: []string{
1159 "-enable-ocsp-stapling",
1160 },
1161 },
1162 {
1163 name: "SkipServerKeyExchange",
1164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001165 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1167 Bugs: ProtocolBugs{
1168 SkipServerKeyExchange: true,
1169 },
1170 },
1171 shouldFail: true,
1172 expectedError: ":UNEXPECTED_MESSAGE:",
1173 },
1174 {
Adam Langley7c803a62015-06-15 15:35:05 -07001175 testType: serverTest,
1176 name: "Alert",
1177 config: Config{
1178 Bugs: ProtocolBugs{
1179 SendSpuriousAlert: alertRecordOverflow,
1180 },
1181 },
1182 shouldFail: true,
1183 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1184 },
1185 {
1186 protocol: dtls,
1187 testType: serverTest,
1188 name: "Alert-DTLS",
1189 config: Config{
1190 Bugs: ProtocolBugs{
1191 SendSpuriousAlert: alertRecordOverflow,
1192 },
1193 },
1194 shouldFail: true,
1195 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1196 },
1197 {
1198 testType: serverTest,
1199 name: "FragmentAlert",
1200 config: Config{
1201 Bugs: ProtocolBugs{
1202 FragmentAlert: true,
1203 SendSpuriousAlert: alertRecordOverflow,
1204 },
1205 },
1206 shouldFail: true,
1207 expectedError: ":BAD_ALERT:",
1208 },
1209 {
1210 protocol: dtls,
1211 testType: serverTest,
1212 name: "FragmentAlert-DTLS",
1213 config: Config{
1214 Bugs: ProtocolBugs{
1215 FragmentAlert: true,
1216 SendSpuriousAlert: alertRecordOverflow,
1217 },
1218 },
1219 shouldFail: true,
1220 expectedError: ":BAD_ALERT:",
1221 },
1222 {
1223 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001224 name: "DoubleAlert",
1225 config: Config{
1226 Bugs: ProtocolBugs{
1227 DoubleAlert: true,
1228 SendSpuriousAlert: alertRecordOverflow,
1229 },
1230 },
1231 shouldFail: true,
1232 expectedError: ":BAD_ALERT:",
1233 },
1234 {
1235 protocol: dtls,
1236 testType: serverTest,
1237 name: "DoubleAlert-DTLS",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 DoubleAlert: true,
1241 SendSpuriousAlert: alertRecordOverflow,
1242 },
1243 },
1244 shouldFail: true,
1245 expectedError: ":BAD_ALERT:",
1246 },
1247 {
Adam Langley7c803a62015-06-15 15:35:05 -07001248 name: "SkipNewSessionTicket",
1249 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001250 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001251 Bugs: ProtocolBugs{
1252 SkipNewSessionTicket: true,
1253 },
1254 },
1255 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001256 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001257 },
1258 {
1259 testType: serverTest,
1260 name: "FallbackSCSV",
1261 config: Config{
1262 MaxVersion: VersionTLS11,
1263 Bugs: ProtocolBugs{
1264 SendFallbackSCSV: true,
1265 },
1266 },
1267 shouldFail: true,
1268 expectedError: ":INAPPROPRIATE_FALLBACK:",
1269 },
1270 {
1271 testType: serverTest,
1272 name: "FallbackSCSV-VersionMatch",
1273 config: Config{
1274 Bugs: ProtocolBugs{
1275 SendFallbackSCSV: true,
1276 },
1277 },
1278 },
1279 {
1280 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001281 name: "FallbackSCSV-VersionMatch-TLS12",
1282 config: Config{
1283 MaxVersion: VersionTLS12,
1284 Bugs: ProtocolBugs{
1285 SendFallbackSCSV: true,
1286 },
1287 },
1288 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1289 },
1290 {
1291 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001292 name: "FragmentedClientVersion",
1293 config: Config{
1294 Bugs: ProtocolBugs{
1295 MaxHandshakeRecordLength: 1,
1296 FragmentClientVersion: true,
1297 },
1298 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001299 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001300 },
1301 {
Adam Langley7c803a62015-06-15 15:35:05 -07001302 testType: serverTest,
1303 name: "HttpGET",
1304 sendPrefix: "GET / HTTP/1.0\n",
1305 shouldFail: true,
1306 expectedError: ":HTTP_REQUEST:",
1307 },
1308 {
1309 testType: serverTest,
1310 name: "HttpPOST",
1311 sendPrefix: "POST / HTTP/1.0\n",
1312 shouldFail: true,
1313 expectedError: ":HTTP_REQUEST:",
1314 },
1315 {
1316 testType: serverTest,
1317 name: "HttpHEAD",
1318 sendPrefix: "HEAD / HTTP/1.0\n",
1319 shouldFail: true,
1320 expectedError: ":HTTP_REQUEST:",
1321 },
1322 {
1323 testType: serverTest,
1324 name: "HttpPUT",
1325 sendPrefix: "PUT / HTTP/1.0\n",
1326 shouldFail: true,
1327 expectedError: ":HTTP_REQUEST:",
1328 },
1329 {
1330 testType: serverTest,
1331 name: "HttpCONNECT",
1332 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1333 shouldFail: true,
1334 expectedError: ":HTTPS_PROXY_REQUEST:",
1335 },
1336 {
1337 testType: serverTest,
1338 name: "Garbage",
1339 sendPrefix: "blah",
1340 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001341 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001342 },
1343 {
Adam Langley7c803a62015-06-15 15:35:05 -07001344 name: "RSAEphemeralKey",
1345 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001346 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001347 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1348 Bugs: ProtocolBugs{
1349 RSAEphemeralKey: true,
1350 },
1351 },
1352 shouldFail: true,
1353 expectedError: ":UNEXPECTED_MESSAGE:",
1354 },
1355 {
1356 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001357 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001358 shouldFail: true,
1359 expectedError: ":WRONG_SSL_VERSION:",
1360 },
1361 {
1362 protocol: dtls,
1363 name: "DisableEverything-DTLS",
1364 flags: []string{"-no-tls12", "-no-tls1"},
1365 shouldFail: true,
1366 expectedError: ":WRONG_SSL_VERSION:",
1367 },
1368 {
Adam Langley7c803a62015-06-15 15:35:05 -07001369 protocol: dtls,
1370 testType: serverTest,
1371 name: "MTU",
1372 config: Config{
1373 Bugs: ProtocolBugs{
1374 MaxPacketLength: 256,
1375 },
1376 },
1377 flags: []string{"-mtu", "256"},
1378 },
1379 {
1380 protocol: dtls,
1381 testType: serverTest,
1382 name: "MTUExceeded",
1383 config: Config{
1384 Bugs: ProtocolBugs{
1385 MaxPacketLength: 255,
1386 },
1387 },
1388 flags: []string{"-mtu", "256"},
1389 shouldFail: true,
1390 expectedLocalError: "dtls: exceeded maximum packet length",
1391 },
1392 {
1393 name: "CertMismatchRSA",
1394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001395 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001396 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001397 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001398 Bugs: ProtocolBugs{
1399 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1400 },
1401 },
1402 shouldFail: true,
1403 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1404 },
1405 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001406 name: "CertMismatchRSA-TLS13",
1407 config: Config{
1408 MaxVersion: VersionTLS13,
1409 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1410 Certificates: []Certificate{ecdsaP256Certificate},
1411 Bugs: ProtocolBugs{
1412 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1417 },
1418 {
Adam Langley7c803a62015-06-15 15:35:05 -07001419 name: "CertMismatchECDSA",
1420 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001421 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001422 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001423 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001424 Bugs: ProtocolBugs{
1425 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1426 },
1427 },
1428 shouldFail: true,
1429 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1430 },
1431 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001432 name: "CertMismatchECDSA-TLS13",
1433 config: Config{
1434 MaxVersion: VersionTLS13,
1435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1436 Certificates: []Certificate{rsaCertificate},
1437 Bugs: ProtocolBugs{
1438 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1439 },
1440 },
1441 shouldFail: true,
1442 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1443 },
1444 {
Adam Langley7c803a62015-06-15 15:35:05 -07001445 name: "EmptyCertificateList",
1446 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001447 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1449 Bugs: ProtocolBugs{
1450 EmptyCertificateList: true,
1451 },
1452 },
1453 shouldFail: true,
1454 expectedError: ":DECODE_ERROR:",
1455 },
1456 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001457 name: "EmptyCertificateList-TLS13",
1458 config: Config{
1459 MaxVersion: VersionTLS13,
1460 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1461 Bugs: ProtocolBugs{
1462 EmptyCertificateList: true,
1463 },
1464 },
1465 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001466 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001467 },
1468 {
Adam Langley7c803a62015-06-15 15:35:05 -07001469 name: "TLSFatalBadPackets",
1470 damageFirstWrite: true,
1471 shouldFail: true,
1472 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1473 },
1474 {
1475 protocol: dtls,
1476 name: "DTLSIgnoreBadPackets",
1477 damageFirstWrite: true,
1478 },
1479 {
1480 protocol: dtls,
1481 name: "DTLSIgnoreBadPackets-Async",
1482 damageFirstWrite: true,
1483 flags: []string{"-async"},
1484 },
1485 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001486 name: "AppDataBeforeHandshake",
1487 config: Config{
1488 Bugs: ProtocolBugs{
1489 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1490 },
1491 },
1492 shouldFail: true,
1493 expectedError: ":UNEXPECTED_RECORD:",
1494 },
1495 {
1496 name: "AppDataBeforeHandshake-Empty",
1497 config: Config{
1498 Bugs: ProtocolBugs{
1499 AppDataBeforeHandshake: []byte{},
1500 },
1501 },
1502 shouldFail: true,
1503 expectedError: ":UNEXPECTED_RECORD:",
1504 },
1505 {
1506 protocol: dtls,
1507 name: "AppDataBeforeHandshake-DTLS",
1508 config: Config{
1509 Bugs: ProtocolBugs{
1510 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1511 },
1512 },
1513 shouldFail: true,
1514 expectedError: ":UNEXPECTED_RECORD:",
1515 },
1516 {
1517 protocol: dtls,
1518 name: "AppDataBeforeHandshake-DTLS-Empty",
1519 config: Config{
1520 Bugs: ProtocolBugs{
1521 AppDataBeforeHandshake: []byte{},
1522 },
1523 },
1524 shouldFail: true,
1525 expectedError: ":UNEXPECTED_RECORD:",
1526 },
1527 {
Adam Langley7c803a62015-06-15 15:35:05 -07001528 name: "AppDataAfterChangeCipherSpec",
1529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001530 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001531 Bugs: ProtocolBugs{
1532 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1533 },
1534 },
1535 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001536 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001537 },
1538 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001539 name: "AppDataAfterChangeCipherSpec-Empty",
1540 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001541 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001542 Bugs: ProtocolBugs{
1543 AppDataAfterChangeCipherSpec: []byte{},
1544 },
1545 },
1546 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001547 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001548 },
1549 {
Adam Langley7c803a62015-06-15 15:35:05 -07001550 protocol: dtls,
1551 name: "AppDataAfterChangeCipherSpec-DTLS",
1552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001553 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001554 Bugs: ProtocolBugs{
1555 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1556 },
1557 },
1558 // BoringSSL's DTLS implementation will drop the out-of-order
1559 // application data.
1560 },
1561 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001562 protocol: dtls,
1563 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001565 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001566 Bugs: ProtocolBugs{
1567 AppDataAfterChangeCipherSpec: []byte{},
1568 },
1569 },
1570 // BoringSSL's DTLS implementation will drop the out-of-order
1571 // application data.
1572 },
1573 {
Adam Langley7c803a62015-06-15 15:35:05 -07001574 name: "AlertAfterChangeCipherSpec",
1575 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001576 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001577 Bugs: ProtocolBugs{
1578 AlertAfterChangeCipherSpec: alertRecordOverflow,
1579 },
1580 },
1581 shouldFail: true,
1582 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1583 },
1584 {
1585 protocol: dtls,
1586 name: "AlertAfterChangeCipherSpec-DTLS",
1587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001588 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001589 Bugs: ProtocolBugs{
1590 AlertAfterChangeCipherSpec: alertRecordOverflow,
1591 },
1592 },
1593 shouldFail: true,
1594 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1595 },
1596 {
1597 protocol: dtls,
1598 name: "ReorderHandshakeFragments-Small-DTLS",
1599 config: Config{
1600 Bugs: ProtocolBugs{
1601 ReorderHandshakeFragments: true,
1602 // Small enough that every handshake message is
1603 // fragmented.
1604 MaxHandshakeRecordLength: 2,
1605 },
1606 },
1607 },
1608 {
1609 protocol: dtls,
1610 name: "ReorderHandshakeFragments-Large-DTLS",
1611 config: Config{
1612 Bugs: ProtocolBugs{
1613 ReorderHandshakeFragments: true,
1614 // Large enough that no handshake message is
1615 // fragmented.
1616 MaxHandshakeRecordLength: 2048,
1617 },
1618 },
1619 },
1620 {
1621 protocol: dtls,
1622 name: "MixCompleteMessageWithFragments-DTLS",
1623 config: Config{
1624 Bugs: ProtocolBugs{
1625 ReorderHandshakeFragments: true,
1626 MixCompleteMessageWithFragments: true,
1627 MaxHandshakeRecordLength: 2,
1628 },
1629 },
1630 },
1631 {
1632 name: "SendInvalidRecordType",
1633 config: Config{
1634 Bugs: ProtocolBugs{
1635 SendInvalidRecordType: true,
1636 },
1637 },
1638 shouldFail: true,
1639 expectedError: ":UNEXPECTED_RECORD:",
1640 },
1641 {
1642 protocol: dtls,
1643 name: "SendInvalidRecordType-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 SendInvalidRecordType: true,
1647 },
1648 },
1649 shouldFail: true,
1650 expectedError: ":UNEXPECTED_RECORD:",
1651 },
1652 {
1653 name: "FalseStart-SkipServerSecondLeg",
1654 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001655 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001656 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1657 NextProtos: []string{"foo"},
1658 Bugs: ProtocolBugs{
1659 SkipNewSessionTicket: true,
1660 SkipChangeCipherSpec: true,
1661 SkipFinished: true,
1662 ExpectFalseStart: true,
1663 },
1664 },
1665 flags: []string{
1666 "-false-start",
1667 "-handshake-never-done",
1668 "-advertise-alpn", "\x03foo",
1669 },
1670 shimWritesFirst: true,
1671 shouldFail: true,
1672 expectedError: ":UNEXPECTED_RECORD:",
1673 },
1674 {
1675 name: "FalseStart-SkipServerSecondLeg-Implicit",
1676 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001677 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001678 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1679 NextProtos: []string{"foo"},
1680 Bugs: ProtocolBugs{
1681 SkipNewSessionTicket: true,
1682 SkipChangeCipherSpec: true,
1683 SkipFinished: true,
1684 },
1685 },
1686 flags: []string{
1687 "-implicit-handshake",
1688 "-false-start",
1689 "-handshake-never-done",
1690 "-advertise-alpn", "\x03foo",
1691 },
1692 shouldFail: true,
1693 expectedError: ":UNEXPECTED_RECORD:",
1694 },
1695 {
1696 testType: serverTest,
1697 name: "FailEarlyCallback",
1698 flags: []string{"-fail-early-callback"},
1699 shouldFail: true,
1700 expectedError: ":CONNECTION_REJECTED:",
1701 expectedLocalError: "remote error: access denied",
1702 },
1703 {
Adam Langley7c803a62015-06-15 15:35:05 -07001704 protocol: dtls,
1705 name: "FragmentMessageTypeMismatch-DTLS",
1706 config: Config{
1707 Bugs: ProtocolBugs{
1708 MaxHandshakeRecordLength: 2,
1709 FragmentMessageTypeMismatch: true,
1710 },
1711 },
1712 shouldFail: true,
1713 expectedError: ":FRAGMENT_MISMATCH:",
1714 },
1715 {
1716 protocol: dtls,
1717 name: "FragmentMessageLengthMismatch-DTLS",
1718 config: Config{
1719 Bugs: ProtocolBugs{
1720 MaxHandshakeRecordLength: 2,
1721 FragmentMessageLengthMismatch: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":FRAGMENT_MISMATCH:",
1726 },
1727 {
1728 protocol: dtls,
1729 name: "SplitFragments-Header-DTLS",
1730 config: Config{
1731 Bugs: ProtocolBugs{
1732 SplitFragments: 2,
1733 },
1734 },
1735 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001736 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001737 },
1738 {
1739 protocol: dtls,
1740 name: "SplitFragments-Boundary-DTLS",
1741 config: Config{
1742 Bugs: ProtocolBugs{
1743 SplitFragments: dtlsRecordHeaderLen,
1744 },
1745 },
1746 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001747 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001748 },
1749 {
1750 protocol: dtls,
1751 name: "SplitFragments-Body-DTLS",
1752 config: Config{
1753 Bugs: ProtocolBugs{
1754 SplitFragments: dtlsRecordHeaderLen + 1,
1755 },
1756 },
1757 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001758 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001759 },
1760 {
1761 protocol: dtls,
1762 name: "SendEmptyFragments-DTLS",
1763 config: Config{
1764 Bugs: ProtocolBugs{
1765 SendEmptyFragments: true,
1766 },
1767 },
1768 },
1769 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001770 name: "BadFinished-Client",
1771 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001772 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001773 Bugs: ProtocolBugs{
1774 BadFinished: true,
1775 },
1776 },
1777 shouldFail: true,
1778 expectedError: ":DIGEST_CHECK_FAILED:",
1779 },
1780 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001781 name: "BadFinished-Client-TLS13",
1782 config: Config{
1783 MaxVersion: VersionTLS13,
1784 Bugs: ProtocolBugs{
1785 BadFinished: true,
1786 },
1787 },
1788 shouldFail: true,
1789 expectedError: ":DIGEST_CHECK_FAILED:",
1790 },
1791 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001792 testType: serverTest,
1793 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001795 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001796 Bugs: ProtocolBugs{
1797 BadFinished: true,
1798 },
1799 },
1800 shouldFail: true,
1801 expectedError: ":DIGEST_CHECK_FAILED:",
1802 },
1803 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001804 testType: serverTest,
1805 name: "BadFinished-Server-TLS13",
1806 config: Config{
1807 MaxVersion: VersionTLS13,
1808 Bugs: ProtocolBugs{
1809 BadFinished: true,
1810 },
1811 },
1812 shouldFail: true,
1813 expectedError: ":DIGEST_CHECK_FAILED:",
1814 },
1815 {
Adam Langley7c803a62015-06-15 15:35:05 -07001816 name: "FalseStart-BadFinished",
1817 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001818 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001819 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1820 NextProtos: []string{"foo"},
1821 Bugs: ProtocolBugs{
1822 BadFinished: true,
1823 ExpectFalseStart: true,
1824 },
1825 },
1826 flags: []string{
1827 "-false-start",
1828 "-handshake-never-done",
1829 "-advertise-alpn", "\x03foo",
1830 },
1831 shimWritesFirst: true,
1832 shouldFail: true,
1833 expectedError: ":DIGEST_CHECK_FAILED:",
1834 },
1835 {
1836 name: "NoFalseStart-NoALPN",
1837 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001838 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001839 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1840 Bugs: ProtocolBugs{
1841 ExpectFalseStart: true,
1842 AlertBeforeFalseStartTest: alertAccessDenied,
1843 },
1844 },
1845 flags: []string{
1846 "-false-start",
1847 },
1848 shimWritesFirst: true,
1849 shouldFail: true,
1850 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1851 expectedLocalError: "tls: peer did not false start: EOF",
1852 },
1853 {
1854 name: "NoFalseStart-NoAEAD",
1855 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001856 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001857 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1858 NextProtos: []string{"foo"},
1859 Bugs: ProtocolBugs{
1860 ExpectFalseStart: true,
1861 AlertBeforeFalseStartTest: alertAccessDenied,
1862 },
1863 },
1864 flags: []string{
1865 "-false-start",
1866 "-advertise-alpn", "\x03foo",
1867 },
1868 shimWritesFirst: true,
1869 shouldFail: true,
1870 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1871 expectedLocalError: "tls: peer did not false start: EOF",
1872 },
1873 {
1874 name: "NoFalseStart-RSA",
1875 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001876 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001877 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1878 NextProtos: []string{"foo"},
1879 Bugs: ProtocolBugs{
1880 ExpectFalseStart: true,
1881 AlertBeforeFalseStartTest: alertAccessDenied,
1882 },
1883 },
1884 flags: []string{
1885 "-false-start",
1886 "-advertise-alpn", "\x03foo",
1887 },
1888 shimWritesFirst: true,
1889 shouldFail: true,
1890 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1891 expectedLocalError: "tls: peer did not false start: EOF",
1892 },
1893 {
1894 name: "NoFalseStart-DHE_RSA",
1895 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001896 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001897 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1898 NextProtos: []string{"foo"},
1899 Bugs: ProtocolBugs{
1900 ExpectFalseStart: true,
1901 AlertBeforeFalseStartTest: alertAccessDenied,
1902 },
1903 },
1904 flags: []string{
1905 "-false-start",
1906 "-advertise-alpn", "\x03foo",
1907 },
1908 shimWritesFirst: true,
1909 shouldFail: true,
1910 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1911 expectedLocalError: "tls: peer did not false start: EOF",
1912 },
1913 {
Adam Langley7c803a62015-06-15 15:35:05 -07001914 protocol: dtls,
1915 name: "SendSplitAlert-Sync",
1916 config: Config{
1917 Bugs: ProtocolBugs{
1918 SendSplitAlert: true,
1919 },
1920 },
1921 },
1922 {
1923 protocol: dtls,
1924 name: "SendSplitAlert-Async",
1925 config: Config{
1926 Bugs: ProtocolBugs{
1927 SendSplitAlert: true,
1928 },
1929 },
1930 flags: []string{"-async"},
1931 },
1932 {
1933 protocol: dtls,
1934 name: "PackDTLSHandshake",
1935 config: Config{
1936 Bugs: ProtocolBugs{
1937 MaxHandshakeRecordLength: 2,
1938 PackHandshakeFragments: 20,
1939 PackHandshakeRecords: 200,
1940 },
1941 },
1942 },
1943 {
Adam Langley7c803a62015-06-15 15:35:05 -07001944 name: "SendEmptyRecords-Pass",
1945 sendEmptyRecords: 32,
1946 },
1947 {
1948 name: "SendEmptyRecords",
1949 sendEmptyRecords: 33,
1950 shouldFail: true,
1951 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1952 },
1953 {
1954 name: "SendEmptyRecords-Async",
1955 sendEmptyRecords: 33,
1956 flags: []string{"-async"},
1957 shouldFail: true,
1958 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1959 },
1960 {
David Benjamine8e84b92016-08-03 15:39:47 -04001961 name: "SendWarningAlerts-Pass",
1962 config: Config{
1963 MaxVersion: VersionTLS12,
1964 },
Adam Langley7c803a62015-06-15 15:35:05 -07001965 sendWarningAlerts: 4,
1966 },
1967 {
David Benjamine8e84b92016-08-03 15:39:47 -04001968 protocol: dtls,
1969 name: "SendWarningAlerts-DTLS-Pass",
1970 config: Config{
1971 MaxVersion: VersionTLS12,
1972 },
Adam Langley7c803a62015-06-15 15:35:05 -07001973 sendWarningAlerts: 4,
1974 },
1975 {
David Benjamine8e84b92016-08-03 15:39:47 -04001976 name: "SendWarningAlerts-TLS13",
1977 config: Config{
1978 MaxVersion: VersionTLS13,
1979 },
1980 sendWarningAlerts: 4,
1981 shouldFail: true,
1982 expectedError: ":BAD_ALERT:",
1983 expectedLocalError: "remote error: error decoding message",
1984 },
1985 {
1986 name: "SendWarningAlerts",
1987 config: Config{
1988 MaxVersion: VersionTLS12,
1989 },
Adam Langley7c803a62015-06-15 15:35:05 -07001990 sendWarningAlerts: 5,
1991 shouldFail: true,
1992 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1993 },
1994 {
David Benjamine8e84b92016-08-03 15:39:47 -04001995 name: "SendWarningAlerts-Async",
1996 config: Config{
1997 MaxVersion: VersionTLS12,
1998 },
Adam Langley7c803a62015-06-15 15:35:05 -07001999 sendWarningAlerts: 5,
2000 flags: []string{"-async"},
2001 shouldFail: true,
2002 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2003 },
David Benjaminba4594a2015-06-18 18:36:15 -04002004 {
2005 name: "EmptySessionID",
2006 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002007 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002008 SessionTicketsDisabled: true,
2009 },
2010 noSessionCache: true,
2011 flags: []string{"-expect-no-session"},
2012 },
David Benjamin30789da2015-08-29 22:56:45 -04002013 {
2014 name: "Unclean-Shutdown",
2015 config: Config{
2016 Bugs: ProtocolBugs{
2017 NoCloseNotify: true,
2018 ExpectCloseNotify: true,
2019 },
2020 },
2021 shimShutsDown: true,
2022 flags: []string{"-check-close-notify"},
2023 shouldFail: true,
2024 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2025 },
2026 {
2027 name: "Unclean-Shutdown-Ignored",
2028 config: Config{
2029 Bugs: ProtocolBugs{
2030 NoCloseNotify: true,
2031 },
2032 },
2033 shimShutsDown: true,
2034 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002035 {
David Benjaminfa214e42016-05-10 17:03:10 -04002036 name: "Unclean-Shutdown-Alert",
2037 config: Config{
2038 Bugs: ProtocolBugs{
2039 SendAlertOnShutdown: alertDecompressionFailure,
2040 ExpectCloseNotify: true,
2041 },
2042 },
2043 shimShutsDown: true,
2044 flags: []string{"-check-close-notify"},
2045 shouldFail: true,
2046 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2047 },
2048 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002049 name: "LargePlaintext",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 SendLargeRecords: true,
2053 },
2054 },
2055 messageLen: maxPlaintext + 1,
2056 shouldFail: true,
2057 expectedError: ":DATA_LENGTH_TOO_LONG:",
2058 },
2059 {
2060 protocol: dtls,
2061 name: "LargePlaintext-DTLS",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SendLargeRecords: true,
2065 },
2066 },
2067 messageLen: maxPlaintext + 1,
2068 shouldFail: true,
2069 expectedError: ":DATA_LENGTH_TOO_LONG:",
2070 },
2071 {
2072 name: "LargeCiphertext",
2073 config: Config{
2074 Bugs: ProtocolBugs{
2075 SendLargeRecords: true,
2076 },
2077 },
2078 messageLen: maxPlaintext * 2,
2079 shouldFail: true,
2080 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2081 },
2082 {
2083 protocol: dtls,
2084 name: "LargeCiphertext-DTLS",
2085 config: Config{
2086 Bugs: ProtocolBugs{
2087 SendLargeRecords: true,
2088 },
2089 },
2090 messageLen: maxPlaintext * 2,
2091 // Unlike the other four cases, DTLS drops records which
2092 // are invalid before authentication, so the connection
2093 // does not fail.
2094 expectMessageDropped: true,
2095 },
David Benjamindd6fed92015-10-23 17:41:12 -04002096 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002097 // In TLS 1.2 and below, empty NewSessionTicket messages
2098 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002099 name: "SendEmptySessionTicket",
2100 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002101 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002102 Bugs: ProtocolBugs{
2103 SendEmptySessionTicket: true,
2104 FailIfSessionOffered: true,
2105 },
2106 },
2107 flags: []string{"-expect-no-session"},
2108 resumeSession: true,
2109 expectResumeRejected: true,
2110 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002111 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002112 name: "BadHelloRequest-1",
2113 renegotiate: 1,
2114 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002115 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002116 Bugs: ProtocolBugs{
2117 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2118 },
2119 },
2120 flags: []string{
2121 "-renegotiate-freely",
2122 "-expect-total-renegotiations", "1",
2123 },
2124 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002125 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002126 },
2127 {
2128 name: "BadHelloRequest-2",
2129 renegotiate: 1,
2130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002131 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 Bugs: ProtocolBugs{
2133 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2134 },
2135 },
2136 flags: []string{
2137 "-renegotiate-freely",
2138 "-expect-total-renegotiations", "1",
2139 },
2140 shouldFail: true,
2141 expectedError: ":BAD_HELLO_REQUEST:",
2142 },
David Benjaminef1b0092015-11-21 14:05:44 -05002143 {
2144 testType: serverTest,
2145 name: "SupportTicketsWithSessionID",
2146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002147 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002148 SessionTicketsDisabled: true,
2149 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002150 resumeConfig: &Config{
2151 MaxVersion: VersionTLS12,
2152 },
David Benjaminef1b0092015-11-21 14:05:44 -05002153 resumeSession: true,
2154 },
David Benjamin02edcd02016-07-27 17:40:37 -04002155 {
2156 protocol: dtls,
2157 name: "DTLS-SendExtraFinished",
2158 config: Config{
2159 Bugs: ProtocolBugs{
2160 SendExtraFinished: true,
2161 },
2162 },
2163 shouldFail: true,
2164 expectedError: ":UNEXPECTED_RECORD:",
2165 },
2166 {
2167 protocol: dtls,
2168 name: "DTLS-SendExtraFinished-Reordered",
2169 config: Config{
2170 Bugs: ProtocolBugs{
2171 MaxHandshakeRecordLength: 2,
2172 ReorderHandshakeFragments: true,
2173 SendExtraFinished: true,
2174 },
2175 },
2176 shouldFail: true,
2177 expectedError: ":UNEXPECTED_RECORD:",
2178 },
David Benjamine97fb482016-07-29 09:23:07 -04002179 {
2180 testType: serverTest,
2181 name: "V2ClientHello-EmptyRecordPrefix",
2182 config: Config{
2183 // Choose a cipher suite that does not involve
2184 // elliptic curves, so no extensions are
2185 // involved.
2186 MaxVersion: VersionTLS12,
2187 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2188 Bugs: ProtocolBugs{
2189 SendV2ClientHello: true,
2190 },
2191 },
2192 sendPrefix: string([]byte{
2193 byte(recordTypeHandshake),
2194 3, 1, // version
2195 0, 0, // length
2196 }),
2197 // A no-op empty record may not be sent before V2ClientHello.
2198 shouldFail: true,
2199 expectedError: ":WRONG_VERSION_NUMBER:",
2200 },
2201 {
2202 testType: serverTest,
2203 name: "V2ClientHello-WarningAlertPrefix",
2204 config: Config{
2205 // Choose a cipher suite that does not involve
2206 // elliptic curves, so no extensions are
2207 // involved.
2208 MaxVersion: VersionTLS12,
2209 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2210 Bugs: ProtocolBugs{
2211 SendV2ClientHello: true,
2212 },
2213 },
2214 sendPrefix: string([]byte{
2215 byte(recordTypeAlert),
2216 3, 1, // version
2217 0, 2, // length
2218 alertLevelWarning, byte(alertDecompressionFailure),
2219 }),
2220 // A no-op warning alert may not be sent before V2ClientHello.
2221 shouldFail: true,
2222 expectedError: ":WRONG_VERSION_NUMBER:",
2223 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002224 {
2225 testType: clientTest,
2226 name: "KeyUpdate",
2227 config: Config{
2228 MaxVersion: VersionTLS13,
2229 Bugs: ProtocolBugs{
2230 SendKeyUpdateBeforeEveryAppDataRecord: true,
2231 },
2232 },
2233 },
Adam Langley7c803a62015-06-15 15:35:05 -07002234 }
Adam Langley7c803a62015-06-15 15:35:05 -07002235 testCases = append(testCases, basicTests...)
2236}
2237
Adam Langley95c29f32014-06-20 12:00:00 -07002238func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002239 const bogusCipher = 0xfe00
2240
Adam Langley95c29f32014-06-20 12:00:00 -07002241 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002242 const psk = "12345"
2243 const pskIdentity = "luggage combo"
2244
Adam Langley95c29f32014-06-20 12:00:00 -07002245 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002246 var certFile string
2247 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002248 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002249 cert = ecdsaP256Certificate
2250 certFile = ecdsaP256CertificateFile
2251 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002252 } else {
David Benjamin33863262016-07-08 17:20:12 -07002253 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002254 certFile = rsaCertificateFile
2255 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002256 }
2257
David Benjamin48cae082014-10-27 01:06:24 -04002258 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002259 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002260 flags = append(flags,
2261 "-psk", psk,
2262 "-psk-identity", pskIdentity)
2263 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002264 if hasComponent(suite.name, "NULL") {
2265 // NULL ciphers must be explicitly enabled.
2266 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2267 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002268 if hasComponent(suite.name, "CECPQ1") {
2269 // CECPQ1 ciphers must be explicitly enabled.
2270 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2271 }
David Benjamin48cae082014-10-27 01:06:24 -04002272
Adam Langley95c29f32014-06-20 12:00:00 -07002273 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002274 for _, protocol := range []protocol{tls, dtls} {
2275 var prefix string
2276 if protocol == dtls {
2277 if !ver.hasDTLS {
2278 continue
2279 }
2280 prefix = "D"
2281 }
Adam Langley95c29f32014-06-20 12:00:00 -07002282
David Benjamin0407e762016-06-17 16:41:18 -04002283 var shouldServerFail, shouldClientFail bool
2284 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2285 // BoringSSL clients accept ECDHE on SSLv3, but
2286 // a BoringSSL server will never select it
2287 // because the extension is missing.
2288 shouldServerFail = true
2289 }
2290 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2291 shouldClientFail = true
2292 shouldServerFail = true
2293 }
David Benjamin54c217c2016-07-13 12:35:25 -04002294 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002295 shouldClientFail = true
2296 shouldServerFail = true
2297 }
David Benjamin0407e762016-06-17 16:41:18 -04002298 if !isDTLSCipher(suite.name) && protocol == dtls {
2299 shouldClientFail = true
2300 shouldServerFail = true
2301 }
David Benjamin4298d772015-12-19 00:18:25 -05002302
David Benjamin0407e762016-06-17 16:41:18 -04002303 var expectedServerError, expectedClientError string
2304 if shouldServerFail {
2305 expectedServerError = ":NO_SHARED_CIPHER:"
2306 }
2307 if shouldClientFail {
2308 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2309 }
David Benjamin025b3d32014-07-01 19:53:04 -04002310
David Benjamin9deb1172016-07-13 17:13:49 -04002311 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2312 resumeSession := ver.version < VersionTLS13
2313
David Benjamin6fd297b2014-08-11 18:43:38 -04002314 testCases = append(testCases, testCase{
2315 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002316 protocol: protocol,
2317
2318 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002319 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002320 MinVersion: ver.version,
2321 MaxVersion: ver.version,
2322 CipherSuites: []uint16{suite.id},
2323 Certificates: []Certificate{cert},
2324 PreSharedKey: []byte(psk),
2325 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002326 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002327 EnableAllCiphers: shouldServerFail,
2328 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002329 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002330 },
2331 certFile: certFile,
2332 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002333 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002334 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002335 shouldFail: shouldServerFail,
2336 expectedError: expectedServerError,
2337 })
2338
2339 testCases = append(testCases, testCase{
2340 testType: clientTest,
2341 protocol: protocol,
2342 name: prefix + ver.name + "-" + suite.name + "-client",
2343 config: Config{
2344 MinVersion: ver.version,
2345 MaxVersion: ver.version,
2346 CipherSuites: []uint16{suite.id},
2347 Certificates: []Certificate{cert},
2348 PreSharedKey: []byte(psk),
2349 PreSharedKeyIdentity: pskIdentity,
2350 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002351 EnableAllCiphers: shouldClientFail,
2352 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002353 },
2354 },
2355 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002356 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002357 shouldFail: shouldClientFail,
2358 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002359 })
David Benjamin2c99d282015-09-01 10:23:00 -04002360
Nick Harper1fd39d82016-06-14 18:14:35 -07002361 if !shouldClientFail {
2362 // Ensure the maximum record size is accepted.
2363 testCases = append(testCases, testCase{
2364 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2365 config: Config{
2366 MinVersion: ver.version,
2367 MaxVersion: ver.version,
2368 CipherSuites: []uint16{suite.id},
2369 Certificates: []Certificate{cert},
2370 PreSharedKey: []byte(psk),
2371 PreSharedKeyIdentity: pskIdentity,
2372 },
2373 flags: flags,
2374 messageLen: maxPlaintext,
2375 })
2376 }
2377 }
David Benjamin2c99d282015-09-01 10:23:00 -04002378 }
Adam Langley95c29f32014-06-20 12:00:00 -07002379 }
Adam Langleya7997f12015-05-14 17:38:50 -07002380
2381 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002382 name: "NoSharedCipher",
2383 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002384 MaxVersion: VersionTLS12,
2385 CipherSuites: []uint16{},
2386 },
2387 shouldFail: true,
2388 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2389 })
2390
2391 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002392 name: "NoSharedCipher-TLS13",
2393 config: Config{
2394 MaxVersion: VersionTLS13,
2395 CipherSuites: []uint16{},
2396 },
2397 shouldFail: true,
2398 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2399 })
2400
2401 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002402 name: "UnsupportedCipherSuite",
2403 config: Config{
2404 MaxVersion: VersionTLS12,
2405 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2406 Bugs: ProtocolBugs{
2407 IgnorePeerCipherPreferences: true,
2408 },
2409 },
2410 flags: []string{"-cipher", "DEFAULT:!RC4"},
2411 shouldFail: true,
2412 expectedError: ":WRONG_CIPHER_RETURNED:",
2413 })
2414
2415 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002416 name: "ServerHelloBogusCipher",
2417 config: Config{
2418 MaxVersion: VersionTLS12,
2419 Bugs: ProtocolBugs{
2420 SendCipherSuite: bogusCipher,
2421 },
2422 },
2423 shouldFail: true,
2424 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2425 })
2426 testCases = append(testCases, testCase{
2427 name: "ServerHelloBogusCipher-TLS13",
2428 config: Config{
2429 MaxVersion: VersionTLS13,
2430 Bugs: ProtocolBugs{
2431 SendCipherSuite: bogusCipher,
2432 },
2433 },
2434 shouldFail: true,
2435 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2436 })
2437
2438 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002439 name: "WeakDH",
2440 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002441 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002442 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2443 Bugs: ProtocolBugs{
2444 // This is a 1023-bit prime number, generated
2445 // with:
2446 // openssl gendh 1023 | openssl asn1parse -i
2447 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2448 },
2449 },
2450 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002451 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002452 })
Adam Langleycef75832015-09-03 14:51:12 -07002453
David Benjamincd24a392015-11-11 13:23:05 -08002454 testCases = append(testCases, testCase{
2455 name: "SillyDH",
2456 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002457 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002458 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2459 Bugs: ProtocolBugs{
2460 // This is a 4097-bit prime number, generated
2461 // with:
2462 // openssl gendh 4097 | openssl asn1parse -i
2463 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2464 },
2465 },
2466 shouldFail: true,
2467 expectedError: ":DH_P_TOO_LONG:",
2468 })
2469
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002470 // This test ensures that Diffie-Hellman public values are padded with
2471 // zeros so that they're the same length as the prime. This is to avoid
2472 // hitting a bug in yaSSL.
2473 testCases = append(testCases, testCase{
2474 testType: serverTest,
2475 name: "DHPublicValuePadded",
2476 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002477 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002478 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2479 Bugs: ProtocolBugs{
2480 RequireDHPublicValueLen: (1025 + 7) / 8,
2481 },
2482 },
2483 flags: []string{"-use-sparse-dh-prime"},
2484 })
David Benjamincd24a392015-11-11 13:23:05 -08002485
David Benjamin241ae832016-01-15 03:04:54 -05002486 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002487 testCases = append(testCases, testCase{
2488 testType: serverTest,
2489 name: "UnknownCipher",
2490 config: Config{
2491 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2492 },
2493 })
2494
Adam Langleycef75832015-09-03 14:51:12 -07002495 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2496 // 1.1 specific cipher suite settings. A server is setup with the given
2497 // cipher lists and then a connection is made for each member of
2498 // expectations. The cipher suite that the server selects must match
2499 // the specified one.
2500 var versionSpecificCiphersTest = []struct {
2501 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2502 // expectations is a map from TLS version to cipher suite id.
2503 expectations map[uint16]uint16
2504 }{
2505 {
2506 // Test that the null case (where no version-specific ciphers are set)
2507 // works as expected.
2508 "RC4-SHA:AES128-SHA", // default ciphers
2509 "", // no ciphers specifically for TLS ≥ 1.0
2510 "", // no ciphers specifically for TLS ≥ 1.1
2511 map[uint16]uint16{
2512 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2513 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2514 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2515 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2516 },
2517 },
2518 {
2519 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2520 // cipher.
2521 "RC4-SHA:AES128-SHA", // default
2522 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2523 "", // no ciphers specifically for TLS ≥ 1.1
2524 map[uint16]uint16{
2525 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2526 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2527 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2528 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2529 },
2530 },
2531 {
2532 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2533 // cipher.
2534 "RC4-SHA:AES128-SHA", // default
2535 "", // no ciphers specifically for TLS ≥ 1.0
2536 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2537 map[uint16]uint16{
2538 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2539 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2540 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2541 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2542 },
2543 },
2544 {
2545 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2546 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2547 "RC4-SHA:AES128-SHA", // default
2548 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2549 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2550 map[uint16]uint16{
2551 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2552 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2553 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2554 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2555 },
2556 },
2557 }
2558
2559 for i, test := range versionSpecificCiphersTest {
2560 for version, expectedCipherSuite := range test.expectations {
2561 flags := []string{"-cipher", test.ciphersDefault}
2562 if len(test.ciphersTLS10) > 0 {
2563 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2564 }
2565 if len(test.ciphersTLS11) > 0 {
2566 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2567 }
2568
2569 testCases = append(testCases, testCase{
2570 testType: serverTest,
2571 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2572 config: Config{
2573 MaxVersion: version,
2574 MinVersion: version,
2575 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2576 },
2577 flags: flags,
2578 expectedCipher: expectedCipherSuite,
2579 })
2580 }
2581 }
Adam Langley95c29f32014-06-20 12:00:00 -07002582}
2583
2584func addBadECDSASignatureTests() {
2585 for badR := BadValue(1); badR < NumBadValues; badR++ {
2586 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002587 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002588 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2589 config: Config{
2590 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002591 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002592 Bugs: ProtocolBugs{
2593 BadECDSAR: badR,
2594 BadECDSAS: badS,
2595 },
2596 },
2597 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002598 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002599 })
2600 }
2601 }
2602}
2603
Adam Langley80842bd2014-06-20 12:00:00 -07002604func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002605 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002606 name: "MaxCBCPadding",
2607 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002608 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002609 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2610 Bugs: ProtocolBugs{
2611 MaxPadding: true,
2612 },
2613 },
2614 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2615 })
David Benjamin025b3d32014-07-01 19:53:04 -04002616 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002617 name: "BadCBCPadding",
2618 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002619 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002620 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2621 Bugs: ProtocolBugs{
2622 PaddingFirstByteBad: true,
2623 },
2624 },
2625 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002626 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002627 })
2628 // OpenSSL previously had an issue where the first byte of padding in
2629 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002630 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002631 name: "BadCBCPadding255",
2632 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002633 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002634 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2635 Bugs: ProtocolBugs{
2636 MaxPadding: true,
2637 PaddingFirstByteBadIf255: true,
2638 },
2639 },
2640 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2641 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002642 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002643 })
2644}
2645
Kenny Root7fdeaf12014-08-05 15:23:37 -07002646func addCBCSplittingTests() {
2647 testCases = append(testCases, testCase{
2648 name: "CBCRecordSplitting",
2649 config: Config{
2650 MaxVersion: VersionTLS10,
2651 MinVersion: VersionTLS10,
2652 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2653 },
David Benjaminac8302a2015-09-01 17:18:15 -04002654 messageLen: -1, // read until EOF
2655 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002656 flags: []string{
2657 "-async",
2658 "-write-different-record-sizes",
2659 "-cbc-record-splitting",
2660 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002661 })
2662 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002663 name: "CBCRecordSplittingPartialWrite",
2664 config: Config{
2665 MaxVersion: VersionTLS10,
2666 MinVersion: VersionTLS10,
2667 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2668 },
2669 messageLen: -1, // read until EOF
2670 flags: []string{
2671 "-async",
2672 "-write-different-record-sizes",
2673 "-cbc-record-splitting",
2674 "-partial-write",
2675 },
2676 })
2677}
2678
David Benjamin636293b2014-07-08 17:59:18 -04002679func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002680 // Add a dummy cert pool to stress certificate authority parsing.
2681 // TODO(davidben): Add tests that those values parse out correctly.
2682 certPool := x509.NewCertPool()
2683 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2684 if err != nil {
2685 panic(err)
2686 }
2687 certPool.AddCert(cert)
2688
David Benjamin636293b2014-07-08 17:59:18 -04002689 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002690 testCases = append(testCases, testCase{
2691 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002692 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002693 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002694 MinVersion: ver.version,
2695 MaxVersion: ver.version,
2696 ClientAuth: RequireAnyClientCert,
2697 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002698 },
2699 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002700 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2701 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002702 },
2703 })
2704 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002705 testType: serverTest,
2706 name: ver.name + "-Server-ClientAuth-RSA",
2707 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002708 MinVersion: ver.version,
2709 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002710 Certificates: []Certificate{rsaCertificate},
2711 },
2712 flags: []string{"-require-any-client-certificate"},
2713 })
David Benjamine098ec22014-08-27 23:13:20 -04002714 if ver.version != VersionSSL30 {
2715 testCases = append(testCases, testCase{
2716 testType: serverTest,
2717 name: ver.name + "-Server-ClientAuth-ECDSA",
2718 config: Config{
2719 MinVersion: ver.version,
2720 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002721 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002722 },
2723 flags: []string{"-require-any-client-certificate"},
2724 })
2725 testCases = append(testCases, testCase{
2726 testType: clientTest,
2727 name: ver.name + "-Client-ClientAuth-ECDSA",
2728 config: Config{
2729 MinVersion: ver.version,
2730 MaxVersion: ver.version,
2731 ClientAuth: RequireAnyClientCert,
2732 ClientCAs: certPool,
2733 },
2734 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002735 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2736 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002737 },
2738 })
2739 }
David Benjamin636293b2014-07-08 17:59:18 -04002740 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002741
2742 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002743 name: "NoClientCertificate",
2744 config: Config{
2745 MaxVersion: VersionTLS12,
2746 ClientAuth: RequireAnyClientCert,
2747 },
2748 shouldFail: true,
2749 expectedLocalError: "client didn't provide a certificate",
2750 })
2751
2752 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002753 name: "NoClientCertificate-TLS13",
2754 config: Config{
2755 MaxVersion: VersionTLS13,
2756 ClientAuth: RequireAnyClientCert,
2757 },
2758 shouldFail: true,
2759 expectedLocalError: "client didn't provide a certificate",
2760 })
2761
2762 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002763 testType: serverTest,
2764 name: "RequireAnyClientCertificate",
2765 config: Config{
2766 MaxVersion: VersionTLS12,
2767 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002768 flags: []string{"-require-any-client-certificate"},
2769 shouldFail: true,
2770 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2771 })
2772
2773 testCases = append(testCases, testCase{
2774 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002775 name: "RequireAnyClientCertificate-TLS13",
2776 config: Config{
2777 MaxVersion: VersionTLS13,
2778 },
2779 flags: []string{"-require-any-client-certificate"},
2780 shouldFail: true,
2781 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2782 })
2783
2784 testCases = append(testCases, testCase{
2785 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002786 name: "RequireAnyClientCertificate-SSL3",
2787 config: Config{
2788 MaxVersion: VersionSSL30,
2789 },
2790 flags: []string{"-require-any-client-certificate"},
2791 shouldFail: true,
2792 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2793 })
2794
2795 testCases = append(testCases, testCase{
2796 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002797 name: "SkipClientCertificate",
2798 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002799 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002800 Bugs: ProtocolBugs{
2801 SkipClientCertificate: true,
2802 },
2803 },
2804 // Setting SSL_VERIFY_PEER allows anonymous clients.
2805 flags: []string{"-verify-peer"},
2806 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002807 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002808 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002809
Steven Valdez143e8b32016-07-11 13:19:03 -04002810 testCases = append(testCases, testCase{
2811 testType: serverTest,
2812 name: "SkipClientCertificate-TLS13",
2813 config: Config{
2814 MaxVersion: VersionTLS13,
2815 Bugs: ProtocolBugs{
2816 SkipClientCertificate: true,
2817 },
2818 },
2819 // Setting SSL_VERIFY_PEER allows anonymous clients.
2820 flags: []string{"-verify-peer"},
2821 shouldFail: true,
2822 expectedError: ":UNEXPECTED_MESSAGE:",
2823 })
2824
David Benjaminc032dfa2016-05-12 14:54:57 -04002825 // Client auth is only legal in certificate-based ciphers.
2826 testCases = append(testCases, testCase{
2827 testType: clientTest,
2828 name: "ClientAuth-PSK",
2829 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002830 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002831 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2832 PreSharedKey: []byte("secret"),
2833 ClientAuth: RequireAnyClientCert,
2834 },
2835 flags: []string{
2836 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2837 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2838 "-psk", "secret",
2839 },
2840 shouldFail: true,
2841 expectedError: ":UNEXPECTED_MESSAGE:",
2842 })
2843 testCases = append(testCases, testCase{
2844 testType: clientTest,
2845 name: "ClientAuth-ECDHE_PSK",
2846 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002847 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002848 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2849 PreSharedKey: []byte("secret"),
2850 ClientAuth: RequireAnyClientCert,
2851 },
2852 flags: []string{
2853 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2854 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2855 "-psk", "secret",
2856 },
2857 shouldFail: true,
2858 expectedError: ":UNEXPECTED_MESSAGE:",
2859 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002860
2861 // Regression test for a bug where the client CA list, if explicitly
2862 // set to NULL, was mis-encoded.
2863 testCases = append(testCases, testCase{
2864 testType: serverTest,
2865 name: "Null-Client-CA-List",
2866 config: Config{
2867 MaxVersion: VersionTLS12,
2868 Certificates: []Certificate{rsaCertificate},
2869 },
2870 flags: []string{
2871 "-require-any-client-certificate",
2872 "-use-null-client-ca-list",
2873 },
2874 })
David Benjamin636293b2014-07-08 17:59:18 -04002875}
2876
Adam Langley75712922014-10-10 16:23:43 -07002877func addExtendedMasterSecretTests() {
2878 const expectEMSFlag = "-expect-extended-master-secret"
2879
2880 for _, with := range []bool{false, true} {
2881 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002882 if with {
2883 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002884 }
2885
2886 for _, isClient := range []bool{false, true} {
2887 suffix := "-Server"
2888 testType := serverTest
2889 if isClient {
2890 suffix = "-Client"
2891 testType = clientTest
2892 }
2893
2894 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002895 // In TLS 1.3, the extension is irrelevant and
2896 // always reports as enabled.
2897 var flags []string
2898 if with || ver.version >= VersionTLS13 {
2899 flags = []string{expectEMSFlag}
2900 }
2901
Adam Langley75712922014-10-10 16:23:43 -07002902 test := testCase{
2903 testType: testType,
2904 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2905 config: Config{
2906 MinVersion: ver.version,
2907 MaxVersion: ver.version,
2908 Bugs: ProtocolBugs{
2909 NoExtendedMasterSecret: !with,
2910 RequireExtendedMasterSecret: with,
2911 },
2912 },
David Benjamin48cae082014-10-27 01:06:24 -04002913 flags: flags,
2914 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002915 }
2916 if test.shouldFail {
2917 test.expectedLocalError = "extended master secret required but not supported by peer"
2918 }
2919 testCases = append(testCases, test)
2920 }
2921 }
2922 }
2923
Adam Langleyba5934b2015-06-02 10:50:35 -07002924 for _, isClient := range []bool{false, true} {
2925 for _, supportedInFirstConnection := range []bool{false, true} {
2926 for _, supportedInResumeConnection := range []bool{false, true} {
2927 boolToWord := func(b bool) string {
2928 if b {
2929 return "Yes"
2930 }
2931 return "No"
2932 }
2933 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2934 if isClient {
2935 suffix += "Client"
2936 } else {
2937 suffix += "Server"
2938 }
2939
2940 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002941 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002942 Bugs: ProtocolBugs{
2943 RequireExtendedMasterSecret: true,
2944 },
2945 }
2946
2947 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002948 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002949 Bugs: ProtocolBugs{
2950 NoExtendedMasterSecret: true,
2951 },
2952 }
2953
2954 test := testCase{
2955 name: "ExtendedMasterSecret-" + suffix,
2956 resumeSession: true,
2957 }
2958
2959 if !isClient {
2960 test.testType = serverTest
2961 }
2962
2963 if supportedInFirstConnection {
2964 test.config = supportedConfig
2965 } else {
2966 test.config = noSupportConfig
2967 }
2968
2969 if supportedInResumeConnection {
2970 test.resumeConfig = &supportedConfig
2971 } else {
2972 test.resumeConfig = &noSupportConfig
2973 }
2974
2975 switch suffix {
2976 case "YesToYes-Client", "YesToYes-Server":
2977 // When a session is resumed, it should
2978 // still be aware that its master
2979 // secret was generated via EMS and
2980 // thus it's safe to use tls-unique.
2981 test.flags = []string{expectEMSFlag}
2982 case "NoToYes-Server":
2983 // If an original connection did not
2984 // contain EMS, but a resumption
2985 // handshake does, then a server should
2986 // not resume the session.
2987 test.expectResumeRejected = true
2988 case "YesToNo-Server":
2989 // Resuming an EMS session without the
2990 // EMS extension should cause the
2991 // server to abort the connection.
2992 test.shouldFail = true
2993 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2994 case "NoToYes-Client":
2995 // A client should abort a connection
2996 // where the server resumed a non-EMS
2997 // session but echoed the EMS
2998 // extension.
2999 test.shouldFail = true
3000 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3001 case "YesToNo-Client":
3002 // A client should abort a connection
3003 // where the server didn't echo EMS
3004 // when the session used it.
3005 test.shouldFail = true
3006 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3007 }
3008
3009 testCases = append(testCases, test)
3010 }
3011 }
3012 }
Adam Langley75712922014-10-10 16:23:43 -07003013}
3014
David Benjamin582ba042016-07-07 12:33:25 -07003015type stateMachineTestConfig struct {
3016 protocol protocol
3017 async bool
3018 splitHandshake, packHandshakeFlight bool
3019}
3020
David Benjamin43ec06f2014-08-05 02:28:57 -04003021// Adds tests that try to cover the range of the handshake state machine, under
3022// various conditions. Some of these are redundant with other tests, but they
3023// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003024func addAllStateMachineCoverageTests() {
3025 for _, async := range []bool{false, true} {
3026 for _, protocol := range []protocol{tls, dtls} {
3027 addStateMachineCoverageTests(stateMachineTestConfig{
3028 protocol: protocol,
3029 async: async,
3030 })
3031 addStateMachineCoverageTests(stateMachineTestConfig{
3032 protocol: protocol,
3033 async: async,
3034 splitHandshake: true,
3035 })
3036 if protocol == tls {
3037 addStateMachineCoverageTests(stateMachineTestConfig{
3038 protocol: protocol,
3039 async: async,
3040 packHandshakeFlight: true,
3041 })
3042 }
3043 }
3044 }
3045}
3046
3047func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003048 var tests []testCase
3049
3050 // Basic handshake, with resumption. Client and server,
3051 // session ID and session ticket.
3052 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003053 name: "Basic-Client",
3054 config: Config{
3055 MaxVersion: VersionTLS12,
3056 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003057 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003058 // Ensure session tickets are used, not session IDs.
3059 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003060 })
3061 tests = append(tests, testCase{
3062 name: "Basic-Client-RenewTicket",
3063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003064 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003065 Bugs: ProtocolBugs{
3066 RenewTicketOnResume: true,
3067 },
3068 },
David Benjaminba4594a2015-06-18 18:36:15 -04003069 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003070 resumeSession: true,
3071 })
3072 tests = append(tests, testCase{
3073 name: "Basic-Client-NoTicket",
3074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003075 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003076 SessionTicketsDisabled: true,
3077 },
3078 resumeSession: true,
3079 })
3080 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003081 name: "Basic-Client-Implicit",
3082 config: Config{
3083 MaxVersion: VersionTLS12,
3084 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003085 flags: []string{"-implicit-handshake"},
3086 resumeSession: true,
3087 })
3088 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003089 testType: serverTest,
3090 name: "Basic-Server",
3091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003092 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003093 Bugs: ProtocolBugs{
3094 RequireSessionTickets: true,
3095 },
3096 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003097 resumeSession: true,
3098 })
3099 tests = append(tests, testCase{
3100 testType: serverTest,
3101 name: "Basic-Server-NoTickets",
3102 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003103 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003104 SessionTicketsDisabled: true,
3105 },
3106 resumeSession: true,
3107 })
3108 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003109 testType: serverTest,
3110 name: "Basic-Server-Implicit",
3111 config: Config{
3112 MaxVersion: VersionTLS12,
3113 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003114 flags: []string{"-implicit-handshake"},
3115 resumeSession: true,
3116 })
3117 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003118 testType: serverTest,
3119 name: "Basic-Server-EarlyCallback",
3120 config: Config{
3121 MaxVersion: VersionTLS12,
3122 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003123 flags: []string{"-use-early-callback"},
3124 resumeSession: true,
3125 })
3126
Steven Valdez143e8b32016-07-11 13:19:03 -04003127 // TLS 1.3 basic handshake shapes.
3128 tests = append(tests, testCase{
3129 name: "TLS13-1RTT-Client",
3130 config: Config{
3131 MaxVersion: VersionTLS13,
3132 },
3133 })
3134 tests = append(tests, testCase{
3135 testType: serverTest,
3136 name: "TLS13-1RTT-Server",
3137 config: Config{
3138 MaxVersion: VersionTLS13,
3139 },
3140 })
3141
David Benjamin760b1dd2015-05-15 23:33:48 -04003142 // TLS client auth.
3143 tests = append(tests, testCase{
3144 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003145 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003147 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003148 ClientAuth: RequestClientCert,
3149 },
3150 })
3151 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003152 testType: serverTest,
3153 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003154 config: Config{
3155 MaxVersion: VersionTLS12,
3156 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003157 // Setting SSL_VERIFY_PEER allows anonymous clients.
3158 flags: []string{"-verify-peer"},
3159 })
David Benjamin582ba042016-07-07 12:33:25 -07003160 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003161 tests = append(tests, testCase{
3162 testType: clientTest,
3163 name: "ClientAuth-NoCertificate-Client-SSL3",
3164 config: Config{
3165 MaxVersion: VersionSSL30,
3166 ClientAuth: RequestClientCert,
3167 },
3168 })
3169 tests = append(tests, testCase{
3170 testType: serverTest,
3171 name: "ClientAuth-NoCertificate-Server-SSL3",
3172 config: Config{
3173 MaxVersion: VersionSSL30,
3174 },
3175 // Setting SSL_VERIFY_PEER allows anonymous clients.
3176 flags: []string{"-verify-peer"},
3177 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003178 tests = append(tests, testCase{
3179 testType: clientTest,
3180 name: "ClientAuth-NoCertificate-Client-TLS13",
3181 config: Config{
3182 MaxVersion: VersionTLS13,
3183 ClientAuth: RequestClientCert,
3184 },
3185 })
3186 tests = append(tests, testCase{
3187 testType: serverTest,
3188 name: "ClientAuth-NoCertificate-Server-TLS13",
3189 config: Config{
3190 MaxVersion: VersionTLS13,
3191 },
3192 // Setting SSL_VERIFY_PEER allows anonymous clients.
3193 flags: []string{"-verify-peer"},
3194 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003195 }
3196 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003197 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003198 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003199 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003200 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003201 ClientAuth: RequireAnyClientCert,
3202 },
3203 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003204 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3205 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003206 },
3207 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003208 tests = append(tests, testCase{
3209 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003210 name: "ClientAuth-RSA-Client-TLS13",
3211 config: Config{
3212 MaxVersion: VersionTLS13,
3213 ClientAuth: RequireAnyClientCert,
3214 },
3215 flags: []string{
3216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3218 },
3219 })
3220 tests = append(tests, testCase{
3221 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003222 name: "ClientAuth-ECDSA-Client",
3223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003224 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003225 ClientAuth: RequireAnyClientCert,
3226 },
3227 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003228 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3229 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003230 },
3231 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003232 tests = append(tests, testCase{
3233 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003234 name: "ClientAuth-ECDSA-Client-TLS13",
3235 config: Config{
3236 MaxVersion: VersionTLS13,
3237 ClientAuth: RequireAnyClientCert,
3238 },
3239 flags: []string{
3240 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3241 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3242 },
3243 })
3244 tests = append(tests, testCase{
3245 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 name: "ClientAuth-NoCertificate-OldCallback",
3247 config: Config{
3248 MaxVersion: VersionTLS12,
3249 ClientAuth: RequestClientCert,
3250 },
3251 flags: []string{"-use-old-client-cert-callback"},
3252 })
3253 tests = append(tests, testCase{
3254 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003255 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3256 config: Config{
3257 MaxVersion: VersionTLS13,
3258 ClientAuth: RequestClientCert,
3259 },
3260 flags: []string{"-use-old-client-cert-callback"},
3261 })
3262 tests = append(tests, testCase{
3263 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003264 name: "ClientAuth-OldCallback",
3265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003266 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003267 ClientAuth: RequireAnyClientCert,
3268 },
3269 flags: []string{
3270 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3271 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3272 "-use-old-client-cert-callback",
3273 },
3274 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003275 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003276 testType: clientTest,
3277 name: "ClientAuth-OldCallback-TLS13",
3278 config: Config{
3279 MaxVersion: VersionTLS13,
3280 ClientAuth: RequireAnyClientCert,
3281 },
3282 flags: []string{
3283 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3284 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3285 "-use-old-client-cert-callback",
3286 },
3287 })
3288 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003289 testType: serverTest,
3290 name: "ClientAuth-Server",
3291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003292 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003293 Certificates: []Certificate{rsaCertificate},
3294 },
3295 flags: []string{"-require-any-client-certificate"},
3296 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003297 tests = append(tests, testCase{
3298 testType: serverTest,
3299 name: "ClientAuth-Server-TLS13",
3300 config: Config{
3301 MaxVersion: VersionTLS13,
3302 Certificates: []Certificate{rsaCertificate},
3303 },
3304 flags: []string{"-require-any-client-certificate"},
3305 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003306
David Benjamin4c3ddf72016-06-29 18:13:53 -04003307 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003308 tests = append(tests, testCase{
3309 testType: serverTest,
3310 name: "Basic-Server-RSA",
3311 config: Config{
3312 MaxVersion: VersionTLS12,
3313 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3314 },
3315 flags: []string{
3316 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3317 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3318 },
3319 })
3320 tests = append(tests, testCase{
3321 testType: serverTest,
3322 name: "Basic-Server-ECDHE-RSA",
3323 config: Config{
3324 MaxVersion: VersionTLS12,
3325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3326 },
3327 flags: []string{
3328 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3329 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3330 },
3331 })
3332 tests = append(tests, testCase{
3333 testType: serverTest,
3334 name: "Basic-Server-ECDHE-ECDSA",
3335 config: Config{
3336 MaxVersion: VersionTLS12,
3337 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3338 },
3339 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003340 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3341 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003342 },
3343 })
3344
David Benjamin760b1dd2015-05-15 23:33:48 -04003345 // No session ticket support; server doesn't send NewSessionTicket.
3346 tests = append(tests, testCase{
3347 name: "SessionTicketsDisabled-Client",
3348 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003349 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003350 SessionTicketsDisabled: true,
3351 },
3352 })
3353 tests = append(tests, testCase{
3354 testType: serverTest,
3355 name: "SessionTicketsDisabled-Server",
3356 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003357 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003358 SessionTicketsDisabled: true,
3359 },
3360 })
3361
3362 // Skip ServerKeyExchange in PSK key exchange if there's no
3363 // identity hint.
3364 tests = append(tests, testCase{
3365 name: "EmptyPSKHint-Client",
3366 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003367 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003368 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3369 PreSharedKey: []byte("secret"),
3370 },
3371 flags: []string{"-psk", "secret"},
3372 })
3373 tests = append(tests, testCase{
3374 testType: serverTest,
3375 name: "EmptyPSKHint-Server",
3376 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003377 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003378 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3379 PreSharedKey: []byte("secret"),
3380 },
3381 flags: []string{"-psk", "secret"},
3382 })
3383
David Benjamin4c3ddf72016-06-29 18:13:53 -04003384 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003385 tests = append(tests, testCase{
3386 testType: clientTest,
3387 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003388 config: Config{
3389 MaxVersion: VersionTLS12,
3390 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003391 flags: []string{
3392 "-enable-ocsp-stapling",
3393 "-expect-ocsp-response",
3394 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003395 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003396 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003397 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003398 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003399 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003400 testType: serverTest,
3401 name: "OCSPStapling-Server",
3402 config: Config{
3403 MaxVersion: VersionTLS12,
3404 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003405 expectedOCSPResponse: testOCSPResponse,
3406 flags: []string{
3407 "-ocsp-response",
3408 base64.StdEncoding.EncodeToString(testOCSPResponse),
3409 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003410 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003411 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003412 tests = append(tests, testCase{
3413 testType: clientTest,
3414 name: "OCSPStapling-Client-TLS13",
3415 config: Config{
3416 MaxVersion: VersionTLS13,
3417 },
3418 flags: []string{
3419 "-enable-ocsp-stapling",
3420 "-expect-ocsp-response",
3421 base64.StdEncoding.EncodeToString(testOCSPResponse),
3422 "-verify-peer",
3423 },
3424 // TODO(davidben): Enable this when resumption is implemented
3425 // in TLS 1.3.
3426 resumeSession: false,
3427 })
3428 tests = append(tests, testCase{
3429 testType: serverTest,
3430 name: "OCSPStapling-Server-TLS13",
3431 config: Config{
3432 MaxVersion: VersionTLS13,
3433 },
3434 expectedOCSPResponse: testOCSPResponse,
3435 flags: []string{
3436 "-ocsp-response",
3437 base64.StdEncoding.EncodeToString(testOCSPResponse),
3438 },
3439 // TODO(davidben): Enable this when resumption is implemented
3440 // in TLS 1.3.
3441 resumeSession: false,
3442 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003443
David Benjamin4c3ddf72016-06-29 18:13:53 -04003444 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003445 for _, vers := range tlsVersions {
3446 if config.protocol == dtls && !vers.hasDTLS {
3447 continue
3448 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003449 for _, testType := range []testType{clientTest, serverTest} {
3450 suffix := "-Client"
3451 if testType == serverTest {
3452 suffix = "-Server"
3453 }
3454 suffix += "-" + vers.name
3455
3456 flag := "-verify-peer"
3457 if testType == serverTest {
3458 flag = "-require-any-client-certificate"
3459 }
3460
3461 tests = append(tests, testCase{
3462 testType: testType,
3463 name: "CertificateVerificationSucceed" + suffix,
3464 config: Config{
3465 MaxVersion: vers.version,
3466 Certificates: []Certificate{rsaCertificate},
3467 },
3468 flags: []string{
3469 flag,
3470 "-expect-verify-result",
3471 },
3472 // TODO(davidben): Enable this when resumption is
3473 // implemented in TLS 1.3.
3474 resumeSession: vers.version != VersionTLS13,
3475 })
3476 tests = append(tests, testCase{
3477 testType: testType,
3478 name: "CertificateVerificationFail" + suffix,
3479 config: Config{
3480 MaxVersion: vers.version,
3481 Certificates: []Certificate{rsaCertificate},
3482 },
3483 flags: []string{
3484 flag,
3485 "-verify-fail",
3486 },
3487 shouldFail: true,
3488 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3489 })
3490 }
3491
3492 // By default, the client is in a soft fail mode where the peer
3493 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003494 tests = append(tests, testCase{
3495 testType: clientTest,
3496 name: "CertificateVerificationSoftFail-" + vers.name,
3497 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003498 MaxVersion: vers.version,
3499 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003500 },
3501 flags: []string{
3502 "-verify-fail",
3503 "-expect-verify-result",
3504 },
David Benjaminbb9e36e2016-08-03 14:14:47 -04003505 // TODO(davidben): Enable this when resumption is
3506 // implemented in TLS 1.3.
Adam Langley9498e742016-07-18 10:17:16 -07003507 resumeSession: vers.version != VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04003508 })
3509 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003510
David Benjamin1d4f4c02016-07-26 18:03:08 -04003511 tests = append(tests, testCase{
3512 name: "ShimSendAlert",
3513 flags: []string{"-send-alert"},
3514 shimWritesFirst: true,
3515 shouldFail: true,
3516 expectedLocalError: "remote error: decompression failure",
3517 })
3518
David Benjamin582ba042016-07-07 12:33:25 -07003519 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003520 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003521 name: "Renegotiate-Client",
3522 config: Config{
3523 MaxVersion: VersionTLS12,
3524 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003525 renegotiate: 1,
3526 flags: []string{
3527 "-renegotiate-freely",
3528 "-expect-total-renegotiations", "1",
3529 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003530 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003531
David Benjamin47921102016-07-28 11:29:18 -04003532 tests = append(tests, testCase{
3533 name: "SendHalfHelloRequest",
3534 config: Config{
3535 MaxVersion: VersionTLS12,
3536 Bugs: ProtocolBugs{
3537 PackHelloRequestWithFinished: config.packHandshakeFlight,
3538 },
3539 },
3540 sendHalfHelloRequest: true,
3541 flags: []string{"-renegotiate-ignore"},
3542 shouldFail: true,
3543 expectedError: ":UNEXPECTED_RECORD:",
3544 })
3545
David Benjamin760b1dd2015-05-15 23:33:48 -04003546 // NPN on client and server; results in post-handshake message.
3547 tests = append(tests, testCase{
3548 name: "NPN-Client",
3549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003550 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003551 NextProtos: []string{"foo"},
3552 },
3553 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003554 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003555 expectedNextProto: "foo",
3556 expectedNextProtoType: npn,
3557 })
3558 tests = append(tests, testCase{
3559 testType: serverTest,
3560 name: "NPN-Server",
3561 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003562 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003563 NextProtos: []string{"bar"},
3564 },
3565 flags: []string{
3566 "-advertise-npn", "\x03foo\x03bar\x03baz",
3567 "-expect-next-proto", "bar",
3568 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003569 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003570 expectedNextProto: "bar",
3571 expectedNextProtoType: npn,
3572 })
3573
3574 // TODO(davidben): Add tests for when False Start doesn't trigger.
3575
3576 // Client does False Start and negotiates NPN.
3577 tests = append(tests, testCase{
3578 name: "FalseStart",
3579 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003580 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003581 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3582 NextProtos: []string{"foo"},
3583 Bugs: ProtocolBugs{
3584 ExpectFalseStart: true,
3585 },
3586 },
3587 flags: []string{
3588 "-false-start",
3589 "-select-next-proto", "foo",
3590 },
3591 shimWritesFirst: true,
3592 resumeSession: true,
3593 })
3594
3595 // Client does False Start and negotiates ALPN.
3596 tests = append(tests, testCase{
3597 name: "FalseStart-ALPN",
3598 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003599 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003600 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3601 NextProtos: []string{"foo"},
3602 Bugs: ProtocolBugs{
3603 ExpectFalseStart: true,
3604 },
3605 },
3606 flags: []string{
3607 "-false-start",
3608 "-advertise-alpn", "\x03foo",
3609 },
3610 shimWritesFirst: true,
3611 resumeSession: true,
3612 })
3613
3614 // Client does False Start but doesn't explicitly call
3615 // SSL_connect.
3616 tests = append(tests, testCase{
3617 name: "FalseStart-Implicit",
3618 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003619 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003620 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3621 NextProtos: []string{"foo"},
3622 },
3623 flags: []string{
3624 "-implicit-handshake",
3625 "-false-start",
3626 "-advertise-alpn", "\x03foo",
3627 },
3628 })
3629
3630 // False Start without session tickets.
3631 tests = append(tests, testCase{
3632 name: "FalseStart-SessionTicketsDisabled",
3633 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003634 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003635 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3636 NextProtos: []string{"foo"},
3637 SessionTicketsDisabled: true,
3638 Bugs: ProtocolBugs{
3639 ExpectFalseStart: true,
3640 },
3641 },
3642 flags: []string{
3643 "-false-start",
3644 "-select-next-proto", "foo",
3645 },
3646 shimWritesFirst: true,
3647 })
3648
Adam Langleydf759b52016-07-11 15:24:37 -07003649 tests = append(tests, testCase{
3650 name: "FalseStart-CECPQ1",
3651 config: Config{
3652 MaxVersion: VersionTLS12,
3653 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3654 NextProtos: []string{"foo"},
3655 Bugs: ProtocolBugs{
3656 ExpectFalseStart: true,
3657 },
3658 },
3659 flags: []string{
3660 "-false-start",
3661 "-cipher", "DEFAULT:kCECPQ1",
3662 "-select-next-proto", "foo",
3663 },
3664 shimWritesFirst: true,
3665 resumeSession: true,
3666 })
3667
David Benjamin760b1dd2015-05-15 23:33:48 -04003668 // Server parses a V2ClientHello.
3669 tests = append(tests, testCase{
3670 testType: serverTest,
3671 name: "SendV2ClientHello",
3672 config: Config{
3673 // Choose a cipher suite that does not involve
3674 // elliptic curves, so no extensions are
3675 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003676 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003677 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3678 Bugs: ProtocolBugs{
3679 SendV2ClientHello: true,
3680 },
3681 },
3682 })
3683
3684 // Client sends a Channel ID.
3685 tests = append(tests, testCase{
3686 name: "ChannelID-Client",
3687 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003688 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003689 RequestChannelID: true,
3690 },
Adam Langley7c803a62015-06-15 15:35:05 -07003691 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003692 resumeSession: true,
3693 expectChannelID: true,
3694 })
3695
3696 // Server accepts a Channel ID.
3697 tests = append(tests, testCase{
3698 testType: serverTest,
3699 name: "ChannelID-Server",
3700 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003701 MaxVersion: VersionTLS12,
3702 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003703 },
3704 flags: []string{
3705 "-expect-channel-id",
3706 base64.StdEncoding.EncodeToString(channelIDBytes),
3707 },
3708 resumeSession: true,
3709 expectChannelID: true,
3710 })
David Benjamin30789da2015-08-29 22:56:45 -04003711
David Benjaminf8fcdf32016-06-08 15:56:13 -04003712 // Channel ID and NPN at the same time, to ensure their relative
3713 // ordering is correct.
3714 tests = append(tests, testCase{
3715 name: "ChannelID-NPN-Client",
3716 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003717 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003718 RequestChannelID: true,
3719 NextProtos: []string{"foo"},
3720 },
3721 flags: []string{
3722 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3723 "-select-next-proto", "foo",
3724 },
3725 resumeSession: true,
3726 expectChannelID: true,
3727 expectedNextProto: "foo",
3728 expectedNextProtoType: npn,
3729 })
3730 tests = append(tests, testCase{
3731 testType: serverTest,
3732 name: "ChannelID-NPN-Server",
3733 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003734 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003735 ChannelID: channelIDKey,
3736 NextProtos: []string{"bar"},
3737 },
3738 flags: []string{
3739 "-expect-channel-id",
3740 base64.StdEncoding.EncodeToString(channelIDBytes),
3741 "-advertise-npn", "\x03foo\x03bar\x03baz",
3742 "-expect-next-proto", "bar",
3743 },
3744 resumeSession: true,
3745 expectChannelID: true,
3746 expectedNextProto: "bar",
3747 expectedNextProtoType: npn,
3748 })
3749
David Benjamin30789da2015-08-29 22:56:45 -04003750 // Bidirectional shutdown with the runner initiating.
3751 tests = append(tests, testCase{
3752 name: "Shutdown-Runner",
3753 config: Config{
3754 Bugs: ProtocolBugs{
3755 ExpectCloseNotify: true,
3756 },
3757 },
3758 flags: []string{"-check-close-notify"},
3759 })
3760
3761 // Bidirectional shutdown with the shim initiating. The runner,
3762 // in the meantime, sends garbage before the close_notify which
3763 // the shim must ignore.
3764 tests = append(tests, testCase{
3765 name: "Shutdown-Shim",
3766 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003767 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003768 Bugs: ProtocolBugs{
3769 ExpectCloseNotify: true,
3770 },
3771 },
3772 shimShutsDown: true,
3773 sendEmptyRecords: 1,
3774 sendWarningAlerts: 1,
3775 flags: []string{"-check-close-notify"},
3776 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003777 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003778 // TODO(davidben): DTLS 1.3 will want a similar thing for
3779 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003780 tests = append(tests, testCase{
3781 name: "SkipHelloVerifyRequest",
3782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003784 Bugs: ProtocolBugs{
3785 SkipHelloVerifyRequest: true,
3786 },
3787 },
3788 })
3789 }
3790
David Benjamin760b1dd2015-05-15 23:33:48 -04003791 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003792 test.protocol = config.protocol
3793 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003794 test.name += "-DTLS"
3795 }
David Benjamin582ba042016-07-07 12:33:25 -07003796 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003797 test.name += "-Async"
3798 test.flags = append(test.flags, "-async")
3799 } else {
3800 test.name += "-Sync"
3801 }
David Benjamin582ba042016-07-07 12:33:25 -07003802 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003803 test.name += "-SplitHandshakeRecords"
3804 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003805 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003806 test.config.Bugs.MaxPacketLength = 256
3807 test.flags = append(test.flags, "-mtu", "256")
3808 }
3809 }
David Benjamin582ba042016-07-07 12:33:25 -07003810 if config.packHandshakeFlight {
3811 test.name += "-PackHandshakeFlight"
3812 test.config.Bugs.PackHandshakeFlight = true
3813 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003814 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003815 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003816}
3817
Adam Langley524e7172015-02-20 16:04:00 -08003818func addDDoSCallbackTests() {
3819 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003820 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003821 for _, resume := range []bool{false, true} {
3822 suffix := "Resume"
3823 if resume {
3824 suffix = "No" + suffix
3825 }
3826
3827 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003828 testType: serverTest,
3829 name: "Server-DDoS-OK-" + suffix,
3830 config: Config{
3831 MaxVersion: VersionTLS12,
3832 },
Adam Langley524e7172015-02-20 16:04:00 -08003833 flags: []string{"-install-ddos-callback"},
3834 resumeSession: resume,
3835 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003836 if !resume {
3837 testCases = append(testCases, testCase{
3838 testType: serverTest,
3839 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3840 config: Config{
3841 MaxVersion: VersionTLS13,
3842 },
3843 flags: []string{"-install-ddos-callback"},
3844 resumeSession: resume,
3845 })
3846 }
Adam Langley524e7172015-02-20 16:04:00 -08003847
3848 failFlag := "-fail-ddos-callback"
3849 if resume {
3850 failFlag = "-fail-second-ddos-callback"
3851 }
3852 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003853 testType: serverTest,
3854 name: "Server-DDoS-Reject-" + suffix,
3855 config: Config{
3856 MaxVersion: VersionTLS12,
3857 },
Adam Langley524e7172015-02-20 16:04:00 -08003858 flags: []string{"-install-ddos-callback", failFlag},
3859 resumeSession: resume,
3860 shouldFail: true,
3861 expectedError: ":CONNECTION_REJECTED:",
3862 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003863 if !resume {
3864 testCases = append(testCases, testCase{
3865 testType: serverTest,
3866 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3867 config: Config{
3868 MaxVersion: VersionTLS13,
3869 },
3870 flags: []string{"-install-ddos-callback", failFlag},
3871 resumeSession: resume,
3872 shouldFail: true,
3873 expectedError: ":CONNECTION_REJECTED:",
3874 })
3875 }
Adam Langley524e7172015-02-20 16:04:00 -08003876 }
3877}
3878
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003879func addVersionNegotiationTests() {
3880 for i, shimVers := range tlsVersions {
3881 // Assemble flags to disable all newer versions on the shim.
3882 var flags []string
3883 for _, vers := range tlsVersions[i+1:] {
3884 flags = append(flags, vers.flag)
3885 }
3886
3887 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003888 protocols := []protocol{tls}
3889 if runnerVers.hasDTLS && shimVers.hasDTLS {
3890 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003891 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003892 for _, protocol := range protocols {
3893 expectedVersion := shimVers.version
3894 if runnerVers.version < shimVers.version {
3895 expectedVersion = runnerVers.version
3896 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003897
David Benjamin8b8c0062014-11-23 02:47:52 -05003898 suffix := shimVers.name + "-" + runnerVers.name
3899 if protocol == dtls {
3900 suffix += "-DTLS"
3901 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003902
David Benjamin1eb367c2014-12-12 18:17:51 -05003903 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3904
David Benjamin1e29a6b2014-12-10 02:27:24 -05003905 clientVers := shimVers.version
3906 if clientVers > VersionTLS10 {
3907 clientVers = VersionTLS10
3908 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003909 serverVers := expectedVersion
3910 if expectedVersion >= VersionTLS13 {
3911 serverVers = VersionTLS10
3912 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003913 testCases = append(testCases, testCase{
3914 protocol: protocol,
3915 testType: clientTest,
3916 name: "VersionNegotiation-Client-" + suffix,
3917 config: Config{
3918 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003919 Bugs: ProtocolBugs{
3920 ExpectInitialRecordVersion: clientVers,
3921 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003922 },
3923 flags: flags,
3924 expectedVersion: expectedVersion,
3925 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003926 testCases = append(testCases, testCase{
3927 protocol: protocol,
3928 testType: clientTest,
3929 name: "VersionNegotiation-Client2-" + suffix,
3930 config: Config{
3931 MaxVersion: runnerVers.version,
3932 Bugs: ProtocolBugs{
3933 ExpectInitialRecordVersion: clientVers,
3934 },
3935 },
3936 flags: []string{"-max-version", shimVersFlag},
3937 expectedVersion: expectedVersion,
3938 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003939
3940 testCases = append(testCases, testCase{
3941 protocol: protocol,
3942 testType: serverTest,
3943 name: "VersionNegotiation-Server-" + suffix,
3944 config: Config{
3945 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003946 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003947 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003948 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003949 },
3950 flags: flags,
3951 expectedVersion: expectedVersion,
3952 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003953 testCases = append(testCases, testCase{
3954 protocol: protocol,
3955 testType: serverTest,
3956 name: "VersionNegotiation-Server2-" + suffix,
3957 config: Config{
3958 MaxVersion: runnerVers.version,
3959 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003960 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003961 },
3962 },
3963 flags: []string{"-max-version", shimVersFlag},
3964 expectedVersion: expectedVersion,
3965 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003966 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003967 }
3968 }
David Benjamin95c69562016-06-29 18:15:03 -04003969
3970 // Test for version tolerance.
3971 testCases = append(testCases, testCase{
3972 testType: serverTest,
3973 name: "MinorVersionTolerance",
3974 config: Config{
3975 Bugs: ProtocolBugs{
3976 SendClientVersion: 0x03ff,
3977 },
3978 },
3979 expectedVersion: VersionTLS13,
3980 })
3981 testCases = append(testCases, testCase{
3982 testType: serverTest,
3983 name: "MajorVersionTolerance",
3984 config: Config{
3985 Bugs: ProtocolBugs{
3986 SendClientVersion: 0x0400,
3987 },
3988 },
3989 expectedVersion: VersionTLS13,
3990 })
3991 testCases = append(testCases, testCase{
3992 protocol: dtls,
3993 testType: serverTest,
3994 name: "MinorVersionTolerance-DTLS",
3995 config: Config{
3996 Bugs: ProtocolBugs{
3997 SendClientVersion: 0x03ff,
3998 },
3999 },
4000 expectedVersion: VersionTLS12,
4001 })
4002 testCases = append(testCases, testCase{
4003 protocol: dtls,
4004 testType: serverTest,
4005 name: "MajorVersionTolerance-DTLS",
4006 config: Config{
4007 Bugs: ProtocolBugs{
4008 SendClientVersion: 0x0400,
4009 },
4010 },
4011 expectedVersion: VersionTLS12,
4012 })
4013
4014 // Test that versions below 3.0 are rejected.
4015 testCases = append(testCases, testCase{
4016 testType: serverTest,
4017 name: "VersionTooLow",
4018 config: Config{
4019 Bugs: ProtocolBugs{
4020 SendClientVersion: 0x0200,
4021 },
4022 },
4023 shouldFail: true,
4024 expectedError: ":UNSUPPORTED_PROTOCOL:",
4025 })
4026 testCases = append(testCases, testCase{
4027 protocol: dtls,
4028 testType: serverTest,
4029 name: "VersionTooLow-DTLS",
4030 config: Config{
4031 Bugs: ProtocolBugs{
4032 // 0x0201 is the lowest version expressable in
4033 // DTLS.
4034 SendClientVersion: 0x0201,
4035 },
4036 },
4037 shouldFail: true,
4038 expectedError: ":UNSUPPORTED_PROTOCOL:",
4039 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004040
4041 // Test TLS 1.3's downgrade signal.
4042 testCases = append(testCases, testCase{
4043 name: "Downgrade-TLS12-Client",
4044 config: Config{
4045 Bugs: ProtocolBugs{
4046 NegotiateVersion: VersionTLS12,
4047 },
4048 },
4049 shouldFail: true,
4050 expectedError: ":DOWNGRADE_DETECTED:",
4051 })
4052 testCases = append(testCases, testCase{
4053 testType: serverTest,
4054 name: "Downgrade-TLS12-Server",
4055 config: Config{
4056 Bugs: ProtocolBugs{
4057 SendClientVersion: VersionTLS12,
4058 },
4059 },
4060 shouldFail: true,
4061 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4062 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004063
4064 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4065 // behave correctly when both real maximum and fallback versions are
4066 // set.
4067 testCases = append(testCases, testCase{
4068 name: "Downgrade-TLS12-Client-Fallback",
4069 config: Config{
4070 Bugs: ProtocolBugs{
4071 FailIfNotFallbackSCSV: true,
4072 },
4073 },
4074 flags: []string{
4075 "-max-version", strconv.Itoa(VersionTLS13),
4076 "-fallback-version", strconv.Itoa(VersionTLS12),
4077 },
4078 shouldFail: true,
4079 expectedError: ":DOWNGRADE_DETECTED:",
4080 })
4081 testCases = append(testCases, testCase{
4082 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4083 flags: []string{
4084 "-max-version", strconv.Itoa(VersionTLS12),
4085 "-fallback-version", strconv.Itoa(VersionTLS12),
4086 },
4087 })
4088
4089 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4090 // just have such connections fail than risk getting confused because we
4091 // didn't sent the 1.3 ClientHello.)
4092 testCases = append(testCases, testCase{
4093 name: "Downgrade-TLS12-Fallback-CheckVersion",
4094 config: Config{
4095 Bugs: ProtocolBugs{
4096 NegotiateVersion: VersionTLS13,
4097 FailIfNotFallbackSCSV: true,
4098 },
4099 },
4100 flags: []string{
4101 "-max-version", strconv.Itoa(VersionTLS13),
4102 "-fallback-version", strconv.Itoa(VersionTLS12),
4103 },
4104 shouldFail: true,
4105 expectedError: ":UNSUPPORTED_PROTOCOL:",
4106 })
4107
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004108}
4109
David Benjaminaccb4542014-12-12 23:44:33 -05004110func addMinimumVersionTests() {
4111 for i, shimVers := range tlsVersions {
4112 // Assemble flags to disable all older versions on the shim.
4113 var flags []string
4114 for _, vers := range tlsVersions[:i] {
4115 flags = append(flags, vers.flag)
4116 }
4117
4118 for _, runnerVers := range tlsVersions {
4119 protocols := []protocol{tls}
4120 if runnerVers.hasDTLS && shimVers.hasDTLS {
4121 protocols = append(protocols, dtls)
4122 }
4123 for _, protocol := range protocols {
4124 suffix := shimVers.name + "-" + runnerVers.name
4125 if protocol == dtls {
4126 suffix += "-DTLS"
4127 }
4128 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4129
David Benjaminaccb4542014-12-12 23:44:33 -05004130 var expectedVersion uint16
4131 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004132 var expectedClientError, expectedServerError string
4133 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004134 if runnerVers.version >= shimVers.version {
4135 expectedVersion = runnerVers.version
4136 } else {
4137 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004138 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4139 expectedServerLocalError = "remote error: protocol version not supported"
4140 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4141 // If the client's minimum version is TLS 1.3 and the runner's
4142 // maximum is below TLS 1.2, the runner will fail to select a
4143 // cipher before the shim rejects the selected version.
4144 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4145 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4146 } else {
4147 expectedClientError = expectedServerError
4148 expectedClientLocalError = expectedServerLocalError
4149 }
David Benjaminaccb4542014-12-12 23:44:33 -05004150 }
4151
4152 testCases = append(testCases, testCase{
4153 protocol: protocol,
4154 testType: clientTest,
4155 name: "MinimumVersion-Client-" + suffix,
4156 config: Config{
4157 MaxVersion: runnerVers.version,
4158 },
David Benjamin87909c02014-12-13 01:55:01 -05004159 flags: flags,
4160 expectedVersion: expectedVersion,
4161 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004162 expectedError: expectedClientError,
4163 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004164 })
4165 testCases = append(testCases, testCase{
4166 protocol: protocol,
4167 testType: clientTest,
4168 name: "MinimumVersion-Client2-" + suffix,
4169 config: Config{
4170 MaxVersion: runnerVers.version,
4171 },
David Benjamin87909c02014-12-13 01:55:01 -05004172 flags: []string{"-min-version", shimVersFlag},
4173 expectedVersion: expectedVersion,
4174 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004175 expectedError: expectedClientError,
4176 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004177 })
4178
4179 testCases = append(testCases, testCase{
4180 protocol: protocol,
4181 testType: serverTest,
4182 name: "MinimumVersion-Server-" + suffix,
4183 config: Config{
4184 MaxVersion: runnerVers.version,
4185 },
David Benjamin87909c02014-12-13 01:55:01 -05004186 flags: flags,
4187 expectedVersion: expectedVersion,
4188 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004189 expectedError: expectedServerError,
4190 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004191 })
4192 testCases = append(testCases, testCase{
4193 protocol: protocol,
4194 testType: serverTest,
4195 name: "MinimumVersion-Server2-" + suffix,
4196 config: Config{
4197 MaxVersion: runnerVers.version,
4198 },
David Benjamin87909c02014-12-13 01:55:01 -05004199 flags: []string{"-min-version", shimVersFlag},
4200 expectedVersion: expectedVersion,
4201 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004202 expectedError: expectedServerError,
4203 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004204 })
4205 }
4206 }
4207 }
4208}
4209
David Benjamine78bfde2014-09-06 12:45:15 -04004210func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004211 // TODO(davidben): Extensions, where applicable, all move their server
4212 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4213 // tests for both. Also test interaction with 0-RTT when implemented.
4214
David Benjamin97d17d92016-07-14 16:12:00 -04004215 // Repeat extensions tests all versions except SSL 3.0.
4216 for _, ver := range tlsVersions {
4217 if ver.version == VersionSSL30 {
4218 continue
4219 }
4220
4221 // TODO(davidben): Implement resumption in TLS 1.3.
4222 resumeSession := ver.version < VersionTLS13
4223
4224 // Test that duplicate extensions are rejected.
4225 testCases = append(testCases, testCase{
4226 testType: clientTest,
4227 name: "DuplicateExtensionClient-" + ver.name,
4228 config: Config{
4229 MaxVersion: ver.version,
4230 Bugs: ProtocolBugs{
4231 DuplicateExtension: true,
4232 },
David Benjamine78bfde2014-09-06 12:45:15 -04004233 },
David Benjamin97d17d92016-07-14 16:12:00 -04004234 shouldFail: true,
4235 expectedLocalError: "remote error: error decoding message",
4236 })
4237 testCases = append(testCases, testCase{
4238 testType: serverTest,
4239 name: "DuplicateExtensionServer-" + ver.name,
4240 config: Config{
4241 MaxVersion: ver.version,
4242 Bugs: ProtocolBugs{
4243 DuplicateExtension: true,
4244 },
David Benjamine78bfde2014-09-06 12:45:15 -04004245 },
David Benjamin97d17d92016-07-14 16:12:00 -04004246 shouldFail: true,
4247 expectedLocalError: "remote error: error decoding message",
4248 })
4249
4250 // Test SNI.
4251 testCases = append(testCases, testCase{
4252 testType: clientTest,
4253 name: "ServerNameExtensionClient-" + ver.name,
4254 config: Config{
4255 MaxVersion: ver.version,
4256 Bugs: ProtocolBugs{
4257 ExpectServerName: "example.com",
4258 },
David Benjamine78bfde2014-09-06 12:45:15 -04004259 },
David Benjamin97d17d92016-07-14 16:12:00 -04004260 flags: []string{"-host-name", "example.com"},
4261 })
4262 testCases = append(testCases, testCase{
4263 testType: clientTest,
4264 name: "ServerNameExtensionClientMismatch-" + ver.name,
4265 config: Config{
4266 MaxVersion: ver.version,
4267 Bugs: ProtocolBugs{
4268 ExpectServerName: "mismatch.com",
4269 },
David Benjamine78bfde2014-09-06 12:45:15 -04004270 },
David Benjamin97d17d92016-07-14 16:12:00 -04004271 flags: []string{"-host-name", "example.com"},
4272 shouldFail: true,
4273 expectedLocalError: "tls: unexpected server name",
4274 })
4275 testCases = append(testCases, testCase{
4276 testType: clientTest,
4277 name: "ServerNameExtensionClientMissing-" + ver.name,
4278 config: Config{
4279 MaxVersion: ver.version,
4280 Bugs: ProtocolBugs{
4281 ExpectServerName: "missing.com",
4282 },
David Benjamine78bfde2014-09-06 12:45:15 -04004283 },
David Benjamin97d17d92016-07-14 16:12:00 -04004284 shouldFail: true,
4285 expectedLocalError: "tls: unexpected server name",
4286 })
4287 testCases = append(testCases, testCase{
4288 testType: serverTest,
4289 name: "ServerNameExtensionServer-" + ver.name,
4290 config: Config{
4291 MaxVersion: ver.version,
4292 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004293 },
David Benjamin97d17d92016-07-14 16:12:00 -04004294 flags: []string{"-expect-server-name", "example.com"},
4295 resumeSession: resumeSession,
4296 })
4297
4298 // Test ALPN.
4299 testCases = append(testCases, testCase{
4300 testType: clientTest,
4301 name: "ALPNClient-" + ver.name,
4302 config: Config{
4303 MaxVersion: ver.version,
4304 NextProtos: []string{"foo"},
4305 },
4306 flags: []string{
4307 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4308 "-expect-alpn", "foo",
4309 },
4310 expectedNextProto: "foo",
4311 expectedNextProtoType: alpn,
4312 resumeSession: resumeSession,
4313 })
4314 testCases = append(testCases, testCase{
4315 testType: serverTest,
4316 name: "ALPNServer-" + ver.name,
4317 config: Config{
4318 MaxVersion: ver.version,
4319 NextProtos: []string{"foo", "bar", "baz"},
4320 },
4321 flags: []string{
4322 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4323 "-select-alpn", "foo",
4324 },
4325 expectedNextProto: "foo",
4326 expectedNextProtoType: alpn,
4327 resumeSession: resumeSession,
4328 })
4329 testCases = append(testCases, testCase{
4330 testType: serverTest,
4331 name: "ALPNServer-Decline-" + ver.name,
4332 config: Config{
4333 MaxVersion: ver.version,
4334 NextProtos: []string{"foo", "bar", "baz"},
4335 },
4336 flags: []string{"-decline-alpn"},
4337 expectNoNextProto: true,
4338 resumeSession: resumeSession,
4339 })
4340
David Benjamin25fe85b2016-08-09 20:00:32 -04004341 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4342 // called once.
4343 testCases = append(testCases, testCase{
4344 testType: serverTest,
4345 name: "ALPNServer-Async-" + ver.name,
4346 config: Config{
4347 MaxVersion: ver.version,
4348 NextProtos: []string{"foo", "bar", "baz"},
4349 },
4350 flags: []string{
4351 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4352 "-select-alpn", "foo",
4353 "-async",
4354 },
4355 expectedNextProto: "foo",
4356 expectedNextProtoType: alpn,
4357 resumeSession: resumeSession,
4358 })
4359
David Benjamin97d17d92016-07-14 16:12:00 -04004360 var emptyString string
4361 testCases = append(testCases, testCase{
4362 testType: clientTest,
4363 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4364 config: Config{
4365 MaxVersion: ver.version,
4366 NextProtos: []string{""},
4367 Bugs: ProtocolBugs{
4368 // A server returning an empty ALPN protocol
4369 // should be rejected.
4370 ALPNProtocol: &emptyString,
4371 },
4372 },
4373 flags: []string{
4374 "-advertise-alpn", "\x03foo",
4375 },
4376 shouldFail: true,
4377 expectedError: ":PARSE_TLSEXT:",
4378 })
4379 testCases = append(testCases, testCase{
4380 testType: serverTest,
4381 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4382 config: Config{
4383 MaxVersion: ver.version,
4384 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004385 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004386 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004387 },
David Benjamin97d17d92016-07-14 16:12:00 -04004388 flags: []string{
4389 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004390 },
David Benjamin97d17d92016-07-14 16:12:00 -04004391 shouldFail: true,
4392 expectedError: ":PARSE_TLSEXT:",
4393 })
4394
4395 // Test NPN and the interaction with ALPN.
4396 if ver.version < VersionTLS13 {
4397 // Test that the server prefers ALPN over NPN.
4398 testCases = append(testCases, testCase{
4399 testType: serverTest,
4400 name: "ALPNServer-Preferred-" + ver.name,
4401 config: Config{
4402 MaxVersion: ver.version,
4403 NextProtos: []string{"foo", "bar", "baz"},
4404 },
4405 flags: []string{
4406 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4407 "-select-alpn", "foo",
4408 "-advertise-npn", "\x03foo\x03bar\x03baz",
4409 },
4410 expectedNextProto: "foo",
4411 expectedNextProtoType: alpn,
4412 resumeSession: resumeSession,
4413 })
4414 testCases = append(testCases, testCase{
4415 testType: serverTest,
4416 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4417 config: Config{
4418 MaxVersion: ver.version,
4419 NextProtos: []string{"foo", "bar", "baz"},
4420 Bugs: ProtocolBugs{
4421 SwapNPNAndALPN: true,
4422 },
4423 },
4424 flags: []string{
4425 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4426 "-select-alpn", "foo",
4427 "-advertise-npn", "\x03foo\x03bar\x03baz",
4428 },
4429 expectedNextProto: "foo",
4430 expectedNextProtoType: alpn,
4431 resumeSession: resumeSession,
4432 })
4433
4434 // Test that negotiating both NPN and ALPN is forbidden.
4435 testCases = append(testCases, testCase{
4436 name: "NegotiateALPNAndNPN-" + ver.name,
4437 config: Config{
4438 MaxVersion: ver.version,
4439 NextProtos: []string{"foo", "bar", "baz"},
4440 Bugs: ProtocolBugs{
4441 NegotiateALPNAndNPN: true,
4442 },
4443 },
4444 flags: []string{
4445 "-advertise-alpn", "\x03foo",
4446 "-select-next-proto", "foo",
4447 },
4448 shouldFail: true,
4449 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4450 })
4451 testCases = append(testCases, testCase{
4452 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4453 config: Config{
4454 MaxVersion: ver.version,
4455 NextProtos: []string{"foo", "bar", "baz"},
4456 Bugs: ProtocolBugs{
4457 NegotiateALPNAndNPN: true,
4458 SwapNPNAndALPN: true,
4459 },
4460 },
4461 flags: []string{
4462 "-advertise-alpn", "\x03foo",
4463 "-select-next-proto", "foo",
4464 },
4465 shouldFail: true,
4466 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4467 })
4468
4469 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4470 testCases = append(testCases, testCase{
4471 name: "DisableNPN-" + ver.name,
4472 config: Config{
4473 MaxVersion: ver.version,
4474 NextProtos: []string{"foo"},
4475 },
4476 flags: []string{
4477 "-select-next-proto", "foo",
4478 "-disable-npn",
4479 },
4480 expectNoNextProto: true,
4481 })
4482 }
4483
4484 // Test ticket behavior.
4485 //
4486 // TODO(davidben): Add TLS 1.3 versions of these.
4487 if ver.version < VersionTLS13 {
4488 // Resume with a corrupt ticket.
4489 testCases = append(testCases, testCase{
4490 testType: serverTest,
4491 name: "CorruptTicket-" + ver.name,
4492 config: Config{
4493 MaxVersion: ver.version,
4494 Bugs: ProtocolBugs{
4495 CorruptTicket: true,
4496 },
4497 },
4498 resumeSession: true,
4499 expectResumeRejected: true,
4500 })
4501 // Test the ticket callback, with and without renewal.
4502 testCases = append(testCases, testCase{
4503 testType: serverTest,
4504 name: "TicketCallback-" + ver.name,
4505 config: Config{
4506 MaxVersion: ver.version,
4507 },
4508 resumeSession: true,
4509 flags: []string{"-use-ticket-callback"},
4510 })
4511 testCases = append(testCases, testCase{
4512 testType: serverTest,
4513 name: "TicketCallback-Renew-" + ver.name,
4514 config: Config{
4515 MaxVersion: ver.version,
4516 Bugs: ProtocolBugs{
4517 ExpectNewTicket: true,
4518 },
4519 },
4520 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4521 resumeSession: true,
4522 })
4523
David Benjamin25fe85b2016-08-09 20:00:32 -04004524 // Test that the ticket callback is only called once when everything before
4525 // it in the ClientHello is asynchronous. This corrupts the ticket so
4526 // certificate selection callbacks run.
4527 testCases = append(testCases, testCase{
4528 testType: serverTest,
4529 name: "TicketCallback-SingleCall-" + ver.name,
4530 config: Config{
4531 MaxVersion: ver.version,
4532 Bugs: ProtocolBugs{
4533 CorruptTicket: true,
4534 },
4535 },
4536 resumeSession: true,
4537 expectResumeRejected: true,
4538 flags: []string{
4539 "-use-ticket-callback",
4540 "-async",
4541 },
4542 })
4543
David Benjamin97d17d92016-07-14 16:12:00 -04004544 // Resume with an oversized session id.
4545 testCases = append(testCases, testCase{
4546 testType: serverTest,
4547 name: "OversizedSessionId-" + ver.name,
4548 config: Config{
4549 MaxVersion: ver.version,
4550 Bugs: ProtocolBugs{
4551 OversizedSessionId: true,
4552 },
4553 },
4554 resumeSession: true,
4555 shouldFail: true,
4556 expectedError: ":DECODE_ERROR:",
4557 })
4558 }
4559
4560 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4561 // are ignored.
4562 if ver.hasDTLS {
4563 testCases = append(testCases, testCase{
4564 protocol: dtls,
4565 name: "SRTP-Client-" + ver.name,
4566 config: Config{
4567 MaxVersion: ver.version,
4568 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4569 },
4570 flags: []string{
4571 "-srtp-profiles",
4572 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4573 },
4574 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4575 })
4576 testCases = append(testCases, testCase{
4577 protocol: dtls,
4578 testType: serverTest,
4579 name: "SRTP-Server-" + ver.name,
4580 config: Config{
4581 MaxVersion: ver.version,
4582 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4583 },
4584 flags: []string{
4585 "-srtp-profiles",
4586 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4587 },
4588 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4589 })
4590 // Test that the MKI is ignored.
4591 testCases = append(testCases, testCase{
4592 protocol: dtls,
4593 testType: serverTest,
4594 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4595 config: Config{
4596 MaxVersion: ver.version,
4597 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4598 Bugs: ProtocolBugs{
4599 SRTPMasterKeyIdentifer: "bogus",
4600 },
4601 },
4602 flags: []string{
4603 "-srtp-profiles",
4604 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4605 },
4606 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4607 })
4608 // Test that SRTP isn't negotiated on the server if there were
4609 // no matching profiles.
4610 testCases = append(testCases, testCase{
4611 protocol: dtls,
4612 testType: serverTest,
4613 name: "SRTP-Server-NoMatch-" + ver.name,
4614 config: Config{
4615 MaxVersion: ver.version,
4616 SRTPProtectionProfiles: []uint16{100, 101, 102},
4617 },
4618 flags: []string{
4619 "-srtp-profiles",
4620 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4621 },
4622 expectedSRTPProtectionProfile: 0,
4623 })
4624 // Test that the server returning an invalid SRTP profile is
4625 // flagged as an error by the client.
4626 testCases = append(testCases, testCase{
4627 protocol: dtls,
4628 name: "SRTP-Client-NoMatch-" + ver.name,
4629 config: Config{
4630 MaxVersion: ver.version,
4631 Bugs: ProtocolBugs{
4632 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4633 },
4634 },
4635 flags: []string{
4636 "-srtp-profiles",
4637 "SRTP_AES128_CM_SHA1_80",
4638 },
4639 shouldFail: true,
4640 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4641 })
4642 }
4643
4644 // Test SCT list.
4645 testCases = append(testCases, testCase{
4646 name: "SignedCertificateTimestampList-Client-" + ver.name,
4647 testType: clientTest,
4648 config: Config{
4649 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004650 },
David Benjamin97d17d92016-07-14 16:12:00 -04004651 flags: []string{
4652 "-enable-signed-cert-timestamps",
4653 "-expect-signed-cert-timestamps",
4654 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004655 },
David Benjamin97d17d92016-07-14 16:12:00 -04004656 resumeSession: resumeSession,
4657 })
4658 testCases = append(testCases, testCase{
4659 name: "SendSCTListOnResume-" + ver.name,
4660 config: Config{
4661 MaxVersion: ver.version,
4662 Bugs: ProtocolBugs{
4663 SendSCTListOnResume: []byte("bogus"),
4664 },
David Benjamind98452d2015-06-16 14:16:23 -04004665 },
David Benjamin97d17d92016-07-14 16:12:00 -04004666 flags: []string{
4667 "-enable-signed-cert-timestamps",
4668 "-expect-signed-cert-timestamps",
4669 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004670 },
David Benjamin97d17d92016-07-14 16:12:00 -04004671 resumeSession: resumeSession,
4672 })
4673 testCases = append(testCases, testCase{
4674 name: "SignedCertificateTimestampList-Server-" + ver.name,
4675 testType: serverTest,
4676 config: Config{
4677 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004678 },
David Benjamin97d17d92016-07-14 16:12:00 -04004679 flags: []string{
4680 "-signed-cert-timestamps",
4681 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004682 },
David Benjamin97d17d92016-07-14 16:12:00 -04004683 expectedSCTList: testSCTList,
4684 resumeSession: resumeSession,
4685 })
4686 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004687
Paul Lietar4fac72e2015-09-09 13:44:55 +01004688 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004689 testType: clientTest,
4690 name: "ClientHelloPadding",
4691 config: Config{
4692 Bugs: ProtocolBugs{
4693 RequireClientHelloSize: 512,
4694 },
4695 },
4696 // This hostname just needs to be long enough to push the
4697 // ClientHello into F5's danger zone between 256 and 511 bytes
4698 // long.
4699 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4700 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004701
4702 // Extensions should not function in SSL 3.0.
4703 testCases = append(testCases, testCase{
4704 testType: serverTest,
4705 name: "SSLv3Extensions-NoALPN",
4706 config: Config{
4707 MaxVersion: VersionSSL30,
4708 NextProtos: []string{"foo", "bar", "baz"},
4709 },
4710 flags: []string{
4711 "-select-alpn", "foo",
4712 },
4713 expectNoNextProto: true,
4714 })
4715
4716 // Test session tickets separately as they follow a different codepath.
4717 testCases = append(testCases, testCase{
4718 testType: serverTest,
4719 name: "SSLv3Extensions-NoTickets",
4720 config: Config{
4721 MaxVersion: VersionSSL30,
4722 Bugs: ProtocolBugs{
4723 // Historically, session tickets in SSL 3.0
4724 // failed in different ways depending on whether
4725 // the client supported renegotiation_info.
4726 NoRenegotiationInfo: true,
4727 },
4728 },
4729 resumeSession: true,
4730 })
4731 testCases = append(testCases, testCase{
4732 testType: serverTest,
4733 name: "SSLv3Extensions-NoTickets2",
4734 config: Config{
4735 MaxVersion: VersionSSL30,
4736 },
4737 resumeSession: true,
4738 })
4739
4740 // But SSL 3.0 does send and process renegotiation_info.
4741 testCases = append(testCases, testCase{
4742 testType: serverTest,
4743 name: "SSLv3Extensions-RenegotiationInfo",
4744 config: Config{
4745 MaxVersion: VersionSSL30,
4746 Bugs: ProtocolBugs{
4747 RequireRenegotiationInfo: true,
4748 },
4749 },
4750 })
4751 testCases = append(testCases, testCase{
4752 testType: serverTest,
4753 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4754 config: Config{
4755 MaxVersion: VersionSSL30,
4756 Bugs: ProtocolBugs{
4757 NoRenegotiationInfo: true,
4758 SendRenegotiationSCSV: true,
4759 RequireRenegotiationInfo: true,
4760 },
4761 },
4762 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004763
4764 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4765 // in ServerHello.
4766 testCases = append(testCases, testCase{
4767 name: "NPN-Forbidden-TLS13",
4768 config: Config{
4769 MaxVersion: VersionTLS13,
4770 NextProtos: []string{"foo"},
4771 Bugs: ProtocolBugs{
4772 NegotiateNPNAtAllVersions: true,
4773 },
4774 },
4775 flags: []string{"-select-next-proto", "foo"},
4776 shouldFail: true,
4777 expectedError: ":ERROR_PARSING_EXTENSION:",
4778 })
4779 testCases = append(testCases, testCase{
4780 name: "EMS-Forbidden-TLS13",
4781 config: Config{
4782 MaxVersion: VersionTLS13,
4783 Bugs: ProtocolBugs{
4784 NegotiateEMSAtAllVersions: true,
4785 },
4786 },
4787 shouldFail: true,
4788 expectedError: ":ERROR_PARSING_EXTENSION:",
4789 })
4790 testCases = append(testCases, testCase{
4791 name: "RenegotiationInfo-Forbidden-TLS13",
4792 config: Config{
4793 MaxVersion: VersionTLS13,
4794 Bugs: ProtocolBugs{
4795 NegotiateRenegotiationInfoAtAllVersions: true,
4796 },
4797 },
4798 shouldFail: true,
4799 expectedError: ":ERROR_PARSING_EXTENSION:",
4800 })
4801 testCases = append(testCases, testCase{
4802 name: "ChannelID-Forbidden-TLS13",
4803 config: Config{
4804 MaxVersion: VersionTLS13,
4805 RequestChannelID: true,
4806 Bugs: ProtocolBugs{
4807 NegotiateChannelIDAtAllVersions: true,
4808 },
4809 },
4810 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4811 shouldFail: true,
4812 expectedError: ":ERROR_PARSING_EXTENSION:",
4813 })
4814 testCases = append(testCases, testCase{
4815 name: "Ticket-Forbidden-TLS13",
4816 config: Config{
4817 MaxVersion: VersionTLS12,
4818 },
4819 resumeConfig: &Config{
4820 MaxVersion: VersionTLS13,
4821 Bugs: ProtocolBugs{
4822 AdvertiseTicketExtension: true,
4823 },
4824 },
4825 resumeSession: true,
4826 shouldFail: true,
4827 expectedError: ":ERROR_PARSING_EXTENSION:",
4828 })
4829
4830 // Test that illegal extensions in TLS 1.3 are declined by the server if
4831 // offered in ClientHello. The runner's server will fail if this occurs,
4832 // so we exercise the offering path. (EMS and Renegotiation Info are
4833 // implicit in every test.)
4834 testCases = append(testCases, testCase{
4835 testType: serverTest,
4836 name: "ChannelID-Declined-TLS13",
4837 config: Config{
4838 MaxVersion: VersionTLS13,
4839 ChannelID: channelIDKey,
4840 },
4841 flags: []string{"-enable-channel-id"},
4842 })
4843 testCases = append(testCases, testCase{
4844 testType: serverTest,
4845 name: "NPN-Server",
4846 config: Config{
4847 MaxVersion: VersionTLS13,
4848 NextProtos: []string{"bar"},
4849 },
4850 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4851 })
David Benjamine78bfde2014-09-06 12:45:15 -04004852}
4853
David Benjamin01fe8202014-09-24 15:21:44 -04004854func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004855 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004856 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4857 if sessionVers.version >= VersionTLS13 {
4858 continue
4859 }
David Benjamin01fe8202014-09-24 15:21:44 -04004860 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004861 if resumeVers.version >= VersionTLS13 {
4862 continue
4863 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004864 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4865 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4866 // TLS 1.3 only shares ciphers with TLS 1.2, so
4867 // we skip certain combinations and use a
4868 // different cipher to test with.
4869 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4870 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4871 continue
4872 }
4873 }
4874
David Benjamin8b8c0062014-11-23 02:47:52 -05004875 protocols := []protocol{tls}
4876 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4877 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004878 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004879 for _, protocol := range protocols {
4880 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4881 if protocol == dtls {
4882 suffix += "-DTLS"
4883 }
4884
David Benjaminece3de92015-03-16 18:02:20 -04004885 if sessionVers.version == resumeVers.version {
4886 testCases = append(testCases, testCase{
4887 protocol: protocol,
4888 name: "Resume-Client" + suffix,
4889 resumeSession: true,
4890 config: Config{
4891 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004892 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004893 },
David Benjaminece3de92015-03-16 18:02:20 -04004894 expectedVersion: sessionVers.version,
4895 expectedResumeVersion: resumeVers.version,
4896 })
4897 } else {
4898 testCases = append(testCases, testCase{
4899 protocol: protocol,
4900 name: "Resume-Client-Mismatch" + suffix,
4901 resumeSession: true,
4902 config: Config{
4903 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004904 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004905 },
David Benjaminece3de92015-03-16 18:02:20 -04004906 expectedVersion: sessionVers.version,
4907 resumeConfig: &Config{
4908 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004909 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004910 Bugs: ProtocolBugs{
4911 AllowSessionVersionMismatch: true,
4912 },
4913 },
4914 expectedResumeVersion: resumeVers.version,
4915 shouldFail: true,
4916 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4917 })
4918 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004919
4920 testCases = append(testCases, testCase{
4921 protocol: protocol,
4922 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004923 resumeSession: true,
4924 config: Config{
4925 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004926 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004927 },
4928 expectedVersion: sessionVers.version,
4929 resumeConfig: &Config{
4930 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004931 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004932 },
4933 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004934 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004935 expectedResumeVersion: resumeVers.version,
4936 })
4937
David Benjamin8b8c0062014-11-23 02:47:52 -05004938 testCases = append(testCases, testCase{
4939 protocol: protocol,
4940 testType: serverTest,
4941 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004942 resumeSession: true,
4943 config: Config{
4944 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004945 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004946 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004947 expectedVersion: sessionVers.version,
4948 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004949 resumeConfig: &Config{
4950 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004951 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004952 },
4953 expectedResumeVersion: resumeVers.version,
4954 })
4955 }
David Benjamin01fe8202014-09-24 15:21:44 -04004956 }
4957 }
David Benjaminece3de92015-03-16 18:02:20 -04004958
Nick Harper1fd39d82016-06-14 18:14:35 -07004959 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004960 testCases = append(testCases, testCase{
4961 name: "Resume-Client-CipherMismatch",
4962 resumeSession: true,
4963 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004964 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004965 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4966 },
4967 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004968 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004969 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4970 Bugs: ProtocolBugs{
4971 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4972 },
4973 },
4974 shouldFail: true,
4975 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4976 })
David Benjamin01fe8202014-09-24 15:21:44 -04004977}
4978
Adam Langley2ae77d22014-10-28 17:29:33 -07004979func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004980 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004981 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004982 testType: serverTest,
4983 name: "Renegotiate-Server-Forbidden",
4984 config: Config{
4985 MaxVersion: VersionTLS12,
4986 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004987 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004988 shouldFail: true,
4989 expectedError: ":NO_RENEGOTIATION:",
4990 expectedLocalError: "remote error: no renegotiation",
4991 })
Adam Langley5021b222015-06-12 18:27:58 -07004992 // The server shouldn't echo the renegotiation extension unless
4993 // requested by the client.
4994 testCases = append(testCases, testCase{
4995 testType: serverTest,
4996 name: "Renegotiate-Server-NoExt",
4997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004998 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004999 Bugs: ProtocolBugs{
5000 NoRenegotiationInfo: true,
5001 RequireRenegotiationInfo: true,
5002 },
5003 },
5004 shouldFail: true,
5005 expectedLocalError: "renegotiation extension missing",
5006 })
5007 // The renegotiation SCSV should be sufficient for the server to echo
5008 // the extension.
5009 testCases = append(testCases, testCase{
5010 testType: serverTest,
5011 name: "Renegotiate-Server-NoExt-SCSV",
5012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005013 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005014 Bugs: ProtocolBugs{
5015 NoRenegotiationInfo: true,
5016 SendRenegotiationSCSV: true,
5017 RequireRenegotiationInfo: true,
5018 },
5019 },
5020 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005021 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005022 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005024 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005025 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005026 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005027 },
5028 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005029 renegotiate: 1,
5030 flags: []string{
5031 "-renegotiate-freely",
5032 "-expect-total-renegotiations", "1",
5033 },
David Benjamincdea40c2015-03-19 14:09:43 -04005034 })
5035 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005036 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005037 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005039 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005040 Bugs: ProtocolBugs{
5041 EmptyRenegotiationInfo: true,
5042 },
5043 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005044 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005045 shouldFail: true,
5046 expectedError: ":RENEGOTIATION_MISMATCH:",
5047 })
5048 testCases = append(testCases, testCase{
5049 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005050 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005052 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005053 Bugs: ProtocolBugs{
5054 BadRenegotiationInfo: true,
5055 },
5056 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005057 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005058 shouldFail: true,
5059 expectedError: ":RENEGOTIATION_MISMATCH:",
5060 })
5061 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005062 name: "Renegotiate-Client-Downgrade",
5063 renegotiate: 1,
5064 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005065 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005066 Bugs: ProtocolBugs{
5067 NoRenegotiationInfoAfterInitial: true,
5068 },
5069 },
5070 flags: []string{"-renegotiate-freely"},
5071 shouldFail: true,
5072 expectedError: ":RENEGOTIATION_MISMATCH:",
5073 })
5074 testCases = append(testCases, testCase{
5075 name: "Renegotiate-Client-Upgrade",
5076 renegotiate: 1,
5077 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005078 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005079 Bugs: ProtocolBugs{
5080 NoRenegotiationInfoInInitial: true,
5081 },
5082 },
5083 flags: []string{"-renegotiate-freely"},
5084 shouldFail: true,
5085 expectedError: ":RENEGOTIATION_MISMATCH:",
5086 })
5087 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005088 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005089 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005091 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005092 Bugs: ProtocolBugs{
5093 NoRenegotiationInfo: true,
5094 },
5095 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005096 flags: []string{
5097 "-renegotiate-freely",
5098 "-expect-total-renegotiations", "1",
5099 },
David Benjamincff0b902015-05-15 23:09:47 -04005100 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005101
5102 // Test that the server may switch ciphers on renegotiation without
5103 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005104 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005105 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005106 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005107 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005108 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005109 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5110 },
5111 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005112 flags: []string{
5113 "-renegotiate-freely",
5114 "-expect-total-renegotiations", "1",
5115 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005116 })
5117 testCases = append(testCases, testCase{
5118 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005119 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005120 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005121 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005122 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5123 },
5124 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005125 flags: []string{
5126 "-renegotiate-freely",
5127 "-expect-total-renegotiations", "1",
5128 },
David Benjaminb16346b2015-04-08 19:16:58 -04005129 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005130
5131 // Test that the server may not switch versions on renegotiation.
5132 testCases = append(testCases, testCase{
5133 name: "Renegotiate-Client-SwitchVersion",
5134 config: Config{
5135 MaxVersion: VersionTLS12,
5136 // Pick a cipher which exists at both versions.
5137 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5138 Bugs: ProtocolBugs{
5139 NegotiateVersionOnRenego: VersionTLS11,
5140 },
5141 },
5142 renegotiate: 1,
5143 flags: []string{
5144 "-renegotiate-freely",
5145 "-expect-total-renegotiations", "1",
5146 },
5147 shouldFail: true,
5148 expectedError: ":WRONG_SSL_VERSION:",
5149 })
5150
David Benjaminb16346b2015-04-08 19:16:58 -04005151 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005152 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005153 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005154 config: Config{
5155 MaxVersion: VersionTLS10,
5156 Bugs: ProtocolBugs{
5157 RequireSameRenegoClientVersion: true,
5158 },
5159 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005160 flags: []string{
5161 "-renegotiate-freely",
5162 "-expect-total-renegotiations", "1",
5163 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005164 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005165 testCases = append(testCases, testCase{
5166 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005167 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005168 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005169 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005170 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5171 NextProtos: []string{"foo"},
5172 },
5173 flags: []string{
5174 "-false-start",
5175 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005176 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005177 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005178 },
5179 shimWritesFirst: true,
5180 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005181
5182 // Client-side renegotiation controls.
5183 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005184 name: "Renegotiate-Client-Forbidden-1",
5185 config: Config{
5186 MaxVersion: VersionTLS12,
5187 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005188 renegotiate: 1,
5189 shouldFail: true,
5190 expectedError: ":NO_RENEGOTIATION:",
5191 expectedLocalError: "remote error: no renegotiation",
5192 })
5193 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005194 name: "Renegotiate-Client-Once-1",
5195 config: Config{
5196 MaxVersion: VersionTLS12,
5197 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005198 renegotiate: 1,
5199 flags: []string{
5200 "-renegotiate-once",
5201 "-expect-total-renegotiations", "1",
5202 },
5203 })
5204 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005205 name: "Renegotiate-Client-Freely-1",
5206 config: Config{
5207 MaxVersion: VersionTLS12,
5208 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005209 renegotiate: 1,
5210 flags: []string{
5211 "-renegotiate-freely",
5212 "-expect-total-renegotiations", "1",
5213 },
5214 })
5215 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005216 name: "Renegotiate-Client-Once-2",
5217 config: Config{
5218 MaxVersion: VersionTLS12,
5219 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005220 renegotiate: 2,
5221 flags: []string{"-renegotiate-once"},
5222 shouldFail: true,
5223 expectedError: ":NO_RENEGOTIATION:",
5224 expectedLocalError: "remote error: no renegotiation",
5225 })
5226 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005227 name: "Renegotiate-Client-Freely-2",
5228 config: Config{
5229 MaxVersion: VersionTLS12,
5230 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005231 renegotiate: 2,
5232 flags: []string{
5233 "-renegotiate-freely",
5234 "-expect-total-renegotiations", "2",
5235 },
5236 })
Adam Langley27a0d082015-11-03 13:34:10 -08005237 testCases = append(testCases, testCase{
5238 name: "Renegotiate-Client-NoIgnore",
5239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005240 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005241 Bugs: ProtocolBugs{
5242 SendHelloRequestBeforeEveryAppDataRecord: true,
5243 },
5244 },
5245 shouldFail: true,
5246 expectedError: ":NO_RENEGOTIATION:",
5247 })
5248 testCases = append(testCases, testCase{
5249 name: "Renegotiate-Client-Ignore",
5250 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005251 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005252 Bugs: ProtocolBugs{
5253 SendHelloRequestBeforeEveryAppDataRecord: true,
5254 },
5255 },
5256 flags: []string{
5257 "-renegotiate-ignore",
5258 "-expect-total-renegotiations", "0",
5259 },
5260 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005261
David Benjamin397c8e62016-07-08 14:14:36 -07005262 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005263 testCases = append(testCases, testCase{
5264 name: "StrayHelloRequest",
5265 config: Config{
5266 MaxVersion: VersionTLS12,
5267 Bugs: ProtocolBugs{
5268 SendHelloRequestBeforeEveryHandshakeMessage: true,
5269 },
5270 },
5271 })
5272 testCases = append(testCases, testCase{
5273 name: "StrayHelloRequest-Packed",
5274 config: Config{
5275 MaxVersion: VersionTLS12,
5276 Bugs: ProtocolBugs{
5277 PackHandshakeFlight: true,
5278 SendHelloRequestBeforeEveryHandshakeMessage: true,
5279 },
5280 },
5281 })
5282
David Benjamin12d2c482016-07-24 10:56:51 -04005283 // Test renegotiation works if HelloRequest and server Finished come in
5284 // the same record.
5285 testCases = append(testCases, testCase{
5286 name: "Renegotiate-Client-Packed",
5287 config: Config{
5288 MaxVersion: VersionTLS12,
5289 Bugs: ProtocolBugs{
5290 PackHandshakeFlight: true,
5291 PackHelloRequestWithFinished: true,
5292 },
5293 },
5294 renegotiate: 1,
5295 flags: []string{
5296 "-renegotiate-freely",
5297 "-expect-total-renegotiations", "1",
5298 },
5299 })
5300
David Benjamin397c8e62016-07-08 14:14:36 -07005301 // Renegotiation is forbidden in TLS 1.3.
5302 testCases = append(testCases, testCase{
5303 name: "Renegotiate-Client-TLS13",
5304 config: Config{
5305 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005306 Bugs: ProtocolBugs{
5307 SendHelloRequestBeforeEveryAppDataRecord: true,
5308 },
David Benjamin397c8e62016-07-08 14:14:36 -07005309 },
David Benjamin397c8e62016-07-08 14:14:36 -07005310 flags: []string{
5311 "-renegotiate-freely",
5312 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005313 shouldFail: true,
5314 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005315 })
5316
5317 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5318 testCases = append(testCases, testCase{
5319 name: "StrayHelloRequest-TLS13",
5320 config: Config{
5321 MaxVersion: VersionTLS13,
5322 Bugs: ProtocolBugs{
5323 SendHelloRequestBeforeEveryHandshakeMessage: true,
5324 },
5325 },
5326 shouldFail: true,
5327 expectedError: ":UNEXPECTED_MESSAGE:",
5328 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005329}
5330
David Benjamin5e961c12014-11-07 01:48:35 -05005331func addDTLSReplayTests() {
5332 // Test that sequence number replays are detected.
5333 testCases = append(testCases, testCase{
5334 protocol: dtls,
5335 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005336 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005337 replayWrites: true,
5338 })
5339
David Benjamin8e6db492015-07-25 18:29:23 -04005340 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005341 // than the retransmit window.
5342 testCases = append(testCases, testCase{
5343 protocol: dtls,
5344 name: "DTLS-Replay-LargeGaps",
5345 config: Config{
5346 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005347 SequenceNumberMapping: func(in uint64) uint64 {
5348 return in * 127
5349 },
David Benjamin5e961c12014-11-07 01:48:35 -05005350 },
5351 },
David Benjamin8e6db492015-07-25 18:29:23 -04005352 messageCount: 200,
5353 replayWrites: true,
5354 })
5355
5356 // Test the incoming sequence number changing non-monotonically.
5357 testCases = append(testCases, testCase{
5358 protocol: dtls,
5359 name: "DTLS-Replay-NonMonotonic",
5360 config: Config{
5361 Bugs: ProtocolBugs{
5362 SequenceNumberMapping: func(in uint64) uint64 {
5363 return in ^ 31
5364 },
5365 },
5366 },
5367 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005368 replayWrites: true,
5369 })
5370}
5371
Nick Harper60edffd2016-06-21 15:19:24 -07005372var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005373 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005374 id signatureAlgorithm
5375 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005376}{
Nick Harper60edffd2016-06-21 15:19:24 -07005377 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5378 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5379 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5380 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005381 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005382 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5383 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5384 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005385 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5386 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5387 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005388 // Tests for key types prior to TLS 1.2.
5389 {"RSA", 0, testCertRSA},
5390 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005391}
5392
Nick Harper60edffd2016-06-21 15:19:24 -07005393const fakeSigAlg1 signatureAlgorithm = 0x2a01
5394const fakeSigAlg2 signatureAlgorithm = 0xff01
5395
5396func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005397 // Not all ciphers involve a signature. Advertise a list which gives all
5398 // versions a signing cipher.
5399 signingCiphers := []uint16{
5400 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5401 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5402 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5403 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5404 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5405 }
5406
David Benjaminca3d5452016-07-14 12:51:01 -04005407 var allAlgorithms []signatureAlgorithm
5408 for _, alg := range testSignatureAlgorithms {
5409 if alg.id != 0 {
5410 allAlgorithms = append(allAlgorithms, alg.id)
5411 }
5412 }
5413
Nick Harper60edffd2016-06-21 15:19:24 -07005414 // Make sure each signature algorithm works. Include some fake values in
5415 // the list and ensure they're ignored.
5416 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005417 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005418 if (ver.version < VersionTLS12) != (alg.id == 0) {
5419 continue
5420 }
5421
5422 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5423 // or remove it in C.
5424 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005425 continue
5426 }
Nick Harper60edffd2016-06-21 15:19:24 -07005427
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005428 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005429 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005430 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5431 shouldFail = true
5432 }
5433 // RSA-PSS does not exist in TLS 1.2.
5434 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5435 shouldFail = true
5436 }
5437
5438 var signError, verifyError string
5439 if shouldFail {
5440 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5441 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005442 }
David Benjamin000800a2014-11-14 01:43:59 -05005443
David Benjamin1fb125c2016-07-08 18:52:12 -07005444 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005445
David Benjamin7a41d372016-07-09 11:21:54 -07005446 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005447 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005448 config: Config{
5449 MaxVersion: ver.version,
5450 ClientAuth: RequireAnyClientCert,
5451 VerifySignatureAlgorithms: []signatureAlgorithm{
5452 fakeSigAlg1,
5453 alg.id,
5454 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005455 },
David Benjamin7a41d372016-07-09 11:21:54 -07005456 },
5457 flags: []string{
5458 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5459 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5460 "-enable-all-curves",
5461 },
5462 shouldFail: shouldFail,
5463 expectedError: signError,
5464 expectedPeerSignatureAlgorithm: alg.id,
5465 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005466
David Benjamin7a41d372016-07-09 11:21:54 -07005467 testCases = append(testCases, testCase{
5468 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005469 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005470 config: Config{
5471 MaxVersion: ver.version,
5472 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5473 SignSignatureAlgorithms: []signatureAlgorithm{
5474 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005475 },
David Benjamin7a41d372016-07-09 11:21:54 -07005476 Bugs: ProtocolBugs{
5477 SkipECDSACurveCheck: shouldFail,
5478 IgnoreSignatureVersionChecks: shouldFail,
5479 // The client won't advertise 1.3-only algorithms after
5480 // version negotiation.
5481 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005482 },
David Benjamin7a41d372016-07-09 11:21:54 -07005483 },
5484 flags: []string{
5485 "-require-any-client-certificate",
5486 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5487 "-enable-all-curves",
5488 },
5489 shouldFail: shouldFail,
5490 expectedError: verifyError,
5491 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005492
5493 testCases = append(testCases, testCase{
5494 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005495 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005496 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005497 MaxVersion: ver.version,
5498 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005499 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005500 fakeSigAlg1,
5501 alg.id,
5502 fakeSigAlg2,
5503 },
5504 },
5505 flags: []string{
5506 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5507 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5508 "-enable-all-curves",
5509 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005510 shouldFail: shouldFail,
5511 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005512 expectedPeerSignatureAlgorithm: alg.id,
5513 })
5514
5515 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005516 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005517 config: Config{
5518 MaxVersion: ver.version,
5519 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005520 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005521 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005522 alg.id,
5523 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005524 Bugs: ProtocolBugs{
5525 SkipECDSACurveCheck: shouldFail,
5526 IgnoreSignatureVersionChecks: shouldFail,
5527 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005528 },
5529 flags: []string{
5530 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5531 "-enable-all-curves",
5532 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005533 shouldFail: shouldFail,
5534 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005535 })
David Benjamin5208fd42016-07-13 21:43:25 -04005536
5537 if !shouldFail {
5538 testCases = append(testCases, testCase{
5539 testType: serverTest,
5540 name: "ClientAuth-InvalidSignature" + suffix,
5541 config: Config{
5542 MaxVersion: ver.version,
5543 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5544 SignSignatureAlgorithms: []signatureAlgorithm{
5545 alg.id,
5546 },
5547 Bugs: ProtocolBugs{
5548 InvalidSignature: true,
5549 },
5550 },
5551 flags: []string{
5552 "-require-any-client-certificate",
5553 "-enable-all-curves",
5554 },
5555 shouldFail: true,
5556 expectedError: ":BAD_SIGNATURE:",
5557 })
5558
5559 testCases = append(testCases, testCase{
5560 name: "ServerAuth-InvalidSignature" + suffix,
5561 config: Config{
5562 MaxVersion: ver.version,
5563 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5564 CipherSuites: signingCiphers,
5565 SignSignatureAlgorithms: []signatureAlgorithm{
5566 alg.id,
5567 },
5568 Bugs: ProtocolBugs{
5569 InvalidSignature: true,
5570 },
5571 },
5572 flags: []string{"-enable-all-curves"},
5573 shouldFail: true,
5574 expectedError: ":BAD_SIGNATURE:",
5575 })
5576 }
David Benjaminca3d5452016-07-14 12:51:01 -04005577
5578 if ver.version >= VersionTLS12 && !shouldFail {
5579 testCases = append(testCases, testCase{
5580 name: "ClientAuth-Sign-Negotiate" + suffix,
5581 config: Config{
5582 MaxVersion: ver.version,
5583 ClientAuth: RequireAnyClientCert,
5584 VerifySignatureAlgorithms: allAlgorithms,
5585 },
5586 flags: []string{
5587 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5588 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5589 "-enable-all-curves",
5590 "-signing-prefs", strconv.Itoa(int(alg.id)),
5591 },
5592 expectedPeerSignatureAlgorithm: alg.id,
5593 })
5594
5595 testCases = append(testCases, testCase{
5596 testType: serverTest,
5597 name: "ServerAuth-Sign-Negotiate" + suffix,
5598 config: Config{
5599 MaxVersion: ver.version,
5600 CipherSuites: signingCiphers,
5601 VerifySignatureAlgorithms: allAlgorithms,
5602 },
5603 flags: []string{
5604 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5605 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5606 "-enable-all-curves",
5607 "-signing-prefs", strconv.Itoa(int(alg.id)),
5608 },
5609 expectedPeerSignatureAlgorithm: alg.id,
5610 })
5611 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005612 }
David Benjamin000800a2014-11-14 01:43:59 -05005613 }
5614
Nick Harper60edffd2016-06-21 15:19:24 -07005615 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005616 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005617 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005618 config: Config{
5619 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005620 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005621 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005622 signatureECDSAWithP521AndSHA512,
5623 signatureRSAPKCS1WithSHA384,
5624 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005625 },
5626 },
5627 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005628 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5629 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005630 },
Nick Harper60edffd2016-06-21 15:19:24 -07005631 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005632 })
5633
5634 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005635 name: "ClientAuth-SignatureType-TLS13",
5636 config: Config{
5637 ClientAuth: RequireAnyClientCert,
5638 MaxVersion: VersionTLS13,
5639 VerifySignatureAlgorithms: []signatureAlgorithm{
5640 signatureECDSAWithP521AndSHA512,
5641 signatureRSAPKCS1WithSHA384,
5642 signatureRSAPSSWithSHA384,
5643 signatureECDSAWithSHA1,
5644 },
5645 },
5646 flags: []string{
5647 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5648 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5649 },
5650 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5651 })
5652
5653 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005654 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005655 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005656 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005657 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005658 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005659 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005660 signatureECDSAWithP521AndSHA512,
5661 signatureRSAPKCS1WithSHA384,
5662 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005663 },
5664 },
Nick Harper60edffd2016-06-21 15:19:24 -07005665 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005666 })
5667
Steven Valdez143e8b32016-07-11 13:19:03 -04005668 testCases = append(testCases, testCase{
5669 testType: serverTest,
5670 name: "ServerAuth-SignatureType-TLS13",
5671 config: Config{
5672 MaxVersion: VersionTLS13,
5673 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5674 VerifySignatureAlgorithms: []signatureAlgorithm{
5675 signatureECDSAWithP521AndSHA512,
5676 signatureRSAPKCS1WithSHA384,
5677 signatureRSAPSSWithSHA384,
5678 signatureECDSAWithSHA1,
5679 },
5680 },
5681 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5682 })
5683
David Benjamina95e9f32016-07-08 16:28:04 -07005684 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005685 testCases = append(testCases, testCase{
5686 testType: serverTest,
5687 name: "Verify-ClientAuth-SignatureType",
5688 config: Config{
5689 MaxVersion: VersionTLS12,
5690 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005691 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005692 signatureRSAPKCS1WithSHA256,
5693 },
5694 Bugs: ProtocolBugs{
5695 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5696 },
5697 },
5698 flags: []string{
5699 "-require-any-client-certificate",
5700 },
5701 shouldFail: true,
5702 expectedError: ":WRONG_SIGNATURE_TYPE:",
5703 })
5704
5705 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005706 testType: serverTest,
5707 name: "Verify-ClientAuth-SignatureType-TLS13",
5708 config: Config{
5709 MaxVersion: VersionTLS13,
5710 Certificates: []Certificate{rsaCertificate},
5711 SignSignatureAlgorithms: []signatureAlgorithm{
5712 signatureRSAPSSWithSHA256,
5713 },
5714 Bugs: ProtocolBugs{
5715 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5716 },
5717 },
5718 flags: []string{
5719 "-require-any-client-certificate",
5720 },
5721 shouldFail: true,
5722 expectedError: ":WRONG_SIGNATURE_TYPE:",
5723 })
5724
5725 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005726 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005727 config: Config{
5728 MaxVersion: VersionTLS12,
5729 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005730 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005731 signatureRSAPKCS1WithSHA256,
5732 },
5733 Bugs: ProtocolBugs{
5734 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5735 },
5736 },
5737 shouldFail: true,
5738 expectedError: ":WRONG_SIGNATURE_TYPE:",
5739 })
5740
Steven Valdez143e8b32016-07-11 13:19:03 -04005741 testCases = append(testCases, testCase{
5742 name: "Verify-ServerAuth-SignatureType-TLS13",
5743 config: Config{
5744 MaxVersion: VersionTLS13,
5745 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5746 SignSignatureAlgorithms: []signatureAlgorithm{
5747 signatureRSAPSSWithSHA256,
5748 },
5749 Bugs: ProtocolBugs{
5750 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5751 },
5752 },
5753 shouldFail: true,
5754 expectedError: ":WRONG_SIGNATURE_TYPE:",
5755 })
5756
David Benjamin51dd7d62016-07-08 16:07:01 -07005757 // Test that, if the list is missing, the peer falls back to SHA-1 in
5758 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005759 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005760 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005761 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005762 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005763 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005764 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005765 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005766 },
5767 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005768 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005769 },
5770 },
5771 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005772 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5773 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005774 },
5775 })
5776
5777 testCases = append(testCases, testCase{
5778 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005779 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005780 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005781 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005782 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005783 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005784 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005785 },
5786 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005787 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005788 },
5789 },
5790 })
David Benjamin72dc7832015-03-16 17:49:43 -04005791
David Benjamin51dd7d62016-07-08 16:07:01 -07005792 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005793 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005794 config: Config{
5795 MaxVersion: VersionTLS13,
5796 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005797 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005798 signatureRSAPKCS1WithSHA1,
5799 },
5800 Bugs: ProtocolBugs{
5801 NoSignatureAlgorithms: true,
5802 },
5803 },
5804 flags: []string{
5805 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5806 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5807 },
David Benjamin48901652016-08-01 12:12:47 -04005808 shouldFail: true,
5809 // An empty CertificateRequest signature algorithm list is a
5810 // syntax error in TLS 1.3.
5811 expectedError: ":DECODE_ERROR:",
5812 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005813 })
5814
5815 testCases = append(testCases, testCase{
5816 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005817 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005818 config: Config{
5819 MaxVersion: VersionTLS13,
5820 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005821 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005822 signatureRSAPKCS1WithSHA1,
5823 },
5824 Bugs: ProtocolBugs{
5825 NoSignatureAlgorithms: true,
5826 },
5827 },
5828 shouldFail: true,
5829 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5830 })
5831
David Benjaminb62d2872016-07-18 14:55:02 +02005832 // Test that hash preferences are enforced. BoringSSL does not implement
5833 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005834 testCases = append(testCases, testCase{
5835 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005836 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005838 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005839 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005840 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005841 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005842 },
5843 Bugs: ProtocolBugs{
5844 IgnorePeerSignatureAlgorithmPreferences: true,
5845 },
5846 },
5847 flags: []string{"-require-any-client-certificate"},
5848 shouldFail: true,
5849 expectedError: ":WRONG_SIGNATURE_TYPE:",
5850 })
5851
5852 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005853 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005854 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005855 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005856 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005857 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005858 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005859 },
5860 Bugs: ProtocolBugs{
5861 IgnorePeerSignatureAlgorithmPreferences: true,
5862 },
5863 },
5864 shouldFail: true,
5865 expectedError: ":WRONG_SIGNATURE_TYPE:",
5866 })
David Benjaminb62d2872016-07-18 14:55:02 +02005867 testCases = append(testCases, testCase{
5868 testType: serverTest,
5869 name: "ClientAuth-Enforced-TLS13",
5870 config: Config{
5871 MaxVersion: VersionTLS13,
5872 Certificates: []Certificate{rsaCertificate},
5873 SignSignatureAlgorithms: []signatureAlgorithm{
5874 signatureRSAPKCS1WithMD5,
5875 },
5876 Bugs: ProtocolBugs{
5877 IgnorePeerSignatureAlgorithmPreferences: true,
5878 IgnoreSignatureVersionChecks: true,
5879 },
5880 },
5881 flags: []string{"-require-any-client-certificate"},
5882 shouldFail: true,
5883 expectedError: ":WRONG_SIGNATURE_TYPE:",
5884 })
5885
5886 testCases = append(testCases, testCase{
5887 name: "ServerAuth-Enforced-TLS13",
5888 config: Config{
5889 MaxVersion: VersionTLS13,
5890 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5891 SignSignatureAlgorithms: []signatureAlgorithm{
5892 signatureRSAPKCS1WithMD5,
5893 },
5894 Bugs: ProtocolBugs{
5895 IgnorePeerSignatureAlgorithmPreferences: true,
5896 IgnoreSignatureVersionChecks: true,
5897 },
5898 },
5899 shouldFail: true,
5900 expectedError: ":WRONG_SIGNATURE_TYPE:",
5901 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005902
5903 // Test that the agreed upon digest respects the client preferences and
5904 // the server digests.
5905 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005906 name: "NoCommonAlgorithms-Digests",
5907 config: Config{
5908 MaxVersion: VersionTLS12,
5909 ClientAuth: RequireAnyClientCert,
5910 VerifySignatureAlgorithms: []signatureAlgorithm{
5911 signatureRSAPKCS1WithSHA512,
5912 signatureRSAPKCS1WithSHA1,
5913 },
5914 },
5915 flags: []string{
5916 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5917 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5918 "-digest-prefs", "SHA256",
5919 },
5920 shouldFail: true,
5921 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5922 })
5923 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005924 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005925 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005926 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005927 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005928 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005929 signatureRSAPKCS1WithSHA512,
5930 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005931 },
5932 },
5933 flags: []string{
5934 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5935 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005936 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005937 },
David Benjaminca3d5452016-07-14 12:51:01 -04005938 shouldFail: true,
5939 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5940 })
5941 testCases = append(testCases, testCase{
5942 name: "NoCommonAlgorithms-TLS13",
5943 config: Config{
5944 MaxVersion: VersionTLS13,
5945 ClientAuth: RequireAnyClientCert,
5946 VerifySignatureAlgorithms: []signatureAlgorithm{
5947 signatureRSAPSSWithSHA512,
5948 signatureRSAPSSWithSHA384,
5949 },
5950 },
5951 flags: []string{
5952 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5953 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5954 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5955 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005956 shouldFail: true,
5957 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005958 })
5959 testCases = append(testCases, testCase{
5960 name: "Agree-Digest-SHA256",
5961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005962 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005963 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005964 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005965 signatureRSAPKCS1WithSHA1,
5966 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005967 },
5968 },
5969 flags: []string{
5970 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5971 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005972 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005973 },
Nick Harper60edffd2016-06-21 15:19:24 -07005974 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005975 })
5976 testCases = append(testCases, testCase{
5977 name: "Agree-Digest-SHA1",
5978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005979 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005980 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005981 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005982 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005983 },
5984 },
5985 flags: []string{
5986 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5987 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005988 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005989 },
Nick Harper60edffd2016-06-21 15:19:24 -07005990 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005991 })
5992 testCases = append(testCases, testCase{
5993 name: "Agree-Digest-Default",
5994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005995 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005996 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005997 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005998 signatureRSAPKCS1WithSHA256,
5999 signatureECDSAWithP256AndSHA256,
6000 signatureRSAPKCS1WithSHA1,
6001 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006002 },
6003 },
6004 flags: []string{
6005 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6006 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6007 },
Nick Harper60edffd2016-06-21 15:19:24 -07006008 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006009 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006010
David Benjaminca3d5452016-07-14 12:51:01 -04006011 // Test that the signing preference list may include extra algorithms
6012 // without negotiation problems.
6013 testCases = append(testCases, testCase{
6014 testType: serverTest,
6015 name: "FilterExtraAlgorithms",
6016 config: Config{
6017 MaxVersion: VersionTLS12,
6018 VerifySignatureAlgorithms: []signatureAlgorithm{
6019 signatureRSAPKCS1WithSHA256,
6020 },
6021 },
6022 flags: []string{
6023 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6024 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6025 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6026 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6027 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6028 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6029 },
6030 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6031 })
6032
David Benjamin4c3ddf72016-06-29 18:13:53 -04006033 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6034 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006035 testCases = append(testCases, testCase{
6036 name: "CheckLeafCurve",
6037 config: Config{
6038 MaxVersion: VersionTLS12,
6039 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006040 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006041 },
6042 flags: []string{"-p384-only"},
6043 shouldFail: true,
6044 expectedError: ":BAD_ECC_CERT:",
6045 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006046
6047 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6048 testCases = append(testCases, testCase{
6049 name: "CheckLeafCurve-TLS13",
6050 config: Config{
6051 MaxVersion: VersionTLS13,
6052 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6053 Certificates: []Certificate{ecdsaP256Certificate},
6054 },
6055 flags: []string{"-p384-only"},
6056 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006057
6058 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6059 testCases = append(testCases, testCase{
6060 name: "ECDSACurveMismatch-Verify-TLS12",
6061 config: Config{
6062 MaxVersion: VersionTLS12,
6063 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6064 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006065 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006066 signatureECDSAWithP384AndSHA384,
6067 },
6068 },
6069 })
6070
6071 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6072 testCases = append(testCases, testCase{
6073 name: "ECDSACurveMismatch-Verify-TLS13",
6074 config: Config{
6075 MaxVersion: VersionTLS13,
6076 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6077 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006078 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006079 signatureECDSAWithP384AndSHA384,
6080 },
6081 Bugs: ProtocolBugs{
6082 SkipECDSACurveCheck: true,
6083 },
6084 },
6085 shouldFail: true,
6086 expectedError: ":WRONG_SIGNATURE_TYPE:",
6087 })
6088
6089 // Signature algorithm selection in TLS 1.3 should take the curve into
6090 // account.
6091 testCases = append(testCases, testCase{
6092 testType: serverTest,
6093 name: "ECDSACurveMismatch-Sign-TLS13",
6094 config: Config{
6095 MaxVersion: VersionTLS13,
6096 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006097 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006098 signatureECDSAWithP384AndSHA384,
6099 signatureECDSAWithP256AndSHA256,
6100 },
6101 },
6102 flags: []string{
6103 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6104 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6105 },
6106 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6107 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006108
6109 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6110 // server does not attempt to sign in that case.
6111 testCases = append(testCases, testCase{
6112 testType: serverTest,
6113 name: "RSA-PSS-Large",
6114 config: Config{
6115 MaxVersion: VersionTLS13,
6116 VerifySignatureAlgorithms: []signatureAlgorithm{
6117 signatureRSAPSSWithSHA512,
6118 },
6119 },
6120 flags: []string{
6121 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6122 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6123 },
6124 shouldFail: true,
6125 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6126 })
David Benjamin000800a2014-11-14 01:43:59 -05006127}
6128
David Benjamin83f90402015-01-27 01:09:43 -05006129// timeouts is the retransmit schedule for BoringSSL. It doubles and
6130// caps at 60 seconds. On the 13th timeout, it gives up.
6131var timeouts = []time.Duration{
6132 1 * time.Second,
6133 2 * time.Second,
6134 4 * time.Second,
6135 8 * time.Second,
6136 16 * time.Second,
6137 32 * time.Second,
6138 60 * time.Second,
6139 60 * time.Second,
6140 60 * time.Second,
6141 60 * time.Second,
6142 60 * time.Second,
6143 60 * time.Second,
6144 60 * time.Second,
6145}
6146
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006147// shortTimeouts is an alternate set of timeouts which would occur if the
6148// initial timeout duration was set to 250ms.
6149var shortTimeouts = []time.Duration{
6150 250 * time.Millisecond,
6151 500 * time.Millisecond,
6152 1 * time.Second,
6153 2 * time.Second,
6154 4 * time.Second,
6155 8 * time.Second,
6156 16 * time.Second,
6157 32 * time.Second,
6158 60 * time.Second,
6159 60 * time.Second,
6160 60 * time.Second,
6161 60 * time.Second,
6162 60 * time.Second,
6163}
6164
David Benjamin83f90402015-01-27 01:09:43 -05006165func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006166 // These tests work by coordinating some behavior on both the shim and
6167 // the runner.
6168 //
6169 // TimeoutSchedule configures the runner to send a series of timeout
6170 // opcodes to the shim (see packetAdaptor) immediately before reading
6171 // each peer handshake flight N. The timeout opcode both simulates a
6172 // timeout in the shim and acts as a synchronization point to help the
6173 // runner bracket each handshake flight.
6174 //
6175 // We assume the shim does not read from the channel eagerly. It must
6176 // first wait until it has sent flight N and is ready to receive
6177 // handshake flight N+1. At this point, it will process the timeout
6178 // opcode. It must then immediately respond with a timeout ACK and act
6179 // as if the shim was idle for the specified amount of time.
6180 //
6181 // The runner then drops all packets received before the ACK and
6182 // continues waiting for flight N. This ordering results in one attempt
6183 // at sending flight N to be dropped. For the test to complete, the
6184 // shim must send flight N again, testing that the shim implements DTLS
6185 // retransmit on a timeout.
6186
Steven Valdez143e8b32016-07-11 13:19:03 -04006187 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006188 // likely be more epochs to cross and the final message's retransmit may
6189 // be more complex.
6190
David Benjamin585d7a42016-06-02 14:58:00 -04006191 for _, async := range []bool{true, false} {
6192 var tests []testCase
6193
6194 // Test that this is indeed the timeout schedule. Stress all
6195 // four patterns of handshake.
6196 for i := 1; i < len(timeouts); i++ {
6197 number := strconv.Itoa(i)
6198 tests = append(tests, testCase{
6199 protocol: dtls,
6200 name: "DTLS-Retransmit-Client-" + number,
6201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006202 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006203 Bugs: ProtocolBugs{
6204 TimeoutSchedule: timeouts[:i],
6205 },
6206 },
6207 resumeSession: true,
6208 })
6209 tests = append(tests, testCase{
6210 protocol: dtls,
6211 testType: serverTest,
6212 name: "DTLS-Retransmit-Server-" + number,
6213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006214 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006215 Bugs: ProtocolBugs{
6216 TimeoutSchedule: timeouts[:i],
6217 },
6218 },
6219 resumeSession: true,
6220 })
6221 }
6222
6223 // Test that exceeding the timeout schedule hits a read
6224 // timeout.
6225 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006226 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006227 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006229 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006230 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006231 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006232 },
6233 },
6234 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006235 shouldFail: true,
6236 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006237 })
David Benjamin585d7a42016-06-02 14:58:00 -04006238
6239 if async {
6240 // Test that timeout handling has a fudge factor, due to API
6241 // problems.
6242 tests = append(tests, testCase{
6243 protocol: dtls,
6244 name: "DTLS-Retransmit-Fudge",
6245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006246 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006247 Bugs: ProtocolBugs{
6248 TimeoutSchedule: []time.Duration{
6249 timeouts[0] - 10*time.Millisecond,
6250 },
6251 },
6252 },
6253 resumeSession: true,
6254 })
6255 }
6256
6257 // Test that the final Finished retransmitting isn't
6258 // duplicated if the peer badly fragments everything.
6259 tests = append(tests, testCase{
6260 testType: serverTest,
6261 protocol: dtls,
6262 name: "DTLS-Retransmit-Fragmented",
6263 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006264 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006265 Bugs: ProtocolBugs{
6266 TimeoutSchedule: []time.Duration{timeouts[0]},
6267 MaxHandshakeRecordLength: 2,
6268 },
6269 },
6270 })
6271
6272 // Test the timeout schedule when a shorter initial timeout duration is set.
6273 tests = append(tests, testCase{
6274 protocol: dtls,
6275 name: "DTLS-Retransmit-Short-Client",
6276 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006277 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006278 Bugs: ProtocolBugs{
6279 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6280 },
6281 },
6282 resumeSession: true,
6283 flags: []string{"-initial-timeout-duration-ms", "250"},
6284 })
6285 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006286 protocol: dtls,
6287 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006288 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006289 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006290 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006291 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006292 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006293 },
6294 },
6295 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006296 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006297 })
David Benjamin585d7a42016-06-02 14:58:00 -04006298
6299 for _, test := range tests {
6300 if async {
6301 test.name += "-Async"
6302 test.flags = append(test.flags, "-async")
6303 }
6304
6305 testCases = append(testCases, test)
6306 }
David Benjamin83f90402015-01-27 01:09:43 -05006307 }
David Benjamin83f90402015-01-27 01:09:43 -05006308}
6309
David Benjaminc565ebb2015-04-03 04:06:36 -04006310func addExportKeyingMaterialTests() {
6311 for _, vers := range tlsVersions {
6312 if vers.version == VersionSSL30 {
6313 continue
6314 }
6315 testCases = append(testCases, testCase{
6316 name: "ExportKeyingMaterial-" + vers.name,
6317 config: Config{
6318 MaxVersion: vers.version,
6319 },
6320 exportKeyingMaterial: 1024,
6321 exportLabel: "label",
6322 exportContext: "context",
6323 useExportContext: true,
6324 })
6325 testCases = append(testCases, testCase{
6326 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6327 config: Config{
6328 MaxVersion: vers.version,
6329 },
6330 exportKeyingMaterial: 1024,
6331 })
6332 testCases = append(testCases, testCase{
6333 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6334 config: Config{
6335 MaxVersion: vers.version,
6336 },
6337 exportKeyingMaterial: 1024,
6338 useExportContext: true,
6339 })
6340 testCases = append(testCases, testCase{
6341 name: "ExportKeyingMaterial-Small-" + vers.name,
6342 config: Config{
6343 MaxVersion: vers.version,
6344 },
6345 exportKeyingMaterial: 1,
6346 exportLabel: "label",
6347 exportContext: "context",
6348 useExportContext: true,
6349 })
6350 }
6351 testCases = append(testCases, testCase{
6352 name: "ExportKeyingMaterial-SSL3",
6353 config: Config{
6354 MaxVersion: VersionSSL30,
6355 },
6356 exportKeyingMaterial: 1024,
6357 exportLabel: "label",
6358 exportContext: "context",
6359 useExportContext: true,
6360 shouldFail: true,
6361 expectedError: "failed to export keying material",
6362 })
6363}
6364
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006365func addTLSUniqueTests() {
6366 for _, isClient := range []bool{false, true} {
6367 for _, isResumption := range []bool{false, true} {
6368 for _, hasEMS := range []bool{false, true} {
6369 var suffix string
6370 if isResumption {
6371 suffix = "Resume-"
6372 } else {
6373 suffix = "Full-"
6374 }
6375
6376 if hasEMS {
6377 suffix += "EMS-"
6378 } else {
6379 suffix += "NoEMS-"
6380 }
6381
6382 if isClient {
6383 suffix += "Client"
6384 } else {
6385 suffix += "Server"
6386 }
6387
6388 test := testCase{
6389 name: "TLSUnique-" + suffix,
6390 testTLSUnique: true,
6391 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006392 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006393 Bugs: ProtocolBugs{
6394 NoExtendedMasterSecret: !hasEMS,
6395 },
6396 },
6397 }
6398
6399 if isResumption {
6400 test.resumeSession = true
6401 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006402 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006403 Bugs: ProtocolBugs{
6404 NoExtendedMasterSecret: !hasEMS,
6405 },
6406 }
6407 }
6408
6409 if isResumption && !hasEMS {
6410 test.shouldFail = true
6411 test.expectedError = "failed to get tls-unique"
6412 }
6413
6414 testCases = append(testCases, test)
6415 }
6416 }
6417 }
6418}
6419
Adam Langley09505632015-07-30 18:10:13 -07006420func addCustomExtensionTests() {
6421 expectedContents := "custom extension"
6422 emptyString := ""
6423
6424 for _, isClient := range []bool{false, true} {
6425 suffix := "Server"
6426 flag := "-enable-server-custom-extension"
6427 testType := serverTest
6428 if isClient {
6429 suffix = "Client"
6430 flag = "-enable-client-custom-extension"
6431 testType = clientTest
6432 }
6433
6434 testCases = append(testCases, testCase{
6435 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006436 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006437 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006438 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006439 Bugs: ProtocolBugs{
6440 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006441 ExpectedCustomExtension: &expectedContents,
6442 },
6443 },
6444 flags: []string{flag},
6445 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006446 testCases = append(testCases, testCase{
6447 testType: testType,
6448 name: "CustomExtensions-" + suffix + "-TLS13",
6449 config: Config{
6450 MaxVersion: VersionTLS13,
6451 Bugs: ProtocolBugs{
6452 CustomExtension: expectedContents,
6453 ExpectedCustomExtension: &expectedContents,
6454 },
6455 },
6456 flags: []string{flag},
6457 })
Adam Langley09505632015-07-30 18:10:13 -07006458
6459 // If the parse callback fails, the handshake should also fail.
6460 testCases = append(testCases, testCase{
6461 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006462 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006463 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006464 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006465 Bugs: ProtocolBugs{
6466 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006467 ExpectedCustomExtension: &expectedContents,
6468 },
6469 },
David Benjamin399e7c92015-07-30 23:01:27 -04006470 flags: []string{flag},
6471 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006472 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6473 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006474 testCases = append(testCases, testCase{
6475 testType: testType,
6476 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6477 config: Config{
6478 MaxVersion: VersionTLS13,
6479 Bugs: ProtocolBugs{
6480 CustomExtension: expectedContents + "foo",
6481 ExpectedCustomExtension: &expectedContents,
6482 },
6483 },
6484 flags: []string{flag},
6485 shouldFail: true,
6486 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6487 })
Adam Langley09505632015-07-30 18:10:13 -07006488
6489 // If the add callback fails, the handshake should also fail.
6490 testCases = append(testCases, testCase{
6491 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006492 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006494 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006495 Bugs: ProtocolBugs{
6496 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006497 ExpectedCustomExtension: &expectedContents,
6498 },
6499 },
David Benjamin399e7c92015-07-30 23:01:27 -04006500 flags: []string{flag, "-custom-extension-fail-add"},
6501 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006502 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6503 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006504 testCases = append(testCases, testCase{
6505 testType: testType,
6506 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6507 config: Config{
6508 MaxVersion: VersionTLS13,
6509 Bugs: ProtocolBugs{
6510 CustomExtension: expectedContents,
6511 ExpectedCustomExtension: &expectedContents,
6512 },
6513 },
6514 flags: []string{flag, "-custom-extension-fail-add"},
6515 shouldFail: true,
6516 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6517 })
Adam Langley09505632015-07-30 18:10:13 -07006518
6519 // If the add callback returns zero, no extension should be
6520 // added.
6521 skipCustomExtension := expectedContents
6522 if isClient {
6523 // For the case where the client skips sending the
6524 // custom extension, the server must not “echo” it.
6525 skipCustomExtension = ""
6526 }
6527 testCases = append(testCases, testCase{
6528 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006529 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006530 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006531 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006532 Bugs: ProtocolBugs{
6533 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006534 ExpectedCustomExtension: &emptyString,
6535 },
6536 },
6537 flags: []string{flag, "-custom-extension-skip"},
6538 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006539 testCases = append(testCases, testCase{
6540 testType: testType,
6541 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6542 config: Config{
6543 MaxVersion: VersionTLS13,
6544 Bugs: ProtocolBugs{
6545 CustomExtension: skipCustomExtension,
6546 ExpectedCustomExtension: &emptyString,
6547 },
6548 },
6549 flags: []string{flag, "-custom-extension-skip"},
6550 })
Adam Langley09505632015-07-30 18:10:13 -07006551 }
6552
6553 // The custom extension add callback should not be called if the client
6554 // doesn't send the extension.
6555 testCases = append(testCases, testCase{
6556 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006557 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006558 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006559 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006560 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006561 ExpectedCustomExtension: &emptyString,
6562 },
6563 },
6564 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6565 })
Adam Langley2deb9842015-08-07 11:15:37 -07006566
Steven Valdez143e8b32016-07-11 13:19:03 -04006567 testCases = append(testCases, testCase{
6568 testType: serverTest,
6569 name: "CustomExtensions-NotCalled-Server-TLS13",
6570 config: Config{
6571 MaxVersion: VersionTLS13,
6572 Bugs: ProtocolBugs{
6573 ExpectedCustomExtension: &emptyString,
6574 },
6575 },
6576 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6577 })
6578
Adam Langley2deb9842015-08-07 11:15:37 -07006579 // Test an unknown extension from the server.
6580 testCases = append(testCases, testCase{
6581 testType: clientTest,
6582 name: "UnknownExtension-Client",
6583 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006584 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006585 Bugs: ProtocolBugs{
6586 CustomExtension: expectedContents,
6587 },
6588 },
David Benjamin0c40a962016-08-01 12:05:50 -04006589 shouldFail: true,
6590 expectedError: ":UNEXPECTED_EXTENSION:",
6591 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006592 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006593 testCases = append(testCases, testCase{
6594 testType: clientTest,
6595 name: "UnknownExtension-Client-TLS13",
6596 config: Config{
6597 MaxVersion: VersionTLS13,
6598 Bugs: ProtocolBugs{
6599 CustomExtension: expectedContents,
6600 },
6601 },
David Benjamin0c40a962016-08-01 12:05:50 -04006602 shouldFail: true,
6603 expectedError: ":UNEXPECTED_EXTENSION:",
6604 expectedLocalError: "remote error: unsupported extension",
6605 })
6606
6607 // Test a known but unoffered extension from the server.
6608 testCases = append(testCases, testCase{
6609 testType: clientTest,
6610 name: "UnofferedExtension-Client",
6611 config: Config{
6612 MaxVersion: VersionTLS12,
6613 Bugs: ProtocolBugs{
6614 SendALPN: "alpn",
6615 },
6616 },
6617 shouldFail: true,
6618 expectedError: ":UNEXPECTED_EXTENSION:",
6619 expectedLocalError: "remote error: unsupported extension",
6620 })
6621 testCases = append(testCases, testCase{
6622 testType: clientTest,
6623 name: "UnofferedExtension-Client-TLS13",
6624 config: Config{
6625 MaxVersion: VersionTLS13,
6626 Bugs: ProtocolBugs{
6627 SendALPN: "alpn",
6628 },
6629 },
6630 shouldFail: true,
6631 expectedError: ":UNEXPECTED_EXTENSION:",
6632 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006633 })
Adam Langley09505632015-07-30 18:10:13 -07006634}
6635
David Benjaminb36a3952015-12-01 18:53:13 -05006636func addRSAClientKeyExchangeTests() {
6637 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6638 testCases = append(testCases, testCase{
6639 testType: serverTest,
6640 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6641 config: Config{
6642 // Ensure the ClientHello version and final
6643 // version are different, to detect if the
6644 // server uses the wrong one.
6645 MaxVersion: VersionTLS11,
6646 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6647 Bugs: ProtocolBugs{
6648 BadRSAClientKeyExchange: bad,
6649 },
6650 },
6651 shouldFail: true,
6652 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6653 })
6654 }
6655}
6656
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006657var testCurves = []struct {
6658 name string
6659 id CurveID
6660}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006661 {"P-256", CurveP256},
6662 {"P-384", CurveP384},
6663 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006664 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006665}
6666
Steven Valdez5440fe02016-07-18 12:40:30 -04006667const bogusCurve = 0x1234
6668
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006669func addCurveTests() {
6670 for _, curve := range testCurves {
6671 testCases = append(testCases, testCase{
6672 name: "CurveTest-Client-" + curve.name,
6673 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006674 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006675 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6676 CurvePreferences: []CurveID{curve.id},
6677 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006678 flags: []string{"-enable-all-curves"},
6679 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006680 })
6681 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006682 name: "CurveTest-Client-" + curve.name + "-TLS13",
6683 config: Config{
6684 MaxVersion: VersionTLS13,
6685 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6686 CurvePreferences: []CurveID{curve.id},
6687 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006688 flags: []string{"-enable-all-curves"},
6689 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006690 })
6691 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006692 testType: serverTest,
6693 name: "CurveTest-Server-" + curve.name,
6694 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006695 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006696 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6697 CurvePreferences: []CurveID{curve.id},
6698 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006699 flags: []string{"-enable-all-curves"},
6700 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006701 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006702 testCases = append(testCases, testCase{
6703 testType: serverTest,
6704 name: "CurveTest-Server-" + curve.name + "-TLS13",
6705 config: Config{
6706 MaxVersion: VersionTLS13,
6707 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6708 CurvePreferences: []CurveID{curve.id},
6709 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006710 flags: []string{"-enable-all-curves"},
6711 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006712 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006713 }
David Benjamin241ae832016-01-15 03:04:54 -05006714
6715 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006716 testCases = append(testCases, testCase{
6717 testType: serverTest,
6718 name: "UnknownCurve",
6719 config: Config{
6720 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6721 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6722 },
6723 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006724
6725 // The server must not consider ECDHE ciphers when there are no
6726 // supported curves.
6727 testCases = append(testCases, testCase{
6728 testType: serverTest,
6729 name: "NoSupportedCurves",
6730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006731 MaxVersion: VersionTLS12,
6732 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6733 Bugs: ProtocolBugs{
6734 NoSupportedCurves: true,
6735 },
6736 },
6737 shouldFail: true,
6738 expectedError: ":NO_SHARED_CIPHER:",
6739 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006740 testCases = append(testCases, testCase{
6741 testType: serverTest,
6742 name: "NoSupportedCurves-TLS13",
6743 config: Config{
6744 MaxVersion: VersionTLS13,
6745 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6746 Bugs: ProtocolBugs{
6747 NoSupportedCurves: true,
6748 },
6749 },
6750 shouldFail: true,
6751 expectedError: ":NO_SHARED_CIPHER:",
6752 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006753
6754 // The server must fall back to another cipher when there are no
6755 // supported curves.
6756 testCases = append(testCases, testCase{
6757 testType: serverTest,
6758 name: "NoCommonCurves",
6759 config: Config{
6760 MaxVersion: VersionTLS12,
6761 CipherSuites: []uint16{
6762 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6763 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6764 },
6765 CurvePreferences: []CurveID{CurveP224},
6766 },
6767 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6768 })
6769
6770 // The client must reject bogus curves and disabled curves.
6771 testCases = append(testCases, testCase{
6772 name: "BadECDHECurve",
6773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006774 MaxVersion: VersionTLS12,
6775 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6776 Bugs: ProtocolBugs{
6777 SendCurve: bogusCurve,
6778 },
6779 },
6780 shouldFail: true,
6781 expectedError: ":WRONG_CURVE:",
6782 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006783 testCases = append(testCases, testCase{
6784 name: "BadECDHECurve-TLS13",
6785 config: Config{
6786 MaxVersion: VersionTLS13,
6787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6788 Bugs: ProtocolBugs{
6789 SendCurve: bogusCurve,
6790 },
6791 },
6792 shouldFail: true,
6793 expectedError: ":WRONG_CURVE:",
6794 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006795
6796 testCases = append(testCases, testCase{
6797 name: "UnsupportedCurve",
6798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006799 MaxVersion: VersionTLS12,
6800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6801 CurvePreferences: []CurveID{CurveP256},
6802 Bugs: ProtocolBugs{
6803 IgnorePeerCurvePreferences: true,
6804 },
6805 },
6806 flags: []string{"-p384-only"},
6807 shouldFail: true,
6808 expectedError: ":WRONG_CURVE:",
6809 })
6810
David Benjamin4f921572016-07-17 14:20:10 +02006811 testCases = append(testCases, testCase{
6812 // TODO(davidben): Add a TLS 1.3 version where
6813 // HelloRetryRequest requests an unsupported curve.
6814 name: "UnsupportedCurve-ServerHello-TLS13",
6815 config: Config{
6816 MaxVersion: VersionTLS12,
6817 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6818 CurvePreferences: []CurveID{CurveP384},
6819 Bugs: ProtocolBugs{
6820 SendCurve: CurveP256,
6821 },
6822 },
6823 flags: []string{"-p384-only"},
6824 shouldFail: true,
6825 expectedError: ":WRONG_CURVE:",
6826 })
6827
David Benjamin4c3ddf72016-06-29 18:13:53 -04006828 // Test invalid curve points.
6829 testCases = append(testCases, testCase{
6830 name: "InvalidECDHPoint-Client",
6831 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006832 MaxVersion: VersionTLS12,
6833 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6834 CurvePreferences: []CurveID{CurveP256},
6835 Bugs: ProtocolBugs{
6836 InvalidECDHPoint: true,
6837 },
6838 },
6839 shouldFail: true,
6840 expectedError: ":INVALID_ENCODING:",
6841 })
6842 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006843 name: "InvalidECDHPoint-Client-TLS13",
6844 config: Config{
6845 MaxVersion: VersionTLS13,
6846 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6847 CurvePreferences: []CurveID{CurveP256},
6848 Bugs: ProtocolBugs{
6849 InvalidECDHPoint: true,
6850 },
6851 },
6852 shouldFail: true,
6853 expectedError: ":INVALID_ENCODING:",
6854 })
6855 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006856 testType: serverTest,
6857 name: "InvalidECDHPoint-Server",
6858 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006859 MaxVersion: VersionTLS12,
6860 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6861 CurvePreferences: []CurveID{CurveP256},
6862 Bugs: ProtocolBugs{
6863 InvalidECDHPoint: true,
6864 },
6865 },
6866 shouldFail: true,
6867 expectedError: ":INVALID_ENCODING:",
6868 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006869 testCases = append(testCases, testCase{
6870 testType: serverTest,
6871 name: "InvalidECDHPoint-Server-TLS13",
6872 config: Config{
6873 MaxVersion: VersionTLS13,
6874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6875 CurvePreferences: []CurveID{CurveP256},
6876 Bugs: ProtocolBugs{
6877 InvalidECDHPoint: true,
6878 },
6879 },
6880 shouldFail: true,
6881 expectedError: ":INVALID_ENCODING:",
6882 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006883}
6884
Matt Braithwaite54217e42016-06-13 13:03:47 -07006885func addCECPQ1Tests() {
6886 testCases = append(testCases, testCase{
6887 testType: clientTest,
6888 name: "CECPQ1-Client-BadX25519Part",
6889 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006890 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006891 MinVersion: VersionTLS12,
6892 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6893 Bugs: ProtocolBugs{
6894 CECPQ1BadX25519Part: true,
6895 },
6896 },
6897 flags: []string{"-cipher", "kCECPQ1"},
6898 shouldFail: true,
6899 expectedLocalError: "local error: bad record MAC",
6900 })
6901 testCases = append(testCases, testCase{
6902 testType: clientTest,
6903 name: "CECPQ1-Client-BadNewhopePart",
6904 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006905 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006906 MinVersion: VersionTLS12,
6907 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6908 Bugs: ProtocolBugs{
6909 CECPQ1BadNewhopePart: true,
6910 },
6911 },
6912 flags: []string{"-cipher", "kCECPQ1"},
6913 shouldFail: true,
6914 expectedLocalError: "local error: bad record MAC",
6915 })
6916 testCases = append(testCases, testCase{
6917 testType: serverTest,
6918 name: "CECPQ1-Server-BadX25519Part",
6919 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006920 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006921 MinVersion: VersionTLS12,
6922 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6923 Bugs: ProtocolBugs{
6924 CECPQ1BadX25519Part: true,
6925 },
6926 },
6927 flags: []string{"-cipher", "kCECPQ1"},
6928 shouldFail: true,
6929 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6930 })
6931 testCases = append(testCases, testCase{
6932 testType: serverTest,
6933 name: "CECPQ1-Server-BadNewhopePart",
6934 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006935 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006936 MinVersion: VersionTLS12,
6937 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6938 Bugs: ProtocolBugs{
6939 CECPQ1BadNewhopePart: true,
6940 },
6941 },
6942 flags: []string{"-cipher", "kCECPQ1"},
6943 shouldFail: true,
6944 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6945 })
6946}
6947
David Benjamin4cc36ad2015-12-19 14:23:26 -05006948func addKeyExchangeInfoTests() {
6949 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006950 name: "KeyExchangeInfo-DHE-Client",
6951 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006952 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006953 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6954 Bugs: ProtocolBugs{
6955 // This is a 1234-bit prime number, generated
6956 // with:
6957 // openssl gendh 1234 | openssl asn1parse -i
6958 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6959 },
6960 },
David Benjamin9e68f192016-06-30 14:55:33 -04006961 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006962 })
6963 testCases = append(testCases, testCase{
6964 testType: serverTest,
6965 name: "KeyExchangeInfo-DHE-Server",
6966 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006967 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006968 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6969 },
6970 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006971 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006972 })
6973
6974 testCases = append(testCases, testCase{
6975 name: "KeyExchangeInfo-ECDHE-Client",
6976 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006977 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006978 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6979 CurvePreferences: []CurveID{CurveX25519},
6980 },
David Benjamin9e68f192016-06-30 14:55:33 -04006981 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006982 })
6983 testCases = append(testCases, testCase{
6984 testType: serverTest,
6985 name: "KeyExchangeInfo-ECDHE-Server",
6986 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006987 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006988 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6989 CurvePreferences: []CurveID{CurveX25519},
6990 },
David Benjamin9e68f192016-06-30 14:55:33 -04006991 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006992 })
6993}
6994
David Benjaminc9ae27c2016-06-24 22:56:37 -04006995func addTLS13RecordTests() {
6996 testCases = append(testCases, testCase{
6997 name: "TLS13-RecordPadding",
6998 config: Config{
6999 MaxVersion: VersionTLS13,
7000 MinVersion: VersionTLS13,
7001 Bugs: ProtocolBugs{
7002 RecordPadding: 10,
7003 },
7004 },
7005 })
7006
7007 testCases = append(testCases, testCase{
7008 name: "TLS13-EmptyRecords",
7009 config: Config{
7010 MaxVersion: VersionTLS13,
7011 MinVersion: VersionTLS13,
7012 Bugs: ProtocolBugs{
7013 OmitRecordContents: true,
7014 },
7015 },
7016 shouldFail: true,
7017 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7018 })
7019
7020 testCases = append(testCases, testCase{
7021 name: "TLS13-OnlyPadding",
7022 config: Config{
7023 MaxVersion: VersionTLS13,
7024 MinVersion: VersionTLS13,
7025 Bugs: ProtocolBugs{
7026 OmitRecordContents: true,
7027 RecordPadding: 10,
7028 },
7029 },
7030 shouldFail: true,
7031 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7032 })
7033
7034 testCases = append(testCases, testCase{
7035 name: "TLS13-WrongOuterRecord",
7036 config: Config{
7037 MaxVersion: VersionTLS13,
7038 MinVersion: VersionTLS13,
7039 Bugs: ProtocolBugs{
7040 OuterRecordType: recordTypeHandshake,
7041 },
7042 },
7043 shouldFail: true,
7044 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7045 })
7046}
7047
David Benjamin82261be2016-07-07 14:32:50 -07007048func addChangeCipherSpecTests() {
7049 // Test missing ChangeCipherSpecs.
7050 testCases = append(testCases, testCase{
7051 name: "SkipChangeCipherSpec-Client",
7052 config: Config{
7053 MaxVersion: VersionTLS12,
7054 Bugs: ProtocolBugs{
7055 SkipChangeCipherSpec: true,
7056 },
7057 },
7058 shouldFail: true,
7059 expectedError: ":UNEXPECTED_RECORD:",
7060 })
7061 testCases = append(testCases, testCase{
7062 testType: serverTest,
7063 name: "SkipChangeCipherSpec-Server",
7064 config: Config{
7065 MaxVersion: VersionTLS12,
7066 Bugs: ProtocolBugs{
7067 SkipChangeCipherSpec: true,
7068 },
7069 },
7070 shouldFail: true,
7071 expectedError: ":UNEXPECTED_RECORD:",
7072 })
7073 testCases = append(testCases, testCase{
7074 testType: serverTest,
7075 name: "SkipChangeCipherSpec-Server-NPN",
7076 config: Config{
7077 MaxVersion: VersionTLS12,
7078 NextProtos: []string{"bar"},
7079 Bugs: ProtocolBugs{
7080 SkipChangeCipherSpec: true,
7081 },
7082 },
7083 flags: []string{
7084 "-advertise-npn", "\x03foo\x03bar\x03baz",
7085 },
7086 shouldFail: true,
7087 expectedError: ":UNEXPECTED_RECORD:",
7088 })
7089
7090 // Test synchronization between the handshake and ChangeCipherSpec.
7091 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7092 // rejected. Test both with and without handshake packing to handle both
7093 // when the partial post-CCS message is in its own record and when it is
7094 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007095 for _, packed := range []bool{false, true} {
7096 var suffix string
7097 if packed {
7098 suffix = "-Packed"
7099 }
7100
7101 testCases = append(testCases, testCase{
7102 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7103 config: Config{
7104 MaxVersion: VersionTLS12,
7105 Bugs: ProtocolBugs{
7106 FragmentAcrossChangeCipherSpec: true,
7107 PackHandshakeFlight: packed,
7108 },
7109 },
7110 shouldFail: true,
7111 expectedError: ":UNEXPECTED_RECORD:",
7112 })
7113 testCases = append(testCases, testCase{
7114 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7115 config: Config{
7116 MaxVersion: VersionTLS12,
7117 },
7118 resumeSession: true,
7119 resumeConfig: &Config{
7120 MaxVersion: VersionTLS12,
7121 Bugs: ProtocolBugs{
7122 FragmentAcrossChangeCipherSpec: true,
7123 PackHandshakeFlight: packed,
7124 },
7125 },
7126 shouldFail: true,
7127 expectedError: ":UNEXPECTED_RECORD:",
7128 })
7129 testCases = append(testCases, testCase{
7130 testType: serverTest,
7131 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7132 config: Config{
7133 MaxVersion: VersionTLS12,
7134 Bugs: ProtocolBugs{
7135 FragmentAcrossChangeCipherSpec: true,
7136 PackHandshakeFlight: packed,
7137 },
7138 },
7139 shouldFail: true,
7140 expectedError: ":UNEXPECTED_RECORD:",
7141 })
7142 testCases = append(testCases, testCase{
7143 testType: serverTest,
7144 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7145 config: Config{
7146 MaxVersion: VersionTLS12,
7147 },
7148 resumeSession: true,
7149 resumeConfig: &Config{
7150 MaxVersion: VersionTLS12,
7151 Bugs: ProtocolBugs{
7152 FragmentAcrossChangeCipherSpec: true,
7153 PackHandshakeFlight: packed,
7154 },
7155 },
7156 shouldFail: true,
7157 expectedError: ":UNEXPECTED_RECORD:",
7158 })
7159 testCases = append(testCases, testCase{
7160 testType: serverTest,
7161 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7162 config: Config{
7163 MaxVersion: VersionTLS12,
7164 NextProtos: []string{"bar"},
7165 Bugs: ProtocolBugs{
7166 FragmentAcrossChangeCipherSpec: true,
7167 PackHandshakeFlight: packed,
7168 },
7169 },
7170 flags: []string{
7171 "-advertise-npn", "\x03foo\x03bar\x03baz",
7172 },
7173 shouldFail: true,
7174 expectedError: ":UNEXPECTED_RECORD:",
7175 })
7176 }
7177
David Benjamin61672812016-07-14 23:10:43 -04007178 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7179 // messages in the handshake queue. Do this by testing the server
7180 // reading the client Finished, reversing the flight so Finished comes
7181 // first.
7182 testCases = append(testCases, testCase{
7183 protocol: dtls,
7184 testType: serverTest,
7185 name: "SendUnencryptedFinished-DTLS",
7186 config: Config{
7187 MaxVersion: VersionTLS12,
7188 Bugs: ProtocolBugs{
7189 SendUnencryptedFinished: true,
7190 ReverseHandshakeFragments: true,
7191 },
7192 },
7193 shouldFail: true,
7194 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7195 })
7196
Steven Valdez143e8b32016-07-11 13:19:03 -04007197 // Test synchronization between encryption changes and the handshake in
7198 // TLS 1.3, where ChangeCipherSpec is implicit.
7199 testCases = append(testCases, testCase{
7200 name: "PartialEncryptedExtensionsWithServerHello",
7201 config: Config{
7202 MaxVersion: VersionTLS13,
7203 Bugs: ProtocolBugs{
7204 PartialEncryptedExtensionsWithServerHello: true,
7205 },
7206 },
7207 shouldFail: true,
7208 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7209 })
7210 testCases = append(testCases, testCase{
7211 testType: serverTest,
7212 name: "PartialClientFinishedWithClientHello",
7213 config: Config{
7214 MaxVersion: VersionTLS13,
7215 Bugs: ProtocolBugs{
7216 PartialClientFinishedWithClientHello: true,
7217 },
7218 },
7219 shouldFail: true,
7220 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7221 })
7222
David Benjamin82261be2016-07-07 14:32:50 -07007223 // Test that early ChangeCipherSpecs are handled correctly.
7224 testCases = append(testCases, testCase{
7225 testType: serverTest,
7226 name: "EarlyChangeCipherSpec-server-1",
7227 config: Config{
7228 MaxVersion: VersionTLS12,
7229 Bugs: ProtocolBugs{
7230 EarlyChangeCipherSpec: 1,
7231 },
7232 },
7233 shouldFail: true,
7234 expectedError: ":UNEXPECTED_RECORD:",
7235 })
7236 testCases = append(testCases, testCase{
7237 testType: serverTest,
7238 name: "EarlyChangeCipherSpec-server-2",
7239 config: Config{
7240 MaxVersion: VersionTLS12,
7241 Bugs: ProtocolBugs{
7242 EarlyChangeCipherSpec: 2,
7243 },
7244 },
7245 shouldFail: true,
7246 expectedError: ":UNEXPECTED_RECORD:",
7247 })
7248 testCases = append(testCases, testCase{
7249 protocol: dtls,
7250 name: "StrayChangeCipherSpec",
7251 config: Config{
7252 // TODO(davidben): Once DTLS 1.3 exists, test
7253 // that stray ChangeCipherSpec messages are
7254 // rejected.
7255 MaxVersion: VersionTLS12,
7256 Bugs: ProtocolBugs{
7257 StrayChangeCipherSpec: true,
7258 },
7259 },
7260 })
7261
7262 // Test that the contents of ChangeCipherSpec are checked.
7263 testCases = append(testCases, testCase{
7264 name: "BadChangeCipherSpec-1",
7265 config: Config{
7266 MaxVersion: VersionTLS12,
7267 Bugs: ProtocolBugs{
7268 BadChangeCipherSpec: []byte{2},
7269 },
7270 },
7271 shouldFail: true,
7272 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7273 })
7274 testCases = append(testCases, testCase{
7275 name: "BadChangeCipherSpec-2",
7276 config: Config{
7277 MaxVersion: VersionTLS12,
7278 Bugs: ProtocolBugs{
7279 BadChangeCipherSpec: []byte{1, 1},
7280 },
7281 },
7282 shouldFail: true,
7283 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7284 })
7285 testCases = append(testCases, testCase{
7286 protocol: dtls,
7287 name: "BadChangeCipherSpec-DTLS-1",
7288 config: Config{
7289 MaxVersion: VersionTLS12,
7290 Bugs: ProtocolBugs{
7291 BadChangeCipherSpec: []byte{2},
7292 },
7293 },
7294 shouldFail: true,
7295 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7296 })
7297 testCases = append(testCases, testCase{
7298 protocol: dtls,
7299 name: "BadChangeCipherSpec-DTLS-2",
7300 config: Config{
7301 MaxVersion: VersionTLS12,
7302 Bugs: ProtocolBugs{
7303 BadChangeCipherSpec: []byte{1, 1},
7304 },
7305 },
7306 shouldFail: true,
7307 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7308 })
7309}
7310
David Benjamin0b8d5da2016-07-15 00:39:56 -04007311func addWrongMessageTypeTests() {
7312 for _, protocol := range []protocol{tls, dtls} {
7313 var suffix string
7314 if protocol == dtls {
7315 suffix = "-DTLS"
7316 }
7317
7318 testCases = append(testCases, testCase{
7319 protocol: protocol,
7320 testType: serverTest,
7321 name: "WrongMessageType-ClientHello" + suffix,
7322 config: Config{
7323 MaxVersion: VersionTLS12,
7324 Bugs: ProtocolBugs{
7325 SendWrongMessageType: typeClientHello,
7326 },
7327 },
7328 shouldFail: true,
7329 expectedError: ":UNEXPECTED_MESSAGE:",
7330 expectedLocalError: "remote error: unexpected message",
7331 })
7332
7333 if protocol == dtls {
7334 testCases = append(testCases, testCase{
7335 protocol: protocol,
7336 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7337 config: Config{
7338 MaxVersion: VersionTLS12,
7339 Bugs: ProtocolBugs{
7340 SendWrongMessageType: typeHelloVerifyRequest,
7341 },
7342 },
7343 shouldFail: true,
7344 expectedError: ":UNEXPECTED_MESSAGE:",
7345 expectedLocalError: "remote error: unexpected message",
7346 })
7347 }
7348
7349 testCases = append(testCases, testCase{
7350 protocol: protocol,
7351 name: "WrongMessageType-ServerHello" + suffix,
7352 config: Config{
7353 MaxVersion: VersionTLS12,
7354 Bugs: ProtocolBugs{
7355 SendWrongMessageType: typeServerHello,
7356 },
7357 },
7358 shouldFail: true,
7359 expectedError: ":UNEXPECTED_MESSAGE:",
7360 expectedLocalError: "remote error: unexpected message",
7361 })
7362
7363 testCases = append(testCases, testCase{
7364 protocol: protocol,
7365 name: "WrongMessageType-ServerCertificate" + suffix,
7366 config: Config{
7367 MaxVersion: VersionTLS12,
7368 Bugs: ProtocolBugs{
7369 SendWrongMessageType: typeCertificate,
7370 },
7371 },
7372 shouldFail: true,
7373 expectedError: ":UNEXPECTED_MESSAGE:",
7374 expectedLocalError: "remote error: unexpected message",
7375 })
7376
7377 testCases = append(testCases, testCase{
7378 protocol: protocol,
7379 name: "WrongMessageType-CertificateStatus" + suffix,
7380 config: Config{
7381 MaxVersion: VersionTLS12,
7382 Bugs: ProtocolBugs{
7383 SendWrongMessageType: typeCertificateStatus,
7384 },
7385 },
7386 flags: []string{"-enable-ocsp-stapling"},
7387 shouldFail: true,
7388 expectedError: ":UNEXPECTED_MESSAGE:",
7389 expectedLocalError: "remote error: unexpected message",
7390 })
7391
7392 testCases = append(testCases, testCase{
7393 protocol: protocol,
7394 name: "WrongMessageType-ServerKeyExchange" + suffix,
7395 config: Config{
7396 MaxVersion: VersionTLS12,
7397 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7398 Bugs: ProtocolBugs{
7399 SendWrongMessageType: typeServerKeyExchange,
7400 },
7401 },
7402 shouldFail: true,
7403 expectedError: ":UNEXPECTED_MESSAGE:",
7404 expectedLocalError: "remote error: unexpected message",
7405 })
7406
7407 testCases = append(testCases, testCase{
7408 protocol: protocol,
7409 name: "WrongMessageType-CertificateRequest" + suffix,
7410 config: Config{
7411 MaxVersion: VersionTLS12,
7412 ClientAuth: RequireAnyClientCert,
7413 Bugs: ProtocolBugs{
7414 SendWrongMessageType: typeCertificateRequest,
7415 },
7416 },
7417 shouldFail: true,
7418 expectedError: ":UNEXPECTED_MESSAGE:",
7419 expectedLocalError: "remote error: unexpected message",
7420 })
7421
7422 testCases = append(testCases, testCase{
7423 protocol: protocol,
7424 name: "WrongMessageType-ServerHelloDone" + suffix,
7425 config: Config{
7426 MaxVersion: VersionTLS12,
7427 Bugs: ProtocolBugs{
7428 SendWrongMessageType: typeServerHelloDone,
7429 },
7430 },
7431 shouldFail: true,
7432 expectedError: ":UNEXPECTED_MESSAGE:",
7433 expectedLocalError: "remote error: unexpected message",
7434 })
7435
7436 testCases = append(testCases, testCase{
7437 testType: serverTest,
7438 protocol: protocol,
7439 name: "WrongMessageType-ClientCertificate" + suffix,
7440 config: Config{
7441 Certificates: []Certificate{rsaCertificate},
7442 MaxVersion: VersionTLS12,
7443 Bugs: ProtocolBugs{
7444 SendWrongMessageType: typeCertificate,
7445 },
7446 },
7447 flags: []string{"-require-any-client-certificate"},
7448 shouldFail: true,
7449 expectedError: ":UNEXPECTED_MESSAGE:",
7450 expectedLocalError: "remote error: unexpected message",
7451 })
7452
7453 testCases = append(testCases, testCase{
7454 testType: serverTest,
7455 protocol: protocol,
7456 name: "WrongMessageType-CertificateVerify" + suffix,
7457 config: Config{
7458 Certificates: []Certificate{rsaCertificate},
7459 MaxVersion: VersionTLS12,
7460 Bugs: ProtocolBugs{
7461 SendWrongMessageType: typeCertificateVerify,
7462 },
7463 },
7464 flags: []string{"-require-any-client-certificate"},
7465 shouldFail: true,
7466 expectedError: ":UNEXPECTED_MESSAGE:",
7467 expectedLocalError: "remote error: unexpected message",
7468 })
7469
7470 testCases = append(testCases, testCase{
7471 testType: serverTest,
7472 protocol: protocol,
7473 name: "WrongMessageType-ClientKeyExchange" + suffix,
7474 config: Config{
7475 MaxVersion: VersionTLS12,
7476 Bugs: ProtocolBugs{
7477 SendWrongMessageType: typeClientKeyExchange,
7478 },
7479 },
7480 shouldFail: true,
7481 expectedError: ":UNEXPECTED_MESSAGE:",
7482 expectedLocalError: "remote error: unexpected message",
7483 })
7484
7485 if protocol != dtls {
7486 testCases = append(testCases, testCase{
7487 testType: serverTest,
7488 protocol: protocol,
7489 name: "WrongMessageType-NextProtocol" + suffix,
7490 config: Config{
7491 MaxVersion: VersionTLS12,
7492 NextProtos: []string{"bar"},
7493 Bugs: ProtocolBugs{
7494 SendWrongMessageType: typeNextProtocol,
7495 },
7496 },
7497 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7498 shouldFail: true,
7499 expectedError: ":UNEXPECTED_MESSAGE:",
7500 expectedLocalError: "remote error: unexpected message",
7501 })
7502
7503 testCases = append(testCases, testCase{
7504 testType: serverTest,
7505 protocol: protocol,
7506 name: "WrongMessageType-ChannelID" + suffix,
7507 config: Config{
7508 MaxVersion: VersionTLS12,
7509 ChannelID: channelIDKey,
7510 Bugs: ProtocolBugs{
7511 SendWrongMessageType: typeChannelID,
7512 },
7513 },
7514 flags: []string{
7515 "-expect-channel-id",
7516 base64.StdEncoding.EncodeToString(channelIDBytes),
7517 },
7518 shouldFail: true,
7519 expectedError: ":UNEXPECTED_MESSAGE:",
7520 expectedLocalError: "remote error: unexpected message",
7521 })
7522 }
7523
7524 testCases = append(testCases, testCase{
7525 testType: serverTest,
7526 protocol: protocol,
7527 name: "WrongMessageType-ClientFinished" + suffix,
7528 config: Config{
7529 MaxVersion: VersionTLS12,
7530 Bugs: ProtocolBugs{
7531 SendWrongMessageType: typeFinished,
7532 },
7533 },
7534 shouldFail: true,
7535 expectedError: ":UNEXPECTED_MESSAGE:",
7536 expectedLocalError: "remote error: unexpected message",
7537 })
7538
7539 testCases = append(testCases, testCase{
7540 protocol: protocol,
7541 name: "WrongMessageType-NewSessionTicket" + suffix,
7542 config: Config{
7543 MaxVersion: VersionTLS12,
7544 Bugs: ProtocolBugs{
7545 SendWrongMessageType: typeNewSessionTicket,
7546 },
7547 },
7548 shouldFail: true,
7549 expectedError: ":UNEXPECTED_MESSAGE:",
7550 expectedLocalError: "remote error: unexpected message",
7551 })
7552
7553 testCases = append(testCases, testCase{
7554 protocol: protocol,
7555 name: "WrongMessageType-ServerFinished" + suffix,
7556 config: Config{
7557 MaxVersion: VersionTLS12,
7558 Bugs: ProtocolBugs{
7559 SendWrongMessageType: typeFinished,
7560 },
7561 },
7562 shouldFail: true,
7563 expectedError: ":UNEXPECTED_MESSAGE:",
7564 expectedLocalError: "remote error: unexpected message",
7565 })
7566
7567 }
7568}
7569
Steven Valdez143e8b32016-07-11 13:19:03 -04007570func addTLS13WrongMessageTypeTests() {
7571 testCases = append(testCases, testCase{
7572 testType: serverTest,
7573 name: "WrongMessageType-TLS13-ClientHello",
7574 config: Config{
7575 MaxVersion: VersionTLS13,
7576 Bugs: ProtocolBugs{
7577 SendWrongMessageType: typeClientHello,
7578 },
7579 },
7580 shouldFail: true,
7581 expectedError: ":UNEXPECTED_MESSAGE:",
7582 expectedLocalError: "remote error: unexpected message",
7583 })
7584
7585 testCases = append(testCases, testCase{
7586 name: "WrongMessageType-TLS13-ServerHello",
7587 config: Config{
7588 MaxVersion: VersionTLS13,
7589 Bugs: ProtocolBugs{
7590 SendWrongMessageType: typeServerHello,
7591 },
7592 },
7593 shouldFail: true,
7594 expectedError: ":UNEXPECTED_MESSAGE:",
7595 // The alert comes in with the wrong encryption.
7596 expectedLocalError: "local error: bad record MAC",
7597 })
7598
7599 testCases = append(testCases, testCase{
7600 name: "WrongMessageType-TLS13-EncryptedExtensions",
7601 config: Config{
7602 MaxVersion: VersionTLS13,
7603 Bugs: ProtocolBugs{
7604 SendWrongMessageType: typeEncryptedExtensions,
7605 },
7606 },
7607 shouldFail: true,
7608 expectedError: ":UNEXPECTED_MESSAGE:",
7609 expectedLocalError: "remote error: unexpected message",
7610 })
7611
7612 testCases = append(testCases, testCase{
7613 name: "WrongMessageType-TLS13-CertificateRequest",
7614 config: Config{
7615 MaxVersion: VersionTLS13,
7616 ClientAuth: RequireAnyClientCert,
7617 Bugs: ProtocolBugs{
7618 SendWrongMessageType: typeCertificateRequest,
7619 },
7620 },
7621 shouldFail: true,
7622 expectedError: ":UNEXPECTED_MESSAGE:",
7623 expectedLocalError: "remote error: unexpected message",
7624 })
7625
7626 testCases = append(testCases, testCase{
7627 name: "WrongMessageType-TLS13-ServerCertificate",
7628 config: Config{
7629 MaxVersion: VersionTLS13,
7630 Bugs: ProtocolBugs{
7631 SendWrongMessageType: typeCertificate,
7632 },
7633 },
7634 shouldFail: true,
7635 expectedError: ":UNEXPECTED_MESSAGE:",
7636 expectedLocalError: "remote error: unexpected message",
7637 })
7638
7639 testCases = append(testCases, testCase{
7640 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7641 config: Config{
7642 MaxVersion: VersionTLS13,
7643 Bugs: ProtocolBugs{
7644 SendWrongMessageType: typeCertificateVerify,
7645 },
7646 },
7647 shouldFail: true,
7648 expectedError: ":UNEXPECTED_MESSAGE:",
7649 expectedLocalError: "remote error: unexpected message",
7650 })
7651
7652 testCases = append(testCases, testCase{
7653 name: "WrongMessageType-TLS13-ServerFinished",
7654 config: Config{
7655 MaxVersion: VersionTLS13,
7656 Bugs: ProtocolBugs{
7657 SendWrongMessageType: typeFinished,
7658 },
7659 },
7660 shouldFail: true,
7661 expectedError: ":UNEXPECTED_MESSAGE:",
7662 expectedLocalError: "remote error: unexpected message",
7663 })
7664
7665 testCases = append(testCases, testCase{
7666 testType: serverTest,
7667 name: "WrongMessageType-TLS13-ClientCertificate",
7668 config: Config{
7669 Certificates: []Certificate{rsaCertificate},
7670 MaxVersion: VersionTLS13,
7671 Bugs: ProtocolBugs{
7672 SendWrongMessageType: typeCertificate,
7673 },
7674 },
7675 flags: []string{"-require-any-client-certificate"},
7676 shouldFail: true,
7677 expectedError: ":UNEXPECTED_MESSAGE:",
7678 expectedLocalError: "remote error: unexpected message",
7679 })
7680
7681 testCases = append(testCases, testCase{
7682 testType: serverTest,
7683 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7684 config: Config{
7685 Certificates: []Certificate{rsaCertificate},
7686 MaxVersion: VersionTLS13,
7687 Bugs: ProtocolBugs{
7688 SendWrongMessageType: typeCertificateVerify,
7689 },
7690 },
7691 flags: []string{"-require-any-client-certificate"},
7692 shouldFail: true,
7693 expectedError: ":UNEXPECTED_MESSAGE:",
7694 expectedLocalError: "remote error: unexpected message",
7695 })
7696
7697 testCases = append(testCases, testCase{
7698 testType: serverTest,
7699 name: "WrongMessageType-TLS13-ClientFinished",
7700 config: Config{
7701 MaxVersion: VersionTLS13,
7702 Bugs: ProtocolBugs{
7703 SendWrongMessageType: typeFinished,
7704 },
7705 },
7706 shouldFail: true,
7707 expectedError: ":UNEXPECTED_MESSAGE:",
7708 expectedLocalError: "remote error: unexpected message",
7709 })
7710}
7711
7712func addTLS13HandshakeTests() {
7713 testCases = append(testCases, testCase{
7714 testType: clientTest,
7715 name: "MissingKeyShare-Client",
7716 config: Config{
7717 MaxVersion: VersionTLS13,
7718 Bugs: ProtocolBugs{
7719 MissingKeyShare: true,
7720 },
7721 },
7722 shouldFail: true,
7723 expectedError: ":MISSING_KEY_SHARE:",
7724 })
7725
7726 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007727 testType: serverTest,
7728 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007729 config: Config{
7730 MaxVersion: VersionTLS13,
7731 Bugs: ProtocolBugs{
7732 MissingKeyShare: true,
7733 },
7734 },
7735 shouldFail: true,
7736 expectedError: ":MISSING_KEY_SHARE:",
7737 })
7738
7739 testCases = append(testCases, testCase{
7740 testType: clientTest,
7741 name: "ClientHelloMissingKeyShare",
7742 config: Config{
7743 MaxVersion: VersionTLS13,
7744 Bugs: ProtocolBugs{
7745 MissingKeyShare: true,
7746 },
7747 },
7748 shouldFail: true,
7749 expectedError: ":MISSING_KEY_SHARE:",
7750 })
7751
7752 testCases = append(testCases, testCase{
7753 testType: clientTest,
7754 name: "MissingKeyShare",
7755 config: Config{
7756 MaxVersion: VersionTLS13,
7757 Bugs: ProtocolBugs{
7758 MissingKeyShare: true,
7759 },
7760 },
7761 shouldFail: true,
7762 expectedError: ":MISSING_KEY_SHARE:",
7763 })
7764
7765 testCases = append(testCases, testCase{
7766 testType: serverTest,
7767 name: "DuplicateKeyShares",
7768 config: Config{
7769 MaxVersion: VersionTLS13,
7770 Bugs: ProtocolBugs{
7771 DuplicateKeyShares: true,
7772 },
7773 },
7774 })
7775
7776 testCases = append(testCases, testCase{
7777 testType: clientTest,
7778 name: "EmptyEncryptedExtensions",
7779 config: Config{
7780 MaxVersion: VersionTLS13,
7781 Bugs: ProtocolBugs{
7782 EmptyEncryptedExtensions: true,
7783 },
7784 },
7785 shouldFail: true,
7786 expectedLocalError: "remote error: error decoding message",
7787 })
7788
7789 testCases = append(testCases, testCase{
7790 testType: clientTest,
7791 name: "EncryptedExtensionsWithKeyShare",
7792 config: Config{
7793 MaxVersion: VersionTLS13,
7794 Bugs: ProtocolBugs{
7795 EncryptedExtensionsWithKeyShare: true,
7796 },
7797 },
7798 shouldFail: true,
7799 expectedLocalError: "remote error: unsupported extension",
7800 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007801
7802 testCases = append(testCases, testCase{
7803 testType: serverTest,
7804 name: "SendHelloRetryRequest",
7805 config: Config{
7806 MaxVersion: VersionTLS13,
7807 // Require a HelloRetryRequest for every curve.
7808 DefaultCurves: []CurveID{},
7809 },
7810 expectedCurveID: CurveX25519,
7811 })
7812
7813 testCases = append(testCases, testCase{
7814 testType: serverTest,
7815 name: "SendHelloRetryRequest-2",
7816 config: Config{
7817 MaxVersion: VersionTLS13,
7818 DefaultCurves: []CurveID{CurveP384},
7819 },
7820 // Although the ClientHello did not predict our preferred curve,
7821 // we always select it whether it is predicted or not.
7822 expectedCurveID: CurveX25519,
7823 })
7824
7825 testCases = append(testCases, testCase{
7826 name: "UnknownCurve-HelloRetryRequest",
7827 config: Config{
7828 MaxVersion: VersionTLS13,
7829 // P-384 requires HelloRetryRequest in BoringSSL.
7830 CurvePreferences: []CurveID{CurveP384},
7831 Bugs: ProtocolBugs{
7832 SendHelloRetryRequestCurve: bogusCurve,
7833 },
7834 },
7835 shouldFail: true,
7836 expectedError: ":WRONG_CURVE:",
7837 })
7838
7839 testCases = append(testCases, testCase{
7840 name: "DisabledCurve-HelloRetryRequest",
7841 config: Config{
7842 MaxVersion: VersionTLS13,
7843 CurvePreferences: []CurveID{CurveP256},
7844 Bugs: ProtocolBugs{
7845 IgnorePeerCurvePreferences: true,
7846 },
7847 },
7848 flags: []string{"-p384-only"},
7849 shouldFail: true,
7850 expectedError: ":WRONG_CURVE:",
7851 })
7852
7853 testCases = append(testCases, testCase{
7854 name: "UnnecessaryHelloRetryRequest",
7855 config: Config{
7856 MaxVersion: VersionTLS13,
7857 Bugs: ProtocolBugs{
7858 UnnecessaryHelloRetryRequest: true,
7859 },
7860 },
7861 shouldFail: true,
7862 expectedError: ":WRONG_CURVE:",
7863 })
7864
7865 testCases = append(testCases, testCase{
7866 name: "SecondHelloRetryRequest",
7867 config: Config{
7868 MaxVersion: VersionTLS13,
7869 // P-384 requires HelloRetryRequest in BoringSSL.
7870 CurvePreferences: []CurveID{CurveP384},
7871 Bugs: ProtocolBugs{
7872 SecondHelloRetryRequest: true,
7873 },
7874 },
7875 shouldFail: true,
7876 expectedError: ":UNEXPECTED_MESSAGE:",
7877 })
7878
7879 testCases = append(testCases, testCase{
7880 testType: serverTest,
7881 name: "SecondClientHelloMissingKeyShare",
7882 config: Config{
7883 MaxVersion: VersionTLS13,
7884 DefaultCurves: []CurveID{},
7885 Bugs: ProtocolBugs{
7886 SecondClientHelloMissingKeyShare: true,
7887 },
7888 },
7889 shouldFail: true,
7890 expectedError: ":MISSING_KEY_SHARE:",
7891 })
7892
7893 testCases = append(testCases, testCase{
7894 testType: serverTest,
7895 name: "SecondClientHelloWrongCurve",
7896 config: Config{
7897 MaxVersion: VersionTLS13,
7898 DefaultCurves: []CurveID{},
7899 Bugs: ProtocolBugs{
7900 MisinterpretHelloRetryRequestCurve: CurveP521,
7901 },
7902 },
7903 shouldFail: true,
7904 expectedError: ":WRONG_CURVE:",
7905 })
7906
7907 testCases = append(testCases, testCase{
7908 name: "HelloRetryRequestVersionMismatch",
7909 config: Config{
7910 MaxVersion: VersionTLS13,
7911 // P-384 requires HelloRetryRequest in BoringSSL.
7912 CurvePreferences: []CurveID{CurveP384},
7913 Bugs: ProtocolBugs{
7914 SendServerHelloVersion: 0x0305,
7915 },
7916 },
7917 shouldFail: true,
7918 expectedError: ":WRONG_VERSION_NUMBER:",
7919 })
7920
7921 testCases = append(testCases, testCase{
7922 name: "HelloRetryRequestCurveMismatch",
7923 config: Config{
7924 MaxVersion: VersionTLS13,
7925 // P-384 requires HelloRetryRequest in BoringSSL.
7926 CurvePreferences: []CurveID{CurveP384},
7927 Bugs: ProtocolBugs{
7928 // Send P-384 (correct) in the HelloRetryRequest.
7929 SendHelloRetryRequestCurve: CurveP384,
7930 // But send P-256 in the ServerHello.
7931 SendCurve: CurveP256,
7932 },
7933 },
7934 shouldFail: true,
7935 expectedError: ":WRONG_CURVE:",
7936 })
7937
7938 // Test the server selecting a curve that requires a HelloRetryRequest
7939 // without sending it.
7940 testCases = append(testCases, testCase{
7941 name: "SkipHelloRetryRequest",
7942 config: Config{
7943 MaxVersion: VersionTLS13,
7944 // P-384 requires HelloRetryRequest in BoringSSL.
7945 CurvePreferences: []CurveID{CurveP384},
7946 Bugs: ProtocolBugs{
7947 SkipHelloRetryRequest: true,
7948 },
7949 },
7950 shouldFail: true,
7951 expectedError: ":WRONG_CURVE:",
7952 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007953}
7954
Adam Langley7c803a62015-06-15 15:35:05 -07007955func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007956 defer wg.Done()
7957
7958 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007959 var err error
7960
7961 if *mallocTest < 0 {
7962 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007963 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007964 } else {
7965 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7966 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007967 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007968 if err != nil {
7969 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7970 }
7971 break
7972 }
7973 }
7974 }
Adam Langley95c29f32014-06-20 12:00:00 -07007975 statusChan <- statusMsg{test: test, err: err}
7976 }
7977}
7978
7979type statusMsg struct {
7980 test *testCase
7981 started bool
7982 err error
7983}
7984
David Benjamin5f237bc2015-02-11 17:14:15 -05007985func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02007986 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07007987
David Benjamin5f237bc2015-02-11 17:14:15 -05007988 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07007989 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05007990 if !*pipe {
7991 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05007992 var erase string
7993 for i := 0; i < lineLen; i++ {
7994 erase += "\b \b"
7995 }
7996 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05007997 }
7998
Adam Langley95c29f32014-06-20 12:00:00 -07007999 if msg.started {
8000 started++
8001 } else {
8002 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008003
8004 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008005 if msg.err == errUnimplemented {
8006 if *pipe {
8007 // Print each test instead of a status line.
8008 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8009 }
8010 unimplemented++
8011 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8012 } else {
8013 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8014 failed++
8015 testOutput.addResult(msg.test.name, "FAIL")
8016 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008017 } else {
8018 if *pipe {
8019 // Print each test instead of a status line.
8020 fmt.Printf("PASSED (%s)\n", msg.test.name)
8021 }
8022 testOutput.addResult(msg.test.name, "PASS")
8023 }
Adam Langley95c29f32014-06-20 12:00:00 -07008024 }
8025
David Benjamin5f237bc2015-02-11 17:14:15 -05008026 if !*pipe {
8027 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008028 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008029 lineLen = len(line)
8030 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008031 }
Adam Langley95c29f32014-06-20 12:00:00 -07008032 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008033
8034 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008035}
8036
8037func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008038 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008039 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008040 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008041
Adam Langley7c803a62015-06-15 15:35:05 -07008042 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008043 addCipherSuiteTests()
8044 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008045 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008046 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008047 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008048 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008049 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008050 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008051 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008052 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008053 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008054 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008055 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008056 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008057 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008058 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008059 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008060 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008061 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008062 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008063 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05008064 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008065 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008066 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008067 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008068 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008069 addTLS13WrongMessageTypeTests()
8070 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008071
8072 var wg sync.WaitGroup
8073
Adam Langley7c803a62015-06-15 15:35:05 -07008074 statusChan := make(chan statusMsg, *numWorkers)
8075 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008076 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008077
EKRf71d7ed2016-08-06 13:25:12 -07008078 if len(*shimConfigFile) != 0 {
8079 encoded, err := ioutil.ReadFile(*shimConfigFile)
8080 if err != nil {
8081 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8082 os.Exit(1)
8083 }
8084
8085 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8086 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8087 os.Exit(1)
8088 }
8089 }
8090
David Benjamin025b3d32014-07-01 19:53:04 -04008091 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008092
Adam Langley7c803a62015-06-15 15:35:05 -07008093 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008094 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008095 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008096 }
8097
David Benjamin270f0a72016-03-17 14:41:36 -04008098 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008099 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008100 matched := true
8101 if len(*testToRun) != 0 {
8102 var err error
8103 matched, err = filepath.Match(*testToRun, testCases[i].name)
8104 if err != nil {
8105 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8106 os.Exit(1)
8107 }
8108 }
8109
EKRf71d7ed2016-08-06 13:25:12 -07008110 if !*includeDisabled {
8111 for pattern := range shimConfig.DisabledTests {
8112 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8113 if err != nil {
8114 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8115 os.Exit(1)
8116 }
8117
8118 if isDisabled {
8119 matched = false
8120 break
8121 }
8122 }
8123 }
8124
David Benjamin17e12922016-07-28 18:04:43 -04008125 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008126 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008127 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008128 }
8129 }
David Benjamin17e12922016-07-28 18:04:43 -04008130
David Benjamin270f0a72016-03-17 14:41:36 -04008131 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008132 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008133 os.Exit(1)
8134 }
Adam Langley95c29f32014-06-20 12:00:00 -07008135
8136 close(testChan)
8137 wg.Wait()
8138 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008139 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008140
8141 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008142
8143 if *jsonOutput != "" {
8144 if err := testOutput.writeTo(*jsonOutput); err != nil {
8145 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8146 }
8147 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008148
EKR842ae6c2016-07-27 09:22:05 +02008149 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8150 os.Exit(1)
8151 }
8152
8153 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008154 os.Exit(1)
8155 }
Adam Langley95c29f32014-06-20 12:00:00 -07008156}