blob: ec20947a235d605c43b7464d02ac347787ad732f [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
David Benjamin46662482016-08-17 00:51:00 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700300 // expectResumeRejected, if true, specifies that the attempted
301 // resumption must be rejected by the client. This is only valid for a
302 // serverTest.
303 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400304 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500305 // resumption. Unless newSessionsOnResume is set,
306 // SessionTicketKey, ServerSessionCache, and
307 // ClientSessionCache are copied from the initial connection's
308 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400309 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400322 // shimShutsDown, if true, runs a test where the shim shuts down the
323 // connection immediately after the handshake rather than echoing
324 // messages from the runner.
325 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400341 // exportKeyingMaterial, if non-zero, configures the test to exchange
342 // keying material and verify they match.
343 exportKeyingMaterial int
344 exportLabel string
345 exportContext string
346 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700350 // testTLSUnique, if true, causes the shim to send the tls-unique value
351 // which will be compared against the expected value.
352 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700365}
366
Adam Langley7c803a62015-06-15 15:35:05 -0700367var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700368
David Benjaminc07afb72016-09-22 10:18:58 -0400369func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500370 if len(data) == 0 {
371 return
372 }
373
374 protocol := "tls"
375 if test.protocol == dtls {
376 protocol = "dtls"
377 }
378
379 side := "client"
380 if test.testType == serverTest {
381 side = "server"
382 }
383
384 dir := path.Join(*transcriptDir, protocol, side)
385 if err := os.MkdirAll(dir, 0755); err != nil {
386 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
387 return
388 }
389
David Benjaminc07afb72016-09-22 10:18:58 -0400390 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500391 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 Benjaminc07afb72016-09-22 10:18:58 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
David Benjamin01a90572016-09-22 00:11:43 -0400439 if *deterministic {
440 config.Time = func() time.Time { return time.Unix(1234, 1234) }
441 }
David Benjamine54af062016-08-08 19:21:18 -0400442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400467 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
Steven Valdez32635b82016-08-16 11:25:03 -0400618 for i := 0; i < test.sendKeyUpdates; i++ {
619 tlsConn.SendKeyUpdate()
620 }
621
David Benjamina8ebe222015-06-06 03:04:39 -0400622 for i := 0; i < test.sendEmptyRecords; i++ {
623 tlsConn.Write(nil)
624 }
625
David Benjamin24f346d2015-06-06 03:28:08 -0400626 for i := 0; i < test.sendWarningAlerts; i++ {
627 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
628 }
629
David Benjamin47921102016-07-28 11:29:18 -0400630 if test.sendHalfHelloRequest {
631 tlsConn.SendHalfHelloRequest()
632 }
633
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400634 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700635 if test.renegotiateCiphers != nil {
636 config.CipherSuites = test.renegotiateCiphers
637 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400638 for i := 0; i < test.renegotiate; i++ {
639 if err := tlsConn.Renegotiate(); err != nil {
640 return err
641 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700642 }
643 } else if test.renegotiateCiphers != nil {
644 panic("renegotiateCiphers without renegotiate")
645 }
646
David Benjamin5fa3eba2015-01-22 16:35:40 -0500647 if test.damageFirstWrite {
648 connDamage.setDamage(true)
649 tlsConn.Write([]byte("DAMAGED WRITE"))
650 connDamage.setDamage(false)
651 }
652
David Benjamin8e6db492015-07-25 18:29:23 -0400653 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700654 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400655 if test.protocol == dtls {
656 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
657 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700658 // Read until EOF.
659 _, err := io.Copy(ioutil.Discard, tlsConn)
660 return err
661 }
David Benjamin4417d052015-04-05 04:17:25 -0400662 if messageLen == 0 {
663 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700664 }
Adam Langley95c29f32014-06-20 12:00:00 -0700665
David Benjamin8e6db492015-07-25 18:29:23 -0400666 messageCount := test.messageCount
667 if messageCount == 0 {
668 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400669 }
670
David Benjamin8e6db492015-07-25 18:29:23 -0400671 for j := 0; j < messageCount; j++ {
672 testMessage := make([]byte, messageLen)
673 for i := range testMessage {
674 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400675 }
David Benjamin8e6db492015-07-25 18:29:23 -0400676 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700677
Steven Valdez32635b82016-08-16 11:25:03 -0400678 for i := 0; i < test.sendKeyUpdates; i++ {
679 tlsConn.SendKeyUpdate()
680 }
681
David Benjamin8e6db492015-07-25 18:29:23 -0400682 for i := 0; i < test.sendEmptyRecords; i++ {
683 tlsConn.Write(nil)
684 }
685
686 for i := 0; i < test.sendWarningAlerts; i++ {
687 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
688 }
689
David Benjamin4f75aaf2015-09-01 16:53:10 -0400690 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400691 // The shim will not respond.
692 continue
693 }
694
David Benjamin8e6db492015-07-25 18:29:23 -0400695 buf := make([]byte, len(testMessage))
696 if test.protocol == dtls {
697 bufTmp := make([]byte, len(buf)+1)
698 n, err := tlsConn.Read(bufTmp)
699 if err != nil {
700 return err
701 }
702 if n != len(buf) {
703 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
704 }
705 copy(buf, bufTmp)
706 } else {
707 _, err := io.ReadFull(tlsConn, buf)
708 if err != nil {
709 return err
710 }
711 }
712
713 for i, v := range buf {
714 if v != testMessage[i]^0xff {
715 return fmt.Errorf("bad reply contents at byte %d", i)
716 }
Adam Langley95c29f32014-06-20 12:00:00 -0700717 }
718 }
719
720 return nil
721}
722
David Benjamin325b5c32014-07-01 19:40:31 -0400723func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400724 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700725 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400726 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700727 }
David Benjamin325b5c32014-07-01 19:40:31 -0400728 valgrindArgs = append(valgrindArgs, path)
729 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700730
David Benjamin325b5c32014-07-01 19:40:31 -0400731 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732}
733
David Benjamin325b5c32014-07-01 19:40:31 -0400734func gdbOf(path string, args ...string) *exec.Cmd {
735 xtermArgs := []string{"-e", "gdb", "--args"}
736 xtermArgs = append(xtermArgs, path)
737 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700738
David Benjamin325b5c32014-07-01 19:40:31 -0400739 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700740}
741
David Benjamind16bf342015-12-18 00:53:12 -0500742func lldbOf(path string, args ...string) *exec.Cmd {
743 xtermArgs := []string{"-e", "lldb", "--"}
744 xtermArgs = append(xtermArgs, path)
745 xtermArgs = append(xtermArgs, args...)
746
747 return exec.Command("xterm", xtermArgs...)
748}
749
EKR842ae6c2016-07-27 09:22:05 +0200750var (
751 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
752 errUnimplemented = errors.New("child process does not implement needed flags")
753)
Adam Langley69a01602014-11-17 17:26:55 -0800754
David Benjamin87c8a642015-02-21 01:54:29 -0500755// accept accepts a connection from listener, unless waitChan signals a process
756// exit first.
757func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
758 type connOrError struct {
759 conn net.Conn
760 err error
761 }
762 connChan := make(chan connOrError, 1)
763 go func() {
764 conn, err := listener.Accept()
765 connChan <- connOrError{conn, err}
766 close(connChan)
767 }()
768 select {
769 case result := <-connChan:
770 return result.conn, result.err
771 case childErr := <-waitChan:
772 waitChan <- childErr
773 return nil, fmt.Errorf("child exited early: %s", childErr)
774 }
775}
776
EKRf71d7ed2016-08-06 13:25:12 -0700777func translateExpectedError(errorStr string) string {
778 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
779 return translated
780 }
781
782 if *looseErrors {
783 return ""
784 }
785
786 return errorStr
787}
788
Adam Langley7c803a62015-06-15 15:35:05 -0700789func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700790 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
791 panic("Error expected without shouldFail in " + test.name)
792 }
793
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700794 if test.expectResumeRejected && !test.resumeSession {
795 panic("expectResumeRejected without resumeSession in " + test.name)
796 }
797
David Benjamin87c8a642015-02-21 01:54:29 -0500798 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
799 if err != nil {
800 panic(err)
801 }
802 defer func() {
803 if listener != nil {
804 listener.Close()
805 }
806 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400809 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400810 flags = append(flags, "-server")
811
David Benjamin025b3d32014-07-01 19:53:04 -0400812 flags = append(flags, "-key-file")
813 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700814 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400815 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700816 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400817 }
818
819 flags = append(flags, "-cert-file")
820 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700821 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400822 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700823 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400824 }
825 }
David Benjamin5a593af2014-08-11 19:51:50 -0400826
David Benjamin6fd297b2014-08-11 18:43:38 -0400827 if test.protocol == dtls {
828 flags = append(flags, "-dtls")
829 }
830
David Benjamin46662482016-08-17 00:51:00 -0400831 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400832 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400833 resumeCount++
834 if test.resumeRenewedSession {
835 resumeCount++
836 }
837 }
838
839 if resumeCount > 0 {
840 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400841 }
842
David Benjamine58c4f52014-08-24 03:47:07 -0400843 if test.shimWritesFirst {
844 flags = append(flags, "-shim-writes-first")
845 }
846
David Benjamin30789da2015-08-29 22:56:45 -0400847 if test.shimShutsDown {
848 flags = append(flags, "-shim-shuts-down")
849 }
850
David Benjaminc565ebb2015-04-03 04:06:36 -0400851 if test.exportKeyingMaterial > 0 {
852 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
853 flags = append(flags, "-export-label", test.exportLabel)
854 flags = append(flags, "-export-context", test.exportContext)
855 if test.useExportContext {
856 flags = append(flags, "-use-export-context")
857 }
858 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700859 if test.expectResumeRejected {
860 flags = append(flags, "-expect-session-miss")
861 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400862
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700863 if test.testTLSUnique {
864 flags = append(flags, "-tls-unique")
865 }
866
David Benjamin025b3d32014-07-01 19:53:04 -0400867 flags = append(flags, test.flags...)
868
869 var shim *exec.Cmd
870 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700871 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700872 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500874 } else if *useLLDB {
875 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400876 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700877 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400878 }
David Benjamin025b3d32014-07-01 19:53:04 -0400879 shim.Stdin = os.Stdin
880 var stdoutBuf, stderrBuf bytes.Buffer
881 shim.Stdout = &stdoutBuf
882 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800883 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500884 shim.Env = os.Environ()
885 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800886 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400887 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800888 }
889 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
890 }
David Benjamin025b3d32014-07-01 19:53:04 -0400891
892 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700893 panic(err)
894 }
David Benjamin87c8a642015-02-21 01:54:29 -0500895 waitChan := make(chan error, 1)
896 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700897
898 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700899
David Benjamin7a4aaa42016-09-20 17:58:14 -0400900 if *deterministic {
901 config.Rand = &deterministicRand{}
902 }
903
David Benjamin87c8a642015-02-21 01:54:29 -0500904 conn, err := acceptOrWait(listener, waitChan)
905 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400906 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn.Close()
908 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500909
David Benjamin46662482016-08-17 00:51:00 -0400910 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400911 var resumeConfig Config
912 if test.resumeConfig != nil {
913 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400914 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500915 resumeConfig.SessionTicketKey = config.SessionTicketKey
916 resumeConfig.ClientSessionCache = config.ClientSessionCache
917 resumeConfig.ServerSessionCache = config.ServerSessionCache
918 }
David Benjamin2e045a92016-06-08 13:09:56 -0400919 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400920 } else {
921 resumeConfig = config
922 }
David Benjamin87c8a642015-02-21 01:54:29 -0500923 var connResume net.Conn
924 connResume, err = acceptOrWait(listener, waitChan)
925 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400926 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500927 connResume.Close()
928 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400929 }
930
David Benjamin87c8a642015-02-21 01:54:29 -0500931 // Close the listener now. This is to avoid hangs should the shim try to
932 // open more connections than expected.
933 listener.Close()
934 listener = nil
935
936 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400937 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800938 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200939 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
940 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800941 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200942 case 89:
943 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400944 case 99:
945 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800946 }
947 }
Adam Langley95c29f32014-06-20 12:00:00 -0700948
David Benjamin9bea3492016-03-02 10:59:16 -0500949 // Account for Windows line endings.
950 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
951 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500952
953 // Separate the errors from the shim and those from tools like
954 // AddressSanitizer.
955 var extraStderr string
956 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
957 stderr = stderrParts[0]
958 extraStderr = stderrParts[1]
959 }
960
Adam Langley95c29f32014-06-20 12:00:00 -0700961 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700962 expectedError := translateExpectedError(test.expectedError)
963 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200964
Adam Langleyac61fa32014-06-23 12:03:11 -0700965 localError := "none"
966 if err != nil {
967 localError = err.Error()
968 }
969 if len(test.expectedLocalError) != 0 {
970 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
971 }
Adam Langley95c29f32014-06-20 12:00:00 -0700972
973 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700974 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700975 if childErr != nil {
976 childError = childErr.Error()
977 }
978
979 var msg string
980 switch {
981 case failed && !test.shouldFail:
982 msg = "unexpected failure"
983 case !failed && test.shouldFail:
984 msg = "unexpected success"
985 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700986 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700987 default:
988 panic("internal error")
989 }
990
David Benjamin9aafb642016-09-20 19:36:53 -0400991 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700992 }
993
David Benjamind2ba8892016-09-20 19:41:04 -0400994 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -0500995 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700996 }
997
David Benjamind2ba8892016-09-20 19:41:04 -0400998 if *useValgrind && isValgrindError {
999 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1000 }
1001
Adam Langley95c29f32014-06-20 12:00:00 -07001002 return nil
1003}
1004
1005var tlsVersions = []struct {
1006 name string
1007 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001008 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001009 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001010}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001011 {"SSL3", VersionSSL30, "-no-ssl3", false},
1012 {"TLS1", VersionTLS10, "-no-tls1", true},
1013 {"TLS11", VersionTLS11, "-no-tls11", false},
1014 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001015 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001016}
1017
1018var testCipherSuites = []struct {
1019 name string
1020 id uint16
1021}{
1022 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001023 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001024 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001025 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001026 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001028 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001029 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1030 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001031 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001032 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1033 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001034 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001035 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1036 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001037 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1038 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001039 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001041 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001042 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001043 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001044 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001045 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001046 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001048 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001049 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001050 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001051 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1052 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1053 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1054 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001055 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1056 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001057 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1058 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001059 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001060 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1061 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001062 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001063}
1064
David Benjamin8b8c0062014-11-23 02:47:52 -05001065func hasComponent(suiteName, component string) bool {
1066 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1067}
1068
David Benjaminf7768e42014-08-31 02:06:47 -04001069func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001070 return hasComponent(suiteName, "GCM") ||
1071 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001072 hasComponent(suiteName, "SHA384") ||
1073 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001074}
1075
Nick Harper1fd39d82016-06-14 18:14:35 -07001076func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001077 // Only AEADs.
1078 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1079 return false
1080 }
1081 // No old CHACHA20_POLY1305.
1082 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1083 return false
1084 }
1085 // Must have ECDHE.
1086 // TODO(davidben,svaldez): Add pure PSK support.
1087 if !hasComponent(suiteName, "ECDHE") {
1088 return false
1089 }
1090 // TODO(davidben,svaldez): Add PSK support.
1091 if hasComponent(suiteName, "PSK") {
1092 return false
1093 }
1094 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001095}
1096
David Benjamin8b8c0062014-11-23 02:47:52 -05001097func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001098 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001099}
1100
Adam Langleya7997f12015-05-14 17:38:50 -07001101func bigFromHex(hex string) *big.Int {
1102 ret, ok := new(big.Int).SetString(hex, 16)
1103 if !ok {
1104 panic("failed to parse hex number 0x" + hex)
1105 }
1106 return ret
1107}
1108
Adam Langley7c803a62015-06-15 15:35:05 -07001109func addBasicTests() {
1110 basicTests := []testCase{
1111 {
Adam Langley7c803a62015-06-15 15:35:05 -07001112 name: "NoFallbackSCSV",
1113 config: Config{
1114 Bugs: ProtocolBugs{
1115 FailIfNotFallbackSCSV: true,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedLocalError: "no fallback SCSV found",
1120 },
1121 {
1122 name: "SendFallbackSCSV",
1123 config: Config{
1124 Bugs: ProtocolBugs{
1125 FailIfNotFallbackSCSV: true,
1126 },
1127 },
1128 flags: []string{"-fallback-scsv"},
1129 },
1130 {
1131 name: "ClientCertificateTypes",
1132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001133 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001134 ClientAuth: RequestClientCert,
1135 ClientCertificateTypes: []byte{
1136 CertTypeDSSSign,
1137 CertTypeRSASign,
1138 CertTypeECDSASign,
1139 },
1140 },
1141 flags: []string{
1142 "-expect-certificate-types",
1143 base64.StdEncoding.EncodeToString([]byte{
1144 CertTypeDSSSign,
1145 CertTypeRSASign,
1146 CertTypeECDSASign,
1147 }),
1148 },
1149 },
1150 {
Adam Langley7c803a62015-06-15 15:35:05 -07001151 name: "UnauthenticatedECDH",
1152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001153 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001154 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1155 Bugs: ProtocolBugs{
1156 UnauthenticatedECDH: true,
1157 },
1158 },
1159 shouldFail: true,
1160 expectedError: ":UNEXPECTED_MESSAGE:",
1161 },
1162 {
1163 name: "SkipCertificateStatus",
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 SkipCertificateStatus: true,
1169 },
1170 },
1171 flags: []string{
1172 "-enable-ocsp-stapling",
1173 },
1174 },
1175 {
1176 name: "SkipServerKeyExchange",
1177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001178 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1180 Bugs: ProtocolBugs{
1181 SkipServerKeyExchange: true,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedError: ":UNEXPECTED_MESSAGE:",
1186 },
1187 {
Adam Langley7c803a62015-06-15 15:35:05 -07001188 testType: serverTest,
1189 name: "Alert",
1190 config: Config{
1191 Bugs: ProtocolBugs{
1192 SendSpuriousAlert: alertRecordOverflow,
1193 },
1194 },
1195 shouldFail: true,
1196 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1197 },
1198 {
1199 protocol: dtls,
1200 testType: serverTest,
1201 name: "Alert-DTLS",
1202 config: Config{
1203 Bugs: ProtocolBugs{
1204 SendSpuriousAlert: alertRecordOverflow,
1205 },
1206 },
1207 shouldFail: true,
1208 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1209 },
1210 {
1211 testType: serverTest,
1212 name: "FragmentAlert",
1213 config: Config{
1214 Bugs: ProtocolBugs{
1215 FragmentAlert: true,
1216 SendSpuriousAlert: alertRecordOverflow,
1217 },
1218 },
1219 shouldFail: true,
1220 expectedError: ":BAD_ALERT:",
1221 },
1222 {
1223 protocol: dtls,
1224 testType: serverTest,
1225 name: "FragmentAlert-DTLS",
1226 config: Config{
1227 Bugs: ProtocolBugs{
1228 FragmentAlert: true,
1229 SendSpuriousAlert: alertRecordOverflow,
1230 },
1231 },
1232 shouldFail: true,
1233 expectedError: ":BAD_ALERT:",
1234 },
1235 {
1236 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001237 name: "DoubleAlert",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 DoubleAlert: true,
1241 SendSpuriousAlert: alertRecordOverflow,
1242 },
1243 },
1244 shouldFail: true,
1245 expectedError: ":BAD_ALERT:",
1246 },
1247 {
1248 protocol: dtls,
1249 testType: serverTest,
1250 name: "DoubleAlert-DTLS",
1251 config: Config{
1252 Bugs: ProtocolBugs{
1253 DoubleAlert: true,
1254 SendSpuriousAlert: alertRecordOverflow,
1255 },
1256 },
1257 shouldFail: true,
1258 expectedError: ":BAD_ALERT:",
1259 },
1260 {
Adam Langley7c803a62015-06-15 15:35:05 -07001261 name: "SkipNewSessionTicket",
1262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001263 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001264 Bugs: ProtocolBugs{
1265 SkipNewSessionTicket: true,
1266 },
1267 },
1268 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001269 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001270 },
1271 {
1272 testType: serverTest,
1273 name: "FallbackSCSV",
1274 config: Config{
1275 MaxVersion: VersionTLS11,
1276 Bugs: ProtocolBugs{
1277 SendFallbackSCSV: true,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":INAPPROPRIATE_FALLBACK:",
1282 },
1283 {
1284 testType: serverTest,
1285 name: "FallbackSCSV-VersionMatch",
1286 config: Config{
1287 Bugs: ProtocolBugs{
1288 SendFallbackSCSV: true,
1289 },
1290 },
1291 },
1292 {
1293 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001294 name: "FallbackSCSV-VersionMatch-TLS12",
1295 config: Config{
1296 MaxVersion: VersionTLS12,
1297 Bugs: ProtocolBugs{
1298 SendFallbackSCSV: true,
1299 },
1300 },
1301 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1302 },
1303 {
1304 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001305 name: "FragmentedClientVersion",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 MaxHandshakeRecordLength: 1,
1309 FragmentClientVersion: true,
1310 },
1311 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001312 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001313 },
1314 {
Adam Langley7c803a62015-06-15 15:35:05 -07001315 testType: serverTest,
1316 name: "HttpGET",
1317 sendPrefix: "GET / HTTP/1.0\n",
1318 shouldFail: true,
1319 expectedError: ":HTTP_REQUEST:",
1320 },
1321 {
1322 testType: serverTest,
1323 name: "HttpPOST",
1324 sendPrefix: "POST / HTTP/1.0\n",
1325 shouldFail: true,
1326 expectedError: ":HTTP_REQUEST:",
1327 },
1328 {
1329 testType: serverTest,
1330 name: "HttpHEAD",
1331 sendPrefix: "HEAD / HTTP/1.0\n",
1332 shouldFail: true,
1333 expectedError: ":HTTP_REQUEST:",
1334 },
1335 {
1336 testType: serverTest,
1337 name: "HttpPUT",
1338 sendPrefix: "PUT / HTTP/1.0\n",
1339 shouldFail: true,
1340 expectedError: ":HTTP_REQUEST:",
1341 },
1342 {
1343 testType: serverTest,
1344 name: "HttpCONNECT",
1345 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1346 shouldFail: true,
1347 expectedError: ":HTTPS_PROXY_REQUEST:",
1348 },
1349 {
1350 testType: serverTest,
1351 name: "Garbage",
1352 sendPrefix: "blah",
1353 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001354 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001355 },
1356 {
Adam Langley7c803a62015-06-15 15:35:05 -07001357 name: "RSAEphemeralKey",
1358 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001359 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001360 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1361 Bugs: ProtocolBugs{
1362 RSAEphemeralKey: true,
1363 },
1364 },
1365 shouldFail: true,
1366 expectedError: ":UNEXPECTED_MESSAGE:",
1367 },
1368 {
1369 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001370 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001371 shouldFail: true,
1372 expectedError: ":WRONG_SSL_VERSION:",
1373 },
1374 {
1375 protocol: dtls,
1376 name: "DisableEverything-DTLS",
1377 flags: []string{"-no-tls12", "-no-tls1"},
1378 shouldFail: true,
1379 expectedError: ":WRONG_SSL_VERSION:",
1380 },
1381 {
Adam Langley7c803a62015-06-15 15:35:05 -07001382 protocol: dtls,
1383 testType: serverTest,
1384 name: "MTU",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 MaxPacketLength: 256,
1388 },
1389 },
1390 flags: []string{"-mtu", "256"},
1391 },
1392 {
1393 protocol: dtls,
1394 testType: serverTest,
1395 name: "MTUExceeded",
1396 config: Config{
1397 Bugs: ProtocolBugs{
1398 MaxPacketLength: 255,
1399 },
1400 },
1401 flags: []string{"-mtu", "256"},
1402 shouldFail: true,
1403 expectedLocalError: "dtls: exceeded maximum packet length",
1404 },
1405 {
1406 name: "CertMismatchRSA",
1407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001408 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001409 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001410 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001411 Bugs: ProtocolBugs{
1412 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1413 },
1414 },
1415 shouldFail: true,
1416 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1417 },
1418 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001419 name: "CertMismatchRSA-TLS13",
1420 config: Config{
1421 MaxVersion: VersionTLS13,
1422 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1423 Certificates: []Certificate{ecdsaP256Certificate},
1424 Bugs: ProtocolBugs{
1425 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1426 },
1427 },
1428 shouldFail: true,
1429 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1430 },
1431 {
Adam Langley7c803a62015-06-15 15:35:05 -07001432 name: "CertMismatchECDSA",
1433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001434 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001435 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001436 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001437 Bugs: ProtocolBugs{
1438 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1439 },
1440 },
1441 shouldFail: true,
1442 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1443 },
1444 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001445 name: "CertMismatchECDSA-TLS13",
1446 config: Config{
1447 MaxVersion: VersionTLS13,
1448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1449 Certificates: []Certificate{rsaCertificate},
1450 Bugs: ProtocolBugs{
1451 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1452 },
1453 },
1454 shouldFail: true,
1455 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1456 },
1457 {
Adam Langley7c803a62015-06-15 15:35:05 -07001458 name: "EmptyCertificateList",
1459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001460 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001461 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1462 Bugs: ProtocolBugs{
1463 EmptyCertificateList: true,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":DECODE_ERROR:",
1468 },
1469 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001470 name: "EmptyCertificateList-TLS13",
1471 config: Config{
1472 MaxVersion: VersionTLS13,
1473 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1474 Bugs: ProtocolBugs{
1475 EmptyCertificateList: true,
1476 },
1477 },
1478 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001479 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001480 },
1481 {
Adam Langley7c803a62015-06-15 15:35:05 -07001482 name: "TLSFatalBadPackets",
1483 damageFirstWrite: true,
1484 shouldFail: true,
1485 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1486 },
1487 {
1488 protocol: dtls,
1489 name: "DTLSIgnoreBadPackets",
1490 damageFirstWrite: true,
1491 },
1492 {
1493 protocol: dtls,
1494 name: "DTLSIgnoreBadPackets-Async",
1495 damageFirstWrite: true,
1496 flags: []string{"-async"},
1497 },
1498 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001499 name: "AppDataBeforeHandshake",
1500 config: Config{
1501 Bugs: ProtocolBugs{
1502 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1503 },
1504 },
1505 shouldFail: true,
1506 expectedError: ":UNEXPECTED_RECORD:",
1507 },
1508 {
1509 name: "AppDataBeforeHandshake-Empty",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte{},
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
1519 protocol: dtls,
1520 name: "AppDataBeforeHandshake-DTLS",
1521 config: Config{
1522 Bugs: ProtocolBugs{
1523 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1524 },
1525 },
1526 shouldFail: true,
1527 expectedError: ":UNEXPECTED_RECORD:",
1528 },
1529 {
1530 protocol: dtls,
1531 name: "AppDataBeforeHandshake-DTLS-Empty",
1532 config: Config{
1533 Bugs: ProtocolBugs{
1534 AppDataBeforeHandshake: []byte{},
1535 },
1536 },
1537 shouldFail: true,
1538 expectedError: ":UNEXPECTED_RECORD:",
1539 },
1540 {
Adam Langley7c803a62015-06-15 15:35:05 -07001541 name: "AppDataAfterChangeCipherSpec",
1542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001543 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001544 Bugs: ProtocolBugs{
1545 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1546 },
1547 },
1548 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001549 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001550 },
1551 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001552 name: "AppDataAfterChangeCipherSpec-Empty",
1553 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001554 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001555 Bugs: ProtocolBugs{
1556 AppDataAfterChangeCipherSpec: []byte{},
1557 },
1558 },
1559 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001560 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001561 },
1562 {
Adam Langley7c803a62015-06-15 15:35:05 -07001563 protocol: dtls,
1564 name: "AppDataAfterChangeCipherSpec-DTLS",
1565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001566 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001567 Bugs: ProtocolBugs{
1568 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1569 },
1570 },
1571 // BoringSSL's DTLS implementation will drop the out-of-order
1572 // application data.
1573 },
1574 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001575 protocol: dtls,
1576 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001578 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001579 Bugs: ProtocolBugs{
1580 AppDataAfterChangeCipherSpec: []byte{},
1581 },
1582 },
1583 // BoringSSL's DTLS implementation will drop the out-of-order
1584 // application data.
1585 },
1586 {
Adam Langley7c803a62015-06-15 15:35:05 -07001587 name: "AlertAfterChangeCipherSpec",
1588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001589 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001590 Bugs: ProtocolBugs{
1591 AlertAfterChangeCipherSpec: alertRecordOverflow,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "AlertAfterChangeCipherSpec-DTLS",
1600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001601 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001602 Bugs: ProtocolBugs{
1603 AlertAfterChangeCipherSpec: alertRecordOverflow,
1604 },
1605 },
1606 shouldFail: true,
1607 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1608 },
1609 {
1610 protocol: dtls,
1611 name: "ReorderHandshakeFragments-Small-DTLS",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 ReorderHandshakeFragments: true,
1615 // Small enough that every handshake message is
1616 // fragmented.
1617 MaxHandshakeRecordLength: 2,
1618 },
1619 },
1620 },
1621 {
1622 protocol: dtls,
1623 name: "ReorderHandshakeFragments-Large-DTLS",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 ReorderHandshakeFragments: true,
1627 // Large enough that no handshake message is
1628 // fragmented.
1629 MaxHandshakeRecordLength: 2048,
1630 },
1631 },
1632 },
1633 {
1634 protocol: dtls,
1635 name: "MixCompleteMessageWithFragments-DTLS",
1636 config: Config{
1637 Bugs: ProtocolBugs{
1638 ReorderHandshakeFragments: true,
1639 MixCompleteMessageWithFragments: true,
1640 MaxHandshakeRecordLength: 2,
1641 },
1642 },
1643 },
1644 {
1645 name: "SendInvalidRecordType",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SendInvalidRecordType: true,
1649 },
1650 },
1651 shouldFail: true,
1652 expectedError: ":UNEXPECTED_RECORD:",
1653 },
1654 {
1655 protocol: dtls,
1656 name: "SendInvalidRecordType-DTLS",
1657 config: Config{
1658 Bugs: ProtocolBugs{
1659 SendInvalidRecordType: true,
1660 },
1661 },
1662 shouldFail: true,
1663 expectedError: ":UNEXPECTED_RECORD:",
1664 },
1665 {
1666 name: "FalseStart-SkipServerSecondLeg",
1667 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001668 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001669 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1670 NextProtos: []string{"foo"},
1671 Bugs: ProtocolBugs{
1672 SkipNewSessionTicket: true,
1673 SkipChangeCipherSpec: true,
1674 SkipFinished: true,
1675 ExpectFalseStart: true,
1676 },
1677 },
1678 flags: []string{
1679 "-false-start",
1680 "-handshake-never-done",
1681 "-advertise-alpn", "\x03foo",
1682 },
1683 shimWritesFirst: true,
1684 shouldFail: true,
1685 expectedError: ":UNEXPECTED_RECORD:",
1686 },
1687 {
1688 name: "FalseStart-SkipServerSecondLeg-Implicit",
1689 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001690 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001691 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1692 NextProtos: []string{"foo"},
1693 Bugs: ProtocolBugs{
1694 SkipNewSessionTicket: true,
1695 SkipChangeCipherSpec: true,
1696 SkipFinished: true,
1697 },
1698 },
1699 flags: []string{
1700 "-implicit-handshake",
1701 "-false-start",
1702 "-handshake-never-done",
1703 "-advertise-alpn", "\x03foo",
1704 },
1705 shouldFail: true,
1706 expectedError: ":UNEXPECTED_RECORD:",
1707 },
1708 {
1709 testType: serverTest,
1710 name: "FailEarlyCallback",
1711 flags: []string{"-fail-early-callback"},
1712 shouldFail: true,
1713 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001714 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001715 },
1716 {
Adam Langley7c803a62015-06-15 15:35:05 -07001717 protocol: dtls,
1718 name: "FragmentMessageTypeMismatch-DTLS",
1719 config: Config{
1720 Bugs: ProtocolBugs{
1721 MaxHandshakeRecordLength: 2,
1722 FragmentMessageTypeMismatch: true,
1723 },
1724 },
1725 shouldFail: true,
1726 expectedError: ":FRAGMENT_MISMATCH:",
1727 },
1728 {
1729 protocol: dtls,
1730 name: "FragmentMessageLengthMismatch-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 MaxHandshakeRecordLength: 2,
1734 FragmentMessageLengthMismatch: true,
1735 },
1736 },
1737 shouldFail: true,
1738 expectedError: ":FRAGMENT_MISMATCH:",
1739 },
1740 {
1741 protocol: dtls,
1742 name: "SplitFragments-Header-DTLS",
1743 config: Config{
1744 Bugs: ProtocolBugs{
1745 SplitFragments: 2,
1746 },
1747 },
1748 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001749 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001750 },
1751 {
1752 protocol: dtls,
1753 name: "SplitFragments-Boundary-DTLS",
1754 config: Config{
1755 Bugs: ProtocolBugs{
1756 SplitFragments: dtlsRecordHeaderLen,
1757 },
1758 },
1759 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001760 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001761 },
1762 {
1763 protocol: dtls,
1764 name: "SplitFragments-Body-DTLS",
1765 config: Config{
1766 Bugs: ProtocolBugs{
1767 SplitFragments: dtlsRecordHeaderLen + 1,
1768 },
1769 },
1770 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001771 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001772 },
1773 {
1774 protocol: dtls,
1775 name: "SendEmptyFragments-DTLS",
1776 config: Config{
1777 Bugs: ProtocolBugs{
1778 SendEmptyFragments: true,
1779 },
1780 },
1781 },
1782 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001783 name: "BadFinished-Client",
1784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001785 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 Bugs: ProtocolBugs{
1787 BadFinished: true,
1788 },
1789 },
1790 shouldFail: true,
1791 expectedError: ":DIGEST_CHECK_FAILED:",
1792 },
1793 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001794 name: "BadFinished-Client-TLS13",
1795 config: Config{
1796 MaxVersion: VersionTLS13,
1797 Bugs: ProtocolBugs{
1798 BadFinished: true,
1799 },
1800 },
1801 shouldFail: true,
1802 expectedError: ":DIGEST_CHECK_FAILED:",
1803 },
1804 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001805 testType: serverTest,
1806 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001807 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001808 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001809 Bugs: ProtocolBugs{
1810 BadFinished: true,
1811 },
1812 },
1813 shouldFail: true,
1814 expectedError: ":DIGEST_CHECK_FAILED:",
1815 },
1816 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001817 testType: serverTest,
1818 name: "BadFinished-Server-TLS13",
1819 config: Config{
1820 MaxVersion: VersionTLS13,
1821 Bugs: ProtocolBugs{
1822 BadFinished: true,
1823 },
1824 },
1825 shouldFail: true,
1826 expectedError: ":DIGEST_CHECK_FAILED:",
1827 },
1828 {
Adam Langley7c803a62015-06-15 15:35:05 -07001829 name: "FalseStart-BadFinished",
1830 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001831 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1833 NextProtos: []string{"foo"},
1834 Bugs: ProtocolBugs{
1835 BadFinished: true,
1836 ExpectFalseStart: true,
1837 },
1838 },
1839 flags: []string{
1840 "-false-start",
1841 "-handshake-never-done",
1842 "-advertise-alpn", "\x03foo",
1843 },
1844 shimWritesFirst: true,
1845 shouldFail: true,
1846 expectedError: ":DIGEST_CHECK_FAILED:",
1847 },
1848 {
1849 name: "NoFalseStart-NoALPN",
1850 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001851 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1853 Bugs: ProtocolBugs{
1854 ExpectFalseStart: true,
1855 AlertBeforeFalseStartTest: alertAccessDenied,
1856 },
1857 },
1858 flags: []string{
1859 "-false-start",
1860 },
1861 shimWritesFirst: true,
1862 shouldFail: true,
1863 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1864 expectedLocalError: "tls: peer did not false start: EOF",
1865 },
1866 {
1867 name: "NoFalseStart-NoAEAD",
1868 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001869 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1871 NextProtos: []string{"foo"},
1872 Bugs: ProtocolBugs{
1873 ExpectFalseStart: true,
1874 AlertBeforeFalseStartTest: alertAccessDenied,
1875 },
1876 },
1877 flags: []string{
1878 "-false-start",
1879 "-advertise-alpn", "\x03foo",
1880 },
1881 shimWritesFirst: true,
1882 shouldFail: true,
1883 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1884 expectedLocalError: "tls: peer did not false start: EOF",
1885 },
1886 {
1887 name: "NoFalseStart-RSA",
1888 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001889 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001890 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1891 NextProtos: []string{"foo"},
1892 Bugs: ProtocolBugs{
1893 ExpectFalseStart: true,
1894 AlertBeforeFalseStartTest: alertAccessDenied,
1895 },
1896 },
1897 flags: []string{
1898 "-false-start",
1899 "-advertise-alpn", "\x03foo",
1900 },
1901 shimWritesFirst: true,
1902 shouldFail: true,
1903 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1904 expectedLocalError: "tls: peer did not false start: EOF",
1905 },
1906 {
1907 name: "NoFalseStart-DHE_RSA",
1908 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001909 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001910 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1911 NextProtos: []string{"foo"},
1912 Bugs: ProtocolBugs{
1913 ExpectFalseStart: true,
1914 AlertBeforeFalseStartTest: alertAccessDenied,
1915 },
1916 },
1917 flags: []string{
1918 "-false-start",
1919 "-advertise-alpn", "\x03foo",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
Adam Langley7c803a62015-06-15 15:35:05 -07001927 protocol: dtls,
1928 name: "SendSplitAlert-Sync",
1929 config: Config{
1930 Bugs: ProtocolBugs{
1931 SendSplitAlert: true,
1932 },
1933 },
1934 },
1935 {
1936 protocol: dtls,
1937 name: "SendSplitAlert-Async",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendSplitAlert: true,
1941 },
1942 },
1943 flags: []string{"-async"},
1944 },
1945 {
1946 protocol: dtls,
1947 name: "PackDTLSHandshake",
1948 config: Config{
1949 Bugs: ProtocolBugs{
1950 MaxHandshakeRecordLength: 2,
1951 PackHandshakeFragments: 20,
1952 PackHandshakeRecords: 200,
1953 },
1954 },
1955 },
1956 {
Adam Langley7c803a62015-06-15 15:35:05 -07001957 name: "SendEmptyRecords-Pass",
1958 sendEmptyRecords: 32,
1959 },
1960 {
1961 name: "SendEmptyRecords",
1962 sendEmptyRecords: 33,
1963 shouldFail: true,
1964 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1965 },
1966 {
1967 name: "SendEmptyRecords-Async",
1968 sendEmptyRecords: 33,
1969 flags: []string{"-async"},
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1972 },
1973 {
David Benjamine8e84b92016-08-03 15:39:47 -04001974 name: "SendWarningAlerts-Pass",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 4,
1979 },
1980 {
David Benjamine8e84b92016-08-03 15:39:47 -04001981 protocol: dtls,
1982 name: "SendWarningAlerts-DTLS-Pass",
1983 config: Config{
1984 MaxVersion: VersionTLS12,
1985 },
Adam Langley7c803a62015-06-15 15:35:05 -07001986 sendWarningAlerts: 4,
1987 },
1988 {
David Benjamine8e84b92016-08-03 15:39:47 -04001989 name: "SendWarningAlerts-TLS13",
1990 config: Config{
1991 MaxVersion: VersionTLS13,
1992 },
1993 sendWarningAlerts: 4,
1994 shouldFail: true,
1995 expectedError: ":BAD_ALERT:",
1996 expectedLocalError: "remote error: error decoding message",
1997 },
1998 {
1999 name: "SendWarningAlerts",
2000 config: Config{
2001 MaxVersion: VersionTLS12,
2002 },
Adam Langley7c803a62015-06-15 15:35:05 -07002003 sendWarningAlerts: 5,
2004 shouldFail: true,
2005 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2006 },
2007 {
David Benjamine8e84b92016-08-03 15:39:47 -04002008 name: "SendWarningAlerts-Async",
2009 config: Config{
2010 MaxVersion: VersionTLS12,
2011 },
Adam Langley7c803a62015-06-15 15:35:05 -07002012 sendWarningAlerts: 5,
2013 flags: []string{"-async"},
2014 shouldFail: true,
2015 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2016 },
David Benjaminba4594a2015-06-18 18:36:15 -04002017 {
Steven Valdez32635b82016-08-16 11:25:03 -04002018 name: "SendKeyUpdates",
2019 config: Config{
2020 MaxVersion: VersionTLS13,
2021 },
2022 sendKeyUpdates: 33,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_KEY_UPDATES:",
2025 },
2026 {
David Benjaminba4594a2015-06-18 18:36:15 -04002027 name: "EmptySessionID",
2028 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002029 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002030 SessionTicketsDisabled: true,
2031 },
2032 noSessionCache: true,
2033 flags: []string{"-expect-no-session"},
2034 },
David Benjamin30789da2015-08-29 22:56:45 -04002035 {
2036 name: "Unclean-Shutdown",
2037 config: Config{
2038 Bugs: ProtocolBugs{
2039 NoCloseNotify: true,
2040 ExpectCloseNotify: true,
2041 },
2042 },
2043 shimShutsDown: true,
2044 flags: []string{"-check-close-notify"},
2045 shouldFail: true,
2046 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2047 },
2048 {
2049 name: "Unclean-Shutdown-Ignored",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 NoCloseNotify: true,
2053 },
2054 },
2055 shimShutsDown: true,
2056 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002057 {
David Benjaminfa214e42016-05-10 17:03:10 -04002058 name: "Unclean-Shutdown-Alert",
2059 config: Config{
2060 Bugs: ProtocolBugs{
2061 SendAlertOnShutdown: alertDecompressionFailure,
2062 ExpectCloseNotify: true,
2063 },
2064 },
2065 shimShutsDown: true,
2066 flags: []string{"-check-close-notify"},
2067 shouldFail: true,
2068 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2069 },
2070 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002071 name: "LargePlaintext",
2072 config: Config{
2073 Bugs: ProtocolBugs{
2074 SendLargeRecords: true,
2075 },
2076 },
2077 messageLen: maxPlaintext + 1,
2078 shouldFail: true,
2079 expectedError: ":DATA_LENGTH_TOO_LONG:",
2080 },
2081 {
2082 protocol: dtls,
2083 name: "LargePlaintext-DTLS",
2084 config: Config{
2085 Bugs: ProtocolBugs{
2086 SendLargeRecords: true,
2087 },
2088 },
2089 messageLen: maxPlaintext + 1,
2090 shouldFail: true,
2091 expectedError: ":DATA_LENGTH_TOO_LONG:",
2092 },
2093 {
2094 name: "LargeCiphertext",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 SendLargeRecords: true,
2098 },
2099 },
2100 messageLen: maxPlaintext * 2,
2101 shouldFail: true,
2102 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2103 },
2104 {
2105 protocol: dtls,
2106 name: "LargeCiphertext-DTLS",
2107 config: Config{
2108 Bugs: ProtocolBugs{
2109 SendLargeRecords: true,
2110 },
2111 },
2112 messageLen: maxPlaintext * 2,
2113 // Unlike the other four cases, DTLS drops records which
2114 // are invalid before authentication, so the connection
2115 // does not fail.
2116 expectMessageDropped: true,
2117 },
David Benjamindd6fed92015-10-23 17:41:12 -04002118 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002119 // In TLS 1.2 and below, empty NewSessionTicket messages
2120 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002121 name: "SendEmptySessionTicket",
2122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002124 Bugs: ProtocolBugs{
2125 SendEmptySessionTicket: true,
2126 FailIfSessionOffered: true,
2127 },
2128 },
David Benjamin46662482016-08-17 00:51:00 -04002129 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002130 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002131 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 name: "BadHelloRequest-1",
2133 renegotiate: 1,
2134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002135 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002136 Bugs: ProtocolBugs{
2137 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2138 },
2139 },
2140 flags: []string{
2141 "-renegotiate-freely",
2142 "-expect-total-renegotiations", "1",
2143 },
2144 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002145 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002146 },
2147 {
2148 name: "BadHelloRequest-2",
2149 renegotiate: 1,
2150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002151 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002152 Bugs: ProtocolBugs{
2153 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2154 },
2155 },
2156 flags: []string{
2157 "-renegotiate-freely",
2158 "-expect-total-renegotiations", "1",
2159 },
2160 shouldFail: true,
2161 expectedError: ":BAD_HELLO_REQUEST:",
2162 },
David Benjaminef1b0092015-11-21 14:05:44 -05002163 {
2164 testType: serverTest,
2165 name: "SupportTicketsWithSessionID",
2166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002167 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002168 SessionTicketsDisabled: true,
2169 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002170 resumeConfig: &Config{
2171 MaxVersion: VersionTLS12,
2172 },
David Benjaminef1b0092015-11-21 14:05:44 -05002173 resumeSession: true,
2174 },
David Benjamin02edcd02016-07-27 17:40:37 -04002175 {
2176 protocol: dtls,
2177 name: "DTLS-SendExtraFinished",
2178 config: Config{
2179 Bugs: ProtocolBugs{
2180 SendExtraFinished: true,
2181 },
2182 },
2183 shouldFail: true,
2184 expectedError: ":UNEXPECTED_RECORD:",
2185 },
2186 {
2187 protocol: dtls,
2188 name: "DTLS-SendExtraFinished-Reordered",
2189 config: Config{
2190 Bugs: ProtocolBugs{
2191 MaxHandshakeRecordLength: 2,
2192 ReorderHandshakeFragments: true,
2193 SendExtraFinished: true,
2194 },
2195 },
2196 shouldFail: true,
2197 expectedError: ":UNEXPECTED_RECORD:",
2198 },
David Benjamine97fb482016-07-29 09:23:07 -04002199 {
2200 testType: serverTest,
2201 name: "V2ClientHello-EmptyRecordPrefix",
2202 config: Config{
2203 // Choose a cipher suite that does not involve
2204 // elliptic curves, so no extensions are
2205 // involved.
2206 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002207 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002208 Bugs: ProtocolBugs{
2209 SendV2ClientHello: true,
2210 },
2211 },
2212 sendPrefix: string([]byte{
2213 byte(recordTypeHandshake),
2214 3, 1, // version
2215 0, 0, // length
2216 }),
2217 // A no-op empty record may not be sent before V2ClientHello.
2218 shouldFail: true,
2219 expectedError: ":WRONG_VERSION_NUMBER:",
2220 },
2221 {
2222 testType: serverTest,
2223 name: "V2ClientHello-WarningAlertPrefix",
2224 config: Config{
2225 // Choose a cipher suite that does not involve
2226 // elliptic curves, so no extensions are
2227 // involved.
2228 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002229 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002230 Bugs: ProtocolBugs{
2231 SendV2ClientHello: true,
2232 },
2233 },
2234 sendPrefix: string([]byte{
2235 byte(recordTypeAlert),
2236 3, 1, // version
2237 0, 2, // length
2238 alertLevelWarning, byte(alertDecompressionFailure),
2239 }),
2240 // A no-op warning alert may not be sent before V2ClientHello.
2241 shouldFail: true,
2242 expectedError: ":WRONG_VERSION_NUMBER:",
2243 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002244 {
2245 testType: clientTest,
2246 name: "KeyUpdate",
2247 config: Config{
2248 MaxVersion: VersionTLS13,
2249 Bugs: ProtocolBugs{
2250 SendKeyUpdateBeforeEveryAppDataRecord: true,
2251 },
2252 },
2253 },
David Benjaminabe94e32016-09-04 14:18:58 -04002254 {
2255 name: "SendSNIWarningAlert",
2256 config: Config{
2257 MaxVersion: VersionTLS12,
2258 Bugs: ProtocolBugs{
2259 SendSNIWarningAlert: true,
2260 },
2261 },
2262 },
David Benjaminc241d792016-09-09 10:34:20 -04002263 {
2264 testType: serverTest,
2265 name: "ExtraCompressionMethods-TLS12",
2266 config: Config{
2267 MaxVersion: VersionTLS12,
2268 Bugs: ProtocolBugs{
2269 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2270 },
2271 },
2272 },
2273 {
2274 testType: serverTest,
2275 name: "ExtraCompressionMethods-TLS13",
2276 config: Config{
2277 MaxVersion: VersionTLS13,
2278 Bugs: ProtocolBugs{
2279 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2280 },
2281 },
2282 shouldFail: true,
2283 expectedError: ":INVALID_COMPRESSION_LIST:",
2284 expectedLocalError: "remote error: illegal parameter",
2285 },
2286 {
2287 testType: serverTest,
2288 name: "NoNullCompression-TLS12",
2289 config: Config{
2290 MaxVersion: VersionTLS12,
2291 Bugs: ProtocolBugs{
2292 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2293 },
2294 },
2295 shouldFail: true,
2296 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2297 expectedLocalError: "remote error: illegal parameter",
2298 },
2299 {
2300 testType: serverTest,
2301 name: "NoNullCompression-TLS13",
2302 config: Config{
2303 MaxVersion: VersionTLS13,
2304 Bugs: ProtocolBugs{
2305 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2306 },
2307 },
2308 shouldFail: true,
2309 expectedError: ":INVALID_COMPRESSION_LIST:",
2310 expectedLocalError: "remote error: illegal parameter",
2311 },
David Benjamin65ac9972016-09-02 21:35:25 -04002312 {
2313 name: "GREASE-TLS12",
2314 config: Config{
2315 MaxVersion: VersionTLS12,
2316 Bugs: ProtocolBugs{
2317 ExpectGREASE: true,
2318 },
2319 },
2320 flags: []string{"-enable-grease"},
2321 },
2322 {
2323 name: "GREASE-TLS13",
2324 config: Config{
2325 MaxVersion: VersionTLS13,
2326 Bugs: ProtocolBugs{
2327 ExpectGREASE: true,
2328 },
2329 },
2330 flags: []string{"-enable-grease"},
2331 },
Adam Langley7c803a62015-06-15 15:35:05 -07002332 }
Adam Langley7c803a62015-06-15 15:35:05 -07002333 testCases = append(testCases, basicTests...)
2334}
2335
Adam Langley95c29f32014-06-20 12:00:00 -07002336func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002337 const bogusCipher = 0xfe00
2338
Adam Langley95c29f32014-06-20 12:00:00 -07002339 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002340 const psk = "12345"
2341 const pskIdentity = "luggage combo"
2342
Adam Langley95c29f32014-06-20 12:00:00 -07002343 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002344 var certFile string
2345 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002346 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002347 cert = ecdsaP256Certificate
2348 certFile = ecdsaP256CertificateFile
2349 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002350 } else {
David Benjamin33863262016-07-08 17:20:12 -07002351 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002352 certFile = rsaCertificateFile
2353 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002354 }
2355
David Benjamin48cae082014-10-27 01:06:24 -04002356 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002357 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002358 flags = append(flags,
2359 "-psk", psk,
2360 "-psk-identity", pskIdentity)
2361 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002362 if hasComponent(suite.name, "NULL") {
2363 // NULL ciphers must be explicitly enabled.
2364 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2365 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002366 if hasComponent(suite.name, "CECPQ1") {
2367 // CECPQ1 ciphers must be explicitly enabled.
2368 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2369 }
David Benjamin881f1962016-08-10 18:29:12 -04002370 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2371 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2372 // for now.
2373 flags = append(flags, "-cipher", suite.name)
2374 }
David Benjamin48cae082014-10-27 01:06:24 -04002375
Adam Langley95c29f32014-06-20 12:00:00 -07002376 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002377 for _, protocol := range []protocol{tls, dtls} {
2378 var prefix string
2379 if protocol == dtls {
2380 if !ver.hasDTLS {
2381 continue
2382 }
2383 prefix = "D"
2384 }
Adam Langley95c29f32014-06-20 12:00:00 -07002385
David Benjamin0407e762016-06-17 16:41:18 -04002386 var shouldServerFail, shouldClientFail bool
2387 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2388 // BoringSSL clients accept ECDHE on SSLv3, but
2389 // a BoringSSL server will never select it
2390 // because the extension is missing.
2391 shouldServerFail = true
2392 }
2393 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2394 shouldClientFail = true
2395 shouldServerFail = true
2396 }
David Benjamin54c217c2016-07-13 12:35:25 -04002397 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002398 shouldClientFail = true
2399 shouldServerFail = true
2400 }
David Benjamin0407e762016-06-17 16:41:18 -04002401 if !isDTLSCipher(suite.name) && protocol == dtls {
2402 shouldClientFail = true
2403 shouldServerFail = true
2404 }
David Benjamin4298d772015-12-19 00:18:25 -05002405
David Benjamin0407e762016-06-17 16:41:18 -04002406 var expectedServerError, expectedClientError string
2407 if shouldServerFail {
2408 expectedServerError = ":NO_SHARED_CIPHER:"
2409 }
2410 if shouldClientFail {
2411 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2412 }
David Benjamin025b3d32014-07-01 19:53:04 -04002413
David Benjamin6fd297b2014-08-11 18:43:38 -04002414 testCases = append(testCases, testCase{
2415 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002416 protocol: protocol,
2417
2418 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002419 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002420 MinVersion: ver.version,
2421 MaxVersion: ver.version,
2422 CipherSuites: []uint16{suite.id},
2423 Certificates: []Certificate{cert},
2424 PreSharedKey: []byte(psk),
2425 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002426 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002427 EnableAllCiphers: shouldServerFail,
2428 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002429 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002430 },
2431 certFile: certFile,
2432 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002433 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002434 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002435 shouldFail: shouldServerFail,
2436 expectedError: expectedServerError,
2437 })
2438
2439 testCases = append(testCases, testCase{
2440 testType: clientTest,
2441 protocol: protocol,
2442 name: prefix + ver.name + "-" + suite.name + "-client",
2443 config: Config{
2444 MinVersion: ver.version,
2445 MaxVersion: ver.version,
2446 CipherSuites: []uint16{suite.id},
2447 Certificates: []Certificate{cert},
2448 PreSharedKey: []byte(psk),
2449 PreSharedKeyIdentity: pskIdentity,
2450 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002451 EnableAllCiphers: shouldClientFail,
2452 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002453 },
2454 },
2455 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002456 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002457 shouldFail: shouldClientFail,
2458 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002459 })
David Benjamin2c99d282015-09-01 10:23:00 -04002460
Nick Harper1fd39d82016-06-14 18:14:35 -07002461 if !shouldClientFail {
2462 // Ensure the maximum record size is accepted.
2463 testCases = append(testCases, testCase{
2464 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2465 config: Config{
2466 MinVersion: ver.version,
2467 MaxVersion: ver.version,
2468 CipherSuites: []uint16{suite.id},
2469 Certificates: []Certificate{cert},
2470 PreSharedKey: []byte(psk),
2471 PreSharedKeyIdentity: pskIdentity,
2472 },
2473 flags: flags,
2474 messageLen: maxPlaintext,
2475 })
2476 }
2477 }
David Benjamin2c99d282015-09-01 10:23:00 -04002478 }
Adam Langley95c29f32014-06-20 12:00:00 -07002479 }
Adam Langleya7997f12015-05-14 17:38:50 -07002480
2481 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002482 name: "NoSharedCipher",
2483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002484 MaxVersion: VersionTLS12,
2485 CipherSuites: []uint16{},
2486 },
2487 shouldFail: true,
2488 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2489 })
2490
2491 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002492 name: "NoSharedCipher-TLS13",
2493 config: Config{
2494 MaxVersion: VersionTLS13,
2495 CipherSuites: []uint16{},
2496 },
2497 shouldFail: true,
2498 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2499 })
2500
2501 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002502 name: "UnsupportedCipherSuite",
2503 config: Config{
2504 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002505 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002506 Bugs: ProtocolBugs{
2507 IgnorePeerCipherPreferences: true,
2508 },
2509 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002510 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002511 shouldFail: true,
2512 expectedError: ":WRONG_CIPHER_RETURNED:",
2513 })
2514
2515 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002516 name: "ServerHelloBogusCipher",
2517 config: Config{
2518 MaxVersion: VersionTLS12,
2519 Bugs: ProtocolBugs{
2520 SendCipherSuite: bogusCipher,
2521 },
2522 },
2523 shouldFail: true,
2524 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2525 })
2526 testCases = append(testCases, testCase{
2527 name: "ServerHelloBogusCipher-TLS13",
2528 config: Config{
2529 MaxVersion: VersionTLS13,
2530 Bugs: ProtocolBugs{
2531 SendCipherSuite: bogusCipher,
2532 },
2533 },
2534 shouldFail: true,
2535 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2536 })
2537
2538 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002539 name: "WeakDH",
2540 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002541 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002542 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2543 Bugs: ProtocolBugs{
2544 // This is a 1023-bit prime number, generated
2545 // with:
2546 // openssl gendh 1023 | openssl asn1parse -i
2547 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2548 },
2549 },
2550 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002551 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002552 })
Adam Langleycef75832015-09-03 14:51:12 -07002553
David Benjamincd24a392015-11-11 13:23:05 -08002554 testCases = append(testCases, testCase{
2555 name: "SillyDH",
2556 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002557 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002558 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2559 Bugs: ProtocolBugs{
2560 // This is a 4097-bit prime number, generated
2561 // with:
2562 // openssl gendh 4097 | openssl asn1parse -i
2563 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2564 },
2565 },
2566 shouldFail: true,
2567 expectedError: ":DH_P_TOO_LONG:",
2568 })
2569
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002570 // This test ensures that Diffie-Hellman public values are padded with
2571 // zeros so that they're the same length as the prime. This is to avoid
2572 // hitting a bug in yaSSL.
2573 testCases = append(testCases, testCase{
2574 testType: serverTest,
2575 name: "DHPublicValuePadded",
2576 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002577 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002578 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2579 Bugs: ProtocolBugs{
2580 RequireDHPublicValueLen: (1025 + 7) / 8,
2581 },
2582 },
2583 flags: []string{"-use-sparse-dh-prime"},
2584 })
David Benjamincd24a392015-11-11 13:23:05 -08002585
David Benjamin241ae832016-01-15 03:04:54 -05002586 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002587 testCases = append(testCases, testCase{
2588 testType: serverTest,
2589 name: "UnknownCipher",
2590 config: Config{
2591 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2592 },
2593 })
2594
David Benjamin78679342016-09-16 19:42:05 -04002595 // Test empty ECDHE_PSK identity hints work as expected.
2596 testCases = append(testCases, testCase{
2597 name: "EmptyECDHEPSKHint",
2598 config: Config{
2599 MaxVersion: VersionTLS12,
2600 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2601 PreSharedKey: []byte("secret"),
2602 },
2603 flags: []string{"-psk", "secret"},
2604 })
2605
2606 // Test empty PSK identity hints work as expected, even if an explicit
2607 // ServerKeyExchange is sent.
2608 testCases = append(testCases, testCase{
2609 name: "ExplicitEmptyPSKHint",
2610 config: Config{
2611 MaxVersion: VersionTLS12,
2612 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2613 PreSharedKey: []byte("secret"),
2614 Bugs: ProtocolBugs{
2615 AlwaysSendPreSharedKeyIdentityHint: true,
2616 },
2617 },
2618 flags: []string{"-psk", "secret"},
2619 })
2620
Adam Langleycef75832015-09-03 14:51:12 -07002621 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2622 // 1.1 specific cipher suite settings. A server is setup with the given
2623 // cipher lists and then a connection is made for each member of
2624 // expectations. The cipher suite that the server selects must match
2625 // the specified one.
2626 var versionSpecificCiphersTest = []struct {
2627 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2628 // expectations is a map from TLS version to cipher suite id.
2629 expectations map[uint16]uint16
2630 }{
2631 {
2632 // Test that the null case (where no version-specific ciphers are set)
2633 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002634 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2635 "", // no ciphers specifically for TLS ≥ 1.0
2636 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002637 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002638 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2639 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2640 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2641 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002642 },
2643 },
2644 {
2645 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2646 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002647 "DES-CBC3-SHA:AES128-SHA", // default
2648 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2649 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002650 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002651 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002652 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2653 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2654 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2655 },
2656 },
2657 {
2658 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2659 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002660 "DES-CBC3-SHA:AES128-SHA", // default
2661 "", // no ciphers specifically for TLS ≥ 1.0
2662 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002663 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002664 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2665 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002666 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2667 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2668 },
2669 },
2670 {
2671 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2672 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002673 "DES-CBC3-SHA:AES128-SHA", // default
2674 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2675 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002676 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002677 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002678 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2679 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2680 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2681 },
2682 },
2683 }
2684
2685 for i, test := range versionSpecificCiphersTest {
2686 for version, expectedCipherSuite := range test.expectations {
2687 flags := []string{"-cipher", test.ciphersDefault}
2688 if len(test.ciphersTLS10) > 0 {
2689 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2690 }
2691 if len(test.ciphersTLS11) > 0 {
2692 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2693 }
2694
2695 testCases = append(testCases, testCase{
2696 testType: serverTest,
2697 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2698 config: Config{
2699 MaxVersion: version,
2700 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002701 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002702 },
2703 flags: flags,
2704 expectedCipher: expectedCipherSuite,
2705 })
2706 }
2707 }
Adam Langley95c29f32014-06-20 12:00:00 -07002708}
2709
2710func addBadECDSASignatureTests() {
2711 for badR := BadValue(1); badR < NumBadValues; badR++ {
2712 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002713 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002714 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2715 config: Config{
2716 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002717 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002718 Bugs: ProtocolBugs{
2719 BadECDSAR: badR,
2720 BadECDSAS: badS,
2721 },
2722 },
2723 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002724 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002725 })
2726 }
2727 }
2728}
2729
Adam Langley80842bd2014-06-20 12:00:00 -07002730func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002731 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002732 name: "MaxCBCPadding",
2733 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002734 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002735 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2736 Bugs: ProtocolBugs{
2737 MaxPadding: true,
2738 },
2739 },
2740 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2741 })
David Benjamin025b3d32014-07-01 19:53:04 -04002742 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002743 name: "BadCBCPadding",
2744 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002745 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002746 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2747 Bugs: ProtocolBugs{
2748 PaddingFirstByteBad: true,
2749 },
2750 },
2751 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002752 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002753 })
2754 // OpenSSL previously had an issue where the first byte of padding in
2755 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002756 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002757 name: "BadCBCPadding255",
2758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002759 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2761 Bugs: ProtocolBugs{
2762 MaxPadding: true,
2763 PaddingFirstByteBadIf255: true,
2764 },
2765 },
2766 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2767 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002768 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002769 })
2770}
2771
Kenny Root7fdeaf12014-08-05 15:23:37 -07002772func addCBCSplittingTests() {
2773 testCases = append(testCases, testCase{
2774 name: "CBCRecordSplitting",
2775 config: Config{
2776 MaxVersion: VersionTLS10,
2777 MinVersion: VersionTLS10,
2778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2779 },
David Benjaminac8302a2015-09-01 17:18:15 -04002780 messageLen: -1, // read until EOF
2781 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002782 flags: []string{
2783 "-async",
2784 "-write-different-record-sizes",
2785 "-cbc-record-splitting",
2786 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002787 })
2788 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002789 name: "CBCRecordSplittingPartialWrite",
2790 config: Config{
2791 MaxVersion: VersionTLS10,
2792 MinVersion: VersionTLS10,
2793 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2794 },
2795 messageLen: -1, // read until EOF
2796 flags: []string{
2797 "-async",
2798 "-write-different-record-sizes",
2799 "-cbc-record-splitting",
2800 "-partial-write",
2801 },
2802 })
2803}
2804
David Benjamin636293b2014-07-08 17:59:18 -04002805func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002806 // Add a dummy cert pool to stress certificate authority parsing.
2807 // TODO(davidben): Add tests that those values parse out correctly.
2808 certPool := x509.NewCertPool()
2809 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2810 if err != nil {
2811 panic(err)
2812 }
2813 certPool.AddCert(cert)
2814
David Benjamin636293b2014-07-08 17:59:18 -04002815 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002816 testCases = append(testCases, testCase{
2817 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002818 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002819 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002820 MinVersion: ver.version,
2821 MaxVersion: ver.version,
2822 ClientAuth: RequireAnyClientCert,
2823 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002824 },
2825 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002826 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2827 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002828 },
2829 })
2830 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002831 testType: serverTest,
2832 name: ver.name + "-Server-ClientAuth-RSA",
2833 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002834 MinVersion: ver.version,
2835 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002836 Certificates: []Certificate{rsaCertificate},
2837 },
2838 flags: []string{"-require-any-client-certificate"},
2839 })
David Benjamine098ec22014-08-27 23:13:20 -04002840 if ver.version != VersionSSL30 {
2841 testCases = append(testCases, testCase{
2842 testType: serverTest,
2843 name: ver.name + "-Server-ClientAuth-ECDSA",
2844 config: Config{
2845 MinVersion: ver.version,
2846 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002847 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002848 },
2849 flags: []string{"-require-any-client-certificate"},
2850 })
2851 testCases = append(testCases, testCase{
2852 testType: clientTest,
2853 name: ver.name + "-Client-ClientAuth-ECDSA",
2854 config: Config{
2855 MinVersion: ver.version,
2856 MaxVersion: ver.version,
2857 ClientAuth: RequireAnyClientCert,
2858 ClientCAs: certPool,
2859 },
2860 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002861 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2862 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002863 },
2864 })
2865 }
Adam Langley37646832016-08-01 16:16:46 -07002866
2867 testCases = append(testCases, testCase{
2868 name: "NoClientCertificate-" + ver.name,
2869 config: Config{
2870 MinVersion: ver.version,
2871 MaxVersion: ver.version,
2872 ClientAuth: RequireAnyClientCert,
2873 },
2874 shouldFail: true,
2875 expectedLocalError: "client didn't provide a certificate",
2876 })
2877
2878 testCases = append(testCases, testCase{
2879 // Even if not configured to expect a certificate, OpenSSL will
2880 // return X509_V_OK as the verify_result.
2881 testType: serverTest,
2882 name: "NoClientCertificateRequested-Server-" + ver.name,
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 },
2887 flags: []string{
2888 "-expect-verify-result",
2889 },
2890 // TODO(davidben): Switch this to true when TLS 1.3
2891 // supports session resumption.
2892 resumeSession: ver.version < VersionTLS13,
2893 })
2894
2895 testCases = append(testCases, testCase{
2896 // If a client certificate is not provided, OpenSSL will still
2897 // return X509_V_OK as the verify_result.
2898 testType: serverTest,
2899 name: "NoClientCertificate-Server-" + ver.name,
2900 config: Config{
2901 MinVersion: ver.version,
2902 MaxVersion: ver.version,
2903 },
2904 flags: []string{
2905 "-expect-verify-result",
2906 "-verify-peer",
2907 },
2908 // TODO(davidben): Switch this to true when TLS 1.3
2909 // supports session resumption.
2910 resumeSession: ver.version < VersionTLS13,
2911 })
2912
2913 testCases = append(testCases, testCase{
2914 testType: serverTest,
2915 name: "RequireAnyClientCertificate-" + ver.name,
2916 config: Config{
2917 MinVersion: ver.version,
2918 MaxVersion: ver.version,
2919 },
2920 flags: []string{"-require-any-client-certificate"},
2921 shouldFail: true,
2922 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2923 })
2924
2925 if ver.version != VersionSSL30 {
2926 testCases = append(testCases, testCase{
2927 testType: serverTest,
2928 name: "SkipClientCertificate-" + ver.name,
2929 config: Config{
2930 MinVersion: ver.version,
2931 MaxVersion: ver.version,
2932 Bugs: ProtocolBugs{
2933 SkipClientCertificate: true,
2934 },
2935 },
2936 // Setting SSL_VERIFY_PEER allows anonymous clients.
2937 flags: []string{"-verify-peer"},
2938 shouldFail: true,
2939 expectedError: ":UNEXPECTED_MESSAGE:",
2940 })
2941 }
David Benjamin636293b2014-07-08 17:59:18 -04002942 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002943
David Benjaminc032dfa2016-05-12 14:54:57 -04002944 // Client auth is only legal in certificate-based ciphers.
2945 testCases = append(testCases, testCase{
2946 testType: clientTest,
2947 name: "ClientAuth-PSK",
2948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002949 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002950 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2951 PreSharedKey: []byte("secret"),
2952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-psk", "secret",
2958 },
2959 shouldFail: true,
2960 expectedError: ":UNEXPECTED_MESSAGE:",
2961 })
2962 testCases = append(testCases, testCase{
2963 testType: clientTest,
2964 name: "ClientAuth-ECDHE_PSK",
2965 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002966 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002967 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2968 PreSharedKey: []byte("secret"),
2969 ClientAuth: RequireAnyClientCert,
2970 },
2971 flags: []string{
2972 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2973 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2974 "-psk", "secret",
2975 },
2976 shouldFail: true,
2977 expectedError: ":UNEXPECTED_MESSAGE:",
2978 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002979
2980 // Regression test for a bug where the client CA list, if explicitly
2981 // set to NULL, was mis-encoded.
2982 testCases = append(testCases, testCase{
2983 testType: serverTest,
2984 name: "Null-Client-CA-List",
2985 config: Config{
2986 MaxVersion: VersionTLS12,
2987 Certificates: []Certificate{rsaCertificate},
2988 },
2989 flags: []string{
2990 "-require-any-client-certificate",
2991 "-use-null-client-ca-list",
2992 },
2993 })
David Benjamin636293b2014-07-08 17:59:18 -04002994}
2995
Adam Langley75712922014-10-10 16:23:43 -07002996func addExtendedMasterSecretTests() {
2997 const expectEMSFlag = "-expect-extended-master-secret"
2998
2999 for _, with := range []bool{false, true} {
3000 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003001 if with {
3002 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003003 }
3004
3005 for _, isClient := range []bool{false, true} {
3006 suffix := "-Server"
3007 testType := serverTest
3008 if isClient {
3009 suffix = "-Client"
3010 testType = clientTest
3011 }
3012
3013 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003014 // In TLS 1.3, the extension is irrelevant and
3015 // always reports as enabled.
3016 var flags []string
3017 if with || ver.version >= VersionTLS13 {
3018 flags = []string{expectEMSFlag}
3019 }
3020
Adam Langley75712922014-10-10 16:23:43 -07003021 test := testCase{
3022 testType: testType,
3023 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3024 config: Config{
3025 MinVersion: ver.version,
3026 MaxVersion: ver.version,
3027 Bugs: ProtocolBugs{
3028 NoExtendedMasterSecret: !with,
3029 RequireExtendedMasterSecret: with,
3030 },
3031 },
David Benjamin48cae082014-10-27 01:06:24 -04003032 flags: flags,
3033 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003034 }
3035 if test.shouldFail {
3036 test.expectedLocalError = "extended master secret required but not supported by peer"
3037 }
3038 testCases = append(testCases, test)
3039 }
3040 }
3041 }
3042
Adam Langleyba5934b2015-06-02 10:50:35 -07003043 for _, isClient := range []bool{false, true} {
3044 for _, supportedInFirstConnection := range []bool{false, true} {
3045 for _, supportedInResumeConnection := range []bool{false, true} {
3046 boolToWord := func(b bool) string {
3047 if b {
3048 return "Yes"
3049 }
3050 return "No"
3051 }
3052 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3053 if isClient {
3054 suffix += "Client"
3055 } else {
3056 suffix += "Server"
3057 }
3058
3059 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003060 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003061 Bugs: ProtocolBugs{
3062 RequireExtendedMasterSecret: true,
3063 },
3064 }
3065
3066 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003067 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003068 Bugs: ProtocolBugs{
3069 NoExtendedMasterSecret: true,
3070 },
3071 }
3072
3073 test := testCase{
3074 name: "ExtendedMasterSecret-" + suffix,
3075 resumeSession: true,
3076 }
3077
3078 if !isClient {
3079 test.testType = serverTest
3080 }
3081
3082 if supportedInFirstConnection {
3083 test.config = supportedConfig
3084 } else {
3085 test.config = noSupportConfig
3086 }
3087
3088 if supportedInResumeConnection {
3089 test.resumeConfig = &supportedConfig
3090 } else {
3091 test.resumeConfig = &noSupportConfig
3092 }
3093
3094 switch suffix {
3095 case "YesToYes-Client", "YesToYes-Server":
3096 // When a session is resumed, it should
3097 // still be aware that its master
3098 // secret was generated via EMS and
3099 // thus it's safe to use tls-unique.
3100 test.flags = []string{expectEMSFlag}
3101 case "NoToYes-Server":
3102 // If an original connection did not
3103 // contain EMS, but a resumption
3104 // handshake does, then a server should
3105 // not resume the session.
3106 test.expectResumeRejected = true
3107 case "YesToNo-Server":
3108 // Resuming an EMS session without the
3109 // EMS extension should cause the
3110 // server to abort the connection.
3111 test.shouldFail = true
3112 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3113 case "NoToYes-Client":
3114 // A client should abort a connection
3115 // where the server resumed a non-EMS
3116 // session but echoed the EMS
3117 // extension.
3118 test.shouldFail = true
3119 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3120 case "YesToNo-Client":
3121 // A client should abort a connection
3122 // where the server didn't echo EMS
3123 // when the session used it.
3124 test.shouldFail = true
3125 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3126 }
3127
3128 testCases = append(testCases, test)
3129 }
3130 }
3131 }
David Benjamin163c9562016-08-29 23:14:17 -04003132
3133 // Switching EMS on renegotiation is forbidden.
3134 testCases = append(testCases, testCase{
3135 name: "ExtendedMasterSecret-Renego-NoEMS",
3136 config: Config{
3137 MaxVersion: VersionTLS12,
3138 Bugs: ProtocolBugs{
3139 NoExtendedMasterSecret: true,
3140 NoExtendedMasterSecretOnRenegotiation: true,
3141 },
3142 },
3143 renegotiate: 1,
3144 flags: []string{
3145 "-renegotiate-freely",
3146 "-expect-total-renegotiations", "1",
3147 },
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 name: "ExtendedMasterSecret-Renego-Upgrade",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 Bugs: ProtocolBugs{
3155 NoExtendedMasterSecret: true,
3156 },
3157 },
3158 renegotiate: 1,
3159 flags: []string{
3160 "-renegotiate-freely",
3161 "-expect-total-renegotiations", "1",
3162 },
3163 shouldFail: true,
3164 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3165 })
3166
3167 testCases = append(testCases, testCase{
3168 name: "ExtendedMasterSecret-Renego-Downgrade",
3169 config: Config{
3170 MaxVersion: VersionTLS12,
3171 Bugs: ProtocolBugs{
3172 NoExtendedMasterSecretOnRenegotiation: true,
3173 },
3174 },
3175 renegotiate: 1,
3176 flags: []string{
3177 "-renegotiate-freely",
3178 "-expect-total-renegotiations", "1",
3179 },
3180 shouldFail: true,
3181 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3182 })
Adam Langley75712922014-10-10 16:23:43 -07003183}
3184
David Benjamin582ba042016-07-07 12:33:25 -07003185type stateMachineTestConfig struct {
3186 protocol protocol
3187 async bool
3188 splitHandshake, packHandshakeFlight bool
3189}
3190
David Benjamin43ec06f2014-08-05 02:28:57 -04003191// Adds tests that try to cover the range of the handshake state machine, under
3192// various conditions. Some of these are redundant with other tests, but they
3193// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003194func addAllStateMachineCoverageTests() {
3195 for _, async := range []bool{false, true} {
3196 for _, protocol := range []protocol{tls, dtls} {
3197 addStateMachineCoverageTests(stateMachineTestConfig{
3198 protocol: protocol,
3199 async: async,
3200 })
3201 addStateMachineCoverageTests(stateMachineTestConfig{
3202 protocol: protocol,
3203 async: async,
3204 splitHandshake: true,
3205 })
3206 if protocol == tls {
3207 addStateMachineCoverageTests(stateMachineTestConfig{
3208 protocol: protocol,
3209 async: async,
3210 packHandshakeFlight: true,
3211 })
3212 }
3213 }
3214 }
3215}
3216
3217func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 var tests []testCase
3219
3220 // Basic handshake, with resumption. Client and server,
3221 // session ID and session ticket.
3222 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003223 name: "Basic-Client",
3224 config: Config{
3225 MaxVersion: VersionTLS12,
3226 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003227 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003228 // Ensure session tickets are used, not session IDs.
3229 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 })
3231 tests = append(tests, testCase{
3232 name: "Basic-Client-RenewTicket",
3233 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003234 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003235 Bugs: ProtocolBugs{
3236 RenewTicketOnResume: true,
3237 },
3238 },
David Benjamin46662482016-08-17 00:51:00 -04003239 flags: []string{"-expect-ticket-renewal"},
3240 resumeSession: true,
3241 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003242 })
3243 tests = append(tests, testCase{
3244 name: "Basic-Client-NoTicket",
3245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003247 SessionTicketsDisabled: true,
3248 },
3249 resumeSession: true,
3250 })
3251 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003252 name: "Basic-Client-Implicit",
3253 config: Config{
3254 MaxVersion: VersionTLS12,
3255 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003256 flags: []string{"-implicit-handshake"},
3257 resumeSession: true,
3258 })
3259 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003260 testType: serverTest,
3261 name: "Basic-Server",
3262 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003263 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003264 Bugs: ProtocolBugs{
3265 RequireSessionTickets: true,
3266 },
3267 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 resumeSession: true,
3269 })
3270 tests = append(tests, testCase{
3271 testType: serverTest,
3272 name: "Basic-Server-NoTickets",
3273 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003274 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003275 SessionTicketsDisabled: true,
3276 },
3277 resumeSession: true,
3278 })
3279 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003280 testType: serverTest,
3281 name: "Basic-Server-Implicit",
3282 config: Config{
3283 MaxVersion: VersionTLS12,
3284 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003285 flags: []string{"-implicit-handshake"},
3286 resumeSession: true,
3287 })
3288 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003289 testType: serverTest,
3290 name: "Basic-Server-EarlyCallback",
3291 config: Config{
3292 MaxVersion: VersionTLS12,
3293 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003294 flags: []string{"-use-early-callback"},
3295 resumeSession: true,
3296 })
3297
Steven Valdez143e8b32016-07-11 13:19:03 -04003298 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003299 if config.protocol == tls {
3300 tests = append(tests, testCase{
3301 name: "TLS13-1RTT-Client",
3302 config: Config{
3303 MaxVersion: VersionTLS13,
3304 MinVersion: VersionTLS13,
3305 },
David Benjamin46662482016-08-17 00:51:00 -04003306 resumeSession: true,
3307 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003308 })
3309
3310 tests = append(tests, testCase{
3311 testType: serverTest,
3312 name: "TLS13-1RTT-Server",
3313 config: Config{
3314 MaxVersion: VersionTLS13,
3315 MinVersion: VersionTLS13,
3316 },
David Benjamin46662482016-08-17 00:51:00 -04003317 resumeSession: true,
3318 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003319 })
3320
3321 tests = append(tests, testCase{
3322 name: "TLS13-HelloRetryRequest-Client",
3323 config: Config{
3324 MaxVersion: VersionTLS13,
3325 MinVersion: VersionTLS13,
3326 // P-384 requires a HelloRetryRequest against
3327 // BoringSSL's default configuration. Assert
3328 // that we do indeed test this with
3329 // ExpectMissingKeyShare.
3330 CurvePreferences: []CurveID{CurveP384},
3331 Bugs: ProtocolBugs{
3332 ExpectMissingKeyShare: true,
3333 },
3334 },
3335 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3336 resumeSession: true,
3337 })
3338
3339 tests = append(tests, testCase{
3340 testType: serverTest,
3341 name: "TLS13-HelloRetryRequest-Server",
3342 config: Config{
3343 MaxVersion: VersionTLS13,
3344 MinVersion: VersionTLS13,
3345 // Require a HelloRetryRequest for every curve.
3346 DefaultCurves: []CurveID{},
3347 },
3348 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3349 resumeSession: true,
3350 })
3351 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003352
David Benjamin760b1dd2015-05-15 23:33:48 -04003353 // TLS client auth.
3354 tests = append(tests, testCase{
3355 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003356 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003357 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003358 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003359 ClientAuth: RequestClientCert,
3360 },
3361 })
3362 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003363 testType: serverTest,
3364 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003365 config: Config{
3366 MaxVersion: VersionTLS12,
3367 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003368 // Setting SSL_VERIFY_PEER allows anonymous clients.
3369 flags: []string{"-verify-peer"},
3370 })
David Benjamin582ba042016-07-07 12:33:25 -07003371 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003372 tests = append(tests, testCase{
3373 testType: clientTest,
3374 name: "ClientAuth-NoCertificate-Client-SSL3",
3375 config: Config{
3376 MaxVersion: VersionSSL30,
3377 ClientAuth: RequestClientCert,
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: serverTest,
3382 name: "ClientAuth-NoCertificate-Server-SSL3",
3383 config: Config{
3384 MaxVersion: VersionSSL30,
3385 },
3386 // Setting SSL_VERIFY_PEER allows anonymous clients.
3387 flags: []string{"-verify-peer"},
3388 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003389 tests = append(tests, testCase{
3390 testType: clientTest,
3391 name: "ClientAuth-NoCertificate-Client-TLS13",
3392 config: Config{
3393 MaxVersion: VersionTLS13,
3394 ClientAuth: RequestClientCert,
3395 },
3396 })
3397 tests = append(tests, testCase{
3398 testType: serverTest,
3399 name: "ClientAuth-NoCertificate-Server-TLS13",
3400 config: Config{
3401 MaxVersion: VersionTLS13,
3402 },
3403 // Setting SSL_VERIFY_PEER allows anonymous clients.
3404 flags: []string{"-verify-peer"},
3405 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003406 }
3407 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003408 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003409 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003412 ClientAuth: RequireAnyClientCert,
3413 },
3414 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003415 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3416 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003417 },
3418 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003419 tests = append(tests, testCase{
3420 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003421 name: "ClientAuth-RSA-Client-TLS13",
3422 config: Config{
3423 MaxVersion: VersionTLS13,
3424 ClientAuth: RequireAnyClientCert,
3425 },
3426 flags: []string{
3427 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3428 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3429 },
3430 })
3431 tests = append(tests, testCase{
3432 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003433 name: "ClientAuth-ECDSA-Client",
3434 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003435 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003436 ClientAuth: RequireAnyClientCert,
3437 },
3438 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003439 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3440 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003441 },
3442 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003443 tests = append(tests, testCase{
3444 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003445 name: "ClientAuth-ECDSA-Client-TLS13",
3446 config: Config{
3447 MaxVersion: VersionTLS13,
3448 ClientAuth: RequireAnyClientCert,
3449 },
3450 flags: []string{
3451 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3452 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3453 },
3454 })
3455 tests = append(tests, testCase{
3456 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003457 name: "ClientAuth-NoCertificate-OldCallback",
3458 config: Config{
3459 MaxVersion: VersionTLS12,
3460 ClientAuth: RequestClientCert,
3461 },
3462 flags: []string{"-use-old-client-cert-callback"},
3463 })
3464 tests = append(tests, testCase{
3465 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003466 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3467 config: Config{
3468 MaxVersion: VersionTLS13,
3469 ClientAuth: RequestClientCert,
3470 },
3471 flags: []string{"-use-old-client-cert-callback"},
3472 })
3473 tests = append(tests, testCase{
3474 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003475 name: "ClientAuth-OldCallback",
3476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003477 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003478 ClientAuth: RequireAnyClientCert,
3479 },
3480 flags: []string{
3481 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3482 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3483 "-use-old-client-cert-callback",
3484 },
3485 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003486 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003487 testType: clientTest,
3488 name: "ClientAuth-OldCallback-TLS13",
3489 config: Config{
3490 MaxVersion: VersionTLS13,
3491 ClientAuth: RequireAnyClientCert,
3492 },
3493 flags: []string{
3494 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3495 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3496 "-use-old-client-cert-callback",
3497 },
3498 })
3499 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003500 testType: serverTest,
3501 name: "ClientAuth-Server",
3502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003503 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003504 Certificates: []Certificate{rsaCertificate},
3505 },
3506 flags: []string{"-require-any-client-certificate"},
3507 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003508 tests = append(tests, testCase{
3509 testType: serverTest,
3510 name: "ClientAuth-Server-TLS13",
3511 config: Config{
3512 MaxVersion: VersionTLS13,
3513 Certificates: []Certificate{rsaCertificate},
3514 },
3515 flags: []string{"-require-any-client-certificate"},
3516 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003517
David Benjamin4c3ddf72016-06-29 18:13:53 -04003518 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003519 tests = append(tests, testCase{
3520 testType: serverTest,
3521 name: "Basic-Server-RSA",
3522 config: Config{
3523 MaxVersion: VersionTLS12,
3524 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3525 },
3526 flags: []string{
3527 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3528 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3529 },
3530 })
3531 tests = append(tests, testCase{
3532 testType: serverTest,
3533 name: "Basic-Server-ECDHE-RSA",
3534 config: Config{
3535 MaxVersion: VersionTLS12,
3536 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3537 },
3538 flags: []string{
3539 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3540 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3541 },
3542 })
3543 tests = append(tests, testCase{
3544 testType: serverTest,
3545 name: "Basic-Server-ECDHE-ECDSA",
3546 config: Config{
3547 MaxVersion: VersionTLS12,
3548 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3549 },
3550 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003551 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3552 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003553 },
3554 })
3555
David Benjamin760b1dd2015-05-15 23:33:48 -04003556 // No session ticket support; server doesn't send NewSessionTicket.
3557 tests = append(tests, testCase{
3558 name: "SessionTicketsDisabled-Client",
3559 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003560 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003561 SessionTicketsDisabled: true,
3562 },
3563 })
3564 tests = append(tests, testCase{
3565 testType: serverTest,
3566 name: "SessionTicketsDisabled-Server",
3567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003568 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003569 SessionTicketsDisabled: true,
3570 },
3571 })
3572
3573 // Skip ServerKeyExchange in PSK key exchange if there's no
3574 // identity hint.
3575 tests = append(tests, testCase{
3576 name: "EmptyPSKHint-Client",
3577 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003578 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003579 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3580 PreSharedKey: []byte("secret"),
3581 },
3582 flags: []string{"-psk", "secret"},
3583 })
3584 tests = append(tests, testCase{
3585 testType: serverTest,
3586 name: "EmptyPSKHint-Server",
3587 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003588 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003589 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3590 PreSharedKey: []byte("secret"),
3591 },
3592 flags: []string{"-psk", "secret"},
3593 })
3594
David Benjamin4c3ddf72016-06-29 18:13:53 -04003595 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003596 tests = append(tests, testCase{
3597 testType: clientTest,
3598 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003599 config: Config{
3600 MaxVersion: VersionTLS12,
3601 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003602 flags: []string{
3603 "-enable-ocsp-stapling",
3604 "-expect-ocsp-response",
3605 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003606 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003607 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003608 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003609 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003610 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003611 testType: serverTest,
3612 name: "OCSPStapling-Server",
3613 config: Config{
3614 MaxVersion: VersionTLS12,
3615 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003616 expectedOCSPResponse: testOCSPResponse,
3617 flags: []string{
3618 "-ocsp-response",
3619 base64.StdEncoding.EncodeToString(testOCSPResponse),
3620 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003621 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003622 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003623 tests = append(tests, testCase{
3624 testType: clientTest,
3625 name: "OCSPStapling-Client-TLS13",
3626 config: Config{
3627 MaxVersion: VersionTLS13,
3628 },
3629 flags: []string{
3630 "-enable-ocsp-stapling",
3631 "-expect-ocsp-response",
3632 base64.StdEncoding.EncodeToString(testOCSPResponse),
3633 "-verify-peer",
3634 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003635 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003636 })
3637 tests = append(tests, testCase{
3638 testType: serverTest,
3639 name: "OCSPStapling-Server-TLS13",
3640 config: Config{
3641 MaxVersion: VersionTLS13,
3642 },
3643 expectedOCSPResponse: testOCSPResponse,
3644 flags: []string{
3645 "-ocsp-response",
3646 base64.StdEncoding.EncodeToString(testOCSPResponse),
3647 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003648 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003649 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003650
David Benjamin4c3ddf72016-06-29 18:13:53 -04003651 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003652 for _, vers := range tlsVersions {
3653 if config.protocol == dtls && !vers.hasDTLS {
3654 continue
3655 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003656 for _, testType := range []testType{clientTest, serverTest} {
3657 suffix := "-Client"
3658 if testType == serverTest {
3659 suffix = "-Server"
3660 }
3661 suffix += "-" + vers.name
3662
3663 flag := "-verify-peer"
3664 if testType == serverTest {
3665 flag = "-require-any-client-certificate"
3666 }
3667
3668 tests = append(tests, testCase{
3669 testType: testType,
3670 name: "CertificateVerificationSucceed" + suffix,
3671 config: Config{
3672 MaxVersion: vers.version,
3673 Certificates: []Certificate{rsaCertificate},
3674 },
3675 flags: []string{
3676 flag,
3677 "-expect-verify-result",
3678 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003679 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003680 })
3681 tests = append(tests, testCase{
3682 testType: testType,
3683 name: "CertificateVerificationFail" + suffix,
3684 config: Config{
3685 MaxVersion: vers.version,
3686 Certificates: []Certificate{rsaCertificate},
3687 },
3688 flags: []string{
3689 flag,
3690 "-verify-fail",
3691 },
3692 shouldFail: true,
3693 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3694 })
3695 }
3696
3697 // By default, the client is in a soft fail mode where the peer
3698 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003699 tests = append(tests, testCase{
3700 testType: clientTest,
3701 name: "CertificateVerificationSoftFail-" + vers.name,
3702 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003703 MaxVersion: vers.version,
3704 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003705 },
3706 flags: []string{
3707 "-verify-fail",
3708 "-expect-verify-result",
3709 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003710 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003711 })
3712 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003713
David Benjamin1d4f4c02016-07-26 18:03:08 -04003714 tests = append(tests, testCase{
3715 name: "ShimSendAlert",
3716 flags: []string{"-send-alert"},
3717 shimWritesFirst: true,
3718 shouldFail: true,
3719 expectedLocalError: "remote error: decompression failure",
3720 })
3721
David Benjamin582ba042016-07-07 12:33:25 -07003722 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003723 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003724 name: "Renegotiate-Client",
3725 config: Config{
3726 MaxVersion: VersionTLS12,
3727 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003728 renegotiate: 1,
3729 flags: []string{
3730 "-renegotiate-freely",
3731 "-expect-total-renegotiations", "1",
3732 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003733 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003734
David Benjamin47921102016-07-28 11:29:18 -04003735 tests = append(tests, testCase{
3736 name: "SendHalfHelloRequest",
3737 config: Config{
3738 MaxVersion: VersionTLS12,
3739 Bugs: ProtocolBugs{
3740 PackHelloRequestWithFinished: config.packHandshakeFlight,
3741 },
3742 },
3743 sendHalfHelloRequest: true,
3744 flags: []string{"-renegotiate-ignore"},
3745 shouldFail: true,
3746 expectedError: ":UNEXPECTED_RECORD:",
3747 })
3748
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 // NPN on client and server; results in post-handshake message.
3750 tests = append(tests, testCase{
3751 name: "NPN-Client",
3752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003754 NextProtos: []string{"foo"},
3755 },
3756 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003757 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003758 expectedNextProto: "foo",
3759 expectedNextProtoType: npn,
3760 })
3761 tests = append(tests, testCase{
3762 testType: serverTest,
3763 name: "NPN-Server",
3764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003766 NextProtos: []string{"bar"},
3767 },
3768 flags: []string{
3769 "-advertise-npn", "\x03foo\x03bar\x03baz",
3770 "-expect-next-proto", "bar",
3771 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003772 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003773 expectedNextProto: "bar",
3774 expectedNextProtoType: npn,
3775 })
3776
3777 // TODO(davidben): Add tests for when False Start doesn't trigger.
3778
3779 // Client does False Start and negotiates NPN.
3780 tests = append(tests, testCase{
3781 name: "FalseStart",
3782 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003783 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3785 NextProtos: []string{"foo"},
3786 Bugs: ProtocolBugs{
3787 ExpectFalseStart: true,
3788 },
3789 },
3790 flags: []string{
3791 "-false-start",
3792 "-select-next-proto", "foo",
3793 },
3794 shimWritesFirst: true,
3795 resumeSession: true,
3796 })
3797
3798 // Client does False Start and negotiates ALPN.
3799 tests = append(tests, testCase{
3800 name: "FalseStart-ALPN",
3801 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003802 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3804 NextProtos: []string{"foo"},
3805 Bugs: ProtocolBugs{
3806 ExpectFalseStart: true,
3807 },
3808 },
3809 flags: []string{
3810 "-false-start",
3811 "-advertise-alpn", "\x03foo",
3812 },
3813 shimWritesFirst: true,
3814 resumeSession: true,
3815 })
3816
3817 // Client does False Start but doesn't explicitly call
3818 // SSL_connect.
3819 tests = append(tests, testCase{
3820 name: "FalseStart-Implicit",
3821 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003822 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003823 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3824 NextProtos: []string{"foo"},
3825 },
3826 flags: []string{
3827 "-implicit-handshake",
3828 "-false-start",
3829 "-advertise-alpn", "\x03foo",
3830 },
3831 })
3832
3833 // False Start without session tickets.
3834 tests = append(tests, testCase{
3835 name: "FalseStart-SessionTicketsDisabled",
3836 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003837 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3839 NextProtos: []string{"foo"},
3840 SessionTicketsDisabled: true,
3841 Bugs: ProtocolBugs{
3842 ExpectFalseStart: true,
3843 },
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-select-next-proto", "foo",
3848 },
3849 shimWritesFirst: true,
3850 })
3851
Adam Langleydf759b52016-07-11 15:24:37 -07003852 tests = append(tests, testCase{
3853 name: "FalseStart-CECPQ1",
3854 config: Config{
3855 MaxVersion: VersionTLS12,
3856 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3857 NextProtos: []string{"foo"},
3858 Bugs: ProtocolBugs{
3859 ExpectFalseStart: true,
3860 },
3861 },
3862 flags: []string{
3863 "-false-start",
3864 "-cipher", "DEFAULT:kCECPQ1",
3865 "-select-next-proto", "foo",
3866 },
3867 shimWritesFirst: true,
3868 resumeSession: true,
3869 })
3870
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 // Server parses a V2ClientHello.
3872 tests = append(tests, testCase{
3873 testType: serverTest,
3874 name: "SendV2ClientHello",
3875 config: Config{
3876 // Choose a cipher suite that does not involve
3877 // elliptic curves, so no extensions are
3878 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003879 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003880 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 Bugs: ProtocolBugs{
3882 SendV2ClientHello: true,
3883 },
3884 },
3885 })
3886
3887 // Client sends a Channel ID.
3888 tests = append(tests, testCase{
3889 name: "ChannelID-Client",
3890 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003891 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003892 RequestChannelID: true,
3893 },
Adam Langley7c803a62015-06-15 15:35:05 -07003894 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003895 resumeSession: true,
3896 expectChannelID: true,
3897 })
3898
3899 // Server accepts a Channel ID.
3900 tests = append(tests, testCase{
3901 testType: serverTest,
3902 name: "ChannelID-Server",
3903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003904 MaxVersion: VersionTLS12,
3905 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003906 },
3907 flags: []string{
3908 "-expect-channel-id",
3909 base64.StdEncoding.EncodeToString(channelIDBytes),
3910 },
3911 resumeSession: true,
3912 expectChannelID: true,
3913 })
David Benjamin30789da2015-08-29 22:56:45 -04003914
David Benjaminf8fcdf32016-06-08 15:56:13 -04003915 // Channel ID and NPN at the same time, to ensure their relative
3916 // ordering is correct.
3917 tests = append(tests, testCase{
3918 name: "ChannelID-NPN-Client",
3919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003920 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003921 RequestChannelID: true,
3922 NextProtos: []string{"foo"},
3923 },
3924 flags: []string{
3925 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3926 "-select-next-proto", "foo",
3927 },
3928 resumeSession: true,
3929 expectChannelID: true,
3930 expectedNextProto: "foo",
3931 expectedNextProtoType: npn,
3932 })
3933 tests = append(tests, testCase{
3934 testType: serverTest,
3935 name: "ChannelID-NPN-Server",
3936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003937 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003938 ChannelID: channelIDKey,
3939 NextProtos: []string{"bar"},
3940 },
3941 flags: []string{
3942 "-expect-channel-id",
3943 base64.StdEncoding.EncodeToString(channelIDBytes),
3944 "-advertise-npn", "\x03foo\x03bar\x03baz",
3945 "-expect-next-proto", "bar",
3946 },
3947 resumeSession: true,
3948 expectChannelID: true,
3949 expectedNextProto: "bar",
3950 expectedNextProtoType: npn,
3951 })
3952
David Benjamin30789da2015-08-29 22:56:45 -04003953 // Bidirectional shutdown with the runner initiating.
3954 tests = append(tests, testCase{
3955 name: "Shutdown-Runner",
3956 config: Config{
3957 Bugs: ProtocolBugs{
3958 ExpectCloseNotify: true,
3959 },
3960 },
3961 flags: []string{"-check-close-notify"},
3962 })
3963
3964 // Bidirectional shutdown with the shim initiating. The runner,
3965 // in the meantime, sends garbage before the close_notify which
3966 // the shim must ignore.
3967 tests = append(tests, testCase{
3968 name: "Shutdown-Shim",
3969 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003970 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003971 Bugs: ProtocolBugs{
3972 ExpectCloseNotify: true,
3973 },
3974 },
3975 shimShutsDown: true,
3976 sendEmptyRecords: 1,
3977 sendWarningAlerts: 1,
3978 flags: []string{"-check-close-notify"},
3979 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003980 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003981 // TODO(davidben): DTLS 1.3 will want a similar thing for
3982 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003983 tests = append(tests, testCase{
3984 name: "SkipHelloVerifyRequest",
3985 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003986 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003987 Bugs: ProtocolBugs{
3988 SkipHelloVerifyRequest: true,
3989 },
3990 },
3991 })
3992 }
3993
David Benjamin760b1dd2015-05-15 23:33:48 -04003994 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003995 test.protocol = config.protocol
3996 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003997 test.name += "-DTLS"
3998 }
David Benjamin582ba042016-07-07 12:33:25 -07003999 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004000 test.name += "-Async"
4001 test.flags = append(test.flags, "-async")
4002 } else {
4003 test.name += "-Sync"
4004 }
David Benjamin582ba042016-07-07 12:33:25 -07004005 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004006 test.name += "-SplitHandshakeRecords"
4007 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004008 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004009 test.config.Bugs.MaxPacketLength = 256
4010 test.flags = append(test.flags, "-mtu", "256")
4011 }
4012 }
David Benjamin582ba042016-07-07 12:33:25 -07004013 if config.packHandshakeFlight {
4014 test.name += "-PackHandshakeFlight"
4015 test.config.Bugs.PackHandshakeFlight = true
4016 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004018 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004019}
4020
Adam Langley524e7172015-02-20 16:04:00 -08004021func addDDoSCallbackTests() {
4022 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004023 for _, resume := range []bool{false, true} {
4024 suffix := "Resume"
4025 if resume {
4026 suffix = "No" + suffix
4027 }
4028
4029 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004030 testType: serverTest,
4031 name: "Server-DDoS-OK-" + suffix,
4032 config: Config{
4033 MaxVersion: VersionTLS12,
4034 },
Adam Langley524e7172015-02-20 16:04:00 -08004035 flags: []string{"-install-ddos-callback"},
4036 resumeSession: resume,
4037 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004038 testCases = append(testCases, testCase{
4039 testType: serverTest,
4040 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4041 config: Config{
4042 MaxVersion: VersionTLS13,
4043 },
4044 flags: []string{"-install-ddos-callback"},
4045 resumeSession: resume,
4046 })
Adam Langley524e7172015-02-20 16:04:00 -08004047
4048 failFlag := "-fail-ddos-callback"
4049 if resume {
4050 failFlag = "-fail-second-ddos-callback"
4051 }
4052 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004053 testType: serverTest,
4054 name: "Server-DDoS-Reject-" + suffix,
4055 config: Config{
4056 MaxVersion: VersionTLS12,
4057 },
David Benjamin2c66e072016-09-16 15:58:00 -04004058 flags: []string{"-install-ddos-callback", failFlag},
4059 resumeSession: resume,
4060 shouldFail: true,
4061 expectedError: ":CONNECTION_REJECTED:",
4062 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004063 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004064 testCases = append(testCases, testCase{
4065 testType: serverTest,
4066 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4067 config: Config{
4068 MaxVersion: VersionTLS13,
4069 },
David Benjamin2c66e072016-09-16 15:58:00 -04004070 flags: []string{"-install-ddos-callback", failFlag},
4071 resumeSession: resume,
4072 shouldFail: true,
4073 expectedError: ":CONNECTION_REJECTED:",
4074 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004075 })
Adam Langley524e7172015-02-20 16:04:00 -08004076 }
4077}
4078
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004079func addVersionNegotiationTests() {
4080 for i, shimVers := range tlsVersions {
4081 // Assemble flags to disable all newer versions on the shim.
4082 var flags []string
4083 for _, vers := range tlsVersions[i+1:] {
4084 flags = append(flags, vers.flag)
4085 }
4086
Steven Valdezfdd10992016-09-15 16:27:05 -04004087 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004088 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004089 protocols := []protocol{tls}
4090 if runnerVers.hasDTLS && shimVers.hasDTLS {
4091 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004092 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004093 for _, protocol := range protocols {
4094 expectedVersion := shimVers.version
4095 if runnerVers.version < shimVers.version {
4096 expectedVersion = runnerVers.version
4097 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004098
David Benjamin8b8c0062014-11-23 02:47:52 -05004099 suffix := shimVers.name + "-" + runnerVers.name
4100 if protocol == dtls {
4101 suffix += "-DTLS"
4102 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004103
David Benjamin1eb367c2014-12-12 18:17:51 -05004104 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4105
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004106 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004107 clientVers := shimVers.version
4108 if clientVers > VersionTLS10 {
4109 clientVers = VersionTLS10
4110 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004111 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004112 serverVers := expectedVersion
4113 if expectedVersion >= VersionTLS13 {
4114 serverVers = VersionTLS10
4115 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004116 serverVers = versionToWire(serverVers, protocol == dtls)
4117
David Benjamin8b8c0062014-11-23 02:47:52 -05004118 testCases = append(testCases, testCase{
4119 protocol: protocol,
4120 testType: clientTest,
4121 name: "VersionNegotiation-Client-" + suffix,
4122 config: Config{
4123 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004124 Bugs: ProtocolBugs{
4125 ExpectInitialRecordVersion: clientVers,
4126 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004127 },
4128 flags: flags,
4129 expectedVersion: expectedVersion,
4130 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004131 testCases = append(testCases, testCase{
4132 protocol: protocol,
4133 testType: clientTest,
4134 name: "VersionNegotiation-Client2-" + suffix,
4135 config: Config{
4136 MaxVersion: runnerVers.version,
4137 Bugs: ProtocolBugs{
4138 ExpectInitialRecordVersion: clientVers,
4139 },
4140 },
4141 flags: []string{"-max-version", shimVersFlag},
4142 expectedVersion: expectedVersion,
4143 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004144
4145 testCases = append(testCases, testCase{
4146 protocol: protocol,
4147 testType: serverTest,
4148 name: "VersionNegotiation-Server-" + suffix,
4149 config: Config{
4150 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004151 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004152 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004153 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004154 },
4155 flags: flags,
4156 expectedVersion: expectedVersion,
4157 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004158 testCases = append(testCases, testCase{
4159 protocol: protocol,
4160 testType: serverTest,
4161 name: "VersionNegotiation-Server2-" + suffix,
4162 config: Config{
4163 MaxVersion: runnerVers.version,
4164 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004165 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004166 },
4167 },
4168 flags: []string{"-max-version", shimVersFlag},
4169 expectedVersion: expectedVersion,
4170 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004171 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004172 }
4173 }
David Benjamin95c69562016-06-29 18:15:03 -04004174
Steven Valdezfdd10992016-09-15 16:27:05 -04004175 // Test the version extension at all versions.
4176 for _, vers := range tlsVersions {
4177 protocols := []protocol{tls}
4178 if vers.hasDTLS {
4179 protocols = append(protocols, dtls)
4180 }
4181 for _, protocol := range protocols {
4182 suffix := vers.name
4183 if protocol == dtls {
4184 suffix += "-DTLS"
4185 }
4186
4187 wireVersion := versionToWire(vers.version, protocol == dtls)
4188 testCases = append(testCases, testCase{
4189 protocol: protocol,
4190 testType: serverTest,
4191 name: "VersionNegotiationExtension-" + suffix,
4192 config: Config{
4193 Bugs: ProtocolBugs{
4194 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4195 },
4196 },
4197 expectedVersion: vers.version,
4198 })
4199 }
4200
4201 }
4202
4203 // If all versions are unknown, negotiation fails.
4204 testCases = append(testCases, testCase{
4205 testType: serverTest,
4206 name: "NoSupportedVersions",
4207 config: Config{
4208 Bugs: ProtocolBugs{
4209 SendSupportedVersions: []uint16{0x1111},
4210 },
4211 },
4212 shouldFail: true,
4213 expectedError: ":UNSUPPORTED_PROTOCOL:",
4214 })
4215 testCases = append(testCases, testCase{
4216 protocol: dtls,
4217 testType: serverTest,
4218 name: "NoSupportedVersions-DTLS",
4219 config: Config{
4220 Bugs: ProtocolBugs{
4221 SendSupportedVersions: []uint16{0x1111},
4222 },
4223 },
4224 shouldFail: true,
4225 expectedError: ":UNSUPPORTED_PROTOCOL:",
4226 })
4227
4228 testCases = append(testCases, testCase{
4229 testType: serverTest,
4230 name: "ClientHelloVersionTooHigh",
4231 config: Config{
4232 MaxVersion: VersionTLS13,
4233 Bugs: ProtocolBugs{
4234 SendClientVersion: 0x0304,
4235 OmitSupportedVersions: true,
4236 },
4237 },
4238 expectedVersion: VersionTLS12,
4239 })
4240
4241 testCases = append(testCases, testCase{
4242 testType: serverTest,
4243 name: "ConflictingVersionNegotiation",
4244 config: Config{
4245 MaxVersion: VersionTLS13,
4246 Bugs: ProtocolBugs{
4247 SendClientVersion: 0x0304,
4248 SendSupportedVersions: []uint16{0x0303},
4249 },
4250 },
4251 expectedVersion: VersionTLS12,
4252 })
4253
David Benjamin95c69562016-06-29 18:15:03 -04004254 // Test for version tolerance.
4255 testCases = append(testCases, testCase{
4256 testType: serverTest,
4257 name: "MinorVersionTolerance",
4258 config: Config{
4259 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004260 SendClientVersion: 0x03ff,
4261 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004262 },
4263 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004264 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004265 })
4266 testCases = append(testCases, testCase{
4267 testType: serverTest,
4268 name: "MajorVersionTolerance",
4269 config: Config{
4270 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004271 SendClientVersion: 0x0400,
4272 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004273 },
4274 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004275 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004276 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004277
David Benjamin95c69562016-06-29 18:15:03 -04004278 testCases = append(testCases, testCase{
4279 protocol: dtls,
4280 testType: serverTest,
4281 name: "MinorVersionTolerance-DTLS",
4282 config: Config{
4283 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004284 SendClientVersion: 0xfe00,
4285 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004286 },
4287 },
4288 expectedVersion: VersionTLS12,
4289 })
4290 testCases = append(testCases, testCase{
4291 protocol: dtls,
4292 testType: serverTest,
4293 name: "MajorVersionTolerance-DTLS",
4294 config: Config{
4295 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004296 SendClientVersion: 0xfdff,
4297 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004298 },
4299 },
4300 expectedVersion: VersionTLS12,
4301 })
4302
4303 // Test that versions below 3.0 are rejected.
4304 testCases = append(testCases, testCase{
4305 testType: serverTest,
4306 name: "VersionTooLow",
4307 config: Config{
4308 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004309 SendClientVersion: 0x0200,
4310 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004311 },
4312 },
4313 shouldFail: true,
4314 expectedError: ":UNSUPPORTED_PROTOCOL:",
4315 })
4316 testCases = append(testCases, testCase{
4317 protocol: dtls,
4318 testType: serverTest,
4319 name: "VersionTooLow-DTLS",
4320 config: Config{
4321 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004322 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004323 },
4324 },
4325 shouldFail: true,
4326 expectedError: ":UNSUPPORTED_PROTOCOL:",
4327 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004328
David Benjamin2dc02042016-09-19 19:57:37 -04004329 testCases = append(testCases, testCase{
4330 name: "ServerBogusVersion",
4331 config: Config{
4332 Bugs: ProtocolBugs{
4333 SendServerHelloVersion: 0x1234,
4334 },
4335 },
4336 shouldFail: true,
4337 expectedError: ":UNSUPPORTED_PROTOCOL:",
4338 })
4339
David Benjamin1f61f0d2016-07-10 12:20:35 -04004340 // Test TLS 1.3's downgrade signal.
4341 testCases = append(testCases, testCase{
4342 name: "Downgrade-TLS12-Client",
4343 config: Config{
4344 Bugs: ProtocolBugs{
4345 NegotiateVersion: VersionTLS12,
4346 },
4347 },
David Benjamin55108632016-08-11 22:01:18 -04004348 // TODO(davidben): This test should fail once TLS 1.3 is final
4349 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004350 })
4351 testCases = append(testCases, testCase{
4352 testType: serverTest,
4353 name: "Downgrade-TLS12-Server",
4354 config: Config{
4355 Bugs: ProtocolBugs{
4356 SendClientVersion: VersionTLS12,
4357 },
4358 },
David Benjamin55108632016-08-11 22:01:18 -04004359 // TODO(davidben): This test should fail once TLS 1.3 is final
4360 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004361 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004362}
4363
David Benjaminaccb4542014-12-12 23:44:33 -05004364func addMinimumVersionTests() {
4365 for i, shimVers := range tlsVersions {
4366 // Assemble flags to disable all older versions on the shim.
4367 var flags []string
4368 for _, vers := range tlsVersions[:i] {
4369 flags = append(flags, vers.flag)
4370 }
4371
4372 for _, runnerVers := range tlsVersions {
4373 protocols := []protocol{tls}
4374 if runnerVers.hasDTLS && shimVers.hasDTLS {
4375 protocols = append(protocols, dtls)
4376 }
4377 for _, protocol := range protocols {
4378 suffix := shimVers.name + "-" + runnerVers.name
4379 if protocol == dtls {
4380 suffix += "-DTLS"
4381 }
4382 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4383
David Benjaminaccb4542014-12-12 23:44:33 -05004384 var expectedVersion uint16
4385 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004386 var expectedClientError, expectedServerError string
4387 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004388 if runnerVers.version >= shimVers.version {
4389 expectedVersion = runnerVers.version
4390 } else {
4391 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004392 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4393 expectedServerLocalError = "remote error: protocol version not supported"
4394 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4395 // If the client's minimum version is TLS 1.3 and the runner's
4396 // maximum is below TLS 1.2, the runner will fail to select a
4397 // cipher before the shim rejects the selected version.
4398 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4399 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4400 } else {
4401 expectedClientError = expectedServerError
4402 expectedClientLocalError = expectedServerLocalError
4403 }
David Benjaminaccb4542014-12-12 23:44:33 -05004404 }
4405
Steven Valdezfdd10992016-09-15 16:27:05 -04004406 // Test the client enforces minimum
4407 // versions. Use the NegotiateVersion bug to
4408 // ensure the server does not decline to select
4409 // a version first. This may occur if the
4410 // versions extension is used.
David Benjaminaccb4542014-12-12 23:44:33 -05004411 testCases = append(testCases, testCase{
4412 protocol: protocol,
4413 testType: clientTest,
4414 name: "MinimumVersion-Client-" + suffix,
4415 config: Config{
4416 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004417 Bugs: ProtocolBugs{
4418 NegotiateVersion: runnerVers.version,
4419 },
David Benjaminaccb4542014-12-12 23:44:33 -05004420 },
David Benjamin87909c02014-12-13 01:55:01 -05004421 flags: flags,
4422 expectedVersion: expectedVersion,
4423 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004424 expectedError: expectedClientError,
4425 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004426 })
4427 testCases = append(testCases, testCase{
4428 protocol: protocol,
4429 testType: clientTest,
4430 name: "MinimumVersion-Client2-" + suffix,
4431 config: Config{
4432 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004433 Bugs: ProtocolBugs{
4434 NegotiateVersion: runnerVers.version,
4435 },
David Benjaminaccb4542014-12-12 23:44:33 -05004436 },
David Benjamin87909c02014-12-13 01:55:01 -05004437 flags: []string{"-min-version", shimVersFlag},
4438 expectedVersion: expectedVersion,
4439 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004440 expectedError: expectedClientError,
4441 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004442 })
4443
4444 testCases = append(testCases, testCase{
4445 protocol: protocol,
4446 testType: serverTest,
4447 name: "MinimumVersion-Server-" + suffix,
4448 config: Config{
4449 MaxVersion: runnerVers.version,
4450 },
David Benjamin87909c02014-12-13 01:55:01 -05004451 flags: flags,
4452 expectedVersion: expectedVersion,
4453 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004454 expectedError: expectedServerError,
4455 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004456 })
4457 testCases = append(testCases, testCase{
4458 protocol: protocol,
4459 testType: serverTest,
4460 name: "MinimumVersion-Server2-" + suffix,
4461 config: Config{
4462 MaxVersion: runnerVers.version,
4463 },
David Benjamin87909c02014-12-13 01:55:01 -05004464 flags: []string{"-min-version", shimVersFlag},
4465 expectedVersion: expectedVersion,
4466 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004467 expectedError: expectedServerError,
4468 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004469 })
4470 }
4471 }
4472 }
4473}
4474
David Benjamine78bfde2014-09-06 12:45:15 -04004475func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004476 // TODO(davidben): Extensions, where applicable, all move their server
4477 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4478 // tests for both. Also test interaction with 0-RTT when implemented.
4479
David Benjamin97d17d92016-07-14 16:12:00 -04004480 // Repeat extensions tests all versions except SSL 3.0.
4481 for _, ver := range tlsVersions {
4482 if ver.version == VersionSSL30 {
4483 continue
4484 }
4485
David Benjamin97d17d92016-07-14 16:12:00 -04004486 // Test that duplicate extensions are rejected.
4487 testCases = append(testCases, testCase{
4488 testType: clientTest,
4489 name: "DuplicateExtensionClient-" + ver.name,
4490 config: Config{
4491 MaxVersion: ver.version,
4492 Bugs: ProtocolBugs{
4493 DuplicateExtension: true,
4494 },
David Benjamine78bfde2014-09-06 12:45:15 -04004495 },
David Benjamin97d17d92016-07-14 16:12:00 -04004496 shouldFail: true,
4497 expectedLocalError: "remote error: error decoding message",
4498 })
4499 testCases = append(testCases, testCase{
4500 testType: serverTest,
4501 name: "DuplicateExtensionServer-" + ver.name,
4502 config: Config{
4503 MaxVersion: ver.version,
4504 Bugs: ProtocolBugs{
4505 DuplicateExtension: true,
4506 },
David Benjamine78bfde2014-09-06 12:45:15 -04004507 },
David Benjamin97d17d92016-07-14 16:12:00 -04004508 shouldFail: true,
4509 expectedLocalError: "remote error: error decoding message",
4510 })
4511
4512 // Test SNI.
4513 testCases = append(testCases, testCase{
4514 testType: clientTest,
4515 name: "ServerNameExtensionClient-" + ver.name,
4516 config: Config{
4517 MaxVersion: ver.version,
4518 Bugs: ProtocolBugs{
4519 ExpectServerName: "example.com",
4520 },
David Benjamine78bfde2014-09-06 12:45:15 -04004521 },
David Benjamin97d17d92016-07-14 16:12:00 -04004522 flags: []string{"-host-name", "example.com"},
4523 })
4524 testCases = append(testCases, testCase{
4525 testType: clientTest,
4526 name: "ServerNameExtensionClientMismatch-" + ver.name,
4527 config: Config{
4528 MaxVersion: ver.version,
4529 Bugs: ProtocolBugs{
4530 ExpectServerName: "mismatch.com",
4531 },
David Benjamine78bfde2014-09-06 12:45:15 -04004532 },
David Benjamin97d17d92016-07-14 16:12:00 -04004533 flags: []string{"-host-name", "example.com"},
4534 shouldFail: true,
4535 expectedLocalError: "tls: unexpected server name",
4536 })
4537 testCases = append(testCases, testCase{
4538 testType: clientTest,
4539 name: "ServerNameExtensionClientMissing-" + ver.name,
4540 config: Config{
4541 MaxVersion: ver.version,
4542 Bugs: ProtocolBugs{
4543 ExpectServerName: "missing.com",
4544 },
David Benjamine78bfde2014-09-06 12:45:15 -04004545 },
David Benjamin97d17d92016-07-14 16:12:00 -04004546 shouldFail: true,
4547 expectedLocalError: "tls: unexpected server name",
4548 })
4549 testCases = append(testCases, testCase{
4550 testType: serverTest,
4551 name: "ServerNameExtensionServer-" + ver.name,
4552 config: Config{
4553 MaxVersion: ver.version,
4554 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004555 },
David Benjamin97d17d92016-07-14 16:12:00 -04004556 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004557 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004558 })
4559
4560 // Test ALPN.
4561 testCases = append(testCases, testCase{
4562 testType: clientTest,
4563 name: "ALPNClient-" + ver.name,
4564 config: Config{
4565 MaxVersion: ver.version,
4566 NextProtos: []string{"foo"},
4567 },
4568 flags: []string{
4569 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4570 "-expect-alpn", "foo",
4571 },
4572 expectedNextProto: "foo",
4573 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004574 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004575 })
4576 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004577 testType: clientTest,
4578 name: "ALPNClient-Mismatch-" + ver.name,
4579 config: Config{
4580 MaxVersion: ver.version,
4581 Bugs: ProtocolBugs{
4582 SendALPN: "baz",
4583 },
4584 },
4585 flags: []string{
4586 "-advertise-alpn", "\x03foo\x03bar",
4587 },
4588 shouldFail: true,
4589 expectedError: ":INVALID_ALPN_PROTOCOL:",
4590 expectedLocalError: "remote error: illegal parameter",
4591 })
4592 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004593 testType: serverTest,
4594 name: "ALPNServer-" + ver.name,
4595 config: Config{
4596 MaxVersion: ver.version,
4597 NextProtos: []string{"foo", "bar", "baz"},
4598 },
4599 flags: []string{
4600 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4601 "-select-alpn", "foo",
4602 },
4603 expectedNextProto: "foo",
4604 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004605 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004606 })
4607 testCases = append(testCases, testCase{
4608 testType: serverTest,
4609 name: "ALPNServer-Decline-" + ver.name,
4610 config: Config{
4611 MaxVersion: ver.version,
4612 NextProtos: []string{"foo", "bar", "baz"},
4613 },
4614 flags: []string{"-decline-alpn"},
4615 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004616 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004617 })
4618
David Benjamin25fe85b2016-08-09 20:00:32 -04004619 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4620 // called once.
4621 testCases = append(testCases, testCase{
4622 testType: serverTest,
4623 name: "ALPNServer-Async-" + ver.name,
4624 config: Config{
4625 MaxVersion: ver.version,
4626 NextProtos: []string{"foo", "bar", "baz"},
4627 },
4628 flags: []string{
4629 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4630 "-select-alpn", "foo",
4631 "-async",
4632 },
4633 expectedNextProto: "foo",
4634 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004635 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004636 })
4637
David Benjamin97d17d92016-07-14 16:12:00 -04004638 var emptyString string
4639 testCases = append(testCases, testCase{
4640 testType: clientTest,
4641 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4642 config: Config{
4643 MaxVersion: ver.version,
4644 NextProtos: []string{""},
4645 Bugs: ProtocolBugs{
4646 // A server returning an empty ALPN protocol
4647 // should be rejected.
4648 ALPNProtocol: &emptyString,
4649 },
4650 },
4651 flags: []string{
4652 "-advertise-alpn", "\x03foo",
4653 },
4654 shouldFail: true,
4655 expectedError: ":PARSE_TLSEXT:",
4656 })
4657 testCases = append(testCases, testCase{
4658 testType: serverTest,
4659 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4660 config: Config{
4661 MaxVersion: ver.version,
4662 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004663 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004664 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004665 },
David Benjamin97d17d92016-07-14 16:12:00 -04004666 flags: []string{
4667 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004668 },
David Benjamin97d17d92016-07-14 16:12:00 -04004669 shouldFail: true,
4670 expectedError: ":PARSE_TLSEXT:",
4671 })
4672
4673 // Test NPN and the interaction with ALPN.
4674 if ver.version < VersionTLS13 {
4675 // Test that the server prefers ALPN over NPN.
4676 testCases = append(testCases, testCase{
4677 testType: serverTest,
4678 name: "ALPNServer-Preferred-" + ver.name,
4679 config: Config{
4680 MaxVersion: ver.version,
4681 NextProtos: []string{"foo", "bar", "baz"},
4682 },
4683 flags: []string{
4684 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4685 "-select-alpn", "foo",
4686 "-advertise-npn", "\x03foo\x03bar\x03baz",
4687 },
4688 expectedNextProto: "foo",
4689 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004690 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004691 })
4692 testCases = append(testCases, testCase{
4693 testType: serverTest,
4694 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4695 config: Config{
4696 MaxVersion: ver.version,
4697 NextProtos: []string{"foo", "bar", "baz"},
4698 Bugs: ProtocolBugs{
4699 SwapNPNAndALPN: true,
4700 },
4701 },
4702 flags: []string{
4703 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4704 "-select-alpn", "foo",
4705 "-advertise-npn", "\x03foo\x03bar\x03baz",
4706 },
4707 expectedNextProto: "foo",
4708 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004709 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004710 })
4711
4712 // Test that negotiating both NPN and ALPN is forbidden.
4713 testCases = append(testCases, testCase{
4714 name: "NegotiateALPNAndNPN-" + ver.name,
4715 config: Config{
4716 MaxVersion: ver.version,
4717 NextProtos: []string{"foo", "bar", "baz"},
4718 Bugs: ProtocolBugs{
4719 NegotiateALPNAndNPN: true,
4720 },
4721 },
4722 flags: []string{
4723 "-advertise-alpn", "\x03foo",
4724 "-select-next-proto", "foo",
4725 },
4726 shouldFail: true,
4727 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4728 })
4729 testCases = append(testCases, testCase{
4730 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4731 config: Config{
4732 MaxVersion: ver.version,
4733 NextProtos: []string{"foo", "bar", "baz"},
4734 Bugs: ProtocolBugs{
4735 NegotiateALPNAndNPN: true,
4736 SwapNPNAndALPN: true,
4737 },
4738 },
4739 flags: []string{
4740 "-advertise-alpn", "\x03foo",
4741 "-select-next-proto", "foo",
4742 },
4743 shouldFail: true,
4744 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4745 })
4746
4747 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4748 testCases = append(testCases, testCase{
4749 name: "DisableNPN-" + ver.name,
4750 config: Config{
4751 MaxVersion: ver.version,
4752 NextProtos: []string{"foo"},
4753 },
4754 flags: []string{
4755 "-select-next-proto", "foo",
4756 "-disable-npn",
4757 },
4758 expectNoNextProto: true,
4759 })
4760 }
4761
4762 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004763
4764 // Resume with a corrupt ticket.
4765 testCases = append(testCases, testCase{
4766 testType: serverTest,
4767 name: "CorruptTicket-" + ver.name,
4768 config: Config{
4769 MaxVersion: ver.version,
4770 Bugs: ProtocolBugs{
4771 CorruptTicket: true,
4772 },
4773 },
4774 resumeSession: true,
4775 expectResumeRejected: true,
4776 })
4777 // Test the ticket callback, with and without renewal.
4778 testCases = append(testCases, testCase{
4779 testType: serverTest,
4780 name: "TicketCallback-" + ver.name,
4781 config: Config{
4782 MaxVersion: ver.version,
4783 },
4784 resumeSession: true,
4785 flags: []string{"-use-ticket-callback"},
4786 })
4787 testCases = append(testCases, testCase{
4788 testType: serverTest,
4789 name: "TicketCallback-Renew-" + ver.name,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 Bugs: ProtocolBugs{
4793 ExpectNewTicket: true,
4794 },
4795 },
4796 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4797 resumeSession: true,
4798 })
4799
4800 // Test that the ticket callback is only called once when everything before
4801 // it in the ClientHello is asynchronous. This corrupts the ticket so
4802 // certificate selection callbacks run.
4803 testCases = append(testCases, testCase{
4804 testType: serverTest,
4805 name: "TicketCallback-SingleCall-" + ver.name,
4806 config: Config{
4807 MaxVersion: ver.version,
4808 Bugs: ProtocolBugs{
4809 CorruptTicket: true,
4810 },
4811 },
4812 resumeSession: true,
4813 expectResumeRejected: true,
4814 flags: []string{
4815 "-use-ticket-callback",
4816 "-async",
4817 },
4818 })
4819
4820 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004821 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004822 testCases = append(testCases, testCase{
4823 testType: serverTest,
4824 name: "OversizedSessionId-" + ver.name,
4825 config: Config{
4826 MaxVersion: ver.version,
4827 Bugs: ProtocolBugs{
4828 OversizedSessionId: true,
4829 },
4830 },
4831 resumeSession: true,
4832 shouldFail: true,
4833 expectedError: ":DECODE_ERROR:",
4834 })
4835 }
4836
4837 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4838 // are ignored.
4839 if ver.hasDTLS {
4840 testCases = append(testCases, testCase{
4841 protocol: dtls,
4842 name: "SRTP-Client-" + ver.name,
4843 config: Config{
4844 MaxVersion: ver.version,
4845 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4846 },
4847 flags: []string{
4848 "-srtp-profiles",
4849 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4850 },
4851 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4852 })
4853 testCases = append(testCases, testCase{
4854 protocol: dtls,
4855 testType: serverTest,
4856 name: "SRTP-Server-" + ver.name,
4857 config: Config{
4858 MaxVersion: ver.version,
4859 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4860 },
4861 flags: []string{
4862 "-srtp-profiles",
4863 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4864 },
4865 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4866 })
4867 // Test that the MKI is ignored.
4868 testCases = append(testCases, testCase{
4869 protocol: dtls,
4870 testType: serverTest,
4871 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4872 config: Config{
4873 MaxVersion: ver.version,
4874 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4875 Bugs: ProtocolBugs{
4876 SRTPMasterKeyIdentifer: "bogus",
4877 },
4878 },
4879 flags: []string{
4880 "-srtp-profiles",
4881 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4882 },
4883 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4884 })
4885 // Test that SRTP isn't negotiated on the server if there were
4886 // no matching profiles.
4887 testCases = append(testCases, testCase{
4888 protocol: dtls,
4889 testType: serverTest,
4890 name: "SRTP-Server-NoMatch-" + ver.name,
4891 config: Config{
4892 MaxVersion: ver.version,
4893 SRTPProtectionProfiles: []uint16{100, 101, 102},
4894 },
4895 flags: []string{
4896 "-srtp-profiles",
4897 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4898 },
4899 expectedSRTPProtectionProfile: 0,
4900 })
4901 // Test that the server returning an invalid SRTP profile is
4902 // flagged as an error by the client.
4903 testCases = append(testCases, testCase{
4904 protocol: dtls,
4905 name: "SRTP-Client-NoMatch-" + ver.name,
4906 config: Config{
4907 MaxVersion: ver.version,
4908 Bugs: ProtocolBugs{
4909 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4910 },
4911 },
4912 flags: []string{
4913 "-srtp-profiles",
4914 "SRTP_AES128_CM_SHA1_80",
4915 },
4916 shouldFail: true,
4917 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4918 })
4919 }
4920
4921 // Test SCT list.
4922 testCases = append(testCases, testCase{
4923 name: "SignedCertificateTimestampList-Client-" + ver.name,
4924 testType: clientTest,
4925 config: Config{
4926 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004927 },
David Benjamin97d17d92016-07-14 16:12:00 -04004928 flags: []string{
4929 "-enable-signed-cert-timestamps",
4930 "-expect-signed-cert-timestamps",
4931 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004932 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004933 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004934 })
4935 testCases = append(testCases, testCase{
4936 name: "SendSCTListOnResume-" + ver.name,
4937 config: Config{
4938 MaxVersion: ver.version,
4939 Bugs: ProtocolBugs{
4940 SendSCTListOnResume: []byte("bogus"),
4941 },
David Benjamind98452d2015-06-16 14:16:23 -04004942 },
David Benjamin97d17d92016-07-14 16:12:00 -04004943 flags: []string{
4944 "-enable-signed-cert-timestamps",
4945 "-expect-signed-cert-timestamps",
4946 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004947 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004948 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004949 })
4950 testCases = append(testCases, testCase{
4951 name: "SignedCertificateTimestampList-Server-" + ver.name,
4952 testType: serverTest,
4953 config: Config{
4954 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004955 },
David Benjamin97d17d92016-07-14 16:12:00 -04004956 flags: []string{
4957 "-signed-cert-timestamps",
4958 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004959 },
David Benjamin97d17d92016-07-14 16:12:00 -04004960 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004961 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004962 })
4963 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004964
Paul Lietar4fac72e2015-09-09 13:44:55 +01004965 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004966 testType: clientTest,
4967 name: "ClientHelloPadding",
4968 config: Config{
4969 Bugs: ProtocolBugs{
4970 RequireClientHelloSize: 512,
4971 },
4972 },
4973 // This hostname just needs to be long enough to push the
4974 // ClientHello into F5's danger zone between 256 and 511 bytes
4975 // long.
4976 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4977 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004978
4979 // Extensions should not function in SSL 3.0.
4980 testCases = append(testCases, testCase{
4981 testType: serverTest,
4982 name: "SSLv3Extensions-NoALPN",
4983 config: Config{
4984 MaxVersion: VersionSSL30,
4985 NextProtos: []string{"foo", "bar", "baz"},
4986 },
4987 flags: []string{
4988 "-select-alpn", "foo",
4989 },
4990 expectNoNextProto: true,
4991 })
4992
4993 // Test session tickets separately as they follow a different codepath.
4994 testCases = append(testCases, testCase{
4995 testType: serverTest,
4996 name: "SSLv3Extensions-NoTickets",
4997 config: Config{
4998 MaxVersion: VersionSSL30,
4999 Bugs: ProtocolBugs{
5000 // Historically, session tickets in SSL 3.0
5001 // failed in different ways depending on whether
5002 // the client supported renegotiation_info.
5003 NoRenegotiationInfo: true,
5004 },
5005 },
5006 resumeSession: true,
5007 })
5008 testCases = append(testCases, testCase{
5009 testType: serverTest,
5010 name: "SSLv3Extensions-NoTickets2",
5011 config: Config{
5012 MaxVersion: VersionSSL30,
5013 },
5014 resumeSession: true,
5015 })
5016
5017 // But SSL 3.0 does send and process renegotiation_info.
5018 testCases = append(testCases, testCase{
5019 testType: serverTest,
5020 name: "SSLv3Extensions-RenegotiationInfo",
5021 config: Config{
5022 MaxVersion: VersionSSL30,
5023 Bugs: ProtocolBugs{
5024 RequireRenegotiationInfo: true,
5025 },
5026 },
5027 })
5028 testCases = append(testCases, testCase{
5029 testType: serverTest,
5030 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5031 config: Config{
5032 MaxVersion: VersionSSL30,
5033 Bugs: ProtocolBugs{
5034 NoRenegotiationInfo: true,
5035 SendRenegotiationSCSV: true,
5036 RequireRenegotiationInfo: true,
5037 },
5038 },
5039 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005040
5041 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5042 // in ServerHello.
5043 testCases = append(testCases, testCase{
5044 name: "NPN-Forbidden-TLS13",
5045 config: Config{
5046 MaxVersion: VersionTLS13,
5047 NextProtos: []string{"foo"},
5048 Bugs: ProtocolBugs{
5049 NegotiateNPNAtAllVersions: true,
5050 },
5051 },
5052 flags: []string{"-select-next-proto", "foo"},
5053 shouldFail: true,
5054 expectedError: ":ERROR_PARSING_EXTENSION:",
5055 })
5056 testCases = append(testCases, testCase{
5057 name: "EMS-Forbidden-TLS13",
5058 config: Config{
5059 MaxVersion: VersionTLS13,
5060 Bugs: ProtocolBugs{
5061 NegotiateEMSAtAllVersions: true,
5062 },
5063 },
5064 shouldFail: true,
5065 expectedError: ":ERROR_PARSING_EXTENSION:",
5066 })
5067 testCases = append(testCases, testCase{
5068 name: "RenegotiationInfo-Forbidden-TLS13",
5069 config: Config{
5070 MaxVersion: VersionTLS13,
5071 Bugs: ProtocolBugs{
5072 NegotiateRenegotiationInfoAtAllVersions: true,
5073 },
5074 },
5075 shouldFail: true,
5076 expectedError: ":ERROR_PARSING_EXTENSION:",
5077 })
5078 testCases = append(testCases, testCase{
5079 name: "ChannelID-Forbidden-TLS13",
5080 config: Config{
5081 MaxVersion: VersionTLS13,
5082 RequestChannelID: true,
5083 Bugs: ProtocolBugs{
5084 NegotiateChannelIDAtAllVersions: true,
5085 },
5086 },
5087 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
5088 shouldFail: true,
5089 expectedError: ":ERROR_PARSING_EXTENSION:",
5090 })
5091 testCases = append(testCases, testCase{
5092 name: "Ticket-Forbidden-TLS13",
5093 config: Config{
5094 MaxVersion: VersionTLS12,
5095 },
5096 resumeConfig: &Config{
5097 MaxVersion: VersionTLS13,
5098 Bugs: ProtocolBugs{
5099 AdvertiseTicketExtension: true,
5100 },
5101 },
5102 resumeSession: true,
5103 shouldFail: true,
5104 expectedError: ":ERROR_PARSING_EXTENSION:",
5105 })
5106
5107 // Test that illegal extensions in TLS 1.3 are declined by the server if
5108 // offered in ClientHello. The runner's server will fail if this occurs,
5109 // so we exercise the offering path. (EMS and Renegotiation Info are
5110 // implicit in every test.)
5111 testCases = append(testCases, testCase{
5112 testType: serverTest,
5113 name: "ChannelID-Declined-TLS13",
5114 config: Config{
5115 MaxVersion: VersionTLS13,
5116 ChannelID: channelIDKey,
5117 },
5118 flags: []string{"-enable-channel-id"},
5119 })
5120 testCases = append(testCases, testCase{
5121 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005122 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005123 config: Config{
5124 MaxVersion: VersionTLS13,
5125 NextProtos: []string{"bar"},
5126 },
5127 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5128 })
David Benjamin196df5b2016-09-21 16:23:27 -04005129
5130 testCases = append(testCases, testCase{
5131 testType: serverTest,
5132 name: "InvalidChannelIDSignature",
5133 config: Config{
5134 MaxVersion: VersionTLS12,
5135 ChannelID: channelIDKey,
5136 Bugs: ProtocolBugs{
5137 InvalidChannelIDSignature: true,
5138 },
5139 },
5140 flags: []string{"-enable-channel-id"},
5141 shouldFail: true,
5142 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5143 expectedLocalError: "remote error: error decrypting message",
5144 })
David Benjamine78bfde2014-09-06 12:45:15 -04005145}
5146
David Benjamin01fe8202014-09-24 15:21:44 -04005147func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005148 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005149 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005150 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5151 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5152 // TLS 1.3 only shares ciphers with TLS 1.2, so
5153 // we skip certain combinations and use a
5154 // different cipher to test with.
5155 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5156 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5157 continue
5158 }
5159 }
5160
David Benjamin8b8c0062014-11-23 02:47:52 -05005161 protocols := []protocol{tls}
5162 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5163 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005164 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005165 for _, protocol := range protocols {
5166 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5167 if protocol == dtls {
5168 suffix += "-DTLS"
5169 }
5170
David Benjaminece3de92015-03-16 18:02:20 -04005171 if sessionVers.version == resumeVers.version {
5172 testCases = append(testCases, testCase{
5173 protocol: protocol,
5174 name: "Resume-Client" + suffix,
5175 resumeSession: true,
5176 config: Config{
5177 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005178 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005179 Bugs: ProtocolBugs{
5180 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5181 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5182 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005183 },
David Benjaminece3de92015-03-16 18:02:20 -04005184 expectedVersion: sessionVers.version,
5185 expectedResumeVersion: resumeVers.version,
5186 })
5187 } else {
David Benjamin405da482016-08-08 17:25:07 -04005188 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5189
5190 // Offering a TLS 1.3 session sends an empty session ID, so
5191 // there is no way to convince a non-lookahead client the
5192 // session was resumed. It will appear to the client that a
5193 // stray ChangeCipherSpec was sent.
5194 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5195 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005196 }
5197
David Benjaminece3de92015-03-16 18:02:20 -04005198 testCases = append(testCases, testCase{
5199 protocol: protocol,
5200 name: "Resume-Client-Mismatch" + suffix,
5201 resumeSession: true,
5202 config: Config{
5203 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005204 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005205 },
David Benjaminece3de92015-03-16 18:02:20 -04005206 expectedVersion: sessionVers.version,
5207 resumeConfig: &Config{
5208 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005209 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005210 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005211 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005212 },
5213 },
5214 expectedResumeVersion: resumeVers.version,
5215 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005216 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005217 })
5218 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005219
5220 testCases = append(testCases, testCase{
5221 protocol: protocol,
5222 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005223 resumeSession: true,
5224 config: Config{
5225 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005226 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005227 },
5228 expectedVersion: sessionVers.version,
5229 resumeConfig: &Config{
5230 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005231 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005232 },
5233 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005234 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005235 expectedResumeVersion: resumeVers.version,
5236 })
5237
David Benjamin8b8c0062014-11-23 02:47:52 -05005238 testCases = append(testCases, testCase{
5239 protocol: protocol,
5240 testType: serverTest,
5241 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005242 resumeSession: true,
5243 config: Config{
5244 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005245 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005246 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005247 expectedVersion: sessionVers.version,
5248 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005249 resumeConfig: &Config{
5250 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005251 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005252 Bugs: ProtocolBugs{
5253 SendBothTickets: true,
5254 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005255 },
5256 expectedResumeVersion: resumeVers.version,
5257 })
5258 }
David Benjamin01fe8202014-09-24 15:21:44 -04005259 }
5260 }
David Benjaminece3de92015-03-16 18:02:20 -04005261
5262 testCases = append(testCases, testCase{
5263 name: "Resume-Client-CipherMismatch",
5264 resumeSession: true,
5265 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005266 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005267 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5268 },
5269 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005270 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005271 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5272 Bugs: ProtocolBugs{
5273 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5274 },
5275 },
5276 shouldFail: true,
5277 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5278 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005279
5280 testCases = append(testCases, testCase{
5281 name: "Resume-Client-CipherMismatch-TLS13",
5282 resumeSession: true,
5283 config: Config{
5284 MaxVersion: VersionTLS13,
5285 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5286 },
5287 resumeConfig: &Config{
5288 MaxVersion: VersionTLS13,
5289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5290 Bugs: ProtocolBugs{
5291 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5292 },
5293 },
5294 shouldFail: true,
5295 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5296 })
David Benjamin01fe8202014-09-24 15:21:44 -04005297}
5298
Adam Langley2ae77d22014-10-28 17:29:33 -07005299func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005300 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005301 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005302 testType: serverTest,
5303 name: "Renegotiate-Server-Forbidden",
5304 config: Config{
5305 MaxVersion: VersionTLS12,
5306 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005307 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005308 shouldFail: true,
5309 expectedError: ":NO_RENEGOTIATION:",
5310 expectedLocalError: "remote error: no renegotiation",
5311 })
Adam Langley5021b222015-06-12 18:27:58 -07005312 // The server shouldn't echo the renegotiation extension unless
5313 // requested by the client.
5314 testCases = append(testCases, testCase{
5315 testType: serverTest,
5316 name: "Renegotiate-Server-NoExt",
5317 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005318 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005319 Bugs: ProtocolBugs{
5320 NoRenegotiationInfo: true,
5321 RequireRenegotiationInfo: true,
5322 },
5323 },
5324 shouldFail: true,
5325 expectedLocalError: "renegotiation extension missing",
5326 })
5327 // The renegotiation SCSV should be sufficient for the server to echo
5328 // the extension.
5329 testCases = append(testCases, testCase{
5330 testType: serverTest,
5331 name: "Renegotiate-Server-NoExt-SCSV",
5332 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005333 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005334 Bugs: ProtocolBugs{
5335 NoRenegotiationInfo: true,
5336 SendRenegotiationSCSV: true,
5337 RequireRenegotiationInfo: true,
5338 },
5339 },
5340 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005341 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005342 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005343 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005344 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005345 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005346 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005347 },
5348 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005349 renegotiate: 1,
5350 flags: []string{
5351 "-renegotiate-freely",
5352 "-expect-total-renegotiations", "1",
5353 },
David Benjamincdea40c2015-03-19 14:09:43 -04005354 })
5355 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005356 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005357 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005359 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005360 Bugs: ProtocolBugs{
5361 EmptyRenegotiationInfo: true,
5362 },
5363 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005364 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005365 shouldFail: true,
5366 expectedError: ":RENEGOTIATION_MISMATCH:",
5367 })
5368 testCases = append(testCases, testCase{
5369 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005370 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005371 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005372 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005373 Bugs: ProtocolBugs{
5374 BadRenegotiationInfo: true,
5375 },
5376 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005377 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005378 shouldFail: true,
5379 expectedError: ":RENEGOTIATION_MISMATCH:",
5380 })
5381 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005382 name: "Renegotiate-Client-Downgrade",
5383 renegotiate: 1,
5384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005385 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005386 Bugs: ProtocolBugs{
5387 NoRenegotiationInfoAfterInitial: true,
5388 },
5389 },
5390 flags: []string{"-renegotiate-freely"},
5391 shouldFail: true,
5392 expectedError: ":RENEGOTIATION_MISMATCH:",
5393 })
5394 testCases = append(testCases, testCase{
5395 name: "Renegotiate-Client-Upgrade",
5396 renegotiate: 1,
5397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005398 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005399 Bugs: ProtocolBugs{
5400 NoRenegotiationInfoInInitial: true,
5401 },
5402 },
5403 flags: []string{"-renegotiate-freely"},
5404 shouldFail: true,
5405 expectedError: ":RENEGOTIATION_MISMATCH:",
5406 })
5407 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005408 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005409 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005411 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005412 Bugs: ProtocolBugs{
5413 NoRenegotiationInfo: true,
5414 },
5415 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005416 flags: []string{
5417 "-renegotiate-freely",
5418 "-expect-total-renegotiations", "1",
5419 },
David Benjamincff0b902015-05-15 23:09:47 -04005420 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005421
5422 // Test that the server may switch ciphers on renegotiation without
5423 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005424 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005425 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005426 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005427 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005428 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005429 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005430 },
5431 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005432 flags: []string{
5433 "-renegotiate-freely",
5434 "-expect-total-renegotiations", "1",
5435 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005436 })
5437 testCases = append(testCases, testCase{
5438 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005439 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005440 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005441 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005442 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5443 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005444 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005445 flags: []string{
5446 "-renegotiate-freely",
5447 "-expect-total-renegotiations", "1",
5448 },
David Benjaminb16346b2015-04-08 19:16:58 -04005449 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005450
5451 // Test that the server may not switch versions on renegotiation.
5452 testCases = append(testCases, testCase{
5453 name: "Renegotiate-Client-SwitchVersion",
5454 config: Config{
5455 MaxVersion: VersionTLS12,
5456 // Pick a cipher which exists at both versions.
5457 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5458 Bugs: ProtocolBugs{
5459 NegotiateVersionOnRenego: VersionTLS11,
5460 },
5461 },
5462 renegotiate: 1,
5463 flags: []string{
5464 "-renegotiate-freely",
5465 "-expect-total-renegotiations", "1",
5466 },
5467 shouldFail: true,
5468 expectedError: ":WRONG_SSL_VERSION:",
5469 })
5470
David Benjaminb16346b2015-04-08 19:16:58 -04005471 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005472 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005473 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005474 config: Config{
5475 MaxVersion: VersionTLS10,
5476 Bugs: ProtocolBugs{
5477 RequireSameRenegoClientVersion: true,
5478 },
5479 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005480 flags: []string{
5481 "-renegotiate-freely",
5482 "-expect-total-renegotiations", "1",
5483 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005484 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005485 testCases = append(testCases, testCase{
5486 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005487 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005488 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005489 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005490 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5491 NextProtos: []string{"foo"},
5492 },
5493 flags: []string{
5494 "-false-start",
5495 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005496 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005497 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005498 },
5499 shimWritesFirst: true,
5500 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005501
5502 // Client-side renegotiation controls.
5503 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005504 name: "Renegotiate-Client-Forbidden-1",
5505 config: Config{
5506 MaxVersion: VersionTLS12,
5507 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005508 renegotiate: 1,
5509 shouldFail: true,
5510 expectedError: ":NO_RENEGOTIATION:",
5511 expectedLocalError: "remote error: no renegotiation",
5512 })
5513 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005514 name: "Renegotiate-Client-Once-1",
5515 config: Config{
5516 MaxVersion: VersionTLS12,
5517 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005518 renegotiate: 1,
5519 flags: []string{
5520 "-renegotiate-once",
5521 "-expect-total-renegotiations", "1",
5522 },
5523 })
5524 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005525 name: "Renegotiate-Client-Freely-1",
5526 config: Config{
5527 MaxVersion: VersionTLS12,
5528 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005529 renegotiate: 1,
5530 flags: []string{
5531 "-renegotiate-freely",
5532 "-expect-total-renegotiations", "1",
5533 },
5534 })
5535 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005536 name: "Renegotiate-Client-Once-2",
5537 config: Config{
5538 MaxVersion: VersionTLS12,
5539 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005540 renegotiate: 2,
5541 flags: []string{"-renegotiate-once"},
5542 shouldFail: true,
5543 expectedError: ":NO_RENEGOTIATION:",
5544 expectedLocalError: "remote error: no renegotiation",
5545 })
5546 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005547 name: "Renegotiate-Client-Freely-2",
5548 config: Config{
5549 MaxVersion: VersionTLS12,
5550 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005551 renegotiate: 2,
5552 flags: []string{
5553 "-renegotiate-freely",
5554 "-expect-total-renegotiations", "2",
5555 },
5556 })
Adam Langley27a0d082015-11-03 13:34:10 -08005557 testCases = append(testCases, testCase{
5558 name: "Renegotiate-Client-NoIgnore",
5559 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005560 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005561 Bugs: ProtocolBugs{
5562 SendHelloRequestBeforeEveryAppDataRecord: true,
5563 },
5564 },
5565 shouldFail: true,
5566 expectedError: ":NO_RENEGOTIATION:",
5567 })
5568 testCases = append(testCases, testCase{
5569 name: "Renegotiate-Client-Ignore",
5570 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005571 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005572 Bugs: ProtocolBugs{
5573 SendHelloRequestBeforeEveryAppDataRecord: true,
5574 },
5575 },
5576 flags: []string{
5577 "-renegotiate-ignore",
5578 "-expect-total-renegotiations", "0",
5579 },
5580 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005581
David Benjamin397c8e62016-07-08 14:14:36 -07005582 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005583 testCases = append(testCases, testCase{
5584 name: "StrayHelloRequest",
5585 config: Config{
5586 MaxVersion: VersionTLS12,
5587 Bugs: ProtocolBugs{
5588 SendHelloRequestBeforeEveryHandshakeMessage: true,
5589 },
5590 },
5591 })
5592 testCases = append(testCases, testCase{
5593 name: "StrayHelloRequest-Packed",
5594 config: Config{
5595 MaxVersion: VersionTLS12,
5596 Bugs: ProtocolBugs{
5597 PackHandshakeFlight: true,
5598 SendHelloRequestBeforeEveryHandshakeMessage: true,
5599 },
5600 },
5601 })
5602
David Benjamin12d2c482016-07-24 10:56:51 -04005603 // Test renegotiation works if HelloRequest and server Finished come in
5604 // the same record.
5605 testCases = append(testCases, testCase{
5606 name: "Renegotiate-Client-Packed",
5607 config: Config{
5608 MaxVersion: VersionTLS12,
5609 Bugs: ProtocolBugs{
5610 PackHandshakeFlight: true,
5611 PackHelloRequestWithFinished: true,
5612 },
5613 },
5614 renegotiate: 1,
5615 flags: []string{
5616 "-renegotiate-freely",
5617 "-expect-total-renegotiations", "1",
5618 },
5619 })
5620
David Benjamin397c8e62016-07-08 14:14:36 -07005621 // Renegotiation is forbidden in TLS 1.3.
5622 testCases = append(testCases, testCase{
5623 name: "Renegotiate-Client-TLS13",
5624 config: Config{
5625 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005626 Bugs: ProtocolBugs{
5627 SendHelloRequestBeforeEveryAppDataRecord: true,
5628 },
David Benjamin397c8e62016-07-08 14:14:36 -07005629 },
David Benjamin397c8e62016-07-08 14:14:36 -07005630 flags: []string{
5631 "-renegotiate-freely",
5632 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005633 shouldFail: true,
5634 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005635 })
5636
5637 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5638 testCases = append(testCases, testCase{
5639 name: "StrayHelloRequest-TLS13",
5640 config: Config{
5641 MaxVersion: VersionTLS13,
5642 Bugs: ProtocolBugs{
5643 SendHelloRequestBeforeEveryHandshakeMessage: true,
5644 },
5645 },
5646 shouldFail: true,
5647 expectedError: ":UNEXPECTED_MESSAGE:",
5648 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005649}
5650
David Benjamin5e961c12014-11-07 01:48:35 -05005651func addDTLSReplayTests() {
5652 // Test that sequence number replays are detected.
5653 testCases = append(testCases, testCase{
5654 protocol: dtls,
5655 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005656 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005657 replayWrites: true,
5658 })
5659
David Benjamin8e6db492015-07-25 18:29:23 -04005660 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005661 // than the retransmit window.
5662 testCases = append(testCases, testCase{
5663 protocol: dtls,
5664 name: "DTLS-Replay-LargeGaps",
5665 config: Config{
5666 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005667 SequenceNumberMapping: func(in uint64) uint64 {
5668 return in * 127
5669 },
David Benjamin5e961c12014-11-07 01:48:35 -05005670 },
5671 },
David Benjamin8e6db492015-07-25 18:29:23 -04005672 messageCount: 200,
5673 replayWrites: true,
5674 })
5675
5676 // Test the incoming sequence number changing non-monotonically.
5677 testCases = append(testCases, testCase{
5678 protocol: dtls,
5679 name: "DTLS-Replay-NonMonotonic",
5680 config: Config{
5681 Bugs: ProtocolBugs{
5682 SequenceNumberMapping: func(in uint64) uint64 {
5683 return in ^ 31
5684 },
5685 },
5686 },
5687 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005688 replayWrites: true,
5689 })
5690}
5691
Nick Harper60edffd2016-06-21 15:19:24 -07005692var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005693 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005694 id signatureAlgorithm
5695 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005696}{
Nick Harper60edffd2016-06-21 15:19:24 -07005697 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5698 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5699 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5700 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005701 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005702 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5703 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5704 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005705 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5706 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5707 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005708 // Tests for key types prior to TLS 1.2.
5709 {"RSA", 0, testCertRSA},
5710 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005711}
5712
Nick Harper60edffd2016-06-21 15:19:24 -07005713const fakeSigAlg1 signatureAlgorithm = 0x2a01
5714const fakeSigAlg2 signatureAlgorithm = 0xff01
5715
5716func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005717 // Not all ciphers involve a signature. Advertise a list which gives all
5718 // versions a signing cipher.
5719 signingCiphers := []uint16{
5720 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5721 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5722 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5723 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5724 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5725 }
5726
David Benjaminca3d5452016-07-14 12:51:01 -04005727 var allAlgorithms []signatureAlgorithm
5728 for _, alg := range testSignatureAlgorithms {
5729 if alg.id != 0 {
5730 allAlgorithms = append(allAlgorithms, alg.id)
5731 }
5732 }
5733
Nick Harper60edffd2016-06-21 15:19:24 -07005734 // Make sure each signature algorithm works. Include some fake values in
5735 // the list and ensure they're ignored.
5736 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005737 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005738 if (ver.version < VersionTLS12) != (alg.id == 0) {
5739 continue
5740 }
5741
5742 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5743 // or remove it in C.
5744 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005745 continue
5746 }
Nick Harper60edffd2016-06-21 15:19:24 -07005747
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005748 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005749 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005750 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5751 shouldFail = true
5752 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005753 // RSA-PKCS1 does not exist in TLS 1.3.
5754 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5755 shouldFail = true
5756 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005757
5758 var signError, verifyError string
5759 if shouldFail {
5760 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5761 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005762 }
David Benjamin000800a2014-11-14 01:43:59 -05005763
David Benjamin1fb125c2016-07-08 18:52:12 -07005764 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005765
David Benjamin7a41d372016-07-09 11:21:54 -07005766 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005767 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005768 config: Config{
5769 MaxVersion: ver.version,
5770 ClientAuth: RequireAnyClientCert,
5771 VerifySignatureAlgorithms: []signatureAlgorithm{
5772 fakeSigAlg1,
5773 alg.id,
5774 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005775 },
David Benjamin7a41d372016-07-09 11:21:54 -07005776 },
5777 flags: []string{
5778 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5779 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5780 "-enable-all-curves",
5781 },
5782 shouldFail: shouldFail,
5783 expectedError: signError,
5784 expectedPeerSignatureAlgorithm: alg.id,
5785 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005786
David Benjamin7a41d372016-07-09 11:21:54 -07005787 testCases = append(testCases, testCase{
5788 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005789 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005790 config: Config{
5791 MaxVersion: ver.version,
5792 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5793 SignSignatureAlgorithms: []signatureAlgorithm{
5794 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005795 },
David Benjamin7a41d372016-07-09 11:21:54 -07005796 Bugs: ProtocolBugs{
5797 SkipECDSACurveCheck: shouldFail,
5798 IgnoreSignatureVersionChecks: shouldFail,
5799 // The client won't advertise 1.3-only algorithms after
5800 // version negotiation.
5801 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005802 },
David Benjamin7a41d372016-07-09 11:21:54 -07005803 },
5804 flags: []string{
5805 "-require-any-client-certificate",
5806 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5807 "-enable-all-curves",
5808 },
5809 shouldFail: shouldFail,
5810 expectedError: verifyError,
5811 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005812
5813 testCases = append(testCases, testCase{
5814 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005815 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005816 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005817 MaxVersion: ver.version,
5818 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005819 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005820 fakeSigAlg1,
5821 alg.id,
5822 fakeSigAlg2,
5823 },
5824 },
5825 flags: []string{
5826 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5827 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5828 "-enable-all-curves",
5829 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005830 shouldFail: shouldFail,
5831 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005832 expectedPeerSignatureAlgorithm: alg.id,
5833 })
5834
5835 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005836 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005837 config: Config{
5838 MaxVersion: ver.version,
5839 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005840 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005841 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005842 alg.id,
5843 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005844 Bugs: ProtocolBugs{
5845 SkipECDSACurveCheck: shouldFail,
5846 IgnoreSignatureVersionChecks: shouldFail,
5847 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005848 },
5849 flags: []string{
5850 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5851 "-enable-all-curves",
5852 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005853 shouldFail: shouldFail,
5854 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005855 })
David Benjamin5208fd42016-07-13 21:43:25 -04005856
5857 if !shouldFail {
5858 testCases = append(testCases, testCase{
5859 testType: serverTest,
5860 name: "ClientAuth-InvalidSignature" + suffix,
5861 config: Config{
5862 MaxVersion: ver.version,
5863 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5864 SignSignatureAlgorithms: []signatureAlgorithm{
5865 alg.id,
5866 },
5867 Bugs: ProtocolBugs{
5868 InvalidSignature: true,
5869 },
5870 },
5871 flags: []string{
5872 "-require-any-client-certificate",
5873 "-enable-all-curves",
5874 },
5875 shouldFail: true,
5876 expectedError: ":BAD_SIGNATURE:",
5877 })
5878
5879 testCases = append(testCases, testCase{
5880 name: "ServerAuth-InvalidSignature" + suffix,
5881 config: Config{
5882 MaxVersion: ver.version,
5883 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5884 CipherSuites: signingCiphers,
5885 SignSignatureAlgorithms: []signatureAlgorithm{
5886 alg.id,
5887 },
5888 Bugs: ProtocolBugs{
5889 InvalidSignature: true,
5890 },
5891 },
5892 flags: []string{"-enable-all-curves"},
5893 shouldFail: true,
5894 expectedError: ":BAD_SIGNATURE:",
5895 })
5896 }
David Benjaminca3d5452016-07-14 12:51:01 -04005897
5898 if ver.version >= VersionTLS12 && !shouldFail {
5899 testCases = append(testCases, testCase{
5900 name: "ClientAuth-Sign-Negotiate" + suffix,
5901 config: Config{
5902 MaxVersion: ver.version,
5903 ClientAuth: RequireAnyClientCert,
5904 VerifySignatureAlgorithms: allAlgorithms,
5905 },
5906 flags: []string{
5907 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5908 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5909 "-enable-all-curves",
5910 "-signing-prefs", strconv.Itoa(int(alg.id)),
5911 },
5912 expectedPeerSignatureAlgorithm: alg.id,
5913 })
5914
5915 testCases = append(testCases, testCase{
5916 testType: serverTest,
5917 name: "ServerAuth-Sign-Negotiate" + suffix,
5918 config: Config{
5919 MaxVersion: ver.version,
5920 CipherSuites: signingCiphers,
5921 VerifySignatureAlgorithms: allAlgorithms,
5922 },
5923 flags: []string{
5924 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5925 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5926 "-enable-all-curves",
5927 "-signing-prefs", strconv.Itoa(int(alg.id)),
5928 },
5929 expectedPeerSignatureAlgorithm: alg.id,
5930 })
5931 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005932 }
David Benjamin000800a2014-11-14 01:43:59 -05005933 }
5934
Nick Harper60edffd2016-06-21 15:19:24 -07005935 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005936 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005937 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005938 config: Config{
5939 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005940 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005941 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005942 signatureECDSAWithP521AndSHA512,
5943 signatureRSAPKCS1WithSHA384,
5944 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005945 },
5946 },
5947 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005948 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5949 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005950 },
Nick Harper60edffd2016-06-21 15:19:24 -07005951 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005952 })
5953
5954 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005955 name: "ClientAuth-SignatureType-TLS13",
5956 config: Config{
5957 ClientAuth: RequireAnyClientCert,
5958 MaxVersion: VersionTLS13,
5959 VerifySignatureAlgorithms: []signatureAlgorithm{
5960 signatureECDSAWithP521AndSHA512,
5961 signatureRSAPKCS1WithSHA384,
5962 signatureRSAPSSWithSHA384,
5963 signatureECDSAWithSHA1,
5964 },
5965 },
5966 flags: []string{
5967 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5968 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5969 },
5970 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5971 })
5972
5973 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005974 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005975 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005977 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005978 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005979 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005980 signatureECDSAWithP521AndSHA512,
5981 signatureRSAPKCS1WithSHA384,
5982 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005983 },
5984 },
Nick Harper60edffd2016-06-21 15:19:24 -07005985 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005986 })
5987
Steven Valdez143e8b32016-07-11 13:19:03 -04005988 testCases = append(testCases, testCase{
5989 testType: serverTest,
5990 name: "ServerAuth-SignatureType-TLS13",
5991 config: Config{
5992 MaxVersion: VersionTLS13,
5993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5994 VerifySignatureAlgorithms: []signatureAlgorithm{
5995 signatureECDSAWithP521AndSHA512,
5996 signatureRSAPKCS1WithSHA384,
5997 signatureRSAPSSWithSHA384,
5998 signatureECDSAWithSHA1,
5999 },
6000 },
6001 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6002 })
6003
David Benjamina95e9f32016-07-08 16:28:04 -07006004 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006005 testCases = append(testCases, testCase{
6006 testType: serverTest,
6007 name: "Verify-ClientAuth-SignatureType",
6008 config: Config{
6009 MaxVersion: VersionTLS12,
6010 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006011 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006012 signatureRSAPKCS1WithSHA256,
6013 },
6014 Bugs: ProtocolBugs{
6015 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6016 },
6017 },
6018 flags: []string{
6019 "-require-any-client-certificate",
6020 },
6021 shouldFail: true,
6022 expectedError: ":WRONG_SIGNATURE_TYPE:",
6023 })
6024
6025 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006026 testType: serverTest,
6027 name: "Verify-ClientAuth-SignatureType-TLS13",
6028 config: Config{
6029 MaxVersion: VersionTLS13,
6030 Certificates: []Certificate{rsaCertificate},
6031 SignSignatureAlgorithms: []signatureAlgorithm{
6032 signatureRSAPSSWithSHA256,
6033 },
6034 Bugs: ProtocolBugs{
6035 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6036 },
6037 },
6038 flags: []string{
6039 "-require-any-client-certificate",
6040 },
6041 shouldFail: true,
6042 expectedError: ":WRONG_SIGNATURE_TYPE:",
6043 })
6044
6045 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006046 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006047 config: Config{
6048 MaxVersion: VersionTLS12,
6049 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006050 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006051 signatureRSAPKCS1WithSHA256,
6052 },
6053 Bugs: ProtocolBugs{
6054 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6055 },
6056 },
6057 shouldFail: true,
6058 expectedError: ":WRONG_SIGNATURE_TYPE:",
6059 })
6060
Steven Valdez143e8b32016-07-11 13:19:03 -04006061 testCases = append(testCases, testCase{
6062 name: "Verify-ServerAuth-SignatureType-TLS13",
6063 config: Config{
6064 MaxVersion: VersionTLS13,
6065 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6066 SignSignatureAlgorithms: []signatureAlgorithm{
6067 signatureRSAPSSWithSHA256,
6068 },
6069 Bugs: ProtocolBugs{
6070 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6071 },
6072 },
6073 shouldFail: true,
6074 expectedError: ":WRONG_SIGNATURE_TYPE:",
6075 })
6076
David Benjamin51dd7d62016-07-08 16:07:01 -07006077 // Test that, if the list is missing, the peer falls back to SHA-1 in
6078 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006079 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006080 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006081 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006082 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006083 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006084 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006085 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006086 },
6087 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006088 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006089 },
6090 },
6091 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006092 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6093 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006094 },
6095 })
6096
6097 testCases = append(testCases, testCase{
6098 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006099 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006100 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006101 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006102 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006103 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006104 },
6105 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006106 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006107 },
6108 },
David Benjaminee32bea2016-08-17 13:36:44 -04006109 flags: []string{
6110 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6111 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6112 },
6113 })
6114
6115 testCases = append(testCases, testCase{
6116 name: "ClientAuth-SHA1-Fallback-ECDSA",
6117 config: Config{
6118 MaxVersion: VersionTLS12,
6119 ClientAuth: RequireAnyClientCert,
6120 VerifySignatureAlgorithms: []signatureAlgorithm{
6121 signatureECDSAWithSHA1,
6122 },
6123 Bugs: ProtocolBugs{
6124 NoSignatureAlgorithms: true,
6125 },
6126 },
6127 flags: []string{
6128 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6129 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6130 },
6131 })
6132
6133 testCases = append(testCases, testCase{
6134 testType: serverTest,
6135 name: "ServerAuth-SHA1-Fallback-ECDSA",
6136 config: Config{
6137 MaxVersion: VersionTLS12,
6138 VerifySignatureAlgorithms: []signatureAlgorithm{
6139 signatureECDSAWithSHA1,
6140 },
6141 Bugs: ProtocolBugs{
6142 NoSignatureAlgorithms: true,
6143 },
6144 },
6145 flags: []string{
6146 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6147 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6148 },
David Benjamin000800a2014-11-14 01:43:59 -05006149 })
David Benjamin72dc7832015-03-16 17:49:43 -04006150
David Benjamin51dd7d62016-07-08 16:07:01 -07006151 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006152 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006153 config: Config{
6154 MaxVersion: VersionTLS13,
6155 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006156 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006157 signatureRSAPKCS1WithSHA1,
6158 },
6159 Bugs: ProtocolBugs{
6160 NoSignatureAlgorithms: true,
6161 },
6162 },
6163 flags: []string{
6164 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6165 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6166 },
David Benjamin48901652016-08-01 12:12:47 -04006167 shouldFail: true,
6168 // An empty CertificateRequest signature algorithm list is a
6169 // syntax error in TLS 1.3.
6170 expectedError: ":DECODE_ERROR:",
6171 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006172 })
6173
6174 testCases = append(testCases, testCase{
6175 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006176 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006177 config: Config{
6178 MaxVersion: VersionTLS13,
6179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006180 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006181 signatureRSAPKCS1WithSHA1,
6182 },
6183 Bugs: ProtocolBugs{
6184 NoSignatureAlgorithms: true,
6185 },
6186 },
6187 shouldFail: true,
6188 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6189 })
6190
David Benjaminb62d2872016-07-18 14:55:02 +02006191 // Test that hash preferences are enforced. BoringSSL does not implement
6192 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006193 testCases = append(testCases, testCase{
6194 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006195 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006197 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006198 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006199 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006200 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006201 },
6202 Bugs: ProtocolBugs{
6203 IgnorePeerSignatureAlgorithmPreferences: true,
6204 },
6205 },
6206 flags: []string{"-require-any-client-certificate"},
6207 shouldFail: true,
6208 expectedError: ":WRONG_SIGNATURE_TYPE:",
6209 })
6210
6211 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006212 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006214 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006215 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006216 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006217 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006218 },
6219 Bugs: ProtocolBugs{
6220 IgnorePeerSignatureAlgorithmPreferences: true,
6221 },
6222 },
6223 shouldFail: true,
6224 expectedError: ":WRONG_SIGNATURE_TYPE:",
6225 })
David Benjaminb62d2872016-07-18 14:55:02 +02006226 testCases = append(testCases, testCase{
6227 testType: serverTest,
6228 name: "ClientAuth-Enforced-TLS13",
6229 config: Config{
6230 MaxVersion: VersionTLS13,
6231 Certificates: []Certificate{rsaCertificate},
6232 SignSignatureAlgorithms: []signatureAlgorithm{
6233 signatureRSAPKCS1WithMD5,
6234 },
6235 Bugs: ProtocolBugs{
6236 IgnorePeerSignatureAlgorithmPreferences: true,
6237 IgnoreSignatureVersionChecks: true,
6238 },
6239 },
6240 flags: []string{"-require-any-client-certificate"},
6241 shouldFail: true,
6242 expectedError: ":WRONG_SIGNATURE_TYPE:",
6243 })
6244
6245 testCases = append(testCases, testCase{
6246 name: "ServerAuth-Enforced-TLS13",
6247 config: Config{
6248 MaxVersion: VersionTLS13,
6249 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6250 SignSignatureAlgorithms: []signatureAlgorithm{
6251 signatureRSAPKCS1WithMD5,
6252 },
6253 Bugs: ProtocolBugs{
6254 IgnorePeerSignatureAlgorithmPreferences: true,
6255 IgnoreSignatureVersionChecks: true,
6256 },
6257 },
6258 shouldFail: true,
6259 expectedError: ":WRONG_SIGNATURE_TYPE:",
6260 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006261
6262 // Test that the agreed upon digest respects the client preferences and
6263 // the server digests.
6264 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006265 name: "NoCommonAlgorithms-Digests",
6266 config: Config{
6267 MaxVersion: VersionTLS12,
6268 ClientAuth: RequireAnyClientCert,
6269 VerifySignatureAlgorithms: []signatureAlgorithm{
6270 signatureRSAPKCS1WithSHA512,
6271 signatureRSAPKCS1WithSHA1,
6272 },
6273 },
6274 flags: []string{
6275 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6276 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6277 "-digest-prefs", "SHA256",
6278 },
6279 shouldFail: true,
6280 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6281 })
6282 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006283 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006285 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006286 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006287 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006288 signatureRSAPKCS1WithSHA512,
6289 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006290 },
6291 },
6292 flags: []string{
6293 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6294 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006295 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006296 },
David Benjaminca3d5452016-07-14 12:51:01 -04006297 shouldFail: true,
6298 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6299 })
6300 testCases = append(testCases, testCase{
6301 name: "NoCommonAlgorithms-TLS13",
6302 config: Config{
6303 MaxVersion: VersionTLS13,
6304 ClientAuth: RequireAnyClientCert,
6305 VerifySignatureAlgorithms: []signatureAlgorithm{
6306 signatureRSAPSSWithSHA512,
6307 signatureRSAPSSWithSHA384,
6308 },
6309 },
6310 flags: []string{
6311 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6312 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6313 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6314 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006315 shouldFail: true,
6316 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006317 })
6318 testCases = append(testCases, testCase{
6319 name: "Agree-Digest-SHA256",
6320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006321 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006322 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006323 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006324 signatureRSAPKCS1WithSHA1,
6325 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006326 },
6327 },
6328 flags: []string{
6329 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6330 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006331 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006332 },
Nick Harper60edffd2016-06-21 15:19:24 -07006333 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006334 })
6335 testCases = append(testCases, testCase{
6336 name: "Agree-Digest-SHA1",
6337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006338 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006339 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006340 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006341 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006342 },
6343 },
6344 flags: []string{
6345 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6346 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006347 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006348 },
Nick Harper60edffd2016-06-21 15:19:24 -07006349 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006350 })
6351 testCases = append(testCases, testCase{
6352 name: "Agree-Digest-Default",
6353 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006354 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006355 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006356 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006357 signatureRSAPKCS1WithSHA256,
6358 signatureECDSAWithP256AndSHA256,
6359 signatureRSAPKCS1WithSHA1,
6360 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006361 },
6362 },
6363 flags: []string{
6364 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6365 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6366 },
Nick Harper60edffd2016-06-21 15:19:24 -07006367 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006368 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006369
David Benjaminca3d5452016-07-14 12:51:01 -04006370 // Test that the signing preference list may include extra algorithms
6371 // without negotiation problems.
6372 testCases = append(testCases, testCase{
6373 testType: serverTest,
6374 name: "FilterExtraAlgorithms",
6375 config: Config{
6376 MaxVersion: VersionTLS12,
6377 VerifySignatureAlgorithms: []signatureAlgorithm{
6378 signatureRSAPKCS1WithSHA256,
6379 },
6380 },
6381 flags: []string{
6382 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6383 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6384 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6385 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6386 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6387 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6388 },
6389 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6390 })
6391
David Benjamin4c3ddf72016-06-29 18:13:53 -04006392 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6393 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006394 testCases = append(testCases, testCase{
6395 name: "CheckLeafCurve",
6396 config: Config{
6397 MaxVersion: VersionTLS12,
6398 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006399 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006400 },
6401 flags: []string{"-p384-only"},
6402 shouldFail: true,
6403 expectedError: ":BAD_ECC_CERT:",
6404 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006405
6406 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6407 testCases = append(testCases, testCase{
6408 name: "CheckLeafCurve-TLS13",
6409 config: Config{
6410 MaxVersion: VersionTLS13,
6411 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6412 Certificates: []Certificate{ecdsaP256Certificate},
6413 },
6414 flags: []string{"-p384-only"},
6415 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006416
6417 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6418 testCases = append(testCases, testCase{
6419 name: "ECDSACurveMismatch-Verify-TLS12",
6420 config: Config{
6421 MaxVersion: VersionTLS12,
6422 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6423 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006424 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006425 signatureECDSAWithP384AndSHA384,
6426 },
6427 },
6428 })
6429
6430 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6431 testCases = append(testCases, testCase{
6432 name: "ECDSACurveMismatch-Verify-TLS13",
6433 config: Config{
6434 MaxVersion: VersionTLS13,
6435 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6436 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006437 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006438 signatureECDSAWithP384AndSHA384,
6439 },
6440 Bugs: ProtocolBugs{
6441 SkipECDSACurveCheck: true,
6442 },
6443 },
6444 shouldFail: true,
6445 expectedError: ":WRONG_SIGNATURE_TYPE:",
6446 })
6447
6448 // Signature algorithm selection in TLS 1.3 should take the curve into
6449 // account.
6450 testCases = append(testCases, testCase{
6451 testType: serverTest,
6452 name: "ECDSACurveMismatch-Sign-TLS13",
6453 config: Config{
6454 MaxVersion: VersionTLS13,
6455 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006456 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006457 signatureECDSAWithP384AndSHA384,
6458 signatureECDSAWithP256AndSHA256,
6459 },
6460 },
6461 flags: []string{
6462 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6463 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6464 },
6465 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6466 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006467
6468 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6469 // server does not attempt to sign in that case.
6470 testCases = append(testCases, testCase{
6471 testType: serverTest,
6472 name: "RSA-PSS-Large",
6473 config: Config{
6474 MaxVersion: VersionTLS13,
6475 VerifySignatureAlgorithms: []signatureAlgorithm{
6476 signatureRSAPSSWithSHA512,
6477 },
6478 },
6479 flags: []string{
6480 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6481 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6482 },
6483 shouldFail: true,
6484 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6485 })
David Benjamin57e929f2016-08-30 00:30:38 -04006486
6487 // Test that RSA-PSS is enabled by default for TLS 1.2.
6488 testCases = append(testCases, testCase{
6489 testType: clientTest,
6490 name: "RSA-PSS-Default-Verify",
6491 config: Config{
6492 MaxVersion: VersionTLS12,
6493 SignSignatureAlgorithms: []signatureAlgorithm{
6494 signatureRSAPSSWithSHA256,
6495 },
6496 },
6497 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6498 })
6499
6500 testCases = append(testCases, testCase{
6501 testType: serverTest,
6502 name: "RSA-PSS-Default-Sign",
6503 config: Config{
6504 MaxVersion: VersionTLS12,
6505 VerifySignatureAlgorithms: []signatureAlgorithm{
6506 signatureRSAPSSWithSHA256,
6507 },
6508 },
6509 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6510 })
David Benjamin000800a2014-11-14 01:43:59 -05006511}
6512
David Benjamin83f90402015-01-27 01:09:43 -05006513// timeouts is the retransmit schedule for BoringSSL. It doubles and
6514// caps at 60 seconds. On the 13th timeout, it gives up.
6515var timeouts = []time.Duration{
6516 1 * time.Second,
6517 2 * time.Second,
6518 4 * time.Second,
6519 8 * time.Second,
6520 16 * time.Second,
6521 32 * time.Second,
6522 60 * time.Second,
6523 60 * time.Second,
6524 60 * time.Second,
6525 60 * time.Second,
6526 60 * time.Second,
6527 60 * time.Second,
6528 60 * time.Second,
6529}
6530
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006531// shortTimeouts is an alternate set of timeouts which would occur if the
6532// initial timeout duration was set to 250ms.
6533var shortTimeouts = []time.Duration{
6534 250 * time.Millisecond,
6535 500 * time.Millisecond,
6536 1 * time.Second,
6537 2 * time.Second,
6538 4 * time.Second,
6539 8 * time.Second,
6540 16 * time.Second,
6541 32 * time.Second,
6542 60 * time.Second,
6543 60 * time.Second,
6544 60 * time.Second,
6545 60 * time.Second,
6546 60 * time.Second,
6547}
6548
David Benjamin83f90402015-01-27 01:09:43 -05006549func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006550 // These tests work by coordinating some behavior on both the shim and
6551 // the runner.
6552 //
6553 // TimeoutSchedule configures the runner to send a series of timeout
6554 // opcodes to the shim (see packetAdaptor) immediately before reading
6555 // each peer handshake flight N. The timeout opcode both simulates a
6556 // timeout in the shim and acts as a synchronization point to help the
6557 // runner bracket each handshake flight.
6558 //
6559 // We assume the shim does not read from the channel eagerly. It must
6560 // first wait until it has sent flight N and is ready to receive
6561 // handshake flight N+1. At this point, it will process the timeout
6562 // opcode. It must then immediately respond with a timeout ACK and act
6563 // as if the shim was idle for the specified amount of time.
6564 //
6565 // The runner then drops all packets received before the ACK and
6566 // continues waiting for flight N. This ordering results in one attempt
6567 // at sending flight N to be dropped. For the test to complete, the
6568 // shim must send flight N again, testing that the shim implements DTLS
6569 // retransmit on a timeout.
6570
Steven Valdez143e8b32016-07-11 13:19:03 -04006571 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006572 // likely be more epochs to cross and the final message's retransmit may
6573 // be more complex.
6574
David Benjamin585d7a42016-06-02 14:58:00 -04006575 for _, async := range []bool{true, false} {
6576 var tests []testCase
6577
6578 // Test that this is indeed the timeout schedule. Stress all
6579 // four patterns of handshake.
6580 for i := 1; i < len(timeouts); i++ {
6581 number := strconv.Itoa(i)
6582 tests = append(tests, testCase{
6583 protocol: dtls,
6584 name: "DTLS-Retransmit-Client-" + number,
6585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006586 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006587 Bugs: ProtocolBugs{
6588 TimeoutSchedule: timeouts[:i],
6589 },
6590 },
6591 resumeSession: true,
6592 })
6593 tests = append(tests, testCase{
6594 protocol: dtls,
6595 testType: serverTest,
6596 name: "DTLS-Retransmit-Server-" + number,
6597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006598 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006599 Bugs: ProtocolBugs{
6600 TimeoutSchedule: timeouts[:i],
6601 },
6602 },
6603 resumeSession: true,
6604 })
6605 }
6606
6607 // Test that exceeding the timeout schedule hits a read
6608 // timeout.
6609 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006610 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006611 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006613 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006614 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006615 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006616 },
6617 },
6618 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006619 shouldFail: true,
6620 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006621 })
David Benjamin585d7a42016-06-02 14:58:00 -04006622
6623 if async {
6624 // Test that timeout handling has a fudge factor, due to API
6625 // problems.
6626 tests = append(tests, testCase{
6627 protocol: dtls,
6628 name: "DTLS-Retransmit-Fudge",
6629 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006630 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006631 Bugs: ProtocolBugs{
6632 TimeoutSchedule: []time.Duration{
6633 timeouts[0] - 10*time.Millisecond,
6634 },
6635 },
6636 },
6637 resumeSession: true,
6638 })
6639 }
6640
6641 // Test that the final Finished retransmitting isn't
6642 // duplicated if the peer badly fragments everything.
6643 tests = append(tests, testCase{
6644 testType: serverTest,
6645 protocol: dtls,
6646 name: "DTLS-Retransmit-Fragmented",
6647 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006648 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006649 Bugs: ProtocolBugs{
6650 TimeoutSchedule: []time.Duration{timeouts[0]},
6651 MaxHandshakeRecordLength: 2,
6652 },
6653 },
6654 })
6655
6656 // Test the timeout schedule when a shorter initial timeout duration is set.
6657 tests = append(tests, testCase{
6658 protocol: dtls,
6659 name: "DTLS-Retransmit-Short-Client",
6660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006661 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006662 Bugs: ProtocolBugs{
6663 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6664 },
6665 },
6666 resumeSession: true,
6667 flags: []string{"-initial-timeout-duration-ms", "250"},
6668 })
6669 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006670 protocol: dtls,
6671 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006672 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006673 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006674 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006675 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006676 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006677 },
6678 },
6679 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006680 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006681 })
David Benjamin585d7a42016-06-02 14:58:00 -04006682
6683 for _, test := range tests {
6684 if async {
6685 test.name += "-Async"
6686 test.flags = append(test.flags, "-async")
6687 }
6688
6689 testCases = append(testCases, test)
6690 }
David Benjamin83f90402015-01-27 01:09:43 -05006691 }
David Benjamin83f90402015-01-27 01:09:43 -05006692}
6693
David Benjaminc565ebb2015-04-03 04:06:36 -04006694func addExportKeyingMaterialTests() {
6695 for _, vers := range tlsVersions {
6696 if vers.version == VersionSSL30 {
6697 continue
6698 }
6699 testCases = append(testCases, testCase{
6700 name: "ExportKeyingMaterial-" + vers.name,
6701 config: Config{
6702 MaxVersion: vers.version,
6703 },
6704 exportKeyingMaterial: 1024,
6705 exportLabel: "label",
6706 exportContext: "context",
6707 useExportContext: true,
6708 })
6709 testCases = append(testCases, testCase{
6710 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6711 config: Config{
6712 MaxVersion: vers.version,
6713 },
6714 exportKeyingMaterial: 1024,
6715 })
6716 testCases = append(testCases, testCase{
6717 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6718 config: Config{
6719 MaxVersion: vers.version,
6720 },
6721 exportKeyingMaterial: 1024,
6722 useExportContext: true,
6723 })
6724 testCases = append(testCases, testCase{
6725 name: "ExportKeyingMaterial-Small-" + vers.name,
6726 config: Config{
6727 MaxVersion: vers.version,
6728 },
6729 exportKeyingMaterial: 1,
6730 exportLabel: "label",
6731 exportContext: "context",
6732 useExportContext: true,
6733 })
6734 }
6735 testCases = append(testCases, testCase{
6736 name: "ExportKeyingMaterial-SSL3",
6737 config: Config{
6738 MaxVersion: VersionSSL30,
6739 },
6740 exportKeyingMaterial: 1024,
6741 exportLabel: "label",
6742 exportContext: "context",
6743 useExportContext: true,
6744 shouldFail: true,
6745 expectedError: "failed to export keying material",
6746 })
6747}
6748
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006749func addTLSUniqueTests() {
6750 for _, isClient := range []bool{false, true} {
6751 for _, isResumption := range []bool{false, true} {
6752 for _, hasEMS := range []bool{false, true} {
6753 var suffix string
6754 if isResumption {
6755 suffix = "Resume-"
6756 } else {
6757 suffix = "Full-"
6758 }
6759
6760 if hasEMS {
6761 suffix += "EMS-"
6762 } else {
6763 suffix += "NoEMS-"
6764 }
6765
6766 if isClient {
6767 suffix += "Client"
6768 } else {
6769 suffix += "Server"
6770 }
6771
6772 test := testCase{
6773 name: "TLSUnique-" + suffix,
6774 testTLSUnique: true,
6775 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006776 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006777 Bugs: ProtocolBugs{
6778 NoExtendedMasterSecret: !hasEMS,
6779 },
6780 },
6781 }
6782
6783 if isResumption {
6784 test.resumeSession = true
6785 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006786 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006787 Bugs: ProtocolBugs{
6788 NoExtendedMasterSecret: !hasEMS,
6789 },
6790 }
6791 }
6792
6793 if isResumption && !hasEMS {
6794 test.shouldFail = true
6795 test.expectedError = "failed to get tls-unique"
6796 }
6797
6798 testCases = append(testCases, test)
6799 }
6800 }
6801 }
6802}
6803
Adam Langley09505632015-07-30 18:10:13 -07006804func addCustomExtensionTests() {
6805 expectedContents := "custom extension"
6806 emptyString := ""
6807
6808 for _, isClient := range []bool{false, true} {
6809 suffix := "Server"
6810 flag := "-enable-server-custom-extension"
6811 testType := serverTest
6812 if isClient {
6813 suffix = "Client"
6814 flag = "-enable-client-custom-extension"
6815 testType = clientTest
6816 }
6817
6818 testCases = append(testCases, testCase{
6819 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006820 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006822 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006823 Bugs: ProtocolBugs{
6824 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006825 ExpectedCustomExtension: &expectedContents,
6826 },
6827 },
6828 flags: []string{flag},
6829 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006830 testCases = append(testCases, testCase{
6831 testType: testType,
6832 name: "CustomExtensions-" + suffix + "-TLS13",
6833 config: Config{
6834 MaxVersion: VersionTLS13,
6835 Bugs: ProtocolBugs{
6836 CustomExtension: expectedContents,
6837 ExpectedCustomExtension: &expectedContents,
6838 },
6839 },
6840 flags: []string{flag},
6841 })
Adam Langley09505632015-07-30 18:10:13 -07006842
6843 // If the parse callback fails, the handshake should also fail.
6844 testCases = append(testCases, testCase{
6845 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006846 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006848 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006849 Bugs: ProtocolBugs{
6850 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006851 ExpectedCustomExtension: &expectedContents,
6852 },
6853 },
David Benjamin399e7c92015-07-30 23:01:27 -04006854 flags: []string{flag},
6855 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006856 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6857 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006858 testCases = append(testCases, testCase{
6859 testType: testType,
6860 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6861 config: Config{
6862 MaxVersion: VersionTLS13,
6863 Bugs: ProtocolBugs{
6864 CustomExtension: expectedContents + "foo",
6865 ExpectedCustomExtension: &expectedContents,
6866 },
6867 },
6868 flags: []string{flag},
6869 shouldFail: true,
6870 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6871 })
Adam Langley09505632015-07-30 18:10:13 -07006872
6873 // If the add callback fails, the handshake should also fail.
6874 testCases = append(testCases, testCase{
6875 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006876 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006877 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006878 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006879 Bugs: ProtocolBugs{
6880 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006881 ExpectedCustomExtension: &expectedContents,
6882 },
6883 },
David Benjamin399e7c92015-07-30 23:01:27 -04006884 flags: []string{flag, "-custom-extension-fail-add"},
6885 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006886 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6887 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006888 testCases = append(testCases, testCase{
6889 testType: testType,
6890 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6891 config: Config{
6892 MaxVersion: VersionTLS13,
6893 Bugs: ProtocolBugs{
6894 CustomExtension: expectedContents,
6895 ExpectedCustomExtension: &expectedContents,
6896 },
6897 },
6898 flags: []string{flag, "-custom-extension-fail-add"},
6899 shouldFail: true,
6900 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6901 })
Adam Langley09505632015-07-30 18:10:13 -07006902
6903 // If the add callback returns zero, no extension should be
6904 // added.
6905 skipCustomExtension := expectedContents
6906 if isClient {
6907 // For the case where the client skips sending the
6908 // custom extension, the server must not “echo” it.
6909 skipCustomExtension = ""
6910 }
6911 testCases = append(testCases, testCase{
6912 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006913 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006915 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006916 Bugs: ProtocolBugs{
6917 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006918 ExpectedCustomExtension: &emptyString,
6919 },
6920 },
6921 flags: []string{flag, "-custom-extension-skip"},
6922 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006923 testCases = append(testCases, testCase{
6924 testType: testType,
6925 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6926 config: Config{
6927 MaxVersion: VersionTLS13,
6928 Bugs: ProtocolBugs{
6929 CustomExtension: skipCustomExtension,
6930 ExpectedCustomExtension: &emptyString,
6931 },
6932 },
6933 flags: []string{flag, "-custom-extension-skip"},
6934 })
Adam Langley09505632015-07-30 18:10:13 -07006935 }
6936
6937 // The custom extension add callback should not be called if the client
6938 // doesn't send the extension.
6939 testCases = append(testCases, testCase{
6940 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006941 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006942 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006943 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006944 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006945 ExpectedCustomExtension: &emptyString,
6946 },
6947 },
6948 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6949 })
Adam Langley2deb9842015-08-07 11:15:37 -07006950
Steven Valdez143e8b32016-07-11 13:19:03 -04006951 testCases = append(testCases, testCase{
6952 testType: serverTest,
6953 name: "CustomExtensions-NotCalled-Server-TLS13",
6954 config: Config{
6955 MaxVersion: VersionTLS13,
6956 Bugs: ProtocolBugs{
6957 ExpectedCustomExtension: &emptyString,
6958 },
6959 },
6960 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6961 })
6962
Adam Langley2deb9842015-08-07 11:15:37 -07006963 // Test an unknown extension from the server.
6964 testCases = append(testCases, testCase{
6965 testType: clientTest,
6966 name: "UnknownExtension-Client",
6967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006968 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006969 Bugs: ProtocolBugs{
6970 CustomExtension: expectedContents,
6971 },
6972 },
David Benjamin0c40a962016-08-01 12:05:50 -04006973 shouldFail: true,
6974 expectedError: ":UNEXPECTED_EXTENSION:",
6975 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006976 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006977 testCases = append(testCases, testCase{
6978 testType: clientTest,
6979 name: "UnknownExtension-Client-TLS13",
6980 config: Config{
6981 MaxVersion: VersionTLS13,
6982 Bugs: ProtocolBugs{
6983 CustomExtension: expectedContents,
6984 },
6985 },
David Benjamin0c40a962016-08-01 12:05:50 -04006986 shouldFail: true,
6987 expectedError: ":UNEXPECTED_EXTENSION:",
6988 expectedLocalError: "remote error: unsupported extension",
6989 })
6990
6991 // Test a known but unoffered extension from the server.
6992 testCases = append(testCases, testCase{
6993 testType: clientTest,
6994 name: "UnofferedExtension-Client",
6995 config: Config{
6996 MaxVersion: VersionTLS12,
6997 Bugs: ProtocolBugs{
6998 SendALPN: "alpn",
6999 },
7000 },
7001 shouldFail: true,
7002 expectedError: ":UNEXPECTED_EXTENSION:",
7003 expectedLocalError: "remote error: unsupported extension",
7004 })
7005 testCases = append(testCases, testCase{
7006 testType: clientTest,
7007 name: "UnofferedExtension-Client-TLS13",
7008 config: Config{
7009 MaxVersion: VersionTLS13,
7010 Bugs: ProtocolBugs{
7011 SendALPN: "alpn",
7012 },
7013 },
7014 shouldFail: true,
7015 expectedError: ":UNEXPECTED_EXTENSION:",
7016 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007017 })
Adam Langley09505632015-07-30 18:10:13 -07007018}
7019
David Benjaminb36a3952015-12-01 18:53:13 -05007020func addRSAClientKeyExchangeTests() {
7021 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7022 testCases = append(testCases, testCase{
7023 testType: serverTest,
7024 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7025 config: Config{
7026 // Ensure the ClientHello version and final
7027 // version are different, to detect if the
7028 // server uses the wrong one.
7029 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007030 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007031 Bugs: ProtocolBugs{
7032 BadRSAClientKeyExchange: bad,
7033 },
7034 },
7035 shouldFail: true,
7036 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7037 })
7038 }
David Benjamine63d9d72016-09-19 18:27:34 -04007039
7040 // The server must compare whatever was in ClientHello.version for the
7041 // RSA premaster.
7042 testCases = append(testCases, testCase{
7043 testType: serverTest,
7044 name: "SendClientVersion-RSA",
7045 config: Config{
7046 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7047 Bugs: ProtocolBugs{
7048 SendClientVersion: 0x1234,
7049 },
7050 },
7051 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7052 })
David Benjaminb36a3952015-12-01 18:53:13 -05007053}
7054
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007055var testCurves = []struct {
7056 name string
7057 id CurveID
7058}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007059 {"P-256", CurveP256},
7060 {"P-384", CurveP384},
7061 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007062 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007063}
7064
Steven Valdez5440fe02016-07-18 12:40:30 -04007065const bogusCurve = 0x1234
7066
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007067func addCurveTests() {
7068 for _, curve := range testCurves {
7069 testCases = append(testCases, testCase{
7070 name: "CurveTest-Client-" + curve.name,
7071 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007072 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007073 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7074 CurvePreferences: []CurveID{curve.id},
7075 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007076 flags: []string{
7077 "-enable-all-curves",
7078 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7079 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007080 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007081 })
7082 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007083 name: "CurveTest-Client-" + curve.name + "-TLS13",
7084 config: Config{
7085 MaxVersion: VersionTLS13,
7086 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7087 CurvePreferences: []CurveID{curve.id},
7088 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007089 flags: []string{
7090 "-enable-all-curves",
7091 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7092 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007093 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007094 })
7095 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007096 testType: serverTest,
7097 name: "CurveTest-Server-" + curve.name,
7098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007099 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7101 CurvePreferences: []CurveID{curve.id},
7102 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007103 flags: []string{
7104 "-enable-all-curves",
7105 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7106 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007107 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007108 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007109 testCases = append(testCases, testCase{
7110 testType: serverTest,
7111 name: "CurveTest-Server-" + curve.name + "-TLS13",
7112 config: Config{
7113 MaxVersion: VersionTLS13,
7114 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7115 CurvePreferences: []CurveID{curve.id},
7116 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007117 flags: []string{
7118 "-enable-all-curves",
7119 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7120 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007121 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007122 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007123 }
David Benjamin241ae832016-01-15 03:04:54 -05007124
7125 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007126 testCases = append(testCases, testCase{
7127 testType: serverTest,
7128 name: "UnknownCurve",
7129 config: Config{
7130 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7131 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7132 },
7133 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007134
7135 // The server must not consider ECDHE ciphers when there are no
7136 // supported curves.
7137 testCases = append(testCases, testCase{
7138 testType: serverTest,
7139 name: "NoSupportedCurves",
7140 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007141 MaxVersion: VersionTLS12,
7142 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7143 Bugs: ProtocolBugs{
7144 NoSupportedCurves: true,
7145 },
7146 },
7147 shouldFail: true,
7148 expectedError: ":NO_SHARED_CIPHER:",
7149 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007150 testCases = append(testCases, testCase{
7151 testType: serverTest,
7152 name: "NoSupportedCurves-TLS13",
7153 config: Config{
7154 MaxVersion: VersionTLS13,
7155 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7156 Bugs: ProtocolBugs{
7157 NoSupportedCurves: true,
7158 },
7159 },
7160 shouldFail: true,
7161 expectedError: ":NO_SHARED_CIPHER:",
7162 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007163
7164 // The server must fall back to another cipher when there are no
7165 // supported curves.
7166 testCases = append(testCases, testCase{
7167 testType: serverTest,
7168 name: "NoCommonCurves",
7169 config: Config{
7170 MaxVersion: VersionTLS12,
7171 CipherSuites: []uint16{
7172 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7173 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7174 },
7175 CurvePreferences: []CurveID{CurveP224},
7176 },
7177 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7178 })
7179
7180 // The client must reject bogus curves and disabled curves.
7181 testCases = append(testCases, testCase{
7182 name: "BadECDHECurve",
7183 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007184 MaxVersion: VersionTLS12,
7185 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7186 Bugs: ProtocolBugs{
7187 SendCurve: bogusCurve,
7188 },
7189 },
7190 shouldFail: true,
7191 expectedError: ":WRONG_CURVE:",
7192 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007193 testCases = append(testCases, testCase{
7194 name: "BadECDHECurve-TLS13",
7195 config: Config{
7196 MaxVersion: VersionTLS13,
7197 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7198 Bugs: ProtocolBugs{
7199 SendCurve: bogusCurve,
7200 },
7201 },
7202 shouldFail: true,
7203 expectedError: ":WRONG_CURVE:",
7204 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007205
7206 testCases = append(testCases, testCase{
7207 name: "UnsupportedCurve",
7208 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007209 MaxVersion: VersionTLS12,
7210 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7211 CurvePreferences: []CurveID{CurveP256},
7212 Bugs: ProtocolBugs{
7213 IgnorePeerCurvePreferences: true,
7214 },
7215 },
7216 flags: []string{"-p384-only"},
7217 shouldFail: true,
7218 expectedError: ":WRONG_CURVE:",
7219 })
7220
David Benjamin4f921572016-07-17 14:20:10 +02007221 testCases = append(testCases, testCase{
7222 // TODO(davidben): Add a TLS 1.3 version where
7223 // HelloRetryRequest requests an unsupported curve.
7224 name: "UnsupportedCurve-ServerHello-TLS13",
7225 config: Config{
7226 MaxVersion: VersionTLS12,
7227 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7228 CurvePreferences: []CurveID{CurveP384},
7229 Bugs: ProtocolBugs{
7230 SendCurve: CurveP256,
7231 },
7232 },
7233 flags: []string{"-p384-only"},
7234 shouldFail: true,
7235 expectedError: ":WRONG_CURVE:",
7236 })
7237
David Benjamin4c3ddf72016-06-29 18:13:53 -04007238 // Test invalid curve points.
7239 testCases = append(testCases, testCase{
7240 name: "InvalidECDHPoint-Client",
7241 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007242 MaxVersion: VersionTLS12,
7243 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7244 CurvePreferences: []CurveID{CurveP256},
7245 Bugs: ProtocolBugs{
7246 InvalidECDHPoint: true,
7247 },
7248 },
7249 shouldFail: true,
7250 expectedError: ":INVALID_ENCODING:",
7251 })
7252 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007253 name: "InvalidECDHPoint-Client-TLS13",
7254 config: Config{
7255 MaxVersion: VersionTLS13,
7256 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7257 CurvePreferences: []CurveID{CurveP256},
7258 Bugs: ProtocolBugs{
7259 InvalidECDHPoint: true,
7260 },
7261 },
7262 shouldFail: true,
7263 expectedError: ":INVALID_ENCODING:",
7264 })
7265 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007266 testType: serverTest,
7267 name: "InvalidECDHPoint-Server",
7268 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007269 MaxVersion: VersionTLS12,
7270 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7271 CurvePreferences: []CurveID{CurveP256},
7272 Bugs: ProtocolBugs{
7273 InvalidECDHPoint: true,
7274 },
7275 },
7276 shouldFail: true,
7277 expectedError: ":INVALID_ENCODING:",
7278 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007279 testCases = append(testCases, testCase{
7280 testType: serverTest,
7281 name: "InvalidECDHPoint-Server-TLS13",
7282 config: Config{
7283 MaxVersion: VersionTLS13,
7284 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7285 CurvePreferences: []CurveID{CurveP256},
7286 Bugs: ProtocolBugs{
7287 InvalidECDHPoint: true,
7288 },
7289 },
7290 shouldFail: true,
7291 expectedError: ":INVALID_ENCODING:",
7292 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007293}
7294
Matt Braithwaite54217e42016-06-13 13:03:47 -07007295func addCECPQ1Tests() {
7296 testCases = append(testCases, testCase{
7297 testType: clientTest,
7298 name: "CECPQ1-Client-BadX25519Part",
7299 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007300 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007301 MinVersion: VersionTLS12,
7302 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7303 Bugs: ProtocolBugs{
7304 CECPQ1BadX25519Part: true,
7305 },
7306 },
7307 flags: []string{"-cipher", "kCECPQ1"},
7308 shouldFail: true,
7309 expectedLocalError: "local error: bad record MAC",
7310 })
7311 testCases = append(testCases, testCase{
7312 testType: clientTest,
7313 name: "CECPQ1-Client-BadNewhopePart",
7314 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007315 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007316 MinVersion: VersionTLS12,
7317 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7318 Bugs: ProtocolBugs{
7319 CECPQ1BadNewhopePart: true,
7320 },
7321 },
7322 flags: []string{"-cipher", "kCECPQ1"},
7323 shouldFail: true,
7324 expectedLocalError: "local error: bad record MAC",
7325 })
7326 testCases = append(testCases, testCase{
7327 testType: serverTest,
7328 name: "CECPQ1-Server-BadX25519Part",
7329 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007330 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007331 MinVersion: VersionTLS12,
7332 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7333 Bugs: ProtocolBugs{
7334 CECPQ1BadX25519Part: true,
7335 },
7336 },
7337 flags: []string{"-cipher", "kCECPQ1"},
7338 shouldFail: true,
7339 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7340 })
7341 testCases = append(testCases, testCase{
7342 testType: serverTest,
7343 name: "CECPQ1-Server-BadNewhopePart",
7344 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007345 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007346 MinVersion: VersionTLS12,
7347 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7348 Bugs: ProtocolBugs{
7349 CECPQ1BadNewhopePart: true,
7350 },
7351 },
7352 flags: []string{"-cipher", "kCECPQ1"},
7353 shouldFail: true,
7354 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7355 })
7356}
7357
David Benjamin5c4e8572016-08-19 17:44:53 -04007358func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007359 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007360 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007361 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007362 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007363 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7364 Bugs: ProtocolBugs{
7365 // This is a 1234-bit prime number, generated
7366 // with:
7367 // openssl gendh 1234 | openssl asn1parse -i
7368 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7369 },
7370 },
David Benjamin9e68f192016-06-30 14:55:33 -04007371 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007372 })
7373 testCases = append(testCases, testCase{
7374 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007375 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007376 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007377 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007378 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7379 },
7380 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007381 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007382 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007383}
7384
David Benjaminc9ae27c2016-06-24 22:56:37 -04007385func addTLS13RecordTests() {
7386 testCases = append(testCases, testCase{
7387 name: "TLS13-RecordPadding",
7388 config: Config{
7389 MaxVersion: VersionTLS13,
7390 MinVersion: VersionTLS13,
7391 Bugs: ProtocolBugs{
7392 RecordPadding: 10,
7393 },
7394 },
7395 })
7396
7397 testCases = append(testCases, testCase{
7398 name: "TLS13-EmptyRecords",
7399 config: Config{
7400 MaxVersion: VersionTLS13,
7401 MinVersion: VersionTLS13,
7402 Bugs: ProtocolBugs{
7403 OmitRecordContents: true,
7404 },
7405 },
7406 shouldFail: true,
7407 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7408 })
7409
7410 testCases = append(testCases, testCase{
7411 name: "TLS13-OnlyPadding",
7412 config: Config{
7413 MaxVersion: VersionTLS13,
7414 MinVersion: VersionTLS13,
7415 Bugs: ProtocolBugs{
7416 OmitRecordContents: true,
7417 RecordPadding: 10,
7418 },
7419 },
7420 shouldFail: true,
7421 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7422 })
7423
7424 testCases = append(testCases, testCase{
7425 name: "TLS13-WrongOuterRecord",
7426 config: Config{
7427 MaxVersion: VersionTLS13,
7428 MinVersion: VersionTLS13,
7429 Bugs: ProtocolBugs{
7430 OuterRecordType: recordTypeHandshake,
7431 },
7432 },
7433 shouldFail: true,
7434 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7435 })
7436}
7437
David Benjamin82261be2016-07-07 14:32:50 -07007438func addChangeCipherSpecTests() {
7439 // Test missing ChangeCipherSpecs.
7440 testCases = append(testCases, testCase{
7441 name: "SkipChangeCipherSpec-Client",
7442 config: Config{
7443 MaxVersion: VersionTLS12,
7444 Bugs: ProtocolBugs{
7445 SkipChangeCipherSpec: true,
7446 },
7447 },
7448 shouldFail: true,
7449 expectedError: ":UNEXPECTED_RECORD:",
7450 })
7451 testCases = append(testCases, testCase{
7452 testType: serverTest,
7453 name: "SkipChangeCipherSpec-Server",
7454 config: Config{
7455 MaxVersion: VersionTLS12,
7456 Bugs: ProtocolBugs{
7457 SkipChangeCipherSpec: true,
7458 },
7459 },
7460 shouldFail: true,
7461 expectedError: ":UNEXPECTED_RECORD:",
7462 })
7463 testCases = append(testCases, testCase{
7464 testType: serverTest,
7465 name: "SkipChangeCipherSpec-Server-NPN",
7466 config: Config{
7467 MaxVersion: VersionTLS12,
7468 NextProtos: []string{"bar"},
7469 Bugs: ProtocolBugs{
7470 SkipChangeCipherSpec: true,
7471 },
7472 },
7473 flags: []string{
7474 "-advertise-npn", "\x03foo\x03bar\x03baz",
7475 },
7476 shouldFail: true,
7477 expectedError: ":UNEXPECTED_RECORD:",
7478 })
7479
7480 // Test synchronization between the handshake and ChangeCipherSpec.
7481 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7482 // rejected. Test both with and without handshake packing to handle both
7483 // when the partial post-CCS message is in its own record and when it is
7484 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007485 for _, packed := range []bool{false, true} {
7486 var suffix string
7487 if packed {
7488 suffix = "-Packed"
7489 }
7490
7491 testCases = append(testCases, testCase{
7492 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7493 config: Config{
7494 MaxVersion: VersionTLS12,
7495 Bugs: ProtocolBugs{
7496 FragmentAcrossChangeCipherSpec: true,
7497 PackHandshakeFlight: packed,
7498 },
7499 },
7500 shouldFail: true,
7501 expectedError: ":UNEXPECTED_RECORD:",
7502 })
7503 testCases = append(testCases, testCase{
7504 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7505 config: Config{
7506 MaxVersion: VersionTLS12,
7507 },
7508 resumeSession: true,
7509 resumeConfig: &Config{
7510 MaxVersion: VersionTLS12,
7511 Bugs: ProtocolBugs{
7512 FragmentAcrossChangeCipherSpec: true,
7513 PackHandshakeFlight: packed,
7514 },
7515 },
7516 shouldFail: true,
7517 expectedError: ":UNEXPECTED_RECORD:",
7518 })
7519 testCases = append(testCases, testCase{
7520 testType: serverTest,
7521 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7522 config: Config{
7523 MaxVersion: VersionTLS12,
7524 Bugs: ProtocolBugs{
7525 FragmentAcrossChangeCipherSpec: true,
7526 PackHandshakeFlight: packed,
7527 },
7528 },
7529 shouldFail: true,
7530 expectedError: ":UNEXPECTED_RECORD:",
7531 })
7532 testCases = append(testCases, testCase{
7533 testType: serverTest,
7534 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7535 config: Config{
7536 MaxVersion: VersionTLS12,
7537 },
7538 resumeSession: true,
7539 resumeConfig: &Config{
7540 MaxVersion: VersionTLS12,
7541 Bugs: ProtocolBugs{
7542 FragmentAcrossChangeCipherSpec: true,
7543 PackHandshakeFlight: packed,
7544 },
7545 },
7546 shouldFail: true,
7547 expectedError: ":UNEXPECTED_RECORD:",
7548 })
7549 testCases = append(testCases, testCase{
7550 testType: serverTest,
7551 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7552 config: Config{
7553 MaxVersion: VersionTLS12,
7554 NextProtos: []string{"bar"},
7555 Bugs: ProtocolBugs{
7556 FragmentAcrossChangeCipherSpec: true,
7557 PackHandshakeFlight: packed,
7558 },
7559 },
7560 flags: []string{
7561 "-advertise-npn", "\x03foo\x03bar\x03baz",
7562 },
7563 shouldFail: true,
7564 expectedError: ":UNEXPECTED_RECORD:",
7565 })
7566 }
7567
David Benjamin61672812016-07-14 23:10:43 -04007568 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7569 // messages in the handshake queue. Do this by testing the server
7570 // reading the client Finished, reversing the flight so Finished comes
7571 // first.
7572 testCases = append(testCases, testCase{
7573 protocol: dtls,
7574 testType: serverTest,
7575 name: "SendUnencryptedFinished-DTLS",
7576 config: Config{
7577 MaxVersion: VersionTLS12,
7578 Bugs: ProtocolBugs{
7579 SendUnencryptedFinished: true,
7580 ReverseHandshakeFragments: true,
7581 },
7582 },
7583 shouldFail: true,
7584 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7585 })
7586
Steven Valdez143e8b32016-07-11 13:19:03 -04007587 // Test synchronization between encryption changes and the handshake in
7588 // TLS 1.3, where ChangeCipherSpec is implicit.
7589 testCases = append(testCases, testCase{
7590 name: "PartialEncryptedExtensionsWithServerHello",
7591 config: Config{
7592 MaxVersion: VersionTLS13,
7593 Bugs: ProtocolBugs{
7594 PartialEncryptedExtensionsWithServerHello: true,
7595 },
7596 },
7597 shouldFail: true,
7598 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7599 })
7600 testCases = append(testCases, testCase{
7601 testType: serverTest,
7602 name: "PartialClientFinishedWithClientHello",
7603 config: Config{
7604 MaxVersion: VersionTLS13,
7605 Bugs: ProtocolBugs{
7606 PartialClientFinishedWithClientHello: true,
7607 },
7608 },
7609 shouldFail: true,
7610 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7611 })
7612
David Benjamin82261be2016-07-07 14:32:50 -07007613 // Test that early ChangeCipherSpecs are handled correctly.
7614 testCases = append(testCases, testCase{
7615 testType: serverTest,
7616 name: "EarlyChangeCipherSpec-server-1",
7617 config: Config{
7618 MaxVersion: VersionTLS12,
7619 Bugs: ProtocolBugs{
7620 EarlyChangeCipherSpec: 1,
7621 },
7622 },
7623 shouldFail: true,
7624 expectedError: ":UNEXPECTED_RECORD:",
7625 })
7626 testCases = append(testCases, testCase{
7627 testType: serverTest,
7628 name: "EarlyChangeCipherSpec-server-2",
7629 config: Config{
7630 MaxVersion: VersionTLS12,
7631 Bugs: ProtocolBugs{
7632 EarlyChangeCipherSpec: 2,
7633 },
7634 },
7635 shouldFail: true,
7636 expectedError: ":UNEXPECTED_RECORD:",
7637 })
7638 testCases = append(testCases, testCase{
7639 protocol: dtls,
7640 name: "StrayChangeCipherSpec",
7641 config: Config{
7642 // TODO(davidben): Once DTLS 1.3 exists, test
7643 // that stray ChangeCipherSpec messages are
7644 // rejected.
7645 MaxVersion: VersionTLS12,
7646 Bugs: ProtocolBugs{
7647 StrayChangeCipherSpec: true,
7648 },
7649 },
7650 })
7651
7652 // Test that the contents of ChangeCipherSpec are checked.
7653 testCases = append(testCases, testCase{
7654 name: "BadChangeCipherSpec-1",
7655 config: Config{
7656 MaxVersion: VersionTLS12,
7657 Bugs: ProtocolBugs{
7658 BadChangeCipherSpec: []byte{2},
7659 },
7660 },
7661 shouldFail: true,
7662 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7663 })
7664 testCases = append(testCases, testCase{
7665 name: "BadChangeCipherSpec-2",
7666 config: Config{
7667 MaxVersion: VersionTLS12,
7668 Bugs: ProtocolBugs{
7669 BadChangeCipherSpec: []byte{1, 1},
7670 },
7671 },
7672 shouldFail: true,
7673 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7674 })
7675 testCases = append(testCases, testCase{
7676 protocol: dtls,
7677 name: "BadChangeCipherSpec-DTLS-1",
7678 config: Config{
7679 MaxVersion: VersionTLS12,
7680 Bugs: ProtocolBugs{
7681 BadChangeCipherSpec: []byte{2},
7682 },
7683 },
7684 shouldFail: true,
7685 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7686 })
7687 testCases = append(testCases, testCase{
7688 protocol: dtls,
7689 name: "BadChangeCipherSpec-DTLS-2",
7690 config: Config{
7691 MaxVersion: VersionTLS12,
7692 Bugs: ProtocolBugs{
7693 BadChangeCipherSpec: []byte{1, 1},
7694 },
7695 },
7696 shouldFail: true,
7697 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7698 })
7699}
7700
David Benjamincd2c8062016-09-09 11:28:16 -04007701type perMessageTest struct {
7702 messageType uint8
7703 test testCase
7704}
7705
7706// makePerMessageTests returns a series of test templates which cover each
7707// message in the TLS handshake. These may be used with bugs like
7708// WrongMessageType to fully test a per-message bug.
7709func makePerMessageTests() []perMessageTest {
7710 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007711 for _, protocol := range []protocol{tls, dtls} {
7712 var suffix string
7713 if protocol == dtls {
7714 suffix = "-DTLS"
7715 }
7716
David Benjamincd2c8062016-09-09 11:28:16 -04007717 ret = append(ret, perMessageTest{
7718 messageType: typeClientHello,
7719 test: testCase{
7720 protocol: protocol,
7721 testType: serverTest,
7722 name: "ClientHello" + suffix,
7723 config: Config{
7724 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007725 },
7726 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007727 })
7728
7729 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007730 ret = append(ret, perMessageTest{
7731 messageType: typeHelloVerifyRequest,
7732 test: testCase{
7733 protocol: protocol,
7734 name: "HelloVerifyRequest" + suffix,
7735 config: Config{
7736 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007737 },
7738 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007739 })
7740 }
7741
David Benjamincd2c8062016-09-09 11:28:16 -04007742 ret = append(ret, perMessageTest{
7743 messageType: typeServerHello,
7744 test: testCase{
7745 protocol: protocol,
7746 name: "ServerHello" + suffix,
7747 config: Config{
7748 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007749 },
7750 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007751 })
7752
David Benjamincd2c8062016-09-09 11:28:16 -04007753 ret = append(ret, perMessageTest{
7754 messageType: typeCertificate,
7755 test: testCase{
7756 protocol: protocol,
7757 name: "ServerCertificate" + suffix,
7758 config: Config{
7759 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007760 },
7761 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007762 })
7763
David Benjamincd2c8062016-09-09 11:28:16 -04007764 ret = append(ret, perMessageTest{
7765 messageType: typeCertificateStatus,
7766 test: testCase{
7767 protocol: protocol,
7768 name: "CertificateStatus" + suffix,
7769 config: Config{
7770 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007771 },
David Benjamincd2c8062016-09-09 11:28:16 -04007772 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007773 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007774 })
7775
David Benjamincd2c8062016-09-09 11:28:16 -04007776 ret = append(ret, perMessageTest{
7777 messageType: typeServerKeyExchange,
7778 test: testCase{
7779 protocol: protocol,
7780 name: "ServerKeyExchange" + suffix,
7781 config: Config{
7782 MaxVersion: VersionTLS12,
7783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007784 },
7785 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007786 })
7787
David Benjamincd2c8062016-09-09 11:28:16 -04007788 ret = append(ret, perMessageTest{
7789 messageType: typeCertificateRequest,
7790 test: testCase{
7791 protocol: protocol,
7792 name: "CertificateRequest" + suffix,
7793 config: Config{
7794 MaxVersion: VersionTLS12,
7795 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007796 },
7797 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007798 })
7799
David Benjamincd2c8062016-09-09 11:28:16 -04007800 ret = append(ret, perMessageTest{
7801 messageType: typeServerHelloDone,
7802 test: testCase{
7803 protocol: protocol,
7804 name: "ServerHelloDone" + suffix,
7805 config: Config{
7806 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007807 },
7808 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007809 })
7810
David Benjamincd2c8062016-09-09 11:28:16 -04007811 ret = append(ret, perMessageTest{
7812 messageType: typeCertificate,
7813 test: testCase{
7814 testType: serverTest,
7815 protocol: protocol,
7816 name: "ClientCertificate" + suffix,
7817 config: Config{
7818 Certificates: []Certificate{rsaCertificate},
7819 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007820 },
David Benjamincd2c8062016-09-09 11:28:16 -04007821 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007822 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007823 })
7824
David Benjamincd2c8062016-09-09 11:28:16 -04007825 ret = append(ret, perMessageTest{
7826 messageType: typeCertificateVerify,
7827 test: testCase{
7828 testType: serverTest,
7829 protocol: protocol,
7830 name: "CertificateVerify" + suffix,
7831 config: Config{
7832 Certificates: []Certificate{rsaCertificate},
7833 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007834 },
David Benjamincd2c8062016-09-09 11:28:16 -04007835 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007836 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007837 })
7838
David Benjamincd2c8062016-09-09 11:28:16 -04007839 ret = append(ret, perMessageTest{
7840 messageType: typeClientKeyExchange,
7841 test: testCase{
7842 testType: serverTest,
7843 protocol: protocol,
7844 name: "ClientKeyExchange" + suffix,
7845 config: Config{
7846 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007847 },
7848 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007849 })
7850
7851 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007852 ret = append(ret, perMessageTest{
7853 messageType: typeNextProtocol,
7854 test: testCase{
7855 testType: serverTest,
7856 protocol: protocol,
7857 name: "NextProtocol" + suffix,
7858 config: Config{
7859 MaxVersion: VersionTLS12,
7860 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007861 },
David Benjamincd2c8062016-09-09 11:28:16 -04007862 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007863 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007864 })
7865
David Benjamincd2c8062016-09-09 11:28:16 -04007866 ret = append(ret, perMessageTest{
7867 messageType: typeChannelID,
7868 test: testCase{
7869 testType: serverTest,
7870 protocol: protocol,
7871 name: "ChannelID" + suffix,
7872 config: Config{
7873 MaxVersion: VersionTLS12,
7874 ChannelID: channelIDKey,
7875 },
7876 flags: []string{
7877 "-expect-channel-id",
7878 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007879 },
7880 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007881 })
7882 }
7883
David Benjamincd2c8062016-09-09 11:28:16 -04007884 ret = append(ret, perMessageTest{
7885 messageType: typeFinished,
7886 test: testCase{
7887 testType: serverTest,
7888 protocol: protocol,
7889 name: "ClientFinished" + suffix,
7890 config: Config{
7891 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007892 },
7893 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007894 })
7895
David Benjamincd2c8062016-09-09 11:28:16 -04007896 ret = append(ret, perMessageTest{
7897 messageType: typeNewSessionTicket,
7898 test: testCase{
7899 protocol: protocol,
7900 name: "NewSessionTicket" + suffix,
7901 config: Config{
7902 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007903 },
7904 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007905 })
7906
David Benjamincd2c8062016-09-09 11:28:16 -04007907 ret = append(ret, perMessageTest{
7908 messageType: typeFinished,
7909 test: testCase{
7910 protocol: protocol,
7911 name: "ServerFinished" + suffix,
7912 config: Config{
7913 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007914 },
7915 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007916 })
7917
7918 }
David Benjamincd2c8062016-09-09 11:28:16 -04007919
7920 ret = append(ret, perMessageTest{
7921 messageType: typeClientHello,
7922 test: testCase{
7923 testType: serverTest,
7924 name: "TLS13-ClientHello",
7925 config: Config{
7926 MaxVersion: VersionTLS13,
7927 },
7928 },
7929 })
7930
7931 ret = append(ret, perMessageTest{
7932 messageType: typeServerHello,
7933 test: testCase{
7934 name: "TLS13-ServerHello",
7935 config: Config{
7936 MaxVersion: VersionTLS13,
7937 },
7938 },
7939 })
7940
7941 ret = append(ret, perMessageTest{
7942 messageType: typeEncryptedExtensions,
7943 test: testCase{
7944 name: "TLS13-EncryptedExtensions",
7945 config: Config{
7946 MaxVersion: VersionTLS13,
7947 },
7948 },
7949 })
7950
7951 ret = append(ret, perMessageTest{
7952 messageType: typeCertificateRequest,
7953 test: testCase{
7954 name: "TLS13-CertificateRequest",
7955 config: Config{
7956 MaxVersion: VersionTLS13,
7957 ClientAuth: RequireAnyClientCert,
7958 },
7959 },
7960 })
7961
7962 ret = append(ret, perMessageTest{
7963 messageType: typeCertificate,
7964 test: testCase{
7965 name: "TLS13-ServerCertificate",
7966 config: Config{
7967 MaxVersion: VersionTLS13,
7968 },
7969 },
7970 })
7971
7972 ret = append(ret, perMessageTest{
7973 messageType: typeCertificateVerify,
7974 test: testCase{
7975 name: "TLS13-ServerCertificateVerify",
7976 config: Config{
7977 MaxVersion: VersionTLS13,
7978 },
7979 },
7980 })
7981
7982 ret = append(ret, perMessageTest{
7983 messageType: typeFinished,
7984 test: testCase{
7985 name: "TLS13-ServerFinished",
7986 config: Config{
7987 MaxVersion: VersionTLS13,
7988 },
7989 },
7990 })
7991
7992 ret = append(ret, perMessageTest{
7993 messageType: typeCertificate,
7994 test: testCase{
7995 testType: serverTest,
7996 name: "TLS13-ClientCertificate",
7997 config: Config{
7998 Certificates: []Certificate{rsaCertificate},
7999 MaxVersion: VersionTLS13,
8000 },
8001 flags: []string{"-require-any-client-certificate"},
8002 },
8003 })
8004
8005 ret = append(ret, perMessageTest{
8006 messageType: typeCertificateVerify,
8007 test: testCase{
8008 testType: serverTest,
8009 name: "TLS13-ClientCertificateVerify",
8010 config: Config{
8011 Certificates: []Certificate{rsaCertificate},
8012 MaxVersion: VersionTLS13,
8013 },
8014 flags: []string{"-require-any-client-certificate"},
8015 },
8016 })
8017
8018 ret = append(ret, perMessageTest{
8019 messageType: typeFinished,
8020 test: testCase{
8021 testType: serverTest,
8022 name: "TLS13-ClientFinished",
8023 config: Config{
8024 MaxVersion: VersionTLS13,
8025 },
8026 },
8027 })
8028
8029 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008030}
8031
David Benjamincd2c8062016-09-09 11:28:16 -04008032func addWrongMessageTypeTests() {
8033 for _, t := range makePerMessageTests() {
8034 t.test.name = "WrongMessageType-" + t.test.name
8035 t.test.config.Bugs.SendWrongMessageType = t.messageType
8036 t.test.shouldFail = true
8037 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8038 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008039
David Benjamincd2c8062016-09-09 11:28:16 -04008040 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8041 // In TLS 1.3, a bad ServerHello means the client sends
8042 // an unencrypted alert while the server expects
8043 // encryption, so the alert is not readable by runner.
8044 t.test.expectedLocalError = "local error: bad record MAC"
8045 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008046
David Benjamincd2c8062016-09-09 11:28:16 -04008047 testCases = append(testCases, t.test)
8048 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008049}
8050
David Benjamin639846e2016-09-09 11:41:18 -04008051func addTrailingMessageDataTests() {
8052 for _, t := range makePerMessageTests() {
8053 t.test.name = "TrailingMessageData-" + t.test.name
8054 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8055 t.test.shouldFail = true
8056 t.test.expectedError = ":DECODE_ERROR:"
8057 t.test.expectedLocalError = "remote error: error decoding message"
8058
8059 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8060 // In TLS 1.3, a bad ServerHello means the client sends
8061 // an unencrypted alert while the server expects
8062 // encryption, so the alert is not readable by runner.
8063 t.test.expectedLocalError = "local error: bad record MAC"
8064 }
8065
8066 if t.messageType == typeFinished {
8067 // Bad Finished messages read as the verify data having
8068 // the wrong length.
8069 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8070 t.test.expectedLocalError = "remote error: error decrypting message"
8071 }
8072
8073 testCases = append(testCases, t.test)
8074 }
8075}
8076
Steven Valdez143e8b32016-07-11 13:19:03 -04008077func addTLS13HandshakeTests() {
8078 testCases = append(testCases, testCase{
8079 testType: clientTest,
8080 name: "MissingKeyShare-Client",
8081 config: Config{
8082 MaxVersion: VersionTLS13,
8083 Bugs: ProtocolBugs{
8084 MissingKeyShare: true,
8085 },
8086 },
8087 shouldFail: true,
8088 expectedError: ":MISSING_KEY_SHARE:",
8089 })
8090
8091 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008092 testType: serverTest,
8093 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008094 config: Config{
8095 MaxVersion: VersionTLS13,
8096 Bugs: ProtocolBugs{
8097 MissingKeyShare: true,
8098 },
8099 },
8100 shouldFail: true,
8101 expectedError: ":MISSING_KEY_SHARE:",
8102 })
8103
8104 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008105 testType: serverTest,
8106 name: "DuplicateKeyShares",
8107 config: Config{
8108 MaxVersion: VersionTLS13,
8109 Bugs: ProtocolBugs{
8110 DuplicateKeyShares: true,
8111 },
8112 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008113 shouldFail: true,
8114 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008115 })
8116
8117 testCases = append(testCases, testCase{
8118 testType: clientTest,
8119 name: "EmptyEncryptedExtensions",
8120 config: Config{
8121 MaxVersion: VersionTLS13,
8122 Bugs: ProtocolBugs{
8123 EmptyEncryptedExtensions: true,
8124 },
8125 },
8126 shouldFail: true,
8127 expectedLocalError: "remote error: error decoding message",
8128 })
8129
8130 testCases = append(testCases, testCase{
8131 testType: clientTest,
8132 name: "EncryptedExtensionsWithKeyShare",
8133 config: Config{
8134 MaxVersion: VersionTLS13,
8135 Bugs: ProtocolBugs{
8136 EncryptedExtensionsWithKeyShare: true,
8137 },
8138 },
8139 shouldFail: true,
8140 expectedLocalError: "remote error: unsupported extension",
8141 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008142
8143 testCases = append(testCases, testCase{
8144 testType: serverTest,
8145 name: "SendHelloRetryRequest",
8146 config: Config{
8147 MaxVersion: VersionTLS13,
8148 // Require a HelloRetryRequest for every curve.
8149 DefaultCurves: []CurveID{},
8150 },
8151 expectedCurveID: CurveX25519,
8152 })
8153
8154 testCases = append(testCases, testCase{
8155 testType: serverTest,
8156 name: "SendHelloRetryRequest-2",
8157 config: Config{
8158 MaxVersion: VersionTLS13,
8159 DefaultCurves: []CurveID{CurveP384},
8160 },
8161 // Although the ClientHello did not predict our preferred curve,
8162 // we always select it whether it is predicted or not.
8163 expectedCurveID: CurveX25519,
8164 })
8165
8166 testCases = append(testCases, testCase{
8167 name: "UnknownCurve-HelloRetryRequest",
8168 config: Config{
8169 MaxVersion: VersionTLS13,
8170 // P-384 requires HelloRetryRequest in BoringSSL.
8171 CurvePreferences: []CurveID{CurveP384},
8172 Bugs: ProtocolBugs{
8173 SendHelloRetryRequestCurve: bogusCurve,
8174 },
8175 },
8176 shouldFail: true,
8177 expectedError: ":WRONG_CURVE:",
8178 })
8179
8180 testCases = append(testCases, testCase{
8181 name: "DisabledCurve-HelloRetryRequest",
8182 config: Config{
8183 MaxVersion: VersionTLS13,
8184 CurvePreferences: []CurveID{CurveP256},
8185 Bugs: ProtocolBugs{
8186 IgnorePeerCurvePreferences: true,
8187 },
8188 },
8189 flags: []string{"-p384-only"},
8190 shouldFail: true,
8191 expectedError: ":WRONG_CURVE:",
8192 })
8193
8194 testCases = append(testCases, testCase{
8195 name: "UnnecessaryHelloRetryRequest",
8196 config: Config{
8197 MaxVersion: VersionTLS13,
8198 Bugs: ProtocolBugs{
8199 UnnecessaryHelloRetryRequest: true,
8200 },
8201 },
8202 shouldFail: true,
8203 expectedError: ":WRONG_CURVE:",
8204 })
8205
8206 testCases = append(testCases, testCase{
8207 name: "SecondHelloRetryRequest",
8208 config: Config{
8209 MaxVersion: VersionTLS13,
8210 // P-384 requires HelloRetryRequest in BoringSSL.
8211 CurvePreferences: []CurveID{CurveP384},
8212 Bugs: ProtocolBugs{
8213 SecondHelloRetryRequest: true,
8214 },
8215 },
8216 shouldFail: true,
8217 expectedError: ":UNEXPECTED_MESSAGE:",
8218 })
8219
8220 testCases = append(testCases, testCase{
8221 testType: serverTest,
8222 name: "SecondClientHelloMissingKeyShare",
8223 config: Config{
8224 MaxVersion: VersionTLS13,
8225 DefaultCurves: []CurveID{},
8226 Bugs: ProtocolBugs{
8227 SecondClientHelloMissingKeyShare: true,
8228 },
8229 },
8230 shouldFail: true,
8231 expectedError: ":MISSING_KEY_SHARE:",
8232 })
8233
8234 testCases = append(testCases, testCase{
8235 testType: serverTest,
8236 name: "SecondClientHelloWrongCurve",
8237 config: Config{
8238 MaxVersion: VersionTLS13,
8239 DefaultCurves: []CurveID{},
8240 Bugs: ProtocolBugs{
8241 MisinterpretHelloRetryRequestCurve: CurveP521,
8242 },
8243 },
8244 shouldFail: true,
8245 expectedError: ":WRONG_CURVE:",
8246 })
8247
8248 testCases = append(testCases, testCase{
8249 name: "HelloRetryRequestVersionMismatch",
8250 config: Config{
8251 MaxVersion: VersionTLS13,
8252 // P-384 requires HelloRetryRequest in BoringSSL.
8253 CurvePreferences: []CurveID{CurveP384},
8254 Bugs: ProtocolBugs{
8255 SendServerHelloVersion: 0x0305,
8256 },
8257 },
8258 shouldFail: true,
8259 expectedError: ":WRONG_VERSION_NUMBER:",
8260 })
8261
8262 testCases = append(testCases, testCase{
8263 name: "HelloRetryRequestCurveMismatch",
8264 config: Config{
8265 MaxVersion: VersionTLS13,
8266 // P-384 requires HelloRetryRequest in BoringSSL.
8267 CurvePreferences: []CurveID{CurveP384},
8268 Bugs: ProtocolBugs{
8269 // Send P-384 (correct) in the HelloRetryRequest.
8270 SendHelloRetryRequestCurve: CurveP384,
8271 // But send P-256 in the ServerHello.
8272 SendCurve: CurveP256,
8273 },
8274 },
8275 shouldFail: true,
8276 expectedError: ":WRONG_CURVE:",
8277 })
8278
8279 // Test the server selecting a curve that requires a HelloRetryRequest
8280 // without sending it.
8281 testCases = append(testCases, testCase{
8282 name: "SkipHelloRetryRequest",
8283 config: Config{
8284 MaxVersion: VersionTLS13,
8285 // P-384 requires HelloRetryRequest in BoringSSL.
8286 CurvePreferences: []CurveID{CurveP384},
8287 Bugs: ProtocolBugs{
8288 SkipHelloRetryRequest: true,
8289 },
8290 },
8291 shouldFail: true,
8292 expectedError: ":WRONG_CURVE:",
8293 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008294
8295 testCases = append(testCases, testCase{
8296 name: "TLS13-RequestContextInHandshake",
8297 config: Config{
8298 MaxVersion: VersionTLS13,
8299 MinVersion: VersionTLS13,
8300 ClientAuth: RequireAnyClientCert,
8301 Bugs: ProtocolBugs{
8302 SendRequestContext: []byte("request context"),
8303 },
8304 },
8305 flags: []string{
8306 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8307 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8308 },
8309 shouldFail: true,
8310 expectedError: ":DECODE_ERROR:",
8311 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008312
8313 testCases = append(testCases, testCase{
8314 testType: serverTest,
8315 name: "TLS13-TrailingKeyShareData",
8316 config: Config{
8317 MaxVersion: VersionTLS13,
8318 Bugs: ProtocolBugs{
8319 TrailingKeyShareData: true,
8320 },
8321 },
8322 shouldFail: true,
8323 expectedError: ":DECODE_ERROR:",
8324 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008325}
8326
David Benjaminf3fbade2016-09-19 13:08:16 -04008327func addPeekTests() {
8328 // Test SSL_peek works, including on empty records.
8329 testCases = append(testCases, testCase{
8330 name: "Peek-Basic",
8331 sendEmptyRecords: 1,
8332 flags: []string{"-peek-then-read"},
8333 })
8334
8335 // Test SSL_peek can drive the initial handshake.
8336 testCases = append(testCases, testCase{
8337 name: "Peek-ImplicitHandshake",
8338 flags: []string{
8339 "-peek-then-read",
8340 "-implicit-handshake",
8341 },
8342 })
8343
8344 // Test SSL_peek can discover and drive a renegotiation.
8345 testCases = append(testCases, testCase{
8346 name: "Peek-Renegotiate",
8347 config: Config{
8348 MaxVersion: VersionTLS12,
8349 },
8350 renegotiate: 1,
8351 flags: []string{
8352 "-peek-then-read",
8353 "-renegotiate-freely",
8354 "-expect-total-renegotiations", "1",
8355 },
8356 })
8357
8358 // Test SSL_peek can discover a close_notify.
8359 testCases = append(testCases, testCase{
8360 name: "Peek-Shutdown",
8361 config: Config{
8362 Bugs: ProtocolBugs{
8363 ExpectCloseNotify: true,
8364 },
8365 },
8366 flags: []string{
8367 "-peek-then-read",
8368 "-check-close-notify",
8369 },
8370 })
8371
8372 // Test SSL_peek can discover an alert.
8373 testCases = append(testCases, testCase{
8374 name: "Peek-Alert",
8375 config: Config{
8376 Bugs: ProtocolBugs{
8377 SendSpuriousAlert: alertRecordOverflow,
8378 },
8379 },
8380 flags: []string{"-peek-then-read"},
8381 shouldFail: true,
8382 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8383 })
8384
8385 // Test SSL_peek can handle KeyUpdate.
8386 testCases = append(testCases, testCase{
8387 name: "Peek-KeyUpdate",
8388 config: Config{
8389 MaxVersion: VersionTLS13,
8390 Bugs: ProtocolBugs{
8391 SendKeyUpdateBeforeEveryAppDataRecord: true,
8392 },
8393 },
8394 flags: []string{"-peek-then-read"},
8395 })
8396}
8397
Adam Langley7c803a62015-06-15 15:35:05 -07008398func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008399 defer wg.Done()
8400
8401 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008402 var err error
8403
8404 if *mallocTest < 0 {
8405 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008406 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008407 } else {
8408 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8409 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008410 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008411 if err != nil {
8412 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8413 }
8414 break
8415 }
8416 }
8417 }
Adam Langley95c29f32014-06-20 12:00:00 -07008418 statusChan <- statusMsg{test: test, err: err}
8419 }
8420}
8421
8422type statusMsg struct {
8423 test *testCase
8424 started bool
8425 err error
8426}
8427
David Benjamin5f237bc2015-02-11 17:14:15 -05008428func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008429 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008430
David Benjamin5f237bc2015-02-11 17:14:15 -05008431 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008432 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008433 if !*pipe {
8434 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008435 var erase string
8436 for i := 0; i < lineLen; i++ {
8437 erase += "\b \b"
8438 }
8439 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008440 }
8441
Adam Langley95c29f32014-06-20 12:00:00 -07008442 if msg.started {
8443 started++
8444 } else {
8445 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008446
8447 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008448 if msg.err == errUnimplemented {
8449 if *pipe {
8450 // Print each test instead of a status line.
8451 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8452 }
8453 unimplemented++
8454 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8455 } else {
8456 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8457 failed++
8458 testOutput.addResult(msg.test.name, "FAIL")
8459 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008460 } else {
8461 if *pipe {
8462 // Print each test instead of a status line.
8463 fmt.Printf("PASSED (%s)\n", msg.test.name)
8464 }
8465 testOutput.addResult(msg.test.name, "PASS")
8466 }
Adam Langley95c29f32014-06-20 12:00:00 -07008467 }
8468
David Benjamin5f237bc2015-02-11 17:14:15 -05008469 if !*pipe {
8470 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008471 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008472 lineLen = len(line)
8473 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008474 }
Adam Langley95c29f32014-06-20 12:00:00 -07008475 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008476
8477 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008478}
8479
8480func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008481 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008482 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008483 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008484
Adam Langley7c803a62015-06-15 15:35:05 -07008485 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008486 addCipherSuiteTests()
8487 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008488 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008489 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008490 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008491 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008492 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008493 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008494 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008495 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008496 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008497 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008498 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008499 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008500 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008501 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008502 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008503 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008504 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008505 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008506 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008507 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008508 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008509 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008510 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008511 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008512 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008513 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008514 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008515
8516 var wg sync.WaitGroup
8517
Adam Langley7c803a62015-06-15 15:35:05 -07008518 statusChan := make(chan statusMsg, *numWorkers)
8519 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008520 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008521
EKRf71d7ed2016-08-06 13:25:12 -07008522 if len(*shimConfigFile) != 0 {
8523 encoded, err := ioutil.ReadFile(*shimConfigFile)
8524 if err != nil {
8525 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8526 os.Exit(1)
8527 }
8528
8529 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8530 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8531 os.Exit(1)
8532 }
8533 }
8534
David Benjamin025b3d32014-07-01 19:53:04 -04008535 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008536
Adam Langley7c803a62015-06-15 15:35:05 -07008537 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008538 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008539 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008540 }
8541
David Benjamin270f0a72016-03-17 14:41:36 -04008542 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008543 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008544 matched := true
8545 if len(*testToRun) != 0 {
8546 var err error
8547 matched, err = filepath.Match(*testToRun, testCases[i].name)
8548 if err != nil {
8549 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8550 os.Exit(1)
8551 }
8552 }
8553
EKRf71d7ed2016-08-06 13:25:12 -07008554 if !*includeDisabled {
8555 for pattern := range shimConfig.DisabledTests {
8556 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8557 if err != nil {
8558 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8559 os.Exit(1)
8560 }
8561
8562 if isDisabled {
8563 matched = false
8564 break
8565 }
8566 }
8567 }
8568
David Benjamin17e12922016-07-28 18:04:43 -04008569 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008570 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008571 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008572 }
8573 }
David Benjamin17e12922016-07-28 18:04:43 -04008574
David Benjamin270f0a72016-03-17 14:41:36 -04008575 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008576 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008577 os.Exit(1)
8578 }
Adam Langley95c29f32014-06-20 12:00:00 -07008579
8580 close(testChan)
8581 wg.Wait()
8582 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008583 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008584
8585 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008586
8587 if *jsonOutput != "" {
8588 if err := testOutput.writeTo(*jsonOutput); err != nil {
8589 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8590 }
8591 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008592
EKR842ae6c2016-07-27 09:22:05 +02008593 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8594 os.Exit(1)
8595 }
8596
8597 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008598 os.Exit(1)
8599 }
Adam Langley95c29f32014-06-20 12:00:00 -07008600}