blob: 7ae441c62e3b676f824e66bf7823129c1de55870 [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"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 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.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin3969fdf2017-08-29 15:50:58 -0400141 garbageCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400142)
David Benjamin33863262016-07-08 17:20:12 -0700143
144var testCerts = []struct {
145 id testCert
146 certFile, keyFile string
147 cert *Certificate
148}{
149 {
150 id: testCertRSA,
151 certFile: rsaCertificateFile,
152 keyFile: rsaKeyFile,
153 cert: &rsaCertificate,
154 },
155 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400156 id: testCertRSA1024,
157 certFile: rsa1024CertificateFile,
158 keyFile: rsa1024KeyFile,
159 cert: &rsa1024Certificate,
160 },
161 {
David Benjamin2c516452016-11-15 10:16:54 +0900162 id: testCertRSAChain,
163 certFile: rsaChainCertificateFile,
164 keyFile: rsaChainKeyFile,
165 cert: &rsaChainCertificate,
166 },
167 {
Adam Langley898be922017-02-27 12:37:59 -0800168 id: testCertECDSAP224,
169 certFile: ecdsaP224CertificateFile,
170 keyFile: ecdsaP224KeyFile,
171 cert: &ecdsaP224Certificate,
172 },
173 {
David Benjamin33863262016-07-08 17:20:12 -0700174 id: testCertECDSAP256,
175 certFile: ecdsaP256CertificateFile,
176 keyFile: ecdsaP256KeyFile,
177 cert: &ecdsaP256Certificate,
178 },
179 {
180 id: testCertECDSAP384,
181 certFile: ecdsaP384CertificateFile,
182 keyFile: ecdsaP384KeyFile,
183 cert: &ecdsaP384Certificate,
184 },
185 {
186 id: testCertECDSAP521,
187 certFile: ecdsaP521CertificateFile,
188 keyFile: ecdsaP521KeyFile,
189 cert: &ecdsaP521Certificate,
190 },
David Benjamin69522112017-03-28 15:38:29 -0500191 {
192 id: testCertEd25519,
193 certFile: ed25519CertificateFile,
194 keyFile: ed25519KeyFile,
195 cert: &ed25519Certificate,
196 },
David Benjamin33863262016-07-08 17:20:12 -0700197}
198
David Benjamina08e49d2014-08-24 01:46:07 -0400199var channelIDKey *ecdsa.PrivateKey
200var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700201
David Benjamin61f95272014-11-25 01:55:35 -0500202var testOCSPResponse = []byte{1, 2, 3, 4}
David Benjamin5c4271f2017-08-23 22:09:41 -0700203var testOCSPResponse2 = []byte{5, 6, 7, 8}
Adam Langleycfa08c32016-11-17 13:21:27 -0800204var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin5c4271f2017-08-23 22:09:41 -0700205var testSCTList2 = []byte{0, 6, 0, 4, 1, 2, 3, 4}
David Benjamin61f95272014-11-25 01:55:35 -0500206
Steven Valdeza833c352016-11-01 13:39:36 -0400207var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800208var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400209
Adam Langley95c29f32014-06-20 12:00:00 -0700210func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700211 for i := range testCerts {
212 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
213 if err != nil {
214 panic(err)
215 }
216 cert.OCSPStaple = testOCSPResponse
217 cert.SignedCertificateTimestampList = testSCTList
218 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700219 }
David Benjamina08e49d2014-08-24 01:46:07 -0400220
Adam Langley7c803a62015-06-15 15:35:05 -0700221 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400222 if err != nil {
223 panic(err)
224 }
225 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
226 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
227 panic("bad key type")
228 }
229 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
230 if err != nil {
231 panic(err)
232 }
233 if channelIDKey.Curve != elliptic.P256() {
234 panic("bad curve")
235 }
236
237 channelIDBytes = make([]byte, 64)
238 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
239 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
David Benjamin3969fdf2017-08-29 15:50:58 -0400240
241 garbageCertificate.Certificate = [][]byte{[]byte("GARBAGE")}
242 garbageCertificate.PrivateKey = rsaCertificate.PrivateKey
Adam Langley95c29f32014-06-20 12:00:00 -0700243}
244
David Benjamin33863262016-07-08 17:20:12 -0700245func getRunnerCertificate(t testCert) Certificate {
246 for _, cert := range testCerts {
247 if cert.id == t {
248 return *cert.cert
249 }
250 }
251 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700252}
253
David Benjamin33863262016-07-08 17:20:12 -0700254func getShimCertificate(t testCert) string {
255 for _, cert := range testCerts {
256 if cert.id == t {
257 return cert.certFile
258 }
259 }
260 panic("Unknown test certificate")
261}
262
263func getShimKey(t testCert) string {
264 for _, cert := range testCerts {
265 if cert.id == t {
266 return cert.keyFile
267 }
268 }
269 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700270}
271
Steven Valdez520e1222017-06-13 12:45:25 -0400272// recordVersionToWire maps a record-layer protocol version to its wire
273// representation.
274func recordVersionToWire(vers uint16, protocol protocol) uint16 {
Steven Valdezc94998a2017-06-20 10:55:02 -0400275 if protocol == dtls {
276 switch vers {
277 case VersionTLS12:
278 return VersionDTLS12
279 case VersionTLS10:
280 return VersionDTLS10
281 }
282 } else {
283 switch vers {
284 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
285 return vers
Steven Valdezc94998a2017-06-20 10:55:02 -0400286 }
287 }
288
289 panic("unknown version")
290}
291
Adam Langley2ff79332017-02-28 13:45:39 -0800292// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
293func encodeDERValues(values [][]byte) string {
294 var ret string
295 for i, v := range values {
296 if i > 0 {
297 ret += ","
298 }
299 ret += hex.EncodeToString(v)
300 }
301
302 return ret
303}
304
David Benjamin025b3d32014-07-01 19:53:04 -0400305type testType int
306
307const (
308 clientTest testType = iota
309 serverTest
310)
311
David Benjamin6fd297b2014-08-11 18:43:38 -0400312type protocol int
313
314const (
315 tls protocol = iota
316 dtls
317)
318
David Benjaminfc7b0862014-09-06 13:21:53 -0400319const (
320 alpn = 1
321 npn = 2
322)
323
Adam Langley95c29f32014-06-20 12:00:00 -0700324type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400325 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400326 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700327 name string
328 config Config
329 shouldFail bool
330 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700331 // expectedLocalError, if not empty, contains a substring that must be
332 // found in the local error.
333 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400334 // expectedVersion, if non-zero, specifies the TLS version that must be
335 // negotiated.
336 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400337 // expectedResumeVersion, if non-zero, specifies the TLS version that
338 // must be negotiated on resumption. If zero, expectedVersion is used.
339 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400340 // expectedCipher, if non-zero, specifies the TLS cipher suite that
341 // should be negotiated.
342 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400343 // expectChannelID controls whether the connection should have
344 // negotiated a Channel ID with channelIDKey.
345 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400346 // expectedNextProto controls whether the connection should
347 // negotiate a next protocol via NPN or ALPN.
348 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400349 // expectNoNextProto, if true, means that no next protocol should be
350 // negotiated.
351 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400352 // expectedNextProtoType, if non-zero, is the expected next
353 // protocol negotiation mechanism.
354 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500355 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
356 // should be negotiated. If zero, none should be negotiated.
357 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100358 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
359 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100360 // expectedSCTList, if not nil, is the expected SCT list to be received.
361 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700362 // expectedPeerSignatureAlgorithm, if not zero, is the signature
363 // algorithm that the peer should have used in the handshake.
364 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400365 // expectedCurveID, if not zero, is the curve that the handshake should
366 // have used.
367 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700368 // messageLen is the length, in bytes, of the test message that will be
369 // sent.
370 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400371 // messageCount is the number of test messages that will be sent.
372 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400373 // certFile is the path to the certificate to use for the server.
374 certFile string
375 // keyFile is the path to the private key to use for the server.
376 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400377 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400378 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400379 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400380 // resumeRenewedSession controls whether a third connection should be
381 // tested which attempts to resume the second connection's session.
382 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700383 // expectResumeRejected, if true, specifies that the attempted
384 // resumption must be rejected by the client. This is only valid for a
385 // serverTest.
386 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400387 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500388 // resumption. Unless newSessionsOnResume is set,
389 // SessionTicketKey, ServerSessionCache, and
390 // ClientSessionCache are copied from the initial connection's
391 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400392 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500393 // newSessionsOnResume, if true, will cause resumeConfig to
394 // use a different session resumption context.
395 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400396 // noSessionCache, if true, will cause the server to run without a
397 // session cache.
398 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400399 // sendPrefix sends a prefix on the socket before actually performing a
400 // handshake.
401 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400402 // shimWritesFirst controls whether the shim sends an initial "hello"
403 // message before doing a roundtrip with the runner.
404 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400405 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
406 // does not complete the write until responding to the first runner
407 // message.
408 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400409 // shimShutsDown, if true, runs a test where the shim shuts down the
410 // connection immediately after the handshake rather than echoing
411 // messages from the runner.
412 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400413 // renegotiate indicates the number of times the connection should be
414 // renegotiated during the exchange.
415 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400416 // sendHalfHelloRequest, if true, causes the server to send half a
417 // HelloRequest when the handshake completes.
418 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700419 // renegotiateCiphers is a list of ciphersuite ids that will be
420 // switched in just before renegotiation.
421 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500422 // replayWrites, if true, configures the underlying transport
423 // to replay every write it makes in DTLS tests.
424 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500425 // damageFirstWrite, if true, configures the underlying transport to
426 // damage the final byte of the first application data write.
427 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400428 // exportKeyingMaterial, if non-zero, configures the test to exchange
429 // keying material and verify they match.
430 exportKeyingMaterial int
431 exportLabel string
432 exportContext string
433 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400434 // flags, if not empty, contains a list of command-line flags that will
435 // be passed to the shim program.
436 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700437 // testTLSUnique, if true, causes the shim to send the tls-unique value
438 // which will be compared against the expected value.
439 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400440 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400441 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400442 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400443 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400444 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400445 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400446 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
447 // be sent before each test message.
448 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400449 // sendKeyUpdates is the number of consecutive key updates to send
450 // before and after the test message.
451 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400452 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
453 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400454 // expectMessageDropped, if true, means the test message is expected to
455 // be dropped by the client rather than echoed back.
456 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900457 // expectPeerCertificate, if not nil, is the certificate chain the peer
458 // is expected to send.
459 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500460 // shimPrefix is the prefix that the shim will send to the server.
461 shimPrefix string
462 // resumeShimPrefix is the prefix that the shim will send to the server on a
463 // resumption.
464 resumeShimPrefix string
David Benjamina5022392017-07-10 17:40:39 -0400465 // tls13Variant, if non-zero, causes both runner and shim to be
466 // configured with the specified TLS 1.3 variant. This is a convenience
467 // option for configuring both concurrently.
468 tls13Variant int
Adam Langley95c29f32014-06-20 12:00:00 -0700469}
470
Adam Langley7c803a62015-06-15 15:35:05 -0700471var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700472
David Benjamin0fde2eb2017-06-30 19:11:22 -0400473func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500474 if len(data) == 0 {
475 return
476 }
477
David Benjamin0fde2eb2017-06-30 19:11:22 -0400478 settings, err := ioutil.ReadFile(path)
479 if err != nil {
480 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500481 return
482 }
483
David Benjamin0fde2eb2017-06-30 19:11:22 -0400484 settings = append(settings, data...)
485 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
486 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500487 }
488}
489
David Benjamin3ed59772016-03-08 12:50:21 -0500490// A timeoutConn implements an idle timeout on each Read and Write operation.
491type timeoutConn struct {
492 net.Conn
493 timeout time.Duration
494}
495
496func (t *timeoutConn) Read(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700497 if !*useGDB {
498 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
499 return 0, err
500 }
David Benjamin3ed59772016-03-08 12:50:21 -0500501 }
502 return t.Conn.Read(b)
503}
504
505func (t *timeoutConn) Write(b []byte) (int, error) {
Adam Langley182b5732017-07-28 11:00:23 -0700506 if !*useGDB {
507 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
508 return 0, err
509 }
David Benjamin3ed59772016-03-08 12:50:21 -0500510 }
511 return t.Conn.Write(b)
512}
513
David Benjamin0fde2eb2017-06-30 19:11:22 -0400514func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400515 if !test.noSessionCache {
516 if config.ClientSessionCache == nil {
517 config.ClientSessionCache = NewLRUClientSessionCache(1)
518 }
519 if config.ServerSessionCache == nil {
520 config.ServerSessionCache = NewLRUServerSessionCache(1)
521 }
522 }
523 if test.testType == clientTest {
524 if len(config.Certificates) == 0 {
525 config.Certificates = []Certificate{rsaCertificate}
526 }
527 } else {
528 // Supply a ServerName to ensure a constant session cache key,
529 // rather than falling back to net.Conn.RemoteAddr.
530 if len(config.ServerName) == 0 {
531 config.ServerName = "test"
532 }
533 }
534 if *fuzzer {
535 config.Bugs.NullAllCiphers = true
536 }
David Benjamin01a90572016-09-22 00:11:43 -0400537 if *deterministic {
538 config.Time = func() time.Time { return time.Unix(1234, 1234) }
539 }
Steven Valdez0e4a4482017-07-17 11:12:34 -0400540 if test.tls13Variant != 0 {
541 config.TLS13Variant = test.tls13Variant
542 }
David Benjamine54af062016-08-08 19:21:18 -0400543
David Benjamin01784b42016-06-07 18:00:52 -0400544 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500545
David Benjamin6fd297b2014-08-11 18:43:38 -0400546 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500547 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
548 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500549 }
550
David Benjamin9867b7d2016-03-01 23:25:48 -0500551 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500552 local, peer := "client", "server"
553 if test.testType == clientTest {
554 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500555 }
David Benjaminebda9b32015-11-02 15:33:18 -0500556 connDebug := &recordingConn{
557 Conn: conn,
558 isDatagram: test.protocol == dtls,
559 local: local,
560 peer: peer,
561 }
562 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500563 if *flagDebug {
564 defer connDebug.WriteTo(os.Stdout)
565 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400566 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500567 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400568 path := transcriptPrefix + strconv.Itoa(num)
569 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500570 }()
571 }
David Benjaminebda9b32015-11-02 15:33:18 -0500572
573 if config.Bugs.PacketAdaptor != nil {
574 config.Bugs.PacketAdaptor.debug = connDebug
575 }
576 }
577
578 if test.replayWrites {
579 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400580 }
581
David Benjamin3ed59772016-03-08 12:50:21 -0500582 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500583 if test.damageFirstWrite {
584 connDamage = newDamageAdaptor(conn)
585 conn = connDamage
586 }
587
David Benjamin6fd297b2014-08-11 18:43:38 -0400588 if test.sendPrefix != "" {
589 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
590 return err
591 }
David Benjamin98e882e2014-08-08 13:24:34 -0400592 }
593
David Benjamin1d5c83e2014-07-22 19:20:02 -0400594 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400595 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400596 if test.protocol == dtls {
597 tlsConn = DTLSServer(conn, config)
598 } else {
599 tlsConn = Server(conn, config)
600 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400601 } else {
602 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400603 if test.protocol == dtls {
604 tlsConn = DTLSClient(conn, config)
605 } else {
606 tlsConn = Client(conn, config)
607 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400608 }
David Benjamin30789da2015-08-29 22:56:45 -0400609 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400610
Adam Langley95c29f32014-06-20 12:00:00 -0700611 if err := tlsConn.Handshake(); err != nil {
612 return err
613 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700614
David Benjamin01fe8202014-09-24 15:21:44 -0400615 // TODO(davidben): move all per-connection expectations into a dedicated
616 // expectations struct that can be specified separately for the two
617 // legs.
618 expectedVersion := test.expectedVersion
619 if isResume && test.expectedResumeVersion != 0 {
620 expectedVersion = test.expectedResumeVersion
621 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700622 connState := tlsConn.ConnectionState()
623 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400624 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400625 }
626
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700627 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400628 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
629 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700630 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
631 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
632 }
David Benjamin90da8c82015-04-20 14:57:57 -0400633
David Benjamina08e49d2014-08-24 01:46:07 -0400634 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700635 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400636 if channelID == nil {
637 return fmt.Errorf("no channel ID negotiated")
638 }
639 if channelID.Curve != channelIDKey.Curve ||
640 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
641 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
642 return fmt.Errorf("incorrect channel ID")
643 }
David Benjamin634f4752017-07-01 11:08:41 -0400644 } else if connState.ChannelID != nil {
645 return fmt.Errorf("channel ID unexpectedly negotiated")
David Benjamina08e49d2014-08-24 01:46:07 -0400646 }
647
David Benjaminae2888f2014-09-06 12:58:58 -0400648 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700649 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400650 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
651 }
652 }
653
David Benjaminc7ce9772015-10-09 19:32:41 -0400654 if test.expectNoNextProto {
655 if actual := connState.NegotiatedProtocol; actual != "" {
656 return fmt.Errorf("got unexpected next proto %s", actual)
657 }
658 }
659
David Benjaminfc7b0862014-09-06 13:21:53 -0400660 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700661 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400662 return fmt.Errorf("next proto type mismatch")
663 }
664 }
665
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700666 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500667 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
668 }
669
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100670 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300671 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100672 }
673
Paul Lietar4fac72e2015-09-09 13:44:55 +0100674 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
675 return fmt.Errorf("SCT list mismatch")
676 }
677
Nick Harper60edffd2016-06-21 15:19:24 -0700678 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
679 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400680 }
681
Steven Valdez5440fe02016-07-18 12:40:30 -0400682 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
683 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
684 }
685
David Benjamin2c516452016-11-15 10:16:54 +0900686 if test.expectPeerCertificate != nil {
687 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
688 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
689 }
690 for i, cert := range connState.PeerCertificates {
691 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
692 return fmt.Errorf("peer certificate %d did not match", i+1)
693 }
694 }
695 }
696
David Benjaminc565ebb2015-04-03 04:06:36 -0400697 if test.exportKeyingMaterial > 0 {
698 actual := make([]byte, test.exportKeyingMaterial)
699 if _, err := io.ReadFull(tlsConn, actual); err != nil {
700 return err
701 }
702 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
703 if err != nil {
704 return err
705 }
706 if !bytes.Equal(actual, expected) {
707 return fmt.Errorf("keying material mismatch")
708 }
709 }
710
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700711 if test.testTLSUnique {
712 var peersValue [12]byte
713 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
714 return err
715 }
716 expected := tlsConn.ConnectionState().TLSUnique
717 if !bytes.Equal(peersValue[:], expected) {
718 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
719 }
720 }
721
David Benjamin47921102016-07-28 11:29:18 -0400722 if test.sendHalfHelloRequest {
723 tlsConn.SendHalfHelloRequest()
724 }
725
Steven Valdeze831a812017-03-09 14:56:07 -0500726 shimPrefix := test.shimPrefix
727 if isResume {
728 shimPrefix = test.resumeShimPrefix
729 }
730 if test.shimWritesFirst || test.readWithUnfinishedWrite {
731 shimPrefix = "hello"
732 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400733 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400734 // If readWithUnfinishedWrite is set, the shim prefix will be
735 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500736 if shimPrefix != "" && !test.readWithUnfinishedWrite {
737 var buf = make([]byte, len(shimPrefix))
738 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400739 if err != nil {
740 return err
741 }
Steven Valdeze831a812017-03-09 14:56:07 -0500742 if string(buf) != shimPrefix {
743 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400744 }
Steven Valdeze831a812017-03-09 14:56:07 -0500745 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400746 }
747
Adam Langleycf2d4f42014-10-28 19:06:14 -0700748 if test.renegotiateCiphers != nil {
749 config.CipherSuites = test.renegotiateCiphers
750 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400751 for i := 0; i < test.renegotiate; i++ {
752 if err := tlsConn.Renegotiate(); err != nil {
753 return err
754 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700755 }
756 } else if test.renegotiateCiphers != nil {
757 panic("renegotiateCiphers without renegotiate")
758 }
759
David Benjamin5fa3eba2015-01-22 16:35:40 -0500760 if test.damageFirstWrite {
761 connDamage.setDamage(true)
762 tlsConn.Write([]byte("DAMAGED WRITE"))
763 connDamage.setDamage(false)
764 }
765
David Benjamin8e6db492015-07-25 18:29:23 -0400766 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700767 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400768 if test.protocol == dtls {
769 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
770 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700771 // Read until EOF.
772 _, err := io.Copy(ioutil.Discard, tlsConn)
773 return err
774 }
David Benjamin4417d052015-04-05 04:17:25 -0400775 if messageLen == 0 {
776 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700777 }
Adam Langley95c29f32014-06-20 12:00:00 -0700778
David Benjamin8e6db492015-07-25 18:29:23 -0400779 messageCount := test.messageCount
780 if messageCount == 0 {
781 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400782 }
783
David Benjamin8e6db492015-07-25 18:29:23 -0400784 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400785 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400786 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400787 }
788
David Benjamin8e6db492015-07-25 18:29:23 -0400789 for i := 0; i < test.sendEmptyRecords; i++ {
790 tlsConn.Write(nil)
791 }
792
793 for i := 0; i < test.sendWarningAlerts; i++ {
794 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
795 }
796
David Benjamin24e58862017-06-14 18:45:29 -0400797 if test.sendBogusAlertType {
798 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
799 }
800
David Benjaminbbba9392017-04-06 12:54:12 -0400801 testMessage := make([]byte, messageLen)
802 for i := range testMessage {
803 testMessage[i] = 0x42 ^ byte(j)
804 }
805 tlsConn.Write(testMessage)
806
807 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500808 if shimPrefix != "" {
809 var buf = make([]byte, len(shimPrefix))
810 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400811 if err != nil {
812 return err
813 }
Steven Valdeze831a812017-03-09 14:56:07 -0500814 if string(buf) != shimPrefix {
815 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400816 }
Steven Valdeze831a812017-03-09 14:56:07 -0500817 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400818 }
819
David Benjamin4f75aaf2015-09-01 16:53:10 -0400820 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400821 // The shim will not respond.
822 continue
823 }
824
David Benjaminbbba9392017-04-06 12:54:12 -0400825 // Process the KeyUpdate ACK. However many KeyUpdates the runner
826 // sends, the shim should respond only once.
827 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
828 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
829 return err
830 }
831 }
832
David Benjamin8e6db492015-07-25 18:29:23 -0400833 buf := make([]byte, len(testMessage))
834 if test.protocol == dtls {
835 bufTmp := make([]byte, len(buf)+1)
836 n, err := tlsConn.Read(bufTmp)
837 if err != nil {
838 return err
839 }
840 if n != len(buf) {
841 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
842 }
843 copy(buf, bufTmp)
844 } else {
845 _, err := io.ReadFull(tlsConn, buf)
846 if err != nil {
847 return err
848 }
849 }
850
851 for i, v := range buf {
852 if v != testMessage[i]^0xff {
853 return fmt.Errorf("bad reply contents at byte %d", i)
854 }
Adam Langley95c29f32014-06-20 12:00:00 -0700855 }
856 }
857
858 return nil
859}
860
David Benjamin325b5c32014-07-01 19:40:31 -0400861func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400862 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700863 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400864 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700865 }
David Benjamin325b5c32014-07-01 19:40:31 -0400866 valgrindArgs = append(valgrindArgs, path)
867 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700868
David Benjamin325b5c32014-07-01 19:40:31 -0400869 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700870}
871
David Benjamin325b5c32014-07-01 19:40:31 -0400872func gdbOf(path string, args ...string) *exec.Cmd {
873 xtermArgs := []string{"-e", "gdb", "--args"}
874 xtermArgs = append(xtermArgs, path)
875 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700876
David Benjamin325b5c32014-07-01 19:40:31 -0400877 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700878}
879
David Benjamind16bf342015-12-18 00:53:12 -0500880func lldbOf(path string, args ...string) *exec.Cmd {
881 xtermArgs := []string{"-e", "lldb", "--"}
882 xtermArgs = append(xtermArgs, path)
883 xtermArgs = append(xtermArgs, args...)
884
885 return exec.Command("xterm", xtermArgs...)
886}
887
EKR842ae6c2016-07-27 09:22:05 +0200888var (
889 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
890 errUnimplemented = errors.New("child process does not implement needed flags")
891)
Adam Langley69a01602014-11-17 17:26:55 -0800892
David Benjamin87c8a642015-02-21 01:54:29 -0500893// accept accepts a connection from listener, unless waitChan signals a process
894// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400895func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500896 type connOrError struct {
David Benjaminc3864402017-07-14 16:48:36 -0400897 conn net.Conn
898 err error
899 startTime, endTime time.Time
David Benjamin87c8a642015-02-21 01:54:29 -0500900 }
901 connChan := make(chan connOrError, 1)
902 go func() {
David Benjaminc3864402017-07-14 16:48:36 -0400903 startTime := time.Now()
Adam Langley182b5732017-07-28 11:00:23 -0700904 if !*useGDB {
905 listener.SetDeadline(time.Now().Add(*idleTimeout))
906 }
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn, err := listener.Accept()
David Benjaminc3864402017-07-14 16:48:36 -0400908 endTime := time.Now()
909 connChan <- connOrError{conn, err, startTime, endTime}
David Benjamin87c8a642015-02-21 01:54:29 -0500910 close(connChan)
911 }()
912 select {
913 case result := <-connChan:
David Benjaminc3864402017-07-14 16:48:36 -0400914 if result.err != nil {
915 // TODO(davidben): Remove this logging when
916 // https://crbug.com/boringssl/199 is resolved.
917 fmt.Fprintf(os.Stderr, "acceptOrWait failed, startTime=%v, endTime=%v\n", result.startTime, result.endTime)
918 }
David Benjamin87c8a642015-02-21 01:54:29 -0500919 return result.conn, result.err
920 case childErr := <-waitChan:
921 waitChan <- childErr
922 return nil, fmt.Errorf("child exited early: %s", childErr)
923 }
924}
925
EKRf71d7ed2016-08-06 13:25:12 -0700926func translateExpectedError(errorStr string) string {
927 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
928 return translated
929 }
930
931 if *looseErrors {
932 return ""
933 }
934
935 return errorStr
936}
937
Adam Langley7c803a62015-06-15 15:35:05 -0700938func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400939 // Help debugging panics on the Go side.
940 defer func() {
941 if r := recover(); r != nil {
942 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
943 panic(r)
944 }
945 }()
946
Adam Langley38311732014-10-16 19:04:35 -0700947 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
948 panic("Error expected without shouldFail in " + test.name)
949 }
950
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700951 if test.expectResumeRejected && !test.resumeSession {
952 panic("expectResumeRejected without resumeSession in " + test.name)
953 }
954
Adam Langley33b1d4f2016-12-07 15:03:45 -0800955 for _, ver := range tlsVersions {
956 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
957 continue
958 }
959
David Benjamina5022392017-07-10 17:40:39 -0400960 if test.config.MaxVersion == 0 && test.config.MinVersion == 0 && test.expectedVersion == 0 {
961 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
Adam Langley33b1d4f2016-12-07 15:03:45 -0800962 }
963
David Benjamina5022392017-07-10 17:40:39 -0400964 if ver.tls13Variant != 0 {
965 var foundFlag bool
966 for _, flag := range test.flags {
967 if flag == "-tls13-variant" {
968 foundFlag = true
969 break
970 }
971 }
972 if !foundFlag && test.config.TLS13Variant != ver.tls13Variant && test.tls13Variant != ver.tls13Variant {
973 panic(fmt.Sprintf("The name of test %q suggests that uses an experimental TLS 1.3 variant, but neither the shim nor the runner configures it", test.name))
974 }
975 }
976
Adam Langley33b1d4f2016-12-07 15:03:45 -0800977 }
978
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700979 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
980 if err != nil {
981 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
982 }
David Benjamin87c8a642015-02-21 01:54:29 -0500983 if err != nil {
984 panic(err)
985 }
986 defer func() {
987 if listener != nil {
988 listener.Close()
989 }
990 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700991
David Benjamin87c8a642015-02-21 01:54:29 -0500992 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400993 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400994 flags = append(flags, "-server")
995
David Benjamin025b3d32014-07-01 19:53:04 -0400996 flags = append(flags, "-key-file")
997 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700998 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400999 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001000 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001001 }
1002
1003 flags = append(flags, "-cert-file")
1004 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -07001005 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001006 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001007 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -04001008 }
1009 }
David Benjamin5a593af2014-08-11 19:51:50 -04001010
David Benjamin6fd297b2014-08-11 18:43:38 -04001011 if test.protocol == dtls {
1012 flags = append(flags, "-dtls")
1013 }
1014
David Benjamin46662482016-08-17 00:51:00 -04001015 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -04001016 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -04001017 resumeCount++
1018 if test.resumeRenewedSession {
1019 resumeCount++
1020 }
1021 }
1022
1023 if resumeCount > 0 {
1024 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -04001025 }
1026
David Benjamine58c4f52014-08-24 03:47:07 -04001027 if test.shimWritesFirst {
1028 flags = append(flags, "-shim-writes-first")
1029 }
1030
David Benjaminbbba9392017-04-06 12:54:12 -04001031 if test.readWithUnfinishedWrite {
1032 flags = append(flags, "-read-with-unfinished-write")
1033 }
1034
David Benjamin30789da2015-08-29 22:56:45 -04001035 if test.shimShutsDown {
1036 flags = append(flags, "-shim-shuts-down")
1037 }
1038
David Benjaminc565ebb2015-04-03 04:06:36 -04001039 if test.exportKeyingMaterial > 0 {
1040 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1041 flags = append(flags, "-export-label", test.exportLabel)
1042 flags = append(flags, "-export-context", test.exportContext)
1043 if test.useExportContext {
1044 flags = append(flags, "-use-export-context")
1045 }
1046 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001047 if test.expectResumeRejected {
1048 flags = append(flags, "-expect-session-miss")
1049 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001050
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001051 if test.testTLSUnique {
1052 flags = append(flags, "-tls-unique")
1053 }
1054
David Benjamina5022392017-07-10 17:40:39 -04001055 if test.tls13Variant != 0 {
David Benjamina5022392017-07-10 17:40:39 -04001056 flags = append(flags, "-tls13-variant", strconv.Itoa(test.tls13Variant))
1057 }
1058
David Benjamin0fde2eb2017-06-30 19:11:22 -04001059 var transcriptPrefix string
1060 if len(*transcriptDir) != 0 {
1061 protocol := "tls"
1062 if test.protocol == dtls {
1063 protocol = "dtls"
1064 }
1065
1066 side := "client"
1067 if test.testType == serverTest {
1068 side = "server"
1069 }
1070
1071 dir := filepath.Join(*transcriptDir, protocol, side)
1072 if err := os.MkdirAll(dir, 0755); err != nil {
1073 return err
1074 }
1075 transcriptPrefix = filepath.Join(dir, test.name+"-")
1076 flags = append(flags, "-write-settings", transcriptPrefix)
1077 }
1078
David Benjamin025b3d32014-07-01 19:53:04 -04001079 flags = append(flags, test.flags...)
1080
1081 var shim *exec.Cmd
1082 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001083 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001084 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001085 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001086 } else if *useLLDB {
1087 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001088 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001089 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001090 }
David Benjamin025b3d32014-07-01 19:53:04 -04001091 shim.Stdin = os.Stdin
1092 var stdoutBuf, stderrBuf bytes.Buffer
1093 shim.Stdout = &stdoutBuf
1094 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001095 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001096 shim.Env = os.Environ()
1097 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001098 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001099 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001100 }
1101 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1102 }
David Benjamin025b3d32014-07-01 19:53:04 -04001103
1104 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001105 panic(err)
1106 }
David Benjamin87c8a642015-02-21 01:54:29 -05001107 waitChan := make(chan error, 1)
1108 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001109
1110 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001111
David Benjamin7a4aaa42016-09-20 17:58:14 -04001112 if *deterministic {
1113 config.Rand = &deterministicRand{}
1114 }
1115
David Benjamin87c8a642015-02-21 01:54:29 -05001116 conn, err := acceptOrWait(listener, waitChan)
1117 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001118 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001119 conn.Close()
1120 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001121
David Benjamin46662482016-08-17 00:51:00 -04001122 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001123 var resumeConfig Config
1124 if test.resumeConfig != nil {
1125 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001126 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001127 resumeConfig.SessionTicketKey = config.SessionTicketKey
1128 resumeConfig.ClientSessionCache = config.ClientSessionCache
1129 resumeConfig.ServerSessionCache = config.ServerSessionCache
1130 }
David Benjamin2e045a92016-06-08 13:09:56 -04001131 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001132 } else {
1133 resumeConfig = config
1134 }
David Benjamin87c8a642015-02-21 01:54:29 -05001135 var connResume net.Conn
1136 connResume, err = acceptOrWait(listener, waitChan)
1137 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001138 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001139 connResume.Close()
1140 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001141 }
1142
David Benjamin87c8a642015-02-21 01:54:29 -05001143 // Close the listener now. This is to avoid hangs should the shim try to
1144 // open more connections than expected.
1145 listener.Close()
1146 listener = nil
1147
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001148 var shimKilledLock sync.Mutex
1149 var shimKilled bool
1150 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1151 shimKilledLock.Lock()
1152 shimKilled = true
1153 shimKilledLock.Unlock()
1154 shim.Process.Kill()
1155 })
David Benjamin87c8a642015-02-21 01:54:29 -05001156 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001157 waitTimeout.Stop()
1158 shimKilledLock.Lock()
1159 if shimKilled && err == nil {
1160 err = errors.New("timeout waiting for the shim to exit.")
1161 }
1162 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001163 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001164 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001165 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1166 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001167 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001168 case 89:
1169 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001170 case 99:
1171 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001172 }
1173 }
Adam Langley95c29f32014-06-20 12:00:00 -07001174
David Benjamin9bea3492016-03-02 10:59:16 -05001175 // Account for Windows line endings.
1176 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1177 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001178
1179 // Separate the errors from the shim and those from tools like
1180 // AddressSanitizer.
1181 var extraStderr string
1182 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1183 stderr = stderrParts[0]
1184 extraStderr = stderrParts[1]
1185 }
1186
Adam Langley95c29f32014-06-20 12:00:00 -07001187 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001188 expectedError := translateExpectedError(test.expectedError)
1189 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001190
Adam Langleyac61fa32014-06-23 12:03:11 -07001191 localError := "none"
1192 if err != nil {
1193 localError = err.Error()
1194 }
1195 if len(test.expectedLocalError) != 0 {
1196 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1197 }
Adam Langley95c29f32014-06-20 12:00:00 -07001198
1199 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001200 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001201 if childErr != nil {
1202 childError = childErr.Error()
1203 }
1204
1205 var msg string
1206 switch {
1207 case failed && !test.shouldFail:
1208 msg = "unexpected failure"
1209 case !failed && test.shouldFail:
1210 msg = "unexpected success"
1211 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001212 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001213 default:
1214 panic("internal error")
1215 }
1216
David Benjamin9aafb642016-09-20 19:36:53 -04001217 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 -07001218 }
1219
David Benjamind2ba8892016-09-20 19:41:04 -04001220 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001221 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001222 }
1223
David Benjamind2ba8892016-09-20 19:41:04 -04001224 if *useValgrind && isValgrindError {
1225 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1226 }
1227
Adam Langley95c29f32014-06-20 12:00:00 -07001228 return nil
1229}
1230
David Benjaminaa012042016-12-10 13:33:05 -05001231type tlsVersion struct {
Steven Valdez520e1222017-06-13 12:45:25 -04001232 name string
1233 // version is the protocol version.
Adam Langley95c29f32014-06-20 12:00:00 -07001234 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001235 // excludeFlag is the legacy shim flag to disable the version.
1236 excludeFlag string
1237 hasDTLS bool
Steven Valdez520e1222017-06-13 12:45:25 -04001238 // versionDTLS, if non-zero, is the DTLS-specific representation of the version.
1239 versionDTLS uint16
1240 // versionWire, if non-zero, is the wire representation of the
1241 // version. Otherwise the wire version is the protocol version or
1242 // versionDTLS.
1243 versionWire uint16
1244 tls13Variant int
David Benjamin353577c2017-06-29 15:54:58 -04001245}
1246
1247func (vers tlsVersion) shimFlag(protocol protocol) string {
Steven Valdez520e1222017-06-13 12:45:25 -04001248 // The shim uses the protocol version in its public API, but uses the
1249 // DTLS-specific version if it exists.
1250 if protocol == dtls && vers.versionDTLS != 0 {
1251 return strconv.Itoa(int(vers.versionDTLS))
David Benjamin353577c2017-06-29 15:54:58 -04001252 }
Steven Valdez520e1222017-06-13 12:45:25 -04001253 return strconv.Itoa(int(vers.version))
1254}
1255
1256func (vers tlsVersion) wire(protocol protocol) uint16 {
1257 if protocol == dtls && vers.versionDTLS != 0 {
1258 return vers.versionDTLS
1259 }
1260 if vers.versionWire != 0 {
1261 return vers.versionWire
1262 }
1263 return vers.version
David Benjaminaa012042016-12-10 13:33:05 -05001264}
1265
1266var tlsVersions = []tlsVersion{
Steven Valdez520e1222017-06-13 12:45:25 -04001267 {
1268 name: "SSL3",
1269 version: VersionSSL30,
1270 excludeFlag: "-no-ssl3",
1271 },
1272 {
1273 name: "TLS1",
1274 version: VersionTLS10,
1275 excludeFlag: "-no-tls1",
1276 hasDTLS: true,
1277 versionDTLS: VersionDTLS10,
1278 },
1279 {
1280 name: "TLS11",
1281 version: VersionTLS11,
1282 excludeFlag: "-no-tls11",
1283 },
1284 {
1285 name: "TLS12",
1286 version: VersionTLS12,
1287 excludeFlag: "-no-tls12",
1288 hasDTLS: true,
1289 versionDTLS: VersionDTLS12,
1290 },
1291 {
1292 name: "TLS13",
1293 version: VersionTLS13,
1294 excludeFlag: "-no-tls13",
1295 versionWire: tls13DraftVersion,
1296 tls13Variant: TLS13Default,
1297 },
1298 {
1299 name: "TLS13Experiment",
1300 version: VersionTLS13,
1301 excludeFlag: "-no-tls13",
1302 versionWire: tls13ExperimentVersion,
1303 tls13Variant: TLS13Experiment,
1304 },
Steven Valdezdbe01582017-07-14 10:39:28 -04001305 {
1306 name: "TLS13RecordTypeExperiment",
1307 version: VersionTLS13,
1308 excludeFlag: "-no-tls13",
1309 versionWire: tls13RecordTypeExperimentVersion,
1310 tls13Variant: TLS13RecordTypeExperiment,
1311 },
Steven Valdez520e1222017-06-13 12:45:25 -04001312}
1313
1314func allVersions(protocol protocol) []tlsVersion {
1315 if protocol == tls {
1316 return tlsVersions
1317 }
1318
1319 var ret []tlsVersion
1320 for _, vers := range tlsVersions {
1321 if vers.hasDTLS {
1322 ret = append(ret, vers)
1323 }
1324 }
1325 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001326}
1327
David Benjaminaa012042016-12-10 13:33:05 -05001328type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001329 name string
1330 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001331}
1332
1333var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001334 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001335 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001336 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001337 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001338 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001339 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001340 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001341 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1342 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001343 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1344 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001345 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001346 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001347 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001348 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001349 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001350 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001351 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001352 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001353 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001354 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001355 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1356 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001357 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1358 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001359 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001360 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1361 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1362 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001363 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001364}
1365
David Benjamin8b8c0062014-11-23 02:47:52 -05001366func hasComponent(suiteName, component string) bool {
1367 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1368}
1369
David Benjaminf7768e42014-08-31 02:06:47 -04001370func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001371 return hasComponent(suiteName, "GCM") ||
1372 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001373 hasComponent(suiteName, "SHA384") ||
1374 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001375}
1376
Nick Harper1fd39d82016-06-14 18:14:35 -07001377func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001378 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001379}
1380
David Benjamin8b8c0062014-11-23 02:47:52 -05001381func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001382 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001383}
1384
Adam Langleya7997f12015-05-14 17:38:50 -07001385func bigFromHex(hex string) *big.Int {
1386 ret, ok := new(big.Int).SetString(hex, 16)
1387 if !ok {
1388 panic("failed to parse hex number 0x" + hex)
1389 }
1390 return ret
1391}
1392
Adam Langley7c803a62015-06-15 15:35:05 -07001393func addBasicTests() {
1394 basicTests := []testCase{
1395 {
Adam Langley7c803a62015-06-15 15:35:05 -07001396 name: "NoFallbackSCSV",
1397 config: Config{
1398 Bugs: ProtocolBugs{
1399 FailIfNotFallbackSCSV: true,
1400 },
1401 },
1402 shouldFail: true,
1403 expectedLocalError: "no fallback SCSV found",
1404 },
1405 {
1406 name: "SendFallbackSCSV",
1407 config: Config{
1408 Bugs: ProtocolBugs{
1409 FailIfNotFallbackSCSV: true,
1410 },
1411 },
1412 flags: []string{"-fallback-scsv"},
1413 },
1414 {
1415 name: "ClientCertificateTypes",
1416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001417 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001418 ClientAuth: RequestClientCert,
1419 ClientCertificateTypes: []byte{
1420 CertTypeDSSSign,
1421 CertTypeRSASign,
1422 CertTypeECDSASign,
1423 },
1424 },
1425 flags: []string{
1426 "-expect-certificate-types",
1427 base64.StdEncoding.EncodeToString([]byte{
1428 CertTypeDSSSign,
1429 CertTypeRSASign,
1430 CertTypeECDSASign,
1431 }),
1432 },
1433 },
1434 {
Adam Langley7c803a62015-06-15 15:35:05 -07001435 name: "UnauthenticatedECDH",
1436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001437 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1439 Bugs: ProtocolBugs{
1440 UnauthenticatedECDH: true,
1441 },
1442 },
1443 shouldFail: true,
1444 expectedError: ":UNEXPECTED_MESSAGE:",
1445 },
1446 {
1447 name: "SkipCertificateStatus",
1448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001449 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1451 Bugs: ProtocolBugs{
1452 SkipCertificateStatus: true,
1453 },
1454 },
1455 flags: []string{
1456 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001457 // This test involves an optional message. Test the message callback
1458 // trace to ensure we do not miss or double-report any.
1459 "-expect-msg-callback",
1460 `write hs 1
1461read hs 2
1462read hs 11
1463read hs 12
1464read hs 14
1465write hs 16
1466write ccs
1467write hs 20
1468read hs 4
1469read ccs
1470read hs 20
1471read alert 1 0
1472`,
1473 },
1474 },
1475 {
1476 protocol: dtls,
1477 name: "SkipCertificateStatus-DTLS",
1478 config: Config{
1479 MaxVersion: VersionTLS12,
1480 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1481 Bugs: ProtocolBugs{
1482 SkipCertificateStatus: true,
1483 },
1484 },
1485 flags: []string{
1486 "-enable-ocsp-stapling",
1487 // This test involves an optional message. Test the message callback
1488 // trace to ensure we do not miss or double-report any.
1489 "-expect-msg-callback",
1490 `write hs 1
1491read hs 3
1492write hs 1
1493read hs 2
1494read hs 11
1495read hs 12
1496read hs 14
1497write hs 16
1498write ccs
1499write hs 20
1500read hs 4
1501read ccs
1502read hs 20
1503read alert 1 0
1504`,
Adam Langley7c803a62015-06-15 15:35:05 -07001505 },
1506 },
1507 {
1508 name: "SkipServerKeyExchange",
1509 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001510 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001511 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1512 Bugs: ProtocolBugs{
1513 SkipServerKeyExchange: true,
1514 },
1515 },
1516 shouldFail: true,
1517 expectedError: ":UNEXPECTED_MESSAGE:",
1518 },
1519 {
Adam Langley7c803a62015-06-15 15:35:05 -07001520 testType: serverTest,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001521 name: "ServerSkipCertificateVerify",
1522 config: Config{
1523 MaxVersion: VersionTLS12,
1524 Certificates: []Certificate{rsaChainCertificate},
1525 Bugs: ProtocolBugs{
1526 SkipCertificateVerify: true,
1527 },
1528 },
1529 expectPeerCertificate: &rsaChainCertificate,
1530 flags: []string{
1531 "-require-any-client-certificate",
1532 },
1533 shouldFail: true,
1534 expectedError: ":UNEXPECTED_RECORD:",
1535 expectedLocalError: "remote error: unexpected message",
1536 },
1537 {
1538 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001539 name: "Alert",
1540 config: Config{
1541 Bugs: ProtocolBugs{
1542 SendSpuriousAlert: alertRecordOverflow,
1543 },
1544 },
1545 shouldFail: true,
1546 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1547 },
1548 {
1549 protocol: dtls,
1550 testType: serverTest,
1551 name: "Alert-DTLS",
1552 config: Config{
1553 Bugs: ProtocolBugs{
1554 SendSpuriousAlert: alertRecordOverflow,
1555 },
1556 },
1557 shouldFail: true,
1558 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1559 },
1560 {
1561 testType: serverTest,
1562 name: "FragmentAlert",
1563 config: Config{
1564 Bugs: ProtocolBugs{
1565 FragmentAlert: true,
1566 SendSpuriousAlert: alertRecordOverflow,
1567 },
1568 },
1569 shouldFail: true,
1570 expectedError: ":BAD_ALERT:",
1571 },
1572 {
1573 protocol: dtls,
1574 testType: serverTest,
1575 name: "FragmentAlert-DTLS",
1576 config: Config{
1577 Bugs: ProtocolBugs{
1578 FragmentAlert: true,
1579 SendSpuriousAlert: alertRecordOverflow,
1580 },
1581 },
1582 shouldFail: true,
1583 expectedError: ":BAD_ALERT:",
1584 },
1585 {
1586 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001587 name: "DoubleAlert",
1588 config: Config{
1589 Bugs: ProtocolBugs{
1590 DoubleAlert: true,
1591 SendSpuriousAlert: alertRecordOverflow,
1592 },
1593 },
1594 shouldFail: true,
1595 expectedError: ":BAD_ALERT:",
1596 },
1597 {
1598 protocol: dtls,
1599 testType: serverTest,
1600 name: "DoubleAlert-DTLS",
1601 config: Config{
1602 Bugs: ProtocolBugs{
1603 DoubleAlert: true,
1604 SendSpuriousAlert: alertRecordOverflow,
1605 },
1606 },
1607 shouldFail: true,
1608 expectedError: ":BAD_ALERT:",
1609 },
1610 {
Adam Langley7c803a62015-06-15 15:35:05 -07001611 name: "SkipNewSessionTicket",
1612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001613 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001614 Bugs: ProtocolBugs{
1615 SkipNewSessionTicket: true,
1616 },
1617 },
1618 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001619 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001620 },
1621 {
1622 testType: serverTest,
1623 name: "FallbackSCSV",
1624 config: Config{
1625 MaxVersion: VersionTLS11,
1626 Bugs: ProtocolBugs{
1627 SendFallbackSCSV: true,
1628 },
1629 },
David Benjamin56cadc32016-12-16 19:54:11 -05001630 shouldFail: true,
1631 expectedError: ":INAPPROPRIATE_FALLBACK:",
1632 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001633 },
1634 {
1635 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001636 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001637 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001638 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001639 Bugs: ProtocolBugs{
1640 SendFallbackSCSV: true,
1641 },
1642 },
1643 },
1644 {
1645 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001646 name: "FallbackSCSV-VersionMatch-TLS12",
1647 config: Config{
1648 MaxVersion: VersionTLS12,
1649 Bugs: ProtocolBugs{
1650 SendFallbackSCSV: true,
1651 },
1652 },
1653 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1654 },
1655 {
1656 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001657 name: "FragmentedClientVersion",
1658 config: Config{
1659 Bugs: ProtocolBugs{
1660 MaxHandshakeRecordLength: 1,
1661 FragmentClientVersion: true,
1662 },
1663 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001664 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 },
1666 {
Adam Langley7c803a62015-06-15 15:35:05 -07001667 testType: serverTest,
1668 name: "HttpGET",
1669 sendPrefix: "GET / HTTP/1.0\n",
1670 shouldFail: true,
1671 expectedError: ":HTTP_REQUEST:",
1672 },
1673 {
1674 testType: serverTest,
1675 name: "HttpPOST",
1676 sendPrefix: "POST / HTTP/1.0\n",
1677 shouldFail: true,
1678 expectedError: ":HTTP_REQUEST:",
1679 },
1680 {
1681 testType: serverTest,
1682 name: "HttpHEAD",
1683 sendPrefix: "HEAD / HTTP/1.0\n",
1684 shouldFail: true,
1685 expectedError: ":HTTP_REQUEST:",
1686 },
1687 {
1688 testType: serverTest,
1689 name: "HttpPUT",
1690 sendPrefix: "PUT / HTTP/1.0\n",
1691 shouldFail: true,
1692 expectedError: ":HTTP_REQUEST:",
1693 },
1694 {
1695 testType: serverTest,
1696 name: "HttpCONNECT",
1697 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1698 shouldFail: true,
1699 expectedError: ":HTTPS_PROXY_REQUEST:",
1700 },
1701 {
1702 testType: serverTest,
1703 name: "Garbage",
1704 sendPrefix: "blah",
1705 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001706 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001707 },
1708 {
Adam Langley7c803a62015-06-15 15:35:05 -07001709 name: "RSAEphemeralKey",
1710 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001711 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001712 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1713 Bugs: ProtocolBugs{
1714 RSAEphemeralKey: true,
1715 },
1716 },
1717 shouldFail: true,
1718 expectedError: ":UNEXPECTED_MESSAGE:",
1719 },
1720 {
1721 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001722 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001723 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001724 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001725 },
1726 {
1727 protocol: dtls,
1728 name: "DisableEverything-DTLS",
1729 flags: []string{"-no-tls12", "-no-tls1"},
1730 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001731 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001732 },
1733 {
Adam Langley7c803a62015-06-15 15:35:05 -07001734 protocol: dtls,
1735 testType: serverTest,
1736 name: "MTU",
1737 config: Config{
1738 Bugs: ProtocolBugs{
1739 MaxPacketLength: 256,
1740 },
1741 },
1742 flags: []string{"-mtu", "256"},
1743 },
1744 {
1745 protocol: dtls,
1746 testType: serverTest,
1747 name: "MTUExceeded",
1748 config: Config{
1749 Bugs: ProtocolBugs{
1750 MaxPacketLength: 255,
1751 },
1752 },
1753 flags: []string{"-mtu", "256"},
1754 shouldFail: true,
1755 expectedLocalError: "dtls: exceeded maximum packet length",
1756 },
1757 {
Adam Langley7c803a62015-06-15 15:35:05 -07001758 name: "EmptyCertificateList",
1759 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001760 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001761 Bugs: ProtocolBugs{
1762 EmptyCertificateList: true,
1763 },
1764 },
1765 shouldFail: true,
1766 expectedError: ":DECODE_ERROR:",
1767 },
1768 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001769 name: "EmptyCertificateList-TLS13",
1770 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001771 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001772 Bugs: ProtocolBugs{
1773 EmptyCertificateList: true,
1774 },
1775 },
1776 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001777 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001778 },
1779 {
Adam Langley7c803a62015-06-15 15:35:05 -07001780 name: "TLSFatalBadPackets",
1781 damageFirstWrite: true,
1782 shouldFail: true,
1783 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1784 },
1785 {
1786 protocol: dtls,
1787 name: "DTLSIgnoreBadPackets",
1788 damageFirstWrite: true,
1789 },
1790 {
1791 protocol: dtls,
1792 name: "DTLSIgnoreBadPackets-Async",
1793 damageFirstWrite: true,
1794 flags: []string{"-async"},
1795 },
1796 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001797 name: "AppDataBeforeHandshake",
1798 config: Config{
1799 Bugs: ProtocolBugs{
1800 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1801 },
1802 },
1803 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001804 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001805 },
1806 {
1807 name: "AppDataBeforeHandshake-Empty",
1808 config: Config{
1809 Bugs: ProtocolBugs{
1810 AppDataBeforeHandshake: []byte{},
1811 },
1812 },
1813 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001814 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001815 },
1816 {
1817 protocol: dtls,
1818 name: "AppDataBeforeHandshake-DTLS",
1819 config: Config{
1820 Bugs: ProtocolBugs{
1821 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1822 },
1823 },
1824 shouldFail: true,
1825 expectedError: ":UNEXPECTED_RECORD:",
1826 },
1827 {
1828 protocol: dtls,
1829 name: "AppDataBeforeHandshake-DTLS-Empty",
1830 config: Config{
1831 Bugs: ProtocolBugs{
1832 AppDataBeforeHandshake: []byte{},
1833 },
1834 },
1835 shouldFail: true,
1836 expectedError: ":UNEXPECTED_RECORD:",
1837 },
1838 {
Adam Langley7c803a62015-06-15 15:35:05 -07001839 name: "AppDataAfterChangeCipherSpec",
1840 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001841 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001842 Bugs: ProtocolBugs{
1843 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1844 },
1845 },
1846 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001847 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001848 },
1849 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001850 name: "AppDataAfterChangeCipherSpec-Empty",
1851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001852 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001853 Bugs: ProtocolBugs{
1854 AppDataAfterChangeCipherSpec: []byte{},
1855 },
1856 },
1857 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001858 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001859 },
1860 {
Adam Langley7c803a62015-06-15 15:35:05 -07001861 protocol: dtls,
1862 name: "AppDataAfterChangeCipherSpec-DTLS",
1863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001864 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001865 Bugs: ProtocolBugs{
1866 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1867 },
1868 },
1869 // BoringSSL's DTLS implementation will drop the out-of-order
1870 // application data.
1871 },
1872 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001873 protocol: dtls,
1874 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001876 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001877 Bugs: ProtocolBugs{
1878 AppDataAfterChangeCipherSpec: []byte{},
1879 },
1880 },
1881 // BoringSSL's DTLS implementation will drop the out-of-order
1882 // application data.
1883 },
1884 {
Adam Langley7c803a62015-06-15 15:35:05 -07001885 name: "AlertAfterChangeCipherSpec",
1886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001887 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001888 Bugs: ProtocolBugs{
1889 AlertAfterChangeCipherSpec: alertRecordOverflow,
1890 },
1891 },
1892 shouldFail: true,
1893 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1894 },
1895 {
1896 protocol: dtls,
1897 name: "AlertAfterChangeCipherSpec-DTLS",
1898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001899 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001900 Bugs: ProtocolBugs{
1901 AlertAfterChangeCipherSpec: alertRecordOverflow,
1902 },
1903 },
1904 shouldFail: true,
1905 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1906 },
1907 {
1908 protocol: dtls,
1909 name: "ReorderHandshakeFragments-Small-DTLS",
1910 config: Config{
1911 Bugs: ProtocolBugs{
1912 ReorderHandshakeFragments: true,
1913 // Small enough that every handshake message is
1914 // fragmented.
1915 MaxHandshakeRecordLength: 2,
1916 },
1917 },
1918 },
1919 {
1920 protocol: dtls,
1921 name: "ReorderHandshakeFragments-Large-DTLS",
1922 config: Config{
1923 Bugs: ProtocolBugs{
1924 ReorderHandshakeFragments: true,
1925 // Large enough that no handshake message is
1926 // fragmented.
1927 MaxHandshakeRecordLength: 2048,
1928 },
1929 },
1930 },
1931 {
1932 protocol: dtls,
1933 name: "MixCompleteMessageWithFragments-DTLS",
1934 config: Config{
1935 Bugs: ProtocolBugs{
1936 ReorderHandshakeFragments: true,
1937 MixCompleteMessageWithFragments: true,
1938 MaxHandshakeRecordLength: 2,
1939 },
1940 },
1941 },
1942 {
1943 name: "SendInvalidRecordType",
1944 config: Config{
1945 Bugs: ProtocolBugs{
1946 SendInvalidRecordType: true,
1947 },
1948 },
1949 shouldFail: true,
1950 expectedError: ":UNEXPECTED_RECORD:",
1951 },
1952 {
1953 protocol: dtls,
1954 name: "SendInvalidRecordType-DTLS",
1955 config: Config{
1956 Bugs: ProtocolBugs{
1957 SendInvalidRecordType: true,
1958 },
1959 },
1960 shouldFail: true,
1961 expectedError: ":UNEXPECTED_RECORD:",
1962 },
1963 {
1964 name: "FalseStart-SkipServerSecondLeg",
1965 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001966 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1968 NextProtos: []string{"foo"},
1969 Bugs: ProtocolBugs{
1970 SkipNewSessionTicket: true,
1971 SkipChangeCipherSpec: true,
1972 SkipFinished: true,
1973 ExpectFalseStart: true,
1974 },
1975 },
1976 flags: []string{
1977 "-false-start",
1978 "-handshake-never-done",
1979 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001980 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001981 },
1982 shimWritesFirst: true,
1983 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001984 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001985 },
1986 {
1987 name: "FalseStart-SkipServerSecondLeg-Implicit",
1988 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001989 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001990 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1991 NextProtos: []string{"foo"},
1992 Bugs: ProtocolBugs{
1993 SkipNewSessionTicket: true,
1994 SkipChangeCipherSpec: true,
1995 SkipFinished: true,
1996 },
1997 },
1998 flags: []string{
1999 "-implicit-handshake",
2000 "-false-start",
2001 "-handshake-never-done",
2002 "-advertise-alpn", "\x03foo",
2003 },
2004 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04002005 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002006 },
2007 {
2008 testType: serverTest,
2009 name: "FailEarlyCallback",
2010 flags: []string{"-fail-early-callback"},
2011 shouldFail: true,
2012 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002013 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002014 },
2015 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002016 name: "FailCertCallback-Client-TLS12",
2017 config: Config{
2018 MaxVersion: VersionTLS12,
2019 ClientAuth: RequestClientCert,
2020 },
2021 flags: []string{"-fail-cert-callback"},
2022 shouldFail: true,
2023 expectedError: ":CERT_CB_ERROR:",
2024 expectedLocalError: "remote error: internal error",
2025 },
2026 {
2027 testType: serverTest,
2028 name: "FailCertCallback-Server-TLS12",
2029 config: Config{
2030 MaxVersion: VersionTLS12,
2031 },
2032 flags: []string{"-fail-cert-callback"},
2033 shouldFail: true,
2034 expectedError: ":CERT_CB_ERROR:",
2035 expectedLocalError: "remote error: internal error",
2036 },
2037 {
2038 name: "FailCertCallback-Client-TLS13",
2039 config: Config{
2040 MaxVersion: VersionTLS13,
2041 ClientAuth: RequestClientCert,
2042 },
2043 flags: []string{"-fail-cert-callback"},
2044 shouldFail: true,
2045 expectedError: ":CERT_CB_ERROR:",
2046 expectedLocalError: "remote error: internal error",
2047 },
2048 {
2049 testType: serverTest,
2050 name: "FailCertCallback-Server-TLS13",
2051 config: Config{
2052 MaxVersion: VersionTLS13,
2053 },
2054 flags: []string{"-fail-cert-callback"},
2055 shouldFail: true,
2056 expectedError: ":CERT_CB_ERROR:",
2057 expectedLocalError: "remote error: internal error",
2058 },
2059 {
Adam Langley7c803a62015-06-15 15:35:05 -07002060 protocol: dtls,
2061 name: "FragmentMessageTypeMismatch-DTLS",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 MaxHandshakeRecordLength: 2,
2065 FragmentMessageTypeMismatch: true,
2066 },
2067 },
2068 shouldFail: true,
2069 expectedError: ":FRAGMENT_MISMATCH:",
2070 },
2071 {
2072 protocol: dtls,
2073 name: "FragmentMessageLengthMismatch-DTLS",
2074 config: Config{
2075 Bugs: ProtocolBugs{
2076 MaxHandshakeRecordLength: 2,
2077 FragmentMessageLengthMismatch: true,
2078 },
2079 },
2080 shouldFail: true,
2081 expectedError: ":FRAGMENT_MISMATCH:",
2082 },
2083 {
2084 protocol: dtls,
2085 name: "SplitFragments-Header-DTLS",
2086 config: Config{
2087 Bugs: ProtocolBugs{
2088 SplitFragments: 2,
2089 },
2090 },
2091 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002092 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002093 },
2094 {
2095 protocol: dtls,
2096 name: "SplitFragments-Boundary-DTLS",
2097 config: Config{
2098 Bugs: ProtocolBugs{
2099 SplitFragments: dtlsRecordHeaderLen,
2100 },
2101 },
2102 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002103 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002104 },
2105 {
2106 protocol: dtls,
2107 name: "SplitFragments-Body-DTLS",
2108 config: Config{
2109 Bugs: ProtocolBugs{
2110 SplitFragments: dtlsRecordHeaderLen + 1,
2111 },
2112 },
2113 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002114 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002115 },
2116 {
2117 protocol: dtls,
2118 name: "SendEmptyFragments-DTLS",
2119 config: Config{
2120 Bugs: ProtocolBugs{
2121 SendEmptyFragments: true,
2122 },
2123 },
2124 },
2125 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002126 name: "BadFinished-Client",
2127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002128 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002129 Bugs: ProtocolBugs{
2130 BadFinished: true,
2131 },
2132 },
2133 shouldFail: true,
2134 expectedError: ":DIGEST_CHECK_FAILED:",
2135 },
2136 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002137 name: "BadFinished-Client-TLS13",
2138 config: Config{
2139 MaxVersion: VersionTLS13,
2140 Bugs: ProtocolBugs{
2141 BadFinished: true,
2142 },
2143 },
2144 shouldFail: true,
2145 expectedError: ":DIGEST_CHECK_FAILED:",
2146 },
2147 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002148 testType: serverTest,
2149 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002151 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002152 Bugs: ProtocolBugs{
2153 BadFinished: true,
2154 },
2155 },
2156 shouldFail: true,
2157 expectedError: ":DIGEST_CHECK_FAILED:",
2158 },
2159 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002160 testType: serverTest,
2161 name: "BadFinished-Server-TLS13",
2162 config: Config{
2163 MaxVersion: VersionTLS13,
2164 Bugs: ProtocolBugs{
2165 BadFinished: true,
2166 },
2167 },
2168 shouldFail: true,
2169 expectedError: ":DIGEST_CHECK_FAILED:",
2170 },
2171 {
Adam Langley7c803a62015-06-15 15:35:05 -07002172 name: "FalseStart-BadFinished",
2173 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002174 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2176 NextProtos: []string{"foo"},
2177 Bugs: ProtocolBugs{
2178 BadFinished: true,
2179 ExpectFalseStart: true,
2180 },
2181 },
2182 flags: []string{
2183 "-false-start",
2184 "-handshake-never-done",
2185 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002186 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002187 },
2188 shimWritesFirst: true,
2189 shouldFail: true,
2190 expectedError: ":DIGEST_CHECK_FAILED:",
2191 },
2192 {
2193 name: "NoFalseStart-NoALPN",
2194 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002195 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002196 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2197 Bugs: ProtocolBugs{
2198 ExpectFalseStart: true,
2199 AlertBeforeFalseStartTest: alertAccessDenied,
2200 },
2201 },
2202 flags: []string{
2203 "-false-start",
2204 },
2205 shimWritesFirst: true,
2206 shouldFail: true,
2207 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2208 expectedLocalError: "tls: peer did not false start: EOF",
2209 },
2210 {
2211 name: "NoFalseStart-NoAEAD",
2212 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002213 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002214 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2215 NextProtos: []string{"foo"},
2216 Bugs: ProtocolBugs{
2217 ExpectFalseStart: true,
2218 AlertBeforeFalseStartTest: alertAccessDenied,
2219 },
2220 },
2221 flags: []string{
2222 "-false-start",
2223 "-advertise-alpn", "\x03foo",
2224 },
2225 shimWritesFirst: true,
2226 shouldFail: true,
2227 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2228 expectedLocalError: "tls: peer did not false start: EOF",
2229 },
2230 {
2231 name: "NoFalseStart-RSA",
2232 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002233 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002234 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2235 NextProtos: []string{"foo"},
2236 Bugs: ProtocolBugs{
2237 ExpectFalseStart: true,
2238 AlertBeforeFalseStartTest: alertAccessDenied,
2239 },
2240 },
2241 flags: []string{
2242 "-false-start",
2243 "-advertise-alpn", "\x03foo",
2244 },
2245 shimWritesFirst: true,
2246 shouldFail: true,
2247 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2248 expectedLocalError: "tls: peer did not false start: EOF",
2249 },
2250 {
Adam Langley7c803a62015-06-15 15:35:05 -07002251 protocol: dtls,
2252 name: "SendSplitAlert-Sync",
2253 config: Config{
2254 Bugs: ProtocolBugs{
2255 SendSplitAlert: true,
2256 },
2257 },
2258 },
2259 {
2260 protocol: dtls,
2261 name: "SendSplitAlert-Async",
2262 config: Config{
2263 Bugs: ProtocolBugs{
2264 SendSplitAlert: true,
2265 },
2266 },
2267 flags: []string{"-async"},
2268 },
2269 {
2270 protocol: dtls,
2271 name: "PackDTLSHandshake",
2272 config: Config{
2273 Bugs: ProtocolBugs{
2274 MaxHandshakeRecordLength: 2,
2275 PackHandshakeFragments: 20,
2276 PackHandshakeRecords: 200,
2277 },
2278 },
2279 },
2280 {
Adam Langley7c803a62015-06-15 15:35:05 -07002281 name: "SendEmptyRecords-Pass",
2282 sendEmptyRecords: 32,
2283 },
2284 {
2285 name: "SendEmptyRecords",
2286 sendEmptyRecords: 33,
2287 shouldFail: true,
2288 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2289 },
2290 {
2291 name: "SendEmptyRecords-Async",
2292 sendEmptyRecords: 33,
2293 flags: []string{"-async"},
2294 shouldFail: true,
2295 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2296 },
2297 {
David Benjamine8e84b92016-08-03 15:39:47 -04002298 name: "SendWarningAlerts-Pass",
2299 config: Config{
2300 MaxVersion: VersionTLS12,
2301 },
Adam Langley7c803a62015-06-15 15:35:05 -07002302 sendWarningAlerts: 4,
2303 },
2304 {
David Benjamine8e84b92016-08-03 15:39:47 -04002305 protocol: dtls,
2306 name: "SendWarningAlerts-DTLS-Pass",
2307 config: Config{
2308 MaxVersion: VersionTLS12,
2309 },
Adam Langley7c803a62015-06-15 15:35:05 -07002310 sendWarningAlerts: 4,
2311 },
2312 {
David Benjamine8e84b92016-08-03 15:39:47 -04002313 name: "SendWarningAlerts-TLS13",
2314 config: Config{
2315 MaxVersion: VersionTLS13,
2316 },
2317 sendWarningAlerts: 4,
2318 shouldFail: true,
2319 expectedError: ":BAD_ALERT:",
2320 expectedLocalError: "remote error: error decoding message",
2321 },
2322 {
2323 name: "SendWarningAlerts",
2324 config: Config{
2325 MaxVersion: VersionTLS12,
2326 },
Adam Langley7c803a62015-06-15 15:35:05 -07002327 sendWarningAlerts: 5,
2328 shouldFail: true,
2329 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2330 },
2331 {
David Benjamine8e84b92016-08-03 15:39:47 -04002332 name: "SendWarningAlerts-Async",
2333 config: Config{
2334 MaxVersion: VersionTLS12,
2335 },
Adam Langley7c803a62015-06-15 15:35:05 -07002336 sendWarningAlerts: 5,
2337 flags: []string{"-async"},
2338 shouldFail: true,
2339 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2340 },
David Benjaminba4594a2015-06-18 18:36:15 -04002341 {
David Benjamin24e58862017-06-14 18:45:29 -04002342 name: "SendBogusAlertType",
2343 sendBogusAlertType: true,
2344 shouldFail: true,
2345 expectedError: ":UNKNOWN_ALERT_TYPE:",
2346 expectedLocalError: "remote error: illegal parameter",
2347 },
2348 {
2349 protocol: dtls,
2350 name: "SendBogusAlertType-DTLS",
2351 sendBogusAlertType: true,
2352 shouldFail: true,
2353 expectedError: ":UNKNOWN_ALERT_TYPE:",
2354 expectedLocalError: "remote error: illegal parameter",
2355 },
2356 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002357 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002358 config: Config{
2359 MaxVersion: VersionTLS13,
2360 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002361 sendKeyUpdates: 33,
2362 keyUpdateRequest: keyUpdateNotRequested,
2363 shouldFail: true,
2364 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002365 },
2366 {
David Benjaminba4594a2015-06-18 18:36:15 -04002367 name: "EmptySessionID",
2368 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002369 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002370 SessionTicketsDisabled: true,
2371 },
2372 noSessionCache: true,
2373 flags: []string{"-expect-no-session"},
2374 },
David Benjamin30789da2015-08-29 22:56:45 -04002375 {
2376 name: "Unclean-Shutdown",
2377 config: Config{
2378 Bugs: ProtocolBugs{
2379 NoCloseNotify: true,
2380 ExpectCloseNotify: true,
2381 },
2382 },
2383 shimShutsDown: true,
2384 flags: []string{"-check-close-notify"},
2385 shouldFail: true,
2386 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2387 },
2388 {
2389 name: "Unclean-Shutdown-Ignored",
2390 config: Config{
2391 Bugs: ProtocolBugs{
2392 NoCloseNotify: true,
2393 },
2394 },
2395 shimShutsDown: true,
2396 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002397 {
David Benjaminfa214e42016-05-10 17:03:10 -04002398 name: "Unclean-Shutdown-Alert",
2399 config: Config{
2400 Bugs: ProtocolBugs{
2401 SendAlertOnShutdown: alertDecompressionFailure,
2402 ExpectCloseNotify: true,
2403 },
2404 },
2405 shimShutsDown: true,
2406 flags: []string{"-check-close-notify"},
2407 shouldFail: true,
2408 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2409 },
2410 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002411 name: "LargePlaintext",
2412 config: Config{
2413 Bugs: ProtocolBugs{
2414 SendLargeRecords: true,
2415 },
2416 },
2417 messageLen: maxPlaintext + 1,
2418 shouldFail: true,
2419 expectedError: ":DATA_LENGTH_TOO_LONG:",
2420 },
2421 {
2422 protocol: dtls,
2423 name: "LargePlaintext-DTLS",
2424 config: Config{
2425 Bugs: ProtocolBugs{
2426 SendLargeRecords: true,
2427 },
2428 },
2429 messageLen: maxPlaintext + 1,
2430 shouldFail: true,
2431 expectedError: ":DATA_LENGTH_TOO_LONG:",
2432 },
2433 {
2434 name: "LargeCiphertext",
2435 config: Config{
2436 Bugs: ProtocolBugs{
2437 SendLargeRecords: true,
2438 },
2439 },
2440 messageLen: maxPlaintext * 2,
2441 shouldFail: true,
2442 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2443 },
2444 {
2445 protocol: dtls,
2446 name: "LargeCiphertext-DTLS",
2447 config: Config{
2448 Bugs: ProtocolBugs{
2449 SendLargeRecords: true,
2450 },
2451 },
2452 messageLen: maxPlaintext * 2,
2453 // Unlike the other four cases, DTLS drops records which
2454 // are invalid before authentication, so the connection
2455 // does not fail.
2456 expectMessageDropped: true,
2457 },
David Benjamindd6fed92015-10-23 17:41:12 -04002458 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002459 name: "BadHelloRequest-1",
2460 renegotiate: 1,
2461 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002462 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002463 Bugs: ProtocolBugs{
2464 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2465 },
2466 },
2467 flags: []string{
2468 "-renegotiate-freely",
2469 "-expect-total-renegotiations", "1",
2470 },
2471 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002472 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002473 },
2474 {
2475 name: "BadHelloRequest-2",
2476 renegotiate: 1,
2477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002478 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002479 Bugs: ProtocolBugs{
2480 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2481 },
2482 },
2483 flags: []string{
2484 "-renegotiate-freely",
2485 "-expect-total-renegotiations", "1",
2486 },
2487 shouldFail: true,
2488 expectedError: ":BAD_HELLO_REQUEST:",
2489 },
David Benjaminef1b0092015-11-21 14:05:44 -05002490 {
2491 testType: serverTest,
2492 name: "SupportTicketsWithSessionID",
2493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002494 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002495 SessionTicketsDisabled: true,
2496 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002497 resumeConfig: &Config{
2498 MaxVersion: VersionTLS12,
2499 },
David Benjaminef1b0092015-11-21 14:05:44 -05002500 resumeSession: true,
2501 },
David Benjamin02edcd02016-07-27 17:40:37 -04002502 {
2503 protocol: dtls,
2504 name: "DTLS-SendExtraFinished",
2505 config: Config{
2506 Bugs: ProtocolBugs{
2507 SendExtraFinished: true,
2508 },
2509 },
2510 shouldFail: true,
2511 expectedError: ":UNEXPECTED_RECORD:",
2512 },
2513 {
2514 protocol: dtls,
2515 name: "DTLS-SendExtraFinished-Reordered",
2516 config: Config{
2517 Bugs: ProtocolBugs{
2518 MaxHandshakeRecordLength: 2,
2519 ReorderHandshakeFragments: true,
2520 SendExtraFinished: true,
2521 },
2522 },
2523 shouldFail: true,
2524 expectedError: ":UNEXPECTED_RECORD:",
2525 },
David Benjamine97fb482016-07-29 09:23:07 -04002526 {
2527 testType: serverTest,
2528 name: "V2ClientHello-EmptyRecordPrefix",
2529 config: Config{
2530 // Choose a cipher suite that does not involve
2531 // elliptic curves, so no extensions are
2532 // involved.
2533 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002534 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002535 Bugs: ProtocolBugs{
2536 SendV2ClientHello: true,
2537 },
2538 },
2539 sendPrefix: string([]byte{
2540 byte(recordTypeHandshake),
2541 3, 1, // version
2542 0, 0, // length
2543 }),
2544 // A no-op empty record may not be sent before V2ClientHello.
2545 shouldFail: true,
2546 expectedError: ":WRONG_VERSION_NUMBER:",
2547 },
2548 {
2549 testType: serverTest,
2550 name: "V2ClientHello-WarningAlertPrefix",
2551 config: Config{
2552 // Choose a cipher suite that does not involve
2553 // elliptic curves, so no extensions are
2554 // involved.
2555 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002556 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002557 Bugs: ProtocolBugs{
2558 SendV2ClientHello: true,
2559 },
2560 },
2561 sendPrefix: string([]byte{
2562 byte(recordTypeAlert),
2563 3, 1, // version
2564 0, 2, // length
2565 alertLevelWarning, byte(alertDecompressionFailure),
2566 }),
2567 // A no-op warning alert may not be sent before V2ClientHello.
2568 shouldFail: true,
2569 expectedError: ":WRONG_VERSION_NUMBER:",
2570 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002571 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002572 name: "KeyUpdate-Client",
2573 config: Config{
2574 MaxVersion: VersionTLS13,
2575 },
2576 sendKeyUpdates: 1,
2577 keyUpdateRequest: keyUpdateNotRequested,
2578 },
2579 {
2580 testType: serverTest,
2581 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002582 config: Config{
2583 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002584 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002585 sendKeyUpdates: 1,
2586 keyUpdateRequest: keyUpdateNotRequested,
2587 },
2588 {
2589 name: "KeyUpdate-InvalidRequestMode",
2590 config: Config{
2591 MaxVersion: VersionTLS13,
2592 },
2593 sendKeyUpdates: 1,
2594 keyUpdateRequest: 42,
2595 shouldFail: true,
2596 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002597 },
David Benjaminabe94e32016-09-04 14:18:58 -04002598 {
David Benjaminbbba9392017-04-06 12:54:12 -04002599 // Test that KeyUpdates are acknowledged properly.
2600 name: "KeyUpdate-RequestACK",
2601 config: Config{
2602 MaxVersion: VersionTLS13,
2603 Bugs: ProtocolBugs{
2604 RejectUnsolicitedKeyUpdate: true,
2605 },
2606 },
2607 // Test the shim receiving many KeyUpdates in a row.
2608 sendKeyUpdates: 5,
2609 messageCount: 5,
2610 keyUpdateRequest: keyUpdateRequested,
2611 },
2612 {
2613 // Test that KeyUpdates are acknowledged properly if the
2614 // peer's KeyUpdate is discovered while a write is
2615 // pending.
2616 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2617 config: Config{
2618 MaxVersion: VersionTLS13,
2619 Bugs: ProtocolBugs{
2620 RejectUnsolicitedKeyUpdate: true,
2621 },
2622 },
2623 // Test the shim receiving many KeyUpdates in a row.
2624 sendKeyUpdates: 5,
2625 messageCount: 5,
2626 keyUpdateRequest: keyUpdateRequested,
2627 readWithUnfinishedWrite: true,
2628 flags: []string{"-async"},
2629 },
2630 {
David Benjaminabe94e32016-09-04 14:18:58 -04002631 name: "SendSNIWarningAlert",
2632 config: Config{
2633 MaxVersion: VersionTLS12,
2634 Bugs: ProtocolBugs{
2635 SendSNIWarningAlert: true,
2636 },
2637 },
2638 },
David Benjaminc241d792016-09-09 10:34:20 -04002639 {
2640 testType: serverTest,
2641 name: "ExtraCompressionMethods-TLS12",
2642 config: Config{
2643 MaxVersion: VersionTLS12,
2644 Bugs: ProtocolBugs{
2645 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2646 },
2647 },
2648 },
2649 {
2650 testType: serverTest,
2651 name: "ExtraCompressionMethods-TLS13",
2652 config: Config{
2653 MaxVersion: VersionTLS13,
2654 Bugs: ProtocolBugs{
2655 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2656 },
2657 },
2658 shouldFail: true,
2659 expectedError: ":INVALID_COMPRESSION_LIST:",
2660 expectedLocalError: "remote error: illegal parameter",
2661 },
2662 {
2663 testType: serverTest,
2664 name: "NoNullCompression-TLS12",
2665 config: Config{
2666 MaxVersion: VersionTLS12,
2667 Bugs: ProtocolBugs{
2668 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2669 },
2670 },
2671 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002672 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002673 expectedLocalError: "remote error: illegal parameter",
2674 },
2675 {
2676 testType: serverTest,
2677 name: "NoNullCompression-TLS13",
2678 config: Config{
2679 MaxVersion: VersionTLS13,
2680 Bugs: ProtocolBugs{
2681 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2682 },
2683 },
2684 shouldFail: true,
2685 expectedError: ":INVALID_COMPRESSION_LIST:",
2686 expectedLocalError: "remote error: illegal parameter",
2687 },
David Benjamin413e79e2017-07-01 10:11:53 -04002688 // Test that the client rejects invalid compression methods
2689 // from the server.
2690 {
2691 testType: clientTest,
2692 name: "InvalidCompressionMethod",
2693 config: Config{
2694 MaxVersion: VersionTLS12,
2695 Bugs: ProtocolBugs{
2696 SendCompressionMethod: 1,
2697 },
2698 },
2699 shouldFail: true,
2700 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2701 expectedLocalError: "remote error: illegal parameter",
2702 },
David Benjamin65ac9972016-09-02 21:35:25 -04002703 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002704 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002705 config: Config{
2706 MaxVersion: VersionTLS12,
2707 Bugs: ProtocolBugs{
2708 ExpectGREASE: true,
2709 },
2710 },
2711 flags: []string{"-enable-grease"},
2712 },
2713 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002714 name: "GREASE-Client-TLS13",
2715 config: Config{
2716 MaxVersion: VersionTLS13,
2717 Bugs: ProtocolBugs{
2718 ExpectGREASE: true,
2719 },
2720 },
2721 flags: []string{"-enable-grease"},
2722 },
2723 {
2724 testType: serverTest,
2725 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002726 config: Config{
2727 MaxVersion: VersionTLS13,
2728 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002729 // TLS 1.3 servers are expected to
2730 // always enable GREASE. TLS 1.3 is new,
2731 // so there is no existing ecosystem to
2732 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002733 ExpectGREASE: true,
2734 },
2735 },
David Benjamin65ac9972016-09-02 21:35:25 -04002736 },
David Benjamine3fbb362017-01-06 16:19:28 -05002737 {
2738 // Test the server so there is a large certificate as
2739 // well as application data.
2740 testType: serverTest,
2741 name: "MaxSendFragment",
2742 config: Config{
2743 Bugs: ProtocolBugs{
2744 MaxReceivePlaintext: 512,
2745 },
2746 },
2747 messageLen: 1024,
2748 flags: []string{
2749 "-max-send-fragment", "512",
2750 "-read-size", "1024",
2751 },
2752 },
2753 {
2754 // Test the server so there is a large certificate as
2755 // well as application data.
2756 testType: serverTest,
2757 name: "MaxSendFragment-TooLarge",
2758 config: Config{
2759 Bugs: ProtocolBugs{
2760 // Ensure that some of the records are
2761 // 512.
2762 MaxReceivePlaintext: 511,
2763 },
2764 },
2765 messageLen: 1024,
2766 flags: []string{
2767 "-max-send-fragment", "512",
2768 "-read-size", "1024",
2769 },
2770 shouldFail: true,
2771 expectedLocalError: "local error: record overflow",
2772 },
Adam Langley7c803a62015-06-15 15:35:05 -07002773 }
Adam Langley7c803a62015-06-15 15:35:05 -07002774 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002775
2776 // Test that very large messages can be received.
2777 cert := rsaCertificate
2778 for i := 0; i < 50; i++ {
2779 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2780 }
2781 testCases = append(testCases, testCase{
2782 name: "LargeMessage",
2783 config: Config{
2784 Certificates: []Certificate{cert},
2785 },
2786 })
2787 testCases = append(testCases, testCase{
2788 protocol: dtls,
2789 name: "LargeMessage-DTLS",
2790 config: Config{
2791 Certificates: []Certificate{cert},
2792 },
2793 })
2794
2795 // They are rejected if the maximum certificate chain length is capped.
2796 testCases = append(testCases, testCase{
2797 name: "LargeMessage-Reject",
2798 config: Config{
2799 Certificates: []Certificate{cert},
2800 },
2801 flags: []string{"-max-cert-list", "16384"},
2802 shouldFail: true,
2803 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2804 })
2805 testCases = append(testCases, testCase{
2806 protocol: dtls,
2807 name: "LargeMessage-Reject-DTLS",
2808 config: Config{
2809 Certificates: []Certificate{cert},
2810 },
2811 flags: []string{"-max-cert-list", "16384"},
2812 shouldFail: true,
2813 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2814 })
Adam Langley7c803a62015-06-15 15:35:05 -07002815}
2816
David Benjaminaa012042016-12-10 13:33:05 -05002817func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2818 const psk = "12345"
2819 const pskIdentity = "luggage combo"
2820
2821 var prefix string
2822 if protocol == dtls {
2823 if !ver.hasDTLS {
2824 return
2825 }
2826 prefix = "D"
2827 }
2828
2829 var cert Certificate
2830 var certFile string
2831 var keyFile string
2832 if hasComponent(suite.name, "ECDSA") {
2833 cert = ecdsaP256Certificate
2834 certFile = ecdsaP256CertificateFile
2835 keyFile = ecdsaP256KeyFile
2836 } else {
2837 cert = rsaCertificate
2838 certFile = rsaCertificateFile
2839 keyFile = rsaKeyFile
2840 }
2841
2842 var flags []string
2843 if hasComponent(suite.name, "PSK") {
2844 flags = append(flags,
2845 "-psk", psk,
2846 "-psk-identity", pskIdentity)
2847 }
2848 if hasComponent(suite.name, "NULL") {
2849 // NULL ciphers must be explicitly enabled.
2850 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2851 }
David Benjaminaa012042016-12-10 13:33:05 -05002852
2853 var shouldServerFail, shouldClientFail bool
2854 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2855 // BoringSSL clients accept ECDHE on SSLv3, but
2856 // a BoringSSL server will never select it
2857 // because the extension is missing.
2858 shouldServerFail = true
2859 }
2860 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2861 shouldClientFail = true
2862 shouldServerFail = true
2863 }
2864 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2865 shouldClientFail = true
2866 shouldServerFail = true
2867 }
2868 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2869 shouldClientFail = true
2870 shouldServerFail = true
2871 }
2872 if !isDTLSCipher(suite.name) && protocol == dtls {
2873 shouldClientFail = true
2874 shouldServerFail = true
2875 }
2876
2877 var sendCipherSuite uint16
2878 var expectedServerError, expectedClientError string
2879 serverCipherSuites := []uint16{suite.id}
2880 if shouldServerFail {
2881 expectedServerError = ":NO_SHARED_CIPHER:"
2882 }
2883 if shouldClientFail {
2884 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2885 // Configure the server to select ciphers as normal but
2886 // select an incompatible cipher in ServerHello.
2887 serverCipherSuites = nil
2888 sendCipherSuite = suite.id
2889 }
2890
David Benjamincdb6fe92017-02-07 16:06:48 -05002891 // For cipher suites and versions where exporters are defined, verify
2892 // that they interoperate.
2893 var exportKeyingMaterial int
2894 if ver.version > VersionSSL30 {
2895 exportKeyingMaterial = 1024
2896 }
2897
David Benjaminaa012042016-12-10 13:33:05 -05002898 testCases = append(testCases, testCase{
2899 testType: serverTest,
2900 protocol: protocol,
2901 name: prefix + ver.name + "-" + suite.name + "-server",
2902 config: Config{
2903 MinVersion: ver.version,
2904 MaxVersion: ver.version,
2905 CipherSuites: []uint16{suite.id},
2906 Certificates: []Certificate{cert},
2907 PreSharedKey: []byte(psk),
2908 PreSharedKeyIdentity: pskIdentity,
2909 Bugs: ProtocolBugs{
2910 AdvertiseAllConfiguredCiphers: true,
2911 },
2912 },
David Benjamina5022392017-07-10 17:40:39 -04002913 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002914 certFile: certFile,
2915 keyFile: keyFile,
2916 flags: flags,
2917 resumeSession: true,
2918 shouldFail: shouldServerFail,
2919 expectedError: expectedServerError,
2920 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002921 })
2922
2923 testCases = append(testCases, testCase{
2924 testType: clientTest,
2925 protocol: protocol,
2926 name: prefix + ver.name + "-" + suite.name + "-client",
2927 config: Config{
2928 MinVersion: ver.version,
2929 MaxVersion: ver.version,
2930 CipherSuites: serverCipherSuites,
2931 Certificates: []Certificate{cert},
2932 PreSharedKey: []byte(psk),
2933 PreSharedKeyIdentity: pskIdentity,
2934 Bugs: ProtocolBugs{
2935 IgnorePeerCipherPreferences: shouldClientFail,
2936 SendCipherSuite: sendCipherSuite,
2937 },
2938 },
David Benjamina5022392017-07-10 17:40:39 -04002939 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002940 flags: flags,
2941 resumeSession: true,
2942 shouldFail: shouldClientFail,
2943 expectedError: expectedClientError,
2944 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002945 })
2946
David Benjamin6f600d62016-12-21 16:06:54 -05002947 if shouldClientFail {
2948 return
2949 }
2950
2951 // Ensure the maximum record size is accepted.
2952 testCases = append(testCases, testCase{
2953 protocol: protocol,
2954 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2955 config: Config{
2956 MinVersion: ver.version,
2957 MaxVersion: ver.version,
2958 CipherSuites: []uint16{suite.id},
2959 Certificates: []Certificate{cert},
2960 PreSharedKey: []byte(psk),
2961 PreSharedKeyIdentity: pskIdentity,
2962 },
David Benjamina5022392017-07-10 17:40:39 -04002963 tls13Variant: ver.tls13Variant,
2964 flags: flags,
2965 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002966 })
2967
2968 // Test bad records for all ciphers. Bad records are fatal in TLS
2969 // and ignored in DTLS.
2970 var shouldFail bool
2971 var expectedError string
2972 if protocol == tls {
2973 shouldFail = true
2974 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2975 }
2976
2977 testCases = append(testCases, testCase{
2978 protocol: protocol,
2979 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2980 config: Config{
2981 MinVersion: ver.version,
2982 MaxVersion: ver.version,
2983 CipherSuites: []uint16{suite.id},
2984 Certificates: []Certificate{cert},
2985 PreSharedKey: []byte(psk),
2986 PreSharedKeyIdentity: pskIdentity,
2987 },
David Benjamina5022392017-07-10 17:40:39 -04002988 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05002989 flags: flags,
2990 damageFirstWrite: true,
2991 messageLen: maxPlaintext,
2992 shouldFail: shouldFail,
2993 expectedError: expectedError,
2994 })
David Benjaminaa012042016-12-10 13:33:05 -05002995}
2996
Adam Langley95c29f32014-06-20 12:00:00 -07002997func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002998 const bogusCipher = 0xfe00
2999
Adam Langley95c29f32014-06-20 12:00:00 -07003000 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07003001 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04003002 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05003003 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07003004 }
David Benjamin2c99d282015-09-01 10:23:00 -04003005 }
Adam Langley95c29f32014-06-20 12:00:00 -07003006 }
Adam Langleya7997f12015-05-14 17:38:50 -07003007
3008 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003009 name: "NoSharedCipher",
3010 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003011 MaxVersion: VersionTLS12,
3012 CipherSuites: []uint16{},
3013 },
3014 shouldFail: true,
3015 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3016 })
3017
3018 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003019 name: "NoSharedCipher-TLS13",
3020 config: Config{
3021 MaxVersion: VersionTLS13,
3022 CipherSuites: []uint16{},
3023 },
3024 shouldFail: true,
3025 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3026 })
3027
3028 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003029 name: "UnsupportedCipherSuite",
3030 config: Config{
3031 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003032 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003033 Bugs: ProtocolBugs{
3034 IgnorePeerCipherPreferences: true,
3035 },
3036 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003037 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003038 shouldFail: true,
3039 expectedError: ":WRONG_CIPHER_RETURNED:",
3040 })
3041
3042 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003043 name: "ServerHelloBogusCipher",
3044 config: Config{
3045 MaxVersion: VersionTLS12,
3046 Bugs: ProtocolBugs{
3047 SendCipherSuite: bogusCipher,
3048 },
3049 },
3050 shouldFail: true,
3051 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3052 })
3053 testCases = append(testCases, testCase{
3054 name: "ServerHelloBogusCipher-TLS13",
3055 config: Config{
3056 MaxVersion: VersionTLS13,
3057 Bugs: ProtocolBugs{
3058 SendCipherSuite: bogusCipher,
3059 },
3060 },
3061 shouldFail: true,
3062 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3063 })
3064
David Benjamin241ae832016-01-15 03:04:54 -05003065 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003066 testCases = append(testCases, testCase{
3067 testType: serverTest,
3068 name: "UnknownCipher",
3069 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003070 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003071 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003072 Bugs: ProtocolBugs{
3073 AdvertiseAllConfiguredCiphers: true,
3074 },
3075 },
3076 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003077
3078 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003079 testCases = append(testCases, testCase{
3080 testType: serverTest,
3081 name: "UnknownCipher-TLS13",
3082 config: Config{
3083 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003084 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003085 Bugs: ProtocolBugs{
3086 AdvertiseAllConfiguredCiphers: true,
3087 },
David Benjamin241ae832016-01-15 03:04:54 -05003088 },
3089 })
3090
David Benjamin78679342016-09-16 19:42:05 -04003091 // Test empty ECDHE_PSK identity hints work as expected.
3092 testCases = append(testCases, testCase{
3093 name: "EmptyECDHEPSKHint",
3094 config: Config{
3095 MaxVersion: VersionTLS12,
3096 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3097 PreSharedKey: []byte("secret"),
3098 },
3099 flags: []string{"-psk", "secret"},
3100 })
3101
3102 // Test empty PSK identity hints work as expected, even if an explicit
3103 // ServerKeyExchange is sent.
3104 testCases = append(testCases, testCase{
3105 name: "ExplicitEmptyPSKHint",
3106 config: Config{
3107 MaxVersion: VersionTLS12,
3108 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3109 PreSharedKey: []byte("secret"),
3110 Bugs: ProtocolBugs{
3111 AlwaysSendPreSharedKeyIdentityHint: true,
3112 },
3113 },
3114 flags: []string{"-psk", "secret"},
3115 })
David Benjamin69522112017-03-28 15:38:29 -05003116
3117 // Test that clients enforce that the server-sent certificate and cipher
3118 // suite match in TLS 1.2.
3119 testCases = append(testCases, testCase{
3120 name: "CertificateCipherMismatch-RSA",
3121 config: Config{
3122 MaxVersion: VersionTLS12,
3123 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3124 Certificates: []Certificate{rsaCertificate},
3125 Bugs: ProtocolBugs{
3126 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3127 },
3128 },
3129 shouldFail: true,
3130 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3131 })
3132 testCases = append(testCases, testCase{
3133 name: "CertificateCipherMismatch-ECDSA",
3134 config: Config{
3135 MaxVersion: VersionTLS12,
3136 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3137 Certificates: []Certificate{ecdsaP256Certificate},
3138 Bugs: ProtocolBugs{
3139 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3140 },
3141 },
3142 shouldFail: true,
3143 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3144 })
3145 testCases = append(testCases, testCase{
3146 name: "CertificateCipherMismatch-Ed25519",
3147 config: Config{
3148 MaxVersion: VersionTLS12,
3149 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3150 Certificates: []Certificate{ed25519Certificate},
3151 Bugs: ProtocolBugs{
3152 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3153 },
3154 },
3155 shouldFail: true,
3156 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3157 })
3158
3159 // Test that servers decline to select a cipher suite which is
3160 // inconsistent with their configured certificate.
3161 testCases = append(testCases, testCase{
3162 testType: serverTest,
3163 name: "ServerCipherFilter-RSA",
3164 config: Config{
3165 MaxVersion: VersionTLS12,
3166 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3167 },
3168 flags: []string{
3169 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3170 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3171 },
3172 shouldFail: true,
3173 expectedError: ":NO_SHARED_CIPHER:",
3174 })
3175 testCases = append(testCases, testCase{
3176 testType: serverTest,
3177 name: "ServerCipherFilter-ECDSA",
3178 config: Config{
3179 MaxVersion: VersionTLS12,
3180 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3181 },
3182 flags: []string{
3183 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3184 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3185 },
3186 shouldFail: true,
3187 expectedError: ":NO_SHARED_CIPHER:",
3188 })
3189 testCases = append(testCases, testCase{
3190 testType: serverTest,
3191 name: "ServerCipherFilter-Ed25519",
3192 config: Config{
3193 MaxVersion: VersionTLS12,
3194 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3195 },
3196 flags: []string{
3197 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3198 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3199 },
3200 shouldFail: true,
3201 expectedError: ":NO_SHARED_CIPHER:",
3202 })
David Benjamin364af782017-07-01 10:35:27 -04003203
3204 // Test cipher suite negotiation works as expected. Configure a
3205 // complicated cipher suite configuration.
3206 const negotiationTestCiphers = "" +
3207 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3208 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3209 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3210 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3211 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3212 negotiationTests := []struct {
3213 ciphers []uint16
3214 expected uint16
3215 }{
3216 // Server preferences are honored, including when
3217 // equipreference groups are involved.
3218 {
3219 []uint16{
3220 TLS_RSA_WITH_AES_256_GCM_SHA384,
3221 TLS_RSA_WITH_AES_128_CBC_SHA,
3222 TLS_RSA_WITH_AES_128_GCM_SHA256,
3223 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3224 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3225 },
3226 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3227 },
3228 {
3229 []uint16{
3230 TLS_RSA_WITH_AES_256_GCM_SHA384,
3231 TLS_RSA_WITH_AES_128_CBC_SHA,
3232 TLS_RSA_WITH_AES_128_GCM_SHA256,
3233 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3234 },
3235 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3236 },
3237 {
3238 []uint16{
3239 TLS_RSA_WITH_AES_256_GCM_SHA384,
3240 TLS_RSA_WITH_AES_128_CBC_SHA,
3241 TLS_RSA_WITH_AES_128_GCM_SHA256,
3242 },
3243 TLS_RSA_WITH_AES_128_GCM_SHA256,
3244 },
3245 {
3246 []uint16{
3247 TLS_RSA_WITH_AES_256_GCM_SHA384,
3248 TLS_RSA_WITH_AES_128_CBC_SHA,
3249 },
3250 TLS_RSA_WITH_AES_128_CBC_SHA,
3251 },
3252 // Equipreference groups use the client preference.
3253 {
3254 []uint16{
3255 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3256 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3257 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3258 },
3259 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3260 },
3261 {
3262 []uint16{
3263 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3264 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3265 },
3266 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3267 },
3268 {
3269 []uint16{
3270 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3271 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3272 },
3273 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3274 },
3275 {
3276 []uint16{
3277 TLS_RSA_WITH_AES_256_GCM_SHA384,
3278 TLS_RSA_WITH_AES_256_CBC_SHA,
3279 },
3280 TLS_RSA_WITH_AES_256_GCM_SHA384,
3281 },
3282 {
3283 []uint16{
3284 TLS_RSA_WITH_AES_256_CBC_SHA,
3285 TLS_RSA_WITH_AES_256_GCM_SHA384,
3286 },
3287 TLS_RSA_WITH_AES_256_CBC_SHA,
3288 },
3289 // If there are two equipreference groups, the preferred one
3290 // takes precedence.
3291 {
3292 []uint16{
3293 TLS_RSA_WITH_AES_256_GCM_SHA384,
3294 TLS_RSA_WITH_AES_256_CBC_SHA,
3295 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3296 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3297 },
3298 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3299 },
3300 }
3301 for i, t := range negotiationTests {
3302 testCases = append(testCases, testCase{
3303 testType: serverTest,
3304 name: "CipherNegotiation-" + strconv.Itoa(i),
3305 config: Config{
3306 MaxVersion: VersionTLS12,
3307 CipherSuites: t.ciphers,
3308 },
3309 flags: []string{"-cipher", negotiationTestCiphers},
3310 expectedCipher: t.expected,
3311 })
3312 }
Adam Langley95c29f32014-06-20 12:00:00 -07003313}
3314
3315func addBadECDSASignatureTests() {
3316 for badR := BadValue(1); badR < NumBadValues; badR++ {
3317 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003318 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003319 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3320 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003321 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003322 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003323 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003324 Bugs: ProtocolBugs{
3325 BadECDSAR: badR,
3326 BadECDSAS: badS,
3327 },
3328 },
3329 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003330 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003331 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003332 testCases = append(testCases, testCase{
3333 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3334 config: Config{
3335 MaxVersion: VersionTLS13,
3336 Certificates: []Certificate{ecdsaP256Certificate},
3337 Bugs: ProtocolBugs{
3338 BadECDSAR: badR,
3339 BadECDSAS: badS,
3340 },
3341 },
3342 shouldFail: true,
3343 expectedError: ":BAD_SIGNATURE:",
3344 })
Adam Langley95c29f32014-06-20 12:00:00 -07003345 }
3346 }
3347}
3348
Adam Langley80842bd2014-06-20 12:00:00 -07003349func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003350 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003351 name: "MaxCBCPadding",
3352 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003353 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003354 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3355 Bugs: ProtocolBugs{
3356 MaxPadding: true,
3357 },
3358 },
3359 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3360 })
David Benjamin025b3d32014-07-01 19:53:04 -04003361 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003362 name: "BadCBCPadding",
3363 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003364 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003365 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3366 Bugs: ProtocolBugs{
3367 PaddingFirstByteBad: true,
3368 },
3369 },
3370 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003371 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003372 })
3373 // OpenSSL previously had an issue where the first byte of padding in
3374 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003375 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003376 name: "BadCBCPadding255",
3377 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003378 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003379 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3380 Bugs: ProtocolBugs{
3381 MaxPadding: true,
3382 PaddingFirstByteBadIf255: true,
3383 },
3384 },
3385 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3386 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003387 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003388 })
3389}
3390
Kenny Root7fdeaf12014-08-05 15:23:37 -07003391func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003392 var cbcCiphers = []struct {
3393 name string
3394 cipher uint16
3395 }{
3396 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3397 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3398 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3399 }
3400 for _, t := range cbcCiphers {
3401 testCases = append(testCases, testCase{
3402 name: "CBCRecordSplitting-" + t.name,
3403 config: Config{
3404 MaxVersion: VersionTLS10,
3405 MinVersion: VersionTLS10,
3406 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003407 Bugs: ProtocolBugs{
3408 ExpectRecordSplitting: true,
3409 },
David Benjamina1ce8562017-07-01 11:46:57 -04003410 },
3411 messageLen: -1, // read until EOF
3412 resumeSession: true,
3413 flags: []string{
3414 "-async",
3415 "-write-different-record-sizes",
3416 "-cbc-record-splitting",
3417 },
3418 })
3419 testCases = append(testCases, testCase{
3420 name: "CBCRecordSplittingPartialWrite-" + t.name,
3421 config: Config{
3422 MaxVersion: VersionTLS10,
3423 MinVersion: VersionTLS10,
3424 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003425 Bugs: ProtocolBugs{
3426 ExpectRecordSplitting: true,
3427 },
David Benjamina1ce8562017-07-01 11:46:57 -04003428 },
3429 messageLen: -1, // read until EOF
3430 flags: []string{
3431 "-async",
3432 "-write-different-record-sizes",
3433 "-cbc-record-splitting",
3434 "-partial-write",
3435 },
3436 })
3437 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003438}
3439
David Benjamin636293b2014-07-08 17:59:18 -04003440func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003441 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003442 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003443 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3444 cert, err := x509.ParseCertificate(cert.Certificate[0])
3445 if err != nil {
3446 panic(err)
3447 }
3448 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003449 }
Adam Langley2ff79332017-02-28 13:45:39 -08003450 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003451
David Benjamin636293b2014-07-08 17:59:18 -04003452 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003453 testCases = append(testCases, testCase{
3454 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003455 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003456 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003457 MinVersion: ver.version,
3458 MaxVersion: ver.version,
3459 ClientAuth: RequireAnyClientCert,
3460 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003461 },
David Benjamina5022392017-07-10 17:40:39 -04003462 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003463 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003464 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3465 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003466 },
3467 })
3468 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003469 testType: serverTest,
3470 name: ver.name + "-Server-ClientAuth-RSA",
3471 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003472 MinVersion: ver.version,
3473 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003474 Certificates: []Certificate{rsaCertificate},
3475 },
David Benjamina5022392017-07-10 17:40:39 -04003476 tls13Variant: ver.tls13Variant,
3477 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003478 })
David Benjamine098ec22014-08-27 23:13:20 -04003479 if ver.version != VersionSSL30 {
3480 testCases = append(testCases, testCase{
3481 testType: serverTest,
3482 name: ver.name + "-Server-ClientAuth-ECDSA",
3483 config: Config{
3484 MinVersion: ver.version,
3485 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003486 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003487 },
David Benjamina5022392017-07-10 17:40:39 -04003488 tls13Variant: ver.tls13Variant,
3489 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003490 })
3491 testCases = append(testCases, testCase{
3492 testType: clientTest,
3493 name: ver.name + "-Client-ClientAuth-ECDSA",
3494 config: Config{
3495 MinVersion: ver.version,
3496 MaxVersion: ver.version,
3497 ClientAuth: RequireAnyClientCert,
3498 ClientCAs: certPool,
3499 },
David Benjamina5022392017-07-10 17:40:39 -04003500 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003501 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003502 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3503 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003504 },
3505 })
3506 }
Adam Langley37646832016-08-01 16:16:46 -07003507
3508 testCases = append(testCases, testCase{
3509 name: "NoClientCertificate-" + ver.name,
3510 config: Config{
3511 MinVersion: ver.version,
3512 MaxVersion: ver.version,
3513 ClientAuth: RequireAnyClientCert,
3514 },
David Benjamina5022392017-07-10 17:40:39 -04003515 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003516 shouldFail: true,
3517 expectedLocalError: "client didn't provide a certificate",
3518 })
3519
3520 testCases = append(testCases, testCase{
3521 // Even if not configured to expect a certificate, OpenSSL will
3522 // return X509_V_OK as the verify_result.
3523 testType: serverTest,
3524 name: "NoClientCertificateRequested-Server-" + ver.name,
3525 config: Config{
3526 MinVersion: ver.version,
3527 MaxVersion: ver.version,
3528 },
David Benjamina5022392017-07-10 17:40:39 -04003529 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003530 flags: []string{
3531 "-expect-verify-result",
3532 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003533 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003534 })
3535
3536 testCases = append(testCases, testCase{
3537 // If a client certificate is not provided, OpenSSL will still
3538 // return X509_V_OK as the verify_result.
3539 testType: serverTest,
3540 name: "NoClientCertificate-Server-" + ver.name,
3541 config: Config{
3542 MinVersion: ver.version,
3543 MaxVersion: ver.version,
3544 },
David Benjamina5022392017-07-10 17:40:39 -04003545 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003546 flags: []string{
3547 "-expect-verify-result",
3548 "-verify-peer",
3549 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003550 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003551 })
3552
David Benjamin1db9e1b2016-10-07 20:51:43 -04003553 certificateRequired := "remote error: certificate required"
3554 if ver.version < VersionTLS13 {
3555 // Prior to TLS 1.3, the generic handshake_failure alert
3556 // was used.
3557 certificateRequired = "remote error: handshake failure"
3558 }
Adam Langley37646832016-08-01 16:16:46 -07003559 testCases = append(testCases, testCase{
3560 testType: serverTest,
3561 name: "RequireAnyClientCertificate-" + ver.name,
3562 config: Config{
3563 MinVersion: ver.version,
3564 MaxVersion: ver.version,
3565 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003566 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003567 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003568 shouldFail: true,
3569 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3570 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003571 })
3572
3573 if ver.version != VersionSSL30 {
3574 testCases = append(testCases, testCase{
3575 testType: serverTest,
3576 name: "SkipClientCertificate-" + ver.name,
3577 config: Config{
3578 MinVersion: ver.version,
3579 MaxVersion: ver.version,
3580 Bugs: ProtocolBugs{
3581 SkipClientCertificate: true,
3582 },
3583 },
3584 // Setting SSL_VERIFY_PEER allows anonymous clients.
3585 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003586 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003587 shouldFail: true,
3588 expectedError: ":UNEXPECTED_MESSAGE:",
3589 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003590
3591 testCases = append(testCases, testCase{
3592 testType: serverTest,
3593 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3594 config: Config{
3595 MinVersion: ver.version,
3596 MaxVersion: ver.version,
3597 },
3598 flags: []string{
3599 "-enable-channel-id",
3600 "-verify-peer-if-no-obc",
3601 },
David Benjamina5022392017-07-10 17:40:39 -04003602 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003603 shouldFail: true,
3604 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3605 expectedLocalError: certificateRequired,
3606 })
3607
3608 testCases = append(testCases, testCase{
3609 testType: serverTest,
3610 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3611 config: Config{
3612 MinVersion: ver.version,
3613 MaxVersion: ver.version,
3614 ChannelID: channelIDKey,
3615 },
3616 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003617 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003618 flags: []string{
3619 "-enable-channel-id",
3620 "-verify-peer-if-no-obc",
3621 },
3622 })
Adam Langley37646832016-08-01 16:16:46 -07003623 }
Adam Langley2ff79332017-02-28 13:45:39 -08003624
3625 testCases = append(testCases, testCase{
3626 testType: serverTest,
3627 name: ver.name + "-Server-CertReq-CA-List",
3628 config: Config{
3629 MinVersion: ver.version,
3630 MaxVersion: ver.version,
3631 Certificates: []Certificate{rsaCertificate},
3632 Bugs: ProtocolBugs{
3633 ExpectCertificateReqNames: caNames,
3634 },
3635 },
David Benjamina5022392017-07-10 17:40:39 -04003636 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003637 flags: []string{
3638 "-require-any-client-certificate",
3639 "-use-client-ca-list", encodeDERValues(caNames),
3640 },
3641 })
3642
3643 testCases = append(testCases, testCase{
3644 testType: clientTest,
3645 name: ver.name + "-Client-CertReq-CA-List",
3646 config: Config{
3647 MinVersion: ver.version,
3648 MaxVersion: ver.version,
3649 Certificates: []Certificate{rsaCertificate},
3650 ClientAuth: RequireAnyClientCert,
3651 ClientCAs: certPool,
3652 },
David Benjamina5022392017-07-10 17:40:39 -04003653 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003654 flags: []string{
3655 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3656 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3657 "-expect-client-ca-list", encodeDERValues(caNames),
3658 },
3659 })
David Benjamin636293b2014-07-08 17:59:18 -04003660 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003661
David Benjaminc032dfa2016-05-12 14:54:57 -04003662 // Client auth is only legal in certificate-based ciphers.
3663 testCases = append(testCases, testCase{
3664 testType: clientTest,
3665 name: "ClientAuth-PSK",
3666 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003667 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003668 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3669 PreSharedKey: []byte("secret"),
3670 ClientAuth: RequireAnyClientCert,
3671 },
3672 flags: []string{
3673 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3674 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3675 "-psk", "secret",
3676 },
3677 shouldFail: true,
3678 expectedError: ":UNEXPECTED_MESSAGE:",
3679 })
3680 testCases = append(testCases, testCase{
3681 testType: clientTest,
3682 name: "ClientAuth-ECDHE_PSK",
3683 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003684 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003685 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3686 PreSharedKey: []byte("secret"),
3687 ClientAuth: RequireAnyClientCert,
3688 },
3689 flags: []string{
3690 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3691 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3692 "-psk", "secret",
3693 },
3694 shouldFail: true,
3695 expectedError: ":UNEXPECTED_MESSAGE:",
3696 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003697
3698 // Regression test for a bug where the client CA list, if explicitly
3699 // set to NULL, was mis-encoded.
3700 testCases = append(testCases, testCase{
3701 testType: serverTest,
3702 name: "Null-Client-CA-List",
3703 config: Config{
3704 MaxVersion: VersionTLS12,
3705 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003706 Bugs: ProtocolBugs{
3707 ExpectCertificateReqNames: [][]byte{},
3708 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003709 },
3710 flags: []string{
3711 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003712 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003713 },
3714 })
David Benjamin636293b2014-07-08 17:59:18 -04003715}
3716
Adam Langley75712922014-10-10 16:23:43 -07003717func addExtendedMasterSecretTests() {
3718 const expectEMSFlag = "-expect-extended-master-secret"
3719
3720 for _, with := range []bool{false, true} {
3721 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003722 if with {
3723 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003724 }
3725
3726 for _, isClient := range []bool{false, true} {
3727 suffix := "-Server"
3728 testType := serverTest
3729 if isClient {
3730 suffix = "-Client"
3731 testType = clientTest
3732 }
3733
3734 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003735 // In TLS 1.3, the extension is irrelevant and
3736 // always reports as enabled.
3737 var flags []string
3738 if with || ver.version >= VersionTLS13 {
3739 flags = []string{expectEMSFlag}
3740 }
3741
Adam Langley75712922014-10-10 16:23:43 -07003742 test := testCase{
3743 testType: testType,
3744 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3745 config: Config{
3746 MinVersion: ver.version,
3747 MaxVersion: ver.version,
3748 Bugs: ProtocolBugs{
3749 NoExtendedMasterSecret: !with,
3750 RequireExtendedMasterSecret: with,
3751 },
3752 },
David Benjamina5022392017-07-10 17:40:39 -04003753 tls13Variant: ver.tls13Variant,
3754 flags: flags,
3755 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003756 }
3757 if test.shouldFail {
3758 test.expectedLocalError = "extended master secret required but not supported by peer"
3759 }
3760 testCases = append(testCases, test)
3761 }
3762 }
3763 }
3764
Adam Langleyba5934b2015-06-02 10:50:35 -07003765 for _, isClient := range []bool{false, true} {
3766 for _, supportedInFirstConnection := range []bool{false, true} {
3767 for _, supportedInResumeConnection := range []bool{false, true} {
3768 boolToWord := func(b bool) string {
3769 if b {
3770 return "Yes"
3771 }
3772 return "No"
3773 }
3774 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3775 if isClient {
3776 suffix += "Client"
3777 } else {
3778 suffix += "Server"
3779 }
3780
3781 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003782 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003783 Bugs: ProtocolBugs{
3784 RequireExtendedMasterSecret: true,
3785 },
3786 }
3787
3788 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003789 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003790 Bugs: ProtocolBugs{
3791 NoExtendedMasterSecret: true,
3792 },
3793 }
3794
3795 test := testCase{
3796 name: "ExtendedMasterSecret-" + suffix,
3797 resumeSession: true,
3798 }
3799
3800 if !isClient {
3801 test.testType = serverTest
3802 }
3803
3804 if supportedInFirstConnection {
3805 test.config = supportedConfig
3806 } else {
3807 test.config = noSupportConfig
3808 }
3809
3810 if supportedInResumeConnection {
3811 test.resumeConfig = &supportedConfig
3812 } else {
3813 test.resumeConfig = &noSupportConfig
3814 }
3815
3816 switch suffix {
3817 case "YesToYes-Client", "YesToYes-Server":
3818 // When a session is resumed, it should
3819 // still be aware that its master
3820 // secret was generated via EMS and
3821 // thus it's safe to use tls-unique.
3822 test.flags = []string{expectEMSFlag}
3823 case "NoToYes-Server":
3824 // If an original connection did not
3825 // contain EMS, but a resumption
3826 // handshake does, then a server should
3827 // not resume the session.
3828 test.expectResumeRejected = true
3829 case "YesToNo-Server":
3830 // Resuming an EMS session without the
3831 // EMS extension should cause the
3832 // server to abort the connection.
3833 test.shouldFail = true
3834 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3835 case "NoToYes-Client":
3836 // A client should abort a connection
3837 // where the server resumed a non-EMS
3838 // session but echoed the EMS
3839 // extension.
3840 test.shouldFail = true
3841 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3842 case "YesToNo-Client":
3843 // A client should abort a connection
3844 // where the server didn't echo EMS
3845 // when the session used it.
3846 test.shouldFail = true
3847 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3848 }
3849
3850 testCases = append(testCases, test)
3851 }
3852 }
3853 }
David Benjamin163c9562016-08-29 23:14:17 -04003854
3855 // Switching EMS on renegotiation is forbidden.
3856 testCases = append(testCases, testCase{
3857 name: "ExtendedMasterSecret-Renego-NoEMS",
3858 config: Config{
3859 MaxVersion: VersionTLS12,
3860 Bugs: ProtocolBugs{
3861 NoExtendedMasterSecret: true,
3862 NoExtendedMasterSecretOnRenegotiation: true,
3863 },
3864 },
3865 renegotiate: 1,
3866 flags: []string{
3867 "-renegotiate-freely",
3868 "-expect-total-renegotiations", "1",
3869 },
3870 })
3871
3872 testCases = append(testCases, testCase{
3873 name: "ExtendedMasterSecret-Renego-Upgrade",
3874 config: Config{
3875 MaxVersion: VersionTLS12,
3876 Bugs: ProtocolBugs{
3877 NoExtendedMasterSecret: true,
3878 },
3879 },
3880 renegotiate: 1,
3881 flags: []string{
3882 "-renegotiate-freely",
3883 "-expect-total-renegotiations", "1",
3884 },
3885 shouldFail: true,
3886 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3887 })
3888
3889 testCases = append(testCases, testCase{
3890 name: "ExtendedMasterSecret-Renego-Downgrade",
3891 config: Config{
3892 MaxVersion: VersionTLS12,
3893 Bugs: ProtocolBugs{
3894 NoExtendedMasterSecretOnRenegotiation: true,
3895 },
3896 },
3897 renegotiate: 1,
3898 flags: []string{
3899 "-renegotiate-freely",
3900 "-expect-total-renegotiations", "1",
3901 },
3902 shouldFail: true,
3903 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3904 })
Adam Langley75712922014-10-10 16:23:43 -07003905}
3906
David Benjamin582ba042016-07-07 12:33:25 -07003907type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003908 protocol protocol
3909 async bool
3910 splitHandshake bool
3911 packHandshakeFlight bool
3912 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003913}
3914
David Benjamin43ec06f2014-08-05 02:28:57 -04003915// Adds tests that try to cover the range of the handshake state machine, under
3916// various conditions. Some of these are redundant with other tests, but they
3917// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003918func addAllStateMachineCoverageTests() {
3919 for _, async := range []bool{false, true} {
3920 for _, protocol := range []protocol{tls, dtls} {
3921 addStateMachineCoverageTests(stateMachineTestConfig{
3922 protocol: protocol,
3923 async: async,
3924 })
3925 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003926 protocol: protocol,
3927 async: async,
3928 implicitHandshake: true,
3929 })
3930 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003931 protocol: protocol,
3932 async: async,
3933 splitHandshake: true,
3934 })
3935 if protocol == tls {
3936 addStateMachineCoverageTests(stateMachineTestConfig{
3937 protocol: protocol,
3938 async: async,
3939 packHandshakeFlight: true,
3940 })
3941 }
3942 }
3943 }
3944}
3945
3946func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003947 var tests []testCase
3948
3949 // Basic handshake, with resumption. Client and server,
3950 // session ID and session ticket.
3951 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003952 name: "Basic-Client",
3953 config: Config{
3954 MaxVersion: VersionTLS12,
3955 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003956 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003957 // Ensure session tickets are used, not session IDs.
3958 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003959 })
3960 tests = append(tests, testCase{
3961 name: "Basic-Client-RenewTicket",
3962 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003963 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003964 Bugs: ProtocolBugs{
3965 RenewTicketOnResume: true,
3966 },
3967 },
David Benjamin46662482016-08-17 00:51:00 -04003968 flags: []string{"-expect-ticket-renewal"},
3969 resumeSession: true,
3970 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003971 })
3972 tests = append(tests, testCase{
3973 name: "Basic-Client-NoTicket",
3974 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003975 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003976 SessionTicketsDisabled: true,
3977 },
3978 resumeSession: true,
3979 })
3980 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003981 testType: serverTest,
3982 name: "Basic-Server",
3983 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003984 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003985 Bugs: ProtocolBugs{
3986 RequireSessionTickets: true,
3987 },
3988 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003989 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003990 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003991 })
3992 tests = append(tests, testCase{
3993 testType: serverTest,
3994 name: "Basic-Server-NoTickets",
3995 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003996 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003997 SessionTicketsDisabled: true,
3998 },
3999 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004000 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004001 })
4002 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004003 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004004 name: "Basic-Server-EarlyCallback",
4005 config: Config{
4006 MaxVersion: VersionTLS12,
4007 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004008 flags: []string{"-use-early-callback"},
4009 resumeSession: true,
4010 })
4011
Steven Valdez143e8b32016-07-11 13:19:03 -04004012 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004013 if config.protocol == tls {
4014 tests = append(tests, testCase{
4015 name: "TLS13-1RTT-Client",
4016 config: Config{
4017 MaxVersion: VersionTLS13,
4018 MinVersion: VersionTLS13,
4019 },
David Benjamin46662482016-08-17 00:51:00 -04004020 resumeSession: true,
4021 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004022 })
4023
4024 tests = append(tests, testCase{
4025 testType: serverTest,
4026 name: "TLS13-1RTT-Server",
4027 config: Config{
4028 MaxVersion: VersionTLS13,
4029 MinVersion: VersionTLS13,
4030 },
David Benjamin46662482016-08-17 00:51:00 -04004031 resumeSession: true,
4032 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004033 // TLS 1.3 uses tickets, so the session should not be
4034 // cached statefully.
4035 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004036 })
4037
4038 tests = append(tests, testCase{
4039 name: "TLS13-HelloRetryRequest-Client",
4040 config: Config{
4041 MaxVersion: VersionTLS13,
4042 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004043 // P-384 requires a HelloRetryRequest against BoringSSL's default
4044 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004045 CurvePreferences: []CurveID{CurveP384},
4046 Bugs: ProtocolBugs{
4047 ExpectMissingKeyShare: true,
4048 },
4049 },
4050 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4051 resumeSession: true,
4052 })
4053
4054 tests = append(tests, testCase{
4055 testType: serverTest,
4056 name: "TLS13-HelloRetryRequest-Server",
4057 config: Config{
4058 MaxVersion: VersionTLS13,
4059 MinVersion: VersionTLS13,
4060 // Require a HelloRetryRequest for every curve.
4061 DefaultCurves: []CurveID{},
4062 },
4063 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4064 resumeSession: true,
4065 })
Steven Valdez2d850622017-01-11 11:34:52 -05004066
Steven Valdez2d850622017-01-11 11:34:52 -05004067 tests = append(tests, testCase{
4068 testType: clientTest,
4069 name: "TLS13-EarlyData-Client",
4070 config: Config{
4071 MaxVersion: VersionTLS13,
4072 MinVersion: VersionTLS13,
4073 MaxEarlyDataSize: 16384,
4074 },
Steven Valdeze831a812017-03-09 14:56:07 -05004075 resumeConfig: &Config{
4076 MaxVersion: VersionTLS13,
4077 MinVersion: VersionTLS13,
4078 MaxEarlyDataSize: 16384,
4079 Bugs: ProtocolBugs{
4080 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4081 },
4082 },
Steven Valdez2d850622017-01-11 11:34:52 -05004083 resumeSession: true,
4084 flags: []string{
4085 "-enable-early-data",
4086 "-expect-early-data-info",
4087 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004088 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004089 },
4090 })
4091
4092 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004093 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004094 name: "TLS13Experiment-EarlyData-Client",
4095 config: Config{
4096 MaxVersion: VersionTLS13,
4097 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004098 MaxEarlyDataSize: 16384,
4099 },
4100 resumeConfig: &Config{
4101 MaxVersion: VersionTLS13,
4102 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004103 MaxEarlyDataSize: 16384,
4104 Bugs: ProtocolBugs{
4105 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4106 },
4107 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004108 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004109 resumeSession: true,
4110 flags: []string{
4111 "-enable-early-data",
4112 "-expect-early-data-info",
4113 "-expect-accept-early-data",
4114 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004115 },
4116 })
4117
4118 tests = append(tests, testCase{
4119 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004120 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4121 config: Config{
4122 MaxVersion: VersionTLS13,
4123 MinVersion: VersionTLS13,
4124 TLS13Variant: TLS13RecordTypeExperiment,
4125 MaxEarlyDataSize: 16384,
4126 },
4127 resumeConfig: &Config{
4128 MaxVersion: VersionTLS13,
4129 MinVersion: VersionTLS13,
4130 TLS13Variant: TLS13RecordTypeExperiment,
4131 MaxEarlyDataSize: 16384,
4132 Bugs: ProtocolBugs{
4133 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4134 },
4135 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004136 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004137 resumeSession: true,
4138 flags: []string{
4139 "-enable-early-data",
4140 "-expect-early-data-info",
4141 "-expect-accept-early-data",
4142 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004143 },
4144 })
4145
4146 tests = append(tests, testCase{
4147 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004148 name: "TLS13-EarlyData-TooMuchData-Client",
4149 config: Config{
4150 MaxVersion: VersionTLS13,
4151 MinVersion: VersionTLS13,
4152 MaxEarlyDataSize: 2,
4153 },
4154 resumeConfig: &Config{
4155 MaxVersion: VersionTLS13,
4156 MinVersion: VersionTLS13,
4157 MaxEarlyDataSize: 2,
4158 Bugs: ProtocolBugs{
4159 ExpectEarlyData: [][]byte{{'h', 'e'}},
4160 },
4161 },
4162 resumeShimPrefix: "llo",
4163 resumeSession: true,
4164 flags: []string{
4165 "-enable-early-data",
4166 "-expect-early-data-info",
4167 "-expect-accept-early-data",
4168 "-on-resume-shim-writes-first",
4169 },
4170 })
4171
4172 // Unfinished writes can only be tested when operations are async. EarlyData
4173 // can't be tested as part of an ImplicitHandshake in this case since
4174 // otherwise the early data will be sent as normal data.
4175 if config.async && !config.implicitHandshake {
4176 tests = append(tests, testCase{
4177 testType: clientTest,
4178 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4179 config: Config{
4180 MaxVersion: VersionTLS13,
4181 MinVersion: VersionTLS13,
4182 MaxEarlyDataSize: 16384,
4183 },
4184 resumeConfig: &Config{
4185 MaxVersion: VersionTLS13,
4186 MinVersion: VersionTLS13,
4187 MaxEarlyDataSize: 16384,
4188 Bugs: ProtocolBugs{
4189 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4190 },
4191 },
4192 resumeSession: true,
4193 flags: []string{
4194 "-enable-early-data",
4195 "-expect-early-data-info",
4196 "-expect-accept-early-data",
4197 "-on-resume-read-with-unfinished-write",
4198 "-on-resume-shim-writes-first",
4199 },
4200 })
4201
4202 // Rejected unfinished writes are discarded (from the
4203 // perspective of the calling application) on 0-RTT
4204 // reject.
4205 tests = append(tests, testCase{
4206 testType: clientTest,
4207 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4208 config: Config{
4209 MaxVersion: VersionTLS13,
4210 MinVersion: VersionTLS13,
4211 MaxEarlyDataSize: 16384,
4212 },
4213 resumeConfig: &Config{
4214 MaxVersion: VersionTLS13,
4215 MinVersion: VersionTLS13,
4216 MaxEarlyDataSize: 16384,
4217 Bugs: ProtocolBugs{
4218 AlwaysRejectEarlyData: true,
4219 },
4220 },
4221 resumeSession: true,
4222 flags: []string{
4223 "-enable-early-data",
4224 "-expect-early-data-info",
4225 "-expect-reject-early-data",
4226 "-on-resume-read-with-unfinished-write",
4227 "-on-resume-shim-writes-first",
4228 },
4229 })
4230 }
4231
4232 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004233 testType: serverTest,
4234 name: "TLS13-EarlyData-Server",
4235 config: Config{
4236 MaxVersion: VersionTLS13,
4237 MinVersion: VersionTLS13,
4238 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004239 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004240 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004241 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004242 },
4243 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004244 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004245 resumeSession: true,
4246 flags: []string{
4247 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004248 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004249 },
4250 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004251
4252 tests = append(tests, testCase{
4253 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004254 name: "TLS13Experiment-EarlyData-Server",
4255 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004256 MaxVersion: VersionTLS13,
4257 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004258 Bugs: ProtocolBugs{
4259 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4260 ExpectEarlyDataAccepted: true,
4261 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4262 },
4263 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004264 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004265 messageCount: 2,
4266 resumeSession: true,
4267 flags: []string{
4268 "-enable-early-data",
4269 "-expect-accept-early-data",
Steven Valdez520e1222017-06-13 12:45:25 -04004270 },
4271 })
4272
4273 tests = append(tests, testCase{
4274 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004275 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4276 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004277 MaxVersion: VersionTLS13,
4278 MinVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -04004279 Bugs: ProtocolBugs{
4280 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4281 ExpectEarlyDataAccepted: true,
4282 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4283 },
4284 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004285 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004286 messageCount: 2,
4287 resumeSession: true,
4288 flags: []string{
4289 "-enable-early-data",
4290 "-expect-accept-early-data",
Steven Valdezdbe01582017-07-14 10:39:28 -04004291 },
4292 })
4293
4294 tests = append(tests, testCase{
4295 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004296 name: "TLS13-MaxEarlyData-Server",
4297 config: Config{
4298 MaxVersion: VersionTLS13,
4299 MinVersion: VersionTLS13,
4300 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004301 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004302 ExpectEarlyDataAccepted: true,
4303 },
4304 },
4305 messageCount: 2,
4306 resumeSession: true,
4307 flags: []string{
4308 "-enable-early-data",
4309 "-expect-accept-early-data",
4310 },
4311 shouldFail: true,
4312 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4313 })
David Benjamine73c7f42016-08-17 00:29:33 -04004314 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004315
David Benjamin760b1dd2015-05-15 23:33:48 -04004316 // TLS client auth.
4317 tests = append(tests, testCase{
4318 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004319 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004321 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004322 ClientAuth: RequestClientCert,
4323 },
4324 })
4325 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004326 testType: serverTest,
4327 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004328 config: Config{
4329 MaxVersion: VersionTLS12,
4330 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004331 // Setting SSL_VERIFY_PEER allows anonymous clients.
4332 flags: []string{"-verify-peer"},
4333 })
David Benjamin582ba042016-07-07 12:33:25 -07004334 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004335 tests = append(tests, testCase{
4336 testType: clientTest,
4337 name: "ClientAuth-NoCertificate-Client-SSL3",
4338 config: Config{
4339 MaxVersion: VersionSSL30,
4340 ClientAuth: RequestClientCert,
4341 },
4342 })
4343 tests = append(tests, testCase{
4344 testType: serverTest,
4345 name: "ClientAuth-NoCertificate-Server-SSL3",
4346 config: Config{
4347 MaxVersion: VersionSSL30,
4348 },
4349 // Setting SSL_VERIFY_PEER allows anonymous clients.
4350 flags: []string{"-verify-peer"},
4351 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004352 tests = append(tests, testCase{
4353 testType: clientTest,
4354 name: "ClientAuth-NoCertificate-Client-TLS13",
4355 config: Config{
4356 MaxVersion: VersionTLS13,
4357 ClientAuth: RequestClientCert,
4358 },
4359 })
4360 tests = append(tests, testCase{
4361 testType: serverTest,
4362 name: "ClientAuth-NoCertificate-Server-TLS13",
4363 config: Config{
4364 MaxVersion: VersionTLS13,
4365 },
4366 // Setting SSL_VERIFY_PEER allows anonymous clients.
4367 flags: []string{"-verify-peer"},
4368 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004369 }
4370 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004371 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004372 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004374 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004375 ClientAuth: RequireAnyClientCert,
4376 },
4377 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004378 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4379 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004380 },
4381 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004382 tests = append(tests, testCase{
4383 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004384 name: "ClientAuth-RSA-Client-TLS13",
4385 config: Config{
4386 MaxVersion: VersionTLS13,
4387 ClientAuth: RequireAnyClientCert,
4388 },
4389 flags: []string{
4390 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4391 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4392 },
4393 })
4394 tests = append(tests, testCase{
4395 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004396 name: "ClientAuth-ECDSA-Client",
4397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004398 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004399 ClientAuth: RequireAnyClientCert,
4400 },
4401 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004402 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4403 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004404 },
4405 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004406 tests = append(tests, testCase{
4407 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004408 name: "ClientAuth-ECDSA-Client-TLS13",
4409 config: Config{
4410 MaxVersion: VersionTLS13,
4411 ClientAuth: RequireAnyClientCert,
4412 },
4413 flags: []string{
4414 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4415 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4416 },
4417 })
4418 tests = append(tests, testCase{
4419 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004420 name: "ClientAuth-NoCertificate-OldCallback",
4421 config: Config{
4422 MaxVersion: VersionTLS12,
4423 ClientAuth: RequestClientCert,
4424 },
4425 flags: []string{"-use-old-client-cert-callback"},
4426 })
4427 tests = append(tests, testCase{
4428 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004429 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4430 config: Config{
4431 MaxVersion: VersionTLS13,
4432 ClientAuth: RequestClientCert,
4433 },
4434 flags: []string{"-use-old-client-cert-callback"},
4435 })
4436 tests = append(tests, testCase{
4437 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004438 name: "ClientAuth-OldCallback",
4439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004440 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004441 ClientAuth: RequireAnyClientCert,
4442 },
4443 flags: []string{
4444 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4445 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4446 "-use-old-client-cert-callback",
4447 },
4448 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004449 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004450 testType: clientTest,
4451 name: "ClientAuth-OldCallback-TLS13",
4452 config: Config{
4453 MaxVersion: VersionTLS13,
4454 ClientAuth: RequireAnyClientCert,
4455 },
4456 flags: []string{
4457 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4458 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4459 "-use-old-client-cert-callback",
4460 },
4461 })
4462 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004463 testType: serverTest,
4464 name: "ClientAuth-Server",
4465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004466 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004467 Certificates: []Certificate{rsaCertificate},
4468 },
4469 flags: []string{"-require-any-client-certificate"},
4470 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004471 tests = append(tests, testCase{
4472 testType: serverTest,
4473 name: "ClientAuth-Server-TLS13",
4474 config: Config{
4475 MaxVersion: VersionTLS13,
4476 Certificates: []Certificate{rsaCertificate},
4477 },
4478 flags: []string{"-require-any-client-certificate"},
4479 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004480
David Benjamin4c3ddf72016-06-29 18:13:53 -04004481 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004482 tests = append(tests, testCase{
4483 testType: serverTest,
4484 name: "Basic-Server-RSA",
4485 config: Config{
4486 MaxVersion: VersionTLS12,
4487 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4488 },
4489 flags: []string{
4490 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4491 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4492 },
4493 })
4494 tests = append(tests, testCase{
4495 testType: serverTest,
4496 name: "Basic-Server-ECDHE-RSA",
4497 config: Config{
4498 MaxVersion: VersionTLS12,
4499 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4500 },
4501 flags: []string{
4502 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4503 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4504 },
4505 })
4506 tests = append(tests, testCase{
4507 testType: serverTest,
4508 name: "Basic-Server-ECDHE-ECDSA",
4509 config: Config{
4510 MaxVersion: VersionTLS12,
4511 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4512 },
4513 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004514 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4515 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004516 },
4517 })
David Benjamin69522112017-03-28 15:38:29 -05004518 tests = append(tests, testCase{
4519 testType: serverTest,
4520 name: "Basic-Server-Ed25519",
4521 config: Config{
4522 MaxVersion: VersionTLS12,
4523 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4524 },
4525 flags: []string{
4526 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4527 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4528 "-enable-ed25519",
4529 },
4530 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004531
David Benjamin760b1dd2015-05-15 23:33:48 -04004532 // No session ticket support; server doesn't send NewSessionTicket.
4533 tests = append(tests, testCase{
4534 name: "SessionTicketsDisabled-Client",
4535 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004536 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004537 SessionTicketsDisabled: true,
4538 },
4539 })
4540 tests = append(tests, testCase{
4541 testType: serverTest,
4542 name: "SessionTicketsDisabled-Server",
4543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004544 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004545 SessionTicketsDisabled: true,
4546 },
4547 })
4548
4549 // Skip ServerKeyExchange in PSK key exchange if there's no
4550 // identity hint.
4551 tests = append(tests, testCase{
4552 name: "EmptyPSKHint-Client",
4553 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004554 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004555 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4556 PreSharedKey: []byte("secret"),
4557 },
4558 flags: []string{"-psk", "secret"},
4559 })
4560 tests = append(tests, testCase{
4561 testType: serverTest,
4562 name: "EmptyPSKHint-Server",
4563 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004564 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004565 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4566 PreSharedKey: []byte("secret"),
4567 },
4568 flags: []string{"-psk", "secret"},
4569 })
4570
David Benjamin4c3ddf72016-06-29 18:13:53 -04004571 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004572 tests = append(tests, testCase{
4573 testType: clientTest,
4574 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004575 config: Config{
4576 MaxVersion: VersionTLS12,
4577 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004578 flags: []string{
4579 "-enable-ocsp-stapling",
4580 "-expect-ocsp-response",
4581 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004582 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004583 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004584 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004585 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004586 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004587 testType: serverTest,
4588 name: "OCSPStapling-Server",
4589 config: Config{
4590 MaxVersion: VersionTLS12,
4591 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004592 expectedOCSPResponse: testOCSPResponse,
4593 flags: []string{
4594 "-ocsp-response",
4595 base64.StdEncoding.EncodeToString(testOCSPResponse),
4596 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004597 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004598 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004599 tests = append(tests, testCase{
4600 testType: clientTest,
4601 name: "OCSPStapling-Client-TLS13",
4602 config: Config{
4603 MaxVersion: VersionTLS13,
4604 },
4605 flags: []string{
4606 "-enable-ocsp-stapling",
4607 "-expect-ocsp-response",
4608 base64.StdEncoding.EncodeToString(testOCSPResponse),
4609 "-verify-peer",
4610 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004611 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004612 })
4613 tests = append(tests, testCase{
4614 testType: serverTest,
4615 name: "OCSPStapling-Server-TLS13",
4616 config: Config{
4617 MaxVersion: VersionTLS13,
4618 },
4619 expectedOCSPResponse: testOCSPResponse,
4620 flags: []string{
4621 "-ocsp-response",
4622 base64.StdEncoding.EncodeToString(testOCSPResponse),
4623 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004624 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004625 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004626
David Benjamin4c3ddf72016-06-29 18:13:53 -04004627 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004628 for _, vers := range tlsVersions {
4629 if config.protocol == dtls && !vers.hasDTLS {
4630 continue
4631 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004632 for _, useCustomCallback := range []bool{false, true} {
4633 for _, testType := range []testType{clientTest, serverTest} {
4634 suffix := "-Client"
4635 if testType == serverTest {
4636 suffix = "-Server"
4637 }
4638 suffix += "-" + vers.name
4639 if useCustomCallback {
4640 suffix += "-CustomCallback"
4641 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004642
David Benjamin3a1dd462017-07-11 16:13:10 -04004643 flags := []string{"-verify-peer"}
4644 if testType == serverTest {
4645 flags = append(flags, "-require-any-client-certificate")
4646 }
4647 if useCustomCallback {
4648 flags = append(flags, "-use-custom-verify-callback")
4649 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004650
David Benjamin3a1dd462017-07-11 16:13:10 -04004651 tests = append(tests, testCase{
4652 testType: testType,
4653 name: "CertificateVerificationSucceed" + suffix,
4654 config: Config{
4655 MaxVersion: vers.version,
4656 Certificates: []Certificate{rsaCertificate},
4657 },
4658 tls13Variant: vers.tls13Variant,
4659 flags: append([]string{"-expect-verify-result"}, flags...),
4660 resumeSession: true,
4661 })
4662 tests = append(tests, testCase{
4663 testType: testType,
4664 name: "CertificateVerificationFail" + suffix,
4665 config: Config{
4666 MaxVersion: vers.version,
4667 Certificates: []Certificate{rsaCertificate},
4668 },
4669 tls13Variant: vers.tls13Variant,
4670 flags: append([]string{"-verify-fail"}, flags...),
4671 shouldFail: true,
4672 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4673 })
4674 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004675 }
4676
4677 // By default, the client is in a soft fail mode where the peer
4678 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004679 tests = append(tests, testCase{
4680 testType: clientTest,
4681 name: "CertificateVerificationSoftFail-" + vers.name,
4682 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004683 MaxVersion: vers.version,
4684 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004685 },
David Benjamina5022392017-07-10 17:40:39 -04004686 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004687 flags: []string{
4688 "-verify-fail",
4689 "-expect-verify-result",
4690 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004691 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004692 })
4693 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004694
David Benjamin1d4f4c02016-07-26 18:03:08 -04004695 tests = append(tests, testCase{
4696 name: "ShimSendAlert",
4697 flags: []string{"-send-alert"},
4698 shimWritesFirst: true,
4699 shouldFail: true,
4700 expectedLocalError: "remote error: decompression failure",
4701 })
4702
David Benjamin582ba042016-07-07 12:33:25 -07004703 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004704 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004705 name: "Renegotiate-Client",
4706 config: Config{
4707 MaxVersion: VersionTLS12,
4708 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004709 renegotiate: 1,
4710 flags: []string{
4711 "-renegotiate-freely",
4712 "-expect-total-renegotiations", "1",
4713 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004714 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004715
David Benjamin47921102016-07-28 11:29:18 -04004716 tests = append(tests, testCase{
4717 name: "SendHalfHelloRequest",
4718 config: Config{
4719 MaxVersion: VersionTLS12,
4720 Bugs: ProtocolBugs{
4721 PackHelloRequestWithFinished: config.packHandshakeFlight,
4722 },
4723 },
4724 sendHalfHelloRequest: true,
4725 flags: []string{"-renegotiate-ignore"},
4726 shouldFail: true,
4727 expectedError: ":UNEXPECTED_RECORD:",
4728 })
4729
David Benjamin760b1dd2015-05-15 23:33:48 -04004730 // NPN on client and server; results in post-handshake message.
4731 tests = append(tests, testCase{
4732 name: "NPN-Client",
4733 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004734 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004735 NextProtos: []string{"foo"},
4736 },
4737 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004738 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004739 expectedNextProto: "foo",
4740 expectedNextProtoType: npn,
4741 })
4742 tests = append(tests, testCase{
4743 testType: serverTest,
4744 name: "NPN-Server",
4745 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004746 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004747 NextProtos: []string{"bar"},
4748 },
4749 flags: []string{
4750 "-advertise-npn", "\x03foo\x03bar\x03baz",
4751 "-expect-next-proto", "bar",
4752 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004753 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004754 expectedNextProto: "bar",
4755 expectedNextProtoType: npn,
4756 })
4757
4758 // TODO(davidben): Add tests for when False Start doesn't trigger.
4759
4760 // Client does False Start and negotiates NPN.
4761 tests = append(tests, testCase{
4762 name: "FalseStart",
4763 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004764 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004765 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4766 NextProtos: []string{"foo"},
4767 Bugs: ProtocolBugs{
4768 ExpectFalseStart: true,
4769 },
4770 },
4771 flags: []string{
4772 "-false-start",
4773 "-select-next-proto", "foo",
4774 },
4775 shimWritesFirst: true,
4776 resumeSession: true,
4777 })
4778
4779 // Client does False Start and negotiates ALPN.
4780 tests = append(tests, testCase{
4781 name: "FalseStart-ALPN",
4782 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004783 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4785 NextProtos: []string{"foo"},
4786 Bugs: ProtocolBugs{
4787 ExpectFalseStart: true,
4788 },
4789 },
4790 flags: []string{
4791 "-false-start",
4792 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004793 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004794 },
4795 shimWritesFirst: true,
4796 resumeSession: true,
4797 })
4798
David Benjamin760b1dd2015-05-15 23:33:48 -04004799 // False Start without session tickets.
4800 tests = append(tests, testCase{
4801 name: "FalseStart-SessionTicketsDisabled",
4802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004803 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4805 NextProtos: []string{"foo"},
4806 SessionTicketsDisabled: true,
4807 Bugs: ProtocolBugs{
4808 ExpectFalseStart: true,
4809 },
4810 },
4811 flags: []string{
4812 "-false-start",
4813 "-select-next-proto", "foo",
4814 },
4815 shimWritesFirst: true,
4816 })
4817
4818 // Server parses a V2ClientHello.
4819 tests = append(tests, testCase{
4820 testType: serverTest,
4821 name: "SendV2ClientHello",
4822 config: Config{
4823 // Choose a cipher suite that does not involve
4824 // elliptic curves, so no extensions are
4825 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004826 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004827 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004828 Bugs: ProtocolBugs{
4829 SendV2ClientHello: true,
4830 },
4831 },
David Benjamin78b8b992017-08-01 18:38:41 -04004832 flags: []string{
4833 "-expect-msg-callback",
4834 `read v2clienthello
4835write hs 2
4836write hs 11
4837write hs 14
4838read hs 16
4839read ccs
4840read hs 20
4841write ccs
4842write hs 20
4843read alert 1 0
4844`,
4845 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004846 })
4847
Nick Harper60a85cb2016-09-23 16:25:11 -07004848 // Test Channel ID
4849 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004850 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004851 continue
4852 }
4853 // Client sends a Channel ID.
4854 tests = append(tests, testCase{
4855 name: "ChannelID-Client-" + ver.name,
4856 config: Config{
4857 MaxVersion: ver.version,
4858 RequestChannelID: true,
4859 },
David Benjamina5022392017-07-10 17:40:39 -04004860 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004861 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4862 resumeSession: true,
4863 expectChannelID: true,
4864 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004865
Nick Harper60a85cb2016-09-23 16:25:11 -07004866 // Server accepts a Channel ID.
4867 tests = append(tests, testCase{
4868 testType: serverTest,
4869 name: "ChannelID-Server-" + ver.name,
4870 config: Config{
4871 MaxVersion: ver.version,
4872 ChannelID: channelIDKey,
4873 },
David Benjamina5022392017-07-10 17:40:39 -04004874 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004875 flags: []string{
4876 "-expect-channel-id",
4877 base64.StdEncoding.EncodeToString(channelIDBytes),
4878 },
4879 resumeSession: true,
4880 expectChannelID: true,
4881 })
4882
4883 tests = append(tests, testCase{
4884 testType: serverTest,
4885 name: "InvalidChannelIDSignature-" + ver.name,
4886 config: Config{
4887 MaxVersion: ver.version,
4888 ChannelID: channelIDKey,
4889 Bugs: ProtocolBugs{
4890 InvalidChannelIDSignature: true,
4891 },
4892 },
David Benjamina5022392017-07-10 17:40:39 -04004893 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004894 flags: []string{"-enable-channel-id"},
4895 shouldFail: true,
4896 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4897 })
David Benjamin634f4752017-07-01 11:08:41 -04004898
4899 if ver.version < VersionTLS13 {
4900 // Channel ID requires ECDHE ciphers.
4901 tests = append(tests, testCase{
4902 testType: serverTest,
4903 name: "ChannelID-NoECDHE-" + ver.name,
4904 config: Config{
4905 MaxVersion: ver.version,
4906 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4907 ChannelID: channelIDKey,
4908 },
4909 expectChannelID: false,
4910 flags: []string{"-enable-channel-id"},
4911 })
4912
4913 // Sanity-check setting expectChannelID false works.
4914 tests = append(tests, testCase{
4915 testType: serverTest,
4916 name: "ChannelID-ECDHE-" + ver.name,
4917 config: Config{
4918 MaxVersion: ver.version,
4919 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4920 ChannelID: channelIDKey,
4921 },
4922 expectChannelID: false,
4923 flags: []string{"-enable-channel-id"},
4924 shouldFail: true,
4925 expectedLocalError: "channel ID unexpectedly negotiated",
4926 })
4927 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004928 }
David Benjamin30789da2015-08-29 22:56:45 -04004929
David Benjaminf8fcdf32016-06-08 15:56:13 -04004930 // Channel ID and NPN at the same time, to ensure their relative
4931 // ordering is correct.
4932 tests = append(tests, testCase{
4933 name: "ChannelID-NPN-Client",
4934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004935 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004936 RequestChannelID: true,
4937 NextProtos: []string{"foo"},
4938 },
4939 flags: []string{
4940 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4941 "-select-next-proto", "foo",
4942 },
4943 resumeSession: true,
4944 expectChannelID: true,
4945 expectedNextProto: "foo",
4946 expectedNextProtoType: npn,
4947 })
4948 tests = append(tests, testCase{
4949 testType: serverTest,
4950 name: "ChannelID-NPN-Server",
4951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004952 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004953 ChannelID: channelIDKey,
4954 NextProtos: []string{"bar"},
4955 },
4956 flags: []string{
4957 "-expect-channel-id",
4958 base64.StdEncoding.EncodeToString(channelIDBytes),
4959 "-advertise-npn", "\x03foo\x03bar\x03baz",
4960 "-expect-next-proto", "bar",
4961 },
4962 resumeSession: true,
4963 expectChannelID: true,
4964 expectedNextProto: "bar",
4965 expectedNextProtoType: npn,
4966 })
4967
David Benjamin30789da2015-08-29 22:56:45 -04004968 // Bidirectional shutdown with the runner initiating.
4969 tests = append(tests, testCase{
4970 name: "Shutdown-Runner",
4971 config: Config{
4972 Bugs: ProtocolBugs{
4973 ExpectCloseNotify: true,
4974 },
4975 },
4976 flags: []string{"-check-close-notify"},
4977 })
4978
David Benjamine3843d42017-03-25 18:00:56 -05004979 if !config.implicitHandshake {
4980 // Bidirectional shutdown with the shim initiating. The runner,
4981 // in the meantime, sends garbage before the close_notify which
4982 // the shim must ignore. This test is disabled under implicit
4983 // handshake tests because the shim never reads or writes.
4984 tests = append(tests, testCase{
4985 name: "Shutdown-Shim",
4986 config: Config{
4987 MaxVersion: VersionTLS12,
4988 Bugs: ProtocolBugs{
4989 ExpectCloseNotify: true,
4990 },
David Benjamin30789da2015-08-29 22:56:45 -04004991 },
David Benjamine3843d42017-03-25 18:00:56 -05004992 shimShutsDown: true,
4993 sendEmptyRecords: 1,
4994 sendWarningAlerts: 1,
4995 flags: []string{"-check-close-notify"},
4996 })
4997 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004998 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004999 // TODO(davidben): DTLS 1.3 will want a similar thing for
5000 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04005001 tests = append(tests, testCase{
5002 name: "SkipHelloVerifyRequest",
5003 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005004 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04005005 Bugs: ProtocolBugs{
5006 SkipHelloVerifyRequest: true,
5007 },
5008 },
5009 })
5010 }
5011
David Benjamin760b1dd2015-05-15 23:33:48 -04005012 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07005013 test.protocol = config.protocol
5014 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005015 test.name += "-DTLS"
5016 }
David Benjamin582ba042016-07-07 12:33:25 -07005017 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05005018 test.name += "-Async"
5019 test.flags = append(test.flags, "-async")
5020 } else {
5021 test.name += "-Sync"
5022 }
David Benjamin582ba042016-07-07 12:33:25 -07005023 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005024 test.name += "-SplitHandshakeRecords"
5025 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005026 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005027 test.config.Bugs.MaxPacketLength = 256
5028 test.flags = append(test.flags, "-mtu", "256")
5029 }
5030 }
David Benjamin582ba042016-07-07 12:33:25 -07005031 if config.packHandshakeFlight {
5032 test.name += "-PackHandshakeFlight"
5033 test.config.Bugs.PackHandshakeFlight = true
5034 }
David Benjamine3843d42017-03-25 18:00:56 -05005035 if config.implicitHandshake {
5036 test.name += "-ImplicitHandshake"
5037 test.flags = append(test.flags, "-implicit-handshake")
5038 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005039 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005040 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005041}
5042
Adam Langley524e7172015-02-20 16:04:00 -08005043func addDDoSCallbackTests() {
5044 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005045 for _, resume := range []bool{false, true} {
5046 suffix := "Resume"
5047 if resume {
5048 suffix = "No" + suffix
5049 }
5050
5051 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005052 testType: serverTest,
5053 name: "Server-DDoS-OK-" + suffix,
5054 config: Config{
5055 MaxVersion: VersionTLS12,
5056 },
Adam Langley524e7172015-02-20 16:04:00 -08005057 flags: []string{"-install-ddos-callback"},
5058 resumeSession: resume,
5059 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005060 testCases = append(testCases, testCase{
5061 testType: serverTest,
5062 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5063 config: Config{
5064 MaxVersion: VersionTLS13,
5065 },
5066 flags: []string{"-install-ddos-callback"},
5067 resumeSession: resume,
5068 })
Adam Langley524e7172015-02-20 16:04:00 -08005069
5070 failFlag := "-fail-ddos-callback"
5071 if resume {
5072 failFlag = "-fail-second-ddos-callback"
5073 }
5074 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005075 testType: serverTest,
5076 name: "Server-DDoS-Reject-" + suffix,
5077 config: Config{
5078 MaxVersion: VersionTLS12,
5079 },
David Benjamin2c66e072016-09-16 15:58:00 -04005080 flags: []string{"-install-ddos-callback", failFlag},
5081 resumeSession: resume,
5082 shouldFail: true,
5083 expectedError: ":CONNECTION_REJECTED:",
5084 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005085 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005086 testCases = append(testCases, testCase{
5087 testType: serverTest,
5088 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5089 config: Config{
5090 MaxVersion: VersionTLS13,
5091 },
David Benjamin2c66e072016-09-16 15:58:00 -04005092 flags: []string{"-install-ddos-callback", failFlag},
5093 resumeSession: resume,
5094 shouldFail: true,
5095 expectedError: ":CONNECTION_REJECTED:",
5096 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005097 })
Adam Langley524e7172015-02-20 16:04:00 -08005098 }
5099}
5100
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005101func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005102 for _, protocol := range []protocol{tls, dtls} {
5103 for _, shimVers := range allVersions(protocol) {
5104 // Assemble flags to disable all newer versions on the shim.
5105 var flags []string
5106 for _, vers := range allVersions(protocol) {
5107 if vers.version > shimVers.version {
5108 flags = append(flags, vers.excludeFlag)
5109 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005110 }
Steven Valdez520e1222017-06-13 12:45:25 -04005111
5112 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5113
5114 if shimVers.tls13Variant != 0 {
5115 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5116 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5117 }
5118
5119 // Test configuring the runner's maximum version.
5120 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005121 expectedVersion := shimVers.version
5122 if runnerVers.version < shimVers.version {
5123 expectedVersion = runnerVers.version
5124 }
Steven Valdez520e1222017-06-13 12:45:25 -04005125 // When running and shim have different TLS 1.3 variants enabled,
5126 // shim clients are expected to fall back to TLS 1.2, while shim
5127 // servers support both variants when enabled when the experiment is
5128 // enabled.
5129 expectedServerVersion := expectedVersion
5130 expectedClientVersion := expectedVersion
5131 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5132 expectedClientVersion = VersionTLS12
5133 expectedServerVersion = VersionTLS12
5134 if shimVers.tls13Variant != TLS13Default {
5135 expectedServerVersion = VersionTLS13
5136 }
5137 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005138
David Benjamin8b8c0062014-11-23 02:47:52 -05005139 suffix := shimVers.name + "-" + runnerVers.name
5140 if protocol == dtls {
5141 suffix += "-DTLS"
5142 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005143
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005144 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005145 clientVers := shimVers.version
5146 if clientVers > VersionTLS10 {
5147 clientVers = VersionTLS10
5148 }
Steven Valdez520e1222017-06-13 12:45:25 -04005149 clientVers = recordVersionToWire(clientVers, protocol)
5150 serverVers := expectedServerVersion
5151 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005152 serverVers = VersionTLS10
5153 }
Steven Valdez520e1222017-06-13 12:45:25 -04005154 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005155
David Benjamin8b8c0062014-11-23 02:47:52 -05005156 testCases = append(testCases, testCase{
5157 protocol: protocol,
5158 testType: clientTest,
5159 name: "VersionNegotiation-Client-" + suffix,
5160 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005161 MaxVersion: runnerVers.version,
5162 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005163 Bugs: ProtocolBugs{
5164 ExpectInitialRecordVersion: clientVers,
5165 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005166 },
5167 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005168 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005169 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005170 testCases = append(testCases, testCase{
5171 protocol: protocol,
5172 testType: clientTest,
5173 name: "VersionNegotiation-Client2-" + suffix,
5174 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005175 MaxVersion: runnerVers.version,
5176 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005177 Bugs: ProtocolBugs{
5178 ExpectInitialRecordVersion: clientVers,
5179 },
5180 },
Steven Valdez520e1222017-06-13 12:45:25 -04005181 flags: flags2,
5182 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005183 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005184
5185 testCases = append(testCases, testCase{
5186 protocol: protocol,
5187 testType: serverTest,
5188 name: "VersionNegotiation-Server-" + suffix,
5189 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005190 MaxVersion: runnerVers.version,
5191 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005192 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005193 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005194 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005195 },
5196 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005197 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005198 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005199 testCases = append(testCases, testCase{
5200 protocol: protocol,
5201 testType: serverTest,
5202 name: "VersionNegotiation-Server2-" + suffix,
5203 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005204 MaxVersion: runnerVers.version,
5205 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005206 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005207 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005208 },
5209 },
Steven Valdez520e1222017-06-13 12:45:25 -04005210 flags: flags2,
5211 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005212 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005213 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005214 }
5215 }
David Benjamin95c69562016-06-29 18:15:03 -04005216
Steven Valdezfdd10992016-09-15 16:27:05 -04005217 // Test the version extension at all versions.
5218 for _, vers := range tlsVersions {
5219 protocols := []protocol{tls}
5220 if vers.hasDTLS {
5221 protocols = append(protocols, dtls)
5222 }
5223 for _, protocol := range protocols {
5224 suffix := vers.name
5225 if protocol == dtls {
5226 suffix += "-DTLS"
5227 }
5228
Steven Valdezfdd10992016-09-15 16:27:05 -04005229 testCases = append(testCases, testCase{
5230 protocol: protocol,
5231 testType: serverTest,
5232 name: "VersionNegotiationExtension-" + suffix,
5233 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005234 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005235 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005236 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005237 },
5238 },
5239 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005240 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005241 })
5242 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005243 }
5244
5245 // If all versions are unknown, negotiation fails.
5246 testCases = append(testCases, testCase{
5247 testType: serverTest,
5248 name: "NoSupportedVersions",
5249 config: Config{
5250 Bugs: ProtocolBugs{
5251 SendSupportedVersions: []uint16{0x1111},
5252 },
5253 },
5254 shouldFail: true,
5255 expectedError: ":UNSUPPORTED_PROTOCOL:",
5256 })
5257 testCases = append(testCases, testCase{
5258 protocol: dtls,
5259 testType: serverTest,
5260 name: "NoSupportedVersions-DTLS",
5261 config: Config{
5262 Bugs: ProtocolBugs{
5263 SendSupportedVersions: []uint16{0x1111},
5264 },
5265 },
5266 shouldFail: true,
5267 expectedError: ":UNSUPPORTED_PROTOCOL:",
5268 })
5269
5270 testCases = append(testCases, testCase{
5271 testType: serverTest,
5272 name: "ClientHelloVersionTooHigh",
5273 config: Config{
5274 MaxVersion: VersionTLS13,
5275 Bugs: ProtocolBugs{
5276 SendClientVersion: 0x0304,
5277 OmitSupportedVersions: true,
5278 },
5279 },
5280 expectedVersion: VersionTLS12,
5281 })
5282
5283 testCases = append(testCases, testCase{
5284 testType: serverTest,
5285 name: "ConflictingVersionNegotiation",
5286 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005287 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005288 SendClientVersion: VersionTLS12,
5289 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005290 },
5291 },
David Benjaminad75a662016-09-30 15:42:59 -04005292 // The extension takes precedence over the ClientHello version.
5293 expectedVersion: VersionTLS11,
5294 })
5295
5296 testCases = append(testCases, testCase{
5297 testType: serverTest,
5298 name: "ConflictingVersionNegotiation-2",
5299 config: Config{
5300 Bugs: ProtocolBugs{
5301 SendClientVersion: VersionTLS11,
5302 SendSupportedVersions: []uint16{VersionTLS12},
5303 },
5304 },
5305 // The extension takes precedence over the ClientHello version.
5306 expectedVersion: VersionTLS12,
5307 })
5308
5309 testCases = append(testCases, testCase{
5310 testType: serverTest,
5311 name: "RejectFinalTLS13",
5312 config: Config{
5313 Bugs: ProtocolBugs{
5314 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5315 },
5316 },
5317 // We currently implement a draft TLS 1.3 version. Ensure that
5318 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005319 expectedVersion: VersionTLS12,
5320 })
5321
Steven Valdez038da9b2017-07-10 12:57:25 -04005322 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5323 // the ServerHello.
5324 testCases = append(testCases, testCase{
5325 testType: clientTest,
5326 name: "SupportedVersionSelection-TLS12",
5327 config: Config{
5328 MaxVersion: VersionTLS12,
5329 Bugs: ProtocolBugs{
5330 SendServerSupportedExtensionVersion: VersionTLS12,
5331 },
5332 },
5333 shouldFail: true,
5334 expectedError: ":UNEXPECTED_EXTENSION:",
5335 })
5336
5337 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5338 // supported_versions extension in the ServerHello.
5339 testCases = append(testCases, testCase{
5340 testType: clientTest,
5341 name: "SupportedVersionSelection-TLS13",
5342 config: Config{
5343 MaxVersion: VersionTLS13,
5344 Bugs: ProtocolBugs{
5345 SendServerSupportedExtensionVersion: tls13DraftVersion,
5346 },
5347 },
5348 shouldFail: true,
5349 expectedError: ":UNEXPECTED_EXTENSION:",
5350 })
5351
Brian Smithf85d3232016-10-28 10:34:06 -10005352 // Test that the maximum version is selected regardless of the
5353 // client-sent order.
5354 testCases = append(testCases, testCase{
5355 testType: serverTest,
5356 name: "IgnoreClientVersionOrder",
5357 config: Config{
5358 Bugs: ProtocolBugs{
5359 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5360 },
5361 },
5362 expectedVersion: VersionTLS13,
5363 })
5364
David Benjamin95c69562016-06-29 18:15:03 -04005365 // Test for version tolerance.
5366 testCases = append(testCases, testCase{
5367 testType: serverTest,
5368 name: "MinorVersionTolerance",
5369 config: Config{
5370 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005371 SendClientVersion: 0x03ff,
5372 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005373 },
5374 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005375 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005376 })
5377 testCases = append(testCases, testCase{
5378 testType: serverTest,
5379 name: "MajorVersionTolerance",
5380 config: Config{
5381 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005382 SendClientVersion: 0x0400,
5383 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005384 },
5385 },
David Benjaminad75a662016-09-30 15:42:59 -04005386 // TLS 1.3 must be negotiated with the supported_versions
5387 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005388 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005389 })
David Benjaminad75a662016-09-30 15:42:59 -04005390 testCases = append(testCases, testCase{
5391 testType: serverTest,
5392 name: "VersionTolerance-TLS13",
5393 config: Config{
5394 Bugs: ProtocolBugs{
5395 // Although TLS 1.3 does not use
5396 // ClientHello.version, it still tolerates high
5397 // values there.
5398 SendClientVersion: 0x0400,
5399 },
5400 },
5401 expectedVersion: VersionTLS13,
5402 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005403
David Benjamin95c69562016-06-29 18:15:03 -04005404 testCases = append(testCases, testCase{
5405 protocol: dtls,
5406 testType: serverTest,
5407 name: "MinorVersionTolerance-DTLS",
5408 config: Config{
5409 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005410 SendClientVersion: 0xfe00,
5411 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005412 },
5413 },
5414 expectedVersion: VersionTLS12,
5415 })
5416 testCases = append(testCases, testCase{
5417 protocol: dtls,
5418 testType: serverTest,
5419 name: "MajorVersionTolerance-DTLS",
5420 config: Config{
5421 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005422 SendClientVersion: 0xfdff,
5423 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005424 },
5425 },
5426 expectedVersion: VersionTLS12,
5427 })
5428
5429 // Test that versions below 3.0 are rejected.
5430 testCases = append(testCases, testCase{
5431 testType: serverTest,
5432 name: "VersionTooLow",
5433 config: Config{
5434 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005435 SendClientVersion: 0x0200,
5436 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005437 },
5438 },
5439 shouldFail: true,
5440 expectedError: ":UNSUPPORTED_PROTOCOL:",
5441 })
5442 testCases = append(testCases, testCase{
5443 protocol: dtls,
5444 testType: serverTest,
5445 name: "VersionTooLow-DTLS",
5446 config: Config{
5447 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005448 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005449 },
5450 },
5451 shouldFail: true,
5452 expectedError: ":UNSUPPORTED_PROTOCOL:",
5453 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005454
David Benjamin2dc02042016-09-19 19:57:37 -04005455 testCases = append(testCases, testCase{
5456 name: "ServerBogusVersion",
5457 config: Config{
5458 Bugs: ProtocolBugs{
5459 SendServerHelloVersion: 0x1234,
5460 },
5461 },
5462 shouldFail: true,
5463 expectedError: ":UNSUPPORTED_PROTOCOL:",
5464 })
5465
David Benjamin1f61f0d2016-07-10 12:20:35 -04005466 // Test TLS 1.3's downgrade signal.
5467 testCases = append(testCases, testCase{
5468 name: "Downgrade-TLS12-Client",
5469 config: Config{
5470 Bugs: ProtocolBugs{
5471 NegotiateVersion: VersionTLS12,
5472 },
5473 },
David Benjamin592b5322016-09-30 15:15:01 -04005474 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005475 // TODO(davidben): This test should fail once TLS 1.3 is final
5476 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005477 })
5478 testCases = append(testCases, testCase{
5479 testType: serverTest,
5480 name: "Downgrade-TLS12-Server",
5481 config: Config{
5482 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005483 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005484 },
5485 },
David Benjamin592b5322016-09-30 15:15:01 -04005486 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005487 // TODO(davidben): This test should fail once TLS 1.3 is final
5488 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005489 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005490}
5491
David Benjaminaccb4542014-12-12 23:44:33 -05005492func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005493 for _, protocol := range []protocol{tls, dtls} {
5494 for _, shimVers := range allVersions(protocol) {
5495 // Assemble flags to disable all older versions on the shim.
5496 var flags []string
5497 for _, vers := range allVersions(protocol) {
5498 if vers.version < shimVers.version {
5499 flags = append(flags, vers.excludeFlag)
5500 }
David Benjaminaccb4542014-12-12 23:44:33 -05005501 }
Steven Valdez520e1222017-06-13 12:45:25 -04005502
5503 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5504
5505 if shimVers.tls13Variant != 0 {
5506 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5507 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5508 }
5509
5510 for _, runnerVers := range allVersions(protocol) {
5511 // Different TLS 1.3 variants are incompatible with each other and don't
5512 // produce consistent minimum versions.
5513 //
5514 // TODO(davidben): Fold these tests (the main value is in the
5515 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5516 // on intended shim behavior, not the shim + runner combination.
5517 if shimVers.tls13Variant != runnerVers.tls13Variant {
5518 continue
5519 }
5520
David Benjaminaccb4542014-12-12 23:44:33 -05005521 suffix := shimVers.name + "-" + runnerVers.name
5522 if protocol == dtls {
5523 suffix += "-DTLS"
5524 }
David Benjaminaccb4542014-12-12 23:44:33 -05005525
David Benjaminaccb4542014-12-12 23:44:33 -05005526 var expectedVersion uint16
5527 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005528 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005529 if runnerVers.version >= shimVers.version {
5530 expectedVersion = runnerVers.version
5531 } else {
5532 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005533 expectedError = ":UNSUPPORTED_PROTOCOL:"
5534 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005535 }
5536
5537 testCases = append(testCases, testCase{
5538 protocol: protocol,
5539 testType: clientTest,
5540 name: "MinimumVersion-Client-" + suffix,
5541 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005542 MaxVersion: runnerVers.version,
5543 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005544 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005545 // Ensure the server does not decline to
5546 // select a version (versions extension) or
5547 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005548 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005549 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005550 },
David Benjaminaccb4542014-12-12 23:44:33 -05005551 },
David Benjamin87909c02014-12-13 01:55:01 -05005552 flags: flags,
5553 expectedVersion: expectedVersion,
5554 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005555 expectedError: expectedError,
5556 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005557 })
5558 testCases = append(testCases, testCase{
5559 protocol: protocol,
5560 testType: clientTest,
5561 name: "MinimumVersion-Client2-" + suffix,
5562 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005563 MaxVersion: runnerVers.version,
5564 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005565 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005566 // Ensure the server does not decline to
5567 // select a version (versions extension) or
5568 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005569 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005570 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005571 },
David Benjaminaccb4542014-12-12 23:44:33 -05005572 },
Steven Valdez520e1222017-06-13 12:45:25 -04005573 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005574 expectedVersion: expectedVersion,
5575 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005576 expectedError: expectedError,
5577 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005578 })
5579
5580 testCases = append(testCases, testCase{
5581 protocol: protocol,
5582 testType: serverTest,
5583 name: "MinimumVersion-Server-" + suffix,
5584 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005585 MaxVersion: runnerVers.version,
5586 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005587 },
David Benjamin87909c02014-12-13 01:55:01 -05005588 flags: flags,
5589 expectedVersion: expectedVersion,
5590 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005591 expectedError: expectedError,
5592 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005593 })
5594 testCases = append(testCases, testCase{
5595 protocol: protocol,
5596 testType: serverTest,
5597 name: "MinimumVersion-Server2-" + suffix,
5598 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005599 MaxVersion: runnerVers.version,
5600 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005601 },
Steven Valdez520e1222017-06-13 12:45:25 -04005602 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005603 expectedVersion: expectedVersion,
5604 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005605 expectedError: expectedError,
5606 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005607 })
5608 }
5609 }
5610 }
5611}
5612
David Benjamine78bfde2014-09-06 12:45:15 -04005613func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005614 // TODO(davidben): Extensions, where applicable, all move their server
5615 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5616 // tests for both. Also test interaction with 0-RTT when implemented.
5617
David Benjamin97d17d92016-07-14 16:12:00 -04005618 // Repeat extensions tests all versions except SSL 3.0.
5619 for _, ver := range tlsVersions {
5620 if ver.version == VersionSSL30 {
5621 continue
5622 }
5623
David Benjamin97d17d92016-07-14 16:12:00 -04005624 // Test that duplicate extensions are rejected.
5625 testCases = append(testCases, testCase{
5626 testType: clientTest,
5627 name: "DuplicateExtensionClient-" + ver.name,
5628 config: Config{
5629 MaxVersion: ver.version,
5630 Bugs: ProtocolBugs{
5631 DuplicateExtension: true,
5632 },
David Benjamine78bfde2014-09-06 12:45:15 -04005633 },
David Benjamina5022392017-07-10 17:40:39 -04005634 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005635 shouldFail: true,
5636 expectedLocalError: "remote error: error decoding message",
5637 })
5638 testCases = append(testCases, testCase{
5639 testType: serverTest,
5640 name: "DuplicateExtensionServer-" + ver.name,
5641 config: Config{
5642 MaxVersion: ver.version,
5643 Bugs: ProtocolBugs{
5644 DuplicateExtension: true,
5645 },
David Benjamine78bfde2014-09-06 12:45:15 -04005646 },
David Benjamina5022392017-07-10 17:40:39 -04005647 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005648 shouldFail: true,
5649 expectedLocalError: "remote error: error decoding message",
5650 })
5651
5652 // Test SNI.
5653 testCases = append(testCases, testCase{
5654 testType: clientTest,
5655 name: "ServerNameExtensionClient-" + ver.name,
5656 config: Config{
5657 MaxVersion: ver.version,
5658 Bugs: ProtocolBugs{
5659 ExpectServerName: "example.com",
5660 },
David Benjamine78bfde2014-09-06 12:45:15 -04005661 },
David Benjamina5022392017-07-10 17:40:39 -04005662 tls13Variant: ver.tls13Variant,
5663 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005664 })
5665 testCases = append(testCases, testCase{
5666 testType: clientTest,
5667 name: "ServerNameExtensionClientMismatch-" + ver.name,
5668 config: Config{
5669 MaxVersion: ver.version,
5670 Bugs: ProtocolBugs{
5671 ExpectServerName: "mismatch.com",
5672 },
David Benjamine78bfde2014-09-06 12:45:15 -04005673 },
David Benjamin97d17d92016-07-14 16:12:00 -04005674 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005675 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005676 shouldFail: true,
5677 expectedLocalError: "tls: unexpected server name",
5678 })
5679 testCases = append(testCases, testCase{
5680 testType: clientTest,
5681 name: "ServerNameExtensionClientMissing-" + ver.name,
5682 config: Config{
5683 MaxVersion: ver.version,
5684 Bugs: ProtocolBugs{
5685 ExpectServerName: "missing.com",
5686 },
David Benjamine78bfde2014-09-06 12:45:15 -04005687 },
David Benjamina5022392017-07-10 17:40:39 -04005688 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005689 shouldFail: true,
5690 expectedLocalError: "tls: unexpected server name",
5691 })
5692 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005693 testType: clientTest,
5694 name: "TolerateServerNameAck-" + ver.name,
5695 config: Config{
5696 MaxVersion: ver.version,
5697 Bugs: ProtocolBugs{
5698 SendServerNameAck: true,
5699 },
5700 },
David Benjamina5022392017-07-10 17:40:39 -04005701 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005702 flags: []string{"-host-name", "example.com"},
5703 resumeSession: true,
5704 })
5705 testCases = append(testCases, testCase{
5706 testType: clientTest,
5707 name: "UnsolicitedServerNameAck-" + ver.name,
5708 config: Config{
5709 MaxVersion: ver.version,
5710 Bugs: ProtocolBugs{
5711 SendServerNameAck: true,
5712 },
5713 },
David Benjamina5022392017-07-10 17:40:39 -04005714 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005715 shouldFail: true,
5716 expectedError: ":UNEXPECTED_EXTENSION:",
5717 expectedLocalError: "remote error: unsupported extension",
5718 })
5719 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005720 testType: serverTest,
5721 name: "ServerNameExtensionServer-" + ver.name,
5722 config: Config{
5723 MaxVersion: ver.version,
5724 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005725 },
David Benjamina5022392017-07-10 17:40:39 -04005726 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005727 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005728 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005729 })
5730
5731 // Test ALPN.
5732 testCases = append(testCases, testCase{
5733 testType: clientTest,
5734 name: "ALPNClient-" + ver.name,
5735 config: Config{
5736 MaxVersion: ver.version,
5737 NextProtos: []string{"foo"},
5738 },
5739 flags: []string{
5740 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5741 "-expect-alpn", "foo",
5742 },
David Benjamina5022392017-07-10 17:40:39 -04005743 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005744 expectedNextProto: "foo",
5745 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005746 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005747 })
5748 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005749 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005750 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005751 config: Config{
5752 MaxVersion: ver.version,
5753 Bugs: ProtocolBugs{
5754 SendALPN: "baz",
5755 },
5756 },
5757 flags: []string{
5758 "-advertise-alpn", "\x03foo\x03bar",
5759 },
David Benjamina5022392017-07-10 17:40:39 -04005760 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005761 shouldFail: true,
5762 expectedError: ":INVALID_ALPN_PROTOCOL:",
5763 expectedLocalError: "remote error: illegal parameter",
5764 })
5765 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005766 testType: clientTest,
5767 name: "ALPNClient-AllowUnknown-" + ver.name,
5768 config: Config{
5769 MaxVersion: ver.version,
5770 Bugs: ProtocolBugs{
5771 SendALPN: "baz",
5772 },
5773 },
5774 flags: []string{
5775 "-advertise-alpn", "\x03foo\x03bar",
5776 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005777 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005778 },
David Benjamina5022392017-07-10 17:40:39 -04005779 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005780 })
5781 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005782 testType: serverTest,
5783 name: "ALPNServer-" + ver.name,
5784 config: Config{
5785 MaxVersion: ver.version,
5786 NextProtos: []string{"foo", "bar", "baz"},
5787 },
5788 flags: []string{
5789 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5790 "-select-alpn", "foo",
5791 },
David Benjamina5022392017-07-10 17:40:39 -04005792 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005793 expectedNextProto: "foo",
5794 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005795 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005796 })
5797 testCases = append(testCases, testCase{
5798 testType: serverTest,
5799 name: "ALPNServer-Decline-" + ver.name,
5800 config: Config{
5801 MaxVersion: ver.version,
5802 NextProtos: []string{"foo", "bar", "baz"},
5803 },
5804 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005805 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005806 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005807 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005808 })
5809
David Benjamin25fe85b2016-08-09 20:00:32 -04005810 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5811 // called once.
5812 testCases = append(testCases, testCase{
5813 testType: serverTest,
5814 name: "ALPNServer-Async-" + ver.name,
5815 config: Config{
5816 MaxVersion: ver.version,
5817 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005818 // Prior to TLS 1.3, exercise the asynchronous session callback.
5819 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005820 },
5821 flags: []string{
5822 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5823 "-select-alpn", "foo",
5824 "-async",
5825 },
David Benjamina5022392017-07-10 17:40:39 -04005826 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005827 expectedNextProto: "foo",
5828 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005829 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005830 })
5831
David Benjamin97d17d92016-07-14 16:12:00 -04005832 var emptyString string
5833 testCases = append(testCases, testCase{
5834 testType: clientTest,
5835 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5836 config: Config{
5837 MaxVersion: ver.version,
5838 NextProtos: []string{""},
5839 Bugs: ProtocolBugs{
5840 // A server returning an empty ALPN protocol
5841 // should be rejected.
5842 ALPNProtocol: &emptyString,
5843 },
5844 },
5845 flags: []string{
5846 "-advertise-alpn", "\x03foo",
5847 },
David Benjamina5022392017-07-10 17:40:39 -04005848 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005849 shouldFail: true,
5850 expectedError: ":PARSE_TLSEXT:",
5851 })
5852 testCases = append(testCases, testCase{
5853 testType: serverTest,
5854 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5855 config: Config{
5856 MaxVersion: ver.version,
5857 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005858 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005859 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005860 },
David Benjamin97d17d92016-07-14 16:12:00 -04005861 flags: []string{
5862 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005863 },
David Benjamina5022392017-07-10 17:40:39 -04005864 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005865 shouldFail: true,
5866 expectedError: ":PARSE_TLSEXT:",
5867 })
5868
5869 // Test NPN and the interaction with ALPN.
5870 if ver.version < VersionTLS13 {
5871 // Test that the server prefers ALPN over NPN.
5872 testCases = append(testCases, testCase{
5873 testType: serverTest,
5874 name: "ALPNServer-Preferred-" + ver.name,
5875 config: Config{
5876 MaxVersion: ver.version,
5877 NextProtos: []string{"foo", "bar", "baz"},
5878 },
5879 flags: []string{
5880 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5881 "-select-alpn", "foo",
5882 "-advertise-npn", "\x03foo\x03bar\x03baz",
5883 },
David Benjamina5022392017-07-10 17:40:39 -04005884 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005885 expectedNextProto: "foo",
5886 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005887 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005888 })
5889 testCases = append(testCases, testCase{
5890 testType: serverTest,
5891 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5892 config: Config{
5893 MaxVersion: ver.version,
5894 NextProtos: []string{"foo", "bar", "baz"},
5895 Bugs: ProtocolBugs{
5896 SwapNPNAndALPN: true,
5897 },
5898 },
5899 flags: []string{
5900 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5901 "-select-alpn", "foo",
5902 "-advertise-npn", "\x03foo\x03bar\x03baz",
5903 },
David Benjamina5022392017-07-10 17:40:39 -04005904 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005905 expectedNextProto: "foo",
5906 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005907 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005908 })
5909
5910 // Test that negotiating both NPN and ALPN is forbidden.
5911 testCases = append(testCases, testCase{
5912 name: "NegotiateALPNAndNPN-" + ver.name,
5913 config: Config{
5914 MaxVersion: ver.version,
5915 NextProtos: []string{"foo", "bar", "baz"},
5916 Bugs: ProtocolBugs{
5917 NegotiateALPNAndNPN: true,
5918 },
5919 },
5920 flags: []string{
5921 "-advertise-alpn", "\x03foo",
5922 "-select-next-proto", "foo",
5923 },
David Benjamina5022392017-07-10 17:40:39 -04005924 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005925 shouldFail: true,
5926 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5927 })
5928 testCases = append(testCases, testCase{
5929 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5930 config: Config{
5931 MaxVersion: ver.version,
5932 NextProtos: []string{"foo", "bar", "baz"},
5933 Bugs: ProtocolBugs{
5934 NegotiateALPNAndNPN: true,
5935 SwapNPNAndALPN: true,
5936 },
5937 },
5938 flags: []string{
5939 "-advertise-alpn", "\x03foo",
5940 "-select-next-proto", "foo",
5941 },
David Benjamina5022392017-07-10 17:40:39 -04005942 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005943 shouldFail: true,
5944 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5945 })
David Benjamin97d17d92016-07-14 16:12:00 -04005946 }
5947
5948 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005949
5950 // Resume with a corrupt ticket.
5951 testCases = append(testCases, testCase{
5952 testType: serverTest,
5953 name: "CorruptTicket-" + ver.name,
5954 config: Config{
5955 MaxVersion: ver.version,
5956 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005957 FilterTicket: func(in []byte) ([]byte, error) {
5958 in[len(in)-1] ^= 1
5959 return in, nil
5960 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005961 },
5962 },
David Benjamina5022392017-07-10 17:40:39 -04005963 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005964 resumeSession: true,
5965 expectResumeRejected: true,
5966 })
5967 // Test the ticket callback, with and without renewal.
5968 testCases = append(testCases, testCase{
5969 testType: serverTest,
5970 name: "TicketCallback-" + ver.name,
5971 config: Config{
5972 MaxVersion: ver.version,
5973 },
David Benjamina5022392017-07-10 17:40:39 -04005974 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005975 resumeSession: true,
5976 flags: []string{"-use-ticket-callback"},
5977 })
5978 testCases = append(testCases, testCase{
5979 testType: serverTest,
5980 name: "TicketCallback-Renew-" + ver.name,
5981 config: Config{
5982 MaxVersion: ver.version,
5983 Bugs: ProtocolBugs{
5984 ExpectNewTicket: true,
5985 },
5986 },
David Benjamina5022392017-07-10 17:40:39 -04005987 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005988 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5989 resumeSession: true,
5990 })
5991
5992 // Test that the ticket callback is only called once when everything before
5993 // it in the ClientHello is asynchronous. This corrupts the ticket so
5994 // certificate selection callbacks run.
5995 testCases = append(testCases, testCase{
5996 testType: serverTest,
5997 name: "TicketCallback-SingleCall-" + ver.name,
5998 config: Config{
5999 MaxVersion: ver.version,
6000 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04006001 FilterTicket: func(in []byte) ([]byte, error) {
6002 in[len(in)-1] ^= 1
6003 return in, nil
6004 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04006005 },
6006 },
David Benjamina5022392017-07-10 17:40:39 -04006007 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006008 resumeSession: true,
6009 expectResumeRejected: true,
6010 flags: []string{
6011 "-use-ticket-callback",
6012 "-async",
6013 },
6014 })
6015
David Benjamind4c349b2017-02-09 14:07:17 -05006016 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04006017 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04006018 testCases = append(testCases, testCase{
6019 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05006020 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04006021 config: Config{
6022 MaxVersion: ver.version,
6023 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006024 EmptyTicketSessionID: true,
6025 },
6026 },
6027 resumeSession: true,
6028 })
6029 testCases = append(testCases, testCase{
6030 testType: serverTest,
6031 name: "TicketSessionIDLength-16-" + ver.name,
6032 config: Config{
6033 MaxVersion: ver.version,
6034 Bugs: ProtocolBugs{
6035 TicketSessionIDLength: 16,
6036 },
6037 },
6038 resumeSession: true,
6039 })
6040 testCases = append(testCases, testCase{
6041 testType: serverTest,
6042 name: "TicketSessionIDLength-32-" + ver.name,
6043 config: Config{
6044 MaxVersion: ver.version,
6045 Bugs: ProtocolBugs{
6046 TicketSessionIDLength: 32,
6047 },
6048 },
6049 resumeSession: true,
6050 })
6051 testCases = append(testCases, testCase{
6052 testType: serverTest,
6053 name: "TicketSessionIDLength-33-" + ver.name,
6054 config: Config{
6055 MaxVersion: ver.version,
6056 Bugs: ProtocolBugs{
6057 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006058 },
6059 },
6060 resumeSession: true,
6061 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006062 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006063 expectedError: ":DECODE_ERROR:",
6064 })
6065 }
6066
6067 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6068 // are ignored.
6069 if ver.hasDTLS {
6070 testCases = append(testCases, testCase{
6071 protocol: dtls,
6072 name: "SRTP-Client-" + ver.name,
6073 config: Config{
6074 MaxVersion: ver.version,
6075 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6076 },
6077 flags: []string{
6078 "-srtp-profiles",
6079 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6080 },
6081 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6082 })
6083 testCases = append(testCases, testCase{
6084 protocol: dtls,
6085 testType: serverTest,
6086 name: "SRTP-Server-" + ver.name,
6087 config: Config{
6088 MaxVersion: ver.version,
6089 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6090 },
6091 flags: []string{
6092 "-srtp-profiles",
6093 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6094 },
6095 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6096 })
6097 // Test that the MKI is ignored.
6098 testCases = append(testCases, testCase{
6099 protocol: dtls,
6100 testType: serverTest,
6101 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6102 config: Config{
6103 MaxVersion: ver.version,
6104 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6105 Bugs: ProtocolBugs{
6106 SRTPMasterKeyIdentifer: "bogus",
6107 },
6108 },
6109 flags: []string{
6110 "-srtp-profiles",
6111 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6112 },
6113 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6114 })
6115 // Test that SRTP isn't negotiated on the server if there were
6116 // no matching profiles.
6117 testCases = append(testCases, testCase{
6118 protocol: dtls,
6119 testType: serverTest,
6120 name: "SRTP-Server-NoMatch-" + ver.name,
6121 config: Config{
6122 MaxVersion: ver.version,
6123 SRTPProtectionProfiles: []uint16{100, 101, 102},
6124 },
6125 flags: []string{
6126 "-srtp-profiles",
6127 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6128 },
6129 expectedSRTPProtectionProfile: 0,
6130 })
6131 // Test that the server returning an invalid SRTP profile is
6132 // flagged as an error by the client.
6133 testCases = append(testCases, testCase{
6134 protocol: dtls,
6135 name: "SRTP-Client-NoMatch-" + ver.name,
6136 config: Config{
6137 MaxVersion: ver.version,
6138 Bugs: ProtocolBugs{
6139 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6140 },
6141 },
6142 flags: []string{
6143 "-srtp-profiles",
6144 "SRTP_AES128_CM_SHA1_80",
6145 },
6146 shouldFail: true,
6147 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6148 })
6149 }
6150
6151 // Test SCT list.
6152 testCases = append(testCases, testCase{
6153 name: "SignedCertificateTimestampList-Client-" + ver.name,
6154 testType: clientTest,
6155 config: Config{
6156 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006157 },
David Benjamin97d17d92016-07-14 16:12:00 -04006158 flags: []string{
6159 "-enable-signed-cert-timestamps",
6160 "-expect-signed-cert-timestamps",
6161 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006162 },
David Benjamina5022392017-07-10 17:40:39 -04006163 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006164 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006165 })
David Benjamindaa88502016-10-04 16:32:16 -04006166
Adam Langleycfa08c32016-11-17 13:21:27 -08006167 var differentSCTList []byte
6168 differentSCTList = append(differentSCTList, testSCTList...)
6169 differentSCTList[len(differentSCTList)-1] ^= 1
6170
David Benjamindaa88502016-10-04 16:32:16 -04006171 // The SCT extension did not specify that it must only be sent on resumption as it
6172 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006173 testCases = append(testCases, testCase{
6174 name: "SendSCTListOnResume-" + ver.name,
6175 config: Config{
6176 MaxVersion: ver.version,
6177 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006178 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006179 },
David Benjamind98452d2015-06-16 14:16:23 -04006180 },
David Benjamin97d17d92016-07-14 16:12:00 -04006181 flags: []string{
6182 "-enable-signed-cert-timestamps",
6183 "-expect-signed-cert-timestamps",
6184 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006185 },
David Benjamina5022392017-07-10 17:40:39 -04006186 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006187 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006188 })
David Benjamindaa88502016-10-04 16:32:16 -04006189
David Benjamin97d17d92016-07-14 16:12:00 -04006190 testCases = append(testCases, testCase{
6191 name: "SignedCertificateTimestampList-Server-" + ver.name,
6192 testType: serverTest,
6193 config: Config{
6194 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006195 },
David Benjamin97d17d92016-07-14 16:12:00 -04006196 flags: []string{
6197 "-signed-cert-timestamps",
6198 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006199 },
David Benjamina5022392017-07-10 17:40:39 -04006200 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006201 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006202 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006203 })
David Benjamin53210cb2016-11-16 09:01:48 +09006204
Adam Langleycfa08c32016-11-17 13:21:27 -08006205 emptySCTListCert := *testCerts[0].cert
6206 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6207
6208 // Test empty SCT list.
6209 testCases = append(testCases, testCase{
6210 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6211 testType: clientTest,
6212 config: Config{
6213 MaxVersion: ver.version,
6214 Certificates: []Certificate{emptySCTListCert},
6215 },
6216 flags: []string{
6217 "-enable-signed-cert-timestamps",
6218 },
David Benjamina5022392017-07-10 17:40:39 -04006219 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006220 shouldFail: true,
6221 expectedError: ":ERROR_PARSING_EXTENSION:",
6222 })
6223
6224 emptySCTCert := *testCerts[0].cert
6225 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6226
6227 // Test empty SCT in non-empty list.
6228 testCases = append(testCases, testCase{
6229 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6230 testType: clientTest,
6231 config: Config{
6232 MaxVersion: ver.version,
6233 Certificates: []Certificate{emptySCTCert},
6234 },
6235 flags: []string{
6236 "-enable-signed-cert-timestamps",
6237 },
David Benjamina5022392017-07-10 17:40:39 -04006238 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006239 shouldFail: true,
6240 expectedError: ":ERROR_PARSING_EXTENSION:",
6241 })
6242
David Benjamin53210cb2016-11-16 09:01:48 +09006243 // Test that certificate-related extensions are not sent unsolicited.
6244 testCases = append(testCases, testCase{
6245 testType: serverTest,
6246 name: "UnsolicitedCertificateExtensions-" + ver.name,
6247 config: Config{
6248 MaxVersion: ver.version,
6249 Bugs: ProtocolBugs{
6250 NoOCSPStapling: true,
6251 NoSignedCertificateTimestamps: true,
6252 },
6253 },
David Benjamina5022392017-07-10 17:40:39 -04006254 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006255 flags: []string{
6256 "-ocsp-response",
6257 base64.StdEncoding.EncodeToString(testOCSPResponse),
6258 "-signed-cert-timestamps",
6259 base64.StdEncoding.EncodeToString(testSCTList),
6260 },
6261 })
David Benjamin97d17d92016-07-14 16:12:00 -04006262 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006263
Paul Lietar4fac72e2015-09-09 13:44:55 +01006264 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006265 testType: clientTest,
6266 name: "ClientHelloPadding",
6267 config: Config{
6268 Bugs: ProtocolBugs{
6269 RequireClientHelloSize: 512,
6270 },
6271 },
6272 // This hostname just needs to be long enough to push the
6273 // ClientHello into F5's danger zone between 256 and 511 bytes
6274 // long.
6275 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6276 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006277
6278 // Extensions should not function in SSL 3.0.
6279 testCases = append(testCases, testCase{
6280 testType: serverTest,
6281 name: "SSLv3Extensions-NoALPN",
6282 config: Config{
6283 MaxVersion: VersionSSL30,
6284 NextProtos: []string{"foo", "bar", "baz"},
6285 },
6286 flags: []string{
6287 "-select-alpn", "foo",
6288 },
6289 expectNoNextProto: true,
6290 })
6291
6292 // Test session tickets separately as they follow a different codepath.
6293 testCases = append(testCases, testCase{
6294 testType: serverTest,
6295 name: "SSLv3Extensions-NoTickets",
6296 config: Config{
6297 MaxVersion: VersionSSL30,
6298 Bugs: ProtocolBugs{
6299 // Historically, session tickets in SSL 3.0
6300 // failed in different ways depending on whether
6301 // the client supported renegotiation_info.
6302 NoRenegotiationInfo: true,
6303 },
6304 },
6305 resumeSession: true,
6306 })
6307 testCases = append(testCases, testCase{
6308 testType: serverTest,
6309 name: "SSLv3Extensions-NoTickets2",
6310 config: Config{
6311 MaxVersion: VersionSSL30,
6312 },
6313 resumeSession: true,
6314 })
6315
6316 // But SSL 3.0 does send and process renegotiation_info.
6317 testCases = append(testCases, testCase{
6318 testType: serverTest,
6319 name: "SSLv3Extensions-RenegotiationInfo",
6320 config: Config{
6321 MaxVersion: VersionSSL30,
6322 Bugs: ProtocolBugs{
6323 RequireRenegotiationInfo: true,
6324 },
6325 },
David Benjamind2610042017-01-03 10:49:28 -05006326 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006327 })
6328 testCases = append(testCases, testCase{
6329 testType: serverTest,
6330 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6331 config: Config{
6332 MaxVersion: VersionSSL30,
6333 Bugs: ProtocolBugs{
6334 NoRenegotiationInfo: true,
6335 SendRenegotiationSCSV: true,
6336 RequireRenegotiationInfo: true,
6337 },
6338 },
David Benjamind2610042017-01-03 10:49:28 -05006339 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006340 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006341
6342 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6343 // in ServerHello.
6344 testCases = append(testCases, testCase{
6345 name: "NPN-Forbidden-TLS13",
6346 config: Config{
6347 MaxVersion: VersionTLS13,
6348 NextProtos: []string{"foo"},
6349 Bugs: ProtocolBugs{
6350 NegotiateNPNAtAllVersions: true,
6351 },
6352 },
6353 flags: []string{"-select-next-proto", "foo"},
6354 shouldFail: true,
6355 expectedError: ":ERROR_PARSING_EXTENSION:",
6356 })
6357 testCases = append(testCases, testCase{
6358 name: "EMS-Forbidden-TLS13",
6359 config: Config{
6360 MaxVersion: VersionTLS13,
6361 Bugs: ProtocolBugs{
6362 NegotiateEMSAtAllVersions: true,
6363 },
6364 },
6365 shouldFail: true,
6366 expectedError: ":ERROR_PARSING_EXTENSION:",
6367 })
6368 testCases = append(testCases, testCase{
6369 name: "RenegotiationInfo-Forbidden-TLS13",
6370 config: Config{
6371 MaxVersion: VersionTLS13,
6372 Bugs: ProtocolBugs{
6373 NegotiateRenegotiationInfoAtAllVersions: true,
6374 },
6375 },
6376 shouldFail: true,
6377 expectedError: ":ERROR_PARSING_EXTENSION:",
6378 })
6379 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006380 name: "Ticket-Forbidden-TLS13",
6381 config: Config{
6382 MaxVersion: VersionTLS12,
6383 },
6384 resumeConfig: &Config{
6385 MaxVersion: VersionTLS13,
6386 Bugs: ProtocolBugs{
6387 AdvertiseTicketExtension: true,
6388 },
6389 },
6390 resumeSession: true,
6391 shouldFail: true,
6392 expectedError: ":ERROR_PARSING_EXTENSION:",
6393 })
6394
6395 // Test that illegal extensions in TLS 1.3 are declined by the server if
6396 // offered in ClientHello. The runner's server will fail if this occurs,
6397 // so we exercise the offering path. (EMS and Renegotiation Info are
6398 // implicit in every test.)
6399 testCases = append(testCases, testCase{
6400 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006401 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006402 config: Config{
6403 MaxVersion: VersionTLS13,
6404 NextProtos: []string{"bar"},
6405 },
6406 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6407 })
David Benjamin196df5b2016-09-21 16:23:27 -04006408
David Benjamindaa88502016-10-04 16:32:16 -04006409 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6410 // tolerated.
6411 testCases = append(testCases, testCase{
6412 name: "SendOCSPResponseOnResume-TLS12",
6413 config: Config{
6414 MaxVersion: VersionTLS12,
6415 Bugs: ProtocolBugs{
6416 SendOCSPResponseOnResume: []byte("bogus"),
6417 },
6418 },
6419 flags: []string{
6420 "-enable-ocsp-stapling",
6421 "-expect-ocsp-response",
6422 base64.StdEncoding.EncodeToString(testOCSPResponse),
6423 },
6424 resumeSession: true,
6425 })
6426
David Benjamindaa88502016-10-04 16:32:16 -04006427 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006428 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006429 config: Config{
6430 MaxVersion: VersionTLS13,
6431 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006432 SendExtensionOnCertificate: testOCSPExtension,
6433 },
6434 },
6435 shouldFail: true,
6436 expectedError: ":UNEXPECTED_EXTENSION:",
6437 })
6438
6439 testCases = append(testCases, testCase{
6440 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6441 config: Config{
6442 MaxVersion: VersionTLS13,
6443 Bugs: ProtocolBugs{
6444 SendExtensionOnCertificate: testSCTExtension,
6445 },
6446 },
6447 shouldFail: true,
6448 expectedError: ":UNEXPECTED_EXTENSION:",
6449 })
6450
6451 // Test that extensions on client certificates are never accepted.
6452 testCases = append(testCases, testCase{
6453 name: "SendExtensionOnClientCertificate-TLS13",
6454 testType: serverTest,
6455 config: Config{
6456 MaxVersion: VersionTLS13,
6457 Certificates: []Certificate{rsaCertificate},
6458 Bugs: ProtocolBugs{
6459 SendExtensionOnCertificate: testOCSPExtension,
6460 },
6461 },
6462 flags: []string{
6463 "-enable-ocsp-stapling",
6464 "-require-any-client-certificate",
6465 },
6466 shouldFail: true,
6467 expectedError: ":UNEXPECTED_EXTENSION:",
6468 })
6469
6470 testCases = append(testCases, testCase{
6471 name: "SendUnknownExtensionOnCertificate-TLS13",
6472 config: Config{
6473 MaxVersion: VersionTLS13,
6474 Bugs: ProtocolBugs{
6475 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6476 },
6477 },
6478 shouldFail: true,
6479 expectedError: ":UNEXPECTED_EXTENSION:",
6480 })
6481
6482 // Test that extensions on intermediates are allowed but ignored.
6483 testCases = append(testCases, testCase{
6484 name: "IgnoreExtensionsOnIntermediates-TLS13",
6485 config: Config{
6486 MaxVersion: VersionTLS13,
6487 Certificates: []Certificate{rsaChainCertificate},
6488 Bugs: ProtocolBugs{
6489 // Send different values on the intermediate. This tests
6490 // the intermediate's extensions do not override the
6491 // leaf's.
David Benjamin5c4271f2017-08-23 22:09:41 -07006492 SendOCSPOnIntermediates: testOCSPResponse2,
6493 SendSCTOnIntermediates: testSCTList2,
David Benjamindaa88502016-10-04 16:32:16 -04006494 },
6495 },
6496 flags: []string{
6497 "-enable-ocsp-stapling",
6498 "-expect-ocsp-response",
6499 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006500 "-enable-signed-cert-timestamps",
6501 "-expect-signed-cert-timestamps",
6502 base64.StdEncoding.EncodeToString(testSCTList),
6503 },
6504 resumeSession: true,
6505 })
6506
6507 // Test that extensions are not sent on intermediates when configured
6508 // only for a leaf.
6509 testCases = append(testCases, testCase{
6510 testType: serverTest,
6511 name: "SendNoExtensionsOnIntermediate-TLS13",
6512 config: Config{
6513 MaxVersion: VersionTLS13,
6514 Bugs: ProtocolBugs{
6515 ExpectNoExtensionsOnIntermediate: true,
6516 },
6517 },
6518 flags: []string{
6519 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6520 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6521 "-ocsp-response",
6522 base64.StdEncoding.EncodeToString(testOCSPResponse),
6523 "-signed-cert-timestamps",
6524 base64.StdEncoding.EncodeToString(testSCTList),
6525 },
6526 })
6527
6528 // Test that extensions are not sent on client certificates.
6529 testCases = append(testCases, testCase{
6530 name: "SendNoClientCertificateExtensions-TLS13",
6531 config: Config{
6532 MaxVersion: VersionTLS13,
6533 ClientAuth: RequireAnyClientCert,
6534 },
6535 flags: []string{
6536 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6537 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6538 "-ocsp-response",
6539 base64.StdEncoding.EncodeToString(testOCSPResponse),
6540 "-signed-cert-timestamps",
6541 base64.StdEncoding.EncodeToString(testSCTList),
6542 },
6543 })
6544
6545 testCases = append(testCases, testCase{
6546 name: "SendDuplicateExtensionsOnCerts-TLS13",
6547 config: Config{
6548 MaxVersion: VersionTLS13,
6549 Bugs: ProtocolBugs{
6550 SendDuplicateCertExtensions: true,
6551 },
6552 },
6553 flags: []string{
6554 "-enable-ocsp-stapling",
6555 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006556 },
6557 resumeSession: true,
6558 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006559 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006560 })
Adam Langley9b885c52016-11-18 14:21:03 -08006561
6562 testCases = append(testCases, testCase{
6563 name: "SignedCertificateTimestampListInvalid-Server",
6564 testType: serverTest,
6565 flags: []string{
6566 "-signed-cert-timestamps",
6567 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6568 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006569 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006570 expectedError: ":INVALID_SCT_LIST:",
6571 })
David Benjamine78bfde2014-09-06 12:45:15 -04006572}
6573
David Benjamin01fe8202014-09-24 15:21:44 -04006574func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006575 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006576 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006577 // SSL 3.0 does not have tickets and TLS 1.3 does not
6578 // have session IDs, so skip their cross-resumption
6579 // tests.
6580 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6581 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6582 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006583 }
6584
David Benjamin8b8c0062014-11-23 02:47:52 -05006585 protocols := []protocol{tls}
6586 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6587 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006588 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006589 for _, protocol := range protocols {
6590 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6591 if protocol == dtls {
6592 suffix += "-DTLS"
6593 }
6594
Steven Valdez520e1222017-06-13 12:45:25 -04006595 // We can't resume across TLS 1.3 variants and error out earlier in the
6596 // session resumption.
6597 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6598 continue
6599 }
6600
David Benjaminece3de92015-03-16 18:02:20 -04006601 if sessionVers.version == resumeVers.version {
6602 testCases = append(testCases, testCase{
6603 protocol: protocol,
6604 name: "Resume-Client" + suffix,
6605 resumeSession: true,
6606 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006607 MaxVersion: sessionVers.version,
6608 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006609 Bugs: ProtocolBugs{
6610 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6611 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6612 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006613 },
David Benjaminece3de92015-03-16 18:02:20 -04006614 expectedVersion: sessionVers.version,
6615 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006616 flags: []string{
6617 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6618 },
David Benjaminece3de92015-03-16 18:02:20 -04006619 })
6620 } else {
David Benjamin405da482016-08-08 17:25:07 -04006621 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6622
6623 // Offering a TLS 1.3 session sends an empty session ID, so
6624 // there is no way to convince a non-lookahead client the
6625 // session was resumed. It will appear to the client that a
6626 // stray ChangeCipherSpec was sent.
6627 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6628 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006629 }
6630
David Benjaminece3de92015-03-16 18:02:20 -04006631 testCases = append(testCases, testCase{
6632 protocol: protocol,
6633 name: "Resume-Client-Mismatch" + suffix,
6634 resumeSession: true,
6635 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006636 MaxVersion: sessionVers.version,
6637 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006638 },
David Benjaminece3de92015-03-16 18:02:20 -04006639 expectedVersion: sessionVers.version,
6640 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006641 MaxVersion: resumeVers.version,
6642 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006643 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006644 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006645 },
6646 },
6647 expectedResumeVersion: resumeVers.version,
6648 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006649 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006650 flags: []string{
6651 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6652 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6653 },
David Benjaminece3de92015-03-16 18:02:20 -04006654 })
6655 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006656
6657 testCases = append(testCases, testCase{
6658 protocol: protocol,
6659 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006660 resumeSession: true,
6661 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006662 MaxVersion: sessionVers.version,
6663 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006664 },
6665 expectedVersion: sessionVers.version,
6666 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006667 MaxVersion: resumeVers.version,
6668 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006669 },
6670 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006671 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006672 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006673 flags: []string{
6674 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6675 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6676 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006677 })
6678
David Benjamin8b8c0062014-11-23 02:47:52 -05006679 testCases = append(testCases, testCase{
6680 protocol: protocol,
6681 testType: serverTest,
6682 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006683 resumeSession: true,
6684 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006685 MaxVersion: sessionVers.version,
6686 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006687 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006688 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006689 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006690 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006691 MaxVersion: resumeVers.version,
6692 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006693 Bugs: ProtocolBugs{
6694 SendBothTickets: true,
6695 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006696 },
6697 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006698 flags: []string{
6699 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6700 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6701 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006702 })
6703 }
David Benjamin01fe8202014-09-24 15:21:44 -04006704 }
6705 }
David Benjaminece3de92015-03-16 18:02:20 -04006706
David Benjamin4199b0d2016-11-01 13:58:25 -04006707 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006708 testCases = append(testCases, testCase{
6709 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006710 name: "ShimTicketRewritable",
6711 resumeSession: true,
6712 config: Config{
6713 MaxVersion: VersionTLS12,
6714 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6715 Bugs: ProtocolBugs{
6716 FilterTicket: func(in []byte) ([]byte, error) {
6717 in, err := SetShimTicketVersion(in, VersionTLS12)
6718 if err != nil {
6719 return nil, err
6720 }
6721 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6722 },
6723 },
6724 },
6725 flags: []string{
6726 "-ticket-key",
6727 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6728 },
6729 })
6730
6731 // Resumptions are declined if the version does not match.
6732 testCases = append(testCases, testCase{
6733 testType: serverTest,
6734 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006735 resumeSession: true,
6736 config: Config{
6737 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006738 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006739 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006740 FilterTicket: func(in []byte) ([]byte, error) {
6741 return SetShimTicketVersion(in, VersionTLS13)
6742 },
6743 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006744 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006745 flags: []string{
6746 "-ticket-key",
6747 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6748 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006749 expectResumeRejected: true,
6750 })
6751
6752 testCases = append(testCases, testCase{
6753 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006754 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006755 resumeSession: true,
6756 config: Config{
6757 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006758 Bugs: ProtocolBugs{
6759 FilterTicket: func(in []byte) ([]byte, error) {
6760 return SetShimTicketVersion(in, VersionTLS12)
6761 },
6762 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006763 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006764 flags: []string{
6765 "-ticket-key",
6766 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6767 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006768 expectResumeRejected: true,
6769 })
6770
David Benjamin4199b0d2016-11-01 13:58:25 -04006771 // Resumptions are declined if the cipher is invalid or disabled.
6772 testCases = append(testCases, testCase{
6773 testType: serverTest,
6774 name: "Resume-Server-DeclineBadCipher",
6775 resumeSession: true,
6776 config: Config{
6777 MaxVersion: VersionTLS12,
6778 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006779 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006780 FilterTicket: func(in []byte) ([]byte, error) {
6781 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6782 },
6783 },
6784 },
6785 flags: []string{
6786 "-ticket-key",
6787 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6788 },
6789 expectResumeRejected: true,
6790 })
6791
6792 testCases = append(testCases, testCase{
6793 testType: serverTest,
6794 name: "Resume-Server-DeclineBadCipher-2",
6795 resumeSession: true,
6796 config: Config{
6797 MaxVersion: VersionTLS12,
6798 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006799 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006800 FilterTicket: func(in []byte) ([]byte, error) {
6801 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6802 },
6803 },
6804 },
6805 flags: []string{
6806 "-cipher", "AES128",
6807 "-ticket-key",
6808 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6809 },
6810 expectResumeRejected: true,
6811 })
6812
David Benjaminf01f42a2016-11-16 19:05:33 +09006813 // Sessions are not resumed if they do not use the preferred cipher.
6814 testCases = append(testCases, testCase{
6815 testType: serverTest,
6816 name: "Resume-Server-CipherNotPreferred",
6817 resumeSession: true,
6818 config: Config{
6819 MaxVersion: VersionTLS12,
6820 Bugs: ProtocolBugs{
6821 ExpectNewTicket: true,
6822 FilterTicket: func(in []byte) ([]byte, error) {
6823 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6824 },
6825 },
6826 },
6827 flags: []string{
6828 "-ticket-key",
6829 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6830 },
6831 shouldFail: false,
6832 expectResumeRejected: true,
6833 })
6834
6835 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6836 // PRF hashes match, but BoringSSL will always decline such resumptions.
6837 testCases = append(testCases, testCase{
6838 testType: serverTest,
6839 name: "Resume-Server-CipherNotPreferred-TLS13",
6840 resumeSession: true,
6841 config: Config{
6842 MaxVersion: VersionTLS13,
6843 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6844 Bugs: ProtocolBugs{
6845 FilterTicket: func(in []byte) ([]byte, error) {
6846 // If the client (runner) offers ChaCha20-Poly1305 first, the
6847 // server (shim) always prefers it. Switch it to AES-GCM.
6848 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6849 },
6850 },
6851 },
6852 flags: []string{
6853 "-ticket-key",
6854 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6855 },
6856 shouldFail: false,
6857 expectResumeRejected: true,
6858 })
6859
6860 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006861 testCases = append(testCases, testCase{
6862 testType: serverTest,
6863 name: "Resume-Server-DeclineBadCipher-TLS13",
6864 resumeSession: true,
6865 config: Config{
6866 MaxVersion: VersionTLS13,
6867 Bugs: ProtocolBugs{
6868 FilterTicket: func(in []byte) ([]byte, error) {
6869 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6870 },
6871 },
6872 },
6873 flags: []string{
6874 "-ticket-key",
6875 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6876 },
6877 expectResumeRejected: true,
6878 })
6879
David Benjaminf01f42a2016-11-16 19:05:33 +09006880 // If the client does not offer the cipher from the session, decline to
6881 // resume. Clients are forbidden from doing this, but BoringSSL selects
6882 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006883 testCases = append(testCases, testCase{
6884 testType: serverTest,
6885 name: "Resume-Server-UnofferedCipher",
6886 resumeSession: true,
6887 config: Config{
6888 MaxVersion: VersionTLS12,
6889 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6890 },
6891 resumeConfig: &Config{
6892 MaxVersion: VersionTLS12,
6893 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6894 Bugs: ProtocolBugs{
6895 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6896 },
6897 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006898 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006899 })
6900
David Benjaminf01f42a2016-11-16 19:05:33 +09006901 // In TLS 1.3, clients may advertise a cipher list which does not
6902 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006903 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6904 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006905 testCases = append(testCases, testCase{
6906 testType: serverTest,
6907 name: "Resume-Server-UnofferedCipher-TLS13",
6908 resumeSession: true,
6909 config: Config{
6910 MaxVersion: VersionTLS13,
6911 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6912 },
6913 resumeConfig: &Config{
6914 MaxVersion: VersionTLS13,
6915 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6916 Bugs: ProtocolBugs{
6917 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6918 },
6919 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006920 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006921 })
6922
David Benjamin4199b0d2016-11-01 13:58:25 -04006923 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006924 testCases = append(testCases, testCase{
6925 name: "Resume-Client-CipherMismatch",
6926 resumeSession: true,
6927 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006928 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006929 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6930 },
6931 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006932 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006933 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6934 Bugs: ProtocolBugs{
6935 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6936 },
6937 },
6938 shouldFail: true,
6939 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6940 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006941
David Benjamine1cc35e2016-11-16 16:25:58 +09006942 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6943 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006944 testCases = append(testCases, testCase{
6945 name: "Resume-Client-CipherMismatch-TLS13",
6946 resumeSession: true,
6947 config: Config{
6948 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006949 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006950 },
6951 resumeConfig: &Config{
6952 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006953 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6954 },
6955 })
6956
6957 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6958 testCases = append(testCases, testCase{
6959 name: "Resume-Client-PRFMismatch-TLS13",
6960 resumeSession: true,
6961 config: Config{
6962 MaxVersion: VersionTLS13,
6963 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6964 },
6965 resumeConfig: &Config{
6966 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006967 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006968 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006969 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006970 },
6971 },
6972 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006973 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006974 })
Steven Valdeza833c352016-11-01 13:39:36 -04006975
6976 testCases = append(testCases, testCase{
6977 testType: serverTest,
6978 name: "Resume-Server-BinderWrongLength",
6979 resumeSession: true,
6980 config: Config{
6981 MaxVersion: VersionTLS13,
6982 Bugs: ProtocolBugs{
6983 SendShortPSKBinder: true,
6984 },
6985 },
6986 shouldFail: true,
6987 expectedLocalError: "remote error: error decrypting message",
6988 expectedError: ":DIGEST_CHECK_FAILED:",
6989 })
6990
6991 testCases = append(testCases, testCase{
6992 testType: serverTest,
6993 name: "Resume-Server-NoPSKBinder",
6994 resumeSession: true,
6995 config: Config{
6996 MaxVersion: VersionTLS13,
6997 Bugs: ProtocolBugs{
6998 SendNoPSKBinder: true,
6999 },
7000 },
7001 shouldFail: true,
7002 expectedLocalError: "remote error: error decoding message",
7003 expectedError: ":DECODE_ERROR:",
7004 })
7005
7006 testCases = append(testCases, testCase{
7007 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05007008 name: "Resume-Server-ExtraPSKBinder",
7009 resumeSession: true,
7010 config: Config{
7011 MaxVersion: VersionTLS13,
7012 Bugs: ProtocolBugs{
7013 SendExtraPSKBinder: true,
7014 },
7015 },
7016 shouldFail: true,
7017 expectedLocalError: "remote error: illegal parameter",
7018 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7019 })
7020
7021 testCases = append(testCases, testCase{
7022 testType: serverTest,
7023 name: "Resume-Server-ExtraIdentityNoBinder",
7024 resumeSession: true,
7025 config: Config{
7026 MaxVersion: VersionTLS13,
7027 Bugs: ProtocolBugs{
7028 ExtraPSKIdentity: true,
7029 },
7030 },
7031 shouldFail: true,
7032 expectedLocalError: "remote error: illegal parameter",
7033 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7034 })
7035
7036 testCases = append(testCases, testCase{
7037 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007038 name: "Resume-Server-InvalidPSKBinder",
7039 resumeSession: true,
7040 config: Config{
7041 MaxVersion: VersionTLS13,
7042 Bugs: ProtocolBugs{
7043 SendInvalidPSKBinder: true,
7044 },
7045 },
7046 shouldFail: true,
7047 expectedLocalError: "remote error: error decrypting message",
7048 expectedError: ":DIGEST_CHECK_FAILED:",
7049 })
7050
7051 testCases = append(testCases, testCase{
7052 testType: serverTest,
7053 name: "Resume-Server-PSKBinderFirstExtension",
7054 resumeSession: true,
7055 config: Config{
7056 MaxVersion: VersionTLS13,
7057 Bugs: ProtocolBugs{
7058 PSKBinderFirst: true,
7059 },
7060 },
7061 shouldFail: true,
7062 expectedLocalError: "remote error: illegal parameter",
7063 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7064 })
David Benjamin01fe8202014-09-24 15:21:44 -04007065}
7066
Adam Langley2ae77d22014-10-28 17:29:33 -07007067func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007068 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007069 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007070 testType: serverTest,
7071 name: "Renegotiate-Server-Forbidden",
7072 config: Config{
7073 MaxVersion: VersionTLS12,
7074 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007075 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007076 shouldFail: true,
7077 expectedError: ":NO_RENEGOTIATION:",
7078 expectedLocalError: "remote error: no renegotiation",
7079 })
Adam Langley5021b222015-06-12 18:27:58 -07007080 // The server shouldn't echo the renegotiation extension unless
7081 // requested by the client.
7082 testCases = append(testCases, testCase{
7083 testType: serverTest,
7084 name: "Renegotiate-Server-NoExt",
7085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007086 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007087 Bugs: ProtocolBugs{
7088 NoRenegotiationInfo: true,
7089 RequireRenegotiationInfo: true,
7090 },
7091 },
7092 shouldFail: true,
7093 expectedLocalError: "renegotiation extension missing",
7094 })
7095 // The renegotiation SCSV should be sufficient for the server to echo
7096 // the extension.
7097 testCases = append(testCases, testCase{
7098 testType: serverTest,
7099 name: "Renegotiate-Server-NoExt-SCSV",
7100 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007101 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007102 Bugs: ProtocolBugs{
7103 NoRenegotiationInfo: true,
7104 SendRenegotiationSCSV: true,
7105 RequireRenegotiationInfo: true,
7106 },
7107 },
7108 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007109 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007110 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007112 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007113 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007114 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007115 },
7116 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007117 renegotiate: 1,
7118 flags: []string{
7119 "-renegotiate-freely",
7120 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007121 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007122 },
David Benjamincdea40c2015-03-19 14:09:43 -04007123 })
7124 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007125 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007126 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007128 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007129 Bugs: ProtocolBugs{
7130 EmptyRenegotiationInfo: true,
7131 },
7132 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007133 flags: []string{"-renegotiate-freely"},
7134 shouldFail: true,
7135 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007136 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007137 })
7138 testCases = append(testCases, testCase{
7139 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007140 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007142 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007143 Bugs: ProtocolBugs{
7144 BadRenegotiationInfo: true,
7145 },
7146 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007147 flags: []string{"-renegotiate-freely"},
7148 shouldFail: true,
7149 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007150 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007151 })
7152 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007153 name: "Renegotiate-Client-BadExt2",
7154 renegotiate: 1,
7155 config: Config{
7156 MaxVersion: VersionTLS12,
7157 Bugs: ProtocolBugs{
7158 BadRenegotiationInfoEnd: true,
7159 },
7160 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007161 flags: []string{"-renegotiate-freely"},
7162 shouldFail: true,
7163 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007164 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007165 })
7166 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007167 name: "Renegotiate-Client-Downgrade",
7168 renegotiate: 1,
7169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007170 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007171 Bugs: ProtocolBugs{
7172 NoRenegotiationInfoAfterInitial: true,
7173 },
7174 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007175 flags: []string{"-renegotiate-freely"},
7176 shouldFail: true,
7177 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007178 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007179 })
7180 testCases = append(testCases, testCase{
7181 name: "Renegotiate-Client-Upgrade",
7182 renegotiate: 1,
7183 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007184 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007185 Bugs: ProtocolBugs{
7186 NoRenegotiationInfoInInitial: true,
7187 },
7188 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007189 flags: []string{"-renegotiate-freely"},
7190 shouldFail: true,
7191 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007192 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007193 })
7194 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007195 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007196 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007198 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007199 Bugs: ProtocolBugs{
7200 NoRenegotiationInfo: true,
7201 },
7202 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007203 flags: []string{
7204 "-renegotiate-freely",
7205 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007206 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007207 },
David Benjamincff0b902015-05-15 23:09:47 -04007208 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007209
7210 // Test that the server may switch ciphers on renegotiation without
7211 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007212 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007213 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007214 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007215 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007216 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007217 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007218 },
7219 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007220 flags: []string{
7221 "-renegotiate-freely",
7222 "-expect-total-renegotiations", "1",
7223 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007224 })
7225 testCases = append(testCases, testCase{
7226 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007227 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007228 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007229 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007230 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7231 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007232 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007233 flags: []string{
7234 "-renegotiate-freely",
7235 "-expect-total-renegotiations", "1",
7236 },
David Benjaminb16346b2015-04-08 19:16:58 -04007237 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007238
7239 // Test that the server may not switch versions on renegotiation.
7240 testCases = append(testCases, testCase{
7241 name: "Renegotiate-Client-SwitchVersion",
7242 config: Config{
7243 MaxVersion: VersionTLS12,
7244 // Pick a cipher which exists at both versions.
7245 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7246 Bugs: ProtocolBugs{
7247 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007248 // Avoid failing early at the record layer.
7249 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007250 },
7251 },
7252 renegotiate: 1,
7253 flags: []string{
7254 "-renegotiate-freely",
7255 "-expect-total-renegotiations", "1",
7256 },
7257 shouldFail: true,
7258 expectedError: ":WRONG_SSL_VERSION:",
7259 })
7260
David Benjaminb16346b2015-04-08 19:16:58 -04007261 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007262 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007263 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007264 config: Config{
7265 MaxVersion: VersionTLS10,
7266 Bugs: ProtocolBugs{
7267 RequireSameRenegoClientVersion: true,
7268 },
7269 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007270 flags: []string{
7271 "-renegotiate-freely",
7272 "-expect-total-renegotiations", "1",
7273 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007274 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007275 testCases = append(testCases, testCase{
7276 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007277 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007278 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007279 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007280 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7281 NextProtos: []string{"foo"},
7282 },
7283 flags: []string{
7284 "-false-start",
7285 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007286 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007287 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007288 },
7289 shimWritesFirst: true,
7290 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007291
7292 // Client-side renegotiation controls.
7293 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007294 name: "Renegotiate-Client-Forbidden-1",
7295 config: Config{
7296 MaxVersion: VersionTLS12,
7297 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007298 renegotiate: 1,
7299 shouldFail: true,
7300 expectedError: ":NO_RENEGOTIATION:",
7301 expectedLocalError: "remote error: no renegotiation",
7302 })
7303 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007304 name: "Renegotiate-Client-Once-1",
7305 config: Config{
7306 MaxVersion: VersionTLS12,
7307 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007308 renegotiate: 1,
7309 flags: []string{
7310 "-renegotiate-once",
7311 "-expect-total-renegotiations", "1",
7312 },
7313 })
7314 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007315 name: "Renegotiate-Client-Freely-1",
7316 config: Config{
7317 MaxVersion: VersionTLS12,
7318 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007319 renegotiate: 1,
7320 flags: []string{
7321 "-renegotiate-freely",
7322 "-expect-total-renegotiations", "1",
7323 },
7324 })
7325 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007326 name: "Renegotiate-Client-Once-2",
7327 config: Config{
7328 MaxVersion: VersionTLS12,
7329 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007330 renegotiate: 2,
7331 flags: []string{"-renegotiate-once"},
7332 shouldFail: true,
7333 expectedError: ":NO_RENEGOTIATION:",
7334 expectedLocalError: "remote error: no renegotiation",
7335 })
7336 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007337 name: "Renegotiate-Client-Freely-2",
7338 config: Config{
7339 MaxVersion: VersionTLS12,
7340 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007341 renegotiate: 2,
7342 flags: []string{
7343 "-renegotiate-freely",
7344 "-expect-total-renegotiations", "2",
7345 },
7346 })
Adam Langley27a0d082015-11-03 13:34:10 -08007347 testCases = append(testCases, testCase{
7348 name: "Renegotiate-Client-NoIgnore",
7349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007350 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007351 Bugs: ProtocolBugs{
7352 SendHelloRequestBeforeEveryAppDataRecord: true,
7353 },
7354 },
7355 shouldFail: true,
7356 expectedError: ":NO_RENEGOTIATION:",
7357 })
7358 testCases = append(testCases, testCase{
7359 name: "Renegotiate-Client-Ignore",
7360 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007361 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007362 Bugs: ProtocolBugs{
7363 SendHelloRequestBeforeEveryAppDataRecord: true,
7364 },
7365 },
7366 flags: []string{
7367 "-renegotiate-ignore",
7368 "-expect-total-renegotiations", "0",
7369 },
7370 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007371
David Benjamin34941c02016-10-08 11:45:31 -04007372 // Renegotiation is not allowed at SSL 3.0.
7373 testCases = append(testCases, testCase{
7374 name: "Renegotiate-Client-SSL3",
7375 config: Config{
7376 MaxVersion: VersionSSL30,
7377 },
7378 renegotiate: 1,
7379 flags: []string{
7380 "-renegotiate-freely",
7381 "-expect-total-renegotiations", "1",
7382 },
7383 shouldFail: true,
7384 expectedError: ":NO_RENEGOTIATION:",
7385 expectedLocalError: "remote error: no renegotiation",
7386 })
7387
David Benjamina1eaba12017-01-01 23:19:22 -05007388 // Renegotiation is not allowed when there is an unfinished write.
7389 testCases = append(testCases, testCase{
7390 name: "Renegotiate-Client-UnfinishedWrite",
7391 config: Config{
7392 MaxVersion: VersionTLS12,
7393 },
David Benjaminbbba9392017-04-06 12:54:12 -04007394 renegotiate: 1,
7395 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007396 flags: []string{
7397 "-async",
7398 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007399 },
7400 shouldFail: true,
7401 expectedError: ":NO_RENEGOTIATION:",
7402 // We do not successfully send the no_renegotiation alert in
7403 // this case. https://crbug.com/boringssl/130
7404 })
7405
David Benjamin07ab5d42017-02-09 20:11:41 -05007406 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007407 testCases = append(testCases, testCase{
7408 name: "StrayHelloRequest",
7409 config: Config{
7410 MaxVersion: VersionTLS12,
7411 Bugs: ProtocolBugs{
7412 SendHelloRequestBeforeEveryHandshakeMessage: true,
7413 },
7414 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007415 shouldFail: true,
7416 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007417 })
7418 testCases = append(testCases, testCase{
7419 name: "StrayHelloRequest-Packed",
7420 config: Config{
7421 MaxVersion: VersionTLS12,
7422 Bugs: ProtocolBugs{
7423 PackHandshakeFlight: true,
7424 SendHelloRequestBeforeEveryHandshakeMessage: true,
7425 },
7426 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007427 shouldFail: true,
7428 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007429 })
7430
David Benjamin12d2c482016-07-24 10:56:51 -04007431 // Test renegotiation works if HelloRequest and server Finished come in
7432 // the same record.
7433 testCases = append(testCases, testCase{
7434 name: "Renegotiate-Client-Packed",
7435 config: Config{
7436 MaxVersion: VersionTLS12,
7437 Bugs: ProtocolBugs{
7438 PackHandshakeFlight: true,
7439 PackHelloRequestWithFinished: true,
7440 },
7441 },
7442 renegotiate: 1,
7443 flags: []string{
7444 "-renegotiate-freely",
7445 "-expect-total-renegotiations", "1",
7446 },
7447 })
7448
David Benjamin397c8e62016-07-08 14:14:36 -07007449 // Renegotiation is forbidden in TLS 1.3.
7450 testCases = append(testCases, testCase{
7451 name: "Renegotiate-Client-TLS13",
7452 config: Config{
7453 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007454 Bugs: ProtocolBugs{
7455 SendHelloRequestBeforeEveryAppDataRecord: true,
7456 },
David Benjamin397c8e62016-07-08 14:14:36 -07007457 },
David Benjamin397c8e62016-07-08 14:14:36 -07007458 flags: []string{
7459 "-renegotiate-freely",
7460 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007461 shouldFail: true,
7462 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007463 })
7464
7465 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7466 testCases = append(testCases, testCase{
7467 name: "StrayHelloRequest-TLS13",
7468 config: Config{
7469 MaxVersion: VersionTLS13,
7470 Bugs: ProtocolBugs{
7471 SendHelloRequestBeforeEveryHandshakeMessage: true,
7472 },
7473 },
7474 shouldFail: true,
7475 expectedError: ":UNEXPECTED_MESSAGE:",
7476 })
David Benjamind2610042017-01-03 10:49:28 -05007477
7478 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7479 // always reads as supporting it, regardless of whether it was
7480 // negotiated.
7481 testCases = append(testCases, testCase{
7482 name: "AlwaysReportRenegotiationInfo-TLS13",
7483 config: Config{
7484 MaxVersion: VersionTLS13,
7485 Bugs: ProtocolBugs{
7486 NoRenegotiationInfo: true,
7487 },
7488 },
7489 flags: []string{
7490 "-expect-secure-renegotiation",
7491 },
7492 })
David Benjamina58baaf2017-02-28 20:54:28 -05007493
7494 // Certificates may not change on renegotiation.
7495 testCases = append(testCases, testCase{
7496 name: "Renegotiation-CertificateChange",
7497 config: Config{
7498 MaxVersion: VersionTLS12,
7499 Certificates: []Certificate{rsaCertificate},
7500 Bugs: ProtocolBugs{
7501 RenegotiationCertificate: &rsaChainCertificate,
7502 },
7503 },
7504 renegotiate: 1,
7505 flags: []string{"-renegotiate-freely"},
7506 shouldFail: true,
7507 expectedError: ":SERVER_CERT_CHANGED:",
7508 })
7509 testCases = append(testCases, testCase{
7510 name: "Renegotiation-CertificateChange-2",
7511 config: Config{
7512 MaxVersion: VersionTLS12,
7513 Certificates: []Certificate{rsaCertificate},
7514 Bugs: ProtocolBugs{
7515 RenegotiationCertificate: &rsa1024Certificate,
7516 },
7517 },
7518 renegotiate: 1,
7519 flags: []string{"-renegotiate-freely"},
7520 shouldFail: true,
7521 expectedError: ":SERVER_CERT_CHANGED:",
7522 })
David Benjaminbbf42462017-03-14 21:27:10 -04007523
7524 // We do not negotiate ALPN after the initial handshake. This is
7525 // error-prone and only risks bugs in consumers.
7526 testCases = append(testCases, testCase{
7527 testType: clientTest,
7528 name: "Renegotiation-ForbidALPN",
7529 config: Config{
7530 MaxVersion: VersionTLS12,
7531 Bugs: ProtocolBugs{
7532 // Forcibly negotiate ALPN on both initial and
7533 // renegotiation handshakes. The test stack will
7534 // internally check the client does not offer
7535 // it.
7536 SendALPN: "foo",
7537 },
7538 },
7539 flags: []string{
7540 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7541 "-expect-alpn", "foo",
7542 "-renegotiate-freely",
7543 },
7544 renegotiate: 1,
7545 shouldFail: true,
7546 expectedError: ":UNEXPECTED_EXTENSION:",
7547 })
David Benjamin5c4271f2017-08-23 22:09:41 -07007548
7549 // The server may send different stapled OCSP responses or SCT lists on
7550 // renegotiation, but BoringSSL ignores this and reports the old values.
7551 // Also test that non-fatal verify results are preserved.
7552 testCases = append(testCases, testCase{
7553 testType: clientTest,
7554 name: "Renegotiation-ChangeAuthProperties",
7555 config: Config{
7556 MaxVersion: VersionTLS12,
7557 Bugs: ProtocolBugs{
7558 SendOCSPResponseOnRenegotiation: testOCSPResponse2,
7559 SendSCTListOnRenegotiation: testSCTList2,
7560 },
7561 },
7562 renegotiate: 1,
7563 flags: []string{
7564 "-renegotiate-freely",
7565 "-expect-total-renegotiations", "1",
7566 "-enable-ocsp-stapling",
7567 "-expect-ocsp-response",
7568 base64.StdEncoding.EncodeToString(testOCSPResponse),
7569 "-enable-signed-cert-timestamps",
7570 "-expect-signed-cert-timestamps",
7571 base64.StdEncoding.EncodeToString(testSCTList),
7572 "-verify-fail",
7573 "-expect-verify-result",
7574 },
7575 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007576}
7577
David Benjamin5e961c12014-11-07 01:48:35 -05007578func addDTLSReplayTests() {
7579 // Test that sequence number replays are detected.
7580 testCases = append(testCases, testCase{
7581 protocol: dtls,
7582 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007583 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007584 replayWrites: true,
7585 })
7586
David Benjamin8e6db492015-07-25 18:29:23 -04007587 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007588 // than the retransmit window.
7589 testCases = append(testCases, testCase{
7590 protocol: dtls,
7591 name: "DTLS-Replay-LargeGaps",
7592 config: Config{
7593 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007594 SequenceNumberMapping: func(in uint64) uint64 {
7595 return in * 127
7596 },
David Benjamin5e961c12014-11-07 01:48:35 -05007597 },
7598 },
David Benjamin8e6db492015-07-25 18:29:23 -04007599 messageCount: 200,
7600 replayWrites: true,
7601 })
7602
7603 // Test the incoming sequence number changing non-monotonically.
7604 testCases = append(testCases, testCase{
7605 protocol: dtls,
7606 name: "DTLS-Replay-NonMonotonic",
7607 config: Config{
7608 Bugs: ProtocolBugs{
7609 SequenceNumberMapping: func(in uint64) uint64 {
7610 return in ^ 31
7611 },
7612 },
7613 },
7614 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007615 replayWrites: true,
7616 })
7617}
7618
Nick Harper60edffd2016-06-21 15:19:24 -07007619var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007620 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007621 id signatureAlgorithm
7622 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007623}{
Nick Harper60edffd2016-06-21 15:19:24 -07007624 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7625 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7626 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7627 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007628 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007629 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7630 // hash function doesn't have to match the curve and so the same
7631 // signature algorithm works with P-224.
7632 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007633 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7634 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7635 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007636 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7637 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7638 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007639 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007640 // Tests for key types prior to TLS 1.2.
7641 {"RSA", 0, testCertRSA},
7642 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007643}
7644
Nick Harper60edffd2016-06-21 15:19:24 -07007645const fakeSigAlg1 signatureAlgorithm = 0x2a01
7646const fakeSigAlg2 signatureAlgorithm = 0xff01
7647
7648func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007649 // Not all ciphers involve a signature. Advertise a list which gives all
7650 // versions a signing cipher.
7651 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007652 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007653 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7654 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7655 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7656 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007657 }
David Benjamin5208fd42016-07-13 21:43:25 -04007658
David Benjaminca3d5452016-07-14 12:51:01 -04007659 var allAlgorithms []signatureAlgorithm
7660 for _, alg := range testSignatureAlgorithms {
7661 if alg.id != 0 {
7662 allAlgorithms = append(allAlgorithms, alg.id)
7663 }
7664 }
7665
Nick Harper60edffd2016-06-21 15:19:24 -07007666 // Make sure each signature algorithm works. Include some fake values in
7667 // the list and ensure they're ignored.
7668 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007669 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007670 if (ver.version < VersionTLS12) != (alg.id == 0) {
7671 continue
7672 }
7673
7674 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7675 // or remove it in C.
7676 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007677 continue
7678 }
Nick Harper60edffd2016-06-21 15:19:24 -07007679
David Benjamin3ef76972016-10-17 17:59:54 -04007680 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007681 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007682 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007683 shouldSignFail = true
7684 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007685 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007686 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007687 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7688 shouldSignFail = true
7689 shouldVerifyFail = true
7690 }
7691 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7692 // the curve has to match the hash size.
7693 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007694 shouldSignFail = true
7695 shouldVerifyFail = true
7696 }
7697
7698 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7699 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7700 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007701 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007702
7703 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007704 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007705 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007706 }
7707 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007708 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007709 }
David Benjamin000800a2014-11-14 01:43:59 -05007710
David Benjamin1fb125c2016-07-08 18:52:12 -07007711 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007712
David Benjamin7a41d372016-07-09 11:21:54 -07007713 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007714 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007715 config: Config{
7716 MaxVersion: ver.version,
7717 ClientAuth: RequireAnyClientCert,
7718 VerifySignatureAlgorithms: []signatureAlgorithm{
7719 fakeSigAlg1,
7720 alg.id,
7721 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007722 },
David Benjamin7a41d372016-07-09 11:21:54 -07007723 },
7724 flags: []string{
7725 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7726 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7727 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007728 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007729 },
David Benjamina5022392017-07-10 17:40:39 -04007730 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007731 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007732 expectedError: signError,
7733 expectedPeerSignatureAlgorithm: alg.id,
7734 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007735
David Benjamin7a41d372016-07-09 11:21:54 -07007736 testCases = append(testCases, testCase{
7737 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007738 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007739 config: Config{
7740 MaxVersion: ver.version,
7741 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7742 SignSignatureAlgorithms: []signatureAlgorithm{
7743 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007744 },
David Benjamin7a41d372016-07-09 11:21:54 -07007745 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007746 SkipECDSACurveCheck: shouldVerifyFail,
7747 IgnoreSignatureVersionChecks: shouldVerifyFail,
7748 // Some signature algorithms may not be advertised.
7749 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007750 },
David Benjamin7a41d372016-07-09 11:21:54 -07007751 },
David Benjamina5022392017-07-10 17:40:39 -04007752 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007753 flags: []string{
7754 "-require-any-client-certificate",
7755 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7756 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007757 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007758 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007759 // Resume the session to assert the peer signature
7760 // algorithm is reported on both handshakes.
7761 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007762 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007763 expectedError: verifyError,
7764 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007765
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007766 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007767 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007768 testCases = append(testCases, testCase{
7769 testType: serverTest,
7770 name: "ServerAuth-Sign" + suffix,
7771 config: Config{
7772 MaxVersion: ver.version,
7773 CipherSuites: signingCiphers,
7774 VerifySignatureAlgorithms: []signatureAlgorithm{
7775 fakeSigAlg1,
7776 alg.id,
7777 fakeSigAlg2,
7778 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007779 },
David Benjamina5022392017-07-10 17:40:39 -04007780 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007781 flags: []string{
7782 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7783 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7784 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007785 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007786 },
7787 shouldFail: shouldSignFail,
7788 expectedError: signError,
7789 expectedPeerSignatureAlgorithm: alg.id,
7790 })
7791 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007792
7793 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007794 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007795 config: Config{
7796 MaxVersion: ver.version,
7797 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007798 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007799 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007800 alg.id,
7801 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007802 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007803 SkipECDSACurveCheck: shouldVerifyFail,
7804 IgnoreSignatureVersionChecks: shouldVerifyFail,
7805 // Some signature algorithms may not be advertised.
7806 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007807 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007808 },
David Benjamina5022392017-07-10 17:40:39 -04007809 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007810 flags: []string{
7811 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7812 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007813 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007814 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007815 // Resume the session to assert the peer signature
7816 // algorithm is reported on both handshakes.
7817 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007818 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007819 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007820 })
David Benjamin5208fd42016-07-13 21:43:25 -04007821
David Benjamin3ef76972016-10-17 17:59:54 -04007822 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007823 testCases = append(testCases, testCase{
7824 testType: serverTest,
7825 name: "ClientAuth-InvalidSignature" + suffix,
7826 config: Config{
7827 MaxVersion: ver.version,
7828 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7829 SignSignatureAlgorithms: []signatureAlgorithm{
7830 alg.id,
7831 },
7832 Bugs: ProtocolBugs{
7833 InvalidSignature: true,
7834 },
7835 },
David Benjamina5022392017-07-10 17:40:39 -04007836 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007837 flags: []string{
7838 "-require-any-client-certificate",
7839 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007840 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007841 },
7842 shouldFail: true,
7843 expectedError: ":BAD_SIGNATURE:",
7844 })
7845
7846 testCases = append(testCases, testCase{
7847 name: "ServerAuth-InvalidSignature" + suffix,
7848 config: Config{
7849 MaxVersion: ver.version,
7850 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7851 CipherSuites: signingCiphers,
7852 SignSignatureAlgorithms: []signatureAlgorithm{
7853 alg.id,
7854 },
7855 Bugs: ProtocolBugs{
7856 InvalidSignature: true,
7857 },
7858 },
David Benjamina5022392017-07-10 17:40:39 -04007859 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007860 flags: []string{
7861 "-enable-all-curves",
7862 "-enable-ed25519",
7863 },
David Benjamin5208fd42016-07-13 21:43:25 -04007864 shouldFail: true,
7865 expectedError: ":BAD_SIGNATURE:",
7866 })
7867 }
David Benjaminca3d5452016-07-14 12:51:01 -04007868
David Benjamin3ef76972016-10-17 17:59:54 -04007869 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007870 testCases = append(testCases, testCase{
7871 name: "ClientAuth-Sign-Negotiate" + suffix,
7872 config: Config{
7873 MaxVersion: ver.version,
7874 ClientAuth: RequireAnyClientCert,
7875 VerifySignatureAlgorithms: allAlgorithms,
7876 },
David Benjamina5022392017-07-10 17:40:39 -04007877 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007878 flags: []string{
7879 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7880 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7881 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007882 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007883 "-signing-prefs", strconv.Itoa(int(alg.id)),
7884 },
7885 expectedPeerSignatureAlgorithm: alg.id,
7886 })
7887
7888 testCases = append(testCases, testCase{
7889 testType: serverTest,
7890 name: "ServerAuth-Sign-Negotiate" + suffix,
7891 config: Config{
7892 MaxVersion: ver.version,
7893 CipherSuites: signingCiphers,
7894 VerifySignatureAlgorithms: allAlgorithms,
7895 },
David Benjamina5022392017-07-10 17:40:39 -04007896 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007897 flags: []string{
7898 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7899 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7900 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007901 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007902 "-signing-prefs", strconv.Itoa(int(alg.id)),
7903 },
7904 expectedPeerSignatureAlgorithm: alg.id,
7905 })
7906 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007907 }
David Benjamin000800a2014-11-14 01:43:59 -05007908 }
7909
Nick Harper60edffd2016-06-21 15:19:24 -07007910 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007911 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007912 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007913 config: Config{
7914 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007915 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007916 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007917 signatureECDSAWithP521AndSHA512,
7918 signatureRSAPKCS1WithSHA384,
7919 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007920 },
7921 },
7922 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007923 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7924 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007925 },
Nick Harper60edffd2016-06-21 15:19:24 -07007926 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007927 })
7928
7929 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007930 name: "ClientAuth-SignatureType-TLS13",
7931 config: Config{
7932 ClientAuth: RequireAnyClientCert,
7933 MaxVersion: VersionTLS13,
7934 VerifySignatureAlgorithms: []signatureAlgorithm{
7935 signatureECDSAWithP521AndSHA512,
7936 signatureRSAPKCS1WithSHA384,
7937 signatureRSAPSSWithSHA384,
7938 signatureECDSAWithSHA1,
7939 },
7940 },
7941 flags: []string{
7942 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7943 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7944 },
7945 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7946 })
7947
7948 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007949 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007950 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007952 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007953 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007954 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007955 signatureECDSAWithP521AndSHA512,
7956 signatureRSAPKCS1WithSHA384,
7957 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007958 },
7959 },
Nick Harper60edffd2016-06-21 15:19:24 -07007960 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007961 })
7962
Steven Valdez143e8b32016-07-11 13:19:03 -04007963 testCases = append(testCases, testCase{
7964 testType: serverTest,
7965 name: "ServerAuth-SignatureType-TLS13",
7966 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007967 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007968 VerifySignatureAlgorithms: []signatureAlgorithm{
7969 signatureECDSAWithP521AndSHA512,
7970 signatureRSAPKCS1WithSHA384,
7971 signatureRSAPSSWithSHA384,
7972 signatureECDSAWithSHA1,
7973 },
7974 },
7975 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7976 })
7977
David Benjamina95e9f32016-07-08 16:28:04 -07007978 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007979 testCases = append(testCases, testCase{
7980 testType: serverTest,
7981 name: "Verify-ClientAuth-SignatureType",
7982 config: Config{
7983 MaxVersion: VersionTLS12,
7984 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007985 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007986 signatureRSAPKCS1WithSHA256,
7987 },
7988 Bugs: ProtocolBugs{
7989 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7990 },
7991 },
7992 flags: []string{
7993 "-require-any-client-certificate",
7994 },
7995 shouldFail: true,
7996 expectedError: ":WRONG_SIGNATURE_TYPE:",
7997 })
7998
7999 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008000 testType: serverTest,
8001 name: "Verify-ClientAuth-SignatureType-TLS13",
8002 config: Config{
8003 MaxVersion: VersionTLS13,
8004 Certificates: []Certificate{rsaCertificate},
8005 SignSignatureAlgorithms: []signatureAlgorithm{
8006 signatureRSAPSSWithSHA256,
8007 },
8008 Bugs: ProtocolBugs{
8009 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8010 },
8011 },
8012 flags: []string{
8013 "-require-any-client-certificate",
8014 },
8015 shouldFail: true,
8016 expectedError: ":WRONG_SIGNATURE_TYPE:",
8017 })
8018
8019 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008020 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07008021 config: Config{
8022 MaxVersion: VersionTLS12,
8023 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008024 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07008025 signatureRSAPKCS1WithSHA256,
8026 },
8027 Bugs: ProtocolBugs{
8028 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8029 },
8030 },
8031 shouldFail: true,
8032 expectedError: ":WRONG_SIGNATURE_TYPE:",
8033 })
8034
Steven Valdez143e8b32016-07-11 13:19:03 -04008035 testCases = append(testCases, testCase{
8036 name: "Verify-ServerAuth-SignatureType-TLS13",
8037 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008038 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008039 SignSignatureAlgorithms: []signatureAlgorithm{
8040 signatureRSAPSSWithSHA256,
8041 },
8042 Bugs: ProtocolBugs{
8043 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8044 },
8045 },
8046 shouldFail: true,
8047 expectedError: ":WRONG_SIGNATURE_TYPE:",
8048 })
8049
David Benjamin51dd7d62016-07-08 16:07:01 -07008050 // Test that, if the list is missing, the peer falls back to SHA-1 in
8051 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008052 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008053 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008055 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008056 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008057 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008058 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008059 },
8060 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008061 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008062 },
8063 },
8064 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008065 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8066 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008067 },
8068 })
8069
8070 testCases = append(testCases, testCase{
8071 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008072 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008073 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008074 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07008075 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008076 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008077 },
8078 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008079 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008080 },
8081 },
David Benjaminee32bea2016-08-17 13:36:44 -04008082 flags: []string{
8083 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8084 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8085 },
8086 })
8087
8088 testCases = append(testCases, testCase{
8089 name: "ClientAuth-SHA1-Fallback-ECDSA",
8090 config: Config{
8091 MaxVersion: VersionTLS12,
8092 ClientAuth: RequireAnyClientCert,
8093 VerifySignatureAlgorithms: []signatureAlgorithm{
8094 signatureECDSAWithSHA1,
8095 },
8096 Bugs: ProtocolBugs{
8097 NoSignatureAlgorithms: true,
8098 },
8099 },
8100 flags: []string{
8101 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8102 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8103 },
8104 })
8105
8106 testCases = append(testCases, testCase{
8107 testType: serverTest,
8108 name: "ServerAuth-SHA1-Fallback-ECDSA",
8109 config: Config{
8110 MaxVersion: VersionTLS12,
8111 VerifySignatureAlgorithms: []signatureAlgorithm{
8112 signatureECDSAWithSHA1,
8113 },
8114 Bugs: ProtocolBugs{
8115 NoSignatureAlgorithms: true,
8116 },
8117 },
8118 flags: []string{
8119 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8120 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8121 },
David Benjamin000800a2014-11-14 01:43:59 -05008122 })
David Benjamin72dc7832015-03-16 17:49:43 -04008123
David Benjamin51dd7d62016-07-08 16:07:01 -07008124 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008125 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008126 config: Config{
8127 MaxVersion: VersionTLS13,
8128 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008129 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008130 signatureRSAPKCS1WithSHA1,
8131 },
8132 Bugs: ProtocolBugs{
8133 NoSignatureAlgorithms: true,
8134 },
8135 },
8136 flags: []string{
8137 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8138 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8139 },
David Benjamin48901652016-08-01 12:12:47 -04008140 shouldFail: true,
8141 // An empty CertificateRequest signature algorithm list is a
8142 // syntax error in TLS 1.3.
8143 expectedError: ":DECODE_ERROR:",
8144 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008145 })
8146
8147 testCases = append(testCases, testCase{
8148 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008149 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008150 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008151 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008152 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008153 signatureRSAPKCS1WithSHA1,
8154 },
8155 Bugs: ProtocolBugs{
8156 NoSignatureAlgorithms: true,
8157 },
8158 },
8159 shouldFail: true,
8160 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8161 })
8162
David Benjaminb62d2872016-07-18 14:55:02 +02008163 // Test that hash preferences are enforced. BoringSSL does not implement
8164 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008165 testCases = append(testCases, testCase{
8166 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008167 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008169 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008170 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008171 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008172 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008173 },
8174 Bugs: ProtocolBugs{
8175 IgnorePeerSignatureAlgorithmPreferences: true,
8176 },
8177 },
8178 flags: []string{"-require-any-client-certificate"},
8179 shouldFail: true,
8180 expectedError: ":WRONG_SIGNATURE_TYPE:",
8181 })
8182
8183 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008184 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008186 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008187 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008188 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008189 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008190 },
8191 Bugs: ProtocolBugs{
8192 IgnorePeerSignatureAlgorithmPreferences: true,
8193 },
8194 },
8195 shouldFail: true,
8196 expectedError: ":WRONG_SIGNATURE_TYPE:",
8197 })
David Benjaminb62d2872016-07-18 14:55:02 +02008198 testCases = append(testCases, testCase{
8199 testType: serverTest,
8200 name: "ClientAuth-Enforced-TLS13",
8201 config: Config{
8202 MaxVersion: VersionTLS13,
8203 Certificates: []Certificate{rsaCertificate},
8204 SignSignatureAlgorithms: []signatureAlgorithm{
8205 signatureRSAPKCS1WithMD5,
8206 },
8207 Bugs: ProtocolBugs{
8208 IgnorePeerSignatureAlgorithmPreferences: true,
8209 IgnoreSignatureVersionChecks: true,
8210 },
8211 },
8212 flags: []string{"-require-any-client-certificate"},
8213 shouldFail: true,
8214 expectedError: ":WRONG_SIGNATURE_TYPE:",
8215 })
8216
8217 testCases = append(testCases, testCase{
8218 name: "ServerAuth-Enforced-TLS13",
8219 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008220 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008221 SignSignatureAlgorithms: []signatureAlgorithm{
8222 signatureRSAPKCS1WithMD5,
8223 },
8224 Bugs: ProtocolBugs{
8225 IgnorePeerSignatureAlgorithmPreferences: true,
8226 IgnoreSignatureVersionChecks: true,
8227 },
8228 },
8229 shouldFail: true,
8230 expectedError: ":WRONG_SIGNATURE_TYPE:",
8231 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008232
8233 // Test that the agreed upon digest respects the client preferences and
8234 // the server digests.
8235 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008236 name: "NoCommonAlgorithms-Digests",
8237 config: Config{
8238 MaxVersion: VersionTLS12,
8239 ClientAuth: RequireAnyClientCert,
8240 VerifySignatureAlgorithms: []signatureAlgorithm{
8241 signatureRSAPKCS1WithSHA512,
8242 signatureRSAPKCS1WithSHA1,
8243 },
8244 },
8245 flags: []string{
8246 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8247 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8248 "-digest-prefs", "SHA256",
8249 },
8250 shouldFail: true,
8251 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8252 })
8253 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008254 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008255 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008256 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008257 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008258 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008259 signatureRSAPKCS1WithSHA512,
8260 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008261 },
8262 },
8263 flags: []string{
8264 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8265 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008266 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008267 },
David Benjaminca3d5452016-07-14 12:51:01 -04008268 shouldFail: true,
8269 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8270 })
8271 testCases = append(testCases, testCase{
8272 name: "NoCommonAlgorithms-TLS13",
8273 config: Config{
8274 MaxVersion: VersionTLS13,
8275 ClientAuth: RequireAnyClientCert,
8276 VerifySignatureAlgorithms: []signatureAlgorithm{
8277 signatureRSAPSSWithSHA512,
8278 signatureRSAPSSWithSHA384,
8279 },
8280 },
8281 flags: []string{
8282 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8283 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8284 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8285 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008286 shouldFail: true,
8287 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008288 })
8289 testCases = append(testCases, testCase{
8290 name: "Agree-Digest-SHA256",
8291 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008292 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008293 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008294 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008295 signatureRSAPKCS1WithSHA1,
8296 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008297 },
8298 },
8299 flags: []string{
8300 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8301 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008302 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008303 },
Nick Harper60edffd2016-06-21 15:19:24 -07008304 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008305 })
8306 testCases = append(testCases, testCase{
8307 name: "Agree-Digest-SHA1",
8308 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008309 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008310 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008311 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008312 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008313 },
8314 },
8315 flags: []string{
8316 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8317 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008318 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008319 },
Nick Harper60edffd2016-06-21 15:19:24 -07008320 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008321 })
8322 testCases = append(testCases, testCase{
8323 name: "Agree-Digest-Default",
8324 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008325 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008326 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008327 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008328 signatureRSAPKCS1WithSHA256,
8329 signatureECDSAWithP256AndSHA256,
8330 signatureRSAPKCS1WithSHA1,
8331 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008332 },
8333 },
8334 flags: []string{
8335 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8336 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8337 },
Nick Harper60edffd2016-06-21 15:19:24 -07008338 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008339 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008340
David Benjaminca3d5452016-07-14 12:51:01 -04008341 // Test that the signing preference list may include extra algorithms
8342 // without negotiation problems.
8343 testCases = append(testCases, testCase{
8344 testType: serverTest,
8345 name: "FilterExtraAlgorithms",
8346 config: Config{
8347 MaxVersion: VersionTLS12,
8348 VerifySignatureAlgorithms: []signatureAlgorithm{
8349 signatureRSAPKCS1WithSHA256,
8350 },
8351 },
8352 flags: []string{
8353 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8354 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8355 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8356 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8357 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8358 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8359 },
8360 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8361 })
8362
David Benjamin4c3ddf72016-06-29 18:13:53 -04008363 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8364 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008365 testCases = append(testCases, testCase{
8366 name: "CheckLeafCurve",
8367 config: Config{
8368 MaxVersion: VersionTLS12,
8369 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008370 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008371 },
8372 flags: []string{"-p384-only"},
8373 shouldFail: true,
8374 expectedError: ":BAD_ECC_CERT:",
8375 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008376
8377 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8378 testCases = append(testCases, testCase{
8379 name: "CheckLeafCurve-TLS13",
8380 config: Config{
8381 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008382 Certificates: []Certificate{ecdsaP256Certificate},
8383 },
8384 flags: []string{"-p384-only"},
8385 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008386
8387 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8388 testCases = append(testCases, testCase{
8389 name: "ECDSACurveMismatch-Verify-TLS12",
8390 config: Config{
8391 MaxVersion: VersionTLS12,
8392 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8393 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008394 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008395 signatureECDSAWithP384AndSHA384,
8396 },
8397 },
8398 })
8399
8400 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8401 testCases = append(testCases, testCase{
8402 name: "ECDSACurveMismatch-Verify-TLS13",
8403 config: Config{
8404 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008405 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008406 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008407 signatureECDSAWithP384AndSHA384,
8408 },
8409 Bugs: ProtocolBugs{
8410 SkipECDSACurveCheck: true,
8411 },
8412 },
8413 shouldFail: true,
8414 expectedError: ":WRONG_SIGNATURE_TYPE:",
8415 })
8416
8417 // Signature algorithm selection in TLS 1.3 should take the curve into
8418 // account.
8419 testCases = append(testCases, testCase{
8420 testType: serverTest,
8421 name: "ECDSACurveMismatch-Sign-TLS13",
8422 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008423 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008424 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008425 signatureECDSAWithP384AndSHA384,
8426 signatureECDSAWithP256AndSHA256,
8427 },
8428 },
8429 flags: []string{
8430 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8431 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8432 },
8433 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8434 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008435
8436 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8437 // server does not attempt to sign in that case.
8438 testCases = append(testCases, testCase{
8439 testType: serverTest,
8440 name: "RSA-PSS-Large",
8441 config: Config{
8442 MaxVersion: VersionTLS13,
8443 VerifySignatureAlgorithms: []signatureAlgorithm{
8444 signatureRSAPSSWithSHA512,
8445 },
8446 },
8447 flags: []string{
8448 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8449 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8450 },
8451 shouldFail: true,
8452 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8453 })
David Benjamin57e929f2016-08-30 00:30:38 -04008454
8455 // Test that RSA-PSS is enabled by default for TLS 1.2.
8456 testCases = append(testCases, testCase{
8457 testType: clientTest,
8458 name: "RSA-PSS-Default-Verify",
8459 config: Config{
8460 MaxVersion: VersionTLS12,
8461 SignSignatureAlgorithms: []signatureAlgorithm{
8462 signatureRSAPSSWithSHA256,
8463 },
8464 },
8465 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8466 })
8467
8468 testCases = append(testCases, testCase{
8469 testType: serverTest,
8470 name: "RSA-PSS-Default-Sign",
8471 config: Config{
8472 MaxVersion: VersionTLS12,
8473 VerifySignatureAlgorithms: []signatureAlgorithm{
8474 signatureRSAPSSWithSHA256,
8475 },
8476 },
8477 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8478 })
David Benjamin69522112017-03-28 15:38:29 -05008479
8480 // TLS 1.1 and below has no way to advertise support for or negotiate
8481 // Ed25519's signature algorithm.
8482 testCases = append(testCases, testCase{
8483 testType: clientTest,
8484 name: "NoEd25519-TLS11-ServerAuth-Verify",
8485 config: Config{
8486 MaxVersion: VersionTLS11,
8487 Certificates: []Certificate{ed25519Certificate},
8488 Bugs: ProtocolBugs{
8489 // Sign with Ed25519 even though it is TLS 1.1.
8490 UseLegacySigningAlgorithm: signatureEd25519,
8491 },
8492 },
8493 flags: []string{"-enable-ed25519"},
8494 shouldFail: true,
8495 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8496 })
8497 testCases = append(testCases, testCase{
8498 testType: serverTest,
8499 name: "NoEd25519-TLS11-ServerAuth-Sign",
8500 config: Config{
8501 MaxVersion: VersionTLS11,
8502 },
8503 flags: []string{
8504 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8505 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8506 },
8507 shouldFail: true,
8508 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8509 })
8510 testCases = append(testCases, testCase{
8511 testType: serverTest,
8512 name: "NoEd25519-TLS11-ClientAuth-Verify",
8513 config: Config{
8514 MaxVersion: VersionTLS11,
8515 Certificates: []Certificate{ed25519Certificate},
8516 Bugs: ProtocolBugs{
8517 // Sign with Ed25519 even though it is TLS 1.1.
8518 UseLegacySigningAlgorithm: signatureEd25519,
8519 },
8520 },
8521 flags: []string{
8522 "-enable-ed25519",
8523 "-require-any-client-certificate",
8524 },
8525 shouldFail: true,
8526 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8527 })
8528 testCases = append(testCases, testCase{
8529 testType: clientTest,
8530 name: "NoEd25519-TLS11-ClientAuth-Sign",
8531 config: Config{
8532 MaxVersion: VersionTLS11,
8533 ClientAuth: RequireAnyClientCert,
8534 },
8535 flags: []string{
8536 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8537 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8538 },
8539 shouldFail: true,
8540 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8541 })
8542
8543 // Test Ed25519 is not advertised by default.
8544 testCases = append(testCases, testCase{
8545 testType: clientTest,
8546 name: "Ed25519DefaultDisable-NoAdvertise",
8547 config: Config{
8548 Certificates: []Certificate{ed25519Certificate},
8549 },
8550 shouldFail: true,
8551 expectedLocalError: "tls: no common signature algorithms",
8552 })
8553
8554 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8555 // preferences.
8556 testCases = append(testCases, testCase{
8557 testType: clientTest,
8558 name: "Ed25519DefaultDisable-NoAccept",
8559 config: Config{
8560 Certificates: []Certificate{ed25519Certificate},
8561 Bugs: ProtocolBugs{
8562 IgnorePeerSignatureAlgorithmPreferences: true,
8563 },
8564 },
8565 shouldFail: true,
8566 expectedLocalError: "remote error: illegal parameter",
8567 expectedError: ":WRONG_SIGNATURE_TYPE:",
8568 })
David Benjamin71c21b42017-04-14 17:05:40 -04008569
8570 // Test that configuring verify preferences changes what the client
8571 // advertises.
8572 testCases = append(testCases, testCase{
8573 name: "VerifyPreferences-Advertised",
8574 config: Config{
8575 Certificates: []Certificate{rsaCertificate},
8576 SignSignatureAlgorithms: []signatureAlgorithm{
8577 signatureRSAPSSWithSHA256,
8578 signatureRSAPSSWithSHA384,
8579 signatureRSAPSSWithSHA512,
8580 },
8581 },
8582 flags: []string{
8583 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8584 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8585 },
8586 })
8587
8588 // Test that the client advertises a set which the runner can find
8589 // nothing in common with.
8590 testCases = append(testCases, testCase{
8591 name: "VerifyPreferences-NoCommonAlgorithms",
8592 config: Config{
8593 Certificates: []Certificate{rsaCertificate},
8594 SignSignatureAlgorithms: []signatureAlgorithm{
8595 signatureRSAPSSWithSHA256,
8596 signatureRSAPSSWithSHA512,
8597 },
8598 },
8599 flags: []string{
8600 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8601 },
8602 shouldFail: true,
8603 expectedLocalError: "tls: no common signature algorithms",
8604 })
8605
8606 // Test that the client enforces its preferences when configured.
8607 testCases = append(testCases, testCase{
8608 name: "VerifyPreferences-Enforced",
8609 config: Config{
8610 Certificates: []Certificate{rsaCertificate},
8611 SignSignatureAlgorithms: []signatureAlgorithm{
8612 signatureRSAPSSWithSHA256,
8613 signatureRSAPSSWithSHA512,
8614 },
8615 Bugs: ProtocolBugs{
8616 IgnorePeerSignatureAlgorithmPreferences: true,
8617 },
8618 },
8619 flags: []string{
8620 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8621 },
8622 shouldFail: true,
8623 expectedLocalError: "remote error: illegal parameter",
8624 expectedError: ":WRONG_SIGNATURE_TYPE:",
8625 })
8626
8627 // Test that explicitly configuring Ed25519 is as good as changing the
8628 // boolean toggle.
8629 testCases = append(testCases, testCase{
8630 name: "VerifyPreferences-Ed25519",
8631 config: Config{
8632 Certificates: []Certificate{ed25519Certificate},
8633 },
8634 flags: []string{
8635 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8636 },
8637 })
David Benjamin000800a2014-11-14 01:43:59 -05008638}
8639
David Benjamin83f90402015-01-27 01:09:43 -05008640// timeouts is the retransmit schedule for BoringSSL. It doubles and
8641// caps at 60 seconds. On the 13th timeout, it gives up.
8642var timeouts = []time.Duration{
8643 1 * time.Second,
8644 2 * time.Second,
8645 4 * time.Second,
8646 8 * time.Second,
8647 16 * time.Second,
8648 32 * time.Second,
8649 60 * time.Second,
8650 60 * time.Second,
8651 60 * time.Second,
8652 60 * time.Second,
8653 60 * time.Second,
8654 60 * time.Second,
8655 60 * time.Second,
8656}
8657
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008658// shortTimeouts is an alternate set of timeouts which would occur if the
8659// initial timeout duration was set to 250ms.
8660var shortTimeouts = []time.Duration{
8661 250 * time.Millisecond,
8662 500 * time.Millisecond,
8663 1 * time.Second,
8664 2 * time.Second,
8665 4 * time.Second,
8666 8 * time.Second,
8667 16 * time.Second,
8668 32 * time.Second,
8669 60 * time.Second,
8670 60 * time.Second,
8671 60 * time.Second,
8672 60 * time.Second,
8673 60 * time.Second,
8674}
8675
David Benjamin83f90402015-01-27 01:09:43 -05008676func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008677 // These tests work by coordinating some behavior on both the shim and
8678 // the runner.
8679 //
8680 // TimeoutSchedule configures the runner to send a series of timeout
8681 // opcodes to the shim (see packetAdaptor) immediately before reading
8682 // each peer handshake flight N. The timeout opcode both simulates a
8683 // timeout in the shim and acts as a synchronization point to help the
8684 // runner bracket each handshake flight.
8685 //
8686 // We assume the shim does not read from the channel eagerly. It must
8687 // first wait until it has sent flight N and is ready to receive
8688 // handshake flight N+1. At this point, it will process the timeout
8689 // opcode. It must then immediately respond with a timeout ACK and act
8690 // as if the shim was idle for the specified amount of time.
8691 //
8692 // The runner then drops all packets received before the ACK and
8693 // continues waiting for flight N. This ordering results in one attempt
8694 // at sending flight N to be dropped. For the test to complete, the
8695 // shim must send flight N again, testing that the shim implements DTLS
8696 // retransmit on a timeout.
8697
Steven Valdez143e8b32016-07-11 13:19:03 -04008698 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008699 // likely be more epochs to cross and the final message's retransmit may
8700 // be more complex.
8701
David Benjamin11c82892017-02-23 20:40:31 -05008702 // Test that this is indeed the timeout schedule. Stress all
8703 // four patterns of handshake.
8704 for i := 1; i < len(timeouts); i++ {
8705 number := strconv.Itoa(i)
8706 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008707 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008708 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008710 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008711 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008712 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008713 },
8714 },
8715 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008716 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008717 })
David Benjamin11c82892017-02-23 20:40:31 -05008718 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008719 protocol: dtls,
8720 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008721 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008722 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008723 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008724 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008725 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008726 },
8727 },
8728 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008729 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008730 })
8731 }
David Benjamin11c82892017-02-23 20:40:31 -05008732
8733 // Test that exceeding the timeout schedule hits a read
8734 // timeout.
8735 testCases = append(testCases, testCase{
8736 protocol: dtls,
8737 name: "DTLS-Retransmit-Timeout",
8738 config: Config{
8739 MaxVersion: VersionTLS12,
8740 Bugs: ProtocolBugs{
8741 TimeoutSchedule: timeouts,
8742 },
8743 },
8744 resumeSession: true,
8745 flags: []string{"-async"},
8746 shouldFail: true,
8747 expectedError: ":READ_TIMEOUT_EXPIRED:",
8748 })
8749
8750 // Test that timeout handling has a fudge factor, due to API
8751 // problems.
8752 testCases = append(testCases, testCase{
8753 protocol: dtls,
8754 name: "DTLS-Retransmit-Fudge",
8755 config: Config{
8756 MaxVersion: VersionTLS12,
8757 Bugs: ProtocolBugs{
8758 TimeoutSchedule: []time.Duration{
8759 timeouts[0] - 10*time.Millisecond,
8760 },
8761 },
8762 },
8763 resumeSession: true,
8764 flags: []string{"-async"},
8765 })
8766
8767 // Test that the final Finished retransmitting isn't
8768 // duplicated if the peer badly fragments everything.
8769 testCases = append(testCases, testCase{
8770 testType: serverTest,
8771 protocol: dtls,
8772 name: "DTLS-Retransmit-Fragmented",
8773 config: Config{
8774 MaxVersion: VersionTLS12,
8775 Bugs: ProtocolBugs{
8776 TimeoutSchedule: []time.Duration{timeouts[0]},
8777 MaxHandshakeRecordLength: 2,
8778 },
8779 },
8780 flags: []string{"-async"},
8781 })
8782
8783 // Test the timeout schedule when a shorter initial timeout duration is set.
8784 testCases = append(testCases, testCase{
8785 protocol: dtls,
8786 name: "DTLS-Retransmit-Short-Client",
8787 config: Config{
8788 MaxVersion: VersionTLS12,
8789 Bugs: ProtocolBugs{
8790 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8791 },
8792 },
8793 resumeSession: true,
8794 flags: []string{
8795 "-async",
8796 "-initial-timeout-duration-ms", "250",
8797 },
8798 })
8799 testCases = append(testCases, testCase{
8800 protocol: dtls,
8801 testType: serverTest,
8802 name: "DTLS-Retransmit-Short-Server",
8803 config: Config{
8804 MaxVersion: VersionTLS12,
8805 Bugs: ProtocolBugs{
8806 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8807 },
8808 },
8809 resumeSession: true,
8810 flags: []string{
8811 "-async",
8812 "-initial-timeout-duration-ms", "250",
8813 },
8814 })
David Benjamin302b8182017-08-22 14:47:22 -07008815
8816 // If the shim sends the last Finished (server full or client resume
8817 // handshakes), it must retransmit that Finished when it sees a
8818 // post-handshake penultimate Finished from the runner. The above tests
8819 // cover this. Conversely, if the shim sends the penultimate Finished
8820 // (client full or server resume), test that it does not retransmit.
8821 testCases = append(testCases, testCase{
8822 protocol: dtls,
8823 testType: clientTest,
8824 name: "DTLS-StrayRetransmitFinished-ClientFull",
8825 config: Config{
8826 MaxVersion: VersionTLS12,
8827 Bugs: ProtocolBugs{
8828 RetransmitFinished: true,
8829 },
8830 },
8831 })
8832 testCases = append(testCases, testCase{
8833 protocol: dtls,
8834 testType: serverTest,
8835 name: "DTLS-StrayRetransmitFinished-ServerResume",
8836 config: Config{
8837 MaxVersion: VersionTLS12,
8838 },
8839 resumeConfig: &Config{
8840 MaxVersion: VersionTLS12,
8841 Bugs: ProtocolBugs{
8842 RetransmitFinished: true,
8843 },
8844 },
8845 resumeSession: true,
8846 })
David Benjamin83f90402015-01-27 01:09:43 -05008847}
8848
David Benjaminc565ebb2015-04-03 04:06:36 -04008849func addExportKeyingMaterialTests() {
8850 for _, vers := range tlsVersions {
8851 if vers.version == VersionSSL30 {
8852 continue
8853 }
8854 testCases = append(testCases, testCase{
8855 name: "ExportKeyingMaterial-" + vers.name,
8856 config: Config{
8857 MaxVersion: vers.version,
8858 },
David Benjamina5022392017-07-10 17:40:39 -04008859 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008860 exportKeyingMaterial: 1024,
8861 exportLabel: "label",
8862 exportContext: "context",
8863 useExportContext: true,
8864 })
8865 testCases = append(testCases, testCase{
8866 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8867 config: Config{
8868 MaxVersion: vers.version,
8869 },
David Benjamina5022392017-07-10 17:40:39 -04008870 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008871 exportKeyingMaterial: 1024,
8872 })
8873 testCases = append(testCases, testCase{
8874 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8875 config: Config{
8876 MaxVersion: vers.version,
8877 },
David Benjamina5022392017-07-10 17:40:39 -04008878 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008879 exportKeyingMaterial: 1024,
8880 useExportContext: true,
8881 })
8882 testCases = append(testCases, testCase{
8883 name: "ExportKeyingMaterial-Small-" + vers.name,
8884 config: Config{
8885 MaxVersion: vers.version,
8886 },
David Benjamina5022392017-07-10 17:40:39 -04008887 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008888 exportKeyingMaterial: 1,
8889 exportLabel: "label",
8890 exportContext: "context",
8891 useExportContext: true,
8892 })
8893 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008894
David Benjaminc565ebb2015-04-03 04:06:36 -04008895 testCases = append(testCases, testCase{
8896 name: "ExportKeyingMaterial-SSL3",
8897 config: Config{
8898 MaxVersion: VersionSSL30,
8899 },
8900 exportKeyingMaterial: 1024,
8901 exportLabel: "label",
8902 exportContext: "context",
8903 useExportContext: true,
8904 shouldFail: true,
8905 expectedError: "failed to export keying material",
8906 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008907
8908 // Exporters work during a False Start.
8909 testCases = append(testCases, testCase{
8910 name: "ExportKeyingMaterial-FalseStart",
8911 config: Config{
8912 MaxVersion: VersionTLS12,
8913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8914 NextProtos: []string{"foo"},
8915 Bugs: ProtocolBugs{
8916 ExpectFalseStart: true,
8917 },
8918 },
8919 flags: []string{
8920 "-false-start",
8921 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008922 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008923 },
8924 shimWritesFirst: true,
8925 exportKeyingMaterial: 1024,
8926 exportLabel: "label",
8927 exportContext: "context",
8928 useExportContext: true,
8929 })
8930
8931 // Exporters do not work in the middle of a renegotiation. Test this by
8932 // triggering the exporter after every SSL_read call and configuring the
8933 // shim to run asynchronously.
8934 testCases = append(testCases, testCase{
8935 name: "ExportKeyingMaterial-Renegotiate",
8936 config: Config{
8937 MaxVersion: VersionTLS12,
8938 },
8939 renegotiate: 1,
8940 flags: []string{
8941 "-async",
8942 "-use-exporter-between-reads",
8943 "-renegotiate-freely",
8944 "-expect-total-renegotiations", "1",
8945 },
8946 shouldFail: true,
8947 expectedError: "failed to export keying material",
8948 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008949}
8950
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008951func addTLSUniqueTests() {
8952 for _, isClient := range []bool{false, true} {
8953 for _, isResumption := range []bool{false, true} {
8954 for _, hasEMS := range []bool{false, true} {
8955 var suffix string
8956 if isResumption {
8957 suffix = "Resume-"
8958 } else {
8959 suffix = "Full-"
8960 }
8961
8962 if hasEMS {
8963 suffix += "EMS-"
8964 } else {
8965 suffix += "NoEMS-"
8966 }
8967
8968 if isClient {
8969 suffix += "Client"
8970 } else {
8971 suffix += "Server"
8972 }
8973
8974 test := testCase{
8975 name: "TLSUnique-" + suffix,
8976 testTLSUnique: true,
8977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008978 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008979 Bugs: ProtocolBugs{
8980 NoExtendedMasterSecret: !hasEMS,
8981 },
8982 },
8983 }
8984
8985 if isResumption {
8986 test.resumeSession = true
8987 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008988 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008989 Bugs: ProtocolBugs{
8990 NoExtendedMasterSecret: !hasEMS,
8991 },
8992 }
8993 }
8994
8995 if isResumption && !hasEMS {
8996 test.shouldFail = true
8997 test.expectedError = "failed to get tls-unique"
8998 }
8999
9000 testCases = append(testCases, test)
9001 }
9002 }
9003 }
9004}
9005
Adam Langley09505632015-07-30 18:10:13 -07009006func addCustomExtensionTests() {
9007 expectedContents := "custom extension"
9008 emptyString := ""
9009
9010 for _, isClient := range []bool{false, true} {
9011 suffix := "Server"
9012 flag := "-enable-server-custom-extension"
9013 testType := serverTest
9014 if isClient {
9015 suffix = "Client"
9016 flag = "-enable-client-custom-extension"
9017 testType = clientTest
9018 }
9019
9020 testCases = append(testCases, testCase{
9021 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009022 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009024 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009025 Bugs: ProtocolBugs{
9026 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009027 ExpectedCustomExtension: &expectedContents,
9028 },
9029 },
9030 flags: []string{flag},
9031 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009032 testCases = append(testCases, testCase{
9033 testType: testType,
9034 name: "CustomExtensions-" + suffix + "-TLS13",
9035 config: Config{
9036 MaxVersion: VersionTLS13,
9037 Bugs: ProtocolBugs{
9038 CustomExtension: expectedContents,
9039 ExpectedCustomExtension: &expectedContents,
9040 },
9041 },
9042 flags: []string{flag},
9043 })
Adam Langley09505632015-07-30 18:10:13 -07009044
9045 // If the parse callback fails, the handshake should also fail.
9046 testCases = append(testCases, testCase{
9047 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009048 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009050 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009051 Bugs: ProtocolBugs{
9052 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07009053 ExpectedCustomExtension: &expectedContents,
9054 },
9055 },
David Benjamin399e7c92015-07-30 23:01:27 -04009056 flags: []string{flag},
9057 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009058 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9059 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009060 testCases = append(testCases, testCase{
9061 testType: testType,
9062 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
9063 config: Config{
9064 MaxVersion: VersionTLS13,
9065 Bugs: ProtocolBugs{
9066 CustomExtension: expectedContents + "foo",
9067 ExpectedCustomExtension: &expectedContents,
9068 },
9069 },
9070 flags: []string{flag},
9071 shouldFail: true,
9072 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9073 })
Adam Langley09505632015-07-30 18:10:13 -07009074
9075 // If the add callback fails, the handshake should also fail.
9076 testCases = append(testCases, testCase{
9077 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009078 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009079 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009080 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009081 Bugs: ProtocolBugs{
9082 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009083 ExpectedCustomExtension: &expectedContents,
9084 },
9085 },
David Benjamin399e7c92015-07-30 23:01:27 -04009086 flags: []string{flag, "-custom-extension-fail-add"},
9087 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009088 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9089 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009090 testCases = append(testCases, testCase{
9091 testType: testType,
9092 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9093 config: Config{
9094 MaxVersion: VersionTLS13,
9095 Bugs: ProtocolBugs{
9096 CustomExtension: expectedContents,
9097 ExpectedCustomExtension: &expectedContents,
9098 },
9099 },
9100 flags: []string{flag, "-custom-extension-fail-add"},
9101 shouldFail: true,
9102 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9103 })
Adam Langley09505632015-07-30 18:10:13 -07009104
9105 // If the add callback returns zero, no extension should be
9106 // added.
9107 skipCustomExtension := expectedContents
9108 if isClient {
9109 // For the case where the client skips sending the
9110 // custom extension, the server must not “echo” it.
9111 skipCustomExtension = ""
9112 }
9113 testCases = append(testCases, testCase{
9114 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009115 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009117 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009118 Bugs: ProtocolBugs{
9119 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009120 ExpectedCustomExtension: &emptyString,
9121 },
9122 },
9123 flags: []string{flag, "-custom-extension-skip"},
9124 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009125 testCases = append(testCases, testCase{
9126 testType: testType,
9127 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9128 config: Config{
9129 MaxVersion: VersionTLS13,
9130 Bugs: ProtocolBugs{
9131 CustomExtension: skipCustomExtension,
9132 ExpectedCustomExtension: &emptyString,
9133 },
9134 },
9135 flags: []string{flag, "-custom-extension-skip"},
9136 })
Adam Langley09505632015-07-30 18:10:13 -07009137 }
9138
Steven Valdezf4ecc842017-08-10 14:02:56 -04009139 // If the client sends both early data and custom extension, the handshake
9140 // should succeed as long as both the extensions aren't returned by the
9141 // server.
9142 testCases = append(testCases, testCase{
9143 testType: clientTest,
9144 name: "CustomExtensions-Client-EarlyData-None",
9145 config: Config{
9146 MaxVersion: VersionTLS13,
9147 MaxEarlyDataSize: 16384,
9148 Bugs: ProtocolBugs{
9149 ExpectedCustomExtension: &expectedContents,
9150 AlwaysRejectEarlyData: true,
9151 },
9152 },
9153 resumeSession: true,
9154 flags: []string{
9155 "-enable-client-custom-extension",
9156 "-enable-early-data",
9157 "-expect-early-data-info",
9158 "-expect-reject-early-data",
9159 },
9160 })
9161
9162 testCases = append(testCases, testCase{
9163 testType: clientTest,
9164 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9165 config: Config{
9166 MaxVersion: VersionTLS13,
9167 MaxEarlyDataSize: 16384,
9168 Bugs: ProtocolBugs{
9169 ExpectedCustomExtension: &expectedContents,
9170 },
9171 },
9172 resumeSession: true,
9173 flags: []string{
9174 "-enable-client-custom-extension",
9175 "-enable-early-data",
9176 "-expect-early-data-info",
9177 "-expect-accept-early-data",
9178 },
9179 })
9180
9181 testCases = append(testCases, testCase{
9182 testType: clientTest,
9183 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9184 config: Config{
9185 MaxVersion: VersionTLS13,
9186 MaxEarlyDataSize: 16384,
9187 Bugs: ProtocolBugs{
9188 AlwaysRejectEarlyData: true,
9189 CustomExtension: expectedContents,
9190 ExpectedCustomExtension: &expectedContents,
9191 },
9192 },
9193 resumeSession: true,
9194 flags: []string{
9195 "-enable-client-custom-extension",
9196 "-enable-early-data",
9197 "-expect-early-data-info",
9198 "-expect-reject-early-data",
9199 },
9200 })
9201
9202 testCases = append(testCases, testCase{
9203 testType: clientTest,
9204 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9205 config: Config{
9206 MaxVersion: VersionTLS13,
9207 MaxEarlyDataSize: 16384,
9208 Bugs: ProtocolBugs{
9209 CustomExtension: expectedContents,
9210 ExpectedCustomExtension: &expectedContents,
9211 },
9212 },
9213 resumeConfig: &Config{
9214 MaxVersion: VersionTLS13,
9215 MaxEarlyDataSize: 16384,
9216 Bugs: ProtocolBugs{
9217 CustomExtension: expectedContents,
9218 ExpectedCustomExtension: &expectedContents,
9219 SendEarlyDataExtension: true,
9220 },
9221 },
9222 resumeSession: true,
9223 shouldFail: true,
9224 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9225 flags: []string{
9226 "-enable-client-custom-extension",
9227 "-enable-early-data",
9228 "-expect-early-data-info",
9229 },
9230 })
9231
9232 // If the server receives both early data and custom extension, only the
9233 // custom extension should be accepted.
9234 testCases = append(testCases, testCase{
9235 testType: serverTest,
9236 name: "CustomExtensions-Server-EarlyDataAccepted",
9237 config: Config{
9238 MaxVersion: VersionTLS13,
9239 MaxEarlyDataSize: 16384,
9240 Bugs: ProtocolBugs{
9241 CustomExtension: expectedContents,
9242 ExpectedCustomExtension: &expectedContents,
9243 ExpectEarlyDataAccepted: false,
9244 },
9245 },
9246 resumeSession: true,
9247 flags: []string{
9248 "-enable-server-custom-extension",
9249 "-enable-early-data",
9250 "-expect-early-data-info",
9251 },
9252 })
9253
Adam Langley09505632015-07-30 18:10:13 -07009254 // The custom extension add callback should not be called if the client
9255 // doesn't send the extension.
9256 testCases = append(testCases, testCase{
9257 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009258 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009259 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009260 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009261 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009262 ExpectedCustomExtension: &emptyString,
9263 },
9264 },
9265 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9266 })
Adam Langley2deb9842015-08-07 11:15:37 -07009267
Steven Valdez143e8b32016-07-11 13:19:03 -04009268 testCases = append(testCases, testCase{
9269 testType: serverTest,
9270 name: "CustomExtensions-NotCalled-Server-TLS13",
9271 config: Config{
9272 MaxVersion: VersionTLS13,
9273 Bugs: ProtocolBugs{
9274 ExpectedCustomExtension: &emptyString,
9275 },
9276 },
9277 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9278 })
9279
Adam Langley2deb9842015-08-07 11:15:37 -07009280 // Test an unknown extension from the server.
9281 testCases = append(testCases, testCase{
9282 testType: clientTest,
9283 name: "UnknownExtension-Client",
9284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009285 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009286 Bugs: ProtocolBugs{
9287 CustomExtension: expectedContents,
9288 },
9289 },
David Benjamin0c40a962016-08-01 12:05:50 -04009290 shouldFail: true,
9291 expectedError: ":UNEXPECTED_EXTENSION:",
9292 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009293 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009294 testCases = append(testCases, testCase{
9295 testType: clientTest,
9296 name: "UnknownExtension-Client-TLS13",
9297 config: Config{
9298 MaxVersion: VersionTLS13,
9299 Bugs: ProtocolBugs{
9300 CustomExtension: expectedContents,
9301 },
9302 },
David Benjamin0c40a962016-08-01 12:05:50 -04009303 shouldFail: true,
9304 expectedError: ":UNEXPECTED_EXTENSION:",
9305 expectedLocalError: "remote error: unsupported extension",
9306 })
David Benjamin490469f2016-10-05 22:44:38 -04009307 testCases = append(testCases, testCase{
9308 testType: clientTest,
9309 name: "UnknownUnencryptedExtension-Client-TLS13",
9310 config: Config{
9311 MaxVersion: VersionTLS13,
9312 Bugs: ProtocolBugs{
9313 CustomUnencryptedExtension: expectedContents,
9314 },
9315 },
9316 shouldFail: true,
9317 expectedError: ":UNEXPECTED_EXTENSION:",
9318 // The shim must send an alert, but alerts at this point do not
9319 // get successfully decrypted by the runner.
9320 expectedLocalError: "local error: bad record MAC",
9321 })
9322 testCases = append(testCases, testCase{
9323 testType: clientTest,
9324 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9325 config: Config{
9326 MaxVersion: VersionTLS13,
9327 Bugs: ProtocolBugs{
9328 SendUnencryptedALPN: "foo",
9329 },
9330 },
9331 flags: []string{
9332 "-advertise-alpn", "\x03foo\x03bar",
9333 },
9334 shouldFail: true,
9335 expectedError: ":UNEXPECTED_EXTENSION:",
9336 // The shim must send an alert, but alerts at this point do not
9337 // get successfully decrypted by the runner.
9338 expectedLocalError: "local error: bad record MAC",
9339 })
David Benjamin0c40a962016-08-01 12:05:50 -04009340
9341 // Test a known but unoffered extension from the server.
9342 testCases = append(testCases, testCase{
9343 testType: clientTest,
9344 name: "UnofferedExtension-Client",
9345 config: Config{
9346 MaxVersion: VersionTLS12,
9347 Bugs: ProtocolBugs{
9348 SendALPN: "alpn",
9349 },
9350 },
9351 shouldFail: true,
9352 expectedError: ":UNEXPECTED_EXTENSION:",
9353 expectedLocalError: "remote error: unsupported extension",
9354 })
9355 testCases = append(testCases, testCase{
9356 testType: clientTest,
9357 name: "UnofferedExtension-Client-TLS13",
9358 config: Config{
9359 MaxVersion: VersionTLS13,
9360 Bugs: ProtocolBugs{
9361 SendALPN: "alpn",
9362 },
9363 },
9364 shouldFail: true,
9365 expectedError: ":UNEXPECTED_EXTENSION:",
9366 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009367 })
Adam Langley09505632015-07-30 18:10:13 -07009368}
9369
David Benjaminb36a3952015-12-01 18:53:13 -05009370func addRSAClientKeyExchangeTests() {
9371 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9372 testCases = append(testCases, testCase{
9373 testType: serverTest,
9374 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9375 config: Config{
9376 // Ensure the ClientHello version and final
9377 // version are different, to detect if the
9378 // server uses the wrong one.
9379 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009380 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009381 Bugs: ProtocolBugs{
9382 BadRSAClientKeyExchange: bad,
9383 },
9384 },
9385 shouldFail: true,
9386 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9387 })
9388 }
David Benjamine63d9d72016-09-19 18:27:34 -04009389
9390 // The server must compare whatever was in ClientHello.version for the
9391 // RSA premaster.
9392 testCases = append(testCases, testCase{
9393 testType: serverTest,
9394 name: "SendClientVersion-RSA",
9395 config: Config{
9396 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9397 Bugs: ProtocolBugs{
9398 SendClientVersion: 0x1234,
9399 },
9400 },
9401 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9402 })
David Benjaminb36a3952015-12-01 18:53:13 -05009403}
9404
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009405var testCurves = []struct {
9406 name string
9407 id CurveID
9408}{
Adam Langley764ab982017-03-10 18:01:30 -08009409 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009410 {"P-256", CurveP256},
9411 {"P-384", CurveP384},
9412 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009413 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009414}
9415
Steven Valdez5440fe02016-07-18 12:40:30 -04009416const bogusCurve = 0x1234
9417
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009418func addCurveTests() {
9419 for _, curve := range testCurves {
9420 testCases = append(testCases, testCase{
9421 name: "CurveTest-Client-" + curve.name,
9422 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009423 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009424 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9425 CurvePreferences: []CurveID{curve.id},
9426 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009427 flags: []string{
9428 "-enable-all-curves",
9429 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9430 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009431 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009432 })
9433 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009434 name: "CurveTest-Client-" + curve.name + "-TLS13",
9435 config: Config{
9436 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009437 CurvePreferences: []CurveID{curve.id},
9438 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009439 flags: []string{
9440 "-enable-all-curves",
9441 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9442 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009443 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009444 })
9445 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009446 testType: serverTest,
9447 name: "CurveTest-Server-" + curve.name,
9448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009449 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9451 CurvePreferences: []CurveID{curve.id},
9452 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009453 flags: []string{
9454 "-enable-all-curves",
9455 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9456 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009457 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009458 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009459 testCases = append(testCases, testCase{
9460 testType: serverTest,
9461 name: "CurveTest-Server-" + curve.name + "-TLS13",
9462 config: Config{
9463 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009464 CurvePreferences: []CurveID{curve.id},
9465 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009466 flags: []string{
9467 "-enable-all-curves",
9468 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9469 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009470 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009471 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009472 }
David Benjamin241ae832016-01-15 03:04:54 -05009473
9474 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009475 testCases = append(testCases, testCase{
9476 testType: serverTest,
9477 name: "UnknownCurve",
9478 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009479 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009480 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9481 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9482 },
9483 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009484
Steven Valdez803c77a2016-09-06 14:13:43 -04009485 // The server must be tolerant to bogus curves.
9486 testCases = append(testCases, testCase{
9487 testType: serverTest,
9488 name: "UnknownCurve-TLS13",
9489 config: Config{
9490 MaxVersion: VersionTLS13,
9491 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9492 },
9493 })
9494
David Benjamin4c3ddf72016-06-29 18:13:53 -04009495 // The server must not consider ECDHE ciphers when there are no
9496 // supported curves.
9497 testCases = append(testCases, testCase{
9498 testType: serverTest,
9499 name: "NoSupportedCurves",
9500 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009501 MaxVersion: VersionTLS12,
9502 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9503 Bugs: ProtocolBugs{
9504 NoSupportedCurves: true,
9505 },
9506 },
9507 shouldFail: true,
9508 expectedError: ":NO_SHARED_CIPHER:",
9509 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009510 testCases = append(testCases, testCase{
9511 testType: serverTest,
9512 name: "NoSupportedCurves-TLS13",
9513 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009514 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009515 Bugs: ProtocolBugs{
9516 NoSupportedCurves: true,
9517 },
9518 },
9519 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009520 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009521 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009522
9523 // The server must fall back to another cipher when there are no
9524 // supported curves.
9525 testCases = append(testCases, testCase{
9526 testType: serverTest,
9527 name: "NoCommonCurves",
9528 config: Config{
9529 MaxVersion: VersionTLS12,
9530 CipherSuites: []uint16{
9531 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009532 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009533 },
9534 CurvePreferences: []CurveID{CurveP224},
9535 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009536 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009537 })
9538
9539 // The client must reject bogus curves and disabled curves.
9540 testCases = append(testCases, testCase{
9541 name: "BadECDHECurve",
9542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009543 MaxVersion: VersionTLS12,
9544 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9545 Bugs: ProtocolBugs{
9546 SendCurve: bogusCurve,
9547 },
9548 },
9549 shouldFail: true,
9550 expectedError: ":WRONG_CURVE:",
9551 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009552 testCases = append(testCases, testCase{
9553 name: "BadECDHECurve-TLS13",
9554 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009555 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009556 Bugs: ProtocolBugs{
9557 SendCurve: bogusCurve,
9558 },
9559 },
9560 shouldFail: true,
9561 expectedError: ":WRONG_CURVE:",
9562 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009563
9564 testCases = append(testCases, testCase{
9565 name: "UnsupportedCurve",
9566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009567 MaxVersion: VersionTLS12,
9568 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9569 CurvePreferences: []CurveID{CurveP256},
9570 Bugs: ProtocolBugs{
9571 IgnorePeerCurvePreferences: true,
9572 },
9573 },
9574 flags: []string{"-p384-only"},
9575 shouldFail: true,
9576 expectedError: ":WRONG_CURVE:",
9577 })
9578
David Benjamin4f921572016-07-17 14:20:10 +02009579 testCases = append(testCases, testCase{
9580 // TODO(davidben): Add a TLS 1.3 version where
9581 // HelloRetryRequest requests an unsupported curve.
9582 name: "UnsupportedCurve-ServerHello-TLS13",
9583 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009584 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009585 CurvePreferences: []CurveID{CurveP384},
9586 Bugs: ProtocolBugs{
9587 SendCurve: CurveP256,
9588 },
9589 },
9590 flags: []string{"-p384-only"},
9591 shouldFail: true,
9592 expectedError: ":WRONG_CURVE:",
9593 })
9594
David Benjamin4c3ddf72016-06-29 18:13:53 -04009595 // Test invalid curve points.
9596 testCases = append(testCases, testCase{
9597 name: "InvalidECDHPoint-Client",
9598 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009599 MaxVersion: VersionTLS12,
9600 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9601 CurvePreferences: []CurveID{CurveP256},
9602 Bugs: ProtocolBugs{
9603 InvalidECDHPoint: true,
9604 },
9605 },
9606 shouldFail: true,
9607 expectedError: ":INVALID_ENCODING:",
9608 })
9609 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009610 name: "InvalidECDHPoint-Client-TLS13",
9611 config: Config{
9612 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009613 CurvePreferences: []CurveID{CurveP256},
9614 Bugs: ProtocolBugs{
9615 InvalidECDHPoint: true,
9616 },
9617 },
9618 shouldFail: true,
9619 expectedError: ":INVALID_ENCODING:",
9620 })
9621 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009622 testType: serverTest,
9623 name: "InvalidECDHPoint-Server",
9624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009625 MaxVersion: VersionTLS12,
9626 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9627 CurvePreferences: []CurveID{CurveP256},
9628 Bugs: ProtocolBugs{
9629 InvalidECDHPoint: true,
9630 },
9631 },
9632 shouldFail: true,
9633 expectedError: ":INVALID_ENCODING:",
9634 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009635 testCases = append(testCases, testCase{
9636 testType: serverTest,
9637 name: "InvalidECDHPoint-Server-TLS13",
9638 config: Config{
9639 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009640 CurvePreferences: []CurveID{CurveP256},
9641 Bugs: ProtocolBugs{
9642 InvalidECDHPoint: true,
9643 },
9644 },
9645 shouldFail: true,
9646 expectedError: ":INVALID_ENCODING:",
9647 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009648
9649 // The previous curve ID should be reported on TLS 1.2 resumption.
9650 testCases = append(testCases, testCase{
9651 name: "CurveID-Resume-Client",
9652 config: Config{
9653 MaxVersion: VersionTLS12,
9654 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9655 CurvePreferences: []CurveID{CurveX25519},
9656 },
9657 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9658 resumeSession: true,
9659 })
9660 testCases = append(testCases, testCase{
9661 testType: serverTest,
9662 name: "CurveID-Resume-Server",
9663 config: Config{
9664 MaxVersion: VersionTLS12,
9665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9666 CurvePreferences: []CurveID{CurveX25519},
9667 },
9668 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9669 resumeSession: true,
9670 })
9671
9672 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9673 // one should be reported.
9674 testCases = append(testCases, testCase{
9675 name: "CurveID-Resume-Client-TLS13",
9676 config: Config{
9677 MaxVersion: VersionTLS13,
9678 CurvePreferences: []CurveID{CurveX25519},
9679 },
9680 resumeConfig: &Config{
9681 MaxVersion: VersionTLS13,
9682 CurvePreferences: []CurveID{CurveP256},
9683 },
9684 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009685 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9686 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009687 },
9688 resumeSession: true,
9689 })
9690 testCases = append(testCases, testCase{
9691 testType: serverTest,
9692 name: "CurveID-Resume-Server-TLS13",
9693 config: Config{
9694 MaxVersion: VersionTLS13,
9695 CurvePreferences: []CurveID{CurveX25519},
9696 },
9697 resumeConfig: &Config{
9698 MaxVersion: VersionTLS13,
9699 CurvePreferences: []CurveID{CurveP256},
9700 },
9701 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009702 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9703 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009704 },
9705 resumeSession: true,
9706 })
David Benjamina81967b2016-12-22 09:16:57 -05009707
9708 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9709 testCases = append(testCases, testCase{
9710 name: "PointFormat-ServerHello-TLS12",
9711 config: Config{
9712 MaxVersion: VersionTLS12,
9713 Bugs: ProtocolBugs{
9714 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9715 },
9716 },
9717 })
9718 testCases = append(testCases, testCase{
9719 name: "PointFormat-EncryptedExtensions-TLS13",
9720 config: Config{
9721 MaxVersion: VersionTLS13,
9722 Bugs: ProtocolBugs{
9723 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9724 },
9725 },
9726 shouldFail: true,
9727 expectedError: ":ERROR_PARSING_EXTENSION:",
9728 })
9729
9730 // Test that we tolerate unknown point formats, as long as
9731 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9732 // check they are still functional.
9733 testCases = append(testCases, testCase{
9734 name: "PointFormat-Client-Tolerance",
9735 config: Config{
9736 MaxVersion: VersionTLS12,
9737 Bugs: ProtocolBugs{
9738 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9739 },
9740 },
9741 })
9742 testCases = append(testCases, testCase{
9743 testType: serverTest,
9744 name: "PointFormat-Server-Tolerance",
9745 config: Config{
9746 MaxVersion: VersionTLS12,
9747 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9748 Bugs: ProtocolBugs{
9749 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9750 },
9751 },
9752 })
9753
9754 // Test TLS 1.2 does not require the point format extension to be
9755 // present.
9756 testCases = append(testCases, testCase{
9757 name: "PointFormat-Client-Missing",
9758 config: Config{
9759 MaxVersion: VersionTLS12,
9760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9761 Bugs: ProtocolBugs{
9762 SendSupportedPointFormats: []byte{},
9763 },
9764 },
9765 })
9766 testCases = append(testCases, testCase{
9767 testType: serverTest,
9768 name: "PointFormat-Server-Missing",
9769 config: Config{
9770 MaxVersion: VersionTLS12,
9771 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9772 Bugs: ProtocolBugs{
9773 SendSupportedPointFormats: []byte{},
9774 },
9775 },
9776 })
9777
9778 // If the point format extension is present, uncompressed points must be
9779 // offered. BoringSSL requires this whether or not ECDHE is used.
9780 testCases = append(testCases, testCase{
9781 name: "PointFormat-Client-MissingUncompressed",
9782 config: Config{
9783 MaxVersion: VersionTLS12,
9784 Bugs: ProtocolBugs{
9785 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9786 },
9787 },
9788 shouldFail: true,
9789 expectedError: ":ERROR_PARSING_EXTENSION:",
9790 })
9791 testCases = append(testCases, testCase{
9792 testType: serverTest,
9793 name: "PointFormat-Server-MissingUncompressed",
9794 config: Config{
9795 MaxVersion: VersionTLS12,
9796 Bugs: ProtocolBugs{
9797 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9798 },
9799 },
9800 shouldFail: true,
9801 expectedError: ":ERROR_PARSING_EXTENSION:",
9802 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009803}
9804
David Benjaminc9ae27c2016-06-24 22:56:37 -04009805func addTLS13RecordTests() {
9806 testCases = append(testCases, testCase{
9807 name: "TLS13-RecordPadding",
9808 config: Config{
9809 MaxVersion: VersionTLS13,
9810 MinVersion: VersionTLS13,
9811 Bugs: ProtocolBugs{
9812 RecordPadding: 10,
9813 },
9814 },
9815 })
9816
9817 testCases = append(testCases, testCase{
9818 name: "TLS13-EmptyRecords",
9819 config: Config{
9820 MaxVersion: VersionTLS13,
9821 MinVersion: VersionTLS13,
9822 Bugs: ProtocolBugs{
9823 OmitRecordContents: true,
9824 },
9825 },
9826 shouldFail: true,
9827 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9828 })
9829
9830 testCases = append(testCases, testCase{
9831 name: "TLS13-OnlyPadding",
9832 config: Config{
9833 MaxVersion: VersionTLS13,
9834 MinVersion: VersionTLS13,
9835 Bugs: ProtocolBugs{
9836 OmitRecordContents: true,
9837 RecordPadding: 10,
9838 },
9839 },
9840 shouldFail: true,
9841 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9842 })
9843
9844 testCases = append(testCases, testCase{
9845 name: "TLS13-WrongOuterRecord",
9846 config: Config{
9847 MaxVersion: VersionTLS13,
9848 MinVersion: VersionTLS13,
9849 Bugs: ProtocolBugs{
9850 OuterRecordType: recordTypeHandshake,
9851 },
9852 },
9853 shouldFail: true,
9854 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9855 })
9856}
9857
Steven Valdez5b986082016-09-01 12:29:49 -04009858func addSessionTicketTests() {
9859 testCases = append(testCases, testCase{
9860 // In TLS 1.2 and below, empty NewSessionTicket messages
9861 // mean the server changed its mind on sending a ticket.
9862 name: "SendEmptySessionTicket",
9863 config: Config{
9864 MaxVersion: VersionTLS12,
9865 Bugs: ProtocolBugs{
9866 SendEmptySessionTicket: true,
9867 },
9868 },
9869 flags: []string{"-expect-no-session"},
9870 })
9871
9872 // Test that the server ignores unknown PSK modes.
9873 testCases = append(testCases, testCase{
9874 testType: serverTest,
9875 name: "TLS13-SendUnknownModeSessionTicket-Server",
9876 config: Config{
9877 MaxVersion: VersionTLS13,
9878 Bugs: ProtocolBugs{
9879 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009880 },
9881 },
9882 resumeSession: true,
9883 expectedResumeVersion: VersionTLS13,
9884 })
9885
Steven Valdeza833c352016-11-01 13:39:36 -04009886 // Test that the server does not send session tickets with no matching key exchange mode.
9887 testCases = append(testCases, testCase{
9888 testType: serverTest,
9889 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9890 config: Config{
9891 MaxVersion: VersionTLS13,
9892 Bugs: ProtocolBugs{
9893 SendPSKKeyExchangeModes: []byte{0x1a},
9894 ExpectNoNewSessionTicket: true,
9895 },
9896 },
9897 })
9898
9899 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009900 testCases = append(testCases, testCase{
9901 testType: serverTest,
9902 name: "TLS13-SendBadKEModeSessionTicket-Server",
9903 config: Config{
9904 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009905 },
9906 resumeConfig: &Config{
9907 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009908 Bugs: ProtocolBugs{
9909 SendPSKKeyExchangeModes: []byte{0x1a},
9910 },
9911 },
9912 resumeSession: true,
9913 expectResumeRejected: true,
9914 })
9915
Steven Valdeza833c352016-11-01 13:39:36 -04009916 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009917 testCases = append(testCases, testCase{
9918 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009919 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009920 config: Config{
9921 MaxVersion: VersionTLS13,
9922 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009923 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009924 },
9925 },
Steven Valdeza833c352016-11-01 13:39:36 -04009926 resumeSession: true,
9927 flags: []string{
9928 "-resumption-delay", "10",
9929 },
Steven Valdez5b986082016-09-01 12:29:49 -04009930 })
9931
Steven Valdeza833c352016-11-01 13:39:36 -04009932 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009933 testCases = append(testCases, testCase{
9934 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009935 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009936 config: Config{
9937 MaxVersion: VersionTLS13,
9938 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009939 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009940 },
9941 },
Steven Valdeza833c352016-11-01 13:39:36 -04009942 resumeSession: true,
9943 shouldFail: true,
9944 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009945 })
9946
David Benjamin35ac5b72017-03-03 15:05:56 -05009947 // Test that the server's ticket age skew reporting works.
9948 testCases = append(testCases, testCase{
9949 testType: serverTest,
9950 name: "TLS13-TicketAgeSkew-Forward",
9951 config: Config{
9952 MaxVersion: VersionTLS13,
9953 Bugs: ProtocolBugs{
9954 SendTicketAge: 15 * time.Second,
9955 },
9956 },
David Benjamin065d7332017-03-26 10:51:43 -05009957 resumeSession: true,
9958 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009959 flags: []string{
9960 "-resumption-delay", "10",
9961 "-expect-ticket-age-skew", "5",
9962 },
9963 })
9964 testCases = append(testCases, testCase{
9965 testType: serverTest,
9966 name: "TLS13-TicketAgeSkew-Backward",
9967 config: Config{
9968 MaxVersion: VersionTLS13,
9969 Bugs: ProtocolBugs{
9970 SendTicketAge: 5 * time.Second,
9971 },
9972 },
David Benjamin065d7332017-03-26 10:51:43 -05009973 resumeSession: true,
9974 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009975 flags: []string{
9976 "-resumption-delay", "10",
9977 "-expect-ticket-age-skew", "-5",
9978 },
9979 })
9980
Steven Valdez08b65f42016-12-07 15:29:45 -05009981 testCases = append(testCases, testCase{
9982 testType: clientTest,
9983 name: "TLS13-SendTicketEarlyDataInfo",
9984 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009985 MaxVersion: VersionTLS13,
9986 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009987 },
9988 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009989 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009990 "-expect-early-data-info",
9991 },
9992 })
9993
David Benjamin9b160662017-01-25 19:53:43 -05009994 // Test that 0-RTT tickets are ignored in clients unless opted in.
9995 testCases = append(testCases, testCase{
9996 testType: clientTest,
9997 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9998 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009999 MaxVersion: VersionTLS13,
10000 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -050010001 },
10002 })
10003
Steven Valdez08b65f42016-12-07 15:29:45 -050010004 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -050010005 testType: clientTest,
10006 name: "TLS13-DuplicateTicketEarlyDataInfo",
10007 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -080010008 MaxVersion: VersionTLS13,
10009 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -050010010 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -050010011 DuplicateTicketEarlyDataInfo: true,
10012 },
10013 },
10014 shouldFail: true,
10015 expectedError: ":DUPLICATE_EXTENSION:",
10016 expectedLocalError: "remote error: illegal parameter",
10017 })
10018
10019 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -050010020 testType: serverTest,
10021 name: "TLS13-ExpectTicketEarlyDataInfo",
10022 config: Config{
10023 MaxVersion: VersionTLS13,
10024 Bugs: ProtocolBugs{
10025 ExpectTicketEarlyDataInfo: true,
10026 },
10027 },
10028 flags: []string{
10029 "-enable-early-data",
10030 },
10031 })
David Benjamin17b30832017-01-28 14:00:32 -050010032
10033 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
10034 // is honored.
10035 testCases = append(testCases, testCase{
10036 testType: clientTest,
10037 name: "TLS13-HonorServerSessionTicketLifetime",
10038 config: Config{
10039 MaxVersion: VersionTLS13,
10040 Bugs: ProtocolBugs{
10041 SendTicketLifetime: 20 * time.Second,
10042 },
10043 },
10044 flags: []string{
10045 "-resumption-delay", "19",
10046 },
10047 resumeSession: true,
10048 })
10049 testCases = append(testCases, testCase{
10050 testType: clientTest,
10051 name: "TLS13-HonorServerSessionTicketLifetime-2",
10052 config: Config{
10053 MaxVersion: VersionTLS13,
10054 Bugs: ProtocolBugs{
10055 SendTicketLifetime: 20 * time.Second,
10056 // The client should not offer the expired session.
10057 ExpectNoTLS13PSK: true,
10058 },
10059 },
10060 flags: []string{
10061 "-resumption-delay", "21",
10062 },
David Benjamin023d4192017-02-06 13:49:07 -050010063 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -050010064 expectResumeRejected: true,
10065 })
Steven Valdez5b986082016-09-01 12:29:49 -040010066}
10067
David Benjamin82261be2016-07-07 14:32:50 -070010068func addChangeCipherSpecTests() {
10069 // Test missing ChangeCipherSpecs.
10070 testCases = append(testCases, testCase{
10071 name: "SkipChangeCipherSpec-Client",
10072 config: Config{
10073 MaxVersion: VersionTLS12,
10074 Bugs: ProtocolBugs{
10075 SkipChangeCipherSpec: true,
10076 },
10077 },
10078 shouldFail: true,
10079 expectedError: ":UNEXPECTED_RECORD:",
10080 })
10081 testCases = append(testCases, testCase{
10082 testType: serverTest,
10083 name: "SkipChangeCipherSpec-Server",
10084 config: Config{
10085 MaxVersion: VersionTLS12,
10086 Bugs: ProtocolBugs{
10087 SkipChangeCipherSpec: true,
10088 },
10089 },
10090 shouldFail: true,
10091 expectedError: ":UNEXPECTED_RECORD:",
10092 })
10093 testCases = append(testCases, testCase{
10094 testType: serverTest,
10095 name: "SkipChangeCipherSpec-Server-NPN",
10096 config: Config{
10097 MaxVersion: VersionTLS12,
10098 NextProtos: []string{"bar"},
10099 Bugs: ProtocolBugs{
10100 SkipChangeCipherSpec: true,
10101 },
10102 },
10103 flags: []string{
10104 "-advertise-npn", "\x03foo\x03bar\x03baz",
10105 },
10106 shouldFail: true,
10107 expectedError: ":UNEXPECTED_RECORD:",
10108 })
10109
10110 // Test synchronization between the handshake and ChangeCipherSpec.
10111 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10112 // rejected. Test both with and without handshake packing to handle both
10113 // when the partial post-CCS message is in its own record and when it is
10114 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010115 for _, packed := range []bool{false, true} {
10116 var suffix string
10117 if packed {
10118 suffix = "-Packed"
10119 }
10120
10121 testCases = append(testCases, testCase{
10122 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10123 config: Config{
10124 MaxVersion: VersionTLS12,
10125 Bugs: ProtocolBugs{
10126 FragmentAcrossChangeCipherSpec: true,
10127 PackHandshakeFlight: packed,
10128 },
10129 },
10130 shouldFail: true,
10131 expectedError: ":UNEXPECTED_RECORD:",
10132 })
10133 testCases = append(testCases, testCase{
10134 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10135 config: Config{
10136 MaxVersion: VersionTLS12,
10137 },
10138 resumeSession: true,
10139 resumeConfig: &Config{
10140 MaxVersion: VersionTLS12,
10141 Bugs: ProtocolBugs{
10142 FragmentAcrossChangeCipherSpec: true,
10143 PackHandshakeFlight: packed,
10144 },
10145 },
10146 shouldFail: true,
10147 expectedError: ":UNEXPECTED_RECORD:",
10148 })
10149 testCases = append(testCases, testCase{
10150 testType: serverTest,
10151 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10152 config: Config{
10153 MaxVersion: VersionTLS12,
10154 Bugs: ProtocolBugs{
10155 FragmentAcrossChangeCipherSpec: true,
10156 PackHandshakeFlight: packed,
10157 },
10158 },
10159 shouldFail: true,
10160 expectedError: ":UNEXPECTED_RECORD:",
10161 })
10162 testCases = append(testCases, testCase{
10163 testType: serverTest,
10164 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10165 config: Config{
10166 MaxVersion: VersionTLS12,
10167 },
10168 resumeSession: true,
10169 resumeConfig: &Config{
10170 MaxVersion: VersionTLS12,
10171 Bugs: ProtocolBugs{
10172 FragmentAcrossChangeCipherSpec: true,
10173 PackHandshakeFlight: packed,
10174 },
10175 },
10176 shouldFail: true,
10177 expectedError: ":UNEXPECTED_RECORD:",
10178 })
10179 testCases = append(testCases, testCase{
10180 testType: serverTest,
10181 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10182 config: Config{
10183 MaxVersion: VersionTLS12,
10184 NextProtos: []string{"bar"},
10185 Bugs: ProtocolBugs{
10186 FragmentAcrossChangeCipherSpec: true,
10187 PackHandshakeFlight: packed,
10188 },
10189 },
10190 flags: []string{
10191 "-advertise-npn", "\x03foo\x03bar\x03baz",
10192 },
10193 shouldFail: true,
10194 expectedError: ":UNEXPECTED_RECORD:",
10195 })
10196 }
10197
David Benjamin61672812016-07-14 23:10:43 -040010198 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10199 // messages in the handshake queue. Do this by testing the server
10200 // reading the client Finished, reversing the flight so Finished comes
10201 // first.
10202 testCases = append(testCases, testCase{
10203 protocol: dtls,
10204 testType: serverTest,
10205 name: "SendUnencryptedFinished-DTLS",
10206 config: Config{
10207 MaxVersion: VersionTLS12,
10208 Bugs: ProtocolBugs{
10209 SendUnencryptedFinished: true,
10210 ReverseHandshakeFragments: true,
10211 },
10212 },
10213 shouldFail: true,
10214 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10215 })
10216
Steven Valdez143e8b32016-07-11 13:19:03 -040010217 // Test synchronization between encryption changes and the handshake in
10218 // TLS 1.3, where ChangeCipherSpec is implicit.
10219 testCases = append(testCases, testCase{
10220 name: "PartialEncryptedExtensionsWithServerHello",
10221 config: Config{
10222 MaxVersion: VersionTLS13,
10223 Bugs: ProtocolBugs{
10224 PartialEncryptedExtensionsWithServerHello: true,
10225 },
10226 },
10227 shouldFail: true,
10228 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10229 })
10230 testCases = append(testCases, testCase{
10231 testType: serverTest,
10232 name: "PartialClientFinishedWithClientHello",
10233 config: Config{
10234 MaxVersion: VersionTLS13,
10235 Bugs: ProtocolBugs{
10236 PartialClientFinishedWithClientHello: true,
10237 },
10238 },
10239 shouldFail: true,
10240 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10241 })
10242
David Benjamin82261be2016-07-07 14:32:50 -070010243 // Test that early ChangeCipherSpecs are handled correctly.
10244 testCases = append(testCases, testCase{
10245 testType: serverTest,
10246 name: "EarlyChangeCipherSpec-server-1",
10247 config: Config{
10248 MaxVersion: VersionTLS12,
10249 Bugs: ProtocolBugs{
10250 EarlyChangeCipherSpec: 1,
10251 },
10252 },
10253 shouldFail: true,
10254 expectedError: ":UNEXPECTED_RECORD:",
10255 })
10256 testCases = append(testCases, testCase{
10257 testType: serverTest,
10258 name: "EarlyChangeCipherSpec-server-2",
10259 config: Config{
10260 MaxVersion: VersionTLS12,
10261 Bugs: ProtocolBugs{
10262 EarlyChangeCipherSpec: 2,
10263 },
10264 },
10265 shouldFail: true,
10266 expectedError: ":UNEXPECTED_RECORD:",
10267 })
10268 testCases = append(testCases, testCase{
10269 protocol: dtls,
10270 name: "StrayChangeCipherSpec",
10271 config: Config{
10272 // TODO(davidben): Once DTLS 1.3 exists, test
10273 // that stray ChangeCipherSpec messages are
10274 // rejected.
10275 MaxVersion: VersionTLS12,
10276 Bugs: ProtocolBugs{
10277 StrayChangeCipherSpec: true,
10278 },
10279 },
10280 })
10281
David Benjaminb0c761e2017-06-25 22:42:55 -040010282 // Test that reordered ChangeCipherSpecs are tolerated.
10283 testCases = append(testCases, testCase{
10284 protocol: dtls,
10285 name: "ReorderChangeCipherSpec-DTLS-Client",
10286 config: Config{
10287 MaxVersion: VersionTLS12,
10288 Bugs: ProtocolBugs{
10289 ReorderChangeCipherSpec: true,
10290 },
10291 },
10292 resumeSession: true,
10293 })
10294 testCases = append(testCases, testCase{
10295 testType: serverTest,
10296 protocol: dtls,
10297 name: "ReorderChangeCipherSpec-DTLS-Server",
10298 config: Config{
10299 MaxVersion: VersionTLS12,
10300 Bugs: ProtocolBugs{
10301 ReorderChangeCipherSpec: true,
10302 },
10303 },
10304 resumeSession: true,
10305 })
10306
David Benjamin82261be2016-07-07 14:32:50 -070010307 // Test that the contents of ChangeCipherSpec are checked.
10308 testCases = append(testCases, testCase{
10309 name: "BadChangeCipherSpec-1",
10310 config: Config{
10311 MaxVersion: VersionTLS12,
10312 Bugs: ProtocolBugs{
10313 BadChangeCipherSpec: []byte{2},
10314 },
10315 },
10316 shouldFail: true,
10317 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10318 })
10319 testCases = append(testCases, testCase{
10320 name: "BadChangeCipherSpec-2",
10321 config: Config{
10322 MaxVersion: VersionTLS12,
10323 Bugs: ProtocolBugs{
10324 BadChangeCipherSpec: []byte{1, 1},
10325 },
10326 },
10327 shouldFail: true,
10328 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10329 })
10330 testCases = append(testCases, testCase{
10331 protocol: dtls,
10332 name: "BadChangeCipherSpec-DTLS-1",
10333 config: Config{
10334 MaxVersion: VersionTLS12,
10335 Bugs: ProtocolBugs{
10336 BadChangeCipherSpec: []byte{2},
10337 },
10338 },
10339 shouldFail: true,
10340 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10341 })
10342 testCases = append(testCases, testCase{
10343 protocol: dtls,
10344 name: "BadChangeCipherSpec-DTLS-2",
10345 config: Config{
10346 MaxVersion: VersionTLS12,
10347 Bugs: ProtocolBugs{
10348 BadChangeCipherSpec: []byte{1, 1},
10349 },
10350 },
10351 shouldFail: true,
10352 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10353 })
10354}
10355
David Benjamincd2c8062016-09-09 11:28:16 -040010356type perMessageTest struct {
10357 messageType uint8
10358 test testCase
10359}
10360
10361// makePerMessageTests returns a series of test templates which cover each
10362// message in the TLS handshake. These may be used with bugs like
10363// WrongMessageType to fully test a per-message bug.
10364func makePerMessageTests() []perMessageTest {
10365 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010366 for _, protocol := range []protocol{tls, dtls} {
10367 var suffix string
10368 if protocol == dtls {
10369 suffix = "-DTLS"
10370 }
10371
David Benjamincd2c8062016-09-09 11:28:16 -040010372 ret = append(ret, perMessageTest{
10373 messageType: typeClientHello,
10374 test: testCase{
10375 protocol: protocol,
10376 testType: serverTest,
10377 name: "ClientHello" + suffix,
10378 config: Config{
10379 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010380 },
10381 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010382 })
10383
10384 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010385 ret = append(ret, perMessageTest{
10386 messageType: typeHelloVerifyRequest,
10387 test: testCase{
10388 protocol: protocol,
10389 name: "HelloVerifyRequest" + suffix,
10390 config: Config{
10391 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010392 },
10393 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010394 })
10395 }
10396
David Benjamincd2c8062016-09-09 11:28:16 -040010397 ret = append(ret, perMessageTest{
10398 messageType: typeServerHello,
10399 test: testCase{
10400 protocol: protocol,
10401 name: "ServerHello" + suffix,
10402 config: Config{
10403 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010404 },
10405 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010406 })
10407
David Benjamincd2c8062016-09-09 11:28:16 -040010408 ret = append(ret, perMessageTest{
10409 messageType: typeCertificate,
10410 test: testCase{
10411 protocol: protocol,
10412 name: "ServerCertificate" + suffix,
10413 config: Config{
10414 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010415 },
10416 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010417 })
10418
David Benjamincd2c8062016-09-09 11:28:16 -040010419 ret = append(ret, perMessageTest{
10420 messageType: typeCertificateStatus,
10421 test: testCase{
10422 protocol: protocol,
10423 name: "CertificateStatus" + suffix,
10424 config: Config{
10425 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010426 },
David Benjamincd2c8062016-09-09 11:28:16 -040010427 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010428 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010429 })
10430
David Benjamincd2c8062016-09-09 11:28:16 -040010431 ret = append(ret, perMessageTest{
10432 messageType: typeServerKeyExchange,
10433 test: testCase{
10434 protocol: protocol,
10435 name: "ServerKeyExchange" + suffix,
10436 config: Config{
10437 MaxVersion: VersionTLS12,
10438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010439 },
10440 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010441 })
10442
David Benjamincd2c8062016-09-09 11:28:16 -040010443 ret = append(ret, perMessageTest{
10444 messageType: typeCertificateRequest,
10445 test: testCase{
10446 protocol: protocol,
10447 name: "CertificateRequest" + suffix,
10448 config: Config{
10449 MaxVersion: VersionTLS12,
10450 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010451 },
10452 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010453 })
10454
David Benjamincd2c8062016-09-09 11:28:16 -040010455 ret = append(ret, perMessageTest{
10456 messageType: typeServerHelloDone,
10457 test: testCase{
10458 protocol: protocol,
10459 name: "ServerHelloDone" + suffix,
10460 config: Config{
10461 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010462 },
10463 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010464 })
10465
David Benjamincd2c8062016-09-09 11:28:16 -040010466 ret = append(ret, perMessageTest{
10467 messageType: typeCertificate,
10468 test: testCase{
10469 testType: serverTest,
10470 protocol: protocol,
10471 name: "ClientCertificate" + suffix,
10472 config: Config{
10473 Certificates: []Certificate{rsaCertificate},
10474 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010475 },
David Benjamincd2c8062016-09-09 11:28:16 -040010476 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010477 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010478 })
10479
David Benjamincd2c8062016-09-09 11:28:16 -040010480 ret = append(ret, perMessageTest{
10481 messageType: typeCertificateVerify,
10482 test: testCase{
10483 testType: serverTest,
10484 protocol: protocol,
10485 name: "CertificateVerify" + suffix,
10486 config: Config{
10487 Certificates: []Certificate{rsaCertificate},
10488 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010489 },
David Benjamincd2c8062016-09-09 11:28:16 -040010490 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010491 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010492 })
10493
David Benjamincd2c8062016-09-09 11:28:16 -040010494 ret = append(ret, perMessageTest{
10495 messageType: typeClientKeyExchange,
10496 test: testCase{
10497 testType: serverTest,
10498 protocol: protocol,
10499 name: "ClientKeyExchange" + suffix,
10500 config: Config{
10501 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010502 },
10503 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010504 })
10505
10506 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010507 ret = append(ret, perMessageTest{
10508 messageType: typeNextProtocol,
10509 test: testCase{
10510 testType: serverTest,
10511 protocol: protocol,
10512 name: "NextProtocol" + suffix,
10513 config: Config{
10514 MaxVersion: VersionTLS12,
10515 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010516 },
David Benjamincd2c8062016-09-09 11:28:16 -040010517 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010518 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010519 })
10520
David Benjamincd2c8062016-09-09 11:28:16 -040010521 ret = append(ret, perMessageTest{
10522 messageType: typeChannelID,
10523 test: testCase{
10524 testType: serverTest,
10525 protocol: protocol,
10526 name: "ChannelID" + suffix,
10527 config: Config{
10528 MaxVersion: VersionTLS12,
10529 ChannelID: channelIDKey,
10530 },
10531 flags: []string{
10532 "-expect-channel-id",
10533 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010534 },
10535 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010536 })
10537 }
10538
David Benjamincd2c8062016-09-09 11:28:16 -040010539 ret = append(ret, perMessageTest{
10540 messageType: typeFinished,
10541 test: testCase{
10542 testType: serverTest,
10543 protocol: protocol,
10544 name: "ClientFinished" + suffix,
10545 config: Config{
10546 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010547 },
10548 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010549 })
10550
David Benjamincd2c8062016-09-09 11:28:16 -040010551 ret = append(ret, perMessageTest{
10552 messageType: typeNewSessionTicket,
10553 test: testCase{
10554 protocol: protocol,
10555 name: "NewSessionTicket" + suffix,
10556 config: Config{
10557 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010558 },
10559 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010560 })
10561
David Benjamincd2c8062016-09-09 11:28:16 -040010562 ret = append(ret, perMessageTest{
10563 messageType: typeFinished,
10564 test: testCase{
10565 protocol: protocol,
10566 name: "ServerFinished" + suffix,
10567 config: Config{
10568 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010569 },
10570 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010571 })
10572
10573 }
David Benjamincd2c8062016-09-09 11:28:16 -040010574
10575 ret = append(ret, perMessageTest{
10576 messageType: typeClientHello,
10577 test: testCase{
10578 testType: serverTest,
10579 name: "TLS13-ClientHello",
10580 config: Config{
10581 MaxVersion: VersionTLS13,
10582 },
10583 },
10584 })
10585
10586 ret = append(ret, perMessageTest{
10587 messageType: typeServerHello,
10588 test: testCase{
10589 name: "TLS13-ServerHello",
10590 config: Config{
10591 MaxVersion: VersionTLS13,
10592 },
10593 },
10594 })
10595
10596 ret = append(ret, perMessageTest{
10597 messageType: typeEncryptedExtensions,
10598 test: testCase{
10599 name: "TLS13-EncryptedExtensions",
10600 config: Config{
10601 MaxVersion: VersionTLS13,
10602 },
10603 },
10604 })
10605
10606 ret = append(ret, perMessageTest{
10607 messageType: typeCertificateRequest,
10608 test: testCase{
10609 name: "TLS13-CertificateRequest",
10610 config: Config{
10611 MaxVersion: VersionTLS13,
10612 ClientAuth: RequireAnyClientCert,
10613 },
10614 },
10615 })
10616
10617 ret = append(ret, perMessageTest{
10618 messageType: typeCertificate,
10619 test: testCase{
10620 name: "TLS13-ServerCertificate",
10621 config: Config{
10622 MaxVersion: VersionTLS13,
10623 },
10624 },
10625 })
10626
10627 ret = append(ret, perMessageTest{
10628 messageType: typeCertificateVerify,
10629 test: testCase{
10630 name: "TLS13-ServerCertificateVerify",
10631 config: Config{
10632 MaxVersion: VersionTLS13,
10633 },
10634 },
10635 })
10636
10637 ret = append(ret, perMessageTest{
10638 messageType: typeFinished,
10639 test: testCase{
10640 name: "TLS13-ServerFinished",
10641 config: Config{
10642 MaxVersion: VersionTLS13,
10643 },
10644 },
10645 })
10646
10647 ret = append(ret, perMessageTest{
10648 messageType: typeCertificate,
10649 test: testCase{
10650 testType: serverTest,
10651 name: "TLS13-ClientCertificate",
10652 config: Config{
10653 Certificates: []Certificate{rsaCertificate},
10654 MaxVersion: VersionTLS13,
10655 },
10656 flags: []string{"-require-any-client-certificate"},
10657 },
10658 })
10659
10660 ret = append(ret, perMessageTest{
10661 messageType: typeCertificateVerify,
10662 test: testCase{
10663 testType: serverTest,
10664 name: "TLS13-ClientCertificateVerify",
10665 config: Config{
10666 Certificates: []Certificate{rsaCertificate},
10667 MaxVersion: VersionTLS13,
10668 },
10669 flags: []string{"-require-any-client-certificate"},
10670 },
10671 })
10672
10673 ret = append(ret, perMessageTest{
10674 messageType: typeFinished,
10675 test: testCase{
10676 testType: serverTest,
10677 name: "TLS13-ClientFinished",
10678 config: Config{
10679 MaxVersion: VersionTLS13,
10680 },
10681 },
10682 })
10683
10684 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010685}
10686
David Benjamincd2c8062016-09-09 11:28:16 -040010687func addWrongMessageTypeTests() {
10688 for _, t := range makePerMessageTests() {
10689 t.test.name = "WrongMessageType-" + t.test.name
10690 t.test.config.Bugs.SendWrongMessageType = t.messageType
10691 t.test.shouldFail = true
10692 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10693 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010694
David Benjamincd2c8062016-09-09 11:28:16 -040010695 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10696 // In TLS 1.3, a bad ServerHello means the client sends
10697 // an unencrypted alert while the server expects
10698 // encryption, so the alert is not readable by runner.
10699 t.test.expectedLocalError = "local error: bad record MAC"
10700 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010701
David Benjamincd2c8062016-09-09 11:28:16 -040010702 testCases = append(testCases, t.test)
10703 }
David Benjaminebacdee2017-04-08 11:00:45 -040010704
10705 // The processing order for TLS 1.3 version negotiation is such that one
10706 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10707 // TLS 1.2. Test that we do not do this.
10708 testCases = append(testCases, testCase{
10709 name: "SendServerHelloAsHelloRetryRequest",
10710 config: Config{
10711 MaxVersion: VersionTLS12,
10712 Bugs: ProtocolBugs{
10713 SendServerHelloAsHelloRetryRequest: true,
10714 },
10715 },
10716 shouldFail: true,
10717 expectedError: ":UNEXPECTED_MESSAGE:",
10718 expectedLocalError: "remote error: unexpected message",
10719 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010720}
10721
David Benjamin639846e2016-09-09 11:41:18 -040010722func addTrailingMessageDataTests() {
10723 for _, t := range makePerMessageTests() {
10724 t.test.name = "TrailingMessageData-" + t.test.name
10725 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10726 t.test.shouldFail = true
10727 t.test.expectedError = ":DECODE_ERROR:"
10728 t.test.expectedLocalError = "remote error: error decoding message"
10729
10730 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10731 // In TLS 1.3, a bad ServerHello means the client sends
10732 // an unencrypted alert while the server expects
10733 // encryption, so the alert is not readable by runner.
10734 t.test.expectedLocalError = "local error: bad record MAC"
10735 }
10736
10737 if t.messageType == typeFinished {
10738 // Bad Finished messages read as the verify data having
10739 // the wrong length.
10740 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10741 t.test.expectedLocalError = "remote error: error decrypting message"
10742 }
10743
10744 testCases = append(testCases, t.test)
10745 }
10746}
10747
Steven Valdez143e8b32016-07-11 13:19:03 -040010748func addTLS13HandshakeTests() {
10749 testCases = append(testCases, testCase{
10750 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010751 name: "NegotiatePSKResumption-TLS13",
10752 config: Config{
10753 MaxVersion: VersionTLS13,
10754 Bugs: ProtocolBugs{
10755 NegotiatePSKResumption: true,
10756 },
10757 },
10758 resumeSession: true,
10759 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010760 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010761 })
10762
10763 testCases = append(testCases, testCase{
10764 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010765 name: "MissingKeyShare-Client",
10766 config: Config{
10767 MaxVersion: VersionTLS13,
10768 Bugs: ProtocolBugs{
10769 MissingKeyShare: true,
10770 },
10771 },
10772 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010773 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010774 })
10775
10776 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010777 testType: serverTest,
10778 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010779 config: Config{
10780 MaxVersion: VersionTLS13,
10781 Bugs: ProtocolBugs{
10782 MissingKeyShare: true,
10783 },
10784 },
10785 shouldFail: true,
10786 expectedError: ":MISSING_KEY_SHARE:",
10787 })
10788
10789 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010790 testType: serverTest,
10791 name: "DuplicateKeyShares",
10792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 Bugs: ProtocolBugs{
10795 DuplicateKeyShares: true,
10796 },
10797 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010798 shouldFail: true,
10799 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010800 })
10801
10802 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010803 testType: serverTest,
10804 name: "SkipEarlyData",
10805 config: Config{
10806 MaxVersion: VersionTLS13,
10807 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010808 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010809 },
10810 },
10811 })
10812
10813 testCases = append(testCases, testCase{
10814 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010815 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010816 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010817 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040010818 Bugs: ProtocolBugs{
10819 SendFakeEarlyDataLength: 4,
10820 },
10821 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010822 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040010823 })
10824
10825 testCases = append(testCases, testCase{
10826 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010827 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10828 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010829 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040010830 Bugs: ProtocolBugs{
10831 SendFakeEarlyDataLength: 4,
10832 },
10833 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010834 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040010835 })
10836
10837 testCases = append(testCases, testCase{
10838 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010839 name: "SkipEarlyData-OmitEarlyDataExtension",
10840 config: Config{
10841 MaxVersion: VersionTLS13,
10842 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010843 SendFakeEarlyDataLength: 4,
10844 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010845 },
10846 },
10847 shouldFail: true,
10848 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10849 })
10850
10851 testCases = append(testCases, testCase{
10852 testType: serverTest,
10853 name: "SkipEarlyData-TooMuchData",
10854 config: Config{
10855 MaxVersion: VersionTLS13,
10856 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010857 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010858 },
10859 },
10860 shouldFail: true,
10861 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10862 })
10863
10864 testCases = append(testCases, testCase{
10865 testType: serverTest,
10866 name: "SkipEarlyData-Interleaved",
10867 config: Config{
10868 MaxVersion: VersionTLS13,
10869 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010870 SendFakeEarlyDataLength: 4,
10871 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010872 },
10873 },
10874 shouldFail: true,
10875 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10876 })
10877
10878 testCases = append(testCases, testCase{
10879 testType: serverTest,
10880 name: "SkipEarlyData-EarlyDataInTLS12",
10881 config: Config{
10882 MaxVersion: VersionTLS13,
10883 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010884 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010885 },
10886 },
10887 shouldFail: true,
10888 expectedError: ":UNEXPECTED_RECORD:",
10889 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10890 })
10891
10892 testCases = append(testCases, testCase{
10893 testType: serverTest,
10894 name: "SkipEarlyData-HRR",
10895 config: Config{
10896 MaxVersion: VersionTLS13,
10897 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010898 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010899 },
10900 DefaultCurves: []CurveID{},
10901 },
10902 })
10903
10904 testCases = append(testCases, testCase{
10905 testType: serverTest,
10906 name: "SkipEarlyData-HRR-Interleaved",
10907 config: Config{
10908 MaxVersion: VersionTLS13,
10909 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010910 SendFakeEarlyDataLength: 4,
10911 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010912 },
10913 DefaultCurves: []CurveID{},
10914 },
10915 shouldFail: true,
10916 expectedError: ":UNEXPECTED_RECORD:",
10917 })
10918
10919 testCases = append(testCases, testCase{
10920 testType: serverTest,
10921 name: "SkipEarlyData-HRR-TooMuchData",
10922 config: Config{
10923 MaxVersion: VersionTLS13,
10924 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010925 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010926 },
10927 DefaultCurves: []CurveID{},
10928 },
10929 shouldFail: true,
10930 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10931 })
10932
10933 // Test that skipping early data looking for cleartext correctly
10934 // processes an alert record.
10935 testCases = append(testCases, testCase{
10936 testType: serverTest,
10937 name: "SkipEarlyData-HRR-FatalAlert",
10938 config: Config{
10939 MaxVersion: VersionTLS13,
10940 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010941 SendEarlyAlert: true,
10942 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010943 },
10944 DefaultCurves: []CurveID{},
10945 },
10946 shouldFail: true,
10947 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10948 })
10949
10950 testCases = append(testCases, testCase{
10951 testType: serverTest,
10952 name: "SkipEarlyData-SecondClientHelloEarlyData",
10953 config: Config{
10954 MaxVersion: VersionTLS13,
10955 Bugs: ProtocolBugs{
10956 SendEarlyDataOnSecondClientHello: true,
10957 },
10958 DefaultCurves: []CurveID{},
10959 },
10960 shouldFail: true,
10961 expectedLocalError: "remote error: bad record MAC",
10962 })
10963
10964 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010965 testType: clientTest,
10966 name: "EmptyEncryptedExtensions",
10967 config: Config{
10968 MaxVersion: VersionTLS13,
10969 Bugs: ProtocolBugs{
10970 EmptyEncryptedExtensions: true,
10971 },
10972 },
10973 shouldFail: true,
10974 expectedLocalError: "remote error: error decoding message",
10975 })
10976
10977 testCases = append(testCases, testCase{
10978 testType: clientTest,
10979 name: "EncryptedExtensionsWithKeyShare",
10980 config: Config{
10981 MaxVersion: VersionTLS13,
10982 Bugs: ProtocolBugs{
10983 EncryptedExtensionsWithKeyShare: true,
10984 },
10985 },
10986 shouldFail: true,
10987 expectedLocalError: "remote error: unsupported extension",
10988 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010989
10990 testCases = append(testCases, testCase{
10991 testType: serverTest,
10992 name: "SendHelloRetryRequest",
10993 config: Config{
10994 MaxVersion: VersionTLS13,
10995 // Require a HelloRetryRequest for every curve.
10996 DefaultCurves: []CurveID{},
10997 },
10998 expectedCurveID: CurveX25519,
10999 })
11000
11001 testCases = append(testCases, testCase{
11002 testType: serverTest,
11003 name: "SendHelloRetryRequest-2",
11004 config: Config{
11005 MaxVersion: VersionTLS13,
11006 DefaultCurves: []CurveID{CurveP384},
11007 },
11008 // Although the ClientHello did not predict our preferred curve,
11009 // we always select it whether it is predicted or not.
11010 expectedCurveID: CurveX25519,
11011 })
11012
11013 testCases = append(testCases, testCase{
11014 name: "UnknownCurve-HelloRetryRequest",
11015 config: Config{
11016 MaxVersion: VersionTLS13,
11017 // P-384 requires HelloRetryRequest in BoringSSL.
11018 CurvePreferences: []CurveID{CurveP384},
11019 Bugs: ProtocolBugs{
11020 SendHelloRetryRequestCurve: bogusCurve,
11021 },
11022 },
11023 shouldFail: true,
11024 expectedError: ":WRONG_CURVE:",
11025 })
11026
11027 testCases = append(testCases, testCase{
11028 name: "DisabledCurve-HelloRetryRequest",
11029 config: Config{
11030 MaxVersion: VersionTLS13,
11031 CurvePreferences: []CurveID{CurveP256},
11032 Bugs: ProtocolBugs{
11033 IgnorePeerCurvePreferences: true,
11034 },
11035 },
11036 flags: []string{"-p384-only"},
11037 shouldFail: true,
11038 expectedError: ":WRONG_CURVE:",
11039 })
11040
11041 testCases = append(testCases, testCase{
11042 name: "UnnecessaryHelloRetryRequest",
11043 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040011044 MaxVersion: VersionTLS13,
11045 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040011046 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040011047 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040011048 },
11049 },
11050 shouldFail: true,
11051 expectedError: ":WRONG_CURVE:",
11052 })
11053
11054 testCases = append(testCases, testCase{
11055 name: "SecondHelloRetryRequest",
11056 config: Config{
11057 MaxVersion: VersionTLS13,
11058 // P-384 requires HelloRetryRequest in BoringSSL.
11059 CurvePreferences: []CurveID{CurveP384},
11060 Bugs: ProtocolBugs{
11061 SecondHelloRetryRequest: true,
11062 },
11063 },
11064 shouldFail: true,
11065 expectedError: ":UNEXPECTED_MESSAGE:",
11066 })
11067
11068 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011069 name: "HelloRetryRequest-Empty",
11070 config: Config{
11071 MaxVersion: VersionTLS13,
11072 Bugs: ProtocolBugs{
11073 AlwaysSendHelloRetryRequest: true,
11074 },
11075 },
11076 shouldFail: true,
11077 expectedError: ":DECODE_ERROR:",
11078 })
11079
11080 testCases = append(testCases, testCase{
11081 name: "HelloRetryRequest-DuplicateCurve",
11082 config: Config{
11083 MaxVersion: VersionTLS13,
11084 // P-384 requires a HelloRetryRequest against BoringSSL's default
11085 // configuration. Assert this ExpectMissingKeyShare.
11086 CurvePreferences: []CurveID{CurveP384},
11087 Bugs: ProtocolBugs{
11088 ExpectMissingKeyShare: true,
11089 DuplicateHelloRetryRequestExtensions: true,
11090 },
11091 },
11092 shouldFail: true,
11093 expectedError: ":DUPLICATE_EXTENSION:",
11094 expectedLocalError: "remote error: illegal parameter",
11095 })
11096
11097 testCases = append(testCases, testCase{
11098 name: "HelloRetryRequest-Cookie",
11099 config: Config{
11100 MaxVersion: VersionTLS13,
11101 Bugs: ProtocolBugs{
11102 SendHelloRetryRequestCookie: []byte("cookie"),
11103 },
11104 },
11105 })
11106
11107 testCases = append(testCases, testCase{
11108 name: "HelloRetryRequest-DuplicateCookie",
11109 config: Config{
11110 MaxVersion: VersionTLS13,
11111 Bugs: ProtocolBugs{
11112 SendHelloRetryRequestCookie: []byte("cookie"),
11113 DuplicateHelloRetryRequestExtensions: true,
11114 },
11115 },
11116 shouldFail: true,
11117 expectedError: ":DUPLICATE_EXTENSION:",
11118 expectedLocalError: "remote error: illegal parameter",
11119 })
11120
11121 testCases = append(testCases, testCase{
11122 name: "HelloRetryRequest-EmptyCookie",
11123 config: Config{
11124 MaxVersion: VersionTLS13,
11125 Bugs: ProtocolBugs{
11126 SendHelloRetryRequestCookie: []byte{},
11127 },
11128 },
11129 shouldFail: true,
11130 expectedError: ":DECODE_ERROR:",
11131 })
11132
11133 testCases = append(testCases, testCase{
11134 name: "HelloRetryRequest-Cookie-Curve",
11135 config: Config{
11136 MaxVersion: VersionTLS13,
11137 // P-384 requires HelloRetryRequest in BoringSSL.
11138 CurvePreferences: []CurveID{CurveP384},
11139 Bugs: ProtocolBugs{
11140 SendHelloRetryRequestCookie: []byte("cookie"),
11141 ExpectMissingKeyShare: true,
11142 },
11143 },
11144 })
11145
11146 testCases = append(testCases, testCase{
11147 name: "HelloRetryRequest-Unknown",
11148 config: Config{
11149 MaxVersion: VersionTLS13,
11150 Bugs: ProtocolBugs{
11151 CustomHelloRetryRequestExtension: "extension",
11152 },
11153 },
11154 shouldFail: true,
11155 expectedError: ":UNEXPECTED_EXTENSION:",
11156 expectedLocalError: "remote error: unsupported extension",
11157 })
11158
11159 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011160 testType: serverTest,
11161 name: "SecondClientHelloMissingKeyShare",
11162 config: Config{
11163 MaxVersion: VersionTLS13,
11164 DefaultCurves: []CurveID{},
11165 Bugs: ProtocolBugs{
11166 SecondClientHelloMissingKeyShare: true,
11167 },
11168 },
11169 shouldFail: true,
11170 expectedError: ":MISSING_KEY_SHARE:",
11171 })
11172
11173 testCases = append(testCases, testCase{
11174 testType: serverTest,
11175 name: "SecondClientHelloWrongCurve",
11176 config: Config{
11177 MaxVersion: VersionTLS13,
11178 DefaultCurves: []CurveID{},
11179 Bugs: ProtocolBugs{
11180 MisinterpretHelloRetryRequestCurve: CurveP521,
11181 },
11182 },
11183 shouldFail: true,
11184 expectedError: ":WRONG_CURVE:",
11185 })
11186
11187 testCases = append(testCases, testCase{
11188 name: "HelloRetryRequestVersionMismatch",
11189 config: Config{
11190 MaxVersion: VersionTLS13,
11191 // P-384 requires HelloRetryRequest in BoringSSL.
11192 CurvePreferences: []CurveID{CurveP384},
11193 Bugs: ProtocolBugs{
11194 SendServerHelloVersion: 0x0305,
11195 },
11196 },
11197 shouldFail: true,
11198 expectedError: ":WRONG_VERSION_NUMBER:",
11199 })
11200
11201 testCases = append(testCases, testCase{
11202 name: "HelloRetryRequestCurveMismatch",
11203 config: Config{
11204 MaxVersion: VersionTLS13,
11205 // P-384 requires HelloRetryRequest in BoringSSL.
11206 CurvePreferences: []CurveID{CurveP384},
11207 Bugs: ProtocolBugs{
11208 // Send P-384 (correct) in the HelloRetryRequest.
11209 SendHelloRetryRequestCurve: CurveP384,
11210 // But send P-256 in the ServerHello.
11211 SendCurve: CurveP256,
11212 },
11213 },
11214 shouldFail: true,
11215 expectedError: ":WRONG_CURVE:",
11216 })
11217
11218 // Test the server selecting a curve that requires a HelloRetryRequest
11219 // without sending it.
11220 testCases = append(testCases, testCase{
11221 name: "SkipHelloRetryRequest",
11222 config: Config{
11223 MaxVersion: VersionTLS13,
11224 // P-384 requires HelloRetryRequest in BoringSSL.
11225 CurvePreferences: []CurveID{CurveP384},
11226 Bugs: ProtocolBugs{
11227 SkipHelloRetryRequest: true,
11228 },
11229 },
11230 shouldFail: true,
11231 expectedError: ":WRONG_CURVE:",
11232 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011233
11234 testCases = append(testCases, testCase{
11235 name: "TLS13-RequestContextInHandshake",
11236 config: Config{
11237 MaxVersion: VersionTLS13,
11238 MinVersion: VersionTLS13,
11239 ClientAuth: RequireAnyClientCert,
11240 Bugs: ProtocolBugs{
11241 SendRequestContext: []byte("request context"),
11242 },
11243 },
11244 flags: []string{
11245 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11246 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11247 },
11248 shouldFail: true,
11249 expectedError: ":DECODE_ERROR:",
11250 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011251
11252 testCases = append(testCases, testCase{
11253 testType: serverTest,
11254 name: "TLS13-TrailingKeyShareData",
11255 config: Config{
11256 MaxVersion: VersionTLS13,
11257 Bugs: ProtocolBugs{
11258 TrailingKeyShareData: true,
11259 },
11260 },
11261 shouldFail: true,
11262 expectedError: ":DECODE_ERROR:",
11263 })
David Benjamin7f78df42016-10-05 22:33:19 -040011264
11265 testCases = append(testCases, testCase{
11266 name: "TLS13-AlwaysSelectPSKIdentity",
11267 config: Config{
11268 MaxVersion: VersionTLS13,
11269 Bugs: ProtocolBugs{
11270 AlwaysSelectPSKIdentity: true,
11271 },
11272 },
11273 shouldFail: true,
11274 expectedError: ":UNEXPECTED_EXTENSION:",
11275 })
11276
11277 testCases = append(testCases, testCase{
11278 name: "TLS13-InvalidPSKIdentity",
11279 config: Config{
11280 MaxVersion: VersionTLS13,
11281 Bugs: ProtocolBugs{
11282 SelectPSKIdentityOnResume: 1,
11283 },
11284 },
11285 resumeSession: true,
11286 shouldFail: true,
11287 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11288 })
David Benjamin1286bee2016-10-07 15:25:06 -040011289
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011290 testCases = append(testCases, testCase{
11291 testType: serverTest,
11292 name: "TLS13-ExtraPSKIdentity",
11293 config: Config{
11294 MaxVersion: VersionTLS13,
11295 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011296 ExtraPSKIdentity: true,
11297 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011298 },
11299 },
11300 resumeSession: true,
11301 })
11302
David Benjamin1286bee2016-10-07 15:25:06 -040011303 // Test that unknown NewSessionTicket extensions are tolerated.
11304 testCases = append(testCases, testCase{
11305 name: "TLS13-CustomTicketExtension",
11306 config: Config{
11307 MaxVersion: VersionTLS13,
11308 Bugs: ProtocolBugs{
11309 CustomTicketExtension: "1234",
11310 },
11311 },
11312 })
Steven Valdez2d850622017-01-11 11:34:52 -050011313
Steven Valdez0e4a4482017-07-17 11:12:34 -040011314 for _, noSessionID := range []bool{false, true} {
11315 prefix := "TLS13Experiment"
11316 variant := TLS13Experiment
11317 if noSessionID {
11318 prefix = "TLS13NoSessionIDExperiment"
11319 variant = TLS13NoSessionIDExperiment
11320 }
11321
11322 // Test that enabling a TLS 1.3 variant does not interfere with
11323 // TLS 1.2 session ID resumption.
11324 testCases = append(testCases, testCase{
11325 testType: clientTest,
11326 name: prefix + "-ResumeTLS12SessionID",
11327 config: Config{
11328 MaxVersion: VersionTLS12,
11329 SessionTicketsDisabled: true,
11330 },
11331 resumeSession: true,
11332 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11333 })
11334
11335 // Test that the server correctly echoes back session IDs of
11336 // various lengths.
11337 testCases = append(testCases, testCase{
11338 testType: serverTest,
11339 name: prefix + "-EmptySessionID",
11340 config: Config{
11341 MaxVersion: VersionTLS13,
11342 Bugs: ProtocolBugs{
11343 SendClientHelloSessionID: []byte{},
11344 },
11345 },
11346 tls13Variant: variant,
11347 })
11348
11349 testCases = append(testCases, testCase{
11350 testType: serverTest,
11351 name: prefix + "-ShortSessionID",
11352 config: Config{
11353 MaxVersion: VersionTLS13,
11354 Bugs: ProtocolBugs{
11355 SendClientHelloSessionID: make([]byte, 16),
11356 },
11357 },
11358 tls13Variant: variant,
11359 })
11360
11361 testCases = append(testCases, testCase{
11362 testType: serverTest,
11363 name: prefix + "-FullSessionID",
11364 config: Config{
11365 MaxVersion: VersionTLS13,
11366 Bugs: ProtocolBugs{
11367 SendClientHelloSessionID: make([]byte, 32),
11368 },
11369 },
11370 tls13Variant: variant,
11371 })
11372 }
11373
11374 // Test that the client sends a fake session ID in TLS13Experiment.
11375 testCases = append(testCases, testCase{
11376 testType: clientTest,
11377 name: "TLS13Experiment-RequireSessionID",
11378 config: Config{
11379 MaxVersion: VersionTLS13,
11380 Bugs: ProtocolBugs{
11381 ExpectClientHelloSessionID: true,
11382 },
11383 },
11384 tls13Variant: TLS13Experiment,
11385 })
11386
11387 // Test that the client does not send a fake session ID in
11388 // TLS13NoSessionIDExperiment.
11389 testCases = append(testCases, testCase{
11390 testType: clientTest,
11391 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11392 config: Config{
11393 MaxVersion: VersionTLS13,
11394 Bugs: ProtocolBugs{
11395 ExpectEmptyClientHelloSessionID: true,
11396 },
11397 },
11398 tls13Variant: TLS13NoSessionIDExperiment,
11399 })
11400
Steven Valdez2d850622017-01-11 11:34:52 -050011401 testCases = append(testCases, testCase{
11402 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011403 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011404 config: Config{
11405 MaxVersion: VersionTLS13,
11406 MaxEarlyDataSize: 16384,
11407 },
11408 resumeConfig: &Config{
11409 MaxVersion: VersionTLS13,
11410 MaxEarlyDataSize: 16384,
11411 Bugs: ProtocolBugs{
11412 AlwaysRejectEarlyData: true,
11413 },
11414 },
11415 resumeSession: true,
11416 flags: []string{
11417 "-enable-early-data",
11418 "-expect-early-data-info",
11419 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011420 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011421 },
11422 })
11423
11424 testCases = append(testCases, testCase{
11425 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011426 name: "TLS13Experiment-EarlyData-Reject-Client",
11427 config: Config{
11428 MaxVersion: VersionTLS13,
11429 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011430 },
11431 resumeConfig: &Config{
11432 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011433 MaxEarlyDataSize: 16384,
11434 Bugs: ProtocolBugs{
11435 AlwaysRejectEarlyData: true,
11436 },
11437 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011438 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011439 resumeSession: true,
11440 flags: []string{
11441 "-enable-early-data",
11442 "-expect-early-data-info",
11443 "-expect-reject-early-data",
11444 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011445 },
11446 })
11447
11448 testCases = append(testCases, testCase{
11449 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011450 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11451 config: Config{
11452 MaxVersion: VersionTLS13,
11453 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011454 },
11455 resumeConfig: &Config{
11456 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011457 MaxEarlyDataSize: 16384,
11458 Bugs: ProtocolBugs{
11459 AlwaysRejectEarlyData: true,
11460 },
11461 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011462 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011463 resumeSession: true,
11464 flags: []string{
11465 "-enable-early-data",
11466 "-expect-early-data-info",
11467 "-expect-reject-early-data",
11468 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011469 },
11470 })
11471
11472 testCases = append(testCases, testCase{
11473 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011474 name: "TLS13-EarlyData-RejectTicket-Client",
11475 config: Config{
11476 MaxVersion: VersionTLS13,
11477 MaxEarlyDataSize: 16384,
11478 Certificates: []Certificate{rsaCertificate},
11479 },
11480 resumeConfig: &Config{
11481 MaxVersion: VersionTLS13,
11482 MaxEarlyDataSize: 16384,
11483 Certificates: []Certificate{ecdsaP256Certificate},
11484 SessionTicketsDisabled: true,
11485 },
11486 resumeSession: true,
11487 expectResumeRejected: true,
11488 flags: []string{
11489 "-enable-early-data",
11490 "-expect-early-data-info",
11491 "-expect-reject-early-data",
11492 "-on-resume-shim-writes-first",
11493 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11494 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11495 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11496 // Session tickets are disabled, so the runner will not send a ticket.
11497 "-on-retry-expect-no-session",
11498 },
11499 })
11500
11501 testCases = append(testCases, testCase{
11502 testType: clientTest,
11503 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011504 config: Config{
11505 MaxVersion: VersionTLS13,
11506 MaxEarlyDataSize: 16384,
11507 },
11508 resumeConfig: &Config{
11509 MaxVersion: VersionTLS13,
11510 MaxEarlyDataSize: 16384,
11511 Bugs: ProtocolBugs{
11512 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11513 },
11514 },
11515 resumeSession: true,
11516 flags: []string{
11517 "-enable-early-data",
11518 "-expect-early-data-info",
11519 "-expect-reject-early-data",
11520 },
11521 })
11522
11523 // The client must check the server does not send the early_data
11524 // extension while rejecting the session.
11525 testCases = append(testCases, testCase{
11526 testType: clientTest,
11527 name: "TLS13-EarlyDataWithoutResume-Client",
11528 config: Config{
11529 MaxVersion: VersionTLS13,
11530 MaxEarlyDataSize: 16384,
11531 },
11532 resumeConfig: &Config{
11533 MaxVersion: VersionTLS13,
11534 SessionTicketsDisabled: true,
11535 Bugs: ProtocolBugs{
11536 SendEarlyDataExtension: true,
11537 },
11538 },
11539 resumeSession: true,
11540 flags: []string{
11541 "-enable-early-data",
11542 "-expect-early-data-info",
11543 },
11544 shouldFail: true,
11545 expectedError: ":UNEXPECTED_EXTENSION:",
11546 })
11547
11548 // The client must fail with a dedicated error code if the server
11549 // responds with TLS 1.2 when offering 0-RTT.
11550 testCases = append(testCases, testCase{
11551 testType: clientTest,
11552 name: "TLS13-EarlyDataVersionDowngrade-Client",
11553 config: Config{
11554 MaxVersion: VersionTLS13,
11555 MaxEarlyDataSize: 16384,
11556 },
11557 resumeConfig: &Config{
11558 MaxVersion: VersionTLS12,
11559 },
11560 resumeSession: true,
11561 flags: []string{
11562 "-enable-early-data",
11563 "-expect-early-data-info",
11564 },
11565 shouldFail: true,
11566 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11567 })
11568
11569 // Test that the client rejects an (unsolicited) early_data extension if
11570 // the server sent an HRR.
11571 testCases = append(testCases, testCase{
11572 testType: clientTest,
11573 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11574 config: Config{
11575 MaxVersion: VersionTLS13,
11576 MaxEarlyDataSize: 16384,
11577 },
11578 resumeConfig: &Config{
11579 MaxVersion: VersionTLS13,
11580 MaxEarlyDataSize: 16384,
11581 Bugs: ProtocolBugs{
11582 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11583 SendEarlyDataExtension: true,
11584 },
11585 },
11586 resumeSession: true,
11587 flags: []string{
11588 "-enable-early-data",
11589 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011590 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011591 },
11592 shouldFail: true,
11593 expectedError: ":UNEXPECTED_EXTENSION:",
11594 })
11595
11596 fooString := "foo"
11597 barString := "bar"
11598
11599 // Test that the client reports the correct ALPN after a 0-RTT reject
11600 // that changed it.
11601 testCases = append(testCases, testCase{
11602 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011603 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011604 config: Config{
11605 MaxVersion: VersionTLS13,
11606 MaxEarlyDataSize: 16384,
11607 Bugs: ProtocolBugs{
11608 ALPNProtocol: &fooString,
11609 },
11610 },
11611 resumeConfig: &Config{
11612 MaxVersion: VersionTLS13,
11613 MaxEarlyDataSize: 16384,
11614 Bugs: ProtocolBugs{
11615 ALPNProtocol: &barString,
11616 },
11617 },
11618 resumeSession: true,
11619 flags: []string{
11620 "-advertise-alpn", "\x03foo\x03bar",
11621 "-enable-early-data",
11622 "-expect-early-data-info",
11623 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011624 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011625 "-on-resume-expect-alpn", "foo",
11626 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011627 },
11628 })
11629
11630 // Test that the client reports the correct ALPN after a 0-RTT reject if
11631 // ALPN was omitted from the first connection.
11632 testCases = append(testCases, testCase{
11633 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011634 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011635 config: Config{
11636 MaxVersion: VersionTLS13,
11637 MaxEarlyDataSize: 16384,
11638 },
11639 resumeConfig: &Config{
11640 MaxVersion: VersionTLS13,
11641 MaxEarlyDataSize: 16384,
11642 NextProtos: []string{"foo"},
11643 },
11644 resumeSession: true,
11645 flags: []string{
11646 "-advertise-alpn", "\x03foo\x03bar",
11647 "-enable-early-data",
11648 "-expect-early-data-info",
11649 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011650 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011651 "-on-resume-expect-alpn", "",
11652 "-on-retry-expect-alpn", "foo",
11653 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011654 },
11655 })
11656
11657 // Test that the client reports the correct ALPN after a 0-RTT reject if
11658 // ALPN was omitted from the second connection.
11659 testCases = append(testCases, testCase{
11660 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011661 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011662 config: Config{
11663 MaxVersion: VersionTLS13,
11664 MaxEarlyDataSize: 16384,
11665 NextProtos: []string{"foo"},
11666 },
11667 resumeConfig: &Config{
11668 MaxVersion: VersionTLS13,
11669 MaxEarlyDataSize: 16384,
11670 },
11671 resumeSession: true,
11672 flags: []string{
11673 "-advertise-alpn", "\x03foo\x03bar",
11674 "-enable-early-data",
11675 "-expect-early-data-info",
11676 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011677 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011678 "-on-resume-expect-alpn", "foo",
11679 "-on-retry-expect-alpn", "",
11680 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011681 },
11682 })
11683
11684 // Test that the client enforces ALPN match on 0-RTT accept.
11685 testCases = append(testCases, testCase{
11686 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011687 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011688 config: Config{
11689 MaxVersion: VersionTLS13,
11690 MaxEarlyDataSize: 16384,
11691 Bugs: ProtocolBugs{
11692 ALPNProtocol: &fooString,
11693 },
11694 },
11695 resumeConfig: &Config{
11696 MaxVersion: VersionTLS13,
11697 MaxEarlyDataSize: 16384,
11698 Bugs: ProtocolBugs{
11699 AlwaysAcceptEarlyData: true,
11700 ALPNProtocol: &barString,
11701 },
11702 },
11703 resumeSession: true,
11704 flags: []string{
11705 "-advertise-alpn", "\x03foo\x03bar",
11706 "-enable-early-data",
11707 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011708 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011709 "-on-resume-expect-alpn", "foo",
11710 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011711 },
11712 shouldFail: true,
11713 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11714 })
11715
11716 // Test that the server correctly rejects 0-RTT when the previous
11717 // session did not allow early data on resumption.
11718 testCases = append(testCases, testCase{
11719 testType: serverTest,
11720 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11721 config: Config{
11722 MaxVersion: VersionTLS13,
11723 },
11724 resumeConfig: &Config{
11725 MaxVersion: VersionTLS13,
11726 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011727 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011728 ExpectEarlyDataAccepted: false,
11729 },
11730 },
11731 resumeSession: true,
11732 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011733 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011734 "-expect-reject-early-data",
11735 },
11736 })
11737
11738 // Test that we reject early data where ALPN is omitted from the first
11739 // connection.
11740 testCases = append(testCases, testCase{
11741 testType: serverTest,
11742 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11743 config: Config{
11744 MaxVersion: VersionTLS13,
11745 NextProtos: []string{},
11746 },
11747 resumeConfig: &Config{
11748 MaxVersion: VersionTLS13,
11749 NextProtos: []string{"foo"},
11750 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011751 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011752 ExpectEarlyDataAccepted: false,
11753 },
11754 },
11755 resumeSession: true,
11756 flags: []string{
11757 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011758 "-on-initial-select-alpn", "",
11759 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011760 },
11761 })
11762
11763 // Test that we reject early data where ALPN is omitted from the second
11764 // connection.
11765 testCases = append(testCases, testCase{
11766 testType: serverTest,
11767 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11768 config: Config{
11769 MaxVersion: VersionTLS13,
11770 NextProtos: []string{"foo"},
11771 },
11772 resumeConfig: &Config{
11773 MaxVersion: VersionTLS13,
11774 NextProtos: []string{},
11775 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011776 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011777 ExpectEarlyDataAccepted: false,
11778 },
11779 },
11780 resumeSession: true,
11781 flags: []string{
11782 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011783 "-on-initial-select-alpn", "foo",
11784 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011785 },
11786 })
11787
11788 // Test that we reject early data with mismatched ALPN.
11789 testCases = append(testCases, testCase{
11790 testType: serverTest,
11791 name: "TLS13-EarlyData-ALPNMismatch-Server",
11792 config: Config{
11793 MaxVersion: VersionTLS13,
11794 NextProtos: []string{"foo"},
11795 },
11796 resumeConfig: &Config{
11797 MaxVersion: VersionTLS13,
11798 NextProtos: []string{"bar"},
11799 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011800 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011801 ExpectEarlyDataAccepted: false,
11802 },
11803 },
11804 resumeSession: true,
11805 flags: []string{
11806 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011807 "-on-initial-select-alpn", "foo",
11808 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011809 },
11810 })
11811
David Benjamin6bb507b2017-03-29 16:35:57 -050011812 // Test that the client offering 0-RTT and Channel ID forbids the server
11813 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011814 testCases = append(testCases, testCase{
11815 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011816 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011817 config: Config{
11818 MaxVersion: VersionTLS13,
11819 MaxEarlyDataSize: 16384,
11820 RequestChannelID: true,
11821 },
11822 resumeSession: true,
11823 expectChannelID: true,
11824 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011825 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011826 flags: []string{
11827 "-enable-early-data",
11828 "-expect-early-data-info",
11829 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11830 },
11831 })
11832
David Benjamin6bb507b2017-03-29 16:35:57 -050011833 // Test that the client offering Channel ID and 0-RTT allows the server
11834 // to decline 0-RTT.
11835 testCases = append(testCases, testCase{
11836 testType: clientTest,
11837 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11838 config: Config{
11839 MaxVersion: VersionTLS13,
11840 MaxEarlyDataSize: 16384,
11841 RequestChannelID: true,
11842 Bugs: ProtocolBugs{
11843 AlwaysRejectEarlyData: true,
11844 },
11845 },
11846 resumeSession: true,
11847 expectChannelID: true,
11848 flags: []string{
11849 "-enable-early-data",
11850 "-expect-early-data-info",
11851 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11852 "-expect-reject-early-data",
11853 },
11854 })
11855
11856 // Test that the client offering Channel ID and 0-RTT allows the server
11857 // to decline Channel ID.
11858 testCases = append(testCases, testCase{
11859 testType: clientTest,
11860 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11861 config: Config{
11862 MaxVersion: VersionTLS13,
11863 MaxEarlyDataSize: 16384,
11864 },
11865 resumeSession: true,
11866 flags: []string{
11867 "-enable-early-data",
11868 "-expect-early-data-info",
11869 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11870 "-expect-accept-early-data",
11871 },
11872 })
11873
11874 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11875 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011876 testCases = append(testCases, testCase{
11877 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011878 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011879 config: Config{
11880 MaxVersion: VersionTLS13,
11881 ChannelID: channelIDKey,
11882 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011883 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011884 ExpectEarlyDataAccepted: false,
11885 },
11886 },
11887 resumeSession: true,
11888 expectChannelID: true,
11889 flags: []string{
11890 "-enable-early-data",
11891 "-expect-reject-early-data",
11892 "-expect-channel-id",
11893 base64.StdEncoding.EncodeToString(channelIDBytes),
11894 },
11895 })
11896
David Benjamin6bb507b2017-03-29 16:35:57 -050011897 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11898 // if not offered Channel ID.
11899 testCases = append(testCases, testCase{
11900 testType: serverTest,
11901 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11902 config: Config{
11903 MaxVersion: VersionTLS13,
11904 Bugs: ProtocolBugs{
11905 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11906 ExpectEarlyDataAccepted: true,
11907 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11908 },
11909 },
11910 resumeSession: true,
11911 expectChannelID: false,
11912 flags: []string{
11913 "-enable-early-data",
11914 "-expect-accept-early-data",
11915 "-enable-channel-id",
11916 },
11917 })
11918
David Benjamin32c89272017-03-26 13:54:21 -050011919 // Test that the server rejects 0-RTT streams without end_of_early_data.
11920 // The subsequent records should fail to decrypt.
11921 testCases = append(testCases, testCase{
11922 testType: serverTest,
11923 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11924 config: Config{
11925 MaxVersion: VersionTLS13,
11926 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011927 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011928 ExpectEarlyDataAccepted: true,
11929 SkipEndOfEarlyData: true,
11930 },
11931 },
11932 resumeSession: true,
11933 flags: []string{"-enable-early-data"},
11934 shouldFail: true,
11935 expectedLocalError: "remote error: bad record MAC",
11936 expectedError: ":BAD_DECRYPT:",
11937 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011938
11939 testCases = append(testCases, testCase{
11940 testType: serverTest,
11941 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11942 config: Config{
11943 MaxVersion: VersionTLS13,
11944 },
11945 resumeConfig: &Config{
11946 MaxVersion: VersionTLS13,
11947 Bugs: ProtocolBugs{
11948 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11949 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011950 ExpectEarlyDataAccepted: true,
11951 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011952 },
11953 resumeSession: true,
11954 shouldFail: true,
11955 expectedError: ":UNEXPECTED_RECORD:",
11956 expectedLocalError: "remote error: unexpected message",
11957 flags: []string{
11958 "-enable-early-data",
11959 },
11960 })
David Benjamind9cbb532017-07-07 13:17:19 -040011961
11962 // Test that the client reports TLS 1.3 as the version while sending
11963 // early data.
11964 testCases = append(testCases, testCase{
11965 testType: clientTest,
11966 name: "TLS13-EarlyData-Client-VersionAPI",
11967 config: Config{
11968 MaxVersion: VersionTLS13,
11969 MaxEarlyDataSize: 16384,
11970 },
11971 resumeSession: true,
11972 flags: []string{
11973 "-enable-early-data",
11974 "-expect-early-data-info",
11975 "-expect-accept-early-data",
11976 "-expect-version", strconv.Itoa(VersionTLS13),
11977 },
11978 })
David Benjamin4a37de02017-08-08 20:15:40 -040011979
11980 // Test that client and server both notice handshake errors after data
11981 // has started flowing.
11982 testCases = append(testCases, testCase{
11983 testType: clientTest,
11984 name: "TLS13-EarlyData-Client-BadFinished",
11985 config: Config{
11986 MaxVersion: VersionTLS13,
11987 MaxEarlyDataSize: 16384,
11988 },
11989 resumeConfig: &Config{
11990 MaxVersion: VersionTLS13,
11991 MaxEarlyDataSize: 16384,
11992 Bugs: ProtocolBugs{
11993 BadFinished: true,
11994 },
11995 },
11996 resumeSession: true,
11997 flags: []string{
11998 "-enable-early-data",
11999 "-expect-early-data-info",
12000 "-expect-accept-early-data",
12001 },
12002 shouldFail: true,
12003 expectedError: ":DIGEST_CHECK_FAILED:",
12004 expectedLocalError: "remote error: error decrypting message",
12005 })
12006 testCases = append(testCases, testCase{
12007 testType: serverTest,
12008 name: "TLS13-EarlyData-Server-BadFinished",
12009 config: Config{
12010 MaxVersion: VersionTLS13,
12011 MaxEarlyDataSize: 16384,
12012 },
12013 resumeConfig: &Config{
12014 MaxVersion: VersionTLS13,
12015 MaxEarlyDataSize: 16384,
12016 Bugs: ProtocolBugs{
12017 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12018 ExpectEarlyDataAccepted: true,
12019 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12020 BadFinished: true,
12021 },
12022 },
12023 resumeSession: true,
12024 flags: []string{
12025 "-enable-early-data",
12026 "-expect-accept-early-data",
12027 },
12028 shouldFail: true,
12029 expectedError: ":DIGEST_CHECK_FAILED:",
12030 expectedLocalError: "remote error: error decrypting message",
12031 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020012032 testCases = append(testCases, testCase{
12033 testType: serverTest,
12034 name: "TLS13-ServerSkipCertificateVerify",
12035 config: Config{
12036 MinVersion: VersionTLS13,
12037 MaxVersion: VersionTLS13,
12038 Certificates: []Certificate{rsaChainCertificate},
12039 Bugs: ProtocolBugs{
12040 SkipCertificateVerify: true,
12041 },
12042 },
12043 expectPeerCertificate: &rsaChainCertificate,
12044 flags: []string{
12045 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12046 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12047 "-require-any-client-certificate",
12048 },
12049 shouldFail: true,
12050 expectedError: ":UNEXPECTED_MESSAGE:",
12051 expectedLocalError: "remote error: unexpected message",
12052 })
12053 testCases = append(testCases, testCase{
12054 testType: clientTest,
12055 name: "TLS13-ClientSkipCertificateVerify",
12056 config: Config{
12057 MinVersion: VersionTLS13,
12058 MaxVersion: VersionTLS13,
12059 Certificates: []Certificate{rsaChainCertificate},
12060 Bugs: ProtocolBugs{
12061 SkipCertificateVerify: true,
12062 },
12063 },
12064 expectPeerCertificate: &rsaChainCertificate,
12065 flags: []string{
12066 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12067 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12068 },
12069 shouldFail: true,
12070 expectedError: ":UNEXPECTED_MESSAGE:",
12071 expectedLocalError: "remote error: unexpected message",
12072 })
Steven Valdez143e8b32016-07-11 13:19:03 -040012073}
12074
David Benjaminabbbee12016-10-31 19:20:42 -040012075func addTLS13CipherPreferenceTests() {
12076 // Test that client preference is honored if the shim has AES hardware
12077 // and ChaCha20-Poly1305 is preferred otherwise.
12078 testCases = append(testCases, testCase{
12079 testType: serverTest,
12080 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
12081 config: Config{
12082 MaxVersion: VersionTLS13,
12083 CipherSuites: []uint16{
12084 TLS_CHACHA20_POLY1305_SHA256,
12085 TLS_AES_128_GCM_SHA256,
12086 },
12087 },
12088 flags: []string{
12089 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12090 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12091 },
12092 })
12093
12094 testCases = append(testCases, testCase{
12095 testType: serverTest,
12096 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
12097 config: Config{
12098 MaxVersion: VersionTLS13,
12099 CipherSuites: []uint16{
12100 TLS_AES_128_GCM_SHA256,
12101 TLS_CHACHA20_POLY1305_SHA256,
12102 },
12103 },
12104 flags: []string{
12105 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12106 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12107 },
12108 })
12109
12110 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
12111 // whether it has AES hardware.
12112 testCases = append(testCases, testCase{
12113 name: "TLS13-CipherPreference-Client",
12114 config: Config{
12115 MaxVersion: VersionTLS13,
12116 // Use the client cipher order. (This is the default but
12117 // is listed to be explicit.)
12118 PreferServerCipherSuites: false,
12119 },
12120 flags: []string{
12121 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12122 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12123 },
12124 })
12125}
12126
David Benjaminf3fbade2016-09-19 13:08:16 -040012127func addPeekTests() {
12128 // Test SSL_peek works, including on empty records.
12129 testCases = append(testCases, testCase{
12130 name: "Peek-Basic",
12131 sendEmptyRecords: 1,
12132 flags: []string{"-peek-then-read"},
12133 })
12134
12135 // Test SSL_peek can drive the initial handshake.
12136 testCases = append(testCases, testCase{
12137 name: "Peek-ImplicitHandshake",
12138 flags: []string{
12139 "-peek-then-read",
12140 "-implicit-handshake",
12141 },
12142 })
12143
12144 // Test SSL_peek can discover and drive a renegotiation.
12145 testCases = append(testCases, testCase{
12146 name: "Peek-Renegotiate",
12147 config: Config{
12148 MaxVersion: VersionTLS12,
12149 },
12150 renegotiate: 1,
12151 flags: []string{
12152 "-peek-then-read",
12153 "-renegotiate-freely",
12154 "-expect-total-renegotiations", "1",
12155 },
12156 })
12157
12158 // Test SSL_peek can discover a close_notify.
12159 testCases = append(testCases, testCase{
12160 name: "Peek-Shutdown",
12161 config: Config{
12162 Bugs: ProtocolBugs{
12163 ExpectCloseNotify: true,
12164 },
12165 },
12166 flags: []string{
12167 "-peek-then-read",
12168 "-check-close-notify",
12169 },
12170 })
12171
12172 // Test SSL_peek can discover an alert.
12173 testCases = append(testCases, testCase{
12174 name: "Peek-Alert",
12175 config: Config{
12176 Bugs: ProtocolBugs{
12177 SendSpuriousAlert: alertRecordOverflow,
12178 },
12179 },
12180 flags: []string{"-peek-then-read"},
12181 shouldFail: true,
12182 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12183 })
12184
12185 // Test SSL_peek can handle KeyUpdate.
12186 testCases = append(testCases, testCase{
12187 name: "Peek-KeyUpdate",
12188 config: Config{
12189 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012190 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012191 sendKeyUpdates: 1,
12192 keyUpdateRequest: keyUpdateNotRequested,
12193 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012194 })
12195}
12196
David Benjamine6f22212016-11-08 14:28:24 -050012197func addRecordVersionTests() {
12198 for _, ver := range tlsVersions {
12199 // Test that the record version is enforced.
12200 testCases = append(testCases, testCase{
12201 name: "CheckRecordVersion-" + ver.name,
12202 config: Config{
12203 MinVersion: ver.version,
12204 MaxVersion: ver.version,
12205 Bugs: ProtocolBugs{
12206 SendRecordVersion: 0x03ff,
12207 },
12208 },
David Benjamina5022392017-07-10 17:40:39 -040012209 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012210 shouldFail: true,
12211 expectedError: ":WRONG_VERSION_NUMBER:",
12212 })
12213
12214 // Test that the ClientHello may use any record version, for
12215 // compatibility reasons.
12216 testCases = append(testCases, testCase{
12217 testType: serverTest,
12218 name: "LooseInitialRecordVersion-" + ver.name,
12219 config: Config{
12220 MinVersion: ver.version,
12221 MaxVersion: ver.version,
12222 Bugs: ProtocolBugs{
12223 SendInitialRecordVersion: 0x03ff,
12224 },
12225 },
David Benjamina5022392017-07-10 17:40:39 -040012226 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012227 })
12228
12229 // Test that garbage ClientHello record versions are rejected.
12230 testCases = append(testCases, testCase{
12231 testType: serverTest,
12232 name: "GarbageInitialRecordVersion-" + ver.name,
12233 config: Config{
12234 MinVersion: ver.version,
12235 MaxVersion: ver.version,
12236 Bugs: ProtocolBugs{
12237 SendInitialRecordVersion: 0xffff,
12238 },
12239 },
David Benjamina5022392017-07-10 17:40:39 -040012240 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012241 shouldFail: true,
12242 expectedError: ":WRONG_VERSION_NUMBER:",
12243 })
12244 }
12245}
12246
David Benjamin2c516452016-11-15 10:16:54 +090012247func addCertificateTests() {
David Benjamin2c516452016-11-15 10:16:54 +090012248 for _, ver := range tlsVersions {
David Benjamin3969fdf2017-08-29 15:50:58 -040012249 // Test that a certificate chain with intermediate may be sent
12250 // and received as both client and server.
David Benjamin2c516452016-11-15 10:16:54 +090012251 testCases = append(testCases, testCase{
12252 testType: clientTest,
12253 name: "SendReceiveIntermediate-Client-" + ver.name,
12254 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012255 MinVersion: ver.version,
12256 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012257 Certificates: []Certificate{rsaChainCertificate},
12258 ClientAuth: RequireAnyClientCert,
12259 },
David Benjamina5022392017-07-10 17:40:39 -040012260 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012261 expectPeerCertificate: &rsaChainCertificate,
12262 flags: []string{
12263 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12264 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12265 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12266 },
12267 })
12268
12269 testCases = append(testCases, testCase{
12270 testType: serverTest,
12271 name: "SendReceiveIntermediate-Server-" + ver.name,
12272 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012273 MinVersion: ver.version,
12274 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012275 Certificates: []Certificate{rsaChainCertificate},
12276 },
David Benjamina5022392017-07-10 17:40:39 -040012277 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012278 expectPeerCertificate: &rsaChainCertificate,
12279 flags: []string{
12280 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12281 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12282 "-require-any-client-certificate",
12283 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12284 },
12285 })
David Benjamin3969fdf2017-08-29 15:50:58 -040012286
12287 // Test that garbage leaf certificates are properly rejected.
12288 testCases = append(testCases, testCase{
12289 testType: clientTest,
12290 name: "GarbageCertificate-Client-" + ver.name,
12291 config: Config{
12292 MinVersion: ver.version,
12293 MaxVersion: ver.version,
12294 Certificates: []Certificate{garbageCertificate},
12295 },
12296 tls13Variant: ver.tls13Variant,
12297 shouldFail: true,
12298 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12299 expectedLocalError: "remote error: error decoding message",
12300 })
12301
12302 testCases = append(testCases, testCase{
12303 testType: serverTest,
12304 name: "GarbageCertificate-Server-" + ver.name,
12305 config: Config{
12306 MinVersion: ver.version,
12307 MaxVersion: ver.version,
12308 Certificates: []Certificate{garbageCertificate},
12309 },
12310 tls13Variant: ver.tls13Variant,
12311 flags: []string{"-require-any-client-certificate"},
12312 shouldFail: true,
12313 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12314 expectedLocalError: "remote error: error decoding message",
12315 })
David Benjamin2c516452016-11-15 10:16:54 +090012316 }
12317}
12318
David Benjaminbbaf3672016-11-17 10:53:09 +090012319func addRetainOnlySHA256ClientCertTests() {
12320 for _, ver := range tlsVersions {
12321 // Test that enabling
12322 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12323 // actually requesting a client certificate is a no-op.
12324 testCases = append(testCases, testCase{
12325 testType: serverTest,
12326 name: "RetainOnlySHA256-NoCert-" + ver.name,
12327 config: Config{
12328 MinVersion: ver.version,
12329 MaxVersion: ver.version,
12330 },
David Benjamina5022392017-07-10 17:40:39 -040012331 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012332 flags: []string{
David Benjaminf2165072017-08-23 23:01:37 -070012333 "-on-initial-retain-only-sha256-client-cert",
12334 "-on-resume-retain-only-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012335 },
12336 resumeSession: true,
12337 })
12338
12339 // Test that when retaining only a SHA-256 certificate is
12340 // enabled, the hash appears as expected.
12341 testCases = append(testCases, testCase{
12342 testType: serverTest,
12343 name: "RetainOnlySHA256-Cert-" + ver.name,
12344 config: Config{
12345 MinVersion: ver.version,
12346 MaxVersion: ver.version,
12347 Certificates: []Certificate{rsaCertificate},
12348 },
David Benjamina5022392017-07-10 17:40:39 -040012349 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012350 flags: []string{
12351 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012352 "-on-initial-retain-only-sha256-client-cert",
12353 "-on-resume-retain-only-sha256-client-cert",
12354 "-on-initial-expect-sha256-client-cert",
12355 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012356 },
12357 resumeSession: true,
12358 })
12359
12360 // Test that when the config changes from on to off, a
12361 // resumption is rejected because the server now wants the full
12362 // certificate chain.
12363 testCases = append(testCases, testCase{
12364 testType: serverTest,
12365 name: "RetainOnlySHA256-OnOff-" + ver.name,
12366 config: Config{
12367 MinVersion: ver.version,
12368 MaxVersion: ver.version,
12369 Certificates: []Certificate{rsaCertificate},
12370 },
David Benjamina5022392017-07-10 17:40:39 -040012371 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012372 flags: []string{
12373 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012374 "-on-initial-retain-only-sha256-client-cert",
12375 "-on-initial-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012376 },
12377 resumeSession: true,
12378 expectResumeRejected: true,
12379 })
12380
12381 // Test that when the config changes from off to on, a
12382 // resumption is rejected because the server now wants just the
12383 // hash.
12384 testCases = append(testCases, testCase{
12385 testType: serverTest,
12386 name: "RetainOnlySHA256-OffOn-" + ver.name,
12387 config: Config{
12388 MinVersion: ver.version,
12389 MaxVersion: ver.version,
12390 Certificates: []Certificate{rsaCertificate},
12391 },
David Benjamina5022392017-07-10 17:40:39 -040012392 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012393 flags: []string{
12394 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012395 "-on-resume-retain-only-sha256-client-cert",
12396 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012397 },
12398 resumeSession: true,
12399 expectResumeRejected: true,
12400 })
12401 }
12402}
12403
Adam Langleya4b91982016-12-12 12:05:53 -080012404func addECDSAKeyUsageTests() {
12405 p256 := elliptic.P256()
12406 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12407 if err != nil {
12408 panic(err)
12409 }
12410
12411 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12412 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12413 if err != nil {
12414 panic(err)
12415 }
12416
12417 template := x509.Certificate{
12418 SerialNumber: serialNumber,
12419 Subject: pkix.Name{
12420 Organization: []string{"Acme Co"},
12421 },
12422 NotBefore: time.Now(),
12423 NotAfter: time.Now(),
12424
12425 // An ECC certificate with only the keyAgreement key usgae may
12426 // be used with ECDH, but not ECDSA.
12427 KeyUsage: x509.KeyUsageKeyAgreement,
12428 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12429 BasicConstraintsValid: true,
12430 }
12431
12432 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12433 if err != nil {
12434 panic(err)
12435 }
12436
12437 cert := Certificate{
12438 Certificate: [][]byte{derBytes},
12439 PrivateKey: priv,
12440 }
12441
12442 for _, ver := range tlsVersions {
12443 if ver.version < VersionTLS12 {
12444 continue
12445 }
12446
12447 testCases = append(testCases, testCase{
12448 testType: clientTest,
12449 name: "ECDSAKeyUsage-" + ver.name,
12450 config: Config{
12451 MinVersion: ver.version,
12452 MaxVersion: ver.version,
12453 Certificates: []Certificate{cert},
12454 },
David Benjamina5022392017-07-10 17:40:39 -040012455 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012456 shouldFail: true,
12457 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12458 })
12459 }
12460}
12461
David Benjamin8c26d752017-03-26 15:13:51 -050012462func addExtraHandshakeTests() {
12463 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12464 // to ensure there is no transport I/O.
12465 testCases = append(testCases, testCase{
12466 testType: clientTest,
12467 name: "ExtraHandshake-Client-TLS12",
12468 config: Config{
12469 MinVersion: VersionTLS12,
12470 MaxVersion: VersionTLS12,
12471 },
12472 flags: []string{
12473 "-async",
12474 "-no-op-extra-handshake",
12475 },
12476 })
12477 testCases = append(testCases, testCase{
12478 testType: serverTest,
12479 name: "ExtraHandshake-Server-TLS12",
12480 config: Config{
12481 MinVersion: VersionTLS12,
12482 MaxVersion: VersionTLS12,
12483 },
12484 flags: []string{
12485 "-async",
12486 "-no-op-extra-handshake",
12487 },
12488 })
12489 testCases = append(testCases, testCase{
12490 testType: clientTest,
12491 name: "ExtraHandshake-Client-TLS13",
12492 config: Config{
12493 MinVersion: VersionTLS13,
12494 MaxVersion: VersionTLS13,
12495 },
12496 flags: []string{
12497 "-async",
12498 "-no-op-extra-handshake",
12499 },
12500 })
12501 testCases = append(testCases, testCase{
12502 testType: serverTest,
12503 name: "ExtraHandshake-Server-TLS13",
12504 config: Config{
12505 MinVersion: VersionTLS13,
12506 MaxVersion: VersionTLS13,
12507 },
12508 flags: []string{
12509 "-async",
12510 "-no-op-extra-handshake",
12511 },
12512 })
12513
12514 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12515 testCases = append(testCases, testCase{
12516 testType: serverTest,
12517 name: "ExtraHandshake-Server-EarlyData-TLS13",
12518 config: Config{
12519 MaxVersion: VersionTLS13,
12520 MinVersion: VersionTLS13,
12521 Bugs: ProtocolBugs{
12522 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12523 ExpectEarlyDataAccepted: true,
12524 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12525 },
12526 },
12527 messageCount: 2,
12528 resumeSession: true,
12529 flags: []string{
12530 "-async",
12531 "-enable-early-data",
12532 "-expect-accept-early-data",
12533 "-no-op-extra-handshake",
12534 },
12535 })
12536
12537 // An extra SSL_do_handshake drives the handshake to completion in False
12538 // Start. We test this by handshaking twice and asserting the False
12539 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12540 // how the test works.
12541 testCases = append(testCases, testCase{
12542 testType: clientTest,
12543 name: "ExtraHandshake-FalseStart",
12544 config: Config{
12545 MaxVersion: VersionTLS12,
12546 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12547 NextProtos: []string{"foo"},
12548 Bugs: ProtocolBugs{
12549 ExpectFalseStart: true,
12550 AlertBeforeFalseStartTest: alertAccessDenied,
12551 },
12552 },
12553 flags: []string{
12554 "-handshake-twice",
12555 "-false-start",
12556 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012557 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012558 },
12559 shimWritesFirst: true,
12560 shouldFail: true,
12561 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12562 expectedLocalError: "tls: peer did not false start: EOF",
12563 })
12564}
12565
David Benjaminb853f312017-07-14 18:40:34 -040012566// Test that omitted and empty extensions blocks are tolerated.
12567func addOmitExtensionsTests() {
12568 for _, ver := range tlsVersions {
12569 if ver.version > VersionTLS12 {
12570 continue
12571 }
12572
12573 testCases = append(testCases, testCase{
12574 testType: serverTest,
12575 name: "OmitExtensions-ClientHello-" + ver.name,
12576 config: Config{
12577 MinVersion: ver.version,
12578 MaxVersion: ver.version,
12579 SessionTicketsDisabled: true,
12580 Bugs: ProtocolBugs{
12581 OmitExtensions: true,
12582 },
12583 },
12584 })
12585
12586 testCases = append(testCases, testCase{
12587 testType: serverTest,
12588 name: "EmptyExtensions-ClientHello-" + ver.name,
12589 config: Config{
12590 MinVersion: ver.version,
12591 MaxVersion: ver.version,
12592 SessionTicketsDisabled: true,
12593 Bugs: ProtocolBugs{
12594 EmptyExtensions: true,
12595 },
12596 },
12597 })
12598
12599 testCases = append(testCases, testCase{
12600 testType: clientTest,
12601 name: "OmitExtensions-ServerHello-" + ver.name,
12602 config: Config{
12603 MinVersion: ver.version,
12604 MaxVersion: ver.version,
12605 SessionTicketsDisabled: true,
12606 Bugs: ProtocolBugs{
12607 OmitExtensions: true,
12608 // Disable all ServerHello extensions so
12609 // OmitExtensions works.
12610 NoExtendedMasterSecret: true,
12611 NoRenegotiationInfo: true,
12612 },
12613 },
12614 })
12615
12616 testCases = append(testCases, testCase{
12617 testType: clientTest,
12618 name: "EmptyExtensions-ServerHello-" + ver.name,
12619 config: Config{
12620 MinVersion: ver.version,
12621 MaxVersion: ver.version,
12622 SessionTicketsDisabled: true,
12623 Bugs: ProtocolBugs{
12624 EmptyExtensions: true,
12625 // Disable all ServerHello extensions so
12626 // EmptyExtensions works.
12627 NoExtendedMasterSecret: true,
12628 NoRenegotiationInfo: true,
12629 },
12630 },
12631 })
12632 }
12633}
12634
Adam Langley7c803a62015-06-15 15:35:05 -070012635func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012636 defer wg.Done()
12637
12638 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012639 var err error
12640
David Benjaminba28dfc2016-11-15 17:47:21 +090012641 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012642 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12643 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012644 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012645 if err != nil {
12646 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12647 }
12648 break
12649 }
12650 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012651 } else if *repeatUntilFailure {
12652 for err == nil {
12653 statusChan <- statusMsg{test: test, started: true}
12654 err = runTest(test, shimPath, -1)
12655 }
12656 } else {
12657 statusChan <- statusMsg{test: test, started: true}
12658 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012659 }
Adam Langley95c29f32014-06-20 12:00:00 -070012660 statusChan <- statusMsg{test: test, err: err}
12661 }
12662}
12663
12664type statusMsg struct {
12665 test *testCase
12666 started bool
12667 err error
12668}
12669
David Benjamin5f237bc2015-02-11 17:14:15 -050012670func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012671 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012672
David Benjamin5f237bc2015-02-11 17:14:15 -050012673 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012674 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012675 if !*pipe {
12676 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012677 var erase string
12678 for i := 0; i < lineLen; i++ {
12679 erase += "\b \b"
12680 }
12681 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012682 }
12683
Adam Langley95c29f32014-06-20 12:00:00 -070012684 if msg.started {
12685 started++
12686 } else {
12687 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012688
12689 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012690 if msg.err == errUnimplemented {
12691 if *pipe {
12692 // Print each test instead of a status line.
12693 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12694 }
12695 unimplemented++
12696 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12697 } else {
12698 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12699 failed++
12700 testOutput.addResult(msg.test.name, "FAIL")
12701 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012702 } else {
12703 if *pipe {
12704 // Print each test instead of a status line.
12705 fmt.Printf("PASSED (%s)\n", msg.test.name)
12706 }
12707 testOutput.addResult(msg.test.name, "PASS")
12708 }
Adam Langley95c29f32014-06-20 12:00:00 -070012709 }
12710
David Benjamin5f237bc2015-02-11 17:14:15 -050012711 if !*pipe {
12712 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012713 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012714 lineLen = len(line)
12715 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012716 }
Adam Langley95c29f32014-06-20 12:00:00 -070012717 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012718
12719 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012720}
12721
12722func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012723 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012724 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012725 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012726
Adam Langley7c803a62015-06-15 15:35:05 -070012727 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012728 addCipherSuiteTests()
12729 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012730 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012731 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012732 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012733 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012734 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012735 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012736 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012737 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012738 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012739 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012740 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012741 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012742 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012743 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012744 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012745 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012746 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012747 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012748 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012749 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012750 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012751 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012752 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012753 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012754 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012755 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012756 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012757 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012758 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012759 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012760 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012761 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012762 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012763
12764 var wg sync.WaitGroup
12765
Adam Langley7c803a62015-06-15 15:35:05 -070012766 statusChan := make(chan statusMsg, *numWorkers)
12767 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012768 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012769
EKRf71d7ed2016-08-06 13:25:12 -070012770 if len(*shimConfigFile) != 0 {
12771 encoded, err := ioutil.ReadFile(*shimConfigFile)
12772 if err != nil {
12773 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12774 os.Exit(1)
12775 }
12776
12777 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12778 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12779 os.Exit(1)
12780 }
12781 }
12782
David Benjamin025b3d32014-07-01 19:53:04 -040012783 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012784
Adam Langley7c803a62015-06-15 15:35:05 -070012785 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012786 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012787 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012788 }
12789
David Benjamin270f0a72016-03-17 14:41:36 -040012790 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012791 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012792 matched := true
12793 if len(*testToRun) != 0 {
12794 var err error
12795 matched, err = filepath.Match(*testToRun, testCases[i].name)
12796 if err != nil {
12797 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12798 os.Exit(1)
12799 }
12800 }
12801
EKRf71d7ed2016-08-06 13:25:12 -070012802 if !*includeDisabled {
12803 for pattern := range shimConfig.DisabledTests {
12804 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12805 if err != nil {
12806 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12807 os.Exit(1)
12808 }
12809
12810 if isDisabled {
12811 matched = false
12812 break
12813 }
12814 }
12815 }
12816
David Benjamin17e12922016-07-28 18:04:43 -040012817 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012818 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012819 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012820
12821 // Only run one test if repeating until failure.
12822 if *repeatUntilFailure {
12823 break
12824 }
Adam Langley95c29f32014-06-20 12:00:00 -070012825 }
12826 }
David Benjamin17e12922016-07-28 18:04:43 -040012827
David Benjamin270f0a72016-03-17 14:41:36 -040012828 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012829 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012830 os.Exit(1)
12831 }
Adam Langley95c29f32014-06-20 12:00:00 -070012832
12833 close(testChan)
12834 wg.Wait()
12835 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012836 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012837
12838 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012839
12840 if *jsonOutput != "" {
12841 if err := testOutput.writeTo(*jsonOutput); err != nil {
12842 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12843 }
12844 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012845
EKR842ae6c2016-07-27 09:22:05 +020012846 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12847 os.Exit(1)
12848 }
12849
12850 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012851 os.Exit(1)
12852 }
Adam Langley95c29f32014-06-20 12:00:00 -070012853}