blob: 093fa2c8b6d7d7dec9ce9ce50797ce5034464206 [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 },
Adam Langley7c803a62015-06-15 15:35:05 -07002793 }
Adam Langley7c803a62015-06-15 15:35:05 -07002794 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002795
2796 // Test that very large messages can be received.
2797 cert := rsaCertificate
2798 for i := 0; i < 50; i++ {
2799 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2800 }
2801 testCases = append(testCases, testCase{
2802 name: "LargeMessage",
2803 config: Config{
2804 Certificates: []Certificate{cert},
2805 },
2806 })
2807 testCases = append(testCases, testCase{
2808 protocol: dtls,
2809 name: "LargeMessage-DTLS",
2810 config: Config{
2811 Certificates: []Certificate{cert},
2812 },
2813 })
2814
2815 // They are rejected if the maximum certificate chain length is capped.
2816 testCases = append(testCases, testCase{
2817 name: "LargeMessage-Reject",
2818 config: Config{
2819 Certificates: []Certificate{cert},
2820 },
2821 flags: []string{"-max-cert-list", "16384"},
2822 shouldFail: true,
2823 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2824 })
2825 testCases = append(testCases, testCase{
2826 protocol: dtls,
2827 name: "LargeMessage-Reject-DTLS",
2828 config: Config{
2829 Certificates: []Certificate{cert},
2830 },
2831 flags: []string{"-max-cert-list", "16384"},
2832 shouldFail: true,
2833 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2834 })
Adam Langley7c803a62015-06-15 15:35:05 -07002835}
2836
David Benjaminaa012042016-12-10 13:33:05 -05002837func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2838 const psk = "12345"
2839 const pskIdentity = "luggage combo"
2840
2841 var prefix string
2842 if protocol == dtls {
2843 if !ver.hasDTLS {
2844 return
2845 }
2846 prefix = "D"
2847 }
2848
2849 var cert Certificate
2850 var certFile string
2851 var keyFile string
2852 if hasComponent(suite.name, "ECDSA") {
2853 cert = ecdsaP256Certificate
2854 certFile = ecdsaP256CertificateFile
2855 keyFile = ecdsaP256KeyFile
2856 } else {
2857 cert = rsaCertificate
2858 certFile = rsaCertificateFile
2859 keyFile = rsaKeyFile
2860 }
2861
2862 var flags []string
2863 if hasComponent(suite.name, "PSK") {
2864 flags = append(flags,
2865 "-psk", psk,
2866 "-psk-identity", pskIdentity)
2867 }
2868 if hasComponent(suite.name, "NULL") {
2869 // NULL ciphers must be explicitly enabled.
2870 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2871 }
David Benjaminaa012042016-12-10 13:33:05 -05002872
2873 var shouldServerFail, shouldClientFail bool
2874 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2875 // BoringSSL clients accept ECDHE on SSLv3, but
2876 // a BoringSSL server will never select it
2877 // because the extension is missing.
2878 shouldServerFail = true
2879 }
2880 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2881 shouldClientFail = true
2882 shouldServerFail = true
2883 }
2884 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2885 shouldClientFail = true
2886 shouldServerFail = true
2887 }
2888 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2889 shouldClientFail = true
2890 shouldServerFail = true
2891 }
2892 if !isDTLSCipher(suite.name) && protocol == dtls {
2893 shouldClientFail = true
2894 shouldServerFail = true
2895 }
2896
2897 var sendCipherSuite uint16
2898 var expectedServerError, expectedClientError string
2899 serverCipherSuites := []uint16{suite.id}
2900 if shouldServerFail {
2901 expectedServerError = ":NO_SHARED_CIPHER:"
2902 }
2903 if shouldClientFail {
2904 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2905 // Configure the server to select ciphers as normal but
2906 // select an incompatible cipher in ServerHello.
2907 serverCipherSuites = nil
2908 sendCipherSuite = suite.id
2909 }
2910
David Benjamincdb6fe92017-02-07 16:06:48 -05002911 // For cipher suites and versions where exporters are defined, verify
2912 // that they interoperate.
2913 var exportKeyingMaterial int
2914 if ver.version > VersionSSL30 {
2915 exportKeyingMaterial = 1024
2916 }
2917
David Benjaminaa012042016-12-10 13:33:05 -05002918 testCases = append(testCases, testCase{
2919 testType: serverTest,
2920 protocol: protocol,
2921 name: prefix + ver.name + "-" + suite.name + "-server",
2922 config: Config{
2923 MinVersion: ver.version,
2924 MaxVersion: ver.version,
2925 CipherSuites: []uint16{suite.id},
2926 Certificates: []Certificate{cert},
2927 PreSharedKey: []byte(psk),
2928 PreSharedKeyIdentity: pskIdentity,
2929 Bugs: ProtocolBugs{
2930 AdvertiseAllConfiguredCiphers: true,
2931 },
2932 },
David Benjamina5022392017-07-10 17:40:39 -04002933 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002934 certFile: certFile,
2935 keyFile: keyFile,
2936 flags: flags,
2937 resumeSession: true,
2938 shouldFail: shouldServerFail,
2939 expectedError: expectedServerError,
2940 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002941 })
2942
2943 testCases = append(testCases, testCase{
2944 testType: clientTest,
2945 protocol: protocol,
2946 name: prefix + ver.name + "-" + suite.name + "-client",
2947 config: Config{
2948 MinVersion: ver.version,
2949 MaxVersion: ver.version,
2950 CipherSuites: serverCipherSuites,
2951 Certificates: []Certificate{cert},
2952 PreSharedKey: []byte(psk),
2953 PreSharedKeyIdentity: pskIdentity,
2954 Bugs: ProtocolBugs{
2955 IgnorePeerCipherPreferences: shouldClientFail,
2956 SendCipherSuite: sendCipherSuite,
2957 },
2958 },
David Benjamina5022392017-07-10 17:40:39 -04002959 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002960 flags: flags,
2961 resumeSession: true,
2962 shouldFail: shouldClientFail,
2963 expectedError: expectedClientError,
2964 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002965 })
2966
David Benjamin6f600d62016-12-21 16:06:54 -05002967 if shouldClientFail {
2968 return
2969 }
2970
2971 // Ensure the maximum record size is accepted.
2972 testCases = append(testCases, testCase{
2973 protocol: protocol,
2974 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2975 config: Config{
2976 MinVersion: ver.version,
2977 MaxVersion: ver.version,
2978 CipherSuites: []uint16{suite.id},
2979 Certificates: []Certificate{cert},
2980 PreSharedKey: []byte(psk),
2981 PreSharedKeyIdentity: pskIdentity,
2982 },
David Benjamina5022392017-07-10 17:40:39 -04002983 tls13Variant: ver.tls13Variant,
2984 flags: flags,
2985 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05002986 })
2987
2988 // Test bad records for all ciphers. Bad records are fatal in TLS
2989 // and ignored in DTLS.
2990 var shouldFail bool
2991 var expectedError string
2992 if protocol == tls {
2993 shouldFail = true
2994 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2995 }
2996
2997 testCases = append(testCases, testCase{
2998 protocol: protocol,
2999 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
3000 config: Config{
3001 MinVersion: ver.version,
3002 MaxVersion: ver.version,
3003 CipherSuites: []uint16{suite.id},
3004 Certificates: []Certificate{cert},
3005 PreSharedKey: []byte(psk),
3006 PreSharedKeyIdentity: pskIdentity,
3007 },
David Benjamina5022392017-07-10 17:40:39 -04003008 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05003009 flags: flags,
3010 damageFirstWrite: true,
3011 messageLen: maxPlaintext,
3012 shouldFail: shouldFail,
3013 expectedError: expectedError,
3014 })
David Benjaminaa012042016-12-10 13:33:05 -05003015}
3016
Adam Langley95c29f32014-06-20 12:00:00 -07003017func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02003018 const bogusCipher = 0xfe00
3019
Adam Langley95c29f32014-06-20 12:00:00 -07003020 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07003021 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04003022 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05003023 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07003024 }
David Benjamin2c99d282015-09-01 10:23:00 -04003025 }
Adam Langley95c29f32014-06-20 12:00:00 -07003026 }
Adam Langleya7997f12015-05-14 17:38:50 -07003027
3028 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003029 name: "NoSharedCipher",
3030 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003031 MaxVersion: VersionTLS12,
3032 CipherSuites: []uint16{},
3033 },
3034 shouldFail: true,
3035 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3036 })
3037
3038 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003039 name: "NoSharedCipher-TLS13",
3040 config: Config{
3041 MaxVersion: VersionTLS13,
3042 CipherSuites: []uint16{},
3043 },
3044 shouldFail: true,
3045 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3046 })
3047
3048 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003049 name: "UnsupportedCipherSuite",
3050 config: Config{
3051 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003052 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003053 Bugs: ProtocolBugs{
3054 IgnorePeerCipherPreferences: true,
3055 },
3056 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003057 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003058 shouldFail: true,
3059 expectedError: ":WRONG_CIPHER_RETURNED:",
3060 })
3061
3062 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003063 name: "ServerHelloBogusCipher",
3064 config: Config{
3065 MaxVersion: VersionTLS12,
3066 Bugs: ProtocolBugs{
3067 SendCipherSuite: bogusCipher,
3068 },
3069 },
3070 shouldFail: true,
3071 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3072 })
3073 testCases = append(testCases, testCase{
3074 name: "ServerHelloBogusCipher-TLS13",
3075 config: Config{
3076 MaxVersion: VersionTLS13,
3077 Bugs: ProtocolBugs{
3078 SendCipherSuite: bogusCipher,
3079 },
3080 },
3081 shouldFail: true,
3082 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3083 })
3084
David Benjamin241ae832016-01-15 03:04:54 -05003085 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003086 testCases = append(testCases, testCase{
3087 testType: serverTest,
3088 name: "UnknownCipher",
3089 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003090 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003091 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003092 Bugs: ProtocolBugs{
3093 AdvertiseAllConfiguredCiphers: true,
3094 },
3095 },
3096 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003097
3098 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003099 testCases = append(testCases, testCase{
3100 testType: serverTest,
3101 name: "UnknownCipher-TLS13",
3102 config: Config{
3103 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003104 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003105 Bugs: ProtocolBugs{
3106 AdvertiseAllConfiguredCiphers: true,
3107 },
David Benjamin241ae832016-01-15 03:04:54 -05003108 },
3109 })
3110
David Benjamin78679342016-09-16 19:42:05 -04003111 // Test empty ECDHE_PSK identity hints work as expected.
3112 testCases = append(testCases, testCase{
3113 name: "EmptyECDHEPSKHint",
3114 config: Config{
3115 MaxVersion: VersionTLS12,
3116 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3117 PreSharedKey: []byte("secret"),
3118 },
3119 flags: []string{"-psk", "secret"},
3120 })
3121
3122 // Test empty PSK identity hints work as expected, even if an explicit
3123 // ServerKeyExchange is sent.
3124 testCases = append(testCases, testCase{
3125 name: "ExplicitEmptyPSKHint",
3126 config: Config{
3127 MaxVersion: VersionTLS12,
3128 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3129 PreSharedKey: []byte("secret"),
3130 Bugs: ProtocolBugs{
3131 AlwaysSendPreSharedKeyIdentityHint: true,
3132 },
3133 },
3134 flags: []string{"-psk", "secret"},
3135 })
David Benjamin69522112017-03-28 15:38:29 -05003136
3137 // Test that clients enforce that the server-sent certificate and cipher
3138 // suite match in TLS 1.2.
3139 testCases = append(testCases, testCase{
3140 name: "CertificateCipherMismatch-RSA",
3141 config: Config{
3142 MaxVersion: VersionTLS12,
3143 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3144 Certificates: []Certificate{rsaCertificate},
3145 Bugs: ProtocolBugs{
3146 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3147 },
3148 },
3149 shouldFail: true,
3150 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3151 })
3152 testCases = append(testCases, testCase{
3153 name: "CertificateCipherMismatch-ECDSA",
3154 config: Config{
3155 MaxVersion: VersionTLS12,
3156 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3157 Certificates: []Certificate{ecdsaP256Certificate},
3158 Bugs: ProtocolBugs{
3159 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3160 },
3161 },
3162 shouldFail: true,
3163 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3164 })
3165 testCases = append(testCases, testCase{
3166 name: "CertificateCipherMismatch-Ed25519",
3167 config: Config{
3168 MaxVersion: VersionTLS12,
3169 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3170 Certificates: []Certificate{ed25519Certificate},
3171 Bugs: ProtocolBugs{
3172 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3173 },
3174 },
3175 shouldFail: true,
3176 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3177 })
3178
3179 // Test that servers decline to select a cipher suite which is
3180 // inconsistent with their configured certificate.
3181 testCases = append(testCases, testCase{
3182 testType: serverTest,
3183 name: "ServerCipherFilter-RSA",
3184 config: Config{
3185 MaxVersion: VersionTLS12,
3186 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3187 },
3188 flags: []string{
3189 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3190 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3191 },
3192 shouldFail: true,
3193 expectedError: ":NO_SHARED_CIPHER:",
3194 })
3195 testCases = append(testCases, testCase{
3196 testType: serverTest,
3197 name: "ServerCipherFilter-ECDSA",
3198 config: Config{
3199 MaxVersion: VersionTLS12,
3200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3201 },
3202 flags: []string{
3203 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3204 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3205 },
3206 shouldFail: true,
3207 expectedError: ":NO_SHARED_CIPHER:",
3208 })
3209 testCases = append(testCases, testCase{
3210 testType: serverTest,
3211 name: "ServerCipherFilter-Ed25519",
3212 config: Config{
3213 MaxVersion: VersionTLS12,
3214 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3215 },
3216 flags: []string{
3217 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3218 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3219 },
3220 shouldFail: true,
3221 expectedError: ":NO_SHARED_CIPHER:",
3222 })
David Benjamin364af782017-07-01 10:35:27 -04003223
3224 // Test cipher suite negotiation works as expected. Configure a
3225 // complicated cipher suite configuration.
3226 const negotiationTestCiphers = "" +
3227 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3228 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3229 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3230 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3231 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3232 negotiationTests := []struct {
3233 ciphers []uint16
3234 expected uint16
3235 }{
3236 // Server preferences are honored, including when
3237 // equipreference groups are involved.
3238 {
3239 []uint16{
3240 TLS_RSA_WITH_AES_256_GCM_SHA384,
3241 TLS_RSA_WITH_AES_128_CBC_SHA,
3242 TLS_RSA_WITH_AES_128_GCM_SHA256,
3243 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3244 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3245 },
3246 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3247 },
3248 {
3249 []uint16{
3250 TLS_RSA_WITH_AES_256_GCM_SHA384,
3251 TLS_RSA_WITH_AES_128_CBC_SHA,
3252 TLS_RSA_WITH_AES_128_GCM_SHA256,
3253 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3254 },
3255 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3256 },
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 },
3263 TLS_RSA_WITH_AES_128_GCM_SHA256,
3264 },
3265 {
3266 []uint16{
3267 TLS_RSA_WITH_AES_256_GCM_SHA384,
3268 TLS_RSA_WITH_AES_128_CBC_SHA,
3269 },
3270 TLS_RSA_WITH_AES_128_CBC_SHA,
3271 },
3272 // Equipreference groups use the client preference.
3273 {
3274 []uint16{
3275 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3276 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3277 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3278 },
3279 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3280 },
3281 {
3282 []uint16{
3283 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3284 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3285 },
3286 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3287 },
3288 {
3289 []uint16{
3290 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3291 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3292 },
3293 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3294 },
3295 {
3296 []uint16{
3297 TLS_RSA_WITH_AES_256_GCM_SHA384,
3298 TLS_RSA_WITH_AES_256_CBC_SHA,
3299 },
3300 TLS_RSA_WITH_AES_256_GCM_SHA384,
3301 },
3302 {
3303 []uint16{
3304 TLS_RSA_WITH_AES_256_CBC_SHA,
3305 TLS_RSA_WITH_AES_256_GCM_SHA384,
3306 },
3307 TLS_RSA_WITH_AES_256_CBC_SHA,
3308 },
3309 // If there are two equipreference groups, the preferred one
3310 // takes precedence.
3311 {
3312 []uint16{
3313 TLS_RSA_WITH_AES_256_GCM_SHA384,
3314 TLS_RSA_WITH_AES_256_CBC_SHA,
3315 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3316 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3317 },
3318 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3319 },
3320 }
3321 for i, t := range negotiationTests {
3322 testCases = append(testCases, testCase{
3323 testType: serverTest,
3324 name: "CipherNegotiation-" + strconv.Itoa(i),
3325 config: Config{
3326 MaxVersion: VersionTLS12,
3327 CipherSuites: t.ciphers,
3328 },
3329 flags: []string{"-cipher", negotiationTestCiphers},
3330 expectedCipher: t.expected,
3331 })
3332 }
Adam Langley95c29f32014-06-20 12:00:00 -07003333}
3334
3335func addBadECDSASignatureTests() {
3336 for badR := BadValue(1); badR < NumBadValues; badR++ {
3337 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003338 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003339 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3340 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003341 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003342 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003343 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003344 Bugs: ProtocolBugs{
3345 BadECDSAR: badR,
3346 BadECDSAS: badS,
3347 },
3348 },
3349 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003350 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003351 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003352 testCases = append(testCases, testCase{
3353 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3354 config: Config{
3355 MaxVersion: VersionTLS13,
3356 Certificates: []Certificate{ecdsaP256Certificate},
3357 Bugs: ProtocolBugs{
3358 BadECDSAR: badR,
3359 BadECDSAS: badS,
3360 },
3361 },
3362 shouldFail: true,
3363 expectedError: ":BAD_SIGNATURE:",
3364 })
Adam Langley95c29f32014-06-20 12:00:00 -07003365 }
3366 }
3367}
3368
Adam Langley80842bd2014-06-20 12:00:00 -07003369func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003370 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003371 name: "MaxCBCPadding",
3372 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003373 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003374 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3375 Bugs: ProtocolBugs{
3376 MaxPadding: true,
3377 },
3378 },
3379 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3380 })
David Benjamin025b3d32014-07-01 19:53:04 -04003381 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003382 name: "BadCBCPadding",
3383 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003384 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003385 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3386 Bugs: ProtocolBugs{
3387 PaddingFirstByteBad: true,
3388 },
3389 },
3390 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003391 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003392 })
3393 // OpenSSL previously had an issue where the first byte of padding in
3394 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003395 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003396 name: "BadCBCPadding255",
3397 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003398 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003399 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3400 Bugs: ProtocolBugs{
3401 MaxPadding: true,
3402 PaddingFirstByteBadIf255: true,
3403 },
3404 },
3405 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3406 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003407 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003408 })
3409}
3410
Kenny Root7fdeaf12014-08-05 15:23:37 -07003411func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003412 var cbcCiphers = []struct {
3413 name string
3414 cipher uint16
3415 }{
3416 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3417 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3418 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3419 }
3420 for _, t := range cbcCiphers {
3421 testCases = append(testCases, testCase{
3422 name: "CBCRecordSplitting-" + t.name,
3423 config: Config{
3424 MaxVersion: VersionTLS10,
3425 MinVersion: VersionTLS10,
3426 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003427 Bugs: ProtocolBugs{
3428 ExpectRecordSplitting: true,
3429 },
David Benjamina1ce8562017-07-01 11:46:57 -04003430 },
3431 messageLen: -1, // read until EOF
3432 resumeSession: true,
3433 flags: []string{
3434 "-async",
3435 "-write-different-record-sizes",
3436 "-cbc-record-splitting",
3437 },
3438 })
3439 testCases = append(testCases, testCase{
3440 name: "CBCRecordSplittingPartialWrite-" + t.name,
3441 config: Config{
3442 MaxVersion: VersionTLS10,
3443 MinVersion: VersionTLS10,
3444 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003445 Bugs: ProtocolBugs{
3446 ExpectRecordSplitting: true,
3447 },
David Benjamina1ce8562017-07-01 11:46:57 -04003448 },
3449 messageLen: -1, // read until EOF
3450 flags: []string{
3451 "-async",
3452 "-write-different-record-sizes",
3453 "-cbc-record-splitting",
3454 "-partial-write",
3455 },
3456 })
3457 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003458}
3459
David Benjamin636293b2014-07-08 17:59:18 -04003460func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003461 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003462 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003463 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3464 cert, err := x509.ParseCertificate(cert.Certificate[0])
3465 if err != nil {
3466 panic(err)
3467 }
3468 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003469 }
Adam Langley2ff79332017-02-28 13:45:39 -08003470 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003471
David Benjamin636293b2014-07-08 17:59:18 -04003472 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003473 testCases = append(testCases, testCase{
3474 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003475 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003476 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003477 MinVersion: ver.version,
3478 MaxVersion: ver.version,
3479 ClientAuth: RequireAnyClientCert,
3480 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003481 },
David Benjamina5022392017-07-10 17:40:39 -04003482 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003483 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003484 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3485 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003486 },
3487 })
3488 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003489 testType: serverTest,
3490 name: ver.name + "-Server-ClientAuth-RSA",
3491 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003492 MinVersion: ver.version,
3493 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003494 Certificates: []Certificate{rsaCertificate},
3495 },
David Benjamina5022392017-07-10 17:40:39 -04003496 tls13Variant: ver.tls13Variant,
3497 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003498 })
David Benjamine098ec22014-08-27 23:13:20 -04003499 if ver.version != VersionSSL30 {
3500 testCases = append(testCases, testCase{
3501 testType: serverTest,
3502 name: ver.name + "-Server-ClientAuth-ECDSA",
3503 config: Config{
3504 MinVersion: ver.version,
3505 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003506 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003507 },
David Benjamina5022392017-07-10 17:40:39 -04003508 tls13Variant: ver.tls13Variant,
3509 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003510 })
3511 testCases = append(testCases, testCase{
3512 testType: clientTest,
3513 name: ver.name + "-Client-ClientAuth-ECDSA",
3514 config: Config{
3515 MinVersion: ver.version,
3516 MaxVersion: ver.version,
3517 ClientAuth: RequireAnyClientCert,
3518 ClientCAs: certPool,
3519 },
David Benjamina5022392017-07-10 17:40:39 -04003520 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003521 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003522 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3523 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003524 },
3525 })
3526 }
Adam Langley37646832016-08-01 16:16:46 -07003527
3528 testCases = append(testCases, testCase{
3529 name: "NoClientCertificate-" + ver.name,
3530 config: Config{
3531 MinVersion: ver.version,
3532 MaxVersion: ver.version,
3533 ClientAuth: RequireAnyClientCert,
3534 },
David Benjamina5022392017-07-10 17:40:39 -04003535 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003536 shouldFail: true,
3537 expectedLocalError: "client didn't provide a certificate",
3538 })
3539
3540 testCases = append(testCases, testCase{
3541 // Even if not configured to expect a certificate, OpenSSL will
3542 // return X509_V_OK as the verify_result.
3543 testType: serverTest,
3544 name: "NoClientCertificateRequested-Server-" + ver.name,
3545 config: Config{
3546 MinVersion: ver.version,
3547 MaxVersion: ver.version,
3548 },
David Benjamina5022392017-07-10 17:40:39 -04003549 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003550 flags: []string{
3551 "-expect-verify-result",
3552 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003553 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003554 })
3555
3556 testCases = append(testCases, testCase{
3557 // If a client certificate is not provided, OpenSSL will still
3558 // return X509_V_OK as the verify_result.
3559 testType: serverTest,
3560 name: "NoClientCertificate-Server-" + ver.name,
3561 config: Config{
3562 MinVersion: ver.version,
3563 MaxVersion: ver.version,
3564 },
David Benjamina5022392017-07-10 17:40:39 -04003565 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003566 flags: []string{
3567 "-expect-verify-result",
3568 "-verify-peer",
3569 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003570 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003571 })
3572
David Benjamin1db9e1b2016-10-07 20:51:43 -04003573 certificateRequired := "remote error: certificate required"
3574 if ver.version < VersionTLS13 {
3575 // Prior to TLS 1.3, the generic handshake_failure alert
3576 // was used.
3577 certificateRequired = "remote error: handshake failure"
3578 }
Adam Langley37646832016-08-01 16:16:46 -07003579 testCases = append(testCases, testCase{
3580 testType: serverTest,
3581 name: "RequireAnyClientCertificate-" + ver.name,
3582 config: Config{
3583 MinVersion: ver.version,
3584 MaxVersion: ver.version,
3585 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003586 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003587 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003588 shouldFail: true,
3589 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3590 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003591 })
3592
3593 if ver.version != VersionSSL30 {
3594 testCases = append(testCases, testCase{
3595 testType: serverTest,
3596 name: "SkipClientCertificate-" + ver.name,
3597 config: Config{
3598 MinVersion: ver.version,
3599 MaxVersion: ver.version,
3600 Bugs: ProtocolBugs{
3601 SkipClientCertificate: true,
3602 },
3603 },
3604 // Setting SSL_VERIFY_PEER allows anonymous clients.
3605 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003606 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003607 shouldFail: true,
3608 expectedError: ":UNEXPECTED_MESSAGE:",
3609 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003610
3611 testCases = append(testCases, testCase{
3612 testType: serverTest,
3613 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3614 config: Config{
3615 MinVersion: ver.version,
3616 MaxVersion: ver.version,
3617 },
3618 flags: []string{
3619 "-enable-channel-id",
3620 "-verify-peer-if-no-obc",
3621 },
David Benjamina5022392017-07-10 17:40:39 -04003622 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003623 shouldFail: true,
3624 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3625 expectedLocalError: certificateRequired,
3626 })
3627
3628 testCases = append(testCases, testCase{
3629 testType: serverTest,
3630 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3631 config: Config{
3632 MinVersion: ver.version,
3633 MaxVersion: ver.version,
3634 ChannelID: channelIDKey,
3635 },
3636 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003637 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003638 flags: []string{
3639 "-enable-channel-id",
3640 "-verify-peer-if-no-obc",
3641 },
3642 })
Adam Langley37646832016-08-01 16:16:46 -07003643 }
Adam Langley2ff79332017-02-28 13:45:39 -08003644
3645 testCases = append(testCases, testCase{
3646 testType: serverTest,
3647 name: ver.name + "-Server-CertReq-CA-List",
3648 config: Config{
3649 MinVersion: ver.version,
3650 MaxVersion: ver.version,
3651 Certificates: []Certificate{rsaCertificate},
3652 Bugs: ProtocolBugs{
3653 ExpectCertificateReqNames: caNames,
3654 },
3655 },
David Benjamina5022392017-07-10 17:40:39 -04003656 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003657 flags: []string{
3658 "-require-any-client-certificate",
3659 "-use-client-ca-list", encodeDERValues(caNames),
3660 },
3661 })
3662
3663 testCases = append(testCases, testCase{
3664 testType: clientTest,
3665 name: ver.name + "-Client-CertReq-CA-List",
3666 config: Config{
3667 MinVersion: ver.version,
3668 MaxVersion: ver.version,
3669 Certificates: []Certificate{rsaCertificate},
3670 ClientAuth: RequireAnyClientCert,
3671 ClientCAs: certPool,
3672 },
David Benjamina5022392017-07-10 17:40:39 -04003673 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003674 flags: []string{
3675 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3676 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3677 "-expect-client-ca-list", encodeDERValues(caNames),
3678 },
3679 })
David Benjamin636293b2014-07-08 17:59:18 -04003680 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003681
David Benjaminc032dfa2016-05-12 14:54:57 -04003682 // Client auth is only legal in certificate-based ciphers.
3683 testCases = append(testCases, testCase{
3684 testType: clientTest,
3685 name: "ClientAuth-PSK",
3686 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003687 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003688 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3689 PreSharedKey: []byte("secret"),
3690 ClientAuth: RequireAnyClientCert,
3691 },
3692 flags: []string{
3693 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3694 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3695 "-psk", "secret",
3696 },
3697 shouldFail: true,
3698 expectedError: ":UNEXPECTED_MESSAGE:",
3699 })
3700 testCases = append(testCases, testCase{
3701 testType: clientTest,
3702 name: "ClientAuth-ECDHE_PSK",
3703 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003704 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003705 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3706 PreSharedKey: []byte("secret"),
3707 ClientAuth: RequireAnyClientCert,
3708 },
3709 flags: []string{
3710 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3711 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3712 "-psk", "secret",
3713 },
3714 shouldFail: true,
3715 expectedError: ":UNEXPECTED_MESSAGE:",
3716 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003717
3718 // Regression test for a bug where the client CA list, if explicitly
3719 // set to NULL, was mis-encoded.
3720 testCases = append(testCases, testCase{
3721 testType: serverTest,
3722 name: "Null-Client-CA-List",
3723 config: Config{
3724 MaxVersion: VersionTLS12,
3725 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003726 Bugs: ProtocolBugs{
3727 ExpectCertificateReqNames: [][]byte{},
3728 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003729 },
3730 flags: []string{
3731 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003732 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003733 },
3734 })
David Benjamin636293b2014-07-08 17:59:18 -04003735}
3736
Adam Langley75712922014-10-10 16:23:43 -07003737func addExtendedMasterSecretTests() {
3738 const expectEMSFlag = "-expect-extended-master-secret"
3739
3740 for _, with := range []bool{false, true} {
3741 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003742 if with {
3743 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003744 }
3745
3746 for _, isClient := range []bool{false, true} {
3747 suffix := "-Server"
3748 testType := serverTest
3749 if isClient {
3750 suffix = "-Client"
3751 testType = clientTest
3752 }
3753
3754 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003755 // In TLS 1.3, the extension is irrelevant and
3756 // always reports as enabled.
3757 var flags []string
3758 if with || ver.version >= VersionTLS13 {
3759 flags = []string{expectEMSFlag}
3760 }
3761
Adam Langley75712922014-10-10 16:23:43 -07003762 test := testCase{
3763 testType: testType,
3764 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3765 config: Config{
3766 MinVersion: ver.version,
3767 MaxVersion: ver.version,
3768 Bugs: ProtocolBugs{
3769 NoExtendedMasterSecret: !with,
3770 RequireExtendedMasterSecret: with,
3771 },
3772 },
David Benjamina5022392017-07-10 17:40:39 -04003773 tls13Variant: ver.tls13Variant,
3774 flags: flags,
3775 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003776 }
3777 if test.shouldFail {
3778 test.expectedLocalError = "extended master secret required but not supported by peer"
3779 }
3780 testCases = append(testCases, test)
3781 }
3782 }
3783 }
3784
Adam Langleyba5934b2015-06-02 10:50:35 -07003785 for _, isClient := range []bool{false, true} {
3786 for _, supportedInFirstConnection := range []bool{false, true} {
3787 for _, supportedInResumeConnection := range []bool{false, true} {
3788 boolToWord := func(b bool) string {
3789 if b {
3790 return "Yes"
3791 }
3792 return "No"
3793 }
3794 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3795 if isClient {
3796 suffix += "Client"
3797 } else {
3798 suffix += "Server"
3799 }
3800
3801 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003802 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003803 Bugs: ProtocolBugs{
3804 RequireExtendedMasterSecret: true,
3805 },
3806 }
3807
3808 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003810 Bugs: ProtocolBugs{
3811 NoExtendedMasterSecret: true,
3812 },
3813 }
3814
3815 test := testCase{
3816 name: "ExtendedMasterSecret-" + suffix,
3817 resumeSession: true,
3818 }
3819
3820 if !isClient {
3821 test.testType = serverTest
3822 }
3823
3824 if supportedInFirstConnection {
3825 test.config = supportedConfig
3826 } else {
3827 test.config = noSupportConfig
3828 }
3829
3830 if supportedInResumeConnection {
3831 test.resumeConfig = &supportedConfig
3832 } else {
3833 test.resumeConfig = &noSupportConfig
3834 }
3835
3836 switch suffix {
3837 case "YesToYes-Client", "YesToYes-Server":
3838 // When a session is resumed, it should
3839 // still be aware that its master
3840 // secret was generated via EMS and
3841 // thus it's safe to use tls-unique.
3842 test.flags = []string{expectEMSFlag}
3843 case "NoToYes-Server":
3844 // If an original connection did not
3845 // contain EMS, but a resumption
3846 // handshake does, then a server should
3847 // not resume the session.
3848 test.expectResumeRejected = true
3849 case "YesToNo-Server":
3850 // Resuming an EMS session without the
3851 // EMS extension should cause the
3852 // server to abort the connection.
3853 test.shouldFail = true
3854 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3855 case "NoToYes-Client":
3856 // A client should abort a connection
3857 // where the server resumed a non-EMS
3858 // session but echoed the EMS
3859 // extension.
3860 test.shouldFail = true
3861 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3862 case "YesToNo-Client":
3863 // A client should abort a connection
3864 // where the server didn't echo EMS
3865 // when the session used it.
3866 test.shouldFail = true
3867 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3868 }
3869
3870 testCases = append(testCases, test)
3871 }
3872 }
3873 }
David Benjamin163c9562016-08-29 23:14:17 -04003874
3875 // Switching EMS on renegotiation is forbidden.
3876 testCases = append(testCases, testCase{
3877 name: "ExtendedMasterSecret-Renego-NoEMS",
3878 config: Config{
3879 MaxVersion: VersionTLS12,
3880 Bugs: ProtocolBugs{
3881 NoExtendedMasterSecret: true,
3882 NoExtendedMasterSecretOnRenegotiation: true,
3883 },
3884 },
3885 renegotiate: 1,
3886 flags: []string{
3887 "-renegotiate-freely",
3888 "-expect-total-renegotiations", "1",
3889 },
3890 })
3891
3892 testCases = append(testCases, testCase{
3893 name: "ExtendedMasterSecret-Renego-Upgrade",
3894 config: Config{
3895 MaxVersion: VersionTLS12,
3896 Bugs: ProtocolBugs{
3897 NoExtendedMasterSecret: true,
3898 },
3899 },
3900 renegotiate: 1,
3901 flags: []string{
3902 "-renegotiate-freely",
3903 "-expect-total-renegotiations", "1",
3904 },
3905 shouldFail: true,
3906 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3907 })
3908
3909 testCases = append(testCases, testCase{
3910 name: "ExtendedMasterSecret-Renego-Downgrade",
3911 config: Config{
3912 MaxVersion: VersionTLS12,
3913 Bugs: ProtocolBugs{
3914 NoExtendedMasterSecretOnRenegotiation: true,
3915 },
3916 },
3917 renegotiate: 1,
3918 flags: []string{
3919 "-renegotiate-freely",
3920 "-expect-total-renegotiations", "1",
3921 },
3922 shouldFail: true,
3923 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3924 })
Adam Langley75712922014-10-10 16:23:43 -07003925}
3926
David Benjamin582ba042016-07-07 12:33:25 -07003927type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003928 protocol protocol
3929 async bool
3930 splitHandshake bool
3931 packHandshakeFlight bool
3932 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003933}
3934
David Benjamin43ec06f2014-08-05 02:28:57 -04003935// Adds tests that try to cover the range of the handshake state machine, under
3936// various conditions. Some of these are redundant with other tests, but they
3937// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003938func addAllStateMachineCoverageTests() {
3939 for _, async := range []bool{false, true} {
3940 for _, protocol := range []protocol{tls, dtls} {
3941 addStateMachineCoverageTests(stateMachineTestConfig{
3942 protocol: protocol,
3943 async: async,
3944 })
3945 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003946 protocol: protocol,
3947 async: async,
3948 implicitHandshake: true,
3949 })
3950 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003951 protocol: protocol,
3952 async: async,
3953 splitHandshake: true,
3954 })
3955 if protocol == tls {
3956 addStateMachineCoverageTests(stateMachineTestConfig{
3957 protocol: protocol,
3958 async: async,
3959 packHandshakeFlight: true,
3960 })
3961 }
3962 }
3963 }
3964}
3965
3966func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003967 var tests []testCase
3968
3969 // Basic handshake, with resumption. Client and server,
3970 // session ID and session ticket.
3971 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003972 name: "Basic-Client",
3973 config: Config{
3974 MaxVersion: VersionTLS12,
3975 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003976 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003977 // Ensure session tickets are used, not session IDs.
3978 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003979 })
3980 tests = append(tests, testCase{
3981 name: "Basic-Client-RenewTicket",
3982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003983 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003984 Bugs: ProtocolBugs{
3985 RenewTicketOnResume: true,
3986 },
3987 },
David Benjamin46662482016-08-17 00:51:00 -04003988 flags: []string{"-expect-ticket-renewal"},
3989 resumeSession: true,
3990 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003991 })
3992 tests = append(tests, testCase{
3993 name: "Basic-Client-NoTicket",
3994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003995 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003996 SessionTicketsDisabled: true,
3997 },
3998 resumeSession: true,
3999 })
4000 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05004001 testType: serverTest,
4002 name: "Basic-Server",
4003 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004004 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05004005 Bugs: ProtocolBugs{
4006 RequireSessionTickets: true,
4007 },
4008 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004009 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004010 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004011 })
4012 tests = append(tests, testCase{
4013 testType: serverTest,
4014 name: "Basic-Server-NoTickets",
4015 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004016 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 SessionTicketsDisabled: true,
4018 },
4019 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004020 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004021 })
4022 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004023 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004024 name: "Basic-Server-EarlyCallback",
4025 config: Config{
4026 MaxVersion: VersionTLS12,
4027 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004028 flags: []string{"-use-early-callback"},
4029 resumeSession: true,
4030 })
4031
Steven Valdez143e8b32016-07-11 13:19:03 -04004032 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004033 if config.protocol == tls {
4034 tests = append(tests, testCase{
4035 name: "TLS13-1RTT-Client",
4036 config: Config{
4037 MaxVersion: VersionTLS13,
4038 MinVersion: VersionTLS13,
4039 },
David Benjamin46662482016-08-17 00:51:00 -04004040 resumeSession: true,
4041 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004042 })
4043
4044 tests = append(tests, testCase{
4045 testType: serverTest,
4046 name: "TLS13-1RTT-Server",
4047 config: Config{
4048 MaxVersion: VersionTLS13,
4049 MinVersion: VersionTLS13,
4050 },
David Benjamin46662482016-08-17 00:51:00 -04004051 resumeSession: true,
4052 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004053 // TLS 1.3 uses tickets, so the session should not be
4054 // cached statefully.
4055 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004056 })
4057
4058 tests = append(tests, testCase{
4059 name: "TLS13-HelloRetryRequest-Client",
4060 config: Config{
4061 MaxVersion: VersionTLS13,
4062 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004063 // P-384 requires a HelloRetryRequest against BoringSSL's default
4064 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004065 CurvePreferences: []CurveID{CurveP384},
4066 Bugs: ProtocolBugs{
4067 ExpectMissingKeyShare: true,
4068 },
4069 },
4070 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4071 resumeSession: true,
4072 })
4073
4074 tests = append(tests, testCase{
4075 testType: serverTest,
4076 name: "TLS13-HelloRetryRequest-Server",
4077 config: Config{
4078 MaxVersion: VersionTLS13,
4079 MinVersion: VersionTLS13,
4080 // Require a HelloRetryRequest for every curve.
4081 DefaultCurves: []CurveID{},
4082 },
4083 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4084 resumeSession: true,
4085 })
Steven Valdez2d850622017-01-11 11:34:52 -05004086
Steven Valdez2d850622017-01-11 11:34:52 -05004087 tests = append(tests, testCase{
4088 testType: clientTest,
4089 name: "TLS13-EarlyData-Client",
4090 config: Config{
4091 MaxVersion: VersionTLS13,
4092 MinVersion: VersionTLS13,
4093 MaxEarlyDataSize: 16384,
4094 },
Steven Valdeze831a812017-03-09 14:56:07 -05004095 resumeConfig: &Config{
4096 MaxVersion: VersionTLS13,
4097 MinVersion: VersionTLS13,
4098 MaxEarlyDataSize: 16384,
4099 Bugs: ProtocolBugs{
4100 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4101 },
4102 },
Steven Valdez2d850622017-01-11 11:34:52 -05004103 resumeSession: true,
4104 flags: []string{
4105 "-enable-early-data",
4106 "-expect-early-data-info",
4107 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05004108 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05004109 },
4110 })
4111
4112 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05004113 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004114 name: "TLS13Experiment-EarlyData-Client",
4115 config: Config{
4116 MaxVersion: VersionTLS13,
4117 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004118 MaxEarlyDataSize: 16384,
4119 },
4120 resumeConfig: &Config{
4121 MaxVersion: VersionTLS13,
4122 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004123 MaxEarlyDataSize: 16384,
4124 Bugs: ProtocolBugs{
4125 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4126 },
4127 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004128 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004129 resumeSession: true,
4130 flags: []string{
4131 "-enable-early-data",
4132 "-expect-early-data-info",
4133 "-expect-accept-early-data",
4134 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -04004135 },
4136 })
4137
4138 tests = append(tests, testCase{
4139 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004140 name: "TLS13RecordTypeExperiment-EarlyData-Client",
4141 config: Config{
4142 MaxVersion: VersionTLS13,
4143 MinVersion: VersionTLS13,
4144 TLS13Variant: TLS13RecordTypeExperiment,
4145 MaxEarlyDataSize: 16384,
4146 },
4147 resumeConfig: &Config{
4148 MaxVersion: VersionTLS13,
4149 MinVersion: VersionTLS13,
4150 TLS13Variant: TLS13RecordTypeExperiment,
4151 MaxEarlyDataSize: 16384,
4152 Bugs: ProtocolBugs{
4153 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4154 },
4155 },
Steven Valdez0e4a4482017-07-17 11:12:34 -04004156 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004157 resumeSession: true,
4158 flags: []string{
4159 "-enable-early-data",
4160 "-expect-early-data-info",
4161 "-expect-accept-early-data",
4162 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -04004163 },
4164 })
4165
4166 tests = append(tests, testCase{
4167 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004168 name: "TLS13-EarlyData-TooMuchData-Client",
4169 config: Config{
4170 MaxVersion: VersionTLS13,
4171 MinVersion: VersionTLS13,
4172 MaxEarlyDataSize: 2,
4173 },
4174 resumeConfig: &Config{
4175 MaxVersion: VersionTLS13,
4176 MinVersion: VersionTLS13,
4177 MaxEarlyDataSize: 2,
4178 Bugs: ProtocolBugs{
4179 ExpectEarlyData: [][]byte{{'h', 'e'}},
4180 },
4181 },
4182 resumeShimPrefix: "llo",
4183 resumeSession: true,
4184 flags: []string{
4185 "-enable-early-data",
4186 "-expect-early-data-info",
4187 "-expect-accept-early-data",
4188 "-on-resume-shim-writes-first",
4189 },
4190 })
4191
4192 // Unfinished writes can only be tested when operations are async. EarlyData
4193 // can't be tested as part of an ImplicitHandshake in this case since
4194 // otherwise the early data will be sent as normal data.
4195 if config.async && !config.implicitHandshake {
4196 tests = append(tests, testCase{
4197 testType: clientTest,
4198 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4199 config: Config{
4200 MaxVersion: VersionTLS13,
4201 MinVersion: VersionTLS13,
4202 MaxEarlyDataSize: 16384,
4203 },
4204 resumeConfig: &Config{
4205 MaxVersion: VersionTLS13,
4206 MinVersion: VersionTLS13,
4207 MaxEarlyDataSize: 16384,
4208 Bugs: ProtocolBugs{
4209 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4210 },
4211 },
4212 resumeSession: true,
4213 flags: []string{
4214 "-enable-early-data",
4215 "-expect-early-data-info",
4216 "-expect-accept-early-data",
4217 "-on-resume-read-with-unfinished-write",
4218 "-on-resume-shim-writes-first",
4219 },
4220 })
4221
4222 // Rejected unfinished writes are discarded (from the
4223 // perspective of the calling application) on 0-RTT
4224 // reject.
4225 tests = append(tests, testCase{
4226 testType: clientTest,
4227 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4228 config: Config{
4229 MaxVersion: VersionTLS13,
4230 MinVersion: VersionTLS13,
4231 MaxEarlyDataSize: 16384,
4232 },
4233 resumeConfig: &Config{
4234 MaxVersion: VersionTLS13,
4235 MinVersion: VersionTLS13,
4236 MaxEarlyDataSize: 16384,
4237 Bugs: ProtocolBugs{
4238 AlwaysRejectEarlyData: true,
4239 },
4240 },
4241 resumeSession: true,
4242 flags: []string{
4243 "-enable-early-data",
4244 "-expect-early-data-info",
4245 "-expect-reject-early-data",
4246 "-on-resume-read-with-unfinished-write",
4247 "-on-resume-shim-writes-first",
4248 },
4249 })
4250 }
4251
4252 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004253 testType: serverTest,
4254 name: "TLS13-EarlyData-Server",
4255 config: Config{
4256 MaxVersion: VersionTLS13,
4257 MinVersion: VersionTLS13,
4258 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05004259 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05004260 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05004261 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05004262 },
4263 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05004264 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05004265 resumeSession: true,
4266 flags: []string{
4267 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05004268 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05004269 },
4270 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004271
4272 tests = append(tests, testCase{
4273 testType: serverTest,
Steven Valdez520e1222017-06-13 12:45:25 -04004274 name: "TLS13Experiment-EarlyData-Server",
4275 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004276 MaxVersion: VersionTLS13,
4277 MinVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -04004278 Bugs: ProtocolBugs{
4279 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4280 ExpectEarlyDataAccepted: true,
4281 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4282 },
4283 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004284 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -04004285 messageCount: 2,
4286 resumeSession: true,
4287 flags: []string{
4288 "-enable-early-data",
4289 "-expect-accept-early-data",
Steven Valdez520e1222017-06-13 12:45:25 -04004290 },
4291 })
4292
4293 tests = append(tests, testCase{
4294 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -04004295 name: "TLS13RecordTypeExperiment-EarlyData-Server",
4296 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -04004297 MaxVersion: VersionTLS13,
4298 MinVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -04004299 Bugs: ProtocolBugs{
4300 SendEarlyData: [][]byte{{1, 2, 3, 4}},
4301 ExpectEarlyDataAccepted: true,
4302 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
4303 },
4304 },
David Benjaminf6ae9e62017-08-08 20:04:41 -04004305 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -04004306 messageCount: 2,
4307 resumeSession: true,
4308 flags: []string{
4309 "-enable-early-data",
4310 "-expect-accept-early-data",
Steven Valdezdbe01582017-07-14 10:39:28 -04004311 },
4312 })
4313
4314 tests = append(tests, testCase{
4315 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004316 name: "TLS13-MaxEarlyData-Server",
4317 config: Config{
4318 MaxVersion: VersionTLS13,
4319 MinVersion: VersionTLS13,
4320 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004321 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004322 ExpectEarlyDataAccepted: true,
4323 },
4324 },
4325 messageCount: 2,
4326 resumeSession: true,
4327 flags: []string{
4328 "-enable-early-data",
4329 "-expect-accept-early-data",
4330 },
4331 shouldFail: true,
4332 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4333 })
David Benjamine73c7f42016-08-17 00:29:33 -04004334 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004335
David Benjamin760b1dd2015-05-15 23:33:48 -04004336 // TLS client auth.
4337 tests = append(tests, testCase{
4338 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004339 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004341 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004342 ClientAuth: RequestClientCert,
4343 },
4344 })
4345 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004346 testType: serverTest,
4347 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004348 config: Config{
4349 MaxVersion: VersionTLS12,
4350 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004351 // Setting SSL_VERIFY_PEER allows anonymous clients.
4352 flags: []string{"-verify-peer"},
4353 })
David Benjamin582ba042016-07-07 12:33:25 -07004354 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004355 tests = append(tests, testCase{
4356 testType: clientTest,
4357 name: "ClientAuth-NoCertificate-Client-SSL3",
4358 config: Config{
4359 MaxVersion: VersionSSL30,
4360 ClientAuth: RequestClientCert,
4361 },
4362 })
4363 tests = append(tests, testCase{
4364 testType: serverTest,
4365 name: "ClientAuth-NoCertificate-Server-SSL3",
4366 config: Config{
4367 MaxVersion: VersionSSL30,
4368 },
4369 // Setting SSL_VERIFY_PEER allows anonymous clients.
4370 flags: []string{"-verify-peer"},
4371 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004372 tests = append(tests, testCase{
4373 testType: clientTest,
4374 name: "ClientAuth-NoCertificate-Client-TLS13",
4375 config: Config{
4376 MaxVersion: VersionTLS13,
4377 ClientAuth: RequestClientCert,
4378 },
4379 })
4380 tests = append(tests, testCase{
4381 testType: serverTest,
4382 name: "ClientAuth-NoCertificate-Server-TLS13",
4383 config: Config{
4384 MaxVersion: VersionTLS13,
4385 },
4386 // Setting SSL_VERIFY_PEER allows anonymous clients.
4387 flags: []string{"-verify-peer"},
4388 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004389 }
4390 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004391 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004392 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004394 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004395 ClientAuth: RequireAnyClientCert,
4396 },
4397 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004400 },
4401 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004402 tests = append(tests, testCase{
4403 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004404 name: "ClientAuth-RSA-Client-TLS13",
4405 config: Config{
4406 MaxVersion: VersionTLS13,
4407 ClientAuth: RequireAnyClientCert,
4408 },
4409 flags: []string{
4410 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4411 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4412 },
4413 })
4414 tests = append(tests, testCase{
4415 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004416 name: "ClientAuth-ECDSA-Client",
4417 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004418 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004419 ClientAuth: RequireAnyClientCert,
4420 },
4421 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004422 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4423 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004424 },
4425 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004426 tests = append(tests, testCase{
4427 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004428 name: "ClientAuth-ECDSA-Client-TLS13",
4429 config: Config{
4430 MaxVersion: VersionTLS13,
4431 ClientAuth: RequireAnyClientCert,
4432 },
4433 flags: []string{
4434 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4435 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4436 },
4437 })
4438 tests = append(tests, testCase{
4439 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004440 name: "ClientAuth-NoCertificate-OldCallback",
4441 config: Config{
4442 MaxVersion: VersionTLS12,
4443 ClientAuth: RequestClientCert,
4444 },
4445 flags: []string{"-use-old-client-cert-callback"},
4446 })
4447 tests = append(tests, testCase{
4448 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004449 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4450 config: Config{
4451 MaxVersion: VersionTLS13,
4452 ClientAuth: RequestClientCert,
4453 },
4454 flags: []string{"-use-old-client-cert-callback"},
4455 })
4456 tests = append(tests, testCase{
4457 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004458 name: "ClientAuth-OldCallback",
4459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004460 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004461 ClientAuth: RequireAnyClientCert,
4462 },
4463 flags: []string{
4464 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4465 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4466 "-use-old-client-cert-callback",
4467 },
4468 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004469 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004470 testType: clientTest,
4471 name: "ClientAuth-OldCallback-TLS13",
4472 config: Config{
4473 MaxVersion: VersionTLS13,
4474 ClientAuth: RequireAnyClientCert,
4475 },
4476 flags: []string{
4477 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4478 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4479 "-use-old-client-cert-callback",
4480 },
4481 })
4482 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004483 testType: serverTest,
4484 name: "ClientAuth-Server",
4485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004486 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004487 Certificates: []Certificate{rsaCertificate},
4488 },
4489 flags: []string{"-require-any-client-certificate"},
4490 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004491 tests = append(tests, testCase{
4492 testType: serverTest,
4493 name: "ClientAuth-Server-TLS13",
4494 config: Config{
4495 MaxVersion: VersionTLS13,
4496 Certificates: []Certificate{rsaCertificate},
4497 },
4498 flags: []string{"-require-any-client-certificate"},
4499 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004500
David Benjamin4c3ddf72016-06-29 18:13:53 -04004501 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004502 tests = append(tests, testCase{
4503 testType: serverTest,
4504 name: "Basic-Server-RSA",
4505 config: Config{
4506 MaxVersion: VersionTLS12,
4507 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4508 },
4509 flags: []string{
4510 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4511 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4512 },
4513 })
4514 tests = append(tests, testCase{
4515 testType: serverTest,
4516 name: "Basic-Server-ECDHE-RSA",
4517 config: Config{
4518 MaxVersion: VersionTLS12,
4519 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4520 },
4521 flags: []string{
4522 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4523 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4524 },
4525 })
4526 tests = append(tests, testCase{
4527 testType: serverTest,
4528 name: "Basic-Server-ECDHE-ECDSA",
4529 config: Config{
4530 MaxVersion: VersionTLS12,
4531 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4532 },
4533 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004534 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4535 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004536 },
4537 })
David Benjamin69522112017-03-28 15:38:29 -05004538 tests = append(tests, testCase{
4539 testType: serverTest,
4540 name: "Basic-Server-Ed25519",
4541 config: Config{
4542 MaxVersion: VersionTLS12,
4543 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4544 },
4545 flags: []string{
4546 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4547 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4548 "-enable-ed25519",
4549 },
4550 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004551
David Benjamin760b1dd2015-05-15 23:33:48 -04004552 // No session ticket support; server doesn't send NewSessionTicket.
4553 tests = append(tests, testCase{
4554 name: "SessionTicketsDisabled-Client",
4555 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004556 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004557 SessionTicketsDisabled: true,
4558 },
4559 })
4560 tests = append(tests, testCase{
4561 testType: serverTest,
4562 name: "SessionTicketsDisabled-Server",
4563 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004564 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004565 SessionTicketsDisabled: true,
4566 },
4567 })
4568
4569 // Skip ServerKeyExchange in PSK key exchange if there's no
4570 // identity hint.
4571 tests = append(tests, testCase{
4572 name: "EmptyPSKHint-Client",
4573 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004574 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004575 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4576 PreSharedKey: []byte("secret"),
4577 },
4578 flags: []string{"-psk", "secret"},
4579 })
4580 tests = append(tests, testCase{
4581 testType: serverTest,
4582 name: "EmptyPSKHint-Server",
4583 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004584 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004585 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4586 PreSharedKey: []byte("secret"),
4587 },
4588 flags: []string{"-psk", "secret"},
4589 })
4590
David Benjamin4c3ddf72016-06-29 18:13:53 -04004591 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004592 tests = append(tests, testCase{
4593 testType: clientTest,
4594 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004595 config: Config{
4596 MaxVersion: VersionTLS12,
4597 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004598 flags: []string{
4599 "-enable-ocsp-stapling",
4600 "-expect-ocsp-response",
4601 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004602 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004603 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004604 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004605 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004606 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004607 testType: serverTest,
4608 name: "OCSPStapling-Server",
4609 config: Config{
4610 MaxVersion: VersionTLS12,
4611 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004612 expectedOCSPResponse: testOCSPResponse,
4613 flags: []string{
4614 "-ocsp-response",
4615 base64.StdEncoding.EncodeToString(testOCSPResponse),
4616 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004617 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004618 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004619 tests = append(tests, testCase{
4620 testType: clientTest,
4621 name: "OCSPStapling-Client-TLS13",
4622 config: Config{
4623 MaxVersion: VersionTLS13,
4624 },
4625 flags: []string{
4626 "-enable-ocsp-stapling",
4627 "-expect-ocsp-response",
4628 base64.StdEncoding.EncodeToString(testOCSPResponse),
4629 "-verify-peer",
4630 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004631 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004632 })
4633 tests = append(tests, testCase{
4634 testType: serverTest,
4635 name: "OCSPStapling-Server-TLS13",
4636 config: Config{
4637 MaxVersion: VersionTLS13,
4638 },
4639 expectedOCSPResponse: testOCSPResponse,
4640 flags: []string{
4641 "-ocsp-response",
4642 base64.StdEncoding.EncodeToString(testOCSPResponse),
4643 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004644 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004645 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004646
David Benjamin4c3ddf72016-06-29 18:13:53 -04004647 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004648 for _, vers := range tlsVersions {
4649 if config.protocol == dtls && !vers.hasDTLS {
4650 continue
4651 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004652 for _, useCustomCallback := range []bool{false, true} {
4653 for _, testType := range []testType{clientTest, serverTest} {
4654 suffix := "-Client"
4655 if testType == serverTest {
4656 suffix = "-Server"
4657 }
4658 suffix += "-" + vers.name
4659 if useCustomCallback {
4660 suffix += "-CustomCallback"
4661 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004662
David Benjamin3a1dd462017-07-11 16:13:10 -04004663 flags := []string{"-verify-peer"}
4664 if testType == serverTest {
4665 flags = append(flags, "-require-any-client-certificate")
4666 }
4667 if useCustomCallback {
4668 flags = append(flags, "-use-custom-verify-callback")
4669 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004670
David Benjamin3a1dd462017-07-11 16:13:10 -04004671 tests = append(tests, testCase{
4672 testType: testType,
4673 name: "CertificateVerificationSucceed" + suffix,
4674 config: Config{
4675 MaxVersion: vers.version,
4676 Certificates: []Certificate{rsaCertificate},
4677 },
4678 tls13Variant: vers.tls13Variant,
4679 flags: append([]string{"-expect-verify-result"}, flags...),
4680 resumeSession: true,
4681 })
4682 tests = append(tests, testCase{
4683 testType: testType,
4684 name: "CertificateVerificationFail" + suffix,
4685 config: Config{
4686 MaxVersion: vers.version,
4687 Certificates: []Certificate{rsaCertificate},
4688 },
4689 tls13Variant: vers.tls13Variant,
4690 flags: append([]string{"-verify-fail"}, flags...),
4691 shouldFail: true,
4692 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4693 })
4694 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004695 }
4696
4697 // By default, the client is in a soft fail mode where the peer
4698 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004699 tests = append(tests, testCase{
4700 testType: clientTest,
4701 name: "CertificateVerificationSoftFail-" + vers.name,
4702 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004703 MaxVersion: vers.version,
4704 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004705 },
David Benjamina5022392017-07-10 17:40:39 -04004706 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004707 flags: []string{
4708 "-verify-fail",
4709 "-expect-verify-result",
4710 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004711 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004712 })
4713 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004714
David Benjamin1d4f4c02016-07-26 18:03:08 -04004715 tests = append(tests, testCase{
4716 name: "ShimSendAlert",
4717 flags: []string{"-send-alert"},
4718 shimWritesFirst: true,
4719 shouldFail: true,
4720 expectedLocalError: "remote error: decompression failure",
4721 })
4722
David Benjamin582ba042016-07-07 12:33:25 -07004723 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004724 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004725 name: "Renegotiate-Client",
4726 config: Config{
4727 MaxVersion: VersionTLS12,
4728 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004729 renegotiate: 1,
4730 flags: []string{
4731 "-renegotiate-freely",
4732 "-expect-total-renegotiations", "1",
4733 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004734 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004735
David Benjamin47921102016-07-28 11:29:18 -04004736 tests = append(tests, testCase{
4737 name: "SendHalfHelloRequest",
4738 config: Config{
4739 MaxVersion: VersionTLS12,
4740 Bugs: ProtocolBugs{
4741 PackHelloRequestWithFinished: config.packHandshakeFlight,
4742 },
4743 },
4744 sendHalfHelloRequest: true,
4745 flags: []string{"-renegotiate-ignore"},
4746 shouldFail: true,
4747 expectedError: ":UNEXPECTED_RECORD:",
4748 })
4749
David Benjamin760b1dd2015-05-15 23:33:48 -04004750 // NPN on client and server; results in post-handshake message.
4751 tests = append(tests, testCase{
4752 name: "NPN-Client",
4753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004754 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004755 NextProtos: []string{"foo"},
4756 },
4757 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004758 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004759 expectedNextProto: "foo",
4760 expectedNextProtoType: npn,
4761 })
4762 tests = append(tests, testCase{
4763 testType: serverTest,
4764 name: "NPN-Server",
4765 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004766 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004767 NextProtos: []string{"bar"},
4768 },
4769 flags: []string{
4770 "-advertise-npn", "\x03foo\x03bar\x03baz",
4771 "-expect-next-proto", "bar",
4772 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004773 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004774 expectedNextProto: "bar",
4775 expectedNextProtoType: npn,
4776 })
4777
4778 // TODO(davidben): Add tests for when False Start doesn't trigger.
4779
4780 // Client does False Start and negotiates NPN.
4781 tests = append(tests, testCase{
4782 name: "FalseStart",
4783 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004784 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004785 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4786 NextProtos: []string{"foo"},
4787 Bugs: ProtocolBugs{
4788 ExpectFalseStart: true,
4789 },
4790 },
4791 flags: []string{
4792 "-false-start",
4793 "-select-next-proto", "foo",
4794 },
4795 shimWritesFirst: true,
4796 resumeSession: true,
4797 })
4798
4799 // Client does False Start and negotiates ALPN.
4800 tests = append(tests, testCase{
4801 name: "FalseStart-ALPN",
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 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004813 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004814 },
4815 shimWritesFirst: true,
4816 resumeSession: true,
4817 })
4818
David Benjamin760b1dd2015-05-15 23:33:48 -04004819 // False Start without session tickets.
4820 tests = append(tests, testCase{
4821 name: "FalseStart-SessionTicketsDisabled",
4822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004823 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004824 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4825 NextProtos: []string{"foo"},
4826 SessionTicketsDisabled: true,
4827 Bugs: ProtocolBugs{
4828 ExpectFalseStart: true,
4829 },
4830 },
4831 flags: []string{
4832 "-false-start",
4833 "-select-next-proto", "foo",
4834 },
4835 shimWritesFirst: true,
4836 })
4837
4838 // Server parses a V2ClientHello.
4839 tests = append(tests, testCase{
4840 testType: serverTest,
4841 name: "SendV2ClientHello",
4842 config: Config{
4843 // Choose a cipher suite that does not involve
4844 // elliptic curves, so no extensions are
4845 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004846 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004847 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004848 Bugs: ProtocolBugs{
4849 SendV2ClientHello: true,
4850 },
4851 },
David Benjamin78b8b992017-08-01 18:38:41 -04004852 flags: []string{
4853 "-expect-msg-callback",
4854 `read v2clienthello
4855write hs 2
4856write hs 11
4857write hs 14
4858read hs 16
4859read ccs
4860read hs 20
4861write ccs
4862write hs 20
4863read alert 1 0
4864`,
4865 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004866 })
4867
Nick Harper60a85cb2016-09-23 16:25:11 -07004868 // Test Channel ID
4869 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004870 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004871 continue
4872 }
4873 // Client sends a Channel ID.
4874 tests = append(tests, testCase{
4875 name: "ChannelID-Client-" + ver.name,
4876 config: Config{
4877 MaxVersion: ver.version,
4878 RequestChannelID: true,
4879 },
David Benjamina5022392017-07-10 17:40:39 -04004880 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004881 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4882 resumeSession: true,
4883 expectChannelID: true,
4884 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004885
Nick Harper60a85cb2016-09-23 16:25:11 -07004886 // Server accepts a Channel ID.
4887 tests = append(tests, testCase{
4888 testType: serverTest,
4889 name: "ChannelID-Server-" + ver.name,
4890 config: Config{
4891 MaxVersion: ver.version,
4892 ChannelID: channelIDKey,
4893 },
David Benjamina5022392017-07-10 17:40:39 -04004894 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004895 flags: []string{
4896 "-expect-channel-id",
4897 base64.StdEncoding.EncodeToString(channelIDBytes),
4898 },
4899 resumeSession: true,
4900 expectChannelID: true,
4901 })
4902
4903 tests = append(tests, testCase{
4904 testType: serverTest,
4905 name: "InvalidChannelIDSignature-" + ver.name,
4906 config: Config{
4907 MaxVersion: ver.version,
4908 ChannelID: channelIDKey,
4909 Bugs: ProtocolBugs{
4910 InvalidChannelIDSignature: true,
4911 },
4912 },
David Benjamina5022392017-07-10 17:40:39 -04004913 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004914 flags: []string{"-enable-channel-id"},
4915 shouldFail: true,
4916 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4917 })
David Benjamin634f4752017-07-01 11:08:41 -04004918
4919 if ver.version < VersionTLS13 {
4920 // Channel ID requires ECDHE ciphers.
4921 tests = append(tests, testCase{
4922 testType: serverTest,
4923 name: "ChannelID-NoECDHE-" + ver.name,
4924 config: Config{
4925 MaxVersion: ver.version,
4926 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4927 ChannelID: channelIDKey,
4928 },
4929 expectChannelID: false,
4930 flags: []string{"-enable-channel-id"},
4931 })
4932
4933 // Sanity-check setting expectChannelID false works.
4934 tests = append(tests, testCase{
4935 testType: serverTest,
4936 name: "ChannelID-ECDHE-" + ver.name,
4937 config: Config{
4938 MaxVersion: ver.version,
4939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4940 ChannelID: channelIDKey,
4941 },
4942 expectChannelID: false,
4943 flags: []string{"-enable-channel-id"},
4944 shouldFail: true,
4945 expectedLocalError: "channel ID unexpectedly negotiated",
4946 })
4947 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004948 }
David Benjamin30789da2015-08-29 22:56:45 -04004949
David Benjaminf8fcdf32016-06-08 15:56:13 -04004950 // Channel ID and NPN at the same time, to ensure their relative
4951 // ordering is correct.
4952 tests = append(tests, testCase{
4953 name: "ChannelID-NPN-Client",
4954 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004955 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004956 RequestChannelID: true,
4957 NextProtos: []string{"foo"},
4958 },
4959 flags: []string{
4960 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4961 "-select-next-proto", "foo",
4962 },
4963 resumeSession: true,
4964 expectChannelID: true,
4965 expectedNextProto: "foo",
4966 expectedNextProtoType: npn,
4967 })
4968 tests = append(tests, testCase{
4969 testType: serverTest,
4970 name: "ChannelID-NPN-Server",
4971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004972 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004973 ChannelID: channelIDKey,
4974 NextProtos: []string{"bar"},
4975 },
4976 flags: []string{
4977 "-expect-channel-id",
4978 base64.StdEncoding.EncodeToString(channelIDBytes),
4979 "-advertise-npn", "\x03foo\x03bar\x03baz",
4980 "-expect-next-proto", "bar",
4981 },
4982 resumeSession: true,
4983 expectChannelID: true,
4984 expectedNextProto: "bar",
4985 expectedNextProtoType: npn,
4986 })
4987
David Benjamin30789da2015-08-29 22:56:45 -04004988 // Bidirectional shutdown with the runner initiating.
4989 tests = append(tests, testCase{
4990 name: "Shutdown-Runner",
4991 config: Config{
4992 Bugs: ProtocolBugs{
4993 ExpectCloseNotify: true,
4994 },
4995 },
4996 flags: []string{"-check-close-notify"},
4997 })
4998
David Benjamine3843d42017-03-25 18:00:56 -05004999 if !config.implicitHandshake {
5000 // Bidirectional shutdown with the shim initiating. The runner,
5001 // in the meantime, sends garbage before the close_notify which
5002 // the shim must ignore. This test is disabled under implicit
5003 // handshake tests because the shim never reads or writes.
5004 tests = append(tests, testCase{
5005 name: "Shutdown-Shim",
5006 config: Config{
5007 MaxVersion: VersionTLS12,
5008 Bugs: ProtocolBugs{
5009 ExpectCloseNotify: true,
5010 },
David Benjamin30789da2015-08-29 22:56:45 -04005011 },
David Benjamine3843d42017-03-25 18:00:56 -05005012 shimShutsDown: true,
5013 sendEmptyRecords: 1,
5014 sendWarningAlerts: 1,
5015 flags: []string{"-check-close-notify"},
5016 })
5017 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005018 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005019 // TODO(davidben): DTLS 1.3 will want a similar thing for
5020 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04005021 tests = append(tests, testCase{
5022 name: "SkipHelloVerifyRequest",
5023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005024 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04005025 Bugs: ProtocolBugs{
5026 SkipHelloVerifyRequest: true,
5027 },
5028 },
5029 })
5030 }
5031
David Benjamin760b1dd2015-05-15 23:33:48 -04005032 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07005033 test.protocol = config.protocol
5034 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005035 test.name += "-DTLS"
5036 }
David Benjamin582ba042016-07-07 12:33:25 -07005037 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05005038 test.name += "-Async"
5039 test.flags = append(test.flags, "-async")
5040 } else {
5041 test.name += "-Sync"
5042 }
David Benjamin582ba042016-07-07 12:33:25 -07005043 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05005044 test.name += "-SplitHandshakeRecords"
5045 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07005046 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05005047 test.config.Bugs.MaxPacketLength = 256
5048 test.flags = append(test.flags, "-mtu", "256")
5049 }
5050 }
David Benjamin582ba042016-07-07 12:33:25 -07005051 if config.packHandshakeFlight {
5052 test.name += "-PackHandshakeFlight"
5053 test.config.Bugs.PackHandshakeFlight = true
5054 }
David Benjamine3843d42017-03-25 18:00:56 -05005055 if config.implicitHandshake {
5056 test.name += "-ImplicitHandshake"
5057 test.flags = append(test.flags, "-implicit-handshake")
5058 }
David Benjamin760b1dd2015-05-15 23:33:48 -04005059 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04005060 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005061}
5062
Adam Langley524e7172015-02-20 16:04:00 -08005063func addDDoSCallbackTests() {
5064 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08005065 for _, resume := range []bool{false, true} {
5066 suffix := "Resume"
5067 if resume {
5068 suffix = "No" + suffix
5069 }
5070
5071 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005072 testType: serverTest,
5073 name: "Server-DDoS-OK-" + suffix,
5074 config: Config{
5075 MaxVersion: VersionTLS12,
5076 },
Adam Langley524e7172015-02-20 16:04:00 -08005077 flags: []string{"-install-ddos-callback"},
5078 resumeSession: resume,
5079 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005080 testCases = append(testCases, testCase{
5081 testType: serverTest,
5082 name: "Server-DDoS-OK-" + suffix + "-TLS13",
5083 config: Config{
5084 MaxVersion: VersionTLS13,
5085 },
5086 flags: []string{"-install-ddos-callback"},
5087 resumeSession: resume,
5088 })
Adam Langley524e7172015-02-20 16:04:00 -08005089
5090 failFlag := "-fail-ddos-callback"
5091 if resume {
5092 failFlag = "-fail-second-ddos-callback"
5093 }
5094 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005095 testType: serverTest,
5096 name: "Server-DDoS-Reject-" + suffix,
5097 config: Config{
5098 MaxVersion: VersionTLS12,
5099 },
David Benjamin2c66e072016-09-16 15:58:00 -04005100 flags: []string{"-install-ddos-callback", failFlag},
5101 resumeSession: resume,
5102 shouldFail: true,
5103 expectedError: ":CONNECTION_REJECTED:",
5104 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08005105 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005106 testCases = append(testCases, testCase{
5107 testType: serverTest,
5108 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
5109 config: Config{
5110 MaxVersion: VersionTLS13,
5111 },
David Benjamin2c66e072016-09-16 15:58:00 -04005112 flags: []string{"-install-ddos-callback", failFlag},
5113 resumeSession: resume,
5114 shouldFail: true,
5115 expectedError: ":CONNECTION_REJECTED:",
5116 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005117 })
Adam Langley524e7172015-02-20 16:04:00 -08005118 }
5119}
5120
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005121func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005122 for _, protocol := range []protocol{tls, dtls} {
5123 for _, shimVers := range allVersions(protocol) {
5124 // Assemble flags to disable all newer versions on the shim.
5125 var flags []string
5126 for _, vers := range allVersions(protocol) {
5127 if vers.version > shimVers.version {
5128 flags = append(flags, vers.excludeFlag)
5129 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005130 }
Steven Valdez520e1222017-06-13 12:45:25 -04005131
5132 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5133
5134 if shimVers.tls13Variant != 0 {
5135 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5136 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5137 }
5138
5139 // Test configuring the runner's maximum version.
5140 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005141 expectedVersion := shimVers.version
5142 if runnerVers.version < shimVers.version {
5143 expectedVersion = runnerVers.version
5144 }
Steven Valdez520e1222017-06-13 12:45:25 -04005145 // When running and shim have different TLS 1.3 variants enabled,
5146 // shim clients are expected to fall back to TLS 1.2, while shim
5147 // servers support both variants when enabled when the experiment is
5148 // enabled.
5149 expectedServerVersion := expectedVersion
5150 expectedClientVersion := expectedVersion
5151 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5152 expectedClientVersion = VersionTLS12
5153 expectedServerVersion = VersionTLS12
5154 if shimVers.tls13Variant != TLS13Default {
5155 expectedServerVersion = VersionTLS13
5156 }
5157 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005158
David Benjamin8b8c0062014-11-23 02:47:52 -05005159 suffix := shimVers.name + "-" + runnerVers.name
5160 if protocol == dtls {
5161 suffix += "-DTLS"
5162 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005163
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005164 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005165 clientVers := shimVers.version
5166 if clientVers > VersionTLS10 {
5167 clientVers = VersionTLS10
5168 }
Steven Valdez520e1222017-06-13 12:45:25 -04005169 clientVers = recordVersionToWire(clientVers, protocol)
5170 serverVers := expectedServerVersion
5171 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005172 serverVers = VersionTLS10
Steven Valdez16821262017-09-08 17:03:42 -04005173 if runnerVers.tls13Variant == TLS13Experiment2 {
5174 serverVers = VersionTLS12
5175 }
Nick Harper1fd39d82016-06-14 18:14:35 -07005176 }
Steven Valdez520e1222017-06-13 12:45:25 -04005177 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005178
David Benjamin8b8c0062014-11-23 02:47:52 -05005179 testCases = append(testCases, testCase{
5180 protocol: protocol,
5181 testType: clientTest,
5182 name: "VersionNegotiation-Client-" + suffix,
5183 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005184 MaxVersion: runnerVers.version,
5185 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005186 Bugs: ProtocolBugs{
5187 ExpectInitialRecordVersion: clientVers,
5188 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005189 },
5190 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005191 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005192 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005193 testCases = append(testCases, testCase{
5194 protocol: protocol,
5195 testType: clientTest,
5196 name: "VersionNegotiation-Client2-" + suffix,
5197 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005198 MaxVersion: runnerVers.version,
5199 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005200 Bugs: ProtocolBugs{
5201 ExpectInitialRecordVersion: clientVers,
5202 },
5203 },
Steven Valdez520e1222017-06-13 12:45:25 -04005204 flags: flags2,
5205 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005206 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005207
5208 testCases = append(testCases, testCase{
5209 protocol: protocol,
5210 testType: serverTest,
5211 name: "VersionNegotiation-Server-" + suffix,
5212 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005213 MaxVersion: runnerVers.version,
5214 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005215 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005216 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005217 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005218 },
5219 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005220 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005221 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005222 testCases = append(testCases, testCase{
5223 protocol: protocol,
5224 testType: serverTest,
5225 name: "VersionNegotiation-Server2-" + suffix,
5226 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005227 MaxVersion: runnerVers.version,
5228 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005229 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005230 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005231 },
5232 },
Steven Valdez520e1222017-06-13 12:45:25 -04005233 flags: flags2,
5234 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005235 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005236 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005237 }
5238 }
David Benjamin95c69562016-06-29 18:15:03 -04005239
Steven Valdezfdd10992016-09-15 16:27:05 -04005240 // Test the version extension at all versions.
5241 for _, vers := range tlsVersions {
5242 protocols := []protocol{tls}
5243 if vers.hasDTLS {
5244 protocols = append(protocols, dtls)
5245 }
5246 for _, protocol := range protocols {
5247 suffix := vers.name
5248 if protocol == dtls {
5249 suffix += "-DTLS"
5250 }
5251
Steven Valdezfdd10992016-09-15 16:27:05 -04005252 testCases = append(testCases, testCase{
5253 protocol: protocol,
5254 testType: serverTest,
5255 name: "VersionNegotiationExtension-" + suffix,
5256 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005257 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005258 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005259 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005260 },
5261 },
5262 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005263 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005264 })
5265 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005266 }
5267
5268 // If all versions are unknown, negotiation fails.
5269 testCases = append(testCases, testCase{
5270 testType: serverTest,
5271 name: "NoSupportedVersions",
5272 config: Config{
5273 Bugs: ProtocolBugs{
5274 SendSupportedVersions: []uint16{0x1111},
5275 },
5276 },
5277 shouldFail: true,
5278 expectedError: ":UNSUPPORTED_PROTOCOL:",
5279 })
5280 testCases = append(testCases, testCase{
5281 protocol: dtls,
5282 testType: serverTest,
5283 name: "NoSupportedVersions-DTLS",
5284 config: Config{
5285 Bugs: ProtocolBugs{
5286 SendSupportedVersions: []uint16{0x1111},
5287 },
5288 },
5289 shouldFail: true,
5290 expectedError: ":UNSUPPORTED_PROTOCOL:",
5291 })
5292
5293 testCases = append(testCases, testCase{
5294 testType: serverTest,
5295 name: "ClientHelloVersionTooHigh",
5296 config: Config{
5297 MaxVersion: VersionTLS13,
5298 Bugs: ProtocolBugs{
5299 SendClientVersion: 0x0304,
5300 OmitSupportedVersions: true,
5301 },
5302 },
5303 expectedVersion: VersionTLS12,
5304 })
5305
5306 testCases = append(testCases, testCase{
5307 testType: serverTest,
5308 name: "ConflictingVersionNegotiation",
5309 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005310 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005311 SendClientVersion: VersionTLS12,
5312 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005313 },
5314 },
David Benjaminad75a662016-09-30 15:42:59 -04005315 // The extension takes precedence over the ClientHello version.
5316 expectedVersion: VersionTLS11,
5317 })
5318
5319 testCases = append(testCases, testCase{
5320 testType: serverTest,
5321 name: "ConflictingVersionNegotiation-2",
5322 config: Config{
5323 Bugs: ProtocolBugs{
5324 SendClientVersion: VersionTLS11,
5325 SendSupportedVersions: []uint16{VersionTLS12},
5326 },
5327 },
5328 // The extension takes precedence over the ClientHello version.
5329 expectedVersion: VersionTLS12,
5330 })
5331
5332 testCases = append(testCases, testCase{
5333 testType: serverTest,
5334 name: "RejectFinalTLS13",
5335 config: Config{
5336 Bugs: ProtocolBugs{
5337 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5338 },
5339 },
5340 // We currently implement a draft TLS 1.3 version. Ensure that
5341 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005342 expectedVersion: VersionTLS12,
5343 })
5344
Steven Valdez038da9b2017-07-10 12:57:25 -04005345 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5346 // the ServerHello.
5347 testCases = append(testCases, testCase{
5348 testType: clientTest,
5349 name: "SupportedVersionSelection-TLS12",
5350 config: Config{
5351 MaxVersion: VersionTLS12,
5352 Bugs: ProtocolBugs{
5353 SendServerSupportedExtensionVersion: VersionTLS12,
5354 },
5355 },
5356 shouldFail: true,
5357 expectedError: ":UNEXPECTED_EXTENSION:",
5358 })
5359
5360 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5361 // supported_versions extension in the ServerHello.
5362 testCases = append(testCases, testCase{
5363 testType: clientTest,
5364 name: "SupportedVersionSelection-TLS13",
5365 config: Config{
5366 MaxVersion: VersionTLS13,
5367 Bugs: ProtocolBugs{
5368 SendServerSupportedExtensionVersion: tls13DraftVersion,
5369 },
5370 },
5371 shouldFail: true,
5372 expectedError: ":UNEXPECTED_EXTENSION:",
5373 })
5374
Brian Smithf85d3232016-10-28 10:34:06 -10005375 // Test that the maximum version is selected regardless of the
5376 // client-sent order.
5377 testCases = append(testCases, testCase{
5378 testType: serverTest,
5379 name: "IgnoreClientVersionOrder",
5380 config: Config{
5381 Bugs: ProtocolBugs{
5382 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5383 },
5384 },
5385 expectedVersion: VersionTLS13,
5386 })
5387
David Benjamin95c69562016-06-29 18:15:03 -04005388 // Test for version tolerance.
5389 testCases = append(testCases, testCase{
5390 testType: serverTest,
5391 name: "MinorVersionTolerance",
5392 config: Config{
5393 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005394 SendClientVersion: 0x03ff,
5395 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005396 },
5397 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005398 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005399 })
5400 testCases = append(testCases, testCase{
5401 testType: serverTest,
5402 name: "MajorVersionTolerance",
5403 config: Config{
5404 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005405 SendClientVersion: 0x0400,
5406 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005407 },
5408 },
David Benjaminad75a662016-09-30 15:42:59 -04005409 // TLS 1.3 must be negotiated with the supported_versions
5410 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005411 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005412 })
David Benjaminad75a662016-09-30 15:42:59 -04005413 testCases = append(testCases, testCase{
5414 testType: serverTest,
5415 name: "VersionTolerance-TLS13",
5416 config: Config{
5417 Bugs: ProtocolBugs{
5418 // Although TLS 1.3 does not use
5419 // ClientHello.version, it still tolerates high
5420 // values there.
5421 SendClientVersion: 0x0400,
5422 },
5423 },
5424 expectedVersion: VersionTLS13,
5425 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005426
David Benjamin95c69562016-06-29 18:15:03 -04005427 testCases = append(testCases, testCase{
5428 protocol: dtls,
5429 testType: serverTest,
5430 name: "MinorVersionTolerance-DTLS",
5431 config: Config{
5432 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005433 SendClientVersion: 0xfe00,
5434 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005435 },
5436 },
5437 expectedVersion: VersionTLS12,
5438 })
5439 testCases = append(testCases, testCase{
5440 protocol: dtls,
5441 testType: serverTest,
5442 name: "MajorVersionTolerance-DTLS",
5443 config: Config{
5444 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005445 SendClientVersion: 0xfdff,
5446 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005447 },
5448 },
5449 expectedVersion: VersionTLS12,
5450 })
5451
5452 // Test that versions below 3.0 are rejected.
5453 testCases = append(testCases, testCase{
5454 testType: serverTest,
5455 name: "VersionTooLow",
5456 config: Config{
5457 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005458 SendClientVersion: 0x0200,
5459 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005460 },
5461 },
5462 shouldFail: true,
5463 expectedError: ":UNSUPPORTED_PROTOCOL:",
5464 })
5465 testCases = append(testCases, testCase{
5466 protocol: dtls,
5467 testType: serverTest,
5468 name: "VersionTooLow-DTLS",
5469 config: Config{
5470 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005471 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005472 },
5473 },
5474 shouldFail: true,
5475 expectedError: ":UNSUPPORTED_PROTOCOL:",
5476 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005477
David Benjamin2dc02042016-09-19 19:57:37 -04005478 testCases = append(testCases, testCase{
5479 name: "ServerBogusVersion",
5480 config: Config{
5481 Bugs: ProtocolBugs{
5482 SendServerHelloVersion: 0x1234,
5483 },
5484 },
5485 shouldFail: true,
5486 expectedError: ":UNSUPPORTED_PROTOCOL:",
5487 })
5488
David Benjamin1f61f0d2016-07-10 12:20:35 -04005489 // Test TLS 1.3's downgrade signal.
5490 testCases = append(testCases, testCase{
5491 name: "Downgrade-TLS12-Client",
5492 config: Config{
5493 Bugs: ProtocolBugs{
5494 NegotiateVersion: VersionTLS12,
5495 },
5496 },
David Benjamin592b5322016-09-30 15:15:01 -04005497 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005498 // TODO(davidben): This test should fail once TLS 1.3 is final
5499 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005500 })
5501 testCases = append(testCases, testCase{
5502 testType: serverTest,
5503 name: "Downgrade-TLS12-Server",
5504 config: Config{
5505 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005506 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005507 },
5508 },
David Benjamin592b5322016-09-30 15:15:01 -04005509 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005510 // TODO(davidben): This test should fail once TLS 1.3 is final
5511 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005512 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005513}
5514
David Benjaminaccb4542014-12-12 23:44:33 -05005515func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005516 for _, protocol := range []protocol{tls, dtls} {
5517 for _, shimVers := range allVersions(protocol) {
5518 // Assemble flags to disable all older versions on the shim.
5519 var flags []string
5520 for _, vers := range allVersions(protocol) {
5521 if vers.version < shimVers.version {
5522 flags = append(flags, vers.excludeFlag)
5523 }
David Benjaminaccb4542014-12-12 23:44:33 -05005524 }
Steven Valdez520e1222017-06-13 12:45:25 -04005525
5526 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5527
5528 if shimVers.tls13Variant != 0 {
5529 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5530 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5531 }
5532
5533 for _, runnerVers := range allVersions(protocol) {
5534 // Different TLS 1.3 variants are incompatible with each other and don't
5535 // produce consistent minimum versions.
5536 //
5537 // TODO(davidben): Fold these tests (the main value is in the
5538 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5539 // on intended shim behavior, not the shim + runner combination.
5540 if shimVers.tls13Variant != runnerVers.tls13Variant {
5541 continue
5542 }
5543
David Benjaminaccb4542014-12-12 23:44:33 -05005544 suffix := shimVers.name + "-" + runnerVers.name
5545 if protocol == dtls {
5546 suffix += "-DTLS"
5547 }
David Benjaminaccb4542014-12-12 23:44:33 -05005548
David Benjaminaccb4542014-12-12 23:44:33 -05005549 var expectedVersion uint16
5550 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005551 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005552 if runnerVers.version >= shimVers.version {
5553 expectedVersion = runnerVers.version
5554 } else {
5555 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005556 expectedError = ":UNSUPPORTED_PROTOCOL:"
5557 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005558 }
5559
5560 testCases = append(testCases, testCase{
5561 protocol: protocol,
5562 testType: clientTest,
5563 name: "MinimumVersion-Client-" + suffix,
5564 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005565 MaxVersion: runnerVers.version,
5566 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005567 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005568 // Ensure the server does not decline to
5569 // select a version (versions extension) or
5570 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005571 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005572 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005573 },
David Benjaminaccb4542014-12-12 23:44:33 -05005574 },
David Benjamin87909c02014-12-13 01:55:01 -05005575 flags: flags,
5576 expectedVersion: expectedVersion,
5577 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005578 expectedError: expectedError,
5579 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005580 })
5581 testCases = append(testCases, testCase{
5582 protocol: protocol,
5583 testType: clientTest,
5584 name: "MinimumVersion-Client2-" + suffix,
5585 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005586 MaxVersion: runnerVers.version,
5587 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005588 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005589 // Ensure the server does not decline to
5590 // select a version (versions extension) or
5591 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005592 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005593 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005594 },
David Benjaminaccb4542014-12-12 23:44:33 -05005595 },
Steven Valdez520e1222017-06-13 12:45:25 -04005596 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005597 expectedVersion: expectedVersion,
5598 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005599 expectedError: expectedError,
5600 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005601 })
5602
5603 testCases = append(testCases, testCase{
5604 protocol: protocol,
5605 testType: serverTest,
5606 name: "MinimumVersion-Server-" + suffix,
5607 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005608 MaxVersion: runnerVers.version,
5609 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005610 },
David Benjamin87909c02014-12-13 01:55:01 -05005611 flags: flags,
5612 expectedVersion: expectedVersion,
5613 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005614 expectedError: expectedError,
5615 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005616 })
5617 testCases = append(testCases, testCase{
5618 protocol: protocol,
5619 testType: serverTest,
5620 name: "MinimumVersion-Server2-" + suffix,
5621 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005622 MaxVersion: runnerVers.version,
5623 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005624 },
Steven Valdez520e1222017-06-13 12:45:25 -04005625 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005626 expectedVersion: expectedVersion,
5627 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005628 expectedError: expectedError,
5629 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005630 })
5631 }
5632 }
5633 }
5634}
5635
David Benjamine78bfde2014-09-06 12:45:15 -04005636func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005637 // TODO(davidben): Extensions, where applicable, all move their server
5638 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5639 // tests for both. Also test interaction with 0-RTT when implemented.
5640
David Benjamin97d17d92016-07-14 16:12:00 -04005641 // Repeat extensions tests all versions except SSL 3.0.
5642 for _, ver := range tlsVersions {
5643 if ver.version == VersionSSL30 {
5644 continue
5645 }
5646
David Benjamin97d17d92016-07-14 16:12:00 -04005647 // Test that duplicate extensions are rejected.
5648 testCases = append(testCases, testCase{
5649 testType: clientTest,
5650 name: "DuplicateExtensionClient-" + ver.name,
5651 config: Config{
5652 MaxVersion: ver.version,
5653 Bugs: ProtocolBugs{
5654 DuplicateExtension: true,
5655 },
David Benjamine78bfde2014-09-06 12:45:15 -04005656 },
David Benjamina5022392017-07-10 17:40:39 -04005657 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005658 shouldFail: true,
5659 expectedLocalError: "remote error: error decoding message",
5660 })
5661 testCases = append(testCases, testCase{
5662 testType: serverTest,
5663 name: "DuplicateExtensionServer-" + ver.name,
5664 config: Config{
5665 MaxVersion: ver.version,
5666 Bugs: ProtocolBugs{
5667 DuplicateExtension: true,
5668 },
David Benjamine78bfde2014-09-06 12:45:15 -04005669 },
David Benjamina5022392017-07-10 17:40:39 -04005670 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005671 shouldFail: true,
5672 expectedLocalError: "remote error: error decoding message",
5673 })
5674
5675 // Test SNI.
5676 testCases = append(testCases, testCase{
5677 testType: clientTest,
5678 name: "ServerNameExtensionClient-" + ver.name,
5679 config: Config{
5680 MaxVersion: ver.version,
5681 Bugs: ProtocolBugs{
5682 ExpectServerName: "example.com",
5683 },
David Benjamine78bfde2014-09-06 12:45:15 -04005684 },
David Benjamina5022392017-07-10 17:40:39 -04005685 tls13Variant: ver.tls13Variant,
5686 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005687 })
5688 testCases = append(testCases, testCase{
5689 testType: clientTest,
5690 name: "ServerNameExtensionClientMismatch-" + ver.name,
5691 config: Config{
5692 MaxVersion: ver.version,
5693 Bugs: ProtocolBugs{
5694 ExpectServerName: "mismatch.com",
5695 },
David Benjamine78bfde2014-09-06 12:45:15 -04005696 },
David Benjamin97d17d92016-07-14 16:12:00 -04005697 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005698 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005699 shouldFail: true,
5700 expectedLocalError: "tls: unexpected server name",
5701 })
5702 testCases = append(testCases, testCase{
5703 testType: clientTest,
5704 name: "ServerNameExtensionClientMissing-" + ver.name,
5705 config: Config{
5706 MaxVersion: ver.version,
5707 Bugs: ProtocolBugs{
5708 ExpectServerName: "missing.com",
5709 },
David Benjamine78bfde2014-09-06 12:45:15 -04005710 },
David Benjamina5022392017-07-10 17:40:39 -04005711 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005712 shouldFail: true,
5713 expectedLocalError: "tls: unexpected server name",
5714 })
5715 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005716 testType: clientTest,
5717 name: "TolerateServerNameAck-" + ver.name,
5718 config: Config{
5719 MaxVersion: ver.version,
5720 Bugs: ProtocolBugs{
5721 SendServerNameAck: true,
5722 },
5723 },
David Benjamina5022392017-07-10 17:40:39 -04005724 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005725 flags: []string{"-host-name", "example.com"},
5726 resumeSession: true,
5727 })
5728 testCases = append(testCases, testCase{
5729 testType: clientTest,
5730 name: "UnsolicitedServerNameAck-" + ver.name,
5731 config: Config{
5732 MaxVersion: ver.version,
5733 Bugs: ProtocolBugs{
5734 SendServerNameAck: true,
5735 },
5736 },
David Benjamina5022392017-07-10 17:40:39 -04005737 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005738 shouldFail: true,
5739 expectedError: ":UNEXPECTED_EXTENSION:",
5740 expectedLocalError: "remote error: unsupported extension",
5741 })
5742 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005743 testType: serverTest,
5744 name: "ServerNameExtensionServer-" + ver.name,
5745 config: Config{
5746 MaxVersion: ver.version,
5747 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005748 },
David Benjamina5022392017-07-10 17:40:39 -04005749 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005750 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005751 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005752 })
5753
5754 // Test ALPN.
5755 testCases = append(testCases, testCase{
5756 testType: clientTest,
5757 name: "ALPNClient-" + ver.name,
5758 config: Config{
5759 MaxVersion: ver.version,
5760 NextProtos: []string{"foo"},
5761 },
5762 flags: []string{
5763 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5764 "-expect-alpn", "foo",
5765 },
David Benjamina5022392017-07-10 17:40:39 -04005766 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005767 expectedNextProto: "foo",
5768 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005769 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005770 })
5771 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005772 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005773 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005774 config: Config{
5775 MaxVersion: ver.version,
5776 Bugs: ProtocolBugs{
5777 SendALPN: "baz",
5778 },
5779 },
5780 flags: []string{
5781 "-advertise-alpn", "\x03foo\x03bar",
5782 },
David Benjamina5022392017-07-10 17:40:39 -04005783 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005784 shouldFail: true,
5785 expectedError: ":INVALID_ALPN_PROTOCOL:",
5786 expectedLocalError: "remote error: illegal parameter",
5787 })
5788 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005789 testType: clientTest,
5790 name: "ALPNClient-AllowUnknown-" + ver.name,
5791 config: Config{
5792 MaxVersion: ver.version,
5793 Bugs: ProtocolBugs{
5794 SendALPN: "baz",
5795 },
5796 },
5797 flags: []string{
5798 "-advertise-alpn", "\x03foo\x03bar",
5799 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005800 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005801 },
David Benjamina5022392017-07-10 17:40:39 -04005802 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005803 })
5804 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005805 testType: serverTest,
5806 name: "ALPNServer-" + ver.name,
5807 config: Config{
5808 MaxVersion: ver.version,
5809 NextProtos: []string{"foo", "bar", "baz"},
5810 },
5811 flags: []string{
5812 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5813 "-select-alpn", "foo",
5814 },
David Benjamina5022392017-07-10 17:40:39 -04005815 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005816 expectedNextProto: "foo",
5817 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005818 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005819 })
5820 testCases = append(testCases, testCase{
5821 testType: serverTest,
5822 name: "ALPNServer-Decline-" + ver.name,
5823 config: Config{
5824 MaxVersion: ver.version,
5825 NextProtos: []string{"foo", "bar", "baz"},
5826 },
5827 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005828 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005829 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005830 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005831 })
5832
David Benjamin25fe85b2016-08-09 20:00:32 -04005833 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5834 // called once.
5835 testCases = append(testCases, testCase{
5836 testType: serverTest,
5837 name: "ALPNServer-Async-" + ver.name,
5838 config: Config{
5839 MaxVersion: ver.version,
5840 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005841 // Prior to TLS 1.3, exercise the asynchronous session callback.
5842 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005843 },
5844 flags: []string{
5845 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5846 "-select-alpn", "foo",
5847 "-async",
5848 },
David Benjamina5022392017-07-10 17:40:39 -04005849 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005850 expectedNextProto: "foo",
5851 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005852 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005853 })
5854
David Benjamin97d17d92016-07-14 16:12:00 -04005855 var emptyString string
5856 testCases = append(testCases, testCase{
5857 testType: clientTest,
5858 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5859 config: Config{
5860 MaxVersion: ver.version,
5861 NextProtos: []string{""},
5862 Bugs: ProtocolBugs{
5863 // A server returning an empty ALPN protocol
5864 // should be rejected.
5865 ALPNProtocol: &emptyString,
5866 },
5867 },
5868 flags: []string{
5869 "-advertise-alpn", "\x03foo",
5870 },
David Benjamina5022392017-07-10 17:40:39 -04005871 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005872 shouldFail: true,
5873 expectedError: ":PARSE_TLSEXT:",
5874 })
5875 testCases = append(testCases, testCase{
5876 testType: serverTest,
5877 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5878 config: Config{
5879 MaxVersion: ver.version,
5880 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005881 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005882 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005883 },
David Benjamin97d17d92016-07-14 16:12:00 -04005884 flags: []string{
5885 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005886 },
David Benjamina5022392017-07-10 17:40:39 -04005887 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005888 shouldFail: true,
5889 expectedError: ":PARSE_TLSEXT:",
5890 })
5891
5892 // Test NPN and the interaction with ALPN.
5893 if ver.version < VersionTLS13 {
5894 // Test that the server prefers ALPN over NPN.
5895 testCases = append(testCases, testCase{
5896 testType: serverTest,
5897 name: "ALPNServer-Preferred-" + ver.name,
5898 config: Config{
5899 MaxVersion: ver.version,
5900 NextProtos: []string{"foo", "bar", "baz"},
5901 },
5902 flags: []string{
5903 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5904 "-select-alpn", "foo",
5905 "-advertise-npn", "\x03foo\x03bar\x03baz",
5906 },
David Benjamina5022392017-07-10 17:40:39 -04005907 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005908 expectedNextProto: "foo",
5909 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005910 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005911 })
5912 testCases = append(testCases, testCase{
5913 testType: serverTest,
5914 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5915 config: Config{
5916 MaxVersion: ver.version,
5917 NextProtos: []string{"foo", "bar", "baz"},
5918 Bugs: ProtocolBugs{
5919 SwapNPNAndALPN: true,
5920 },
5921 },
5922 flags: []string{
5923 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5924 "-select-alpn", "foo",
5925 "-advertise-npn", "\x03foo\x03bar\x03baz",
5926 },
David Benjamina5022392017-07-10 17:40:39 -04005927 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005928 expectedNextProto: "foo",
5929 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005930 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005931 })
5932
5933 // Test that negotiating both NPN and ALPN is forbidden.
5934 testCases = append(testCases, testCase{
5935 name: "NegotiateALPNAndNPN-" + ver.name,
5936 config: Config{
5937 MaxVersion: ver.version,
5938 NextProtos: []string{"foo", "bar", "baz"},
5939 Bugs: ProtocolBugs{
5940 NegotiateALPNAndNPN: true,
5941 },
5942 },
5943 flags: []string{
5944 "-advertise-alpn", "\x03foo",
5945 "-select-next-proto", "foo",
5946 },
David Benjamina5022392017-07-10 17:40:39 -04005947 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005948 shouldFail: true,
5949 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5950 })
5951 testCases = append(testCases, testCase{
5952 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5953 config: Config{
5954 MaxVersion: ver.version,
5955 NextProtos: []string{"foo", "bar", "baz"},
5956 Bugs: ProtocolBugs{
5957 NegotiateALPNAndNPN: true,
5958 SwapNPNAndALPN: true,
5959 },
5960 },
5961 flags: []string{
5962 "-advertise-alpn", "\x03foo",
5963 "-select-next-proto", "foo",
5964 },
David Benjamina5022392017-07-10 17:40:39 -04005965 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005966 shouldFail: true,
5967 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5968 })
David Benjamin97d17d92016-07-14 16:12:00 -04005969 }
5970
5971 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005972
5973 // Resume with a corrupt ticket.
5974 testCases = append(testCases, testCase{
5975 testType: serverTest,
5976 name: "CorruptTicket-" + ver.name,
5977 config: Config{
5978 MaxVersion: ver.version,
5979 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005980 FilterTicket: func(in []byte) ([]byte, error) {
5981 in[len(in)-1] ^= 1
5982 return in, nil
5983 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005984 },
5985 },
David Benjamina5022392017-07-10 17:40:39 -04005986 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005987 resumeSession: true,
5988 expectResumeRejected: true,
5989 })
5990 // Test the ticket callback, with and without renewal.
5991 testCases = append(testCases, testCase{
5992 testType: serverTest,
5993 name: "TicketCallback-" + ver.name,
5994 config: Config{
5995 MaxVersion: ver.version,
5996 },
David Benjamina5022392017-07-10 17:40:39 -04005997 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005998 resumeSession: true,
5999 flags: []string{"-use-ticket-callback"},
6000 })
6001 testCases = append(testCases, testCase{
6002 testType: serverTest,
6003 name: "TicketCallback-Renew-" + ver.name,
6004 config: Config{
6005 MaxVersion: ver.version,
6006 Bugs: ProtocolBugs{
6007 ExpectNewTicket: true,
6008 },
6009 },
David Benjamina5022392017-07-10 17:40:39 -04006010 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006011 flags: []string{"-use-ticket-callback", "-renew-ticket"},
6012 resumeSession: true,
6013 })
6014
6015 // Test that the ticket callback is only called once when everything before
6016 // it in the ClientHello is asynchronous. This corrupts the ticket so
6017 // certificate selection callbacks run.
6018 testCases = append(testCases, testCase{
6019 testType: serverTest,
6020 name: "TicketCallback-SingleCall-" + ver.name,
6021 config: Config{
6022 MaxVersion: ver.version,
6023 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04006024 FilterTicket: func(in []byte) ([]byte, error) {
6025 in[len(in)-1] ^= 1
6026 return in, nil
6027 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04006028 },
6029 },
David Benjamina5022392017-07-10 17:40:39 -04006030 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006031 resumeSession: true,
6032 expectResumeRejected: true,
6033 flags: []string{
6034 "-use-ticket-callback",
6035 "-async",
6036 },
6037 })
6038
David Benjamind4c349b2017-02-09 14:07:17 -05006039 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04006040 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04006041 testCases = append(testCases, testCase{
6042 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05006043 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04006044 config: Config{
6045 MaxVersion: ver.version,
6046 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05006047 EmptyTicketSessionID: true,
6048 },
6049 },
6050 resumeSession: true,
6051 })
6052 testCases = append(testCases, testCase{
6053 testType: serverTest,
6054 name: "TicketSessionIDLength-16-" + ver.name,
6055 config: Config{
6056 MaxVersion: ver.version,
6057 Bugs: ProtocolBugs{
6058 TicketSessionIDLength: 16,
6059 },
6060 },
6061 resumeSession: true,
6062 })
6063 testCases = append(testCases, testCase{
6064 testType: serverTest,
6065 name: "TicketSessionIDLength-32-" + ver.name,
6066 config: Config{
6067 MaxVersion: ver.version,
6068 Bugs: ProtocolBugs{
6069 TicketSessionIDLength: 32,
6070 },
6071 },
6072 resumeSession: true,
6073 })
6074 testCases = append(testCases, testCase{
6075 testType: serverTest,
6076 name: "TicketSessionIDLength-33-" + ver.name,
6077 config: Config{
6078 MaxVersion: ver.version,
6079 Bugs: ProtocolBugs{
6080 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04006081 },
6082 },
6083 resumeSession: true,
6084 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05006085 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04006086 expectedError: ":DECODE_ERROR:",
6087 })
6088 }
6089
6090 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
6091 // are ignored.
6092 if ver.hasDTLS {
6093 testCases = append(testCases, testCase{
6094 protocol: dtls,
6095 name: "SRTP-Client-" + ver.name,
6096 config: Config{
6097 MaxVersion: ver.version,
6098 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6099 },
6100 flags: []string{
6101 "-srtp-profiles",
6102 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6103 },
6104 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6105 })
6106 testCases = append(testCases, testCase{
6107 protocol: dtls,
6108 testType: serverTest,
6109 name: "SRTP-Server-" + ver.name,
6110 config: Config{
6111 MaxVersion: ver.version,
6112 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
6113 },
6114 flags: []string{
6115 "-srtp-profiles",
6116 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6117 },
6118 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6119 })
6120 // Test that the MKI is ignored.
6121 testCases = append(testCases, testCase{
6122 protocol: dtls,
6123 testType: serverTest,
6124 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6125 config: Config{
6126 MaxVersion: ver.version,
6127 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6128 Bugs: ProtocolBugs{
6129 SRTPMasterKeyIdentifer: "bogus",
6130 },
6131 },
6132 flags: []string{
6133 "-srtp-profiles",
6134 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6135 },
6136 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6137 })
6138 // Test that SRTP isn't negotiated on the server if there were
6139 // no matching profiles.
6140 testCases = append(testCases, testCase{
6141 protocol: dtls,
6142 testType: serverTest,
6143 name: "SRTP-Server-NoMatch-" + ver.name,
6144 config: Config{
6145 MaxVersion: ver.version,
6146 SRTPProtectionProfiles: []uint16{100, 101, 102},
6147 },
6148 flags: []string{
6149 "-srtp-profiles",
6150 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6151 },
6152 expectedSRTPProtectionProfile: 0,
6153 })
6154 // Test that the server returning an invalid SRTP profile is
6155 // flagged as an error by the client.
6156 testCases = append(testCases, testCase{
6157 protocol: dtls,
6158 name: "SRTP-Client-NoMatch-" + ver.name,
6159 config: Config{
6160 MaxVersion: ver.version,
6161 Bugs: ProtocolBugs{
6162 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6163 },
6164 },
6165 flags: []string{
6166 "-srtp-profiles",
6167 "SRTP_AES128_CM_SHA1_80",
6168 },
6169 shouldFail: true,
6170 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6171 })
6172 }
6173
6174 // Test SCT list.
6175 testCases = append(testCases, testCase{
6176 name: "SignedCertificateTimestampList-Client-" + ver.name,
6177 testType: clientTest,
6178 config: Config{
6179 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006180 },
David Benjamin97d17d92016-07-14 16:12:00 -04006181 flags: []string{
6182 "-enable-signed-cert-timestamps",
6183 "-expect-signed-cert-timestamps",
6184 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006185 },
David Benjamina5022392017-07-10 17:40:39 -04006186 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006187 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006188 })
David Benjamindaa88502016-10-04 16:32:16 -04006189
Adam Langleycfa08c32016-11-17 13:21:27 -08006190 var differentSCTList []byte
6191 differentSCTList = append(differentSCTList, testSCTList...)
6192 differentSCTList[len(differentSCTList)-1] ^= 1
6193
David Benjamindaa88502016-10-04 16:32:16 -04006194 // The SCT extension did not specify that it must only be sent on resumption as it
6195 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006196 testCases = append(testCases, testCase{
6197 name: "SendSCTListOnResume-" + ver.name,
6198 config: Config{
6199 MaxVersion: ver.version,
6200 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006201 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006202 },
David Benjamind98452d2015-06-16 14:16:23 -04006203 },
David Benjamin97d17d92016-07-14 16:12:00 -04006204 flags: []string{
6205 "-enable-signed-cert-timestamps",
6206 "-expect-signed-cert-timestamps",
6207 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006208 },
David Benjamina5022392017-07-10 17:40:39 -04006209 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006210 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006211 })
David Benjamindaa88502016-10-04 16:32:16 -04006212
David Benjamin97d17d92016-07-14 16:12:00 -04006213 testCases = append(testCases, testCase{
6214 name: "SignedCertificateTimestampList-Server-" + ver.name,
6215 testType: serverTest,
6216 config: Config{
6217 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006218 },
David Benjamin97d17d92016-07-14 16:12:00 -04006219 flags: []string{
6220 "-signed-cert-timestamps",
6221 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006222 },
David Benjamina5022392017-07-10 17:40:39 -04006223 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006224 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006225 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006226 })
David Benjamin53210cb2016-11-16 09:01:48 +09006227
Adam Langleycfa08c32016-11-17 13:21:27 -08006228 emptySCTListCert := *testCerts[0].cert
6229 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6230
6231 // Test empty SCT list.
6232 testCases = append(testCases, testCase{
6233 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6234 testType: clientTest,
6235 config: Config{
6236 MaxVersion: ver.version,
6237 Certificates: []Certificate{emptySCTListCert},
6238 },
6239 flags: []string{
6240 "-enable-signed-cert-timestamps",
6241 },
David Benjamina5022392017-07-10 17:40:39 -04006242 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006243 shouldFail: true,
6244 expectedError: ":ERROR_PARSING_EXTENSION:",
6245 })
6246
6247 emptySCTCert := *testCerts[0].cert
6248 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6249
6250 // Test empty SCT in non-empty list.
6251 testCases = append(testCases, testCase{
6252 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6253 testType: clientTest,
6254 config: Config{
6255 MaxVersion: ver.version,
6256 Certificates: []Certificate{emptySCTCert},
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
David Benjamin53210cb2016-11-16 09:01:48 +09006266 // Test that certificate-related extensions are not sent unsolicited.
6267 testCases = append(testCases, testCase{
6268 testType: serverTest,
6269 name: "UnsolicitedCertificateExtensions-" + ver.name,
6270 config: Config{
6271 MaxVersion: ver.version,
6272 Bugs: ProtocolBugs{
6273 NoOCSPStapling: true,
6274 NoSignedCertificateTimestamps: true,
6275 },
6276 },
David Benjamina5022392017-07-10 17:40:39 -04006277 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006278 flags: []string{
6279 "-ocsp-response",
6280 base64.StdEncoding.EncodeToString(testOCSPResponse),
6281 "-signed-cert-timestamps",
6282 base64.StdEncoding.EncodeToString(testSCTList),
6283 },
6284 })
David Benjamin97d17d92016-07-14 16:12:00 -04006285 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006286
Paul Lietar4fac72e2015-09-09 13:44:55 +01006287 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006288 testType: clientTest,
6289 name: "ClientHelloPadding",
6290 config: Config{
6291 Bugs: ProtocolBugs{
6292 RequireClientHelloSize: 512,
6293 },
6294 },
6295 // This hostname just needs to be long enough to push the
6296 // ClientHello into F5's danger zone between 256 and 511 bytes
6297 // long.
6298 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6299 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006300
6301 // Extensions should not function in SSL 3.0.
6302 testCases = append(testCases, testCase{
6303 testType: serverTest,
6304 name: "SSLv3Extensions-NoALPN",
6305 config: Config{
6306 MaxVersion: VersionSSL30,
6307 NextProtos: []string{"foo", "bar", "baz"},
6308 },
6309 flags: []string{
6310 "-select-alpn", "foo",
6311 },
6312 expectNoNextProto: true,
6313 })
6314
6315 // Test session tickets separately as they follow a different codepath.
6316 testCases = append(testCases, testCase{
6317 testType: serverTest,
6318 name: "SSLv3Extensions-NoTickets",
6319 config: Config{
6320 MaxVersion: VersionSSL30,
6321 Bugs: ProtocolBugs{
6322 // Historically, session tickets in SSL 3.0
6323 // failed in different ways depending on whether
6324 // the client supported renegotiation_info.
6325 NoRenegotiationInfo: true,
6326 },
6327 },
6328 resumeSession: true,
6329 })
6330 testCases = append(testCases, testCase{
6331 testType: serverTest,
6332 name: "SSLv3Extensions-NoTickets2",
6333 config: Config{
6334 MaxVersion: VersionSSL30,
6335 },
6336 resumeSession: true,
6337 })
6338
6339 // But SSL 3.0 does send and process renegotiation_info.
6340 testCases = append(testCases, testCase{
6341 testType: serverTest,
6342 name: "SSLv3Extensions-RenegotiationInfo",
6343 config: Config{
6344 MaxVersion: VersionSSL30,
6345 Bugs: ProtocolBugs{
6346 RequireRenegotiationInfo: true,
6347 },
6348 },
David Benjamind2610042017-01-03 10:49:28 -05006349 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006350 })
6351 testCases = append(testCases, testCase{
6352 testType: serverTest,
6353 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6354 config: Config{
6355 MaxVersion: VersionSSL30,
6356 Bugs: ProtocolBugs{
6357 NoRenegotiationInfo: true,
6358 SendRenegotiationSCSV: true,
6359 RequireRenegotiationInfo: true,
6360 },
6361 },
David Benjamind2610042017-01-03 10:49:28 -05006362 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006363 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006364
6365 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6366 // in ServerHello.
6367 testCases = append(testCases, testCase{
6368 name: "NPN-Forbidden-TLS13",
6369 config: Config{
6370 MaxVersion: VersionTLS13,
6371 NextProtos: []string{"foo"},
6372 Bugs: ProtocolBugs{
6373 NegotiateNPNAtAllVersions: true,
6374 },
6375 },
6376 flags: []string{"-select-next-proto", "foo"},
6377 shouldFail: true,
6378 expectedError: ":ERROR_PARSING_EXTENSION:",
6379 })
6380 testCases = append(testCases, testCase{
6381 name: "EMS-Forbidden-TLS13",
6382 config: Config{
6383 MaxVersion: VersionTLS13,
6384 Bugs: ProtocolBugs{
6385 NegotiateEMSAtAllVersions: true,
6386 },
6387 },
6388 shouldFail: true,
6389 expectedError: ":ERROR_PARSING_EXTENSION:",
6390 })
6391 testCases = append(testCases, testCase{
6392 name: "RenegotiationInfo-Forbidden-TLS13",
6393 config: Config{
6394 MaxVersion: VersionTLS13,
6395 Bugs: ProtocolBugs{
6396 NegotiateRenegotiationInfoAtAllVersions: true,
6397 },
6398 },
6399 shouldFail: true,
6400 expectedError: ":ERROR_PARSING_EXTENSION:",
6401 })
6402 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006403 name: "Ticket-Forbidden-TLS13",
6404 config: Config{
6405 MaxVersion: VersionTLS12,
6406 },
6407 resumeConfig: &Config{
6408 MaxVersion: VersionTLS13,
6409 Bugs: ProtocolBugs{
6410 AdvertiseTicketExtension: true,
6411 },
6412 },
6413 resumeSession: true,
6414 shouldFail: true,
6415 expectedError: ":ERROR_PARSING_EXTENSION:",
6416 })
6417
6418 // Test that illegal extensions in TLS 1.3 are declined by the server if
6419 // offered in ClientHello. The runner's server will fail if this occurs,
6420 // so we exercise the offering path. (EMS and Renegotiation Info are
6421 // implicit in every test.)
6422 testCases = append(testCases, testCase{
6423 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006424 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006425 config: Config{
6426 MaxVersion: VersionTLS13,
6427 NextProtos: []string{"bar"},
6428 },
6429 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6430 })
David Benjamin196df5b2016-09-21 16:23:27 -04006431
David Benjamindaa88502016-10-04 16:32:16 -04006432 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6433 // tolerated.
6434 testCases = append(testCases, testCase{
6435 name: "SendOCSPResponseOnResume-TLS12",
6436 config: Config{
6437 MaxVersion: VersionTLS12,
6438 Bugs: ProtocolBugs{
6439 SendOCSPResponseOnResume: []byte("bogus"),
6440 },
6441 },
6442 flags: []string{
6443 "-enable-ocsp-stapling",
6444 "-expect-ocsp-response",
6445 base64.StdEncoding.EncodeToString(testOCSPResponse),
6446 },
6447 resumeSession: true,
6448 })
6449
David Benjamindaa88502016-10-04 16:32:16 -04006450 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006451 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006452 config: Config{
6453 MaxVersion: VersionTLS13,
6454 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006455 SendExtensionOnCertificate: testOCSPExtension,
6456 },
6457 },
6458 shouldFail: true,
6459 expectedError: ":UNEXPECTED_EXTENSION:",
6460 })
6461
6462 testCases = append(testCases, testCase{
6463 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6464 config: Config{
6465 MaxVersion: VersionTLS13,
6466 Bugs: ProtocolBugs{
6467 SendExtensionOnCertificate: testSCTExtension,
6468 },
6469 },
6470 shouldFail: true,
6471 expectedError: ":UNEXPECTED_EXTENSION:",
6472 })
6473
6474 // Test that extensions on client certificates are never accepted.
6475 testCases = append(testCases, testCase{
6476 name: "SendExtensionOnClientCertificate-TLS13",
6477 testType: serverTest,
6478 config: Config{
6479 MaxVersion: VersionTLS13,
6480 Certificates: []Certificate{rsaCertificate},
6481 Bugs: ProtocolBugs{
6482 SendExtensionOnCertificate: testOCSPExtension,
6483 },
6484 },
6485 flags: []string{
6486 "-enable-ocsp-stapling",
6487 "-require-any-client-certificate",
6488 },
6489 shouldFail: true,
6490 expectedError: ":UNEXPECTED_EXTENSION:",
6491 })
6492
6493 testCases = append(testCases, testCase{
6494 name: "SendUnknownExtensionOnCertificate-TLS13",
6495 config: Config{
6496 MaxVersion: VersionTLS13,
6497 Bugs: ProtocolBugs{
6498 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6499 },
6500 },
6501 shouldFail: true,
6502 expectedError: ":UNEXPECTED_EXTENSION:",
6503 })
6504
6505 // Test that extensions on intermediates are allowed but ignored.
6506 testCases = append(testCases, testCase{
6507 name: "IgnoreExtensionsOnIntermediates-TLS13",
6508 config: Config{
6509 MaxVersion: VersionTLS13,
6510 Certificates: []Certificate{rsaChainCertificate},
6511 Bugs: ProtocolBugs{
6512 // Send different values on the intermediate. This tests
6513 // the intermediate's extensions do not override the
6514 // leaf's.
David Benjamin5c4271f2017-08-23 22:09:41 -07006515 SendOCSPOnIntermediates: testOCSPResponse2,
6516 SendSCTOnIntermediates: testSCTList2,
David Benjamindaa88502016-10-04 16:32:16 -04006517 },
6518 },
6519 flags: []string{
6520 "-enable-ocsp-stapling",
6521 "-expect-ocsp-response",
6522 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006523 "-enable-signed-cert-timestamps",
6524 "-expect-signed-cert-timestamps",
6525 base64.StdEncoding.EncodeToString(testSCTList),
6526 },
6527 resumeSession: true,
6528 })
6529
6530 // Test that extensions are not sent on intermediates when configured
6531 // only for a leaf.
6532 testCases = append(testCases, testCase{
6533 testType: serverTest,
6534 name: "SendNoExtensionsOnIntermediate-TLS13",
6535 config: Config{
6536 MaxVersion: VersionTLS13,
6537 Bugs: ProtocolBugs{
6538 ExpectNoExtensionsOnIntermediate: true,
6539 },
6540 },
6541 flags: []string{
6542 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6543 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6544 "-ocsp-response",
6545 base64.StdEncoding.EncodeToString(testOCSPResponse),
6546 "-signed-cert-timestamps",
6547 base64.StdEncoding.EncodeToString(testSCTList),
6548 },
6549 })
6550
6551 // Test that extensions are not sent on client certificates.
6552 testCases = append(testCases, testCase{
6553 name: "SendNoClientCertificateExtensions-TLS13",
6554 config: Config{
6555 MaxVersion: VersionTLS13,
6556 ClientAuth: RequireAnyClientCert,
6557 },
6558 flags: []string{
6559 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6560 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6561 "-ocsp-response",
6562 base64.StdEncoding.EncodeToString(testOCSPResponse),
6563 "-signed-cert-timestamps",
6564 base64.StdEncoding.EncodeToString(testSCTList),
6565 },
6566 })
6567
6568 testCases = append(testCases, testCase{
6569 name: "SendDuplicateExtensionsOnCerts-TLS13",
6570 config: Config{
6571 MaxVersion: VersionTLS13,
6572 Bugs: ProtocolBugs{
6573 SendDuplicateCertExtensions: true,
6574 },
6575 },
6576 flags: []string{
6577 "-enable-ocsp-stapling",
6578 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006579 },
6580 resumeSession: true,
6581 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006582 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006583 })
Adam Langley9b885c52016-11-18 14:21:03 -08006584
6585 testCases = append(testCases, testCase{
6586 name: "SignedCertificateTimestampListInvalid-Server",
6587 testType: serverTest,
6588 flags: []string{
6589 "-signed-cert-timestamps",
6590 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6591 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006592 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006593 expectedError: ":INVALID_SCT_LIST:",
6594 })
David Benjamine78bfde2014-09-06 12:45:15 -04006595}
6596
David Benjamin01fe8202014-09-24 15:21:44 -04006597func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006598 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006599 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006600 // SSL 3.0 does not have tickets and TLS 1.3 does not
6601 // have session IDs, so skip their cross-resumption
6602 // tests.
6603 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6604 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6605 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006606 }
6607
David Benjamin8b8c0062014-11-23 02:47:52 -05006608 protocols := []protocol{tls}
6609 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6610 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006611 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006612 for _, protocol := range protocols {
6613 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6614 if protocol == dtls {
6615 suffix += "-DTLS"
6616 }
6617
Steven Valdez520e1222017-06-13 12:45:25 -04006618 // We can't resume across TLS 1.3 variants and error out earlier in the
6619 // session resumption.
6620 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6621 continue
6622 }
6623
David Benjaminece3de92015-03-16 18:02:20 -04006624 if sessionVers.version == resumeVers.version {
6625 testCases = append(testCases, testCase{
6626 protocol: protocol,
6627 name: "Resume-Client" + suffix,
6628 resumeSession: true,
6629 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006630 MaxVersion: sessionVers.version,
6631 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006632 Bugs: ProtocolBugs{
6633 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6634 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6635 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006636 },
David Benjaminece3de92015-03-16 18:02:20 -04006637 expectedVersion: sessionVers.version,
6638 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006639 flags: []string{
6640 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6641 },
David Benjaminece3de92015-03-16 18:02:20 -04006642 })
6643 } else {
David Benjamin405da482016-08-08 17:25:07 -04006644 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6645
6646 // Offering a TLS 1.3 session sends an empty session ID, so
6647 // there is no way to convince a non-lookahead client the
6648 // session was resumed. It will appear to the client that a
6649 // stray ChangeCipherSpec was sent.
6650 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6651 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006652 }
6653
David Benjaminece3de92015-03-16 18:02:20 -04006654 testCases = append(testCases, testCase{
6655 protocol: protocol,
6656 name: "Resume-Client-Mismatch" + suffix,
6657 resumeSession: true,
6658 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006659 MaxVersion: sessionVers.version,
6660 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006661 },
David Benjaminece3de92015-03-16 18:02:20 -04006662 expectedVersion: sessionVers.version,
6663 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006664 MaxVersion: resumeVers.version,
6665 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006666 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006667 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006668 },
6669 },
6670 expectedResumeVersion: resumeVers.version,
6671 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006672 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006673 flags: []string{
6674 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6675 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6676 },
David Benjaminece3de92015-03-16 18:02:20 -04006677 })
6678 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006679
6680 testCases = append(testCases, testCase{
6681 protocol: protocol,
6682 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006683 resumeSession: true,
6684 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006685 MaxVersion: sessionVers.version,
6686 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006687 },
6688 expectedVersion: sessionVers.version,
6689 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006690 MaxVersion: resumeVers.version,
6691 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006692 },
6693 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006694 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006695 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006696 flags: []string{
6697 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6698 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6699 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006700 })
6701
David Benjamin8b8c0062014-11-23 02:47:52 -05006702 testCases = append(testCases, testCase{
6703 protocol: protocol,
6704 testType: serverTest,
6705 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006706 resumeSession: true,
6707 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006708 MaxVersion: sessionVers.version,
6709 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006710 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006711 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006712 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006713 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006714 MaxVersion: resumeVers.version,
6715 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006716 Bugs: ProtocolBugs{
6717 SendBothTickets: true,
6718 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006719 },
6720 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006721 flags: []string{
6722 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6723 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6724 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006725 })
6726 }
David Benjamin01fe8202014-09-24 15:21:44 -04006727 }
6728 }
David Benjaminece3de92015-03-16 18:02:20 -04006729
David Benjamin4199b0d2016-11-01 13:58:25 -04006730 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006731 testCases = append(testCases, testCase{
6732 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006733 name: "ShimTicketRewritable",
6734 resumeSession: true,
6735 config: Config{
6736 MaxVersion: VersionTLS12,
6737 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6738 Bugs: ProtocolBugs{
6739 FilterTicket: func(in []byte) ([]byte, error) {
6740 in, err := SetShimTicketVersion(in, VersionTLS12)
6741 if err != nil {
6742 return nil, err
6743 }
6744 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6745 },
6746 },
6747 },
6748 flags: []string{
6749 "-ticket-key",
6750 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6751 },
6752 })
6753
6754 // Resumptions are declined if the version does not match.
6755 testCases = append(testCases, testCase{
6756 testType: serverTest,
6757 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006758 resumeSession: true,
6759 config: Config{
6760 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006761 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006762 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006763 FilterTicket: func(in []byte) ([]byte, error) {
6764 return SetShimTicketVersion(in, VersionTLS13)
6765 },
6766 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006767 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006768 flags: []string{
6769 "-ticket-key",
6770 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6771 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006772 expectResumeRejected: true,
6773 })
6774
6775 testCases = append(testCases, testCase{
6776 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006777 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006778 resumeSession: true,
6779 config: Config{
6780 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006781 Bugs: ProtocolBugs{
6782 FilterTicket: func(in []byte) ([]byte, error) {
6783 return SetShimTicketVersion(in, VersionTLS12)
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
David Benjamin4199b0d2016-11-01 13:58:25 -04006794 // Resumptions are declined if the cipher is invalid or disabled.
6795 testCases = append(testCases, testCase{
6796 testType: serverTest,
6797 name: "Resume-Server-DeclineBadCipher",
6798 resumeSession: true,
6799 config: Config{
6800 MaxVersion: VersionTLS12,
6801 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006802 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006803 FilterTicket: func(in []byte) ([]byte, error) {
6804 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6805 },
6806 },
6807 },
6808 flags: []string{
6809 "-ticket-key",
6810 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6811 },
6812 expectResumeRejected: true,
6813 })
6814
6815 testCases = append(testCases, testCase{
6816 testType: serverTest,
6817 name: "Resume-Server-DeclineBadCipher-2",
6818 resumeSession: true,
6819 config: Config{
6820 MaxVersion: VersionTLS12,
6821 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006822 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006823 FilterTicket: func(in []byte) ([]byte, error) {
6824 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6825 },
6826 },
6827 },
6828 flags: []string{
6829 "-cipher", "AES128",
6830 "-ticket-key",
6831 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6832 },
6833 expectResumeRejected: true,
6834 })
6835
David Benjaminf01f42a2016-11-16 19:05:33 +09006836 // Sessions are not resumed if they do not use the preferred cipher.
6837 testCases = append(testCases, testCase{
6838 testType: serverTest,
6839 name: "Resume-Server-CipherNotPreferred",
6840 resumeSession: true,
6841 config: Config{
6842 MaxVersion: VersionTLS12,
6843 Bugs: ProtocolBugs{
6844 ExpectNewTicket: true,
6845 FilterTicket: func(in []byte) ([]byte, error) {
6846 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6847 },
6848 },
6849 },
6850 flags: []string{
6851 "-ticket-key",
6852 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6853 },
6854 shouldFail: false,
6855 expectResumeRejected: true,
6856 })
6857
6858 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6859 // PRF hashes match, but BoringSSL will always decline such resumptions.
6860 testCases = append(testCases, testCase{
6861 testType: serverTest,
6862 name: "Resume-Server-CipherNotPreferred-TLS13",
6863 resumeSession: true,
6864 config: Config{
6865 MaxVersion: VersionTLS13,
6866 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6867 Bugs: ProtocolBugs{
6868 FilterTicket: func(in []byte) ([]byte, error) {
6869 // If the client (runner) offers ChaCha20-Poly1305 first, the
6870 // server (shim) always prefers it. Switch it to AES-GCM.
6871 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6872 },
6873 },
6874 },
6875 flags: []string{
6876 "-ticket-key",
6877 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6878 },
6879 shouldFail: false,
6880 expectResumeRejected: true,
6881 })
6882
6883 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006884 testCases = append(testCases, testCase{
6885 testType: serverTest,
6886 name: "Resume-Server-DeclineBadCipher-TLS13",
6887 resumeSession: true,
6888 config: Config{
6889 MaxVersion: VersionTLS13,
6890 Bugs: ProtocolBugs{
6891 FilterTicket: func(in []byte) ([]byte, error) {
6892 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6893 },
6894 },
6895 },
6896 flags: []string{
6897 "-ticket-key",
6898 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6899 },
6900 expectResumeRejected: true,
6901 })
6902
David Benjaminf01f42a2016-11-16 19:05:33 +09006903 // If the client does not offer the cipher from the session, decline to
6904 // resume. Clients are forbidden from doing this, but BoringSSL selects
6905 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006906 testCases = append(testCases, testCase{
6907 testType: serverTest,
6908 name: "Resume-Server-UnofferedCipher",
6909 resumeSession: true,
6910 config: Config{
6911 MaxVersion: VersionTLS12,
6912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6913 },
6914 resumeConfig: &Config{
6915 MaxVersion: VersionTLS12,
6916 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6917 Bugs: ProtocolBugs{
6918 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6919 },
6920 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006921 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006922 })
6923
David Benjaminf01f42a2016-11-16 19:05:33 +09006924 // In TLS 1.3, clients may advertise a cipher list which does not
6925 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006926 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6927 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006928 testCases = append(testCases, testCase{
6929 testType: serverTest,
6930 name: "Resume-Server-UnofferedCipher-TLS13",
6931 resumeSession: true,
6932 config: Config{
6933 MaxVersion: VersionTLS13,
6934 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6935 },
6936 resumeConfig: &Config{
6937 MaxVersion: VersionTLS13,
6938 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6939 Bugs: ProtocolBugs{
6940 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6941 },
6942 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006943 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006944 })
6945
David Benjamin4199b0d2016-11-01 13:58:25 -04006946 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006947 testCases = append(testCases, testCase{
6948 name: "Resume-Client-CipherMismatch",
6949 resumeSession: true,
6950 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006951 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006952 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6953 },
6954 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006955 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006956 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6957 Bugs: ProtocolBugs{
6958 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6959 },
6960 },
6961 shouldFail: true,
6962 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6963 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006964
David Benjamine1cc35e2016-11-16 16:25:58 +09006965 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6966 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006967 testCases = append(testCases, testCase{
6968 name: "Resume-Client-CipherMismatch-TLS13",
6969 resumeSession: true,
6970 config: Config{
6971 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006972 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006973 },
6974 resumeConfig: &Config{
6975 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006976 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6977 },
6978 })
6979
6980 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6981 testCases = append(testCases, testCase{
6982 name: "Resume-Client-PRFMismatch-TLS13",
6983 resumeSession: true,
6984 config: Config{
6985 MaxVersion: VersionTLS13,
6986 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6987 },
6988 resumeConfig: &Config{
6989 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006990 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006991 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006992 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006993 },
6994 },
6995 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006996 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006997 })
Steven Valdeza833c352016-11-01 13:39:36 -04006998
6999 testCases = append(testCases, testCase{
7000 testType: serverTest,
7001 name: "Resume-Server-BinderWrongLength",
7002 resumeSession: true,
7003 config: Config{
7004 MaxVersion: VersionTLS13,
7005 Bugs: ProtocolBugs{
7006 SendShortPSKBinder: true,
7007 },
7008 },
7009 shouldFail: true,
7010 expectedLocalError: "remote error: error decrypting message",
7011 expectedError: ":DIGEST_CHECK_FAILED:",
7012 })
7013
7014 testCases = append(testCases, testCase{
7015 testType: serverTest,
7016 name: "Resume-Server-NoPSKBinder",
7017 resumeSession: true,
7018 config: Config{
7019 MaxVersion: VersionTLS13,
7020 Bugs: ProtocolBugs{
7021 SendNoPSKBinder: true,
7022 },
7023 },
7024 shouldFail: true,
7025 expectedLocalError: "remote error: error decoding message",
7026 expectedError: ":DECODE_ERROR:",
7027 })
7028
7029 testCases = append(testCases, testCase{
7030 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05007031 name: "Resume-Server-ExtraPSKBinder",
7032 resumeSession: true,
7033 config: Config{
7034 MaxVersion: VersionTLS13,
7035 Bugs: ProtocolBugs{
7036 SendExtraPSKBinder: true,
7037 },
7038 },
7039 shouldFail: true,
7040 expectedLocalError: "remote error: illegal parameter",
7041 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7042 })
7043
7044 testCases = append(testCases, testCase{
7045 testType: serverTest,
7046 name: "Resume-Server-ExtraIdentityNoBinder",
7047 resumeSession: true,
7048 config: Config{
7049 MaxVersion: VersionTLS13,
7050 Bugs: ProtocolBugs{
7051 ExtraPSKIdentity: true,
7052 },
7053 },
7054 shouldFail: true,
7055 expectedLocalError: "remote error: illegal parameter",
7056 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
7057 })
7058
7059 testCases = append(testCases, testCase{
7060 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04007061 name: "Resume-Server-InvalidPSKBinder",
7062 resumeSession: true,
7063 config: Config{
7064 MaxVersion: VersionTLS13,
7065 Bugs: ProtocolBugs{
7066 SendInvalidPSKBinder: true,
7067 },
7068 },
7069 shouldFail: true,
7070 expectedLocalError: "remote error: error decrypting message",
7071 expectedError: ":DIGEST_CHECK_FAILED:",
7072 })
7073
7074 testCases = append(testCases, testCase{
7075 testType: serverTest,
7076 name: "Resume-Server-PSKBinderFirstExtension",
7077 resumeSession: true,
7078 config: Config{
7079 MaxVersion: VersionTLS13,
7080 Bugs: ProtocolBugs{
7081 PSKBinderFirst: true,
7082 },
7083 },
7084 shouldFail: true,
7085 expectedLocalError: "remote error: illegal parameter",
7086 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
7087 })
David Benjamin01fe8202014-09-24 15:21:44 -04007088}
7089
Adam Langley2ae77d22014-10-28 17:29:33 -07007090func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04007091 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04007092 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007093 testType: serverTest,
7094 name: "Renegotiate-Server-Forbidden",
7095 config: Config{
7096 MaxVersion: VersionTLS12,
7097 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007098 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04007099 shouldFail: true,
7100 expectedError: ":NO_RENEGOTIATION:",
7101 expectedLocalError: "remote error: no renegotiation",
7102 })
Adam Langley5021b222015-06-12 18:27:58 -07007103 // The server shouldn't echo the renegotiation extension unless
7104 // requested by the client.
7105 testCases = append(testCases, testCase{
7106 testType: serverTest,
7107 name: "Renegotiate-Server-NoExt",
7108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007109 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007110 Bugs: ProtocolBugs{
7111 NoRenegotiationInfo: true,
7112 RequireRenegotiationInfo: true,
7113 },
7114 },
7115 shouldFail: true,
7116 expectedLocalError: "renegotiation extension missing",
7117 })
7118 // The renegotiation SCSV should be sufficient for the server to echo
7119 // the extension.
7120 testCases = append(testCases, testCase{
7121 testType: serverTest,
7122 name: "Renegotiate-Server-NoExt-SCSV",
7123 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007124 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007125 Bugs: ProtocolBugs{
7126 NoRenegotiationInfo: true,
7127 SendRenegotiationSCSV: true,
7128 RequireRenegotiationInfo: true,
7129 },
7130 },
7131 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007132 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007133 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007135 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007136 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007137 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007138 },
7139 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007140 renegotiate: 1,
David Benjamind0beda02017-09-06 16:46:50 -04007141 // Test renegotiation after both an initial and resumption
7142 // handshake.
7143 resumeSession: true,
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007144 flags: []string{
7145 "-renegotiate-freely",
7146 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007147 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007148 },
David Benjamincdea40c2015-03-19 14:09:43 -04007149 })
7150 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007151 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007152 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007154 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007155 Bugs: ProtocolBugs{
7156 EmptyRenegotiationInfo: true,
7157 },
7158 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007159 flags: []string{"-renegotiate-freely"},
7160 shouldFail: true,
7161 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007162 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007163 })
7164 testCases = append(testCases, testCase{
7165 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007166 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007168 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007169 Bugs: ProtocolBugs{
7170 BadRenegotiationInfo: true,
7171 },
7172 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007173 flags: []string{"-renegotiate-freely"},
7174 shouldFail: true,
7175 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007176 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007177 })
7178 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007179 name: "Renegotiate-Client-BadExt2",
7180 renegotiate: 1,
7181 config: Config{
7182 MaxVersion: VersionTLS12,
7183 Bugs: ProtocolBugs{
7184 BadRenegotiationInfoEnd: true,
7185 },
7186 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007187 flags: []string{"-renegotiate-freely"},
7188 shouldFail: true,
7189 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007190 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007191 })
7192 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007193 name: "Renegotiate-Client-Downgrade",
7194 renegotiate: 1,
7195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007196 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007197 Bugs: ProtocolBugs{
7198 NoRenegotiationInfoAfterInitial: true,
7199 },
7200 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007201 flags: []string{"-renegotiate-freely"},
7202 shouldFail: true,
7203 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007204 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007205 })
7206 testCases = append(testCases, testCase{
7207 name: "Renegotiate-Client-Upgrade",
7208 renegotiate: 1,
7209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007210 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007211 Bugs: ProtocolBugs{
7212 NoRenegotiationInfoInInitial: true,
7213 },
7214 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007215 flags: []string{"-renegotiate-freely"},
7216 shouldFail: true,
7217 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007218 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007219 })
7220 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007221 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007222 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007224 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007225 Bugs: ProtocolBugs{
7226 NoRenegotiationInfo: true,
7227 },
7228 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007229 flags: []string{
7230 "-renegotiate-freely",
7231 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007232 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007233 },
David Benjamincff0b902015-05-15 23:09:47 -04007234 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007235
7236 // Test that the server may switch ciphers on renegotiation without
7237 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007238 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007239 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007240 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007241 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007242 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007243 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007244 },
7245 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007246 flags: []string{
7247 "-renegotiate-freely",
7248 "-expect-total-renegotiations", "1",
7249 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007250 })
7251 testCases = append(testCases, testCase{
7252 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007253 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007254 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007255 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007256 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7257 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007258 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007259 flags: []string{
7260 "-renegotiate-freely",
7261 "-expect-total-renegotiations", "1",
7262 },
David Benjaminb16346b2015-04-08 19:16:58 -04007263 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007264
7265 // Test that the server may not switch versions on renegotiation.
7266 testCases = append(testCases, testCase{
7267 name: "Renegotiate-Client-SwitchVersion",
7268 config: Config{
7269 MaxVersion: VersionTLS12,
7270 // Pick a cipher which exists at both versions.
7271 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7272 Bugs: ProtocolBugs{
7273 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007274 // Avoid failing early at the record layer.
7275 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007276 },
7277 },
7278 renegotiate: 1,
7279 flags: []string{
7280 "-renegotiate-freely",
7281 "-expect-total-renegotiations", "1",
7282 },
7283 shouldFail: true,
7284 expectedError: ":WRONG_SSL_VERSION:",
7285 })
7286
David Benjaminb16346b2015-04-08 19:16:58 -04007287 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007288 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007289 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007290 config: Config{
7291 MaxVersion: VersionTLS10,
7292 Bugs: ProtocolBugs{
7293 RequireSameRenegoClientVersion: true,
7294 },
7295 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007296 flags: []string{
7297 "-renegotiate-freely",
7298 "-expect-total-renegotiations", "1",
7299 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007300 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007301 testCases = append(testCases, testCase{
7302 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007303 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007304 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007305 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007306 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7307 NextProtos: []string{"foo"},
7308 },
7309 flags: []string{
7310 "-false-start",
7311 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007312 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007313 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007314 },
7315 shimWritesFirst: true,
7316 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007317
7318 // Client-side renegotiation controls.
7319 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007320 name: "Renegotiate-Client-Forbidden-1",
7321 config: Config{
7322 MaxVersion: VersionTLS12,
7323 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007324 renegotiate: 1,
7325 shouldFail: true,
7326 expectedError: ":NO_RENEGOTIATION:",
7327 expectedLocalError: "remote error: no renegotiation",
7328 })
7329 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007330 name: "Renegotiate-Client-Once-1",
7331 config: Config{
7332 MaxVersion: VersionTLS12,
7333 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007334 renegotiate: 1,
7335 flags: []string{
7336 "-renegotiate-once",
7337 "-expect-total-renegotiations", "1",
7338 },
7339 })
7340 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007341 name: "Renegotiate-Client-Freely-1",
7342 config: Config{
7343 MaxVersion: VersionTLS12,
7344 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007345 renegotiate: 1,
7346 flags: []string{
7347 "-renegotiate-freely",
7348 "-expect-total-renegotiations", "1",
7349 },
7350 })
7351 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007352 name: "Renegotiate-Client-Once-2",
7353 config: Config{
7354 MaxVersion: VersionTLS12,
7355 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007356 renegotiate: 2,
7357 flags: []string{"-renegotiate-once"},
7358 shouldFail: true,
7359 expectedError: ":NO_RENEGOTIATION:",
7360 expectedLocalError: "remote error: no renegotiation",
7361 })
7362 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007363 name: "Renegotiate-Client-Freely-2",
7364 config: Config{
7365 MaxVersion: VersionTLS12,
7366 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007367 renegotiate: 2,
7368 flags: []string{
7369 "-renegotiate-freely",
7370 "-expect-total-renegotiations", "2",
7371 },
7372 })
Adam Langley27a0d082015-11-03 13:34:10 -08007373 testCases = append(testCases, testCase{
7374 name: "Renegotiate-Client-NoIgnore",
7375 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007376 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007377 Bugs: ProtocolBugs{
7378 SendHelloRequestBeforeEveryAppDataRecord: true,
7379 },
7380 },
7381 shouldFail: true,
7382 expectedError: ":NO_RENEGOTIATION:",
7383 })
7384 testCases = append(testCases, testCase{
7385 name: "Renegotiate-Client-Ignore",
7386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007387 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007388 Bugs: ProtocolBugs{
7389 SendHelloRequestBeforeEveryAppDataRecord: true,
7390 },
7391 },
7392 flags: []string{
7393 "-renegotiate-ignore",
7394 "-expect-total-renegotiations", "0",
7395 },
7396 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007397
David Benjamin34941c02016-10-08 11:45:31 -04007398 // Renegotiation is not allowed at SSL 3.0.
7399 testCases = append(testCases, testCase{
7400 name: "Renegotiate-Client-SSL3",
7401 config: Config{
7402 MaxVersion: VersionSSL30,
7403 },
7404 renegotiate: 1,
7405 flags: []string{
7406 "-renegotiate-freely",
7407 "-expect-total-renegotiations", "1",
7408 },
7409 shouldFail: true,
7410 expectedError: ":NO_RENEGOTIATION:",
7411 expectedLocalError: "remote error: no renegotiation",
7412 })
7413
David Benjamina1eaba12017-01-01 23:19:22 -05007414 // Renegotiation is not allowed when there is an unfinished write.
7415 testCases = append(testCases, testCase{
7416 name: "Renegotiate-Client-UnfinishedWrite",
7417 config: Config{
7418 MaxVersion: VersionTLS12,
7419 },
David Benjaminbbba9392017-04-06 12:54:12 -04007420 renegotiate: 1,
7421 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007422 flags: []string{
7423 "-async",
7424 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007425 },
7426 shouldFail: true,
7427 expectedError: ":NO_RENEGOTIATION:",
7428 // We do not successfully send the no_renegotiation alert in
7429 // this case. https://crbug.com/boringssl/130
7430 })
7431
David Benjamin07ab5d42017-02-09 20:11:41 -05007432 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007433 testCases = append(testCases, testCase{
7434 name: "StrayHelloRequest",
7435 config: Config{
7436 MaxVersion: VersionTLS12,
7437 Bugs: ProtocolBugs{
7438 SendHelloRequestBeforeEveryHandshakeMessage: true,
7439 },
7440 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007441 shouldFail: true,
7442 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007443 })
7444 testCases = append(testCases, testCase{
7445 name: "StrayHelloRequest-Packed",
7446 config: Config{
7447 MaxVersion: VersionTLS12,
7448 Bugs: ProtocolBugs{
7449 PackHandshakeFlight: true,
7450 SendHelloRequestBeforeEveryHandshakeMessage: true,
7451 },
7452 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007453 shouldFail: true,
7454 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007455 })
7456
David Benjamin12d2c482016-07-24 10:56:51 -04007457 // Test renegotiation works if HelloRequest and server Finished come in
7458 // the same record.
7459 testCases = append(testCases, testCase{
7460 name: "Renegotiate-Client-Packed",
7461 config: Config{
7462 MaxVersion: VersionTLS12,
7463 Bugs: ProtocolBugs{
7464 PackHandshakeFlight: true,
7465 PackHelloRequestWithFinished: true,
7466 },
7467 },
7468 renegotiate: 1,
7469 flags: []string{
7470 "-renegotiate-freely",
7471 "-expect-total-renegotiations", "1",
7472 },
7473 })
7474
David Benjamin397c8e62016-07-08 14:14:36 -07007475 // Renegotiation is forbidden in TLS 1.3.
7476 testCases = append(testCases, testCase{
7477 name: "Renegotiate-Client-TLS13",
7478 config: Config{
7479 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007480 Bugs: ProtocolBugs{
7481 SendHelloRequestBeforeEveryAppDataRecord: true,
7482 },
David Benjamin397c8e62016-07-08 14:14:36 -07007483 },
David Benjamin397c8e62016-07-08 14:14:36 -07007484 flags: []string{
7485 "-renegotiate-freely",
7486 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007487 shouldFail: true,
7488 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007489 })
7490
7491 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7492 testCases = append(testCases, testCase{
7493 name: "StrayHelloRequest-TLS13",
7494 config: Config{
7495 MaxVersion: VersionTLS13,
7496 Bugs: ProtocolBugs{
7497 SendHelloRequestBeforeEveryHandshakeMessage: true,
7498 },
7499 },
7500 shouldFail: true,
7501 expectedError: ":UNEXPECTED_MESSAGE:",
7502 })
David Benjamind2610042017-01-03 10:49:28 -05007503
7504 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7505 // always reads as supporting it, regardless of whether it was
7506 // negotiated.
7507 testCases = append(testCases, testCase{
7508 name: "AlwaysReportRenegotiationInfo-TLS13",
7509 config: Config{
7510 MaxVersion: VersionTLS13,
7511 Bugs: ProtocolBugs{
7512 NoRenegotiationInfo: true,
7513 },
7514 },
7515 flags: []string{
7516 "-expect-secure-renegotiation",
7517 },
7518 })
David Benjamina58baaf2017-02-28 20:54:28 -05007519
7520 // Certificates may not change on renegotiation.
7521 testCases = append(testCases, testCase{
7522 name: "Renegotiation-CertificateChange",
7523 config: Config{
7524 MaxVersion: VersionTLS12,
7525 Certificates: []Certificate{rsaCertificate},
7526 Bugs: ProtocolBugs{
7527 RenegotiationCertificate: &rsaChainCertificate,
7528 },
7529 },
7530 renegotiate: 1,
7531 flags: []string{"-renegotiate-freely"},
7532 shouldFail: true,
7533 expectedError: ":SERVER_CERT_CHANGED:",
7534 })
7535 testCases = append(testCases, testCase{
7536 name: "Renegotiation-CertificateChange-2",
7537 config: Config{
7538 MaxVersion: VersionTLS12,
7539 Certificates: []Certificate{rsaCertificate},
7540 Bugs: ProtocolBugs{
7541 RenegotiationCertificate: &rsa1024Certificate,
7542 },
7543 },
7544 renegotiate: 1,
7545 flags: []string{"-renegotiate-freely"},
7546 shouldFail: true,
7547 expectedError: ":SERVER_CERT_CHANGED:",
7548 })
David Benjaminbbf42462017-03-14 21:27:10 -04007549
7550 // We do not negotiate ALPN after the initial handshake. This is
7551 // error-prone and only risks bugs in consumers.
7552 testCases = append(testCases, testCase{
7553 testType: clientTest,
7554 name: "Renegotiation-ForbidALPN",
7555 config: Config{
7556 MaxVersion: VersionTLS12,
7557 Bugs: ProtocolBugs{
7558 // Forcibly negotiate ALPN on both initial and
7559 // renegotiation handshakes. The test stack will
7560 // internally check the client does not offer
7561 // it.
7562 SendALPN: "foo",
7563 },
7564 },
7565 flags: []string{
7566 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7567 "-expect-alpn", "foo",
7568 "-renegotiate-freely",
7569 },
7570 renegotiate: 1,
7571 shouldFail: true,
7572 expectedError: ":UNEXPECTED_EXTENSION:",
7573 })
David Benjamin5c4271f2017-08-23 22:09:41 -07007574
7575 // The server may send different stapled OCSP responses or SCT lists on
7576 // renegotiation, but BoringSSL ignores this and reports the old values.
7577 // Also test that non-fatal verify results are preserved.
7578 testCases = append(testCases, testCase{
7579 testType: clientTest,
7580 name: "Renegotiation-ChangeAuthProperties",
7581 config: Config{
7582 MaxVersion: VersionTLS12,
7583 Bugs: ProtocolBugs{
7584 SendOCSPResponseOnRenegotiation: testOCSPResponse2,
7585 SendSCTListOnRenegotiation: testSCTList2,
7586 },
7587 },
7588 renegotiate: 1,
7589 flags: []string{
7590 "-renegotiate-freely",
7591 "-expect-total-renegotiations", "1",
7592 "-enable-ocsp-stapling",
7593 "-expect-ocsp-response",
7594 base64.StdEncoding.EncodeToString(testOCSPResponse),
7595 "-enable-signed-cert-timestamps",
7596 "-expect-signed-cert-timestamps",
7597 base64.StdEncoding.EncodeToString(testSCTList),
7598 "-verify-fail",
7599 "-expect-verify-result",
7600 },
7601 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007602}
7603
David Benjamin5e961c12014-11-07 01:48:35 -05007604func addDTLSReplayTests() {
7605 // Test that sequence number replays are detected.
7606 testCases = append(testCases, testCase{
7607 protocol: dtls,
7608 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007609 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007610 replayWrites: true,
7611 })
7612
David Benjamin8e6db492015-07-25 18:29:23 -04007613 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007614 // than the retransmit window.
7615 testCases = append(testCases, testCase{
7616 protocol: dtls,
7617 name: "DTLS-Replay-LargeGaps",
7618 config: Config{
7619 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007620 SequenceNumberMapping: func(in uint64) uint64 {
7621 return in * 127
7622 },
David Benjamin5e961c12014-11-07 01:48:35 -05007623 },
7624 },
David Benjamin8e6db492015-07-25 18:29:23 -04007625 messageCount: 200,
7626 replayWrites: true,
7627 })
7628
7629 // Test the incoming sequence number changing non-monotonically.
7630 testCases = append(testCases, testCase{
7631 protocol: dtls,
7632 name: "DTLS-Replay-NonMonotonic",
7633 config: Config{
7634 Bugs: ProtocolBugs{
7635 SequenceNumberMapping: func(in uint64) uint64 {
7636 return in ^ 31
7637 },
7638 },
7639 },
7640 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007641 replayWrites: true,
7642 })
7643}
7644
Nick Harper60edffd2016-06-21 15:19:24 -07007645var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007646 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007647 id signatureAlgorithm
7648 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007649}{
Nick Harper60edffd2016-06-21 15:19:24 -07007650 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7651 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7652 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7653 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007654 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007655 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7656 // hash function doesn't have to match the curve and so the same
7657 // signature algorithm works with P-224.
7658 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007659 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7660 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7661 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007662 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7663 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7664 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007665 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007666 // Tests for key types prior to TLS 1.2.
7667 {"RSA", 0, testCertRSA},
7668 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007669}
7670
Nick Harper60edffd2016-06-21 15:19:24 -07007671const fakeSigAlg1 signatureAlgorithm = 0x2a01
7672const fakeSigAlg2 signatureAlgorithm = 0xff01
7673
7674func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007675 // Not all ciphers involve a signature. Advertise a list which gives all
7676 // versions a signing cipher.
7677 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007678 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007679 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7680 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7681 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7682 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007683 }
David Benjamin5208fd42016-07-13 21:43:25 -04007684
David Benjaminca3d5452016-07-14 12:51:01 -04007685 var allAlgorithms []signatureAlgorithm
7686 for _, alg := range testSignatureAlgorithms {
7687 if alg.id != 0 {
7688 allAlgorithms = append(allAlgorithms, alg.id)
7689 }
7690 }
7691
Nick Harper60edffd2016-06-21 15:19:24 -07007692 // Make sure each signature algorithm works. Include some fake values in
7693 // the list and ensure they're ignored.
7694 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007695 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007696 if (ver.version < VersionTLS12) != (alg.id == 0) {
7697 continue
7698 }
7699
7700 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7701 // or remove it in C.
7702 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007703 continue
7704 }
Nick Harper60edffd2016-06-21 15:19:24 -07007705
David Benjamin3ef76972016-10-17 17:59:54 -04007706 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007707 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007708 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007709 shouldSignFail = true
7710 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007711 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007712 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007713 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7714 shouldSignFail = true
7715 shouldVerifyFail = true
7716 }
7717 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7718 // the curve has to match the hash size.
7719 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007720 shouldSignFail = true
7721 shouldVerifyFail = true
7722 }
7723
7724 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7725 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7726 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007727 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007728
7729 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007730 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007731 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007732 }
7733 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007734 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007735 }
David Benjamin000800a2014-11-14 01:43:59 -05007736
David Benjamin1fb125c2016-07-08 18:52:12 -07007737 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007738
David Benjamin7a41d372016-07-09 11:21:54 -07007739 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007740 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007741 config: Config{
7742 MaxVersion: ver.version,
7743 ClientAuth: RequireAnyClientCert,
7744 VerifySignatureAlgorithms: []signatureAlgorithm{
7745 fakeSigAlg1,
7746 alg.id,
7747 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007748 },
David Benjamin7a41d372016-07-09 11:21:54 -07007749 },
7750 flags: []string{
7751 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7752 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7753 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007754 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007755 },
David Benjamina5022392017-07-10 17:40:39 -04007756 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007757 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007758 expectedError: signError,
7759 expectedPeerSignatureAlgorithm: alg.id,
7760 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007761
David Benjamin7a41d372016-07-09 11:21:54 -07007762 testCases = append(testCases, testCase{
7763 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007764 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007765 config: Config{
7766 MaxVersion: ver.version,
7767 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7768 SignSignatureAlgorithms: []signatureAlgorithm{
7769 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007770 },
David Benjamin7a41d372016-07-09 11:21:54 -07007771 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007772 SkipECDSACurveCheck: shouldVerifyFail,
7773 IgnoreSignatureVersionChecks: shouldVerifyFail,
7774 // Some signature algorithms may not be advertised.
7775 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007776 },
David Benjamin7a41d372016-07-09 11:21:54 -07007777 },
David Benjamina5022392017-07-10 17:40:39 -04007778 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007779 flags: []string{
7780 "-require-any-client-certificate",
7781 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7782 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007783 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007784 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007785 // Resume the session to assert the peer signature
7786 // algorithm is reported on both handshakes.
7787 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007788 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007789 expectedError: verifyError,
7790 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007791
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007792 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007793 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007794 testCases = append(testCases, testCase{
7795 testType: serverTest,
7796 name: "ServerAuth-Sign" + suffix,
7797 config: Config{
7798 MaxVersion: ver.version,
7799 CipherSuites: signingCiphers,
7800 VerifySignatureAlgorithms: []signatureAlgorithm{
7801 fakeSigAlg1,
7802 alg.id,
7803 fakeSigAlg2,
7804 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007805 },
David Benjamina5022392017-07-10 17:40:39 -04007806 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007807 flags: []string{
7808 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7809 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7810 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007811 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007812 },
7813 shouldFail: shouldSignFail,
7814 expectedError: signError,
7815 expectedPeerSignatureAlgorithm: alg.id,
7816 })
7817 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007818
7819 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007820 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007821 config: Config{
7822 MaxVersion: ver.version,
7823 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007824 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007825 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007826 alg.id,
7827 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007828 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007829 SkipECDSACurveCheck: shouldVerifyFail,
7830 IgnoreSignatureVersionChecks: shouldVerifyFail,
7831 // Some signature algorithms may not be advertised.
7832 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007833 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007834 },
David Benjamina5022392017-07-10 17:40:39 -04007835 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007836 flags: []string{
7837 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7838 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007839 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007840 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007841 // Resume the session to assert the peer signature
7842 // algorithm is reported on both handshakes.
7843 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007844 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007845 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007846 })
David Benjamin5208fd42016-07-13 21:43:25 -04007847
David Benjamin3ef76972016-10-17 17:59:54 -04007848 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007849 testCases = append(testCases, testCase{
7850 testType: serverTest,
7851 name: "ClientAuth-InvalidSignature" + suffix,
7852 config: Config{
7853 MaxVersion: ver.version,
7854 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7855 SignSignatureAlgorithms: []signatureAlgorithm{
7856 alg.id,
7857 },
7858 Bugs: ProtocolBugs{
7859 InvalidSignature: true,
7860 },
7861 },
David Benjamina5022392017-07-10 17:40:39 -04007862 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007863 flags: []string{
7864 "-require-any-client-certificate",
7865 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007866 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007867 },
7868 shouldFail: true,
7869 expectedError: ":BAD_SIGNATURE:",
7870 })
7871
7872 testCases = append(testCases, testCase{
7873 name: "ServerAuth-InvalidSignature" + suffix,
7874 config: Config{
7875 MaxVersion: ver.version,
7876 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7877 CipherSuites: signingCiphers,
7878 SignSignatureAlgorithms: []signatureAlgorithm{
7879 alg.id,
7880 },
7881 Bugs: ProtocolBugs{
7882 InvalidSignature: true,
7883 },
7884 },
David Benjamina5022392017-07-10 17:40:39 -04007885 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007886 flags: []string{
7887 "-enable-all-curves",
7888 "-enable-ed25519",
7889 },
David Benjamin5208fd42016-07-13 21:43:25 -04007890 shouldFail: true,
7891 expectedError: ":BAD_SIGNATURE:",
7892 })
7893 }
David Benjaminca3d5452016-07-14 12:51:01 -04007894
David Benjamin3ef76972016-10-17 17:59:54 -04007895 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007896 testCases = append(testCases, testCase{
7897 name: "ClientAuth-Sign-Negotiate" + suffix,
7898 config: Config{
7899 MaxVersion: ver.version,
7900 ClientAuth: RequireAnyClientCert,
7901 VerifySignatureAlgorithms: allAlgorithms,
7902 },
David Benjamina5022392017-07-10 17:40:39 -04007903 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007904 flags: []string{
7905 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7906 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7907 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007908 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007909 "-signing-prefs", strconv.Itoa(int(alg.id)),
7910 },
7911 expectedPeerSignatureAlgorithm: alg.id,
7912 })
7913
7914 testCases = append(testCases, testCase{
7915 testType: serverTest,
7916 name: "ServerAuth-Sign-Negotiate" + suffix,
7917 config: Config{
7918 MaxVersion: ver.version,
7919 CipherSuites: signingCiphers,
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 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007933 }
David Benjamin000800a2014-11-14 01:43:59 -05007934 }
7935
Nick Harper60edffd2016-06-21 15:19:24 -07007936 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007937 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007938 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007939 config: Config{
7940 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007941 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007942 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007943 signatureECDSAWithP521AndSHA512,
7944 signatureRSAPKCS1WithSHA384,
7945 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007946 },
7947 },
7948 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007949 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7950 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007951 },
Nick Harper60edffd2016-06-21 15:19:24 -07007952 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007953 })
7954
7955 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007956 name: "ClientAuth-SignatureType-TLS13",
7957 config: Config{
7958 ClientAuth: RequireAnyClientCert,
7959 MaxVersion: VersionTLS13,
7960 VerifySignatureAlgorithms: []signatureAlgorithm{
7961 signatureECDSAWithP521AndSHA512,
7962 signatureRSAPKCS1WithSHA384,
7963 signatureRSAPSSWithSHA384,
7964 signatureECDSAWithSHA1,
7965 },
7966 },
7967 flags: []string{
7968 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7969 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7970 },
7971 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7972 })
7973
7974 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007975 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007976 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007978 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007980 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007981 signatureECDSAWithP521AndSHA512,
7982 signatureRSAPKCS1WithSHA384,
7983 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007984 },
7985 },
Nick Harper60edffd2016-06-21 15:19:24 -07007986 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007987 })
7988
Steven Valdez143e8b32016-07-11 13:19:03 -04007989 testCases = append(testCases, testCase{
7990 testType: serverTest,
7991 name: "ServerAuth-SignatureType-TLS13",
7992 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007993 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007994 VerifySignatureAlgorithms: []signatureAlgorithm{
7995 signatureECDSAWithP521AndSHA512,
7996 signatureRSAPKCS1WithSHA384,
7997 signatureRSAPSSWithSHA384,
7998 signatureECDSAWithSHA1,
7999 },
8000 },
8001 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
8002 })
8003
David Benjamina95e9f32016-07-08 16:28:04 -07008004 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07008005 testCases = append(testCases, testCase{
8006 testType: serverTest,
8007 name: "Verify-ClientAuth-SignatureType",
8008 config: Config{
8009 MaxVersion: VersionTLS12,
8010 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008011 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07008012 signatureRSAPKCS1WithSHA256,
8013 },
8014 Bugs: ProtocolBugs{
8015 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8016 },
8017 },
8018 flags: []string{
8019 "-require-any-client-certificate",
8020 },
8021 shouldFail: true,
8022 expectedError: ":WRONG_SIGNATURE_TYPE:",
8023 })
8024
8025 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008026 testType: serverTest,
8027 name: "Verify-ClientAuth-SignatureType-TLS13",
8028 config: Config{
8029 MaxVersion: VersionTLS13,
8030 Certificates: []Certificate{rsaCertificate},
8031 SignSignatureAlgorithms: []signatureAlgorithm{
8032 signatureRSAPSSWithSHA256,
8033 },
8034 Bugs: ProtocolBugs{
8035 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8036 },
8037 },
8038 flags: []string{
8039 "-require-any-client-certificate",
8040 },
8041 shouldFail: true,
8042 expectedError: ":WRONG_SIGNATURE_TYPE:",
8043 })
8044
8045 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008046 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07008047 config: Config{
8048 MaxVersion: VersionTLS12,
8049 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008050 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07008051 signatureRSAPKCS1WithSHA256,
8052 },
8053 Bugs: ProtocolBugs{
8054 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8055 },
8056 },
8057 shouldFail: true,
8058 expectedError: ":WRONG_SIGNATURE_TYPE:",
8059 })
8060
Steven Valdez143e8b32016-07-11 13:19:03 -04008061 testCases = append(testCases, testCase{
8062 name: "Verify-ServerAuth-SignatureType-TLS13",
8063 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008064 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008065 SignSignatureAlgorithms: []signatureAlgorithm{
8066 signatureRSAPSSWithSHA256,
8067 },
8068 Bugs: ProtocolBugs{
8069 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8070 },
8071 },
8072 shouldFail: true,
8073 expectedError: ":WRONG_SIGNATURE_TYPE:",
8074 })
8075
David Benjamin51dd7d62016-07-08 16:07:01 -07008076 // Test that, if the list is missing, the peer falls back to SHA-1 in
8077 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05008078 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04008079 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008081 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05008082 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008083 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008084 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008085 },
8086 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008087 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008088 },
8089 },
8090 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07008091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05008093 },
8094 })
8095
8096 testCases = append(testCases, testCase{
8097 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04008098 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05008099 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04008100 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07008101 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008102 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05008103 },
8104 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07008105 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05008106 },
8107 },
David Benjaminee32bea2016-08-17 13:36:44 -04008108 flags: []string{
8109 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8110 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8111 },
8112 })
8113
8114 testCases = append(testCases, testCase{
8115 name: "ClientAuth-SHA1-Fallback-ECDSA",
8116 config: Config{
8117 MaxVersion: VersionTLS12,
8118 ClientAuth: RequireAnyClientCert,
8119 VerifySignatureAlgorithms: []signatureAlgorithm{
8120 signatureECDSAWithSHA1,
8121 },
8122 Bugs: ProtocolBugs{
8123 NoSignatureAlgorithms: true,
8124 },
8125 },
8126 flags: []string{
8127 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8128 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8129 },
8130 })
8131
8132 testCases = append(testCases, testCase{
8133 testType: serverTest,
8134 name: "ServerAuth-SHA1-Fallback-ECDSA",
8135 config: Config{
8136 MaxVersion: VersionTLS12,
8137 VerifySignatureAlgorithms: []signatureAlgorithm{
8138 signatureECDSAWithSHA1,
8139 },
8140 Bugs: ProtocolBugs{
8141 NoSignatureAlgorithms: true,
8142 },
8143 },
8144 flags: []string{
8145 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8146 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8147 },
David Benjamin000800a2014-11-14 01:43:59 -05008148 })
David Benjamin72dc7832015-03-16 17:49:43 -04008149
David Benjamin51dd7d62016-07-08 16:07:01 -07008150 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008151 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008152 config: Config{
8153 MaxVersion: VersionTLS13,
8154 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008155 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008156 signatureRSAPKCS1WithSHA1,
8157 },
8158 Bugs: ProtocolBugs{
8159 NoSignatureAlgorithms: true,
8160 },
8161 },
8162 flags: []string{
8163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8165 },
David Benjamin48901652016-08-01 12:12:47 -04008166 shouldFail: true,
8167 // An empty CertificateRequest signature algorithm list is a
8168 // syntax error in TLS 1.3.
8169 expectedError: ":DECODE_ERROR:",
8170 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008171 })
8172
8173 testCases = append(testCases, testCase{
8174 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008175 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008176 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008177 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008178 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008179 signatureRSAPKCS1WithSHA1,
8180 },
8181 Bugs: ProtocolBugs{
8182 NoSignatureAlgorithms: true,
8183 },
8184 },
8185 shouldFail: true,
8186 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8187 })
8188
David Benjaminb62d2872016-07-18 14:55:02 +02008189 // Test that hash preferences are enforced. BoringSSL does not implement
8190 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008191 testCases = append(testCases, testCase{
8192 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008193 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008195 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008196 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008197 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008198 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008199 },
8200 Bugs: ProtocolBugs{
8201 IgnorePeerSignatureAlgorithmPreferences: true,
8202 },
8203 },
8204 flags: []string{"-require-any-client-certificate"},
8205 shouldFail: true,
8206 expectedError: ":WRONG_SIGNATURE_TYPE:",
8207 })
8208
8209 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008210 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008211 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008212 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008213 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008214 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008215 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008216 },
8217 Bugs: ProtocolBugs{
8218 IgnorePeerSignatureAlgorithmPreferences: true,
8219 },
8220 },
8221 shouldFail: true,
8222 expectedError: ":WRONG_SIGNATURE_TYPE:",
8223 })
David Benjaminb62d2872016-07-18 14:55:02 +02008224 testCases = append(testCases, testCase{
8225 testType: serverTest,
8226 name: "ClientAuth-Enforced-TLS13",
8227 config: Config{
8228 MaxVersion: VersionTLS13,
8229 Certificates: []Certificate{rsaCertificate},
8230 SignSignatureAlgorithms: []signatureAlgorithm{
8231 signatureRSAPKCS1WithMD5,
8232 },
8233 Bugs: ProtocolBugs{
8234 IgnorePeerSignatureAlgorithmPreferences: true,
8235 IgnoreSignatureVersionChecks: true,
8236 },
8237 },
8238 flags: []string{"-require-any-client-certificate"},
8239 shouldFail: true,
8240 expectedError: ":WRONG_SIGNATURE_TYPE:",
8241 })
8242
8243 testCases = append(testCases, testCase{
8244 name: "ServerAuth-Enforced-TLS13",
8245 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008246 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008247 SignSignatureAlgorithms: []signatureAlgorithm{
8248 signatureRSAPKCS1WithMD5,
8249 },
8250 Bugs: ProtocolBugs{
8251 IgnorePeerSignatureAlgorithmPreferences: true,
8252 IgnoreSignatureVersionChecks: true,
8253 },
8254 },
8255 shouldFail: true,
8256 expectedError: ":WRONG_SIGNATURE_TYPE:",
8257 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008258
8259 // Test that the agreed upon digest respects the client preferences and
8260 // the server digests.
8261 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008262 name: "NoCommonAlgorithms-Digests",
8263 config: Config{
8264 MaxVersion: VersionTLS12,
8265 ClientAuth: RequireAnyClientCert,
8266 VerifySignatureAlgorithms: []signatureAlgorithm{
8267 signatureRSAPKCS1WithSHA512,
8268 signatureRSAPKCS1WithSHA1,
8269 },
8270 },
8271 flags: []string{
8272 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8273 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8274 "-digest-prefs", "SHA256",
8275 },
8276 shouldFail: true,
8277 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8278 })
8279 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008280 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008281 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008282 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008283 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008284 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008285 signatureRSAPKCS1WithSHA512,
8286 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008287 },
8288 },
8289 flags: []string{
8290 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8291 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008292 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008293 },
David Benjaminca3d5452016-07-14 12:51:01 -04008294 shouldFail: true,
8295 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8296 })
8297 testCases = append(testCases, testCase{
8298 name: "NoCommonAlgorithms-TLS13",
8299 config: Config{
8300 MaxVersion: VersionTLS13,
8301 ClientAuth: RequireAnyClientCert,
8302 VerifySignatureAlgorithms: []signatureAlgorithm{
8303 signatureRSAPSSWithSHA512,
8304 signatureRSAPSSWithSHA384,
8305 },
8306 },
8307 flags: []string{
8308 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8309 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8310 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8311 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008312 shouldFail: true,
8313 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008314 })
8315 testCases = append(testCases, testCase{
8316 name: "Agree-Digest-SHA256",
8317 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008318 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008319 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008320 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008321 signatureRSAPKCS1WithSHA1,
8322 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008323 },
8324 },
8325 flags: []string{
8326 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8327 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008328 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008329 },
Nick Harper60edffd2016-06-21 15:19:24 -07008330 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008331 })
8332 testCases = append(testCases, testCase{
8333 name: "Agree-Digest-SHA1",
8334 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008335 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008336 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008337 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008338 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008339 },
8340 },
8341 flags: []string{
8342 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8343 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008344 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008345 },
Nick Harper60edffd2016-06-21 15:19:24 -07008346 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008347 })
8348 testCases = append(testCases, testCase{
8349 name: "Agree-Digest-Default",
8350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008351 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008352 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008353 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008354 signatureRSAPKCS1WithSHA256,
8355 signatureECDSAWithP256AndSHA256,
8356 signatureRSAPKCS1WithSHA1,
8357 signatureECDSAWithSHA1,
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),
8363 },
Nick Harper60edffd2016-06-21 15:19:24 -07008364 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008365 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008366
David Benjaminca3d5452016-07-14 12:51:01 -04008367 // Test that the signing preference list may include extra algorithms
8368 // without negotiation problems.
8369 testCases = append(testCases, testCase{
8370 testType: serverTest,
8371 name: "FilterExtraAlgorithms",
8372 config: Config{
8373 MaxVersion: VersionTLS12,
8374 VerifySignatureAlgorithms: []signatureAlgorithm{
8375 signatureRSAPKCS1WithSHA256,
8376 },
8377 },
8378 flags: []string{
8379 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8380 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8381 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8382 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8383 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8384 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8385 },
8386 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8387 })
8388
David Benjamin4c3ddf72016-06-29 18:13:53 -04008389 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8390 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008391 testCases = append(testCases, testCase{
8392 name: "CheckLeafCurve",
8393 config: Config{
8394 MaxVersion: VersionTLS12,
8395 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008396 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008397 },
8398 flags: []string{"-p384-only"},
8399 shouldFail: true,
8400 expectedError: ":BAD_ECC_CERT:",
8401 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008402
8403 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8404 testCases = append(testCases, testCase{
8405 name: "CheckLeafCurve-TLS13",
8406 config: Config{
8407 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008408 Certificates: []Certificate{ecdsaP256Certificate},
8409 },
8410 flags: []string{"-p384-only"},
8411 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008412
8413 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8414 testCases = append(testCases, testCase{
8415 name: "ECDSACurveMismatch-Verify-TLS12",
8416 config: Config{
8417 MaxVersion: VersionTLS12,
8418 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8419 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008420 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008421 signatureECDSAWithP384AndSHA384,
8422 },
8423 },
8424 })
8425
8426 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8427 testCases = append(testCases, testCase{
8428 name: "ECDSACurveMismatch-Verify-TLS13",
8429 config: Config{
8430 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008431 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008432 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008433 signatureECDSAWithP384AndSHA384,
8434 },
8435 Bugs: ProtocolBugs{
8436 SkipECDSACurveCheck: true,
8437 },
8438 },
8439 shouldFail: true,
8440 expectedError: ":WRONG_SIGNATURE_TYPE:",
8441 })
8442
8443 // Signature algorithm selection in TLS 1.3 should take the curve into
8444 // account.
8445 testCases = append(testCases, testCase{
8446 testType: serverTest,
8447 name: "ECDSACurveMismatch-Sign-TLS13",
8448 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008449 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008450 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008451 signatureECDSAWithP384AndSHA384,
8452 signatureECDSAWithP256AndSHA256,
8453 },
8454 },
8455 flags: []string{
8456 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8457 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8458 },
8459 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8460 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008461
8462 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8463 // server does not attempt to sign in that case.
8464 testCases = append(testCases, testCase{
8465 testType: serverTest,
8466 name: "RSA-PSS-Large",
8467 config: Config{
8468 MaxVersion: VersionTLS13,
8469 VerifySignatureAlgorithms: []signatureAlgorithm{
8470 signatureRSAPSSWithSHA512,
8471 },
8472 },
8473 flags: []string{
8474 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8475 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8476 },
8477 shouldFail: true,
8478 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8479 })
David Benjamin57e929f2016-08-30 00:30:38 -04008480
8481 // Test that RSA-PSS is enabled by default for TLS 1.2.
8482 testCases = append(testCases, testCase{
8483 testType: clientTest,
8484 name: "RSA-PSS-Default-Verify",
8485 config: Config{
8486 MaxVersion: VersionTLS12,
8487 SignSignatureAlgorithms: []signatureAlgorithm{
8488 signatureRSAPSSWithSHA256,
8489 },
8490 },
8491 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8492 })
8493
8494 testCases = append(testCases, testCase{
8495 testType: serverTest,
8496 name: "RSA-PSS-Default-Sign",
8497 config: Config{
8498 MaxVersion: VersionTLS12,
8499 VerifySignatureAlgorithms: []signatureAlgorithm{
8500 signatureRSAPSSWithSHA256,
8501 },
8502 },
8503 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8504 })
David Benjamin69522112017-03-28 15:38:29 -05008505
8506 // TLS 1.1 and below has no way to advertise support for or negotiate
8507 // Ed25519's signature algorithm.
8508 testCases = append(testCases, testCase{
8509 testType: clientTest,
8510 name: "NoEd25519-TLS11-ServerAuth-Verify",
8511 config: Config{
8512 MaxVersion: VersionTLS11,
8513 Certificates: []Certificate{ed25519Certificate},
8514 Bugs: ProtocolBugs{
8515 // Sign with Ed25519 even though it is TLS 1.1.
8516 UseLegacySigningAlgorithm: signatureEd25519,
8517 },
8518 },
8519 flags: []string{"-enable-ed25519"},
8520 shouldFail: true,
8521 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8522 })
8523 testCases = append(testCases, testCase{
8524 testType: serverTest,
8525 name: "NoEd25519-TLS11-ServerAuth-Sign",
8526 config: Config{
8527 MaxVersion: VersionTLS11,
8528 },
8529 flags: []string{
8530 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8531 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8532 },
8533 shouldFail: true,
8534 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8535 })
8536 testCases = append(testCases, testCase{
8537 testType: serverTest,
8538 name: "NoEd25519-TLS11-ClientAuth-Verify",
8539 config: Config{
8540 MaxVersion: VersionTLS11,
8541 Certificates: []Certificate{ed25519Certificate},
8542 Bugs: ProtocolBugs{
8543 // Sign with Ed25519 even though it is TLS 1.1.
8544 UseLegacySigningAlgorithm: signatureEd25519,
8545 },
8546 },
8547 flags: []string{
8548 "-enable-ed25519",
8549 "-require-any-client-certificate",
8550 },
8551 shouldFail: true,
8552 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8553 })
8554 testCases = append(testCases, testCase{
8555 testType: clientTest,
8556 name: "NoEd25519-TLS11-ClientAuth-Sign",
8557 config: Config{
8558 MaxVersion: VersionTLS11,
8559 ClientAuth: RequireAnyClientCert,
8560 },
8561 flags: []string{
8562 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8563 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8564 },
8565 shouldFail: true,
8566 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8567 })
8568
8569 // Test Ed25519 is not advertised by default.
8570 testCases = append(testCases, testCase{
8571 testType: clientTest,
8572 name: "Ed25519DefaultDisable-NoAdvertise",
8573 config: Config{
8574 Certificates: []Certificate{ed25519Certificate},
8575 },
8576 shouldFail: true,
8577 expectedLocalError: "tls: no common signature algorithms",
8578 })
8579
8580 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8581 // preferences.
8582 testCases = append(testCases, testCase{
8583 testType: clientTest,
8584 name: "Ed25519DefaultDisable-NoAccept",
8585 config: Config{
8586 Certificates: []Certificate{ed25519Certificate},
8587 Bugs: ProtocolBugs{
8588 IgnorePeerSignatureAlgorithmPreferences: true,
8589 },
8590 },
8591 shouldFail: true,
8592 expectedLocalError: "remote error: illegal parameter",
8593 expectedError: ":WRONG_SIGNATURE_TYPE:",
8594 })
David Benjamin71c21b42017-04-14 17:05:40 -04008595
8596 // Test that configuring verify preferences changes what the client
8597 // advertises.
8598 testCases = append(testCases, testCase{
8599 name: "VerifyPreferences-Advertised",
8600 config: Config{
8601 Certificates: []Certificate{rsaCertificate},
8602 SignSignatureAlgorithms: []signatureAlgorithm{
8603 signatureRSAPSSWithSHA256,
8604 signatureRSAPSSWithSHA384,
8605 signatureRSAPSSWithSHA512,
8606 },
8607 },
8608 flags: []string{
8609 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8610 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8611 },
8612 })
8613
8614 // Test that the client advertises a set which the runner can find
8615 // nothing in common with.
8616 testCases = append(testCases, testCase{
8617 name: "VerifyPreferences-NoCommonAlgorithms",
8618 config: Config{
8619 Certificates: []Certificate{rsaCertificate},
8620 SignSignatureAlgorithms: []signatureAlgorithm{
8621 signatureRSAPSSWithSHA256,
8622 signatureRSAPSSWithSHA512,
8623 },
8624 },
8625 flags: []string{
8626 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8627 },
8628 shouldFail: true,
8629 expectedLocalError: "tls: no common signature algorithms",
8630 })
8631
8632 // Test that the client enforces its preferences when configured.
8633 testCases = append(testCases, testCase{
8634 name: "VerifyPreferences-Enforced",
8635 config: Config{
8636 Certificates: []Certificate{rsaCertificate},
8637 SignSignatureAlgorithms: []signatureAlgorithm{
8638 signatureRSAPSSWithSHA256,
8639 signatureRSAPSSWithSHA512,
8640 },
8641 Bugs: ProtocolBugs{
8642 IgnorePeerSignatureAlgorithmPreferences: true,
8643 },
8644 },
8645 flags: []string{
8646 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8647 },
8648 shouldFail: true,
8649 expectedLocalError: "remote error: illegal parameter",
8650 expectedError: ":WRONG_SIGNATURE_TYPE:",
8651 })
8652
8653 // Test that explicitly configuring Ed25519 is as good as changing the
8654 // boolean toggle.
8655 testCases = append(testCases, testCase{
8656 name: "VerifyPreferences-Ed25519",
8657 config: Config{
8658 Certificates: []Certificate{ed25519Certificate},
8659 },
8660 flags: []string{
8661 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8662 },
8663 })
David Benjamin000800a2014-11-14 01:43:59 -05008664}
8665
David Benjamin83f90402015-01-27 01:09:43 -05008666// timeouts is the retransmit schedule for BoringSSL. It doubles and
8667// caps at 60 seconds. On the 13th timeout, it gives up.
8668var timeouts = []time.Duration{
8669 1 * time.Second,
8670 2 * time.Second,
8671 4 * time.Second,
8672 8 * time.Second,
8673 16 * time.Second,
8674 32 * time.Second,
8675 60 * time.Second,
8676 60 * time.Second,
8677 60 * time.Second,
8678 60 * time.Second,
8679 60 * time.Second,
8680 60 * time.Second,
8681 60 * time.Second,
8682}
8683
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008684// shortTimeouts is an alternate set of timeouts which would occur if the
8685// initial timeout duration was set to 250ms.
8686var shortTimeouts = []time.Duration{
8687 250 * time.Millisecond,
8688 500 * time.Millisecond,
8689 1 * time.Second,
8690 2 * time.Second,
8691 4 * time.Second,
8692 8 * time.Second,
8693 16 * time.Second,
8694 32 * time.Second,
8695 60 * time.Second,
8696 60 * time.Second,
8697 60 * time.Second,
8698 60 * time.Second,
8699 60 * time.Second,
8700}
8701
David Benjamin83f90402015-01-27 01:09:43 -05008702func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008703 // These tests work by coordinating some behavior on both the shim and
8704 // the runner.
8705 //
8706 // TimeoutSchedule configures the runner to send a series of timeout
8707 // opcodes to the shim (see packetAdaptor) immediately before reading
8708 // each peer handshake flight N. The timeout opcode both simulates a
8709 // timeout in the shim and acts as a synchronization point to help the
8710 // runner bracket each handshake flight.
8711 //
8712 // We assume the shim does not read from the channel eagerly. It must
8713 // first wait until it has sent flight N and is ready to receive
8714 // handshake flight N+1. At this point, it will process the timeout
8715 // opcode. It must then immediately respond with a timeout ACK and act
8716 // as if the shim was idle for the specified amount of time.
8717 //
8718 // The runner then drops all packets received before the ACK and
8719 // continues waiting for flight N. This ordering results in one attempt
8720 // at sending flight N to be dropped. For the test to complete, the
8721 // shim must send flight N again, testing that the shim implements DTLS
8722 // retransmit on a timeout.
8723
Steven Valdez143e8b32016-07-11 13:19:03 -04008724 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008725 // likely be more epochs to cross and the final message's retransmit may
8726 // be more complex.
8727
David Benjamin11c82892017-02-23 20:40:31 -05008728 // Test that this is indeed the timeout schedule. Stress all
8729 // four patterns of handshake.
8730 for i := 1; i < len(timeouts); i++ {
8731 number := strconv.Itoa(i)
8732 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008733 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008734 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008736 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008737 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008738 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008739 },
8740 },
8741 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008742 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008743 })
David Benjamin11c82892017-02-23 20:40:31 -05008744 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008745 protocol: dtls,
8746 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008747 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008748 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008749 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008750 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008751 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008752 },
8753 },
8754 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008755 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008756 })
8757 }
David Benjamin11c82892017-02-23 20:40:31 -05008758
8759 // Test that exceeding the timeout schedule hits a read
8760 // timeout.
8761 testCases = append(testCases, testCase{
8762 protocol: dtls,
8763 name: "DTLS-Retransmit-Timeout",
8764 config: Config{
8765 MaxVersion: VersionTLS12,
8766 Bugs: ProtocolBugs{
8767 TimeoutSchedule: timeouts,
8768 },
8769 },
8770 resumeSession: true,
8771 flags: []string{"-async"},
8772 shouldFail: true,
8773 expectedError: ":READ_TIMEOUT_EXPIRED:",
8774 })
8775
8776 // Test that timeout handling has a fudge factor, due to API
8777 // problems.
8778 testCases = append(testCases, testCase{
8779 protocol: dtls,
8780 name: "DTLS-Retransmit-Fudge",
8781 config: Config{
8782 MaxVersion: VersionTLS12,
8783 Bugs: ProtocolBugs{
8784 TimeoutSchedule: []time.Duration{
8785 timeouts[0] - 10*time.Millisecond,
8786 },
8787 },
8788 },
8789 resumeSession: true,
8790 flags: []string{"-async"},
8791 })
8792
8793 // Test that the final Finished retransmitting isn't
8794 // duplicated if the peer badly fragments everything.
8795 testCases = append(testCases, testCase{
8796 testType: serverTest,
8797 protocol: dtls,
8798 name: "DTLS-Retransmit-Fragmented",
8799 config: Config{
8800 MaxVersion: VersionTLS12,
8801 Bugs: ProtocolBugs{
8802 TimeoutSchedule: []time.Duration{timeouts[0]},
8803 MaxHandshakeRecordLength: 2,
8804 },
8805 },
8806 flags: []string{"-async"},
8807 })
8808
8809 // Test the timeout schedule when a shorter initial timeout duration is set.
8810 testCases = append(testCases, testCase{
8811 protocol: dtls,
8812 name: "DTLS-Retransmit-Short-Client",
8813 config: Config{
8814 MaxVersion: VersionTLS12,
8815 Bugs: ProtocolBugs{
8816 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8817 },
8818 },
8819 resumeSession: true,
8820 flags: []string{
8821 "-async",
8822 "-initial-timeout-duration-ms", "250",
8823 },
8824 })
8825 testCases = append(testCases, testCase{
8826 protocol: dtls,
8827 testType: serverTest,
8828 name: "DTLS-Retransmit-Short-Server",
8829 config: Config{
8830 MaxVersion: VersionTLS12,
8831 Bugs: ProtocolBugs{
8832 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8833 },
8834 },
8835 resumeSession: true,
8836 flags: []string{
8837 "-async",
8838 "-initial-timeout-duration-ms", "250",
8839 },
8840 })
David Benjamin302b8182017-08-22 14:47:22 -07008841
8842 // If the shim sends the last Finished (server full or client resume
8843 // handshakes), it must retransmit that Finished when it sees a
8844 // post-handshake penultimate Finished from the runner. The above tests
8845 // cover this. Conversely, if the shim sends the penultimate Finished
8846 // (client full or server resume), test that it does not retransmit.
8847 testCases = append(testCases, testCase{
8848 protocol: dtls,
8849 testType: clientTest,
8850 name: "DTLS-StrayRetransmitFinished-ClientFull",
8851 config: Config{
8852 MaxVersion: VersionTLS12,
8853 Bugs: ProtocolBugs{
8854 RetransmitFinished: true,
8855 },
8856 },
8857 })
8858 testCases = append(testCases, testCase{
8859 protocol: dtls,
8860 testType: serverTest,
8861 name: "DTLS-StrayRetransmitFinished-ServerResume",
8862 config: Config{
8863 MaxVersion: VersionTLS12,
8864 },
8865 resumeConfig: &Config{
8866 MaxVersion: VersionTLS12,
8867 Bugs: ProtocolBugs{
8868 RetransmitFinished: true,
8869 },
8870 },
8871 resumeSession: true,
8872 })
David Benjamin83f90402015-01-27 01:09:43 -05008873}
8874
David Benjaminc565ebb2015-04-03 04:06:36 -04008875func addExportKeyingMaterialTests() {
8876 for _, vers := range tlsVersions {
8877 if vers.version == VersionSSL30 {
8878 continue
8879 }
8880 testCases = append(testCases, testCase{
8881 name: "ExportKeyingMaterial-" + vers.name,
8882 config: Config{
8883 MaxVersion: vers.version,
8884 },
David Benjamina5022392017-07-10 17:40:39 -04008885 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008886 exportKeyingMaterial: 1024,
8887 exportLabel: "label",
8888 exportContext: "context",
8889 useExportContext: true,
8890 })
8891 testCases = append(testCases, testCase{
8892 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8893 config: Config{
8894 MaxVersion: vers.version,
8895 },
David Benjamina5022392017-07-10 17:40:39 -04008896 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008897 exportKeyingMaterial: 1024,
8898 })
8899 testCases = append(testCases, testCase{
8900 name: "ExportKeyingMaterial-EmptyContext-" + 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 useExportContext: true,
8907 })
8908 testCases = append(testCases, testCase{
8909 name: "ExportKeyingMaterial-Small-" + vers.name,
8910 config: Config{
8911 MaxVersion: vers.version,
8912 },
David Benjamina5022392017-07-10 17:40:39 -04008913 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008914 exportKeyingMaterial: 1,
8915 exportLabel: "label",
8916 exportContext: "context",
8917 useExportContext: true,
8918 })
8919 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008920
David Benjaminc565ebb2015-04-03 04:06:36 -04008921 testCases = append(testCases, testCase{
8922 name: "ExportKeyingMaterial-SSL3",
8923 config: Config{
8924 MaxVersion: VersionSSL30,
8925 },
8926 exportKeyingMaterial: 1024,
8927 exportLabel: "label",
8928 exportContext: "context",
8929 useExportContext: true,
8930 shouldFail: true,
8931 expectedError: "failed to export keying material",
8932 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008933
8934 // Exporters work during a False Start.
8935 testCases = append(testCases, testCase{
8936 name: "ExportKeyingMaterial-FalseStart",
8937 config: Config{
8938 MaxVersion: VersionTLS12,
8939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8940 NextProtos: []string{"foo"},
8941 Bugs: ProtocolBugs{
8942 ExpectFalseStart: true,
8943 },
8944 },
8945 flags: []string{
8946 "-false-start",
8947 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008948 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008949 },
8950 shimWritesFirst: true,
8951 exportKeyingMaterial: 1024,
8952 exportLabel: "label",
8953 exportContext: "context",
8954 useExportContext: true,
8955 })
8956
8957 // Exporters do not work in the middle of a renegotiation. Test this by
8958 // triggering the exporter after every SSL_read call and configuring the
8959 // shim to run asynchronously.
8960 testCases = append(testCases, testCase{
8961 name: "ExportKeyingMaterial-Renegotiate",
8962 config: Config{
8963 MaxVersion: VersionTLS12,
8964 },
8965 renegotiate: 1,
8966 flags: []string{
8967 "-async",
8968 "-use-exporter-between-reads",
8969 "-renegotiate-freely",
8970 "-expect-total-renegotiations", "1",
8971 },
8972 shouldFail: true,
8973 expectedError: "failed to export keying material",
8974 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008975}
8976
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008977func addTLSUniqueTests() {
8978 for _, isClient := range []bool{false, true} {
8979 for _, isResumption := range []bool{false, true} {
8980 for _, hasEMS := range []bool{false, true} {
8981 var suffix string
8982 if isResumption {
8983 suffix = "Resume-"
8984 } else {
8985 suffix = "Full-"
8986 }
8987
8988 if hasEMS {
8989 suffix += "EMS-"
8990 } else {
8991 suffix += "NoEMS-"
8992 }
8993
8994 if isClient {
8995 suffix += "Client"
8996 } else {
8997 suffix += "Server"
8998 }
8999
9000 test := testCase{
9001 name: "TLSUnique-" + suffix,
9002 testTLSUnique: true,
9003 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009004 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009005 Bugs: ProtocolBugs{
9006 NoExtendedMasterSecret: !hasEMS,
9007 },
9008 },
9009 }
9010
9011 if isResumption {
9012 test.resumeSession = true
9013 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009014 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009015 Bugs: ProtocolBugs{
9016 NoExtendedMasterSecret: !hasEMS,
9017 },
9018 }
9019 }
9020
9021 if isResumption && !hasEMS {
9022 test.shouldFail = true
9023 test.expectedError = "failed to get tls-unique"
9024 }
9025
9026 testCases = append(testCases, test)
9027 }
9028 }
9029 }
9030}
9031
Adam Langley09505632015-07-30 18:10:13 -07009032func addCustomExtensionTests() {
9033 expectedContents := "custom extension"
9034 emptyString := ""
9035
9036 for _, isClient := range []bool{false, true} {
9037 suffix := "Server"
9038 flag := "-enable-server-custom-extension"
9039 testType := serverTest
9040 if isClient {
9041 suffix = "Client"
9042 flag = "-enable-client-custom-extension"
9043 testType = clientTest
9044 }
9045
9046 testCases = append(testCases, testCase{
9047 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009048 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009050 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009051 Bugs: ProtocolBugs{
9052 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009053 ExpectedCustomExtension: &expectedContents,
9054 },
9055 },
9056 flags: []string{flag},
9057 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009058 testCases = append(testCases, testCase{
9059 testType: testType,
9060 name: "CustomExtensions-" + suffix + "-TLS13",
9061 config: Config{
9062 MaxVersion: VersionTLS13,
9063 Bugs: ProtocolBugs{
9064 CustomExtension: expectedContents,
9065 ExpectedCustomExtension: &expectedContents,
9066 },
9067 },
9068 flags: []string{flag},
9069 })
Adam Langley09505632015-07-30 18:10:13 -07009070
9071 // If the parse callback fails, the handshake should also fail.
9072 testCases = append(testCases, testCase{
9073 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009074 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009076 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009077 Bugs: ProtocolBugs{
9078 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07009079 ExpectedCustomExtension: &expectedContents,
9080 },
9081 },
David Benjamin399e7c92015-07-30 23:01:27 -04009082 flags: []string{flag},
9083 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009084 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9085 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009086 testCases = append(testCases, testCase{
9087 testType: testType,
9088 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
9089 config: Config{
9090 MaxVersion: VersionTLS13,
9091 Bugs: ProtocolBugs{
9092 CustomExtension: expectedContents + "foo",
9093 ExpectedCustomExtension: &expectedContents,
9094 },
9095 },
9096 flags: []string{flag},
9097 shouldFail: true,
9098 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9099 })
Adam Langley09505632015-07-30 18:10:13 -07009100
9101 // If the add callback fails, the handshake should also fail.
9102 testCases = append(testCases, testCase{
9103 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009104 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009106 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009107 Bugs: ProtocolBugs{
9108 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07009109 ExpectedCustomExtension: &expectedContents,
9110 },
9111 },
David Benjamin399e7c92015-07-30 23:01:27 -04009112 flags: []string{flag, "-custom-extension-fail-add"},
9113 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07009114 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9115 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009116 testCases = append(testCases, testCase{
9117 testType: testType,
9118 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9119 config: Config{
9120 MaxVersion: VersionTLS13,
9121 Bugs: ProtocolBugs{
9122 CustomExtension: expectedContents,
9123 ExpectedCustomExtension: &expectedContents,
9124 },
9125 },
9126 flags: []string{flag, "-custom-extension-fail-add"},
9127 shouldFail: true,
9128 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9129 })
Adam Langley09505632015-07-30 18:10:13 -07009130
9131 // If the add callback returns zero, no extension should be
9132 // added.
9133 skipCustomExtension := expectedContents
9134 if isClient {
9135 // For the case where the client skips sending the
9136 // custom extension, the server must not “echo” it.
9137 skipCustomExtension = ""
9138 }
9139 testCases = append(testCases, testCase{
9140 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009141 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009143 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009144 Bugs: ProtocolBugs{
9145 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009146 ExpectedCustomExtension: &emptyString,
9147 },
9148 },
9149 flags: []string{flag, "-custom-extension-skip"},
9150 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009151 testCases = append(testCases, testCase{
9152 testType: testType,
9153 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9154 config: Config{
9155 MaxVersion: VersionTLS13,
9156 Bugs: ProtocolBugs{
9157 CustomExtension: skipCustomExtension,
9158 ExpectedCustomExtension: &emptyString,
9159 },
9160 },
9161 flags: []string{flag, "-custom-extension-skip"},
9162 })
Adam Langley09505632015-07-30 18:10:13 -07009163 }
9164
Steven Valdezf4ecc842017-08-10 14:02:56 -04009165 // If the client sends both early data and custom extension, the handshake
9166 // should succeed as long as both the extensions aren't returned by the
9167 // server.
9168 testCases = append(testCases, testCase{
9169 testType: clientTest,
9170 name: "CustomExtensions-Client-EarlyData-None",
9171 config: Config{
9172 MaxVersion: VersionTLS13,
9173 MaxEarlyDataSize: 16384,
9174 Bugs: ProtocolBugs{
9175 ExpectedCustomExtension: &expectedContents,
9176 AlwaysRejectEarlyData: true,
9177 },
9178 },
9179 resumeSession: true,
9180 flags: []string{
9181 "-enable-client-custom-extension",
9182 "-enable-early-data",
9183 "-expect-early-data-info",
9184 "-expect-reject-early-data",
9185 },
9186 })
9187
9188 testCases = append(testCases, testCase{
9189 testType: clientTest,
9190 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9191 config: Config{
9192 MaxVersion: VersionTLS13,
9193 MaxEarlyDataSize: 16384,
9194 Bugs: ProtocolBugs{
9195 ExpectedCustomExtension: &expectedContents,
9196 },
9197 },
9198 resumeSession: true,
9199 flags: []string{
9200 "-enable-client-custom-extension",
9201 "-enable-early-data",
9202 "-expect-early-data-info",
9203 "-expect-accept-early-data",
9204 },
9205 })
9206
9207 testCases = append(testCases, testCase{
9208 testType: clientTest,
9209 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9210 config: Config{
9211 MaxVersion: VersionTLS13,
9212 MaxEarlyDataSize: 16384,
9213 Bugs: ProtocolBugs{
9214 AlwaysRejectEarlyData: true,
9215 CustomExtension: expectedContents,
9216 ExpectedCustomExtension: &expectedContents,
9217 },
9218 },
9219 resumeSession: true,
9220 flags: []string{
9221 "-enable-client-custom-extension",
9222 "-enable-early-data",
9223 "-expect-early-data-info",
9224 "-expect-reject-early-data",
9225 },
9226 })
9227
9228 testCases = append(testCases, testCase{
9229 testType: clientTest,
9230 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9231 config: Config{
9232 MaxVersion: VersionTLS13,
9233 MaxEarlyDataSize: 16384,
9234 Bugs: ProtocolBugs{
9235 CustomExtension: expectedContents,
9236 ExpectedCustomExtension: &expectedContents,
9237 },
9238 },
9239 resumeConfig: &Config{
9240 MaxVersion: VersionTLS13,
9241 MaxEarlyDataSize: 16384,
9242 Bugs: ProtocolBugs{
9243 CustomExtension: expectedContents,
9244 ExpectedCustomExtension: &expectedContents,
9245 SendEarlyDataExtension: true,
9246 },
9247 },
9248 resumeSession: true,
9249 shouldFail: true,
9250 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9251 flags: []string{
9252 "-enable-client-custom-extension",
9253 "-enable-early-data",
9254 "-expect-early-data-info",
9255 },
9256 })
9257
9258 // If the server receives both early data and custom extension, only the
9259 // custom extension should be accepted.
9260 testCases = append(testCases, testCase{
9261 testType: serverTest,
9262 name: "CustomExtensions-Server-EarlyDataAccepted",
9263 config: Config{
9264 MaxVersion: VersionTLS13,
9265 MaxEarlyDataSize: 16384,
9266 Bugs: ProtocolBugs{
9267 CustomExtension: expectedContents,
9268 ExpectedCustomExtension: &expectedContents,
9269 ExpectEarlyDataAccepted: false,
9270 },
9271 },
9272 resumeSession: true,
9273 flags: []string{
9274 "-enable-server-custom-extension",
9275 "-enable-early-data",
9276 "-expect-early-data-info",
9277 },
9278 })
9279
Adam Langley09505632015-07-30 18:10:13 -07009280 // The custom extension add callback should not be called if the client
9281 // doesn't send the extension.
9282 testCases = append(testCases, testCase{
9283 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009284 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009286 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009287 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009288 ExpectedCustomExtension: &emptyString,
9289 },
9290 },
9291 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9292 })
Adam Langley2deb9842015-08-07 11:15:37 -07009293
Steven Valdez143e8b32016-07-11 13:19:03 -04009294 testCases = append(testCases, testCase{
9295 testType: serverTest,
9296 name: "CustomExtensions-NotCalled-Server-TLS13",
9297 config: Config{
9298 MaxVersion: VersionTLS13,
9299 Bugs: ProtocolBugs{
9300 ExpectedCustomExtension: &emptyString,
9301 },
9302 },
9303 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9304 })
9305
Adam Langley2deb9842015-08-07 11:15:37 -07009306 // Test an unknown extension from the server.
9307 testCases = append(testCases, testCase{
9308 testType: clientTest,
9309 name: "UnknownExtension-Client",
9310 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009311 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009312 Bugs: ProtocolBugs{
9313 CustomExtension: expectedContents,
9314 },
9315 },
David Benjamin0c40a962016-08-01 12:05:50 -04009316 shouldFail: true,
9317 expectedError: ":UNEXPECTED_EXTENSION:",
9318 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009319 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009320 testCases = append(testCases, testCase{
9321 testType: clientTest,
9322 name: "UnknownExtension-Client-TLS13",
9323 config: Config{
9324 MaxVersion: VersionTLS13,
9325 Bugs: ProtocolBugs{
9326 CustomExtension: expectedContents,
9327 },
9328 },
David Benjamin0c40a962016-08-01 12:05:50 -04009329 shouldFail: true,
9330 expectedError: ":UNEXPECTED_EXTENSION:",
9331 expectedLocalError: "remote error: unsupported extension",
9332 })
David Benjamin490469f2016-10-05 22:44:38 -04009333 testCases = append(testCases, testCase{
9334 testType: clientTest,
9335 name: "UnknownUnencryptedExtension-Client-TLS13",
9336 config: Config{
9337 MaxVersion: VersionTLS13,
9338 Bugs: ProtocolBugs{
9339 CustomUnencryptedExtension: expectedContents,
9340 },
9341 },
9342 shouldFail: true,
9343 expectedError: ":UNEXPECTED_EXTENSION:",
9344 // The shim must send an alert, but alerts at this point do not
9345 // get successfully decrypted by the runner.
9346 expectedLocalError: "local error: bad record MAC",
9347 })
9348 testCases = append(testCases, testCase{
9349 testType: clientTest,
9350 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9351 config: Config{
9352 MaxVersion: VersionTLS13,
9353 Bugs: ProtocolBugs{
9354 SendUnencryptedALPN: "foo",
9355 },
9356 },
9357 flags: []string{
9358 "-advertise-alpn", "\x03foo\x03bar",
9359 },
9360 shouldFail: true,
9361 expectedError: ":UNEXPECTED_EXTENSION:",
9362 // The shim must send an alert, but alerts at this point do not
9363 // get successfully decrypted by the runner.
9364 expectedLocalError: "local error: bad record MAC",
9365 })
David Benjamin0c40a962016-08-01 12:05:50 -04009366
9367 // Test a known but unoffered extension from the server.
9368 testCases = append(testCases, testCase{
9369 testType: clientTest,
9370 name: "UnofferedExtension-Client",
9371 config: Config{
9372 MaxVersion: VersionTLS12,
9373 Bugs: ProtocolBugs{
9374 SendALPN: "alpn",
9375 },
9376 },
9377 shouldFail: true,
9378 expectedError: ":UNEXPECTED_EXTENSION:",
9379 expectedLocalError: "remote error: unsupported extension",
9380 })
9381 testCases = append(testCases, testCase{
9382 testType: clientTest,
9383 name: "UnofferedExtension-Client-TLS13",
9384 config: Config{
9385 MaxVersion: VersionTLS13,
9386 Bugs: ProtocolBugs{
9387 SendALPN: "alpn",
9388 },
9389 },
9390 shouldFail: true,
9391 expectedError: ":UNEXPECTED_EXTENSION:",
9392 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009393 })
Adam Langley09505632015-07-30 18:10:13 -07009394}
9395
David Benjaminb36a3952015-12-01 18:53:13 -05009396func addRSAClientKeyExchangeTests() {
9397 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9398 testCases = append(testCases, testCase{
9399 testType: serverTest,
9400 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9401 config: Config{
9402 // Ensure the ClientHello version and final
9403 // version are different, to detect if the
9404 // server uses the wrong one.
9405 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009406 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009407 Bugs: ProtocolBugs{
9408 BadRSAClientKeyExchange: bad,
9409 },
9410 },
9411 shouldFail: true,
9412 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9413 })
9414 }
David Benjamine63d9d72016-09-19 18:27:34 -04009415
9416 // The server must compare whatever was in ClientHello.version for the
9417 // RSA premaster.
9418 testCases = append(testCases, testCase{
9419 testType: serverTest,
9420 name: "SendClientVersion-RSA",
9421 config: Config{
9422 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9423 Bugs: ProtocolBugs{
9424 SendClientVersion: 0x1234,
9425 },
9426 },
9427 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9428 })
David Benjaminb36a3952015-12-01 18:53:13 -05009429}
9430
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009431var testCurves = []struct {
9432 name string
9433 id CurveID
9434}{
Adam Langley764ab982017-03-10 18:01:30 -08009435 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009436 {"P-256", CurveP256},
9437 {"P-384", CurveP384},
9438 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009439 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009440}
9441
Steven Valdez5440fe02016-07-18 12:40:30 -04009442const bogusCurve = 0x1234
9443
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009444func addCurveTests() {
9445 for _, curve := range testCurves {
9446 testCases = append(testCases, testCase{
9447 name: "CurveTest-Client-" + curve.name,
9448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009449 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9451 CurvePreferences: []CurveID{curve.id},
9452 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009453 flags: []string{
9454 "-enable-all-curves",
9455 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9456 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009457 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009458 })
9459 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009460 name: "CurveTest-Client-" + curve.name + "-TLS13",
9461 config: Config{
9462 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009463 CurvePreferences: []CurveID{curve.id},
9464 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009465 flags: []string{
9466 "-enable-all-curves",
9467 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9468 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009469 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009470 })
9471 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009472 testType: serverTest,
9473 name: "CurveTest-Server-" + curve.name,
9474 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009475 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009476 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9477 CurvePreferences: []CurveID{curve.id},
9478 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009479 flags: []string{
9480 "-enable-all-curves",
9481 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9482 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009483 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009484 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009485 testCases = append(testCases, testCase{
9486 testType: serverTest,
9487 name: "CurveTest-Server-" + curve.name + "-TLS13",
9488 config: Config{
9489 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009490 CurvePreferences: []CurveID{curve.id},
9491 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009492 flags: []string{
9493 "-enable-all-curves",
9494 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9495 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009496 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009497 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009498 }
David Benjamin241ae832016-01-15 03:04:54 -05009499
9500 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009501 testCases = append(testCases, testCase{
9502 testType: serverTest,
9503 name: "UnknownCurve",
9504 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009505 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009506 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9507 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9508 },
9509 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009510
Steven Valdez803c77a2016-09-06 14:13:43 -04009511 // The server must be tolerant to bogus curves.
9512 testCases = append(testCases, testCase{
9513 testType: serverTest,
9514 name: "UnknownCurve-TLS13",
9515 config: Config{
9516 MaxVersion: VersionTLS13,
9517 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9518 },
9519 })
9520
David Benjamin4c3ddf72016-06-29 18:13:53 -04009521 // The server must not consider ECDHE ciphers when there are no
9522 // supported curves.
9523 testCases = append(testCases, testCase{
9524 testType: serverTest,
9525 name: "NoSupportedCurves",
9526 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009527 MaxVersion: VersionTLS12,
9528 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9529 Bugs: ProtocolBugs{
9530 NoSupportedCurves: true,
9531 },
9532 },
9533 shouldFail: true,
9534 expectedError: ":NO_SHARED_CIPHER:",
9535 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009536 testCases = append(testCases, testCase{
9537 testType: serverTest,
9538 name: "NoSupportedCurves-TLS13",
9539 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009540 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009541 Bugs: ProtocolBugs{
9542 NoSupportedCurves: true,
9543 },
9544 },
9545 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009546 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009547 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009548
9549 // The server must fall back to another cipher when there are no
9550 // supported curves.
9551 testCases = append(testCases, testCase{
9552 testType: serverTest,
9553 name: "NoCommonCurves",
9554 config: Config{
9555 MaxVersion: VersionTLS12,
9556 CipherSuites: []uint16{
9557 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009558 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009559 },
9560 CurvePreferences: []CurveID{CurveP224},
9561 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009562 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009563 })
9564
9565 // The client must reject bogus curves and disabled curves.
9566 testCases = append(testCases, testCase{
9567 name: "BadECDHECurve",
9568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009569 MaxVersion: VersionTLS12,
9570 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9571 Bugs: ProtocolBugs{
9572 SendCurve: bogusCurve,
9573 },
9574 },
9575 shouldFail: true,
9576 expectedError: ":WRONG_CURVE:",
9577 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009578 testCases = append(testCases, testCase{
9579 name: "BadECDHECurve-TLS13",
9580 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009581 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009582 Bugs: ProtocolBugs{
9583 SendCurve: bogusCurve,
9584 },
9585 },
9586 shouldFail: true,
9587 expectedError: ":WRONG_CURVE:",
9588 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009589
9590 testCases = append(testCases, testCase{
9591 name: "UnsupportedCurve",
9592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009593 MaxVersion: VersionTLS12,
9594 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9595 CurvePreferences: []CurveID{CurveP256},
9596 Bugs: ProtocolBugs{
9597 IgnorePeerCurvePreferences: true,
9598 },
9599 },
9600 flags: []string{"-p384-only"},
9601 shouldFail: true,
9602 expectedError: ":WRONG_CURVE:",
9603 })
9604
David Benjamin4f921572016-07-17 14:20:10 +02009605 testCases = append(testCases, testCase{
9606 // TODO(davidben): Add a TLS 1.3 version where
9607 // HelloRetryRequest requests an unsupported curve.
9608 name: "UnsupportedCurve-ServerHello-TLS13",
9609 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009610 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009611 CurvePreferences: []CurveID{CurveP384},
9612 Bugs: ProtocolBugs{
9613 SendCurve: CurveP256,
9614 },
9615 },
9616 flags: []string{"-p384-only"},
9617 shouldFail: true,
9618 expectedError: ":WRONG_CURVE:",
9619 })
9620
David Benjamin4c3ddf72016-06-29 18:13:53 -04009621 // Test invalid curve points.
9622 testCases = append(testCases, testCase{
9623 name: "InvalidECDHPoint-Client",
9624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009625 MaxVersion: VersionTLS12,
9626 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9627 CurvePreferences: []CurveID{CurveP256},
9628 Bugs: ProtocolBugs{
9629 InvalidECDHPoint: true,
9630 },
9631 },
9632 shouldFail: true,
9633 expectedError: ":INVALID_ENCODING:",
9634 })
9635 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009636 name: "InvalidECDHPoint-Client-TLS13",
9637 config: Config{
9638 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009639 CurvePreferences: []CurveID{CurveP256},
9640 Bugs: ProtocolBugs{
9641 InvalidECDHPoint: true,
9642 },
9643 },
9644 shouldFail: true,
9645 expectedError: ":INVALID_ENCODING:",
9646 })
9647 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009648 testType: serverTest,
9649 name: "InvalidECDHPoint-Server",
9650 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009651 MaxVersion: VersionTLS12,
9652 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9653 CurvePreferences: []CurveID{CurveP256},
9654 Bugs: ProtocolBugs{
9655 InvalidECDHPoint: true,
9656 },
9657 },
9658 shouldFail: true,
9659 expectedError: ":INVALID_ENCODING:",
9660 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009661 testCases = append(testCases, testCase{
9662 testType: serverTest,
9663 name: "InvalidECDHPoint-Server-TLS13",
9664 config: Config{
9665 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009666 CurvePreferences: []CurveID{CurveP256},
9667 Bugs: ProtocolBugs{
9668 InvalidECDHPoint: true,
9669 },
9670 },
9671 shouldFail: true,
9672 expectedError: ":INVALID_ENCODING:",
9673 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009674
9675 // The previous curve ID should be reported on TLS 1.2 resumption.
9676 testCases = append(testCases, testCase{
9677 name: "CurveID-Resume-Client",
9678 config: Config{
9679 MaxVersion: VersionTLS12,
9680 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9681 CurvePreferences: []CurveID{CurveX25519},
9682 },
9683 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9684 resumeSession: true,
9685 })
9686 testCases = append(testCases, testCase{
9687 testType: serverTest,
9688 name: "CurveID-Resume-Server",
9689 config: Config{
9690 MaxVersion: VersionTLS12,
9691 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9692 CurvePreferences: []CurveID{CurveX25519},
9693 },
9694 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9695 resumeSession: true,
9696 })
9697
9698 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9699 // one should be reported.
9700 testCases = append(testCases, testCase{
9701 name: "CurveID-Resume-Client-TLS13",
9702 config: Config{
9703 MaxVersion: VersionTLS13,
9704 CurvePreferences: []CurveID{CurveX25519},
9705 },
9706 resumeConfig: &Config{
9707 MaxVersion: VersionTLS13,
9708 CurvePreferences: []CurveID{CurveP256},
9709 },
9710 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009711 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9712 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009713 },
9714 resumeSession: true,
9715 })
9716 testCases = append(testCases, testCase{
9717 testType: serverTest,
9718 name: "CurveID-Resume-Server-TLS13",
9719 config: Config{
9720 MaxVersion: VersionTLS13,
9721 CurvePreferences: []CurveID{CurveX25519},
9722 },
9723 resumeConfig: &Config{
9724 MaxVersion: VersionTLS13,
9725 CurvePreferences: []CurveID{CurveP256},
9726 },
9727 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009728 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9729 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009730 },
9731 resumeSession: true,
9732 })
David Benjamina81967b2016-12-22 09:16:57 -05009733
9734 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9735 testCases = append(testCases, testCase{
9736 name: "PointFormat-ServerHello-TLS12",
9737 config: Config{
9738 MaxVersion: VersionTLS12,
9739 Bugs: ProtocolBugs{
9740 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9741 },
9742 },
9743 })
9744 testCases = append(testCases, testCase{
9745 name: "PointFormat-EncryptedExtensions-TLS13",
9746 config: Config{
9747 MaxVersion: VersionTLS13,
9748 Bugs: ProtocolBugs{
9749 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9750 },
9751 },
9752 shouldFail: true,
9753 expectedError: ":ERROR_PARSING_EXTENSION:",
9754 })
9755
9756 // Test that we tolerate unknown point formats, as long as
9757 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9758 // check they are still functional.
9759 testCases = append(testCases, testCase{
9760 name: "PointFormat-Client-Tolerance",
9761 config: Config{
9762 MaxVersion: VersionTLS12,
9763 Bugs: ProtocolBugs{
9764 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9765 },
9766 },
9767 })
9768 testCases = append(testCases, testCase{
9769 testType: serverTest,
9770 name: "PointFormat-Server-Tolerance",
9771 config: Config{
9772 MaxVersion: VersionTLS12,
9773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9774 Bugs: ProtocolBugs{
9775 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9776 },
9777 },
9778 })
9779
9780 // Test TLS 1.2 does not require the point format extension to be
9781 // present.
9782 testCases = append(testCases, testCase{
9783 name: "PointFormat-Client-Missing",
9784 config: Config{
9785 MaxVersion: VersionTLS12,
9786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9787 Bugs: ProtocolBugs{
9788 SendSupportedPointFormats: []byte{},
9789 },
9790 },
9791 })
9792 testCases = append(testCases, testCase{
9793 testType: serverTest,
9794 name: "PointFormat-Server-Missing",
9795 config: Config{
9796 MaxVersion: VersionTLS12,
9797 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9798 Bugs: ProtocolBugs{
9799 SendSupportedPointFormats: []byte{},
9800 },
9801 },
9802 })
9803
9804 // If the point format extension is present, uncompressed points must be
9805 // offered. BoringSSL requires this whether or not ECDHE is used.
9806 testCases = append(testCases, testCase{
9807 name: "PointFormat-Client-MissingUncompressed",
9808 config: Config{
9809 MaxVersion: VersionTLS12,
9810 Bugs: ProtocolBugs{
9811 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9812 },
9813 },
9814 shouldFail: true,
9815 expectedError: ":ERROR_PARSING_EXTENSION:",
9816 })
9817 testCases = append(testCases, testCase{
9818 testType: serverTest,
9819 name: "PointFormat-Server-MissingUncompressed",
9820 config: Config{
9821 MaxVersion: VersionTLS12,
9822 Bugs: ProtocolBugs{
9823 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9824 },
9825 },
9826 shouldFail: true,
9827 expectedError: ":ERROR_PARSING_EXTENSION:",
9828 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009829}
9830
David Benjaminc9ae27c2016-06-24 22:56:37 -04009831func addTLS13RecordTests() {
9832 testCases = append(testCases, testCase{
9833 name: "TLS13-RecordPadding",
9834 config: Config{
9835 MaxVersion: VersionTLS13,
9836 MinVersion: VersionTLS13,
9837 Bugs: ProtocolBugs{
9838 RecordPadding: 10,
9839 },
9840 },
9841 })
9842
9843 testCases = append(testCases, testCase{
9844 name: "TLS13-EmptyRecords",
9845 config: Config{
9846 MaxVersion: VersionTLS13,
9847 MinVersion: VersionTLS13,
9848 Bugs: ProtocolBugs{
9849 OmitRecordContents: true,
9850 },
9851 },
9852 shouldFail: true,
9853 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9854 })
9855
9856 testCases = append(testCases, testCase{
9857 name: "TLS13-OnlyPadding",
9858 config: Config{
9859 MaxVersion: VersionTLS13,
9860 MinVersion: VersionTLS13,
9861 Bugs: ProtocolBugs{
9862 OmitRecordContents: true,
9863 RecordPadding: 10,
9864 },
9865 },
9866 shouldFail: true,
9867 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9868 })
9869
9870 testCases = append(testCases, testCase{
9871 name: "TLS13-WrongOuterRecord",
9872 config: Config{
9873 MaxVersion: VersionTLS13,
9874 MinVersion: VersionTLS13,
9875 Bugs: ProtocolBugs{
9876 OuterRecordType: recordTypeHandshake,
9877 },
9878 },
9879 shouldFail: true,
9880 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9881 })
9882}
9883
Steven Valdez5b986082016-09-01 12:29:49 -04009884func addSessionTicketTests() {
9885 testCases = append(testCases, testCase{
9886 // In TLS 1.2 and below, empty NewSessionTicket messages
9887 // mean the server changed its mind on sending a ticket.
9888 name: "SendEmptySessionTicket",
9889 config: Config{
9890 MaxVersion: VersionTLS12,
9891 Bugs: ProtocolBugs{
9892 SendEmptySessionTicket: true,
9893 },
9894 },
9895 flags: []string{"-expect-no-session"},
9896 })
9897
9898 // Test that the server ignores unknown PSK modes.
9899 testCases = append(testCases, testCase{
9900 testType: serverTest,
9901 name: "TLS13-SendUnknownModeSessionTicket-Server",
9902 config: Config{
9903 MaxVersion: VersionTLS13,
9904 Bugs: ProtocolBugs{
9905 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009906 },
9907 },
9908 resumeSession: true,
9909 expectedResumeVersion: VersionTLS13,
9910 })
9911
Steven Valdeza833c352016-11-01 13:39:36 -04009912 // Test that the server does not send session tickets with no matching key exchange mode.
9913 testCases = append(testCases, testCase{
9914 testType: serverTest,
9915 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9916 config: Config{
9917 MaxVersion: VersionTLS13,
9918 Bugs: ProtocolBugs{
9919 SendPSKKeyExchangeModes: []byte{0x1a},
9920 ExpectNoNewSessionTicket: true,
9921 },
9922 },
9923 })
9924
9925 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009926 testCases = append(testCases, testCase{
9927 testType: serverTest,
9928 name: "TLS13-SendBadKEModeSessionTicket-Server",
9929 config: Config{
9930 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009931 },
9932 resumeConfig: &Config{
9933 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009934 Bugs: ProtocolBugs{
9935 SendPSKKeyExchangeModes: []byte{0x1a},
9936 },
9937 },
9938 resumeSession: true,
9939 expectResumeRejected: true,
9940 })
9941
Steven Valdeza833c352016-11-01 13:39:36 -04009942 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009943 testCases = append(testCases, testCase{
9944 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009945 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009946 config: Config{
9947 MaxVersion: VersionTLS13,
9948 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009949 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009950 },
9951 },
Steven Valdeza833c352016-11-01 13:39:36 -04009952 resumeSession: true,
9953 flags: []string{
9954 "-resumption-delay", "10",
9955 },
Steven Valdez5b986082016-09-01 12:29:49 -04009956 })
9957
Steven Valdeza833c352016-11-01 13:39:36 -04009958 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009959 testCases = append(testCases, testCase{
9960 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009961 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009962 config: Config{
9963 MaxVersion: VersionTLS13,
9964 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009965 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009966 },
9967 },
Steven Valdeza833c352016-11-01 13:39:36 -04009968 resumeSession: true,
9969 shouldFail: true,
9970 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009971 })
9972
David Benjamin35ac5b72017-03-03 15:05:56 -05009973 // Test that the server's ticket age skew reporting works.
9974 testCases = append(testCases, testCase{
9975 testType: serverTest,
9976 name: "TLS13-TicketAgeSkew-Forward",
9977 config: Config{
9978 MaxVersion: VersionTLS13,
9979 Bugs: ProtocolBugs{
9980 SendTicketAge: 15 * time.Second,
9981 },
9982 },
David Benjamin065d7332017-03-26 10:51:43 -05009983 resumeSession: true,
9984 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009985 flags: []string{
9986 "-resumption-delay", "10",
9987 "-expect-ticket-age-skew", "5",
9988 },
9989 })
9990 testCases = append(testCases, testCase{
9991 testType: serverTest,
9992 name: "TLS13-TicketAgeSkew-Backward",
9993 config: Config{
9994 MaxVersion: VersionTLS13,
9995 Bugs: ProtocolBugs{
9996 SendTicketAge: 5 * time.Second,
9997 },
9998 },
David Benjamin065d7332017-03-26 10:51:43 -05009999 resumeSession: true,
10000 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -050010001 flags: []string{
10002 "-resumption-delay", "10",
10003 "-expect-ticket-age-skew", "-5",
10004 },
10005 })
10006
Steven Valdez08b65f42016-12-07 15:29:45 -050010007 testCases = append(testCases, testCase{
10008 testType: clientTest,
10009 name: "TLS13-SendTicketEarlyDataInfo",
10010 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -080010011 MaxVersion: VersionTLS13,
10012 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -050010013 },
10014 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -050010015 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -050010016 "-expect-early-data-info",
10017 },
10018 })
10019
David Benjamin9b160662017-01-25 19:53:43 -050010020 // Test that 0-RTT tickets are ignored in clients unless opted in.
10021 testCases = append(testCases, testCase{
10022 testType: clientTest,
10023 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
10024 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -080010025 MaxVersion: VersionTLS13,
10026 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -050010027 },
10028 })
10029
Steven Valdez08b65f42016-12-07 15:29:45 -050010030 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -050010031 testType: clientTest,
10032 name: "TLS13-DuplicateTicketEarlyDataInfo",
10033 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -080010034 MaxVersion: VersionTLS13,
10035 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -050010036 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -050010037 DuplicateTicketEarlyDataInfo: true,
10038 },
10039 },
10040 shouldFail: true,
10041 expectedError: ":DUPLICATE_EXTENSION:",
10042 expectedLocalError: "remote error: illegal parameter",
10043 })
10044
10045 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -050010046 testType: serverTest,
10047 name: "TLS13-ExpectTicketEarlyDataInfo",
10048 config: Config{
10049 MaxVersion: VersionTLS13,
10050 Bugs: ProtocolBugs{
10051 ExpectTicketEarlyDataInfo: true,
10052 },
10053 },
10054 flags: []string{
10055 "-enable-early-data",
10056 },
10057 })
David Benjamin17b30832017-01-28 14:00:32 -050010058
10059 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
10060 // is honored.
10061 testCases = append(testCases, testCase{
10062 testType: clientTest,
10063 name: "TLS13-HonorServerSessionTicketLifetime",
10064 config: Config{
10065 MaxVersion: VersionTLS13,
10066 Bugs: ProtocolBugs{
10067 SendTicketLifetime: 20 * time.Second,
10068 },
10069 },
10070 flags: []string{
10071 "-resumption-delay", "19",
10072 },
10073 resumeSession: true,
10074 })
10075 testCases = append(testCases, testCase{
10076 testType: clientTest,
10077 name: "TLS13-HonorServerSessionTicketLifetime-2",
10078 config: Config{
10079 MaxVersion: VersionTLS13,
10080 Bugs: ProtocolBugs{
10081 SendTicketLifetime: 20 * time.Second,
10082 // The client should not offer the expired session.
10083 ExpectNoTLS13PSK: true,
10084 },
10085 },
10086 flags: []string{
10087 "-resumption-delay", "21",
10088 },
David Benjamin023d4192017-02-06 13:49:07 -050010089 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -050010090 expectResumeRejected: true,
10091 })
Steven Valdez5b986082016-09-01 12:29:49 -040010092}
10093
David Benjamin82261be2016-07-07 14:32:50 -070010094func addChangeCipherSpecTests() {
10095 // Test missing ChangeCipherSpecs.
10096 testCases = append(testCases, testCase{
10097 name: "SkipChangeCipherSpec-Client",
10098 config: Config{
10099 MaxVersion: VersionTLS12,
10100 Bugs: ProtocolBugs{
10101 SkipChangeCipherSpec: true,
10102 },
10103 },
10104 shouldFail: true,
10105 expectedError: ":UNEXPECTED_RECORD:",
10106 })
10107 testCases = append(testCases, testCase{
10108 testType: serverTest,
10109 name: "SkipChangeCipherSpec-Server",
10110 config: Config{
10111 MaxVersion: VersionTLS12,
10112 Bugs: ProtocolBugs{
10113 SkipChangeCipherSpec: true,
10114 },
10115 },
10116 shouldFail: true,
10117 expectedError: ":UNEXPECTED_RECORD:",
10118 })
10119 testCases = append(testCases, testCase{
10120 testType: serverTest,
10121 name: "SkipChangeCipherSpec-Server-NPN",
10122 config: Config{
10123 MaxVersion: VersionTLS12,
10124 NextProtos: []string{"bar"},
10125 Bugs: ProtocolBugs{
10126 SkipChangeCipherSpec: true,
10127 },
10128 },
10129 flags: []string{
10130 "-advertise-npn", "\x03foo\x03bar\x03baz",
10131 },
10132 shouldFail: true,
10133 expectedError: ":UNEXPECTED_RECORD:",
10134 })
10135
10136 // Test synchronization between the handshake and ChangeCipherSpec.
10137 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10138 // rejected. Test both with and without handshake packing to handle both
10139 // when the partial post-CCS message is in its own record and when it is
10140 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010141 for _, packed := range []bool{false, true} {
10142 var suffix string
10143 if packed {
10144 suffix = "-Packed"
10145 }
10146
10147 testCases = append(testCases, testCase{
10148 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10149 config: Config{
10150 MaxVersion: VersionTLS12,
10151 Bugs: ProtocolBugs{
10152 FragmentAcrossChangeCipherSpec: true,
10153 PackHandshakeFlight: packed,
10154 },
10155 },
10156 shouldFail: true,
10157 expectedError: ":UNEXPECTED_RECORD:",
10158 })
10159 testCases = append(testCases, testCase{
10160 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10161 config: Config{
10162 MaxVersion: VersionTLS12,
10163 },
10164 resumeSession: true,
10165 resumeConfig: &Config{
10166 MaxVersion: VersionTLS12,
10167 Bugs: ProtocolBugs{
10168 FragmentAcrossChangeCipherSpec: true,
10169 PackHandshakeFlight: packed,
10170 },
10171 },
10172 shouldFail: true,
10173 expectedError: ":UNEXPECTED_RECORD:",
10174 })
10175 testCases = append(testCases, testCase{
10176 testType: serverTest,
10177 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10178 config: Config{
10179 MaxVersion: VersionTLS12,
10180 Bugs: ProtocolBugs{
10181 FragmentAcrossChangeCipherSpec: true,
10182 PackHandshakeFlight: packed,
10183 },
10184 },
10185 shouldFail: true,
10186 expectedError: ":UNEXPECTED_RECORD:",
10187 })
10188 testCases = append(testCases, testCase{
10189 testType: serverTest,
10190 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10191 config: Config{
10192 MaxVersion: VersionTLS12,
10193 },
10194 resumeSession: true,
10195 resumeConfig: &Config{
10196 MaxVersion: VersionTLS12,
10197 Bugs: ProtocolBugs{
10198 FragmentAcrossChangeCipherSpec: true,
10199 PackHandshakeFlight: packed,
10200 },
10201 },
10202 shouldFail: true,
10203 expectedError: ":UNEXPECTED_RECORD:",
10204 })
10205 testCases = append(testCases, testCase{
10206 testType: serverTest,
10207 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10208 config: Config{
10209 MaxVersion: VersionTLS12,
10210 NextProtos: []string{"bar"},
10211 Bugs: ProtocolBugs{
10212 FragmentAcrossChangeCipherSpec: true,
10213 PackHandshakeFlight: packed,
10214 },
10215 },
10216 flags: []string{
10217 "-advertise-npn", "\x03foo\x03bar\x03baz",
10218 },
10219 shouldFail: true,
10220 expectedError: ":UNEXPECTED_RECORD:",
10221 })
10222 }
10223
David Benjamin61672812016-07-14 23:10:43 -040010224 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10225 // messages in the handshake queue. Do this by testing the server
10226 // reading the client Finished, reversing the flight so Finished comes
10227 // first.
10228 testCases = append(testCases, testCase{
10229 protocol: dtls,
10230 testType: serverTest,
10231 name: "SendUnencryptedFinished-DTLS",
10232 config: Config{
10233 MaxVersion: VersionTLS12,
10234 Bugs: ProtocolBugs{
10235 SendUnencryptedFinished: true,
10236 ReverseHandshakeFragments: true,
10237 },
10238 },
10239 shouldFail: true,
10240 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10241 })
10242
Steven Valdez143e8b32016-07-11 13:19:03 -040010243 // Test synchronization between encryption changes and the handshake in
10244 // TLS 1.3, where ChangeCipherSpec is implicit.
10245 testCases = append(testCases, testCase{
10246 name: "PartialEncryptedExtensionsWithServerHello",
10247 config: Config{
10248 MaxVersion: VersionTLS13,
10249 Bugs: ProtocolBugs{
10250 PartialEncryptedExtensionsWithServerHello: true,
10251 },
10252 },
10253 shouldFail: true,
10254 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10255 })
10256 testCases = append(testCases, testCase{
10257 testType: serverTest,
10258 name: "PartialClientFinishedWithClientHello",
10259 config: Config{
10260 MaxVersion: VersionTLS13,
10261 Bugs: ProtocolBugs{
10262 PartialClientFinishedWithClientHello: true,
10263 },
10264 },
10265 shouldFail: true,
10266 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10267 })
10268
David Benjamin82261be2016-07-07 14:32:50 -070010269 // Test that early ChangeCipherSpecs are handled correctly.
10270 testCases = append(testCases, testCase{
10271 testType: serverTest,
10272 name: "EarlyChangeCipherSpec-server-1",
10273 config: Config{
10274 MaxVersion: VersionTLS12,
10275 Bugs: ProtocolBugs{
10276 EarlyChangeCipherSpec: 1,
10277 },
10278 },
10279 shouldFail: true,
10280 expectedError: ":UNEXPECTED_RECORD:",
10281 })
10282 testCases = append(testCases, testCase{
10283 testType: serverTest,
10284 name: "EarlyChangeCipherSpec-server-2",
10285 config: Config{
10286 MaxVersion: VersionTLS12,
10287 Bugs: ProtocolBugs{
10288 EarlyChangeCipherSpec: 2,
10289 },
10290 },
10291 shouldFail: true,
10292 expectedError: ":UNEXPECTED_RECORD:",
10293 })
10294 testCases = append(testCases, testCase{
10295 protocol: dtls,
10296 name: "StrayChangeCipherSpec",
10297 config: Config{
10298 // TODO(davidben): Once DTLS 1.3 exists, test
10299 // that stray ChangeCipherSpec messages are
10300 // rejected.
10301 MaxVersion: VersionTLS12,
10302 Bugs: ProtocolBugs{
10303 StrayChangeCipherSpec: true,
10304 },
10305 },
10306 })
10307
David Benjaminb0c761e2017-06-25 22:42:55 -040010308 // Test that reordered ChangeCipherSpecs are tolerated.
10309 testCases = append(testCases, testCase{
10310 protocol: dtls,
10311 name: "ReorderChangeCipherSpec-DTLS-Client",
10312 config: Config{
10313 MaxVersion: VersionTLS12,
10314 Bugs: ProtocolBugs{
10315 ReorderChangeCipherSpec: true,
10316 },
10317 },
10318 resumeSession: true,
10319 })
10320 testCases = append(testCases, testCase{
10321 testType: serverTest,
10322 protocol: dtls,
10323 name: "ReorderChangeCipherSpec-DTLS-Server",
10324 config: Config{
10325 MaxVersion: VersionTLS12,
10326 Bugs: ProtocolBugs{
10327 ReorderChangeCipherSpec: true,
10328 },
10329 },
10330 resumeSession: true,
10331 })
10332
David Benjamin82261be2016-07-07 14:32:50 -070010333 // Test that the contents of ChangeCipherSpec are checked.
10334 testCases = append(testCases, testCase{
10335 name: "BadChangeCipherSpec-1",
10336 config: Config{
10337 MaxVersion: VersionTLS12,
10338 Bugs: ProtocolBugs{
10339 BadChangeCipherSpec: []byte{2},
10340 },
10341 },
10342 shouldFail: true,
10343 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10344 })
10345 testCases = append(testCases, testCase{
10346 name: "BadChangeCipherSpec-2",
10347 config: Config{
10348 MaxVersion: VersionTLS12,
10349 Bugs: ProtocolBugs{
10350 BadChangeCipherSpec: []byte{1, 1},
10351 },
10352 },
10353 shouldFail: true,
10354 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10355 })
10356 testCases = append(testCases, testCase{
10357 protocol: dtls,
10358 name: "BadChangeCipherSpec-DTLS-1",
10359 config: Config{
10360 MaxVersion: VersionTLS12,
10361 Bugs: ProtocolBugs{
10362 BadChangeCipherSpec: []byte{2},
10363 },
10364 },
10365 shouldFail: true,
10366 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10367 })
10368 testCases = append(testCases, testCase{
10369 protocol: dtls,
10370 name: "BadChangeCipherSpec-DTLS-2",
10371 config: Config{
10372 MaxVersion: VersionTLS12,
10373 Bugs: ProtocolBugs{
10374 BadChangeCipherSpec: []byte{1, 1},
10375 },
10376 },
10377 shouldFail: true,
10378 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10379 })
10380}
10381
David Benjamincd2c8062016-09-09 11:28:16 -040010382type perMessageTest struct {
10383 messageType uint8
10384 test testCase
10385}
10386
10387// makePerMessageTests returns a series of test templates which cover each
10388// message in the TLS handshake. These may be used with bugs like
10389// WrongMessageType to fully test a per-message bug.
10390func makePerMessageTests() []perMessageTest {
10391 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010392 for _, protocol := range []protocol{tls, dtls} {
10393 var suffix string
10394 if protocol == dtls {
10395 suffix = "-DTLS"
10396 }
10397
David Benjamincd2c8062016-09-09 11:28:16 -040010398 ret = append(ret, perMessageTest{
10399 messageType: typeClientHello,
10400 test: testCase{
10401 protocol: protocol,
10402 testType: serverTest,
10403 name: "ClientHello" + suffix,
10404 config: Config{
10405 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010406 },
10407 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010408 })
10409
10410 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010411 ret = append(ret, perMessageTest{
10412 messageType: typeHelloVerifyRequest,
10413 test: testCase{
10414 protocol: protocol,
10415 name: "HelloVerifyRequest" + suffix,
10416 config: Config{
10417 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010418 },
10419 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010420 })
10421 }
10422
David Benjamincd2c8062016-09-09 11:28:16 -040010423 ret = append(ret, perMessageTest{
10424 messageType: typeServerHello,
10425 test: testCase{
10426 protocol: protocol,
10427 name: "ServerHello" + suffix,
10428 config: Config{
10429 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010430 },
10431 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010432 })
10433
David Benjamincd2c8062016-09-09 11:28:16 -040010434 ret = append(ret, perMessageTest{
10435 messageType: typeCertificate,
10436 test: testCase{
10437 protocol: protocol,
10438 name: "ServerCertificate" + suffix,
10439 config: Config{
10440 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010441 },
10442 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010443 })
10444
David Benjamincd2c8062016-09-09 11:28:16 -040010445 ret = append(ret, perMessageTest{
10446 messageType: typeCertificateStatus,
10447 test: testCase{
10448 protocol: protocol,
10449 name: "CertificateStatus" + suffix,
10450 config: Config{
10451 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010452 },
David Benjamincd2c8062016-09-09 11:28:16 -040010453 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010454 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010455 })
10456
David Benjamincd2c8062016-09-09 11:28:16 -040010457 ret = append(ret, perMessageTest{
10458 messageType: typeServerKeyExchange,
10459 test: testCase{
10460 protocol: protocol,
10461 name: "ServerKeyExchange" + suffix,
10462 config: Config{
10463 MaxVersion: VersionTLS12,
10464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010465 },
10466 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010467 })
10468
David Benjamincd2c8062016-09-09 11:28:16 -040010469 ret = append(ret, perMessageTest{
10470 messageType: typeCertificateRequest,
10471 test: testCase{
10472 protocol: protocol,
10473 name: "CertificateRequest" + suffix,
10474 config: Config{
10475 MaxVersion: VersionTLS12,
10476 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010477 },
10478 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010479 })
10480
David Benjamincd2c8062016-09-09 11:28:16 -040010481 ret = append(ret, perMessageTest{
10482 messageType: typeServerHelloDone,
10483 test: testCase{
10484 protocol: protocol,
10485 name: "ServerHelloDone" + suffix,
10486 config: Config{
10487 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010488 },
10489 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010490 })
10491
David Benjamincd2c8062016-09-09 11:28:16 -040010492 ret = append(ret, perMessageTest{
10493 messageType: typeCertificate,
10494 test: testCase{
10495 testType: serverTest,
10496 protocol: protocol,
10497 name: "ClientCertificate" + suffix,
10498 config: Config{
10499 Certificates: []Certificate{rsaCertificate},
10500 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010501 },
David Benjamincd2c8062016-09-09 11:28:16 -040010502 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010503 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010504 })
10505
David Benjamincd2c8062016-09-09 11:28:16 -040010506 ret = append(ret, perMessageTest{
10507 messageType: typeCertificateVerify,
10508 test: testCase{
10509 testType: serverTest,
10510 protocol: protocol,
10511 name: "CertificateVerify" + suffix,
10512 config: Config{
10513 Certificates: []Certificate{rsaCertificate},
10514 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010515 },
David Benjamincd2c8062016-09-09 11:28:16 -040010516 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010517 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010518 })
10519
David Benjamincd2c8062016-09-09 11:28:16 -040010520 ret = append(ret, perMessageTest{
10521 messageType: typeClientKeyExchange,
10522 test: testCase{
10523 testType: serverTest,
10524 protocol: protocol,
10525 name: "ClientKeyExchange" + suffix,
10526 config: Config{
10527 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010528 },
10529 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010530 })
10531
10532 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010533 ret = append(ret, perMessageTest{
10534 messageType: typeNextProtocol,
10535 test: testCase{
10536 testType: serverTest,
10537 protocol: protocol,
10538 name: "NextProtocol" + suffix,
10539 config: Config{
10540 MaxVersion: VersionTLS12,
10541 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010542 },
David Benjamincd2c8062016-09-09 11:28:16 -040010543 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010544 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010545 })
10546
David Benjamincd2c8062016-09-09 11:28:16 -040010547 ret = append(ret, perMessageTest{
10548 messageType: typeChannelID,
10549 test: testCase{
10550 testType: serverTest,
10551 protocol: protocol,
10552 name: "ChannelID" + suffix,
10553 config: Config{
10554 MaxVersion: VersionTLS12,
10555 ChannelID: channelIDKey,
10556 },
10557 flags: []string{
10558 "-expect-channel-id",
10559 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010560 },
10561 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010562 })
10563 }
10564
David Benjamincd2c8062016-09-09 11:28:16 -040010565 ret = append(ret, perMessageTest{
10566 messageType: typeFinished,
10567 test: testCase{
10568 testType: serverTest,
10569 protocol: protocol,
10570 name: "ClientFinished" + suffix,
10571 config: Config{
10572 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010573 },
10574 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010575 })
10576
David Benjamincd2c8062016-09-09 11:28:16 -040010577 ret = append(ret, perMessageTest{
10578 messageType: typeNewSessionTicket,
10579 test: testCase{
10580 protocol: protocol,
10581 name: "NewSessionTicket" + suffix,
10582 config: Config{
10583 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010584 },
10585 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010586 })
10587
David Benjamincd2c8062016-09-09 11:28:16 -040010588 ret = append(ret, perMessageTest{
10589 messageType: typeFinished,
10590 test: testCase{
10591 protocol: protocol,
10592 name: "ServerFinished" + suffix,
10593 config: Config{
10594 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010595 },
10596 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010597 })
10598
10599 }
David Benjamincd2c8062016-09-09 11:28:16 -040010600
10601 ret = append(ret, perMessageTest{
10602 messageType: typeClientHello,
10603 test: testCase{
10604 testType: serverTest,
10605 name: "TLS13-ClientHello",
10606 config: Config{
10607 MaxVersion: VersionTLS13,
10608 },
10609 },
10610 })
10611
10612 ret = append(ret, perMessageTest{
10613 messageType: typeServerHello,
10614 test: testCase{
10615 name: "TLS13-ServerHello",
10616 config: Config{
10617 MaxVersion: VersionTLS13,
10618 },
10619 },
10620 })
10621
10622 ret = append(ret, perMessageTest{
10623 messageType: typeEncryptedExtensions,
10624 test: testCase{
10625 name: "TLS13-EncryptedExtensions",
10626 config: Config{
10627 MaxVersion: VersionTLS13,
10628 },
10629 },
10630 })
10631
10632 ret = append(ret, perMessageTest{
10633 messageType: typeCertificateRequest,
10634 test: testCase{
10635 name: "TLS13-CertificateRequest",
10636 config: Config{
10637 MaxVersion: VersionTLS13,
10638 ClientAuth: RequireAnyClientCert,
10639 },
10640 },
10641 })
10642
10643 ret = append(ret, perMessageTest{
10644 messageType: typeCertificate,
10645 test: testCase{
10646 name: "TLS13-ServerCertificate",
10647 config: Config{
10648 MaxVersion: VersionTLS13,
10649 },
10650 },
10651 })
10652
10653 ret = append(ret, perMessageTest{
10654 messageType: typeCertificateVerify,
10655 test: testCase{
10656 name: "TLS13-ServerCertificateVerify",
10657 config: Config{
10658 MaxVersion: VersionTLS13,
10659 },
10660 },
10661 })
10662
10663 ret = append(ret, perMessageTest{
10664 messageType: typeFinished,
10665 test: testCase{
10666 name: "TLS13-ServerFinished",
10667 config: Config{
10668 MaxVersion: VersionTLS13,
10669 },
10670 },
10671 })
10672
10673 ret = append(ret, perMessageTest{
10674 messageType: typeCertificate,
10675 test: testCase{
10676 testType: serverTest,
10677 name: "TLS13-ClientCertificate",
10678 config: Config{
10679 Certificates: []Certificate{rsaCertificate},
10680 MaxVersion: VersionTLS13,
10681 },
10682 flags: []string{"-require-any-client-certificate"},
10683 },
10684 })
10685
10686 ret = append(ret, perMessageTest{
10687 messageType: typeCertificateVerify,
10688 test: testCase{
10689 testType: serverTest,
10690 name: "TLS13-ClientCertificateVerify",
10691 config: Config{
10692 Certificates: []Certificate{rsaCertificate},
10693 MaxVersion: VersionTLS13,
10694 },
10695 flags: []string{"-require-any-client-certificate"},
10696 },
10697 })
10698
10699 ret = append(ret, perMessageTest{
10700 messageType: typeFinished,
10701 test: testCase{
10702 testType: serverTest,
10703 name: "TLS13-ClientFinished",
10704 config: Config{
10705 MaxVersion: VersionTLS13,
10706 },
10707 },
10708 })
10709
10710 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010711}
10712
David Benjamincd2c8062016-09-09 11:28:16 -040010713func addWrongMessageTypeTests() {
10714 for _, t := range makePerMessageTests() {
10715 t.test.name = "WrongMessageType-" + t.test.name
10716 t.test.config.Bugs.SendWrongMessageType = t.messageType
10717 t.test.shouldFail = true
10718 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10719 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010720
David Benjamincd2c8062016-09-09 11:28:16 -040010721 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10722 // In TLS 1.3, a bad ServerHello means the client sends
10723 // an unencrypted alert while the server expects
10724 // encryption, so the alert is not readable by runner.
10725 t.test.expectedLocalError = "local error: bad record MAC"
10726 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010727
David Benjamincd2c8062016-09-09 11:28:16 -040010728 testCases = append(testCases, t.test)
10729 }
David Benjaminebacdee2017-04-08 11:00:45 -040010730
10731 // The processing order for TLS 1.3 version negotiation is such that one
10732 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10733 // TLS 1.2. Test that we do not do this.
10734 testCases = append(testCases, testCase{
10735 name: "SendServerHelloAsHelloRetryRequest",
10736 config: Config{
10737 MaxVersion: VersionTLS12,
10738 Bugs: ProtocolBugs{
10739 SendServerHelloAsHelloRetryRequest: true,
10740 },
10741 },
10742 shouldFail: true,
10743 expectedError: ":UNEXPECTED_MESSAGE:",
10744 expectedLocalError: "remote error: unexpected message",
10745 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010746}
10747
David Benjamin639846e2016-09-09 11:41:18 -040010748func addTrailingMessageDataTests() {
10749 for _, t := range makePerMessageTests() {
10750 t.test.name = "TrailingMessageData-" + t.test.name
10751 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10752 t.test.shouldFail = true
10753 t.test.expectedError = ":DECODE_ERROR:"
10754 t.test.expectedLocalError = "remote error: error decoding message"
10755
10756 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10757 // In TLS 1.3, a bad ServerHello means the client sends
10758 // an unencrypted alert while the server expects
10759 // encryption, so the alert is not readable by runner.
10760 t.test.expectedLocalError = "local error: bad record MAC"
10761 }
10762
10763 if t.messageType == typeFinished {
10764 // Bad Finished messages read as the verify data having
10765 // the wrong length.
10766 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10767 t.test.expectedLocalError = "remote error: error decrypting message"
10768 }
10769
10770 testCases = append(testCases, t.test)
10771 }
10772}
10773
Steven Valdez143e8b32016-07-11 13:19:03 -040010774func addTLS13HandshakeTests() {
10775 testCases = append(testCases, testCase{
10776 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010777 name: "NegotiatePSKResumption-TLS13",
10778 config: Config{
10779 MaxVersion: VersionTLS13,
10780 Bugs: ProtocolBugs{
10781 NegotiatePSKResumption: true,
10782 },
10783 },
10784 resumeSession: true,
10785 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010786 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010787 })
10788
10789 testCases = append(testCases, testCase{
10790 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010791 name: "MissingKeyShare-Client",
10792 config: Config{
10793 MaxVersion: VersionTLS13,
10794 Bugs: ProtocolBugs{
10795 MissingKeyShare: true,
10796 },
10797 },
10798 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010799 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010800 })
10801
10802 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010803 testType: serverTest,
10804 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010805 config: Config{
10806 MaxVersion: VersionTLS13,
10807 Bugs: ProtocolBugs{
10808 MissingKeyShare: true,
10809 },
10810 },
10811 shouldFail: true,
10812 expectedError: ":MISSING_KEY_SHARE:",
10813 })
10814
10815 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010816 testType: serverTest,
10817 name: "DuplicateKeyShares",
10818 config: Config{
10819 MaxVersion: VersionTLS13,
10820 Bugs: ProtocolBugs{
10821 DuplicateKeyShares: true,
10822 },
10823 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010824 shouldFail: true,
10825 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010826 })
10827
10828 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010829 testType: serverTest,
10830 name: "SkipEarlyData",
10831 config: Config{
10832 MaxVersion: VersionTLS13,
10833 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010834 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010835 },
10836 },
10837 })
10838
10839 testCases = append(testCases, testCase{
10840 testType: serverTest,
David Benjamina5022392017-07-10 17:40:39 -040010841 name: "SkipEarlyData-TLS13Experiment",
Steven Valdez520e1222017-06-13 12:45:25 -040010842 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010843 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040010844 Bugs: ProtocolBugs{
10845 SendFakeEarlyDataLength: 4,
10846 },
10847 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010848 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040010849 })
10850
10851 testCases = append(testCases, testCase{
10852 testType: serverTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040010853 name: "SkipEarlyData-TLS13RecordTypeExperiment",
10854 config: Config{
David Benjaminf6ae9e62017-08-08 20:04:41 -040010855 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040010856 Bugs: ProtocolBugs{
10857 SendFakeEarlyDataLength: 4,
10858 },
10859 },
David Benjaminf6ae9e62017-08-08 20:04:41 -040010860 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040010861 })
10862
10863 testCases = append(testCases, testCase{
10864 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010865 name: "SkipEarlyData-OmitEarlyDataExtension",
10866 config: Config{
10867 MaxVersion: VersionTLS13,
10868 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010869 SendFakeEarlyDataLength: 4,
10870 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010871 },
10872 },
10873 shouldFail: true,
10874 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10875 })
10876
10877 testCases = append(testCases, testCase{
10878 testType: serverTest,
10879 name: "SkipEarlyData-TooMuchData",
10880 config: Config{
10881 MaxVersion: VersionTLS13,
10882 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010883 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010884 },
10885 },
10886 shouldFail: true,
10887 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10888 })
10889
10890 testCases = append(testCases, testCase{
10891 testType: serverTest,
10892 name: "SkipEarlyData-Interleaved",
10893 config: Config{
10894 MaxVersion: VersionTLS13,
10895 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010896 SendFakeEarlyDataLength: 4,
10897 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010898 },
10899 },
10900 shouldFail: true,
10901 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10902 })
10903
10904 testCases = append(testCases, testCase{
10905 testType: serverTest,
10906 name: "SkipEarlyData-EarlyDataInTLS12",
10907 config: Config{
10908 MaxVersion: VersionTLS13,
10909 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010910 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010911 },
10912 },
10913 shouldFail: true,
10914 expectedError: ":UNEXPECTED_RECORD:",
10915 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10916 })
10917
10918 testCases = append(testCases, testCase{
10919 testType: serverTest,
10920 name: "SkipEarlyData-HRR",
10921 config: Config{
10922 MaxVersion: VersionTLS13,
10923 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010924 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010925 },
10926 DefaultCurves: []CurveID{},
10927 },
10928 })
10929
10930 testCases = append(testCases, testCase{
10931 testType: serverTest,
10932 name: "SkipEarlyData-HRR-Interleaved",
10933 config: Config{
10934 MaxVersion: VersionTLS13,
10935 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010936 SendFakeEarlyDataLength: 4,
10937 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010938 },
10939 DefaultCurves: []CurveID{},
10940 },
10941 shouldFail: true,
10942 expectedError: ":UNEXPECTED_RECORD:",
10943 })
10944
10945 testCases = append(testCases, testCase{
10946 testType: serverTest,
10947 name: "SkipEarlyData-HRR-TooMuchData",
10948 config: Config{
10949 MaxVersion: VersionTLS13,
10950 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010951 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010952 },
10953 DefaultCurves: []CurveID{},
10954 },
10955 shouldFail: true,
10956 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10957 })
10958
10959 // Test that skipping early data looking for cleartext correctly
10960 // processes an alert record.
10961 testCases = append(testCases, testCase{
10962 testType: serverTest,
10963 name: "SkipEarlyData-HRR-FatalAlert",
10964 config: Config{
10965 MaxVersion: VersionTLS13,
10966 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010967 SendEarlyAlert: true,
10968 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010969 },
10970 DefaultCurves: []CurveID{},
10971 },
10972 shouldFail: true,
10973 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10974 })
10975
10976 testCases = append(testCases, testCase{
10977 testType: serverTest,
10978 name: "SkipEarlyData-SecondClientHelloEarlyData",
10979 config: Config{
10980 MaxVersion: VersionTLS13,
10981 Bugs: ProtocolBugs{
10982 SendEarlyDataOnSecondClientHello: true,
10983 },
10984 DefaultCurves: []CurveID{},
10985 },
10986 shouldFail: true,
10987 expectedLocalError: "remote error: bad record MAC",
10988 })
10989
10990 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010991 testType: clientTest,
10992 name: "EmptyEncryptedExtensions",
10993 config: Config{
10994 MaxVersion: VersionTLS13,
10995 Bugs: ProtocolBugs{
10996 EmptyEncryptedExtensions: true,
10997 },
10998 },
10999 shouldFail: true,
11000 expectedLocalError: "remote error: error decoding message",
11001 })
11002
11003 testCases = append(testCases, testCase{
11004 testType: clientTest,
11005 name: "EncryptedExtensionsWithKeyShare",
11006 config: Config{
11007 MaxVersion: VersionTLS13,
11008 Bugs: ProtocolBugs{
11009 EncryptedExtensionsWithKeyShare: true,
11010 },
11011 },
11012 shouldFail: true,
11013 expectedLocalError: "remote error: unsupported extension",
11014 })
Steven Valdez5440fe02016-07-18 12:40:30 -040011015
11016 testCases = append(testCases, testCase{
11017 testType: serverTest,
11018 name: "SendHelloRetryRequest",
11019 config: Config{
11020 MaxVersion: VersionTLS13,
11021 // Require a HelloRetryRequest for every curve.
11022 DefaultCurves: []CurveID{},
11023 },
11024 expectedCurveID: CurveX25519,
11025 })
11026
11027 testCases = append(testCases, testCase{
11028 testType: serverTest,
11029 name: "SendHelloRetryRequest-2",
11030 config: Config{
11031 MaxVersion: VersionTLS13,
11032 DefaultCurves: []CurveID{CurveP384},
11033 },
11034 // Although the ClientHello did not predict our preferred curve,
11035 // we always select it whether it is predicted or not.
11036 expectedCurveID: CurveX25519,
11037 })
11038
11039 testCases = append(testCases, testCase{
11040 name: "UnknownCurve-HelloRetryRequest",
11041 config: Config{
11042 MaxVersion: VersionTLS13,
11043 // P-384 requires HelloRetryRequest in BoringSSL.
11044 CurvePreferences: []CurveID{CurveP384},
11045 Bugs: ProtocolBugs{
11046 SendHelloRetryRequestCurve: bogusCurve,
11047 },
11048 },
11049 shouldFail: true,
11050 expectedError: ":WRONG_CURVE:",
11051 })
11052
11053 testCases = append(testCases, testCase{
11054 name: "DisabledCurve-HelloRetryRequest",
11055 config: Config{
11056 MaxVersion: VersionTLS13,
11057 CurvePreferences: []CurveID{CurveP256},
11058 Bugs: ProtocolBugs{
11059 IgnorePeerCurvePreferences: true,
11060 },
11061 },
11062 flags: []string{"-p384-only"},
11063 shouldFail: true,
11064 expectedError: ":WRONG_CURVE:",
11065 })
11066
11067 testCases = append(testCases, testCase{
11068 name: "UnnecessaryHelloRetryRequest",
11069 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040011070 MaxVersion: VersionTLS13,
11071 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040011072 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040011073 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040011074 },
11075 },
11076 shouldFail: true,
11077 expectedError: ":WRONG_CURVE:",
11078 })
11079
11080 testCases = append(testCases, testCase{
11081 name: "SecondHelloRetryRequest",
11082 config: Config{
11083 MaxVersion: VersionTLS13,
11084 // P-384 requires HelloRetryRequest in BoringSSL.
11085 CurvePreferences: []CurveID{CurveP384},
11086 Bugs: ProtocolBugs{
11087 SecondHelloRetryRequest: true,
11088 },
11089 },
11090 shouldFail: true,
11091 expectedError: ":UNEXPECTED_MESSAGE:",
11092 })
11093
11094 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011095 name: "HelloRetryRequest-Empty",
11096 config: Config{
11097 MaxVersion: VersionTLS13,
11098 Bugs: ProtocolBugs{
11099 AlwaysSendHelloRetryRequest: true,
11100 },
11101 },
11102 shouldFail: true,
11103 expectedError: ":DECODE_ERROR:",
11104 })
11105
11106 testCases = append(testCases, testCase{
11107 name: "HelloRetryRequest-DuplicateCurve",
11108 config: Config{
11109 MaxVersion: VersionTLS13,
11110 // P-384 requires a HelloRetryRequest against BoringSSL's default
11111 // configuration. Assert this ExpectMissingKeyShare.
11112 CurvePreferences: []CurveID{CurveP384},
11113 Bugs: ProtocolBugs{
11114 ExpectMissingKeyShare: true,
11115 DuplicateHelloRetryRequestExtensions: true,
11116 },
11117 },
11118 shouldFail: true,
11119 expectedError: ":DUPLICATE_EXTENSION:",
11120 expectedLocalError: "remote error: illegal parameter",
11121 })
11122
11123 testCases = append(testCases, testCase{
11124 name: "HelloRetryRequest-Cookie",
11125 config: Config{
11126 MaxVersion: VersionTLS13,
11127 Bugs: ProtocolBugs{
11128 SendHelloRetryRequestCookie: []byte("cookie"),
11129 },
11130 },
11131 })
11132
11133 testCases = append(testCases, testCase{
11134 name: "HelloRetryRequest-DuplicateCookie",
11135 config: Config{
11136 MaxVersion: VersionTLS13,
11137 Bugs: ProtocolBugs{
11138 SendHelloRetryRequestCookie: []byte("cookie"),
11139 DuplicateHelloRetryRequestExtensions: true,
11140 },
11141 },
11142 shouldFail: true,
11143 expectedError: ":DUPLICATE_EXTENSION:",
11144 expectedLocalError: "remote error: illegal parameter",
11145 })
11146
11147 testCases = append(testCases, testCase{
11148 name: "HelloRetryRequest-EmptyCookie",
11149 config: Config{
11150 MaxVersion: VersionTLS13,
11151 Bugs: ProtocolBugs{
11152 SendHelloRetryRequestCookie: []byte{},
11153 },
11154 },
11155 shouldFail: true,
11156 expectedError: ":DECODE_ERROR:",
11157 })
11158
11159 testCases = append(testCases, testCase{
11160 name: "HelloRetryRequest-Cookie-Curve",
11161 config: Config{
11162 MaxVersion: VersionTLS13,
11163 // P-384 requires HelloRetryRequest in BoringSSL.
11164 CurvePreferences: []CurveID{CurveP384},
11165 Bugs: ProtocolBugs{
11166 SendHelloRetryRequestCookie: []byte("cookie"),
11167 ExpectMissingKeyShare: true,
11168 },
11169 },
11170 })
11171
11172 testCases = append(testCases, testCase{
11173 name: "HelloRetryRequest-Unknown",
11174 config: Config{
11175 MaxVersion: VersionTLS13,
11176 Bugs: ProtocolBugs{
11177 CustomHelloRetryRequestExtension: "extension",
11178 },
11179 },
11180 shouldFail: true,
11181 expectedError: ":UNEXPECTED_EXTENSION:",
11182 expectedLocalError: "remote error: unsupported extension",
11183 })
11184
11185 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011186 testType: serverTest,
11187 name: "SecondClientHelloMissingKeyShare",
11188 config: Config{
11189 MaxVersion: VersionTLS13,
11190 DefaultCurves: []CurveID{},
11191 Bugs: ProtocolBugs{
11192 SecondClientHelloMissingKeyShare: true,
11193 },
11194 },
11195 shouldFail: true,
11196 expectedError: ":MISSING_KEY_SHARE:",
11197 })
11198
11199 testCases = append(testCases, testCase{
11200 testType: serverTest,
11201 name: "SecondClientHelloWrongCurve",
11202 config: Config{
11203 MaxVersion: VersionTLS13,
11204 DefaultCurves: []CurveID{},
11205 Bugs: ProtocolBugs{
11206 MisinterpretHelloRetryRequestCurve: CurveP521,
11207 },
11208 },
11209 shouldFail: true,
11210 expectedError: ":WRONG_CURVE:",
11211 })
11212
11213 testCases = append(testCases, testCase{
11214 name: "HelloRetryRequestVersionMismatch",
11215 config: Config{
11216 MaxVersion: VersionTLS13,
11217 // P-384 requires HelloRetryRequest in BoringSSL.
11218 CurvePreferences: []CurveID{CurveP384},
11219 Bugs: ProtocolBugs{
11220 SendServerHelloVersion: 0x0305,
11221 },
11222 },
11223 shouldFail: true,
11224 expectedError: ":WRONG_VERSION_NUMBER:",
11225 })
11226
11227 testCases = append(testCases, testCase{
11228 name: "HelloRetryRequestCurveMismatch",
11229 config: Config{
11230 MaxVersion: VersionTLS13,
11231 // P-384 requires HelloRetryRequest in BoringSSL.
11232 CurvePreferences: []CurveID{CurveP384},
11233 Bugs: ProtocolBugs{
11234 // Send P-384 (correct) in the HelloRetryRequest.
11235 SendHelloRetryRequestCurve: CurveP384,
11236 // But send P-256 in the ServerHello.
11237 SendCurve: CurveP256,
11238 },
11239 },
11240 shouldFail: true,
11241 expectedError: ":WRONG_CURVE:",
11242 })
11243
11244 // Test the server selecting a curve that requires a HelloRetryRequest
11245 // without sending it.
11246 testCases = append(testCases, testCase{
11247 name: "SkipHelloRetryRequest",
11248 config: Config{
11249 MaxVersion: VersionTLS13,
11250 // P-384 requires HelloRetryRequest in BoringSSL.
11251 CurvePreferences: []CurveID{CurveP384},
11252 Bugs: ProtocolBugs{
11253 SkipHelloRetryRequest: true,
11254 },
11255 },
11256 shouldFail: true,
11257 expectedError: ":WRONG_CURVE:",
11258 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011259
11260 testCases = append(testCases, testCase{
11261 name: "TLS13-RequestContextInHandshake",
11262 config: Config{
11263 MaxVersion: VersionTLS13,
11264 MinVersion: VersionTLS13,
11265 ClientAuth: RequireAnyClientCert,
11266 Bugs: ProtocolBugs{
11267 SendRequestContext: []byte("request context"),
11268 },
11269 },
11270 flags: []string{
11271 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11272 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11273 },
11274 shouldFail: true,
11275 expectedError: ":DECODE_ERROR:",
11276 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011277
11278 testCases = append(testCases, testCase{
11279 testType: serverTest,
11280 name: "TLS13-TrailingKeyShareData",
11281 config: Config{
11282 MaxVersion: VersionTLS13,
11283 Bugs: ProtocolBugs{
11284 TrailingKeyShareData: true,
11285 },
11286 },
11287 shouldFail: true,
11288 expectedError: ":DECODE_ERROR:",
11289 })
David Benjamin7f78df42016-10-05 22:33:19 -040011290
11291 testCases = append(testCases, testCase{
11292 name: "TLS13-AlwaysSelectPSKIdentity",
11293 config: Config{
11294 MaxVersion: VersionTLS13,
11295 Bugs: ProtocolBugs{
11296 AlwaysSelectPSKIdentity: true,
11297 },
11298 },
11299 shouldFail: true,
11300 expectedError: ":UNEXPECTED_EXTENSION:",
11301 })
11302
11303 testCases = append(testCases, testCase{
11304 name: "TLS13-InvalidPSKIdentity",
11305 config: Config{
11306 MaxVersion: VersionTLS13,
11307 Bugs: ProtocolBugs{
11308 SelectPSKIdentityOnResume: 1,
11309 },
11310 },
11311 resumeSession: true,
11312 shouldFail: true,
11313 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11314 })
David Benjamin1286bee2016-10-07 15:25:06 -040011315
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011316 testCases = append(testCases, testCase{
11317 testType: serverTest,
11318 name: "TLS13-ExtraPSKIdentity",
11319 config: Config{
11320 MaxVersion: VersionTLS13,
11321 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011322 ExtraPSKIdentity: true,
11323 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011324 },
11325 },
11326 resumeSession: true,
11327 })
11328
David Benjamin1286bee2016-10-07 15:25:06 -040011329 // Test that unknown NewSessionTicket extensions are tolerated.
11330 testCases = append(testCases, testCase{
11331 name: "TLS13-CustomTicketExtension",
11332 config: Config{
11333 MaxVersion: VersionTLS13,
11334 Bugs: ProtocolBugs{
11335 CustomTicketExtension: "1234",
11336 },
11337 },
11338 })
Steven Valdez2d850622017-01-11 11:34:52 -050011339
Steven Valdez0e4a4482017-07-17 11:12:34 -040011340 for _, noSessionID := range []bool{false, true} {
11341 prefix := "TLS13Experiment"
11342 variant := TLS13Experiment
11343 if noSessionID {
11344 prefix = "TLS13NoSessionIDExperiment"
11345 variant = TLS13NoSessionIDExperiment
11346 }
11347
11348 // Test that enabling a TLS 1.3 variant does not interfere with
11349 // TLS 1.2 session ID resumption.
11350 testCases = append(testCases, testCase{
11351 testType: clientTest,
11352 name: prefix + "-ResumeTLS12SessionID",
11353 config: Config{
11354 MaxVersion: VersionTLS12,
11355 SessionTicketsDisabled: true,
11356 },
11357 resumeSession: true,
11358 flags: []string{"-tls13-variant", strconv.Itoa(variant)},
11359 })
11360
11361 // Test that the server correctly echoes back session IDs of
11362 // various lengths.
11363 testCases = append(testCases, testCase{
11364 testType: serverTest,
11365 name: prefix + "-EmptySessionID",
11366 config: Config{
11367 MaxVersion: VersionTLS13,
11368 Bugs: ProtocolBugs{
11369 SendClientHelloSessionID: []byte{},
11370 },
11371 },
11372 tls13Variant: variant,
11373 })
11374
11375 testCases = append(testCases, testCase{
11376 testType: serverTest,
11377 name: prefix + "-ShortSessionID",
11378 config: Config{
11379 MaxVersion: VersionTLS13,
11380 Bugs: ProtocolBugs{
11381 SendClientHelloSessionID: make([]byte, 16),
11382 },
11383 },
11384 tls13Variant: variant,
11385 })
11386
11387 testCases = append(testCases, testCase{
11388 testType: serverTest,
11389 name: prefix + "-FullSessionID",
11390 config: Config{
11391 MaxVersion: VersionTLS13,
11392 Bugs: ProtocolBugs{
11393 SendClientHelloSessionID: make([]byte, 32),
11394 },
11395 },
11396 tls13Variant: variant,
11397 })
11398 }
11399
11400 // Test that the client sends a fake session ID in TLS13Experiment.
11401 testCases = append(testCases, testCase{
11402 testType: clientTest,
11403 name: "TLS13Experiment-RequireSessionID",
11404 config: Config{
11405 MaxVersion: VersionTLS13,
11406 Bugs: ProtocolBugs{
11407 ExpectClientHelloSessionID: true,
11408 },
11409 },
11410 tls13Variant: TLS13Experiment,
11411 })
11412
11413 // Test that the client does not send a fake session ID in
11414 // TLS13NoSessionIDExperiment.
11415 testCases = append(testCases, testCase{
11416 testType: clientTest,
11417 name: "TLS13NoSessionIDExperiment-RequireEmptySessionID",
11418 config: Config{
11419 MaxVersion: VersionTLS13,
11420 Bugs: ProtocolBugs{
11421 ExpectEmptyClientHelloSessionID: true,
11422 },
11423 },
11424 tls13Variant: TLS13NoSessionIDExperiment,
11425 })
11426
Steven Valdez2d850622017-01-11 11:34:52 -050011427 testCases = append(testCases, testCase{
11428 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011429 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011430 config: Config{
11431 MaxVersion: VersionTLS13,
11432 MaxEarlyDataSize: 16384,
11433 },
11434 resumeConfig: &Config{
11435 MaxVersion: VersionTLS13,
11436 MaxEarlyDataSize: 16384,
11437 Bugs: ProtocolBugs{
11438 AlwaysRejectEarlyData: true,
11439 },
11440 },
11441 resumeSession: true,
11442 flags: []string{
11443 "-enable-early-data",
11444 "-expect-early-data-info",
11445 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050011446 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011447 },
11448 })
11449
11450 testCases = append(testCases, testCase{
11451 testType: clientTest,
Steven Valdez520e1222017-06-13 12:45:25 -040011452 name: "TLS13Experiment-EarlyData-Reject-Client",
11453 config: Config{
11454 MaxVersion: VersionTLS13,
11455 MaxEarlyDataSize: 16384,
Steven Valdez520e1222017-06-13 12:45:25 -040011456 },
11457 resumeConfig: &Config{
11458 MaxVersion: VersionTLS13,
Steven Valdez520e1222017-06-13 12:45:25 -040011459 MaxEarlyDataSize: 16384,
11460 Bugs: ProtocolBugs{
11461 AlwaysRejectEarlyData: true,
11462 },
11463 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011464 tls13Variant: TLS13Experiment,
Steven Valdez520e1222017-06-13 12:45:25 -040011465 resumeSession: true,
11466 flags: []string{
11467 "-enable-early-data",
11468 "-expect-early-data-info",
11469 "-expect-reject-early-data",
11470 "-on-resume-shim-writes-first",
Steven Valdez520e1222017-06-13 12:45:25 -040011471 },
11472 })
11473
11474 testCases = append(testCases, testCase{
11475 testType: clientTest,
Steven Valdezdbe01582017-07-14 10:39:28 -040011476 name: "TLS13RecordTypeExperiment-EarlyData-Reject-Client",
11477 config: Config{
11478 MaxVersion: VersionTLS13,
11479 MaxEarlyDataSize: 16384,
Steven Valdezdbe01582017-07-14 10:39:28 -040011480 },
11481 resumeConfig: &Config{
11482 MaxVersion: VersionTLS13,
Steven Valdezdbe01582017-07-14 10:39:28 -040011483 MaxEarlyDataSize: 16384,
11484 Bugs: ProtocolBugs{
11485 AlwaysRejectEarlyData: true,
11486 },
11487 },
Steven Valdez0e4a4482017-07-17 11:12:34 -040011488 tls13Variant: TLS13RecordTypeExperiment,
Steven Valdezdbe01582017-07-14 10:39:28 -040011489 resumeSession: true,
11490 flags: []string{
11491 "-enable-early-data",
11492 "-expect-early-data-info",
11493 "-expect-reject-early-data",
11494 "-on-resume-shim-writes-first",
Steven Valdezdbe01582017-07-14 10:39:28 -040011495 },
11496 })
11497
11498 testCases = append(testCases, testCase{
11499 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011500 name: "TLS13-EarlyData-RejectTicket-Client",
11501 config: Config{
11502 MaxVersion: VersionTLS13,
11503 MaxEarlyDataSize: 16384,
11504 Certificates: []Certificate{rsaCertificate},
11505 },
11506 resumeConfig: &Config{
11507 MaxVersion: VersionTLS13,
11508 MaxEarlyDataSize: 16384,
11509 Certificates: []Certificate{ecdsaP256Certificate},
11510 SessionTicketsDisabled: true,
11511 },
11512 resumeSession: true,
11513 expectResumeRejected: true,
11514 flags: []string{
11515 "-enable-early-data",
11516 "-expect-early-data-info",
11517 "-expect-reject-early-data",
11518 "-on-resume-shim-writes-first",
11519 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11520 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11521 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11522 // Session tickets are disabled, so the runner will not send a ticket.
11523 "-on-retry-expect-no-session",
11524 },
11525 })
11526
11527 testCases = append(testCases, testCase{
11528 testType: clientTest,
11529 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011530 config: Config{
11531 MaxVersion: VersionTLS13,
11532 MaxEarlyDataSize: 16384,
11533 },
11534 resumeConfig: &Config{
11535 MaxVersion: VersionTLS13,
11536 MaxEarlyDataSize: 16384,
11537 Bugs: ProtocolBugs{
11538 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11539 },
11540 },
11541 resumeSession: true,
11542 flags: []string{
11543 "-enable-early-data",
11544 "-expect-early-data-info",
11545 "-expect-reject-early-data",
11546 },
11547 })
11548
11549 // The client must check the server does not send the early_data
11550 // extension while rejecting the session.
11551 testCases = append(testCases, testCase{
11552 testType: clientTest,
11553 name: "TLS13-EarlyDataWithoutResume-Client",
11554 config: Config{
11555 MaxVersion: VersionTLS13,
11556 MaxEarlyDataSize: 16384,
11557 },
11558 resumeConfig: &Config{
11559 MaxVersion: VersionTLS13,
11560 SessionTicketsDisabled: true,
11561 Bugs: ProtocolBugs{
11562 SendEarlyDataExtension: true,
11563 },
11564 },
11565 resumeSession: true,
11566 flags: []string{
11567 "-enable-early-data",
11568 "-expect-early-data-info",
11569 },
11570 shouldFail: true,
11571 expectedError: ":UNEXPECTED_EXTENSION:",
11572 })
11573
11574 // The client must fail with a dedicated error code if the server
11575 // responds with TLS 1.2 when offering 0-RTT.
11576 testCases = append(testCases, testCase{
11577 testType: clientTest,
11578 name: "TLS13-EarlyDataVersionDowngrade-Client",
11579 config: Config{
11580 MaxVersion: VersionTLS13,
11581 MaxEarlyDataSize: 16384,
11582 },
11583 resumeConfig: &Config{
11584 MaxVersion: VersionTLS12,
11585 },
11586 resumeSession: true,
11587 flags: []string{
11588 "-enable-early-data",
11589 "-expect-early-data-info",
11590 },
11591 shouldFail: true,
11592 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11593 })
11594
11595 // Test that the client rejects an (unsolicited) early_data extension if
11596 // the server sent an HRR.
11597 testCases = append(testCases, testCase{
11598 testType: clientTest,
11599 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11600 config: Config{
11601 MaxVersion: VersionTLS13,
11602 MaxEarlyDataSize: 16384,
11603 },
11604 resumeConfig: &Config{
11605 MaxVersion: VersionTLS13,
11606 MaxEarlyDataSize: 16384,
11607 Bugs: ProtocolBugs{
11608 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11609 SendEarlyDataExtension: true,
11610 },
11611 },
11612 resumeSession: true,
11613 flags: []string{
11614 "-enable-early-data",
11615 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011616 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011617 },
11618 shouldFail: true,
11619 expectedError: ":UNEXPECTED_EXTENSION:",
11620 })
11621
11622 fooString := "foo"
11623 barString := "bar"
11624
11625 // Test that the client reports the correct ALPN after a 0-RTT reject
11626 // that changed it.
11627 testCases = append(testCases, testCase{
11628 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011629 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011630 config: Config{
11631 MaxVersion: VersionTLS13,
11632 MaxEarlyDataSize: 16384,
11633 Bugs: ProtocolBugs{
11634 ALPNProtocol: &fooString,
11635 },
11636 },
11637 resumeConfig: &Config{
11638 MaxVersion: VersionTLS13,
11639 MaxEarlyDataSize: 16384,
11640 Bugs: ProtocolBugs{
11641 ALPNProtocol: &barString,
11642 },
11643 },
11644 resumeSession: true,
11645 flags: []string{
11646 "-advertise-alpn", "\x03foo\x03bar",
11647 "-enable-early-data",
11648 "-expect-early-data-info",
11649 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011650 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011651 "-on-resume-expect-alpn", "foo",
11652 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011653 },
11654 })
11655
11656 // Test that the client reports the correct ALPN after a 0-RTT reject if
11657 // ALPN was omitted from the first connection.
11658 testCases = append(testCases, testCase{
11659 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011660 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011661 config: Config{
11662 MaxVersion: VersionTLS13,
11663 MaxEarlyDataSize: 16384,
11664 },
11665 resumeConfig: &Config{
11666 MaxVersion: VersionTLS13,
11667 MaxEarlyDataSize: 16384,
11668 NextProtos: []string{"foo"},
11669 },
11670 resumeSession: true,
11671 flags: []string{
11672 "-advertise-alpn", "\x03foo\x03bar",
11673 "-enable-early-data",
11674 "-expect-early-data-info",
11675 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011676 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011677 "-on-resume-expect-alpn", "",
11678 "-on-retry-expect-alpn", "foo",
11679 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011680 },
11681 })
11682
11683 // Test that the client reports the correct ALPN after a 0-RTT reject if
11684 // ALPN was omitted from the second connection.
11685 testCases = append(testCases, testCase{
11686 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011687 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011688 config: Config{
11689 MaxVersion: VersionTLS13,
11690 MaxEarlyDataSize: 16384,
11691 NextProtos: []string{"foo"},
11692 },
11693 resumeConfig: &Config{
11694 MaxVersion: VersionTLS13,
11695 MaxEarlyDataSize: 16384,
11696 },
11697 resumeSession: true,
11698 flags: []string{
11699 "-advertise-alpn", "\x03foo\x03bar",
11700 "-enable-early-data",
11701 "-expect-early-data-info",
11702 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011703 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011704 "-on-resume-expect-alpn", "foo",
11705 "-on-retry-expect-alpn", "",
11706 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011707 },
11708 })
11709
11710 // Test that the client enforces ALPN match on 0-RTT accept.
11711 testCases = append(testCases, testCase{
11712 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011713 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011714 config: Config{
11715 MaxVersion: VersionTLS13,
11716 MaxEarlyDataSize: 16384,
11717 Bugs: ProtocolBugs{
11718 ALPNProtocol: &fooString,
11719 },
11720 },
11721 resumeConfig: &Config{
11722 MaxVersion: VersionTLS13,
11723 MaxEarlyDataSize: 16384,
11724 Bugs: ProtocolBugs{
11725 AlwaysAcceptEarlyData: true,
11726 ALPNProtocol: &barString,
11727 },
11728 },
11729 resumeSession: true,
11730 flags: []string{
11731 "-advertise-alpn", "\x03foo\x03bar",
11732 "-enable-early-data",
11733 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011734 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011735 "-on-resume-expect-alpn", "foo",
11736 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011737 },
11738 shouldFail: true,
11739 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11740 })
11741
11742 // Test that the server correctly rejects 0-RTT when the previous
11743 // session did not allow early data on resumption.
11744 testCases = append(testCases, testCase{
11745 testType: serverTest,
11746 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11747 config: Config{
11748 MaxVersion: VersionTLS13,
11749 },
11750 resumeConfig: &Config{
11751 MaxVersion: VersionTLS13,
11752 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011753 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011754 ExpectEarlyDataAccepted: false,
11755 },
11756 },
11757 resumeSession: true,
11758 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011759 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011760 "-expect-reject-early-data",
11761 },
11762 })
11763
11764 // Test that we reject early data where ALPN is omitted from the first
11765 // connection.
11766 testCases = append(testCases, testCase{
11767 testType: serverTest,
11768 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11769 config: Config{
11770 MaxVersion: VersionTLS13,
11771 NextProtos: []string{},
11772 },
11773 resumeConfig: &Config{
11774 MaxVersion: VersionTLS13,
11775 NextProtos: []string{"foo"},
11776 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011777 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011778 ExpectEarlyDataAccepted: false,
11779 },
11780 },
11781 resumeSession: true,
11782 flags: []string{
11783 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011784 "-on-initial-select-alpn", "",
11785 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011786 },
11787 })
11788
11789 // Test that we reject early data where ALPN is omitted from the second
11790 // connection.
11791 testCases = append(testCases, testCase{
11792 testType: serverTest,
11793 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11794 config: Config{
11795 MaxVersion: VersionTLS13,
11796 NextProtos: []string{"foo"},
11797 },
11798 resumeConfig: &Config{
11799 MaxVersion: VersionTLS13,
11800 NextProtos: []string{},
11801 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011802 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011803 ExpectEarlyDataAccepted: false,
11804 },
11805 },
11806 resumeSession: true,
11807 flags: []string{
11808 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011809 "-on-initial-select-alpn", "foo",
11810 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011811 },
11812 })
11813
11814 // Test that we reject early data with mismatched ALPN.
11815 testCases = append(testCases, testCase{
11816 testType: serverTest,
11817 name: "TLS13-EarlyData-ALPNMismatch-Server",
11818 config: Config{
11819 MaxVersion: VersionTLS13,
11820 NextProtos: []string{"foo"},
11821 },
11822 resumeConfig: &Config{
11823 MaxVersion: VersionTLS13,
11824 NextProtos: []string{"bar"},
11825 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011826 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011827 ExpectEarlyDataAccepted: false,
11828 },
11829 },
11830 resumeSession: true,
11831 flags: []string{
11832 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011833 "-on-initial-select-alpn", "foo",
11834 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011835 },
11836 })
11837
David Benjamin6bb507b2017-03-29 16:35:57 -050011838 // Test that the client offering 0-RTT and Channel ID forbids the server
11839 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011840 testCases = append(testCases, testCase{
11841 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011842 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011843 config: Config{
11844 MaxVersion: VersionTLS13,
11845 MaxEarlyDataSize: 16384,
11846 RequestChannelID: true,
11847 },
11848 resumeSession: true,
11849 expectChannelID: true,
11850 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011851 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011852 flags: []string{
11853 "-enable-early-data",
11854 "-expect-early-data-info",
11855 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11856 },
11857 })
11858
David Benjamin6bb507b2017-03-29 16:35:57 -050011859 // Test that the client offering Channel ID and 0-RTT allows the server
11860 // to decline 0-RTT.
11861 testCases = append(testCases, testCase{
11862 testType: clientTest,
11863 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11864 config: Config{
11865 MaxVersion: VersionTLS13,
11866 MaxEarlyDataSize: 16384,
11867 RequestChannelID: true,
11868 Bugs: ProtocolBugs{
11869 AlwaysRejectEarlyData: true,
11870 },
11871 },
11872 resumeSession: true,
11873 expectChannelID: true,
11874 flags: []string{
11875 "-enable-early-data",
11876 "-expect-early-data-info",
11877 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11878 "-expect-reject-early-data",
11879 },
11880 })
11881
11882 // Test that the client offering Channel ID and 0-RTT allows the server
11883 // to decline Channel ID.
11884 testCases = append(testCases, testCase{
11885 testType: clientTest,
11886 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11887 config: Config{
11888 MaxVersion: VersionTLS13,
11889 MaxEarlyDataSize: 16384,
11890 },
11891 resumeSession: true,
11892 flags: []string{
11893 "-enable-early-data",
11894 "-expect-early-data-info",
11895 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11896 "-expect-accept-early-data",
11897 },
11898 })
11899
11900 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11901 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011902 testCases = append(testCases, testCase{
11903 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011904 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011905 config: Config{
11906 MaxVersion: VersionTLS13,
11907 ChannelID: channelIDKey,
11908 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011909 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011910 ExpectEarlyDataAccepted: false,
11911 },
11912 },
11913 resumeSession: true,
11914 expectChannelID: true,
11915 flags: []string{
11916 "-enable-early-data",
11917 "-expect-reject-early-data",
11918 "-expect-channel-id",
11919 base64.StdEncoding.EncodeToString(channelIDBytes),
11920 },
11921 })
11922
David Benjamin6bb507b2017-03-29 16:35:57 -050011923 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11924 // if not offered Channel ID.
11925 testCases = append(testCases, testCase{
11926 testType: serverTest,
11927 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11928 config: Config{
11929 MaxVersion: VersionTLS13,
11930 Bugs: ProtocolBugs{
11931 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11932 ExpectEarlyDataAccepted: true,
11933 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11934 },
11935 },
11936 resumeSession: true,
11937 expectChannelID: false,
11938 flags: []string{
11939 "-enable-early-data",
11940 "-expect-accept-early-data",
11941 "-enable-channel-id",
11942 },
11943 })
11944
David Benjamin32c89272017-03-26 13:54:21 -050011945 // Test that the server rejects 0-RTT streams without end_of_early_data.
11946 // The subsequent records should fail to decrypt.
11947 testCases = append(testCases, testCase{
11948 testType: serverTest,
11949 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11950 config: Config{
11951 MaxVersion: VersionTLS13,
11952 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011953 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011954 ExpectEarlyDataAccepted: true,
11955 SkipEndOfEarlyData: true,
11956 },
11957 },
11958 resumeSession: true,
11959 flags: []string{"-enable-early-data"},
11960 shouldFail: true,
11961 expectedLocalError: "remote error: bad record MAC",
11962 expectedError: ":BAD_DECRYPT:",
11963 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011964
11965 testCases = append(testCases, testCase{
11966 testType: serverTest,
11967 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11968 config: Config{
11969 MaxVersion: VersionTLS13,
11970 },
11971 resumeConfig: &Config{
11972 MaxVersion: VersionTLS13,
11973 Bugs: ProtocolBugs{
11974 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11975 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011976 ExpectEarlyDataAccepted: true,
11977 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011978 },
11979 resumeSession: true,
11980 shouldFail: true,
11981 expectedError: ":UNEXPECTED_RECORD:",
11982 expectedLocalError: "remote error: unexpected message",
11983 flags: []string{
11984 "-enable-early-data",
11985 },
11986 })
David Benjamind9cbb532017-07-07 13:17:19 -040011987
11988 // Test that the client reports TLS 1.3 as the version while sending
11989 // early data.
11990 testCases = append(testCases, testCase{
11991 testType: clientTest,
11992 name: "TLS13-EarlyData-Client-VersionAPI",
11993 config: Config{
11994 MaxVersion: VersionTLS13,
11995 MaxEarlyDataSize: 16384,
11996 },
11997 resumeSession: true,
11998 flags: []string{
11999 "-enable-early-data",
12000 "-expect-early-data-info",
12001 "-expect-accept-early-data",
12002 "-expect-version", strconv.Itoa(VersionTLS13),
12003 },
12004 })
David Benjamin4a37de02017-08-08 20:15:40 -040012005
12006 // Test that client and server both notice handshake errors after data
12007 // has started flowing.
12008 testCases = append(testCases, testCase{
12009 testType: clientTest,
12010 name: "TLS13-EarlyData-Client-BadFinished",
12011 config: Config{
12012 MaxVersion: VersionTLS13,
12013 MaxEarlyDataSize: 16384,
12014 },
12015 resumeConfig: &Config{
12016 MaxVersion: VersionTLS13,
12017 MaxEarlyDataSize: 16384,
12018 Bugs: ProtocolBugs{
12019 BadFinished: true,
12020 },
12021 },
12022 resumeSession: true,
12023 flags: []string{
12024 "-enable-early-data",
12025 "-expect-early-data-info",
12026 "-expect-accept-early-data",
12027 },
12028 shouldFail: true,
12029 expectedError: ":DIGEST_CHECK_FAILED:",
12030 expectedLocalError: "remote error: error decrypting message",
12031 })
12032 testCases = append(testCases, testCase{
12033 testType: serverTest,
12034 name: "TLS13-EarlyData-Server-BadFinished",
12035 config: Config{
12036 MaxVersion: VersionTLS13,
12037 MaxEarlyDataSize: 16384,
12038 },
12039 resumeConfig: &Config{
12040 MaxVersion: VersionTLS13,
12041 MaxEarlyDataSize: 16384,
12042 Bugs: ProtocolBugs{
12043 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12044 ExpectEarlyDataAccepted: true,
12045 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12046 BadFinished: true,
12047 },
12048 },
12049 resumeSession: true,
12050 flags: []string{
12051 "-enable-early-data",
12052 "-expect-accept-early-data",
12053 },
12054 shouldFail: true,
12055 expectedError: ":DIGEST_CHECK_FAILED:",
12056 expectedLocalError: "remote error: error decrypting message",
12057 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020012058 testCases = append(testCases, testCase{
12059 testType: serverTest,
12060 name: "TLS13-ServerSkipCertificateVerify",
12061 config: Config{
12062 MinVersion: VersionTLS13,
12063 MaxVersion: VersionTLS13,
12064 Certificates: []Certificate{rsaChainCertificate},
12065 Bugs: ProtocolBugs{
12066 SkipCertificateVerify: true,
12067 },
12068 },
12069 expectPeerCertificate: &rsaChainCertificate,
12070 flags: []string{
12071 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12072 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12073 "-require-any-client-certificate",
12074 },
12075 shouldFail: true,
12076 expectedError: ":UNEXPECTED_MESSAGE:",
12077 expectedLocalError: "remote error: unexpected message",
12078 })
12079 testCases = append(testCases, testCase{
12080 testType: clientTest,
12081 name: "TLS13-ClientSkipCertificateVerify",
12082 config: Config{
12083 MinVersion: VersionTLS13,
12084 MaxVersion: VersionTLS13,
12085 Certificates: []Certificate{rsaChainCertificate},
12086 Bugs: ProtocolBugs{
12087 SkipCertificateVerify: true,
12088 },
12089 },
12090 expectPeerCertificate: &rsaChainCertificate,
12091 flags: []string{
12092 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12093 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12094 },
12095 shouldFail: true,
12096 expectedError: ":UNEXPECTED_MESSAGE:",
12097 expectedLocalError: "remote error: unexpected message",
12098 })
Steven Valdez143e8b32016-07-11 13:19:03 -040012099}
12100
David Benjaminabbbee12016-10-31 19:20:42 -040012101func addTLS13CipherPreferenceTests() {
12102 // Test that client preference is honored if the shim has AES hardware
12103 // and ChaCha20-Poly1305 is preferred otherwise.
12104 testCases = append(testCases, testCase{
12105 testType: serverTest,
12106 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
12107 config: Config{
12108 MaxVersion: VersionTLS13,
12109 CipherSuites: []uint16{
12110 TLS_CHACHA20_POLY1305_SHA256,
12111 TLS_AES_128_GCM_SHA256,
12112 },
12113 },
12114 flags: []string{
12115 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12116 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12117 },
12118 })
12119
12120 testCases = append(testCases, testCase{
12121 testType: serverTest,
12122 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
12123 config: Config{
12124 MaxVersion: VersionTLS13,
12125 CipherSuites: []uint16{
12126 TLS_AES_128_GCM_SHA256,
12127 TLS_CHACHA20_POLY1305_SHA256,
12128 },
12129 },
12130 flags: []string{
12131 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12132 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12133 },
12134 })
12135
12136 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
12137 // whether it has AES hardware.
12138 testCases = append(testCases, testCase{
12139 name: "TLS13-CipherPreference-Client",
12140 config: Config{
12141 MaxVersion: VersionTLS13,
12142 // Use the client cipher order. (This is the default but
12143 // is listed to be explicit.)
12144 PreferServerCipherSuites: false,
12145 },
12146 flags: []string{
12147 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12148 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12149 },
12150 })
12151}
12152
David Benjaminf3fbade2016-09-19 13:08:16 -040012153func addPeekTests() {
12154 // Test SSL_peek works, including on empty records.
12155 testCases = append(testCases, testCase{
12156 name: "Peek-Basic",
12157 sendEmptyRecords: 1,
12158 flags: []string{"-peek-then-read"},
12159 })
12160
12161 // Test SSL_peek can drive the initial handshake.
12162 testCases = append(testCases, testCase{
12163 name: "Peek-ImplicitHandshake",
12164 flags: []string{
12165 "-peek-then-read",
12166 "-implicit-handshake",
12167 },
12168 })
12169
12170 // Test SSL_peek can discover and drive a renegotiation.
12171 testCases = append(testCases, testCase{
12172 name: "Peek-Renegotiate",
12173 config: Config{
12174 MaxVersion: VersionTLS12,
12175 },
12176 renegotiate: 1,
12177 flags: []string{
12178 "-peek-then-read",
12179 "-renegotiate-freely",
12180 "-expect-total-renegotiations", "1",
12181 },
12182 })
12183
12184 // Test SSL_peek can discover a close_notify.
12185 testCases = append(testCases, testCase{
12186 name: "Peek-Shutdown",
12187 config: Config{
12188 Bugs: ProtocolBugs{
12189 ExpectCloseNotify: true,
12190 },
12191 },
12192 flags: []string{
12193 "-peek-then-read",
12194 "-check-close-notify",
12195 },
12196 })
12197
12198 // Test SSL_peek can discover an alert.
12199 testCases = append(testCases, testCase{
12200 name: "Peek-Alert",
12201 config: Config{
12202 Bugs: ProtocolBugs{
12203 SendSpuriousAlert: alertRecordOverflow,
12204 },
12205 },
12206 flags: []string{"-peek-then-read"},
12207 shouldFail: true,
12208 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12209 })
12210
12211 // Test SSL_peek can handle KeyUpdate.
12212 testCases = append(testCases, testCase{
12213 name: "Peek-KeyUpdate",
12214 config: Config{
12215 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012216 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012217 sendKeyUpdates: 1,
12218 keyUpdateRequest: keyUpdateNotRequested,
12219 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012220 })
12221}
12222
David Benjamine6f22212016-11-08 14:28:24 -050012223func addRecordVersionTests() {
12224 for _, ver := range tlsVersions {
12225 // Test that the record version is enforced.
12226 testCases = append(testCases, testCase{
12227 name: "CheckRecordVersion-" + ver.name,
12228 config: Config{
12229 MinVersion: ver.version,
12230 MaxVersion: ver.version,
12231 Bugs: ProtocolBugs{
12232 SendRecordVersion: 0x03ff,
12233 },
12234 },
David Benjamina5022392017-07-10 17:40:39 -040012235 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012236 shouldFail: true,
12237 expectedError: ":WRONG_VERSION_NUMBER:",
12238 })
12239
12240 // Test that the ClientHello may use any record version, for
12241 // compatibility reasons.
12242 testCases = append(testCases, testCase{
12243 testType: serverTest,
12244 name: "LooseInitialRecordVersion-" + ver.name,
12245 config: Config{
12246 MinVersion: ver.version,
12247 MaxVersion: ver.version,
12248 Bugs: ProtocolBugs{
12249 SendInitialRecordVersion: 0x03ff,
12250 },
12251 },
David Benjamina5022392017-07-10 17:40:39 -040012252 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012253 })
12254
12255 // Test that garbage ClientHello record versions are rejected.
12256 testCases = append(testCases, testCase{
12257 testType: serverTest,
12258 name: "GarbageInitialRecordVersion-" + ver.name,
12259 config: Config{
12260 MinVersion: ver.version,
12261 MaxVersion: ver.version,
12262 Bugs: ProtocolBugs{
12263 SendInitialRecordVersion: 0xffff,
12264 },
12265 },
David Benjamina5022392017-07-10 17:40:39 -040012266 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012267 shouldFail: true,
12268 expectedError: ":WRONG_VERSION_NUMBER:",
12269 })
12270 }
12271}
12272
David Benjamin2c516452016-11-15 10:16:54 +090012273func addCertificateTests() {
David Benjamin2c516452016-11-15 10:16:54 +090012274 for _, ver := range tlsVersions {
David Benjamin3969fdf2017-08-29 15:50:58 -040012275 // Test that a certificate chain with intermediate may be sent
12276 // and received as both client and server.
David Benjamin2c516452016-11-15 10:16:54 +090012277 testCases = append(testCases, testCase{
12278 testType: clientTest,
12279 name: "SendReceiveIntermediate-Client-" + ver.name,
12280 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012281 MinVersion: ver.version,
12282 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012283 Certificates: []Certificate{rsaChainCertificate},
12284 ClientAuth: RequireAnyClientCert,
12285 },
David Benjamina5022392017-07-10 17:40:39 -040012286 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012287 expectPeerCertificate: &rsaChainCertificate,
12288 flags: []string{
12289 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12290 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12291 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12292 },
12293 })
12294
12295 testCases = append(testCases, testCase{
12296 testType: serverTest,
12297 name: "SendReceiveIntermediate-Server-" + ver.name,
12298 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012299 MinVersion: ver.version,
12300 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012301 Certificates: []Certificate{rsaChainCertificate},
12302 },
David Benjamina5022392017-07-10 17:40:39 -040012303 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012304 expectPeerCertificate: &rsaChainCertificate,
12305 flags: []string{
12306 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12307 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12308 "-require-any-client-certificate",
12309 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12310 },
12311 })
David Benjamin3969fdf2017-08-29 15:50:58 -040012312
12313 // Test that garbage leaf certificates are properly rejected.
12314 testCases = append(testCases, testCase{
12315 testType: clientTest,
12316 name: "GarbageCertificate-Client-" + ver.name,
12317 config: Config{
12318 MinVersion: ver.version,
12319 MaxVersion: ver.version,
12320 Certificates: []Certificate{garbageCertificate},
12321 },
12322 tls13Variant: ver.tls13Variant,
12323 shouldFail: true,
12324 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12325 expectedLocalError: "remote error: error decoding message",
12326 })
12327
12328 testCases = append(testCases, testCase{
12329 testType: serverTest,
12330 name: "GarbageCertificate-Server-" + ver.name,
12331 config: Config{
12332 MinVersion: ver.version,
12333 MaxVersion: ver.version,
12334 Certificates: []Certificate{garbageCertificate},
12335 },
12336 tls13Variant: ver.tls13Variant,
12337 flags: []string{"-require-any-client-certificate"},
12338 shouldFail: true,
12339 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12340 expectedLocalError: "remote error: error decoding message",
12341 })
David Benjamin2c516452016-11-15 10:16:54 +090012342 }
12343}
12344
David Benjaminbbaf3672016-11-17 10:53:09 +090012345func addRetainOnlySHA256ClientCertTests() {
12346 for _, ver := range tlsVersions {
12347 // Test that enabling
12348 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12349 // actually requesting a client certificate is a no-op.
12350 testCases = append(testCases, testCase{
12351 testType: serverTest,
12352 name: "RetainOnlySHA256-NoCert-" + ver.name,
12353 config: Config{
12354 MinVersion: ver.version,
12355 MaxVersion: ver.version,
12356 },
David Benjamina5022392017-07-10 17:40:39 -040012357 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012358 flags: []string{
David Benjaminf2165072017-08-23 23:01:37 -070012359 "-on-initial-retain-only-sha256-client-cert",
12360 "-on-resume-retain-only-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012361 },
12362 resumeSession: true,
12363 })
12364
12365 // Test that when retaining only a SHA-256 certificate is
12366 // enabled, the hash appears as expected.
12367 testCases = append(testCases, testCase{
12368 testType: serverTest,
12369 name: "RetainOnlySHA256-Cert-" + ver.name,
12370 config: Config{
12371 MinVersion: ver.version,
12372 MaxVersion: ver.version,
12373 Certificates: []Certificate{rsaCertificate},
12374 },
David Benjamina5022392017-07-10 17:40:39 -040012375 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012376 flags: []string{
12377 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012378 "-on-initial-retain-only-sha256-client-cert",
12379 "-on-resume-retain-only-sha256-client-cert",
12380 "-on-initial-expect-sha256-client-cert",
12381 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012382 },
12383 resumeSession: true,
12384 })
12385
12386 // Test that when the config changes from on to off, a
12387 // resumption is rejected because the server now wants the full
12388 // certificate chain.
12389 testCases = append(testCases, testCase{
12390 testType: serverTest,
12391 name: "RetainOnlySHA256-OnOff-" + ver.name,
12392 config: Config{
12393 MinVersion: ver.version,
12394 MaxVersion: ver.version,
12395 Certificates: []Certificate{rsaCertificate},
12396 },
David Benjamina5022392017-07-10 17:40:39 -040012397 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012398 flags: []string{
12399 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012400 "-on-initial-retain-only-sha256-client-cert",
12401 "-on-initial-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012402 },
12403 resumeSession: true,
12404 expectResumeRejected: true,
12405 })
12406
12407 // Test that when the config changes from off to on, a
12408 // resumption is rejected because the server now wants just the
12409 // hash.
12410 testCases = append(testCases, testCase{
12411 testType: serverTest,
12412 name: "RetainOnlySHA256-OffOn-" + ver.name,
12413 config: Config{
12414 MinVersion: ver.version,
12415 MaxVersion: ver.version,
12416 Certificates: []Certificate{rsaCertificate},
12417 },
David Benjamina5022392017-07-10 17:40:39 -040012418 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012419 flags: []string{
12420 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012421 "-on-resume-retain-only-sha256-client-cert",
12422 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012423 },
12424 resumeSession: true,
12425 expectResumeRejected: true,
12426 })
12427 }
12428}
12429
Adam Langleya4b91982016-12-12 12:05:53 -080012430func addECDSAKeyUsageTests() {
12431 p256 := elliptic.P256()
12432 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12433 if err != nil {
12434 panic(err)
12435 }
12436
12437 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12438 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12439 if err != nil {
12440 panic(err)
12441 }
12442
12443 template := x509.Certificate{
12444 SerialNumber: serialNumber,
12445 Subject: pkix.Name{
12446 Organization: []string{"Acme Co"},
12447 },
12448 NotBefore: time.Now(),
12449 NotAfter: time.Now(),
12450
12451 // An ECC certificate with only the keyAgreement key usgae may
12452 // be used with ECDH, but not ECDSA.
12453 KeyUsage: x509.KeyUsageKeyAgreement,
12454 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12455 BasicConstraintsValid: true,
12456 }
12457
12458 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12459 if err != nil {
12460 panic(err)
12461 }
12462
12463 cert := Certificate{
12464 Certificate: [][]byte{derBytes},
12465 PrivateKey: priv,
12466 }
12467
12468 for _, ver := range tlsVersions {
12469 if ver.version < VersionTLS12 {
12470 continue
12471 }
12472
12473 testCases = append(testCases, testCase{
12474 testType: clientTest,
12475 name: "ECDSAKeyUsage-" + ver.name,
12476 config: Config{
12477 MinVersion: ver.version,
12478 MaxVersion: ver.version,
12479 Certificates: []Certificate{cert},
12480 },
David Benjamina5022392017-07-10 17:40:39 -040012481 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012482 shouldFail: true,
12483 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12484 })
12485 }
12486}
12487
David Benjamin8c26d752017-03-26 15:13:51 -050012488func addExtraHandshakeTests() {
12489 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12490 // to ensure there is no transport I/O.
12491 testCases = append(testCases, testCase{
12492 testType: clientTest,
12493 name: "ExtraHandshake-Client-TLS12",
12494 config: Config{
12495 MinVersion: VersionTLS12,
12496 MaxVersion: VersionTLS12,
12497 },
12498 flags: []string{
12499 "-async",
12500 "-no-op-extra-handshake",
12501 },
12502 })
12503 testCases = append(testCases, testCase{
12504 testType: serverTest,
12505 name: "ExtraHandshake-Server-TLS12",
12506 config: Config{
12507 MinVersion: VersionTLS12,
12508 MaxVersion: VersionTLS12,
12509 },
12510 flags: []string{
12511 "-async",
12512 "-no-op-extra-handshake",
12513 },
12514 })
12515 testCases = append(testCases, testCase{
12516 testType: clientTest,
12517 name: "ExtraHandshake-Client-TLS13",
12518 config: Config{
12519 MinVersion: VersionTLS13,
12520 MaxVersion: VersionTLS13,
12521 },
12522 flags: []string{
12523 "-async",
12524 "-no-op-extra-handshake",
12525 },
12526 })
12527 testCases = append(testCases, testCase{
12528 testType: serverTest,
12529 name: "ExtraHandshake-Server-TLS13",
12530 config: Config{
12531 MinVersion: VersionTLS13,
12532 MaxVersion: VersionTLS13,
12533 },
12534 flags: []string{
12535 "-async",
12536 "-no-op-extra-handshake",
12537 },
12538 })
12539
12540 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12541 testCases = append(testCases, testCase{
12542 testType: serverTest,
12543 name: "ExtraHandshake-Server-EarlyData-TLS13",
12544 config: Config{
12545 MaxVersion: VersionTLS13,
12546 MinVersion: VersionTLS13,
12547 Bugs: ProtocolBugs{
12548 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12549 ExpectEarlyDataAccepted: true,
12550 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12551 },
12552 },
12553 messageCount: 2,
12554 resumeSession: true,
12555 flags: []string{
12556 "-async",
12557 "-enable-early-data",
12558 "-expect-accept-early-data",
12559 "-no-op-extra-handshake",
12560 },
12561 })
12562
12563 // An extra SSL_do_handshake drives the handshake to completion in False
12564 // Start. We test this by handshaking twice and asserting the False
12565 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12566 // how the test works.
12567 testCases = append(testCases, testCase{
12568 testType: clientTest,
12569 name: "ExtraHandshake-FalseStart",
12570 config: Config{
12571 MaxVersion: VersionTLS12,
12572 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12573 NextProtos: []string{"foo"},
12574 Bugs: ProtocolBugs{
12575 ExpectFalseStart: true,
12576 AlertBeforeFalseStartTest: alertAccessDenied,
12577 },
12578 },
12579 flags: []string{
12580 "-handshake-twice",
12581 "-false-start",
12582 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012583 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012584 },
12585 shimWritesFirst: true,
12586 shouldFail: true,
12587 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12588 expectedLocalError: "tls: peer did not false start: EOF",
12589 })
12590}
12591
David Benjaminb853f312017-07-14 18:40:34 -040012592// Test that omitted and empty extensions blocks are tolerated.
12593func addOmitExtensionsTests() {
David Benjamin0a471912017-08-31 00:19:57 -040012594 // Check the ExpectOmitExtensions setting works.
12595 testCases = append(testCases, testCase{
12596 testType: serverTest,
12597 name: "ExpectOmitExtensions",
12598 config: Config{
12599 MinVersion: VersionTLS12,
12600 MaxVersion: VersionTLS12,
12601 Bugs: ProtocolBugs{
12602 ExpectOmitExtensions: true,
12603 },
12604 },
12605 shouldFail: true,
12606 expectedLocalError: "tls: ServerHello did not omit extensions",
12607 })
12608
David Benjaminb853f312017-07-14 18:40:34 -040012609 for _, ver := range tlsVersions {
12610 if ver.version > VersionTLS12 {
12611 continue
12612 }
12613
12614 testCases = append(testCases, testCase{
12615 testType: serverTest,
12616 name: "OmitExtensions-ClientHello-" + ver.name,
12617 config: Config{
12618 MinVersion: ver.version,
12619 MaxVersion: ver.version,
12620 SessionTicketsDisabled: true,
12621 Bugs: ProtocolBugs{
12622 OmitExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012623 // With no client extensions, the ServerHello must not have
12624 // extensions. It should then omit the extensions field.
12625 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012626 },
12627 },
12628 })
12629
12630 testCases = append(testCases, testCase{
12631 testType: serverTest,
12632 name: "EmptyExtensions-ClientHello-" + ver.name,
12633 config: Config{
12634 MinVersion: ver.version,
12635 MaxVersion: ver.version,
12636 SessionTicketsDisabled: true,
12637 Bugs: ProtocolBugs{
12638 EmptyExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012639 // With no client extensions, the ServerHello must not have
12640 // extensions. It should then omit the extensions field.
12641 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012642 },
12643 },
12644 })
12645
12646 testCases = append(testCases, testCase{
12647 testType: clientTest,
12648 name: "OmitExtensions-ServerHello-" + ver.name,
12649 config: Config{
12650 MinVersion: ver.version,
12651 MaxVersion: ver.version,
12652 SessionTicketsDisabled: true,
12653 Bugs: ProtocolBugs{
12654 OmitExtensions: true,
12655 // Disable all ServerHello extensions so
12656 // OmitExtensions works.
12657 NoExtendedMasterSecret: true,
12658 NoRenegotiationInfo: true,
12659 },
12660 },
12661 })
12662
12663 testCases = append(testCases, testCase{
12664 testType: clientTest,
12665 name: "EmptyExtensions-ServerHello-" + ver.name,
12666 config: Config{
12667 MinVersion: ver.version,
12668 MaxVersion: ver.version,
12669 SessionTicketsDisabled: true,
12670 Bugs: ProtocolBugs{
12671 EmptyExtensions: true,
12672 // Disable all ServerHello extensions so
12673 // EmptyExtensions works.
12674 NoExtendedMasterSecret: true,
12675 NoRenegotiationInfo: true,
12676 },
12677 },
12678 })
12679 }
12680}
12681
Adam Langley7c803a62015-06-15 15:35:05 -070012682func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012683 defer wg.Done()
12684
12685 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012686 var err error
12687
David Benjaminba28dfc2016-11-15 17:47:21 +090012688 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012689 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12690 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012691 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012692 if err != nil {
12693 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12694 }
12695 break
12696 }
12697 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012698 } else if *repeatUntilFailure {
12699 for err == nil {
12700 statusChan <- statusMsg{test: test, started: true}
12701 err = runTest(test, shimPath, -1)
12702 }
12703 } else {
12704 statusChan <- statusMsg{test: test, started: true}
12705 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012706 }
Adam Langley95c29f32014-06-20 12:00:00 -070012707 statusChan <- statusMsg{test: test, err: err}
12708 }
12709}
12710
12711type statusMsg struct {
12712 test *testCase
12713 started bool
12714 err error
12715}
12716
David Benjamin5f237bc2015-02-11 17:14:15 -050012717func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012718 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012719
David Benjamin5f237bc2015-02-11 17:14:15 -050012720 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012721 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012722 if !*pipe {
12723 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012724 var erase string
12725 for i := 0; i < lineLen; i++ {
12726 erase += "\b \b"
12727 }
12728 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012729 }
12730
Adam Langley95c29f32014-06-20 12:00:00 -070012731 if msg.started {
12732 started++
12733 } else {
12734 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012735
12736 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012737 if msg.err == errUnimplemented {
12738 if *pipe {
12739 // Print each test instead of a status line.
12740 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12741 }
12742 unimplemented++
12743 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12744 } else {
12745 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12746 failed++
12747 testOutput.addResult(msg.test.name, "FAIL")
12748 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012749 } else {
12750 if *pipe {
12751 // Print each test instead of a status line.
12752 fmt.Printf("PASSED (%s)\n", msg.test.name)
12753 }
12754 testOutput.addResult(msg.test.name, "PASS")
12755 }
Adam Langley95c29f32014-06-20 12:00:00 -070012756 }
12757
David Benjamin5f237bc2015-02-11 17:14:15 -050012758 if !*pipe {
12759 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012760 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012761 lineLen = len(line)
12762 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012763 }
Adam Langley95c29f32014-06-20 12:00:00 -070012764 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012765
12766 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012767}
12768
12769func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012770 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012771 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012772 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012773
Adam Langley7c803a62015-06-15 15:35:05 -070012774 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012775 addCipherSuiteTests()
12776 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012777 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012778 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012779 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012780 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012781 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012782 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012783 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012784 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012785 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012786 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012787 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012788 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012789 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012790 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012791 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012792 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012793 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012794 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012795 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012796 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012797 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012798 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012799 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012800 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012801 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012802 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012803 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012804 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012805 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012806 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012807 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012808 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012809 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012810
12811 var wg sync.WaitGroup
12812
Adam Langley7c803a62015-06-15 15:35:05 -070012813 statusChan := make(chan statusMsg, *numWorkers)
12814 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012815 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012816
EKRf71d7ed2016-08-06 13:25:12 -070012817 if len(*shimConfigFile) != 0 {
12818 encoded, err := ioutil.ReadFile(*shimConfigFile)
12819 if err != nil {
12820 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12821 os.Exit(1)
12822 }
12823
12824 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12825 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12826 os.Exit(1)
12827 }
12828 }
12829
David Benjamin025b3d32014-07-01 19:53:04 -040012830 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012831
Adam Langley7c803a62015-06-15 15:35:05 -070012832 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012833 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012834 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012835 }
12836
David Benjamin270f0a72016-03-17 14:41:36 -040012837 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012838 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012839 matched := true
12840 if len(*testToRun) != 0 {
12841 var err error
12842 matched, err = filepath.Match(*testToRun, testCases[i].name)
12843 if err != nil {
12844 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12845 os.Exit(1)
12846 }
12847 }
12848
EKRf71d7ed2016-08-06 13:25:12 -070012849 if !*includeDisabled {
12850 for pattern := range shimConfig.DisabledTests {
12851 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12852 if err != nil {
12853 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12854 os.Exit(1)
12855 }
12856
12857 if isDisabled {
12858 matched = false
12859 break
12860 }
12861 }
12862 }
12863
David Benjamin17e12922016-07-28 18:04:43 -040012864 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012865 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012866 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012867
12868 // Only run one test if repeating until failure.
12869 if *repeatUntilFailure {
12870 break
12871 }
Adam Langley95c29f32014-06-20 12:00:00 -070012872 }
12873 }
David Benjamin17e12922016-07-28 18:04:43 -040012874
David Benjamin270f0a72016-03-17 14:41:36 -040012875 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012876 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012877 os.Exit(1)
12878 }
Adam Langley95c29f32014-06-20 12:00:00 -070012879
12880 close(testChan)
12881 wg.Wait()
12882 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012883 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012884
12885 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012886
12887 if *jsonOutput != "" {
12888 if err := testOutput.writeTo(*jsonOutput); err != nil {
12889 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12890 }
12891 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012892
EKR842ae6c2016-07-27 09:22:05 +020012893 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12894 os.Exit(1)
12895 }
12896
12897 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012898 os.Exit(1)
12899 }
Adam Langley95c29f32014-06-20 12:00:00 -070012900}