blob: 45d3e1393e556788f2960ceeb0ce63e9f138d000 [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 Benjamin881f1962016-08-10 18:29:12 -04002272 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2273 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2274 // for now.
2275 flags = append(flags, "-cipher", suite.name)
2276 }
David Benjamin48cae082014-10-27 01:06:24 -04002277
Adam Langley95c29f32014-06-20 12:00:00 -07002278 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002279 for _, protocol := range []protocol{tls, dtls} {
2280 var prefix string
2281 if protocol == dtls {
2282 if !ver.hasDTLS {
2283 continue
2284 }
2285 prefix = "D"
2286 }
Adam Langley95c29f32014-06-20 12:00:00 -07002287
David Benjamin0407e762016-06-17 16:41:18 -04002288 var shouldServerFail, shouldClientFail bool
2289 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2290 // BoringSSL clients accept ECDHE on SSLv3, but
2291 // a BoringSSL server will never select it
2292 // because the extension is missing.
2293 shouldServerFail = true
2294 }
2295 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2296 shouldClientFail = true
2297 shouldServerFail = true
2298 }
David Benjamin54c217c2016-07-13 12:35:25 -04002299 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002300 shouldClientFail = true
2301 shouldServerFail = true
2302 }
David Benjamin0407e762016-06-17 16:41:18 -04002303 if !isDTLSCipher(suite.name) && protocol == dtls {
2304 shouldClientFail = true
2305 shouldServerFail = true
2306 }
David Benjamin4298d772015-12-19 00:18:25 -05002307
David Benjamin0407e762016-06-17 16:41:18 -04002308 var expectedServerError, expectedClientError string
2309 if shouldServerFail {
2310 expectedServerError = ":NO_SHARED_CIPHER:"
2311 }
2312 if shouldClientFail {
2313 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2314 }
David Benjamin025b3d32014-07-01 19:53:04 -04002315
David Benjamin9deb1172016-07-13 17:13:49 -04002316 // TODO(davidben,svaldez): Implement resumption for TLS 1.3.
2317 resumeSession := ver.version < VersionTLS13
2318
David Benjamin6fd297b2014-08-11 18:43:38 -04002319 testCases = append(testCases, testCase{
2320 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002321 protocol: protocol,
2322
2323 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002324 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002325 MinVersion: ver.version,
2326 MaxVersion: ver.version,
2327 CipherSuites: []uint16{suite.id},
2328 Certificates: []Certificate{cert},
2329 PreSharedKey: []byte(psk),
2330 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002331 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002332 EnableAllCiphers: shouldServerFail,
2333 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002334 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002335 },
2336 certFile: certFile,
2337 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002338 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002339 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002340 shouldFail: shouldServerFail,
2341 expectedError: expectedServerError,
2342 })
2343
2344 testCases = append(testCases, testCase{
2345 testType: clientTest,
2346 protocol: protocol,
2347 name: prefix + ver.name + "-" + suite.name + "-client",
2348 config: Config{
2349 MinVersion: ver.version,
2350 MaxVersion: ver.version,
2351 CipherSuites: []uint16{suite.id},
2352 Certificates: []Certificate{cert},
2353 PreSharedKey: []byte(psk),
2354 PreSharedKeyIdentity: pskIdentity,
2355 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002356 EnableAllCiphers: shouldClientFail,
2357 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002358 },
2359 },
2360 flags: flags,
David Benjamin9deb1172016-07-13 17:13:49 -04002361 resumeSession: resumeSession,
David Benjamin0407e762016-06-17 16:41:18 -04002362 shouldFail: shouldClientFail,
2363 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002364 })
David Benjamin2c99d282015-09-01 10:23:00 -04002365
Nick Harper1fd39d82016-06-14 18:14:35 -07002366 if !shouldClientFail {
2367 // Ensure the maximum record size is accepted.
2368 testCases = append(testCases, testCase{
2369 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2370 config: Config{
2371 MinVersion: ver.version,
2372 MaxVersion: ver.version,
2373 CipherSuites: []uint16{suite.id},
2374 Certificates: []Certificate{cert},
2375 PreSharedKey: []byte(psk),
2376 PreSharedKeyIdentity: pskIdentity,
2377 },
2378 flags: flags,
2379 messageLen: maxPlaintext,
2380 })
2381 }
2382 }
David Benjamin2c99d282015-09-01 10:23:00 -04002383 }
Adam Langley95c29f32014-06-20 12:00:00 -07002384 }
Adam Langleya7997f12015-05-14 17:38:50 -07002385
2386 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002387 name: "NoSharedCipher",
2388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002389 MaxVersion: VersionTLS12,
2390 CipherSuites: []uint16{},
2391 },
2392 shouldFail: true,
2393 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2394 })
2395
2396 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002397 name: "NoSharedCipher-TLS13",
2398 config: Config{
2399 MaxVersion: VersionTLS13,
2400 CipherSuites: []uint16{},
2401 },
2402 shouldFail: true,
2403 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2404 })
2405
2406 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002407 name: "UnsupportedCipherSuite",
2408 config: Config{
2409 MaxVersion: VersionTLS12,
2410 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2411 Bugs: ProtocolBugs{
2412 IgnorePeerCipherPreferences: true,
2413 },
2414 },
2415 flags: []string{"-cipher", "DEFAULT:!RC4"},
2416 shouldFail: true,
2417 expectedError: ":WRONG_CIPHER_RETURNED:",
2418 })
2419
2420 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002421 name: "ServerHelloBogusCipher",
2422 config: Config{
2423 MaxVersion: VersionTLS12,
2424 Bugs: ProtocolBugs{
2425 SendCipherSuite: bogusCipher,
2426 },
2427 },
2428 shouldFail: true,
2429 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2430 })
2431 testCases = append(testCases, testCase{
2432 name: "ServerHelloBogusCipher-TLS13",
2433 config: Config{
2434 MaxVersion: VersionTLS13,
2435 Bugs: ProtocolBugs{
2436 SendCipherSuite: bogusCipher,
2437 },
2438 },
2439 shouldFail: true,
2440 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2441 })
2442
2443 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002444 name: "WeakDH",
2445 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002446 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002447 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2448 Bugs: ProtocolBugs{
2449 // This is a 1023-bit prime number, generated
2450 // with:
2451 // openssl gendh 1023 | openssl asn1parse -i
2452 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2453 },
2454 },
2455 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002456 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002457 })
Adam Langleycef75832015-09-03 14:51:12 -07002458
David Benjamincd24a392015-11-11 13:23:05 -08002459 testCases = append(testCases, testCase{
2460 name: "SillyDH",
2461 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002462 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002463 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2464 Bugs: ProtocolBugs{
2465 // This is a 4097-bit prime number, generated
2466 // with:
2467 // openssl gendh 4097 | openssl asn1parse -i
2468 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2469 },
2470 },
2471 shouldFail: true,
2472 expectedError: ":DH_P_TOO_LONG:",
2473 })
2474
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002475 // This test ensures that Diffie-Hellman public values are padded with
2476 // zeros so that they're the same length as the prime. This is to avoid
2477 // hitting a bug in yaSSL.
2478 testCases = append(testCases, testCase{
2479 testType: serverTest,
2480 name: "DHPublicValuePadded",
2481 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002482 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002483 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2484 Bugs: ProtocolBugs{
2485 RequireDHPublicValueLen: (1025 + 7) / 8,
2486 },
2487 },
2488 flags: []string{"-use-sparse-dh-prime"},
2489 })
David Benjamincd24a392015-11-11 13:23:05 -08002490
David Benjamin241ae832016-01-15 03:04:54 -05002491 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002492 testCases = append(testCases, testCase{
2493 testType: serverTest,
2494 name: "UnknownCipher",
2495 config: Config{
2496 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2497 },
2498 })
2499
Adam Langleycef75832015-09-03 14:51:12 -07002500 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2501 // 1.1 specific cipher suite settings. A server is setup with the given
2502 // cipher lists and then a connection is made for each member of
2503 // expectations. The cipher suite that the server selects must match
2504 // the specified one.
2505 var versionSpecificCiphersTest = []struct {
2506 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2507 // expectations is a map from TLS version to cipher suite id.
2508 expectations map[uint16]uint16
2509 }{
2510 {
2511 // Test that the null case (where no version-specific ciphers are set)
2512 // works as expected.
2513 "RC4-SHA:AES128-SHA", // default ciphers
2514 "", // no ciphers specifically for TLS ≥ 1.0
2515 "", // no ciphers specifically for TLS ≥ 1.1
2516 map[uint16]uint16{
2517 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2518 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2519 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2520 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2521 },
2522 },
2523 {
2524 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2525 // cipher.
2526 "RC4-SHA:AES128-SHA", // default
2527 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2528 "", // no ciphers specifically for TLS ≥ 1.1
2529 map[uint16]uint16{
2530 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2531 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2532 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2533 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2534 },
2535 },
2536 {
2537 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2538 // cipher.
2539 "RC4-SHA:AES128-SHA", // default
2540 "", // no ciphers specifically for TLS ≥ 1.0
2541 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2542 map[uint16]uint16{
2543 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2544 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2545 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2546 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2547 },
2548 },
2549 {
2550 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2551 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2552 "RC4-SHA:AES128-SHA", // default
2553 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2554 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2555 map[uint16]uint16{
2556 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2557 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2558 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2559 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2560 },
2561 },
2562 }
2563
2564 for i, test := range versionSpecificCiphersTest {
2565 for version, expectedCipherSuite := range test.expectations {
2566 flags := []string{"-cipher", test.ciphersDefault}
2567 if len(test.ciphersTLS10) > 0 {
2568 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2569 }
2570 if len(test.ciphersTLS11) > 0 {
2571 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2572 }
2573
2574 testCases = append(testCases, testCase{
2575 testType: serverTest,
2576 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2577 config: Config{
2578 MaxVersion: version,
2579 MinVersion: version,
2580 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2581 },
2582 flags: flags,
2583 expectedCipher: expectedCipherSuite,
2584 })
2585 }
2586 }
Adam Langley95c29f32014-06-20 12:00:00 -07002587}
2588
2589func addBadECDSASignatureTests() {
2590 for badR := BadValue(1); badR < NumBadValues; badR++ {
2591 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002592 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002593 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2594 config: Config{
2595 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002596 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002597 Bugs: ProtocolBugs{
2598 BadECDSAR: badR,
2599 BadECDSAS: badS,
2600 },
2601 },
2602 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002603 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002604 })
2605 }
2606 }
2607}
2608
Adam Langley80842bd2014-06-20 12:00:00 -07002609func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002610 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002611 name: "MaxCBCPadding",
2612 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002613 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002614 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2615 Bugs: ProtocolBugs{
2616 MaxPadding: true,
2617 },
2618 },
2619 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2620 })
David Benjamin025b3d32014-07-01 19:53:04 -04002621 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002622 name: "BadCBCPadding",
2623 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002624 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2626 Bugs: ProtocolBugs{
2627 PaddingFirstByteBad: true,
2628 },
2629 },
2630 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002631 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002632 })
2633 // OpenSSL previously had an issue where the first byte of padding in
2634 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002635 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002636 name: "BadCBCPadding255",
2637 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002638 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002639 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2640 Bugs: ProtocolBugs{
2641 MaxPadding: true,
2642 PaddingFirstByteBadIf255: true,
2643 },
2644 },
2645 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2646 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002647 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002648 })
2649}
2650
Kenny Root7fdeaf12014-08-05 15:23:37 -07002651func addCBCSplittingTests() {
2652 testCases = append(testCases, testCase{
2653 name: "CBCRecordSplitting",
2654 config: Config{
2655 MaxVersion: VersionTLS10,
2656 MinVersion: VersionTLS10,
2657 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2658 },
David Benjaminac8302a2015-09-01 17:18:15 -04002659 messageLen: -1, // read until EOF
2660 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002661 flags: []string{
2662 "-async",
2663 "-write-different-record-sizes",
2664 "-cbc-record-splitting",
2665 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002666 })
2667 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002668 name: "CBCRecordSplittingPartialWrite",
2669 config: Config{
2670 MaxVersion: VersionTLS10,
2671 MinVersion: VersionTLS10,
2672 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2673 },
2674 messageLen: -1, // read until EOF
2675 flags: []string{
2676 "-async",
2677 "-write-different-record-sizes",
2678 "-cbc-record-splitting",
2679 "-partial-write",
2680 },
2681 })
2682}
2683
David Benjamin636293b2014-07-08 17:59:18 -04002684func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002685 // Add a dummy cert pool to stress certificate authority parsing.
2686 // TODO(davidben): Add tests that those values parse out correctly.
2687 certPool := x509.NewCertPool()
2688 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2689 if err != nil {
2690 panic(err)
2691 }
2692 certPool.AddCert(cert)
2693
David Benjamin636293b2014-07-08 17:59:18 -04002694 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002695 testCases = append(testCases, testCase{
2696 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002697 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002698 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002699 MinVersion: ver.version,
2700 MaxVersion: ver.version,
2701 ClientAuth: RequireAnyClientCert,
2702 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002703 },
2704 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002705 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2706 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002707 },
2708 })
2709 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002710 testType: serverTest,
2711 name: ver.name + "-Server-ClientAuth-RSA",
2712 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002713 MinVersion: ver.version,
2714 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002715 Certificates: []Certificate{rsaCertificate},
2716 },
2717 flags: []string{"-require-any-client-certificate"},
2718 })
David Benjamine098ec22014-08-27 23:13:20 -04002719 if ver.version != VersionSSL30 {
2720 testCases = append(testCases, testCase{
2721 testType: serverTest,
2722 name: ver.name + "-Server-ClientAuth-ECDSA",
2723 config: Config{
2724 MinVersion: ver.version,
2725 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002726 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002727 },
2728 flags: []string{"-require-any-client-certificate"},
2729 })
2730 testCases = append(testCases, testCase{
2731 testType: clientTest,
2732 name: ver.name + "-Client-ClientAuth-ECDSA",
2733 config: Config{
2734 MinVersion: ver.version,
2735 MaxVersion: ver.version,
2736 ClientAuth: RequireAnyClientCert,
2737 ClientCAs: certPool,
2738 },
2739 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002740 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2741 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002742 },
2743 })
2744 }
David Benjamin636293b2014-07-08 17:59:18 -04002745 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002746
2747 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002748 name: "NoClientCertificate",
2749 config: Config{
2750 MaxVersion: VersionTLS12,
2751 ClientAuth: RequireAnyClientCert,
2752 },
2753 shouldFail: true,
2754 expectedLocalError: "client didn't provide a certificate",
2755 })
2756
2757 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002758 name: "NoClientCertificate-TLS13",
2759 config: Config{
2760 MaxVersion: VersionTLS13,
2761 ClientAuth: RequireAnyClientCert,
2762 },
2763 shouldFail: true,
2764 expectedLocalError: "client didn't provide a certificate",
2765 })
2766
2767 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002768 testType: serverTest,
2769 name: "RequireAnyClientCertificate",
2770 config: Config{
2771 MaxVersion: VersionTLS12,
2772 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002773 flags: []string{"-require-any-client-certificate"},
2774 shouldFail: true,
2775 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2776 })
2777
2778 testCases = append(testCases, testCase{
2779 testType: serverTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04002780 name: "RequireAnyClientCertificate-TLS13",
2781 config: Config{
2782 MaxVersion: VersionTLS13,
2783 },
2784 flags: []string{"-require-any-client-certificate"},
2785 shouldFail: true,
2786 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2787 })
2788
2789 testCases = append(testCases, testCase{
2790 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002791 name: "RequireAnyClientCertificate-SSL3",
2792 config: Config{
2793 MaxVersion: VersionSSL30,
2794 },
2795 flags: []string{"-require-any-client-certificate"},
2796 shouldFail: true,
2797 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2798 })
2799
2800 testCases = append(testCases, testCase{
2801 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002802 name: "SkipClientCertificate",
2803 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002804 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002805 Bugs: ProtocolBugs{
2806 SkipClientCertificate: true,
2807 },
2808 },
2809 // Setting SSL_VERIFY_PEER allows anonymous clients.
2810 flags: []string{"-verify-peer"},
2811 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002812 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002813 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002814
Steven Valdez143e8b32016-07-11 13:19:03 -04002815 testCases = append(testCases, testCase{
2816 testType: serverTest,
2817 name: "SkipClientCertificate-TLS13",
2818 config: Config{
2819 MaxVersion: VersionTLS13,
2820 Bugs: ProtocolBugs{
2821 SkipClientCertificate: true,
2822 },
2823 },
2824 // Setting SSL_VERIFY_PEER allows anonymous clients.
2825 flags: []string{"-verify-peer"},
2826 shouldFail: true,
2827 expectedError: ":UNEXPECTED_MESSAGE:",
2828 })
2829
David Benjaminc032dfa2016-05-12 14:54:57 -04002830 // Client auth is only legal in certificate-based ciphers.
2831 testCases = append(testCases, testCase{
2832 testType: clientTest,
2833 name: "ClientAuth-PSK",
2834 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002835 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002836 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2837 PreSharedKey: []byte("secret"),
2838 ClientAuth: RequireAnyClientCert,
2839 },
2840 flags: []string{
2841 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2842 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2843 "-psk", "secret",
2844 },
2845 shouldFail: true,
2846 expectedError: ":UNEXPECTED_MESSAGE:",
2847 })
2848 testCases = append(testCases, testCase{
2849 testType: clientTest,
2850 name: "ClientAuth-ECDHE_PSK",
2851 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002852 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002853 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2854 PreSharedKey: []byte("secret"),
2855 ClientAuth: RequireAnyClientCert,
2856 },
2857 flags: []string{
2858 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2859 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2860 "-psk", "secret",
2861 },
2862 shouldFail: true,
2863 expectedError: ":UNEXPECTED_MESSAGE:",
2864 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002865
2866 // Regression test for a bug where the client CA list, if explicitly
2867 // set to NULL, was mis-encoded.
2868 testCases = append(testCases, testCase{
2869 testType: serverTest,
2870 name: "Null-Client-CA-List",
2871 config: Config{
2872 MaxVersion: VersionTLS12,
2873 Certificates: []Certificate{rsaCertificate},
2874 },
2875 flags: []string{
2876 "-require-any-client-certificate",
2877 "-use-null-client-ca-list",
2878 },
2879 })
David Benjamin636293b2014-07-08 17:59:18 -04002880}
2881
Adam Langley75712922014-10-10 16:23:43 -07002882func addExtendedMasterSecretTests() {
2883 const expectEMSFlag = "-expect-extended-master-secret"
2884
2885 for _, with := range []bool{false, true} {
2886 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002887 if with {
2888 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002889 }
2890
2891 for _, isClient := range []bool{false, true} {
2892 suffix := "-Server"
2893 testType := serverTest
2894 if isClient {
2895 suffix = "-Client"
2896 testType = clientTest
2897 }
2898
2899 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002900 // In TLS 1.3, the extension is irrelevant and
2901 // always reports as enabled.
2902 var flags []string
2903 if with || ver.version >= VersionTLS13 {
2904 flags = []string{expectEMSFlag}
2905 }
2906
Adam Langley75712922014-10-10 16:23:43 -07002907 test := testCase{
2908 testType: testType,
2909 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2910 config: Config{
2911 MinVersion: ver.version,
2912 MaxVersion: ver.version,
2913 Bugs: ProtocolBugs{
2914 NoExtendedMasterSecret: !with,
2915 RequireExtendedMasterSecret: with,
2916 },
2917 },
David Benjamin48cae082014-10-27 01:06:24 -04002918 flags: flags,
2919 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002920 }
2921 if test.shouldFail {
2922 test.expectedLocalError = "extended master secret required but not supported by peer"
2923 }
2924 testCases = append(testCases, test)
2925 }
2926 }
2927 }
2928
Adam Langleyba5934b2015-06-02 10:50:35 -07002929 for _, isClient := range []bool{false, true} {
2930 for _, supportedInFirstConnection := range []bool{false, true} {
2931 for _, supportedInResumeConnection := range []bool{false, true} {
2932 boolToWord := func(b bool) string {
2933 if b {
2934 return "Yes"
2935 }
2936 return "No"
2937 }
2938 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2939 if isClient {
2940 suffix += "Client"
2941 } else {
2942 suffix += "Server"
2943 }
2944
2945 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002946 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002947 Bugs: ProtocolBugs{
2948 RequireExtendedMasterSecret: true,
2949 },
2950 }
2951
2952 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002953 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002954 Bugs: ProtocolBugs{
2955 NoExtendedMasterSecret: true,
2956 },
2957 }
2958
2959 test := testCase{
2960 name: "ExtendedMasterSecret-" + suffix,
2961 resumeSession: true,
2962 }
2963
2964 if !isClient {
2965 test.testType = serverTest
2966 }
2967
2968 if supportedInFirstConnection {
2969 test.config = supportedConfig
2970 } else {
2971 test.config = noSupportConfig
2972 }
2973
2974 if supportedInResumeConnection {
2975 test.resumeConfig = &supportedConfig
2976 } else {
2977 test.resumeConfig = &noSupportConfig
2978 }
2979
2980 switch suffix {
2981 case "YesToYes-Client", "YesToYes-Server":
2982 // When a session is resumed, it should
2983 // still be aware that its master
2984 // secret was generated via EMS and
2985 // thus it's safe to use tls-unique.
2986 test.flags = []string{expectEMSFlag}
2987 case "NoToYes-Server":
2988 // If an original connection did not
2989 // contain EMS, but a resumption
2990 // handshake does, then a server should
2991 // not resume the session.
2992 test.expectResumeRejected = true
2993 case "YesToNo-Server":
2994 // Resuming an EMS session without the
2995 // EMS extension should cause the
2996 // server to abort the connection.
2997 test.shouldFail = true
2998 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2999 case "NoToYes-Client":
3000 // A client should abort a connection
3001 // where the server resumed a non-EMS
3002 // session but echoed the EMS
3003 // extension.
3004 test.shouldFail = true
3005 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3006 case "YesToNo-Client":
3007 // A client should abort a connection
3008 // where the server didn't echo EMS
3009 // when the session used it.
3010 test.shouldFail = true
3011 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3012 }
3013
3014 testCases = append(testCases, test)
3015 }
3016 }
3017 }
Adam Langley75712922014-10-10 16:23:43 -07003018}
3019
David Benjamin582ba042016-07-07 12:33:25 -07003020type stateMachineTestConfig struct {
3021 protocol protocol
3022 async bool
3023 splitHandshake, packHandshakeFlight bool
3024}
3025
David Benjamin43ec06f2014-08-05 02:28:57 -04003026// Adds tests that try to cover the range of the handshake state machine, under
3027// various conditions. Some of these are redundant with other tests, but they
3028// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003029func addAllStateMachineCoverageTests() {
3030 for _, async := range []bool{false, true} {
3031 for _, protocol := range []protocol{tls, dtls} {
3032 addStateMachineCoverageTests(stateMachineTestConfig{
3033 protocol: protocol,
3034 async: async,
3035 })
3036 addStateMachineCoverageTests(stateMachineTestConfig{
3037 protocol: protocol,
3038 async: async,
3039 splitHandshake: true,
3040 })
3041 if protocol == tls {
3042 addStateMachineCoverageTests(stateMachineTestConfig{
3043 protocol: protocol,
3044 async: async,
3045 packHandshakeFlight: true,
3046 })
3047 }
3048 }
3049 }
3050}
3051
3052func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003053 var tests []testCase
3054
3055 // Basic handshake, with resumption. Client and server,
3056 // session ID and session ticket.
3057 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003058 name: "Basic-Client",
3059 config: Config{
3060 MaxVersion: VersionTLS12,
3061 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003062 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003063 // Ensure session tickets are used, not session IDs.
3064 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003065 })
3066 tests = append(tests, testCase{
3067 name: "Basic-Client-RenewTicket",
3068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003069 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003070 Bugs: ProtocolBugs{
3071 RenewTicketOnResume: true,
3072 },
3073 },
David Benjaminba4594a2015-06-18 18:36:15 -04003074 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003075 resumeSession: true,
3076 })
3077 tests = append(tests, testCase{
3078 name: "Basic-Client-NoTicket",
3079 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003080 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003081 SessionTicketsDisabled: true,
3082 },
3083 resumeSession: true,
3084 })
3085 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003086 name: "Basic-Client-Implicit",
3087 config: Config{
3088 MaxVersion: VersionTLS12,
3089 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003090 flags: []string{"-implicit-handshake"},
3091 resumeSession: true,
3092 })
3093 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003094 testType: serverTest,
3095 name: "Basic-Server",
3096 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003097 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003098 Bugs: ProtocolBugs{
3099 RequireSessionTickets: true,
3100 },
3101 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003102 resumeSession: true,
3103 })
3104 tests = append(tests, testCase{
3105 testType: serverTest,
3106 name: "Basic-Server-NoTickets",
3107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003108 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003109 SessionTicketsDisabled: true,
3110 },
3111 resumeSession: true,
3112 })
3113 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 testType: serverTest,
3115 name: "Basic-Server-Implicit",
3116 config: Config{
3117 MaxVersion: VersionTLS12,
3118 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003119 flags: []string{"-implicit-handshake"},
3120 resumeSession: true,
3121 })
3122 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003123 testType: serverTest,
3124 name: "Basic-Server-EarlyCallback",
3125 config: Config{
3126 MaxVersion: VersionTLS12,
3127 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003128 flags: []string{"-use-early-callback"},
3129 resumeSession: true,
3130 })
3131
Steven Valdez143e8b32016-07-11 13:19:03 -04003132 // TLS 1.3 basic handshake shapes.
3133 tests = append(tests, testCase{
3134 name: "TLS13-1RTT-Client",
3135 config: Config{
3136 MaxVersion: VersionTLS13,
3137 },
3138 })
3139 tests = append(tests, testCase{
3140 testType: serverTest,
3141 name: "TLS13-1RTT-Server",
3142 config: Config{
3143 MaxVersion: VersionTLS13,
3144 },
3145 })
3146
David Benjamin760b1dd2015-05-15 23:33:48 -04003147 // TLS client auth.
3148 tests = append(tests, testCase{
3149 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003150 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003152 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003153 ClientAuth: RequestClientCert,
3154 },
3155 })
3156 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003157 testType: serverTest,
3158 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003159 config: Config{
3160 MaxVersion: VersionTLS12,
3161 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003162 // Setting SSL_VERIFY_PEER allows anonymous clients.
3163 flags: []string{"-verify-peer"},
3164 })
David Benjamin582ba042016-07-07 12:33:25 -07003165 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003166 tests = append(tests, testCase{
3167 testType: clientTest,
3168 name: "ClientAuth-NoCertificate-Client-SSL3",
3169 config: Config{
3170 MaxVersion: VersionSSL30,
3171 ClientAuth: RequestClientCert,
3172 },
3173 })
3174 tests = append(tests, testCase{
3175 testType: serverTest,
3176 name: "ClientAuth-NoCertificate-Server-SSL3",
3177 config: Config{
3178 MaxVersion: VersionSSL30,
3179 },
3180 // Setting SSL_VERIFY_PEER allows anonymous clients.
3181 flags: []string{"-verify-peer"},
3182 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003183 tests = append(tests, testCase{
3184 testType: clientTest,
3185 name: "ClientAuth-NoCertificate-Client-TLS13",
3186 config: Config{
3187 MaxVersion: VersionTLS13,
3188 ClientAuth: RequestClientCert,
3189 },
3190 })
3191 tests = append(tests, testCase{
3192 testType: serverTest,
3193 name: "ClientAuth-NoCertificate-Server-TLS13",
3194 config: Config{
3195 MaxVersion: VersionTLS13,
3196 },
3197 // Setting SSL_VERIFY_PEER allows anonymous clients.
3198 flags: []string{"-verify-peer"},
3199 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003200 }
3201 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003202 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003203 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003204 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003205 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003206 ClientAuth: RequireAnyClientCert,
3207 },
3208 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003209 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3210 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003211 },
3212 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003213 tests = append(tests, testCase{
3214 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003215 name: "ClientAuth-RSA-Client-TLS13",
3216 config: Config{
3217 MaxVersion: VersionTLS13,
3218 ClientAuth: RequireAnyClientCert,
3219 },
3220 flags: []string{
3221 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3222 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3223 },
3224 })
3225 tests = append(tests, testCase{
3226 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003227 name: "ClientAuth-ECDSA-Client",
3228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003229 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003230 ClientAuth: RequireAnyClientCert,
3231 },
3232 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003233 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3234 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003235 },
3236 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003237 tests = append(tests, testCase{
3238 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003239 name: "ClientAuth-ECDSA-Client-TLS13",
3240 config: Config{
3241 MaxVersion: VersionTLS13,
3242 ClientAuth: RequireAnyClientCert,
3243 },
3244 flags: []string{
3245 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3246 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3247 },
3248 })
3249 tests = append(tests, testCase{
3250 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003251 name: "ClientAuth-NoCertificate-OldCallback",
3252 config: Config{
3253 MaxVersion: VersionTLS12,
3254 ClientAuth: RequestClientCert,
3255 },
3256 flags: []string{"-use-old-client-cert-callback"},
3257 })
3258 tests = append(tests, testCase{
3259 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003260 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3261 config: Config{
3262 MaxVersion: VersionTLS13,
3263 ClientAuth: RequestClientCert,
3264 },
3265 flags: []string{"-use-old-client-cert-callback"},
3266 })
3267 tests = append(tests, testCase{
3268 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003269 name: "ClientAuth-OldCallback",
3270 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003271 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003272 ClientAuth: RequireAnyClientCert,
3273 },
3274 flags: []string{
3275 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3276 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3277 "-use-old-client-cert-callback",
3278 },
3279 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003280 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003281 testType: clientTest,
3282 name: "ClientAuth-OldCallback-TLS13",
3283 config: Config{
3284 MaxVersion: VersionTLS13,
3285 ClientAuth: RequireAnyClientCert,
3286 },
3287 flags: []string{
3288 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3289 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3290 "-use-old-client-cert-callback",
3291 },
3292 })
3293 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003294 testType: serverTest,
3295 name: "ClientAuth-Server",
3296 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003297 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003298 Certificates: []Certificate{rsaCertificate},
3299 },
3300 flags: []string{"-require-any-client-certificate"},
3301 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003302 tests = append(tests, testCase{
3303 testType: serverTest,
3304 name: "ClientAuth-Server-TLS13",
3305 config: Config{
3306 MaxVersion: VersionTLS13,
3307 Certificates: []Certificate{rsaCertificate},
3308 },
3309 flags: []string{"-require-any-client-certificate"},
3310 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003311
David Benjamin4c3ddf72016-06-29 18:13:53 -04003312 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003313 tests = append(tests, testCase{
3314 testType: serverTest,
3315 name: "Basic-Server-RSA",
3316 config: Config{
3317 MaxVersion: VersionTLS12,
3318 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3319 },
3320 flags: []string{
3321 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3322 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3323 },
3324 })
3325 tests = append(tests, testCase{
3326 testType: serverTest,
3327 name: "Basic-Server-ECDHE-RSA",
3328 config: Config{
3329 MaxVersion: VersionTLS12,
3330 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3331 },
3332 flags: []string{
3333 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3334 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3335 },
3336 })
3337 tests = append(tests, testCase{
3338 testType: serverTest,
3339 name: "Basic-Server-ECDHE-ECDSA",
3340 config: Config{
3341 MaxVersion: VersionTLS12,
3342 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3343 },
3344 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003345 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3346 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003347 },
3348 })
3349
David Benjamin760b1dd2015-05-15 23:33:48 -04003350 // No session ticket support; server doesn't send NewSessionTicket.
3351 tests = append(tests, testCase{
3352 name: "SessionTicketsDisabled-Client",
3353 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003354 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003355 SessionTicketsDisabled: true,
3356 },
3357 })
3358 tests = append(tests, testCase{
3359 testType: serverTest,
3360 name: "SessionTicketsDisabled-Server",
3361 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003362 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003363 SessionTicketsDisabled: true,
3364 },
3365 })
3366
3367 // Skip ServerKeyExchange in PSK key exchange if there's no
3368 // identity hint.
3369 tests = append(tests, testCase{
3370 name: "EmptyPSKHint-Client",
3371 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003372 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003373 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3374 PreSharedKey: []byte("secret"),
3375 },
3376 flags: []string{"-psk", "secret"},
3377 })
3378 tests = append(tests, testCase{
3379 testType: serverTest,
3380 name: "EmptyPSKHint-Server",
3381 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003382 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003383 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3384 PreSharedKey: []byte("secret"),
3385 },
3386 flags: []string{"-psk", "secret"},
3387 })
3388
David Benjamin4c3ddf72016-06-29 18:13:53 -04003389 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003390 tests = append(tests, testCase{
3391 testType: clientTest,
3392 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003393 config: Config{
3394 MaxVersion: VersionTLS12,
3395 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003396 flags: []string{
3397 "-enable-ocsp-stapling",
3398 "-expect-ocsp-response",
3399 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003400 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003401 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003402 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003403 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003404 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003405 testType: serverTest,
3406 name: "OCSPStapling-Server",
3407 config: Config{
3408 MaxVersion: VersionTLS12,
3409 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003410 expectedOCSPResponse: testOCSPResponse,
3411 flags: []string{
3412 "-ocsp-response",
3413 base64.StdEncoding.EncodeToString(testOCSPResponse),
3414 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003415 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003416 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003417 tests = append(tests, testCase{
3418 testType: clientTest,
3419 name: "OCSPStapling-Client-TLS13",
3420 config: Config{
3421 MaxVersion: VersionTLS13,
3422 },
3423 flags: []string{
3424 "-enable-ocsp-stapling",
3425 "-expect-ocsp-response",
3426 base64.StdEncoding.EncodeToString(testOCSPResponse),
3427 "-verify-peer",
3428 },
3429 // TODO(davidben): Enable this when resumption is implemented
3430 // in TLS 1.3.
3431 resumeSession: false,
3432 })
3433 tests = append(tests, testCase{
3434 testType: serverTest,
3435 name: "OCSPStapling-Server-TLS13",
3436 config: Config{
3437 MaxVersion: VersionTLS13,
3438 },
3439 expectedOCSPResponse: testOCSPResponse,
3440 flags: []string{
3441 "-ocsp-response",
3442 base64.StdEncoding.EncodeToString(testOCSPResponse),
3443 },
3444 // TODO(davidben): Enable this when resumption is implemented
3445 // in TLS 1.3.
3446 resumeSession: false,
3447 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003448
David Benjamin4c3ddf72016-06-29 18:13:53 -04003449 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003450 for _, vers := range tlsVersions {
3451 if config.protocol == dtls && !vers.hasDTLS {
3452 continue
3453 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003454 for _, testType := range []testType{clientTest, serverTest} {
3455 suffix := "-Client"
3456 if testType == serverTest {
3457 suffix = "-Server"
3458 }
3459 suffix += "-" + vers.name
3460
3461 flag := "-verify-peer"
3462 if testType == serverTest {
3463 flag = "-require-any-client-certificate"
3464 }
3465
3466 tests = append(tests, testCase{
3467 testType: testType,
3468 name: "CertificateVerificationSucceed" + suffix,
3469 config: Config{
3470 MaxVersion: vers.version,
3471 Certificates: []Certificate{rsaCertificate},
3472 },
3473 flags: []string{
3474 flag,
3475 "-expect-verify-result",
3476 },
3477 // TODO(davidben): Enable this when resumption is
3478 // implemented in TLS 1.3.
3479 resumeSession: vers.version != VersionTLS13,
3480 })
3481 tests = append(tests, testCase{
3482 testType: testType,
3483 name: "CertificateVerificationFail" + suffix,
3484 config: Config{
3485 MaxVersion: vers.version,
3486 Certificates: []Certificate{rsaCertificate},
3487 },
3488 flags: []string{
3489 flag,
3490 "-verify-fail",
3491 },
3492 shouldFail: true,
3493 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3494 })
3495 }
3496
3497 // By default, the client is in a soft fail mode where the peer
3498 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003499 tests = append(tests, testCase{
3500 testType: clientTest,
3501 name: "CertificateVerificationSoftFail-" + vers.name,
3502 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003503 MaxVersion: vers.version,
3504 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003505 },
3506 flags: []string{
3507 "-verify-fail",
3508 "-expect-verify-result",
3509 },
David Benjaminbb9e36e2016-08-03 14:14:47 -04003510 // TODO(davidben): Enable this when resumption is
3511 // implemented in TLS 1.3.
Adam Langley9498e742016-07-18 10:17:16 -07003512 resumeSession: vers.version != VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04003513 })
3514 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003515
David Benjamin1d4f4c02016-07-26 18:03:08 -04003516 tests = append(tests, testCase{
3517 name: "ShimSendAlert",
3518 flags: []string{"-send-alert"},
3519 shimWritesFirst: true,
3520 shouldFail: true,
3521 expectedLocalError: "remote error: decompression failure",
3522 })
3523
David Benjamin582ba042016-07-07 12:33:25 -07003524 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003525 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003526 name: "Renegotiate-Client",
3527 config: Config{
3528 MaxVersion: VersionTLS12,
3529 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003530 renegotiate: 1,
3531 flags: []string{
3532 "-renegotiate-freely",
3533 "-expect-total-renegotiations", "1",
3534 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003535 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003536
David Benjamin47921102016-07-28 11:29:18 -04003537 tests = append(tests, testCase{
3538 name: "SendHalfHelloRequest",
3539 config: Config{
3540 MaxVersion: VersionTLS12,
3541 Bugs: ProtocolBugs{
3542 PackHelloRequestWithFinished: config.packHandshakeFlight,
3543 },
3544 },
3545 sendHalfHelloRequest: true,
3546 flags: []string{"-renegotiate-ignore"},
3547 shouldFail: true,
3548 expectedError: ":UNEXPECTED_RECORD:",
3549 })
3550
David Benjamin760b1dd2015-05-15 23:33:48 -04003551 // NPN on client and server; results in post-handshake message.
3552 tests = append(tests, testCase{
3553 name: "NPN-Client",
3554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003555 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003556 NextProtos: []string{"foo"},
3557 },
3558 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003559 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003560 expectedNextProto: "foo",
3561 expectedNextProtoType: npn,
3562 })
3563 tests = append(tests, testCase{
3564 testType: serverTest,
3565 name: "NPN-Server",
3566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003567 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003568 NextProtos: []string{"bar"},
3569 },
3570 flags: []string{
3571 "-advertise-npn", "\x03foo\x03bar\x03baz",
3572 "-expect-next-proto", "bar",
3573 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003574 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003575 expectedNextProto: "bar",
3576 expectedNextProtoType: npn,
3577 })
3578
3579 // TODO(davidben): Add tests for when False Start doesn't trigger.
3580
3581 // Client does False Start and negotiates NPN.
3582 tests = append(tests, testCase{
3583 name: "FalseStart",
3584 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003585 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003586 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3587 NextProtos: []string{"foo"},
3588 Bugs: ProtocolBugs{
3589 ExpectFalseStart: true,
3590 },
3591 },
3592 flags: []string{
3593 "-false-start",
3594 "-select-next-proto", "foo",
3595 },
3596 shimWritesFirst: true,
3597 resumeSession: true,
3598 })
3599
3600 // Client does False Start and negotiates ALPN.
3601 tests = append(tests, testCase{
3602 name: "FalseStart-ALPN",
3603 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003604 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003605 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3606 NextProtos: []string{"foo"},
3607 Bugs: ProtocolBugs{
3608 ExpectFalseStart: true,
3609 },
3610 },
3611 flags: []string{
3612 "-false-start",
3613 "-advertise-alpn", "\x03foo",
3614 },
3615 shimWritesFirst: true,
3616 resumeSession: true,
3617 })
3618
3619 // Client does False Start but doesn't explicitly call
3620 // SSL_connect.
3621 tests = append(tests, testCase{
3622 name: "FalseStart-Implicit",
3623 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003624 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3626 NextProtos: []string{"foo"},
3627 },
3628 flags: []string{
3629 "-implicit-handshake",
3630 "-false-start",
3631 "-advertise-alpn", "\x03foo",
3632 },
3633 })
3634
3635 // False Start without session tickets.
3636 tests = append(tests, testCase{
3637 name: "FalseStart-SessionTicketsDisabled",
3638 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003639 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003640 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3641 NextProtos: []string{"foo"},
3642 SessionTicketsDisabled: true,
3643 Bugs: ProtocolBugs{
3644 ExpectFalseStart: true,
3645 },
3646 },
3647 flags: []string{
3648 "-false-start",
3649 "-select-next-proto", "foo",
3650 },
3651 shimWritesFirst: true,
3652 })
3653
Adam Langleydf759b52016-07-11 15:24:37 -07003654 tests = append(tests, testCase{
3655 name: "FalseStart-CECPQ1",
3656 config: Config{
3657 MaxVersion: VersionTLS12,
3658 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3659 NextProtos: []string{"foo"},
3660 Bugs: ProtocolBugs{
3661 ExpectFalseStart: true,
3662 },
3663 },
3664 flags: []string{
3665 "-false-start",
3666 "-cipher", "DEFAULT:kCECPQ1",
3667 "-select-next-proto", "foo",
3668 },
3669 shimWritesFirst: true,
3670 resumeSession: true,
3671 })
3672
David Benjamin760b1dd2015-05-15 23:33:48 -04003673 // Server parses a V2ClientHello.
3674 tests = append(tests, testCase{
3675 testType: serverTest,
3676 name: "SendV2ClientHello",
3677 config: Config{
3678 // Choose a cipher suite that does not involve
3679 // elliptic curves, so no extensions are
3680 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003681 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003682 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3683 Bugs: ProtocolBugs{
3684 SendV2ClientHello: true,
3685 },
3686 },
3687 })
3688
3689 // Client sends a Channel ID.
3690 tests = append(tests, testCase{
3691 name: "ChannelID-Client",
3692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003693 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003694 RequestChannelID: true,
3695 },
Adam Langley7c803a62015-06-15 15:35:05 -07003696 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003697 resumeSession: true,
3698 expectChannelID: true,
3699 })
3700
3701 // Server accepts a Channel ID.
3702 tests = append(tests, testCase{
3703 testType: serverTest,
3704 name: "ChannelID-Server",
3705 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003706 MaxVersion: VersionTLS12,
3707 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003708 },
3709 flags: []string{
3710 "-expect-channel-id",
3711 base64.StdEncoding.EncodeToString(channelIDBytes),
3712 },
3713 resumeSession: true,
3714 expectChannelID: true,
3715 })
David Benjamin30789da2015-08-29 22:56:45 -04003716
David Benjaminf8fcdf32016-06-08 15:56:13 -04003717 // Channel ID and NPN at the same time, to ensure their relative
3718 // ordering is correct.
3719 tests = append(tests, testCase{
3720 name: "ChannelID-NPN-Client",
3721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003722 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003723 RequestChannelID: true,
3724 NextProtos: []string{"foo"},
3725 },
3726 flags: []string{
3727 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3728 "-select-next-proto", "foo",
3729 },
3730 resumeSession: true,
3731 expectChannelID: true,
3732 expectedNextProto: "foo",
3733 expectedNextProtoType: npn,
3734 })
3735 tests = append(tests, testCase{
3736 testType: serverTest,
3737 name: "ChannelID-NPN-Server",
3738 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003739 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003740 ChannelID: channelIDKey,
3741 NextProtos: []string{"bar"},
3742 },
3743 flags: []string{
3744 "-expect-channel-id",
3745 base64.StdEncoding.EncodeToString(channelIDBytes),
3746 "-advertise-npn", "\x03foo\x03bar\x03baz",
3747 "-expect-next-proto", "bar",
3748 },
3749 resumeSession: true,
3750 expectChannelID: true,
3751 expectedNextProto: "bar",
3752 expectedNextProtoType: npn,
3753 })
3754
David Benjamin30789da2015-08-29 22:56:45 -04003755 // Bidirectional shutdown with the runner initiating.
3756 tests = append(tests, testCase{
3757 name: "Shutdown-Runner",
3758 config: Config{
3759 Bugs: ProtocolBugs{
3760 ExpectCloseNotify: true,
3761 },
3762 },
3763 flags: []string{"-check-close-notify"},
3764 })
3765
3766 // Bidirectional shutdown with the shim initiating. The runner,
3767 // in the meantime, sends garbage before the close_notify which
3768 // the shim must ignore.
3769 tests = append(tests, testCase{
3770 name: "Shutdown-Shim",
3771 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003772 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003773 Bugs: ProtocolBugs{
3774 ExpectCloseNotify: true,
3775 },
3776 },
3777 shimShutsDown: true,
3778 sendEmptyRecords: 1,
3779 sendWarningAlerts: 1,
3780 flags: []string{"-check-close-notify"},
3781 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003782 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 // TODO(davidben): DTLS 1.3 will want a similar thing for
3784 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003785 tests = append(tests, testCase{
3786 name: "SkipHelloVerifyRequest",
3787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003788 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003789 Bugs: ProtocolBugs{
3790 SkipHelloVerifyRequest: true,
3791 },
3792 },
3793 })
3794 }
3795
David Benjamin760b1dd2015-05-15 23:33:48 -04003796 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003797 test.protocol = config.protocol
3798 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003799 test.name += "-DTLS"
3800 }
David Benjamin582ba042016-07-07 12:33:25 -07003801 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003802 test.name += "-Async"
3803 test.flags = append(test.flags, "-async")
3804 } else {
3805 test.name += "-Sync"
3806 }
David Benjamin582ba042016-07-07 12:33:25 -07003807 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003808 test.name += "-SplitHandshakeRecords"
3809 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003810 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003811 test.config.Bugs.MaxPacketLength = 256
3812 test.flags = append(test.flags, "-mtu", "256")
3813 }
3814 }
David Benjamin582ba042016-07-07 12:33:25 -07003815 if config.packHandshakeFlight {
3816 test.name += "-PackHandshakeFlight"
3817 test.config.Bugs.PackHandshakeFlight = true
3818 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003819 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003820 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003821}
3822
Adam Langley524e7172015-02-20 16:04:00 -08003823func addDDoSCallbackTests() {
3824 // DDoS callback.
Steven Valdez143e8b32016-07-11 13:19:03 -04003825 // TODO(davidben): Implement DDoS resumption tests for TLS 1.3.
Adam Langley524e7172015-02-20 16:04:00 -08003826 for _, resume := range []bool{false, true} {
3827 suffix := "Resume"
3828 if resume {
3829 suffix = "No" + suffix
3830 }
3831
3832 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003833 testType: serverTest,
3834 name: "Server-DDoS-OK-" + suffix,
3835 config: Config{
3836 MaxVersion: VersionTLS12,
3837 },
Adam Langley524e7172015-02-20 16:04:00 -08003838 flags: []string{"-install-ddos-callback"},
3839 resumeSession: resume,
3840 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003841 if !resume {
3842 testCases = append(testCases, testCase{
3843 testType: serverTest,
3844 name: "Server-DDoS-OK-" + suffix + "-TLS13",
3845 config: Config{
3846 MaxVersion: VersionTLS13,
3847 },
3848 flags: []string{"-install-ddos-callback"},
3849 resumeSession: resume,
3850 })
3851 }
Adam Langley524e7172015-02-20 16:04:00 -08003852
3853 failFlag := "-fail-ddos-callback"
3854 if resume {
3855 failFlag = "-fail-second-ddos-callback"
3856 }
3857 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003858 testType: serverTest,
3859 name: "Server-DDoS-Reject-" + suffix,
3860 config: Config{
3861 MaxVersion: VersionTLS12,
3862 },
Adam Langley524e7172015-02-20 16:04:00 -08003863 flags: []string{"-install-ddos-callback", failFlag},
3864 resumeSession: resume,
3865 shouldFail: true,
3866 expectedError: ":CONNECTION_REJECTED:",
3867 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003868 if !resume {
3869 testCases = append(testCases, testCase{
3870 testType: serverTest,
3871 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
3872 config: Config{
3873 MaxVersion: VersionTLS13,
3874 },
3875 flags: []string{"-install-ddos-callback", failFlag},
3876 resumeSession: resume,
3877 shouldFail: true,
3878 expectedError: ":CONNECTION_REJECTED:",
3879 })
3880 }
Adam Langley524e7172015-02-20 16:04:00 -08003881 }
3882}
3883
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003884func addVersionNegotiationTests() {
3885 for i, shimVers := range tlsVersions {
3886 // Assemble flags to disable all newer versions on the shim.
3887 var flags []string
3888 for _, vers := range tlsVersions[i+1:] {
3889 flags = append(flags, vers.flag)
3890 }
3891
3892 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003893 protocols := []protocol{tls}
3894 if runnerVers.hasDTLS && shimVers.hasDTLS {
3895 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003896 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003897 for _, protocol := range protocols {
3898 expectedVersion := shimVers.version
3899 if runnerVers.version < shimVers.version {
3900 expectedVersion = runnerVers.version
3901 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003902
David Benjamin8b8c0062014-11-23 02:47:52 -05003903 suffix := shimVers.name + "-" + runnerVers.name
3904 if protocol == dtls {
3905 suffix += "-DTLS"
3906 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003907
David Benjamin1eb367c2014-12-12 18:17:51 -05003908 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3909
David Benjamin1e29a6b2014-12-10 02:27:24 -05003910 clientVers := shimVers.version
3911 if clientVers > VersionTLS10 {
3912 clientVers = VersionTLS10
3913 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003914 serverVers := expectedVersion
3915 if expectedVersion >= VersionTLS13 {
3916 serverVers = VersionTLS10
3917 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003918 testCases = append(testCases, testCase{
3919 protocol: protocol,
3920 testType: clientTest,
3921 name: "VersionNegotiation-Client-" + suffix,
3922 config: Config{
3923 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003924 Bugs: ProtocolBugs{
3925 ExpectInitialRecordVersion: clientVers,
3926 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003927 },
3928 flags: flags,
3929 expectedVersion: expectedVersion,
3930 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003931 testCases = append(testCases, testCase{
3932 protocol: protocol,
3933 testType: clientTest,
3934 name: "VersionNegotiation-Client2-" + suffix,
3935 config: Config{
3936 MaxVersion: runnerVers.version,
3937 Bugs: ProtocolBugs{
3938 ExpectInitialRecordVersion: clientVers,
3939 },
3940 },
3941 flags: []string{"-max-version", shimVersFlag},
3942 expectedVersion: expectedVersion,
3943 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003944
3945 testCases = append(testCases, testCase{
3946 protocol: protocol,
3947 testType: serverTest,
3948 name: "VersionNegotiation-Server-" + suffix,
3949 config: Config{
3950 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003951 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003952 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003953 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003954 },
3955 flags: flags,
3956 expectedVersion: expectedVersion,
3957 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003958 testCases = append(testCases, testCase{
3959 protocol: protocol,
3960 testType: serverTest,
3961 name: "VersionNegotiation-Server2-" + suffix,
3962 config: Config{
3963 MaxVersion: runnerVers.version,
3964 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003965 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003966 },
3967 },
3968 flags: []string{"-max-version", shimVersFlag},
3969 expectedVersion: expectedVersion,
3970 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003971 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003972 }
3973 }
David Benjamin95c69562016-06-29 18:15:03 -04003974
3975 // Test for version tolerance.
3976 testCases = append(testCases, testCase{
3977 testType: serverTest,
3978 name: "MinorVersionTolerance",
3979 config: Config{
3980 Bugs: ProtocolBugs{
3981 SendClientVersion: 0x03ff,
3982 },
3983 },
3984 expectedVersion: VersionTLS13,
3985 })
3986 testCases = append(testCases, testCase{
3987 testType: serverTest,
3988 name: "MajorVersionTolerance",
3989 config: Config{
3990 Bugs: ProtocolBugs{
3991 SendClientVersion: 0x0400,
3992 },
3993 },
3994 expectedVersion: VersionTLS13,
3995 })
3996 testCases = append(testCases, testCase{
3997 protocol: dtls,
3998 testType: serverTest,
3999 name: "MinorVersionTolerance-DTLS",
4000 config: Config{
4001 Bugs: ProtocolBugs{
4002 SendClientVersion: 0x03ff,
4003 },
4004 },
4005 expectedVersion: VersionTLS12,
4006 })
4007 testCases = append(testCases, testCase{
4008 protocol: dtls,
4009 testType: serverTest,
4010 name: "MajorVersionTolerance-DTLS",
4011 config: Config{
4012 Bugs: ProtocolBugs{
4013 SendClientVersion: 0x0400,
4014 },
4015 },
4016 expectedVersion: VersionTLS12,
4017 })
4018
4019 // Test that versions below 3.0 are rejected.
4020 testCases = append(testCases, testCase{
4021 testType: serverTest,
4022 name: "VersionTooLow",
4023 config: Config{
4024 Bugs: ProtocolBugs{
4025 SendClientVersion: 0x0200,
4026 },
4027 },
4028 shouldFail: true,
4029 expectedError: ":UNSUPPORTED_PROTOCOL:",
4030 })
4031 testCases = append(testCases, testCase{
4032 protocol: dtls,
4033 testType: serverTest,
4034 name: "VersionTooLow-DTLS",
4035 config: Config{
4036 Bugs: ProtocolBugs{
4037 // 0x0201 is the lowest version expressable in
4038 // DTLS.
4039 SendClientVersion: 0x0201,
4040 },
4041 },
4042 shouldFail: true,
4043 expectedError: ":UNSUPPORTED_PROTOCOL:",
4044 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004045
4046 // Test TLS 1.3's downgrade signal.
4047 testCases = append(testCases, testCase{
4048 name: "Downgrade-TLS12-Client",
4049 config: Config{
4050 Bugs: ProtocolBugs{
4051 NegotiateVersion: VersionTLS12,
4052 },
4053 },
4054 shouldFail: true,
4055 expectedError: ":DOWNGRADE_DETECTED:",
4056 })
4057 testCases = append(testCases, testCase{
4058 testType: serverTest,
4059 name: "Downgrade-TLS12-Server",
4060 config: Config{
4061 Bugs: ProtocolBugs{
4062 SendClientVersion: VersionTLS12,
4063 },
4064 },
4065 shouldFail: true,
4066 expectedLocalError: "tls: downgrade from TLS 1.3 detected",
4067 })
David Benjamin5e7e7cc2016-07-21 12:55:28 +02004068
4069 // Test that FALLBACK_SCSV is sent and that the downgrade signal works
4070 // behave correctly when both real maximum and fallback versions are
4071 // set.
4072 testCases = append(testCases, testCase{
4073 name: "Downgrade-TLS12-Client-Fallback",
4074 config: Config{
4075 Bugs: ProtocolBugs{
4076 FailIfNotFallbackSCSV: true,
4077 },
4078 },
4079 flags: []string{
4080 "-max-version", strconv.Itoa(VersionTLS13),
4081 "-fallback-version", strconv.Itoa(VersionTLS12),
4082 },
4083 shouldFail: true,
4084 expectedError: ":DOWNGRADE_DETECTED:",
4085 })
4086 testCases = append(testCases, testCase{
4087 name: "Downgrade-TLS12-Client-FallbackEqualsMax",
4088 flags: []string{
4089 "-max-version", strconv.Itoa(VersionTLS12),
4090 "-fallback-version", strconv.Itoa(VersionTLS12),
4091 },
4092 })
4093
4094 // On TLS 1.2 fallback, 1.3 ServerHellos are forbidden. (We would rather
4095 // just have such connections fail than risk getting confused because we
4096 // didn't sent the 1.3 ClientHello.)
4097 testCases = append(testCases, testCase{
4098 name: "Downgrade-TLS12-Fallback-CheckVersion",
4099 config: Config{
4100 Bugs: ProtocolBugs{
4101 NegotiateVersion: VersionTLS13,
4102 FailIfNotFallbackSCSV: true,
4103 },
4104 },
4105 flags: []string{
4106 "-max-version", strconv.Itoa(VersionTLS13),
4107 "-fallback-version", strconv.Itoa(VersionTLS12),
4108 },
4109 shouldFail: true,
4110 expectedError: ":UNSUPPORTED_PROTOCOL:",
4111 })
4112
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004113}
4114
David Benjaminaccb4542014-12-12 23:44:33 -05004115func addMinimumVersionTests() {
4116 for i, shimVers := range tlsVersions {
4117 // Assemble flags to disable all older versions on the shim.
4118 var flags []string
4119 for _, vers := range tlsVersions[:i] {
4120 flags = append(flags, vers.flag)
4121 }
4122
4123 for _, runnerVers := range tlsVersions {
4124 protocols := []protocol{tls}
4125 if runnerVers.hasDTLS && shimVers.hasDTLS {
4126 protocols = append(protocols, dtls)
4127 }
4128 for _, protocol := range protocols {
4129 suffix := shimVers.name + "-" + runnerVers.name
4130 if protocol == dtls {
4131 suffix += "-DTLS"
4132 }
4133 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4134
David Benjaminaccb4542014-12-12 23:44:33 -05004135 var expectedVersion uint16
4136 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004137 var expectedClientError, expectedServerError string
4138 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004139 if runnerVers.version >= shimVers.version {
4140 expectedVersion = runnerVers.version
4141 } else {
4142 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004143 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4144 expectedServerLocalError = "remote error: protocol version not supported"
4145 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4146 // If the client's minimum version is TLS 1.3 and the runner's
4147 // maximum is below TLS 1.2, the runner will fail to select a
4148 // cipher before the shim rejects the selected version.
4149 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4150 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4151 } else {
4152 expectedClientError = expectedServerError
4153 expectedClientLocalError = expectedServerLocalError
4154 }
David Benjaminaccb4542014-12-12 23:44:33 -05004155 }
4156
4157 testCases = append(testCases, testCase{
4158 protocol: protocol,
4159 testType: clientTest,
4160 name: "MinimumVersion-Client-" + suffix,
4161 config: Config{
4162 MaxVersion: runnerVers.version,
4163 },
David Benjamin87909c02014-12-13 01:55:01 -05004164 flags: flags,
4165 expectedVersion: expectedVersion,
4166 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004167 expectedError: expectedClientError,
4168 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004169 })
4170 testCases = append(testCases, testCase{
4171 protocol: protocol,
4172 testType: clientTest,
4173 name: "MinimumVersion-Client2-" + suffix,
4174 config: Config{
4175 MaxVersion: runnerVers.version,
4176 },
David Benjamin87909c02014-12-13 01:55:01 -05004177 flags: []string{"-min-version", shimVersFlag},
4178 expectedVersion: expectedVersion,
4179 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004180 expectedError: expectedClientError,
4181 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004182 })
4183
4184 testCases = append(testCases, testCase{
4185 protocol: protocol,
4186 testType: serverTest,
4187 name: "MinimumVersion-Server-" + suffix,
4188 config: Config{
4189 MaxVersion: runnerVers.version,
4190 },
David Benjamin87909c02014-12-13 01:55:01 -05004191 flags: flags,
4192 expectedVersion: expectedVersion,
4193 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004194 expectedError: expectedServerError,
4195 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004196 })
4197 testCases = append(testCases, testCase{
4198 protocol: protocol,
4199 testType: serverTest,
4200 name: "MinimumVersion-Server2-" + suffix,
4201 config: Config{
4202 MaxVersion: runnerVers.version,
4203 },
David Benjamin87909c02014-12-13 01:55:01 -05004204 flags: []string{"-min-version", shimVersFlag},
4205 expectedVersion: expectedVersion,
4206 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004207 expectedError: expectedServerError,
4208 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004209 })
4210 }
4211 }
4212 }
4213}
4214
David Benjamine78bfde2014-09-06 12:45:15 -04004215func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004216 // TODO(davidben): Extensions, where applicable, all move their server
4217 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4218 // tests for both. Also test interaction with 0-RTT when implemented.
4219
David Benjamin97d17d92016-07-14 16:12:00 -04004220 // Repeat extensions tests all versions except SSL 3.0.
4221 for _, ver := range tlsVersions {
4222 if ver.version == VersionSSL30 {
4223 continue
4224 }
4225
4226 // TODO(davidben): Implement resumption in TLS 1.3.
4227 resumeSession := ver.version < VersionTLS13
4228
4229 // Test that duplicate extensions are rejected.
4230 testCases = append(testCases, testCase{
4231 testType: clientTest,
4232 name: "DuplicateExtensionClient-" + ver.name,
4233 config: Config{
4234 MaxVersion: ver.version,
4235 Bugs: ProtocolBugs{
4236 DuplicateExtension: true,
4237 },
David Benjamine78bfde2014-09-06 12:45:15 -04004238 },
David Benjamin97d17d92016-07-14 16:12:00 -04004239 shouldFail: true,
4240 expectedLocalError: "remote error: error decoding message",
4241 })
4242 testCases = append(testCases, testCase{
4243 testType: serverTest,
4244 name: "DuplicateExtensionServer-" + ver.name,
4245 config: Config{
4246 MaxVersion: ver.version,
4247 Bugs: ProtocolBugs{
4248 DuplicateExtension: true,
4249 },
David Benjamine78bfde2014-09-06 12:45:15 -04004250 },
David Benjamin97d17d92016-07-14 16:12:00 -04004251 shouldFail: true,
4252 expectedLocalError: "remote error: error decoding message",
4253 })
4254
4255 // Test SNI.
4256 testCases = append(testCases, testCase{
4257 testType: clientTest,
4258 name: "ServerNameExtensionClient-" + ver.name,
4259 config: Config{
4260 MaxVersion: ver.version,
4261 Bugs: ProtocolBugs{
4262 ExpectServerName: "example.com",
4263 },
David Benjamine78bfde2014-09-06 12:45:15 -04004264 },
David Benjamin97d17d92016-07-14 16:12:00 -04004265 flags: []string{"-host-name", "example.com"},
4266 })
4267 testCases = append(testCases, testCase{
4268 testType: clientTest,
4269 name: "ServerNameExtensionClientMismatch-" + ver.name,
4270 config: Config{
4271 MaxVersion: ver.version,
4272 Bugs: ProtocolBugs{
4273 ExpectServerName: "mismatch.com",
4274 },
David Benjamine78bfde2014-09-06 12:45:15 -04004275 },
David Benjamin97d17d92016-07-14 16:12:00 -04004276 flags: []string{"-host-name", "example.com"},
4277 shouldFail: true,
4278 expectedLocalError: "tls: unexpected server name",
4279 })
4280 testCases = append(testCases, testCase{
4281 testType: clientTest,
4282 name: "ServerNameExtensionClientMissing-" + ver.name,
4283 config: Config{
4284 MaxVersion: ver.version,
4285 Bugs: ProtocolBugs{
4286 ExpectServerName: "missing.com",
4287 },
David Benjamine78bfde2014-09-06 12:45:15 -04004288 },
David Benjamin97d17d92016-07-14 16:12:00 -04004289 shouldFail: true,
4290 expectedLocalError: "tls: unexpected server name",
4291 })
4292 testCases = append(testCases, testCase{
4293 testType: serverTest,
4294 name: "ServerNameExtensionServer-" + ver.name,
4295 config: Config{
4296 MaxVersion: ver.version,
4297 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004298 },
David Benjamin97d17d92016-07-14 16:12:00 -04004299 flags: []string{"-expect-server-name", "example.com"},
4300 resumeSession: resumeSession,
4301 })
4302
4303 // Test ALPN.
4304 testCases = append(testCases, testCase{
4305 testType: clientTest,
4306 name: "ALPNClient-" + ver.name,
4307 config: Config{
4308 MaxVersion: ver.version,
4309 NextProtos: []string{"foo"},
4310 },
4311 flags: []string{
4312 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4313 "-expect-alpn", "foo",
4314 },
4315 expectedNextProto: "foo",
4316 expectedNextProtoType: alpn,
4317 resumeSession: resumeSession,
4318 })
4319 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004320 testType: clientTest,
4321 name: "ALPNClient-Mismatch-" + ver.name,
4322 config: Config{
4323 MaxVersion: ver.version,
4324 Bugs: ProtocolBugs{
4325 SendALPN: "baz",
4326 },
4327 },
4328 flags: []string{
4329 "-advertise-alpn", "\x03foo\x03bar",
4330 },
4331 shouldFail: true,
4332 expectedError: ":INVALID_ALPN_PROTOCOL:",
4333 expectedLocalError: "remote error: illegal parameter",
4334 })
4335 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004336 testType: serverTest,
4337 name: "ALPNServer-" + ver.name,
4338 config: Config{
4339 MaxVersion: ver.version,
4340 NextProtos: []string{"foo", "bar", "baz"},
4341 },
4342 flags: []string{
4343 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4344 "-select-alpn", "foo",
4345 },
4346 expectedNextProto: "foo",
4347 expectedNextProtoType: alpn,
4348 resumeSession: resumeSession,
4349 })
4350 testCases = append(testCases, testCase{
4351 testType: serverTest,
4352 name: "ALPNServer-Decline-" + ver.name,
4353 config: Config{
4354 MaxVersion: ver.version,
4355 NextProtos: []string{"foo", "bar", "baz"},
4356 },
4357 flags: []string{"-decline-alpn"},
4358 expectNoNextProto: true,
4359 resumeSession: resumeSession,
4360 })
4361
David Benjamin25fe85b2016-08-09 20:00:32 -04004362 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4363 // called once.
4364 testCases = append(testCases, testCase{
4365 testType: serverTest,
4366 name: "ALPNServer-Async-" + ver.name,
4367 config: Config{
4368 MaxVersion: ver.version,
4369 NextProtos: []string{"foo", "bar", "baz"},
4370 },
4371 flags: []string{
4372 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4373 "-select-alpn", "foo",
4374 "-async",
4375 },
4376 expectedNextProto: "foo",
4377 expectedNextProtoType: alpn,
4378 resumeSession: resumeSession,
4379 })
4380
David Benjamin97d17d92016-07-14 16:12:00 -04004381 var emptyString string
4382 testCases = append(testCases, testCase{
4383 testType: clientTest,
4384 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4385 config: Config{
4386 MaxVersion: ver.version,
4387 NextProtos: []string{""},
4388 Bugs: ProtocolBugs{
4389 // A server returning an empty ALPN protocol
4390 // should be rejected.
4391 ALPNProtocol: &emptyString,
4392 },
4393 },
4394 flags: []string{
4395 "-advertise-alpn", "\x03foo",
4396 },
4397 shouldFail: true,
4398 expectedError: ":PARSE_TLSEXT:",
4399 })
4400 testCases = append(testCases, testCase{
4401 testType: serverTest,
4402 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4403 config: Config{
4404 MaxVersion: ver.version,
4405 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004406 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004407 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004408 },
David Benjamin97d17d92016-07-14 16:12:00 -04004409 flags: []string{
4410 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004411 },
David Benjamin97d17d92016-07-14 16:12:00 -04004412 shouldFail: true,
4413 expectedError: ":PARSE_TLSEXT:",
4414 })
4415
4416 // Test NPN and the interaction with ALPN.
4417 if ver.version < VersionTLS13 {
4418 // Test that the server prefers ALPN over NPN.
4419 testCases = append(testCases, testCase{
4420 testType: serverTest,
4421 name: "ALPNServer-Preferred-" + ver.name,
4422 config: Config{
4423 MaxVersion: ver.version,
4424 NextProtos: []string{"foo", "bar", "baz"},
4425 },
4426 flags: []string{
4427 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4428 "-select-alpn", "foo",
4429 "-advertise-npn", "\x03foo\x03bar\x03baz",
4430 },
4431 expectedNextProto: "foo",
4432 expectedNextProtoType: alpn,
4433 resumeSession: resumeSession,
4434 })
4435 testCases = append(testCases, testCase{
4436 testType: serverTest,
4437 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4438 config: Config{
4439 MaxVersion: ver.version,
4440 NextProtos: []string{"foo", "bar", "baz"},
4441 Bugs: ProtocolBugs{
4442 SwapNPNAndALPN: true,
4443 },
4444 },
4445 flags: []string{
4446 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4447 "-select-alpn", "foo",
4448 "-advertise-npn", "\x03foo\x03bar\x03baz",
4449 },
4450 expectedNextProto: "foo",
4451 expectedNextProtoType: alpn,
4452 resumeSession: resumeSession,
4453 })
4454
4455 // Test that negotiating both NPN and ALPN is forbidden.
4456 testCases = append(testCases, testCase{
4457 name: "NegotiateALPNAndNPN-" + ver.name,
4458 config: Config{
4459 MaxVersion: ver.version,
4460 NextProtos: []string{"foo", "bar", "baz"},
4461 Bugs: ProtocolBugs{
4462 NegotiateALPNAndNPN: true,
4463 },
4464 },
4465 flags: []string{
4466 "-advertise-alpn", "\x03foo",
4467 "-select-next-proto", "foo",
4468 },
4469 shouldFail: true,
4470 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4471 })
4472 testCases = append(testCases, testCase{
4473 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4474 config: Config{
4475 MaxVersion: ver.version,
4476 NextProtos: []string{"foo", "bar", "baz"},
4477 Bugs: ProtocolBugs{
4478 NegotiateALPNAndNPN: true,
4479 SwapNPNAndALPN: true,
4480 },
4481 },
4482 flags: []string{
4483 "-advertise-alpn", "\x03foo",
4484 "-select-next-proto", "foo",
4485 },
4486 shouldFail: true,
4487 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4488 })
4489
4490 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4491 testCases = append(testCases, testCase{
4492 name: "DisableNPN-" + ver.name,
4493 config: Config{
4494 MaxVersion: ver.version,
4495 NextProtos: []string{"foo"},
4496 },
4497 flags: []string{
4498 "-select-next-proto", "foo",
4499 "-disable-npn",
4500 },
4501 expectNoNextProto: true,
4502 })
4503 }
4504
4505 // Test ticket behavior.
4506 //
4507 // TODO(davidben): Add TLS 1.3 versions of these.
4508 if ver.version < VersionTLS13 {
4509 // Resume with a corrupt ticket.
4510 testCases = append(testCases, testCase{
4511 testType: serverTest,
4512 name: "CorruptTicket-" + ver.name,
4513 config: Config{
4514 MaxVersion: ver.version,
4515 Bugs: ProtocolBugs{
4516 CorruptTicket: true,
4517 },
4518 },
4519 resumeSession: true,
4520 expectResumeRejected: true,
4521 })
4522 // Test the ticket callback, with and without renewal.
4523 testCases = append(testCases, testCase{
4524 testType: serverTest,
4525 name: "TicketCallback-" + ver.name,
4526 config: Config{
4527 MaxVersion: ver.version,
4528 },
4529 resumeSession: true,
4530 flags: []string{"-use-ticket-callback"},
4531 })
4532 testCases = append(testCases, testCase{
4533 testType: serverTest,
4534 name: "TicketCallback-Renew-" + ver.name,
4535 config: Config{
4536 MaxVersion: ver.version,
4537 Bugs: ProtocolBugs{
4538 ExpectNewTicket: true,
4539 },
4540 },
4541 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4542 resumeSession: true,
4543 })
4544
David Benjamin25fe85b2016-08-09 20:00:32 -04004545 // Test that the ticket callback is only called once when everything before
4546 // it in the ClientHello is asynchronous. This corrupts the ticket so
4547 // certificate selection callbacks run.
4548 testCases = append(testCases, testCase{
4549 testType: serverTest,
4550 name: "TicketCallback-SingleCall-" + ver.name,
4551 config: Config{
4552 MaxVersion: ver.version,
4553 Bugs: ProtocolBugs{
4554 CorruptTicket: true,
4555 },
4556 },
4557 resumeSession: true,
4558 expectResumeRejected: true,
4559 flags: []string{
4560 "-use-ticket-callback",
4561 "-async",
4562 },
4563 })
4564
David Benjamin97d17d92016-07-14 16:12:00 -04004565 // Resume with an oversized session id.
4566 testCases = append(testCases, testCase{
4567 testType: serverTest,
4568 name: "OversizedSessionId-" + ver.name,
4569 config: Config{
4570 MaxVersion: ver.version,
4571 Bugs: ProtocolBugs{
4572 OversizedSessionId: true,
4573 },
4574 },
4575 resumeSession: true,
4576 shouldFail: true,
4577 expectedError: ":DECODE_ERROR:",
4578 })
4579 }
4580
4581 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4582 // are ignored.
4583 if ver.hasDTLS {
4584 testCases = append(testCases, testCase{
4585 protocol: dtls,
4586 name: "SRTP-Client-" + ver.name,
4587 config: Config{
4588 MaxVersion: ver.version,
4589 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4590 },
4591 flags: []string{
4592 "-srtp-profiles",
4593 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4594 },
4595 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4596 })
4597 testCases = append(testCases, testCase{
4598 protocol: dtls,
4599 testType: serverTest,
4600 name: "SRTP-Server-" + ver.name,
4601 config: Config{
4602 MaxVersion: ver.version,
4603 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4604 },
4605 flags: []string{
4606 "-srtp-profiles",
4607 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4608 },
4609 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4610 })
4611 // Test that the MKI is ignored.
4612 testCases = append(testCases, testCase{
4613 protocol: dtls,
4614 testType: serverTest,
4615 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4616 config: Config{
4617 MaxVersion: ver.version,
4618 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4619 Bugs: ProtocolBugs{
4620 SRTPMasterKeyIdentifer: "bogus",
4621 },
4622 },
4623 flags: []string{
4624 "-srtp-profiles",
4625 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4626 },
4627 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4628 })
4629 // Test that SRTP isn't negotiated on the server if there were
4630 // no matching profiles.
4631 testCases = append(testCases, testCase{
4632 protocol: dtls,
4633 testType: serverTest,
4634 name: "SRTP-Server-NoMatch-" + ver.name,
4635 config: Config{
4636 MaxVersion: ver.version,
4637 SRTPProtectionProfiles: []uint16{100, 101, 102},
4638 },
4639 flags: []string{
4640 "-srtp-profiles",
4641 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4642 },
4643 expectedSRTPProtectionProfile: 0,
4644 })
4645 // Test that the server returning an invalid SRTP profile is
4646 // flagged as an error by the client.
4647 testCases = append(testCases, testCase{
4648 protocol: dtls,
4649 name: "SRTP-Client-NoMatch-" + ver.name,
4650 config: Config{
4651 MaxVersion: ver.version,
4652 Bugs: ProtocolBugs{
4653 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4654 },
4655 },
4656 flags: []string{
4657 "-srtp-profiles",
4658 "SRTP_AES128_CM_SHA1_80",
4659 },
4660 shouldFail: true,
4661 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4662 })
4663 }
4664
4665 // Test SCT list.
4666 testCases = append(testCases, testCase{
4667 name: "SignedCertificateTimestampList-Client-" + ver.name,
4668 testType: clientTest,
4669 config: Config{
4670 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004671 },
David Benjamin97d17d92016-07-14 16:12:00 -04004672 flags: []string{
4673 "-enable-signed-cert-timestamps",
4674 "-expect-signed-cert-timestamps",
4675 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004676 },
David Benjamin97d17d92016-07-14 16:12:00 -04004677 resumeSession: resumeSession,
4678 })
4679 testCases = append(testCases, testCase{
4680 name: "SendSCTListOnResume-" + ver.name,
4681 config: Config{
4682 MaxVersion: ver.version,
4683 Bugs: ProtocolBugs{
4684 SendSCTListOnResume: []byte("bogus"),
4685 },
David Benjamind98452d2015-06-16 14:16:23 -04004686 },
David Benjamin97d17d92016-07-14 16:12:00 -04004687 flags: []string{
4688 "-enable-signed-cert-timestamps",
4689 "-expect-signed-cert-timestamps",
4690 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004691 },
David Benjamin97d17d92016-07-14 16:12:00 -04004692 resumeSession: resumeSession,
4693 })
4694 testCases = append(testCases, testCase{
4695 name: "SignedCertificateTimestampList-Server-" + ver.name,
4696 testType: serverTest,
4697 config: Config{
4698 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004699 },
David Benjamin97d17d92016-07-14 16:12:00 -04004700 flags: []string{
4701 "-signed-cert-timestamps",
4702 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004703 },
David Benjamin97d17d92016-07-14 16:12:00 -04004704 expectedSCTList: testSCTList,
4705 resumeSession: resumeSession,
4706 })
4707 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004708
Paul Lietar4fac72e2015-09-09 13:44:55 +01004709 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004710 testType: clientTest,
4711 name: "ClientHelloPadding",
4712 config: Config{
4713 Bugs: ProtocolBugs{
4714 RequireClientHelloSize: 512,
4715 },
4716 },
4717 // This hostname just needs to be long enough to push the
4718 // ClientHello into F5's danger zone between 256 and 511 bytes
4719 // long.
4720 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4721 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004722
4723 // Extensions should not function in SSL 3.0.
4724 testCases = append(testCases, testCase{
4725 testType: serverTest,
4726 name: "SSLv3Extensions-NoALPN",
4727 config: Config{
4728 MaxVersion: VersionSSL30,
4729 NextProtos: []string{"foo", "bar", "baz"},
4730 },
4731 flags: []string{
4732 "-select-alpn", "foo",
4733 },
4734 expectNoNextProto: true,
4735 })
4736
4737 // Test session tickets separately as they follow a different codepath.
4738 testCases = append(testCases, testCase{
4739 testType: serverTest,
4740 name: "SSLv3Extensions-NoTickets",
4741 config: Config{
4742 MaxVersion: VersionSSL30,
4743 Bugs: ProtocolBugs{
4744 // Historically, session tickets in SSL 3.0
4745 // failed in different ways depending on whether
4746 // the client supported renegotiation_info.
4747 NoRenegotiationInfo: true,
4748 },
4749 },
4750 resumeSession: true,
4751 })
4752 testCases = append(testCases, testCase{
4753 testType: serverTest,
4754 name: "SSLv3Extensions-NoTickets2",
4755 config: Config{
4756 MaxVersion: VersionSSL30,
4757 },
4758 resumeSession: true,
4759 })
4760
4761 // But SSL 3.0 does send and process renegotiation_info.
4762 testCases = append(testCases, testCase{
4763 testType: serverTest,
4764 name: "SSLv3Extensions-RenegotiationInfo",
4765 config: Config{
4766 MaxVersion: VersionSSL30,
4767 Bugs: ProtocolBugs{
4768 RequireRenegotiationInfo: true,
4769 },
4770 },
4771 })
4772 testCases = append(testCases, testCase{
4773 testType: serverTest,
4774 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4775 config: Config{
4776 MaxVersion: VersionSSL30,
4777 Bugs: ProtocolBugs{
4778 NoRenegotiationInfo: true,
4779 SendRenegotiationSCSV: true,
4780 RequireRenegotiationInfo: true,
4781 },
4782 },
4783 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004784
4785 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4786 // in ServerHello.
4787 testCases = append(testCases, testCase{
4788 name: "NPN-Forbidden-TLS13",
4789 config: Config{
4790 MaxVersion: VersionTLS13,
4791 NextProtos: []string{"foo"},
4792 Bugs: ProtocolBugs{
4793 NegotiateNPNAtAllVersions: true,
4794 },
4795 },
4796 flags: []string{"-select-next-proto", "foo"},
4797 shouldFail: true,
4798 expectedError: ":ERROR_PARSING_EXTENSION:",
4799 })
4800 testCases = append(testCases, testCase{
4801 name: "EMS-Forbidden-TLS13",
4802 config: Config{
4803 MaxVersion: VersionTLS13,
4804 Bugs: ProtocolBugs{
4805 NegotiateEMSAtAllVersions: true,
4806 },
4807 },
4808 shouldFail: true,
4809 expectedError: ":ERROR_PARSING_EXTENSION:",
4810 })
4811 testCases = append(testCases, testCase{
4812 name: "RenegotiationInfo-Forbidden-TLS13",
4813 config: Config{
4814 MaxVersion: VersionTLS13,
4815 Bugs: ProtocolBugs{
4816 NegotiateRenegotiationInfoAtAllVersions: true,
4817 },
4818 },
4819 shouldFail: true,
4820 expectedError: ":ERROR_PARSING_EXTENSION:",
4821 })
4822 testCases = append(testCases, testCase{
4823 name: "ChannelID-Forbidden-TLS13",
4824 config: Config{
4825 MaxVersion: VersionTLS13,
4826 RequestChannelID: true,
4827 Bugs: ProtocolBugs{
4828 NegotiateChannelIDAtAllVersions: true,
4829 },
4830 },
4831 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4832 shouldFail: true,
4833 expectedError: ":ERROR_PARSING_EXTENSION:",
4834 })
4835 testCases = append(testCases, testCase{
4836 name: "Ticket-Forbidden-TLS13",
4837 config: Config{
4838 MaxVersion: VersionTLS12,
4839 },
4840 resumeConfig: &Config{
4841 MaxVersion: VersionTLS13,
4842 Bugs: ProtocolBugs{
4843 AdvertiseTicketExtension: true,
4844 },
4845 },
4846 resumeSession: true,
4847 shouldFail: true,
4848 expectedError: ":ERROR_PARSING_EXTENSION:",
4849 })
4850
4851 // Test that illegal extensions in TLS 1.3 are declined by the server if
4852 // offered in ClientHello. The runner's server will fail if this occurs,
4853 // so we exercise the offering path. (EMS and Renegotiation Info are
4854 // implicit in every test.)
4855 testCases = append(testCases, testCase{
4856 testType: serverTest,
4857 name: "ChannelID-Declined-TLS13",
4858 config: Config{
4859 MaxVersion: VersionTLS13,
4860 ChannelID: channelIDKey,
4861 },
4862 flags: []string{"-enable-channel-id"},
4863 })
4864 testCases = append(testCases, testCase{
4865 testType: serverTest,
4866 name: "NPN-Server",
4867 config: Config{
4868 MaxVersion: VersionTLS13,
4869 NextProtos: []string{"bar"},
4870 },
4871 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
4872 })
David Benjamine78bfde2014-09-06 12:45:15 -04004873}
4874
David Benjamin01fe8202014-09-24 15:21:44 -04004875func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004876 for _, sessionVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004877 // TODO(davidben,svaldez): Implement resumption in TLS 1.3.
4878 if sessionVers.version >= VersionTLS13 {
4879 continue
4880 }
David Benjamin01fe8202014-09-24 15:21:44 -04004881 for _, resumeVers := range tlsVersions {
David Benjamin6e6abe12016-07-13 20:57:22 -04004882 if resumeVers.version >= VersionTLS13 {
4883 continue
4884 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004885 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4886 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4887 // TLS 1.3 only shares ciphers with TLS 1.2, so
4888 // we skip certain combinations and use a
4889 // different cipher to test with.
4890 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4891 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4892 continue
4893 }
4894 }
4895
David Benjamin8b8c0062014-11-23 02:47:52 -05004896 protocols := []protocol{tls}
4897 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4898 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004899 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004900 for _, protocol := range protocols {
4901 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4902 if protocol == dtls {
4903 suffix += "-DTLS"
4904 }
4905
David Benjaminece3de92015-03-16 18:02:20 -04004906 if sessionVers.version == resumeVers.version {
4907 testCases = append(testCases, testCase{
4908 protocol: protocol,
4909 name: "Resume-Client" + suffix,
4910 resumeSession: true,
4911 config: Config{
4912 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004913 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004914 },
David Benjaminece3de92015-03-16 18:02:20 -04004915 expectedVersion: sessionVers.version,
4916 expectedResumeVersion: resumeVers.version,
4917 })
4918 } else {
4919 testCases = append(testCases, testCase{
4920 protocol: protocol,
4921 name: "Resume-Client-Mismatch" + suffix,
4922 resumeSession: true,
4923 config: Config{
4924 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004925 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004926 },
David Benjaminece3de92015-03-16 18:02:20 -04004927 expectedVersion: sessionVers.version,
4928 resumeConfig: &Config{
4929 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004930 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004931 Bugs: ProtocolBugs{
4932 AllowSessionVersionMismatch: true,
4933 },
4934 },
4935 expectedResumeVersion: resumeVers.version,
4936 shouldFail: true,
4937 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4938 })
4939 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004940
4941 testCases = append(testCases, testCase{
4942 protocol: protocol,
4943 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004944 resumeSession: true,
4945 config: Config{
4946 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004947 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004948 },
4949 expectedVersion: sessionVers.version,
4950 resumeConfig: &Config{
4951 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004952 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004953 },
4954 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004955 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004956 expectedResumeVersion: resumeVers.version,
4957 })
4958
David Benjamin8b8c0062014-11-23 02:47:52 -05004959 testCases = append(testCases, testCase{
4960 protocol: protocol,
4961 testType: serverTest,
4962 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004963 resumeSession: true,
4964 config: Config{
4965 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004966 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004967 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004968 expectedVersion: sessionVers.version,
4969 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004970 resumeConfig: &Config{
4971 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004972 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004973 },
4974 expectedResumeVersion: resumeVers.version,
4975 })
4976 }
David Benjamin01fe8202014-09-24 15:21:44 -04004977 }
4978 }
David Benjaminece3de92015-03-16 18:02:20 -04004979
Nick Harper1fd39d82016-06-14 18:14:35 -07004980 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004981 testCases = append(testCases, testCase{
4982 name: "Resume-Client-CipherMismatch",
4983 resumeSession: true,
4984 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004985 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004986 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4987 },
4988 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004989 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004990 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4991 Bugs: ProtocolBugs{
4992 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4993 },
4994 },
4995 shouldFail: true,
4996 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4997 })
David Benjamin01fe8202014-09-24 15:21:44 -04004998}
4999
Adam Langley2ae77d22014-10-28 17:29:33 -07005000func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005001 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005002 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005003 testType: serverTest,
5004 name: "Renegotiate-Server-Forbidden",
5005 config: Config{
5006 MaxVersion: VersionTLS12,
5007 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005008 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005009 shouldFail: true,
5010 expectedError: ":NO_RENEGOTIATION:",
5011 expectedLocalError: "remote error: no renegotiation",
5012 })
Adam Langley5021b222015-06-12 18:27:58 -07005013 // The server shouldn't echo the renegotiation extension unless
5014 // requested by the client.
5015 testCases = append(testCases, testCase{
5016 testType: serverTest,
5017 name: "Renegotiate-Server-NoExt",
5018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005019 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005020 Bugs: ProtocolBugs{
5021 NoRenegotiationInfo: true,
5022 RequireRenegotiationInfo: true,
5023 },
5024 },
5025 shouldFail: true,
5026 expectedLocalError: "renegotiation extension missing",
5027 })
5028 // The renegotiation SCSV should be sufficient for the server to echo
5029 // the extension.
5030 testCases = append(testCases, testCase{
5031 testType: serverTest,
5032 name: "Renegotiate-Server-NoExt-SCSV",
5033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005034 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005035 Bugs: ProtocolBugs{
5036 NoRenegotiationInfo: true,
5037 SendRenegotiationSCSV: true,
5038 RequireRenegotiationInfo: true,
5039 },
5040 },
5041 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005042 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005043 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005044 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005045 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005046 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005047 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005048 },
5049 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005050 renegotiate: 1,
5051 flags: []string{
5052 "-renegotiate-freely",
5053 "-expect-total-renegotiations", "1",
5054 },
David Benjamincdea40c2015-03-19 14:09:43 -04005055 })
5056 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005057 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005058 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005060 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005061 Bugs: ProtocolBugs{
5062 EmptyRenegotiationInfo: true,
5063 },
5064 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005065 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005066 shouldFail: true,
5067 expectedError: ":RENEGOTIATION_MISMATCH:",
5068 })
5069 testCases = append(testCases, testCase{
5070 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005071 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005073 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005074 Bugs: ProtocolBugs{
5075 BadRenegotiationInfo: true,
5076 },
5077 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005078 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005079 shouldFail: true,
5080 expectedError: ":RENEGOTIATION_MISMATCH:",
5081 })
5082 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005083 name: "Renegotiate-Client-Downgrade",
5084 renegotiate: 1,
5085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005086 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005087 Bugs: ProtocolBugs{
5088 NoRenegotiationInfoAfterInitial: true,
5089 },
5090 },
5091 flags: []string{"-renegotiate-freely"},
5092 shouldFail: true,
5093 expectedError: ":RENEGOTIATION_MISMATCH:",
5094 })
5095 testCases = append(testCases, testCase{
5096 name: "Renegotiate-Client-Upgrade",
5097 renegotiate: 1,
5098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005099 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005100 Bugs: ProtocolBugs{
5101 NoRenegotiationInfoInInitial: true,
5102 },
5103 },
5104 flags: []string{"-renegotiate-freely"},
5105 shouldFail: true,
5106 expectedError: ":RENEGOTIATION_MISMATCH:",
5107 })
5108 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005109 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005110 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005112 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005113 Bugs: ProtocolBugs{
5114 NoRenegotiationInfo: true,
5115 },
5116 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005117 flags: []string{
5118 "-renegotiate-freely",
5119 "-expect-total-renegotiations", "1",
5120 },
David Benjamincff0b902015-05-15 23:09:47 -04005121 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005122
5123 // Test that the server may switch ciphers on renegotiation without
5124 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005125 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005126 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005127 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005128 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005129 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005130 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5131 },
5132 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005133 flags: []string{
5134 "-renegotiate-freely",
5135 "-expect-total-renegotiations", "1",
5136 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005137 })
5138 testCases = append(testCases, testCase{
5139 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005140 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005141 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005142 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005143 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5144 },
5145 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005146 flags: []string{
5147 "-renegotiate-freely",
5148 "-expect-total-renegotiations", "1",
5149 },
David Benjaminb16346b2015-04-08 19:16:58 -04005150 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005151
5152 // Test that the server may not switch versions on renegotiation.
5153 testCases = append(testCases, testCase{
5154 name: "Renegotiate-Client-SwitchVersion",
5155 config: Config{
5156 MaxVersion: VersionTLS12,
5157 // Pick a cipher which exists at both versions.
5158 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5159 Bugs: ProtocolBugs{
5160 NegotiateVersionOnRenego: VersionTLS11,
5161 },
5162 },
5163 renegotiate: 1,
5164 flags: []string{
5165 "-renegotiate-freely",
5166 "-expect-total-renegotiations", "1",
5167 },
5168 shouldFail: true,
5169 expectedError: ":WRONG_SSL_VERSION:",
5170 })
5171
David Benjaminb16346b2015-04-08 19:16:58 -04005172 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005173 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005174 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005175 config: Config{
5176 MaxVersion: VersionTLS10,
5177 Bugs: ProtocolBugs{
5178 RequireSameRenegoClientVersion: true,
5179 },
5180 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005181 flags: []string{
5182 "-renegotiate-freely",
5183 "-expect-total-renegotiations", "1",
5184 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005185 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005186 testCases = append(testCases, testCase{
5187 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005188 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005189 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005190 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005191 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5192 NextProtos: []string{"foo"},
5193 },
5194 flags: []string{
5195 "-false-start",
5196 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005197 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005198 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005199 },
5200 shimWritesFirst: true,
5201 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005202
5203 // Client-side renegotiation controls.
5204 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005205 name: "Renegotiate-Client-Forbidden-1",
5206 config: Config{
5207 MaxVersion: VersionTLS12,
5208 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005209 renegotiate: 1,
5210 shouldFail: true,
5211 expectedError: ":NO_RENEGOTIATION:",
5212 expectedLocalError: "remote error: no renegotiation",
5213 })
5214 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005215 name: "Renegotiate-Client-Once-1",
5216 config: Config{
5217 MaxVersion: VersionTLS12,
5218 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005219 renegotiate: 1,
5220 flags: []string{
5221 "-renegotiate-once",
5222 "-expect-total-renegotiations", "1",
5223 },
5224 })
5225 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005226 name: "Renegotiate-Client-Freely-1",
5227 config: Config{
5228 MaxVersion: VersionTLS12,
5229 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005230 renegotiate: 1,
5231 flags: []string{
5232 "-renegotiate-freely",
5233 "-expect-total-renegotiations", "1",
5234 },
5235 })
5236 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005237 name: "Renegotiate-Client-Once-2",
5238 config: Config{
5239 MaxVersion: VersionTLS12,
5240 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005241 renegotiate: 2,
5242 flags: []string{"-renegotiate-once"},
5243 shouldFail: true,
5244 expectedError: ":NO_RENEGOTIATION:",
5245 expectedLocalError: "remote error: no renegotiation",
5246 })
5247 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005248 name: "Renegotiate-Client-Freely-2",
5249 config: Config{
5250 MaxVersion: VersionTLS12,
5251 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005252 renegotiate: 2,
5253 flags: []string{
5254 "-renegotiate-freely",
5255 "-expect-total-renegotiations", "2",
5256 },
5257 })
Adam Langley27a0d082015-11-03 13:34:10 -08005258 testCases = append(testCases, testCase{
5259 name: "Renegotiate-Client-NoIgnore",
5260 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005261 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005262 Bugs: ProtocolBugs{
5263 SendHelloRequestBeforeEveryAppDataRecord: true,
5264 },
5265 },
5266 shouldFail: true,
5267 expectedError: ":NO_RENEGOTIATION:",
5268 })
5269 testCases = append(testCases, testCase{
5270 name: "Renegotiate-Client-Ignore",
5271 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005272 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005273 Bugs: ProtocolBugs{
5274 SendHelloRequestBeforeEveryAppDataRecord: true,
5275 },
5276 },
5277 flags: []string{
5278 "-renegotiate-ignore",
5279 "-expect-total-renegotiations", "0",
5280 },
5281 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005282
David Benjamin397c8e62016-07-08 14:14:36 -07005283 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005284 testCases = append(testCases, testCase{
5285 name: "StrayHelloRequest",
5286 config: Config{
5287 MaxVersion: VersionTLS12,
5288 Bugs: ProtocolBugs{
5289 SendHelloRequestBeforeEveryHandshakeMessage: true,
5290 },
5291 },
5292 })
5293 testCases = append(testCases, testCase{
5294 name: "StrayHelloRequest-Packed",
5295 config: Config{
5296 MaxVersion: VersionTLS12,
5297 Bugs: ProtocolBugs{
5298 PackHandshakeFlight: true,
5299 SendHelloRequestBeforeEveryHandshakeMessage: true,
5300 },
5301 },
5302 })
5303
David Benjamin12d2c482016-07-24 10:56:51 -04005304 // Test renegotiation works if HelloRequest and server Finished come in
5305 // the same record.
5306 testCases = append(testCases, testCase{
5307 name: "Renegotiate-Client-Packed",
5308 config: Config{
5309 MaxVersion: VersionTLS12,
5310 Bugs: ProtocolBugs{
5311 PackHandshakeFlight: true,
5312 PackHelloRequestWithFinished: true,
5313 },
5314 },
5315 renegotiate: 1,
5316 flags: []string{
5317 "-renegotiate-freely",
5318 "-expect-total-renegotiations", "1",
5319 },
5320 })
5321
David Benjamin397c8e62016-07-08 14:14:36 -07005322 // Renegotiation is forbidden in TLS 1.3.
5323 testCases = append(testCases, testCase{
5324 name: "Renegotiate-Client-TLS13",
5325 config: Config{
5326 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005327 Bugs: ProtocolBugs{
5328 SendHelloRequestBeforeEveryAppDataRecord: true,
5329 },
David Benjamin397c8e62016-07-08 14:14:36 -07005330 },
David Benjamin397c8e62016-07-08 14:14:36 -07005331 flags: []string{
5332 "-renegotiate-freely",
5333 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005334 shouldFail: true,
5335 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005336 })
5337
5338 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5339 testCases = append(testCases, testCase{
5340 name: "StrayHelloRequest-TLS13",
5341 config: Config{
5342 MaxVersion: VersionTLS13,
5343 Bugs: ProtocolBugs{
5344 SendHelloRequestBeforeEveryHandshakeMessage: true,
5345 },
5346 },
5347 shouldFail: true,
5348 expectedError: ":UNEXPECTED_MESSAGE:",
5349 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005350}
5351
David Benjamin5e961c12014-11-07 01:48:35 -05005352func addDTLSReplayTests() {
5353 // Test that sequence number replays are detected.
5354 testCases = append(testCases, testCase{
5355 protocol: dtls,
5356 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005357 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005358 replayWrites: true,
5359 })
5360
David Benjamin8e6db492015-07-25 18:29:23 -04005361 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005362 // than the retransmit window.
5363 testCases = append(testCases, testCase{
5364 protocol: dtls,
5365 name: "DTLS-Replay-LargeGaps",
5366 config: Config{
5367 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005368 SequenceNumberMapping: func(in uint64) uint64 {
5369 return in * 127
5370 },
David Benjamin5e961c12014-11-07 01:48:35 -05005371 },
5372 },
David Benjamin8e6db492015-07-25 18:29:23 -04005373 messageCount: 200,
5374 replayWrites: true,
5375 })
5376
5377 // Test the incoming sequence number changing non-monotonically.
5378 testCases = append(testCases, testCase{
5379 protocol: dtls,
5380 name: "DTLS-Replay-NonMonotonic",
5381 config: Config{
5382 Bugs: ProtocolBugs{
5383 SequenceNumberMapping: func(in uint64) uint64 {
5384 return in ^ 31
5385 },
5386 },
5387 },
5388 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005389 replayWrites: true,
5390 })
5391}
5392
Nick Harper60edffd2016-06-21 15:19:24 -07005393var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005394 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005395 id signatureAlgorithm
5396 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005397}{
Nick Harper60edffd2016-06-21 15:19:24 -07005398 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5399 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5400 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5401 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005402 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005403 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5404 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5405 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005406 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5407 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5408 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005409 // Tests for key types prior to TLS 1.2.
5410 {"RSA", 0, testCertRSA},
5411 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005412}
5413
Nick Harper60edffd2016-06-21 15:19:24 -07005414const fakeSigAlg1 signatureAlgorithm = 0x2a01
5415const fakeSigAlg2 signatureAlgorithm = 0xff01
5416
5417func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005418 // Not all ciphers involve a signature. Advertise a list which gives all
5419 // versions a signing cipher.
5420 signingCiphers := []uint16{
5421 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5422 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5423 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5424 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5425 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5426 }
5427
David Benjaminca3d5452016-07-14 12:51:01 -04005428 var allAlgorithms []signatureAlgorithm
5429 for _, alg := range testSignatureAlgorithms {
5430 if alg.id != 0 {
5431 allAlgorithms = append(allAlgorithms, alg.id)
5432 }
5433 }
5434
Nick Harper60edffd2016-06-21 15:19:24 -07005435 // Make sure each signature algorithm works. Include some fake values in
5436 // the list and ensure they're ignored.
5437 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005438 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005439 if (ver.version < VersionTLS12) != (alg.id == 0) {
5440 continue
5441 }
5442
5443 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5444 // or remove it in C.
5445 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005446 continue
5447 }
Nick Harper60edffd2016-06-21 15:19:24 -07005448
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005449 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005450 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005451 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5452 shouldFail = true
5453 }
5454 // RSA-PSS does not exist in TLS 1.2.
5455 if ver.version == VersionTLS12 && hasComponent(alg.name, "PSS") {
5456 shouldFail = true
5457 }
5458
5459 var signError, verifyError string
5460 if shouldFail {
5461 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5462 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005463 }
David Benjamin000800a2014-11-14 01:43:59 -05005464
David Benjamin1fb125c2016-07-08 18:52:12 -07005465 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005466
David Benjamin7a41d372016-07-09 11:21:54 -07005467 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005468 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005469 config: Config{
5470 MaxVersion: ver.version,
5471 ClientAuth: RequireAnyClientCert,
5472 VerifySignatureAlgorithms: []signatureAlgorithm{
5473 fakeSigAlg1,
5474 alg.id,
5475 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005476 },
David Benjamin7a41d372016-07-09 11:21:54 -07005477 },
5478 flags: []string{
5479 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5480 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5481 "-enable-all-curves",
5482 },
5483 shouldFail: shouldFail,
5484 expectedError: signError,
5485 expectedPeerSignatureAlgorithm: alg.id,
5486 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005487
David Benjamin7a41d372016-07-09 11:21:54 -07005488 testCases = append(testCases, testCase{
5489 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005490 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005491 config: Config{
5492 MaxVersion: ver.version,
5493 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5494 SignSignatureAlgorithms: []signatureAlgorithm{
5495 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005496 },
David Benjamin7a41d372016-07-09 11:21:54 -07005497 Bugs: ProtocolBugs{
5498 SkipECDSACurveCheck: shouldFail,
5499 IgnoreSignatureVersionChecks: shouldFail,
5500 // The client won't advertise 1.3-only algorithms after
5501 // version negotiation.
5502 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005503 },
David Benjamin7a41d372016-07-09 11:21:54 -07005504 },
5505 flags: []string{
5506 "-require-any-client-certificate",
5507 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5508 "-enable-all-curves",
5509 },
5510 shouldFail: shouldFail,
5511 expectedError: verifyError,
5512 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005513
5514 testCases = append(testCases, testCase{
5515 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005516 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005517 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005518 MaxVersion: ver.version,
5519 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005520 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005521 fakeSigAlg1,
5522 alg.id,
5523 fakeSigAlg2,
5524 },
5525 },
5526 flags: []string{
5527 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5528 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5529 "-enable-all-curves",
5530 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005531 shouldFail: shouldFail,
5532 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005533 expectedPeerSignatureAlgorithm: alg.id,
5534 })
5535
5536 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005537 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005538 config: Config{
5539 MaxVersion: ver.version,
5540 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005541 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005542 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005543 alg.id,
5544 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005545 Bugs: ProtocolBugs{
5546 SkipECDSACurveCheck: shouldFail,
5547 IgnoreSignatureVersionChecks: shouldFail,
5548 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005549 },
5550 flags: []string{
5551 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5552 "-enable-all-curves",
5553 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005554 shouldFail: shouldFail,
5555 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005556 })
David Benjamin5208fd42016-07-13 21:43:25 -04005557
5558 if !shouldFail {
5559 testCases = append(testCases, testCase{
5560 testType: serverTest,
5561 name: "ClientAuth-InvalidSignature" + suffix,
5562 config: Config{
5563 MaxVersion: ver.version,
5564 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5565 SignSignatureAlgorithms: []signatureAlgorithm{
5566 alg.id,
5567 },
5568 Bugs: ProtocolBugs{
5569 InvalidSignature: true,
5570 },
5571 },
5572 flags: []string{
5573 "-require-any-client-certificate",
5574 "-enable-all-curves",
5575 },
5576 shouldFail: true,
5577 expectedError: ":BAD_SIGNATURE:",
5578 })
5579
5580 testCases = append(testCases, testCase{
5581 name: "ServerAuth-InvalidSignature" + suffix,
5582 config: Config{
5583 MaxVersion: ver.version,
5584 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5585 CipherSuites: signingCiphers,
5586 SignSignatureAlgorithms: []signatureAlgorithm{
5587 alg.id,
5588 },
5589 Bugs: ProtocolBugs{
5590 InvalidSignature: true,
5591 },
5592 },
5593 flags: []string{"-enable-all-curves"},
5594 shouldFail: true,
5595 expectedError: ":BAD_SIGNATURE:",
5596 })
5597 }
David Benjaminca3d5452016-07-14 12:51:01 -04005598
5599 if ver.version >= VersionTLS12 && !shouldFail {
5600 testCases = append(testCases, testCase{
5601 name: "ClientAuth-Sign-Negotiate" + suffix,
5602 config: Config{
5603 MaxVersion: ver.version,
5604 ClientAuth: RequireAnyClientCert,
5605 VerifySignatureAlgorithms: allAlgorithms,
5606 },
5607 flags: []string{
5608 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5609 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5610 "-enable-all-curves",
5611 "-signing-prefs", strconv.Itoa(int(alg.id)),
5612 },
5613 expectedPeerSignatureAlgorithm: alg.id,
5614 })
5615
5616 testCases = append(testCases, testCase{
5617 testType: serverTest,
5618 name: "ServerAuth-Sign-Negotiate" + suffix,
5619 config: Config{
5620 MaxVersion: ver.version,
5621 CipherSuites: signingCiphers,
5622 VerifySignatureAlgorithms: allAlgorithms,
5623 },
5624 flags: []string{
5625 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5626 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5627 "-enable-all-curves",
5628 "-signing-prefs", strconv.Itoa(int(alg.id)),
5629 },
5630 expectedPeerSignatureAlgorithm: alg.id,
5631 })
5632 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005633 }
David Benjamin000800a2014-11-14 01:43:59 -05005634 }
5635
Nick Harper60edffd2016-06-21 15:19:24 -07005636 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005637 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005638 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005639 config: Config{
5640 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005641 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005642 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005643 signatureECDSAWithP521AndSHA512,
5644 signatureRSAPKCS1WithSHA384,
5645 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005646 },
5647 },
5648 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005649 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5650 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005651 },
Nick Harper60edffd2016-06-21 15:19:24 -07005652 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005653 })
5654
5655 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005656 name: "ClientAuth-SignatureType-TLS13",
5657 config: Config{
5658 ClientAuth: RequireAnyClientCert,
5659 MaxVersion: VersionTLS13,
5660 VerifySignatureAlgorithms: []signatureAlgorithm{
5661 signatureECDSAWithP521AndSHA512,
5662 signatureRSAPKCS1WithSHA384,
5663 signatureRSAPSSWithSHA384,
5664 signatureECDSAWithSHA1,
5665 },
5666 },
5667 flags: []string{
5668 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5669 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5670 },
5671 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5672 })
5673
5674 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005675 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005676 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005677 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005678 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005679 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005680 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005681 signatureECDSAWithP521AndSHA512,
5682 signatureRSAPKCS1WithSHA384,
5683 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005684 },
5685 },
Nick Harper60edffd2016-06-21 15:19:24 -07005686 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005687 })
5688
Steven Valdez143e8b32016-07-11 13:19:03 -04005689 testCases = append(testCases, testCase{
5690 testType: serverTest,
5691 name: "ServerAuth-SignatureType-TLS13",
5692 config: Config{
5693 MaxVersion: VersionTLS13,
5694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5695 VerifySignatureAlgorithms: []signatureAlgorithm{
5696 signatureECDSAWithP521AndSHA512,
5697 signatureRSAPKCS1WithSHA384,
5698 signatureRSAPSSWithSHA384,
5699 signatureECDSAWithSHA1,
5700 },
5701 },
5702 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5703 })
5704
David Benjamina95e9f32016-07-08 16:28:04 -07005705 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005706 testCases = append(testCases, testCase{
5707 testType: serverTest,
5708 name: "Verify-ClientAuth-SignatureType",
5709 config: Config{
5710 MaxVersion: VersionTLS12,
5711 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005712 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005713 signatureRSAPKCS1WithSHA256,
5714 },
5715 Bugs: ProtocolBugs{
5716 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5717 },
5718 },
5719 flags: []string{
5720 "-require-any-client-certificate",
5721 },
5722 shouldFail: true,
5723 expectedError: ":WRONG_SIGNATURE_TYPE:",
5724 })
5725
5726 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005727 testType: serverTest,
5728 name: "Verify-ClientAuth-SignatureType-TLS13",
5729 config: Config{
5730 MaxVersion: VersionTLS13,
5731 Certificates: []Certificate{rsaCertificate},
5732 SignSignatureAlgorithms: []signatureAlgorithm{
5733 signatureRSAPSSWithSHA256,
5734 },
5735 Bugs: ProtocolBugs{
5736 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5737 },
5738 },
5739 flags: []string{
5740 "-require-any-client-certificate",
5741 },
5742 shouldFail: true,
5743 expectedError: ":WRONG_SIGNATURE_TYPE:",
5744 })
5745
5746 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005747 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005748 config: Config{
5749 MaxVersion: VersionTLS12,
5750 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005751 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005752 signatureRSAPKCS1WithSHA256,
5753 },
5754 Bugs: ProtocolBugs{
5755 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5756 },
5757 },
5758 shouldFail: true,
5759 expectedError: ":WRONG_SIGNATURE_TYPE:",
5760 })
5761
Steven Valdez143e8b32016-07-11 13:19:03 -04005762 testCases = append(testCases, testCase{
5763 name: "Verify-ServerAuth-SignatureType-TLS13",
5764 config: Config{
5765 MaxVersion: VersionTLS13,
5766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5767 SignSignatureAlgorithms: []signatureAlgorithm{
5768 signatureRSAPSSWithSHA256,
5769 },
5770 Bugs: ProtocolBugs{
5771 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5772 },
5773 },
5774 shouldFail: true,
5775 expectedError: ":WRONG_SIGNATURE_TYPE:",
5776 })
5777
David Benjamin51dd7d62016-07-08 16:07:01 -07005778 // Test that, if the list is missing, the peer falls back to SHA-1 in
5779 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005780 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005781 name: "ClientAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005783 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005784 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005785 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005786 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005787 },
5788 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005789 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005790 },
5791 },
5792 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005793 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5794 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005795 },
5796 })
5797
5798 testCases = append(testCases, testCase{
5799 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005800 name: "ServerAuth-SHA1-Fallback",
David Benjamin000800a2014-11-14 01:43:59 -05005801 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005802 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005804 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005805 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005806 },
5807 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005808 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005809 },
5810 },
5811 })
David Benjamin72dc7832015-03-16 17:49:43 -04005812
David Benjamin51dd7d62016-07-08 16:07:01 -07005813 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005814 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005815 config: Config{
5816 MaxVersion: VersionTLS13,
5817 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005818 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005819 signatureRSAPKCS1WithSHA1,
5820 },
5821 Bugs: ProtocolBugs{
5822 NoSignatureAlgorithms: true,
5823 },
5824 },
5825 flags: []string{
5826 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5827 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5828 },
David Benjamin48901652016-08-01 12:12:47 -04005829 shouldFail: true,
5830 // An empty CertificateRequest signature algorithm list is a
5831 // syntax error in TLS 1.3.
5832 expectedError: ":DECODE_ERROR:",
5833 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07005834 })
5835
5836 testCases = append(testCases, testCase{
5837 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005838 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07005839 config: Config{
5840 MaxVersion: VersionTLS13,
5841 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005842 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07005843 signatureRSAPKCS1WithSHA1,
5844 },
5845 Bugs: ProtocolBugs{
5846 NoSignatureAlgorithms: true,
5847 },
5848 },
5849 shouldFail: true,
5850 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5851 })
5852
David Benjaminb62d2872016-07-18 14:55:02 +02005853 // Test that hash preferences are enforced. BoringSSL does not implement
5854 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04005855 testCases = append(testCases, testCase{
5856 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005857 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005858 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005859 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005860 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005861 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005862 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005863 },
5864 Bugs: ProtocolBugs{
5865 IgnorePeerSignatureAlgorithmPreferences: true,
5866 },
5867 },
5868 flags: []string{"-require-any-client-certificate"},
5869 shouldFail: true,
5870 expectedError: ":WRONG_SIGNATURE_TYPE:",
5871 })
5872
5873 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005874 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04005875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005876 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04005877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005878 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005879 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04005880 },
5881 Bugs: ProtocolBugs{
5882 IgnorePeerSignatureAlgorithmPreferences: true,
5883 },
5884 },
5885 shouldFail: true,
5886 expectedError: ":WRONG_SIGNATURE_TYPE:",
5887 })
David Benjaminb62d2872016-07-18 14:55:02 +02005888 testCases = append(testCases, testCase{
5889 testType: serverTest,
5890 name: "ClientAuth-Enforced-TLS13",
5891 config: Config{
5892 MaxVersion: VersionTLS13,
5893 Certificates: []Certificate{rsaCertificate},
5894 SignSignatureAlgorithms: []signatureAlgorithm{
5895 signatureRSAPKCS1WithMD5,
5896 },
5897 Bugs: ProtocolBugs{
5898 IgnorePeerSignatureAlgorithmPreferences: true,
5899 IgnoreSignatureVersionChecks: true,
5900 },
5901 },
5902 flags: []string{"-require-any-client-certificate"},
5903 shouldFail: true,
5904 expectedError: ":WRONG_SIGNATURE_TYPE:",
5905 })
5906
5907 testCases = append(testCases, testCase{
5908 name: "ServerAuth-Enforced-TLS13",
5909 config: Config{
5910 MaxVersion: VersionTLS13,
5911 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5912 SignSignatureAlgorithms: []signatureAlgorithm{
5913 signatureRSAPKCS1WithMD5,
5914 },
5915 Bugs: ProtocolBugs{
5916 IgnorePeerSignatureAlgorithmPreferences: true,
5917 IgnoreSignatureVersionChecks: true,
5918 },
5919 },
5920 shouldFail: true,
5921 expectedError: ":WRONG_SIGNATURE_TYPE:",
5922 })
Steven Valdez0d62f262015-09-04 12:41:04 -04005923
5924 // Test that the agreed upon digest respects the client preferences and
5925 // the server digests.
5926 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04005927 name: "NoCommonAlgorithms-Digests",
5928 config: Config{
5929 MaxVersion: VersionTLS12,
5930 ClientAuth: RequireAnyClientCert,
5931 VerifySignatureAlgorithms: []signatureAlgorithm{
5932 signatureRSAPKCS1WithSHA512,
5933 signatureRSAPKCS1WithSHA1,
5934 },
5935 },
5936 flags: []string{
5937 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5938 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5939 "-digest-prefs", "SHA256",
5940 },
5941 shouldFail: true,
5942 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5943 })
5944 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07005945 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04005946 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005947 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005948 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005949 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005950 signatureRSAPKCS1WithSHA512,
5951 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005952 },
5953 },
5954 flags: []string{
5955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005957 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04005958 },
David Benjaminca3d5452016-07-14 12:51:01 -04005959 shouldFail: true,
5960 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
5961 })
5962 testCases = append(testCases, testCase{
5963 name: "NoCommonAlgorithms-TLS13",
5964 config: Config{
5965 MaxVersion: VersionTLS13,
5966 ClientAuth: RequireAnyClientCert,
5967 VerifySignatureAlgorithms: []signatureAlgorithm{
5968 signatureRSAPSSWithSHA512,
5969 signatureRSAPSSWithSHA384,
5970 },
5971 },
5972 flags: []string{
5973 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5974 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5975 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
5976 },
David Benjaminea9a0d52016-07-08 15:52:59 -07005977 shouldFail: true,
5978 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04005979 })
5980 testCases = append(testCases, testCase{
5981 name: "Agree-Digest-SHA256",
5982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005983 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005984 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005985 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005986 signatureRSAPKCS1WithSHA1,
5987 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005988 },
5989 },
5990 flags: []string{
5991 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5992 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04005993 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04005994 },
Nick Harper60edffd2016-06-21 15:19:24 -07005995 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005996 })
5997 testCases = append(testCases, testCase{
5998 name: "Agree-Digest-SHA1",
5999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006000 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006001 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006002 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006003 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006004 },
6005 },
6006 flags: []string{
6007 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6008 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006009 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006010 },
Nick Harper60edffd2016-06-21 15:19:24 -07006011 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006012 })
6013 testCases = append(testCases, testCase{
6014 name: "Agree-Digest-Default",
6015 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006016 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006017 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006018 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006019 signatureRSAPKCS1WithSHA256,
6020 signatureECDSAWithP256AndSHA256,
6021 signatureRSAPKCS1WithSHA1,
6022 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006023 },
6024 },
6025 flags: []string{
6026 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6027 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6028 },
Nick Harper60edffd2016-06-21 15:19:24 -07006029 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006030 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006031
David Benjaminca3d5452016-07-14 12:51:01 -04006032 // Test that the signing preference list may include extra algorithms
6033 // without negotiation problems.
6034 testCases = append(testCases, testCase{
6035 testType: serverTest,
6036 name: "FilterExtraAlgorithms",
6037 config: Config{
6038 MaxVersion: VersionTLS12,
6039 VerifySignatureAlgorithms: []signatureAlgorithm{
6040 signatureRSAPKCS1WithSHA256,
6041 },
6042 },
6043 flags: []string{
6044 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6045 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6046 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6047 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6048 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6049 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6050 },
6051 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6052 })
6053
David Benjamin4c3ddf72016-06-29 18:13:53 -04006054 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6055 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006056 testCases = append(testCases, testCase{
6057 name: "CheckLeafCurve",
6058 config: Config{
6059 MaxVersion: VersionTLS12,
6060 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006061 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006062 },
6063 flags: []string{"-p384-only"},
6064 shouldFail: true,
6065 expectedError: ":BAD_ECC_CERT:",
6066 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006067
6068 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6069 testCases = append(testCases, testCase{
6070 name: "CheckLeafCurve-TLS13",
6071 config: Config{
6072 MaxVersion: VersionTLS13,
6073 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6074 Certificates: []Certificate{ecdsaP256Certificate},
6075 },
6076 flags: []string{"-p384-only"},
6077 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006078
6079 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6080 testCases = append(testCases, testCase{
6081 name: "ECDSACurveMismatch-Verify-TLS12",
6082 config: Config{
6083 MaxVersion: VersionTLS12,
6084 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6085 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006086 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006087 signatureECDSAWithP384AndSHA384,
6088 },
6089 },
6090 })
6091
6092 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6093 testCases = append(testCases, testCase{
6094 name: "ECDSACurveMismatch-Verify-TLS13",
6095 config: Config{
6096 MaxVersion: VersionTLS13,
6097 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6098 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006099 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006100 signatureECDSAWithP384AndSHA384,
6101 },
6102 Bugs: ProtocolBugs{
6103 SkipECDSACurveCheck: true,
6104 },
6105 },
6106 shouldFail: true,
6107 expectedError: ":WRONG_SIGNATURE_TYPE:",
6108 })
6109
6110 // Signature algorithm selection in TLS 1.3 should take the curve into
6111 // account.
6112 testCases = append(testCases, testCase{
6113 testType: serverTest,
6114 name: "ECDSACurveMismatch-Sign-TLS13",
6115 config: Config{
6116 MaxVersion: VersionTLS13,
6117 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006118 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006119 signatureECDSAWithP384AndSHA384,
6120 signatureECDSAWithP256AndSHA256,
6121 },
6122 },
6123 flags: []string{
6124 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6125 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6126 },
6127 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6128 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006129
6130 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6131 // server does not attempt to sign in that case.
6132 testCases = append(testCases, testCase{
6133 testType: serverTest,
6134 name: "RSA-PSS-Large",
6135 config: Config{
6136 MaxVersion: VersionTLS13,
6137 VerifySignatureAlgorithms: []signatureAlgorithm{
6138 signatureRSAPSSWithSHA512,
6139 },
6140 },
6141 flags: []string{
6142 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6143 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6144 },
6145 shouldFail: true,
6146 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6147 })
David Benjamin000800a2014-11-14 01:43:59 -05006148}
6149
David Benjamin83f90402015-01-27 01:09:43 -05006150// timeouts is the retransmit schedule for BoringSSL. It doubles and
6151// caps at 60 seconds. On the 13th timeout, it gives up.
6152var timeouts = []time.Duration{
6153 1 * time.Second,
6154 2 * time.Second,
6155 4 * time.Second,
6156 8 * time.Second,
6157 16 * time.Second,
6158 32 * time.Second,
6159 60 * time.Second,
6160 60 * time.Second,
6161 60 * time.Second,
6162 60 * time.Second,
6163 60 * time.Second,
6164 60 * time.Second,
6165 60 * time.Second,
6166}
6167
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006168// shortTimeouts is an alternate set of timeouts which would occur if the
6169// initial timeout duration was set to 250ms.
6170var shortTimeouts = []time.Duration{
6171 250 * time.Millisecond,
6172 500 * time.Millisecond,
6173 1 * time.Second,
6174 2 * time.Second,
6175 4 * time.Second,
6176 8 * time.Second,
6177 16 * time.Second,
6178 32 * time.Second,
6179 60 * time.Second,
6180 60 * time.Second,
6181 60 * time.Second,
6182 60 * time.Second,
6183 60 * time.Second,
6184}
6185
David Benjamin83f90402015-01-27 01:09:43 -05006186func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006187 // These tests work by coordinating some behavior on both the shim and
6188 // the runner.
6189 //
6190 // TimeoutSchedule configures the runner to send a series of timeout
6191 // opcodes to the shim (see packetAdaptor) immediately before reading
6192 // each peer handshake flight N. The timeout opcode both simulates a
6193 // timeout in the shim and acts as a synchronization point to help the
6194 // runner bracket each handshake flight.
6195 //
6196 // We assume the shim does not read from the channel eagerly. It must
6197 // first wait until it has sent flight N and is ready to receive
6198 // handshake flight N+1. At this point, it will process the timeout
6199 // opcode. It must then immediately respond with a timeout ACK and act
6200 // as if the shim was idle for the specified amount of time.
6201 //
6202 // The runner then drops all packets received before the ACK and
6203 // continues waiting for flight N. This ordering results in one attempt
6204 // at sending flight N to be dropped. For the test to complete, the
6205 // shim must send flight N again, testing that the shim implements DTLS
6206 // retransmit on a timeout.
6207
Steven Valdez143e8b32016-07-11 13:19:03 -04006208 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006209 // likely be more epochs to cross and the final message's retransmit may
6210 // be more complex.
6211
David Benjamin585d7a42016-06-02 14:58:00 -04006212 for _, async := range []bool{true, false} {
6213 var tests []testCase
6214
6215 // Test that this is indeed the timeout schedule. Stress all
6216 // four patterns of handshake.
6217 for i := 1; i < len(timeouts); i++ {
6218 number := strconv.Itoa(i)
6219 tests = append(tests, testCase{
6220 protocol: dtls,
6221 name: "DTLS-Retransmit-Client-" + number,
6222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006223 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006224 Bugs: ProtocolBugs{
6225 TimeoutSchedule: timeouts[:i],
6226 },
6227 },
6228 resumeSession: true,
6229 })
6230 tests = append(tests, testCase{
6231 protocol: dtls,
6232 testType: serverTest,
6233 name: "DTLS-Retransmit-Server-" + number,
6234 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006235 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006236 Bugs: ProtocolBugs{
6237 TimeoutSchedule: timeouts[:i],
6238 },
6239 },
6240 resumeSession: true,
6241 })
6242 }
6243
6244 // Test that exceeding the timeout schedule hits a read
6245 // timeout.
6246 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006247 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006248 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006249 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006250 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006251 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006252 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006253 },
6254 },
6255 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006256 shouldFail: true,
6257 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006258 })
David Benjamin585d7a42016-06-02 14:58:00 -04006259
6260 if async {
6261 // Test that timeout handling has a fudge factor, due to API
6262 // problems.
6263 tests = append(tests, testCase{
6264 protocol: dtls,
6265 name: "DTLS-Retransmit-Fudge",
6266 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006267 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006268 Bugs: ProtocolBugs{
6269 TimeoutSchedule: []time.Duration{
6270 timeouts[0] - 10*time.Millisecond,
6271 },
6272 },
6273 },
6274 resumeSession: true,
6275 })
6276 }
6277
6278 // Test that the final Finished retransmitting isn't
6279 // duplicated if the peer badly fragments everything.
6280 tests = append(tests, testCase{
6281 testType: serverTest,
6282 protocol: dtls,
6283 name: "DTLS-Retransmit-Fragmented",
6284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006285 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006286 Bugs: ProtocolBugs{
6287 TimeoutSchedule: []time.Duration{timeouts[0]},
6288 MaxHandshakeRecordLength: 2,
6289 },
6290 },
6291 })
6292
6293 // Test the timeout schedule when a shorter initial timeout duration is set.
6294 tests = append(tests, testCase{
6295 protocol: dtls,
6296 name: "DTLS-Retransmit-Short-Client",
6297 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006298 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006299 Bugs: ProtocolBugs{
6300 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6301 },
6302 },
6303 resumeSession: true,
6304 flags: []string{"-initial-timeout-duration-ms", "250"},
6305 })
6306 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006307 protocol: dtls,
6308 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006309 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006310 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006311 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006312 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006313 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006314 },
6315 },
6316 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006317 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006318 })
David Benjamin585d7a42016-06-02 14:58:00 -04006319
6320 for _, test := range tests {
6321 if async {
6322 test.name += "-Async"
6323 test.flags = append(test.flags, "-async")
6324 }
6325
6326 testCases = append(testCases, test)
6327 }
David Benjamin83f90402015-01-27 01:09:43 -05006328 }
David Benjamin83f90402015-01-27 01:09:43 -05006329}
6330
David Benjaminc565ebb2015-04-03 04:06:36 -04006331func addExportKeyingMaterialTests() {
6332 for _, vers := range tlsVersions {
6333 if vers.version == VersionSSL30 {
6334 continue
6335 }
6336 testCases = append(testCases, testCase{
6337 name: "ExportKeyingMaterial-" + vers.name,
6338 config: Config{
6339 MaxVersion: vers.version,
6340 },
6341 exportKeyingMaterial: 1024,
6342 exportLabel: "label",
6343 exportContext: "context",
6344 useExportContext: true,
6345 })
6346 testCases = append(testCases, testCase{
6347 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6348 config: Config{
6349 MaxVersion: vers.version,
6350 },
6351 exportKeyingMaterial: 1024,
6352 })
6353 testCases = append(testCases, testCase{
6354 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6355 config: Config{
6356 MaxVersion: vers.version,
6357 },
6358 exportKeyingMaterial: 1024,
6359 useExportContext: true,
6360 })
6361 testCases = append(testCases, testCase{
6362 name: "ExportKeyingMaterial-Small-" + vers.name,
6363 config: Config{
6364 MaxVersion: vers.version,
6365 },
6366 exportKeyingMaterial: 1,
6367 exportLabel: "label",
6368 exportContext: "context",
6369 useExportContext: true,
6370 })
6371 }
6372 testCases = append(testCases, testCase{
6373 name: "ExportKeyingMaterial-SSL3",
6374 config: Config{
6375 MaxVersion: VersionSSL30,
6376 },
6377 exportKeyingMaterial: 1024,
6378 exportLabel: "label",
6379 exportContext: "context",
6380 useExportContext: true,
6381 shouldFail: true,
6382 expectedError: "failed to export keying material",
6383 })
6384}
6385
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006386func addTLSUniqueTests() {
6387 for _, isClient := range []bool{false, true} {
6388 for _, isResumption := range []bool{false, true} {
6389 for _, hasEMS := range []bool{false, true} {
6390 var suffix string
6391 if isResumption {
6392 suffix = "Resume-"
6393 } else {
6394 suffix = "Full-"
6395 }
6396
6397 if hasEMS {
6398 suffix += "EMS-"
6399 } else {
6400 suffix += "NoEMS-"
6401 }
6402
6403 if isClient {
6404 suffix += "Client"
6405 } else {
6406 suffix += "Server"
6407 }
6408
6409 test := testCase{
6410 name: "TLSUnique-" + suffix,
6411 testTLSUnique: true,
6412 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006413 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006414 Bugs: ProtocolBugs{
6415 NoExtendedMasterSecret: !hasEMS,
6416 },
6417 },
6418 }
6419
6420 if isResumption {
6421 test.resumeSession = true
6422 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006423 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006424 Bugs: ProtocolBugs{
6425 NoExtendedMasterSecret: !hasEMS,
6426 },
6427 }
6428 }
6429
6430 if isResumption && !hasEMS {
6431 test.shouldFail = true
6432 test.expectedError = "failed to get tls-unique"
6433 }
6434
6435 testCases = append(testCases, test)
6436 }
6437 }
6438 }
6439}
6440
Adam Langley09505632015-07-30 18:10:13 -07006441func addCustomExtensionTests() {
6442 expectedContents := "custom extension"
6443 emptyString := ""
6444
6445 for _, isClient := range []bool{false, true} {
6446 suffix := "Server"
6447 flag := "-enable-server-custom-extension"
6448 testType := serverTest
6449 if isClient {
6450 suffix = "Client"
6451 flag = "-enable-client-custom-extension"
6452 testType = clientTest
6453 }
6454
6455 testCases = append(testCases, testCase{
6456 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006457 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006459 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006460 Bugs: ProtocolBugs{
6461 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006462 ExpectedCustomExtension: &expectedContents,
6463 },
6464 },
6465 flags: []string{flag},
6466 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006467 testCases = append(testCases, testCase{
6468 testType: testType,
6469 name: "CustomExtensions-" + suffix + "-TLS13",
6470 config: Config{
6471 MaxVersion: VersionTLS13,
6472 Bugs: ProtocolBugs{
6473 CustomExtension: expectedContents,
6474 ExpectedCustomExtension: &expectedContents,
6475 },
6476 },
6477 flags: []string{flag},
6478 })
Adam Langley09505632015-07-30 18:10:13 -07006479
6480 // If the parse callback fails, the handshake should also fail.
6481 testCases = append(testCases, testCase{
6482 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006483 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006484 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006485 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006486 Bugs: ProtocolBugs{
6487 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006488 ExpectedCustomExtension: &expectedContents,
6489 },
6490 },
David Benjamin399e7c92015-07-30 23:01:27 -04006491 flags: []string{flag},
6492 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006493 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6494 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006495 testCases = append(testCases, testCase{
6496 testType: testType,
6497 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6498 config: Config{
6499 MaxVersion: VersionTLS13,
6500 Bugs: ProtocolBugs{
6501 CustomExtension: expectedContents + "foo",
6502 ExpectedCustomExtension: &expectedContents,
6503 },
6504 },
6505 flags: []string{flag},
6506 shouldFail: true,
6507 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6508 })
Adam Langley09505632015-07-30 18:10:13 -07006509
6510 // If the add callback fails, the handshake should also fail.
6511 testCases = append(testCases, testCase{
6512 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006513 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006514 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006515 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006516 Bugs: ProtocolBugs{
6517 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006518 ExpectedCustomExtension: &expectedContents,
6519 },
6520 },
David Benjamin399e7c92015-07-30 23:01:27 -04006521 flags: []string{flag, "-custom-extension-fail-add"},
6522 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006523 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6524 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006525 testCases = append(testCases, testCase{
6526 testType: testType,
6527 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6528 config: Config{
6529 MaxVersion: VersionTLS13,
6530 Bugs: ProtocolBugs{
6531 CustomExtension: expectedContents,
6532 ExpectedCustomExtension: &expectedContents,
6533 },
6534 },
6535 flags: []string{flag, "-custom-extension-fail-add"},
6536 shouldFail: true,
6537 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6538 })
Adam Langley09505632015-07-30 18:10:13 -07006539
6540 // If the add callback returns zero, no extension should be
6541 // added.
6542 skipCustomExtension := expectedContents
6543 if isClient {
6544 // For the case where the client skips sending the
6545 // custom extension, the server must not “echo” it.
6546 skipCustomExtension = ""
6547 }
6548 testCases = append(testCases, testCase{
6549 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006550 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006551 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006552 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006553 Bugs: ProtocolBugs{
6554 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006555 ExpectedCustomExtension: &emptyString,
6556 },
6557 },
6558 flags: []string{flag, "-custom-extension-skip"},
6559 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006560 testCases = append(testCases, testCase{
6561 testType: testType,
6562 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6563 config: Config{
6564 MaxVersion: VersionTLS13,
6565 Bugs: ProtocolBugs{
6566 CustomExtension: skipCustomExtension,
6567 ExpectedCustomExtension: &emptyString,
6568 },
6569 },
6570 flags: []string{flag, "-custom-extension-skip"},
6571 })
Adam Langley09505632015-07-30 18:10:13 -07006572 }
6573
6574 // The custom extension add callback should not be called if the client
6575 // doesn't send the extension.
6576 testCases = append(testCases, testCase{
6577 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006578 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006579 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006580 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006581 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006582 ExpectedCustomExtension: &emptyString,
6583 },
6584 },
6585 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6586 })
Adam Langley2deb9842015-08-07 11:15:37 -07006587
Steven Valdez143e8b32016-07-11 13:19:03 -04006588 testCases = append(testCases, testCase{
6589 testType: serverTest,
6590 name: "CustomExtensions-NotCalled-Server-TLS13",
6591 config: Config{
6592 MaxVersion: VersionTLS13,
6593 Bugs: ProtocolBugs{
6594 ExpectedCustomExtension: &emptyString,
6595 },
6596 },
6597 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6598 })
6599
Adam Langley2deb9842015-08-07 11:15:37 -07006600 // Test an unknown extension from the server.
6601 testCases = append(testCases, testCase{
6602 testType: clientTest,
6603 name: "UnknownExtension-Client",
6604 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006605 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006606 Bugs: ProtocolBugs{
6607 CustomExtension: expectedContents,
6608 },
6609 },
David Benjamin0c40a962016-08-01 12:05:50 -04006610 shouldFail: true,
6611 expectedError: ":UNEXPECTED_EXTENSION:",
6612 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006613 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006614 testCases = append(testCases, testCase{
6615 testType: clientTest,
6616 name: "UnknownExtension-Client-TLS13",
6617 config: Config{
6618 MaxVersion: VersionTLS13,
6619 Bugs: ProtocolBugs{
6620 CustomExtension: expectedContents,
6621 },
6622 },
David Benjamin0c40a962016-08-01 12:05:50 -04006623 shouldFail: true,
6624 expectedError: ":UNEXPECTED_EXTENSION:",
6625 expectedLocalError: "remote error: unsupported extension",
6626 })
6627
6628 // Test a known but unoffered extension from the server.
6629 testCases = append(testCases, testCase{
6630 testType: clientTest,
6631 name: "UnofferedExtension-Client",
6632 config: Config{
6633 MaxVersion: VersionTLS12,
6634 Bugs: ProtocolBugs{
6635 SendALPN: "alpn",
6636 },
6637 },
6638 shouldFail: true,
6639 expectedError: ":UNEXPECTED_EXTENSION:",
6640 expectedLocalError: "remote error: unsupported extension",
6641 })
6642 testCases = append(testCases, testCase{
6643 testType: clientTest,
6644 name: "UnofferedExtension-Client-TLS13",
6645 config: Config{
6646 MaxVersion: VersionTLS13,
6647 Bugs: ProtocolBugs{
6648 SendALPN: "alpn",
6649 },
6650 },
6651 shouldFail: true,
6652 expectedError: ":UNEXPECTED_EXTENSION:",
6653 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006654 })
Adam Langley09505632015-07-30 18:10:13 -07006655}
6656
David Benjaminb36a3952015-12-01 18:53:13 -05006657func addRSAClientKeyExchangeTests() {
6658 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6659 testCases = append(testCases, testCase{
6660 testType: serverTest,
6661 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6662 config: Config{
6663 // Ensure the ClientHello version and final
6664 // version are different, to detect if the
6665 // server uses the wrong one.
6666 MaxVersion: VersionTLS11,
6667 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
6668 Bugs: ProtocolBugs{
6669 BadRSAClientKeyExchange: bad,
6670 },
6671 },
6672 shouldFail: true,
6673 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6674 })
6675 }
6676}
6677
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006678var testCurves = []struct {
6679 name string
6680 id CurveID
6681}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006682 {"P-256", CurveP256},
6683 {"P-384", CurveP384},
6684 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006685 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006686}
6687
Steven Valdez5440fe02016-07-18 12:40:30 -04006688const bogusCurve = 0x1234
6689
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006690func addCurveTests() {
6691 for _, curve := range testCurves {
6692 testCases = append(testCases, testCase{
6693 name: "CurveTest-Client-" + 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 })
6702 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006703 name: "CurveTest-Client-" + curve.name + "-TLS13",
6704 config: Config{
6705 MaxVersion: VersionTLS13,
6706 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6707 CurvePreferences: []CurveID{curve.id},
6708 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006709 flags: []string{"-enable-all-curves"},
6710 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006711 })
6712 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006713 testType: serverTest,
6714 name: "CurveTest-Server-" + curve.name,
6715 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006716 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006717 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6718 CurvePreferences: []CurveID{curve.id},
6719 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006720 flags: []string{"-enable-all-curves"},
6721 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006722 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006723 testCases = append(testCases, testCase{
6724 testType: serverTest,
6725 name: "CurveTest-Server-" + curve.name + "-TLS13",
6726 config: Config{
6727 MaxVersion: VersionTLS13,
6728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6729 CurvePreferences: []CurveID{curve.id},
6730 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006731 flags: []string{"-enable-all-curves"},
6732 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006733 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006734 }
David Benjamin241ae832016-01-15 03:04:54 -05006735
6736 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05006737 testCases = append(testCases, testCase{
6738 testType: serverTest,
6739 name: "UnknownCurve",
6740 config: Config{
6741 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6742 CurvePreferences: []CurveID{bogusCurve, CurveP256},
6743 },
6744 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006745
6746 // The server must not consider ECDHE ciphers when there are no
6747 // supported curves.
6748 testCases = append(testCases, testCase{
6749 testType: serverTest,
6750 name: "NoSupportedCurves",
6751 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006752 MaxVersion: VersionTLS12,
6753 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6754 Bugs: ProtocolBugs{
6755 NoSupportedCurves: true,
6756 },
6757 },
6758 shouldFail: true,
6759 expectedError: ":NO_SHARED_CIPHER:",
6760 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006761 testCases = append(testCases, testCase{
6762 testType: serverTest,
6763 name: "NoSupportedCurves-TLS13",
6764 config: Config{
6765 MaxVersion: VersionTLS13,
6766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6767 Bugs: ProtocolBugs{
6768 NoSupportedCurves: true,
6769 },
6770 },
6771 shouldFail: true,
6772 expectedError: ":NO_SHARED_CIPHER:",
6773 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006774
6775 // The server must fall back to another cipher when there are no
6776 // supported curves.
6777 testCases = append(testCases, testCase{
6778 testType: serverTest,
6779 name: "NoCommonCurves",
6780 config: Config{
6781 MaxVersion: VersionTLS12,
6782 CipherSuites: []uint16{
6783 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6784 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6785 },
6786 CurvePreferences: []CurveID{CurveP224},
6787 },
6788 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
6789 })
6790
6791 // The client must reject bogus curves and disabled curves.
6792 testCases = append(testCases, testCase{
6793 name: "BadECDHECurve",
6794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006795 MaxVersion: VersionTLS12,
6796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6797 Bugs: ProtocolBugs{
6798 SendCurve: bogusCurve,
6799 },
6800 },
6801 shouldFail: true,
6802 expectedError: ":WRONG_CURVE:",
6803 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006804 testCases = append(testCases, testCase{
6805 name: "BadECDHECurve-TLS13",
6806 config: Config{
6807 MaxVersion: VersionTLS13,
6808 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6809 Bugs: ProtocolBugs{
6810 SendCurve: bogusCurve,
6811 },
6812 },
6813 shouldFail: true,
6814 expectedError: ":WRONG_CURVE:",
6815 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006816
6817 testCases = append(testCases, testCase{
6818 name: "UnsupportedCurve",
6819 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006820 MaxVersion: VersionTLS12,
6821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6822 CurvePreferences: []CurveID{CurveP256},
6823 Bugs: ProtocolBugs{
6824 IgnorePeerCurvePreferences: true,
6825 },
6826 },
6827 flags: []string{"-p384-only"},
6828 shouldFail: true,
6829 expectedError: ":WRONG_CURVE:",
6830 })
6831
David Benjamin4f921572016-07-17 14:20:10 +02006832 testCases = append(testCases, testCase{
6833 // TODO(davidben): Add a TLS 1.3 version where
6834 // HelloRetryRequest requests an unsupported curve.
6835 name: "UnsupportedCurve-ServerHello-TLS13",
6836 config: Config{
6837 MaxVersion: VersionTLS12,
6838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6839 CurvePreferences: []CurveID{CurveP384},
6840 Bugs: ProtocolBugs{
6841 SendCurve: CurveP256,
6842 },
6843 },
6844 flags: []string{"-p384-only"},
6845 shouldFail: true,
6846 expectedError: ":WRONG_CURVE:",
6847 })
6848
David Benjamin4c3ddf72016-06-29 18:13:53 -04006849 // Test invalid curve points.
6850 testCases = append(testCases, testCase{
6851 name: "InvalidECDHPoint-Client",
6852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006853 MaxVersion: VersionTLS12,
6854 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6855 CurvePreferences: []CurveID{CurveP256},
6856 Bugs: ProtocolBugs{
6857 InvalidECDHPoint: true,
6858 },
6859 },
6860 shouldFail: true,
6861 expectedError: ":INVALID_ENCODING:",
6862 })
6863 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006864 name: "InvalidECDHPoint-Client-TLS13",
6865 config: Config{
6866 MaxVersion: VersionTLS13,
6867 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6868 CurvePreferences: []CurveID{CurveP256},
6869 Bugs: ProtocolBugs{
6870 InvalidECDHPoint: true,
6871 },
6872 },
6873 shouldFail: true,
6874 expectedError: ":INVALID_ENCODING:",
6875 })
6876 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006877 testType: serverTest,
6878 name: "InvalidECDHPoint-Server",
6879 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006880 MaxVersion: VersionTLS12,
6881 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6882 CurvePreferences: []CurveID{CurveP256},
6883 Bugs: ProtocolBugs{
6884 InvalidECDHPoint: true,
6885 },
6886 },
6887 shouldFail: true,
6888 expectedError: ":INVALID_ENCODING:",
6889 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006890 testCases = append(testCases, testCase{
6891 testType: serverTest,
6892 name: "InvalidECDHPoint-Server-TLS13",
6893 config: Config{
6894 MaxVersion: VersionTLS13,
6895 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6896 CurvePreferences: []CurveID{CurveP256},
6897 Bugs: ProtocolBugs{
6898 InvalidECDHPoint: true,
6899 },
6900 },
6901 shouldFail: true,
6902 expectedError: ":INVALID_ENCODING:",
6903 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006904}
6905
Matt Braithwaite54217e42016-06-13 13:03:47 -07006906func addCECPQ1Tests() {
6907 testCases = append(testCases, testCase{
6908 testType: clientTest,
6909 name: "CECPQ1-Client-BadX25519Part",
6910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006911 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006912 MinVersion: VersionTLS12,
6913 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6914 Bugs: ProtocolBugs{
6915 CECPQ1BadX25519Part: true,
6916 },
6917 },
6918 flags: []string{"-cipher", "kCECPQ1"},
6919 shouldFail: true,
6920 expectedLocalError: "local error: bad record MAC",
6921 })
6922 testCases = append(testCases, testCase{
6923 testType: clientTest,
6924 name: "CECPQ1-Client-BadNewhopePart",
6925 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006926 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006927 MinVersion: VersionTLS12,
6928 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6929 Bugs: ProtocolBugs{
6930 CECPQ1BadNewhopePart: true,
6931 },
6932 },
6933 flags: []string{"-cipher", "kCECPQ1"},
6934 shouldFail: true,
6935 expectedLocalError: "local error: bad record MAC",
6936 })
6937 testCases = append(testCases, testCase{
6938 testType: serverTest,
6939 name: "CECPQ1-Server-BadX25519Part",
6940 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006941 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006942 MinVersion: VersionTLS12,
6943 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6944 Bugs: ProtocolBugs{
6945 CECPQ1BadX25519Part: true,
6946 },
6947 },
6948 flags: []string{"-cipher", "kCECPQ1"},
6949 shouldFail: true,
6950 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6951 })
6952 testCases = append(testCases, testCase{
6953 testType: serverTest,
6954 name: "CECPQ1-Server-BadNewhopePart",
6955 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006956 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07006957 MinVersion: VersionTLS12,
6958 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
6959 Bugs: ProtocolBugs{
6960 CECPQ1BadNewhopePart: true,
6961 },
6962 },
6963 flags: []string{"-cipher", "kCECPQ1"},
6964 shouldFail: true,
6965 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6966 })
6967}
6968
David Benjamin4cc36ad2015-12-19 14:23:26 -05006969func addKeyExchangeInfoTests() {
6970 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05006971 name: "KeyExchangeInfo-DHE-Client",
6972 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006973 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006974 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6975 Bugs: ProtocolBugs{
6976 // This is a 1234-bit prime number, generated
6977 // with:
6978 // openssl gendh 1234 | openssl asn1parse -i
6979 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
6980 },
6981 },
David Benjamin9e68f192016-06-30 14:55:33 -04006982 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006983 })
6984 testCases = append(testCases, testCase{
6985 testType: serverTest,
6986 name: "KeyExchangeInfo-DHE-Server",
6987 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006988 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006989 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
6990 },
6991 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04006992 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05006993 })
6994
6995 testCases = append(testCases, testCase{
6996 name: "KeyExchangeInfo-ECDHE-Client",
6997 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006998 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05006999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7000 CurvePreferences: []CurveID{CurveX25519},
7001 },
David Benjamin9e68f192016-06-30 14:55:33 -04007002 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007003 })
7004 testCases = append(testCases, testCase{
7005 testType: serverTest,
7006 name: "KeyExchangeInfo-ECDHE-Server",
7007 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007008 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007009 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7010 CurvePreferences: []CurveID{CurveX25519},
7011 },
David Benjamin9e68f192016-06-30 14:55:33 -04007012 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007013 })
7014}
7015
David Benjaminc9ae27c2016-06-24 22:56:37 -04007016func addTLS13RecordTests() {
7017 testCases = append(testCases, testCase{
7018 name: "TLS13-RecordPadding",
7019 config: Config{
7020 MaxVersion: VersionTLS13,
7021 MinVersion: VersionTLS13,
7022 Bugs: ProtocolBugs{
7023 RecordPadding: 10,
7024 },
7025 },
7026 })
7027
7028 testCases = append(testCases, testCase{
7029 name: "TLS13-EmptyRecords",
7030 config: Config{
7031 MaxVersion: VersionTLS13,
7032 MinVersion: VersionTLS13,
7033 Bugs: ProtocolBugs{
7034 OmitRecordContents: true,
7035 },
7036 },
7037 shouldFail: true,
7038 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7039 })
7040
7041 testCases = append(testCases, testCase{
7042 name: "TLS13-OnlyPadding",
7043 config: Config{
7044 MaxVersion: VersionTLS13,
7045 MinVersion: VersionTLS13,
7046 Bugs: ProtocolBugs{
7047 OmitRecordContents: true,
7048 RecordPadding: 10,
7049 },
7050 },
7051 shouldFail: true,
7052 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7053 })
7054
7055 testCases = append(testCases, testCase{
7056 name: "TLS13-WrongOuterRecord",
7057 config: Config{
7058 MaxVersion: VersionTLS13,
7059 MinVersion: VersionTLS13,
7060 Bugs: ProtocolBugs{
7061 OuterRecordType: recordTypeHandshake,
7062 },
7063 },
7064 shouldFail: true,
7065 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7066 })
7067}
7068
David Benjamin82261be2016-07-07 14:32:50 -07007069func addChangeCipherSpecTests() {
7070 // Test missing ChangeCipherSpecs.
7071 testCases = append(testCases, testCase{
7072 name: "SkipChangeCipherSpec-Client",
7073 config: Config{
7074 MaxVersion: VersionTLS12,
7075 Bugs: ProtocolBugs{
7076 SkipChangeCipherSpec: true,
7077 },
7078 },
7079 shouldFail: true,
7080 expectedError: ":UNEXPECTED_RECORD:",
7081 })
7082 testCases = append(testCases, testCase{
7083 testType: serverTest,
7084 name: "SkipChangeCipherSpec-Server",
7085 config: Config{
7086 MaxVersion: VersionTLS12,
7087 Bugs: ProtocolBugs{
7088 SkipChangeCipherSpec: true,
7089 },
7090 },
7091 shouldFail: true,
7092 expectedError: ":UNEXPECTED_RECORD:",
7093 })
7094 testCases = append(testCases, testCase{
7095 testType: serverTest,
7096 name: "SkipChangeCipherSpec-Server-NPN",
7097 config: Config{
7098 MaxVersion: VersionTLS12,
7099 NextProtos: []string{"bar"},
7100 Bugs: ProtocolBugs{
7101 SkipChangeCipherSpec: true,
7102 },
7103 },
7104 flags: []string{
7105 "-advertise-npn", "\x03foo\x03bar\x03baz",
7106 },
7107 shouldFail: true,
7108 expectedError: ":UNEXPECTED_RECORD:",
7109 })
7110
7111 // Test synchronization between the handshake and ChangeCipherSpec.
7112 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7113 // rejected. Test both with and without handshake packing to handle both
7114 // when the partial post-CCS message is in its own record and when it is
7115 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007116 for _, packed := range []bool{false, true} {
7117 var suffix string
7118 if packed {
7119 suffix = "-Packed"
7120 }
7121
7122 testCases = append(testCases, testCase{
7123 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7124 config: Config{
7125 MaxVersion: VersionTLS12,
7126 Bugs: ProtocolBugs{
7127 FragmentAcrossChangeCipherSpec: true,
7128 PackHandshakeFlight: packed,
7129 },
7130 },
7131 shouldFail: true,
7132 expectedError: ":UNEXPECTED_RECORD:",
7133 })
7134 testCases = append(testCases, testCase{
7135 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7136 config: Config{
7137 MaxVersion: VersionTLS12,
7138 },
7139 resumeSession: true,
7140 resumeConfig: &Config{
7141 MaxVersion: VersionTLS12,
7142 Bugs: ProtocolBugs{
7143 FragmentAcrossChangeCipherSpec: true,
7144 PackHandshakeFlight: packed,
7145 },
7146 },
7147 shouldFail: true,
7148 expectedError: ":UNEXPECTED_RECORD:",
7149 })
7150 testCases = append(testCases, testCase{
7151 testType: serverTest,
7152 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7153 config: Config{
7154 MaxVersion: VersionTLS12,
7155 Bugs: ProtocolBugs{
7156 FragmentAcrossChangeCipherSpec: true,
7157 PackHandshakeFlight: packed,
7158 },
7159 },
7160 shouldFail: true,
7161 expectedError: ":UNEXPECTED_RECORD:",
7162 })
7163 testCases = append(testCases, testCase{
7164 testType: serverTest,
7165 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7166 config: Config{
7167 MaxVersion: VersionTLS12,
7168 },
7169 resumeSession: true,
7170 resumeConfig: &Config{
7171 MaxVersion: VersionTLS12,
7172 Bugs: ProtocolBugs{
7173 FragmentAcrossChangeCipherSpec: true,
7174 PackHandshakeFlight: packed,
7175 },
7176 },
7177 shouldFail: true,
7178 expectedError: ":UNEXPECTED_RECORD:",
7179 })
7180 testCases = append(testCases, testCase{
7181 testType: serverTest,
7182 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7183 config: Config{
7184 MaxVersion: VersionTLS12,
7185 NextProtos: []string{"bar"},
7186 Bugs: ProtocolBugs{
7187 FragmentAcrossChangeCipherSpec: true,
7188 PackHandshakeFlight: packed,
7189 },
7190 },
7191 flags: []string{
7192 "-advertise-npn", "\x03foo\x03bar\x03baz",
7193 },
7194 shouldFail: true,
7195 expectedError: ":UNEXPECTED_RECORD:",
7196 })
7197 }
7198
David Benjamin61672812016-07-14 23:10:43 -04007199 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7200 // messages in the handshake queue. Do this by testing the server
7201 // reading the client Finished, reversing the flight so Finished comes
7202 // first.
7203 testCases = append(testCases, testCase{
7204 protocol: dtls,
7205 testType: serverTest,
7206 name: "SendUnencryptedFinished-DTLS",
7207 config: Config{
7208 MaxVersion: VersionTLS12,
7209 Bugs: ProtocolBugs{
7210 SendUnencryptedFinished: true,
7211 ReverseHandshakeFragments: true,
7212 },
7213 },
7214 shouldFail: true,
7215 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7216 })
7217
Steven Valdez143e8b32016-07-11 13:19:03 -04007218 // Test synchronization between encryption changes and the handshake in
7219 // TLS 1.3, where ChangeCipherSpec is implicit.
7220 testCases = append(testCases, testCase{
7221 name: "PartialEncryptedExtensionsWithServerHello",
7222 config: Config{
7223 MaxVersion: VersionTLS13,
7224 Bugs: ProtocolBugs{
7225 PartialEncryptedExtensionsWithServerHello: true,
7226 },
7227 },
7228 shouldFail: true,
7229 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7230 })
7231 testCases = append(testCases, testCase{
7232 testType: serverTest,
7233 name: "PartialClientFinishedWithClientHello",
7234 config: Config{
7235 MaxVersion: VersionTLS13,
7236 Bugs: ProtocolBugs{
7237 PartialClientFinishedWithClientHello: true,
7238 },
7239 },
7240 shouldFail: true,
7241 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7242 })
7243
David Benjamin82261be2016-07-07 14:32:50 -07007244 // Test that early ChangeCipherSpecs are handled correctly.
7245 testCases = append(testCases, testCase{
7246 testType: serverTest,
7247 name: "EarlyChangeCipherSpec-server-1",
7248 config: Config{
7249 MaxVersion: VersionTLS12,
7250 Bugs: ProtocolBugs{
7251 EarlyChangeCipherSpec: 1,
7252 },
7253 },
7254 shouldFail: true,
7255 expectedError: ":UNEXPECTED_RECORD:",
7256 })
7257 testCases = append(testCases, testCase{
7258 testType: serverTest,
7259 name: "EarlyChangeCipherSpec-server-2",
7260 config: Config{
7261 MaxVersion: VersionTLS12,
7262 Bugs: ProtocolBugs{
7263 EarlyChangeCipherSpec: 2,
7264 },
7265 },
7266 shouldFail: true,
7267 expectedError: ":UNEXPECTED_RECORD:",
7268 })
7269 testCases = append(testCases, testCase{
7270 protocol: dtls,
7271 name: "StrayChangeCipherSpec",
7272 config: Config{
7273 // TODO(davidben): Once DTLS 1.3 exists, test
7274 // that stray ChangeCipherSpec messages are
7275 // rejected.
7276 MaxVersion: VersionTLS12,
7277 Bugs: ProtocolBugs{
7278 StrayChangeCipherSpec: true,
7279 },
7280 },
7281 })
7282
7283 // Test that the contents of ChangeCipherSpec are checked.
7284 testCases = append(testCases, testCase{
7285 name: "BadChangeCipherSpec-1",
7286 config: Config{
7287 MaxVersion: VersionTLS12,
7288 Bugs: ProtocolBugs{
7289 BadChangeCipherSpec: []byte{2},
7290 },
7291 },
7292 shouldFail: true,
7293 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7294 })
7295 testCases = append(testCases, testCase{
7296 name: "BadChangeCipherSpec-2",
7297 config: Config{
7298 MaxVersion: VersionTLS12,
7299 Bugs: ProtocolBugs{
7300 BadChangeCipherSpec: []byte{1, 1},
7301 },
7302 },
7303 shouldFail: true,
7304 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7305 })
7306 testCases = append(testCases, testCase{
7307 protocol: dtls,
7308 name: "BadChangeCipherSpec-DTLS-1",
7309 config: Config{
7310 MaxVersion: VersionTLS12,
7311 Bugs: ProtocolBugs{
7312 BadChangeCipherSpec: []byte{2},
7313 },
7314 },
7315 shouldFail: true,
7316 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7317 })
7318 testCases = append(testCases, testCase{
7319 protocol: dtls,
7320 name: "BadChangeCipherSpec-DTLS-2",
7321 config: Config{
7322 MaxVersion: VersionTLS12,
7323 Bugs: ProtocolBugs{
7324 BadChangeCipherSpec: []byte{1, 1},
7325 },
7326 },
7327 shouldFail: true,
7328 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7329 })
7330}
7331
David Benjamin0b8d5da2016-07-15 00:39:56 -04007332func addWrongMessageTypeTests() {
7333 for _, protocol := range []protocol{tls, dtls} {
7334 var suffix string
7335 if protocol == dtls {
7336 suffix = "-DTLS"
7337 }
7338
7339 testCases = append(testCases, testCase{
7340 protocol: protocol,
7341 testType: serverTest,
7342 name: "WrongMessageType-ClientHello" + suffix,
7343 config: Config{
7344 MaxVersion: VersionTLS12,
7345 Bugs: ProtocolBugs{
7346 SendWrongMessageType: typeClientHello,
7347 },
7348 },
7349 shouldFail: true,
7350 expectedError: ":UNEXPECTED_MESSAGE:",
7351 expectedLocalError: "remote error: unexpected message",
7352 })
7353
7354 if protocol == dtls {
7355 testCases = append(testCases, testCase{
7356 protocol: protocol,
7357 name: "WrongMessageType-HelloVerifyRequest" + suffix,
7358 config: Config{
7359 MaxVersion: VersionTLS12,
7360 Bugs: ProtocolBugs{
7361 SendWrongMessageType: typeHelloVerifyRequest,
7362 },
7363 },
7364 shouldFail: true,
7365 expectedError: ":UNEXPECTED_MESSAGE:",
7366 expectedLocalError: "remote error: unexpected message",
7367 })
7368 }
7369
7370 testCases = append(testCases, testCase{
7371 protocol: protocol,
7372 name: "WrongMessageType-ServerHello" + suffix,
7373 config: Config{
7374 MaxVersion: VersionTLS12,
7375 Bugs: ProtocolBugs{
7376 SendWrongMessageType: typeServerHello,
7377 },
7378 },
7379 shouldFail: true,
7380 expectedError: ":UNEXPECTED_MESSAGE:",
7381 expectedLocalError: "remote error: unexpected message",
7382 })
7383
7384 testCases = append(testCases, testCase{
7385 protocol: protocol,
7386 name: "WrongMessageType-ServerCertificate" + suffix,
7387 config: Config{
7388 MaxVersion: VersionTLS12,
7389 Bugs: ProtocolBugs{
7390 SendWrongMessageType: typeCertificate,
7391 },
7392 },
7393 shouldFail: true,
7394 expectedError: ":UNEXPECTED_MESSAGE:",
7395 expectedLocalError: "remote error: unexpected message",
7396 })
7397
7398 testCases = append(testCases, testCase{
7399 protocol: protocol,
7400 name: "WrongMessageType-CertificateStatus" + suffix,
7401 config: Config{
7402 MaxVersion: VersionTLS12,
7403 Bugs: ProtocolBugs{
7404 SendWrongMessageType: typeCertificateStatus,
7405 },
7406 },
7407 flags: []string{"-enable-ocsp-stapling"},
7408 shouldFail: true,
7409 expectedError: ":UNEXPECTED_MESSAGE:",
7410 expectedLocalError: "remote error: unexpected message",
7411 })
7412
7413 testCases = append(testCases, testCase{
7414 protocol: protocol,
7415 name: "WrongMessageType-ServerKeyExchange" + suffix,
7416 config: Config{
7417 MaxVersion: VersionTLS12,
7418 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7419 Bugs: ProtocolBugs{
7420 SendWrongMessageType: typeServerKeyExchange,
7421 },
7422 },
7423 shouldFail: true,
7424 expectedError: ":UNEXPECTED_MESSAGE:",
7425 expectedLocalError: "remote error: unexpected message",
7426 })
7427
7428 testCases = append(testCases, testCase{
7429 protocol: protocol,
7430 name: "WrongMessageType-CertificateRequest" + suffix,
7431 config: Config{
7432 MaxVersion: VersionTLS12,
7433 ClientAuth: RequireAnyClientCert,
7434 Bugs: ProtocolBugs{
7435 SendWrongMessageType: typeCertificateRequest,
7436 },
7437 },
7438 shouldFail: true,
7439 expectedError: ":UNEXPECTED_MESSAGE:",
7440 expectedLocalError: "remote error: unexpected message",
7441 })
7442
7443 testCases = append(testCases, testCase{
7444 protocol: protocol,
7445 name: "WrongMessageType-ServerHelloDone" + suffix,
7446 config: Config{
7447 MaxVersion: VersionTLS12,
7448 Bugs: ProtocolBugs{
7449 SendWrongMessageType: typeServerHelloDone,
7450 },
7451 },
7452 shouldFail: true,
7453 expectedError: ":UNEXPECTED_MESSAGE:",
7454 expectedLocalError: "remote error: unexpected message",
7455 })
7456
7457 testCases = append(testCases, testCase{
7458 testType: serverTest,
7459 protocol: protocol,
7460 name: "WrongMessageType-ClientCertificate" + suffix,
7461 config: Config{
7462 Certificates: []Certificate{rsaCertificate},
7463 MaxVersion: VersionTLS12,
7464 Bugs: ProtocolBugs{
7465 SendWrongMessageType: typeCertificate,
7466 },
7467 },
7468 flags: []string{"-require-any-client-certificate"},
7469 shouldFail: true,
7470 expectedError: ":UNEXPECTED_MESSAGE:",
7471 expectedLocalError: "remote error: unexpected message",
7472 })
7473
7474 testCases = append(testCases, testCase{
7475 testType: serverTest,
7476 protocol: protocol,
7477 name: "WrongMessageType-CertificateVerify" + suffix,
7478 config: Config{
7479 Certificates: []Certificate{rsaCertificate},
7480 MaxVersion: VersionTLS12,
7481 Bugs: ProtocolBugs{
7482 SendWrongMessageType: typeCertificateVerify,
7483 },
7484 },
7485 flags: []string{"-require-any-client-certificate"},
7486 shouldFail: true,
7487 expectedError: ":UNEXPECTED_MESSAGE:",
7488 expectedLocalError: "remote error: unexpected message",
7489 })
7490
7491 testCases = append(testCases, testCase{
7492 testType: serverTest,
7493 protocol: protocol,
7494 name: "WrongMessageType-ClientKeyExchange" + suffix,
7495 config: Config{
7496 MaxVersion: VersionTLS12,
7497 Bugs: ProtocolBugs{
7498 SendWrongMessageType: typeClientKeyExchange,
7499 },
7500 },
7501 shouldFail: true,
7502 expectedError: ":UNEXPECTED_MESSAGE:",
7503 expectedLocalError: "remote error: unexpected message",
7504 })
7505
7506 if protocol != dtls {
7507 testCases = append(testCases, testCase{
7508 testType: serverTest,
7509 protocol: protocol,
7510 name: "WrongMessageType-NextProtocol" + suffix,
7511 config: Config{
7512 MaxVersion: VersionTLS12,
7513 NextProtos: []string{"bar"},
7514 Bugs: ProtocolBugs{
7515 SendWrongMessageType: typeNextProtocol,
7516 },
7517 },
7518 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
7519 shouldFail: true,
7520 expectedError: ":UNEXPECTED_MESSAGE:",
7521 expectedLocalError: "remote error: unexpected message",
7522 })
7523
7524 testCases = append(testCases, testCase{
7525 testType: serverTest,
7526 protocol: protocol,
7527 name: "WrongMessageType-ChannelID" + suffix,
7528 config: Config{
7529 MaxVersion: VersionTLS12,
7530 ChannelID: channelIDKey,
7531 Bugs: ProtocolBugs{
7532 SendWrongMessageType: typeChannelID,
7533 },
7534 },
7535 flags: []string{
7536 "-expect-channel-id",
7537 base64.StdEncoding.EncodeToString(channelIDBytes),
7538 },
7539 shouldFail: true,
7540 expectedError: ":UNEXPECTED_MESSAGE:",
7541 expectedLocalError: "remote error: unexpected message",
7542 })
7543 }
7544
7545 testCases = append(testCases, testCase{
7546 testType: serverTest,
7547 protocol: protocol,
7548 name: "WrongMessageType-ClientFinished" + suffix,
7549 config: Config{
7550 MaxVersion: VersionTLS12,
7551 Bugs: ProtocolBugs{
7552 SendWrongMessageType: typeFinished,
7553 },
7554 },
7555 shouldFail: true,
7556 expectedError: ":UNEXPECTED_MESSAGE:",
7557 expectedLocalError: "remote error: unexpected message",
7558 })
7559
7560 testCases = append(testCases, testCase{
7561 protocol: protocol,
7562 name: "WrongMessageType-NewSessionTicket" + suffix,
7563 config: Config{
7564 MaxVersion: VersionTLS12,
7565 Bugs: ProtocolBugs{
7566 SendWrongMessageType: typeNewSessionTicket,
7567 },
7568 },
7569 shouldFail: true,
7570 expectedError: ":UNEXPECTED_MESSAGE:",
7571 expectedLocalError: "remote error: unexpected message",
7572 })
7573
7574 testCases = append(testCases, testCase{
7575 protocol: protocol,
7576 name: "WrongMessageType-ServerFinished" + suffix,
7577 config: Config{
7578 MaxVersion: VersionTLS12,
7579 Bugs: ProtocolBugs{
7580 SendWrongMessageType: typeFinished,
7581 },
7582 },
7583 shouldFail: true,
7584 expectedError: ":UNEXPECTED_MESSAGE:",
7585 expectedLocalError: "remote error: unexpected message",
7586 })
7587
7588 }
7589}
7590
Steven Valdez143e8b32016-07-11 13:19:03 -04007591func addTLS13WrongMessageTypeTests() {
7592 testCases = append(testCases, testCase{
7593 testType: serverTest,
7594 name: "WrongMessageType-TLS13-ClientHello",
7595 config: Config{
7596 MaxVersion: VersionTLS13,
7597 Bugs: ProtocolBugs{
7598 SendWrongMessageType: typeClientHello,
7599 },
7600 },
7601 shouldFail: true,
7602 expectedError: ":UNEXPECTED_MESSAGE:",
7603 expectedLocalError: "remote error: unexpected message",
7604 })
7605
7606 testCases = append(testCases, testCase{
7607 name: "WrongMessageType-TLS13-ServerHello",
7608 config: Config{
7609 MaxVersion: VersionTLS13,
7610 Bugs: ProtocolBugs{
7611 SendWrongMessageType: typeServerHello,
7612 },
7613 },
7614 shouldFail: true,
7615 expectedError: ":UNEXPECTED_MESSAGE:",
7616 // The alert comes in with the wrong encryption.
7617 expectedLocalError: "local error: bad record MAC",
7618 })
7619
7620 testCases = append(testCases, testCase{
7621 name: "WrongMessageType-TLS13-EncryptedExtensions",
7622 config: Config{
7623 MaxVersion: VersionTLS13,
7624 Bugs: ProtocolBugs{
7625 SendWrongMessageType: typeEncryptedExtensions,
7626 },
7627 },
7628 shouldFail: true,
7629 expectedError: ":UNEXPECTED_MESSAGE:",
7630 expectedLocalError: "remote error: unexpected message",
7631 })
7632
7633 testCases = append(testCases, testCase{
7634 name: "WrongMessageType-TLS13-CertificateRequest",
7635 config: Config{
7636 MaxVersion: VersionTLS13,
7637 ClientAuth: RequireAnyClientCert,
7638 Bugs: ProtocolBugs{
7639 SendWrongMessageType: typeCertificateRequest,
7640 },
7641 },
7642 shouldFail: true,
7643 expectedError: ":UNEXPECTED_MESSAGE:",
7644 expectedLocalError: "remote error: unexpected message",
7645 })
7646
7647 testCases = append(testCases, testCase{
7648 name: "WrongMessageType-TLS13-ServerCertificate",
7649 config: Config{
7650 MaxVersion: VersionTLS13,
7651 Bugs: ProtocolBugs{
7652 SendWrongMessageType: typeCertificate,
7653 },
7654 },
7655 shouldFail: true,
7656 expectedError: ":UNEXPECTED_MESSAGE:",
7657 expectedLocalError: "remote error: unexpected message",
7658 })
7659
7660 testCases = append(testCases, testCase{
7661 name: "WrongMessageType-TLS13-ServerCertificateVerify",
7662 config: Config{
7663 MaxVersion: VersionTLS13,
7664 Bugs: ProtocolBugs{
7665 SendWrongMessageType: typeCertificateVerify,
7666 },
7667 },
7668 shouldFail: true,
7669 expectedError: ":UNEXPECTED_MESSAGE:",
7670 expectedLocalError: "remote error: unexpected message",
7671 })
7672
7673 testCases = append(testCases, testCase{
7674 name: "WrongMessageType-TLS13-ServerFinished",
7675 config: Config{
7676 MaxVersion: VersionTLS13,
7677 Bugs: ProtocolBugs{
7678 SendWrongMessageType: typeFinished,
7679 },
7680 },
7681 shouldFail: true,
7682 expectedError: ":UNEXPECTED_MESSAGE:",
7683 expectedLocalError: "remote error: unexpected message",
7684 })
7685
7686 testCases = append(testCases, testCase{
7687 testType: serverTest,
7688 name: "WrongMessageType-TLS13-ClientCertificate",
7689 config: Config{
7690 Certificates: []Certificate{rsaCertificate},
7691 MaxVersion: VersionTLS13,
7692 Bugs: ProtocolBugs{
7693 SendWrongMessageType: typeCertificate,
7694 },
7695 },
7696 flags: []string{"-require-any-client-certificate"},
7697 shouldFail: true,
7698 expectedError: ":UNEXPECTED_MESSAGE:",
7699 expectedLocalError: "remote error: unexpected message",
7700 })
7701
7702 testCases = append(testCases, testCase{
7703 testType: serverTest,
7704 name: "WrongMessageType-TLS13-ClientCertificateVerify",
7705 config: Config{
7706 Certificates: []Certificate{rsaCertificate},
7707 MaxVersion: VersionTLS13,
7708 Bugs: ProtocolBugs{
7709 SendWrongMessageType: typeCertificateVerify,
7710 },
7711 },
7712 flags: []string{"-require-any-client-certificate"},
7713 shouldFail: true,
7714 expectedError: ":UNEXPECTED_MESSAGE:",
7715 expectedLocalError: "remote error: unexpected message",
7716 })
7717
7718 testCases = append(testCases, testCase{
7719 testType: serverTest,
7720 name: "WrongMessageType-TLS13-ClientFinished",
7721 config: Config{
7722 MaxVersion: VersionTLS13,
7723 Bugs: ProtocolBugs{
7724 SendWrongMessageType: typeFinished,
7725 },
7726 },
7727 shouldFail: true,
7728 expectedError: ":UNEXPECTED_MESSAGE:",
7729 expectedLocalError: "remote error: unexpected message",
7730 })
7731}
7732
7733func addTLS13HandshakeTests() {
7734 testCases = append(testCases, testCase{
7735 testType: clientTest,
7736 name: "MissingKeyShare-Client",
7737 config: Config{
7738 MaxVersion: VersionTLS13,
7739 Bugs: ProtocolBugs{
7740 MissingKeyShare: true,
7741 },
7742 },
7743 shouldFail: true,
7744 expectedError: ":MISSING_KEY_SHARE:",
7745 })
7746
7747 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007748 testType: serverTest,
7749 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007750 config: Config{
7751 MaxVersion: VersionTLS13,
7752 Bugs: ProtocolBugs{
7753 MissingKeyShare: true,
7754 },
7755 },
7756 shouldFail: true,
7757 expectedError: ":MISSING_KEY_SHARE:",
7758 })
7759
7760 testCases = append(testCases, testCase{
7761 testType: clientTest,
7762 name: "ClientHelloMissingKeyShare",
7763 config: Config{
7764 MaxVersion: VersionTLS13,
7765 Bugs: ProtocolBugs{
7766 MissingKeyShare: true,
7767 },
7768 },
7769 shouldFail: true,
7770 expectedError: ":MISSING_KEY_SHARE:",
7771 })
7772
7773 testCases = append(testCases, testCase{
7774 testType: clientTest,
7775 name: "MissingKeyShare",
7776 config: Config{
7777 MaxVersion: VersionTLS13,
7778 Bugs: ProtocolBugs{
7779 MissingKeyShare: true,
7780 },
7781 },
7782 shouldFail: true,
7783 expectedError: ":MISSING_KEY_SHARE:",
7784 })
7785
7786 testCases = append(testCases, testCase{
7787 testType: serverTest,
7788 name: "DuplicateKeyShares",
7789 config: Config{
7790 MaxVersion: VersionTLS13,
7791 Bugs: ProtocolBugs{
7792 DuplicateKeyShares: true,
7793 },
7794 },
7795 })
7796
7797 testCases = append(testCases, testCase{
7798 testType: clientTest,
7799 name: "EmptyEncryptedExtensions",
7800 config: Config{
7801 MaxVersion: VersionTLS13,
7802 Bugs: ProtocolBugs{
7803 EmptyEncryptedExtensions: true,
7804 },
7805 },
7806 shouldFail: true,
7807 expectedLocalError: "remote error: error decoding message",
7808 })
7809
7810 testCases = append(testCases, testCase{
7811 testType: clientTest,
7812 name: "EncryptedExtensionsWithKeyShare",
7813 config: Config{
7814 MaxVersion: VersionTLS13,
7815 Bugs: ProtocolBugs{
7816 EncryptedExtensionsWithKeyShare: true,
7817 },
7818 },
7819 shouldFail: true,
7820 expectedLocalError: "remote error: unsupported extension",
7821 })
Steven Valdez5440fe02016-07-18 12:40:30 -04007822
7823 testCases = append(testCases, testCase{
7824 testType: serverTest,
7825 name: "SendHelloRetryRequest",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 // Require a HelloRetryRequest for every curve.
7829 DefaultCurves: []CurveID{},
7830 },
7831 expectedCurveID: CurveX25519,
7832 })
7833
7834 testCases = append(testCases, testCase{
7835 testType: serverTest,
7836 name: "SendHelloRetryRequest-2",
7837 config: Config{
7838 MaxVersion: VersionTLS13,
7839 DefaultCurves: []CurveID{CurveP384},
7840 },
7841 // Although the ClientHello did not predict our preferred curve,
7842 // we always select it whether it is predicted or not.
7843 expectedCurveID: CurveX25519,
7844 })
7845
7846 testCases = append(testCases, testCase{
7847 name: "UnknownCurve-HelloRetryRequest",
7848 config: Config{
7849 MaxVersion: VersionTLS13,
7850 // P-384 requires HelloRetryRequest in BoringSSL.
7851 CurvePreferences: []CurveID{CurveP384},
7852 Bugs: ProtocolBugs{
7853 SendHelloRetryRequestCurve: bogusCurve,
7854 },
7855 },
7856 shouldFail: true,
7857 expectedError: ":WRONG_CURVE:",
7858 })
7859
7860 testCases = append(testCases, testCase{
7861 name: "DisabledCurve-HelloRetryRequest",
7862 config: Config{
7863 MaxVersion: VersionTLS13,
7864 CurvePreferences: []CurveID{CurveP256},
7865 Bugs: ProtocolBugs{
7866 IgnorePeerCurvePreferences: true,
7867 },
7868 },
7869 flags: []string{"-p384-only"},
7870 shouldFail: true,
7871 expectedError: ":WRONG_CURVE:",
7872 })
7873
7874 testCases = append(testCases, testCase{
7875 name: "UnnecessaryHelloRetryRequest",
7876 config: Config{
7877 MaxVersion: VersionTLS13,
7878 Bugs: ProtocolBugs{
7879 UnnecessaryHelloRetryRequest: true,
7880 },
7881 },
7882 shouldFail: true,
7883 expectedError: ":WRONG_CURVE:",
7884 })
7885
7886 testCases = append(testCases, testCase{
7887 name: "SecondHelloRetryRequest",
7888 config: Config{
7889 MaxVersion: VersionTLS13,
7890 // P-384 requires HelloRetryRequest in BoringSSL.
7891 CurvePreferences: []CurveID{CurveP384},
7892 Bugs: ProtocolBugs{
7893 SecondHelloRetryRequest: true,
7894 },
7895 },
7896 shouldFail: true,
7897 expectedError: ":UNEXPECTED_MESSAGE:",
7898 })
7899
7900 testCases = append(testCases, testCase{
7901 testType: serverTest,
7902 name: "SecondClientHelloMissingKeyShare",
7903 config: Config{
7904 MaxVersion: VersionTLS13,
7905 DefaultCurves: []CurveID{},
7906 Bugs: ProtocolBugs{
7907 SecondClientHelloMissingKeyShare: true,
7908 },
7909 },
7910 shouldFail: true,
7911 expectedError: ":MISSING_KEY_SHARE:",
7912 })
7913
7914 testCases = append(testCases, testCase{
7915 testType: serverTest,
7916 name: "SecondClientHelloWrongCurve",
7917 config: Config{
7918 MaxVersion: VersionTLS13,
7919 DefaultCurves: []CurveID{},
7920 Bugs: ProtocolBugs{
7921 MisinterpretHelloRetryRequestCurve: CurveP521,
7922 },
7923 },
7924 shouldFail: true,
7925 expectedError: ":WRONG_CURVE:",
7926 })
7927
7928 testCases = append(testCases, testCase{
7929 name: "HelloRetryRequestVersionMismatch",
7930 config: Config{
7931 MaxVersion: VersionTLS13,
7932 // P-384 requires HelloRetryRequest in BoringSSL.
7933 CurvePreferences: []CurveID{CurveP384},
7934 Bugs: ProtocolBugs{
7935 SendServerHelloVersion: 0x0305,
7936 },
7937 },
7938 shouldFail: true,
7939 expectedError: ":WRONG_VERSION_NUMBER:",
7940 })
7941
7942 testCases = append(testCases, testCase{
7943 name: "HelloRetryRequestCurveMismatch",
7944 config: Config{
7945 MaxVersion: VersionTLS13,
7946 // P-384 requires HelloRetryRequest in BoringSSL.
7947 CurvePreferences: []CurveID{CurveP384},
7948 Bugs: ProtocolBugs{
7949 // Send P-384 (correct) in the HelloRetryRequest.
7950 SendHelloRetryRequestCurve: CurveP384,
7951 // But send P-256 in the ServerHello.
7952 SendCurve: CurveP256,
7953 },
7954 },
7955 shouldFail: true,
7956 expectedError: ":WRONG_CURVE:",
7957 })
7958
7959 // Test the server selecting a curve that requires a HelloRetryRequest
7960 // without sending it.
7961 testCases = append(testCases, testCase{
7962 name: "SkipHelloRetryRequest",
7963 config: Config{
7964 MaxVersion: VersionTLS13,
7965 // P-384 requires HelloRetryRequest in BoringSSL.
7966 CurvePreferences: []CurveID{CurveP384},
7967 Bugs: ProtocolBugs{
7968 SkipHelloRetryRequest: true,
7969 },
7970 },
7971 shouldFail: true,
7972 expectedError: ":WRONG_CURVE:",
7973 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007974}
7975
Adam Langley7c803a62015-06-15 15:35:05 -07007976func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07007977 defer wg.Done()
7978
7979 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08007980 var err error
7981
7982 if *mallocTest < 0 {
7983 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007984 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08007985 } else {
7986 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
7987 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07007988 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08007989 if err != nil {
7990 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
7991 }
7992 break
7993 }
7994 }
7995 }
Adam Langley95c29f32014-06-20 12:00:00 -07007996 statusChan <- statusMsg{test: test, err: err}
7997 }
7998}
7999
8000type statusMsg struct {
8001 test *testCase
8002 started bool
8003 err error
8004}
8005
David Benjamin5f237bc2015-02-11 17:14:15 -05008006func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008007 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008008
David Benjamin5f237bc2015-02-11 17:14:15 -05008009 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008010 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008011 if !*pipe {
8012 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008013 var erase string
8014 for i := 0; i < lineLen; i++ {
8015 erase += "\b \b"
8016 }
8017 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008018 }
8019
Adam Langley95c29f32014-06-20 12:00:00 -07008020 if msg.started {
8021 started++
8022 } else {
8023 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008024
8025 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008026 if msg.err == errUnimplemented {
8027 if *pipe {
8028 // Print each test instead of a status line.
8029 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8030 }
8031 unimplemented++
8032 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8033 } else {
8034 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8035 failed++
8036 testOutput.addResult(msg.test.name, "FAIL")
8037 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008038 } else {
8039 if *pipe {
8040 // Print each test instead of a status line.
8041 fmt.Printf("PASSED (%s)\n", msg.test.name)
8042 }
8043 testOutput.addResult(msg.test.name, "PASS")
8044 }
Adam Langley95c29f32014-06-20 12:00:00 -07008045 }
8046
David Benjamin5f237bc2015-02-11 17:14:15 -05008047 if !*pipe {
8048 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008049 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008050 lineLen = len(line)
8051 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008052 }
Adam Langley95c29f32014-06-20 12:00:00 -07008053 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008054
8055 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008056}
8057
8058func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008059 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008060 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008061 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008062
Adam Langley7c803a62015-06-15 15:35:05 -07008063 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008064 addCipherSuiteTests()
8065 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008066 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008067 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008068 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008069 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008070 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008071 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008072 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008073 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008074 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008075 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008076 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008077 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008078 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008079 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008080 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008081 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008082 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008083 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008084 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05008085 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008086 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008087 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008088 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008089 addWrongMessageTypeTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008090 addTLS13WrongMessageTypeTests()
8091 addTLS13HandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008092
8093 var wg sync.WaitGroup
8094
Adam Langley7c803a62015-06-15 15:35:05 -07008095 statusChan := make(chan statusMsg, *numWorkers)
8096 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008097 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008098
EKRf71d7ed2016-08-06 13:25:12 -07008099 if len(*shimConfigFile) != 0 {
8100 encoded, err := ioutil.ReadFile(*shimConfigFile)
8101 if err != nil {
8102 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8103 os.Exit(1)
8104 }
8105
8106 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8107 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8108 os.Exit(1)
8109 }
8110 }
8111
David Benjamin025b3d32014-07-01 19:53:04 -04008112 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008113
Adam Langley7c803a62015-06-15 15:35:05 -07008114 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008115 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008116 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008117 }
8118
David Benjamin270f0a72016-03-17 14:41:36 -04008119 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008120 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008121 matched := true
8122 if len(*testToRun) != 0 {
8123 var err error
8124 matched, err = filepath.Match(*testToRun, testCases[i].name)
8125 if err != nil {
8126 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8127 os.Exit(1)
8128 }
8129 }
8130
EKRf71d7ed2016-08-06 13:25:12 -07008131 if !*includeDisabled {
8132 for pattern := range shimConfig.DisabledTests {
8133 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8134 if err != nil {
8135 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8136 os.Exit(1)
8137 }
8138
8139 if isDisabled {
8140 matched = false
8141 break
8142 }
8143 }
8144 }
8145
David Benjamin17e12922016-07-28 18:04:43 -04008146 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008147 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008148 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008149 }
8150 }
David Benjamin17e12922016-07-28 18:04:43 -04008151
David Benjamin270f0a72016-03-17 14:41:36 -04008152 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008153 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008154 os.Exit(1)
8155 }
Adam Langley95c29f32014-06-20 12:00:00 -07008156
8157 close(testChan)
8158 wg.Wait()
8159 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008160 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008161
8162 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008163
8164 if *jsonOutput != "" {
8165 if err := testOutput.writeTo(*jsonOutput); err != nil {
8166 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8167 }
8168 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008169
EKR842ae6c2016-07-27 09:22:05 +02008170 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8171 os.Exit(1)
8172 }
8173
8174 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008175 os.Exit(1)
8176 }
Adam Langley95c29f32014-06-20 12:00:00 -07008177}