blob: 0bd24ff582a7355d108a961d7b5944e339acf1a3 [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 {
Steven Valdez16821262017-09-08 17:03:42 -04001306 name: "TLS13Experiment2",
1307 version: VersionTLS13,
1308 excludeFlag: "-no-tls13",
1309 versionWire: tls13Experiment2Version,
1310 tls13Variant: TLS13Experiment2,
1311 },
1312 {
Steven Valdezdbe01582017-07-14 10:39:28 -04001313 name: "TLS13RecordTypeExperiment",
1314 version: VersionTLS13,
1315 excludeFlag: "-no-tls13",
1316 versionWire: tls13RecordTypeExperimentVersion,
1317 tls13Variant: TLS13RecordTypeExperiment,
1318 },
Steven Valdez520e1222017-06-13 12:45:25 -04001319}
1320
1321func allVersions(protocol protocol) []tlsVersion {
1322 if protocol == tls {
1323 return tlsVersions
1324 }
1325
1326 var ret []tlsVersion
1327 for _, vers := range tlsVersions {
1328 if vers.hasDTLS {
1329 ret = append(ret, vers)
1330 }
1331 }
1332 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001333}
1334
David Benjaminaa012042016-12-10 13:33:05 -05001335type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001336 name string
1337 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001338}
1339
1340var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001341 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001342 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001343 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001344 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001345 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001346 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001347 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001348 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1349 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001350 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1351 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001352 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001353 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001354 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001355 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001356 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001357 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001358 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001359 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001360 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001361 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001362 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1363 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001364 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1365 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001366 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001367 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1368 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1369 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001370 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001371}
1372
David Benjamin8b8c0062014-11-23 02:47:52 -05001373func hasComponent(suiteName, component string) bool {
1374 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1375}
1376
David Benjaminf7768e42014-08-31 02:06:47 -04001377func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001378 return hasComponent(suiteName, "GCM") ||
1379 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001380 hasComponent(suiteName, "SHA384") ||
1381 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001382}
1383
Nick Harper1fd39d82016-06-14 18:14:35 -07001384func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001385 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001386}
1387
David Benjamin8b8c0062014-11-23 02:47:52 -05001388func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001389 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001390}
1391
Adam Langleya7997f12015-05-14 17:38:50 -07001392func bigFromHex(hex string) *big.Int {
1393 ret, ok := new(big.Int).SetString(hex, 16)
1394 if !ok {
1395 panic("failed to parse hex number 0x" + hex)
1396 }
1397 return ret
1398}
1399
Adam Langley7c803a62015-06-15 15:35:05 -07001400func addBasicTests() {
1401 basicTests := []testCase{
1402 {
Adam Langley7c803a62015-06-15 15:35:05 -07001403 name: "NoFallbackSCSV",
1404 config: Config{
1405 Bugs: ProtocolBugs{
1406 FailIfNotFallbackSCSV: true,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedLocalError: "no fallback SCSV found",
1411 },
1412 {
1413 name: "SendFallbackSCSV",
1414 config: Config{
1415 Bugs: ProtocolBugs{
1416 FailIfNotFallbackSCSV: true,
1417 },
1418 },
1419 flags: []string{"-fallback-scsv"},
1420 },
1421 {
1422 name: "ClientCertificateTypes",
1423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001424 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001425 ClientAuth: RequestClientCert,
1426 ClientCertificateTypes: []byte{
1427 CertTypeDSSSign,
1428 CertTypeRSASign,
1429 CertTypeECDSASign,
1430 },
1431 },
1432 flags: []string{
1433 "-expect-certificate-types",
1434 base64.StdEncoding.EncodeToString([]byte{
1435 CertTypeDSSSign,
1436 CertTypeRSASign,
1437 CertTypeECDSASign,
1438 }),
1439 },
1440 },
1441 {
Adam Langley7c803a62015-06-15 15:35:05 -07001442 name: "UnauthenticatedECDH",
1443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001444 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001445 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1446 Bugs: ProtocolBugs{
1447 UnauthenticatedECDH: true,
1448 },
1449 },
1450 shouldFail: true,
1451 expectedError: ":UNEXPECTED_MESSAGE:",
1452 },
1453 {
1454 name: "SkipCertificateStatus",
1455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001456 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001457 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1458 Bugs: ProtocolBugs{
1459 SkipCertificateStatus: true,
1460 },
1461 },
1462 flags: []string{
1463 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001464 // This test involves an optional message. Test the message callback
1465 // trace to ensure we do not miss or double-report any.
1466 "-expect-msg-callback",
1467 `write hs 1
1468read hs 2
1469read hs 11
1470read hs 12
1471read hs 14
1472write hs 16
1473write ccs
1474write hs 20
1475read hs 4
1476read ccs
1477read hs 20
1478read alert 1 0
1479`,
1480 },
1481 },
1482 {
1483 protocol: dtls,
1484 name: "SkipCertificateStatus-DTLS",
1485 config: Config{
1486 MaxVersion: VersionTLS12,
1487 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1488 Bugs: ProtocolBugs{
1489 SkipCertificateStatus: true,
1490 },
1491 },
1492 flags: []string{
1493 "-enable-ocsp-stapling",
1494 // This test involves an optional message. Test the message callback
1495 // trace to ensure we do not miss or double-report any.
1496 "-expect-msg-callback",
1497 `write hs 1
1498read hs 3
1499write hs 1
1500read hs 2
1501read hs 11
1502read hs 12
1503read hs 14
1504write hs 16
1505write ccs
1506write hs 20
1507read hs 4
1508read ccs
1509read hs 20
1510read alert 1 0
1511`,
Adam Langley7c803a62015-06-15 15:35:05 -07001512 },
1513 },
1514 {
1515 name: "SkipServerKeyExchange",
1516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001517 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001518 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1519 Bugs: ProtocolBugs{
1520 SkipServerKeyExchange: true,
1521 },
1522 },
1523 shouldFail: true,
1524 expectedError: ":UNEXPECTED_MESSAGE:",
1525 },
1526 {
Adam Langley7c803a62015-06-15 15:35:05 -07001527 testType: serverTest,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001528 name: "ServerSkipCertificateVerify",
1529 config: Config{
1530 MaxVersion: VersionTLS12,
1531 Certificates: []Certificate{rsaChainCertificate},
1532 Bugs: ProtocolBugs{
1533 SkipCertificateVerify: true,
1534 },
1535 },
1536 expectPeerCertificate: &rsaChainCertificate,
1537 flags: []string{
1538 "-require-any-client-certificate",
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_RECORD:",
1542 expectedLocalError: "remote error: unexpected message",
1543 },
1544 {
1545 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001546 name: "Alert",
1547 config: Config{
1548 Bugs: ProtocolBugs{
1549 SendSpuriousAlert: alertRecordOverflow,
1550 },
1551 },
1552 shouldFail: true,
1553 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1554 },
1555 {
1556 protocol: dtls,
1557 testType: serverTest,
1558 name: "Alert-DTLS",
1559 config: Config{
1560 Bugs: ProtocolBugs{
1561 SendSpuriousAlert: alertRecordOverflow,
1562 },
1563 },
1564 shouldFail: true,
1565 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1566 },
1567 {
1568 testType: serverTest,
1569 name: "FragmentAlert",
1570 config: Config{
1571 Bugs: ProtocolBugs{
1572 FragmentAlert: true,
1573 SendSpuriousAlert: alertRecordOverflow,
1574 },
1575 },
1576 shouldFail: true,
1577 expectedError: ":BAD_ALERT:",
1578 },
1579 {
1580 protocol: dtls,
1581 testType: serverTest,
1582 name: "FragmentAlert-DTLS",
1583 config: Config{
1584 Bugs: ProtocolBugs{
1585 FragmentAlert: true,
1586 SendSpuriousAlert: alertRecordOverflow,
1587 },
1588 },
1589 shouldFail: true,
1590 expectedError: ":BAD_ALERT:",
1591 },
1592 {
1593 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001594 name: "DoubleAlert",
1595 config: Config{
1596 Bugs: ProtocolBugs{
1597 DoubleAlert: true,
1598 SendSpuriousAlert: alertRecordOverflow,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":BAD_ALERT:",
1603 },
1604 {
1605 protocol: dtls,
1606 testType: serverTest,
1607 name: "DoubleAlert-DTLS",
1608 config: Config{
1609 Bugs: ProtocolBugs{
1610 DoubleAlert: true,
1611 SendSpuriousAlert: alertRecordOverflow,
1612 },
1613 },
1614 shouldFail: true,
1615 expectedError: ":BAD_ALERT:",
1616 },
1617 {
Adam Langley7c803a62015-06-15 15:35:05 -07001618 name: "SkipNewSessionTicket",
1619 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001620 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001621 Bugs: ProtocolBugs{
1622 SkipNewSessionTicket: true,
1623 },
1624 },
1625 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001626 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001627 },
1628 {
1629 testType: serverTest,
1630 name: "FallbackSCSV",
1631 config: Config{
1632 MaxVersion: VersionTLS11,
1633 Bugs: ProtocolBugs{
1634 SendFallbackSCSV: true,
1635 },
1636 },
David Benjamin56cadc32016-12-16 19:54:11 -05001637 shouldFail: true,
1638 expectedError: ":INAPPROPRIATE_FALLBACK:",
1639 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001640 },
1641 {
1642 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001643 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001644 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001645 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001646 Bugs: ProtocolBugs{
1647 SendFallbackSCSV: true,
1648 },
1649 },
1650 },
1651 {
1652 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001653 name: "FallbackSCSV-VersionMatch-TLS12",
1654 config: Config{
1655 MaxVersion: VersionTLS12,
1656 Bugs: ProtocolBugs{
1657 SendFallbackSCSV: true,
1658 },
1659 },
1660 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1661 },
1662 {
1663 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001664 name: "FragmentedClientVersion",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 MaxHandshakeRecordLength: 1,
1668 FragmentClientVersion: true,
1669 },
1670 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001671 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001672 },
1673 {
Adam Langley7c803a62015-06-15 15:35:05 -07001674 testType: serverTest,
1675 name: "HttpGET",
1676 sendPrefix: "GET / HTTP/1.0\n",
1677 shouldFail: true,
1678 expectedError: ":HTTP_REQUEST:",
1679 },
1680 {
1681 testType: serverTest,
1682 name: "HttpPOST",
1683 sendPrefix: "POST / HTTP/1.0\n",
1684 shouldFail: true,
1685 expectedError: ":HTTP_REQUEST:",
1686 },
1687 {
1688 testType: serverTest,
1689 name: "HttpHEAD",
1690 sendPrefix: "HEAD / HTTP/1.0\n",
1691 shouldFail: true,
1692 expectedError: ":HTTP_REQUEST:",
1693 },
1694 {
1695 testType: serverTest,
1696 name: "HttpPUT",
1697 sendPrefix: "PUT / HTTP/1.0\n",
1698 shouldFail: true,
1699 expectedError: ":HTTP_REQUEST:",
1700 },
1701 {
1702 testType: serverTest,
1703 name: "HttpCONNECT",
1704 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1705 shouldFail: true,
1706 expectedError: ":HTTPS_PROXY_REQUEST:",
1707 },
1708 {
1709 testType: serverTest,
1710 name: "Garbage",
1711 sendPrefix: "blah",
1712 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001713 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001714 },
1715 {
Adam Langley7c803a62015-06-15 15:35:05 -07001716 name: "RSAEphemeralKey",
1717 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001718 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001719 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1720 Bugs: ProtocolBugs{
1721 RSAEphemeralKey: true,
1722 },
1723 },
1724 shouldFail: true,
1725 expectedError: ":UNEXPECTED_MESSAGE:",
1726 },
1727 {
1728 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001729 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001730 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001731 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001732 },
1733 {
1734 protocol: dtls,
1735 name: "DisableEverything-DTLS",
1736 flags: []string{"-no-tls12", "-no-tls1"},
1737 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001738 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001739 },
1740 {
Adam Langley7c803a62015-06-15 15:35:05 -07001741 protocol: dtls,
1742 testType: serverTest,
1743 name: "MTU",
1744 config: Config{
1745 Bugs: ProtocolBugs{
1746 MaxPacketLength: 256,
1747 },
1748 },
1749 flags: []string{"-mtu", "256"},
1750 },
1751 {
1752 protocol: dtls,
1753 testType: serverTest,
1754 name: "MTUExceeded",
1755 config: Config{
1756 Bugs: ProtocolBugs{
1757 MaxPacketLength: 255,
1758 },
1759 },
1760 flags: []string{"-mtu", "256"},
1761 shouldFail: true,
1762 expectedLocalError: "dtls: exceeded maximum packet length",
1763 },
1764 {
Adam Langley7c803a62015-06-15 15:35:05 -07001765 name: "EmptyCertificateList",
1766 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001767 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001768 Bugs: ProtocolBugs{
1769 EmptyCertificateList: true,
1770 },
1771 },
1772 shouldFail: true,
1773 expectedError: ":DECODE_ERROR:",
1774 },
1775 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001776 name: "EmptyCertificateList-TLS13",
1777 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001778 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001779 Bugs: ProtocolBugs{
1780 EmptyCertificateList: true,
1781 },
1782 },
1783 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001784 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001785 },
1786 {
Adam Langley7c803a62015-06-15 15:35:05 -07001787 name: "TLSFatalBadPackets",
1788 damageFirstWrite: true,
1789 shouldFail: true,
1790 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1791 },
1792 {
1793 protocol: dtls,
1794 name: "DTLSIgnoreBadPackets",
1795 damageFirstWrite: true,
1796 },
1797 {
1798 protocol: dtls,
1799 name: "DTLSIgnoreBadPackets-Async",
1800 damageFirstWrite: true,
1801 flags: []string{"-async"},
1802 },
1803 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001804 name: "AppDataBeforeHandshake",
1805 config: Config{
1806 Bugs: ProtocolBugs{
1807 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1808 },
1809 },
1810 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001811 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001812 },
1813 {
1814 name: "AppDataBeforeHandshake-Empty",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 AppDataBeforeHandshake: []byte{},
1818 },
1819 },
1820 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001821 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001822 },
1823 {
1824 protocol: dtls,
1825 name: "AppDataBeforeHandshake-DTLS",
1826 config: Config{
1827 Bugs: ProtocolBugs{
1828 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1829 },
1830 },
1831 shouldFail: true,
1832 expectedError: ":UNEXPECTED_RECORD:",
1833 },
1834 {
1835 protocol: dtls,
1836 name: "AppDataBeforeHandshake-DTLS-Empty",
1837 config: Config{
1838 Bugs: ProtocolBugs{
1839 AppDataBeforeHandshake: []byte{},
1840 },
1841 },
1842 shouldFail: true,
1843 expectedError: ":UNEXPECTED_RECORD:",
1844 },
1845 {
Adam Langley7c803a62015-06-15 15:35:05 -07001846 name: "AppDataAfterChangeCipherSpec",
1847 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001848 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001849 Bugs: ProtocolBugs{
1850 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1851 },
1852 },
1853 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001854 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001855 },
1856 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001857 name: "AppDataAfterChangeCipherSpec-Empty",
1858 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001859 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001860 Bugs: ProtocolBugs{
1861 AppDataAfterChangeCipherSpec: []byte{},
1862 },
1863 },
1864 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001865 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001866 },
1867 {
Adam Langley7c803a62015-06-15 15:35:05 -07001868 protocol: dtls,
1869 name: "AppDataAfterChangeCipherSpec-DTLS",
1870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001871 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001872 Bugs: ProtocolBugs{
1873 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1874 },
1875 },
1876 // BoringSSL's DTLS implementation will drop the out-of-order
1877 // application data.
1878 },
1879 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001880 protocol: dtls,
1881 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001883 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001884 Bugs: ProtocolBugs{
1885 AppDataAfterChangeCipherSpec: []byte{},
1886 },
1887 },
1888 // BoringSSL's DTLS implementation will drop the out-of-order
1889 // application data.
1890 },
1891 {
Adam Langley7c803a62015-06-15 15:35:05 -07001892 name: "AlertAfterChangeCipherSpec",
1893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001894 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001895 Bugs: ProtocolBugs{
1896 AlertAfterChangeCipherSpec: alertRecordOverflow,
1897 },
1898 },
1899 shouldFail: true,
1900 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1901 },
1902 {
1903 protocol: dtls,
1904 name: "AlertAfterChangeCipherSpec-DTLS",
1905 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001906 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001907 Bugs: ProtocolBugs{
1908 AlertAfterChangeCipherSpec: alertRecordOverflow,
1909 },
1910 },
1911 shouldFail: true,
1912 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1913 },
1914 {
1915 protocol: dtls,
1916 name: "ReorderHandshakeFragments-Small-DTLS",
1917 config: Config{
1918 Bugs: ProtocolBugs{
1919 ReorderHandshakeFragments: true,
1920 // Small enough that every handshake message is
1921 // fragmented.
1922 MaxHandshakeRecordLength: 2,
1923 },
1924 },
1925 },
1926 {
1927 protocol: dtls,
1928 name: "ReorderHandshakeFragments-Large-DTLS",
1929 config: Config{
1930 Bugs: ProtocolBugs{
1931 ReorderHandshakeFragments: true,
1932 // Large enough that no handshake message is
1933 // fragmented.
1934 MaxHandshakeRecordLength: 2048,
1935 },
1936 },
1937 },
1938 {
1939 protocol: dtls,
1940 name: "MixCompleteMessageWithFragments-DTLS",
1941 config: Config{
1942 Bugs: ProtocolBugs{
1943 ReorderHandshakeFragments: true,
1944 MixCompleteMessageWithFragments: true,
1945 MaxHandshakeRecordLength: 2,
1946 },
1947 },
1948 },
1949 {
1950 name: "SendInvalidRecordType",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 SendInvalidRecordType: true,
1954 },
1955 },
1956 shouldFail: true,
1957 expectedError: ":UNEXPECTED_RECORD:",
1958 },
1959 {
1960 protocol: dtls,
1961 name: "SendInvalidRecordType-DTLS",
1962 config: Config{
1963 Bugs: ProtocolBugs{
1964 SendInvalidRecordType: true,
1965 },
1966 },
1967 shouldFail: true,
1968 expectedError: ":UNEXPECTED_RECORD:",
1969 },
1970 {
1971 name: "FalseStart-SkipServerSecondLeg",
1972 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001973 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001974 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1975 NextProtos: []string{"foo"},
1976 Bugs: ProtocolBugs{
1977 SkipNewSessionTicket: true,
1978 SkipChangeCipherSpec: true,
1979 SkipFinished: true,
1980 ExpectFalseStart: true,
1981 },
1982 },
1983 flags: []string{
1984 "-false-start",
1985 "-handshake-never-done",
1986 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001987 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001988 },
1989 shimWritesFirst: true,
1990 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001991 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001992 },
1993 {
1994 name: "FalseStart-SkipServerSecondLeg-Implicit",
1995 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001996 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001997 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1998 NextProtos: []string{"foo"},
1999 Bugs: ProtocolBugs{
2000 SkipNewSessionTicket: true,
2001 SkipChangeCipherSpec: true,
2002 SkipFinished: true,
2003 },
2004 },
2005 flags: []string{
2006 "-implicit-handshake",
2007 "-false-start",
2008 "-handshake-never-done",
2009 "-advertise-alpn", "\x03foo",
2010 },
2011 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04002012 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002013 },
2014 {
2015 testType: serverTest,
2016 name: "FailEarlyCallback",
2017 flags: []string{"-fail-early-callback"},
2018 shouldFail: true,
2019 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002020 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002021 },
2022 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002023 name: "FailCertCallback-Client-TLS12",
2024 config: Config{
2025 MaxVersion: VersionTLS12,
2026 ClientAuth: RequestClientCert,
2027 },
2028 flags: []string{"-fail-cert-callback"},
2029 shouldFail: true,
2030 expectedError: ":CERT_CB_ERROR:",
2031 expectedLocalError: "remote error: internal error",
2032 },
2033 {
2034 testType: serverTest,
2035 name: "FailCertCallback-Server-TLS12",
2036 config: Config{
2037 MaxVersion: VersionTLS12,
2038 },
2039 flags: []string{"-fail-cert-callback"},
2040 shouldFail: true,
2041 expectedError: ":CERT_CB_ERROR:",
2042 expectedLocalError: "remote error: internal error",
2043 },
2044 {
2045 name: "FailCertCallback-Client-TLS13",
2046 config: Config{
2047 MaxVersion: VersionTLS13,
2048 ClientAuth: RequestClientCert,
2049 },
2050 flags: []string{"-fail-cert-callback"},
2051 shouldFail: true,
2052 expectedError: ":CERT_CB_ERROR:",
2053 expectedLocalError: "remote error: internal error",
2054 },
2055 {
2056 testType: serverTest,
2057 name: "FailCertCallback-Server-TLS13",
2058 config: Config{
2059 MaxVersion: VersionTLS13,
2060 },
2061 flags: []string{"-fail-cert-callback"},
2062 shouldFail: true,
2063 expectedError: ":CERT_CB_ERROR:",
2064 expectedLocalError: "remote error: internal error",
2065 },
2066 {
Adam Langley7c803a62015-06-15 15:35:05 -07002067 protocol: dtls,
2068 name: "FragmentMessageTypeMismatch-DTLS",
2069 config: Config{
2070 Bugs: ProtocolBugs{
2071 MaxHandshakeRecordLength: 2,
2072 FragmentMessageTypeMismatch: true,
2073 },
2074 },
2075 shouldFail: true,
2076 expectedError: ":FRAGMENT_MISMATCH:",
2077 },
2078 {
2079 protocol: dtls,
2080 name: "FragmentMessageLengthMismatch-DTLS",
2081 config: Config{
2082 Bugs: ProtocolBugs{
2083 MaxHandshakeRecordLength: 2,
2084 FragmentMessageLengthMismatch: true,
2085 },
2086 },
2087 shouldFail: true,
2088 expectedError: ":FRAGMENT_MISMATCH:",
2089 },
2090 {
2091 protocol: dtls,
2092 name: "SplitFragments-Header-DTLS",
2093 config: Config{
2094 Bugs: ProtocolBugs{
2095 SplitFragments: 2,
2096 },
2097 },
2098 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002099 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002100 },
2101 {
2102 protocol: dtls,
2103 name: "SplitFragments-Boundary-DTLS",
2104 config: Config{
2105 Bugs: ProtocolBugs{
2106 SplitFragments: dtlsRecordHeaderLen,
2107 },
2108 },
2109 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002110 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002111 },
2112 {
2113 protocol: dtls,
2114 name: "SplitFragments-Body-DTLS",
2115 config: Config{
2116 Bugs: ProtocolBugs{
2117 SplitFragments: dtlsRecordHeaderLen + 1,
2118 },
2119 },
2120 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002121 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002122 },
2123 {
2124 protocol: dtls,
2125 name: "SendEmptyFragments-DTLS",
2126 config: Config{
2127 Bugs: ProtocolBugs{
2128 SendEmptyFragments: true,
2129 },
2130 },
2131 },
2132 {
David Benjamine51fb0f2017-09-07 11:51:46 -04002133 testType: serverTest,
2134 protocol: dtls,
2135 name: "SendEmptyFragments-Padded-DTLS",
2136 config: Config{
2137 Bugs: ProtocolBugs{
2138 // Test empty fragments for a message with a
2139 // nice power-of-two length.
2140 PadClientHello: 64,
2141 SendEmptyFragments: true,
2142 },
2143 },
2144 },
2145 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002146 name: "BadFinished-Client",
2147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002148 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002149 Bugs: ProtocolBugs{
2150 BadFinished: true,
2151 },
2152 },
2153 shouldFail: true,
2154 expectedError: ":DIGEST_CHECK_FAILED:",
2155 },
2156 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002157 name: "BadFinished-Client-TLS13",
2158 config: Config{
2159 MaxVersion: VersionTLS13,
2160 Bugs: ProtocolBugs{
2161 BadFinished: true,
2162 },
2163 },
2164 shouldFail: true,
2165 expectedError: ":DIGEST_CHECK_FAILED:",
2166 },
2167 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002168 testType: serverTest,
2169 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002171 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002172 Bugs: ProtocolBugs{
2173 BadFinished: true,
2174 },
2175 },
2176 shouldFail: true,
2177 expectedError: ":DIGEST_CHECK_FAILED:",
2178 },
2179 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002180 testType: serverTest,
2181 name: "BadFinished-Server-TLS13",
2182 config: Config{
2183 MaxVersion: VersionTLS13,
2184 Bugs: ProtocolBugs{
2185 BadFinished: true,
2186 },
2187 },
2188 shouldFail: true,
2189 expectedError: ":DIGEST_CHECK_FAILED:",
2190 },
2191 {
Adam Langley7c803a62015-06-15 15:35:05 -07002192 name: "FalseStart-BadFinished",
2193 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002194 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002195 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2196 NextProtos: []string{"foo"},
2197 Bugs: ProtocolBugs{
2198 BadFinished: true,
2199 ExpectFalseStart: true,
2200 },
2201 },
2202 flags: []string{
2203 "-false-start",
2204 "-handshake-never-done",
2205 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002206 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002207 },
2208 shimWritesFirst: true,
2209 shouldFail: true,
2210 expectedError: ":DIGEST_CHECK_FAILED:",
2211 },
2212 {
2213 name: "NoFalseStart-NoALPN",
2214 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002215 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002216 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2217 Bugs: ProtocolBugs{
2218 ExpectFalseStart: true,
2219 AlertBeforeFalseStartTest: alertAccessDenied,
2220 },
2221 },
2222 flags: []string{
2223 "-false-start",
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-NoAEAD",
2232 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002233 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002234 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
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 {
2251 name: "NoFalseStart-RSA",
2252 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002253 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002254 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2255 NextProtos: []string{"foo"},
2256 Bugs: ProtocolBugs{
2257 ExpectFalseStart: true,
2258 AlertBeforeFalseStartTest: alertAccessDenied,
2259 },
2260 },
2261 flags: []string{
2262 "-false-start",
2263 "-advertise-alpn", "\x03foo",
2264 },
2265 shimWritesFirst: true,
2266 shouldFail: true,
2267 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2268 expectedLocalError: "tls: peer did not false start: EOF",
2269 },
2270 {
Adam Langley7c803a62015-06-15 15:35:05 -07002271 protocol: dtls,
2272 name: "SendSplitAlert-Sync",
2273 config: Config{
2274 Bugs: ProtocolBugs{
2275 SendSplitAlert: true,
2276 },
2277 },
2278 },
2279 {
2280 protocol: dtls,
2281 name: "SendSplitAlert-Async",
2282 config: Config{
2283 Bugs: ProtocolBugs{
2284 SendSplitAlert: true,
2285 },
2286 },
2287 flags: []string{"-async"},
2288 },
2289 {
2290 protocol: dtls,
2291 name: "PackDTLSHandshake",
2292 config: Config{
2293 Bugs: ProtocolBugs{
2294 MaxHandshakeRecordLength: 2,
2295 PackHandshakeFragments: 20,
2296 PackHandshakeRecords: 200,
2297 },
2298 },
2299 },
2300 {
Adam Langley7c803a62015-06-15 15:35:05 -07002301 name: "SendEmptyRecords-Pass",
2302 sendEmptyRecords: 32,
2303 },
2304 {
2305 name: "SendEmptyRecords",
2306 sendEmptyRecords: 33,
2307 shouldFail: true,
2308 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2309 },
2310 {
2311 name: "SendEmptyRecords-Async",
2312 sendEmptyRecords: 33,
2313 flags: []string{"-async"},
2314 shouldFail: true,
2315 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2316 },
2317 {
David Benjamine8e84b92016-08-03 15:39:47 -04002318 name: "SendWarningAlerts-Pass",
2319 config: Config{
2320 MaxVersion: VersionTLS12,
2321 },
Adam Langley7c803a62015-06-15 15:35:05 -07002322 sendWarningAlerts: 4,
2323 },
2324 {
David Benjamine8e84b92016-08-03 15:39:47 -04002325 protocol: dtls,
2326 name: "SendWarningAlerts-DTLS-Pass",
2327 config: Config{
2328 MaxVersion: VersionTLS12,
2329 },
Adam Langley7c803a62015-06-15 15:35:05 -07002330 sendWarningAlerts: 4,
2331 },
2332 {
David Benjamine8e84b92016-08-03 15:39:47 -04002333 name: "SendWarningAlerts-TLS13",
2334 config: Config{
2335 MaxVersion: VersionTLS13,
2336 },
2337 sendWarningAlerts: 4,
2338 shouldFail: true,
2339 expectedError: ":BAD_ALERT:",
2340 expectedLocalError: "remote error: error decoding message",
2341 },
2342 {
2343 name: "SendWarningAlerts",
2344 config: Config{
2345 MaxVersion: VersionTLS12,
2346 },
Adam Langley7c803a62015-06-15 15:35:05 -07002347 sendWarningAlerts: 5,
2348 shouldFail: true,
2349 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2350 },
2351 {
David Benjamine8e84b92016-08-03 15:39:47 -04002352 name: "SendWarningAlerts-Async",
2353 config: Config{
2354 MaxVersion: VersionTLS12,
2355 },
Adam Langley7c803a62015-06-15 15:35:05 -07002356 sendWarningAlerts: 5,
2357 flags: []string{"-async"},
2358 shouldFail: true,
2359 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2360 },
David Benjaminba4594a2015-06-18 18:36:15 -04002361 {
David Benjamin24e58862017-06-14 18:45:29 -04002362 name: "SendBogusAlertType",
2363 sendBogusAlertType: true,
2364 shouldFail: true,
2365 expectedError: ":UNKNOWN_ALERT_TYPE:",
2366 expectedLocalError: "remote error: illegal parameter",
2367 },
2368 {
2369 protocol: dtls,
2370 name: "SendBogusAlertType-DTLS",
2371 sendBogusAlertType: true,
2372 shouldFail: true,
2373 expectedError: ":UNKNOWN_ALERT_TYPE:",
2374 expectedLocalError: "remote error: illegal parameter",
2375 },
2376 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002377 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002378 config: Config{
2379 MaxVersion: VersionTLS13,
2380 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002381 sendKeyUpdates: 33,
2382 keyUpdateRequest: keyUpdateNotRequested,
2383 shouldFail: true,
2384 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002385 },
2386 {
David Benjaminba4594a2015-06-18 18:36:15 -04002387 name: "EmptySessionID",
2388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002389 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002390 SessionTicketsDisabled: true,
2391 },
2392 noSessionCache: true,
2393 flags: []string{"-expect-no-session"},
2394 },
David Benjamin30789da2015-08-29 22:56:45 -04002395 {
2396 name: "Unclean-Shutdown",
2397 config: Config{
2398 Bugs: ProtocolBugs{
2399 NoCloseNotify: true,
2400 ExpectCloseNotify: true,
2401 },
2402 },
2403 shimShutsDown: true,
2404 flags: []string{"-check-close-notify"},
2405 shouldFail: true,
2406 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2407 },
2408 {
2409 name: "Unclean-Shutdown-Ignored",
2410 config: Config{
2411 Bugs: ProtocolBugs{
2412 NoCloseNotify: true,
2413 },
2414 },
2415 shimShutsDown: true,
2416 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002417 {
David Benjaminfa214e42016-05-10 17:03:10 -04002418 name: "Unclean-Shutdown-Alert",
2419 config: Config{
2420 Bugs: ProtocolBugs{
2421 SendAlertOnShutdown: alertDecompressionFailure,
2422 ExpectCloseNotify: true,
2423 },
2424 },
2425 shimShutsDown: true,
2426 flags: []string{"-check-close-notify"},
2427 shouldFail: true,
2428 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2429 },
2430 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002431 name: "LargePlaintext",
2432 config: Config{
2433 Bugs: ProtocolBugs{
2434 SendLargeRecords: true,
2435 },
2436 },
2437 messageLen: maxPlaintext + 1,
2438 shouldFail: true,
2439 expectedError: ":DATA_LENGTH_TOO_LONG:",
2440 },
2441 {
2442 protocol: dtls,
2443 name: "LargePlaintext-DTLS",
2444 config: Config{
2445 Bugs: ProtocolBugs{
2446 SendLargeRecords: true,
2447 },
2448 },
2449 messageLen: maxPlaintext + 1,
2450 shouldFail: true,
2451 expectedError: ":DATA_LENGTH_TOO_LONG:",
2452 },
2453 {
2454 name: "LargeCiphertext",
2455 config: Config{
2456 Bugs: ProtocolBugs{
2457 SendLargeRecords: true,
2458 },
2459 },
2460 messageLen: maxPlaintext * 2,
2461 shouldFail: true,
2462 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2463 },
2464 {
2465 protocol: dtls,
2466 name: "LargeCiphertext-DTLS",
2467 config: Config{
2468 Bugs: ProtocolBugs{
2469 SendLargeRecords: true,
2470 },
2471 },
2472 messageLen: maxPlaintext * 2,
2473 // Unlike the other four cases, DTLS drops records which
2474 // are invalid before authentication, so the connection
2475 // does not fail.
2476 expectMessageDropped: true,
2477 },
David Benjamindd6fed92015-10-23 17:41:12 -04002478 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002479 name: "BadHelloRequest-1",
2480 renegotiate: 1,
2481 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002482 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002483 Bugs: ProtocolBugs{
2484 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2485 },
2486 },
2487 flags: []string{
2488 "-renegotiate-freely",
2489 "-expect-total-renegotiations", "1",
2490 },
2491 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002492 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002493 },
2494 {
2495 name: "BadHelloRequest-2",
2496 renegotiate: 1,
2497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002498 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002499 Bugs: ProtocolBugs{
2500 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2501 },
2502 },
2503 flags: []string{
2504 "-renegotiate-freely",
2505 "-expect-total-renegotiations", "1",
2506 },
2507 shouldFail: true,
2508 expectedError: ":BAD_HELLO_REQUEST:",
2509 },
David Benjaminef1b0092015-11-21 14:05:44 -05002510 {
2511 testType: serverTest,
2512 name: "SupportTicketsWithSessionID",
2513 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002514 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002515 SessionTicketsDisabled: true,
2516 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002517 resumeConfig: &Config{
2518 MaxVersion: VersionTLS12,
2519 },
David Benjaminef1b0092015-11-21 14:05:44 -05002520 resumeSession: true,
2521 },
David Benjamin02edcd02016-07-27 17:40:37 -04002522 {
2523 protocol: dtls,
2524 name: "DTLS-SendExtraFinished",
2525 config: Config{
2526 Bugs: ProtocolBugs{
2527 SendExtraFinished: true,
2528 },
2529 },
2530 shouldFail: true,
2531 expectedError: ":UNEXPECTED_RECORD:",
2532 },
2533 {
2534 protocol: dtls,
2535 name: "DTLS-SendExtraFinished-Reordered",
2536 config: Config{
2537 Bugs: ProtocolBugs{
2538 MaxHandshakeRecordLength: 2,
2539 ReorderHandshakeFragments: true,
2540 SendExtraFinished: true,
2541 },
2542 },
2543 shouldFail: true,
2544 expectedError: ":UNEXPECTED_RECORD:",
2545 },
David Benjamine97fb482016-07-29 09:23:07 -04002546 {
2547 testType: serverTest,
2548 name: "V2ClientHello-EmptyRecordPrefix",
2549 config: Config{
2550 // Choose a cipher suite that does not involve
2551 // elliptic curves, so no extensions are
2552 // involved.
2553 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002554 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002555 Bugs: ProtocolBugs{
2556 SendV2ClientHello: true,
2557 },
2558 },
2559 sendPrefix: string([]byte{
2560 byte(recordTypeHandshake),
2561 3, 1, // version
2562 0, 0, // length
2563 }),
2564 // A no-op empty record may not be sent before V2ClientHello.
2565 shouldFail: true,
2566 expectedError: ":WRONG_VERSION_NUMBER:",
2567 },
2568 {
2569 testType: serverTest,
2570 name: "V2ClientHello-WarningAlertPrefix",
2571 config: Config{
2572 // Choose a cipher suite that does not involve
2573 // elliptic curves, so no extensions are
2574 // involved.
2575 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002576 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002577 Bugs: ProtocolBugs{
2578 SendV2ClientHello: true,
2579 },
2580 },
2581 sendPrefix: string([]byte{
2582 byte(recordTypeAlert),
2583 3, 1, // version
2584 0, 2, // length
2585 alertLevelWarning, byte(alertDecompressionFailure),
2586 }),
2587 // A no-op warning alert may not be sent before V2ClientHello.
2588 shouldFail: true,
2589 expectedError: ":WRONG_VERSION_NUMBER:",
2590 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002591 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002592 name: "KeyUpdate-Client",
2593 config: Config{
2594 MaxVersion: VersionTLS13,
2595 },
2596 sendKeyUpdates: 1,
2597 keyUpdateRequest: keyUpdateNotRequested,
2598 },
2599 {
2600 testType: serverTest,
2601 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002602 config: Config{
2603 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002604 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002605 sendKeyUpdates: 1,
2606 keyUpdateRequest: keyUpdateNotRequested,
2607 },
2608 {
2609 name: "KeyUpdate-InvalidRequestMode",
2610 config: Config{
2611 MaxVersion: VersionTLS13,
2612 },
2613 sendKeyUpdates: 1,
2614 keyUpdateRequest: 42,
2615 shouldFail: true,
2616 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002617 },
David Benjaminabe94e32016-09-04 14:18:58 -04002618 {
David Benjaminbbba9392017-04-06 12:54:12 -04002619 // Test that KeyUpdates are acknowledged properly.
2620 name: "KeyUpdate-RequestACK",
2621 config: Config{
2622 MaxVersion: VersionTLS13,
2623 Bugs: ProtocolBugs{
2624 RejectUnsolicitedKeyUpdate: true,
2625 },
2626 },
2627 // Test the shim receiving many KeyUpdates in a row.
2628 sendKeyUpdates: 5,
2629 messageCount: 5,
2630 keyUpdateRequest: keyUpdateRequested,
2631 },
2632 {
2633 // Test that KeyUpdates are acknowledged properly if the
2634 // peer's KeyUpdate is discovered while a write is
2635 // pending.
2636 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2637 config: Config{
2638 MaxVersion: VersionTLS13,
2639 Bugs: ProtocolBugs{
2640 RejectUnsolicitedKeyUpdate: true,
2641 },
2642 },
2643 // Test the shim receiving many KeyUpdates in a row.
2644 sendKeyUpdates: 5,
2645 messageCount: 5,
2646 keyUpdateRequest: keyUpdateRequested,
2647 readWithUnfinishedWrite: true,
2648 flags: []string{"-async"},
2649 },
2650 {
David Benjaminabe94e32016-09-04 14:18:58 -04002651 name: "SendSNIWarningAlert",
2652 config: Config{
2653 MaxVersion: VersionTLS12,
2654 Bugs: ProtocolBugs{
2655 SendSNIWarningAlert: true,
2656 },
2657 },
2658 },
David Benjaminc241d792016-09-09 10:34:20 -04002659 {
2660 testType: serverTest,
2661 name: "ExtraCompressionMethods-TLS12",
2662 config: Config{
2663 MaxVersion: VersionTLS12,
2664 Bugs: ProtocolBugs{
2665 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2666 },
2667 },
2668 },
2669 {
2670 testType: serverTest,
2671 name: "ExtraCompressionMethods-TLS13",
2672 config: Config{
2673 MaxVersion: VersionTLS13,
2674 Bugs: ProtocolBugs{
2675 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2676 },
2677 },
2678 shouldFail: true,
2679 expectedError: ":INVALID_COMPRESSION_LIST:",
2680 expectedLocalError: "remote error: illegal parameter",
2681 },
2682 {
2683 testType: serverTest,
2684 name: "NoNullCompression-TLS12",
2685 config: Config{
2686 MaxVersion: VersionTLS12,
2687 Bugs: ProtocolBugs{
2688 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2689 },
2690 },
2691 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002692 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002693 expectedLocalError: "remote error: illegal parameter",
2694 },
2695 {
2696 testType: serverTest,
2697 name: "NoNullCompression-TLS13",
2698 config: Config{
2699 MaxVersion: VersionTLS13,
2700 Bugs: ProtocolBugs{
2701 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2702 },
2703 },
2704 shouldFail: true,
2705 expectedError: ":INVALID_COMPRESSION_LIST:",
2706 expectedLocalError: "remote error: illegal parameter",
2707 },
David Benjamin413e79e2017-07-01 10:11:53 -04002708 // Test that the client rejects invalid compression methods
2709 // from the server.
2710 {
2711 testType: clientTest,
2712 name: "InvalidCompressionMethod",
2713 config: Config{
2714 MaxVersion: VersionTLS12,
2715 Bugs: ProtocolBugs{
2716 SendCompressionMethod: 1,
2717 },
2718 },
2719 shouldFail: true,
2720 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2721 expectedLocalError: "remote error: illegal parameter",
2722 },
David Benjamin65ac9972016-09-02 21:35:25 -04002723 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002724 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002725 config: Config{
2726 MaxVersion: VersionTLS12,
2727 Bugs: ProtocolBugs{
2728 ExpectGREASE: true,
2729 },
2730 },
2731 flags: []string{"-enable-grease"},
2732 },
2733 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002734 name: "GREASE-Client-TLS13",
2735 config: Config{
2736 MaxVersion: VersionTLS13,
2737 Bugs: ProtocolBugs{
2738 ExpectGREASE: true,
2739 },
2740 },
2741 flags: []string{"-enable-grease"},
2742 },
2743 {
2744 testType: serverTest,
2745 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002746 config: Config{
2747 MaxVersion: VersionTLS13,
2748 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002749 // TLS 1.3 servers are expected to
2750 // always enable GREASE. TLS 1.3 is new,
2751 // so there is no existing ecosystem to
2752 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002753 ExpectGREASE: true,
2754 },
2755 },
David Benjamin65ac9972016-09-02 21:35:25 -04002756 },
David Benjamine3fbb362017-01-06 16:19:28 -05002757 {
2758 // Test the server so there is a large certificate as
2759 // well as application data.
2760 testType: serverTest,
2761 name: "MaxSendFragment",
2762 config: Config{
2763 Bugs: ProtocolBugs{
2764 MaxReceivePlaintext: 512,
2765 },
2766 },
2767 messageLen: 1024,
2768 flags: []string{
2769 "-max-send-fragment", "512",
2770 "-read-size", "1024",
2771 },
2772 },
2773 {
2774 // Test the server so there is a large certificate as
2775 // well as application data.
2776 testType: serverTest,
2777 name: "MaxSendFragment-TooLarge",
2778 config: Config{
2779 Bugs: ProtocolBugs{
2780 // Ensure that some of the records are
2781 // 512.
2782 MaxReceivePlaintext: 511,
2783 },
2784 },
2785 messageLen: 1024,
2786 flags: []string{
2787 "-max-send-fragment", "512",
2788 "-read-size", "1024",
2789 },
2790 shouldFail: true,
2791 expectedLocalError: "local error: record overflow",
2792 },
David Benjaminaba057a2017-09-11 15:21:43 -04002793 {
2794 // Test that Java-like ClientHellos are provided session
2795 // IDs but resumption is always declined. This is to
2796 // workaround a bug that causes connection failures when
2797 // certificates rotate.
2798 testType: serverTest,
2799 name: "JavaWorkaround",
2800 config: Config{
2801 MaxVersion: VersionTLS12,
2802 CurvePreferences: []CurveID{CurveP256, CurveP384, CurveP521},
2803 SessionTicketsDisabled: true,
2804 Bugs: ProtocolBugs{
2805 SendOnlyECExtensions: true,
2806 },
2807 },
2808 flags: []string{"-expect-session-id"},
2809 resumeSession: true,
2810 expectResumeRejected: true,
2811 },
Adam Langley7c803a62015-06-15 15:35:05 -07002812 }
Adam Langley7c803a62015-06-15 15:35:05 -07002813 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002814
2815 // Test that very large messages can be received.
2816 cert := rsaCertificate
2817 for i := 0; i < 50; i++ {
2818 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2819 }
2820 testCases = append(testCases, testCase{
2821 name: "LargeMessage",
2822 config: Config{
2823 Certificates: []Certificate{cert},
2824 },
2825 })
2826 testCases = append(testCases, testCase{
2827 protocol: dtls,
2828 name: "LargeMessage-DTLS",
2829 config: Config{
2830 Certificates: []Certificate{cert},
2831 },
2832 })
2833
2834 // They are rejected if the maximum certificate chain length is capped.
2835 testCases = append(testCases, testCase{
2836 name: "LargeMessage-Reject",
2837 config: Config{
2838 Certificates: []Certificate{cert},
2839 },
2840 flags: []string{"-max-cert-list", "16384"},
2841 shouldFail: true,
2842 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2843 })
2844 testCases = append(testCases, testCase{
2845 protocol: dtls,
2846 name: "LargeMessage-Reject-DTLS",
2847 config: Config{
2848 Certificates: []Certificate{cert},
2849 },
2850 flags: []string{"-max-cert-list", "16384"},
2851 shouldFail: true,
2852 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2853 })
Adam Langley7c803a62015-06-15 15:35:05 -07002854}
2855
David Benjaminaa012042016-12-10 13:33:05 -05002856func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2857 const psk = "12345"
2858 const pskIdentity = "luggage combo"
2859
2860 var prefix string
2861 if protocol == dtls {
2862 if !ver.hasDTLS {
2863 return
2864 }
2865 prefix = "D"
2866 }
2867
2868 var cert Certificate
2869 var certFile string
2870 var keyFile string
2871 if hasComponent(suite.name, "ECDSA") {
2872 cert = ecdsaP256Certificate
2873 certFile = ecdsaP256CertificateFile
2874 keyFile = ecdsaP256KeyFile
2875 } else {
2876 cert = rsaCertificate
2877 certFile = rsaCertificateFile
2878 keyFile = rsaKeyFile
2879 }
2880
2881 var flags []string
2882 if hasComponent(suite.name, "PSK") {
2883 flags = append(flags,
2884 "-psk", psk,
2885 "-psk-identity", pskIdentity)
2886 }
2887 if hasComponent(suite.name, "NULL") {
2888 // NULL ciphers must be explicitly enabled.
2889 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2890 }
David Benjaminaa012042016-12-10 13:33:05 -05002891
2892 var shouldServerFail, shouldClientFail bool
2893 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2894 // BoringSSL clients accept ECDHE on SSLv3, but
2895 // a BoringSSL server will never select it
2896 // because the extension is missing.
2897 shouldServerFail = true
2898 }
2899 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2900 shouldClientFail = true
2901 shouldServerFail = true
2902 }
2903 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2904 shouldClientFail = true
2905 shouldServerFail = true
2906 }
2907 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2908 shouldClientFail = true
2909 shouldServerFail = true
2910 }
2911 if !isDTLSCipher(suite.name) && protocol == dtls {
2912 shouldClientFail = true
2913 shouldServerFail = true
2914 }
2915
2916 var sendCipherSuite uint16
2917 var expectedServerError, expectedClientError string
2918 serverCipherSuites := []uint16{suite.id}
2919 if shouldServerFail {
2920 expectedServerError = ":NO_SHARED_CIPHER:"
2921 }
2922 if shouldClientFail {
2923 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2924 // Configure the server to select ciphers as normal but
2925 // select an incompatible cipher in ServerHello.
2926 serverCipherSuites = nil
2927 sendCipherSuite = suite.id
2928 }
2929
David Benjamincdb6fe92017-02-07 16:06:48 -05002930 // For cipher suites and versions where exporters are defined, verify
2931 // that they interoperate.
2932 var exportKeyingMaterial int
2933 if ver.version > VersionSSL30 {
2934 exportKeyingMaterial = 1024
2935 }
2936
David Benjaminaa012042016-12-10 13:33:05 -05002937 testCases = append(testCases, testCase{
2938 testType: serverTest,
2939 protocol: protocol,
2940 name: prefix + ver.name + "-" + suite.name + "-server",
2941 config: Config{
2942 MinVersion: ver.version,
2943 MaxVersion: ver.version,
2944 CipherSuites: []uint16{suite.id},
2945 Certificates: []Certificate{cert},
2946 PreSharedKey: []byte(psk),
2947 PreSharedKeyIdentity: pskIdentity,
2948 Bugs: ProtocolBugs{
2949 AdvertiseAllConfiguredCiphers: true,
2950 },
2951 },
David Benjamina5022392017-07-10 17:40:39 -04002952 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002953 certFile: certFile,
2954 keyFile: keyFile,
2955 flags: flags,
2956 resumeSession: true,
2957 shouldFail: shouldServerFail,
2958 expectedError: expectedServerError,
2959 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002960 })
2961
2962 testCases = append(testCases, testCase{
2963 testType: clientTest,
2964 protocol: protocol,
2965 name: prefix + ver.name + "-" + suite.name + "-client",
2966 config: Config{
2967 MinVersion: ver.version,
2968 MaxVersion: ver.version,
2969 CipherSuites: serverCipherSuites,
2970 Certificates: []Certificate{cert},
2971 PreSharedKey: []byte(psk),
2972 PreSharedKeyIdentity: pskIdentity,
2973 Bugs: ProtocolBugs{
2974 IgnorePeerCipherPreferences: shouldClientFail,
2975 SendCipherSuite: sendCipherSuite,
2976 },
2977 },
David Benjamina5022392017-07-10 17:40:39 -04002978 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002979 flags: flags,
2980 resumeSession: true,
2981 shouldFail: shouldClientFail,
2982 expectedError: expectedClientError,
2983 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002984 })
2985
David Benjamin6f600d62016-12-21 16:06:54 -05002986 if shouldClientFail {
2987 return
2988 }
2989
2990 // Ensure the maximum record size is accepted.
2991 testCases = append(testCases, testCase{
2992 protocol: protocol,
2993 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2994 config: Config{
2995 MinVersion: ver.version,
2996 MaxVersion: ver.version,
2997 CipherSuites: []uint16{suite.id},
2998 Certificates: []Certificate{cert},
2999 PreSharedKey: []byte(psk),
3000 PreSharedKeyIdentity: pskIdentity,
3001 },
David Benjamina5022392017-07-10 17:40:39 -04003002 tls13Variant: ver.tls13Variant,
3003 flags: flags,
3004 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05003005 })
3006
3007 // Test bad records for all ciphers. Bad records are fatal in TLS
3008 // and ignored in DTLS.
3009 var shouldFail bool
3010 var expectedError string
3011 if protocol == tls {
3012 shouldFail = true
3013 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
3014 }
3015
3016 testCases = append(testCases, testCase{
3017 protocol: protocol,
3018 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
3019 config: Config{
3020 MinVersion: ver.version,
3021 MaxVersion: ver.version,
3022 CipherSuites: []uint16{suite.id},
3023 Certificates: []Certificate{cert},
3024 PreSharedKey: []byte(psk),
3025 PreSharedKeyIdentity: pskIdentity,
3026 },
David Benjamina5022392017-07-10 17:40:39 -04003027 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05003028 flags: flags,
3029 damageFirstWrite: true,
3030 messageLen: maxPlaintext,
3031 shouldFail: shouldFail,
3032 expectedError: expectedError,
3033 })
David Benjaminaa012042016-12-10 13:33:05 -05003034}
3035
Adam Langley95c29f32014-06-20 12:00:00 -07003036func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02003037 const bogusCipher = 0xfe00
3038
Adam Langley95c29f32014-06-20 12:00:00 -07003039 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07003040 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04003041 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05003042 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07003043 }
David Benjamin2c99d282015-09-01 10:23:00 -04003044 }
Adam Langley95c29f32014-06-20 12:00:00 -07003045 }
Adam Langleya7997f12015-05-14 17:38:50 -07003046
3047 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003048 name: "NoSharedCipher",
3049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003050 MaxVersion: VersionTLS12,
3051 CipherSuites: []uint16{},
3052 },
3053 shouldFail: true,
3054 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3055 })
3056
3057 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003058 name: "NoSharedCipher-TLS13",
3059 config: Config{
3060 MaxVersion: VersionTLS13,
3061 CipherSuites: []uint16{},
3062 },
3063 shouldFail: true,
3064 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3065 })
3066
3067 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003068 name: "UnsupportedCipherSuite",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003071 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003072 Bugs: ProtocolBugs{
3073 IgnorePeerCipherPreferences: true,
3074 },
3075 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003076 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003077 shouldFail: true,
3078 expectedError: ":WRONG_CIPHER_RETURNED:",
3079 })
3080
3081 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003082 name: "ServerHelloBogusCipher",
3083 config: Config{
3084 MaxVersion: VersionTLS12,
3085 Bugs: ProtocolBugs{
3086 SendCipherSuite: bogusCipher,
3087 },
3088 },
3089 shouldFail: true,
3090 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3091 })
3092 testCases = append(testCases, testCase{
3093 name: "ServerHelloBogusCipher-TLS13",
3094 config: Config{
3095 MaxVersion: VersionTLS13,
3096 Bugs: ProtocolBugs{
3097 SendCipherSuite: bogusCipher,
3098 },
3099 },
3100 shouldFail: true,
3101 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3102 })
3103
David Benjamin241ae832016-01-15 03:04:54 -05003104 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003105 testCases = append(testCases, testCase{
3106 testType: serverTest,
3107 name: "UnknownCipher",
3108 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003109 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003110 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003111 Bugs: ProtocolBugs{
3112 AdvertiseAllConfiguredCiphers: true,
3113 },
3114 },
3115 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003116
3117 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003118 testCases = append(testCases, testCase{
3119 testType: serverTest,
3120 name: "UnknownCipher-TLS13",
3121 config: Config{
3122 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003123 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003124 Bugs: ProtocolBugs{
3125 AdvertiseAllConfiguredCiphers: true,
3126 },
David Benjamin241ae832016-01-15 03:04:54 -05003127 },
3128 })
3129
David Benjamin78679342016-09-16 19:42:05 -04003130 // Test empty ECDHE_PSK identity hints work as expected.
3131 testCases = append(testCases, testCase{
3132 name: "EmptyECDHEPSKHint",
3133 config: Config{
3134 MaxVersion: VersionTLS12,
3135 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3136 PreSharedKey: []byte("secret"),
3137 },
3138 flags: []string{"-psk", "secret"},
3139 })
3140
3141 // Test empty PSK identity hints work as expected, even if an explicit
3142 // ServerKeyExchange is sent.
3143 testCases = append(testCases, testCase{
3144 name: "ExplicitEmptyPSKHint",
3145 config: Config{
3146 MaxVersion: VersionTLS12,
3147 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3148 PreSharedKey: []byte("secret"),
3149 Bugs: ProtocolBugs{
3150 AlwaysSendPreSharedKeyIdentityHint: true,
3151 },
3152 },
3153 flags: []string{"-psk", "secret"},
3154 })
David Benjamin69522112017-03-28 15:38:29 -05003155
3156 // Test that clients enforce that the server-sent certificate and cipher
3157 // suite match in TLS 1.2.
3158 testCases = append(testCases, testCase{
3159 name: "CertificateCipherMismatch-RSA",
3160 config: Config{
3161 MaxVersion: VersionTLS12,
3162 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3163 Certificates: []Certificate{rsaCertificate},
3164 Bugs: ProtocolBugs{
3165 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3166 },
3167 },
3168 shouldFail: true,
3169 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3170 })
3171 testCases = append(testCases, testCase{
3172 name: "CertificateCipherMismatch-ECDSA",
3173 config: Config{
3174 MaxVersion: VersionTLS12,
3175 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3176 Certificates: []Certificate{ecdsaP256Certificate},
3177 Bugs: ProtocolBugs{
3178 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3179 },
3180 },
3181 shouldFail: true,
3182 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3183 })
3184 testCases = append(testCases, testCase{
3185 name: "CertificateCipherMismatch-Ed25519",
3186 config: Config{
3187 MaxVersion: VersionTLS12,
3188 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3189 Certificates: []Certificate{ed25519Certificate},
3190 Bugs: ProtocolBugs{
3191 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3192 },
3193 },
3194 shouldFail: true,
3195 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3196 })
3197
3198 // Test that servers decline to select a cipher suite which is
3199 // inconsistent with their configured certificate.
3200 testCases = append(testCases, testCase{
3201 testType: serverTest,
3202 name: "ServerCipherFilter-RSA",
3203 config: Config{
3204 MaxVersion: VersionTLS12,
3205 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3206 },
3207 flags: []string{
3208 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3209 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3210 },
3211 shouldFail: true,
3212 expectedError: ":NO_SHARED_CIPHER:",
3213 })
3214 testCases = append(testCases, testCase{
3215 testType: serverTest,
3216 name: "ServerCipherFilter-ECDSA",
3217 config: Config{
3218 MaxVersion: VersionTLS12,
3219 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3220 },
3221 flags: []string{
3222 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3223 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3224 },
3225 shouldFail: true,
3226 expectedError: ":NO_SHARED_CIPHER:",
3227 })
3228 testCases = append(testCases, testCase{
3229 testType: serverTest,
3230 name: "ServerCipherFilter-Ed25519",
3231 config: Config{
3232 MaxVersion: VersionTLS12,
3233 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3234 },
3235 flags: []string{
3236 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3237 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3238 },
3239 shouldFail: true,
3240 expectedError: ":NO_SHARED_CIPHER:",
3241 })
David Benjamin364af782017-07-01 10:35:27 -04003242
3243 // Test cipher suite negotiation works as expected. Configure a
3244 // complicated cipher suite configuration.
3245 const negotiationTestCiphers = "" +
3246 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3247 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3248 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3249 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3250 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3251 negotiationTests := []struct {
3252 ciphers []uint16
3253 expected uint16
3254 }{
3255 // Server preferences are honored, including when
3256 // equipreference groups are involved.
3257 {
3258 []uint16{
3259 TLS_RSA_WITH_AES_256_GCM_SHA384,
3260 TLS_RSA_WITH_AES_128_CBC_SHA,
3261 TLS_RSA_WITH_AES_128_GCM_SHA256,
3262 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3263 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3264 },
3265 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3266 },
3267 {
3268 []uint16{
3269 TLS_RSA_WITH_AES_256_GCM_SHA384,
3270 TLS_RSA_WITH_AES_128_CBC_SHA,
3271 TLS_RSA_WITH_AES_128_GCM_SHA256,
3272 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3273 },
3274 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3275 },
3276 {
3277 []uint16{
3278 TLS_RSA_WITH_AES_256_GCM_SHA384,
3279 TLS_RSA_WITH_AES_128_CBC_SHA,
3280 TLS_RSA_WITH_AES_128_GCM_SHA256,
3281 },
3282 TLS_RSA_WITH_AES_128_GCM_SHA256,
3283 },
3284 {
3285 []uint16{
3286 TLS_RSA_WITH_AES_256_GCM_SHA384,
3287 TLS_RSA_WITH_AES_128_CBC_SHA,
3288 },
3289 TLS_RSA_WITH_AES_128_CBC_SHA,
3290 },
3291 // Equipreference groups use the client preference.
3292 {
3293 []uint16{
3294 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3295 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3296 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3297 },
3298 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3299 },
3300 {
3301 []uint16{
3302 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3303 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3304 },
3305 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3306 },
3307 {
3308 []uint16{
3309 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3310 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3311 },
3312 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3313 },
3314 {
3315 []uint16{
3316 TLS_RSA_WITH_AES_256_GCM_SHA384,
3317 TLS_RSA_WITH_AES_256_CBC_SHA,
3318 },
3319 TLS_RSA_WITH_AES_256_GCM_SHA384,
3320 },
3321 {
3322 []uint16{
3323 TLS_RSA_WITH_AES_256_CBC_SHA,
3324 TLS_RSA_WITH_AES_256_GCM_SHA384,
3325 },
3326 TLS_RSA_WITH_AES_256_CBC_SHA,
3327 },
3328 // If there are two equipreference groups, the preferred one
3329 // takes precedence.
3330 {
3331 []uint16{
3332 TLS_RSA_WITH_AES_256_GCM_SHA384,
3333 TLS_RSA_WITH_AES_256_CBC_SHA,
3334 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3335 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3336 },
3337 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3338 },
3339 }
3340 for i, t := range negotiationTests {
3341 testCases = append(testCases, testCase{
3342 testType: serverTest,
3343 name: "CipherNegotiation-" + strconv.Itoa(i),
3344 config: Config{
3345 MaxVersion: VersionTLS12,
3346 CipherSuites: t.ciphers,
3347 },
3348 flags: []string{"-cipher", negotiationTestCiphers},
3349 expectedCipher: t.expected,
3350 })
3351 }
Adam Langley95c29f32014-06-20 12:00:00 -07003352}
3353
3354func addBadECDSASignatureTests() {
3355 for badR := BadValue(1); badR < NumBadValues; badR++ {
3356 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003357 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003358 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3359 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003360 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003361 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003362 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003363 Bugs: ProtocolBugs{
3364 BadECDSAR: badR,
3365 BadECDSAS: badS,
3366 },
3367 },
3368 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003369 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003370 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003371 testCases = append(testCases, testCase{
3372 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3373 config: Config{
3374 MaxVersion: VersionTLS13,
3375 Certificates: []Certificate{ecdsaP256Certificate},
3376 Bugs: ProtocolBugs{
3377 BadECDSAR: badR,
3378 BadECDSAS: badS,
3379 },
3380 },
3381 shouldFail: true,
3382 expectedError: ":BAD_SIGNATURE:",
3383 })
Adam Langley95c29f32014-06-20 12:00:00 -07003384 }
3385 }
3386}
3387
Adam Langley80842bd2014-06-20 12:00:00 -07003388func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003389 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003390 name: "MaxCBCPadding",
3391 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003392 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003393 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3394 Bugs: ProtocolBugs{
3395 MaxPadding: true,
3396 },
3397 },
3398 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3399 })
David Benjamin025b3d32014-07-01 19:53:04 -04003400 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003401 name: "BadCBCPadding",
3402 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003403 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003404 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3405 Bugs: ProtocolBugs{
3406 PaddingFirstByteBad: true,
3407 },
3408 },
3409 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003410 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003411 })
3412 // OpenSSL previously had an issue where the first byte of padding in
3413 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003414 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003415 name: "BadCBCPadding255",
3416 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003417 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003418 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3419 Bugs: ProtocolBugs{
3420 MaxPadding: true,
3421 PaddingFirstByteBadIf255: true,
3422 },
3423 },
3424 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3425 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003426 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003427 })
3428}
3429
Kenny Root7fdeaf12014-08-05 15:23:37 -07003430func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003431 var cbcCiphers = []struct {
3432 name string
3433 cipher uint16
3434 }{
3435 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3436 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3437 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3438 }
3439 for _, t := range cbcCiphers {
3440 testCases = append(testCases, testCase{
3441 name: "CBCRecordSplitting-" + t.name,
3442 config: Config{
3443 MaxVersion: VersionTLS10,
3444 MinVersion: VersionTLS10,
3445 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003446 Bugs: ProtocolBugs{
3447 ExpectRecordSplitting: true,
3448 },
David Benjamina1ce8562017-07-01 11:46:57 -04003449 },
3450 messageLen: -1, // read until EOF
3451 resumeSession: true,
3452 flags: []string{
3453 "-async",
3454 "-write-different-record-sizes",
3455 "-cbc-record-splitting",
3456 },
3457 })
3458 testCases = append(testCases, testCase{
3459 name: "CBCRecordSplittingPartialWrite-" + t.name,
3460 config: Config{
3461 MaxVersion: VersionTLS10,
3462 MinVersion: VersionTLS10,
3463 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003464 Bugs: ProtocolBugs{
3465 ExpectRecordSplitting: true,
3466 },
David Benjamina1ce8562017-07-01 11:46:57 -04003467 },
3468 messageLen: -1, // read until EOF
3469 flags: []string{
3470 "-async",
3471 "-write-different-record-sizes",
3472 "-cbc-record-splitting",
3473 "-partial-write",
3474 },
3475 })
3476 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003477}
3478
David Benjamin636293b2014-07-08 17:59:18 -04003479func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003480 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003481 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003482 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3483 cert, err := x509.ParseCertificate(cert.Certificate[0])
3484 if err != nil {
3485 panic(err)
3486 }
3487 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003488 }
Adam Langley2ff79332017-02-28 13:45:39 -08003489 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003490
David Benjamin636293b2014-07-08 17:59:18 -04003491 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003492 testCases = append(testCases, testCase{
3493 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003494 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003495 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003496 MinVersion: ver.version,
3497 MaxVersion: ver.version,
3498 ClientAuth: RequireAnyClientCert,
3499 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003500 },
David Benjamina5022392017-07-10 17:40:39 -04003501 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003502 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003503 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3504 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003505 },
3506 })
3507 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003508 testType: serverTest,
3509 name: ver.name + "-Server-ClientAuth-RSA",
3510 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003511 MinVersion: ver.version,
3512 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003513 Certificates: []Certificate{rsaCertificate},
3514 },
David Benjamina5022392017-07-10 17:40:39 -04003515 tls13Variant: ver.tls13Variant,
3516 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003517 })
David Benjamine098ec22014-08-27 23:13:20 -04003518 if ver.version != VersionSSL30 {
3519 testCases = append(testCases, testCase{
3520 testType: serverTest,
3521 name: ver.name + "-Server-ClientAuth-ECDSA",
3522 config: Config{
3523 MinVersion: ver.version,
3524 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003525 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003526 },
David Benjamina5022392017-07-10 17:40:39 -04003527 tls13Variant: ver.tls13Variant,
3528 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003529 })
3530 testCases = append(testCases, testCase{
3531 testType: clientTest,
3532 name: ver.name + "-Client-ClientAuth-ECDSA",
3533 config: Config{
3534 MinVersion: ver.version,
3535 MaxVersion: ver.version,
3536 ClientAuth: RequireAnyClientCert,
3537 ClientCAs: certPool,
3538 },
David Benjamina5022392017-07-10 17:40:39 -04003539 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003540 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003541 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3542 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003543 },
3544 })
3545 }
Adam Langley37646832016-08-01 16:16:46 -07003546
3547 testCases = append(testCases, testCase{
3548 name: "NoClientCertificate-" + ver.name,
3549 config: Config{
3550 MinVersion: ver.version,
3551 MaxVersion: ver.version,
3552 ClientAuth: RequireAnyClientCert,
3553 },
David Benjamina5022392017-07-10 17:40:39 -04003554 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003555 shouldFail: true,
3556 expectedLocalError: "client didn't provide a certificate",
3557 })
3558
3559 testCases = append(testCases, testCase{
3560 // Even if not configured to expect a certificate, OpenSSL will
3561 // return X509_V_OK as the verify_result.
3562 testType: serverTest,
3563 name: "NoClientCertificateRequested-Server-" + ver.name,
3564 config: Config{
3565 MinVersion: ver.version,
3566 MaxVersion: ver.version,
3567 },
David Benjamina5022392017-07-10 17:40:39 -04003568 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003569 flags: []string{
3570 "-expect-verify-result",
3571 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003572 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003573 })
3574
3575 testCases = append(testCases, testCase{
3576 // If a client certificate is not provided, OpenSSL will still
3577 // return X509_V_OK as the verify_result.
3578 testType: serverTest,
3579 name: "NoClientCertificate-Server-" + ver.name,
3580 config: Config{
3581 MinVersion: ver.version,
3582 MaxVersion: ver.version,
3583 },
David Benjamina5022392017-07-10 17:40:39 -04003584 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003585 flags: []string{
3586 "-expect-verify-result",
3587 "-verify-peer",
3588 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003589 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003590 })
3591
David Benjamin1db9e1b2016-10-07 20:51:43 -04003592 certificateRequired := "remote error: certificate required"
3593 if ver.version < VersionTLS13 {
3594 // Prior to TLS 1.3, the generic handshake_failure alert
3595 // was used.
3596 certificateRequired = "remote error: handshake failure"
3597 }
Adam Langley37646832016-08-01 16:16:46 -07003598 testCases = append(testCases, testCase{
3599 testType: serverTest,
3600 name: "RequireAnyClientCertificate-" + ver.name,
3601 config: Config{
3602 MinVersion: ver.version,
3603 MaxVersion: ver.version,
3604 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003605 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003606 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003607 shouldFail: true,
3608 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3609 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003610 })
3611
3612 if ver.version != VersionSSL30 {
3613 testCases = append(testCases, testCase{
3614 testType: serverTest,
3615 name: "SkipClientCertificate-" + ver.name,
3616 config: Config{
3617 MinVersion: ver.version,
3618 MaxVersion: ver.version,
3619 Bugs: ProtocolBugs{
3620 SkipClientCertificate: true,
3621 },
3622 },
3623 // Setting SSL_VERIFY_PEER allows anonymous clients.
3624 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003625 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003626 shouldFail: true,
3627 expectedError: ":UNEXPECTED_MESSAGE:",
3628 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003629
3630 testCases = append(testCases, testCase{
3631 testType: serverTest,
3632 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3633 config: Config{
3634 MinVersion: ver.version,
3635 MaxVersion: ver.version,
3636 },
3637 flags: []string{
3638 "-enable-channel-id",
3639 "-verify-peer-if-no-obc",
3640 },
David Benjamina5022392017-07-10 17:40:39 -04003641 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003642 shouldFail: true,
3643 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3644 expectedLocalError: certificateRequired,
3645 })
3646
3647 testCases = append(testCases, testCase{
3648 testType: serverTest,
3649 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3650 config: Config{
3651 MinVersion: ver.version,
3652 MaxVersion: ver.version,
3653 ChannelID: channelIDKey,
3654 },
3655 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003656 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003657 flags: []string{
3658 "-enable-channel-id",
3659 "-verify-peer-if-no-obc",
3660 },
3661 })
Adam Langley37646832016-08-01 16:16:46 -07003662 }
Adam Langley2ff79332017-02-28 13:45:39 -08003663
3664 testCases = append(testCases, testCase{
3665 testType: serverTest,
3666 name: ver.name + "-Server-CertReq-CA-List",
3667 config: Config{
3668 MinVersion: ver.version,
3669 MaxVersion: ver.version,
3670 Certificates: []Certificate{rsaCertificate},
3671 Bugs: ProtocolBugs{
3672 ExpectCertificateReqNames: caNames,
3673 },
3674 },
David Benjamina5022392017-07-10 17:40:39 -04003675 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003676 flags: []string{
3677 "-require-any-client-certificate",
3678 "-use-client-ca-list", encodeDERValues(caNames),
3679 },
3680 })
3681
3682 testCases = append(testCases, testCase{
3683 testType: clientTest,
3684 name: ver.name + "-Client-CertReq-CA-List",
3685 config: Config{
3686 MinVersion: ver.version,
3687 MaxVersion: ver.version,
3688 Certificates: []Certificate{rsaCertificate},
3689 ClientAuth: RequireAnyClientCert,
3690 ClientCAs: certPool,
3691 },
David Benjamina5022392017-07-10 17:40:39 -04003692 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003693 flags: []string{
3694 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3695 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3696 "-expect-client-ca-list", encodeDERValues(caNames),
3697 },
3698 })
David Benjamin636293b2014-07-08 17:59:18 -04003699 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003700
David Benjaminc032dfa2016-05-12 14:54:57 -04003701 // Client auth is only legal in certificate-based ciphers.
3702 testCases = append(testCases, testCase{
3703 testType: clientTest,
3704 name: "ClientAuth-PSK",
3705 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003706 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003707 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3708 PreSharedKey: []byte("secret"),
3709 ClientAuth: RequireAnyClientCert,
3710 },
3711 flags: []string{
3712 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3713 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3714 "-psk", "secret",
3715 },
3716 shouldFail: true,
3717 expectedError: ":UNEXPECTED_MESSAGE:",
3718 })
3719 testCases = append(testCases, testCase{
3720 testType: clientTest,
3721 name: "ClientAuth-ECDHE_PSK",
3722 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003723 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003724 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3725 PreSharedKey: []byte("secret"),
3726 ClientAuth: RequireAnyClientCert,
3727 },
3728 flags: []string{
3729 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3730 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3731 "-psk", "secret",
3732 },
3733 shouldFail: true,
3734 expectedError: ":UNEXPECTED_MESSAGE:",
3735 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003736
3737 // Regression test for a bug where the client CA list, if explicitly
3738 // set to NULL, was mis-encoded.
3739 testCases = append(testCases, testCase{
3740 testType: serverTest,
3741 name: "Null-Client-CA-List",
3742 config: Config{
3743 MaxVersion: VersionTLS12,
3744 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003745 Bugs: ProtocolBugs{
3746 ExpectCertificateReqNames: [][]byte{},
3747 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003748 },
3749 flags: []string{
3750 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003751 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003752 },
3753 })
David Benjamin636293b2014-07-08 17:59:18 -04003754}
3755
Adam Langley75712922014-10-10 16:23:43 -07003756func addExtendedMasterSecretTests() {
3757 const expectEMSFlag = "-expect-extended-master-secret"
3758
3759 for _, with := range []bool{false, true} {
3760 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003761 if with {
3762 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003763 }
3764
3765 for _, isClient := range []bool{false, true} {
3766 suffix := "-Server"
3767 testType := serverTest
3768 if isClient {
3769 suffix = "-Client"
3770 testType = clientTest
3771 }
3772
3773 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003774 // In TLS 1.3, the extension is irrelevant and
3775 // always reports as enabled.
3776 var flags []string
3777 if with || ver.version >= VersionTLS13 {
3778 flags = []string{expectEMSFlag}
3779 }
3780
Adam Langley75712922014-10-10 16:23:43 -07003781 test := testCase{
3782 testType: testType,
3783 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3784 config: Config{
3785 MinVersion: ver.version,
3786 MaxVersion: ver.version,
3787 Bugs: ProtocolBugs{
3788 NoExtendedMasterSecret: !with,
3789 RequireExtendedMasterSecret: with,
3790 },
3791 },
David Benjamina5022392017-07-10 17:40:39 -04003792 tls13Variant: ver.tls13Variant,
3793 flags: flags,
3794 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003795 }
3796 if test.shouldFail {
3797 test.expectedLocalError = "extended master secret required but not supported by peer"
3798 }
3799 testCases = append(testCases, test)
3800 }
3801 }
3802 }
3803
Adam Langleyba5934b2015-06-02 10:50:35 -07003804 for _, isClient := range []bool{false, true} {
3805 for _, supportedInFirstConnection := range []bool{false, true} {
3806 for _, supportedInResumeConnection := range []bool{false, true} {
3807 boolToWord := func(b bool) string {
3808 if b {
3809 return "Yes"
3810 }
3811 return "No"
3812 }
3813 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3814 if isClient {
3815 suffix += "Client"
3816 } else {
3817 suffix += "Server"
3818 }
3819
3820 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003821 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003822 Bugs: ProtocolBugs{
3823 RequireExtendedMasterSecret: true,
3824 },
3825 }
3826
3827 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003828 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003829 Bugs: ProtocolBugs{
3830 NoExtendedMasterSecret: true,
3831 },
3832 }
3833
3834 test := testCase{
3835 name: "ExtendedMasterSecret-" + suffix,
3836 resumeSession: true,
3837 }
3838
3839 if !isClient {
3840 test.testType = serverTest
3841 }
3842
3843 if supportedInFirstConnection {
3844 test.config = supportedConfig
3845 } else {
3846 test.config = noSupportConfig
3847 }
3848
3849 if supportedInResumeConnection {
3850 test.resumeConfig = &supportedConfig
3851 } else {
3852 test.resumeConfig = &noSupportConfig
3853 }
3854
3855 switch suffix {
3856 case "YesToYes-Client", "YesToYes-Server":
3857 // When a session is resumed, it should
3858 // still be aware that its master
3859 // secret was generated via EMS and
3860 // thus it's safe to use tls-unique.
3861 test.flags = []string{expectEMSFlag}
3862 case "NoToYes-Server":
3863 // If an original connection did not
3864 // contain EMS, but a resumption
3865 // handshake does, then a server should
3866 // not resume the session.
3867 test.expectResumeRejected = true
3868 case "YesToNo-Server":
3869 // Resuming an EMS session without the
3870 // EMS extension should cause the
3871 // server to abort the connection.
3872 test.shouldFail = true
3873 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3874 case "NoToYes-Client":
3875 // A client should abort a connection
3876 // where the server resumed a non-EMS
3877 // session but echoed the EMS
3878 // extension.
3879 test.shouldFail = true
3880 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3881 case "YesToNo-Client":
3882 // A client should abort a connection
3883 // where the server didn't echo EMS
3884 // when the session used it.
3885 test.shouldFail = true
3886 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3887 }
3888
3889 testCases = append(testCases, test)
3890 }
3891 }
3892 }
David Benjamin163c9562016-08-29 23:14:17 -04003893
3894 // Switching EMS on renegotiation is forbidden.
3895 testCases = append(testCases, testCase{
3896 name: "ExtendedMasterSecret-Renego-NoEMS",
3897 config: Config{
3898 MaxVersion: VersionTLS12,
3899 Bugs: ProtocolBugs{
3900 NoExtendedMasterSecret: true,
3901 NoExtendedMasterSecretOnRenegotiation: true,
3902 },
3903 },
3904 renegotiate: 1,
3905 flags: []string{
3906 "-renegotiate-freely",
3907 "-expect-total-renegotiations", "1",
3908 },
3909 })
3910
3911 testCases = append(testCases, testCase{
3912 name: "ExtendedMasterSecret-Renego-Upgrade",
3913 config: Config{
3914 MaxVersion: VersionTLS12,
3915 Bugs: ProtocolBugs{
3916 NoExtendedMasterSecret: true,
3917 },
3918 },
3919 renegotiate: 1,
3920 flags: []string{
3921 "-renegotiate-freely",
3922 "-expect-total-renegotiations", "1",
3923 },
3924 shouldFail: true,
3925 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3926 })
3927
3928 testCases = append(testCases, testCase{
3929 name: "ExtendedMasterSecret-Renego-Downgrade",
3930 config: Config{
3931 MaxVersion: VersionTLS12,
3932 Bugs: ProtocolBugs{
3933 NoExtendedMasterSecretOnRenegotiation: true,
3934 },
3935 },
3936 renegotiate: 1,
3937 flags: []string{
3938 "-renegotiate-freely",
3939 "-expect-total-renegotiations", "1",
3940 },
3941 shouldFail: true,
3942 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3943 })
Adam Langley75712922014-10-10 16:23:43 -07003944}
3945
David Benjamin582ba042016-07-07 12:33:25 -07003946type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003947 protocol protocol
3948 async bool
3949 splitHandshake bool
3950 packHandshakeFlight bool
3951 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003952}
3953
David Benjamin43ec06f2014-08-05 02:28:57 -04003954// Adds tests that try to cover the range of the handshake state machine, under
3955// various conditions. Some of these are redundant with other tests, but they
3956// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003957func addAllStateMachineCoverageTests() {
3958 for _, async := range []bool{false, true} {
3959 for _, protocol := range []protocol{tls, dtls} {
3960 addStateMachineCoverageTests(stateMachineTestConfig{
3961 protocol: protocol,
3962 async: async,
3963 })
3964 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003965 protocol: protocol,
3966 async: async,
3967 implicitHandshake: true,
3968 })
3969 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003970 protocol: protocol,
3971 async: async,
3972 splitHandshake: true,
3973 })
3974 if protocol == tls {
3975 addStateMachineCoverageTests(stateMachineTestConfig{
3976 protocol: protocol,
3977 async: async,
3978 packHandshakeFlight: true,
3979 })
3980 }
3981 }
3982 }
3983}
3984
3985func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003986 var tests []testCase
3987
3988 // Basic handshake, with resumption. Client and server,
3989 // session ID and session ticket.
3990 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003991 name: "Basic-Client",
3992 config: Config{
3993 MaxVersion: VersionTLS12,
3994 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003995 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003996 // Ensure session tickets are used, not session IDs.
3997 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003998 })
3999 tests = append(tests, testCase{
4000 name: "Basic-Client-RenewTicket",
4001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004002 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004003 Bugs: ProtocolBugs{
4004 RenewTicketOnResume: true,
4005 },
4006 },
David Benjamin46662482016-08-17 00:51:00 -04004007 flags: []string{"-expect-ticket-renewal"},
4008 resumeSession: true,
4009 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004010 })
4011 tests = append(tests, testCase{
4012 name: "Basic-Client-NoTicket",
4013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004014 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004015 SessionTicketsDisabled: true,
4016 },
4017 resumeSession: true,
4018 })
4019 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05004020 testType: serverTest,
4021 name: "Basic-Server",
4022 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004023 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05004024 Bugs: ProtocolBugs{
4025 RequireSessionTickets: true,
4026 },
4027 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004028 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004029 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004030 })
4031 tests = append(tests, testCase{
4032 testType: serverTest,
4033 name: "Basic-Server-NoTickets",
4034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004035 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004036 SessionTicketsDisabled: true,
4037 },
4038 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004039 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004040 })
4041 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004042 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004043 name: "Basic-Server-EarlyCallback",
4044 config: Config{
4045 MaxVersion: VersionTLS12,
4046 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004047 flags: []string{"-use-early-callback"},
4048 resumeSession: true,
4049 })
4050
Steven Valdez143e8b32016-07-11 13:19:03 -04004051 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004052 if config.protocol == tls {
4053 tests = append(tests, testCase{
4054 name: "TLS13-1RTT-Client",
4055 config: Config{
4056 MaxVersion: VersionTLS13,
4057 MinVersion: VersionTLS13,
4058 },
David Benjamin46662482016-08-17 00:51:00 -04004059 resumeSession: true,
4060 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004061 })
4062
4063 tests = append(tests, testCase{
4064 testType: serverTest,
4065 name: "TLS13-1RTT-Server",
4066 config: Config{
4067 MaxVersion: VersionTLS13,
4068 MinVersion: VersionTLS13,
4069 },
David Benjamin46662482016-08-17 00:51:00 -04004070 resumeSession: true,
4071 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004072 // TLS 1.3 uses tickets, so the session should not be
4073 // cached statefully.
4074 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004075 })
4076
4077 tests = append(tests, testCase{
4078 name: "TLS13-HelloRetryRequest-Client",
4079 config: Config{
4080 MaxVersion: VersionTLS13,
4081 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004082 // P-384 requires a HelloRetryRequest against BoringSSL's default
4083 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004084 CurvePreferences: []CurveID{CurveP384},
4085 Bugs: ProtocolBugs{
4086 ExpectMissingKeyShare: true,
4087 },
4088 },
4089 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4090 resumeSession: true,
4091 })
4092
4093 tests = append(tests, testCase{
4094 testType: serverTest,
4095 name: "TLS13-HelloRetryRequest-Server",
4096 config: Config{
4097 MaxVersion: VersionTLS13,
4098 MinVersion: VersionTLS13,
4099 // Require a HelloRetryRequest for every curve.
4100 DefaultCurves: []CurveID{},
4101 },
4102 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4103 resumeSession: true,
4104 })
Steven Valdez2d850622017-01-11 11:34:52 -05004105
Steven Valdez2d850622017-01-11 11:34:52 -05004106 tests = append(tests, testCase{
4107 testType: clientTest,
4108 name: "TLS13-EarlyData-Client",
4109 config: Config{
4110 MaxVersion: VersionTLS13,
4111 MinVersion: VersionTLS13,
4112 MaxEarlyDataSize: 16384,
4113 },
Steven Valdeze831a812017-03-09 14:56:07 -05004114 resumeConfig: &Config{
4115 MaxVersion: VersionTLS13,
4116 MinVersion: VersionTLS13,
4117 MaxEarlyDataSize: 16384,
4118 Bugs: ProtocolBugs{
4119 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4120 },
4121 },
Steven Valdez2d850622017-01-11 11:34:52 -05004122 resumeSession: true,
4123 flags: []string{
4124 "-enable-early-data",
4125 "-expect-early-data-info",
4126 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004127 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004128 },
4129 })
4130
4131 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004132 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004133 name: "TLS13Experiment-EarlyData-Client",
4134 config: Config{
4135 MaxVersion: VersionTLS13,
4136 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004137 MaxEarlyDataSize: 16384,
4138 },
4139 resumeConfig: &Config{
4140 MaxVersion: VersionTLS13,
4141 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004142 MaxEarlyDataSize: 16384,
4143 Bugs: ProtocolBugs{
4144 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4145 },
4146 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004147 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004148 resumeSession: true,
4149 flags: []string{
4150 "-enable-early-data",
4151 "-expect-early-data-info",
4152 "-expect-accept-early-data",
4153 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004154 },
4155 })
4156
4157 tests = append(tests, testCase{
4158 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004159 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4160 config: Config{
4161 MaxVersion: VersionTLS13,
4162 MinVersion: VersionTLS13,
4163 TLS13Variant: TLS13RecordTypeExperiment,
4164 MaxEarlyDataSize: 16384,
4165 },
4166 resumeConfig: &Config{
4167 MaxVersion: VersionTLS13,
4168 MinVersion: VersionTLS13,
4169 TLS13Variant: TLS13RecordTypeExperiment,
4170 MaxEarlyDataSize: 16384,
4171 Bugs: ProtocolBugs{
4172 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4173 },
4174 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004175 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004176 resumeSession: true,
4177 flags: []string{
4178 "-enable-early-data",
4179 "-expect-early-data-info",
4180 "-expect-accept-early-data",
4181 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004182 },
4183 })
4184
4185 tests = append(tests, testCase{
4186 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004187 name: "TLS13-EarlyData-TooMuchData-Client",
4188 config: Config{
4189 MaxVersion: VersionTLS13,
4190 MinVersion: VersionTLS13,
4191 MaxEarlyDataSize: 2,
4192 },
4193 resumeConfig: &Config{
4194 MaxVersion: VersionTLS13,
4195 MinVersion: VersionTLS13,
4196 MaxEarlyDataSize: 2,
4197 Bugs: ProtocolBugs{
4198 ExpectEarlyData: [][]byte{{'h', 'e'}},
4199 },
4200 },
4201 resumeShimPrefix: "llo",
4202 resumeSession: true,
4203 flags: []string{
4204 "-enable-early-data",
4205 "-expect-early-data-info",
4206 "-expect-accept-early-data",
4207 "-on-resume-shim-writes-first",
4208 },
4209 })
4210
4211 // Unfinished writes can only be tested when operations are async. EarlyData
4212 // can't be tested as part of an ImplicitHandshake in this case since
4213 // otherwise the early data will be sent as normal data.
4214 if config.async && !config.implicitHandshake {
4215 tests = append(tests, testCase{
4216 testType: clientTest,
4217 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4218 config: Config{
4219 MaxVersion: VersionTLS13,
4220 MinVersion: VersionTLS13,
4221 MaxEarlyDataSize: 16384,
4222 },
4223 resumeConfig: &Config{
4224 MaxVersion: VersionTLS13,
4225 MinVersion: VersionTLS13,
4226 MaxEarlyDataSize: 16384,
4227 Bugs: ProtocolBugs{
4228 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4229 },
4230 },
4231 resumeSession: true,
4232 flags: []string{
4233 "-enable-early-data",
4234 "-expect-early-data-info",
4235 "-expect-accept-early-data",
4236 "-on-resume-read-with-unfinished-write",
4237 "-on-resume-shim-writes-first",
4238 },
4239 })
4240
4241 // Rejected unfinished writes are discarded (from the
4242 // perspective of the calling application) on 0-RTT
4243 // reject.
4244 tests = append(tests, testCase{
4245 testType: clientTest,
4246 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4247 config: Config{
4248 MaxVersion: VersionTLS13,
4249 MinVersion: VersionTLS13,
4250 MaxEarlyDataSize: 16384,
4251 },
4252 resumeConfig: &Config{
4253 MaxVersion: VersionTLS13,
4254 MinVersion: VersionTLS13,
4255 MaxEarlyDataSize: 16384,
4256 Bugs: ProtocolBugs{
4257 AlwaysRejectEarlyData: true,
4258 },
4259 },
4260 resumeSession: true,
4261 flags: []string{
4262 "-enable-early-data",
4263 "-expect-early-data-info",
4264 "-expect-reject-early-data",
4265 "-on-resume-read-with-unfinished-write",
4266 "-on-resume-shim-writes-first",
4267 },
4268 })
4269 }
4270
4271 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004272 testType: serverTest,
4273 name: "TLS13-EarlyData-Server",
4274 config: Config{
4275 MaxVersion: VersionTLS13,
4276 MinVersion: VersionTLS13,
4277 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004278 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004279 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004280 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004281 },
4282 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004283 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004284 resumeSession: true,
4285 flags: []string{
4286 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004287 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004288 },
4289 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004290
4291 tests = append(tests, testCase{
4292 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004293 name: "TLS13Experiment-EarlyData-Server",
4294 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004295 MaxVersion: VersionTLS13,
4296 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004297 Bugs: ProtocolBugs{
4298 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4299 ExpectEarlyDataAccepted: true,
4300 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4301 },
4302 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004303 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004304 messageCount: 2,
4305 resumeSession: true,
4306 flags: []string{
4307 "-enable-early-data",
4308 "-expect-accept-early-data",
Steven Valdez520e1222017-06-13 12:45:25 -04004309 },
4310 })
4311
4312 tests = append(tests, testCase{
4313 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004314 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4315 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004316 MaxVersion: VersionTLS13,
4317 MinVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -04004318 Bugs: ProtocolBugs{
4319 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4320 ExpectEarlyDataAccepted: true,
4321 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4322 },
4323 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004324 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004325 messageCount: 2,
4326 resumeSession: true,
4327 flags: []string{
4328 "-enable-early-data",
4329 "-expect-accept-early-data",
Steven Valdezdbe01582017-07-14 10:39:28 -04004330 },
4331 })
4332
4333 tests = append(tests, testCase{
4334 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004335 name: "TLS13-MaxEarlyData-Server",
4336 config: Config{
4337 MaxVersion: VersionTLS13,
4338 MinVersion: VersionTLS13,
4339 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004340 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004341 ExpectEarlyDataAccepted: true,
4342 },
4343 },
4344 messageCount: 2,
4345 resumeSession: true,
4346 flags: []string{
4347 "-enable-early-data",
4348 "-expect-accept-early-data",
4349 },
4350 shouldFail: true,
4351 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4352 })
David Benjamine73c7f42016-08-17 00:29:33 -04004353 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004354
David Benjamin760b1dd2015-05-15 23:33:48 -04004355 // TLS client auth.
4356 tests = append(tests, testCase{
4357 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004358 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004360 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004361 ClientAuth: RequestClientCert,
4362 },
4363 })
4364 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004365 testType: serverTest,
4366 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004367 config: Config{
4368 MaxVersion: VersionTLS12,
4369 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004370 // Setting SSL_VERIFY_PEER allows anonymous clients.
4371 flags: []string{"-verify-peer"},
4372 })
David Benjamin582ba042016-07-07 12:33:25 -07004373 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004374 tests = append(tests, testCase{
4375 testType: clientTest,
4376 name: "ClientAuth-NoCertificate-Client-SSL3",
4377 config: Config{
4378 MaxVersion: VersionSSL30,
4379 ClientAuth: RequestClientCert,
4380 },
4381 })
4382 tests = append(tests, testCase{
4383 testType: serverTest,
4384 name: "ClientAuth-NoCertificate-Server-SSL3",
4385 config: Config{
4386 MaxVersion: VersionSSL30,
4387 },
4388 // Setting SSL_VERIFY_PEER allows anonymous clients.
4389 flags: []string{"-verify-peer"},
4390 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004391 tests = append(tests, testCase{
4392 testType: clientTest,
4393 name: "ClientAuth-NoCertificate-Client-TLS13",
4394 config: Config{
4395 MaxVersion: VersionTLS13,
4396 ClientAuth: RequestClientCert,
4397 },
4398 })
4399 tests = append(tests, testCase{
4400 testType: serverTest,
4401 name: "ClientAuth-NoCertificate-Server-TLS13",
4402 config: Config{
4403 MaxVersion: VersionTLS13,
4404 },
4405 // Setting SSL_VERIFY_PEER allows anonymous clients.
4406 flags: []string{"-verify-peer"},
4407 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004408 }
4409 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004410 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004411 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004412 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004413 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004414 ClientAuth: RequireAnyClientCert,
4415 },
4416 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004417 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4418 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004419 },
4420 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004421 tests = append(tests, testCase{
4422 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004423 name: "ClientAuth-RSA-Client-TLS13",
4424 config: Config{
4425 MaxVersion: VersionTLS13,
4426 ClientAuth: RequireAnyClientCert,
4427 },
4428 flags: []string{
4429 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4430 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4431 },
4432 })
4433 tests = append(tests, testCase{
4434 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004435 name: "ClientAuth-ECDSA-Client",
4436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004437 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004438 ClientAuth: RequireAnyClientCert,
4439 },
4440 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004441 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4442 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004443 },
4444 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004445 tests = append(tests, testCase{
4446 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004447 name: "ClientAuth-ECDSA-Client-TLS13",
4448 config: Config{
4449 MaxVersion: VersionTLS13,
4450 ClientAuth: RequireAnyClientCert,
4451 },
4452 flags: []string{
4453 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4454 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4455 },
4456 })
4457 tests = append(tests, testCase{
4458 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004459 name: "ClientAuth-NoCertificate-OldCallback",
4460 config: Config{
4461 MaxVersion: VersionTLS12,
4462 ClientAuth: RequestClientCert,
4463 },
4464 flags: []string{"-use-old-client-cert-callback"},
4465 })
4466 tests = append(tests, testCase{
4467 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004468 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4469 config: Config{
4470 MaxVersion: VersionTLS13,
4471 ClientAuth: RequestClientCert,
4472 },
4473 flags: []string{"-use-old-client-cert-callback"},
4474 })
4475 tests = append(tests, testCase{
4476 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004477 name: "ClientAuth-OldCallback",
4478 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004479 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004480 ClientAuth: RequireAnyClientCert,
4481 },
4482 flags: []string{
4483 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4484 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4485 "-use-old-client-cert-callback",
4486 },
4487 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004488 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004489 testType: clientTest,
4490 name: "ClientAuth-OldCallback-TLS13",
4491 config: Config{
4492 MaxVersion: VersionTLS13,
4493 ClientAuth: RequireAnyClientCert,
4494 },
4495 flags: []string{
4496 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4497 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4498 "-use-old-client-cert-callback",
4499 },
4500 })
4501 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004502 testType: serverTest,
4503 name: "ClientAuth-Server",
4504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004505 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004506 Certificates: []Certificate{rsaCertificate},
4507 },
4508 flags: []string{"-require-any-client-certificate"},
4509 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004510 tests = append(tests, testCase{
4511 testType: serverTest,
4512 name: "ClientAuth-Server-TLS13",
4513 config: Config{
4514 MaxVersion: VersionTLS13,
4515 Certificates: []Certificate{rsaCertificate},
4516 },
4517 flags: []string{"-require-any-client-certificate"},
4518 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004519
David Benjamin4c3ddf72016-06-29 18:13:53 -04004520 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004521 tests = append(tests, testCase{
4522 testType: serverTest,
4523 name: "Basic-Server-RSA",
4524 config: Config{
4525 MaxVersion: VersionTLS12,
4526 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4527 },
4528 flags: []string{
4529 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4530 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4531 },
4532 })
4533 tests = append(tests, testCase{
4534 testType: serverTest,
4535 name: "Basic-Server-ECDHE-RSA",
4536 config: Config{
4537 MaxVersion: VersionTLS12,
4538 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4539 },
4540 flags: []string{
4541 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4542 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4543 },
4544 })
4545 tests = append(tests, testCase{
4546 testType: serverTest,
4547 name: "Basic-Server-ECDHE-ECDSA",
4548 config: Config{
4549 MaxVersion: VersionTLS12,
4550 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4551 },
4552 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004553 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4554 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004555 },
4556 })
David Benjamin69522112017-03-28 15:38:29 -05004557 tests = append(tests, testCase{
4558 testType: serverTest,
4559 name: "Basic-Server-Ed25519",
4560 config: Config{
4561 MaxVersion: VersionTLS12,
4562 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4563 },
4564 flags: []string{
4565 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4566 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4567 "-enable-ed25519",
4568 },
4569 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004570
David Benjamin760b1dd2015-05-15 23:33:48 -04004571 // No session ticket support; server doesn't send NewSessionTicket.
4572 tests = append(tests, testCase{
4573 name: "SessionTicketsDisabled-Client",
4574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004575 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004576 SessionTicketsDisabled: true,
4577 },
4578 })
4579 tests = append(tests, testCase{
4580 testType: serverTest,
4581 name: "SessionTicketsDisabled-Server",
4582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004583 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004584 SessionTicketsDisabled: true,
4585 },
4586 })
4587
4588 // Skip ServerKeyExchange in PSK key exchange if there's no
4589 // identity hint.
4590 tests = append(tests, testCase{
4591 name: "EmptyPSKHint-Client",
4592 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004593 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004594 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4595 PreSharedKey: []byte("secret"),
4596 },
4597 flags: []string{"-psk", "secret"},
4598 })
4599 tests = append(tests, testCase{
4600 testType: serverTest,
4601 name: "EmptyPSKHint-Server",
4602 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004603 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004604 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4605 PreSharedKey: []byte("secret"),
4606 },
4607 flags: []string{"-psk", "secret"},
4608 })
4609
David Benjamin4c3ddf72016-06-29 18:13:53 -04004610 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004611 tests = append(tests, testCase{
4612 testType: clientTest,
4613 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004614 config: Config{
4615 MaxVersion: VersionTLS12,
4616 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004617 flags: []string{
4618 "-enable-ocsp-stapling",
4619 "-expect-ocsp-response",
4620 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004621 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004622 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004623 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004624 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004625 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004626 testType: serverTest,
4627 name: "OCSPStapling-Server",
4628 config: Config{
4629 MaxVersion: VersionTLS12,
4630 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004631 expectedOCSPResponse: testOCSPResponse,
4632 flags: []string{
4633 "-ocsp-response",
4634 base64.StdEncoding.EncodeToString(testOCSPResponse),
4635 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004636 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004637 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004638 tests = append(tests, testCase{
4639 testType: clientTest,
4640 name: "OCSPStapling-Client-TLS13",
4641 config: Config{
4642 MaxVersion: VersionTLS13,
4643 },
4644 flags: []string{
4645 "-enable-ocsp-stapling",
4646 "-expect-ocsp-response",
4647 base64.StdEncoding.EncodeToString(testOCSPResponse),
4648 "-verify-peer",
4649 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004650 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004651 })
4652 tests = append(tests, testCase{
4653 testType: serverTest,
4654 name: "OCSPStapling-Server-TLS13",
4655 config: Config{
4656 MaxVersion: VersionTLS13,
4657 },
4658 expectedOCSPResponse: testOCSPResponse,
4659 flags: []string{
4660 "-ocsp-response",
4661 base64.StdEncoding.EncodeToString(testOCSPResponse),
4662 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004663 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004664 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004665
David Benjamin4c3ddf72016-06-29 18:13:53 -04004666 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004667 for _, vers := range tlsVersions {
4668 if config.protocol == dtls && !vers.hasDTLS {
4669 continue
4670 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004671 for _, useCustomCallback := range []bool{false, true} {
4672 for _, testType := range []testType{clientTest, serverTest} {
4673 suffix := "-Client"
4674 if testType == serverTest {
4675 suffix = "-Server"
4676 }
4677 suffix += "-" + vers.name
4678 if useCustomCallback {
4679 suffix += "-CustomCallback"
4680 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004681
David Benjamin3a1dd462017-07-11 16:13:10 -04004682 flags := []string{"-verify-peer"}
4683 if testType == serverTest {
4684 flags = append(flags, "-require-any-client-certificate")
4685 }
4686 if useCustomCallback {
4687 flags = append(flags, "-use-custom-verify-callback")
4688 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004689
David Benjamin3a1dd462017-07-11 16:13:10 -04004690 tests = append(tests, testCase{
4691 testType: testType,
4692 name: "CertificateVerificationSucceed" + suffix,
4693 config: Config{
4694 MaxVersion: vers.version,
4695 Certificates: []Certificate{rsaCertificate},
4696 },
4697 tls13Variant: vers.tls13Variant,
4698 flags: append([]string{"-expect-verify-result"}, flags...),
4699 resumeSession: true,
4700 })
4701 tests = append(tests, testCase{
4702 testType: testType,
4703 name: "CertificateVerificationFail" + suffix,
4704 config: Config{
4705 MaxVersion: vers.version,
4706 Certificates: []Certificate{rsaCertificate},
4707 },
4708 tls13Variant: vers.tls13Variant,
4709 flags: append([]string{"-verify-fail"}, flags...),
4710 shouldFail: true,
4711 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4712 })
4713 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004714 }
4715
4716 // By default, the client is in a soft fail mode where the peer
4717 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004718 tests = append(tests, testCase{
4719 testType: clientTest,
4720 name: "CertificateVerificationSoftFail-" + vers.name,
4721 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004722 MaxVersion: vers.version,
4723 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004724 },
David Benjamina5022392017-07-10 17:40:39 -04004725 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004726 flags: []string{
4727 "-verify-fail",
4728 "-expect-verify-result",
4729 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004730 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004731 })
4732 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004733
David Benjamin1d4f4c02016-07-26 18:03:08 -04004734 tests = append(tests, testCase{
4735 name: "ShimSendAlert",
4736 flags: []string{"-send-alert"},
4737 shimWritesFirst: true,
4738 shouldFail: true,
4739 expectedLocalError: "remote error: decompression failure",
4740 })
4741
David Benjamin582ba042016-07-07 12:33:25 -07004742 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004743 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004744 name: "Renegotiate-Client",
4745 config: Config{
4746 MaxVersion: VersionTLS12,
4747 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004748 renegotiate: 1,
4749 flags: []string{
4750 "-renegotiate-freely",
4751 "-expect-total-renegotiations", "1",
4752 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004753 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004754
David Benjamin47921102016-07-28 11:29:18 -04004755 tests = append(tests, testCase{
4756 name: "SendHalfHelloRequest",
4757 config: Config{
4758 MaxVersion: VersionTLS12,
4759 Bugs: ProtocolBugs{
4760 PackHelloRequestWithFinished: config.packHandshakeFlight,
4761 },
4762 },
4763 sendHalfHelloRequest: true,
4764 flags: []string{"-renegotiate-ignore"},
4765 shouldFail: true,
4766 expectedError: ":UNEXPECTED_RECORD:",
4767 })
4768
David Benjamin760b1dd2015-05-15 23:33:48 -04004769 // NPN on client and server; results in post-handshake message.
4770 tests = append(tests, testCase{
4771 name: "NPN-Client",
4772 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004773 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004774 NextProtos: []string{"foo"},
4775 },
4776 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004777 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004778 expectedNextProto: "foo",
4779 expectedNextProtoType: npn,
4780 })
4781 tests = append(tests, testCase{
4782 testType: serverTest,
4783 name: "NPN-Server",
4784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004785 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004786 NextProtos: []string{"bar"},
4787 },
4788 flags: []string{
4789 "-advertise-npn", "\x03foo\x03bar\x03baz",
4790 "-expect-next-proto", "bar",
4791 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004792 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004793 expectedNextProto: "bar",
4794 expectedNextProtoType: npn,
4795 })
4796
4797 // TODO(davidben): Add tests for when False Start doesn't trigger.
4798
4799 // Client does False Start and negotiates NPN.
4800 tests = append(tests, testCase{
4801 name: "FalseStart",
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 Bugs: ProtocolBugs{
4807 ExpectFalseStart: true,
4808 },
4809 },
4810 flags: []string{
4811 "-false-start",
4812 "-select-next-proto", "foo",
4813 },
4814 shimWritesFirst: true,
4815 resumeSession: true,
4816 })
4817
4818 // Client does False Start and negotiates ALPN.
4819 tests = append(tests, testCase{
4820 name: "FalseStart-ALPN",
4821 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004822 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004823 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4824 NextProtos: []string{"foo"},
4825 Bugs: ProtocolBugs{
4826 ExpectFalseStart: true,
4827 },
4828 },
4829 flags: []string{
4830 "-false-start",
4831 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004832 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004833 },
4834 shimWritesFirst: true,
4835 resumeSession: true,
4836 })
4837
David Benjamin760b1dd2015-05-15 23:33:48 -04004838 // False Start without session tickets.
4839 tests = append(tests, testCase{
4840 name: "FalseStart-SessionTicketsDisabled",
4841 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004842 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004843 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4844 NextProtos: []string{"foo"},
4845 SessionTicketsDisabled: true,
4846 Bugs: ProtocolBugs{
4847 ExpectFalseStart: true,
4848 },
4849 },
4850 flags: []string{
4851 "-false-start",
4852 "-select-next-proto", "foo",
4853 },
4854 shimWritesFirst: true,
4855 })
4856
4857 // Server parses a V2ClientHello.
4858 tests = append(tests, testCase{
4859 testType: serverTest,
4860 name: "SendV2ClientHello",
4861 config: Config{
4862 // Choose a cipher suite that does not involve
4863 // elliptic curves, so no extensions are
4864 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004865 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004866 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004867 Bugs: ProtocolBugs{
4868 SendV2ClientHello: true,
4869 },
4870 },
David Benjamin78b8b992017-08-01 18:38:41 -04004871 flags: []string{
4872 "-expect-msg-callback",
4873 `read v2clienthello
4874write hs 2
4875write hs 11
4876write hs 14
4877read hs 16
4878read ccs
4879read hs 20
4880write ccs
4881write hs 20
4882read alert 1 0
4883`,
4884 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004885 })
4886
Nick Harper60a85cb2016-09-23 16:25:11 -07004887 // Test Channel ID
4888 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004889 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004890 continue
4891 }
4892 // Client sends a Channel ID.
4893 tests = append(tests, testCase{
4894 name: "ChannelID-Client-" + ver.name,
4895 config: Config{
4896 MaxVersion: ver.version,
4897 RequestChannelID: true,
4898 },
David Benjamina5022392017-07-10 17:40:39 -04004899 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004900 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4901 resumeSession: true,
4902 expectChannelID: true,
4903 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004904
Nick Harper60a85cb2016-09-23 16:25:11 -07004905 // Server accepts a Channel ID.
4906 tests = append(tests, testCase{
4907 testType: serverTest,
4908 name: "ChannelID-Server-" + ver.name,
4909 config: Config{
4910 MaxVersion: ver.version,
4911 ChannelID: channelIDKey,
4912 },
David Benjamina5022392017-07-10 17:40:39 -04004913 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004914 flags: []string{
4915 "-expect-channel-id",
4916 base64.StdEncoding.EncodeToString(channelIDBytes),
4917 },
4918 resumeSession: true,
4919 expectChannelID: true,
4920 })
4921
4922 tests = append(tests, testCase{
4923 testType: serverTest,
4924 name: "InvalidChannelIDSignature-" + ver.name,
4925 config: Config{
4926 MaxVersion: ver.version,
4927 ChannelID: channelIDKey,
4928 Bugs: ProtocolBugs{
4929 InvalidChannelIDSignature: true,
4930 },
4931 },
David Benjamina5022392017-07-10 17:40:39 -04004932 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004933 flags: []string{"-enable-channel-id"},
4934 shouldFail: true,
4935 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4936 })
David Benjamin634f4752017-07-01 11:08:41 -04004937
4938 if ver.version < VersionTLS13 {
4939 // Channel ID requires ECDHE ciphers.
4940 tests = append(tests, testCase{
4941 testType: serverTest,
4942 name: "ChannelID-NoECDHE-" + ver.name,
4943 config: Config{
4944 MaxVersion: ver.version,
4945 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4946 ChannelID: channelIDKey,
4947 },
4948 expectChannelID: false,
4949 flags: []string{"-enable-channel-id"},
4950 })
4951
4952 // Sanity-check setting expectChannelID false works.
4953 tests = append(tests, testCase{
4954 testType: serverTest,
4955 name: "ChannelID-ECDHE-" + ver.name,
4956 config: Config{
4957 MaxVersion: ver.version,
4958 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4959 ChannelID: channelIDKey,
4960 },
4961 expectChannelID: false,
4962 flags: []string{"-enable-channel-id"},
4963 shouldFail: true,
4964 expectedLocalError: "channel ID unexpectedly negotiated",
4965 })
4966 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004967 }
David Benjamin30789da2015-08-29 22:56:45 -04004968
David Benjaminf8fcdf32016-06-08 15:56:13 -04004969 // Channel ID and NPN at the same time, to ensure their relative
4970 // ordering is correct.
4971 tests = append(tests, testCase{
4972 name: "ChannelID-NPN-Client",
4973 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004974 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004975 RequestChannelID: true,
4976 NextProtos: []string{"foo"},
4977 },
4978 flags: []string{
4979 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4980 "-select-next-proto", "foo",
4981 },
4982 resumeSession: true,
4983 expectChannelID: true,
4984 expectedNextProto: "foo",
4985 expectedNextProtoType: npn,
4986 })
4987 tests = append(tests, testCase{
4988 testType: serverTest,
4989 name: "ChannelID-NPN-Server",
4990 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004991 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004992 ChannelID: channelIDKey,
4993 NextProtos: []string{"bar"},
4994 },
4995 flags: []string{
4996 "-expect-channel-id",
4997 base64.StdEncoding.EncodeToString(channelIDBytes),
4998 "-advertise-npn", "\x03foo\x03bar\x03baz",
4999 "-expect-next-proto", "bar",
5000 },
5001 resumeSession: true,
5002 expectChannelID: true,
5003 expectedNextProto: "bar",
5004 expectedNextProtoType: npn,
5005 })
5006
David Benjamin30789da2015-08-29 22:56:45 -04005007 // Bidirectional shutdown with the runner initiating.
5008 tests = append(tests, testCase{
5009 name: "Shutdown-Runner",
5010 config: Config{
5011 Bugs: ProtocolBugs{
5012 ExpectCloseNotify: true,
5013 },
5014 },
5015 flags: []string{"-check-close-notify"},
5016 })
5017
David Benjamine3843d42017-03-25 18:00:56 -05005018 if !config.implicitHandshake {
5019 // Bidirectional shutdown with the shim initiating. The runner,
5020 // in the meantime, sends garbage before the close_notify which
5021 // the shim must ignore. This test is disabled under implicit
5022 // handshake tests because the shim never reads or writes.
5023 tests = append(tests, testCase{
5024 name: "Shutdown-Shim",
5025 config: Config{
5026 MaxVersion: VersionTLS12,
5027 Bugs: ProtocolBugs{
5028 ExpectCloseNotify: true,
5029 },
David Benjamin30789da2015-08-29 22:56:45 -04005030 },
David Benjamine3843d42017-03-25 18:00:56 -05005031 shimShutsDown: true,
5032 sendEmptyRecords: 1,
5033 sendWarningAlerts: 1,
5034 flags: []string{"-check-close-notify"},
5035 })
5036 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005037 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005038 // TODO(davidben): DTLS 1.3 will want a similar thing for
5039 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04005040 tests = append(tests, testCase{
5041 name: "SkipHelloVerifyRequest",
5042 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005043 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04005044 Bugs: ProtocolBugs{
5045 SkipHelloVerifyRequest: true,
5046 },
5047 },
5048 })
5049 }
5050
David Benjamin760b1dd2015-05-15 23:33:48 -04005051 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07005052 test.protocol = config.protocol
5053 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005054 test.name += "-DTLS"
5055 }
David Benjamin582ba042016-07-07 12:33:25 -07005056 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05005057 test.name += "-Async"
5058 test.flags = append(test.flags, "-async")
5059 } else {
5060 test.name += "-Sync"
5061 }
David Benjamin582ba042016-07-07 12:33:25 -07005062 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005063 test.name += "-SplitHandshakeRecords"
5064 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005065 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005066 test.config.Bugs.MaxPacketLength = 256
5067 test.flags = append(test.flags, "-mtu", "256")
5068 }
5069 }
David Benjamin582ba042016-07-07 12:33:25 -07005070 if config.packHandshakeFlight {
5071 test.name += "-PackHandshakeFlight"
5072 test.config.Bugs.PackHandshakeFlight = true
5073 }
David Benjamine3843d42017-03-25 18:00:56 -05005074 if config.implicitHandshake {
5075 test.name += "-ImplicitHandshake"
5076 test.flags = append(test.flags, "-implicit-handshake")
5077 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005078 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005079 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005080}
5081
Adam Langley524e7172015-02-20 16:04:00 -08005082func addDDoSCallbackTests() {
5083 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005084 for _, resume := range []bool{false, true} {
5085 suffix := "Resume"
5086 if resume {
5087 suffix = "No" + suffix
5088 }
5089
5090 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005091 testType: serverTest,
5092 name: "Server-DDoS-OK-" + suffix,
5093 config: Config{
5094 MaxVersion: VersionTLS12,
5095 },
Adam Langley524e7172015-02-20 16:04:00 -08005096 flags: []string{"-install-ddos-callback"},
5097 resumeSession: resume,
5098 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005099 testCases = append(testCases, testCase{
5100 testType: serverTest,
5101 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5102 config: Config{
5103 MaxVersion: VersionTLS13,
5104 },
5105 flags: []string{"-install-ddos-callback"},
5106 resumeSession: resume,
5107 })
Adam Langley524e7172015-02-20 16:04:00 -08005108
5109 failFlag := "-fail-ddos-callback"
5110 if resume {
5111 failFlag = "-fail-second-ddos-callback"
5112 }
5113 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005114 testType: serverTest,
5115 name: "Server-DDoS-Reject-" + suffix,
5116 config: Config{
5117 MaxVersion: VersionTLS12,
5118 },
David Benjamin2c66e072016-09-16 15:58:00 -04005119 flags: []string{"-install-ddos-callback", failFlag},
5120 resumeSession: resume,
5121 shouldFail: true,
5122 expectedError: ":CONNECTION_REJECTED:",
5123 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005124 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005125 testCases = append(testCases, testCase{
5126 testType: serverTest,
5127 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5128 config: Config{
5129 MaxVersion: VersionTLS13,
5130 },
David Benjamin2c66e072016-09-16 15:58:00 -04005131 flags: []string{"-install-ddos-callback", failFlag},
5132 resumeSession: resume,
5133 shouldFail: true,
5134 expectedError: ":CONNECTION_REJECTED:",
5135 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005136 })
Adam Langley524e7172015-02-20 16:04:00 -08005137 }
5138}
5139
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005140func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005141 for _, protocol := range []protocol{tls, dtls} {
5142 for _, shimVers := range allVersions(protocol) {
5143 // Assemble flags to disable all newer versions on the shim.
5144 var flags []string
5145 for _, vers := range allVersions(protocol) {
5146 if vers.version > shimVers.version {
5147 flags = append(flags, vers.excludeFlag)
5148 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005149 }
Steven Valdez520e1222017-06-13 12:45:25 -04005150
5151 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5152
5153 if shimVers.tls13Variant != 0 {
5154 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5155 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5156 }
5157
5158 // Test configuring the runner's maximum version.
5159 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005160 expectedVersion := shimVers.version
5161 if runnerVers.version < shimVers.version {
5162 expectedVersion = runnerVers.version
5163 }
Steven Valdez520e1222017-06-13 12:45:25 -04005164 // When running and shim have different TLS 1.3 variants enabled,
5165 // shim clients are expected to fall back to TLS 1.2, while shim
5166 // servers support both variants when enabled when the experiment is
5167 // enabled.
5168 expectedServerVersion := expectedVersion
5169 expectedClientVersion := expectedVersion
5170 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5171 expectedClientVersion = VersionTLS12
5172 expectedServerVersion = VersionTLS12
5173 if shimVers.tls13Variant != TLS13Default {
5174 expectedServerVersion = VersionTLS13
5175 }
5176 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005177
David Benjamin8b8c0062014-11-23 02:47:52 -05005178 suffix := shimVers.name + "-" + runnerVers.name
5179 if protocol == dtls {
5180 suffix += "-DTLS"
5181 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005182
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005183 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005184 clientVers := shimVers.version
5185 if clientVers > VersionTLS10 {
5186 clientVers = VersionTLS10
5187 }
Steven Valdez520e1222017-06-13 12:45:25 -04005188 clientVers = recordVersionToWire(clientVers, protocol)
5189 serverVers := expectedServerVersion
5190 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005191 serverVers = VersionTLS10
Steven Valdez16821262017-09-08 17:03:42 -04005192 if runnerVers.tls13Variant == TLS13Experiment2 {
5193 serverVers = VersionTLS12
5194 }
Nick Harper1fd39d82016-06-14 18:14:35 -07005195 }
Steven Valdez520e1222017-06-13 12:45:25 -04005196 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005197
David Benjamin8b8c0062014-11-23 02:47:52 -05005198 testCases = append(testCases, testCase{
5199 protocol: protocol,
5200 testType: clientTest,
5201 name: "VersionNegotiation-Client-" + suffix,
5202 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005203 MaxVersion: runnerVers.version,
5204 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005205 Bugs: ProtocolBugs{
5206 ExpectInitialRecordVersion: clientVers,
5207 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005208 },
5209 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005210 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005211 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005212 testCases = append(testCases, testCase{
5213 protocol: protocol,
5214 testType: clientTest,
5215 name: "VersionNegotiation-Client2-" + suffix,
5216 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005217 MaxVersion: runnerVers.version,
5218 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005219 Bugs: ProtocolBugs{
5220 ExpectInitialRecordVersion: clientVers,
5221 },
5222 },
Steven Valdez520e1222017-06-13 12:45:25 -04005223 flags: flags2,
5224 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005225 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005226
5227 testCases = append(testCases, testCase{
5228 protocol: protocol,
5229 testType: serverTest,
5230 name: "VersionNegotiation-Server-" + suffix,
5231 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005232 MaxVersion: runnerVers.version,
5233 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005234 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005235 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005236 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005237 },
5238 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005239 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005240 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005241 testCases = append(testCases, testCase{
5242 protocol: protocol,
5243 testType: serverTest,
5244 name: "VersionNegotiation-Server2-" + suffix,
5245 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005246 MaxVersion: runnerVers.version,
5247 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005248 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005249 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005250 },
5251 },
Steven Valdez520e1222017-06-13 12:45:25 -04005252 flags: flags2,
5253 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005254 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005255 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005256 }
5257 }
David Benjamin95c69562016-06-29 18:15:03 -04005258
Steven Valdezfdd10992016-09-15 16:27:05 -04005259 // Test the version extension at all versions.
5260 for _, vers := range tlsVersions {
5261 protocols := []protocol{tls}
5262 if vers.hasDTLS {
5263 protocols = append(protocols, dtls)
5264 }
5265 for _, protocol := range protocols {
5266 suffix := vers.name
5267 if protocol == dtls {
5268 suffix += "-DTLS"
5269 }
5270
Steven Valdezfdd10992016-09-15 16:27:05 -04005271 testCases = append(testCases, testCase{
5272 protocol: protocol,
5273 testType: serverTest,
5274 name: "VersionNegotiationExtension-" + suffix,
5275 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005276 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005277 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005278 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005279 },
5280 },
5281 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005282 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005283 })
5284 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005285 }
5286
5287 // If all versions are unknown, negotiation fails.
5288 testCases = append(testCases, testCase{
5289 testType: serverTest,
5290 name: "NoSupportedVersions",
5291 config: Config{
5292 Bugs: ProtocolBugs{
5293 SendSupportedVersions: []uint16{0x1111},
5294 },
5295 },
5296 shouldFail: true,
5297 expectedError: ":UNSUPPORTED_PROTOCOL:",
5298 })
5299 testCases = append(testCases, testCase{
5300 protocol: dtls,
5301 testType: serverTest,
5302 name: "NoSupportedVersions-DTLS",
5303 config: Config{
5304 Bugs: ProtocolBugs{
5305 SendSupportedVersions: []uint16{0x1111},
5306 },
5307 },
5308 shouldFail: true,
5309 expectedError: ":UNSUPPORTED_PROTOCOL:",
5310 })
5311
5312 testCases = append(testCases, testCase{
5313 testType: serverTest,
5314 name: "ClientHelloVersionTooHigh",
5315 config: Config{
5316 MaxVersion: VersionTLS13,
5317 Bugs: ProtocolBugs{
5318 SendClientVersion: 0x0304,
5319 OmitSupportedVersions: true,
5320 },
5321 },
5322 expectedVersion: VersionTLS12,
5323 })
5324
5325 testCases = append(testCases, testCase{
5326 testType: serverTest,
5327 name: "ConflictingVersionNegotiation",
5328 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005329 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005330 SendClientVersion: VersionTLS12,
5331 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005332 },
5333 },
David Benjaminad75a662016-09-30 15:42:59 -04005334 // The extension takes precedence over the ClientHello version.
5335 expectedVersion: VersionTLS11,
5336 })
5337
5338 testCases = append(testCases, testCase{
5339 testType: serverTest,
5340 name: "ConflictingVersionNegotiation-2",
5341 config: Config{
5342 Bugs: ProtocolBugs{
5343 SendClientVersion: VersionTLS11,
5344 SendSupportedVersions: []uint16{VersionTLS12},
5345 },
5346 },
5347 // The extension takes precedence over the ClientHello version.
5348 expectedVersion: VersionTLS12,
5349 })
5350
5351 testCases = append(testCases, testCase{
5352 testType: serverTest,
5353 name: "RejectFinalTLS13",
5354 config: Config{
5355 Bugs: ProtocolBugs{
5356 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5357 },
5358 },
5359 // We currently implement a draft TLS 1.3 version. Ensure that
5360 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005361 expectedVersion: VersionTLS12,
5362 })
5363
Steven Valdez038da9b2017-07-10 12:57:25 -04005364 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5365 // the ServerHello.
5366 testCases = append(testCases, testCase{
5367 testType: clientTest,
5368 name: "SupportedVersionSelection-TLS12",
5369 config: Config{
5370 MaxVersion: VersionTLS12,
5371 Bugs: ProtocolBugs{
5372 SendServerSupportedExtensionVersion: VersionTLS12,
5373 },
5374 },
5375 shouldFail: true,
5376 expectedError: ":UNEXPECTED_EXTENSION:",
5377 })
5378
5379 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5380 // supported_versions extension in the ServerHello.
5381 testCases = append(testCases, testCase{
5382 testType: clientTest,
5383 name: "SupportedVersionSelection-TLS13",
5384 config: Config{
5385 MaxVersion: VersionTLS13,
5386 Bugs: ProtocolBugs{
5387 SendServerSupportedExtensionVersion: tls13DraftVersion,
5388 },
5389 },
5390 shouldFail: true,
5391 expectedError: ":UNEXPECTED_EXTENSION:",
5392 })
5393
Brian Smithf85d3232016-10-28 10:34:06 -10005394 // Test that the maximum version is selected regardless of the
5395 // client-sent order.
5396 testCases = append(testCases, testCase{
5397 testType: serverTest,
5398 name: "IgnoreClientVersionOrder",
5399 config: Config{
5400 Bugs: ProtocolBugs{
5401 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5402 },
5403 },
5404 expectedVersion: VersionTLS13,
5405 })
5406
David Benjamin95c69562016-06-29 18:15:03 -04005407 // Test for version tolerance.
5408 testCases = append(testCases, testCase{
5409 testType: serverTest,
5410 name: "MinorVersionTolerance",
5411 config: Config{
5412 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005413 SendClientVersion: 0x03ff,
5414 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005415 },
5416 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005417 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005418 })
5419 testCases = append(testCases, testCase{
5420 testType: serverTest,
5421 name: "MajorVersionTolerance",
5422 config: Config{
5423 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005424 SendClientVersion: 0x0400,
5425 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005426 },
5427 },
David Benjaminad75a662016-09-30 15:42:59 -04005428 // TLS 1.3 must be negotiated with the supported_versions
5429 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005430 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005431 })
David Benjaminad75a662016-09-30 15:42:59 -04005432 testCases = append(testCases, testCase{
5433 testType: serverTest,
5434 name: "VersionTolerance-TLS13",
5435 config: Config{
5436 Bugs: ProtocolBugs{
5437 // Although TLS 1.3 does not use
5438 // ClientHello.version, it still tolerates high
5439 // values there.
5440 SendClientVersion: 0x0400,
5441 },
5442 },
5443 expectedVersion: VersionTLS13,
5444 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005445
David Benjamin95c69562016-06-29 18:15:03 -04005446 testCases = append(testCases, testCase{
5447 protocol: dtls,
5448 testType: serverTest,
5449 name: "MinorVersionTolerance-DTLS",
5450 config: Config{
5451 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005452 SendClientVersion: 0xfe00,
5453 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005454 },
5455 },
5456 expectedVersion: VersionTLS12,
5457 })
5458 testCases = append(testCases, testCase{
5459 protocol: dtls,
5460 testType: serverTest,
5461 name: "MajorVersionTolerance-DTLS",
5462 config: Config{
5463 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005464 SendClientVersion: 0xfdff,
5465 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005466 },
5467 },
5468 expectedVersion: VersionTLS12,
5469 })
5470
5471 // Test that versions below 3.0 are rejected.
5472 testCases = append(testCases, testCase{
5473 testType: serverTest,
5474 name: "VersionTooLow",
5475 config: Config{
5476 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005477 SendClientVersion: 0x0200,
5478 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005479 },
5480 },
5481 shouldFail: true,
5482 expectedError: ":UNSUPPORTED_PROTOCOL:",
5483 })
5484 testCases = append(testCases, testCase{
5485 protocol: dtls,
5486 testType: serverTest,
5487 name: "VersionTooLow-DTLS",
5488 config: Config{
5489 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005490 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005491 },
5492 },
5493 shouldFail: true,
5494 expectedError: ":UNSUPPORTED_PROTOCOL:",
5495 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005496
David Benjamin2dc02042016-09-19 19:57:37 -04005497 testCases = append(testCases, testCase{
5498 name: "ServerBogusVersion",
5499 config: Config{
5500 Bugs: ProtocolBugs{
5501 SendServerHelloVersion: 0x1234,
5502 },
5503 },
5504 shouldFail: true,
5505 expectedError: ":UNSUPPORTED_PROTOCOL:",
5506 })
5507
David Benjamin1f61f0d2016-07-10 12:20:35 -04005508 // Test TLS 1.3's downgrade signal.
5509 testCases = append(testCases, testCase{
5510 name: "Downgrade-TLS12-Client",
5511 config: Config{
5512 Bugs: ProtocolBugs{
5513 NegotiateVersion: VersionTLS12,
5514 },
5515 },
David Benjamin592b5322016-09-30 15:15:01 -04005516 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005517 // TODO(davidben): This test should fail once TLS 1.3 is final
5518 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005519 })
5520 testCases = append(testCases, testCase{
5521 testType: serverTest,
5522 name: "Downgrade-TLS12-Server",
5523 config: Config{
5524 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005525 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005526 },
5527 },
David Benjamin592b5322016-09-30 15:15:01 -04005528 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005529 // TODO(davidben): This test should fail once TLS 1.3 is final
5530 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005531 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005532}
5533
David Benjaminaccb4542014-12-12 23:44:33 -05005534func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005535 for _, protocol := range []protocol{tls, dtls} {
5536 for _, shimVers := range allVersions(protocol) {
5537 // Assemble flags to disable all older versions on the shim.
5538 var flags []string
5539 for _, vers := range allVersions(protocol) {
5540 if vers.version < shimVers.version {
5541 flags = append(flags, vers.excludeFlag)
5542 }
David Benjaminaccb4542014-12-12 23:44:33 -05005543 }
Steven Valdez520e1222017-06-13 12:45:25 -04005544
5545 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5546
5547 if shimVers.tls13Variant != 0 {
5548 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5549 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5550 }
5551
5552 for _, runnerVers := range allVersions(protocol) {
5553 // Different TLS 1.3 variants are incompatible with each other and don't
5554 // produce consistent minimum versions.
5555 //
5556 // TODO(davidben): Fold these tests (the main value is in the
5557 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5558 // on intended shim behavior, not the shim + runner combination.
5559 if shimVers.tls13Variant != runnerVers.tls13Variant {
5560 continue
5561 }
5562
David Benjaminaccb4542014-12-12 23:44:33 -05005563 suffix := shimVers.name + "-" + runnerVers.name
5564 if protocol == dtls {
5565 suffix += "-DTLS"
5566 }
David Benjaminaccb4542014-12-12 23:44:33 -05005567
David Benjaminaccb4542014-12-12 23:44:33 -05005568 var expectedVersion uint16
5569 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005570 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005571 if runnerVers.version >= shimVers.version {
5572 expectedVersion = runnerVers.version
5573 } else {
5574 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005575 expectedError = ":UNSUPPORTED_PROTOCOL:"
5576 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005577 }
5578
5579 testCases = append(testCases, testCase{
5580 protocol: protocol,
5581 testType: clientTest,
5582 name: "MinimumVersion-Client-" + suffix,
5583 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005584 MaxVersion: runnerVers.version,
5585 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005586 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005587 // Ensure the server does not decline to
5588 // select a version (versions extension) or
5589 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005590 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005591 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005592 },
David Benjaminaccb4542014-12-12 23:44:33 -05005593 },
David Benjamin87909c02014-12-13 01:55:01 -05005594 flags: flags,
5595 expectedVersion: expectedVersion,
5596 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005597 expectedError: expectedError,
5598 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005599 })
5600 testCases = append(testCases, testCase{
5601 protocol: protocol,
5602 testType: clientTest,
5603 name: "MinimumVersion-Client2-" + suffix,
5604 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005605 MaxVersion: runnerVers.version,
5606 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005607 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005608 // Ensure the server does not decline to
5609 // select a version (versions extension) or
5610 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005611 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005612 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005613 },
David Benjaminaccb4542014-12-12 23:44:33 -05005614 },
Steven Valdez520e1222017-06-13 12:45:25 -04005615 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005616 expectedVersion: expectedVersion,
5617 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005618 expectedError: expectedError,
5619 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005620 })
5621
5622 testCases = append(testCases, testCase{
5623 protocol: protocol,
5624 testType: serverTest,
5625 name: "MinimumVersion-Server-" + suffix,
5626 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005627 MaxVersion: runnerVers.version,
5628 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005629 },
David Benjamin87909c02014-12-13 01:55:01 -05005630 flags: flags,
5631 expectedVersion: expectedVersion,
5632 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005633 expectedError: expectedError,
5634 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005635 })
5636 testCases = append(testCases, testCase{
5637 protocol: protocol,
5638 testType: serverTest,
5639 name: "MinimumVersion-Server2-" + suffix,
5640 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005641 MaxVersion: runnerVers.version,
5642 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005643 },
Steven Valdez520e1222017-06-13 12:45:25 -04005644 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005645 expectedVersion: expectedVersion,
5646 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005647 expectedError: expectedError,
5648 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005649 })
5650 }
5651 }
5652 }
5653}
5654
David Benjamine78bfde2014-09-06 12:45:15 -04005655func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005656 // TODO(davidben): Extensions, where applicable, all move their server
5657 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5658 // tests for both. Also test interaction with 0-RTT when implemented.
5659
David Benjamin97d17d92016-07-14 16:12:00 -04005660 // Repeat extensions tests all versions except SSL 3.0.
5661 for _, ver := range tlsVersions {
5662 if ver.version == VersionSSL30 {
5663 continue
5664 }
5665
David Benjamin97d17d92016-07-14 16:12:00 -04005666 // Test that duplicate extensions are rejected.
5667 testCases = append(testCases, testCase{
5668 testType: clientTest,
5669 name: "DuplicateExtensionClient-" + ver.name,
5670 config: Config{
5671 MaxVersion: ver.version,
5672 Bugs: ProtocolBugs{
5673 DuplicateExtension: true,
5674 },
David Benjamine78bfde2014-09-06 12:45:15 -04005675 },
David Benjamina5022392017-07-10 17:40:39 -04005676 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005677 shouldFail: true,
5678 expectedLocalError: "remote error: error decoding message",
5679 })
5680 testCases = append(testCases, testCase{
5681 testType: serverTest,
5682 name: "DuplicateExtensionServer-" + ver.name,
5683 config: Config{
5684 MaxVersion: ver.version,
5685 Bugs: ProtocolBugs{
5686 DuplicateExtension: true,
5687 },
David Benjamine78bfde2014-09-06 12:45:15 -04005688 },
David Benjamina5022392017-07-10 17:40:39 -04005689 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005690 shouldFail: true,
5691 expectedLocalError: "remote error: error decoding message",
5692 })
5693
5694 // Test SNI.
5695 testCases = append(testCases, testCase{
5696 testType: clientTest,
5697 name: "ServerNameExtensionClient-" + ver.name,
5698 config: Config{
5699 MaxVersion: ver.version,
5700 Bugs: ProtocolBugs{
5701 ExpectServerName: "example.com",
5702 },
David Benjamine78bfde2014-09-06 12:45:15 -04005703 },
David Benjamina5022392017-07-10 17:40:39 -04005704 tls13Variant: ver.tls13Variant,
5705 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005706 })
5707 testCases = append(testCases, testCase{
5708 testType: clientTest,
5709 name: "ServerNameExtensionClientMismatch-" + ver.name,
5710 config: Config{
5711 MaxVersion: ver.version,
5712 Bugs: ProtocolBugs{
5713 ExpectServerName: "mismatch.com",
5714 },
David Benjamine78bfde2014-09-06 12:45:15 -04005715 },
David Benjamin97d17d92016-07-14 16:12:00 -04005716 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005717 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005718 shouldFail: true,
5719 expectedLocalError: "tls: unexpected server name",
5720 })
5721 testCases = append(testCases, testCase{
5722 testType: clientTest,
5723 name: "ServerNameExtensionClientMissing-" + ver.name,
5724 config: Config{
5725 MaxVersion: ver.version,
5726 Bugs: ProtocolBugs{
5727 ExpectServerName: "missing.com",
5728 },
David Benjamine78bfde2014-09-06 12:45:15 -04005729 },
David Benjamina5022392017-07-10 17:40:39 -04005730 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005731 shouldFail: true,
5732 expectedLocalError: "tls: unexpected server name",
5733 })
5734 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005735 testType: clientTest,
5736 name: "TolerateServerNameAck-" + ver.name,
5737 config: Config{
5738 MaxVersion: ver.version,
5739 Bugs: ProtocolBugs{
5740 SendServerNameAck: true,
5741 },
5742 },
David Benjamina5022392017-07-10 17:40:39 -04005743 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005744 flags: []string{"-host-name", "example.com"},
5745 resumeSession: true,
5746 })
5747 testCases = append(testCases, testCase{
5748 testType: clientTest,
5749 name: "UnsolicitedServerNameAck-" + ver.name,
5750 config: Config{
5751 MaxVersion: ver.version,
5752 Bugs: ProtocolBugs{
5753 SendServerNameAck: true,
5754 },
5755 },
David Benjamina5022392017-07-10 17:40:39 -04005756 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005757 shouldFail: true,
5758 expectedError: ":UNEXPECTED_EXTENSION:",
5759 expectedLocalError: "remote error: unsupported extension",
5760 })
5761 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005762 testType: serverTest,
5763 name: "ServerNameExtensionServer-" + ver.name,
5764 config: Config{
5765 MaxVersion: ver.version,
5766 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005767 },
David Benjamina5022392017-07-10 17:40:39 -04005768 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005769 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005770 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005771 })
5772
5773 // Test ALPN.
5774 testCases = append(testCases, testCase{
5775 testType: clientTest,
5776 name: "ALPNClient-" + ver.name,
5777 config: Config{
5778 MaxVersion: ver.version,
5779 NextProtos: []string{"foo"},
5780 },
5781 flags: []string{
5782 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5783 "-expect-alpn", "foo",
5784 },
David Benjamina5022392017-07-10 17:40:39 -04005785 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005786 expectedNextProto: "foo",
5787 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005788 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005789 })
5790 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005791 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005792 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005793 config: Config{
5794 MaxVersion: ver.version,
5795 Bugs: ProtocolBugs{
5796 SendALPN: "baz",
5797 },
5798 },
5799 flags: []string{
5800 "-advertise-alpn", "\x03foo\x03bar",
5801 },
David Benjamina5022392017-07-10 17:40:39 -04005802 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005803 shouldFail: true,
5804 expectedError: ":INVALID_ALPN_PROTOCOL:",
5805 expectedLocalError: "remote error: illegal parameter",
5806 })
5807 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005808 testType: clientTest,
5809 name: "ALPNClient-AllowUnknown-" + ver.name,
5810 config: Config{
5811 MaxVersion: ver.version,
5812 Bugs: ProtocolBugs{
5813 SendALPN: "baz",
5814 },
5815 },
5816 flags: []string{
5817 "-advertise-alpn", "\x03foo\x03bar",
5818 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005819 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005820 },
David Benjamina5022392017-07-10 17:40:39 -04005821 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005822 })
5823 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005824 testType: serverTest,
5825 name: "ALPNServer-" + ver.name,
5826 config: Config{
5827 MaxVersion: ver.version,
5828 NextProtos: []string{"foo", "bar", "baz"},
5829 },
5830 flags: []string{
5831 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5832 "-select-alpn", "foo",
5833 },
David Benjamina5022392017-07-10 17:40:39 -04005834 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005835 expectedNextProto: "foo",
5836 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005837 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005838 })
5839 testCases = append(testCases, testCase{
5840 testType: serverTest,
5841 name: "ALPNServer-Decline-" + ver.name,
5842 config: Config{
5843 MaxVersion: ver.version,
5844 NextProtos: []string{"foo", "bar", "baz"},
5845 },
5846 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005847 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005848 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005849 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005850 })
5851
David Benjamin25fe85b2016-08-09 20:00:32 -04005852 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5853 // called once.
5854 testCases = append(testCases, testCase{
5855 testType: serverTest,
5856 name: "ALPNServer-Async-" + ver.name,
5857 config: Config{
5858 MaxVersion: ver.version,
5859 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005860 // Prior to TLS 1.3, exercise the asynchronous session callback.
5861 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005862 },
5863 flags: []string{
5864 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5865 "-select-alpn", "foo",
5866 "-async",
5867 },
David Benjamina5022392017-07-10 17:40:39 -04005868 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005869 expectedNextProto: "foo",
5870 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005871 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005872 })
5873
David Benjamin97d17d92016-07-14 16:12:00 -04005874 var emptyString string
5875 testCases = append(testCases, testCase{
5876 testType: clientTest,
5877 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5878 config: Config{
5879 MaxVersion: ver.version,
5880 NextProtos: []string{""},
5881 Bugs: ProtocolBugs{
5882 // A server returning an empty ALPN protocol
5883 // should be rejected.
5884 ALPNProtocol: &emptyString,
5885 },
5886 },
5887 flags: []string{
5888 "-advertise-alpn", "\x03foo",
5889 },
David Benjamina5022392017-07-10 17:40:39 -04005890 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005891 shouldFail: true,
5892 expectedError: ":PARSE_TLSEXT:",
5893 })
5894 testCases = append(testCases, testCase{
5895 testType: serverTest,
5896 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5897 config: Config{
5898 MaxVersion: ver.version,
5899 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005900 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005901 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005902 },
David Benjamin97d17d92016-07-14 16:12:00 -04005903 flags: []string{
5904 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005905 },
David Benjamina5022392017-07-10 17:40:39 -04005906 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005907 shouldFail: true,
5908 expectedError: ":PARSE_TLSEXT:",
5909 })
5910
5911 // Test NPN and the interaction with ALPN.
5912 if ver.version < VersionTLS13 {
5913 // Test that the server prefers ALPN over NPN.
5914 testCases = append(testCases, testCase{
5915 testType: serverTest,
5916 name: "ALPNServer-Preferred-" + ver.name,
5917 config: Config{
5918 MaxVersion: ver.version,
5919 NextProtos: []string{"foo", "bar", "baz"},
5920 },
5921 flags: []string{
5922 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5923 "-select-alpn", "foo",
5924 "-advertise-npn", "\x03foo\x03bar\x03baz",
5925 },
David Benjamina5022392017-07-10 17:40:39 -04005926 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005927 expectedNextProto: "foo",
5928 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005929 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005930 })
5931 testCases = append(testCases, testCase{
5932 testType: serverTest,
5933 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5934 config: Config{
5935 MaxVersion: ver.version,
5936 NextProtos: []string{"foo", "bar", "baz"},
5937 Bugs: ProtocolBugs{
5938 SwapNPNAndALPN: true,
5939 },
5940 },
5941 flags: []string{
5942 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5943 "-select-alpn", "foo",
5944 "-advertise-npn", "\x03foo\x03bar\x03baz",
5945 },
David Benjamina5022392017-07-10 17:40:39 -04005946 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005947 expectedNextProto: "foo",
5948 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005949 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005950 })
5951
5952 // Test that negotiating both NPN and ALPN is forbidden.
5953 testCases = append(testCases, testCase{
5954 name: "NegotiateALPNAndNPN-" + ver.name,
5955 config: Config{
5956 MaxVersion: ver.version,
5957 NextProtos: []string{"foo", "bar", "baz"},
5958 Bugs: ProtocolBugs{
5959 NegotiateALPNAndNPN: true,
5960 },
5961 },
5962 flags: []string{
5963 "-advertise-alpn", "\x03foo",
5964 "-select-next-proto", "foo",
5965 },
David Benjamina5022392017-07-10 17:40:39 -04005966 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005967 shouldFail: true,
5968 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5969 })
5970 testCases = append(testCases, testCase{
5971 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5972 config: Config{
5973 MaxVersion: ver.version,
5974 NextProtos: []string{"foo", "bar", "baz"},
5975 Bugs: ProtocolBugs{
5976 NegotiateALPNAndNPN: true,
5977 SwapNPNAndALPN: true,
5978 },
5979 },
5980 flags: []string{
5981 "-advertise-alpn", "\x03foo",
5982 "-select-next-proto", "foo",
5983 },
David Benjamina5022392017-07-10 17:40:39 -04005984 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005985 shouldFail: true,
5986 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5987 })
David Benjamin97d17d92016-07-14 16:12:00 -04005988 }
5989
5990 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005991
5992 // Resume with a corrupt ticket.
5993 testCases = append(testCases, testCase{
5994 testType: serverTest,
5995 name: "CorruptTicket-" + ver.name,
5996 config: Config{
5997 MaxVersion: ver.version,
5998 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005999 FilterTicket: func(in []byte) ([]byte, error) {
6000 in[len(in)-1] ^= 1
6001 return in, nil
6002 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04006003 },
6004 },
David Benjamina5022392017-07-10 17:40:39 -04006005 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006006 resumeSession: true,
6007 expectResumeRejected: true,
6008 })
6009 // Test the ticket callback, with and without renewal.
6010 testCases = append(testCases, testCase{
6011 testType: serverTest,
6012 name: "TicketCallback-" + ver.name,
6013 config: Config{
6014 MaxVersion: ver.version,
6015 },
David Benjamina5022392017-07-10 17:40:39 -04006016 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006017 resumeSession: true,
6018 flags: []string{"-use-ticket-callback"},
6019 })
6020 testCases = append(testCases, testCase{
6021 testType: serverTest,
6022 name: "TicketCallback-Renew-" + ver.name,
6023 config: Config{
6024 MaxVersion: ver.version,
6025 Bugs: ProtocolBugs{
6026 ExpectNewTicket: true,
6027 },
6028 },
David Benjamina5022392017-07-10 17:40:39 -04006029 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006030 flags: []string{"-use-ticket-callback", "-renew-ticket"},
6031 resumeSession: true,
6032 })
6033
6034 // Test that the ticket callback is only called once when everything before
6035 // it in the ClientHello is asynchronous. This corrupts the ticket so
6036 // certificate selection callbacks run.
6037 testCases = append(testCases, testCase{
6038 testType: serverTest,
6039 name: "TicketCallback-SingleCall-" + ver.name,
6040 config: Config{
6041 MaxVersion: ver.version,
6042 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04006043 FilterTicket: func(in []byte) ([]byte, error) {
6044 in[len(in)-1] ^= 1
6045 return in, nil
6046 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04006047 },
6048 },
David Benjamina5022392017-07-10 17:40:39 -04006049 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006050 resumeSession: true,
6051 expectResumeRejected: true,
6052 flags: []string{
6053 "-use-ticket-callback",
6054 "-async",
6055 },
6056 })
6057
David Benjamind4c349b2017-02-09 14:07:17 -05006058 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04006059 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04006060 testCases = append(testCases, testCase{
6061 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05006062 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04006063 config: Config{
6064 MaxVersion: ver.version,
6065 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006066 EmptyTicketSessionID: true,
6067 },
6068 },
6069 resumeSession: true,
6070 })
6071 testCases = append(testCases, testCase{
6072 testType: serverTest,
6073 name: "TicketSessionIDLength-16-" + ver.name,
6074 config: Config{
6075 MaxVersion: ver.version,
6076 Bugs: ProtocolBugs{
6077 TicketSessionIDLength: 16,
6078 },
6079 },
6080 resumeSession: true,
6081 })
6082 testCases = append(testCases, testCase{
6083 testType: serverTest,
6084 name: "TicketSessionIDLength-32-" + ver.name,
6085 config: Config{
6086 MaxVersion: ver.version,
6087 Bugs: ProtocolBugs{
6088 TicketSessionIDLength: 32,
6089 },
6090 },
6091 resumeSession: true,
6092 })
6093 testCases = append(testCases, testCase{
6094 testType: serverTest,
6095 name: "TicketSessionIDLength-33-" + ver.name,
6096 config: Config{
6097 MaxVersion: ver.version,
6098 Bugs: ProtocolBugs{
6099 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006100 },
6101 },
6102 resumeSession: true,
6103 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006104 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006105 expectedError: ":DECODE_ERROR:",
6106 })
6107 }
6108
6109 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6110 // are ignored.
6111 if ver.hasDTLS {
6112 testCases = append(testCases, testCase{
6113 protocol: dtls,
6114 name: "SRTP-Client-" + ver.name,
6115 config: Config{
6116 MaxVersion: ver.version,
6117 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6118 },
6119 flags: []string{
6120 "-srtp-profiles",
6121 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6122 },
6123 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6124 })
6125 testCases = append(testCases, testCase{
6126 protocol: dtls,
6127 testType: serverTest,
6128 name: "SRTP-Server-" + ver.name,
6129 config: Config{
6130 MaxVersion: ver.version,
6131 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6132 },
6133 flags: []string{
6134 "-srtp-profiles",
6135 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6136 },
6137 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6138 })
6139 // Test that the MKI is ignored.
6140 testCases = append(testCases, testCase{
6141 protocol: dtls,
6142 testType: serverTest,
6143 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6144 config: Config{
6145 MaxVersion: ver.version,
6146 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6147 Bugs: ProtocolBugs{
6148 SRTPMasterKeyIdentifer: "bogus",
6149 },
6150 },
6151 flags: []string{
6152 "-srtp-profiles",
6153 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6154 },
6155 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6156 })
6157 // Test that SRTP isn't negotiated on the server if there were
6158 // no matching profiles.
6159 testCases = append(testCases, testCase{
6160 protocol: dtls,
6161 testType: serverTest,
6162 name: "SRTP-Server-NoMatch-" + ver.name,
6163 config: Config{
6164 MaxVersion: ver.version,
6165 SRTPProtectionProfiles: []uint16{100, 101, 102},
6166 },
6167 flags: []string{
6168 "-srtp-profiles",
6169 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6170 },
6171 expectedSRTPProtectionProfile: 0,
6172 })
6173 // Test that the server returning an invalid SRTP profile is
6174 // flagged as an error by the client.
6175 testCases = append(testCases, testCase{
6176 protocol: dtls,
6177 name: "SRTP-Client-NoMatch-" + ver.name,
6178 config: Config{
6179 MaxVersion: ver.version,
6180 Bugs: ProtocolBugs{
6181 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6182 },
6183 },
6184 flags: []string{
6185 "-srtp-profiles",
6186 "SRTP_AES128_CM_SHA1_80",
6187 },
6188 shouldFail: true,
6189 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6190 })
6191 }
6192
6193 // Test SCT list.
6194 testCases = append(testCases, testCase{
6195 name: "SignedCertificateTimestampList-Client-" + ver.name,
6196 testType: clientTest,
6197 config: Config{
6198 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006199 },
David Benjamin97d17d92016-07-14 16:12:00 -04006200 flags: []string{
6201 "-enable-signed-cert-timestamps",
6202 "-expect-signed-cert-timestamps",
6203 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006204 },
David Benjamina5022392017-07-10 17:40:39 -04006205 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006206 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006207 })
David Benjamindaa88502016-10-04 16:32:16 -04006208
Adam Langleycfa08c32016-11-17 13:21:27 -08006209 var differentSCTList []byte
6210 differentSCTList = append(differentSCTList, testSCTList...)
6211 differentSCTList[len(differentSCTList)-1] ^= 1
6212
David Benjamindaa88502016-10-04 16:32:16 -04006213 // The SCT extension did not specify that it must only be sent on resumption as it
6214 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006215 testCases = append(testCases, testCase{
6216 name: "SendSCTListOnResume-" + ver.name,
6217 config: Config{
6218 MaxVersion: ver.version,
6219 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006220 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006221 },
David Benjamind98452d2015-06-16 14:16:23 -04006222 },
David Benjamin97d17d92016-07-14 16:12:00 -04006223 flags: []string{
6224 "-enable-signed-cert-timestamps",
6225 "-expect-signed-cert-timestamps",
6226 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006227 },
David Benjamina5022392017-07-10 17:40:39 -04006228 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006229 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006230 })
David Benjamindaa88502016-10-04 16:32:16 -04006231
David Benjamin97d17d92016-07-14 16:12:00 -04006232 testCases = append(testCases, testCase{
6233 name: "SignedCertificateTimestampList-Server-" + ver.name,
6234 testType: serverTest,
6235 config: Config{
6236 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006237 },
David Benjamin97d17d92016-07-14 16:12:00 -04006238 flags: []string{
6239 "-signed-cert-timestamps",
6240 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006241 },
David Benjamina5022392017-07-10 17:40:39 -04006242 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006243 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006244 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006245 })
David Benjamin53210cb2016-11-16 09:01:48 +09006246
Adam Langleycfa08c32016-11-17 13:21:27 -08006247 emptySCTListCert := *testCerts[0].cert
6248 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6249
6250 // Test empty SCT list.
6251 testCases = append(testCases, testCase{
6252 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6253 testType: clientTest,
6254 config: Config{
6255 MaxVersion: ver.version,
6256 Certificates: []Certificate{emptySCTListCert},
6257 },
6258 flags: []string{
6259 "-enable-signed-cert-timestamps",
6260 },
David Benjamina5022392017-07-10 17:40:39 -04006261 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006262 shouldFail: true,
6263 expectedError: ":ERROR_PARSING_EXTENSION:",
6264 })
6265
6266 emptySCTCert := *testCerts[0].cert
6267 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6268
6269 // Test empty SCT in non-empty list.
6270 testCases = append(testCases, testCase{
6271 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6272 testType: clientTest,
6273 config: Config{
6274 MaxVersion: ver.version,
6275 Certificates: []Certificate{emptySCTCert},
6276 },
6277 flags: []string{
6278 "-enable-signed-cert-timestamps",
6279 },
David Benjamina5022392017-07-10 17:40:39 -04006280 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006281 shouldFail: true,
6282 expectedError: ":ERROR_PARSING_EXTENSION:",
6283 })
6284
David Benjamin53210cb2016-11-16 09:01:48 +09006285 // Test that certificate-related extensions are not sent unsolicited.
6286 testCases = append(testCases, testCase{
6287 testType: serverTest,
6288 name: "UnsolicitedCertificateExtensions-" + ver.name,
6289 config: Config{
6290 MaxVersion: ver.version,
6291 Bugs: ProtocolBugs{
6292 NoOCSPStapling: true,
6293 NoSignedCertificateTimestamps: true,
6294 },
6295 },
David Benjamina5022392017-07-10 17:40:39 -04006296 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006297 flags: []string{
6298 "-ocsp-response",
6299 base64.StdEncoding.EncodeToString(testOCSPResponse),
6300 "-signed-cert-timestamps",
6301 base64.StdEncoding.EncodeToString(testSCTList),
6302 },
6303 })
David Benjamin97d17d92016-07-14 16:12:00 -04006304 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006305
Paul Lietar4fac72e2015-09-09 13:44:55 +01006306 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006307 testType: clientTest,
6308 name: "ClientHelloPadding",
6309 config: Config{
6310 Bugs: ProtocolBugs{
6311 RequireClientHelloSize: 512,
6312 },
6313 },
6314 // This hostname just needs to be long enough to push the
6315 // ClientHello into F5's danger zone between 256 and 511 bytes
6316 // long.
6317 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6318 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006319
6320 // Extensions should not function in SSL 3.0.
6321 testCases = append(testCases, testCase{
6322 testType: serverTest,
6323 name: "SSLv3Extensions-NoALPN",
6324 config: Config{
6325 MaxVersion: VersionSSL30,
6326 NextProtos: []string{"foo", "bar", "baz"},
6327 },
6328 flags: []string{
6329 "-select-alpn", "foo",
6330 },
6331 expectNoNextProto: true,
6332 })
6333
6334 // Test session tickets separately as they follow a different codepath.
6335 testCases = append(testCases, testCase{
6336 testType: serverTest,
6337 name: "SSLv3Extensions-NoTickets",
6338 config: Config{
6339 MaxVersion: VersionSSL30,
6340 Bugs: ProtocolBugs{
6341 // Historically, session tickets in SSL 3.0
6342 // failed in different ways depending on whether
6343 // the client supported renegotiation_info.
6344 NoRenegotiationInfo: true,
6345 },
6346 },
6347 resumeSession: true,
6348 })
6349 testCases = append(testCases, testCase{
6350 testType: serverTest,
6351 name: "SSLv3Extensions-NoTickets2",
6352 config: Config{
6353 MaxVersion: VersionSSL30,
6354 },
6355 resumeSession: true,
6356 })
6357
6358 // But SSL 3.0 does send and process renegotiation_info.
6359 testCases = append(testCases, testCase{
6360 testType: serverTest,
6361 name: "SSLv3Extensions-RenegotiationInfo",
6362 config: Config{
6363 MaxVersion: VersionSSL30,
6364 Bugs: ProtocolBugs{
6365 RequireRenegotiationInfo: true,
6366 },
6367 },
David Benjamind2610042017-01-03 10:49:28 -05006368 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006369 })
6370 testCases = append(testCases, testCase{
6371 testType: serverTest,
6372 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6373 config: Config{
6374 MaxVersion: VersionSSL30,
6375 Bugs: ProtocolBugs{
6376 NoRenegotiationInfo: true,
6377 SendRenegotiationSCSV: true,
6378 RequireRenegotiationInfo: true,
6379 },
6380 },
David Benjamind2610042017-01-03 10:49:28 -05006381 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006382 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006383
6384 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6385 // in ServerHello.
6386 testCases = append(testCases, testCase{
6387 name: "NPN-Forbidden-TLS13",
6388 config: Config{
6389 MaxVersion: VersionTLS13,
6390 NextProtos: []string{"foo"},
6391 Bugs: ProtocolBugs{
6392 NegotiateNPNAtAllVersions: true,
6393 },
6394 },
6395 flags: []string{"-select-next-proto", "foo"},
6396 shouldFail: true,
6397 expectedError: ":ERROR_PARSING_EXTENSION:",
6398 })
6399 testCases = append(testCases, testCase{
6400 name: "EMS-Forbidden-TLS13",
6401 config: Config{
6402 MaxVersion: VersionTLS13,
6403 Bugs: ProtocolBugs{
6404 NegotiateEMSAtAllVersions: true,
6405 },
6406 },
6407 shouldFail: true,
6408 expectedError: ":ERROR_PARSING_EXTENSION:",
6409 })
6410 testCases = append(testCases, testCase{
6411 name: "RenegotiationInfo-Forbidden-TLS13",
6412 config: Config{
6413 MaxVersion: VersionTLS13,
6414 Bugs: ProtocolBugs{
6415 NegotiateRenegotiationInfoAtAllVersions: true,
6416 },
6417 },
6418 shouldFail: true,
6419 expectedError: ":ERROR_PARSING_EXTENSION:",
6420 })
6421 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006422 name: "Ticket-Forbidden-TLS13",
6423 config: Config{
6424 MaxVersion: VersionTLS12,
6425 },
6426 resumeConfig: &Config{
6427 MaxVersion: VersionTLS13,
6428 Bugs: ProtocolBugs{
6429 AdvertiseTicketExtension: true,
6430 },
6431 },
6432 resumeSession: true,
6433 shouldFail: true,
6434 expectedError: ":ERROR_PARSING_EXTENSION:",
6435 })
6436
6437 // Test that illegal extensions in TLS 1.3 are declined by the server if
6438 // offered in ClientHello. The runner's server will fail if this occurs,
6439 // so we exercise the offering path. (EMS and Renegotiation Info are
6440 // implicit in every test.)
6441 testCases = append(testCases, testCase{
6442 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006443 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006444 config: Config{
6445 MaxVersion: VersionTLS13,
6446 NextProtos: []string{"bar"},
6447 },
6448 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6449 })
David Benjamin196df5b2016-09-21 16:23:27 -04006450
David Benjamindaa88502016-10-04 16:32:16 -04006451 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6452 // tolerated.
6453 testCases = append(testCases, testCase{
6454 name: "SendOCSPResponseOnResume-TLS12",
6455 config: Config{
6456 MaxVersion: VersionTLS12,
6457 Bugs: ProtocolBugs{
6458 SendOCSPResponseOnResume: []byte("bogus"),
6459 },
6460 },
6461 flags: []string{
6462 "-enable-ocsp-stapling",
6463 "-expect-ocsp-response",
6464 base64.StdEncoding.EncodeToString(testOCSPResponse),
6465 },
6466 resumeSession: true,
6467 })
6468
David Benjamindaa88502016-10-04 16:32:16 -04006469 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006470 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006471 config: Config{
6472 MaxVersion: VersionTLS13,
6473 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006474 SendExtensionOnCertificate: testOCSPExtension,
6475 },
6476 },
6477 shouldFail: true,
6478 expectedError: ":UNEXPECTED_EXTENSION:",
6479 })
6480
6481 testCases = append(testCases, testCase{
6482 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6483 config: Config{
6484 MaxVersion: VersionTLS13,
6485 Bugs: ProtocolBugs{
6486 SendExtensionOnCertificate: testSCTExtension,
6487 },
6488 },
6489 shouldFail: true,
6490 expectedError: ":UNEXPECTED_EXTENSION:",
6491 })
6492
6493 // Test that extensions on client certificates are never accepted.
6494 testCases = append(testCases, testCase{
6495 name: "SendExtensionOnClientCertificate-TLS13",
6496 testType: serverTest,
6497 config: Config{
6498 MaxVersion: VersionTLS13,
6499 Certificates: []Certificate{rsaCertificate},
6500 Bugs: ProtocolBugs{
6501 SendExtensionOnCertificate: testOCSPExtension,
6502 },
6503 },
6504 flags: []string{
6505 "-enable-ocsp-stapling",
6506 "-require-any-client-certificate",
6507 },
6508 shouldFail: true,
6509 expectedError: ":UNEXPECTED_EXTENSION:",
6510 })
6511
6512 testCases = append(testCases, testCase{
6513 name: "SendUnknownExtensionOnCertificate-TLS13",
6514 config: Config{
6515 MaxVersion: VersionTLS13,
6516 Bugs: ProtocolBugs{
6517 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6518 },
6519 },
6520 shouldFail: true,
6521 expectedError: ":UNEXPECTED_EXTENSION:",
6522 })
6523
6524 // Test that extensions on intermediates are allowed but ignored.
6525 testCases = append(testCases, testCase{
6526 name: "IgnoreExtensionsOnIntermediates-TLS13",
6527 config: Config{
6528 MaxVersion: VersionTLS13,
6529 Certificates: []Certificate{rsaChainCertificate},
6530 Bugs: ProtocolBugs{
6531 // Send different values on the intermediate. This tests
6532 // the intermediate's extensions do not override the
6533 // leaf's.
David Benjamin5c4271f2017-08-23 22:09:41 -07006534 SendOCSPOnIntermediates: testOCSPResponse2,
6535 SendSCTOnIntermediates: testSCTList2,
David Benjamindaa88502016-10-04 16:32:16 -04006536 },
6537 },
6538 flags: []string{
6539 "-enable-ocsp-stapling",
6540 "-expect-ocsp-response",
6541 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006542 "-enable-signed-cert-timestamps",
6543 "-expect-signed-cert-timestamps",
6544 base64.StdEncoding.EncodeToString(testSCTList),
6545 },
6546 resumeSession: true,
6547 })
6548
6549 // Test that extensions are not sent on intermediates when configured
6550 // only for a leaf.
6551 testCases = append(testCases, testCase{
6552 testType: serverTest,
6553 name: "SendNoExtensionsOnIntermediate-TLS13",
6554 config: Config{
6555 MaxVersion: VersionTLS13,
6556 Bugs: ProtocolBugs{
6557 ExpectNoExtensionsOnIntermediate: true,
6558 },
6559 },
6560 flags: []string{
6561 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6562 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6563 "-ocsp-response",
6564 base64.StdEncoding.EncodeToString(testOCSPResponse),
6565 "-signed-cert-timestamps",
6566 base64.StdEncoding.EncodeToString(testSCTList),
6567 },
6568 })
6569
6570 // Test that extensions are not sent on client certificates.
6571 testCases = append(testCases, testCase{
6572 name: "SendNoClientCertificateExtensions-TLS13",
6573 config: Config{
6574 MaxVersion: VersionTLS13,
6575 ClientAuth: RequireAnyClientCert,
6576 },
6577 flags: []string{
6578 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6579 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6580 "-ocsp-response",
6581 base64.StdEncoding.EncodeToString(testOCSPResponse),
6582 "-signed-cert-timestamps",
6583 base64.StdEncoding.EncodeToString(testSCTList),
6584 },
6585 })
6586
6587 testCases = append(testCases, testCase{
6588 name: "SendDuplicateExtensionsOnCerts-TLS13",
6589 config: Config{
6590 MaxVersion: VersionTLS13,
6591 Bugs: ProtocolBugs{
6592 SendDuplicateCertExtensions: true,
6593 },
6594 },
6595 flags: []string{
6596 "-enable-ocsp-stapling",
6597 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006598 },
6599 resumeSession: true,
6600 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006601 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006602 })
Adam Langley9b885c52016-11-18 14:21:03 -08006603
6604 testCases = append(testCases, testCase{
6605 name: "SignedCertificateTimestampListInvalid-Server",
6606 testType: serverTest,
6607 flags: []string{
6608 "-signed-cert-timestamps",
6609 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6610 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006611 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006612 expectedError: ":INVALID_SCT_LIST:",
6613 })
David Benjamine78bfde2014-09-06 12:45:15 -04006614}
6615
David Benjamin01fe8202014-09-24 15:21:44 -04006616func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006617 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006618 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006619 // SSL 3.0 does not have tickets and TLS 1.3 does not
6620 // have session IDs, so skip their cross-resumption
6621 // tests.
6622 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6623 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6624 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006625 }
6626
David Benjamin8b8c0062014-11-23 02:47:52 -05006627 protocols := []protocol{tls}
6628 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6629 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006630 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006631 for _, protocol := range protocols {
6632 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6633 if protocol == dtls {
6634 suffix += "-DTLS"
6635 }
6636
Steven Valdez520e1222017-06-13 12:45:25 -04006637 // We can't resume across TLS 1.3 variants and error out earlier in the
6638 // session resumption.
6639 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6640 continue
6641 }
6642
David Benjaminece3de92015-03-16 18:02:20 -04006643 if sessionVers.version == resumeVers.version {
6644 testCases = append(testCases, testCase{
6645 protocol: protocol,
6646 name: "Resume-Client" + suffix,
6647 resumeSession: true,
6648 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006649 MaxVersion: sessionVers.version,
6650 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006651 Bugs: ProtocolBugs{
6652 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6653 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6654 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006655 },
David Benjaminece3de92015-03-16 18:02:20 -04006656 expectedVersion: sessionVers.version,
6657 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006658 flags: []string{
6659 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6660 },
David Benjaminece3de92015-03-16 18:02:20 -04006661 })
6662 } else {
David Benjamin405da482016-08-08 17:25:07 -04006663 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6664
6665 // Offering a TLS 1.3 session sends an empty session ID, so
6666 // there is no way to convince a non-lookahead client the
6667 // session was resumed. It will appear to the client that a
6668 // stray ChangeCipherSpec was sent.
6669 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6670 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006671 }
6672
David Benjaminece3de92015-03-16 18:02:20 -04006673 testCases = append(testCases, testCase{
6674 protocol: protocol,
6675 name: "Resume-Client-Mismatch" + suffix,
6676 resumeSession: true,
6677 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006678 MaxVersion: sessionVers.version,
6679 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006680 },
David Benjaminece3de92015-03-16 18:02:20 -04006681 expectedVersion: sessionVers.version,
6682 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006683 MaxVersion: resumeVers.version,
6684 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006685 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006686 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006687 },
6688 },
6689 expectedResumeVersion: resumeVers.version,
6690 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006691 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006692 flags: []string{
6693 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6694 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6695 },
David Benjaminece3de92015-03-16 18:02:20 -04006696 })
6697 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006698
6699 testCases = append(testCases, testCase{
6700 protocol: protocol,
6701 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006702 resumeSession: true,
6703 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006704 MaxVersion: sessionVers.version,
6705 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006706 },
6707 expectedVersion: sessionVers.version,
6708 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006709 MaxVersion: resumeVers.version,
6710 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006711 },
6712 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006713 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006714 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006715 flags: []string{
6716 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6717 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6718 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006719 })
6720
David Benjamin8b8c0062014-11-23 02:47:52 -05006721 testCases = append(testCases, testCase{
6722 protocol: protocol,
6723 testType: serverTest,
6724 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006725 resumeSession: true,
6726 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006727 MaxVersion: sessionVers.version,
6728 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006729 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006730 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006731 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006732 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006733 MaxVersion: resumeVers.version,
6734 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006735 Bugs: ProtocolBugs{
6736 SendBothTickets: true,
6737 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006738 },
6739 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006740 flags: []string{
6741 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6742 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6743 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006744 })
6745 }
David Benjamin01fe8202014-09-24 15:21:44 -04006746 }
6747 }
David Benjaminece3de92015-03-16 18:02:20 -04006748
David Benjamin4199b0d2016-11-01 13:58:25 -04006749 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006750 testCases = append(testCases, testCase{
6751 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006752 name: "ShimTicketRewritable",
6753 resumeSession: true,
6754 config: Config{
6755 MaxVersion: VersionTLS12,
6756 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6757 Bugs: ProtocolBugs{
6758 FilterTicket: func(in []byte) ([]byte, error) {
6759 in, err := SetShimTicketVersion(in, VersionTLS12)
6760 if err != nil {
6761 return nil, err
6762 }
6763 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6764 },
6765 },
6766 },
6767 flags: []string{
6768 "-ticket-key",
6769 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6770 },
6771 })
6772
6773 // Resumptions are declined if the version does not match.
6774 testCases = append(testCases, testCase{
6775 testType: serverTest,
6776 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006777 resumeSession: true,
6778 config: Config{
6779 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006780 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006781 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006782 FilterTicket: func(in []byte) ([]byte, error) {
6783 return SetShimTicketVersion(in, VersionTLS13)
6784 },
6785 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006786 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006787 flags: []string{
6788 "-ticket-key",
6789 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6790 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006791 expectResumeRejected: true,
6792 })
6793
6794 testCases = append(testCases, testCase{
6795 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006796 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006797 resumeSession: true,
6798 config: Config{
6799 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006800 Bugs: ProtocolBugs{
6801 FilterTicket: func(in []byte) ([]byte, error) {
6802 return SetShimTicketVersion(in, VersionTLS12)
6803 },
6804 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006805 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006806 flags: []string{
6807 "-ticket-key",
6808 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6809 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006810 expectResumeRejected: true,
6811 })
6812
David Benjamin4199b0d2016-11-01 13:58:25 -04006813 // Resumptions are declined if the cipher is invalid or disabled.
6814 testCases = append(testCases, testCase{
6815 testType: serverTest,
6816 name: "Resume-Server-DeclineBadCipher",
6817 resumeSession: true,
6818 config: Config{
6819 MaxVersion: VersionTLS12,
6820 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006821 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006822 FilterTicket: func(in []byte) ([]byte, error) {
6823 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6824 },
6825 },
6826 },
6827 flags: []string{
6828 "-ticket-key",
6829 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6830 },
6831 expectResumeRejected: true,
6832 })
6833
6834 testCases = append(testCases, testCase{
6835 testType: serverTest,
6836 name: "Resume-Server-DeclineBadCipher-2",
6837 resumeSession: true,
6838 config: Config{
6839 MaxVersion: VersionTLS12,
6840 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006841 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006842 FilterTicket: func(in []byte) ([]byte, error) {
6843 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6844 },
6845 },
6846 },
6847 flags: []string{
6848 "-cipher", "AES128",
6849 "-ticket-key",
6850 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6851 },
6852 expectResumeRejected: true,
6853 })
6854
David Benjaminf01f42a2016-11-16 19:05:33 +09006855 // Sessions are not resumed if they do not use the preferred cipher.
6856 testCases = append(testCases, testCase{
6857 testType: serverTest,
6858 name: "Resume-Server-CipherNotPreferred",
6859 resumeSession: true,
6860 config: Config{
6861 MaxVersion: VersionTLS12,
6862 Bugs: ProtocolBugs{
6863 ExpectNewTicket: true,
6864 FilterTicket: func(in []byte) ([]byte, error) {
6865 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6866 },
6867 },
6868 },
6869 flags: []string{
6870 "-ticket-key",
6871 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6872 },
6873 shouldFail: false,
6874 expectResumeRejected: true,
6875 })
6876
6877 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6878 // PRF hashes match, but BoringSSL will always decline such resumptions.
6879 testCases = append(testCases, testCase{
6880 testType: serverTest,
6881 name: "Resume-Server-CipherNotPreferred-TLS13",
6882 resumeSession: true,
6883 config: Config{
6884 MaxVersion: VersionTLS13,
6885 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6886 Bugs: ProtocolBugs{
6887 FilterTicket: func(in []byte) ([]byte, error) {
6888 // If the client (runner) offers ChaCha20-Poly1305 first, the
6889 // server (shim) always prefers it. Switch it to AES-GCM.
6890 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6891 },
6892 },
6893 },
6894 flags: []string{
6895 "-ticket-key",
6896 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6897 },
6898 shouldFail: false,
6899 expectResumeRejected: true,
6900 })
6901
6902 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006903 testCases = append(testCases, testCase{
6904 testType: serverTest,
6905 name: "Resume-Server-DeclineBadCipher-TLS13",
6906 resumeSession: true,
6907 config: Config{
6908 MaxVersion: VersionTLS13,
6909 Bugs: ProtocolBugs{
6910 FilterTicket: func(in []byte) ([]byte, error) {
6911 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6912 },
6913 },
6914 },
6915 flags: []string{
6916 "-ticket-key",
6917 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6918 },
6919 expectResumeRejected: true,
6920 })
6921
David Benjaminf01f42a2016-11-16 19:05:33 +09006922 // If the client does not offer the cipher from the session, decline to
6923 // resume. Clients are forbidden from doing this, but BoringSSL selects
6924 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006925 testCases = append(testCases, testCase{
6926 testType: serverTest,
6927 name: "Resume-Server-UnofferedCipher",
6928 resumeSession: true,
6929 config: Config{
6930 MaxVersion: VersionTLS12,
6931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6932 },
6933 resumeConfig: &Config{
6934 MaxVersion: VersionTLS12,
6935 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6936 Bugs: ProtocolBugs{
6937 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6938 },
6939 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006940 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006941 })
6942
David Benjaminf01f42a2016-11-16 19:05:33 +09006943 // In TLS 1.3, clients may advertise a cipher list which does not
6944 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006945 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6946 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006947 testCases = append(testCases, testCase{
6948 testType: serverTest,
6949 name: "Resume-Server-UnofferedCipher-TLS13",
6950 resumeSession: true,
6951 config: Config{
6952 MaxVersion: VersionTLS13,
6953 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6954 },
6955 resumeConfig: &Config{
6956 MaxVersion: VersionTLS13,
6957 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6958 Bugs: ProtocolBugs{
6959 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6960 },
6961 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006962 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006963 })
6964
David Benjamin4199b0d2016-11-01 13:58:25 -04006965 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006966 testCases = append(testCases, testCase{
6967 name: "Resume-Client-CipherMismatch",
6968 resumeSession: true,
6969 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006970 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006971 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6972 },
6973 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006974 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006975 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6976 Bugs: ProtocolBugs{
6977 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6978 },
6979 },
6980 shouldFail: true,
6981 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6982 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006983
David Benjamine1cc35e2016-11-16 16:25:58 +09006984 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6985 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006986 testCases = append(testCases, testCase{
6987 name: "Resume-Client-CipherMismatch-TLS13",
6988 resumeSession: true,
6989 config: Config{
6990 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006991 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006992 },
6993 resumeConfig: &Config{
6994 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006995 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6996 },
6997 })
6998
6999 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
7000 testCases = append(testCases, testCase{
7001 name: "Resume-Client-PRFMismatch-TLS13",
7002 resumeSession: true,
7003 config: Config{
7004 MaxVersion: VersionTLS13,
7005 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
7006 },
7007 resumeConfig: &Config{
7008 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04007009 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04007010 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04007011 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04007012 },
7013 },
7014 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09007015 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04007016 })
Steven Valdeza833c352016-11-01 13:39:36 -04007017
7018 testCases = append(testCases, testCase{
7019 testType: serverTest,
7020 name: "Resume-Server-BinderWrongLength",
7021 resumeSession: true,
7022 config: Config{
7023 MaxVersion: VersionTLS13,
7024 Bugs: ProtocolBugs{
7025 SendShortPSKBinder: true,
7026 },
7027 },
7028 shouldFail: true,
7029 expectedLocalError: "remote error: error decrypting message",
7030 expectedError: ":DIGEST_CHECK_FAILED:",
7031 })
7032
7033 testCases = append(testCases, testCase{
7034 testType: serverTest,
7035 name: "Resume-Server-NoPSKBinder",
7036 resumeSession: true,
7037 config: Config{
7038 MaxVersion: VersionTLS13,
7039 Bugs: ProtocolBugs{
7040 SendNoPSKBinder: true,
7041 },
7042 },
7043 shouldFail: true,
7044 expectedLocalError: "remote error: error decoding message",
7045 expectedError: ":DECODE_ERROR:",
7046 })
7047
7048 testCases = append(testCases, testCase{
7049 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05007050 name: "Resume-Server-ExtraPSKBinder",
7051 resumeSession: true,
7052 config: Config{
7053 MaxVersion: VersionTLS13,
7054 Bugs: ProtocolBugs{
7055 SendExtraPSKBinder: true,
7056 },
7057 },
7058 shouldFail: true,
7059 expectedLocalError: "remote error: illegal parameter",
7060 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7061 })
7062
7063 testCases = append(testCases, testCase{
7064 testType: serverTest,
7065 name: "Resume-Server-ExtraIdentityNoBinder",
7066 resumeSession: true,
7067 config: Config{
7068 MaxVersion: VersionTLS13,
7069 Bugs: ProtocolBugs{
7070 ExtraPSKIdentity: true,
7071 },
7072 },
7073 shouldFail: true,
7074 expectedLocalError: "remote error: illegal parameter",
7075 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7076 })
7077
7078 testCases = append(testCases, testCase{
7079 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007080 name: "Resume-Server-InvalidPSKBinder",
7081 resumeSession: true,
7082 config: Config{
7083 MaxVersion: VersionTLS13,
7084 Bugs: ProtocolBugs{
7085 SendInvalidPSKBinder: true,
7086 },
7087 },
7088 shouldFail: true,
7089 expectedLocalError: "remote error: error decrypting message",
7090 expectedError: ":DIGEST_CHECK_FAILED:",
7091 })
7092
7093 testCases = append(testCases, testCase{
7094 testType: serverTest,
7095 name: "Resume-Server-PSKBinderFirstExtension",
7096 resumeSession: true,
7097 config: Config{
7098 MaxVersion: VersionTLS13,
7099 Bugs: ProtocolBugs{
7100 PSKBinderFirst: true,
7101 },
7102 },
7103 shouldFail: true,
7104 expectedLocalError: "remote error: illegal parameter",
7105 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7106 })
David Benjamin01fe8202014-09-24 15:21:44 -04007107}
7108
Adam Langley2ae77d22014-10-28 17:29:33 -07007109func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007110 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007111 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007112 testType: serverTest,
7113 name: "Renegotiate-Server-Forbidden",
7114 config: Config{
7115 MaxVersion: VersionTLS12,
7116 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007117 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007118 shouldFail: true,
7119 expectedError: ":NO_RENEGOTIATION:",
7120 expectedLocalError: "remote error: no renegotiation",
7121 })
Adam Langley5021b222015-06-12 18:27:58 -07007122 // The server shouldn't echo the renegotiation extension unless
7123 // requested by the client.
7124 testCases = append(testCases, testCase{
7125 testType: serverTest,
7126 name: "Renegotiate-Server-NoExt",
7127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007128 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007129 Bugs: ProtocolBugs{
7130 NoRenegotiationInfo: true,
7131 RequireRenegotiationInfo: true,
7132 },
7133 },
7134 shouldFail: true,
7135 expectedLocalError: "renegotiation extension missing",
7136 })
7137 // The renegotiation SCSV should be sufficient for the server to echo
7138 // the extension.
7139 testCases = append(testCases, testCase{
7140 testType: serverTest,
7141 name: "Renegotiate-Server-NoExt-SCSV",
7142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007143 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007144 Bugs: ProtocolBugs{
7145 NoRenegotiationInfo: true,
7146 SendRenegotiationSCSV: true,
7147 RequireRenegotiationInfo: true,
7148 },
7149 },
7150 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007151 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007152 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007154 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007155 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007156 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007157 },
7158 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007159 renegotiate: 1,
David Benjamind0beda02017-09-06 16:46:50 -04007160 // Test renegotiation after both an initial and resumption
7161 // handshake.
7162 resumeSession: true,
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007163 flags: []string{
7164 "-renegotiate-freely",
7165 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007166 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007167 },
David Benjamincdea40c2015-03-19 14:09:43 -04007168 })
7169 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007170 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007171 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007173 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007174 Bugs: ProtocolBugs{
7175 EmptyRenegotiationInfo: true,
7176 },
7177 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007178 flags: []string{"-renegotiate-freely"},
7179 shouldFail: true,
7180 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007181 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007182 })
7183 testCases = append(testCases, testCase{
7184 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007185 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007186 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007187 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007188 Bugs: ProtocolBugs{
7189 BadRenegotiationInfo: true,
7190 },
7191 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007192 flags: []string{"-renegotiate-freely"},
7193 shouldFail: true,
7194 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007195 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007196 })
7197 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007198 name: "Renegotiate-Client-BadExt2",
7199 renegotiate: 1,
7200 config: Config{
7201 MaxVersion: VersionTLS12,
7202 Bugs: ProtocolBugs{
7203 BadRenegotiationInfoEnd: true,
7204 },
7205 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007206 flags: []string{"-renegotiate-freely"},
7207 shouldFail: true,
7208 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007209 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007210 })
7211 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007212 name: "Renegotiate-Client-Downgrade",
7213 renegotiate: 1,
7214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007215 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007216 Bugs: ProtocolBugs{
7217 NoRenegotiationInfoAfterInitial: true,
7218 },
7219 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007220 flags: []string{"-renegotiate-freely"},
7221 shouldFail: true,
7222 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007223 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007224 })
7225 testCases = append(testCases, testCase{
7226 name: "Renegotiate-Client-Upgrade",
7227 renegotiate: 1,
7228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007229 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007230 Bugs: ProtocolBugs{
7231 NoRenegotiationInfoInInitial: true,
7232 },
7233 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007234 flags: []string{"-renegotiate-freely"},
7235 shouldFail: true,
7236 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007237 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007238 })
7239 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007240 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007241 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007242 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007243 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007244 Bugs: ProtocolBugs{
7245 NoRenegotiationInfo: true,
7246 },
7247 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007248 flags: []string{
7249 "-renegotiate-freely",
7250 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007251 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007252 },
David Benjamincff0b902015-05-15 23:09:47 -04007253 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007254
7255 // Test that the server may switch ciphers on renegotiation without
7256 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007257 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007258 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007259 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007260 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007261 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007262 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007263 },
7264 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007265 flags: []string{
7266 "-renegotiate-freely",
7267 "-expect-total-renegotiations", "1",
7268 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007269 })
7270 testCases = append(testCases, testCase{
7271 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007272 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007273 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007274 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007275 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7276 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007277 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007278 flags: []string{
7279 "-renegotiate-freely",
7280 "-expect-total-renegotiations", "1",
7281 },
David Benjaminb16346b2015-04-08 19:16:58 -04007282 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007283
7284 // Test that the server may not switch versions on renegotiation.
7285 testCases = append(testCases, testCase{
7286 name: "Renegotiate-Client-SwitchVersion",
7287 config: Config{
7288 MaxVersion: VersionTLS12,
7289 // Pick a cipher which exists at both versions.
7290 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7291 Bugs: ProtocolBugs{
7292 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007293 // Avoid failing early at the record layer.
7294 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007295 },
7296 },
7297 renegotiate: 1,
7298 flags: []string{
7299 "-renegotiate-freely",
7300 "-expect-total-renegotiations", "1",
7301 },
7302 shouldFail: true,
7303 expectedError: ":WRONG_SSL_VERSION:",
7304 })
7305
David Benjaminb16346b2015-04-08 19:16:58 -04007306 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007307 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007308 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007309 config: Config{
7310 MaxVersion: VersionTLS10,
7311 Bugs: ProtocolBugs{
7312 RequireSameRenegoClientVersion: true,
7313 },
7314 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007315 flags: []string{
7316 "-renegotiate-freely",
7317 "-expect-total-renegotiations", "1",
7318 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007319 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007320 testCases = append(testCases, testCase{
7321 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007322 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007323 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007324 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7326 NextProtos: []string{"foo"},
7327 },
7328 flags: []string{
7329 "-false-start",
7330 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007331 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007332 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007333 },
7334 shimWritesFirst: true,
7335 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007336
7337 // Client-side renegotiation controls.
7338 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007339 name: "Renegotiate-Client-Forbidden-1",
7340 config: Config{
7341 MaxVersion: VersionTLS12,
7342 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007343 renegotiate: 1,
7344 shouldFail: true,
7345 expectedError: ":NO_RENEGOTIATION:",
7346 expectedLocalError: "remote error: no renegotiation",
7347 })
7348 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007349 name: "Renegotiate-Client-Once-1",
7350 config: Config{
7351 MaxVersion: VersionTLS12,
7352 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007353 renegotiate: 1,
7354 flags: []string{
7355 "-renegotiate-once",
7356 "-expect-total-renegotiations", "1",
7357 },
7358 })
7359 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007360 name: "Renegotiate-Client-Freely-1",
7361 config: Config{
7362 MaxVersion: VersionTLS12,
7363 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007364 renegotiate: 1,
7365 flags: []string{
7366 "-renegotiate-freely",
7367 "-expect-total-renegotiations", "1",
7368 },
7369 })
7370 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007371 name: "Renegotiate-Client-Once-2",
7372 config: Config{
7373 MaxVersion: VersionTLS12,
7374 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007375 renegotiate: 2,
7376 flags: []string{"-renegotiate-once"},
7377 shouldFail: true,
7378 expectedError: ":NO_RENEGOTIATION:",
7379 expectedLocalError: "remote error: no renegotiation",
7380 })
7381 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007382 name: "Renegotiate-Client-Freely-2",
7383 config: Config{
7384 MaxVersion: VersionTLS12,
7385 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007386 renegotiate: 2,
7387 flags: []string{
7388 "-renegotiate-freely",
7389 "-expect-total-renegotiations", "2",
7390 },
7391 })
Adam Langley27a0d082015-11-03 13:34:10 -08007392 testCases = append(testCases, testCase{
7393 name: "Renegotiate-Client-NoIgnore",
7394 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007395 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007396 Bugs: ProtocolBugs{
7397 SendHelloRequestBeforeEveryAppDataRecord: true,
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":NO_RENEGOTIATION:",
7402 })
7403 testCases = append(testCases, testCase{
7404 name: "Renegotiate-Client-Ignore",
7405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007406 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007407 Bugs: ProtocolBugs{
7408 SendHelloRequestBeforeEveryAppDataRecord: true,
7409 },
7410 },
7411 flags: []string{
7412 "-renegotiate-ignore",
7413 "-expect-total-renegotiations", "0",
7414 },
7415 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007416
David Benjamin34941c02016-10-08 11:45:31 -04007417 // Renegotiation is not allowed at SSL 3.0.
7418 testCases = append(testCases, testCase{
7419 name: "Renegotiate-Client-SSL3",
7420 config: Config{
7421 MaxVersion: VersionSSL30,
7422 },
7423 renegotiate: 1,
7424 flags: []string{
7425 "-renegotiate-freely",
7426 "-expect-total-renegotiations", "1",
7427 },
7428 shouldFail: true,
7429 expectedError: ":NO_RENEGOTIATION:",
7430 expectedLocalError: "remote error: no renegotiation",
7431 })
7432
David Benjamina1eaba12017-01-01 23:19:22 -05007433 // Renegotiation is not allowed when there is an unfinished write.
7434 testCases = append(testCases, testCase{
7435 name: "Renegotiate-Client-UnfinishedWrite",
7436 config: Config{
7437 MaxVersion: VersionTLS12,
7438 },
David Benjaminbbba9392017-04-06 12:54:12 -04007439 renegotiate: 1,
7440 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007441 flags: []string{
7442 "-async",
7443 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007444 },
7445 shouldFail: true,
7446 expectedError: ":NO_RENEGOTIATION:",
7447 // We do not successfully send the no_renegotiation alert in
7448 // this case. https://crbug.com/boringssl/130
7449 })
7450
David Benjamin07ab5d42017-02-09 20:11:41 -05007451 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007452 testCases = append(testCases, testCase{
7453 name: "StrayHelloRequest",
7454 config: Config{
7455 MaxVersion: VersionTLS12,
7456 Bugs: ProtocolBugs{
7457 SendHelloRequestBeforeEveryHandshakeMessage: true,
7458 },
7459 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007460 shouldFail: true,
7461 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007462 })
7463 testCases = append(testCases, testCase{
7464 name: "StrayHelloRequest-Packed",
7465 config: Config{
7466 MaxVersion: VersionTLS12,
7467 Bugs: ProtocolBugs{
7468 PackHandshakeFlight: true,
7469 SendHelloRequestBeforeEveryHandshakeMessage: true,
7470 },
7471 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007472 shouldFail: true,
7473 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007474 })
7475
David Benjamin12d2c482016-07-24 10:56:51 -04007476 // Test renegotiation works if HelloRequest and server Finished come in
7477 // the same record.
7478 testCases = append(testCases, testCase{
7479 name: "Renegotiate-Client-Packed",
7480 config: Config{
7481 MaxVersion: VersionTLS12,
7482 Bugs: ProtocolBugs{
7483 PackHandshakeFlight: true,
7484 PackHelloRequestWithFinished: true,
7485 },
7486 },
7487 renegotiate: 1,
7488 flags: []string{
7489 "-renegotiate-freely",
7490 "-expect-total-renegotiations", "1",
7491 },
7492 })
7493
David Benjamin397c8e62016-07-08 14:14:36 -07007494 // Renegotiation is forbidden in TLS 1.3.
7495 testCases = append(testCases, testCase{
7496 name: "Renegotiate-Client-TLS13",
7497 config: Config{
7498 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007499 Bugs: ProtocolBugs{
7500 SendHelloRequestBeforeEveryAppDataRecord: true,
7501 },
David Benjamin397c8e62016-07-08 14:14:36 -07007502 },
David Benjamin397c8e62016-07-08 14:14:36 -07007503 flags: []string{
7504 "-renegotiate-freely",
7505 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007506 shouldFail: true,
7507 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007508 })
7509
7510 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7511 testCases = append(testCases, testCase{
7512 name: "StrayHelloRequest-TLS13",
7513 config: Config{
7514 MaxVersion: VersionTLS13,
7515 Bugs: ProtocolBugs{
7516 SendHelloRequestBeforeEveryHandshakeMessage: true,
7517 },
7518 },
7519 shouldFail: true,
7520 expectedError: ":UNEXPECTED_MESSAGE:",
7521 })
David Benjamind2610042017-01-03 10:49:28 -05007522
7523 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7524 // always reads as supporting it, regardless of whether it was
7525 // negotiated.
7526 testCases = append(testCases, testCase{
7527 name: "AlwaysReportRenegotiationInfo-TLS13",
7528 config: Config{
7529 MaxVersion: VersionTLS13,
7530 Bugs: ProtocolBugs{
7531 NoRenegotiationInfo: true,
7532 },
7533 },
7534 flags: []string{
7535 "-expect-secure-renegotiation",
7536 },
7537 })
David Benjamina58baaf2017-02-28 20:54:28 -05007538
7539 // Certificates may not change on renegotiation.
7540 testCases = append(testCases, testCase{
7541 name: "Renegotiation-CertificateChange",
7542 config: Config{
7543 MaxVersion: VersionTLS12,
7544 Certificates: []Certificate{rsaCertificate},
7545 Bugs: ProtocolBugs{
7546 RenegotiationCertificate: &rsaChainCertificate,
7547 },
7548 },
7549 renegotiate: 1,
7550 flags: []string{"-renegotiate-freely"},
7551 shouldFail: true,
7552 expectedError: ":SERVER_CERT_CHANGED:",
7553 })
7554 testCases = append(testCases, testCase{
7555 name: "Renegotiation-CertificateChange-2",
7556 config: Config{
7557 MaxVersion: VersionTLS12,
7558 Certificates: []Certificate{rsaCertificate},
7559 Bugs: ProtocolBugs{
7560 RenegotiationCertificate: &rsa1024Certificate,
7561 },
7562 },
7563 renegotiate: 1,
7564 flags: []string{"-renegotiate-freely"},
7565 shouldFail: true,
7566 expectedError: ":SERVER_CERT_CHANGED:",
7567 })
David Benjaminbbf42462017-03-14 21:27:10 -04007568
7569 // We do not negotiate ALPN after the initial handshake. This is
7570 // error-prone and only risks bugs in consumers.
7571 testCases = append(testCases, testCase{
7572 testType: clientTest,
7573 name: "Renegotiation-ForbidALPN",
7574 config: Config{
7575 MaxVersion: VersionTLS12,
7576 Bugs: ProtocolBugs{
7577 // Forcibly negotiate ALPN on both initial and
7578 // renegotiation handshakes. The test stack will
7579 // internally check the client does not offer
7580 // it.
7581 SendALPN: "foo",
7582 },
7583 },
7584 flags: []string{
7585 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7586 "-expect-alpn", "foo",
7587 "-renegotiate-freely",
7588 },
7589 renegotiate: 1,
7590 shouldFail: true,
7591 expectedError: ":UNEXPECTED_EXTENSION:",
7592 })
David Benjamin5c4271f2017-08-23 22:09:41 -07007593
7594 // The server may send different stapled OCSP responses or SCT lists on
7595 // renegotiation, but BoringSSL ignores this and reports the old values.
7596 // Also test that non-fatal verify results are preserved.
7597 testCases = append(testCases, testCase{
7598 testType: clientTest,
7599 name: "Renegotiation-ChangeAuthProperties",
7600 config: Config{
7601 MaxVersion: VersionTLS12,
7602 Bugs: ProtocolBugs{
7603 SendOCSPResponseOnRenegotiation: testOCSPResponse2,
7604 SendSCTListOnRenegotiation: testSCTList2,
7605 },
7606 },
7607 renegotiate: 1,
7608 flags: []string{
7609 "-renegotiate-freely",
7610 "-expect-total-renegotiations", "1",
7611 "-enable-ocsp-stapling",
7612 "-expect-ocsp-response",
7613 base64.StdEncoding.EncodeToString(testOCSPResponse),
7614 "-enable-signed-cert-timestamps",
7615 "-expect-signed-cert-timestamps",
7616 base64.StdEncoding.EncodeToString(testSCTList),
7617 "-verify-fail",
7618 "-expect-verify-result",
7619 },
7620 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007621}
7622
David Benjamin5e961c12014-11-07 01:48:35 -05007623func addDTLSReplayTests() {
7624 // Test that sequence number replays are detected.
7625 testCases = append(testCases, testCase{
7626 protocol: dtls,
7627 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007628 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007629 replayWrites: true,
7630 })
7631
David Benjamin8e6db492015-07-25 18:29:23 -04007632 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007633 // than the retransmit window.
7634 testCases = append(testCases, testCase{
7635 protocol: dtls,
7636 name: "DTLS-Replay-LargeGaps",
7637 config: Config{
7638 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007639 SequenceNumberMapping: func(in uint64) uint64 {
7640 return in * 127
7641 },
David Benjamin5e961c12014-11-07 01:48:35 -05007642 },
7643 },
David Benjamin8e6db492015-07-25 18:29:23 -04007644 messageCount: 200,
7645 replayWrites: true,
7646 })
7647
7648 // Test the incoming sequence number changing non-monotonically.
7649 testCases = append(testCases, testCase{
7650 protocol: dtls,
7651 name: "DTLS-Replay-NonMonotonic",
7652 config: Config{
7653 Bugs: ProtocolBugs{
7654 SequenceNumberMapping: func(in uint64) uint64 {
7655 return in ^ 31
7656 },
7657 },
7658 },
7659 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007660 replayWrites: true,
7661 })
7662}
7663
Nick Harper60edffd2016-06-21 15:19:24 -07007664var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007665 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007666 id signatureAlgorithm
7667 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007668}{
Nick Harper60edffd2016-06-21 15:19:24 -07007669 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7670 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7671 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7672 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007673 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007674 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7675 // hash function doesn't have to match the curve and so the same
7676 // signature algorithm works with P-224.
7677 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007678 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7679 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7680 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007681 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7682 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7683 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007684 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007685 // Tests for key types prior to TLS 1.2.
7686 {"RSA", 0, testCertRSA},
7687 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007688}
7689
Nick Harper60edffd2016-06-21 15:19:24 -07007690const fakeSigAlg1 signatureAlgorithm = 0x2a01
7691const fakeSigAlg2 signatureAlgorithm = 0xff01
7692
7693func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007694 // Not all ciphers involve a signature. Advertise a list which gives all
7695 // versions a signing cipher.
7696 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007697 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007698 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7699 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7700 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7701 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007702 }
David Benjamin5208fd42016-07-13 21:43:25 -04007703
David Benjaminca3d5452016-07-14 12:51:01 -04007704 var allAlgorithms []signatureAlgorithm
7705 for _, alg := range testSignatureAlgorithms {
7706 if alg.id != 0 {
7707 allAlgorithms = append(allAlgorithms, alg.id)
7708 }
7709 }
7710
Nick Harper60edffd2016-06-21 15:19:24 -07007711 // Make sure each signature algorithm works. Include some fake values in
7712 // the list and ensure they're ignored.
7713 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007714 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007715 if (ver.version < VersionTLS12) != (alg.id == 0) {
7716 continue
7717 }
7718
7719 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7720 // or remove it in C.
7721 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007722 continue
7723 }
Nick Harper60edffd2016-06-21 15:19:24 -07007724
David Benjamin3ef76972016-10-17 17:59:54 -04007725 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007726 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007727 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007728 shouldSignFail = true
7729 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007730 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007731 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007732 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7733 shouldSignFail = true
7734 shouldVerifyFail = true
7735 }
7736 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7737 // the curve has to match the hash size.
7738 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007739 shouldSignFail = true
7740 shouldVerifyFail = true
7741 }
7742
7743 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7744 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7745 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007746 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007747
7748 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007749 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007750 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007751 }
7752 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007753 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007754 }
David Benjamin000800a2014-11-14 01:43:59 -05007755
David Benjamin1fb125c2016-07-08 18:52:12 -07007756 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007757
David Benjamin7a41d372016-07-09 11:21:54 -07007758 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007759 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007760 config: Config{
7761 MaxVersion: ver.version,
7762 ClientAuth: RequireAnyClientCert,
7763 VerifySignatureAlgorithms: []signatureAlgorithm{
7764 fakeSigAlg1,
7765 alg.id,
7766 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007767 },
David Benjamin7a41d372016-07-09 11:21:54 -07007768 },
7769 flags: []string{
7770 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7771 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7772 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007773 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007774 },
David Benjamina5022392017-07-10 17:40:39 -04007775 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007776 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007777 expectedError: signError,
7778 expectedPeerSignatureAlgorithm: alg.id,
7779 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007780
David Benjamin7a41d372016-07-09 11:21:54 -07007781 testCases = append(testCases, testCase{
7782 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007783 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007784 config: Config{
7785 MaxVersion: ver.version,
7786 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7787 SignSignatureAlgorithms: []signatureAlgorithm{
7788 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007789 },
David Benjamin7a41d372016-07-09 11:21:54 -07007790 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007791 SkipECDSACurveCheck: shouldVerifyFail,
7792 IgnoreSignatureVersionChecks: shouldVerifyFail,
7793 // Some signature algorithms may not be advertised.
7794 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007795 },
David Benjamin7a41d372016-07-09 11:21:54 -07007796 },
David Benjamina5022392017-07-10 17:40:39 -04007797 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007798 flags: []string{
7799 "-require-any-client-certificate",
7800 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7801 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007802 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007803 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007804 // Resume the session to assert the peer signature
7805 // algorithm is reported on both handshakes.
7806 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007807 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007808 expectedError: verifyError,
7809 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007810
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007811 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007812 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007813 testCases = append(testCases, testCase{
7814 testType: serverTest,
7815 name: "ServerAuth-Sign" + suffix,
7816 config: Config{
7817 MaxVersion: ver.version,
7818 CipherSuites: signingCiphers,
7819 VerifySignatureAlgorithms: []signatureAlgorithm{
7820 fakeSigAlg1,
7821 alg.id,
7822 fakeSigAlg2,
7823 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007824 },
David Benjamina5022392017-07-10 17:40:39 -04007825 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007826 flags: []string{
7827 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7828 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7829 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007830 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007831 },
7832 shouldFail: shouldSignFail,
7833 expectedError: signError,
7834 expectedPeerSignatureAlgorithm: alg.id,
7835 })
7836 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007837
7838 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007839 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007840 config: Config{
7841 MaxVersion: ver.version,
7842 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007843 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007844 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007845 alg.id,
7846 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007847 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007848 SkipECDSACurveCheck: shouldVerifyFail,
7849 IgnoreSignatureVersionChecks: shouldVerifyFail,
7850 // Some signature algorithms may not be advertised.
7851 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007852 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007853 },
David Benjamina5022392017-07-10 17:40:39 -04007854 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007855 flags: []string{
7856 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7857 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007858 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007859 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007860 // Resume the session to assert the peer signature
7861 // algorithm is reported on both handshakes.
7862 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007863 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007864 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007865 })
David Benjamin5208fd42016-07-13 21:43:25 -04007866
David Benjamin3ef76972016-10-17 17:59:54 -04007867 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007868 testCases = append(testCases, testCase{
7869 testType: serverTest,
7870 name: "ClientAuth-InvalidSignature" + suffix,
7871 config: Config{
7872 MaxVersion: ver.version,
7873 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7874 SignSignatureAlgorithms: []signatureAlgorithm{
7875 alg.id,
7876 },
7877 Bugs: ProtocolBugs{
7878 InvalidSignature: true,
7879 },
7880 },
David Benjamina5022392017-07-10 17:40:39 -04007881 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007882 flags: []string{
7883 "-require-any-client-certificate",
7884 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007885 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007886 },
7887 shouldFail: true,
7888 expectedError: ":BAD_SIGNATURE:",
7889 })
7890
7891 testCases = append(testCases, testCase{
7892 name: "ServerAuth-InvalidSignature" + suffix,
7893 config: Config{
7894 MaxVersion: ver.version,
7895 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7896 CipherSuites: signingCiphers,
7897 SignSignatureAlgorithms: []signatureAlgorithm{
7898 alg.id,
7899 },
7900 Bugs: ProtocolBugs{
7901 InvalidSignature: true,
7902 },
7903 },
David Benjamina5022392017-07-10 17:40:39 -04007904 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007905 flags: []string{
7906 "-enable-all-curves",
7907 "-enable-ed25519",
7908 },
David Benjamin5208fd42016-07-13 21:43:25 -04007909 shouldFail: true,
7910 expectedError: ":BAD_SIGNATURE:",
7911 })
7912 }
David Benjaminca3d5452016-07-14 12:51:01 -04007913
David Benjamin3ef76972016-10-17 17:59:54 -04007914 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007915 testCases = append(testCases, testCase{
7916 name: "ClientAuth-Sign-Negotiate" + suffix,
7917 config: Config{
7918 MaxVersion: ver.version,
7919 ClientAuth: RequireAnyClientCert,
7920 VerifySignatureAlgorithms: allAlgorithms,
7921 },
David Benjamina5022392017-07-10 17:40:39 -04007922 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007923 flags: []string{
7924 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7925 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7926 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007927 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007928 "-signing-prefs", strconv.Itoa(int(alg.id)),
7929 },
7930 expectedPeerSignatureAlgorithm: alg.id,
7931 })
7932
7933 testCases = append(testCases, testCase{
7934 testType: serverTest,
7935 name: "ServerAuth-Sign-Negotiate" + suffix,
7936 config: Config{
7937 MaxVersion: ver.version,
7938 CipherSuites: signingCiphers,
7939 VerifySignatureAlgorithms: allAlgorithms,
7940 },
David Benjamina5022392017-07-10 17:40:39 -04007941 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007942 flags: []string{
7943 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7944 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7945 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007946 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007947 "-signing-prefs", strconv.Itoa(int(alg.id)),
7948 },
7949 expectedPeerSignatureAlgorithm: alg.id,
7950 })
7951 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007952 }
David Benjamin000800a2014-11-14 01:43:59 -05007953 }
7954
Nick Harper60edffd2016-06-21 15:19:24 -07007955 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007956 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007957 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007958 config: Config{
7959 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007960 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007961 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007962 signatureECDSAWithP521AndSHA512,
7963 signatureRSAPKCS1WithSHA384,
7964 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007965 },
7966 },
7967 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007968 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7969 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007970 },
Nick Harper60edffd2016-06-21 15:19:24 -07007971 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007972 })
7973
7974 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007975 name: "ClientAuth-SignatureType-TLS13",
7976 config: Config{
7977 ClientAuth: RequireAnyClientCert,
7978 MaxVersion: VersionTLS13,
7979 VerifySignatureAlgorithms: []signatureAlgorithm{
7980 signatureECDSAWithP521AndSHA512,
7981 signatureRSAPKCS1WithSHA384,
7982 signatureRSAPSSWithSHA384,
7983 signatureECDSAWithSHA1,
7984 },
7985 },
7986 flags: []string{
7987 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7988 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7989 },
7990 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7991 })
7992
7993 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007994 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007995 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007996 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007997 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007999 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008000 signatureECDSAWithP521AndSHA512,
8001 signatureRSAPKCS1WithSHA384,
8002 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008003 },
8004 },
Nick Harper60edffd2016-06-21 15:19:24 -07008005 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05008006 })
8007
Steven Valdez143e8b32016-07-11 13:19:03 -04008008 testCases = append(testCases, testCase{
8009 testType: serverTest,
8010 name: "ServerAuth-SignatureType-TLS13",
8011 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008012 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008013 VerifySignatureAlgorithms: []signatureAlgorithm{
8014 signatureECDSAWithP521AndSHA512,
8015 signatureRSAPKCS1WithSHA384,
8016 signatureRSAPSSWithSHA384,
8017 signatureECDSAWithSHA1,
8018 },
8019 },
8020 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
8021 })
8022
David Benjamina95e9f32016-07-08 16:28:04 -07008023 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07008024 testCases = append(testCases, testCase{
8025 testType: serverTest,
8026 name: "Verify-ClientAuth-SignatureType",
8027 config: Config{
8028 MaxVersion: VersionTLS12,
8029 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008030 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07008031 signatureRSAPKCS1WithSHA256,
8032 },
8033 Bugs: ProtocolBugs{
8034 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8035 },
8036 },
8037 flags: []string{
8038 "-require-any-client-certificate",
8039 },
8040 shouldFail: true,
8041 expectedError: ":WRONG_SIGNATURE_TYPE:",
8042 })
8043
8044 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008045 testType: serverTest,
8046 name: "Verify-ClientAuth-SignatureType-TLS13",
8047 config: Config{
8048 MaxVersion: VersionTLS13,
8049 Certificates: []Certificate{rsaCertificate},
8050 SignSignatureAlgorithms: []signatureAlgorithm{
8051 signatureRSAPSSWithSHA256,
8052 },
8053 Bugs: ProtocolBugs{
8054 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8055 },
8056 },
8057 flags: []string{
8058 "-require-any-client-certificate",
8059 },
8060 shouldFail: true,
8061 expectedError: ":WRONG_SIGNATURE_TYPE:",
8062 })
8063
8064 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008065 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07008066 config: Config{
8067 MaxVersion: VersionTLS12,
8068 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008069 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07008070 signatureRSAPKCS1WithSHA256,
8071 },
8072 Bugs: ProtocolBugs{
8073 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8074 },
8075 },
8076 shouldFail: true,
8077 expectedError: ":WRONG_SIGNATURE_TYPE:",
8078 })
8079
Steven Valdez143e8b32016-07-11 13:19:03 -04008080 testCases = append(testCases, testCase{
8081 name: "Verify-ServerAuth-SignatureType-TLS13",
8082 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008083 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008084 SignSignatureAlgorithms: []signatureAlgorithm{
8085 signatureRSAPSSWithSHA256,
8086 },
8087 Bugs: ProtocolBugs{
8088 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8089 },
8090 },
8091 shouldFail: true,
8092 expectedError: ":WRONG_SIGNATURE_TYPE:",
8093 })
8094
David Benjamin51dd7d62016-07-08 16:07:01 -07008095 // Test that, if the list is missing, the peer falls back to SHA-1 in
8096 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008097 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008098 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008100 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008101 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008102 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008103 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008104 },
8105 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008106 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008107 },
8108 },
8109 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008110 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8111 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008112 },
8113 })
8114
8115 testCases = append(testCases, testCase{
8116 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008117 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008118 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008119 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07008120 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008121 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008122 },
8123 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008124 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008125 },
8126 },
David Benjaminee32bea2016-08-17 13:36:44 -04008127 flags: []string{
8128 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8129 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8130 },
8131 })
8132
8133 testCases = append(testCases, testCase{
8134 name: "ClientAuth-SHA1-Fallback-ECDSA",
8135 config: Config{
8136 MaxVersion: VersionTLS12,
8137 ClientAuth: RequireAnyClientCert,
8138 VerifySignatureAlgorithms: []signatureAlgorithm{
8139 signatureECDSAWithSHA1,
8140 },
8141 Bugs: ProtocolBugs{
8142 NoSignatureAlgorithms: true,
8143 },
8144 },
8145 flags: []string{
8146 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8147 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8148 },
8149 })
8150
8151 testCases = append(testCases, testCase{
8152 testType: serverTest,
8153 name: "ServerAuth-SHA1-Fallback-ECDSA",
8154 config: Config{
8155 MaxVersion: VersionTLS12,
8156 VerifySignatureAlgorithms: []signatureAlgorithm{
8157 signatureECDSAWithSHA1,
8158 },
8159 Bugs: ProtocolBugs{
8160 NoSignatureAlgorithms: true,
8161 },
8162 },
8163 flags: []string{
8164 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8165 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8166 },
David Benjamin000800a2014-11-14 01:43:59 -05008167 })
David Benjamin72dc7832015-03-16 17:49:43 -04008168
David Benjamin51dd7d62016-07-08 16:07:01 -07008169 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008170 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008171 config: Config{
8172 MaxVersion: VersionTLS13,
8173 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008174 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008175 signatureRSAPKCS1WithSHA1,
8176 },
8177 Bugs: ProtocolBugs{
8178 NoSignatureAlgorithms: true,
8179 },
8180 },
8181 flags: []string{
8182 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8183 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8184 },
David Benjamin48901652016-08-01 12:12:47 -04008185 shouldFail: true,
8186 // An empty CertificateRequest signature algorithm list is a
8187 // syntax error in TLS 1.3.
8188 expectedError: ":DECODE_ERROR:",
8189 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008190 })
8191
8192 testCases = append(testCases, testCase{
8193 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008194 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008195 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008196 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008197 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008198 signatureRSAPKCS1WithSHA1,
8199 },
8200 Bugs: ProtocolBugs{
8201 NoSignatureAlgorithms: true,
8202 },
8203 },
8204 shouldFail: true,
8205 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8206 })
8207
David Benjaminb62d2872016-07-18 14:55:02 +02008208 // Test that hash preferences are enforced. BoringSSL does not implement
8209 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008210 testCases = append(testCases, testCase{
8211 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008212 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008214 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008215 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008216 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008217 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008218 },
8219 Bugs: ProtocolBugs{
8220 IgnorePeerSignatureAlgorithmPreferences: true,
8221 },
8222 },
8223 flags: []string{"-require-any-client-certificate"},
8224 shouldFail: true,
8225 expectedError: ":WRONG_SIGNATURE_TYPE:",
8226 })
8227
8228 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008229 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008230 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008231 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008232 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008233 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008234 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008235 },
8236 Bugs: ProtocolBugs{
8237 IgnorePeerSignatureAlgorithmPreferences: true,
8238 },
8239 },
8240 shouldFail: true,
8241 expectedError: ":WRONG_SIGNATURE_TYPE:",
8242 })
David Benjaminb62d2872016-07-18 14:55:02 +02008243 testCases = append(testCases, testCase{
8244 testType: serverTest,
8245 name: "ClientAuth-Enforced-TLS13",
8246 config: Config{
8247 MaxVersion: VersionTLS13,
8248 Certificates: []Certificate{rsaCertificate},
8249 SignSignatureAlgorithms: []signatureAlgorithm{
8250 signatureRSAPKCS1WithMD5,
8251 },
8252 Bugs: ProtocolBugs{
8253 IgnorePeerSignatureAlgorithmPreferences: true,
8254 IgnoreSignatureVersionChecks: true,
8255 },
8256 },
8257 flags: []string{"-require-any-client-certificate"},
8258 shouldFail: true,
8259 expectedError: ":WRONG_SIGNATURE_TYPE:",
8260 })
8261
8262 testCases = append(testCases, testCase{
8263 name: "ServerAuth-Enforced-TLS13",
8264 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008265 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008266 SignSignatureAlgorithms: []signatureAlgorithm{
8267 signatureRSAPKCS1WithMD5,
8268 },
8269 Bugs: ProtocolBugs{
8270 IgnorePeerSignatureAlgorithmPreferences: true,
8271 IgnoreSignatureVersionChecks: true,
8272 },
8273 },
8274 shouldFail: true,
8275 expectedError: ":WRONG_SIGNATURE_TYPE:",
8276 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008277
8278 // Test that the agreed upon digest respects the client preferences and
8279 // the server digests.
8280 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008281 name: "NoCommonAlgorithms-Digests",
8282 config: Config{
8283 MaxVersion: VersionTLS12,
8284 ClientAuth: RequireAnyClientCert,
8285 VerifySignatureAlgorithms: []signatureAlgorithm{
8286 signatureRSAPKCS1WithSHA512,
8287 signatureRSAPKCS1WithSHA1,
8288 },
8289 },
8290 flags: []string{
8291 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8292 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8293 "-digest-prefs", "SHA256",
8294 },
8295 shouldFail: true,
8296 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8297 })
8298 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008299 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008301 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008302 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008303 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008304 signatureRSAPKCS1WithSHA512,
8305 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008306 },
8307 },
8308 flags: []string{
8309 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8310 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008311 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008312 },
David Benjaminca3d5452016-07-14 12:51:01 -04008313 shouldFail: true,
8314 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8315 })
8316 testCases = append(testCases, testCase{
8317 name: "NoCommonAlgorithms-TLS13",
8318 config: Config{
8319 MaxVersion: VersionTLS13,
8320 ClientAuth: RequireAnyClientCert,
8321 VerifySignatureAlgorithms: []signatureAlgorithm{
8322 signatureRSAPSSWithSHA512,
8323 signatureRSAPSSWithSHA384,
8324 },
8325 },
8326 flags: []string{
8327 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8328 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8329 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8330 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008331 shouldFail: true,
8332 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008333 })
8334 testCases = append(testCases, testCase{
8335 name: "Agree-Digest-SHA256",
8336 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008337 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008338 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008339 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008340 signatureRSAPKCS1WithSHA1,
8341 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008342 },
8343 },
8344 flags: []string{
8345 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8346 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008347 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008348 },
Nick Harper60edffd2016-06-21 15:19:24 -07008349 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008350 })
8351 testCases = append(testCases, testCase{
8352 name: "Agree-Digest-SHA1",
8353 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008354 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008355 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008356 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008357 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008358 },
8359 },
8360 flags: []string{
8361 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8362 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008363 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008364 },
Nick Harper60edffd2016-06-21 15:19:24 -07008365 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008366 })
8367 testCases = append(testCases, testCase{
8368 name: "Agree-Digest-Default",
8369 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008370 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008371 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008372 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008373 signatureRSAPKCS1WithSHA256,
8374 signatureECDSAWithP256AndSHA256,
8375 signatureRSAPKCS1WithSHA1,
8376 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008377 },
8378 },
8379 flags: []string{
8380 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8381 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8382 },
Nick Harper60edffd2016-06-21 15:19:24 -07008383 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008384 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008385
David Benjaminca3d5452016-07-14 12:51:01 -04008386 // Test that the signing preference list may include extra algorithms
8387 // without negotiation problems.
8388 testCases = append(testCases, testCase{
8389 testType: serverTest,
8390 name: "FilterExtraAlgorithms",
8391 config: Config{
8392 MaxVersion: VersionTLS12,
8393 VerifySignatureAlgorithms: []signatureAlgorithm{
8394 signatureRSAPKCS1WithSHA256,
8395 },
8396 },
8397 flags: []string{
8398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8400 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8401 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8402 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8403 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8404 },
8405 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8406 })
8407
David Benjamin4c3ddf72016-06-29 18:13:53 -04008408 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8409 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008410 testCases = append(testCases, testCase{
8411 name: "CheckLeafCurve",
8412 config: Config{
8413 MaxVersion: VersionTLS12,
8414 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008415 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008416 },
8417 flags: []string{"-p384-only"},
8418 shouldFail: true,
8419 expectedError: ":BAD_ECC_CERT:",
8420 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008421
8422 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8423 testCases = append(testCases, testCase{
8424 name: "CheckLeafCurve-TLS13",
8425 config: Config{
8426 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008427 Certificates: []Certificate{ecdsaP256Certificate},
8428 },
8429 flags: []string{"-p384-only"},
8430 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008431
8432 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8433 testCases = append(testCases, testCase{
8434 name: "ECDSACurveMismatch-Verify-TLS12",
8435 config: Config{
8436 MaxVersion: VersionTLS12,
8437 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8438 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008439 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008440 signatureECDSAWithP384AndSHA384,
8441 },
8442 },
8443 })
8444
8445 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8446 testCases = append(testCases, testCase{
8447 name: "ECDSACurveMismatch-Verify-TLS13",
8448 config: Config{
8449 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008450 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008451 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008452 signatureECDSAWithP384AndSHA384,
8453 },
8454 Bugs: ProtocolBugs{
8455 SkipECDSACurveCheck: true,
8456 },
8457 },
8458 shouldFail: true,
8459 expectedError: ":WRONG_SIGNATURE_TYPE:",
8460 })
8461
8462 // Signature algorithm selection in TLS 1.3 should take the curve into
8463 // account.
8464 testCases = append(testCases, testCase{
8465 testType: serverTest,
8466 name: "ECDSACurveMismatch-Sign-TLS13",
8467 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008468 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008469 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008470 signatureECDSAWithP384AndSHA384,
8471 signatureECDSAWithP256AndSHA256,
8472 },
8473 },
8474 flags: []string{
8475 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8476 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8477 },
8478 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8479 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008480
8481 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8482 // server does not attempt to sign in that case.
8483 testCases = append(testCases, testCase{
8484 testType: serverTest,
8485 name: "RSA-PSS-Large",
8486 config: Config{
8487 MaxVersion: VersionTLS13,
8488 VerifySignatureAlgorithms: []signatureAlgorithm{
8489 signatureRSAPSSWithSHA512,
8490 },
8491 },
8492 flags: []string{
8493 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8494 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8495 },
8496 shouldFail: true,
8497 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8498 })
David Benjamin57e929f2016-08-30 00:30:38 -04008499
8500 // Test that RSA-PSS is enabled by default for TLS 1.2.
8501 testCases = append(testCases, testCase{
8502 testType: clientTest,
8503 name: "RSA-PSS-Default-Verify",
8504 config: Config{
8505 MaxVersion: VersionTLS12,
8506 SignSignatureAlgorithms: []signatureAlgorithm{
8507 signatureRSAPSSWithSHA256,
8508 },
8509 },
8510 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8511 })
8512
8513 testCases = append(testCases, testCase{
8514 testType: serverTest,
8515 name: "RSA-PSS-Default-Sign",
8516 config: Config{
8517 MaxVersion: VersionTLS12,
8518 VerifySignatureAlgorithms: []signatureAlgorithm{
8519 signatureRSAPSSWithSHA256,
8520 },
8521 },
8522 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8523 })
David Benjamin69522112017-03-28 15:38:29 -05008524
8525 // TLS 1.1 and below has no way to advertise support for or negotiate
8526 // Ed25519's signature algorithm.
8527 testCases = append(testCases, testCase{
8528 testType: clientTest,
8529 name: "NoEd25519-TLS11-ServerAuth-Verify",
8530 config: Config{
8531 MaxVersion: VersionTLS11,
8532 Certificates: []Certificate{ed25519Certificate},
8533 Bugs: ProtocolBugs{
8534 // Sign with Ed25519 even though it is TLS 1.1.
8535 UseLegacySigningAlgorithm: signatureEd25519,
8536 },
8537 },
8538 flags: []string{"-enable-ed25519"},
8539 shouldFail: true,
8540 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8541 })
8542 testCases = append(testCases, testCase{
8543 testType: serverTest,
8544 name: "NoEd25519-TLS11-ServerAuth-Sign",
8545 config: Config{
8546 MaxVersion: VersionTLS11,
8547 },
8548 flags: []string{
8549 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8550 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8551 },
8552 shouldFail: true,
8553 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8554 })
8555 testCases = append(testCases, testCase{
8556 testType: serverTest,
8557 name: "NoEd25519-TLS11-ClientAuth-Verify",
8558 config: Config{
8559 MaxVersion: VersionTLS11,
8560 Certificates: []Certificate{ed25519Certificate},
8561 Bugs: ProtocolBugs{
8562 // Sign with Ed25519 even though it is TLS 1.1.
8563 UseLegacySigningAlgorithm: signatureEd25519,
8564 },
8565 },
8566 flags: []string{
8567 "-enable-ed25519",
8568 "-require-any-client-certificate",
8569 },
8570 shouldFail: true,
8571 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8572 })
8573 testCases = append(testCases, testCase{
8574 testType: clientTest,
8575 name: "NoEd25519-TLS11-ClientAuth-Sign",
8576 config: Config{
8577 MaxVersion: VersionTLS11,
8578 ClientAuth: RequireAnyClientCert,
8579 },
8580 flags: []string{
8581 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8582 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8583 },
8584 shouldFail: true,
8585 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8586 })
8587
8588 // Test Ed25519 is not advertised by default.
8589 testCases = append(testCases, testCase{
8590 testType: clientTest,
8591 name: "Ed25519DefaultDisable-NoAdvertise",
8592 config: Config{
8593 Certificates: []Certificate{ed25519Certificate},
8594 },
8595 shouldFail: true,
8596 expectedLocalError: "tls: no common signature algorithms",
8597 })
8598
8599 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8600 // preferences.
8601 testCases = append(testCases, testCase{
8602 testType: clientTest,
8603 name: "Ed25519DefaultDisable-NoAccept",
8604 config: Config{
8605 Certificates: []Certificate{ed25519Certificate},
8606 Bugs: ProtocolBugs{
8607 IgnorePeerSignatureAlgorithmPreferences: true,
8608 },
8609 },
8610 shouldFail: true,
8611 expectedLocalError: "remote error: illegal parameter",
8612 expectedError: ":WRONG_SIGNATURE_TYPE:",
8613 })
David Benjamin71c21b42017-04-14 17:05:40 -04008614
8615 // Test that configuring verify preferences changes what the client
8616 // advertises.
8617 testCases = append(testCases, testCase{
8618 name: "VerifyPreferences-Advertised",
8619 config: Config{
8620 Certificates: []Certificate{rsaCertificate},
8621 SignSignatureAlgorithms: []signatureAlgorithm{
8622 signatureRSAPSSWithSHA256,
8623 signatureRSAPSSWithSHA384,
8624 signatureRSAPSSWithSHA512,
8625 },
8626 },
8627 flags: []string{
8628 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8629 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8630 },
8631 })
8632
8633 // Test that the client advertises a set which the runner can find
8634 // nothing in common with.
8635 testCases = append(testCases, testCase{
8636 name: "VerifyPreferences-NoCommonAlgorithms",
8637 config: Config{
8638 Certificates: []Certificate{rsaCertificate},
8639 SignSignatureAlgorithms: []signatureAlgorithm{
8640 signatureRSAPSSWithSHA256,
8641 signatureRSAPSSWithSHA512,
8642 },
8643 },
8644 flags: []string{
8645 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8646 },
8647 shouldFail: true,
8648 expectedLocalError: "tls: no common signature algorithms",
8649 })
8650
8651 // Test that the client enforces its preferences when configured.
8652 testCases = append(testCases, testCase{
8653 name: "VerifyPreferences-Enforced",
8654 config: Config{
8655 Certificates: []Certificate{rsaCertificate},
8656 SignSignatureAlgorithms: []signatureAlgorithm{
8657 signatureRSAPSSWithSHA256,
8658 signatureRSAPSSWithSHA512,
8659 },
8660 Bugs: ProtocolBugs{
8661 IgnorePeerSignatureAlgorithmPreferences: true,
8662 },
8663 },
8664 flags: []string{
8665 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8666 },
8667 shouldFail: true,
8668 expectedLocalError: "remote error: illegal parameter",
8669 expectedError: ":WRONG_SIGNATURE_TYPE:",
8670 })
8671
8672 // Test that explicitly configuring Ed25519 is as good as changing the
8673 // boolean toggle.
8674 testCases = append(testCases, testCase{
8675 name: "VerifyPreferences-Ed25519",
8676 config: Config{
8677 Certificates: []Certificate{ed25519Certificate},
8678 },
8679 flags: []string{
8680 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8681 },
8682 })
David Benjamin000800a2014-11-14 01:43:59 -05008683}
8684
David Benjamin83f90402015-01-27 01:09:43 -05008685// timeouts is the retransmit schedule for BoringSSL. It doubles and
8686// caps at 60 seconds. On the 13th timeout, it gives up.
8687var timeouts = []time.Duration{
8688 1 * time.Second,
8689 2 * time.Second,
8690 4 * time.Second,
8691 8 * time.Second,
8692 16 * time.Second,
8693 32 * time.Second,
8694 60 * time.Second,
8695 60 * time.Second,
8696 60 * time.Second,
8697 60 * time.Second,
8698 60 * time.Second,
8699 60 * time.Second,
8700 60 * time.Second,
8701}
8702
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008703// shortTimeouts is an alternate set of timeouts which would occur if the
8704// initial timeout duration was set to 250ms.
8705var shortTimeouts = []time.Duration{
8706 250 * time.Millisecond,
8707 500 * time.Millisecond,
8708 1 * time.Second,
8709 2 * time.Second,
8710 4 * time.Second,
8711 8 * time.Second,
8712 16 * time.Second,
8713 32 * time.Second,
8714 60 * time.Second,
8715 60 * time.Second,
8716 60 * time.Second,
8717 60 * time.Second,
8718 60 * time.Second,
8719}
8720
David Benjamin83f90402015-01-27 01:09:43 -05008721func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008722 // These tests work by coordinating some behavior on both the shim and
8723 // the runner.
8724 //
8725 // TimeoutSchedule configures the runner to send a series of timeout
8726 // opcodes to the shim (see packetAdaptor) immediately before reading
8727 // each peer handshake flight N. The timeout opcode both simulates a
8728 // timeout in the shim and acts as a synchronization point to help the
8729 // runner bracket each handshake flight.
8730 //
8731 // We assume the shim does not read from the channel eagerly. It must
8732 // first wait until it has sent flight N and is ready to receive
8733 // handshake flight N+1. At this point, it will process the timeout
8734 // opcode. It must then immediately respond with a timeout ACK and act
8735 // as if the shim was idle for the specified amount of time.
8736 //
8737 // The runner then drops all packets received before the ACK and
8738 // continues waiting for flight N. This ordering results in one attempt
8739 // at sending flight N to be dropped. For the test to complete, the
8740 // shim must send flight N again, testing that the shim implements DTLS
8741 // retransmit on a timeout.
8742
Steven Valdez143e8b32016-07-11 13:19:03 -04008743 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008744 // likely be more epochs to cross and the final message's retransmit may
8745 // be more complex.
8746
David Benjamin11c82892017-02-23 20:40:31 -05008747 // Test that this is indeed the timeout schedule. Stress all
8748 // four patterns of handshake.
8749 for i := 1; i < len(timeouts); i++ {
8750 number := strconv.Itoa(i)
8751 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008752 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008753 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008754 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008755 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008756 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008757 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008758 },
8759 },
8760 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008761 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008762 })
David Benjamin11c82892017-02-23 20:40:31 -05008763 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008764 protocol: dtls,
8765 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008766 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008767 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008768 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008769 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008770 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008771 },
8772 },
8773 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008774 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008775 })
8776 }
David Benjamin11c82892017-02-23 20:40:31 -05008777
8778 // Test that exceeding the timeout schedule hits a read
8779 // timeout.
8780 testCases = append(testCases, testCase{
8781 protocol: dtls,
8782 name: "DTLS-Retransmit-Timeout",
8783 config: Config{
8784 MaxVersion: VersionTLS12,
8785 Bugs: ProtocolBugs{
8786 TimeoutSchedule: timeouts,
8787 },
8788 },
8789 resumeSession: true,
8790 flags: []string{"-async"},
8791 shouldFail: true,
8792 expectedError: ":READ_TIMEOUT_EXPIRED:",
8793 })
8794
8795 // Test that timeout handling has a fudge factor, due to API
8796 // problems.
8797 testCases = append(testCases, testCase{
8798 protocol: dtls,
8799 name: "DTLS-Retransmit-Fudge",
8800 config: Config{
8801 MaxVersion: VersionTLS12,
8802 Bugs: ProtocolBugs{
8803 TimeoutSchedule: []time.Duration{
8804 timeouts[0] - 10*time.Millisecond,
8805 },
8806 },
8807 },
8808 resumeSession: true,
8809 flags: []string{"-async"},
8810 })
8811
8812 // Test that the final Finished retransmitting isn't
8813 // duplicated if the peer badly fragments everything.
8814 testCases = append(testCases, testCase{
8815 testType: serverTest,
8816 protocol: dtls,
8817 name: "DTLS-Retransmit-Fragmented",
8818 config: Config{
8819 MaxVersion: VersionTLS12,
8820 Bugs: ProtocolBugs{
8821 TimeoutSchedule: []time.Duration{timeouts[0]},
8822 MaxHandshakeRecordLength: 2,
8823 },
8824 },
8825 flags: []string{"-async"},
8826 })
8827
8828 // Test the timeout schedule when a shorter initial timeout duration is set.
8829 testCases = append(testCases, testCase{
8830 protocol: dtls,
8831 name: "DTLS-Retransmit-Short-Client",
8832 config: Config{
8833 MaxVersion: VersionTLS12,
8834 Bugs: ProtocolBugs{
8835 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8836 },
8837 },
8838 resumeSession: true,
8839 flags: []string{
8840 "-async",
8841 "-initial-timeout-duration-ms", "250",
8842 },
8843 })
8844 testCases = append(testCases, testCase{
8845 protocol: dtls,
8846 testType: serverTest,
8847 name: "DTLS-Retransmit-Short-Server",
8848 config: Config{
8849 MaxVersion: VersionTLS12,
8850 Bugs: ProtocolBugs{
8851 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8852 },
8853 },
8854 resumeSession: true,
8855 flags: []string{
8856 "-async",
8857 "-initial-timeout-duration-ms", "250",
8858 },
8859 })
David Benjamin302b8182017-08-22 14:47:22 -07008860
8861 // If the shim sends the last Finished (server full or client resume
8862 // handshakes), it must retransmit that Finished when it sees a
8863 // post-handshake penultimate Finished from the runner. The above tests
8864 // cover this. Conversely, if the shim sends the penultimate Finished
8865 // (client full or server resume), test that it does not retransmit.
8866 testCases = append(testCases, testCase{
8867 protocol: dtls,
8868 testType: clientTest,
8869 name: "DTLS-StrayRetransmitFinished-ClientFull",
8870 config: Config{
8871 MaxVersion: VersionTLS12,
8872 Bugs: ProtocolBugs{
8873 RetransmitFinished: true,
8874 },
8875 },
8876 })
8877 testCases = append(testCases, testCase{
8878 protocol: dtls,
8879 testType: serverTest,
8880 name: "DTLS-StrayRetransmitFinished-ServerResume",
8881 config: Config{
8882 MaxVersion: VersionTLS12,
8883 },
8884 resumeConfig: &Config{
8885 MaxVersion: VersionTLS12,
8886 Bugs: ProtocolBugs{
8887 RetransmitFinished: true,
8888 },
8889 },
8890 resumeSession: true,
8891 })
David Benjamin83f90402015-01-27 01:09:43 -05008892}
8893
David Benjaminc565ebb2015-04-03 04:06:36 -04008894func addExportKeyingMaterialTests() {
8895 for _, vers := range tlsVersions {
8896 if vers.version == VersionSSL30 {
8897 continue
8898 }
8899 testCases = append(testCases, testCase{
8900 name: "ExportKeyingMaterial-" + vers.name,
8901 config: Config{
8902 MaxVersion: vers.version,
8903 },
David Benjamina5022392017-07-10 17:40:39 -04008904 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008905 exportKeyingMaterial: 1024,
8906 exportLabel: "label",
8907 exportContext: "context",
8908 useExportContext: true,
8909 })
8910 testCases = append(testCases, testCase{
8911 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8912 config: Config{
8913 MaxVersion: vers.version,
8914 },
David Benjamina5022392017-07-10 17:40:39 -04008915 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008916 exportKeyingMaterial: 1024,
8917 })
8918 testCases = append(testCases, testCase{
8919 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8920 config: Config{
8921 MaxVersion: vers.version,
8922 },
David Benjamina5022392017-07-10 17:40:39 -04008923 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008924 exportKeyingMaterial: 1024,
8925 useExportContext: true,
8926 })
8927 testCases = append(testCases, testCase{
8928 name: "ExportKeyingMaterial-Small-" + vers.name,
8929 config: Config{
8930 MaxVersion: vers.version,
8931 },
David Benjamina5022392017-07-10 17:40:39 -04008932 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008933 exportKeyingMaterial: 1,
8934 exportLabel: "label",
8935 exportContext: "context",
8936 useExportContext: true,
8937 })
8938 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008939
David Benjaminc565ebb2015-04-03 04:06:36 -04008940 testCases = append(testCases, testCase{
8941 name: "ExportKeyingMaterial-SSL3",
8942 config: Config{
8943 MaxVersion: VersionSSL30,
8944 },
8945 exportKeyingMaterial: 1024,
8946 exportLabel: "label",
8947 exportContext: "context",
8948 useExportContext: true,
8949 shouldFail: true,
8950 expectedError: "failed to export keying material",
8951 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008952
8953 // Exporters work during a False Start.
8954 testCases = append(testCases, testCase{
8955 name: "ExportKeyingMaterial-FalseStart",
8956 config: Config{
8957 MaxVersion: VersionTLS12,
8958 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8959 NextProtos: []string{"foo"},
8960 Bugs: ProtocolBugs{
8961 ExpectFalseStart: true,
8962 },
8963 },
8964 flags: []string{
8965 "-false-start",
8966 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008967 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008968 },
8969 shimWritesFirst: true,
8970 exportKeyingMaterial: 1024,
8971 exportLabel: "label",
8972 exportContext: "context",
8973 useExportContext: true,
8974 })
8975
8976 // Exporters do not work in the middle of a renegotiation. Test this by
8977 // triggering the exporter after every SSL_read call and configuring the
8978 // shim to run asynchronously.
8979 testCases = append(testCases, testCase{
8980 name: "ExportKeyingMaterial-Renegotiate",
8981 config: Config{
8982 MaxVersion: VersionTLS12,
8983 },
8984 renegotiate: 1,
8985 flags: []string{
8986 "-async",
8987 "-use-exporter-between-reads",
8988 "-renegotiate-freely",
8989 "-expect-total-renegotiations", "1",
8990 },
8991 shouldFail: true,
8992 expectedError: "failed to export keying material",
8993 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008994}
8995
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008996func addTLSUniqueTests() {
8997 for _, isClient := range []bool{false, true} {
8998 for _, isResumption := range []bool{false, true} {
8999 for _, hasEMS := range []bool{false, true} {
9000 var suffix string
9001 if isResumption {
9002 suffix = "Resume-"
9003 } else {
9004 suffix = "Full-"
9005 }
9006
9007 if hasEMS {
9008 suffix += "EMS-"
9009 } else {
9010 suffix += "NoEMS-"
9011 }
9012
9013 if isClient {
9014 suffix += "Client"
9015 } else {
9016 suffix += "Server"
9017 }
9018
9019 test := testCase{
9020 name: "TLSUnique-" + suffix,
9021 testTLSUnique: true,
9022 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009023 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009024 Bugs: ProtocolBugs{
9025 NoExtendedMasterSecret: !hasEMS,
9026 },
9027 },
9028 }
9029
9030 if isResumption {
9031 test.resumeSession = true
9032 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009033 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009034 Bugs: ProtocolBugs{
9035 NoExtendedMasterSecret: !hasEMS,
9036 },
9037 }
9038 }
9039
9040 if isResumption && !hasEMS {
9041 test.shouldFail = true
9042 test.expectedError = "failed to get tls-unique"
9043 }
9044
9045 testCases = append(testCases, test)
9046 }
9047 }
9048 }
9049}
9050
Adam Langley09505632015-07-30 18:10:13 -07009051func addCustomExtensionTests() {
9052 expectedContents := "custom extension"
9053 emptyString := ""
9054
9055 for _, isClient := range []bool{false, true} {
9056 suffix := "Server"
9057 flag := "-enable-server-custom-extension"
9058 testType := serverTest
9059 if isClient {
9060 suffix = "Client"
9061 flag = "-enable-client-custom-extension"
9062 testType = clientTest
9063 }
9064
9065 testCases = append(testCases, testCase{
9066 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009067 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009069 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009070 Bugs: ProtocolBugs{
9071 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009072 ExpectedCustomExtension: &expectedContents,
9073 },
9074 },
9075 flags: []string{flag},
9076 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009077 testCases = append(testCases, testCase{
9078 testType: testType,
9079 name: "CustomExtensions-" + suffix + "-TLS13",
9080 config: Config{
9081 MaxVersion: VersionTLS13,
9082 Bugs: ProtocolBugs{
9083 CustomExtension: expectedContents,
9084 ExpectedCustomExtension: &expectedContents,
9085 },
9086 },
9087 flags: []string{flag},
9088 })
Adam Langley09505632015-07-30 18:10:13 -07009089
9090 // If the parse callback fails, the handshake should also fail.
9091 testCases = append(testCases, testCase{
9092 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009093 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009094 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009095 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009096 Bugs: ProtocolBugs{
9097 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07009098 ExpectedCustomExtension: &expectedContents,
9099 },
9100 },
David Benjamin399e7c92015-07-30 23:01:27 -04009101 flags: []string{flag},
9102 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009103 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9104 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009105 testCases = append(testCases, testCase{
9106 testType: testType,
9107 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
9108 config: Config{
9109 MaxVersion: VersionTLS13,
9110 Bugs: ProtocolBugs{
9111 CustomExtension: expectedContents + "foo",
9112 ExpectedCustomExtension: &expectedContents,
9113 },
9114 },
9115 flags: []string{flag},
9116 shouldFail: true,
9117 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9118 })
Adam Langley09505632015-07-30 18:10:13 -07009119
9120 // If the add callback fails, the handshake should also fail.
9121 testCases = append(testCases, testCase{
9122 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009123 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009124 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009125 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009126 Bugs: ProtocolBugs{
9127 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009128 ExpectedCustomExtension: &expectedContents,
9129 },
9130 },
David Benjamin399e7c92015-07-30 23:01:27 -04009131 flags: []string{flag, "-custom-extension-fail-add"},
9132 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009133 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9134 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009135 testCases = append(testCases, testCase{
9136 testType: testType,
9137 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9138 config: Config{
9139 MaxVersion: VersionTLS13,
9140 Bugs: ProtocolBugs{
9141 CustomExtension: expectedContents,
9142 ExpectedCustomExtension: &expectedContents,
9143 },
9144 },
9145 flags: []string{flag, "-custom-extension-fail-add"},
9146 shouldFail: true,
9147 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9148 })
Adam Langley09505632015-07-30 18:10:13 -07009149
9150 // If the add callback returns zero, no extension should be
9151 // added.
9152 skipCustomExtension := expectedContents
9153 if isClient {
9154 // For the case where the client skips sending the
9155 // custom extension, the server must not “echo” it.
9156 skipCustomExtension = ""
9157 }
9158 testCases = append(testCases, testCase{
9159 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009160 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009161 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009162 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009163 Bugs: ProtocolBugs{
9164 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009165 ExpectedCustomExtension: &emptyString,
9166 },
9167 },
9168 flags: []string{flag, "-custom-extension-skip"},
9169 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009170 testCases = append(testCases, testCase{
9171 testType: testType,
9172 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9173 config: Config{
9174 MaxVersion: VersionTLS13,
9175 Bugs: ProtocolBugs{
9176 CustomExtension: skipCustomExtension,
9177 ExpectedCustomExtension: &emptyString,
9178 },
9179 },
9180 flags: []string{flag, "-custom-extension-skip"},
9181 })
Adam Langley09505632015-07-30 18:10:13 -07009182 }
9183
Steven Valdezf4ecc842017-08-10 14:02:56 -04009184 // If the client sends both early data and custom extension, the handshake
9185 // should succeed as long as both the extensions aren't returned by the
9186 // server.
9187 testCases = append(testCases, testCase{
9188 testType: clientTest,
9189 name: "CustomExtensions-Client-EarlyData-None",
9190 config: Config{
9191 MaxVersion: VersionTLS13,
9192 MaxEarlyDataSize: 16384,
9193 Bugs: ProtocolBugs{
9194 ExpectedCustomExtension: &expectedContents,
9195 AlwaysRejectEarlyData: true,
9196 },
9197 },
9198 resumeSession: true,
9199 flags: []string{
9200 "-enable-client-custom-extension",
9201 "-enable-early-data",
9202 "-expect-early-data-info",
9203 "-expect-reject-early-data",
9204 },
9205 })
9206
9207 testCases = append(testCases, testCase{
9208 testType: clientTest,
9209 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9210 config: Config{
9211 MaxVersion: VersionTLS13,
9212 MaxEarlyDataSize: 16384,
9213 Bugs: ProtocolBugs{
9214 ExpectedCustomExtension: &expectedContents,
9215 },
9216 },
9217 resumeSession: true,
9218 flags: []string{
9219 "-enable-client-custom-extension",
9220 "-enable-early-data",
9221 "-expect-early-data-info",
9222 "-expect-accept-early-data",
9223 },
9224 })
9225
9226 testCases = append(testCases, testCase{
9227 testType: clientTest,
9228 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9229 config: Config{
9230 MaxVersion: VersionTLS13,
9231 MaxEarlyDataSize: 16384,
9232 Bugs: ProtocolBugs{
9233 AlwaysRejectEarlyData: true,
9234 CustomExtension: expectedContents,
9235 ExpectedCustomExtension: &expectedContents,
9236 },
9237 },
9238 resumeSession: true,
9239 flags: []string{
9240 "-enable-client-custom-extension",
9241 "-enable-early-data",
9242 "-expect-early-data-info",
9243 "-expect-reject-early-data",
9244 },
9245 })
9246
9247 testCases = append(testCases, testCase{
9248 testType: clientTest,
9249 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9250 config: Config{
9251 MaxVersion: VersionTLS13,
9252 MaxEarlyDataSize: 16384,
9253 Bugs: ProtocolBugs{
9254 CustomExtension: expectedContents,
9255 ExpectedCustomExtension: &expectedContents,
9256 },
9257 },
9258 resumeConfig: &Config{
9259 MaxVersion: VersionTLS13,
9260 MaxEarlyDataSize: 16384,
9261 Bugs: ProtocolBugs{
9262 CustomExtension: expectedContents,
9263 ExpectedCustomExtension: &expectedContents,
9264 SendEarlyDataExtension: true,
9265 },
9266 },
9267 resumeSession: true,
9268 shouldFail: true,
9269 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9270 flags: []string{
9271 "-enable-client-custom-extension",
9272 "-enable-early-data",
9273 "-expect-early-data-info",
9274 },
9275 })
9276
9277 // If the server receives both early data and custom extension, only the
9278 // custom extension should be accepted.
9279 testCases = append(testCases, testCase{
9280 testType: serverTest,
9281 name: "CustomExtensions-Server-EarlyDataAccepted",
9282 config: Config{
9283 MaxVersion: VersionTLS13,
9284 MaxEarlyDataSize: 16384,
9285 Bugs: ProtocolBugs{
9286 CustomExtension: expectedContents,
9287 ExpectedCustomExtension: &expectedContents,
9288 ExpectEarlyDataAccepted: false,
9289 },
9290 },
9291 resumeSession: true,
9292 flags: []string{
9293 "-enable-server-custom-extension",
9294 "-enable-early-data",
9295 "-expect-early-data-info",
9296 },
9297 })
9298
Adam Langley09505632015-07-30 18:10:13 -07009299 // The custom extension add callback should not be called if the client
9300 // doesn't send the extension.
9301 testCases = append(testCases, testCase{
9302 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009303 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009304 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009305 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009306 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009307 ExpectedCustomExtension: &emptyString,
9308 },
9309 },
9310 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9311 })
Adam Langley2deb9842015-08-07 11:15:37 -07009312
Steven Valdez143e8b32016-07-11 13:19:03 -04009313 testCases = append(testCases, testCase{
9314 testType: serverTest,
9315 name: "CustomExtensions-NotCalled-Server-TLS13",
9316 config: Config{
9317 MaxVersion: VersionTLS13,
9318 Bugs: ProtocolBugs{
9319 ExpectedCustomExtension: &emptyString,
9320 },
9321 },
9322 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9323 })
9324
Adam Langley2deb9842015-08-07 11:15:37 -07009325 // Test an unknown extension from the server.
9326 testCases = append(testCases, testCase{
9327 testType: clientTest,
9328 name: "UnknownExtension-Client",
9329 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009330 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009331 Bugs: ProtocolBugs{
9332 CustomExtension: expectedContents,
9333 },
9334 },
David Benjamin0c40a962016-08-01 12:05:50 -04009335 shouldFail: true,
9336 expectedError: ":UNEXPECTED_EXTENSION:",
9337 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009338 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009339 testCases = append(testCases, testCase{
9340 testType: clientTest,
9341 name: "UnknownExtension-Client-TLS13",
9342 config: Config{
9343 MaxVersion: VersionTLS13,
9344 Bugs: ProtocolBugs{
9345 CustomExtension: expectedContents,
9346 },
9347 },
David Benjamin0c40a962016-08-01 12:05:50 -04009348 shouldFail: true,
9349 expectedError: ":UNEXPECTED_EXTENSION:",
9350 expectedLocalError: "remote error: unsupported extension",
9351 })
David Benjamin490469f2016-10-05 22:44:38 -04009352 testCases = append(testCases, testCase{
9353 testType: clientTest,
9354 name: "UnknownUnencryptedExtension-Client-TLS13",
9355 config: Config{
9356 MaxVersion: VersionTLS13,
9357 Bugs: ProtocolBugs{
9358 CustomUnencryptedExtension: expectedContents,
9359 },
9360 },
9361 shouldFail: true,
9362 expectedError: ":UNEXPECTED_EXTENSION:",
9363 // The shim must send an alert, but alerts at this point do not
9364 // get successfully decrypted by the runner.
9365 expectedLocalError: "local error: bad record MAC",
9366 })
9367 testCases = append(testCases, testCase{
9368 testType: clientTest,
9369 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9370 config: Config{
9371 MaxVersion: VersionTLS13,
9372 Bugs: ProtocolBugs{
9373 SendUnencryptedALPN: "foo",
9374 },
9375 },
9376 flags: []string{
9377 "-advertise-alpn", "\x03foo\x03bar",
9378 },
9379 shouldFail: true,
9380 expectedError: ":UNEXPECTED_EXTENSION:",
9381 // The shim must send an alert, but alerts at this point do not
9382 // get successfully decrypted by the runner.
9383 expectedLocalError: "local error: bad record MAC",
9384 })
David Benjamin0c40a962016-08-01 12:05:50 -04009385
9386 // Test a known but unoffered extension from the server.
9387 testCases = append(testCases, testCase{
9388 testType: clientTest,
9389 name: "UnofferedExtension-Client",
9390 config: Config{
9391 MaxVersion: VersionTLS12,
9392 Bugs: ProtocolBugs{
9393 SendALPN: "alpn",
9394 },
9395 },
9396 shouldFail: true,
9397 expectedError: ":UNEXPECTED_EXTENSION:",
9398 expectedLocalError: "remote error: unsupported extension",
9399 })
9400 testCases = append(testCases, testCase{
9401 testType: clientTest,
9402 name: "UnofferedExtension-Client-TLS13",
9403 config: Config{
9404 MaxVersion: VersionTLS13,
9405 Bugs: ProtocolBugs{
9406 SendALPN: "alpn",
9407 },
9408 },
9409 shouldFail: true,
9410 expectedError: ":UNEXPECTED_EXTENSION:",
9411 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009412 })
Adam Langley09505632015-07-30 18:10:13 -07009413}
9414
David Benjaminb36a3952015-12-01 18:53:13 -05009415func addRSAClientKeyExchangeTests() {
9416 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9417 testCases = append(testCases, testCase{
9418 testType: serverTest,
9419 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9420 config: Config{
9421 // Ensure the ClientHello version and final
9422 // version are different, to detect if the
9423 // server uses the wrong one.
9424 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009425 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009426 Bugs: ProtocolBugs{
9427 BadRSAClientKeyExchange: bad,
9428 },
9429 },
9430 shouldFail: true,
9431 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9432 })
9433 }
David Benjamine63d9d72016-09-19 18:27:34 -04009434
9435 // The server must compare whatever was in ClientHello.version for the
9436 // RSA premaster.
9437 testCases = append(testCases, testCase{
9438 testType: serverTest,
9439 name: "SendClientVersion-RSA",
9440 config: Config{
9441 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9442 Bugs: ProtocolBugs{
9443 SendClientVersion: 0x1234,
9444 },
9445 },
9446 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9447 })
David Benjaminb36a3952015-12-01 18:53:13 -05009448}
9449
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009450var testCurves = []struct {
9451 name string
9452 id CurveID
9453}{
Adam Langley764ab982017-03-10 18:01:30 -08009454 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009455 {"P-256", CurveP256},
9456 {"P-384", CurveP384},
9457 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009458 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009459}
9460
Steven Valdez5440fe02016-07-18 12:40:30 -04009461const bogusCurve = 0x1234
9462
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009463func addCurveTests() {
9464 for _, curve := range testCurves {
9465 testCases = append(testCases, testCase{
9466 name: "CurveTest-Client-" + curve.name,
9467 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009468 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009469 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9470 CurvePreferences: []CurveID{curve.id},
9471 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009472 flags: []string{
9473 "-enable-all-curves",
9474 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9475 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009476 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009477 })
9478 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009479 name: "CurveTest-Client-" + curve.name + "-TLS13",
9480 config: Config{
9481 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009482 CurvePreferences: []CurveID{curve.id},
9483 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009484 flags: []string{
9485 "-enable-all-curves",
9486 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9487 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009488 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009489 })
9490 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009491 testType: serverTest,
9492 name: "CurveTest-Server-" + curve.name,
9493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009494 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009495 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9496 CurvePreferences: []CurveID{curve.id},
9497 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009498 flags: []string{
9499 "-enable-all-curves",
9500 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9501 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009502 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009503 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009504 testCases = append(testCases, testCase{
9505 testType: serverTest,
9506 name: "CurveTest-Server-" + curve.name + "-TLS13",
9507 config: Config{
9508 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009509 CurvePreferences: []CurveID{curve.id},
9510 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009511 flags: []string{
9512 "-enable-all-curves",
9513 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9514 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009515 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009516 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009517 }
David Benjamin241ae832016-01-15 03:04:54 -05009518
9519 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009520 testCases = append(testCases, testCase{
9521 testType: serverTest,
9522 name: "UnknownCurve",
9523 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009524 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009525 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9526 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9527 },
9528 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009529
Steven Valdez803c77a2016-09-06 14:13:43 -04009530 // The server must be tolerant to bogus curves.
9531 testCases = append(testCases, testCase{
9532 testType: serverTest,
9533 name: "UnknownCurve-TLS13",
9534 config: Config{
9535 MaxVersion: VersionTLS13,
9536 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9537 },
9538 })
9539
David Benjamin4c3ddf72016-06-29 18:13:53 -04009540 // The server must not consider ECDHE ciphers when there are no
9541 // supported curves.
9542 testCases = append(testCases, testCase{
9543 testType: serverTest,
9544 name: "NoSupportedCurves",
9545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009546 MaxVersion: VersionTLS12,
9547 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9548 Bugs: ProtocolBugs{
9549 NoSupportedCurves: true,
9550 },
9551 },
9552 shouldFail: true,
9553 expectedError: ":NO_SHARED_CIPHER:",
9554 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009555 testCases = append(testCases, testCase{
9556 testType: serverTest,
9557 name: "NoSupportedCurves-TLS13",
9558 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009559 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009560 Bugs: ProtocolBugs{
9561 NoSupportedCurves: true,
9562 },
9563 },
9564 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009565 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009566 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009567
9568 // The server must fall back to another cipher when there are no
9569 // supported curves.
9570 testCases = append(testCases, testCase{
9571 testType: serverTest,
9572 name: "NoCommonCurves",
9573 config: Config{
9574 MaxVersion: VersionTLS12,
9575 CipherSuites: []uint16{
9576 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009577 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009578 },
9579 CurvePreferences: []CurveID{CurveP224},
9580 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009581 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009582 })
9583
9584 // The client must reject bogus curves and disabled curves.
9585 testCases = append(testCases, testCase{
9586 name: "BadECDHECurve",
9587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009588 MaxVersion: VersionTLS12,
9589 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9590 Bugs: ProtocolBugs{
9591 SendCurve: bogusCurve,
9592 },
9593 },
9594 shouldFail: true,
9595 expectedError: ":WRONG_CURVE:",
9596 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009597 testCases = append(testCases, testCase{
9598 name: "BadECDHECurve-TLS13",
9599 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009600 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009601 Bugs: ProtocolBugs{
9602 SendCurve: bogusCurve,
9603 },
9604 },
9605 shouldFail: true,
9606 expectedError: ":WRONG_CURVE:",
9607 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009608
9609 testCases = append(testCases, testCase{
9610 name: "UnsupportedCurve",
9611 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009612 MaxVersion: VersionTLS12,
9613 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9614 CurvePreferences: []CurveID{CurveP256},
9615 Bugs: ProtocolBugs{
9616 IgnorePeerCurvePreferences: true,
9617 },
9618 },
9619 flags: []string{"-p384-only"},
9620 shouldFail: true,
9621 expectedError: ":WRONG_CURVE:",
9622 })
9623
David Benjamin4f921572016-07-17 14:20:10 +02009624 testCases = append(testCases, testCase{
9625 // TODO(davidben): Add a TLS 1.3 version where
9626 // HelloRetryRequest requests an unsupported curve.
9627 name: "UnsupportedCurve-ServerHello-TLS13",
9628 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009629 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009630 CurvePreferences: []CurveID{CurveP384},
9631 Bugs: ProtocolBugs{
9632 SendCurve: CurveP256,
9633 },
9634 },
9635 flags: []string{"-p384-only"},
9636 shouldFail: true,
9637 expectedError: ":WRONG_CURVE:",
9638 })
9639
David Benjamin4c3ddf72016-06-29 18:13:53 -04009640 // Test invalid curve points.
9641 testCases = append(testCases, testCase{
9642 name: "InvalidECDHPoint-Client",
9643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009644 MaxVersion: VersionTLS12,
9645 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9646 CurvePreferences: []CurveID{CurveP256},
9647 Bugs: ProtocolBugs{
9648 InvalidECDHPoint: true,
9649 },
9650 },
9651 shouldFail: true,
9652 expectedError: ":INVALID_ENCODING:",
9653 })
9654 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009655 name: "InvalidECDHPoint-Client-TLS13",
9656 config: Config{
9657 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009658 CurvePreferences: []CurveID{CurveP256},
9659 Bugs: ProtocolBugs{
9660 InvalidECDHPoint: true,
9661 },
9662 },
9663 shouldFail: true,
9664 expectedError: ":INVALID_ENCODING:",
9665 })
9666 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009667 testType: serverTest,
9668 name: "InvalidECDHPoint-Server",
9669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009670 MaxVersion: VersionTLS12,
9671 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9672 CurvePreferences: []CurveID{CurveP256},
9673 Bugs: ProtocolBugs{
9674 InvalidECDHPoint: true,
9675 },
9676 },
9677 shouldFail: true,
9678 expectedError: ":INVALID_ENCODING:",
9679 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009680 testCases = append(testCases, testCase{
9681 testType: serverTest,
9682 name: "InvalidECDHPoint-Server-TLS13",
9683 config: Config{
9684 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009685 CurvePreferences: []CurveID{CurveP256},
9686 Bugs: ProtocolBugs{
9687 InvalidECDHPoint: true,
9688 },
9689 },
9690 shouldFail: true,
9691 expectedError: ":INVALID_ENCODING:",
9692 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009693
9694 // The previous curve ID should be reported on TLS 1.2 resumption.
9695 testCases = append(testCases, testCase{
9696 name: "CurveID-Resume-Client",
9697 config: Config{
9698 MaxVersion: VersionTLS12,
9699 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9700 CurvePreferences: []CurveID{CurveX25519},
9701 },
9702 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9703 resumeSession: true,
9704 })
9705 testCases = append(testCases, testCase{
9706 testType: serverTest,
9707 name: "CurveID-Resume-Server",
9708 config: Config{
9709 MaxVersion: VersionTLS12,
9710 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9711 CurvePreferences: []CurveID{CurveX25519},
9712 },
9713 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9714 resumeSession: true,
9715 })
9716
9717 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9718 // one should be reported.
9719 testCases = append(testCases, testCase{
9720 name: "CurveID-Resume-Client-TLS13",
9721 config: Config{
9722 MaxVersion: VersionTLS13,
9723 CurvePreferences: []CurveID{CurveX25519},
9724 },
9725 resumeConfig: &Config{
9726 MaxVersion: VersionTLS13,
9727 CurvePreferences: []CurveID{CurveP256},
9728 },
9729 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009730 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9731 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009732 },
9733 resumeSession: true,
9734 })
9735 testCases = append(testCases, testCase{
9736 testType: serverTest,
9737 name: "CurveID-Resume-Server-TLS13",
9738 config: Config{
9739 MaxVersion: VersionTLS13,
9740 CurvePreferences: []CurveID{CurveX25519},
9741 },
9742 resumeConfig: &Config{
9743 MaxVersion: VersionTLS13,
9744 CurvePreferences: []CurveID{CurveP256},
9745 },
9746 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009747 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9748 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009749 },
9750 resumeSession: true,
9751 })
David Benjamina81967b2016-12-22 09:16:57 -05009752
9753 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9754 testCases = append(testCases, testCase{
9755 name: "PointFormat-ServerHello-TLS12",
9756 config: Config{
9757 MaxVersion: VersionTLS12,
9758 Bugs: ProtocolBugs{
9759 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9760 },
9761 },
9762 })
9763 testCases = append(testCases, testCase{
9764 name: "PointFormat-EncryptedExtensions-TLS13",
9765 config: Config{
9766 MaxVersion: VersionTLS13,
9767 Bugs: ProtocolBugs{
9768 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9769 },
9770 },
9771 shouldFail: true,
9772 expectedError: ":ERROR_PARSING_EXTENSION:",
9773 })
9774
9775 // Test that we tolerate unknown point formats, as long as
9776 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9777 // check they are still functional.
9778 testCases = append(testCases, testCase{
9779 name: "PointFormat-Client-Tolerance",
9780 config: Config{
9781 MaxVersion: VersionTLS12,
9782 Bugs: ProtocolBugs{
9783 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9784 },
9785 },
9786 })
9787 testCases = append(testCases, testCase{
9788 testType: serverTest,
9789 name: "PointFormat-Server-Tolerance",
9790 config: Config{
9791 MaxVersion: VersionTLS12,
9792 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9793 Bugs: ProtocolBugs{
9794 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9795 },
9796 },
9797 })
9798
9799 // Test TLS 1.2 does not require the point format extension to be
9800 // present.
9801 testCases = append(testCases, testCase{
9802 name: "PointFormat-Client-Missing",
9803 config: Config{
9804 MaxVersion: VersionTLS12,
9805 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9806 Bugs: ProtocolBugs{
9807 SendSupportedPointFormats: []byte{},
9808 },
9809 },
9810 })
9811 testCases = append(testCases, testCase{
9812 testType: serverTest,
9813 name: "PointFormat-Server-Missing",
9814 config: Config{
9815 MaxVersion: VersionTLS12,
9816 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9817 Bugs: ProtocolBugs{
9818 SendSupportedPointFormats: []byte{},
9819 },
9820 },
9821 })
9822
9823 // If the point format extension is present, uncompressed points must be
9824 // offered. BoringSSL requires this whether or not ECDHE is used.
9825 testCases = append(testCases, testCase{
9826 name: "PointFormat-Client-MissingUncompressed",
9827 config: Config{
9828 MaxVersion: VersionTLS12,
9829 Bugs: ProtocolBugs{
9830 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9831 },
9832 },
9833 shouldFail: true,
9834 expectedError: ":ERROR_PARSING_EXTENSION:",
9835 })
9836 testCases = append(testCases, testCase{
9837 testType: serverTest,
9838 name: "PointFormat-Server-MissingUncompressed",
9839 config: Config{
9840 MaxVersion: VersionTLS12,
9841 Bugs: ProtocolBugs{
9842 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9843 },
9844 },
9845 shouldFail: true,
9846 expectedError: ":ERROR_PARSING_EXTENSION:",
9847 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009848}
9849
David Benjaminc9ae27c2016-06-24 22:56:37 -04009850func addTLS13RecordTests() {
9851 testCases = append(testCases, testCase{
9852 name: "TLS13-RecordPadding",
9853 config: Config{
9854 MaxVersion: VersionTLS13,
9855 MinVersion: VersionTLS13,
9856 Bugs: ProtocolBugs{
9857 RecordPadding: 10,
9858 },
9859 },
9860 })
9861
9862 testCases = append(testCases, testCase{
9863 name: "TLS13-EmptyRecords",
9864 config: Config{
9865 MaxVersion: VersionTLS13,
9866 MinVersion: VersionTLS13,
9867 Bugs: ProtocolBugs{
9868 OmitRecordContents: true,
9869 },
9870 },
9871 shouldFail: true,
9872 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9873 })
9874
9875 testCases = append(testCases, testCase{
9876 name: "TLS13-OnlyPadding",
9877 config: Config{
9878 MaxVersion: VersionTLS13,
9879 MinVersion: VersionTLS13,
9880 Bugs: ProtocolBugs{
9881 OmitRecordContents: true,
9882 RecordPadding: 10,
9883 },
9884 },
9885 shouldFail: true,
9886 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9887 })
9888
9889 testCases = append(testCases, testCase{
9890 name: "TLS13-WrongOuterRecord",
9891 config: Config{
9892 MaxVersion: VersionTLS13,
9893 MinVersion: VersionTLS13,
9894 Bugs: ProtocolBugs{
9895 OuterRecordType: recordTypeHandshake,
9896 },
9897 },
9898 shouldFail: true,
9899 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9900 })
9901}
9902
Steven Valdez5b986082016-09-01 12:29:49 -04009903func addSessionTicketTests() {
9904 testCases = append(testCases, testCase{
9905 // In TLS 1.2 and below, empty NewSessionTicket messages
9906 // mean the server changed its mind on sending a ticket.
9907 name: "SendEmptySessionTicket",
9908 config: Config{
9909 MaxVersion: VersionTLS12,
9910 Bugs: ProtocolBugs{
9911 SendEmptySessionTicket: true,
9912 },
9913 },
9914 flags: []string{"-expect-no-session"},
9915 })
9916
9917 // Test that the server ignores unknown PSK modes.
9918 testCases = append(testCases, testCase{
9919 testType: serverTest,
9920 name: "TLS13-SendUnknownModeSessionTicket-Server",
9921 config: Config{
9922 MaxVersion: VersionTLS13,
9923 Bugs: ProtocolBugs{
9924 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009925 },
9926 },
9927 resumeSession: true,
9928 expectedResumeVersion: VersionTLS13,
9929 })
9930
Steven Valdeza833c352016-11-01 13:39:36 -04009931 // Test that the server does not send session tickets with no matching key exchange mode.
9932 testCases = append(testCases, testCase{
9933 testType: serverTest,
9934 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9935 config: Config{
9936 MaxVersion: VersionTLS13,
9937 Bugs: ProtocolBugs{
9938 SendPSKKeyExchangeModes: []byte{0x1a},
9939 ExpectNoNewSessionTicket: true,
9940 },
9941 },
9942 })
9943
9944 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009945 testCases = append(testCases, testCase{
9946 testType: serverTest,
9947 name: "TLS13-SendBadKEModeSessionTicket-Server",
9948 config: Config{
9949 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009950 },
9951 resumeConfig: &Config{
9952 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009953 Bugs: ProtocolBugs{
9954 SendPSKKeyExchangeModes: []byte{0x1a},
9955 },
9956 },
9957 resumeSession: true,
9958 expectResumeRejected: true,
9959 })
9960
Steven Valdeza833c352016-11-01 13:39:36 -04009961 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009962 testCases = append(testCases, testCase{
9963 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009964 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009965 config: Config{
9966 MaxVersion: VersionTLS13,
9967 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009968 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009969 },
9970 },
Steven Valdeza833c352016-11-01 13:39:36 -04009971 resumeSession: true,
9972 flags: []string{
9973 "-resumption-delay", "10",
9974 },
Steven Valdez5b986082016-09-01 12:29:49 -04009975 })
9976
Steven Valdeza833c352016-11-01 13:39:36 -04009977 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009978 testCases = append(testCases, testCase{
9979 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009980 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009981 config: Config{
9982 MaxVersion: VersionTLS13,
9983 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009984 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009985 },
9986 },
Steven Valdeza833c352016-11-01 13:39:36 -04009987 resumeSession: true,
9988 shouldFail: true,
9989 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009990 })
9991
David Benjamin35ac5b72017-03-03 15:05:56 -05009992 // Test that the server's ticket age skew reporting works.
9993 testCases = append(testCases, testCase{
9994 testType: serverTest,
9995 name: "TLS13-TicketAgeSkew-Forward",
9996 config: Config{
9997 MaxVersion: VersionTLS13,
9998 Bugs: ProtocolBugs{
9999 SendTicketAge: 15 * time.Second,
10000 },
10001 },
David Benjamin065d7332017-03-26 10:51:43 -050010002 resumeSession: true,
10003 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -050010004 flags: []string{
10005 "-resumption-delay", "10",
10006 "-expect-ticket-age-skew", "5",
10007 },
10008 })
10009 testCases = append(testCases, testCase{
10010 testType: serverTest,
10011 name: "TLS13-TicketAgeSkew-Backward",
10012 config: Config{
10013 MaxVersion: VersionTLS13,
10014 Bugs: ProtocolBugs{
10015 SendTicketAge: 5 * time.Second,
10016 },
10017 },
David Benjamin065d7332017-03-26 10:51:43 -050010018 resumeSession: true,
10019 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -050010020 flags: []string{
10021 "-resumption-delay", "10",
10022 "-expect-ticket-age-skew", "-5",
10023 },
10024 })
10025
Steven Valdez08b65f42016-12-07 15:29:45 -050010026 testCases = append(testCases, testCase{
10027 testType: clientTest,
10028 name: "TLS13-SendTicketEarlyDataInfo",
10029 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -080010030 MaxVersion: VersionTLS13,
10031 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -050010032 },
10033 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -050010034 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -050010035 "-expect-early-data-info",
10036 },
10037 })
10038
David Benjamin9b160662017-01-25 19:53:43 -050010039 // Test that 0-RTT tickets are ignored in clients unless opted in.
10040 testCases = append(testCases, testCase{
10041 testType: clientTest,
10042 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
10043 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -080010044 MaxVersion: VersionTLS13,
10045 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -050010046 },
10047 })
10048
Steven Valdez08b65f42016-12-07 15:29:45 -050010049 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -050010050 testType: clientTest,
10051 name: "TLS13-DuplicateTicketEarlyDataInfo",
10052 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -080010053 MaxVersion: VersionTLS13,
10054 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -050010055 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -050010056 DuplicateTicketEarlyDataInfo: true,
10057 },
10058 },
10059 shouldFail: true,
10060 expectedError: ":DUPLICATE_EXTENSION:",
10061 expectedLocalError: "remote error: illegal parameter",
10062 })
10063
10064 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -050010065 testType: serverTest,
10066 name: "TLS13-ExpectTicketEarlyDataInfo",
10067 config: Config{
10068 MaxVersion: VersionTLS13,
10069 Bugs: ProtocolBugs{
10070 ExpectTicketEarlyDataInfo: true,
10071 },
10072 },
10073 flags: []string{
10074 "-enable-early-data",
10075 },
10076 })
David Benjamin17b30832017-01-28 14:00:32 -050010077
10078 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
10079 // is honored.
10080 testCases = append(testCases, testCase{
10081 testType: clientTest,
10082 name: "TLS13-HonorServerSessionTicketLifetime",
10083 config: Config{
10084 MaxVersion: VersionTLS13,
10085 Bugs: ProtocolBugs{
10086 SendTicketLifetime: 20 * time.Second,
10087 },
10088 },
10089 flags: []string{
10090 "-resumption-delay", "19",
10091 },
10092 resumeSession: true,
10093 })
10094 testCases = append(testCases, testCase{
10095 testType: clientTest,
10096 name: "TLS13-HonorServerSessionTicketLifetime-2",
10097 config: Config{
10098 MaxVersion: VersionTLS13,
10099 Bugs: ProtocolBugs{
10100 SendTicketLifetime: 20 * time.Second,
10101 // The client should not offer the expired session.
10102 ExpectNoTLS13PSK: true,
10103 },
10104 },
10105 flags: []string{
10106 "-resumption-delay", "21",
10107 },
David Benjamin023d4192017-02-06 13:49:07 -050010108 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -050010109 expectResumeRejected: true,
10110 })
Steven Valdez5b986082016-09-01 12:29:49 -040010111}
10112
David Benjamin82261be2016-07-07 14:32:50 -070010113func addChangeCipherSpecTests() {
10114 // Test missing ChangeCipherSpecs.
10115 testCases = append(testCases, testCase{
10116 name: "SkipChangeCipherSpec-Client",
10117 config: Config{
10118 MaxVersion: VersionTLS12,
10119 Bugs: ProtocolBugs{
10120 SkipChangeCipherSpec: true,
10121 },
10122 },
10123 shouldFail: true,
10124 expectedError: ":UNEXPECTED_RECORD:",
10125 })
10126 testCases = append(testCases, testCase{
10127 testType: serverTest,
10128 name: "SkipChangeCipherSpec-Server",
10129 config: Config{
10130 MaxVersion: VersionTLS12,
10131 Bugs: ProtocolBugs{
10132 SkipChangeCipherSpec: true,
10133 },
10134 },
10135 shouldFail: true,
10136 expectedError: ":UNEXPECTED_RECORD:",
10137 })
10138 testCases = append(testCases, testCase{
10139 testType: serverTest,
10140 name: "SkipChangeCipherSpec-Server-NPN",
10141 config: Config{
10142 MaxVersion: VersionTLS12,
10143 NextProtos: []string{"bar"},
10144 Bugs: ProtocolBugs{
10145 SkipChangeCipherSpec: true,
10146 },
10147 },
10148 flags: []string{
10149 "-advertise-npn", "\x03foo\x03bar\x03baz",
10150 },
10151 shouldFail: true,
10152 expectedError: ":UNEXPECTED_RECORD:",
10153 })
10154
10155 // Test synchronization between the handshake and ChangeCipherSpec.
10156 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10157 // rejected. Test both with and without handshake packing to handle both
10158 // when the partial post-CCS message is in its own record and when it is
10159 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010160 for _, packed := range []bool{false, true} {
10161 var suffix string
10162 if packed {
10163 suffix = "-Packed"
10164 }
10165
10166 testCases = append(testCases, testCase{
10167 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10168 config: Config{
10169 MaxVersion: VersionTLS12,
10170 Bugs: ProtocolBugs{
10171 FragmentAcrossChangeCipherSpec: true,
10172 PackHandshakeFlight: packed,
10173 },
10174 },
10175 shouldFail: true,
10176 expectedError: ":UNEXPECTED_RECORD:",
10177 })
10178 testCases = append(testCases, testCase{
10179 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10180 config: Config{
10181 MaxVersion: VersionTLS12,
10182 },
10183 resumeSession: true,
10184 resumeConfig: &Config{
10185 MaxVersion: VersionTLS12,
10186 Bugs: ProtocolBugs{
10187 FragmentAcrossChangeCipherSpec: true,
10188 PackHandshakeFlight: packed,
10189 },
10190 },
10191 shouldFail: true,
10192 expectedError: ":UNEXPECTED_RECORD:",
10193 })
10194 testCases = append(testCases, testCase{
10195 testType: serverTest,
10196 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10197 config: Config{
10198 MaxVersion: VersionTLS12,
10199 Bugs: ProtocolBugs{
10200 FragmentAcrossChangeCipherSpec: true,
10201 PackHandshakeFlight: packed,
10202 },
10203 },
10204 shouldFail: true,
10205 expectedError: ":UNEXPECTED_RECORD:",
10206 })
10207 testCases = append(testCases, testCase{
10208 testType: serverTest,
10209 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10210 config: Config{
10211 MaxVersion: VersionTLS12,
10212 },
10213 resumeSession: true,
10214 resumeConfig: &Config{
10215 MaxVersion: VersionTLS12,
10216 Bugs: ProtocolBugs{
10217 FragmentAcrossChangeCipherSpec: true,
10218 PackHandshakeFlight: packed,
10219 },
10220 },
10221 shouldFail: true,
10222 expectedError: ":UNEXPECTED_RECORD:",
10223 })
10224 testCases = append(testCases, testCase{
10225 testType: serverTest,
10226 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10227 config: Config{
10228 MaxVersion: VersionTLS12,
10229 NextProtos: []string{"bar"},
10230 Bugs: ProtocolBugs{
10231 FragmentAcrossChangeCipherSpec: true,
10232 PackHandshakeFlight: packed,
10233 },
10234 },
10235 flags: []string{
10236 "-advertise-npn", "\x03foo\x03bar\x03baz",
10237 },
10238 shouldFail: true,
10239 expectedError: ":UNEXPECTED_RECORD:",
10240 })
10241 }
10242
David Benjamin61672812016-07-14 23:10:43 -040010243 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10244 // messages in the handshake queue. Do this by testing the server
10245 // reading the client Finished, reversing the flight so Finished comes
10246 // first.
10247 testCases = append(testCases, testCase{
10248 protocol: dtls,
10249 testType: serverTest,
10250 name: "SendUnencryptedFinished-DTLS",
10251 config: Config{
10252 MaxVersion: VersionTLS12,
10253 Bugs: ProtocolBugs{
10254 SendUnencryptedFinished: true,
10255 ReverseHandshakeFragments: true,
10256 },
10257 },
10258 shouldFail: true,
10259 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10260 })
10261
Steven Valdez143e8b32016-07-11 13:19:03 -040010262 // Test synchronization between encryption changes and the handshake in
10263 // TLS 1.3, where ChangeCipherSpec is implicit.
10264 testCases = append(testCases, testCase{
10265 name: "PartialEncryptedExtensionsWithServerHello",
10266 config: Config{
10267 MaxVersion: VersionTLS13,
10268 Bugs: ProtocolBugs{
10269 PartialEncryptedExtensionsWithServerHello: true,
10270 },
10271 },
10272 shouldFail: true,
10273 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10274 })
10275 testCases = append(testCases, testCase{
10276 testType: serverTest,
10277 name: "PartialClientFinishedWithClientHello",
10278 config: Config{
10279 MaxVersion: VersionTLS13,
10280 Bugs: ProtocolBugs{
10281 PartialClientFinishedWithClientHello: true,
10282 },
10283 },
10284 shouldFail: true,
10285 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10286 })
10287
David Benjamin82261be2016-07-07 14:32:50 -070010288 // Test that early ChangeCipherSpecs are handled correctly.
10289 testCases = append(testCases, testCase{
10290 testType: serverTest,
10291 name: "EarlyChangeCipherSpec-server-1",
10292 config: Config{
10293 MaxVersion: VersionTLS12,
10294 Bugs: ProtocolBugs{
10295 EarlyChangeCipherSpec: 1,
10296 },
10297 },
10298 shouldFail: true,
10299 expectedError: ":UNEXPECTED_RECORD:",
10300 })
10301 testCases = append(testCases, testCase{
10302 testType: serverTest,
10303 name: "EarlyChangeCipherSpec-server-2",
10304 config: Config{
10305 MaxVersion: VersionTLS12,
10306 Bugs: ProtocolBugs{
10307 EarlyChangeCipherSpec: 2,
10308 },
10309 },
10310 shouldFail: true,
10311 expectedError: ":UNEXPECTED_RECORD:",
10312 })
10313 testCases = append(testCases, testCase{
10314 protocol: dtls,
10315 name: "StrayChangeCipherSpec",
10316 config: Config{
10317 // TODO(davidben): Once DTLS 1.3 exists, test
10318 // that stray ChangeCipherSpec messages are
10319 // rejected.
10320 MaxVersion: VersionTLS12,
10321 Bugs: ProtocolBugs{
10322 StrayChangeCipherSpec: true,
10323 },
10324 },
10325 })
10326
David Benjaminb0c761e2017-06-25 22:42:55 -040010327 // Test that reordered ChangeCipherSpecs are tolerated.
10328 testCases = append(testCases, testCase{
10329 protocol: dtls,
10330 name: "ReorderChangeCipherSpec-DTLS-Client",
10331 config: Config{
10332 MaxVersion: VersionTLS12,
10333 Bugs: ProtocolBugs{
10334 ReorderChangeCipherSpec: true,
10335 },
10336 },
10337 resumeSession: true,
10338 })
10339 testCases = append(testCases, testCase{
10340 testType: serverTest,
10341 protocol: dtls,
10342 name: "ReorderChangeCipherSpec-DTLS-Server",
10343 config: Config{
10344 MaxVersion: VersionTLS12,
10345 Bugs: ProtocolBugs{
10346 ReorderChangeCipherSpec: true,
10347 },
10348 },
10349 resumeSession: true,
10350 })
10351
David Benjamin82261be2016-07-07 14:32:50 -070010352 // Test that the contents of ChangeCipherSpec are checked.
10353 testCases = append(testCases, testCase{
10354 name: "BadChangeCipherSpec-1",
10355 config: Config{
10356 MaxVersion: VersionTLS12,
10357 Bugs: ProtocolBugs{
10358 BadChangeCipherSpec: []byte{2},
10359 },
10360 },
10361 shouldFail: true,
10362 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10363 })
10364 testCases = append(testCases, testCase{
10365 name: "BadChangeCipherSpec-2",
10366 config: Config{
10367 MaxVersion: VersionTLS12,
10368 Bugs: ProtocolBugs{
10369 BadChangeCipherSpec: []byte{1, 1},
10370 },
10371 },
10372 shouldFail: true,
10373 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10374 })
10375 testCases = append(testCases, testCase{
10376 protocol: dtls,
10377 name: "BadChangeCipherSpec-DTLS-1",
10378 config: Config{
10379 MaxVersion: VersionTLS12,
10380 Bugs: ProtocolBugs{
10381 BadChangeCipherSpec: []byte{2},
10382 },
10383 },
10384 shouldFail: true,
10385 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10386 })
10387 testCases = append(testCases, testCase{
10388 protocol: dtls,
10389 name: "BadChangeCipherSpec-DTLS-2",
10390 config: Config{
10391 MaxVersion: VersionTLS12,
10392 Bugs: ProtocolBugs{
10393 BadChangeCipherSpec: []byte{1, 1},
10394 },
10395 },
10396 shouldFail: true,
10397 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10398 })
10399}
10400
David Benjamincd2c8062016-09-09 11:28:16 -040010401type perMessageTest struct {
10402 messageType uint8
10403 test testCase
10404}
10405
10406// makePerMessageTests returns a series of test templates which cover each
10407// message in the TLS handshake. These may be used with bugs like
10408// WrongMessageType to fully test a per-message bug.
10409func makePerMessageTests() []perMessageTest {
10410 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010411 for _, protocol := range []protocol{tls, dtls} {
10412 var suffix string
10413 if protocol == dtls {
10414 suffix = "-DTLS"
10415 }
10416
David Benjamincd2c8062016-09-09 11:28:16 -040010417 ret = append(ret, perMessageTest{
10418 messageType: typeClientHello,
10419 test: testCase{
10420 protocol: protocol,
10421 testType: serverTest,
10422 name: "ClientHello" + suffix,
10423 config: Config{
10424 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010425 },
10426 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010427 })
10428
10429 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010430 ret = append(ret, perMessageTest{
10431 messageType: typeHelloVerifyRequest,
10432 test: testCase{
10433 protocol: protocol,
10434 name: "HelloVerifyRequest" + suffix,
10435 config: Config{
10436 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010437 },
10438 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010439 })
10440 }
10441
David Benjamincd2c8062016-09-09 11:28:16 -040010442 ret = append(ret, perMessageTest{
10443 messageType: typeServerHello,
10444 test: testCase{
10445 protocol: protocol,
10446 name: "ServerHello" + suffix,
10447 config: Config{
10448 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010449 },
10450 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010451 })
10452
David Benjamincd2c8062016-09-09 11:28:16 -040010453 ret = append(ret, perMessageTest{
10454 messageType: typeCertificate,
10455 test: testCase{
10456 protocol: protocol,
10457 name: "ServerCertificate" + suffix,
10458 config: Config{
10459 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010460 },
10461 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010462 })
10463
David Benjamincd2c8062016-09-09 11:28:16 -040010464 ret = append(ret, perMessageTest{
10465 messageType: typeCertificateStatus,
10466 test: testCase{
10467 protocol: protocol,
10468 name: "CertificateStatus" + suffix,
10469 config: Config{
10470 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010471 },
David Benjamincd2c8062016-09-09 11:28:16 -040010472 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010473 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010474 })
10475
David Benjamincd2c8062016-09-09 11:28:16 -040010476 ret = append(ret, perMessageTest{
10477 messageType: typeServerKeyExchange,
10478 test: testCase{
10479 protocol: protocol,
10480 name: "ServerKeyExchange" + suffix,
10481 config: Config{
10482 MaxVersion: VersionTLS12,
10483 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010484 },
10485 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010486 })
10487
David Benjamincd2c8062016-09-09 11:28:16 -040010488 ret = append(ret, perMessageTest{
10489 messageType: typeCertificateRequest,
10490 test: testCase{
10491 protocol: protocol,
10492 name: "CertificateRequest" + suffix,
10493 config: Config{
10494 MaxVersion: VersionTLS12,
10495 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010496 },
10497 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010498 })
10499
David Benjamincd2c8062016-09-09 11:28:16 -040010500 ret = append(ret, perMessageTest{
10501 messageType: typeServerHelloDone,
10502 test: testCase{
10503 protocol: protocol,
10504 name: "ServerHelloDone" + suffix,
10505 config: Config{
10506 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010507 },
10508 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010509 })
10510
David Benjamincd2c8062016-09-09 11:28:16 -040010511 ret = append(ret, perMessageTest{
10512 messageType: typeCertificate,
10513 test: testCase{
10514 testType: serverTest,
10515 protocol: protocol,
10516 name: "ClientCertificate" + suffix,
10517 config: Config{
10518 Certificates: []Certificate{rsaCertificate},
10519 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010520 },
David Benjamincd2c8062016-09-09 11:28:16 -040010521 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010522 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010523 })
10524
David Benjamincd2c8062016-09-09 11:28:16 -040010525 ret = append(ret, perMessageTest{
10526 messageType: typeCertificateVerify,
10527 test: testCase{
10528 testType: serverTest,
10529 protocol: protocol,
10530 name: "CertificateVerify" + suffix,
10531 config: Config{
10532 Certificates: []Certificate{rsaCertificate},
10533 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010534 },
David Benjamincd2c8062016-09-09 11:28:16 -040010535 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010536 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010537 })
10538
David Benjamincd2c8062016-09-09 11:28:16 -040010539 ret = append(ret, perMessageTest{
10540 messageType: typeClientKeyExchange,
10541 test: testCase{
10542 testType: serverTest,
10543 protocol: protocol,
10544 name: "ClientKeyExchange" + 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
10551 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010552 ret = append(ret, perMessageTest{
10553 messageType: typeNextProtocol,
10554 test: testCase{
10555 testType: serverTest,
10556 protocol: protocol,
10557 name: "NextProtocol" + suffix,
10558 config: Config{
10559 MaxVersion: VersionTLS12,
10560 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010561 },
David Benjamincd2c8062016-09-09 11:28:16 -040010562 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010563 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010564 })
10565
David Benjamincd2c8062016-09-09 11:28:16 -040010566 ret = append(ret, perMessageTest{
10567 messageType: typeChannelID,
10568 test: testCase{
10569 testType: serverTest,
10570 protocol: protocol,
10571 name: "ChannelID" + suffix,
10572 config: Config{
10573 MaxVersion: VersionTLS12,
10574 ChannelID: channelIDKey,
10575 },
10576 flags: []string{
10577 "-expect-channel-id",
10578 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010579 },
10580 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010581 })
10582 }
10583
David Benjamincd2c8062016-09-09 11:28:16 -040010584 ret = append(ret, perMessageTest{
10585 messageType: typeFinished,
10586 test: testCase{
10587 testType: serverTest,
10588 protocol: protocol,
10589 name: "ClientFinished" + suffix,
10590 config: Config{
10591 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010592 },
10593 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010594 })
10595
David Benjamincd2c8062016-09-09 11:28:16 -040010596 ret = append(ret, perMessageTest{
10597 messageType: typeNewSessionTicket,
10598 test: testCase{
10599 protocol: protocol,
10600 name: "NewSessionTicket" + suffix,
10601 config: Config{
10602 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010603 },
10604 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010605 })
10606
David Benjamincd2c8062016-09-09 11:28:16 -040010607 ret = append(ret, perMessageTest{
10608 messageType: typeFinished,
10609 test: testCase{
10610 protocol: protocol,
10611 name: "ServerFinished" + suffix,
10612 config: Config{
10613 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010614 },
10615 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010616 })
10617
10618 }
David Benjamincd2c8062016-09-09 11:28:16 -040010619
10620 ret = append(ret, perMessageTest{
10621 messageType: typeClientHello,
10622 test: testCase{
10623 testType: serverTest,
10624 name: "TLS13-ClientHello",
10625 config: Config{
10626 MaxVersion: VersionTLS13,
10627 },
10628 },
10629 })
10630
10631 ret = append(ret, perMessageTest{
10632 messageType: typeServerHello,
10633 test: testCase{
10634 name: "TLS13-ServerHello",
10635 config: Config{
10636 MaxVersion: VersionTLS13,
10637 },
10638 },
10639 })
10640
10641 ret = append(ret, perMessageTest{
10642 messageType: typeEncryptedExtensions,
10643 test: testCase{
10644 name: "TLS13-EncryptedExtensions",
10645 config: Config{
10646 MaxVersion: VersionTLS13,
10647 },
10648 },
10649 })
10650
10651 ret = append(ret, perMessageTest{
10652 messageType: typeCertificateRequest,
10653 test: testCase{
10654 name: "TLS13-CertificateRequest",
10655 config: Config{
10656 MaxVersion: VersionTLS13,
10657 ClientAuth: RequireAnyClientCert,
10658 },
10659 },
10660 })
10661
10662 ret = append(ret, perMessageTest{
10663 messageType: typeCertificate,
10664 test: testCase{
10665 name: "TLS13-ServerCertificate",
10666 config: Config{
10667 MaxVersion: VersionTLS13,
10668 },
10669 },
10670 })
10671
10672 ret = append(ret, perMessageTest{
10673 messageType: typeCertificateVerify,
10674 test: testCase{
10675 name: "TLS13-ServerCertificateVerify",
10676 config: Config{
10677 MaxVersion: VersionTLS13,
10678 },
10679 },
10680 })
10681
10682 ret = append(ret, perMessageTest{
10683 messageType: typeFinished,
10684 test: testCase{
10685 name: "TLS13-ServerFinished",
10686 config: Config{
10687 MaxVersion: VersionTLS13,
10688 },
10689 },
10690 })
10691
10692 ret = append(ret, perMessageTest{
10693 messageType: typeCertificate,
10694 test: testCase{
10695 testType: serverTest,
10696 name: "TLS13-ClientCertificate",
10697 config: Config{
10698 Certificates: []Certificate{rsaCertificate},
10699 MaxVersion: VersionTLS13,
10700 },
10701 flags: []string{"-require-any-client-certificate"},
10702 },
10703 })
10704
10705 ret = append(ret, perMessageTest{
10706 messageType: typeCertificateVerify,
10707 test: testCase{
10708 testType: serverTest,
10709 name: "TLS13-ClientCertificateVerify",
10710 config: Config{
10711 Certificates: []Certificate{rsaCertificate},
10712 MaxVersion: VersionTLS13,
10713 },
10714 flags: []string{"-require-any-client-certificate"},
10715 },
10716 })
10717
10718 ret = append(ret, perMessageTest{
10719 messageType: typeFinished,
10720 test: testCase{
10721 testType: serverTest,
10722 name: "TLS13-ClientFinished",
10723 config: Config{
10724 MaxVersion: VersionTLS13,
10725 },
10726 },
10727 })
10728
10729 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010730}
10731
David Benjamincd2c8062016-09-09 11:28:16 -040010732func addWrongMessageTypeTests() {
10733 for _, t := range makePerMessageTests() {
10734 t.test.name = "WrongMessageType-" + t.test.name
10735 t.test.config.Bugs.SendWrongMessageType = t.messageType
10736 t.test.shouldFail = true
10737 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10738 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010739
David Benjamincd2c8062016-09-09 11:28:16 -040010740 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10741 // In TLS 1.3, a bad ServerHello means the client sends
10742 // an unencrypted alert while the server expects
10743 // encryption, so the alert is not readable by runner.
10744 t.test.expectedLocalError = "local error: bad record MAC"
10745 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010746
David Benjamincd2c8062016-09-09 11:28:16 -040010747 testCases = append(testCases, t.test)
10748 }
David Benjaminebacdee2017-04-08 11:00:45 -040010749
10750 // The processing order for TLS 1.3 version negotiation is such that one
10751 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10752 // TLS 1.2. Test that we do not do this.
10753 testCases = append(testCases, testCase{
10754 name: "SendServerHelloAsHelloRetryRequest",
10755 config: Config{
10756 MaxVersion: VersionTLS12,
10757 Bugs: ProtocolBugs{
10758 SendServerHelloAsHelloRetryRequest: true,
10759 },
10760 },
10761 shouldFail: true,
10762 expectedError: ":UNEXPECTED_MESSAGE:",
10763 expectedLocalError: "remote error: unexpected message",
10764 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010765}
10766
David Benjamin639846e2016-09-09 11:41:18 -040010767func addTrailingMessageDataTests() {
10768 for _, t := range makePerMessageTests() {
10769 t.test.name = "TrailingMessageData-" + t.test.name
10770 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10771 t.test.shouldFail = true
10772 t.test.expectedError = ":DECODE_ERROR:"
10773 t.test.expectedLocalError = "remote error: error decoding message"
10774
10775 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10776 // In TLS 1.3, a bad ServerHello means the client sends
10777 // an unencrypted alert while the server expects
10778 // encryption, so the alert is not readable by runner.
10779 t.test.expectedLocalError = "local error: bad record MAC"
10780 }
10781
10782 if t.messageType == typeFinished {
10783 // Bad Finished messages read as the verify data having
10784 // the wrong length.
10785 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10786 t.test.expectedLocalError = "remote error: error decrypting message"
10787 }
10788
10789 testCases = append(testCases, t.test)
10790 }
10791}
10792
Steven Valdez143e8b32016-07-11 13:19:03 -040010793func addTLS13HandshakeTests() {
10794 testCases = append(testCases, testCase{
10795 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010796 name: "NegotiatePSKResumption-TLS13",
10797 config: Config{
10798 MaxVersion: VersionTLS13,
10799 Bugs: ProtocolBugs{
10800 NegotiatePSKResumption: true,
10801 },
10802 },
10803 resumeSession: true,
10804 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010805 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010806 })
10807
10808 testCases = append(testCases, testCase{
10809 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010810 name: "MissingKeyShare-Client",
10811 config: Config{
10812 MaxVersion: VersionTLS13,
10813 Bugs: ProtocolBugs{
10814 MissingKeyShare: true,
10815 },
10816 },
10817 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010818 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010819 })
10820
10821 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010822 testType: serverTest,
10823 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010824 config: Config{
10825 MaxVersion: VersionTLS13,
10826 Bugs: ProtocolBugs{
10827 MissingKeyShare: true,
10828 },
10829 },
10830 shouldFail: true,
10831 expectedError: ":MISSING_KEY_SHARE:",
10832 })
10833
10834 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010835 testType: serverTest,
10836 name: "DuplicateKeyShares",
10837 config: Config{
10838 MaxVersion: VersionTLS13,
10839 Bugs: ProtocolBugs{
10840 DuplicateKeyShares: true,
10841 },
10842 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010843 shouldFail: true,
10844 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010845 })
10846
10847 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010848 testType: serverTest,
10849 name: "SkipEarlyData",
10850 config: Config{
10851 MaxVersion: VersionTLS13,
10852 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010853 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010854 },
10855 },
10856 })
10857
10858 testCases = append(testCases, testCase{
10859 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010860 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010861 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010862 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040010863 Bugs: ProtocolBugs{
10864 SendFakeEarlyDataLength: 4,
10865 },
10866 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010867 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040010868 })
10869
10870 testCases = append(testCases, testCase{
10871 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010872 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10873 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010874 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040010875 Bugs: ProtocolBugs{
10876 SendFakeEarlyDataLength: 4,
10877 },
10878 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010879 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040010880 })
10881
10882 testCases = append(testCases, testCase{
10883 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010884 name: "SkipEarlyData-OmitEarlyDataExtension",
10885 config: Config{
10886 MaxVersion: VersionTLS13,
10887 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010888 SendFakeEarlyDataLength: 4,
10889 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010890 },
10891 },
10892 shouldFail: true,
10893 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10894 })
10895
10896 testCases = append(testCases, testCase{
10897 testType: serverTest,
10898 name: "SkipEarlyData-TooMuchData",
10899 config: Config{
10900 MaxVersion: VersionTLS13,
10901 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010902 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010903 },
10904 },
10905 shouldFail: true,
10906 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10907 })
10908
10909 testCases = append(testCases, testCase{
10910 testType: serverTest,
10911 name: "SkipEarlyData-Interleaved",
10912 config: Config{
10913 MaxVersion: VersionTLS13,
10914 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010915 SendFakeEarlyDataLength: 4,
10916 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010917 },
10918 },
10919 shouldFail: true,
10920 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10921 })
10922
10923 testCases = append(testCases, testCase{
10924 testType: serverTest,
10925 name: "SkipEarlyData-EarlyDataInTLS12",
10926 config: Config{
10927 MaxVersion: VersionTLS13,
10928 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010929 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010930 },
10931 },
10932 shouldFail: true,
10933 expectedError: ":UNEXPECTED_RECORD:",
10934 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10935 })
10936
10937 testCases = append(testCases, testCase{
10938 testType: serverTest,
10939 name: "SkipEarlyData-HRR",
10940 config: Config{
10941 MaxVersion: VersionTLS13,
10942 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010943 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010944 },
10945 DefaultCurves: []CurveID{},
10946 },
10947 })
10948
10949 testCases = append(testCases, testCase{
10950 testType: serverTest,
10951 name: "SkipEarlyData-HRR-Interleaved",
10952 config: Config{
10953 MaxVersion: VersionTLS13,
10954 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010955 SendFakeEarlyDataLength: 4,
10956 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010957 },
10958 DefaultCurves: []CurveID{},
10959 },
10960 shouldFail: true,
10961 expectedError: ":UNEXPECTED_RECORD:",
10962 })
10963
10964 testCases = append(testCases, testCase{
10965 testType: serverTest,
10966 name: "SkipEarlyData-HRR-TooMuchData",
10967 config: Config{
10968 MaxVersion: VersionTLS13,
10969 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010970 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010971 },
10972 DefaultCurves: []CurveID{},
10973 },
10974 shouldFail: true,
10975 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10976 })
10977
10978 // Test that skipping early data looking for cleartext correctly
10979 // processes an alert record.
10980 testCases = append(testCases, testCase{
10981 testType: serverTest,
10982 name: "SkipEarlyData-HRR-FatalAlert",
10983 config: Config{
10984 MaxVersion: VersionTLS13,
10985 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010986 SendEarlyAlert: true,
10987 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010988 },
10989 DefaultCurves: []CurveID{},
10990 },
10991 shouldFail: true,
10992 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10993 })
10994
10995 testCases = append(testCases, testCase{
10996 testType: serverTest,
10997 name: "SkipEarlyData-SecondClientHelloEarlyData",
10998 config: Config{
10999 MaxVersion: VersionTLS13,
11000 Bugs: ProtocolBugs{
11001 SendEarlyDataOnSecondClientHello: true,
11002 },
11003 DefaultCurves: []CurveID{},
11004 },
11005 shouldFail: true,
11006 expectedLocalError: "remote error: bad record MAC",
11007 })
11008
11009 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040011010 testType: clientTest,
11011 name: "EmptyEncryptedExtensions",
11012 config: Config{
11013 MaxVersion: VersionTLS13,
11014 Bugs: ProtocolBugs{
11015 EmptyEncryptedExtensions: true,
11016 },
11017 },
11018 shouldFail: true,
11019 expectedLocalError: "remote error: error decoding message",
11020 })
11021
11022 testCases = append(testCases, testCase{
11023 testType: clientTest,
11024 name: "EncryptedExtensionsWithKeyShare",
11025 config: Config{
11026 MaxVersion: VersionTLS13,
11027 Bugs: ProtocolBugs{
11028 EncryptedExtensionsWithKeyShare: true,
11029 },
11030 },
11031 shouldFail: true,
11032 expectedLocalError: "remote error: unsupported extension",
11033 })
Steven Valdez5440fe02016-07-18 12:40:30 -040011034
11035 testCases = append(testCases, testCase{
11036 testType: serverTest,
11037 name: "SendHelloRetryRequest",
11038 config: Config{
11039 MaxVersion: VersionTLS13,
11040 // Require a HelloRetryRequest for every curve.
11041 DefaultCurves: []CurveID{},
11042 },
11043 expectedCurveID: CurveX25519,
11044 })
11045
11046 testCases = append(testCases, testCase{
11047 testType: serverTest,
11048 name: "SendHelloRetryRequest-2",
11049 config: Config{
11050 MaxVersion: VersionTLS13,
11051 DefaultCurves: []CurveID{CurveP384},
11052 },
11053 // Although the ClientHello did not predict our preferred curve,
11054 // we always select it whether it is predicted or not.
11055 expectedCurveID: CurveX25519,
11056 })
11057
11058 testCases = append(testCases, testCase{
11059 name: "UnknownCurve-HelloRetryRequest",
11060 config: Config{
11061 MaxVersion: VersionTLS13,
11062 // P-384 requires HelloRetryRequest in BoringSSL.
11063 CurvePreferences: []CurveID{CurveP384},
11064 Bugs: ProtocolBugs{
11065 SendHelloRetryRequestCurve: bogusCurve,
11066 },
11067 },
11068 shouldFail: true,
11069 expectedError: ":WRONG_CURVE:",
11070 })
11071
11072 testCases = append(testCases, testCase{
11073 name: "DisabledCurve-HelloRetryRequest",
11074 config: Config{
11075 MaxVersion: VersionTLS13,
11076 CurvePreferences: []CurveID{CurveP256},
11077 Bugs: ProtocolBugs{
11078 IgnorePeerCurvePreferences: true,
11079 },
11080 },
11081 flags: []string{"-p384-only"},
11082 shouldFail: true,
11083 expectedError: ":WRONG_CURVE:",
11084 })
11085
11086 testCases = append(testCases, testCase{
11087 name: "UnnecessaryHelloRetryRequest",
11088 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040011089 MaxVersion: VersionTLS13,
11090 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040011091 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040011092 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040011093 },
11094 },
11095 shouldFail: true,
11096 expectedError: ":WRONG_CURVE:",
11097 })
11098
11099 testCases = append(testCases, testCase{
11100 name: "SecondHelloRetryRequest",
11101 config: Config{
11102 MaxVersion: VersionTLS13,
11103 // P-384 requires HelloRetryRequest in BoringSSL.
11104 CurvePreferences: []CurveID{CurveP384},
11105 Bugs: ProtocolBugs{
11106 SecondHelloRetryRequest: true,
11107 },
11108 },
11109 shouldFail: true,
11110 expectedError: ":UNEXPECTED_MESSAGE:",
11111 })
11112
11113 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011114 name: "HelloRetryRequest-Empty",
11115 config: Config{
11116 MaxVersion: VersionTLS13,
11117 Bugs: ProtocolBugs{
11118 AlwaysSendHelloRetryRequest: true,
11119 },
11120 },
11121 shouldFail: true,
11122 expectedError: ":DECODE_ERROR:",
11123 })
11124
11125 testCases = append(testCases, testCase{
11126 name: "HelloRetryRequest-DuplicateCurve",
11127 config: Config{
11128 MaxVersion: VersionTLS13,
11129 // P-384 requires a HelloRetryRequest against BoringSSL's default
11130 // configuration. Assert this ExpectMissingKeyShare.
11131 CurvePreferences: []CurveID{CurveP384},
11132 Bugs: ProtocolBugs{
11133 ExpectMissingKeyShare: true,
11134 DuplicateHelloRetryRequestExtensions: true,
11135 },
11136 },
11137 shouldFail: true,
11138 expectedError: ":DUPLICATE_EXTENSION:",
11139 expectedLocalError: "remote error: illegal parameter",
11140 })
11141
11142 testCases = append(testCases, testCase{
11143 name: "HelloRetryRequest-Cookie",
11144 config: Config{
11145 MaxVersion: VersionTLS13,
11146 Bugs: ProtocolBugs{
11147 SendHelloRetryRequestCookie: []byte("cookie"),
11148 },
11149 },
11150 })
11151
11152 testCases = append(testCases, testCase{
11153 name: "HelloRetryRequest-DuplicateCookie",
11154 config: Config{
11155 MaxVersion: VersionTLS13,
11156 Bugs: ProtocolBugs{
11157 SendHelloRetryRequestCookie: []byte("cookie"),
11158 DuplicateHelloRetryRequestExtensions: true,
11159 },
11160 },
11161 shouldFail: true,
11162 expectedError: ":DUPLICATE_EXTENSION:",
11163 expectedLocalError: "remote error: illegal parameter",
11164 })
11165
11166 testCases = append(testCases, testCase{
11167 name: "HelloRetryRequest-EmptyCookie",
11168 config: Config{
11169 MaxVersion: VersionTLS13,
11170 Bugs: ProtocolBugs{
11171 SendHelloRetryRequestCookie: []byte{},
11172 },
11173 },
11174 shouldFail: true,
11175 expectedError: ":DECODE_ERROR:",
11176 })
11177
11178 testCases = append(testCases, testCase{
11179 name: "HelloRetryRequest-Cookie-Curve",
11180 config: Config{
11181 MaxVersion: VersionTLS13,
11182 // P-384 requires HelloRetryRequest in BoringSSL.
11183 CurvePreferences: []CurveID{CurveP384},
11184 Bugs: ProtocolBugs{
11185 SendHelloRetryRequestCookie: []byte("cookie"),
11186 ExpectMissingKeyShare: true,
11187 },
11188 },
11189 })
11190
11191 testCases = append(testCases, testCase{
11192 name: "HelloRetryRequest-Unknown",
11193 config: Config{
11194 MaxVersion: VersionTLS13,
11195 Bugs: ProtocolBugs{
11196 CustomHelloRetryRequestExtension: "extension",
11197 },
11198 },
11199 shouldFail: true,
11200 expectedError: ":UNEXPECTED_EXTENSION:",
11201 expectedLocalError: "remote error: unsupported extension",
11202 })
11203
11204 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011205 testType: serverTest,
11206 name: "SecondClientHelloMissingKeyShare",
11207 config: Config{
11208 MaxVersion: VersionTLS13,
11209 DefaultCurves: []CurveID{},
11210 Bugs: ProtocolBugs{
11211 SecondClientHelloMissingKeyShare: true,
11212 },
11213 },
11214 shouldFail: true,
11215 expectedError: ":MISSING_KEY_SHARE:",
11216 })
11217
11218 testCases = append(testCases, testCase{
11219 testType: serverTest,
11220 name: "SecondClientHelloWrongCurve",
11221 config: Config{
11222 MaxVersion: VersionTLS13,
11223 DefaultCurves: []CurveID{},
11224 Bugs: ProtocolBugs{
11225 MisinterpretHelloRetryRequestCurve: CurveP521,
11226 },
11227 },
11228 shouldFail: true,
11229 expectedError: ":WRONG_CURVE:",
11230 })
11231
11232 testCases = append(testCases, testCase{
11233 name: "HelloRetryRequestVersionMismatch",
11234 config: Config{
11235 MaxVersion: VersionTLS13,
11236 // P-384 requires HelloRetryRequest in BoringSSL.
11237 CurvePreferences: []CurveID{CurveP384},
11238 Bugs: ProtocolBugs{
11239 SendServerHelloVersion: 0x0305,
11240 },
11241 },
11242 shouldFail: true,
11243 expectedError: ":WRONG_VERSION_NUMBER:",
11244 })
11245
11246 testCases = append(testCases, testCase{
11247 name: "HelloRetryRequestCurveMismatch",
11248 config: Config{
11249 MaxVersion: VersionTLS13,
11250 // P-384 requires HelloRetryRequest in BoringSSL.
11251 CurvePreferences: []CurveID{CurveP384},
11252 Bugs: ProtocolBugs{
11253 // Send P-384 (correct) in the HelloRetryRequest.
11254 SendHelloRetryRequestCurve: CurveP384,
11255 // But send P-256 in the ServerHello.
11256 SendCurve: CurveP256,
11257 },
11258 },
11259 shouldFail: true,
11260 expectedError: ":WRONG_CURVE:",
11261 })
11262
11263 // Test the server selecting a curve that requires a HelloRetryRequest
11264 // without sending it.
11265 testCases = append(testCases, testCase{
11266 name: "SkipHelloRetryRequest",
11267 config: Config{
11268 MaxVersion: VersionTLS13,
11269 // P-384 requires HelloRetryRequest in BoringSSL.
11270 CurvePreferences: []CurveID{CurveP384},
11271 Bugs: ProtocolBugs{
11272 SkipHelloRetryRequest: true,
11273 },
11274 },
11275 shouldFail: true,
11276 expectedError: ":WRONG_CURVE:",
11277 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011278
11279 testCases = append(testCases, testCase{
11280 name: "TLS13-RequestContextInHandshake",
11281 config: Config{
11282 MaxVersion: VersionTLS13,
11283 MinVersion: VersionTLS13,
11284 ClientAuth: RequireAnyClientCert,
11285 Bugs: ProtocolBugs{
11286 SendRequestContext: []byte("request context"),
11287 },
11288 },
11289 flags: []string{
11290 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11291 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11292 },
11293 shouldFail: true,
11294 expectedError: ":DECODE_ERROR:",
11295 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011296
11297 testCases = append(testCases, testCase{
11298 testType: serverTest,
11299 name: "TLS13-TrailingKeyShareData",
11300 config: Config{
11301 MaxVersion: VersionTLS13,
11302 Bugs: ProtocolBugs{
11303 TrailingKeyShareData: true,
11304 },
11305 },
11306 shouldFail: true,
11307 expectedError: ":DECODE_ERROR:",
11308 })
David Benjamin7f78df42016-10-05 22:33:19 -040011309
11310 testCases = append(testCases, testCase{
11311 name: "TLS13-AlwaysSelectPSKIdentity",
11312 config: Config{
11313 MaxVersion: VersionTLS13,
11314 Bugs: ProtocolBugs{
11315 AlwaysSelectPSKIdentity: true,
11316 },
11317 },
11318 shouldFail: true,
11319 expectedError: ":UNEXPECTED_EXTENSION:",
11320 })
11321
11322 testCases = append(testCases, testCase{
11323 name: "TLS13-InvalidPSKIdentity",
11324 config: Config{
11325 MaxVersion: VersionTLS13,
11326 Bugs: ProtocolBugs{
11327 SelectPSKIdentityOnResume: 1,
11328 },
11329 },
11330 resumeSession: true,
11331 shouldFail: true,
11332 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11333 })
David Benjamin1286bee2016-10-07 15:25:06 -040011334
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011335 testCases = append(testCases, testCase{
11336 testType: serverTest,
11337 name: "TLS13-ExtraPSKIdentity",
11338 config: Config{
11339 MaxVersion: VersionTLS13,
11340 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011341 ExtraPSKIdentity: true,
11342 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011343 },
11344 },
11345 resumeSession: true,
11346 })
11347
David Benjamin1286bee2016-10-07 15:25:06 -040011348 // Test that unknown NewSessionTicket extensions are tolerated.
11349 testCases = append(testCases, testCase{
11350 name: "TLS13-CustomTicketExtension",
11351 config: Config{
11352 MaxVersion: VersionTLS13,
11353 Bugs: ProtocolBugs{
11354 CustomTicketExtension: "1234",
11355 },
11356 },
11357 })
Steven Valdez2d850622017-01-11 11:34:52 -050011358
Steven Valdez0e4a4482017-07-17 11:12:34 -040011359 for _, noSessionID := range []bool{false, true} {
11360 prefix := "TLS13Experiment"
11361 variant := TLS13Experiment
11362 if noSessionID {
11363 prefix = "TLS13NoSessionIDExperiment"
11364 variant = TLS13NoSessionIDExperiment
11365 }
11366
11367 // Test that enabling a TLS 1.3 variant does not interfere with
11368 // TLS 1.2 session ID resumption.
11369 testCases = append(testCases, testCase{
11370 testType: clientTest,
11371 name: prefix + "-ResumeTLS12SessionID",
11372 config: Config{
11373 MaxVersion: VersionTLS12,
11374 SessionTicketsDisabled: true,
11375 },
11376 resumeSession: true,
11377 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11378 })
11379
11380 // Test that the server correctly echoes back session IDs of
11381 // various lengths.
11382 testCases = append(testCases, testCase{
11383 testType: serverTest,
11384 name: prefix + "-EmptySessionID",
11385 config: Config{
11386 MaxVersion: VersionTLS13,
11387 Bugs: ProtocolBugs{
11388 SendClientHelloSessionID: []byte{},
11389 },
11390 },
11391 tls13Variant: variant,
11392 })
11393
11394 testCases = append(testCases, testCase{
11395 testType: serverTest,
11396 name: prefix + "-ShortSessionID",
11397 config: Config{
11398 MaxVersion: VersionTLS13,
11399 Bugs: ProtocolBugs{
11400 SendClientHelloSessionID: make([]byte, 16),
11401 },
11402 },
11403 tls13Variant: variant,
11404 })
11405
11406 testCases = append(testCases, testCase{
11407 testType: serverTest,
11408 name: prefix + "-FullSessionID",
11409 config: Config{
11410 MaxVersion: VersionTLS13,
11411 Bugs: ProtocolBugs{
11412 SendClientHelloSessionID: make([]byte, 32),
11413 },
11414 },
11415 tls13Variant: variant,
11416 })
11417 }
11418
11419 // Test that the client sends a fake session ID in TLS13Experiment.
11420 testCases = append(testCases, testCase{
11421 testType: clientTest,
11422 name: "TLS13Experiment-RequireSessionID",
11423 config: Config{
11424 MaxVersion: VersionTLS13,
11425 Bugs: ProtocolBugs{
11426 ExpectClientHelloSessionID: true,
11427 },
11428 },
11429 tls13Variant: TLS13Experiment,
11430 })
11431
11432 // Test that the client does not send a fake session ID in
11433 // TLS13NoSessionIDExperiment.
11434 testCases = append(testCases, testCase{
11435 testType: clientTest,
11436 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11437 config: Config{
11438 MaxVersion: VersionTLS13,
11439 Bugs: ProtocolBugs{
11440 ExpectEmptyClientHelloSessionID: true,
11441 },
11442 },
11443 tls13Variant: TLS13NoSessionIDExperiment,
11444 })
11445
Steven Valdez2d850622017-01-11 11:34:52 -050011446 testCases = append(testCases, testCase{
11447 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011448 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011449 config: Config{
11450 MaxVersion: VersionTLS13,
11451 MaxEarlyDataSize: 16384,
11452 },
11453 resumeConfig: &Config{
11454 MaxVersion: VersionTLS13,
11455 MaxEarlyDataSize: 16384,
11456 Bugs: ProtocolBugs{
11457 AlwaysRejectEarlyData: true,
11458 },
11459 },
11460 resumeSession: true,
11461 flags: []string{
11462 "-enable-early-data",
11463 "-expect-early-data-info",
11464 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011465 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011466 },
11467 })
11468
11469 testCases = append(testCases, testCase{
11470 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011471 name: "TLS13Experiment-EarlyData-Reject-Client",
11472 config: Config{
11473 MaxVersion: VersionTLS13,
11474 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011475 },
11476 resumeConfig: &Config{
11477 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011478 MaxEarlyDataSize: 16384,
11479 Bugs: ProtocolBugs{
11480 AlwaysRejectEarlyData: true,
11481 },
11482 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011483 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011484 resumeSession: true,
11485 flags: []string{
11486 "-enable-early-data",
11487 "-expect-early-data-info",
11488 "-expect-reject-early-data",
11489 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011490 },
11491 })
11492
11493 testCases = append(testCases, testCase{
11494 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011495 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11496 config: Config{
11497 MaxVersion: VersionTLS13,
11498 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011499 },
11500 resumeConfig: &Config{
11501 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011502 MaxEarlyDataSize: 16384,
11503 Bugs: ProtocolBugs{
11504 AlwaysRejectEarlyData: true,
11505 },
11506 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011507 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011508 resumeSession: true,
11509 flags: []string{
11510 "-enable-early-data",
11511 "-expect-early-data-info",
11512 "-expect-reject-early-data",
11513 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011514 },
11515 })
11516
11517 testCases = append(testCases, testCase{
11518 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011519 name: "TLS13-EarlyData-RejectTicket-Client",
11520 config: Config{
11521 MaxVersion: VersionTLS13,
11522 MaxEarlyDataSize: 16384,
11523 Certificates: []Certificate{rsaCertificate},
11524 },
11525 resumeConfig: &Config{
11526 MaxVersion: VersionTLS13,
11527 MaxEarlyDataSize: 16384,
11528 Certificates: []Certificate{ecdsaP256Certificate},
11529 SessionTicketsDisabled: true,
11530 },
11531 resumeSession: true,
11532 expectResumeRejected: true,
11533 flags: []string{
11534 "-enable-early-data",
11535 "-expect-early-data-info",
11536 "-expect-reject-early-data",
11537 "-on-resume-shim-writes-first",
11538 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11539 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11540 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11541 // Session tickets are disabled, so the runner will not send a ticket.
11542 "-on-retry-expect-no-session",
11543 },
11544 })
11545
11546 testCases = append(testCases, testCase{
11547 testType: clientTest,
11548 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011549 config: Config{
11550 MaxVersion: VersionTLS13,
11551 MaxEarlyDataSize: 16384,
11552 },
11553 resumeConfig: &Config{
11554 MaxVersion: VersionTLS13,
11555 MaxEarlyDataSize: 16384,
11556 Bugs: ProtocolBugs{
11557 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11558 },
11559 },
11560 resumeSession: true,
11561 flags: []string{
11562 "-enable-early-data",
11563 "-expect-early-data-info",
11564 "-expect-reject-early-data",
11565 },
11566 })
11567
11568 // The client must check the server does not send the early_data
11569 // extension while rejecting the session.
11570 testCases = append(testCases, testCase{
11571 testType: clientTest,
11572 name: "TLS13-EarlyDataWithoutResume-Client",
11573 config: Config{
11574 MaxVersion: VersionTLS13,
11575 MaxEarlyDataSize: 16384,
11576 },
11577 resumeConfig: &Config{
11578 MaxVersion: VersionTLS13,
11579 SessionTicketsDisabled: true,
11580 Bugs: ProtocolBugs{
11581 SendEarlyDataExtension: true,
11582 },
11583 },
11584 resumeSession: true,
11585 flags: []string{
11586 "-enable-early-data",
11587 "-expect-early-data-info",
11588 },
11589 shouldFail: true,
11590 expectedError: ":UNEXPECTED_EXTENSION:",
11591 })
11592
11593 // The client must fail with a dedicated error code if the server
11594 // responds with TLS 1.2 when offering 0-RTT.
11595 testCases = append(testCases, testCase{
11596 testType: clientTest,
11597 name: "TLS13-EarlyDataVersionDowngrade-Client",
11598 config: Config{
11599 MaxVersion: VersionTLS13,
11600 MaxEarlyDataSize: 16384,
11601 },
11602 resumeConfig: &Config{
11603 MaxVersion: VersionTLS12,
11604 },
11605 resumeSession: true,
11606 flags: []string{
11607 "-enable-early-data",
11608 "-expect-early-data-info",
11609 },
11610 shouldFail: true,
11611 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11612 })
11613
11614 // Test that the client rejects an (unsolicited) early_data extension if
11615 // the server sent an HRR.
11616 testCases = append(testCases, testCase{
11617 testType: clientTest,
11618 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11619 config: Config{
11620 MaxVersion: VersionTLS13,
11621 MaxEarlyDataSize: 16384,
11622 },
11623 resumeConfig: &Config{
11624 MaxVersion: VersionTLS13,
11625 MaxEarlyDataSize: 16384,
11626 Bugs: ProtocolBugs{
11627 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11628 SendEarlyDataExtension: true,
11629 },
11630 },
11631 resumeSession: true,
11632 flags: []string{
11633 "-enable-early-data",
11634 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011635 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011636 },
11637 shouldFail: true,
11638 expectedError: ":UNEXPECTED_EXTENSION:",
11639 })
11640
11641 fooString := "foo"
11642 barString := "bar"
11643
11644 // Test that the client reports the correct ALPN after a 0-RTT reject
11645 // that changed it.
11646 testCases = append(testCases, testCase{
11647 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011648 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011649 config: Config{
11650 MaxVersion: VersionTLS13,
11651 MaxEarlyDataSize: 16384,
11652 Bugs: ProtocolBugs{
11653 ALPNProtocol: &fooString,
11654 },
11655 },
11656 resumeConfig: &Config{
11657 MaxVersion: VersionTLS13,
11658 MaxEarlyDataSize: 16384,
11659 Bugs: ProtocolBugs{
11660 ALPNProtocol: &barString,
11661 },
11662 },
11663 resumeSession: true,
11664 flags: []string{
11665 "-advertise-alpn", "\x03foo\x03bar",
11666 "-enable-early-data",
11667 "-expect-early-data-info",
11668 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011669 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011670 "-on-resume-expect-alpn", "foo",
11671 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011672 },
11673 })
11674
11675 // Test that the client reports the correct ALPN after a 0-RTT reject if
11676 // ALPN was omitted from the first connection.
11677 testCases = append(testCases, testCase{
11678 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011679 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011680 config: Config{
11681 MaxVersion: VersionTLS13,
11682 MaxEarlyDataSize: 16384,
11683 },
11684 resumeConfig: &Config{
11685 MaxVersion: VersionTLS13,
11686 MaxEarlyDataSize: 16384,
11687 NextProtos: []string{"foo"},
11688 },
11689 resumeSession: true,
11690 flags: []string{
11691 "-advertise-alpn", "\x03foo\x03bar",
11692 "-enable-early-data",
11693 "-expect-early-data-info",
11694 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011695 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011696 "-on-resume-expect-alpn", "",
11697 "-on-retry-expect-alpn", "foo",
11698 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011699 },
11700 })
11701
11702 // Test that the client reports the correct ALPN after a 0-RTT reject if
11703 // ALPN was omitted from the second connection.
11704 testCases = append(testCases, testCase{
11705 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011706 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011707 config: Config{
11708 MaxVersion: VersionTLS13,
11709 MaxEarlyDataSize: 16384,
11710 NextProtos: []string{"foo"},
11711 },
11712 resumeConfig: &Config{
11713 MaxVersion: VersionTLS13,
11714 MaxEarlyDataSize: 16384,
11715 },
11716 resumeSession: true,
11717 flags: []string{
11718 "-advertise-alpn", "\x03foo\x03bar",
11719 "-enable-early-data",
11720 "-expect-early-data-info",
11721 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011722 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011723 "-on-resume-expect-alpn", "foo",
11724 "-on-retry-expect-alpn", "",
11725 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011726 },
11727 })
11728
11729 // Test that the client enforces ALPN match on 0-RTT accept.
11730 testCases = append(testCases, testCase{
11731 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011732 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011733 config: Config{
11734 MaxVersion: VersionTLS13,
11735 MaxEarlyDataSize: 16384,
11736 Bugs: ProtocolBugs{
11737 ALPNProtocol: &fooString,
11738 },
11739 },
11740 resumeConfig: &Config{
11741 MaxVersion: VersionTLS13,
11742 MaxEarlyDataSize: 16384,
11743 Bugs: ProtocolBugs{
11744 AlwaysAcceptEarlyData: true,
11745 ALPNProtocol: &barString,
11746 },
11747 },
11748 resumeSession: true,
11749 flags: []string{
11750 "-advertise-alpn", "\x03foo\x03bar",
11751 "-enable-early-data",
11752 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011753 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011754 "-on-resume-expect-alpn", "foo",
11755 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011756 },
11757 shouldFail: true,
11758 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11759 })
11760
11761 // Test that the server correctly rejects 0-RTT when the previous
11762 // session did not allow early data on resumption.
11763 testCases = append(testCases, testCase{
11764 testType: serverTest,
11765 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11766 config: Config{
11767 MaxVersion: VersionTLS13,
11768 },
11769 resumeConfig: &Config{
11770 MaxVersion: VersionTLS13,
11771 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011772 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011773 ExpectEarlyDataAccepted: false,
11774 },
11775 },
11776 resumeSession: true,
11777 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011778 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011779 "-expect-reject-early-data",
11780 },
11781 })
11782
11783 // Test that we reject early data where ALPN is omitted from the first
11784 // connection.
11785 testCases = append(testCases, testCase{
11786 testType: serverTest,
11787 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11788 config: Config{
11789 MaxVersion: VersionTLS13,
11790 NextProtos: []string{},
11791 },
11792 resumeConfig: &Config{
11793 MaxVersion: VersionTLS13,
11794 NextProtos: []string{"foo"},
11795 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011796 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011797 ExpectEarlyDataAccepted: false,
11798 },
11799 },
11800 resumeSession: true,
11801 flags: []string{
11802 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011803 "-on-initial-select-alpn", "",
11804 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011805 },
11806 })
11807
11808 // Test that we reject early data where ALPN is omitted from the second
11809 // connection.
11810 testCases = append(testCases, testCase{
11811 testType: serverTest,
11812 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11813 config: Config{
11814 MaxVersion: VersionTLS13,
11815 NextProtos: []string{"foo"},
11816 },
11817 resumeConfig: &Config{
11818 MaxVersion: VersionTLS13,
11819 NextProtos: []string{},
11820 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011821 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011822 ExpectEarlyDataAccepted: false,
11823 },
11824 },
11825 resumeSession: true,
11826 flags: []string{
11827 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011828 "-on-initial-select-alpn", "foo",
11829 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011830 },
11831 })
11832
11833 // Test that we reject early data with mismatched ALPN.
11834 testCases = append(testCases, testCase{
11835 testType: serverTest,
11836 name: "TLS13-EarlyData-ALPNMismatch-Server",
11837 config: Config{
11838 MaxVersion: VersionTLS13,
11839 NextProtos: []string{"foo"},
11840 },
11841 resumeConfig: &Config{
11842 MaxVersion: VersionTLS13,
11843 NextProtos: []string{"bar"},
11844 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011845 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011846 ExpectEarlyDataAccepted: false,
11847 },
11848 },
11849 resumeSession: true,
11850 flags: []string{
11851 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011852 "-on-initial-select-alpn", "foo",
11853 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011854 },
11855 })
11856
David Benjamin6bb507b2017-03-29 16:35:57 -050011857 // Test that the client offering 0-RTT and Channel ID forbids the server
11858 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011859 testCases = append(testCases, testCase{
11860 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011861 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011862 config: Config{
11863 MaxVersion: VersionTLS13,
11864 MaxEarlyDataSize: 16384,
11865 RequestChannelID: true,
11866 },
11867 resumeSession: true,
11868 expectChannelID: true,
11869 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011870 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011871 flags: []string{
11872 "-enable-early-data",
11873 "-expect-early-data-info",
11874 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11875 },
11876 })
11877
David Benjamin6bb507b2017-03-29 16:35:57 -050011878 // Test that the client offering Channel ID and 0-RTT allows the server
11879 // to decline 0-RTT.
11880 testCases = append(testCases, testCase{
11881 testType: clientTest,
11882 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11883 config: Config{
11884 MaxVersion: VersionTLS13,
11885 MaxEarlyDataSize: 16384,
11886 RequestChannelID: true,
11887 Bugs: ProtocolBugs{
11888 AlwaysRejectEarlyData: true,
11889 },
11890 },
11891 resumeSession: true,
11892 expectChannelID: true,
11893 flags: []string{
11894 "-enable-early-data",
11895 "-expect-early-data-info",
11896 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11897 "-expect-reject-early-data",
11898 },
11899 })
11900
11901 // Test that the client offering Channel ID and 0-RTT allows the server
11902 // to decline Channel ID.
11903 testCases = append(testCases, testCase{
11904 testType: clientTest,
11905 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11906 config: Config{
11907 MaxVersion: VersionTLS13,
11908 MaxEarlyDataSize: 16384,
11909 },
11910 resumeSession: true,
11911 flags: []string{
11912 "-enable-early-data",
11913 "-expect-early-data-info",
11914 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11915 "-expect-accept-early-data",
11916 },
11917 })
11918
11919 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11920 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011921 testCases = append(testCases, testCase{
11922 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011923 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011924 config: Config{
11925 MaxVersion: VersionTLS13,
11926 ChannelID: channelIDKey,
11927 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011928 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011929 ExpectEarlyDataAccepted: false,
11930 },
11931 },
11932 resumeSession: true,
11933 expectChannelID: true,
11934 flags: []string{
11935 "-enable-early-data",
11936 "-expect-reject-early-data",
11937 "-expect-channel-id",
11938 base64.StdEncoding.EncodeToString(channelIDBytes),
11939 },
11940 })
11941
David Benjamin6bb507b2017-03-29 16:35:57 -050011942 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11943 // if not offered Channel ID.
11944 testCases = append(testCases, testCase{
11945 testType: serverTest,
11946 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11947 config: Config{
11948 MaxVersion: VersionTLS13,
11949 Bugs: ProtocolBugs{
11950 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11951 ExpectEarlyDataAccepted: true,
11952 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11953 },
11954 },
11955 resumeSession: true,
11956 expectChannelID: false,
11957 flags: []string{
11958 "-enable-early-data",
11959 "-expect-accept-early-data",
11960 "-enable-channel-id",
11961 },
11962 })
11963
David Benjamin32c89272017-03-26 13:54:21 -050011964 // Test that the server rejects 0-RTT streams without end_of_early_data.
11965 // The subsequent records should fail to decrypt.
11966 testCases = append(testCases, testCase{
11967 testType: serverTest,
11968 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11969 config: Config{
11970 MaxVersion: VersionTLS13,
11971 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011972 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011973 ExpectEarlyDataAccepted: true,
11974 SkipEndOfEarlyData: true,
11975 },
11976 },
11977 resumeSession: true,
11978 flags: []string{"-enable-early-data"},
11979 shouldFail: true,
11980 expectedLocalError: "remote error: bad record MAC",
11981 expectedError: ":BAD_DECRYPT:",
11982 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011983
11984 testCases = append(testCases, testCase{
11985 testType: serverTest,
11986 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11987 config: Config{
11988 MaxVersion: VersionTLS13,
11989 },
11990 resumeConfig: &Config{
11991 MaxVersion: VersionTLS13,
11992 Bugs: ProtocolBugs{
11993 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11994 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011995 ExpectEarlyDataAccepted: true,
11996 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011997 },
11998 resumeSession: true,
11999 shouldFail: true,
12000 expectedError: ":UNEXPECTED_RECORD:",
12001 expectedLocalError: "remote error: unexpected message",
12002 flags: []string{
12003 "-enable-early-data",
12004 },
12005 })
David Benjamind9cbb532017-07-07 13:17:19 -040012006
12007 // Test that the client reports TLS 1.3 as the version while sending
12008 // early data.
12009 testCases = append(testCases, testCase{
12010 testType: clientTest,
12011 name: "TLS13-EarlyData-Client-VersionAPI",
12012 config: Config{
12013 MaxVersion: VersionTLS13,
12014 MaxEarlyDataSize: 16384,
12015 },
12016 resumeSession: true,
12017 flags: []string{
12018 "-enable-early-data",
12019 "-expect-early-data-info",
12020 "-expect-accept-early-data",
12021 "-expect-version", strconv.Itoa(VersionTLS13),
12022 },
12023 })
David Benjamin4a37de02017-08-08 20:15:40 -040012024
12025 // Test that client and server both notice handshake errors after data
12026 // has started flowing.
12027 testCases = append(testCases, testCase{
12028 testType: clientTest,
12029 name: "TLS13-EarlyData-Client-BadFinished",
12030 config: Config{
12031 MaxVersion: VersionTLS13,
12032 MaxEarlyDataSize: 16384,
12033 },
12034 resumeConfig: &Config{
12035 MaxVersion: VersionTLS13,
12036 MaxEarlyDataSize: 16384,
12037 Bugs: ProtocolBugs{
12038 BadFinished: true,
12039 },
12040 },
12041 resumeSession: true,
12042 flags: []string{
12043 "-enable-early-data",
12044 "-expect-early-data-info",
12045 "-expect-accept-early-data",
12046 },
12047 shouldFail: true,
12048 expectedError: ":DIGEST_CHECK_FAILED:",
12049 expectedLocalError: "remote error: error decrypting message",
12050 })
12051 testCases = append(testCases, testCase{
12052 testType: serverTest,
12053 name: "TLS13-EarlyData-Server-BadFinished",
12054 config: Config{
12055 MaxVersion: VersionTLS13,
12056 MaxEarlyDataSize: 16384,
12057 },
12058 resumeConfig: &Config{
12059 MaxVersion: VersionTLS13,
12060 MaxEarlyDataSize: 16384,
12061 Bugs: ProtocolBugs{
12062 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12063 ExpectEarlyDataAccepted: true,
12064 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12065 BadFinished: true,
12066 },
12067 },
12068 resumeSession: true,
12069 flags: []string{
12070 "-enable-early-data",
12071 "-expect-accept-early-data",
12072 },
12073 shouldFail: true,
12074 expectedError: ":DIGEST_CHECK_FAILED:",
12075 expectedLocalError: "remote error: error decrypting message",
12076 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020012077 testCases = append(testCases, testCase{
12078 testType: serverTest,
12079 name: "TLS13-ServerSkipCertificateVerify",
12080 config: Config{
12081 MinVersion: VersionTLS13,
12082 MaxVersion: VersionTLS13,
12083 Certificates: []Certificate{rsaChainCertificate},
12084 Bugs: ProtocolBugs{
12085 SkipCertificateVerify: true,
12086 },
12087 },
12088 expectPeerCertificate: &rsaChainCertificate,
12089 flags: []string{
12090 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12091 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12092 "-require-any-client-certificate",
12093 },
12094 shouldFail: true,
12095 expectedError: ":UNEXPECTED_MESSAGE:",
12096 expectedLocalError: "remote error: unexpected message",
12097 })
12098 testCases = append(testCases, testCase{
12099 testType: clientTest,
12100 name: "TLS13-ClientSkipCertificateVerify",
12101 config: Config{
12102 MinVersion: VersionTLS13,
12103 MaxVersion: VersionTLS13,
12104 Certificates: []Certificate{rsaChainCertificate},
12105 Bugs: ProtocolBugs{
12106 SkipCertificateVerify: true,
12107 },
12108 },
12109 expectPeerCertificate: &rsaChainCertificate,
12110 flags: []string{
12111 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12112 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12113 },
12114 shouldFail: true,
12115 expectedError: ":UNEXPECTED_MESSAGE:",
12116 expectedLocalError: "remote error: unexpected message",
12117 })
Steven Valdez143e8b32016-07-11 13:19:03 -040012118}
12119
David Benjaminabbbee12016-10-31 19:20:42 -040012120func addTLS13CipherPreferenceTests() {
12121 // Test that client preference is honored if the shim has AES hardware
12122 // and ChaCha20-Poly1305 is preferred otherwise.
12123 testCases = append(testCases, testCase{
12124 testType: serverTest,
12125 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
12126 config: Config{
12127 MaxVersion: VersionTLS13,
12128 CipherSuites: []uint16{
12129 TLS_CHACHA20_POLY1305_SHA256,
12130 TLS_AES_128_GCM_SHA256,
12131 },
12132 },
12133 flags: []string{
12134 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12135 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12136 },
12137 })
12138
12139 testCases = append(testCases, testCase{
12140 testType: serverTest,
12141 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
12142 config: Config{
12143 MaxVersion: VersionTLS13,
12144 CipherSuites: []uint16{
12145 TLS_AES_128_GCM_SHA256,
12146 TLS_CHACHA20_POLY1305_SHA256,
12147 },
12148 },
12149 flags: []string{
12150 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12151 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12152 },
12153 })
12154
12155 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
12156 // whether it has AES hardware.
12157 testCases = append(testCases, testCase{
12158 name: "TLS13-CipherPreference-Client",
12159 config: Config{
12160 MaxVersion: VersionTLS13,
12161 // Use the client cipher order. (This is the default but
12162 // is listed to be explicit.)
12163 PreferServerCipherSuites: false,
12164 },
12165 flags: []string{
12166 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12167 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12168 },
12169 })
12170}
12171
David Benjaminf3fbade2016-09-19 13:08:16 -040012172func addPeekTests() {
12173 // Test SSL_peek works, including on empty records.
12174 testCases = append(testCases, testCase{
12175 name: "Peek-Basic",
12176 sendEmptyRecords: 1,
12177 flags: []string{"-peek-then-read"},
12178 })
12179
12180 // Test SSL_peek can drive the initial handshake.
12181 testCases = append(testCases, testCase{
12182 name: "Peek-ImplicitHandshake",
12183 flags: []string{
12184 "-peek-then-read",
12185 "-implicit-handshake",
12186 },
12187 })
12188
12189 // Test SSL_peek can discover and drive a renegotiation.
12190 testCases = append(testCases, testCase{
12191 name: "Peek-Renegotiate",
12192 config: Config{
12193 MaxVersion: VersionTLS12,
12194 },
12195 renegotiate: 1,
12196 flags: []string{
12197 "-peek-then-read",
12198 "-renegotiate-freely",
12199 "-expect-total-renegotiations", "1",
12200 },
12201 })
12202
12203 // Test SSL_peek can discover a close_notify.
12204 testCases = append(testCases, testCase{
12205 name: "Peek-Shutdown",
12206 config: Config{
12207 Bugs: ProtocolBugs{
12208 ExpectCloseNotify: true,
12209 },
12210 },
12211 flags: []string{
12212 "-peek-then-read",
12213 "-check-close-notify",
12214 },
12215 })
12216
12217 // Test SSL_peek can discover an alert.
12218 testCases = append(testCases, testCase{
12219 name: "Peek-Alert",
12220 config: Config{
12221 Bugs: ProtocolBugs{
12222 SendSpuriousAlert: alertRecordOverflow,
12223 },
12224 },
12225 flags: []string{"-peek-then-read"},
12226 shouldFail: true,
12227 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12228 })
12229
12230 // Test SSL_peek can handle KeyUpdate.
12231 testCases = append(testCases, testCase{
12232 name: "Peek-KeyUpdate",
12233 config: Config{
12234 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012235 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012236 sendKeyUpdates: 1,
12237 keyUpdateRequest: keyUpdateNotRequested,
12238 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012239 })
12240}
12241
David Benjamine6f22212016-11-08 14:28:24 -050012242func addRecordVersionTests() {
12243 for _, ver := range tlsVersions {
12244 // Test that the record version is enforced.
12245 testCases = append(testCases, testCase{
12246 name: "CheckRecordVersion-" + ver.name,
12247 config: Config{
12248 MinVersion: ver.version,
12249 MaxVersion: ver.version,
12250 Bugs: ProtocolBugs{
12251 SendRecordVersion: 0x03ff,
12252 },
12253 },
David Benjamina5022392017-07-10 17:40:39 -040012254 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012255 shouldFail: true,
12256 expectedError: ":WRONG_VERSION_NUMBER:",
12257 })
12258
12259 // Test that the ClientHello may use any record version, for
12260 // compatibility reasons.
12261 testCases = append(testCases, testCase{
12262 testType: serverTest,
12263 name: "LooseInitialRecordVersion-" + ver.name,
12264 config: Config{
12265 MinVersion: ver.version,
12266 MaxVersion: ver.version,
12267 Bugs: ProtocolBugs{
12268 SendInitialRecordVersion: 0x03ff,
12269 },
12270 },
David Benjamina5022392017-07-10 17:40:39 -040012271 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012272 })
12273
12274 // Test that garbage ClientHello record versions are rejected.
12275 testCases = append(testCases, testCase{
12276 testType: serverTest,
12277 name: "GarbageInitialRecordVersion-" + ver.name,
12278 config: Config{
12279 MinVersion: ver.version,
12280 MaxVersion: ver.version,
12281 Bugs: ProtocolBugs{
12282 SendInitialRecordVersion: 0xffff,
12283 },
12284 },
David Benjamina5022392017-07-10 17:40:39 -040012285 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012286 shouldFail: true,
12287 expectedError: ":WRONG_VERSION_NUMBER:",
12288 })
12289 }
12290}
12291
David Benjamin2c516452016-11-15 10:16:54 +090012292func addCertificateTests() {
David Benjamin2c516452016-11-15 10:16:54 +090012293 for _, ver := range tlsVersions {
David Benjamin3969fdf2017-08-29 15:50:58 -040012294 // Test that a certificate chain with intermediate may be sent
12295 // and received as both client and server.
David Benjamin2c516452016-11-15 10:16:54 +090012296 testCases = append(testCases, testCase{
12297 testType: clientTest,
12298 name: "SendReceiveIntermediate-Client-" + ver.name,
12299 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012300 MinVersion: ver.version,
12301 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012302 Certificates: []Certificate{rsaChainCertificate},
12303 ClientAuth: RequireAnyClientCert,
12304 },
David Benjamina5022392017-07-10 17:40:39 -040012305 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012306 expectPeerCertificate: &rsaChainCertificate,
12307 flags: []string{
12308 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12309 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12310 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12311 },
12312 })
12313
12314 testCases = append(testCases, testCase{
12315 testType: serverTest,
12316 name: "SendReceiveIntermediate-Server-" + ver.name,
12317 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012318 MinVersion: ver.version,
12319 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012320 Certificates: []Certificate{rsaChainCertificate},
12321 },
David Benjamina5022392017-07-10 17:40:39 -040012322 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012323 expectPeerCertificate: &rsaChainCertificate,
12324 flags: []string{
12325 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12326 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12327 "-require-any-client-certificate",
12328 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12329 },
12330 })
David Benjamin3969fdf2017-08-29 15:50:58 -040012331
12332 // Test that garbage leaf certificates are properly rejected.
12333 testCases = append(testCases, testCase{
12334 testType: clientTest,
12335 name: "GarbageCertificate-Client-" + ver.name,
12336 config: Config{
12337 MinVersion: ver.version,
12338 MaxVersion: ver.version,
12339 Certificates: []Certificate{garbageCertificate},
12340 },
12341 tls13Variant: ver.tls13Variant,
12342 shouldFail: true,
12343 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12344 expectedLocalError: "remote error: error decoding message",
12345 })
12346
12347 testCases = append(testCases, testCase{
12348 testType: serverTest,
12349 name: "GarbageCertificate-Server-" + ver.name,
12350 config: Config{
12351 MinVersion: ver.version,
12352 MaxVersion: ver.version,
12353 Certificates: []Certificate{garbageCertificate},
12354 },
12355 tls13Variant: ver.tls13Variant,
12356 flags: []string{"-require-any-client-certificate"},
12357 shouldFail: true,
12358 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12359 expectedLocalError: "remote error: error decoding message",
12360 })
David Benjamin2c516452016-11-15 10:16:54 +090012361 }
12362}
12363
David Benjaminbbaf3672016-11-17 10:53:09 +090012364func addRetainOnlySHA256ClientCertTests() {
12365 for _, ver := range tlsVersions {
12366 // Test that enabling
12367 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12368 // actually requesting a client certificate is a no-op.
12369 testCases = append(testCases, testCase{
12370 testType: serverTest,
12371 name: "RetainOnlySHA256-NoCert-" + ver.name,
12372 config: Config{
12373 MinVersion: ver.version,
12374 MaxVersion: ver.version,
12375 },
David Benjamina5022392017-07-10 17:40:39 -040012376 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012377 flags: []string{
David Benjaminf2165072017-08-23 23:01:37 -070012378 "-on-initial-retain-only-sha256-client-cert",
12379 "-on-resume-retain-only-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012380 },
12381 resumeSession: true,
12382 })
12383
12384 // Test that when retaining only a SHA-256 certificate is
12385 // enabled, the hash appears as expected.
12386 testCases = append(testCases, testCase{
12387 testType: serverTest,
12388 name: "RetainOnlySHA256-Cert-" + ver.name,
12389 config: Config{
12390 MinVersion: ver.version,
12391 MaxVersion: ver.version,
12392 Certificates: []Certificate{rsaCertificate},
12393 },
David Benjamina5022392017-07-10 17:40:39 -040012394 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012395 flags: []string{
12396 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012397 "-on-initial-retain-only-sha256-client-cert",
12398 "-on-resume-retain-only-sha256-client-cert",
12399 "-on-initial-expect-sha256-client-cert",
12400 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012401 },
12402 resumeSession: true,
12403 })
12404
12405 // Test that when the config changes from on to off, a
12406 // resumption is rejected because the server now wants the full
12407 // certificate chain.
12408 testCases = append(testCases, testCase{
12409 testType: serverTest,
12410 name: "RetainOnlySHA256-OnOff-" + ver.name,
12411 config: Config{
12412 MinVersion: ver.version,
12413 MaxVersion: ver.version,
12414 Certificates: []Certificate{rsaCertificate},
12415 },
David Benjamina5022392017-07-10 17:40:39 -040012416 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012417 flags: []string{
12418 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012419 "-on-initial-retain-only-sha256-client-cert",
12420 "-on-initial-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012421 },
12422 resumeSession: true,
12423 expectResumeRejected: true,
12424 })
12425
12426 // Test that when the config changes from off to on, a
12427 // resumption is rejected because the server now wants just the
12428 // hash.
12429 testCases = append(testCases, testCase{
12430 testType: serverTest,
12431 name: "RetainOnlySHA256-OffOn-" + ver.name,
12432 config: Config{
12433 MinVersion: ver.version,
12434 MaxVersion: ver.version,
12435 Certificates: []Certificate{rsaCertificate},
12436 },
David Benjamina5022392017-07-10 17:40:39 -040012437 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012438 flags: []string{
12439 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012440 "-on-resume-retain-only-sha256-client-cert",
12441 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012442 },
12443 resumeSession: true,
12444 expectResumeRejected: true,
12445 })
12446 }
12447}
12448
Adam Langleya4b91982016-12-12 12:05:53 -080012449func addECDSAKeyUsageTests() {
12450 p256 := elliptic.P256()
12451 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12452 if err != nil {
12453 panic(err)
12454 }
12455
12456 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12457 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12458 if err != nil {
12459 panic(err)
12460 }
12461
12462 template := x509.Certificate{
12463 SerialNumber: serialNumber,
12464 Subject: pkix.Name{
12465 Organization: []string{"Acme Co"},
12466 },
12467 NotBefore: time.Now(),
12468 NotAfter: time.Now(),
12469
12470 // An ECC certificate with only the keyAgreement key usgae may
12471 // be used with ECDH, but not ECDSA.
12472 KeyUsage: x509.KeyUsageKeyAgreement,
12473 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12474 BasicConstraintsValid: true,
12475 }
12476
12477 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12478 if err != nil {
12479 panic(err)
12480 }
12481
12482 cert := Certificate{
12483 Certificate: [][]byte{derBytes},
12484 PrivateKey: priv,
12485 }
12486
12487 for _, ver := range tlsVersions {
12488 if ver.version < VersionTLS12 {
12489 continue
12490 }
12491
12492 testCases = append(testCases, testCase{
12493 testType: clientTest,
12494 name: "ECDSAKeyUsage-" + ver.name,
12495 config: Config{
12496 MinVersion: ver.version,
12497 MaxVersion: ver.version,
12498 Certificates: []Certificate{cert},
12499 },
David Benjamina5022392017-07-10 17:40:39 -040012500 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012501 shouldFail: true,
12502 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12503 })
12504 }
12505}
12506
David Benjamin8c26d752017-03-26 15:13:51 -050012507func addExtraHandshakeTests() {
12508 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12509 // to ensure there is no transport I/O.
12510 testCases = append(testCases, testCase{
12511 testType: clientTest,
12512 name: "ExtraHandshake-Client-TLS12",
12513 config: Config{
12514 MinVersion: VersionTLS12,
12515 MaxVersion: VersionTLS12,
12516 },
12517 flags: []string{
12518 "-async",
12519 "-no-op-extra-handshake",
12520 },
12521 })
12522 testCases = append(testCases, testCase{
12523 testType: serverTest,
12524 name: "ExtraHandshake-Server-TLS12",
12525 config: Config{
12526 MinVersion: VersionTLS12,
12527 MaxVersion: VersionTLS12,
12528 },
12529 flags: []string{
12530 "-async",
12531 "-no-op-extra-handshake",
12532 },
12533 })
12534 testCases = append(testCases, testCase{
12535 testType: clientTest,
12536 name: "ExtraHandshake-Client-TLS13",
12537 config: Config{
12538 MinVersion: VersionTLS13,
12539 MaxVersion: VersionTLS13,
12540 },
12541 flags: []string{
12542 "-async",
12543 "-no-op-extra-handshake",
12544 },
12545 })
12546 testCases = append(testCases, testCase{
12547 testType: serverTest,
12548 name: "ExtraHandshake-Server-TLS13",
12549 config: Config{
12550 MinVersion: VersionTLS13,
12551 MaxVersion: VersionTLS13,
12552 },
12553 flags: []string{
12554 "-async",
12555 "-no-op-extra-handshake",
12556 },
12557 })
12558
12559 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12560 testCases = append(testCases, testCase{
12561 testType: serverTest,
12562 name: "ExtraHandshake-Server-EarlyData-TLS13",
12563 config: Config{
12564 MaxVersion: VersionTLS13,
12565 MinVersion: VersionTLS13,
12566 Bugs: ProtocolBugs{
12567 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12568 ExpectEarlyDataAccepted: true,
12569 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12570 },
12571 },
12572 messageCount: 2,
12573 resumeSession: true,
12574 flags: []string{
12575 "-async",
12576 "-enable-early-data",
12577 "-expect-accept-early-data",
12578 "-no-op-extra-handshake",
12579 },
12580 })
12581
12582 // An extra SSL_do_handshake drives the handshake to completion in False
12583 // Start. We test this by handshaking twice and asserting the False
12584 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12585 // how the test works.
12586 testCases = append(testCases, testCase{
12587 testType: clientTest,
12588 name: "ExtraHandshake-FalseStart",
12589 config: Config{
12590 MaxVersion: VersionTLS12,
12591 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12592 NextProtos: []string{"foo"},
12593 Bugs: ProtocolBugs{
12594 ExpectFalseStart: true,
12595 AlertBeforeFalseStartTest: alertAccessDenied,
12596 },
12597 },
12598 flags: []string{
12599 "-handshake-twice",
12600 "-false-start",
12601 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012602 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012603 },
12604 shimWritesFirst: true,
12605 shouldFail: true,
12606 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12607 expectedLocalError: "tls: peer did not false start: EOF",
12608 })
12609}
12610
David Benjaminb853f312017-07-14 18:40:34 -040012611// Test that omitted and empty extensions blocks are tolerated.
12612func addOmitExtensionsTests() {
David Benjamin0a471912017-08-31 00:19:57 -040012613 // Check the ExpectOmitExtensions setting works.
12614 testCases = append(testCases, testCase{
12615 testType: serverTest,
12616 name: "ExpectOmitExtensions",
12617 config: Config{
12618 MinVersion: VersionTLS12,
12619 MaxVersion: VersionTLS12,
12620 Bugs: ProtocolBugs{
12621 ExpectOmitExtensions: true,
12622 },
12623 },
12624 shouldFail: true,
12625 expectedLocalError: "tls: ServerHello did not omit extensions",
12626 })
12627
David Benjaminb853f312017-07-14 18:40:34 -040012628 for _, ver := range tlsVersions {
12629 if ver.version > VersionTLS12 {
12630 continue
12631 }
12632
12633 testCases = append(testCases, testCase{
12634 testType: serverTest,
12635 name: "OmitExtensions-ClientHello-" + ver.name,
12636 config: Config{
12637 MinVersion: ver.version,
12638 MaxVersion: ver.version,
12639 SessionTicketsDisabled: true,
12640 Bugs: ProtocolBugs{
12641 OmitExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012642 // With no client extensions, the ServerHello must not have
12643 // extensions. It should then omit the extensions field.
12644 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012645 },
12646 },
12647 })
12648
12649 testCases = append(testCases, testCase{
12650 testType: serverTest,
12651 name: "EmptyExtensions-ClientHello-" + ver.name,
12652 config: Config{
12653 MinVersion: ver.version,
12654 MaxVersion: ver.version,
12655 SessionTicketsDisabled: true,
12656 Bugs: ProtocolBugs{
12657 EmptyExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012658 // With no client extensions, the ServerHello must not have
12659 // extensions. It should then omit the extensions field.
12660 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012661 },
12662 },
12663 })
12664
12665 testCases = append(testCases, testCase{
12666 testType: clientTest,
12667 name: "OmitExtensions-ServerHello-" + ver.name,
12668 config: Config{
12669 MinVersion: ver.version,
12670 MaxVersion: ver.version,
12671 SessionTicketsDisabled: true,
12672 Bugs: ProtocolBugs{
12673 OmitExtensions: true,
12674 // Disable all ServerHello extensions so
12675 // OmitExtensions works.
12676 NoExtendedMasterSecret: true,
12677 NoRenegotiationInfo: true,
12678 },
12679 },
12680 })
12681
12682 testCases = append(testCases, testCase{
12683 testType: clientTest,
12684 name: "EmptyExtensions-ServerHello-" + ver.name,
12685 config: Config{
12686 MinVersion: ver.version,
12687 MaxVersion: ver.version,
12688 SessionTicketsDisabled: true,
12689 Bugs: ProtocolBugs{
12690 EmptyExtensions: true,
12691 // Disable all ServerHello extensions so
12692 // EmptyExtensions works.
12693 NoExtendedMasterSecret: true,
12694 NoRenegotiationInfo: true,
12695 },
12696 },
12697 })
12698 }
12699}
12700
Adam Langley7c803a62015-06-15 15:35:05 -070012701func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012702 defer wg.Done()
12703
12704 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012705 var err error
12706
David Benjaminba28dfc2016-11-15 17:47:21 +090012707 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012708 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12709 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012710 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012711 if err != nil {
12712 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12713 }
12714 break
12715 }
12716 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012717 } else if *repeatUntilFailure {
12718 for err == nil {
12719 statusChan <- statusMsg{test: test, started: true}
12720 err = runTest(test, shimPath, -1)
12721 }
12722 } else {
12723 statusChan <- statusMsg{test: test, started: true}
12724 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012725 }
Adam Langley95c29f32014-06-20 12:00:00 -070012726 statusChan <- statusMsg{test: test, err: err}
12727 }
12728}
12729
12730type statusMsg struct {
12731 test *testCase
12732 started bool
12733 err error
12734}
12735
David Benjamin5f237bc2015-02-11 17:14:15 -050012736func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012737 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012738
David Benjamin5f237bc2015-02-11 17:14:15 -050012739 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012740 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012741 if !*pipe {
12742 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012743 var erase string
12744 for i := 0; i < lineLen; i++ {
12745 erase += "\b \b"
12746 }
12747 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012748 }
12749
Adam Langley95c29f32014-06-20 12:00:00 -070012750 if msg.started {
12751 started++
12752 } else {
12753 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012754
12755 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012756 if msg.err == errUnimplemented {
12757 if *pipe {
12758 // Print each test instead of a status line.
12759 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12760 }
12761 unimplemented++
12762 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12763 } else {
12764 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12765 failed++
12766 testOutput.addResult(msg.test.name, "FAIL")
12767 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012768 } else {
12769 if *pipe {
12770 // Print each test instead of a status line.
12771 fmt.Printf("PASSED (%s)\n", msg.test.name)
12772 }
12773 testOutput.addResult(msg.test.name, "PASS")
12774 }
Adam Langley95c29f32014-06-20 12:00:00 -070012775 }
12776
David Benjamin5f237bc2015-02-11 17:14:15 -050012777 if !*pipe {
12778 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012779 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012780 lineLen = len(line)
12781 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012782 }
Adam Langley95c29f32014-06-20 12:00:00 -070012783 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012784
12785 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012786}
12787
12788func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012789 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012790 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012791 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012792
Adam Langley7c803a62015-06-15 15:35:05 -070012793 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012794 addCipherSuiteTests()
12795 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012796 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012797 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012798 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012799 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012800 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012801 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012802 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012803 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012804 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012805 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012806 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012807 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012808 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012809 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012810 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012811 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012812 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012813 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012814 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012815 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012816 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012817 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012818 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012819 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012820 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012821 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012822 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012823 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012824 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012825 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012826 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012827 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012828 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012829
12830 var wg sync.WaitGroup
12831
Adam Langley7c803a62015-06-15 15:35:05 -070012832 statusChan := make(chan statusMsg, *numWorkers)
12833 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012834 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012835
EKRf71d7ed2016-08-06 13:25:12 -070012836 if len(*shimConfigFile) != 0 {
12837 encoded, err := ioutil.ReadFile(*shimConfigFile)
12838 if err != nil {
12839 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12840 os.Exit(1)
12841 }
12842
12843 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12844 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12845 os.Exit(1)
12846 }
12847 }
12848
David Benjamin025b3d32014-07-01 19:53:04 -040012849 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012850
Adam Langley7c803a62015-06-15 15:35:05 -070012851 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012852 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012853 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012854 }
12855
David Benjamin270f0a72016-03-17 14:41:36 -040012856 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012857 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012858 matched := true
12859 if len(*testToRun) != 0 {
12860 var err error
12861 matched, err = filepath.Match(*testToRun, testCases[i].name)
12862 if err != nil {
12863 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12864 os.Exit(1)
12865 }
12866 }
12867
EKRf71d7ed2016-08-06 13:25:12 -070012868 if !*includeDisabled {
12869 for pattern := range shimConfig.DisabledTests {
12870 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12871 if err != nil {
12872 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12873 os.Exit(1)
12874 }
12875
12876 if isDisabled {
12877 matched = false
12878 break
12879 }
12880 }
12881 }
12882
David Benjamin17e12922016-07-28 18:04:43 -040012883 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012884 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012885 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012886
12887 // Only run one test if repeating until failure.
12888 if *repeatUntilFailure {
12889 break
12890 }
Adam Langley95c29f32014-06-20 12:00:00 -070012891 }
12892 }
David Benjamin17e12922016-07-28 18:04:43 -040012893
David Benjamin270f0a72016-03-17 14:41:36 -040012894 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012895 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012896 os.Exit(1)
12897 }
Adam Langley95c29f32014-06-20 12:00:00 -070012898
12899 close(testChan)
12900 wg.Wait()
12901 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012902 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012903
12904 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012905
12906 if *jsonOutput != "" {
12907 if err := testOutput.writeTo(*jsonOutput); err != nil {
12908 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12909 }
12910 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012911
EKR842ae6c2016-07-27 09:22:05 +020012912 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12913 os.Exit(1)
12914 }
12915
12916 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012917 os.Exit(1)
12918 }
Adam Langley95c29f32014-06-20 12:00:00 -070012919}