blob: ee72c2ef046ef4e670c87a44e2c95ae0a1d9cb0f [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 Valdezc7d4d212017-09-11 13:53:08 -04001313 name: "TLS13Experiment3",
1314 version: VersionTLS13,
1315 excludeFlag: "-no-tls13",
1316 versionWire: tls13Experiment3Version,
1317 tls13Variant: TLS13Experiment3,
1318 },
1319 {
Steven Valdezdbe01582017-07-14 10:39:28 -04001320 name: "TLS13RecordTypeExperiment",
1321 version: VersionTLS13,
1322 excludeFlag: "-no-tls13",
1323 versionWire: tls13RecordTypeExperimentVersion,
1324 tls13Variant: TLS13RecordTypeExperiment,
1325 },
Steven Valdez520e1222017-06-13 12:45:25 -04001326}
1327
1328func allVersions(protocol protocol) []tlsVersion {
1329 if protocol == tls {
1330 return tlsVersions
1331 }
1332
1333 var ret []tlsVersion
1334 for _, vers := range tlsVersions {
1335 if vers.hasDTLS {
1336 ret = append(ret, vers)
1337 }
1338 }
1339 return ret
Adam Langley95c29f32014-06-20 12:00:00 -07001340}
1341
David Benjaminaa012042016-12-10 13:33:05 -05001342type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001343 name string
1344 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001345}
1346
1347var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001348 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001349 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001350 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001351 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001352 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001353 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001354 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001355 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1356 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001357 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1358 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001359 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001360 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001361 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001362 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001363 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001364 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001365 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001366 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001367 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001368 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001369 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1370 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001371 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1372 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001373 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001374 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1375 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1376 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001377 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001378}
1379
David Benjamin8b8c0062014-11-23 02:47:52 -05001380func hasComponent(suiteName, component string) bool {
1381 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1382}
1383
David Benjaminf7768e42014-08-31 02:06:47 -04001384func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001385 return hasComponent(suiteName, "GCM") ||
1386 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001387 hasComponent(suiteName, "SHA384") ||
1388 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001389}
1390
Nick Harper1fd39d82016-06-14 18:14:35 -07001391func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001392 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001393}
1394
David Benjamin8b8c0062014-11-23 02:47:52 -05001395func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001396 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001397}
1398
Adam Langleya7997f12015-05-14 17:38:50 -07001399func bigFromHex(hex string) *big.Int {
1400 ret, ok := new(big.Int).SetString(hex, 16)
1401 if !ok {
1402 panic("failed to parse hex number 0x" + hex)
1403 }
1404 return ret
1405}
1406
Adam Langley7c803a62015-06-15 15:35:05 -07001407func addBasicTests() {
1408 basicTests := []testCase{
1409 {
Adam Langley7c803a62015-06-15 15:35:05 -07001410 name: "NoFallbackSCSV",
1411 config: Config{
1412 Bugs: ProtocolBugs{
1413 FailIfNotFallbackSCSV: true,
1414 },
1415 },
1416 shouldFail: true,
1417 expectedLocalError: "no fallback SCSV found",
1418 },
1419 {
1420 name: "SendFallbackSCSV",
1421 config: Config{
1422 Bugs: ProtocolBugs{
1423 FailIfNotFallbackSCSV: true,
1424 },
1425 },
1426 flags: []string{"-fallback-scsv"},
1427 },
1428 {
1429 name: "ClientCertificateTypes",
1430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001431 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001432 ClientAuth: RequestClientCert,
1433 ClientCertificateTypes: []byte{
1434 CertTypeDSSSign,
1435 CertTypeRSASign,
1436 CertTypeECDSASign,
1437 },
1438 },
1439 flags: []string{
1440 "-expect-certificate-types",
1441 base64.StdEncoding.EncodeToString([]byte{
1442 CertTypeDSSSign,
1443 CertTypeRSASign,
1444 CertTypeECDSASign,
1445 }),
1446 },
1447 },
1448 {
Adam Langley7c803a62015-06-15 15:35:05 -07001449 name: "UnauthenticatedECDH",
1450 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001451 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001452 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1453 Bugs: ProtocolBugs{
1454 UnauthenticatedECDH: true,
1455 },
1456 },
1457 shouldFail: true,
1458 expectedError: ":UNEXPECTED_MESSAGE:",
1459 },
1460 {
1461 name: "SkipCertificateStatus",
1462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001463 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1465 Bugs: ProtocolBugs{
1466 SkipCertificateStatus: true,
1467 },
1468 },
1469 flags: []string{
1470 "-enable-ocsp-stapling",
David Benjamin78b8b992017-08-01 18:38:41 -04001471 // This test involves an optional message. Test the message callback
1472 // trace to ensure we do not miss or double-report any.
1473 "-expect-msg-callback",
1474 `write hs 1
1475read hs 2
1476read hs 11
1477read hs 12
1478read hs 14
1479write hs 16
1480write ccs
1481write hs 20
1482read hs 4
1483read ccs
1484read hs 20
1485read alert 1 0
1486`,
1487 },
1488 },
1489 {
1490 protocol: dtls,
1491 name: "SkipCertificateStatus-DTLS",
1492 config: Config{
1493 MaxVersion: VersionTLS12,
1494 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1495 Bugs: ProtocolBugs{
1496 SkipCertificateStatus: true,
1497 },
1498 },
1499 flags: []string{
1500 "-enable-ocsp-stapling",
1501 // This test involves an optional message. Test the message callback
1502 // trace to ensure we do not miss or double-report any.
1503 "-expect-msg-callback",
1504 `write hs 1
1505read hs 3
1506write hs 1
1507read hs 2
1508read hs 11
1509read hs 12
1510read hs 14
1511write hs 16
1512write ccs
1513write hs 20
1514read hs 4
1515read ccs
1516read hs 20
1517read alert 1 0
1518`,
Adam Langley7c803a62015-06-15 15:35:05 -07001519 },
1520 },
1521 {
1522 name: "SkipServerKeyExchange",
1523 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001524 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001525 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1526 Bugs: ProtocolBugs{
1527 SkipServerKeyExchange: true,
1528 },
1529 },
1530 shouldFail: true,
1531 expectedError: ":UNEXPECTED_MESSAGE:",
1532 },
1533 {
Adam Langley7c803a62015-06-15 15:35:05 -07001534 testType: serverTest,
Dimitar Vlahovskibd708452017-08-10 18:01:06 +02001535 name: "ServerSkipCertificateVerify",
1536 config: Config{
1537 MaxVersion: VersionTLS12,
1538 Certificates: []Certificate{rsaChainCertificate},
1539 Bugs: ProtocolBugs{
1540 SkipCertificateVerify: true,
1541 },
1542 },
1543 expectPeerCertificate: &rsaChainCertificate,
1544 flags: []string{
1545 "-require-any-client-certificate",
1546 },
1547 shouldFail: true,
1548 expectedError: ":UNEXPECTED_RECORD:",
1549 expectedLocalError: "remote error: unexpected message",
1550 },
1551 {
1552 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001553 name: "Alert",
1554 config: Config{
1555 Bugs: ProtocolBugs{
1556 SendSpuriousAlert: alertRecordOverflow,
1557 },
1558 },
1559 shouldFail: true,
1560 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1561 },
1562 {
1563 protocol: dtls,
1564 testType: serverTest,
1565 name: "Alert-DTLS",
1566 config: Config{
1567 Bugs: ProtocolBugs{
1568 SendSpuriousAlert: alertRecordOverflow,
1569 },
1570 },
1571 shouldFail: true,
1572 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1573 },
1574 {
1575 testType: serverTest,
1576 name: "FragmentAlert",
1577 config: Config{
1578 Bugs: ProtocolBugs{
1579 FragmentAlert: true,
1580 SendSpuriousAlert: alertRecordOverflow,
1581 },
1582 },
1583 shouldFail: true,
1584 expectedError: ":BAD_ALERT:",
1585 },
1586 {
1587 protocol: dtls,
1588 testType: serverTest,
1589 name: "FragmentAlert-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 FragmentAlert: true,
1593 SendSpuriousAlert: alertRecordOverflow,
1594 },
1595 },
1596 shouldFail: true,
1597 expectedError: ":BAD_ALERT:",
1598 },
1599 {
1600 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001601 name: "DoubleAlert",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 DoubleAlert: true,
1605 SendSpuriousAlert: alertRecordOverflow,
1606 },
1607 },
1608 shouldFail: true,
1609 expectedError: ":BAD_ALERT:",
1610 },
1611 {
1612 protocol: dtls,
1613 testType: serverTest,
1614 name: "DoubleAlert-DTLS",
1615 config: Config{
1616 Bugs: ProtocolBugs{
1617 DoubleAlert: true,
1618 SendSpuriousAlert: alertRecordOverflow,
1619 },
1620 },
1621 shouldFail: true,
1622 expectedError: ":BAD_ALERT:",
1623 },
1624 {
Adam Langley7c803a62015-06-15 15:35:05 -07001625 name: "SkipNewSessionTicket",
1626 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001627 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001628 Bugs: ProtocolBugs{
1629 SkipNewSessionTicket: true,
1630 },
1631 },
1632 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001633 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001634 },
1635 {
1636 testType: serverTest,
1637 name: "FallbackSCSV",
1638 config: Config{
1639 MaxVersion: VersionTLS11,
1640 Bugs: ProtocolBugs{
1641 SendFallbackSCSV: true,
1642 },
1643 },
David Benjamin56cadc32016-12-16 19:54:11 -05001644 shouldFail: true,
1645 expectedError: ":INAPPROPRIATE_FALLBACK:",
1646 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001647 },
1648 {
1649 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001650 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001651 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001652 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001653 Bugs: ProtocolBugs{
1654 SendFallbackSCSV: true,
1655 },
1656 },
1657 },
1658 {
1659 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001660 name: "FallbackSCSV-VersionMatch-TLS12",
1661 config: Config{
1662 MaxVersion: VersionTLS12,
1663 Bugs: ProtocolBugs{
1664 SendFallbackSCSV: true,
1665 },
1666 },
1667 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1668 },
1669 {
1670 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001671 name: "FragmentedClientVersion",
1672 config: Config{
1673 Bugs: ProtocolBugs{
1674 MaxHandshakeRecordLength: 1,
1675 FragmentClientVersion: true,
1676 },
1677 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001678 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001679 },
1680 {
Adam Langley7c803a62015-06-15 15:35:05 -07001681 testType: serverTest,
1682 name: "HttpGET",
1683 sendPrefix: "GET / HTTP/1.0\n",
1684 shouldFail: true,
1685 expectedError: ":HTTP_REQUEST:",
1686 },
1687 {
1688 testType: serverTest,
1689 name: "HttpPOST",
1690 sendPrefix: "POST / HTTP/1.0\n",
1691 shouldFail: true,
1692 expectedError: ":HTTP_REQUEST:",
1693 },
1694 {
1695 testType: serverTest,
1696 name: "HttpHEAD",
1697 sendPrefix: "HEAD / HTTP/1.0\n",
1698 shouldFail: true,
1699 expectedError: ":HTTP_REQUEST:",
1700 },
1701 {
1702 testType: serverTest,
1703 name: "HttpPUT",
1704 sendPrefix: "PUT / HTTP/1.0\n",
1705 shouldFail: true,
1706 expectedError: ":HTTP_REQUEST:",
1707 },
1708 {
1709 testType: serverTest,
1710 name: "HttpCONNECT",
1711 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1712 shouldFail: true,
1713 expectedError: ":HTTPS_PROXY_REQUEST:",
1714 },
1715 {
1716 testType: serverTest,
1717 name: "Garbage",
1718 sendPrefix: "blah",
1719 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001720 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001721 },
1722 {
Adam Langley7c803a62015-06-15 15:35:05 -07001723 name: "RSAEphemeralKey",
1724 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001725 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001726 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1727 Bugs: ProtocolBugs{
1728 RSAEphemeralKey: true,
1729 },
1730 },
1731 shouldFail: true,
1732 expectedError: ":UNEXPECTED_MESSAGE:",
1733 },
1734 {
1735 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001736 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001737 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001738 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001739 },
1740 {
1741 protocol: dtls,
1742 name: "DisableEverything-DTLS",
1743 flags: []string{"-no-tls12", "-no-tls1"},
1744 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001745 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001746 },
1747 {
Adam Langley7c803a62015-06-15 15:35:05 -07001748 protocol: dtls,
1749 testType: serverTest,
1750 name: "MTU",
1751 config: Config{
1752 Bugs: ProtocolBugs{
1753 MaxPacketLength: 256,
1754 },
1755 },
1756 flags: []string{"-mtu", "256"},
1757 },
1758 {
1759 protocol: dtls,
1760 testType: serverTest,
1761 name: "MTUExceeded",
1762 config: Config{
1763 Bugs: ProtocolBugs{
1764 MaxPacketLength: 255,
1765 },
1766 },
1767 flags: []string{"-mtu", "256"},
1768 shouldFail: true,
1769 expectedLocalError: "dtls: exceeded maximum packet length",
1770 },
1771 {
Adam Langley7c803a62015-06-15 15:35:05 -07001772 name: "EmptyCertificateList",
1773 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001774 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001775 Bugs: ProtocolBugs{
1776 EmptyCertificateList: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DECODE_ERROR:",
1781 },
1782 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001783 name: "EmptyCertificateList-TLS13",
1784 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001785 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001786 Bugs: ProtocolBugs{
1787 EmptyCertificateList: true,
1788 },
1789 },
1790 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001791 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001792 },
1793 {
Adam Langley7c803a62015-06-15 15:35:05 -07001794 name: "TLSFatalBadPackets",
1795 damageFirstWrite: true,
1796 shouldFail: true,
1797 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1798 },
1799 {
1800 protocol: dtls,
1801 name: "DTLSIgnoreBadPackets",
1802 damageFirstWrite: true,
1803 },
1804 {
1805 protocol: dtls,
1806 name: "DTLSIgnoreBadPackets-Async",
1807 damageFirstWrite: true,
1808 flags: []string{"-async"},
1809 },
1810 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001811 name: "AppDataBeforeHandshake",
1812 config: Config{
1813 Bugs: ProtocolBugs{
1814 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1815 },
1816 },
1817 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001818 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001819 },
1820 {
1821 name: "AppDataBeforeHandshake-Empty",
1822 config: Config{
1823 Bugs: ProtocolBugs{
1824 AppDataBeforeHandshake: []byte{},
1825 },
1826 },
1827 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001828 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001829 },
1830 {
1831 protocol: dtls,
1832 name: "AppDataBeforeHandshake-DTLS",
1833 config: Config{
1834 Bugs: ProtocolBugs{
1835 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1836 },
1837 },
1838 shouldFail: true,
1839 expectedError: ":UNEXPECTED_RECORD:",
1840 },
1841 {
1842 protocol: dtls,
1843 name: "AppDataBeforeHandshake-DTLS-Empty",
1844 config: Config{
1845 Bugs: ProtocolBugs{
1846 AppDataBeforeHandshake: []byte{},
1847 },
1848 },
1849 shouldFail: true,
1850 expectedError: ":UNEXPECTED_RECORD:",
1851 },
1852 {
Adam Langley7c803a62015-06-15 15:35:05 -07001853 name: "AppDataAfterChangeCipherSpec",
1854 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001855 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001856 Bugs: ProtocolBugs{
1857 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1858 },
1859 },
1860 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001861 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001862 },
1863 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001864 name: "AppDataAfterChangeCipherSpec-Empty",
1865 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001866 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001867 Bugs: ProtocolBugs{
1868 AppDataAfterChangeCipherSpec: []byte{},
1869 },
1870 },
1871 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001872 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001873 },
1874 {
Adam Langley7c803a62015-06-15 15:35:05 -07001875 protocol: dtls,
1876 name: "AppDataAfterChangeCipherSpec-DTLS",
1877 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001878 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001879 Bugs: ProtocolBugs{
1880 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1881 },
1882 },
1883 // BoringSSL's DTLS implementation will drop the out-of-order
1884 // application data.
1885 },
1886 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001887 protocol: dtls,
1888 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1889 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001890 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001891 Bugs: ProtocolBugs{
1892 AppDataAfterChangeCipherSpec: []byte{},
1893 },
1894 },
1895 // BoringSSL's DTLS implementation will drop the out-of-order
1896 // application data.
1897 },
1898 {
Adam Langley7c803a62015-06-15 15:35:05 -07001899 name: "AlertAfterChangeCipherSpec",
1900 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001901 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001902 Bugs: ProtocolBugs{
1903 AlertAfterChangeCipherSpec: alertRecordOverflow,
1904 },
1905 },
1906 shouldFail: true,
1907 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1908 },
1909 {
1910 protocol: dtls,
1911 name: "AlertAfterChangeCipherSpec-DTLS",
1912 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001913 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001914 Bugs: ProtocolBugs{
1915 AlertAfterChangeCipherSpec: alertRecordOverflow,
1916 },
1917 },
1918 shouldFail: true,
1919 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1920 },
1921 {
1922 protocol: dtls,
1923 name: "ReorderHandshakeFragments-Small-DTLS",
1924 config: Config{
1925 Bugs: ProtocolBugs{
1926 ReorderHandshakeFragments: true,
1927 // Small enough that every handshake message is
1928 // fragmented.
1929 MaxHandshakeRecordLength: 2,
1930 },
1931 },
1932 },
1933 {
1934 protocol: dtls,
1935 name: "ReorderHandshakeFragments-Large-DTLS",
1936 config: Config{
1937 Bugs: ProtocolBugs{
1938 ReorderHandshakeFragments: true,
1939 // Large enough that no handshake message is
1940 // fragmented.
1941 MaxHandshakeRecordLength: 2048,
1942 },
1943 },
1944 },
1945 {
1946 protocol: dtls,
1947 name: "MixCompleteMessageWithFragments-DTLS",
1948 config: Config{
1949 Bugs: ProtocolBugs{
1950 ReorderHandshakeFragments: true,
1951 MixCompleteMessageWithFragments: true,
1952 MaxHandshakeRecordLength: 2,
1953 },
1954 },
1955 },
1956 {
1957 name: "SendInvalidRecordType",
1958 config: Config{
1959 Bugs: ProtocolBugs{
1960 SendInvalidRecordType: true,
1961 },
1962 },
1963 shouldFail: true,
1964 expectedError: ":UNEXPECTED_RECORD:",
1965 },
1966 {
1967 protocol: dtls,
1968 name: "SendInvalidRecordType-DTLS",
1969 config: Config{
1970 Bugs: ProtocolBugs{
1971 SendInvalidRecordType: true,
1972 },
1973 },
1974 shouldFail: true,
1975 expectedError: ":UNEXPECTED_RECORD:",
1976 },
1977 {
1978 name: "FalseStart-SkipServerSecondLeg",
1979 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001980 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1982 NextProtos: []string{"foo"},
1983 Bugs: ProtocolBugs{
1984 SkipNewSessionTicket: true,
1985 SkipChangeCipherSpec: true,
1986 SkipFinished: true,
1987 ExpectFalseStart: true,
1988 },
1989 },
1990 flags: []string{
1991 "-false-start",
1992 "-handshake-never-done",
1993 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001994 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001995 },
1996 shimWritesFirst: true,
1997 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001998 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001999 },
2000 {
2001 name: "FalseStart-SkipServerSecondLeg-Implicit",
2002 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002003 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002004 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2005 NextProtos: []string{"foo"},
2006 Bugs: ProtocolBugs{
2007 SkipNewSessionTicket: true,
2008 SkipChangeCipherSpec: true,
2009 SkipFinished: true,
2010 },
2011 },
2012 flags: []string{
2013 "-implicit-handshake",
2014 "-false-start",
2015 "-handshake-never-done",
2016 "-advertise-alpn", "\x03foo",
2017 },
2018 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04002019 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07002020 },
2021 {
2022 testType: serverTest,
2023 name: "FailEarlyCallback",
2024 flags: []string{"-fail-early-callback"},
2025 shouldFail: true,
2026 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04002027 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07002028 },
2029 {
David Benjaminb8d74f52016-11-14 22:02:50 +09002030 name: "FailCertCallback-Client-TLS12",
2031 config: Config{
2032 MaxVersion: VersionTLS12,
2033 ClientAuth: RequestClientCert,
2034 },
2035 flags: []string{"-fail-cert-callback"},
2036 shouldFail: true,
2037 expectedError: ":CERT_CB_ERROR:",
2038 expectedLocalError: "remote error: internal error",
2039 },
2040 {
2041 testType: serverTest,
2042 name: "FailCertCallback-Server-TLS12",
2043 config: Config{
2044 MaxVersion: VersionTLS12,
2045 },
2046 flags: []string{"-fail-cert-callback"},
2047 shouldFail: true,
2048 expectedError: ":CERT_CB_ERROR:",
2049 expectedLocalError: "remote error: internal error",
2050 },
2051 {
2052 name: "FailCertCallback-Client-TLS13",
2053 config: Config{
2054 MaxVersion: VersionTLS13,
2055 ClientAuth: RequestClientCert,
2056 },
2057 flags: []string{"-fail-cert-callback"},
2058 shouldFail: true,
2059 expectedError: ":CERT_CB_ERROR:",
2060 expectedLocalError: "remote error: internal error",
2061 },
2062 {
2063 testType: serverTest,
2064 name: "FailCertCallback-Server-TLS13",
2065 config: Config{
2066 MaxVersion: VersionTLS13,
2067 },
2068 flags: []string{"-fail-cert-callback"},
2069 shouldFail: true,
2070 expectedError: ":CERT_CB_ERROR:",
2071 expectedLocalError: "remote error: internal error",
2072 },
2073 {
Adam Langley7c803a62015-06-15 15:35:05 -07002074 protocol: dtls,
2075 name: "FragmentMessageTypeMismatch-DTLS",
2076 config: Config{
2077 Bugs: ProtocolBugs{
2078 MaxHandshakeRecordLength: 2,
2079 FragmentMessageTypeMismatch: true,
2080 },
2081 },
2082 shouldFail: true,
2083 expectedError: ":FRAGMENT_MISMATCH:",
2084 },
2085 {
2086 protocol: dtls,
2087 name: "FragmentMessageLengthMismatch-DTLS",
2088 config: Config{
2089 Bugs: ProtocolBugs{
2090 MaxHandshakeRecordLength: 2,
2091 FragmentMessageLengthMismatch: true,
2092 },
2093 },
2094 shouldFail: true,
2095 expectedError: ":FRAGMENT_MISMATCH:",
2096 },
2097 {
2098 protocol: dtls,
2099 name: "SplitFragments-Header-DTLS",
2100 config: Config{
2101 Bugs: ProtocolBugs{
2102 SplitFragments: 2,
2103 },
2104 },
2105 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002106 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002107 },
2108 {
2109 protocol: dtls,
2110 name: "SplitFragments-Boundary-DTLS",
2111 config: Config{
2112 Bugs: ProtocolBugs{
2113 SplitFragments: dtlsRecordHeaderLen,
2114 },
2115 },
2116 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002117 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002118 },
2119 {
2120 protocol: dtls,
2121 name: "SplitFragments-Body-DTLS",
2122 config: Config{
2123 Bugs: ProtocolBugs{
2124 SplitFragments: dtlsRecordHeaderLen + 1,
2125 },
2126 },
2127 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04002128 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07002129 },
2130 {
2131 protocol: dtls,
2132 name: "SendEmptyFragments-DTLS",
2133 config: Config{
2134 Bugs: ProtocolBugs{
2135 SendEmptyFragments: true,
2136 },
2137 },
2138 },
2139 {
David Benjamine51fb0f2017-09-07 11:51:46 -04002140 testType: serverTest,
2141 protocol: dtls,
2142 name: "SendEmptyFragments-Padded-DTLS",
2143 config: Config{
2144 Bugs: ProtocolBugs{
2145 // Test empty fragments for a message with a
2146 // nice power-of-two length.
2147 PadClientHello: 64,
2148 SendEmptyFragments: true,
2149 },
2150 },
2151 },
2152 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002153 name: "BadFinished-Client",
2154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002155 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05002156 Bugs: ProtocolBugs{
2157 BadFinished: true,
2158 },
2159 },
2160 shouldFail: true,
2161 expectedError: ":DIGEST_CHECK_FAILED:",
2162 },
2163 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002164 name: "BadFinished-Client-TLS13",
2165 config: Config{
2166 MaxVersion: VersionTLS13,
2167 Bugs: ProtocolBugs{
2168 BadFinished: true,
2169 },
2170 },
2171 shouldFail: true,
2172 expectedError: ":DIGEST_CHECK_FAILED:",
2173 },
2174 {
David Benjaminbf82aed2016-03-01 22:57:40 -05002175 testType: serverTest,
2176 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07002177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002178 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002179 Bugs: ProtocolBugs{
2180 BadFinished: true,
2181 },
2182 },
2183 shouldFail: true,
2184 expectedError: ":DIGEST_CHECK_FAILED:",
2185 },
2186 {
Steven Valdez143e8b32016-07-11 13:19:03 -04002187 testType: serverTest,
2188 name: "BadFinished-Server-TLS13",
2189 config: Config{
2190 MaxVersion: VersionTLS13,
2191 Bugs: ProtocolBugs{
2192 BadFinished: true,
2193 },
2194 },
2195 shouldFail: true,
2196 expectedError: ":DIGEST_CHECK_FAILED:",
2197 },
2198 {
Adam Langley7c803a62015-06-15 15:35:05 -07002199 name: "FalseStart-BadFinished",
2200 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002201 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002202 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2203 NextProtos: []string{"foo"},
2204 Bugs: ProtocolBugs{
2205 BadFinished: true,
2206 ExpectFalseStart: true,
2207 },
2208 },
2209 flags: []string{
2210 "-false-start",
2211 "-handshake-never-done",
2212 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002213 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002214 },
2215 shimWritesFirst: true,
2216 shouldFail: true,
2217 expectedError: ":DIGEST_CHECK_FAILED:",
2218 },
2219 {
2220 name: "NoFalseStart-NoALPN",
2221 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002222 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002223 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2224 Bugs: ProtocolBugs{
2225 ExpectFalseStart: true,
2226 AlertBeforeFalseStartTest: alertAccessDenied,
2227 },
2228 },
2229 flags: []string{
2230 "-false-start",
2231 },
2232 shimWritesFirst: true,
2233 shouldFail: true,
2234 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2235 expectedLocalError: "tls: peer did not false start: EOF",
2236 },
2237 {
2238 name: "NoFalseStart-NoAEAD",
2239 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002240 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002241 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2242 NextProtos: []string{"foo"},
2243 Bugs: ProtocolBugs{
2244 ExpectFalseStart: true,
2245 AlertBeforeFalseStartTest: alertAccessDenied,
2246 },
2247 },
2248 flags: []string{
2249 "-false-start",
2250 "-advertise-alpn", "\x03foo",
2251 },
2252 shimWritesFirst: true,
2253 shouldFail: true,
2254 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2255 expectedLocalError: "tls: peer did not false start: EOF",
2256 },
2257 {
2258 name: "NoFalseStart-RSA",
2259 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002260 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002261 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2262 NextProtos: []string{"foo"},
2263 Bugs: ProtocolBugs{
2264 ExpectFalseStart: true,
2265 AlertBeforeFalseStartTest: alertAccessDenied,
2266 },
2267 },
2268 flags: []string{
2269 "-false-start",
2270 "-advertise-alpn", "\x03foo",
2271 },
2272 shimWritesFirst: true,
2273 shouldFail: true,
2274 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2275 expectedLocalError: "tls: peer did not false start: EOF",
2276 },
2277 {
Adam Langley7c803a62015-06-15 15:35:05 -07002278 protocol: dtls,
2279 name: "SendSplitAlert-Sync",
2280 config: Config{
2281 Bugs: ProtocolBugs{
2282 SendSplitAlert: true,
2283 },
2284 },
2285 },
2286 {
2287 protocol: dtls,
2288 name: "SendSplitAlert-Async",
2289 config: Config{
2290 Bugs: ProtocolBugs{
2291 SendSplitAlert: true,
2292 },
2293 },
2294 flags: []string{"-async"},
2295 },
2296 {
2297 protocol: dtls,
2298 name: "PackDTLSHandshake",
2299 config: Config{
2300 Bugs: ProtocolBugs{
2301 MaxHandshakeRecordLength: 2,
2302 PackHandshakeFragments: 20,
2303 PackHandshakeRecords: 200,
2304 },
2305 },
2306 },
2307 {
Adam Langley7c803a62015-06-15 15:35:05 -07002308 name: "SendEmptyRecords-Pass",
2309 sendEmptyRecords: 32,
2310 },
2311 {
2312 name: "SendEmptyRecords",
2313 sendEmptyRecords: 33,
2314 shouldFail: true,
2315 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2316 },
2317 {
2318 name: "SendEmptyRecords-Async",
2319 sendEmptyRecords: 33,
2320 flags: []string{"-async"},
2321 shouldFail: true,
2322 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2323 },
2324 {
David Benjamine8e84b92016-08-03 15:39:47 -04002325 name: "SendWarningAlerts-Pass",
2326 config: Config{
2327 MaxVersion: VersionTLS12,
2328 },
Adam Langley7c803a62015-06-15 15:35:05 -07002329 sendWarningAlerts: 4,
2330 },
2331 {
David Benjamine8e84b92016-08-03 15:39:47 -04002332 protocol: dtls,
2333 name: "SendWarningAlerts-DTLS-Pass",
2334 config: Config{
2335 MaxVersion: VersionTLS12,
2336 },
Adam Langley7c803a62015-06-15 15:35:05 -07002337 sendWarningAlerts: 4,
2338 },
2339 {
David Benjamine8e84b92016-08-03 15:39:47 -04002340 name: "SendWarningAlerts-TLS13",
2341 config: Config{
2342 MaxVersion: VersionTLS13,
2343 },
2344 sendWarningAlerts: 4,
2345 shouldFail: true,
2346 expectedError: ":BAD_ALERT:",
2347 expectedLocalError: "remote error: error decoding message",
2348 },
2349 {
2350 name: "SendWarningAlerts",
2351 config: Config{
2352 MaxVersion: VersionTLS12,
2353 },
Adam Langley7c803a62015-06-15 15:35:05 -07002354 sendWarningAlerts: 5,
2355 shouldFail: true,
2356 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2357 },
2358 {
David Benjamine8e84b92016-08-03 15:39:47 -04002359 name: "SendWarningAlerts-Async",
2360 config: Config{
2361 MaxVersion: VersionTLS12,
2362 },
Adam Langley7c803a62015-06-15 15:35:05 -07002363 sendWarningAlerts: 5,
2364 flags: []string{"-async"},
2365 shouldFail: true,
2366 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2367 },
David Benjaminba4594a2015-06-18 18:36:15 -04002368 {
David Benjamin24e58862017-06-14 18:45:29 -04002369 name: "SendBogusAlertType",
2370 sendBogusAlertType: true,
2371 shouldFail: true,
2372 expectedError: ":UNKNOWN_ALERT_TYPE:",
2373 expectedLocalError: "remote error: illegal parameter",
2374 },
2375 {
2376 protocol: dtls,
2377 name: "SendBogusAlertType-DTLS",
2378 sendBogusAlertType: true,
2379 shouldFail: true,
2380 expectedError: ":UNKNOWN_ALERT_TYPE:",
2381 expectedLocalError: "remote error: illegal parameter",
2382 },
2383 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002384 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002385 config: Config{
2386 MaxVersion: VersionTLS13,
2387 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002388 sendKeyUpdates: 33,
2389 keyUpdateRequest: keyUpdateNotRequested,
2390 shouldFail: true,
2391 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002392 },
2393 {
David Benjaminba4594a2015-06-18 18:36:15 -04002394 name: "EmptySessionID",
2395 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002396 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002397 SessionTicketsDisabled: true,
2398 },
2399 noSessionCache: true,
2400 flags: []string{"-expect-no-session"},
2401 },
David Benjamin30789da2015-08-29 22:56:45 -04002402 {
2403 name: "Unclean-Shutdown",
2404 config: Config{
2405 Bugs: ProtocolBugs{
2406 NoCloseNotify: true,
2407 ExpectCloseNotify: true,
2408 },
2409 },
2410 shimShutsDown: true,
2411 flags: []string{"-check-close-notify"},
2412 shouldFail: true,
2413 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2414 },
2415 {
2416 name: "Unclean-Shutdown-Ignored",
2417 config: Config{
2418 Bugs: ProtocolBugs{
2419 NoCloseNotify: true,
2420 },
2421 },
2422 shimShutsDown: true,
2423 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002424 {
David Benjaminfa214e42016-05-10 17:03:10 -04002425 name: "Unclean-Shutdown-Alert",
2426 config: Config{
2427 Bugs: ProtocolBugs{
2428 SendAlertOnShutdown: alertDecompressionFailure,
2429 ExpectCloseNotify: true,
2430 },
2431 },
2432 shimShutsDown: true,
2433 flags: []string{"-check-close-notify"},
2434 shouldFail: true,
2435 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2436 },
2437 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002438 name: "LargePlaintext",
2439 config: Config{
2440 Bugs: ProtocolBugs{
2441 SendLargeRecords: true,
2442 },
2443 },
2444 messageLen: maxPlaintext + 1,
2445 shouldFail: true,
2446 expectedError: ":DATA_LENGTH_TOO_LONG:",
2447 },
2448 {
2449 protocol: dtls,
2450 name: "LargePlaintext-DTLS",
2451 config: Config{
2452 Bugs: ProtocolBugs{
2453 SendLargeRecords: true,
2454 },
2455 },
2456 messageLen: maxPlaintext + 1,
2457 shouldFail: true,
2458 expectedError: ":DATA_LENGTH_TOO_LONG:",
2459 },
2460 {
2461 name: "LargeCiphertext",
2462 config: Config{
2463 Bugs: ProtocolBugs{
2464 SendLargeRecords: true,
2465 },
2466 },
2467 messageLen: maxPlaintext * 2,
2468 shouldFail: true,
2469 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2470 },
2471 {
2472 protocol: dtls,
2473 name: "LargeCiphertext-DTLS",
2474 config: Config{
2475 Bugs: ProtocolBugs{
2476 SendLargeRecords: true,
2477 },
2478 },
2479 messageLen: maxPlaintext * 2,
2480 // Unlike the other four cases, DTLS drops records which
2481 // are invalid before authentication, so the connection
2482 // does not fail.
2483 expectMessageDropped: true,
2484 },
David Benjamindd6fed92015-10-23 17:41:12 -04002485 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002486 name: "BadHelloRequest-1",
2487 renegotiate: 1,
2488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002489 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002490 Bugs: ProtocolBugs{
2491 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2492 },
2493 },
2494 flags: []string{
2495 "-renegotiate-freely",
2496 "-expect-total-renegotiations", "1",
2497 },
2498 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002499 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002500 },
2501 {
2502 name: "BadHelloRequest-2",
2503 renegotiate: 1,
2504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002505 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002506 Bugs: ProtocolBugs{
2507 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2508 },
2509 },
2510 flags: []string{
2511 "-renegotiate-freely",
2512 "-expect-total-renegotiations", "1",
2513 },
2514 shouldFail: true,
2515 expectedError: ":BAD_HELLO_REQUEST:",
2516 },
David Benjaminef1b0092015-11-21 14:05:44 -05002517 {
2518 testType: serverTest,
2519 name: "SupportTicketsWithSessionID",
2520 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002521 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002522 SessionTicketsDisabled: true,
2523 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002524 resumeConfig: &Config{
2525 MaxVersion: VersionTLS12,
2526 },
David Benjaminef1b0092015-11-21 14:05:44 -05002527 resumeSession: true,
2528 },
David Benjamin02edcd02016-07-27 17:40:37 -04002529 {
2530 protocol: dtls,
2531 name: "DTLS-SendExtraFinished",
2532 config: Config{
2533 Bugs: ProtocolBugs{
2534 SendExtraFinished: true,
2535 },
2536 },
2537 shouldFail: true,
2538 expectedError: ":UNEXPECTED_RECORD:",
2539 },
2540 {
2541 protocol: dtls,
2542 name: "DTLS-SendExtraFinished-Reordered",
2543 config: Config{
2544 Bugs: ProtocolBugs{
2545 MaxHandshakeRecordLength: 2,
2546 ReorderHandshakeFragments: true,
2547 SendExtraFinished: true,
2548 },
2549 },
2550 shouldFail: true,
2551 expectedError: ":UNEXPECTED_RECORD:",
2552 },
David Benjamine97fb482016-07-29 09:23:07 -04002553 {
2554 testType: serverTest,
2555 name: "V2ClientHello-EmptyRecordPrefix",
2556 config: Config{
2557 // Choose a cipher suite that does not involve
2558 // elliptic curves, so no extensions are
2559 // involved.
2560 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002561 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002562 Bugs: ProtocolBugs{
2563 SendV2ClientHello: true,
2564 },
2565 },
2566 sendPrefix: string([]byte{
2567 byte(recordTypeHandshake),
2568 3, 1, // version
2569 0, 0, // length
2570 }),
2571 // A no-op empty record may not be sent before V2ClientHello.
2572 shouldFail: true,
2573 expectedError: ":WRONG_VERSION_NUMBER:",
2574 },
2575 {
2576 testType: serverTest,
2577 name: "V2ClientHello-WarningAlertPrefix",
2578 config: Config{
2579 // Choose a cipher suite that does not involve
2580 // elliptic curves, so no extensions are
2581 // involved.
2582 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002583 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002584 Bugs: ProtocolBugs{
2585 SendV2ClientHello: true,
2586 },
2587 },
2588 sendPrefix: string([]byte{
2589 byte(recordTypeAlert),
2590 3, 1, // version
2591 0, 2, // length
2592 alertLevelWarning, byte(alertDecompressionFailure),
2593 }),
2594 // A no-op warning alert may not be sent before V2ClientHello.
2595 shouldFail: true,
2596 expectedError: ":WRONG_VERSION_NUMBER:",
2597 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002598 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002599 name: "KeyUpdate-Client",
2600 config: Config{
2601 MaxVersion: VersionTLS13,
2602 },
2603 sendKeyUpdates: 1,
2604 keyUpdateRequest: keyUpdateNotRequested,
2605 },
2606 {
2607 testType: serverTest,
2608 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002609 config: Config{
2610 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002611 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002612 sendKeyUpdates: 1,
2613 keyUpdateRequest: keyUpdateNotRequested,
2614 },
2615 {
2616 name: "KeyUpdate-InvalidRequestMode",
2617 config: Config{
2618 MaxVersion: VersionTLS13,
2619 },
2620 sendKeyUpdates: 1,
2621 keyUpdateRequest: 42,
2622 shouldFail: true,
2623 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002624 },
David Benjaminabe94e32016-09-04 14:18:58 -04002625 {
David Benjaminbbba9392017-04-06 12:54:12 -04002626 // Test that KeyUpdates are acknowledged properly.
2627 name: "KeyUpdate-RequestACK",
2628 config: Config{
2629 MaxVersion: VersionTLS13,
2630 Bugs: ProtocolBugs{
2631 RejectUnsolicitedKeyUpdate: true,
2632 },
2633 },
2634 // Test the shim receiving many KeyUpdates in a row.
2635 sendKeyUpdates: 5,
2636 messageCount: 5,
2637 keyUpdateRequest: keyUpdateRequested,
2638 },
2639 {
2640 // Test that KeyUpdates are acknowledged properly if the
2641 // peer's KeyUpdate is discovered while a write is
2642 // pending.
2643 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2644 config: Config{
2645 MaxVersion: VersionTLS13,
2646 Bugs: ProtocolBugs{
2647 RejectUnsolicitedKeyUpdate: true,
2648 },
2649 },
2650 // Test the shim receiving many KeyUpdates in a row.
2651 sendKeyUpdates: 5,
2652 messageCount: 5,
2653 keyUpdateRequest: keyUpdateRequested,
2654 readWithUnfinishedWrite: true,
2655 flags: []string{"-async"},
2656 },
2657 {
David Benjaminabe94e32016-09-04 14:18:58 -04002658 name: "SendSNIWarningAlert",
2659 config: Config{
2660 MaxVersion: VersionTLS12,
2661 Bugs: ProtocolBugs{
2662 SendSNIWarningAlert: true,
2663 },
2664 },
2665 },
David Benjaminc241d792016-09-09 10:34:20 -04002666 {
2667 testType: serverTest,
2668 name: "ExtraCompressionMethods-TLS12",
2669 config: Config{
2670 MaxVersion: VersionTLS12,
2671 Bugs: ProtocolBugs{
2672 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2673 },
2674 },
2675 },
2676 {
2677 testType: serverTest,
2678 name: "ExtraCompressionMethods-TLS13",
2679 config: Config{
2680 MaxVersion: VersionTLS13,
2681 Bugs: ProtocolBugs{
2682 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2683 },
2684 },
2685 shouldFail: true,
2686 expectedError: ":INVALID_COMPRESSION_LIST:",
2687 expectedLocalError: "remote error: illegal parameter",
2688 },
2689 {
2690 testType: serverTest,
2691 name: "NoNullCompression-TLS12",
2692 config: Config{
2693 MaxVersion: VersionTLS12,
2694 Bugs: ProtocolBugs{
2695 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2696 },
2697 },
2698 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002699 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002700 expectedLocalError: "remote error: illegal parameter",
2701 },
2702 {
2703 testType: serverTest,
2704 name: "NoNullCompression-TLS13",
2705 config: Config{
2706 MaxVersion: VersionTLS13,
2707 Bugs: ProtocolBugs{
2708 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2709 },
2710 },
2711 shouldFail: true,
2712 expectedError: ":INVALID_COMPRESSION_LIST:",
2713 expectedLocalError: "remote error: illegal parameter",
2714 },
David Benjamin413e79e2017-07-01 10:11:53 -04002715 // Test that the client rejects invalid compression methods
2716 // from the server.
2717 {
2718 testType: clientTest,
2719 name: "InvalidCompressionMethod",
2720 config: Config{
2721 MaxVersion: VersionTLS12,
2722 Bugs: ProtocolBugs{
2723 SendCompressionMethod: 1,
2724 },
2725 },
2726 shouldFail: true,
2727 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2728 expectedLocalError: "remote error: illegal parameter",
2729 },
David Benjamin65ac9972016-09-02 21:35:25 -04002730 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002731 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002732 config: Config{
2733 MaxVersion: VersionTLS12,
2734 Bugs: ProtocolBugs{
2735 ExpectGREASE: true,
2736 },
2737 },
2738 flags: []string{"-enable-grease"},
2739 },
2740 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002741 name: "GREASE-Client-TLS13",
2742 config: Config{
2743 MaxVersion: VersionTLS13,
2744 Bugs: ProtocolBugs{
2745 ExpectGREASE: true,
2746 },
2747 },
2748 flags: []string{"-enable-grease"},
2749 },
2750 {
2751 testType: serverTest,
2752 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002753 config: Config{
2754 MaxVersion: VersionTLS13,
2755 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002756 // TLS 1.3 servers are expected to
2757 // always enable GREASE. TLS 1.3 is new,
2758 // so there is no existing ecosystem to
2759 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002760 ExpectGREASE: true,
2761 },
2762 },
David Benjamin65ac9972016-09-02 21:35:25 -04002763 },
David Benjamine3fbb362017-01-06 16:19:28 -05002764 {
2765 // Test the server so there is a large certificate as
2766 // well as application data.
2767 testType: serverTest,
2768 name: "MaxSendFragment",
2769 config: Config{
2770 Bugs: ProtocolBugs{
2771 MaxReceivePlaintext: 512,
2772 },
2773 },
2774 messageLen: 1024,
2775 flags: []string{
2776 "-max-send-fragment", "512",
2777 "-read-size", "1024",
2778 },
2779 },
2780 {
2781 // Test the server so there is a large certificate as
2782 // well as application data.
2783 testType: serverTest,
2784 name: "MaxSendFragment-TooLarge",
2785 config: Config{
2786 Bugs: ProtocolBugs{
2787 // Ensure that some of the records are
2788 // 512.
2789 MaxReceivePlaintext: 511,
2790 },
2791 },
2792 messageLen: 1024,
2793 flags: []string{
2794 "-max-send-fragment", "512",
2795 "-read-size", "1024",
2796 },
2797 shouldFail: true,
2798 expectedLocalError: "local error: record overflow",
2799 },
David Benjaminaba057a2017-09-11 15:21:43 -04002800 {
2801 // Test that Java-like ClientHellos are provided session
2802 // IDs but resumption is always declined. This is to
2803 // workaround a bug that causes connection failures when
2804 // certificates rotate.
2805 testType: serverTest,
2806 name: "JavaWorkaround",
2807 config: Config{
2808 MaxVersion: VersionTLS12,
2809 CurvePreferences: []CurveID{CurveP256, CurveP384, CurveP521},
2810 SessionTicketsDisabled: true,
2811 Bugs: ProtocolBugs{
2812 SendOnlyECExtensions: true,
2813 },
2814 },
2815 flags: []string{"-expect-session-id"},
2816 resumeSession: true,
2817 expectResumeRejected: true,
2818 },
Adam Langley7c803a62015-06-15 15:35:05 -07002819 }
Adam Langley7c803a62015-06-15 15:35:05 -07002820 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002821
2822 // Test that very large messages can be received.
2823 cert := rsaCertificate
2824 for i := 0; i < 50; i++ {
2825 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2826 }
2827 testCases = append(testCases, testCase{
2828 name: "LargeMessage",
2829 config: Config{
2830 Certificates: []Certificate{cert},
2831 },
2832 })
2833 testCases = append(testCases, testCase{
2834 protocol: dtls,
2835 name: "LargeMessage-DTLS",
2836 config: Config{
2837 Certificates: []Certificate{cert},
2838 },
2839 })
2840
2841 // They are rejected if the maximum certificate chain length is capped.
2842 testCases = append(testCases, testCase{
2843 name: "LargeMessage-Reject",
2844 config: Config{
2845 Certificates: []Certificate{cert},
2846 },
2847 flags: []string{"-max-cert-list", "16384"},
2848 shouldFail: true,
2849 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2850 })
2851 testCases = append(testCases, testCase{
2852 protocol: dtls,
2853 name: "LargeMessage-Reject-DTLS",
2854 config: Config{
2855 Certificates: []Certificate{cert},
2856 },
2857 flags: []string{"-max-cert-list", "16384"},
2858 shouldFail: true,
2859 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2860 })
Adam Langley7c803a62015-06-15 15:35:05 -07002861}
2862
David Benjaminaa012042016-12-10 13:33:05 -05002863func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2864 const psk = "12345"
2865 const pskIdentity = "luggage combo"
2866
2867 var prefix string
2868 if protocol == dtls {
2869 if !ver.hasDTLS {
2870 return
2871 }
2872 prefix = "D"
2873 }
2874
2875 var cert Certificate
2876 var certFile string
2877 var keyFile string
2878 if hasComponent(suite.name, "ECDSA") {
2879 cert = ecdsaP256Certificate
2880 certFile = ecdsaP256CertificateFile
2881 keyFile = ecdsaP256KeyFile
2882 } else {
2883 cert = rsaCertificate
2884 certFile = rsaCertificateFile
2885 keyFile = rsaKeyFile
2886 }
2887
2888 var flags []string
2889 if hasComponent(suite.name, "PSK") {
2890 flags = append(flags,
2891 "-psk", psk,
2892 "-psk-identity", pskIdentity)
2893 }
2894 if hasComponent(suite.name, "NULL") {
2895 // NULL ciphers must be explicitly enabled.
2896 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2897 }
David Benjaminaa012042016-12-10 13:33:05 -05002898
2899 var shouldServerFail, shouldClientFail bool
2900 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2901 // BoringSSL clients accept ECDHE on SSLv3, but
2902 // a BoringSSL server will never select it
2903 // because the extension is missing.
2904 shouldServerFail = true
2905 }
2906 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2907 shouldClientFail = true
2908 shouldServerFail = true
2909 }
2910 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2911 shouldClientFail = true
2912 shouldServerFail = true
2913 }
2914 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2915 shouldClientFail = true
2916 shouldServerFail = true
2917 }
2918 if !isDTLSCipher(suite.name) && protocol == dtls {
2919 shouldClientFail = true
2920 shouldServerFail = true
2921 }
2922
2923 var sendCipherSuite uint16
2924 var expectedServerError, expectedClientError string
2925 serverCipherSuites := []uint16{suite.id}
2926 if shouldServerFail {
2927 expectedServerError = ":NO_SHARED_CIPHER:"
2928 }
2929 if shouldClientFail {
2930 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2931 // Configure the server to select ciphers as normal but
2932 // select an incompatible cipher in ServerHello.
2933 serverCipherSuites = nil
2934 sendCipherSuite = suite.id
2935 }
2936
David Benjamincdb6fe92017-02-07 16:06:48 -05002937 // For cipher suites and versions where exporters are defined, verify
2938 // that they interoperate.
2939 var exportKeyingMaterial int
2940 if ver.version > VersionSSL30 {
2941 exportKeyingMaterial = 1024
2942 }
2943
David Benjaminaa012042016-12-10 13:33:05 -05002944 testCases = append(testCases, testCase{
2945 testType: serverTest,
2946 protocol: protocol,
2947 name: prefix + ver.name + "-" + suite.name + "-server",
2948 config: Config{
2949 MinVersion: ver.version,
2950 MaxVersion: ver.version,
2951 CipherSuites: []uint16{suite.id},
2952 Certificates: []Certificate{cert},
2953 PreSharedKey: []byte(psk),
2954 PreSharedKeyIdentity: pskIdentity,
2955 Bugs: ProtocolBugs{
2956 AdvertiseAllConfiguredCiphers: true,
2957 },
2958 },
David Benjamina5022392017-07-10 17:40:39 -04002959 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002960 certFile: certFile,
2961 keyFile: keyFile,
2962 flags: flags,
2963 resumeSession: true,
2964 shouldFail: shouldServerFail,
2965 expectedError: expectedServerError,
2966 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002967 })
2968
2969 testCases = append(testCases, testCase{
2970 testType: clientTest,
2971 protocol: protocol,
2972 name: prefix + ver.name + "-" + suite.name + "-client",
2973 config: Config{
2974 MinVersion: ver.version,
2975 MaxVersion: ver.version,
2976 CipherSuites: serverCipherSuites,
2977 Certificates: []Certificate{cert},
2978 PreSharedKey: []byte(psk),
2979 PreSharedKeyIdentity: pskIdentity,
2980 Bugs: ProtocolBugs{
2981 IgnorePeerCipherPreferences: shouldClientFail,
2982 SendCipherSuite: sendCipherSuite,
2983 },
2984 },
David Benjamina5022392017-07-10 17:40:39 -04002985 tls13Variant: ver.tls13Variant,
David Benjamincdb6fe92017-02-07 16:06:48 -05002986 flags: flags,
2987 resumeSession: true,
2988 shouldFail: shouldClientFail,
2989 expectedError: expectedClientError,
2990 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002991 })
2992
David Benjamin6f600d62016-12-21 16:06:54 -05002993 if shouldClientFail {
2994 return
2995 }
2996
2997 // Ensure the maximum record size is accepted.
2998 testCases = append(testCases, testCase{
2999 protocol: protocol,
3000 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
3001 config: Config{
3002 MinVersion: ver.version,
3003 MaxVersion: ver.version,
3004 CipherSuites: []uint16{suite.id},
3005 Certificates: []Certificate{cert},
3006 PreSharedKey: []byte(psk),
3007 PreSharedKeyIdentity: pskIdentity,
3008 },
David Benjamina5022392017-07-10 17:40:39 -04003009 tls13Variant: ver.tls13Variant,
3010 flags: flags,
3011 messageLen: maxPlaintext,
David Benjamin6f600d62016-12-21 16:06:54 -05003012 })
3013
3014 // Test bad records for all ciphers. Bad records are fatal in TLS
3015 // and ignored in DTLS.
3016 var shouldFail bool
3017 var expectedError string
3018 if protocol == tls {
3019 shouldFail = true
3020 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
3021 }
3022
3023 testCases = append(testCases, testCase{
3024 protocol: protocol,
3025 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
3026 config: Config{
3027 MinVersion: ver.version,
3028 MaxVersion: ver.version,
3029 CipherSuites: []uint16{suite.id},
3030 Certificates: []Certificate{cert},
3031 PreSharedKey: []byte(psk),
3032 PreSharedKeyIdentity: pskIdentity,
3033 },
David Benjamina5022392017-07-10 17:40:39 -04003034 tls13Variant: ver.tls13Variant,
David Benjamin6f600d62016-12-21 16:06:54 -05003035 flags: flags,
3036 damageFirstWrite: true,
3037 messageLen: maxPlaintext,
3038 shouldFail: shouldFail,
3039 expectedError: expectedError,
3040 })
David Benjaminaa012042016-12-10 13:33:05 -05003041}
3042
Adam Langley95c29f32014-06-20 12:00:00 -07003043func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02003044 const bogusCipher = 0xfe00
3045
Adam Langley95c29f32014-06-20 12:00:00 -07003046 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07003047 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04003048 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05003049 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07003050 }
David Benjamin2c99d282015-09-01 10:23:00 -04003051 }
Adam Langley95c29f32014-06-20 12:00:00 -07003052 }
Adam Langleya7997f12015-05-14 17:38:50 -07003053
3054 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003055 name: "NoSharedCipher",
3056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003057 MaxVersion: VersionTLS12,
3058 CipherSuites: []uint16{},
3059 },
3060 shouldFail: true,
3061 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3062 })
3063
3064 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003065 name: "NoSharedCipher-TLS13",
3066 config: Config{
3067 MaxVersion: VersionTLS13,
3068 CipherSuites: []uint16{},
3069 },
3070 shouldFail: true,
3071 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
3072 })
3073
3074 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003075 name: "UnsupportedCipherSuite",
3076 config: Config{
3077 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003078 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003079 Bugs: ProtocolBugs{
3080 IgnorePeerCipherPreferences: true,
3081 },
3082 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07003083 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04003084 shouldFail: true,
3085 expectedError: ":WRONG_CIPHER_RETURNED:",
3086 })
3087
3088 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02003089 name: "ServerHelloBogusCipher",
3090 config: Config{
3091 MaxVersion: VersionTLS12,
3092 Bugs: ProtocolBugs{
3093 SendCipherSuite: bogusCipher,
3094 },
3095 },
3096 shouldFail: true,
3097 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3098 })
3099 testCases = append(testCases, testCase{
3100 name: "ServerHelloBogusCipher-TLS13",
3101 config: Config{
3102 MaxVersion: VersionTLS13,
3103 Bugs: ProtocolBugs{
3104 SendCipherSuite: bogusCipher,
3105 },
3106 },
3107 shouldFail: true,
3108 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
3109 })
3110
David Benjamin241ae832016-01-15 03:04:54 -05003111 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05003112 testCases = append(testCases, testCase{
3113 testType: serverTest,
3114 name: "UnknownCipher",
3115 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003116 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05003117 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003118 Bugs: ProtocolBugs{
3119 AdvertiseAllConfiguredCiphers: true,
3120 },
3121 },
3122 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003123
3124 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04003125 testCases = append(testCases, testCase{
3126 testType: serverTest,
3127 name: "UnknownCipher-TLS13",
3128 config: Config{
3129 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04003130 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04003131 Bugs: ProtocolBugs{
3132 AdvertiseAllConfiguredCiphers: true,
3133 },
David Benjamin241ae832016-01-15 03:04:54 -05003134 },
3135 })
3136
David Benjamin78679342016-09-16 19:42:05 -04003137 // Test empty ECDHE_PSK identity hints work as expected.
3138 testCases = append(testCases, testCase{
3139 name: "EmptyECDHEPSKHint",
3140 config: Config{
3141 MaxVersion: VersionTLS12,
3142 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3143 PreSharedKey: []byte("secret"),
3144 },
3145 flags: []string{"-psk", "secret"},
3146 })
3147
3148 // Test empty PSK identity hints work as expected, even if an explicit
3149 // ServerKeyExchange is sent.
3150 testCases = append(testCases, testCase{
3151 name: "ExplicitEmptyPSKHint",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3155 PreSharedKey: []byte("secret"),
3156 Bugs: ProtocolBugs{
3157 AlwaysSendPreSharedKeyIdentityHint: true,
3158 },
3159 },
3160 flags: []string{"-psk", "secret"},
3161 })
David Benjamin69522112017-03-28 15:38:29 -05003162
3163 // Test that clients enforce that the server-sent certificate and cipher
3164 // suite match in TLS 1.2.
3165 testCases = append(testCases, testCase{
3166 name: "CertificateCipherMismatch-RSA",
3167 config: Config{
3168 MaxVersion: VersionTLS12,
3169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3170 Certificates: []Certificate{rsaCertificate},
3171 Bugs: ProtocolBugs{
3172 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
3173 },
3174 },
3175 shouldFail: true,
3176 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3177 })
3178 testCases = append(testCases, testCase{
3179 name: "CertificateCipherMismatch-ECDSA",
3180 config: Config{
3181 MaxVersion: VersionTLS12,
3182 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3183 Certificates: []Certificate{ecdsaP256Certificate},
3184 Bugs: ProtocolBugs{
3185 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3186 },
3187 },
3188 shouldFail: true,
3189 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3190 })
3191 testCases = append(testCases, testCase{
3192 name: "CertificateCipherMismatch-Ed25519",
3193 config: Config{
3194 MaxVersion: VersionTLS12,
3195 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3196 Certificates: []Certificate{ed25519Certificate},
3197 Bugs: ProtocolBugs{
3198 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3199 },
3200 },
3201 shouldFail: true,
3202 expectedError: ":WRONG_CERTIFICATE_TYPE:",
3203 })
3204
3205 // Test that servers decline to select a cipher suite which is
3206 // inconsistent with their configured certificate.
3207 testCases = append(testCases, testCase{
3208 testType: serverTest,
3209 name: "ServerCipherFilter-RSA",
3210 config: Config{
3211 MaxVersion: VersionTLS12,
3212 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3213 },
3214 flags: []string{
3215 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3216 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3217 },
3218 shouldFail: true,
3219 expectedError: ":NO_SHARED_CIPHER:",
3220 })
3221 testCases = append(testCases, testCase{
3222 testType: serverTest,
3223 name: "ServerCipherFilter-ECDSA",
3224 config: Config{
3225 MaxVersion: VersionTLS12,
3226 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3227 },
3228 flags: []string{
3229 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3230 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3231 },
3232 shouldFail: true,
3233 expectedError: ":NO_SHARED_CIPHER:",
3234 })
3235 testCases = append(testCases, testCase{
3236 testType: serverTest,
3237 name: "ServerCipherFilter-Ed25519",
3238 config: Config{
3239 MaxVersion: VersionTLS12,
3240 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3241 },
3242 flags: []string{
3243 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3244 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3245 },
3246 shouldFail: true,
3247 expectedError: ":NO_SHARED_CIPHER:",
3248 })
David Benjamin364af782017-07-01 10:35:27 -04003249
3250 // Test cipher suite negotiation works as expected. Configure a
3251 // complicated cipher suite configuration.
3252 const negotiationTestCiphers = "" +
3253 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3254 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3255 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3256 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3257 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3258 negotiationTests := []struct {
3259 ciphers []uint16
3260 expected uint16
3261 }{
3262 // Server preferences are honored, including when
3263 // equipreference groups are involved.
3264 {
3265 []uint16{
3266 TLS_RSA_WITH_AES_256_GCM_SHA384,
3267 TLS_RSA_WITH_AES_128_CBC_SHA,
3268 TLS_RSA_WITH_AES_128_GCM_SHA256,
3269 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3270 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3271 },
3272 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3273 },
3274 {
3275 []uint16{
3276 TLS_RSA_WITH_AES_256_GCM_SHA384,
3277 TLS_RSA_WITH_AES_128_CBC_SHA,
3278 TLS_RSA_WITH_AES_128_GCM_SHA256,
3279 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3280 },
3281 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3282 },
3283 {
3284 []uint16{
3285 TLS_RSA_WITH_AES_256_GCM_SHA384,
3286 TLS_RSA_WITH_AES_128_CBC_SHA,
3287 TLS_RSA_WITH_AES_128_GCM_SHA256,
3288 },
3289 TLS_RSA_WITH_AES_128_GCM_SHA256,
3290 },
3291 {
3292 []uint16{
3293 TLS_RSA_WITH_AES_256_GCM_SHA384,
3294 TLS_RSA_WITH_AES_128_CBC_SHA,
3295 },
3296 TLS_RSA_WITH_AES_128_CBC_SHA,
3297 },
3298 // Equipreference groups use the client preference.
3299 {
3300 []uint16{
3301 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3302 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3303 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3304 },
3305 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3306 },
3307 {
3308 []uint16{
3309 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3310 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3311 },
3312 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3313 },
3314 {
3315 []uint16{
3316 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3317 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3318 },
3319 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3320 },
3321 {
3322 []uint16{
3323 TLS_RSA_WITH_AES_256_GCM_SHA384,
3324 TLS_RSA_WITH_AES_256_CBC_SHA,
3325 },
3326 TLS_RSA_WITH_AES_256_GCM_SHA384,
3327 },
3328 {
3329 []uint16{
3330 TLS_RSA_WITH_AES_256_CBC_SHA,
3331 TLS_RSA_WITH_AES_256_GCM_SHA384,
3332 },
3333 TLS_RSA_WITH_AES_256_CBC_SHA,
3334 },
3335 // If there are two equipreference groups, the preferred one
3336 // takes precedence.
3337 {
3338 []uint16{
3339 TLS_RSA_WITH_AES_256_GCM_SHA384,
3340 TLS_RSA_WITH_AES_256_CBC_SHA,
3341 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3342 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3343 },
3344 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3345 },
3346 }
3347 for i, t := range negotiationTests {
3348 testCases = append(testCases, testCase{
3349 testType: serverTest,
3350 name: "CipherNegotiation-" + strconv.Itoa(i),
3351 config: Config{
3352 MaxVersion: VersionTLS12,
3353 CipherSuites: t.ciphers,
3354 },
3355 flags: []string{"-cipher", negotiationTestCiphers},
3356 expectedCipher: t.expected,
3357 })
3358 }
Adam Langley95c29f32014-06-20 12:00:00 -07003359}
3360
3361func addBadECDSASignatureTests() {
3362 for badR := BadValue(1); badR < NumBadValues; badR++ {
3363 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003364 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003365 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3366 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003367 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003368 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003369 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003370 Bugs: ProtocolBugs{
3371 BadECDSAR: badR,
3372 BadECDSAS: badS,
3373 },
3374 },
3375 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003376 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003377 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003378 testCases = append(testCases, testCase{
3379 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3380 config: Config{
3381 MaxVersion: VersionTLS13,
3382 Certificates: []Certificate{ecdsaP256Certificate},
3383 Bugs: ProtocolBugs{
3384 BadECDSAR: badR,
3385 BadECDSAS: badS,
3386 },
3387 },
3388 shouldFail: true,
3389 expectedError: ":BAD_SIGNATURE:",
3390 })
Adam Langley95c29f32014-06-20 12:00:00 -07003391 }
3392 }
3393}
3394
Adam Langley80842bd2014-06-20 12:00:00 -07003395func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003396 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003397 name: "MaxCBCPadding",
3398 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003399 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003400 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3401 Bugs: ProtocolBugs{
3402 MaxPadding: true,
3403 },
3404 },
3405 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3406 })
David Benjamin025b3d32014-07-01 19:53:04 -04003407 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003408 name: "BadCBCPadding",
3409 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003410 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003411 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3412 Bugs: ProtocolBugs{
3413 PaddingFirstByteBad: true,
3414 },
3415 },
3416 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003417 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003418 })
3419 // OpenSSL previously had an issue where the first byte of padding in
3420 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003421 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003422 name: "BadCBCPadding255",
3423 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003424 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003425 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3426 Bugs: ProtocolBugs{
3427 MaxPadding: true,
3428 PaddingFirstByteBadIf255: true,
3429 },
3430 },
3431 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3432 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003433 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003434 })
3435}
3436
Kenny Root7fdeaf12014-08-05 15:23:37 -07003437func addCBCSplittingTests() {
David Benjamina1ce8562017-07-01 11:46:57 -04003438 var cbcCiphers = []struct {
3439 name string
3440 cipher uint16
3441 }{
3442 {"3DES", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
3443 {"AES128", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3444 {"AES256", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
3445 }
3446 for _, t := range cbcCiphers {
3447 testCases = append(testCases, testCase{
3448 name: "CBCRecordSplitting-" + t.name,
3449 config: Config{
3450 MaxVersion: VersionTLS10,
3451 MinVersion: VersionTLS10,
3452 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003453 Bugs: ProtocolBugs{
3454 ExpectRecordSplitting: true,
3455 },
David Benjamina1ce8562017-07-01 11:46:57 -04003456 },
3457 messageLen: -1, // read until EOF
3458 resumeSession: true,
3459 flags: []string{
3460 "-async",
3461 "-write-different-record-sizes",
3462 "-cbc-record-splitting",
3463 },
3464 })
3465 testCases = append(testCases, testCase{
3466 name: "CBCRecordSplittingPartialWrite-" + t.name,
3467 config: Config{
3468 MaxVersion: VersionTLS10,
3469 MinVersion: VersionTLS10,
3470 CipherSuites: []uint16{t.cipher},
David Benjamin09ed1192017-07-14 20:11:07 -04003471 Bugs: ProtocolBugs{
3472 ExpectRecordSplitting: true,
3473 },
David Benjamina1ce8562017-07-01 11:46:57 -04003474 },
3475 messageLen: -1, // read until EOF
3476 flags: []string{
3477 "-async",
3478 "-write-different-record-sizes",
3479 "-cbc-record-splitting",
3480 "-partial-write",
3481 },
3482 })
3483 }
Kenny Root7fdeaf12014-08-05 15:23:37 -07003484}
3485
David Benjamin636293b2014-07-08 17:59:18 -04003486func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003487 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003488 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003489 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3490 cert, err := x509.ParseCertificate(cert.Certificate[0])
3491 if err != nil {
3492 panic(err)
3493 }
3494 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003495 }
Adam Langley2ff79332017-02-28 13:45:39 -08003496 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003497
David Benjamin636293b2014-07-08 17:59:18 -04003498 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003499 testCases = append(testCases, testCase{
3500 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003501 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003502 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003503 MinVersion: ver.version,
3504 MaxVersion: ver.version,
3505 ClientAuth: RequireAnyClientCert,
3506 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003507 },
David Benjamina5022392017-07-10 17:40:39 -04003508 tls13Variant: ver.tls13Variant,
David Benjamin636293b2014-07-08 17:59:18 -04003509 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003510 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3511 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003512 },
3513 })
3514 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003515 testType: serverTest,
3516 name: ver.name + "-Server-ClientAuth-RSA",
3517 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003518 MinVersion: ver.version,
3519 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003520 Certificates: []Certificate{rsaCertificate},
3521 },
David Benjamina5022392017-07-10 17:40:39 -04003522 tls13Variant: ver.tls13Variant,
3523 flags: []string{"-require-any-client-certificate"},
David Benjamin67666e72014-07-12 15:47:52 -04003524 })
David Benjamine098ec22014-08-27 23:13:20 -04003525 if ver.version != VersionSSL30 {
3526 testCases = append(testCases, testCase{
3527 testType: serverTest,
3528 name: ver.name + "-Server-ClientAuth-ECDSA",
3529 config: Config{
3530 MinVersion: ver.version,
3531 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003532 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003533 },
David Benjamina5022392017-07-10 17:40:39 -04003534 tls13Variant: ver.tls13Variant,
3535 flags: []string{"-require-any-client-certificate"},
David Benjamine098ec22014-08-27 23:13:20 -04003536 })
3537 testCases = append(testCases, testCase{
3538 testType: clientTest,
3539 name: ver.name + "-Client-ClientAuth-ECDSA",
3540 config: Config{
3541 MinVersion: ver.version,
3542 MaxVersion: ver.version,
3543 ClientAuth: RequireAnyClientCert,
3544 ClientCAs: certPool,
3545 },
David Benjamina5022392017-07-10 17:40:39 -04003546 tls13Variant: ver.tls13Variant,
David Benjamine098ec22014-08-27 23:13:20 -04003547 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003548 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3549 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003550 },
3551 })
3552 }
Adam Langley37646832016-08-01 16:16:46 -07003553
3554 testCases = append(testCases, testCase{
3555 name: "NoClientCertificate-" + ver.name,
3556 config: Config{
3557 MinVersion: ver.version,
3558 MaxVersion: ver.version,
3559 ClientAuth: RequireAnyClientCert,
3560 },
David Benjamina5022392017-07-10 17:40:39 -04003561 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003562 shouldFail: true,
3563 expectedLocalError: "client didn't provide a certificate",
3564 })
3565
3566 testCases = append(testCases, testCase{
3567 // Even if not configured to expect a certificate, OpenSSL will
3568 // return X509_V_OK as the verify_result.
3569 testType: serverTest,
3570 name: "NoClientCertificateRequested-Server-" + ver.name,
3571 config: Config{
3572 MinVersion: ver.version,
3573 MaxVersion: ver.version,
3574 },
David Benjamina5022392017-07-10 17:40:39 -04003575 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003576 flags: []string{
3577 "-expect-verify-result",
3578 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003579 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003580 })
3581
3582 testCases = append(testCases, testCase{
3583 // If a client certificate is not provided, OpenSSL will still
3584 // return X509_V_OK as the verify_result.
3585 testType: serverTest,
3586 name: "NoClientCertificate-Server-" + ver.name,
3587 config: Config{
3588 MinVersion: ver.version,
3589 MaxVersion: ver.version,
3590 },
David Benjamina5022392017-07-10 17:40:39 -04003591 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003592 flags: []string{
3593 "-expect-verify-result",
3594 "-verify-peer",
3595 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003596 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003597 })
3598
David Benjamin1db9e1b2016-10-07 20:51:43 -04003599 certificateRequired := "remote error: certificate required"
3600 if ver.version < VersionTLS13 {
3601 // Prior to TLS 1.3, the generic handshake_failure alert
3602 // was used.
3603 certificateRequired = "remote error: handshake failure"
3604 }
Adam Langley37646832016-08-01 16:16:46 -07003605 testCases = append(testCases, testCase{
3606 testType: serverTest,
3607 name: "RequireAnyClientCertificate-" + ver.name,
3608 config: Config{
3609 MinVersion: ver.version,
3610 MaxVersion: ver.version,
3611 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003612 flags: []string{"-require-any-client-certificate"},
David Benjamina5022392017-07-10 17:40:39 -04003613 tls13Variant: ver.tls13Variant,
David Benjamin1db9e1b2016-10-07 20:51:43 -04003614 shouldFail: true,
3615 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3616 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003617 })
3618
3619 if ver.version != VersionSSL30 {
3620 testCases = append(testCases, testCase{
3621 testType: serverTest,
3622 name: "SkipClientCertificate-" + ver.name,
3623 config: Config{
3624 MinVersion: ver.version,
3625 MaxVersion: ver.version,
3626 Bugs: ProtocolBugs{
3627 SkipClientCertificate: true,
3628 },
3629 },
3630 // Setting SSL_VERIFY_PEER allows anonymous clients.
3631 flags: []string{"-verify-peer"},
David Benjamina5022392017-07-10 17:40:39 -04003632 tls13Variant: ver.tls13Variant,
Adam Langley37646832016-08-01 16:16:46 -07003633 shouldFail: true,
3634 expectedError: ":UNEXPECTED_MESSAGE:",
3635 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003636
3637 testCases = append(testCases, testCase{
3638 testType: serverTest,
3639 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3640 config: Config{
3641 MinVersion: ver.version,
3642 MaxVersion: ver.version,
3643 },
3644 flags: []string{
3645 "-enable-channel-id",
3646 "-verify-peer-if-no-obc",
3647 },
David Benjamina5022392017-07-10 17:40:39 -04003648 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003649 shouldFail: true,
3650 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3651 expectedLocalError: certificateRequired,
3652 })
3653
3654 testCases = append(testCases, testCase{
3655 testType: serverTest,
3656 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3657 config: Config{
3658 MinVersion: ver.version,
3659 MaxVersion: ver.version,
3660 ChannelID: channelIDKey,
3661 },
3662 expectChannelID: true,
David Benjamina5022392017-07-10 17:40:39 -04003663 tls13Variant: ver.tls13Variant,
David Benjaminc3648fa2017-07-01 10:50:56 -04003664 flags: []string{
3665 "-enable-channel-id",
3666 "-verify-peer-if-no-obc",
3667 },
3668 })
Adam Langley37646832016-08-01 16:16:46 -07003669 }
Adam Langley2ff79332017-02-28 13:45:39 -08003670
3671 testCases = append(testCases, testCase{
3672 testType: serverTest,
3673 name: ver.name + "-Server-CertReq-CA-List",
3674 config: Config{
3675 MinVersion: ver.version,
3676 MaxVersion: ver.version,
3677 Certificates: []Certificate{rsaCertificate},
3678 Bugs: ProtocolBugs{
3679 ExpectCertificateReqNames: caNames,
3680 },
3681 },
David Benjamina5022392017-07-10 17:40:39 -04003682 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003683 flags: []string{
3684 "-require-any-client-certificate",
3685 "-use-client-ca-list", encodeDERValues(caNames),
3686 },
3687 })
3688
3689 testCases = append(testCases, testCase{
3690 testType: clientTest,
3691 name: ver.name + "-Client-CertReq-CA-List",
3692 config: Config{
3693 MinVersion: ver.version,
3694 MaxVersion: ver.version,
3695 Certificates: []Certificate{rsaCertificate},
3696 ClientAuth: RequireAnyClientCert,
3697 ClientCAs: certPool,
3698 },
David Benjamina5022392017-07-10 17:40:39 -04003699 tls13Variant: ver.tls13Variant,
Adam Langley2ff79332017-02-28 13:45:39 -08003700 flags: []string{
3701 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3702 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3703 "-expect-client-ca-list", encodeDERValues(caNames),
3704 },
3705 })
David Benjamin636293b2014-07-08 17:59:18 -04003706 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003707
David Benjaminc032dfa2016-05-12 14:54:57 -04003708 // Client auth is only legal in certificate-based ciphers.
3709 testCases = append(testCases, testCase{
3710 testType: clientTest,
3711 name: "ClientAuth-PSK",
3712 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003713 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003714 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3715 PreSharedKey: []byte("secret"),
3716 ClientAuth: RequireAnyClientCert,
3717 },
3718 flags: []string{
3719 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3720 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3721 "-psk", "secret",
3722 },
3723 shouldFail: true,
3724 expectedError: ":UNEXPECTED_MESSAGE:",
3725 })
3726 testCases = append(testCases, testCase{
3727 testType: clientTest,
3728 name: "ClientAuth-ECDHE_PSK",
3729 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003730 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003731 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3732 PreSharedKey: []byte("secret"),
3733 ClientAuth: RequireAnyClientCert,
3734 },
3735 flags: []string{
3736 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3737 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3738 "-psk", "secret",
3739 },
3740 shouldFail: true,
3741 expectedError: ":UNEXPECTED_MESSAGE:",
3742 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003743
3744 // Regression test for a bug where the client CA list, if explicitly
3745 // set to NULL, was mis-encoded.
3746 testCases = append(testCases, testCase{
3747 testType: serverTest,
3748 name: "Null-Client-CA-List",
3749 config: Config{
3750 MaxVersion: VersionTLS12,
3751 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003752 Bugs: ProtocolBugs{
3753 ExpectCertificateReqNames: [][]byte{},
3754 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003755 },
3756 flags: []string{
3757 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003758 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003759 },
3760 })
David Benjamin636293b2014-07-08 17:59:18 -04003761}
3762
Adam Langley75712922014-10-10 16:23:43 -07003763func addExtendedMasterSecretTests() {
3764 const expectEMSFlag = "-expect-extended-master-secret"
3765
3766 for _, with := range []bool{false, true} {
3767 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003768 if with {
3769 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003770 }
3771
3772 for _, isClient := range []bool{false, true} {
3773 suffix := "-Server"
3774 testType := serverTest
3775 if isClient {
3776 suffix = "-Client"
3777 testType = clientTest
3778 }
3779
3780 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003781 // In TLS 1.3, the extension is irrelevant and
3782 // always reports as enabled.
3783 var flags []string
3784 if with || ver.version >= VersionTLS13 {
3785 flags = []string{expectEMSFlag}
3786 }
3787
Adam Langley75712922014-10-10 16:23:43 -07003788 test := testCase{
3789 testType: testType,
3790 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3791 config: Config{
3792 MinVersion: ver.version,
3793 MaxVersion: ver.version,
3794 Bugs: ProtocolBugs{
3795 NoExtendedMasterSecret: !with,
3796 RequireExtendedMasterSecret: with,
3797 },
3798 },
David Benjamina5022392017-07-10 17:40:39 -04003799 tls13Variant: ver.tls13Variant,
3800 flags: flags,
3801 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003802 }
3803 if test.shouldFail {
3804 test.expectedLocalError = "extended master secret required but not supported by peer"
3805 }
3806 testCases = append(testCases, test)
3807 }
3808 }
3809 }
3810
Adam Langleyba5934b2015-06-02 10:50:35 -07003811 for _, isClient := range []bool{false, true} {
3812 for _, supportedInFirstConnection := range []bool{false, true} {
3813 for _, supportedInResumeConnection := range []bool{false, true} {
3814 boolToWord := func(b bool) string {
3815 if b {
3816 return "Yes"
3817 }
3818 return "No"
3819 }
3820 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3821 if isClient {
3822 suffix += "Client"
3823 } else {
3824 suffix += "Server"
3825 }
3826
3827 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003828 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003829 Bugs: ProtocolBugs{
3830 RequireExtendedMasterSecret: true,
3831 },
3832 }
3833
3834 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003835 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003836 Bugs: ProtocolBugs{
3837 NoExtendedMasterSecret: true,
3838 },
3839 }
3840
3841 test := testCase{
3842 name: "ExtendedMasterSecret-" + suffix,
3843 resumeSession: true,
3844 }
3845
3846 if !isClient {
3847 test.testType = serverTest
3848 }
3849
3850 if supportedInFirstConnection {
3851 test.config = supportedConfig
3852 } else {
3853 test.config = noSupportConfig
3854 }
3855
3856 if supportedInResumeConnection {
3857 test.resumeConfig = &supportedConfig
3858 } else {
3859 test.resumeConfig = &noSupportConfig
3860 }
3861
3862 switch suffix {
3863 case "YesToYes-Client", "YesToYes-Server":
3864 // When a session is resumed, it should
3865 // still be aware that its master
3866 // secret was generated via EMS and
3867 // thus it's safe to use tls-unique.
3868 test.flags = []string{expectEMSFlag}
3869 case "NoToYes-Server":
3870 // If an original connection did not
3871 // contain EMS, but a resumption
3872 // handshake does, then a server should
3873 // not resume the session.
3874 test.expectResumeRejected = true
3875 case "YesToNo-Server":
3876 // Resuming an EMS session without the
3877 // EMS extension should cause the
3878 // server to abort the connection.
3879 test.shouldFail = true
3880 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3881 case "NoToYes-Client":
3882 // A client should abort a connection
3883 // where the server resumed a non-EMS
3884 // session but echoed the EMS
3885 // extension.
3886 test.shouldFail = true
3887 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3888 case "YesToNo-Client":
3889 // A client should abort a connection
3890 // where the server didn't echo EMS
3891 // when the session used it.
3892 test.shouldFail = true
3893 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3894 }
3895
3896 testCases = append(testCases, test)
3897 }
3898 }
3899 }
David Benjamin163c9562016-08-29 23:14:17 -04003900
3901 // Switching EMS on renegotiation is forbidden.
3902 testCases = append(testCases, testCase{
3903 name: "ExtendedMasterSecret-Renego-NoEMS",
3904 config: Config{
3905 MaxVersion: VersionTLS12,
3906 Bugs: ProtocolBugs{
3907 NoExtendedMasterSecret: true,
3908 NoExtendedMasterSecretOnRenegotiation: true,
3909 },
3910 },
3911 renegotiate: 1,
3912 flags: []string{
3913 "-renegotiate-freely",
3914 "-expect-total-renegotiations", "1",
3915 },
3916 })
3917
3918 testCases = append(testCases, testCase{
3919 name: "ExtendedMasterSecret-Renego-Upgrade",
3920 config: Config{
3921 MaxVersion: VersionTLS12,
3922 Bugs: ProtocolBugs{
3923 NoExtendedMasterSecret: true,
3924 },
3925 },
3926 renegotiate: 1,
3927 flags: []string{
3928 "-renegotiate-freely",
3929 "-expect-total-renegotiations", "1",
3930 },
3931 shouldFail: true,
3932 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3933 })
3934
3935 testCases = append(testCases, testCase{
3936 name: "ExtendedMasterSecret-Renego-Downgrade",
3937 config: Config{
3938 MaxVersion: VersionTLS12,
3939 Bugs: ProtocolBugs{
3940 NoExtendedMasterSecretOnRenegotiation: true,
3941 },
3942 },
3943 renegotiate: 1,
3944 flags: []string{
3945 "-renegotiate-freely",
3946 "-expect-total-renegotiations", "1",
3947 },
3948 shouldFail: true,
3949 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3950 })
Adam Langley75712922014-10-10 16:23:43 -07003951}
3952
David Benjamin582ba042016-07-07 12:33:25 -07003953type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003954 protocol protocol
3955 async bool
3956 splitHandshake bool
3957 packHandshakeFlight bool
3958 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003959}
3960
David Benjamin43ec06f2014-08-05 02:28:57 -04003961// Adds tests that try to cover the range of the handshake state machine, under
3962// various conditions. Some of these are redundant with other tests, but they
3963// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003964func addAllStateMachineCoverageTests() {
3965 for _, async := range []bool{false, true} {
3966 for _, protocol := range []protocol{tls, dtls} {
3967 addStateMachineCoverageTests(stateMachineTestConfig{
3968 protocol: protocol,
3969 async: async,
3970 })
3971 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003972 protocol: protocol,
3973 async: async,
3974 implicitHandshake: true,
3975 })
3976 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003977 protocol: protocol,
3978 async: async,
3979 splitHandshake: true,
3980 })
3981 if protocol == tls {
3982 addStateMachineCoverageTests(stateMachineTestConfig{
3983 protocol: protocol,
3984 async: async,
3985 packHandshakeFlight: true,
3986 })
3987 }
3988 }
3989 }
3990}
3991
3992func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003993 var tests []testCase
3994
3995 // Basic handshake, with resumption. Client and server,
3996 // session ID and session ticket.
3997 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003998 name: "Basic-Client",
3999 config: Config{
4000 MaxVersion: VersionTLS12,
4001 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004002 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05004003 // Ensure session tickets are used, not session IDs.
4004 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004005 })
4006 tests = append(tests, testCase{
4007 name: "Basic-Client-RenewTicket",
4008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004009 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004010 Bugs: ProtocolBugs{
4011 RenewTicketOnResume: true,
4012 },
4013 },
David Benjamin46662482016-08-17 00:51:00 -04004014 flags: []string{"-expect-ticket-renewal"},
4015 resumeSession: true,
4016 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 })
4018 tests = append(tests, testCase{
4019 name: "Basic-Client-NoTicket",
4020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004021 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004022 SessionTicketsDisabled: true,
4023 },
4024 resumeSession: true,
4025 })
4026 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05004027 testType: serverTest,
4028 name: "Basic-Server",
4029 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004030 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05004031 Bugs: ProtocolBugs{
4032 RequireSessionTickets: true,
4033 },
4034 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004035 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004036 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004037 })
4038 tests = append(tests, testCase{
4039 testType: serverTest,
4040 name: "Basic-Server-NoTickets",
4041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004042 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004043 SessionTicketsDisabled: true,
4044 },
4045 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004046 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04004047 })
4048 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004049 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004050 name: "Basic-Server-EarlyCallback",
4051 config: Config{
4052 MaxVersion: VersionTLS12,
4053 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004054 flags: []string{"-use-early-callback"},
4055 resumeSession: true,
4056 })
4057
Steven Valdez143e8b32016-07-11 13:19:03 -04004058 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04004059 if config.protocol == tls {
4060 tests = append(tests, testCase{
4061 name: "TLS13-1RTT-Client",
4062 config: Config{
4063 MaxVersion: VersionTLS13,
4064 MinVersion: VersionTLS13,
4065 },
David Benjamin46662482016-08-17 00:51:00 -04004066 resumeSession: true,
4067 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04004068 })
4069
4070 tests = append(tests, testCase{
4071 testType: serverTest,
4072 name: "TLS13-1RTT-Server",
4073 config: Config{
4074 MaxVersion: VersionTLS13,
4075 MinVersion: VersionTLS13,
4076 },
David Benjamin46662482016-08-17 00:51:00 -04004077 resumeSession: true,
4078 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05004079 // TLS 1.3 uses tickets, so the session should not be
4080 // cached statefully.
4081 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04004082 })
4083
4084 tests = append(tests, testCase{
4085 name: "TLS13-HelloRetryRequest-Client",
4086 config: Config{
4087 MaxVersion: VersionTLS13,
4088 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04004089 // P-384 requires a HelloRetryRequest against BoringSSL's default
4090 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04004091 CurvePreferences: []CurveID{CurveP384},
4092 Bugs: ProtocolBugs{
4093 ExpectMissingKeyShare: true,
4094 },
4095 },
4096 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4097 resumeSession: true,
4098 })
4099
4100 tests = append(tests, testCase{
4101 testType: serverTest,
4102 name: "TLS13-HelloRetryRequest-Server",
4103 config: Config{
4104 MaxVersion: VersionTLS13,
4105 MinVersion: VersionTLS13,
4106 // Require a HelloRetryRequest for every curve.
4107 DefaultCurves: []CurveID{},
4108 },
4109 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
4110 resumeSession: true,
4111 })
Steven Valdez2d850622017-01-11 11:34:52 -05004112
Steven Valdez2d850622017-01-11 11:34:52 -05004113 tests = append(tests, testCase{
4114 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -05004115 name: "TLS13-EarlyData-TooMuchData-Client",
4116 config: Config{
4117 MaxVersion: VersionTLS13,
4118 MinVersion: VersionTLS13,
4119 MaxEarlyDataSize: 2,
4120 },
4121 resumeConfig: &Config{
4122 MaxVersion: VersionTLS13,
4123 MinVersion: VersionTLS13,
4124 MaxEarlyDataSize: 2,
4125 Bugs: ProtocolBugs{
4126 ExpectEarlyData: [][]byte{{'h', 'e'}},
4127 },
4128 },
4129 resumeShimPrefix: "llo",
4130 resumeSession: true,
4131 flags: []string{
4132 "-enable-early-data",
4133 "-expect-early-data-info",
4134 "-expect-accept-early-data",
4135 "-on-resume-shim-writes-first",
4136 },
4137 })
4138
4139 // Unfinished writes can only be tested when operations are async. EarlyData
4140 // can't be tested as part of an ImplicitHandshake in this case since
4141 // otherwise the early data will be sent as normal data.
4142 if config.async && !config.implicitHandshake {
4143 tests = append(tests, testCase{
4144 testType: clientTest,
4145 name: "TLS13-EarlyData-UnfinishedWrite-Client",
4146 config: Config{
4147 MaxVersion: VersionTLS13,
4148 MinVersion: VersionTLS13,
4149 MaxEarlyDataSize: 16384,
4150 },
4151 resumeConfig: &Config{
4152 MaxVersion: VersionTLS13,
4153 MinVersion: VersionTLS13,
4154 MaxEarlyDataSize: 16384,
4155 Bugs: ProtocolBugs{
4156 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
4157 },
4158 },
4159 resumeSession: true,
4160 flags: []string{
4161 "-enable-early-data",
4162 "-expect-early-data-info",
4163 "-expect-accept-early-data",
4164 "-on-resume-read-with-unfinished-write",
4165 "-on-resume-shim-writes-first",
4166 },
4167 })
4168
4169 // Rejected unfinished writes are discarded (from the
4170 // perspective of the calling application) on 0-RTT
4171 // reject.
4172 tests = append(tests, testCase{
4173 testType: clientTest,
4174 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
4175 config: Config{
4176 MaxVersion: VersionTLS13,
4177 MinVersion: VersionTLS13,
4178 MaxEarlyDataSize: 16384,
4179 },
4180 resumeConfig: &Config{
4181 MaxVersion: VersionTLS13,
4182 MinVersion: VersionTLS13,
4183 MaxEarlyDataSize: 16384,
4184 Bugs: ProtocolBugs{
4185 AlwaysRejectEarlyData: true,
4186 },
4187 },
4188 resumeSession: true,
4189 flags: []string{
4190 "-enable-early-data",
4191 "-expect-early-data-info",
4192 "-expect-reject-early-data",
4193 "-on-resume-read-with-unfinished-write",
4194 "-on-resume-shim-writes-first",
4195 },
4196 })
4197 }
4198
4199 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05004200 testType: serverTest,
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004201 name: "TLS13-MaxEarlyData-Server",
4202 config: Config{
4203 MaxVersion: VersionTLS13,
4204 MinVersion: VersionTLS13,
4205 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04004206 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01004207 ExpectEarlyDataAccepted: true,
4208 },
4209 },
4210 messageCount: 2,
4211 resumeSession: true,
4212 flags: []string{
4213 "-enable-early-data",
4214 "-expect-accept-early-data",
4215 },
4216 shouldFail: true,
4217 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4218 })
David Benjamine73c7f42016-08-17 00:29:33 -04004219 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004220
David Benjamin760b1dd2015-05-15 23:33:48 -04004221 // TLS client auth.
4222 tests = append(tests, testCase{
4223 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004224 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004226 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004227 ClientAuth: RequestClientCert,
4228 },
4229 })
4230 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004231 testType: serverTest,
4232 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004233 config: Config{
4234 MaxVersion: VersionTLS12,
4235 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004236 // Setting SSL_VERIFY_PEER allows anonymous clients.
4237 flags: []string{"-verify-peer"},
4238 })
David Benjamin582ba042016-07-07 12:33:25 -07004239 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004240 tests = append(tests, testCase{
4241 testType: clientTest,
4242 name: "ClientAuth-NoCertificate-Client-SSL3",
4243 config: Config{
4244 MaxVersion: VersionSSL30,
4245 ClientAuth: RequestClientCert,
4246 },
4247 })
4248 tests = append(tests, testCase{
4249 testType: serverTest,
4250 name: "ClientAuth-NoCertificate-Server-SSL3",
4251 config: Config{
4252 MaxVersion: VersionSSL30,
4253 },
4254 // Setting SSL_VERIFY_PEER allows anonymous clients.
4255 flags: []string{"-verify-peer"},
4256 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004257 tests = append(tests, testCase{
4258 testType: clientTest,
4259 name: "ClientAuth-NoCertificate-Client-TLS13",
4260 config: Config{
4261 MaxVersion: VersionTLS13,
4262 ClientAuth: RequestClientCert,
4263 },
4264 })
4265 tests = append(tests, testCase{
4266 testType: serverTest,
4267 name: "ClientAuth-NoCertificate-Server-TLS13",
4268 config: Config{
4269 MaxVersion: VersionTLS13,
4270 },
4271 // Setting SSL_VERIFY_PEER allows anonymous clients.
4272 flags: []string{"-verify-peer"},
4273 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004274 }
4275 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004276 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004277 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004279 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004280 ClientAuth: RequireAnyClientCert,
4281 },
4282 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004283 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4284 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004285 },
4286 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004287 tests = append(tests, testCase{
4288 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004289 name: "ClientAuth-RSA-Client-TLS13",
4290 config: Config{
4291 MaxVersion: VersionTLS13,
4292 ClientAuth: RequireAnyClientCert,
4293 },
4294 flags: []string{
4295 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4296 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4297 },
4298 })
4299 tests = append(tests, testCase{
4300 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004301 name: "ClientAuth-ECDSA-Client",
4302 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004303 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004304 ClientAuth: RequireAnyClientCert,
4305 },
4306 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004307 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4308 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004309 },
4310 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004311 tests = append(tests, testCase{
4312 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004313 name: "ClientAuth-ECDSA-Client-TLS13",
4314 config: Config{
4315 MaxVersion: VersionTLS13,
4316 ClientAuth: RequireAnyClientCert,
4317 },
4318 flags: []string{
4319 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4320 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4321 },
4322 })
4323 tests = append(tests, testCase{
4324 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004325 name: "ClientAuth-NoCertificate-OldCallback",
4326 config: Config{
4327 MaxVersion: VersionTLS12,
4328 ClientAuth: RequestClientCert,
4329 },
4330 flags: []string{"-use-old-client-cert-callback"},
4331 })
4332 tests = append(tests, testCase{
4333 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004334 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4335 config: Config{
4336 MaxVersion: VersionTLS13,
4337 ClientAuth: RequestClientCert,
4338 },
4339 flags: []string{"-use-old-client-cert-callback"},
4340 })
4341 tests = append(tests, testCase{
4342 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004343 name: "ClientAuth-OldCallback",
4344 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004345 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004346 ClientAuth: RequireAnyClientCert,
4347 },
4348 flags: []string{
4349 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4350 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4351 "-use-old-client-cert-callback",
4352 },
4353 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004354 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004355 testType: clientTest,
4356 name: "ClientAuth-OldCallback-TLS13",
4357 config: Config{
4358 MaxVersion: VersionTLS13,
4359 ClientAuth: RequireAnyClientCert,
4360 },
4361 flags: []string{
4362 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4363 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4364 "-use-old-client-cert-callback",
4365 },
4366 })
4367 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004368 testType: serverTest,
4369 name: "ClientAuth-Server",
4370 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004371 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004372 Certificates: []Certificate{rsaCertificate},
4373 },
4374 flags: []string{"-require-any-client-certificate"},
4375 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004376 tests = append(tests, testCase{
4377 testType: serverTest,
4378 name: "ClientAuth-Server-TLS13",
4379 config: Config{
4380 MaxVersion: VersionTLS13,
4381 Certificates: []Certificate{rsaCertificate},
4382 },
4383 flags: []string{"-require-any-client-certificate"},
4384 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004385
David Benjamin4c3ddf72016-06-29 18:13:53 -04004386 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004387 tests = append(tests, testCase{
4388 testType: serverTest,
4389 name: "Basic-Server-RSA",
4390 config: Config{
4391 MaxVersion: VersionTLS12,
4392 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4393 },
4394 flags: []string{
4395 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4396 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4397 },
4398 })
4399 tests = append(tests, testCase{
4400 testType: serverTest,
4401 name: "Basic-Server-ECDHE-RSA",
4402 config: Config{
4403 MaxVersion: VersionTLS12,
4404 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4405 },
4406 flags: []string{
4407 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4408 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4409 },
4410 })
4411 tests = append(tests, testCase{
4412 testType: serverTest,
4413 name: "Basic-Server-ECDHE-ECDSA",
4414 config: Config{
4415 MaxVersion: VersionTLS12,
4416 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4417 },
4418 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004419 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4420 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004421 },
4422 })
David Benjamin69522112017-03-28 15:38:29 -05004423 tests = append(tests, testCase{
4424 testType: serverTest,
4425 name: "Basic-Server-Ed25519",
4426 config: Config{
4427 MaxVersion: VersionTLS12,
4428 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4429 },
4430 flags: []string{
4431 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4432 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4433 "-enable-ed25519",
4434 },
4435 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004436
David Benjamin760b1dd2015-05-15 23:33:48 -04004437 // No session ticket support; server doesn't send NewSessionTicket.
4438 tests = append(tests, testCase{
4439 name: "SessionTicketsDisabled-Client",
4440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004441 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004442 SessionTicketsDisabled: true,
4443 },
4444 })
4445 tests = append(tests, testCase{
4446 testType: serverTest,
4447 name: "SessionTicketsDisabled-Server",
4448 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004449 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004450 SessionTicketsDisabled: true,
4451 },
4452 })
4453
4454 // Skip ServerKeyExchange in PSK key exchange if there's no
4455 // identity hint.
4456 tests = append(tests, testCase{
4457 name: "EmptyPSKHint-Client",
4458 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004459 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004460 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4461 PreSharedKey: []byte("secret"),
4462 },
4463 flags: []string{"-psk", "secret"},
4464 })
4465 tests = append(tests, testCase{
4466 testType: serverTest,
4467 name: "EmptyPSKHint-Server",
4468 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004469 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004470 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4471 PreSharedKey: []byte("secret"),
4472 },
4473 flags: []string{"-psk", "secret"},
4474 })
4475
David Benjamin4c3ddf72016-06-29 18:13:53 -04004476 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004477 tests = append(tests, testCase{
4478 testType: clientTest,
4479 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004480 config: Config{
4481 MaxVersion: VersionTLS12,
4482 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004483 flags: []string{
4484 "-enable-ocsp-stapling",
4485 "-expect-ocsp-response",
4486 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004487 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004488 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004489 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004490 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004491 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004492 testType: serverTest,
4493 name: "OCSPStapling-Server",
4494 config: Config{
4495 MaxVersion: VersionTLS12,
4496 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004497 expectedOCSPResponse: testOCSPResponse,
4498 flags: []string{
4499 "-ocsp-response",
4500 base64.StdEncoding.EncodeToString(testOCSPResponse),
4501 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004502 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004503 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004504 tests = append(tests, testCase{
4505 testType: clientTest,
4506 name: "OCSPStapling-Client-TLS13",
4507 config: Config{
4508 MaxVersion: VersionTLS13,
4509 },
4510 flags: []string{
4511 "-enable-ocsp-stapling",
4512 "-expect-ocsp-response",
4513 base64.StdEncoding.EncodeToString(testOCSPResponse),
4514 "-verify-peer",
4515 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004516 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004517 })
4518 tests = append(tests, testCase{
4519 testType: serverTest,
4520 name: "OCSPStapling-Server-TLS13",
4521 config: Config{
4522 MaxVersion: VersionTLS13,
4523 },
4524 expectedOCSPResponse: testOCSPResponse,
4525 flags: []string{
4526 "-ocsp-response",
4527 base64.StdEncoding.EncodeToString(testOCSPResponse),
4528 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004529 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004530 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004531
David Benjamin4c3ddf72016-06-29 18:13:53 -04004532 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004533 for _, vers := range tlsVersions {
4534 if config.protocol == dtls && !vers.hasDTLS {
4535 continue
4536 }
David Benjamin3a1dd462017-07-11 16:13:10 -04004537 for _, useCustomCallback := range []bool{false, true} {
4538 for _, testType := range []testType{clientTest, serverTest} {
4539 suffix := "-Client"
4540 if testType == serverTest {
4541 suffix = "-Server"
4542 }
4543 suffix += "-" + vers.name
4544 if useCustomCallback {
4545 suffix += "-CustomCallback"
4546 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004547
David Benjamin3a1dd462017-07-11 16:13:10 -04004548 flags := []string{"-verify-peer"}
4549 if testType == serverTest {
4550 flags = append(flags, "-require-any-client-certificate")
4551 }
4552 if useCustomCallback {
4553 flags = append(flags, "-use-custom-verify-callback")
4554 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004555
David Benjamin3a1dd462017-07-11 16:13:10 -04004556 tests = append(tests, testCase{
4557 testType: testType,
4558 name: "CertificateVerificationSucceed" + suffix,
4559 config: Config{
4560 MaxVersion: vers.version,
4561 Certificates: []Certificate{rsaCertificate},
4562 },
4563 tls13Variant: vers.tls13Variant,
4564 flags: append([]string{"-expect-verify-result"}, flags...),
4565 resumeSession: true,
4566 })
4567 tests = append(tests, testCase{
4568 testType: testType,
4569 name: "CertificateVerificationFail" + suffix,
4570 config: Config{
4571 MaxVersion: vers.version,
4572 Certificates: []Certificate{rsaCertificate},
4573 },
4574 tls13Variant: vers.tls13Variant,
4575 flags: append([]string{"-verify-fail"}, flags...),
4576 shouldFail: true,
4577 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4578 })
4579 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004580 }
4581
4582 // By default, the client is in a soft fail mode where the peer
4583 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004584 tests = append(tests, testCase{
4585 testType: clientTest,
4586 name: "CertificateVerificationSoftFail-" + vers.name,
4587 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004588 MaxVersion: vers.version,
4589 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004590 },
David Benjamina5022392017-07-10 17:40:39 -04004591 tls13Variant: vers.tls13Variant,
Steven Valdez143e8b32016-07-11 13:19:03 -04004592 flags: []string{
4593 "-verify-fail",
4594 "-expect-verify-result",
4595 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004596 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004597 })
4598 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004599
David Benjamin1d4f4c02016-07-26 18:03:08 -04004600 tests = append(tests, testCase{
4601 name: "ShimSendAlert",
4602 flags: []string{"-send-alert"},
4603 shimWritesFirst: true,
4604 shouldFail: true,
4605 expectedLocalError: "remote error: decompression failure",
4606 })
4607
David Benjamin582ba042016-07-07 12:33:25 -07004608 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004609 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004610 name: "Renegotiate-Client",
4611 config: Config{
4612 MaxVersion: VersionTLS12,
4613 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004614 renegotiate: 1,
4615 flags: []string{
4616 "-renegotiate-freely",
4617 "-expect-total-renegotiations", "1",
4618 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004619 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004620
David Benjamin47921102016-07-28 11:29:18 -04004621 tests = append(tests, testCase{
4622 name: "SendHalfHelloRequest",
4623 config: Config{
4624 MaxVersion: VersionTLS12,
4625 Bugs: ProtocolBugs{
4626 PackHelloRequestWithFinished: config.packHandshakeFlight,
4627 },
4628 },
4629 sendHalfHelloRequest: true,
4630 flags: []string{"-renegotiate-ignore"},
4631 shouldFail: true,
4632 expectedError: ":UNEXPECTED_RECORD:",
4633 })
4634
David Benjamin760b1dd2015-05-15 23:33:48 -04004635 // NPN on client and server; results in post-handshake message.
4636 tests = append(tests, testCase{
4637 name: "NPN-Client",
4638 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004639 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004640 NextProtos: []string{"foo"},
4641 },
4642 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004643 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004644 expectedNextProto: "foo",
4645 expectedNextProtoType: npn,
4646 })
4647 tests = append(tests, testCase{
4648 testType: serverTest,
4649 name: "NPN-Server",
4650 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004651 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004652 NextProtos: []string{"bar"},
4653 },
4654 flags: []string{
4655 "-advertise-npn", "\x03foo\x03bar\x03baz",
4656 "-expect-next-proto", "bar",
4657 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004658 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004659 expectedNextProto: "bar",
4660 expectedNextProtoType: npn,
4661 })
4662
4663 // TODO(davidben): Add tests for when False Start doesn't trigger.
4664
4665 // Client does False Start and negotiates NPN.
4666 tests = append(tests, testCase{
4667 name: "FalseStart",
4668 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004669 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004670 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4671 NextProtos: []string{"foo"},
4672 Bugs: ProtocolBugs{
4673 ExpectFalseStart: true,
4674 },
4675 },
4676 flags: []string{
4677 "-false-start",
4678 "-select-next-proto", "foo",
4679 },
4680 shimWritesFirst: true,
4681 resumeSession: true,
4682 })
4683
4684 // Client does False Start and negotiates ALPN.
4685 tests = append(tests, testCase{
4686 name: "FalseStart-ALPN",
4687 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004688 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004689 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4690 NextProtos: []string{"foo"},
4691 Bugs: ProtocolBugs{
4692 ExpectFalseStart: true,
4693 },
4694 },
4695 flags: []string{
4696 "-false-start",
4697 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004698 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004699 },
4700 shimWritesFirst: true,
4701 resumeSession: true,
4702 })
4703
David Benjamin760b1dd2015-05-15 23:33:48 -04004704 // False Start without session tickets.
4705 tests = append(tests, testCase{
4706 name: "FalseStart-SessionTicketsDisabled",
4707 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004708 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004709 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4710 NextProtos: []string{"foo"},
4711 SessionTicketsDisabled: true,
4712 Bugs: ProtocolBugs{
4713 ExpectFalseStart: true,
4714 },
4715 },
4716 flags: []string{
4717 "-false-start",
4718 "-select-next-proto", "foo",
4719 },
4720 shimWritesFirst: true,
4721 })
4722
4723 // Server parses a V2ClientHello.
4724 tests = append(tests, testCase{
4725 testType: serverTest,
4726 name: "SendV2ClientHello",
4727 config: Config{
4728 // Choose a cipher suite that does not involve
4729 // elliptic curves, so no extensions are
4730 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004731 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004732 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004733 Bugs: ProtocolBugs{
4734 SendV2ClientHello: true,
4735 },
4736 },
David Benjamin78b8b992017-08-01 18:38:41 -04004737 flags: []string{
4738 "-expect-msg-callback",
4739 `read v2clienthello
4740write hs 2
4741write hs 11
4742write hs 14
4743read hs 16
4744read ccs
4745read hs 20
4746write ccs
4747write hs 20
4748read alert 1 0
4749`,
4750 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004751 })
4752
Nick Harper60a85cb2016-09-23 16:25:11 -07004753 // Test Channel ID
4754 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004755 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004756 continue
4757 }
4758 // Client sends a Channel ID.
4759 tests = append(tests, testCase{
4760 name: "ChannelID-Client-" + ver.name,
4761 config: Config{
4762 MaxVersion: ver.version,
4763 RequestChannelID: true,
4764 },
David Benjamina5022392017-07-10 17:40:39 -04004765 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004766 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4767 resumeSession: true,
4768 expectChannelID: true,
4769 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004770
Nick Harper60a85cb2016-09-23 16:25:11 -07004771 // Server accepts a Channel ID.
4772 tests = append(tests, testCase{
4773 testType: serverTest,
4774 name: "ChannelID-Server-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 ChannelID: channelIDKey,
4778 },
David Benjamina5022392017-07-10 17:40:39 -04004779 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004780 flags: []string{
4781 "-expect-channel-id",
4782 base64.StdEncoding.EncodeToString(channelIDBytes),
4783 },
4784 resumeSession: true,
4785 expectChannelID: true,
4786 })
4787
4788 tests = append(tests, testCase{
4789 testType: serverTest,
4790 name: "InvalidChannelIDSignature-" + ver.name,
4791 config: Config{
4792 MaxVersion: ver.version,
4793 ChannelID: channelIDKey,
4794 Bugs: ProtocolBugs{
4795 InvalidChannelIDSignature: true,
4796 },
4797 },
David Benjamina5022392017-07-10 17:40:39 -04004798 tls13Variant: ver.tls13Variant,
Nick Harper60a85cb2016-09-23 16:25:11 -07004799 flags: []string{"-enable-channel-id"},
4800 shouldFail: true,
4801 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4802 })
David Benjamin634f4752017-07-01 11:08:41 -04004803
4804 if ver.version < VersionTLS13 {
4805 // Channel ID requires ECDHE ciphers.
4806 tests = append(tests, testCase{
4807 testType: serverTest,
4808 name: "ChannelID-NoECDHE-" + ver.name,
4809 config: Config{
4810 MaxVersion: ver.version,
4811 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4812 ChannelID: channelIDKey,
4813 },
4814 expectChannelID: false,
4815 flags: []string{"-enable-channel-id"},
4816 })
4817
4818 // Sanity-check setting expectChannelID false works.
4819 tests = append(tests, testCase{
4820 testType: serverTest,
4821 name: "ChannelID-ECDHE-" + ver.name,
4822 config: Config{
4823 MaxVersion: ver.version,
4824 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
4825 ChannelID: channelIDKey,
4826 },
4827 expectChannelID: false,
4828 flags: []string{"-enable-channel-id"},
4829 shouldFail: true,
4830 expectedLocalError: "channel ID unexpectedly negotiated",
4831 })
4832 }
Nick Harper60a85cb2016-09-23 16:25:11 -07004833 }
David Benjamin30789da2015-08-29 22:56:45 -04004834
David Benjaminf8fcdf32016-06-08 15:56:13 -04004835 // Channel ID and NPN at the same time, to ensure their relative
4836 // ordering is correct.
4837 tests = append(tests, testCase{
4838 name: "ChannelID-NPN-Client",
4839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004840 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004841 RequestChannelID: true,
4842 NextProtos: []string{"foo"},
4843 },
4844 flags: []string{
4845 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4846 "-select-next-proto", "foo",
4847 },
4848 resumeSession: true,
4849 expectChannelID: true,
4850 expectedNextProto: "foo",
4851 expectedNextProtoType: npn,
4852 })
4853 tests = append(tests, testCase{
4854 testType: serverTest,
4855 name: "ChannelID-NPN-Server",
4856 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004857 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004858 ChannelID: channelIDKey,
4859 NextProtos: []string{"bar"},
4860 },
4861 flags: []string{
4862 "-expect-channel-id",
4863 base64.StdEncoding.EncodeToString(channelIDBytes),
4864 "-advertise-npn", "\x03foo\x03bar\x03baz",
4865 "-expect-next-proto", "bar",
4866 },
4867 resumeSession: true,
4868 expectChannelID: true,
4869 expectedNextProto: "bar",
4870 expectedNextProtoType: npn,
4871 })
4872
David Benjamin30789da2015-08-29 22:56:45 -04004873 // Bidirectional shutdown with the runner initiating.
4874 tests = append(tests, testCase{
4875 name: "Shutdown-Runner",
4876 config: Config{
4877 Bugs: ProtocolBugs{
4878 ExpectCloseNotify: true,
4879 },
4880 },
4881 flags: []string{"-check-close-notify"},
4882 })
4883
David Benjamine3843d42017-03-25 18:00:56 -05004884 if !config.implicitHandshake {
4885 // Bidirectional shutdown with the shim initiating. The runner,
4886 // in the meantime, sends garbage before the close_notify which
4887 // the shim must ignore. This test is disabled under implicit
4888 // handshake tests because the shim never reads or writes.
4889 tests = append(tests, testCase{
4890 name: "Shutdown-Shim",
4891 config: Config{
4892 MaxVersion: VersionTLS12,
4893 Bugs: ProtocolBugs{
4894 ExpectCloseNotify: true,
4895 },
David Benjamin30789da2015-08-29 22:56:45 -04004896 },
David Benjamine3843d42017-03-25 18:00:56 -05004897 shimShutsDown: true,
4898 sendEmptyRecords: 1,
4899 sendWarningAlerts: 1,
4900 flags: []string{"-check-close-notify"},
4901 })
4902 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004903 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004904 // TODO(davidben): DTLS 1.3 will want a similar thing for
4905 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004906 tests = append(tests, testCase{
4907 name: "SkipHelloVerifyRequest",
4908 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004909 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004910 Bugs: ProtocolBugs{
4911 SkipHelloVerifyRequest: true,
4912 },
4913 },
4914 })
4915 }
4916
David Benjamin760b1dd2015-05-15 23:33:48 -04004917 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004918 test.protocol = config.protocol
4919 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004920 test.name += "-DTLS"
4921 }
David Benjamin582ba042016-07-07 12:33:25 -07004922 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004923 test.name += "-Async"
4924 test.flags = append(test.flags, "-async")
4925 } else {
4926 test.name += "-Sync"
4927 }
David Benjamin582ba042016-07-07 12:33:25 -07004928 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004929 test.name += "-SplitHandshakeRecords"
4930 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004931 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004932 test.config.Bugs.MaxPacketLength = 256
4933 test.flags = append(test.flags, "-mtu", "256")
4934 }
4935 }
David Benjamin582ba042016-07-07 12:33:25 -07004936 if config.packHandshakeFlight {
4937 test.name += "-PackHandshakeFlight"
4938 test.config.Bugs.PackHandshakeFlight = true
4939 }
David Benjamine3843d42017-03-25 18:00:56 -05004940 if config.implicitHandshake {
4941 test.name += "-ImplicitHandshake"
4942 test.flags = append(test.flags, "-implicit-handshake")
4943 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004944 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004945 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004946}
4947
Adam Langley524e7172015-02-20 16:04:00 -08004948func addDDoSCallbackTests() {
4949 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004950 for _, resume := range []bool{false, true} {
4951 suffix := "Resume"
4952 if resume {
4953 suffix = "No" + suffix
4954 }
4955
4956 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004957 testType: serverTest,
4958 name: "Server-DDoS-OK-" + suffix,
4959 config: Config{
4960 MaxVersion: VersionTLS12,
4961 },
Adam Langley524e7172015-02-20 16:04:00 -08004962 flags: []string{"-install-ddos-callback"},
4963 resumeSession: resume,
4964 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004965 testCases = append(testCases, testCase{
4966 testType: serverTest,
4967 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4968 config: Config{
4969 MaxVersion: VersionTLS13,
4970 },
4971 flags: []string{"-install-ddos-callback"},
4972 resumeSession: resume,
4973 })
Adam Langley524e7172015-02-20 16:04:00 -08004974
4975 failFlag := "-fail-ddos-callback"
4976 if resume {
4977 failFlag = "-fail-second-ddos-callback"
4978 }
4979 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004980 testType: serverTest,
4981 name: "Server-DDoS-Reject-" + suffix,
4982 config: Config{
4983 MaxVersion: VersionTLS12,
4984 },
David Benjamin2c66e072016-09-16 15:58:00 -04004985 flags: []string{"-install-ddos-callback", failFlag},
4986 resumeSession: resume,
4987 shouldFail: true,
4988 expectedError: ":CONNECTION_REJECTED:",
4989 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004990 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004991 testCases = append(testCases, testCase{
4992 testType: serverTest,
4993 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4994 config: Config{
4995 MaxVersion: VersionTLS13,
4996 },
David Benjamin2c66e072016-09-16 15:58:00 -04004997 flags: []string{"-install-ddos-callback", failFlag},
4998 resumeSession: resume,
4999 shouldFail: true,
5000 expectedError: ":CONNECTION_REJECTED:",
5001 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005002 })
Adam Langley524e7172015-02-20 16:04:00 -08005003 }
5004}
5005
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005006func addVersionNegotiationTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005007 for _, protocol := range []protocol{tls, dtls} {
5008 for _, shimVers := range allVersions(protocol) {
5009 // Assemble flags to disable all newer versions on the shim.
5010 var flags []string
5011 for _, vers := range allVersions(protocol) {
5012 if vers.version > shimVers.version {
5013 flags = append(flags, vers.excludeFlag)
5014 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005015 }
Steven Valdez520e1222017-06-13 12:45:25 -04005016
5017 flags2 := []string{"-max-version", shimVers.shimFlag(protocol)}
5018
5019 if shimVers.tls13Variant != 0 {
5020 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5021 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5022 }
5023
5024 // Test configuring the runner's maximum version.
5025 for _, runnerVers := range allVersions(protocol) {
David Benjamin8b8c0062014-11-23 02:47:52 -05005026 expectedVersion := shimVers.version
5027 if runnerVers.version < shimVers.version {
5028 expectedVersion = runnerVers.version
5029 }
Steven Valdez520e1222017-06-13 12:45:25 -04005030 // When running and shim have different TLS 1.3 variants enabled,
5031 // shim clients are expected to fall back to TLS 1.2, while shim
5032 // servers support both variants when enabled when the experiment is
5033 // enabled.
5034 expectedServerVersion := expectedVersion
5035 expectedClientVersion := expectedVersion
5036 if expectedVersion == VersionTLS13 && runnerVers.tls13Variant != shimVers.tls13Variant {
5037 expectedClientVersion = VersionTLS12
5038 expectedServerVersion = VersionTLS12
5039 if shimVers.tls13Variant != TLS13Default {
5040 expectedServerVersion = VersionTLS13
5041 }
5042 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005043
David Benjamin8b8c0062014-11-23 02:47:52 -05005044 suffix := shimVers.name + "-" + runnerVers.name
5045 if protocol == dtls {
5046 suffix += "-DTLS"
5047 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005048
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005049 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05005050 clientVers := shimVers.version
5051 if clientVers > VersionTLS10 {
5052 clientVers = VersionTLS10
5053 }
Steven Valdez520e1222017-06-13 12:45:25 -04005054 clientVers = recordVersionToWire(clientVers, protocol)
5055 serverVers := expectedServerVersion
5056 if expectedServerVersion >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07005057 serverVers = VersionTLS10
Steven Valdezc7d4d212017-09-11 13:53:08 -04005058 if runnerVers.tls13Variant == TLS13Experiment2 || runnerVers.tls13Variant == TLS13Experiment3 {
Steven Valdez16821262017-09-08 17:03:42 -04005059 serverVers = VersionTLS12
5060 }
Nick Harper1fd39d82016-06-14 18:14:35 -07005061 }
Steven Valdez520e1222017-06-13 12:45:25 -04005062 serverVers = recordVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04005063
David Benjamin8b8c0062014-11-23 02:47:52 -05005064 testCases = append(testCases, testCase{
5065 protocol: protocol,
5066 testType: clientTest,
5067 name: "VersionNegotiation-Client-" + suffix,
5068 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005069 MaxVersion: runnerVers.version,
5070 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005071 Bugs: ProtocolBugs{
5072 ExpectInitialRecordVersion: clientVers,
5073 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005074 },
5075 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005076 expectedVersion: expectedClientVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005077 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005078 testCases = append(testCases, testCase{
5079 protocol: protocol,
5080 testType: clientTest,
5081 name: "VersionNegotiation-Client2-" + suffix,
5082 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005083 MaxVersion: runnerVers.version,
5084 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005085 Bugs: ProtocolBugs{
5086 ExpectInitialRecordVersion: clientVers,
5087 },
5088 },
Steven Valdez520e1222017-06-13 12:45:25 -04005089 flags: flags2,
5090 expectedVersion: expectedClientVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005091 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005092
5093 testCases = append(testCases, testCase{
5094 protocol: protocol,
5095 testType: serverTest,
5096 name: "VersionNegotiation-Server-" + suffix,
5097 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005098 MaxVersion: runnerVers.version,
5099 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005100 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005101 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05005102 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005103 },
5104 flags: flags,
Steven Valdez520e1222017-06-13 12:45:25 -04005105 expectedVersion: expectedServerVersion,
David Benjamin8b8c0062014-11-23 02:47:52 -05005106 })
David Benjamin1eb367c2014-12-12 18:17:51 -05005107 testCases = append(testCases, testCase{
5108 protocol: protocol,
5109 testType: serverTest,
5110 name: "VersionNegotiation-Server2-" + suffix,
5111 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005112 MaxVersion: runnerVers.version,
5113 TLS13Variant: runnerVers.tls13Variant,
David Benjamin1eb367c2014-12-12 18:17:51 -05005114 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07005115 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05005116 },
5117 },
Steven Valdez520e1222017-06-13 12:45:25 -04005118 flags: flags2,
5119 expectedVersion: expectedServerVersion,
David Benjamin1eb367c2014-12-12 18:17:51 -05005120 })
David Benjamin8b8c0062014-11-23 02:47:52 -05005121 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005122 }
5123 }
David Benjamin95c69562016-06-29 18:15:03 -04005124
Steven Valdezfdd10992016-09-15 16:27:05 -04005125 // Test the version extension at all versions.
5126 for _, vers := range tlsVersions {
5127 protocols := []protocol{tls}
5128 if vers.hasDTLS {
5129 protocols = append(protocols, dtls)
5130 }
5131 for _, protocol := range protocols {
5132 suffix := vers.name
5133 if protocol == dtls {
5134 suffix += "-DTLS"
5135 }
5136
Steven Valdezfdd10992016-09-15 16:27:05 -04005137 testCases = append(testCases, testCase{
5138 protocol: protocol,
5139 testType: serverTest,
5140 name: "VersionNegotiationExtension-" + suffix,
5141 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005142 TLS13Variant: vers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005143 Bugs: ProtocolBugs{
Steven Valdez520e1222017-06-13 12:45:25 -04005144 SendSupportedVersions: []uint16{0x1111, vers.wire(protocol), 0x2222},
Steven Valdezfdd10992016-09-15 16:27:05 -04005145 },
5146 },
5147 expectedVersion: vers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04005148 flags: []string{"-tls13-variant", strconv.Itoa(vers.tls13Variant)},
Steven Valdezfdd10992016-09-15 16:27:05 -04005149 })
5150 }
Steven Valdezfdd10992016-09-15 16:27:05 -04005151 }
5152
5153 // If all versions are unknown, negotiation fails.
5154 testCases = append(testCases, testCase{
5155 testType: serverTest,
5156 name: "NoSupportedVersions",
5157 config: Config{
5158 Bugs: ProtocolBugs{
5159 SendSupportedVersions: []uint16{0x1111},
5160 },
5161 },
5162 shouldFail: true,
5163 expectedError: ":UNSUPPORTED_PROTOCOL:",
5164 })
5165 testCases = append(testCases, testCase{
5166 protocol: dtls,
5167 testType: serverTest,
5168 name: "NoSupportedVersions-DTLS",
5169 config: Config{
5170 Bugs: ProtocolBugs{
5171 SendSupportedVersions: []uint16{0x1111},
5172 },
5173 },
5174 shouldFail: true,
5175 expectedError: ":UNSUPPORTED_PROTOCOL:",
5176 })
5177
5178 testCases = append(testCases, testCase{
5179 testType: serverTest,
5180 name: "ClientHelloVersionTooHigh",
5181 config: Config{
5182 MaxVersion: VersionTLS13,
5183 Bugs: ProtocolBugs{
5184 SendClientVersion: 0x0304,
5185 OmitSupportedVersions: true,
5186 },
5187 },
5188 expectedVersion: VersionTLS12,
5189 })
5190
5191 testCases = append(testCases, testCase{
5192 testType: serverTest,
5193 name: "ConflictingVersionNegotiation",
5194 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04005195 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04005196 SendClientVersion: VersionTLS12,
5197 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04005198 },
5199 },
David Benjaminad75a662016-09-30 15:42:59 -04005200 // The extension takes precedence over the ClientHello version.
5201 expectedVersion: VersionTLS11,
5202 })
5203
5204 testCases = append(testCases, testCase{
5205 testType: serverTest,
5206 name: "ConflictingVersionNegotiation-2",
5207 config: Config{
5208 Bugs: ProtocolBugs{
5209 SendClientVersion: VersionTLS11,
5210 SendSupportedVersions: []uint16{VersionTLS12},
5211 },
5212 },
5213 // The extension takes precedence over the ClientHello version.
5214 expectedVersion: VersionTLS12,
5215 })
5216
5217 testCases = append(testCases, testCase{
5218 testType: serverTest,
5219 name: "RejectFinalTLS13",
5220 config: Config{
5221 Bugs: ProtocolBugs{
5222 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
5223 },
5224 },
5225 // We currently implement a draft TLS 1.3 version. Ensure that
5226 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04005227 expectedVersion: VersionTLS12,
5228 })
5229
Steven Valdez038da9b2017-07-10 12:57:25 -04005230 // Test that TLS 1.2 isn't negotiated by the supported_versions extension in
5231 // the ServerHello.
5232 testCases = append(testCases, testCase{
5233 testType: clientTest,
5234 name: "SupportedVersionSelection-TLS12",
5235 config: Config{
5236 MaxVersion: VersionTLS12,
5237 Bugs: ProtocolBugs{
5238 SendServerSupportedExtensionVersion: VersionTLS12,
5239 },
5240 },
5241 shouldFail: true,
5242 expectedError: ":UNEXPECTED_EXTENSION:",
5243 })
5244
5245 // Test that the non-experimental TLS 1.3 isn't negotiated by the
5246 // supported_versions extension in the ServerHello.
5247 testCases = append(testCases, testCase{
5248 testType: clientTest,
5249 name: "SupportedVersionSelection-TLS13",
5250 config: Config{
5251 MaxVersion: VersionTLS13,
5252 Bugs: ProtocolBugs{
5253 SendServerSupportedExtensionVersion: tls13DraftVersion,
5254 },
5255 },
5256 shouldFail: true,
5257 expectedError: ":UNEXPECTED_EXTENSION:",
5258 })
5259
Brian Smithf85d3232016-10-28 10:34:06 -10005260 // Test that the maximum version is selected regardless of the
5261 // client-sent order.
5262 testCases = append(testCases, testCase{
5263 testType: serverTest,
5264 name: "IgnoreClientVersionOrder",
5265 config: Config{
5266 Bugs: ProtocolBugs{
5267 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
5268 },
5269 },
5270 expectedVersion: VersionTLS13,
5271 })
5272
David Benjamin95c69562016-06-29 18:15:03 -04005273 // Test for version tolerance.
5274 testCases = append(testCases, testCase{
5275 testType: serverTest,
5276 name: "MinorVersionTolerance",
5277 config: Config{
5278 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005279 SendClientVersion: 0x03ff,
5280 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005281 },
5282 },
Steven Valdezfdd10992016-09-15 16:27:05 -04005283 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005284 })
5285 testCases = append(testCases, testCase{
5286 testType: serverTest,
5287 name: "MajorVersionTolerance",
5288 config: Config{
5289 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005290 SendClientVersion: 0x0400,
5291 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005292 },
5293 },
David Benjaminad75a662016-09-30 15:42:59 -04005294 // TLS 1.3 must be negotiated with the supported_versions
5295 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04005296 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04005297 })
David Benjaminad75a662016-09-30 15:42:59 -04005298 testCases = append(testCases, testCase{
5299 testType: serverTest,
5300 name: "VersionTolerance-TLS13",
5301 config: Config{
5302 Bugs: ProtocolBugs{
5303 // Although TLS 1.3 does not use
5304 // ClientHello.version, it still tolerates high
5305 // values there.
5306 SendClientVersion: 0x0400,
5307 },
5308 },
5309 expectedVersion: VersionTLS13,
5310 })
Steven Valdezfdd10992016-09-15 16:27:05 -04005311
David Benjamin95c69562016-06-29 18:15:03 -04005312 testCases = append(testCases, testCase{
5313 protocol: dtls,
5314 testType: serverTest,
5315 name: "MinorVersionTolerance-DTLS",
5316 config: Config{
5317 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005318 SendClientVersion: 0xfe00,
5319 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005320 },
5321 },
5322 expectedVersion: VersionTLS12,
5323 })
5324 testCases = append(testCases, testCase{
5325 protocol: dtls,
5326 testType: serverTest,
5327 name: "MajorVersionTolerance-DTLS",
5328 config: Config{
5329 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005330 SendClientVersion: 0xfdff,
5331 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005332 },
5333 },
5334 expectedVersion: VersionTLS12,
5335 })
5336
5337 // Test that versions below 3.0 are rejected.
5338 testCases = append(testCases, testCase{
5339 testType: serverTest,
5340 name: "VersionTooLow",
5341 config: Config{
5342 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005343 SendClientVersion: 0x0200,
5344 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005345 },
5346 },
5347 shouldFail: true,
5348 expectedError: ":UNSUPPORTED_PROTOCOL:",
5349 })
5350 testCases = append(testCases, testCase{
5351 protocol: dtls,
5352 testType: serverTest,
5353 name: "VersionTooLow-DTLS",
5354 config: Config{
5355 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005356 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005357 },
5358 },
5359 shouldFail: true,
5360 expectedError: ":UNSUPPORTED_PROTOCOL:",
5361 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005362
David Benjamin2dc02042016-09-19 19:57:37 -04005363 testCases = append(testCases, testCase{
5364 name: "ServerBogusVersion",
5365 config: Config{
5366 Bugs: ProtocolBugs{
5367 SendServerHelloVersion: 0x1234,
5368 },
5369 },
5370 shouldFail: true,
5371 expectedError: ":UNSUPPORTED_PROTOCOL:",
5372 })
5373
David Benjamin1f61f0d2016-07-10 12:20:35 -04005374 // Test TLS 1.3's downgrade signal.
5375 testCases = append(testCases, testCase{
5376 name: "Downgrade-TLS12-Client",
5377 config: Config{
5378 Bugs: ProtocolBugs{
5379 NegotiateVersion: VersionTLS12,
5380 },
5381 },
David Benjamin592b5322016-09-30 15:15:01 -04005382 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005383 // TODO(davidben): This test should fail once TLS 1.3 is final
5384 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005385 })
5386 testCases = append(testCases, testCase{
5387 testType: serverTest,
5388 name: "Downgrade-TLS12-Server",
5389 config: Config{
5390 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005391 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005392 },
5393 },
David Benjamin592b5322016-09-30 15:15:01 -04005394 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005395 // TODO(davidben): This test should fail once TLS 1.3 is final
5396 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005397 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005398}
5399
David Benjaminaccb4542014-12-12 23:44:33 -05005400func addMinimumVersionTests() {
Steven Valdez520e1222017-06-13 12:45:25 -04005401 for _, protocol := range []protocol{tls, dtls} {
5402 for _, shimVers := range allVersions(protocol) {
5403 // Assemble flags to disable all older versions on the shim.
5404 var flags []string
5405 for _, vers := range allVersions(protocol) {
5406 if vers.version < shimVers.version {
5407 flags = append(flags, vers.excludeFlag)
5408 }
David Benjaminaccb4542014-12-12 23:44:33 -05005409 }
Steven Valdez520e1222017-06-13 12:45:25 -04005410
5411 flags2 := []string{"-min-version", shimVers.shimFlag(protocol)}
5412
5413 if shimVers.tls13Variant != 0 {
5414 flags = append(flags, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5415 flags2 = append(flags2, "-tls13-variant", strconv.Itoa(shimVers.tls13Variant))
5416 }
5417
5418 for _, runnerVers := range allVersions(protocol) {
5419 // Different TLS 1.3 variants are incompatible with each other and don't
5420 // produce consistent minimum versions.
5421 //
5422 // TODO(davidben): Fold these tests (the main value is in the
5423 // NegotiateVersion bug) into addVersionNegotiationTests and test based
5424 // on intended shim behavior, not the shim + runner combination.
5425 if shimVers.tls13Variant != runnerVers.tls13Variant {
5426 continue
5427 }
5428
David Benjaminaccb4542014-12-12 23:44:33 -05005429 suffix := shimVers.name + "-" + runnerVers.name
5430 if protocol == dtls {
5431 suffix += "-DTLS"
5432 }
David Benjaminaccb4542014-12-12 23:44:33 -05005433
David Benjaminaccb4542014-12-12 23:44:33 -05005434 var expectedVersion uint16
5435 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005436 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005437 if runnerVers.version >= shimVers.version {
5438 expectedVersion = runnerVers.version
5439 } else {
5440 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005441 expectedError = ":UNSUPPORTED_PROTOCOL:"
5442 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005443 }
5444
5445 testCases = append(testCases, testCase{
5446 protocol: protocol,
5447 testType: clientTest,
5448 name: "MinimumVersion-Client-" + suffix,
5449 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005450 MaxVersion: runnerVers.version,
5451 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005452 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005453 // Ensure the server does not decline to
5454 // select a version (versions extension) or
5455 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005456 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005457 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005458 },
David Benjaminaccb4542014-12-12 23:44:33 -05005459 },
David Benjamin87909c02014-12-13 01:55:01 -05005460 flags: flags,
5461 expectedVersion: expectedVersion,
5462 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005463 expectedError: expectedError,
5464 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005465 })
5466 testCases = append(testCases, testCase{
5467 protocol: protocol,
5468 testType: clientTest,
5469 name: "MinimumVersion-Client2-" + suffix,
5470 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005471 MaxVersion: runnerVers.version,
5472 TLS13Variant: runnerVers.tls13Variant,
Steven Valdezfdd10992016-09-15 16:27:05 -04005473 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005474 // Ensure the server does not decline to
5475 // select a version (versions extension) or
5476 // cipher (some ciphers depend on versions).
Steven Valdez520e1222017-06-13 12:45:25 -04005477 NegotiateVersion: runnerVers.wire(protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005478 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005479 },
David Benjaminaccb4542014-12-12 23:44:33 -05005480 },
Steven Valdez520e1222017-06-13 12:45:25 -04005481 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005482 expectedVersion: expectedVersion,
5483 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005484 expectedError: expectedError,
5485 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005486 })
5487
5488 testCases = append(testCases, testCase{
5489 protocol: protocol,
5490 testType: serverTest,
5491 name: "MinimumVersion-Server-" + suffix,
5492 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005493 MaxVersion: runnerVers.version,
5494 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005495 },
David Benjamin87909c02014-12-13 01:55:01 -05005496 flags: flags,
5497 expectedVersion: expectedVersion,
5498 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005499 expectedError: expectedError,
5500 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005501 })
5502 testCases = append(testCases, testCase{
5503 protocol: protocol,
5504 testType: serverTest,
5505 name: "MinimumVersion-Server2-" + suffix,
5506 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04005507 MaxVersion: runnerVers.version,
5508 TLS13Variant: runnerVers.tls13Variant,
David Benjaminaccb4542014-12-12 23:44:33 -05005509 },
Steven Valdez520e1222017-06-13 12:45:25 -04005510 flags: flags2,
David Benjamin87909c02014-12-13 01:55:01 -05005511 expectedVersion: expectedVersion,
5512 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005513 expectedError: expectedError,
5514 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005515 })
5516 }
5517 }
5518 }
5519}
5520
David Benjamine78bfde2014-09-06 12:45:15 -04005521func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005522 // TODO(davidben): Extensions, where applicable, all move their server
5523 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5524 // tests for both. Also test interaction with 0-RTT when implemented.
5525
David Benjamin97d17d92016-07-14 16:12:00 -04005526 // Repeat extensions tests all versions except SSL 3.0.
5527 for _, ver := range tlsVersions {
5528 if ver.version == VersionSSL30 {
5529 continue
5530 }
5531
David Benjamin97d17d92016-07-14 16:12:00 -04005532 // Test that duplicate extensions are rejected.
5533 testCases = append(testCases, testCase{
5534 testType: clientTest,
5535 name: "DuplicateExtensionClient-" + ver.name,
5536 config: Config{
5537 MaxVersion: ver.version,
5538 Bugs: ProtocolBugs{
5539 DuplicateExtension: true,
5540 },
David Benjamine78bfde2014-09-06 12:45:15 -04005541 },
David Benjamina5022392017-07-10 17:40:39 -04005542 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005543 shouldFail: true,
5544 expectedLocalError: "remote error: error decoding message",
5545 })
5546 testCases = append(testCases, testCase{
5547 testType: serverTest,
5548 name: "DuplicateExtensionServer-" + ver.name,
5549 config: Config{
5550 MaxVersion: ver.version,
5551 Bugs: ProtocolBugs{
5552 DuplicateExtension: true,
5553 },
David Benjamine78bfde2014-09-06 12:45:15 -04005554 },
David Benjamina5022392017-07-10 17:40:39 -04005555 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005556 shouldFail: true,
5557 expectedLocalError: "remote error: error decoding message",
5558 })
5559
5560 // Test SNI.
5561 testCases = append(testCases, testCase{
5562 testType: clientTest,
5563 name: "ServerNameExtensionClient-" + ver.name,
5564 config: Config{
5565 MaxVersion: ver.version,
5566 Bugs: ProtocolBugs{
5567 ExpectServerName: "example.com",
5568 },
David Benjamine78bfde2014-09-06 12:45:15 -04005569 },
David Benjamina5022392017-07-10 17:40:39 -04005570 tls13Variant: ver.tls13Variant,
5571 flags: []string{"-host-name", "example.com"},
David Benjamin97d17d92016-07-14 16:12:00 -04005572 })
5573 testCases = append(testCases, testCase{
5574 testType: clientTest,
5575 name: "ServerNameExtensionClientMismatch-" + ver.name,
5576 config: Config{
5577 MaxVersion: ver.version,
5578 Bugs: ProtocolBugs{
5579 ExpectServerName: "mismatch.com",
5580 },
David Benjamine78bfde2014-09-06 12:45:15 -04005581 },
David Benjamin97d17d92016-07-14 16:12:00 -04005582 flags: []string{"-host-name", "example.com"},
David Benjamina5022392017-07-10 17:40:39 -04005583 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005584 shouldFail: true,
5585 expectedLocalError: "tls: unexpected server name",
5586 })
5587 testCases = append(testCases, testCase{
5588 testType: clientTest,
5589 name: "ServerNameExtensionClientMissing-" + ver.name,
5590 config: Config{
5591 MaxVersion: ver.version,
5592 Bugs: ProtocolBugs{
5593 ExpectServerName: "missing.com",
5594 },
David Benjamine78bfde2014-09-06 12:45:15 -04005595 },
David Benjamina5022392017-07-10 17:40:39 -04005596 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005597 shouldFail: true,
5598 expectedLocalError: "tls: unexpected server name",
5599 })
5600 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005601 testType: clientTest,
5602 name: "TolerateServerNameAck-" + ver.name,
5603 config: Config{
5604 MaxVersion: ver.version,
5605 Bugs: ProtocolBugs{
5606 SendServerNameAck: true,
5607 },
5608 },
David Benjamina5022392017-07-10 17:40:39 -04005609 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005610 flags: []string{"-host-name", "example.com"},
5611 resumeSession: true,
5612 })
5613 testCases = append(testCases, testCase{
5614 testType: clientTest,
5615 name: "UnsolicitedServerNameAck-" + ver.name,
5616 config: Config{
5617 MaxVersion: ver.version,
5618 Bugs: ProtocolBugs{
5619 SendServerNameAck: true,
5620 },
5621 },
David Benjamina5022392017-07-10 17:40:39 -04005622 tls13Variant: ver.tls13Variant,
David Benjamin023d4192017-02-06 13:49:07 -05005623 shouldFail: true,
5624 expectedError: ":UNEXPECTED_EXTENSION:",
5625 expectedLocalError: "remote error: unsupported extension",
5626 })
5627 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005628 testType: serverTest,
5629 name: "ServerNameExtensionServer-" + ver.name,
5630 config: Config{
5631 MaxVersion: ver.version,
5632 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005633 },
David Benjamina5022392017-07-10 17:40:39 -04005634 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005635 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005636 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005637 })
5638
5639 // Test ALPN.
5640 testCases = append(testCases, testCase{
5641 testType: clientTest,
5642 name: "ALPNClient-" + ver.name,
5643 config: Config{
5644 MaxVersion: ver.version,
5645 NextProtos: []string{"foo"},
5646 },
5647 flags: []string{
5648 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5649 "-expect-alpn", "foo",
5650 },
David Benjamina5022392017-07-10 17:40:39 -04005651 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005652 expectedNextProto: "foo",
5653 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005654 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005655 })
5656 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005657 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005658 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005659 config: Config{
5660 MaxVersion: ver.version,
5661 Bugs: ProtocolBugs{
5662 SendALPN: "baz",
5663 },
5664 },
5665 flags: []string{
5666 "-advertise-alpn", "\x03foo\x03bar",
5667 },
David Benjamina5022392017-07-10 17:40:39 -04005668 tls13Variant: ver.tls13Variant,
David Benjamin3e517572016-08-11 11:52:23 -04005669 shouldFail: true,
5670 expectedError: ":INVALID_ALPN_PROTOCOL:",
5671 expectedLocalError: "remote error: illegal parameter",
5672 })
5673 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005674 testType: clientTest,
5675 name: "ALPNClient-AllowUnknown-" + ver.name,
5676 config: Config{
5677 MaxVersion: ver.version,
5678 Bugs: ProtocolBugs{
5679 SendALPN: "baz",
5680 },
5681 },
5682 flags: []string{
5683 "-advertise-alpn", "\x03foo\x03bar",
5684 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005685 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005686 },
David Benjamina5022392017-07-10 17:40:39 -04005687 tls13Variant: ver.tls13Variant,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005688 })
5689 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005690 testType: serverTest,
5691 name: "ALPNServer-" + ver.name,
5692 config: Config{
5693 MaxVersion: ver.version,
5694 NextProtos: []string{"foo", "bar", "baz"},
5695 },
5696 flags: []string{
5697 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5698 "-select-alpn", "foo",
5699 },
David Benjamina5022392017-07-10 17:40:39 -04005700 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005701 expectedNextProto: "foo",
5702 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005703 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005704 })
5705 testCases = append(testCases, testCase{
5706 testType: serverTest,
5707 name: "ALPNServer-Decline-" + ver.name,
5708 config: Config{
5709 MaxVersion: ver.version,
5710 NextProtos: []string{"foo", "bar", "baz"},
5711 },
5712 flags: []string{"-decline-alpn"},
David Benjamina5022392017-07-10 17:40:39 -04005713 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005714 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005715 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005716 })
5717
David Benjamin25fe85b2016-08-09 20:00:32 -04005718 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5719 // called once.
5720 testCases = append(testCases, testCase{
5721 testType: serverTest,
5722 name: "ALPNServer-Async-" + ver.name,
5723 config: Config{
5724 MaxVersion: ver.version,
5725 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005726 // Prior to TLS 1.3, exercise the asynchronous session callback.
5727 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005728 },
5729 flags: []string{
5730 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5731 "-select-alpn", "foo",
5732 "-async",
5733 },
David Benjamina5022392017-07-10 17:40:39 -04005734 tls13Variant: ver.tls13Variant,
David Benjamin25fe85b2016-08-09 20:00:32 -04005735 expectedNextProto: "foo",
5736 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005737 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005738 })
5739
David Benjamin97d17d92016-07-14 16:12:00 -04005740 var emptyString string
5741 testCases = append(testCases, testCase{
5742 testType: clientTest,
5743 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5744 config: Config{
5745 MaxVersion: ver.version,
5746 NextProtos: []string{""},
5747 Bugs: ProtocolBugs{
5748 // A server returning an empty ALPN protocol
5749 // should be rejected.
5750 ALPNProtocol: &emptyString,
5751 },
5752 },
5753 flags: []string{
5754 "-advertise-alpn", "\x03foo",
5755 },
David Benjamina5022392017-07-10 17:40:39 -04005756 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005757 shouldFail: true,
5758 expectedError: ":PARSE_TLSEXT:",
5759 })
5760 testCases = append(testCases, testCase{
5761 testType: serverTest,
5762 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5763 config: Config{
5764 MaxVersion: ver.version,
5765 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005766 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005767 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005768 },
David Benjamin97d17d92016-07-14 16:12:00 -04005769 flags: []string{
5770 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005771 },
David Benjamina5022392017-07-10 17:40:39 -04005772 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005773 shouldFail: true,
5774 expectedError: ":PARSE_TLSEXT:",
5775 })
5776
5777 // Test NPN and the interaction with ALPN.
5778 if ver.version < VersionTLS13 {
5779 // Test that the server prefers ALPN over NPN.
5780 testCases = append(testCases, testCase{
5781 testType: serverTest,
5782 name: "ALPNServer-Preferred-" + ver.name,
5783 config: Config{
5784 MaxVersion: ver.version,
5785 NextProtos: []string{"foo", "bar", "baz"},
5786 },
5787 flags: []string{
5788 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5789 "-select-alpn", "foo",
5790 "-advertise-npn", "\x03foo\x03bar\x03baz",
5791 },
David Benjamina5022392017-07-10 17:40:39 -04005792 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005793 expectedNextProto: "foo",
5794 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005795 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005796 })
5797 testCases = append(testCases, testCase{
5798 testType: serverTest,
5799 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5800 config: Config{
5801 MaxVersion: ver.version,
5802 NextProtos: []string{"foo", "bar", "baz"},
5803 Bugs: ProtocolBugs{
5804 SwapNPNAndALPN: true,
5805 },
5806 },
5807 flags: []string{
5808 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5809 "-select-alpn", "foo",
5810 "-advertise-npn", "\x03foo\x03bar\x03baz",
5811 },
David Benjamina5022392017-07-10 17:40:39 -04005812 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005813 expectedNextProto: "foo",
5814 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005815 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005816 })
5817
5818 // Test that negotiating both NPN and ALPN is forbidden.
5819 testCases = append(testCases, testCase{
5820 name: "NegotiateALPNAndNPN-" + ver.name,
5821 config: Config{
5822 MaxVersion: ver.version,
5823 NextProtos: []string{"foo", "bar", "baz"},
5824 Bugs: ProtocolBugs{
5825 NegotiateALPNAndNPN: true,
5826 },
5827 },
5828 flags: []string{
5829 "-advertise-alpn", "\x03foo",
5830 "-select-next-proto", "foo",
5831 },
David Benjamina5022392017-07-10 17:40:39 -04005832 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005833 shouldFail: true,
5834 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5835 })
5836 testCases = append(testCases, testCase{
5837 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5838 config: Config{
5839 MaxVersion: ver.version,
5840 NextProtos: []string{"foo", "bar", "baz"},
5841 Bugs: ProtocolBugs{
5842 NegotiateALPNAndNPN: true,
5843 SwapNPNAndALPN: true,
5844 },
5845 },
5846 flags: []string{
5847 "-advertise-alpn", "\x03foo",
5848 "-select-next-proto", "foo",
5849 },
David Benjamina5022392017-07-10 17:40:39 -04005850 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04005851 shouldFail: true,
5852 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5853 })
David Benjamin97d17d92016-07-14 16:12:00 -04005854 }
5855
5856 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005857
5858 // Resume with a corrupt ticket.
5859 testCases = append(testCases, testCase{
5860 testType: serverTest,
5861 name: "CorruptTicket-" + ver.name,
5862 config: Config{
5863 MaxVersion: ver.version,
5864 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005865 FilterTicket: func(in []byte) ([]byte, error) {
5866 in[len(in)-1] ^= 1
5867 return in, nil
5868 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005869 },
5870 },
David Benjamina5022392017-07-10 17:40:39 -04005871 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005872 resumeSession: true,
5873 expectResumeRejected: true,
5874 })
5875 // Test the ticket callback, with and without renewal.
5876 testCases = append(testCases, testCase{
5877 testType: serverTest,
5878 name: "TicketCallback-" + ver.name,
5879 config: Config{
5880 MaxVersion: ver.version,
5881 },
David Benjamina5022392017-07-10 17:40:39 -04005882 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005883 resumeSession: true,
5884 flags: []string{"-use-ticket-callback"},
5885 })
5886 testCases = append(testCases, testCase{
5887 testType: serverTest,
5888 name: "TicketCallback-Renew-" + ver.name,
5889 config: Config{
5890 MaxVersion: ver.version,
5891 Bugs: ProtocolBugs{
5892 ExpectNewTicket: true,
5893 },
5894 },
David Benjamina5022392017-07-10 17:40:39 -04005895 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005896 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5897 resumeSession: true,
5898 })
5899
5900 // Test that the ticket callback is only called once when everything before
5901 // it in the ClientHello is asynchronous. This corrupts the ticket so
5902 // certificate selection callbacks run.
5903 testCases = append(testCases, testCase{
5904 testType: serverTest,
5905 name: "TicketCallback-SingleCall-" + ver.name,
5906 config: Config{
5907 MaxVersion: ver.version,
5908 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005909 FilterTicket: func(in []byte) ([]byte, error) {
5910 in[len(in)-1] ^= 1
5911 return in, nil
5912 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005913 },
5914 },
David Benjamina5022392017-07-10 17:40:39 -04005915 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005916 resumeSession: true,
5917 expectResumeRejected: true,
5918 flags: []string{
5919 "-use-ticket-callback",
5920 "-async",
5921 },
5922 })
5923
David Benjamind4c349b2017-02-09 14:07:17 -05005924 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005925 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005926 testCases = append(testCases, testCase{
5927 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005928 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005929 config: Config{
5930 MaxVersion: ver.version,
5931 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005932 EmptyTicketSessionID: true,
5933 },
5934 },
5935 resumeSession: true,
5936 })
5937 testCases = append(testCases, testCase{
5938 testType: serverTest,
5939 name: "TicketSessionIDLength-16-" + ver.name,
5940 config: Config{
5941 MaxVersion: ver.version,
5942 Bugs: ProtocolBugs{
5943 TicketSessionIDLength: 16,
5944 },
5945 },
5946 resumeSession: true,
5947 })
5948 testCases = append(testCases, testCase{
5949 testType: serverTest,
5950 name: "TicketSessionIDLength-32-" + ver.name,
5951 config: Config{
5952 MaxVersion: ver.version,
5953 Bugs: ProtocolBugs{
5954 TicketSessionIDLength: 32,
5955 },
5956 },
5957 resumeSession: true,
5958 })
5959 testCases = append(testCases, testCase{
5960 testType: serverTest,
5961 name: "TicketSessionIDLength-33-" + ver.name,
5962 config: Config{
5963 MaxVersion: ver.version,
5964 Bugs: ProtocolBugs{
5965 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005966 },
5967 },
5968 resumeSession: true,
5969 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005970 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005971 expectedError: ":DECODE_ERROR:",
5972 })
5973 }
5974
5975 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5976 // are ignored.
5977 if ver.hasDTLS {
5978 testCases = append(testCases, testCase{
5979 protocol: dtls,
5980 name: "SRTP-Client-" + ver.name,
5981 config: Config{
5982 MaxVersion: ver.version,
5983 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5984 },
5985 flags: []string{
5986 "-srtp-profiles",
5987 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5988 },
5989 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5990 })
5991 testCases = append(testCases, testCase{
5992 protocol: dtls,
5993 testType: serverTest,
5994 name: "SRTP-Server-" + ver.name,
5995 config: Config{
5996 MaxVersion: ver.version,
5997 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5998 },
5999 flags: []string{
6000 "-srtp-profiles",
6001 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6002 },
6003 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6004 })
6005 // Test that the MKI is ignored.
6006 testCases = append(testCases, testCase{
6007 protocol: dtls,
6008 testType: serverTest,
6009 name: "SRTP-Server-IgnoreMKI-" + ver.name,
6010 config: Config{
6011 MaxVersion: ver.version,
6012 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
6013 Bugs: ProtocolBugs{
6014 SRTPMasterKeyIdentifer: "bogus",
6015 },
6016 },
6017 flags: []string{
6018 "-srtp-profiles",
6019 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6020 },
6021 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
6022 })
6023 // Test that SRTP isn't negotiated on the server if there were
6024 // no matching profiles.
6025 testCases = append(testCases, testCase{
6026 protocol: dtls,
6027 testType: serverTest,
6028 name: "SRTP-Server-NoMatch-" + ver.name,
6029 config: Config{
6030 MaxVersion: ver.version,
6031 SRTPProtectionProfiles: []uint16{100, 101, 102},
6032 },
6033 flags: []string{
6034 "-srtp-profiles",
6035 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
6036 },
6037 expectedSRTPProtectionProfile: 0,
6038 })
6039 // Test that the server returning an invalid SRTP profile is
6040 // flagged as an error by the client.
6041 testCases = append(testCases, testCase{
6042 protocol: dtls,
6043 name: "SRTP-Client-NoMatch-" + ver.name,
6044 config: Config{
6045 MaxVersion: ver.version,
6046 Bugs: ProtocolBugs{
6047 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
6048 },
6049 },
6050 flags: []string{
6051 "-srtp-profiles",
6052 "SRTP_AES128_CM_SHA1_80",
6053 },
6054 shouldFail: true,
6055 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
6056 })
6057 }
6058
6059 // Test SCT list.
6060 testCases = append(testCases, testCase{
6061 name: "SignedCertificateTimestampList-Client-" + ver.name,
6062 testType: clientTest,
6063 config: Config{
6064 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04006065 },
David Benjamin97d17d92016-07-14 16:12:00 -04006066 flags: []string{
6067 "-enable-signed-cert-timestamps",
6068 "-expect-signed-cert-timestamps",
6069 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006070 },
David Benjamina5022392017-07-10 17:40:39 -04006071 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006072 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006073 })
David Benjamindaa88502016-10-04 16:32:16 -04006074
Adam Langleycfa08c32016-11-17 13:21:27 -08006075 var differentSCTList []byte
6076 differentSCTList = append(differentSCTList, testSCTList...)
6077 differentSCTList[len(differentSCTList)-1] ^= 1
6078
David Benjamindaa88502016-10-04 16:32:16 -04006079 // The SCT extension did not specify that it must only be sent on resumption as it
6080 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04006081 testCases = append(testCases, testCase{
6082 name: "SendSCTListOnResume-" + ver.name,
6083 config: Config{
6084 MaxVersion: ver.version,
6085 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08006086 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04006087 },
David Benjamind98452d2015-06-16 14:16:23 -04006088 },
David Benjamin97d17d92016-07-14 16:12:00 -04006089 flags: []string{
6090 "-enable-signed-cert-timestamps",
6091 "-expect-signed-cert-timestamps",
6092 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07006093 },
David Benjamina5022392017-07-10 17:40:39 -04006094 tls13Variant: ver.tls13Variant,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006095 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006096 })
David Benjamindaa88502016-10-04 16:32:16 -04006097
David Benjamin97d17d92016-07-14 16:12:00 -04006098 testCases = append(testCases, testCase{
6099 name: "SignedCertificateTimestampList-Server-" + ver.name,
6100 testType: serverTest,
6101 config: Config{
6102 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05006103 },
David Benjamin97d17d92016-07-14 16:12:00 -04006104 flags: []string{
6105 "-signed-cert-timestamps",
6106 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05006107 },
David Benjamina5022392017-07-10 17:40:39 -04006108 tls13Variant: ver.tls13Variant,
David Benjamin97d17d92016-07-14 16:12:00 -04006109 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006110 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04006111 })
David Benjamin53210cb2016-11-16 09:01:48 +09006112
Adam Langleycfa08c32016-11-17 13:21:27 -08006113 emptySCTListCert := *testCerts[0].cert
6114 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
6115
6116 // Test empty SCT list.
6117 testCases = append(testCases, testCase{
6118 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
6119 testType: clientTest,
6120 config: Config{
6121 MaxVersion: ver.version,
6122 Certificates: []Certificate{emptySCTListCert},
6123 },
6124 flags: []string{
6125 "-enable-signed-cert-timestamps",
6126 },
David Benjamina5022392017-07-10 17:40:39 -04006127 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006128 shouldFail: true,
6129 expectedError: ":ERROR_PARSING_EXTENSION:",
6130 })
6131
6132 emptySCTCert := *testCerts[0].cert
6133 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
6134
6135 // Test empty SCT in non-empty list.
6136 testCases = append(testCases, testCase{
6137 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
6138 testType: clientTest,
6139 config: Config{
6140 MaxVersion: ver.version,
6141 Certificates: []Certificate{emptySCTCert},
6142 },
6143 flags: []string{
6144 "-enable-signed-cert-timestamps",
6145 },
David Benjamina5022392017-07-10 17:40:39 -04006146 tls13Variant: ver.tls13Variant,
Adam Langleycfa08c32016-11-17 13:21:27 -08006147 shouldFail: true,
6148 expectedError: ":ERROR_PARSING_EXTENSION:",
6149 })
6150
David Benjamin53210cb2016-11-16 09:01:48 +09006151 // Test that certificate-related extensions are not sent unsolicited.
6152 testCases = append(testCases, testCase{
6153 testType: serverTest,
6154 name: "UnsolicitedCertificateExtensions-" + ver.name,
6155 config: Config{
6156 MaxVersion: ver.version,
6157 Bugs: ProtocolBugs{
6158 NoOCSPStapling: true,
6159 NoSignedCertificateTimestamps: true,
6160 },
6161 },
David Benjamina5022392017-07-10 17:40:39 -04006162 tls13Variant: ver.tls13Variant,
David Benjamin53210cb2016-11-16 09:01:48 +09006163 flags: []string{
6164 "-ocsp-response",
6165 base64.StdEncoding.EncodeToString(testOCSPResponse),
6166 "-signed-cert-timestamps",
6167 base64.StdEncoding.EncodeToString(testSCTList),
6168 },
6169 })
David Benjamin97d17d92016-07-14 16:12:00 -04006170 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04006171
Paul Lietar4fac72e2015-09-09 13:44:55 +01006172 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07006173 testType: clientTest,
6174 name: "ClientHelloPadding",
6175 config: Config{
6176 Bugs: ProtocolBugs{
6177 RequireClientHelloSize: 512,
6178 },
6179 },
6180 // This hostname just needs to be long enough to push the
6181 // ClientHello into F5's danger zone between 256 and 511 bytes
6182 // long.
6183 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
6184 })
David Benjaminc7ce9772015-10-09 19:32:41 -04006185
6186 // Extensions should not function in SSL 3.0.
6187 testCases = append(testCases, testCase{
6188 testType: serverTest,
6189 name: "SSLv3Extensions-NoALPN",
6190 config: Config{
6191 MaxVersion: VersionSSL30,
6192 NextProtos: []string{"foo", "bar", "baz"},
6193 },
6194 flags: []string{
6195 "-select-alpn", "foo",
6196 },
6197 expectNoNextProto: true,
6198 })
6199
6200 // Test session tickets separately as they follow a different codepath.
6201 testCases = append(testCases, testCase{
6202 testType: serverTest,
6203 name: "SSLv3Extensions-NoTickets",
6204 config: Config{
6205 MaxVersion: VersionSSL30,
6206 Bugs: ProtocolBugs{
6207 // Historically, session tickets in SSL 3.0
6208 // failed in different ways depending on whether
6209 // the client supported renegotiation_info.
6210 NoRenegotiationInfo: true,
6211 },
6212 },
6213 resumeSession: true,
6214 })
6215 testCases = append(testCases, testCase{
6216 testType: serverTest,
6217 name: "SSLv3Extensions-NoTickets2",
6218 config: Config{
6219 MaxVersion: VersionSSL30,
6220 },
6221 resumeSession: true,
6222 })
6223
6224 // But SSL 3.0 does send and process renegotiation_info.
6225 testCases = append(testCases, testCase{
6226 testType: serverTest,
6227 name: "SSLv3Extensions-RenegotiationInfo",
6228 config: Config{
6229 MaxVersion: VersionSSL30,
6230 Bugs: ProtocolBugs{
6231 RequireRenegotiationInfo: true,
6232 },
6233 },
David Benjamind2610042017-01-03 10:49:28 -05006234 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006235 })
6236 testCases = append(testCases, testCase{
6237 testType: serverTest,
6238 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
6239 config: Config{
6240 MaxVersion: VersionSSL30,
6241 Bugs: ProtocolBugs{
6242 NoRenegotiationInfo: true,
6243 SendRenegotiationSCSV: true,
6244 RequireRenegotiationInfo: true,
6245 },
6246 },
David Benjamind2610042017-01-03 10:49:28 -05006247 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04006248 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006249
6250 // Test that illegal extensions in TLS 1.3 are rejected by the client if
6251 // in ServerHello.
6252 testCases = append(testCases, testCase{
6253 name: "NPN-Forbidden-TLS13",
6254 config: Config{
6255 MaxVersion: VersionTLS13,
6256 NextProtos: []string{"foo"},
6257 Bugs: ProtocolBugs{
6258 NegotiateNPNAtAllVersions: true,
6259 },
6260 },
6261 flags: []string{"-select-next-proto", "foo"},
6262 shouldFail: true,
6263 expectedError: ":ERROR_PARSING_EXTENSION:",
6264 })
6265 testCases = append(testCases, testCase{
6266 name: "EMS-Forbidden-TLS13",
6267 config: Config{
6268 MaxVersion: VersionTLS13,
6269 Bugs: ProtocolBugs{
6270 NegotiateEMSAtAllVersions: true,
6271 },
6272 },
6273 shouldFail: true,
6274 expectedError: ":ERROR_PARSING_EXTENSION:",
6275 })
6276 testCases = append(testCases, testCase{
6277 name: "RenegotiationInfo-Forbidden-TLS13",
6278 config: Config{
6279 MaxVersion: VersionTLS13,
6280 Bugs: ProtocolBugs{
6281 NegotiateRenegotiationInfoAtAllVersions: true,
6282 },
6283 },
6284 shouldFail: true,
6285 expectedError: ":ERROR_PARSING_EXTENSION:",
6286 })
6287 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006288 name: "Ticket-Forbidden-TLS13",
6289 config: Config{
6290 MaxVersion: VersionTLS12,
6291 },
6292 resumeConfig: &Config{
6293 MaxVersion: VersionTLS13,
6294 Bugs: ProtocolBugs{
6295 AdvertiseTicketExtension: true,
6296 },
6297 },
6298 resumeSession: true,
6299 shouldFail: true,
6300 expectedError: ":ERROR_PARSING_EXTENSION:",
6301 })
6302
6303 // Test that illegal extensions in TLS 1.3 are declined by the server if
6304 // offered in ClientHello. The runner's server will fail if this occurs,
6305 // so we exercise the offering path. (EMS and Renegotiation Info are
6306 // implicit in every test.)
6307 testCases = append(testCases, testCase{
6308 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04006309 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04006310 config: Config{
6311 MaxVersion: VersionTLS13,
6312 NextProtos: []string{"bar"},
6313 },
6314 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
6315 })
David Benjamin196df5b2016-09-21 16:23:27 -04006316
David Benjamindaa88502016-10-04 16:32:16 -04006317 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
6318 // tolerated.
6319 testCases = append(testCases, testCase{
6320 name: "SendOCSPResponseOnResume-TLS12",
6321 config: Config{
6322 MaxVersion: VersionTLS12,
6323 Bugs: ProtocolBugs{
6324 SendOCSPResponseOnResume: []byte("bogus"),
6325 },
6326 },
6327 flags: []string{
6328 "-enable-ocsp-stapling",
6329 "-expect-ocsp-response",
6330 base64.StdEncoding.EncodeToString(testOCSPResponse),
6331 },
6332 resumeSession: true,
6333 })
6334
David Benjamindaa88502016-10-04 16:32:16 -04006335 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04006336 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04006337 config: Config{
6338 MaxVersion: VersionTLS13,
6339 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04006340 SendExtensionOnCertificate: testOCSPExtension,
6341 },
6342 },
6343 shouldFail: true,
6344 expectedError: ":UNEXPECTED_EXTENSION:",
6345 })
6346
6347 testCases = append(testCases, testCase{
6348 name: "SendUnsolicitedSCTOnCertificate-TLS13",
6349 config: Config{
6350 MaxVersion: VersionTLS13,
6351 Bugs: ProtocolBugs{
6352 SendExtensionOnCertificate: testSCTExtension,
6353 },
6354 },
6355 shouldFail: true,
6356 expectedError: ":UNEXPECTED_EXTENSION:",
6357 })
6358
6359 // Test that extensions on client certificates are never accepted.
6360 testCases = append(testCases, testCase{
6361 name: "SendExtensionOnClientCertificate-TLS13",
6362 testType: serverTest,
6363 config: Config{
6364 MaxVersion: VersionTLS13,
6365 Certificates: []Certificate{rsaCertificate},
6366 Bugs: ProtocolBugs{
6367 SendExtensionOnCertificate: testOCSPExtension,
6368 },
6369 },
6370 flags: []string{
6371 "-enable-ocsp-stapling",
6372 "-require-any-client-certificate",
6373 },
6374 shouldFail: true,
6375 expectedError: ":UNEXPECTED_EXTENSION:",
6376 })
6377
6378 testCases = append(testCases, testCase{
6379 name: "SendUnknownExtensionOnCertificate-TLS13",
6380 config: Config{
6381 MaxVersion: VersionTLS13,
6382 Bugs: ProtocolBugs{
6383 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6384 },
6385 },
6386 shouldFail: true,
6387 expectedError: ":UNEXPECTED_EXTENSION:",
6388 })
6389
6390 // Test that extensions on intermediates are allowed but ignored.
6391 testCases = append(testCases, testCase{
6392 name: "IgnoreExtensionsOnIntermediates-TLS13",
6393 config: Config{
6394 MaxVersion: VersionTLS13,
6395 Certificates: []Certificate{rsaChainCertificate},
6396 Bugs: ProtocolBugs{
6397 // Send different values on the intermediate. This tests
6398 // the intermediate's extensions do not override the
6399 // leaf's.
David Benjamin5c4271f2017-08-23 22:09:41 -07006400 SendOCSPOnIntermediates: testOCSPResponse2,
6401 SendSCTOnIntermediates: testSCTList2,
David Benjamindaa88502016-10-04 16:32:16 -04006402 },
6403 },
6404 flags: []string{
6405 "-enable-ocsp-stapling",
6406 "-expect-ocsp-response",
6407 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006408 "-enable-signed-cert-timestamps",
6409 "-expect-signed-cert-timestamps",
6410 base64.StdEncoding.EncodeToString(testSCTList),
6411 },
6412 resumeSession: true,
6413 })
6414
6415 // Test that extensions are not sent on intermediates when configured
6416 // only for a leaf.
6417 testCases = append(testCases, testCase{
6418 testType: serverTest,
6419 name: "SendNoExtensionsOnIntermediate-TLS13",
6420 config: Config{
6421 MaxVersion: VersionTLS13,
6422 Bugs: ProtocolBugs{
6423 ExpectNoExtensionsOnIntermediate: true,
6424 },
6425 },
6426 flags: []string{
6427 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6428 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6429 "-ocsp-response",
6430 base64.StdEncoding.EncodeToString(testOCSPResponse),
6431 "-signed-cert-timestamps",
6432 base64.StdEncoding.EncodeToString(testSCTList),
6433 },
6434 })
6435
6436 // Test that extensions are not sent on client certificates.
6437 testCases = append(testCases, testCase{
6438 name: "SendNoClientCertificateExtensions-TLS13",
6439 config: Config{
6440 MaxVersion: VersionTLS13,
6441 ClientAuth: RequireAnyClientCert,
6442 },
6443 flags: []string{
6444 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6445 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6446 "-ocsp-response",
6447 base64.StdEncoding.EncodeToString(testOCSPResponse),
6448 "-signed-cert-timestamps",
6449 base64.StdEncoding.EncodeToString(testSCTList),
6450 },
6451 })
6452
6453 testCases = append(testCases, testCase{
6454 name: "SendDuplicateExtensionsOnCerts-TLS13",
6455 config: Config{
6456 MaxVersion: VersionTLS13,
6457 Bugs: ProtocolBugs{
6458 SendDuplicateCertExtensions: true,
6459 },
6460 },
6461 flags: []string{
6462 "-enable-ocsp-stapling",
6463 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006464 },
6465 resumeSession: true,
6466 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006467 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006468 })
Adam Langley9b885c52016-11-18 14:21:03 -08006469
6470 testCases = append(testCases, testCase{
6471 name: "SignedCertificateTimestampListInvalid-Server",
6472 testType: serverTest,
6473 flags: []string{
6474 "-signed-cert-timestamps",
6475 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6476 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006477 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006478 expectedError: ":INVALID_SCT_LIST:",
6479 })
David Benjamine78bfde2014-09-06 12:45:15 -04006480}
6481
David Benjamin01fe8202014-09-24 15:21:44 -04006482func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006483 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006484 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006485 // SSL 3.0 does not have tickets and TLS 1.3 does not
6486 // have session IDs, so skip their cross-resumption
6487 // tests.
6488 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6489 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6490 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006491 }
6492
David Benjamin8b8c0062014-11-23 02:47:52 -05006493 protocols := []protocol{tls}
6494 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6495 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006496 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006497 for _, protocol := range protocols {
6498 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6499 if protocol == dtls {
6500 suffix += "-DTLS"
6501 }
6502
Steven Valdez520e1222017-06-13 12:45:25 -04006503 // We can't resume across TLS 1.3 variants and error out earlier in the
6504 // session resumption.
6505 if sessionVers.tls13Variant != resumeVers.tls13Variant {
6506 continue
6507 }
6508
David Benjaminece3de92015-03-16 18:02:20 -04006509 if sessionVers.version == resumeVers.version {
6510 testCases = append(testCases, testCase{
6511 protocol: protocol,
6512 name: "Resume-Client" + suffix,
6513 resumeSession: true,
6514 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006515 MaxVersion: sessionVers.version,
6516 TLS13Variant: sessionVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006517 Bugs: ProtocolBugs{
6518 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6519 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6520 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006521 },
David Benjaminece3de92015-03-16 18:02:20 -04006522 expectedVersion: sessionVers.version,
6523 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006524 flags: []string{
6525 "-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6526 },
David Benjaminece3de92015-03-16 18:02:20 -04006527 })
6528 } else {
David Benjamin405da482016-08-08 17:25:07 -04006529 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6530
6531 // Offering a TLS 1.3 session sends an empty session ID, so
6532 // there is no way to convince a non-lookahead client the
6533 // session was resumed. It will appear to the client that a
6534 // stray ChangeCipherSpec was sent.
6535 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6536 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006537 }
6538
David Benjaminece3de92015-03-16 18:02:20 -04006539 testCases = append(testCases, testCase{
6540 protocol: protocol,
6541 name: "Resume-Client-Mismatch" + suffix,
6542 resumeSession: true,
6543 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006544 MaxVersion: sessionVers.version,
6545 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006546 },
David Benjaminece3de92015-03-16 18:02:20 -04006547 expectedVersion: sessionVers.version,
6548 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006549 MaxVersion: resumeVers.version,
6550 TLS13Variant: resumeVers.tls13Variant,
David Benjaminece3de92015-03-16 18:02:20 -04006551 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006552 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006553 },
6554 },
6555 expectedResumeVersion: resumeVers.version,
6556 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006557 expectedError: error,
Steven Valdez520e1222017-06-13 12:45:25 -04006558 flags: []string{
6559 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6560 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6561 },
David Benjaminece3de92015-03-16 18:02:20 -04006562 })
6563 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006564
6565 testCases = append(testCases, testCase{
6566 protocol: protocol,
6567 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006568 resumeSession: true,
6569 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006570 MaxVersion: sessionVers.version,
6571 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006572 },
6573 expectedVersion: sessionVers.version,
6574 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006575 MaxVersion: resumeVers.version,
6576 TLS13Variant: resumeVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006577 },
6578 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006579 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006580 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006581 flags: []string{
6582 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6583 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6584 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006585 })
6586
David Benjamin8b8c0062014-11-23 02:47:52 -05006587 testCases = append(testCases, testCase{
6588 protocol: protocol,
6589 testType: serverTest,
6590 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006591 resumeSession: true,
6592 config: Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006593 MaxVersion: sessionVers.version,
6594 TLS13Variant: sessionVers.tls13Variant,
David Benjamin8b8c0062014-11-23 02:47:52 -05006595 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006596 expectedVersion: sessionVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006597 expectResumeRejected: sessionVers != resumeVers,
David Benjamin8b8c0062014-11-23 02:47:52 -05006598 resumeConfig: &Config{
Steven Valdez520e1222017-06-13 12:45:25 -04006599 MaxVersion: resumeVers.version,
6600 TLS13Variant: resumeVers.tls13Variant,
David Benjamin405da482016-08-08 17:25:07 -04006601 Bugs: ProtocolBugs{
6602 SendBothTickets: true,
6603 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006604 },
6605 expectedResumeVersion: resumeVers.version,
Steven Valdez520e1222017-06-13 12:45:25 -04006606 flags: []string{
6607 "-on-initial-tls13-variant", strconv.Itoa(sessionVers.tls13Variant),
6608 "-on-resume-tls13-variant", strconv.Itoa(resumeVers.tls13Variant),
6609 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006610 })
6611 }
David Benjamin01fe8202014-09-24 15:21:44 -04006612 }
6613 }
David Benjaminece3de92015-03-16 18:02:20 -04006614
David Benjamin4199b0d2016-11-01 13:58:25 -04006615 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006616 testCases = append(testCases, testCase{
6617 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006618 name: "ShimTicketRewritable",
6619 resumeSession: true,
6620 config: Config{
6621 MaxVersion: VersionTLS12,
6622 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6623 Bugs: ProtocolBugs{
6624 FilterTicket: func(in []byte) ([]byte, error) {
6625 in, err := SetShimTicketVersion(in, VersionTLS12)
6626 if err != nil {
6627 return nil, err
6628 }
6629 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6630 },
6631 },
6632 },
6633 flags: []string{
6634 "-ticket-key",
6635 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6636 },
6637 })
6638
6639 // Resumptions are declined if the version does not match.
6640 testCases = append(testCases, testCase{
6641 testType: serverTest,
6642 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006643 resumeSession: true,
6644 config: Config{
6645 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006646 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006647 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006648 FilterTicket: func(in []byte) ([]byte, error) {
6649 return SetShimTicketVersion(in, VersionTLS13)
6650 },
6651 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006652 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006653 flags: []string{
6654 "-ticket-key",
6655 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6656 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006657 expectResumeRejected: true,
6658 })
6659
6660 testCases = append(testCases, testCase{
6661 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006662 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006663 resumeSession: true,
6664 config: Config{
6665 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006666 Bugs: ProtocolBugs{
6667 FilterTicket: func(in []byte) ([]byte, error) {
6668 return SetShimTicketVersion(in, VersionTLS12)
6669 },
6670 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006671 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006672 flags: []string{
6673 "-ticket-key",
6674 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6675 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006676 expectResumeRejected: true,
6677 })
6678
David Benjamin4199b0d2016-11-01 13:58:25 -04006679 // Resumptions are declined if the cipher is invalid or disabled.
6680 testCases = append(testCases, testCase{
6681 testType: serverTest,
6682 name: "Resume-Server-DeclineBadCipher",
6683 resumeSession: true,
6684 config: Config{
6685 MaxVersion: VersionTLS12,
6686 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006687 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006688 FilterTicket: func(in []byte) ([]byte, error) {
6689 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6690 },
6691 },
6692 },
6693 flags: []string{
6694 "-ticket-key",
6695 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6696 },
6697 expectResumeRejected: true,
6698 })
6699
6700 testCases = append(testCases, testCase{
6701 testType: serverTest,
6702 name: "Resume-Server-DeclineBadCipher-2",
6703 resumeSession: true,
6704 config: Config{
6705 MaxVersion: VersionTLS12,
6706 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006707 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006708 FilterTicket: func(in []byte) ([]byte, error) {
6709 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6710 },
6711 },
6712 },
6713 flags: []string{
6714 "-cipher", "AES128",
6715 "-ticket-key",
6716 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6717 },
6718 expectResumeRejected: true,
6719 })
6720
David Benjaminf01f42a2016-11-16 19:05:33 +09006721 // Sessions are not resumed if they do not use the preferred cipher.
6722 testCases = append(testCases, testCase{
6723 testType: serverTest,
6724 name: "Resume-Server-CipherNotPreferred",
6725 resumeSession: true,
6726 config: Config{
6727 MaxVersion: VersionTLS12,
6728 Bugs: ProtocolBugs{
6729 ExpectNewTicket: true,
6730 FilterTicket: func(in []byte) ([]byte, error) {
6731 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6732 },
6733 },
6734 },
6735 flags: []string{
6736 "-ticket-key",
6737 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6738 },
6739 shouldFail: false,
6740 expectResumeRejected: true,
6741 })
6742
6743 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6744 // PRF hashes match, but BoringSSL will always decline such resumptions.
6745 testCases = append(testCases, testCase{
6746 testType: serverTest,
6747 name: "Resume-Server-CipherNotPreferred-TLS13",
6748 resumeSession: true,
6749 config: Config{
6750 MaxVersion: VersionTLS13,
6751 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6752 Bugs: ProtocolBugs{
6753 FilterTicket: func(in []byte) ([]byte, error) {
6754 // If the client (runner) offers ChaCha20-Poly1305 first, the
6755 // server (shim) always prefers it. Switch it to AES-GCM.
6756 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6757 },
6758 },
6759 },
6760 flags: []string{
6761 "-ticket-key",
6762 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6763 },
6764 shouldFail: false,
6765 expectResumeRejected: true,
6766 })
6767
6768 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006769 testCases = append(testCases, testCase{
6770 testType: serverTest,
6771 name: "Resume-Server-DeclineBadCipher-TLS13",
6772 resumeSession: true,
6773 config: Config{
6774 MaxVersion: VersionTLS13,
6775 Bugs: ProtocolBugs{
6776 FilterTicket: func(in []byte) ([]byte, error) {
6777 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6778 },
6779 },
6780 },
6781 flags: []string{
6782 "-ticket-key",
6783 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6784 },
6785 expectResumeRejected: true,
6786 })
6787
David Benjaminf01f42a2016-11-16 19:05:33 +09006788 // If the client does not offer the cipher from the session, decline to
6789 // resume. Clients are forbidden from doing this, but BoringSSL selects
6790 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006791 testCases = append(testCases, testCase{
6792 testType: serverTest,
6793 name: "Resume-Server-UnofferedCipher",
6794 resumeSession: true,
6795 config: Config{
6796 MaxVersion: VersionTLS12,
6797 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6798 },
6799 resumeConfig: &Config{
6800 MaxVersion: VersionTLS12,
6801 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6802 Bugs: ProtocolBugs{
6803 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6804 },
6805 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006806 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006807 })
6808
David Benjaminf01f42a2016-11-16 19:05:33 +09006809 // In TLS 1.3, clients may advertise a cipher list which does not
6810 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006811 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6812 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006813 testCases = append(testCases, testCase{
6814 testType: serverTest,
6815 name: "Resume-Server-UnofferedCipher-TLS13",
6816 resumeSession: true,
6817 config: Config{
6818 MaxVersion: VersionTLS13,
6819 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6820 },
6821 resumeConfig: &Config{
6822 MaxVersion: VersionTLS13,
6823 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6824 Bugs: ProtocolBugs{
6825 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6826 },
6827 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006828 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006829 })
6830
David Benjamin4199b0d2016-11-01 13:58:25 -04006831 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006832 testCases = append(testCases, testCase{
6833 name: "Resume-Client-CipherMismatch",
6834 resumeSession: true,
6835 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006836 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006837 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6838 },
6839 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006840 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006841 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6842 Bugs: ProtocolBugs{
6843 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6844 },
6845 },
6846 shouldFail: true,
6847 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6848 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006849
David Benjamine1cc35e2016-11-16 16:25:58 +09006850 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6851 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006852 testCases = append(testCases, testCase{
6853 name: "Resume-Client-CipherMismatch-TLS13",
6854 resumeSession: true,
6855 config: Config{
6856 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006857 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006858 },
6859 resumeConfig: &Config{
6860 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006861 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6862 },
6863 })
6864
6865 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6866 testCases = append(testCases, testCase{
6867 name: "Resume-Client-PRFMismatch-TLS13",
6868 resumeSession: true,
6869 config: Config{
6870 MaxVersion: VersionTLS13,
6871 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6872 },
6873 resumeConfig: &Config{
6874 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006875 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006876 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006877 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006878 },
6879 },
6880 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006881 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006882 })
Steven Valdeza833c352016-11-01 13:39:36 -04006883
6884 testCases = append(testCases, testCase{
6885 testType: serverTest,
6886 name: "Resume-Server-BinderWrongLength",
6887 resumeSession: true,
6888 config: Config{
6889 MaxVersion: VersionTLS13,
6890 Bugs: ProtocolBugs{
6891 SendShortPSKBinder: true,
6892 },
6893 },
6894 shouldFail: true,
6895 expectedLocalError: "remote error: error decrypting message",
6896 expectedError: ":DIGEST_CHECK_FAILED:",
6897 })
6898
6899 testCases = append(testCases, testCase{
6900 testType: serverTest,
6901 name: "Resume-Server-NoPSKBinder",
6902 resumeSession: true,
6903 config: Config{
6904 MaxVersion: VersionTLS13,
6905 Bugs: ProtocolBugs{
6906 SendNoPSKBinder: true,
6907 },
6908 },
6909 shouldFail: true,
6910 expectedLocalError: "remote error: error decoding message",
6911 expectedError: ":DECODE_ERROR:",
6912 })
6913
6914 testCases = append(testCases, testCase{
6915 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006916 name: "Resume-Server-ExtraPSKBinder",
6917 resumeSession: true,
6918 config: Config{
6919 MaxVersion: VersionTLS13,
6920 Bugs: ProtocolBugs{
6921 SendExtraPSKBinder: true,
6922 },
6923 },
6924 shouldFail: true,
6925 expectedLocalError: "remote error: illegal parameter",
6926 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6927 })
6928
6929 testCases = append(testCases, testCase{
6930 testType: serverTest,
6931 name: "Resume-Server-ExtraIdentityNoBinder",
6932 resumeSession: true,
6933 config: Config{
6934 MaxVersion: VersionTLS13,
6935 Bugs: ProtocolBugs{
6936 ExtraPSKIdentity: true,
6937 },
6938 },
6939 shouldFail: true,
6940 expectedLocalError: "remote error: illegal parameter",
6941 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6942 })
6943
6944 testCases = append(testCases, testCase{
6945 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006946 name: "Resume-Server-InvalidPSKBinder",
6947 resumeSession: true,
6948 config: Config{
6949 MaxVersion: VersionTLS13,
6950 Bugs: ProtocolBugs{
6951 SendInvalidPSKBinder: true,
6952 },
6953 },
6954 shouldFail: true,
6955 expectedLocalError: "remote error: error decrypting message",
6956 expectedError: ":DIGEST_CHECK_FAILED:",
6957 })
6958
6959 testCases = append(testCases, testCase{
6960 testType: serverTest,
6961 name: "Resume-Server-PSKBinderFirstExtension",
6962 resumeSession: true,
6963 config: Config{
6964 MaxVersion: VersionTLS13,
6965 Bugs: ProtocolBugs{
6966 PSKBinderFirst: true,
6967 },
6968 },
6969 shouldFail: true,
6970 expectedLocalError: "remote error: illegal parameter",
6971 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6972 })
David Benjamin01fe8202014-09-24 15:21:44 -04006973}
6974
Adam Langley2ae77d22014-10-28 17:29:33 -07006975func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006976 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006977 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006978 testType: serverTest,
6979 name: "Renegotiate-Server-Forbidden",
6980 config: Config{
6981 MaxVersion: VersionTLS12,
6982 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006983 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006984 shouldFail: true,
6985 expectedError: ":NO_RENEGOTIATION:",
6986 expectedLocalError: "remote error: no renegotiation",
6987 })
Adam Langley5021b222015-06-12 18:27:58 -07006988 // The server shouldn't echo the renegotiation extension unless
6989 // requested by the client.
6990 testCases = append(testCases, testCase{
6991 testType: serverTest,
6992 name: "Renegotiate-Server-NoExt",
6993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006994 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006995 Bugs: ProtocolBugs{
6996 NoRenegotiationInfo: true,
6997 RequireRenegotiationInfo: true,
6998 },
6999 },
7000 shouldFail: true,
7001 expectedLocalError: "renegotiation extension missing",
7002 })
7003 // The renegotiation SCSV should be sufficient for the server to echo
7004 // the extension.
7005 testCases = append(testCases, testCase{
7006 testType: serverTest,
7007 name: "Renegotiate-Server-NoExt-SCSV",
7008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007009 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07007010 Bugs: ProtocolBugs{
7011 NoRenegotiationInfo: true,
7012 SendRenegotiationSCSV: true,
7013 RequireRenegotiationInfo: true,
7014 },
7015 },
7016 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07007017 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007018 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04007019 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007020 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04007021 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04007022 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04007023 },
7024 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007025 renegotiate: 1,
David Benjamind0beda02017-09-06 16:46:50 -04007026 // Test renegotiation after both an initial and resumption
7027 // handshake.
7028 resumeSession: true,
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007029 flags: []string{
7030 "-renegotiate-freely",
7031 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007032 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007033 },
David Benjamincdea40c2015-03-19 14:09:43 -04007034 })
7035 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007036 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007037 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007039 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007040 Bugs: ProtocolBugs{
7041 EmptyRenegotiationInfo: true,
7042 },
7043 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007044 flags: []string{"-renegotiate-freely"},
7045 shouldFail: true,
7046 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007047 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007048 })
7049 testCases = append(testCases, testCase{
7050 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007051 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007052 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007053 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007054 Bugs: ProtocolBugs{
7055 BadRenegotiationInfo: true,
7056 },
7057 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007058 flags: []string{"-renegotiate-freely"},
7059 shouldFail: true,
7060 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007061 expectedLocalError: "handshake failure",
Adam Langleycf2d4f42014-10-28 19:06:14 -07007062 })
7063 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04007064 name: "Renegotiate-Client-BadExt2",
7065 renegotiate: 1,
7066 config: Config{
7067 MaxVersion: VersionTLS12,
7068 Bugs: ProtocolBugs{
7069 BadRenegotiationInfoEnd: true,
7070 },
7071 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007072 flags: []string{"-renegotiate-freely"},
7073 shouldFail: true,
7074 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007075 expectedLocalError: "handshake failure",
David Benjamin9343b0b2017-07-01 00:31:27 -04007076 })
7077 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05007078 name: "Renegotiate-Client-Downgrade",
7079 renegotiate: 1,
7080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007081 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007082 Bugs: ProtocolBugs{
7083 NoRenegotiationInfoAfterInitial: true,
7084 },
7085 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007086 flags: []string{"-renegotiate-freely"},
7087 shouldFail: true,
7088 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007089 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007090 })
7091 testCases = append(testCases, testCase{
7092 name: "Renegotiate-Client-Upgrade",
7093 renegotiate: 1,
7094 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007095 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05007096 Bugs: ProtocolBugs{
7097 NoRenegotiationInfoInInitial: true,
7098 },
7099 },
Adam Langleye6c58ff2017-07-28 11:00:11 -07007100 flags: []string{"-renegotiate-freely"},
7101 shouldFail: true,
7102 expectedError: ":RENEGOTIATION_MISMATCH:",
Adam Langley10e10602017-07-25 13:33:21 -07007103 expectedLocalError: "handshake failure",
David Benjamin3e052de2015-11-25 20:10:31 -05007104 })
7105 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04007106 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007107 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04007108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007109 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04007110 Bugs: ProtocolBugs{
7111 NoRenegotiationInfo: true,
7112 },
7113 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007114 flags: []string{
7115 "-renegotiate-freely",
7116 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05007117 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007118 },
David Benjamincff0b902015-05-15 23:09:47 -04007119 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007120
7121 // Test that the server may switch ciphers on renegotiation without
7122 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04007123 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07007124 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007125 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007126 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007127 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007128 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07007129 },
7130 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007131 flags: []string{
7132 "-renegotiate-freely",
7133 "-expect-total-renegotiations", "1",
7134 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07007135 })
7136 testCases = append(testCases, testCase{
7137 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007138 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007139 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007140 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07007141 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7142 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07007143 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007144 flags: []string{
7145 "-renegotiate-freely",
7146 "-expect-total-renegotiations", "1",
7147 },
David Benjaminb16346b2015-04-08 19:16:58 -04007148 })
David Benjamine7e36aa2016-08-08 12:39:41 -04007149
7150 // Test that the server may not switch versions on renegotiation.
7151 testCases = append(testCases, testCase{
7152 name: "Renegotiate-Client-SwitchVersion",
7153 config: Config{
7154 MaxVersion: VersionTLS12,
7155 // Pick a cipher which exists at both versions.
7156 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
7157 Bugs: ProtocolBugs{
7158 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05007159 // Avoid failing early at the record layer.
7160 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04007161 },
7162 },
7163 renegotiate: 1,
7164 flags: []string{
7165 "-renegotiate-freely",
7166 "-expect-total-renegotiations", "1",
7167 },
7168 shouldFail: true,
7169 expectedError: ":WRONG_SSL_VERSION:",
7170 })
7171
David Benjaminb16346b2015-04-08 19:16:58 -04007172 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05007173 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007174 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05007175 config: Config{
7176 MaxVersion: VersionTLS10,
7177 Bugs: ProtocolBugs{
7178 RequireSameRenegoClientVersion: true,
7179 },
7180 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007181 flags: []string{
7182 "-renegotiate-freely",
7183 "-expect-total-renegotiations", "1",
7184 },
David Benjaminc44b1df2014-11-23 12:11:01 -05007185 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07007186 testCases = append(testCases, testCase{
7187 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007188 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007189 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007190 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07007191 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7192 NextProtos: []string{"foo"},
7193 },
7194 flags: []string{
7195 "-false-start",
7196 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007197 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04007198 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07007199 },
7200 shimWritesFirst: true,
7201 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007202
7203 // Client-side renegotiation controls.
7204 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007205 name: "Renegotiate-Client-Forbidden-1",
7206 config: Config{
7207 MaxVersion: VersionTLS12,
7208 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007209 renegotiate: 1,
7210 shouldFail: true,
7211 expectedError: ":NO_RENEGOTIATION:",
7212 expectedLocalError: "remote error: no renegotiation",
7213 })
7214 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007215 name: "Renegotiate-Client-Once-1",
7216 config: Config{
7217 MaxVersion: VersionTLS12,
7218 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007219 renegotiate: 1,
7220 flags: []string{
7221 "-renegotiate-once",
7222 "-expect-total-renegotiations", "1",
7223 },
7224 })
7225 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007226 name: "Renegotiate-Client-Freely-1",
7227 config: Config{
7228 MaxVersion: VersionTLS12,
7229 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007230 renegotiate: 1,
7231 flags: []string{
7232 "-renegotiate-freely",
7233 "-expect-total-renegotiations", "1",
7234 },
7235 })
7236 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007237 name: "Renegotiate-Client-Once-2",
7238 config: Config{
7239 MaxVersion: VersionTLS12,
7240 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007241 renegotiate: 2,
7242 flags: []string{"-renegotiate-once"},
7243 shouldFail: true,
7244 expectedError: ":NO_RENEGOTIATION:",
7245 expectedLocalError: "remote error: no renegotiation",
7246 })
7247 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007248 name: "Renegotiate-Client-Freely-2",
7249 config: Config{
7250 MaxVersion: VersionTLS12,
7251 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04007252 renegotiate: 2,
7253 flags: []string{
7254 "-renegotiate-freely",
7255 "-expect-total-renegotiations", "2",
7256 },
7257 })
Adam Langley27a0d082015-11-03 13:34:10 -08007258 testCases = append(testCases, testCase{
7259 name: "Renegotiate-Client-NoIgnore",
7260 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007261 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007262 Bugs: ProtocolBugs{
7263 SendHelloRequestBeforeEveryAppDataRecord: true,
7264 },
7265 },
7266 shouldFail: true,
7267 expectedError: ":NO_RENEGOTIATION:",
7268 })
7269 testCases = append(testCases, testCase{
7270 name: "Renegotiate-Client-Ignore",
7271 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007272 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08007273 Bugs: ProtocolBugs{
7274 SendHelloRequestBeforeEveryAppDataRecord: true,
7275 },
7276 },
7277 flags: []string{
7278 "-renegotiate-ignore",
7279 "-expect-total-renegotiations", "0",
7280 },
7281 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007282
David Benjamin34941c02016-10-08 11:45:31 -04007283 // Renegotiation is not allowed at SSL 3.0.
7284 testCases = append(testCases, testCase{
7285 name: "Renegotiate-Client-SSL3",
7286 config: Config{
7287 MaxVersion: VersionSSL30,
7288 },
7289 renegotiate: 1,
7290 flags: []string{
7291 "-renegotiate-freely",
7292 "-expect-total-renegotiations", "1",
7293 },
7294 shouldFail: true,
7295 expectedError: ":NO_RENEGOTIATION:",
7296 expectedLocalError: "remote error: no renegotiation",
7297 })
7298
David Benjamina1eaba12017-01-01 23:19:22 -05007299 // Renegotiation is not allowed when there is an unfinished write.
7300 testCases = append(testCases, testCase{
7301 name: "Renegotiate-Client-UnfinishedWrite",
7302 config: Config{
7303 MaxVersion: VersionTLS12,
7304 },
David Benjaminbbba9392017-04-06 12:54:12 -04007305 renegotiate: 1,
7306 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05007307 flags: []string{
7308 "-async",
7309 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05007310 },
7311 shouldFail: true,
7312 expectedError: ":NO_RENEGOTIATION:",
7313 // We do not successfully send the no_renegotiation alert in
7314 // this case. https://crbug.com/boringssl/130
7315 })
7316
David Benjamin07ab5d42017-02-09 20:11:41 -05007317 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07007318 testCases = append(testCases, testCase{
7319 name: "StrayHelloRequest",
7320 config: Config{
7321 MaxVersion: VersionTLS12,
7322 Bugs: ProtocolBugs{
7323 SendHelloRequestBeforeEveryHandshakeMessage: true,
7324 },
7325 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007326 shouldFail: true,
7327 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007328 })
7329 testCases = append(testCases, testCase{
7330 name: "StrayHelloRequest-Packed",
7331 config: Config{
7332 MaxVersion: VersionTLS12,
7333 Bugs: ProtocolBugs{
7334 PackHandshakeFlight: true,
7335 SendHelloRequestBeforeEveryHandshakeMessage: true,
7336 },
7337 },
David Benjamin07ab5d42017-02-09 20:11:41 -05007338 shouldFail: true,
7339 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07007340 })
7341
David Benjamin12d2c482016-07-24 10:56:51 -04007342 // Test renegotiation works if HelloRequest and server Finished come in
7343 // the same record.
7344 testCases = append(testCases, testCase{
7345 name: "Renegotiate-Client-Packed",
7346 config: Config{
7347 MaxVersion: VersionTLS12,
7348 Bugs: ProtocolBugs{
7349 PackHandshakeFlight: true,
7350 PackHelloRequestWithFinished: true,
7351 },
7352 },
7353 renegotiate: 1,
7354 flags: []string{
7355 "-renegotiate-freely",
7356 "-expect-total-renegotiations", "1",
7357 },
7358 })
7359
David Benjamin397c8e62016-07-08 14:14:36 -07007360 // Renegotiation is forbidden in TLS 1.3.
7361 testCases = append(testCases, testCase{
7362 name: "Renegotiate-Client-TLS13",
7363 config: Config{
7364 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007365 Bugs: ProtocolBugs{
7366 SendHelloRequestBeforeEveryAppDataRecord: true,
7367 },
David Benjamin397c8e62016-07-08 14:14:36 -07007368 },
David Benjamin397c8e62016-07-08 14:14:36 -07007369 flags: []string{
7370 "-renegotiate-freely",
7371 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04007372 shouldFail: true,
7373 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07007374 })
7375
7376 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
7377 testCases = append(testCases, testCase{
7378 name: "StrayHelloRequest-TLS13",
7379 config: Config{
7380 MaxVersion: VersionTLS13,
7381 Bugs: ProtocolBugs{
7382 SendHelloRequestBeforeEveryHandshakeMessage: true,
7383 },
7384 },
7385 shouldFail: true,
7386 expectedError: ":UNEXPECTED_MESSAGE:",
7387 })
David Benjamind2610042017-01-03 10:49:28 -05007388
7389 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
7390 // always reads as supporting it, regardless of whether it was
7391 // negotiated.
7392 testCases = append(testCases, testCase{
7393 name: "AlwaysReportRenegotiationInfo-TLS13",
7394 config: Config{
7395 MaxVersion: VersionTLS13,
7396 Bugs: ProtocolBugs{
7397 NoRenegotiationInfo: true,
7398 },
7399 },
7400 flags: []string{
7401 "-expect-secure-renegotiation",
7402 },
7403 })
David Benjamina58baaf2017-02-28 20:54:28 -05007404
7405 // Certificates may not change on renegotiation.
7406 testCases = append(testCases, testCase{
7407 name: "Renegotiation-CertificateChange",
7408 config: Config{
7409 MaxVersion: VersionTLS12,
7410 Certificates: []Certificate{rsaCertificate},
7411 Bugs: ProtocolBugs{
7412 RenegotiationCertificate: &rsaChainCertificate,
7413 },
7414 },
7415 renegotiate: 1,
7416 flags: []string{"-renegotiate-freely"},
7417 shouldFail: true,
7418 expectedError: ":SERVER_CERT_CHANGED:",
7419 })
7420 testCases = append(testCases, testCase{
7421 name: "Renegotiation-CertificateChange-2",
7422 config: Config{
7423 MaxVersion: VersionTLS12,
7424 Certificates: []Certificate{rsaCertificate},
7425 Bugs: ProtocolBugs{
7426 RenegotiationCertificate: &rsa1024Certificate,
7427 },
7428 },
7429 renegotiate: 1,
7430 flags: []string{"-renegotiate-freely"},
7431 shouldFail: true,
7432 expectedError: ":SERVER_CERT_CHANGED:",
7433 })
David Benjaminbbf42462017-03-14 21:27:10 -04007434
7435 // We do not negotiate ALPN after the initial handshake. This is
7436 // error-prone and only risks bugs in consumers.
7437 testCases = append(testCases, testCase{
7438 testType: clientTest,
7439 name: "Renegotiation-ForbidALPN",
7440 config: Config{
7441 MaxVersion: VersionTLS12,
7442 Bugs: ProtocolBugs{
7443 // Forcibly negotiate ALPN on both initial and
7444 // renegotiation handshakes. The test stack will
7445 // internally check the client does not offer
7446 // it.
7447 SendALPN: "foo",
7448 },
7449 },
7450 flags: []string{
7451 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7452 "-expect-alpn", "foo",
7453 "-renegotiate-freely",
7454 },
7455 renegotiate: 1,
7456 shouldFail: true,
7457 expectedError: ":UNEXPECTED_EXTENSION:",
7458 })
David Benjamin5c4271f2017-08-23 22:09:41 -07007459
7460 // The server may send different stapled OCSP responses or SCT lists on
7461 // renegotiation, but BoringSSL ignores this and reports the old values.
7462 // Also test that non-fatal verify results are preserved.
7463 testCases = append(testCases, testCase{
7464 testType: clientTest,
7465 name: "Renegotiation-ChangeAuthProperties",
7466 config: Config{
7467 MaxVersion: VersionTLS12,
7468 Bugs: ProtocolBugs{
7469 SendOCSPResponseOnRenegotiation: testOCSPResponse2,
7470 SendSCTListOnRenegotiation: testSCTList2,
7471 },
7472 },
7473 renegotiate: 1,
7474 flags: []string{
7475 "-renegotiate-freely",
7476 "-expect-total-renegotiations", "1",
7477 "-enable-ocsp-stapling",
7478 "-expect-ocsp-response",
7479 base64.StdEncoding.EncodeToString(testOCSPResponse),
7480 "-enable-signed-cert-timestamps",
7481 "-expect-signed-cert-timestamps",
7482 base64.StdEncoding.EncodeToString(testSCTList),
7483 "-verify-fail",
7484 "-expect-verify-result",
7485 },
7486 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007487}
7488
David Benjamin5e961c12014-11-07 01:48:35 -05007489func addDTLSReplayTests() {
7490 // Test that sequence number replays are detected.
7491 testCases = append(testCases, testCase{
7492 protocol: dtls,
7493 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007494 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007495 replayWrites: true,
7496 })
7497
David Benjamin8e6db492015-07-25 18:29:23 -04007498 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007499 // than the retransmit window.
7500 testCases = append(testCases, testCase{
7501 protocol: dtls,
7502 name: "DTLS-Replay-LargeGaps",
7503 config: Config{
7504 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007505 SequenceNumberMapping: func(in uint64) uint64 {
7506 return in * 127
7507 },
David Benjamin5e961c12014-11-07 01:48:35 -05007508 },
7509 },
David Benjamin8e6db492015-07-25 18:29:23 -04007510 messageCount: 200,
7511 replayWrites: true,
7512 })
7513
7514 // Test the incoming sequence number changing non-monotonically.
7515 testCases = append(testCases, testCase{
7516 protocol: dtls,
7517 name: "DTLS-Replay-NonMonotonic",
7518 config: Config{
7519 Bugs: ProtocolBugs{
7520 SequenceNumberMapping: func(in uint64) uint64 {
7521 return in ^ 31
7522 },
7523 },
7524 },
7525 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007526 replayWrites: true,
7527 })
7528}
7529
Nick Harper60edffd2016-06-21 15:19:24 -07007530var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007531 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007532 id signatureAlgorithm
7533 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007534}{
Nick Harper60edffd2016-06-21 15:19:24 -07007535 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7536 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7537 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7538 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007539 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007540 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7541 // hash function doesn't have to match the curve and so the same
7542 // signature algorithm works with P-224.
7543 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007544 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7545 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7546 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007547 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7548 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7549 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007550 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007551 // Tests for key types prior to TLS 1.2.
7552 {"RSA", 0, testCertRSA},
7553 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007554}
7555
Nick Harper60edffd2016-06-21 15:19:24 -07007556const fakeSigAlg1 signatureAlgorithm = 0x2a01
7557const fakeSigAlg2 signatureAlgorithm = 0xff01
7558
7559func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007560 // Not all ciphers involve a signature. Advertise a list which gives all
7561 // versions a signing cipher.
7562 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007563 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007564 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7565 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7566 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7567 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007568 }
David Benjamin5208fd42016-07-13 21:43:25 -04007569
David Benjaminca3d5452016-07-14 12:51:01 -04007570 var allAlgorithms []signatureAlgorithm
7571 for _, alg := range testSignatureAlgorithms {
7572 if alg.id != 0 {
7573 allAlgorithms = append(allAlgorithms, alg.id)
7574 }
7575 }
7576
Nick Harper60edffd2016-06-21 15:19:24 -07007577 // Make sure each signature algorithm works. Include some fake values in
7578 // the list and ensure they're ignored.
7579 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007580 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007581 if (ver.version < VersionTLS12) != (alg.id == 0) {
7582 continue
7583 }
7584
7585 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7586 // or remove it in C.
7587 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007588 continue
7589 }
Nick Harper60edffd2016-06-21 15:19:24 -07007590
David Benjamin3ef76972016-10-17 17:59:54 -04007591 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007592 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007593 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007594 shouldSignFail = true
7595 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007596 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007597 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007598 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7599 shouldSignFail = true
7600 shouldVerifyFail = true
7601 }
7602 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7603 // the curve has to match the hash size.
7604 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007605 shouldSignFail = true
7606 shouldVerifyFail = true
7607 }
7608
7609 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7610 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7611 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007612 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007613
7614 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007615 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007616 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007617 }
7618 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007619 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007620 }
David Benjamin000800a2014-11-14 01:43:59 -05007621
David Benjamin1fb125c2016-07-08 18:52:12 -07007622 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007623
David Benjamin7a41d372016-07-09 11:21:54 -07007624 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007625 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007626 config: Config{
7627 MaxVersion: ver.version,
7628 ClientAuth: RequireAnyClientCert,
7629 VerifySignatureAlgorithms: []signatureAlgorithm{
7630 fakeSigAlg1,
7631 alg.id,
7632 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007633 },
David Benjamin7a41d372016-07-09 11:21:54 -07007634 },
7635 flags: []string{
7636 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7637 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7638 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007639 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007640 },
David Benjamina5022392017-07-10 17:40:39 -04007641 tls13Variant: ver.tls13Variant,
David Benjamin3ef76972016-10-17 17:59:54 -04007642 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007643 expectedError: signError,
7644 expectedPeerSignatureAlgorithm: alg.id,
7645 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007646
David Benjamin7a41d372016-07-09 11:21:54 -07007647 testCases = append(testCases, testCase{
7648 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007649 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007650 config: Config{
7651 MaxVersion: ver.version,
7652 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7653 SignSignatureAlgorithms: []signatureAlgorithm{
7654 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007655 },
David Benjamin7a41d372016-07-09 11:21:54 -07007656 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007657 SkipECDSACurveCheck: shouldVerifyFail,
7658 IgnoreSignatureVersionChecks: shouldVerifyFail,
7659 // Some signature algorithms may not be advertised.
7660 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007661 },
David Benjamin7a41d372016-07-09 11:21:54 -07007662 },
David Benjamina5022392017-07-10 17:40:39 -04007663 tls13Variant: ver.tls13Variant,
David Benjamin7a41d372016-07-09 11:21:54 -07007664 flags: []string{
7665 "-require-any-client-certificate",
7666 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7667 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007668 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007669 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007670 // Resume the session to assert the peer signature
7671 // algorithm is reported on both handshakes.
7672 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007673 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007674 expectedError: verifyError,
7675 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007676
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007677 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007678 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007679 testCases = append(testCases, testCase{
7680 testType: serverTest,
7681 name: "ServerAuth-Sign" + suffix,
7682 config: Config{
7683 MaxVersion: ver.version,
7684 CipherSuites: signingCiphers,
7685 VerifySignatureAlgorithms: []signatureAlgorithm{
7686 fakeSigAlg1,
7687 alg.id,
7688 fakeSigAlg2,
7689 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007690 },
David Benjamina5022392017-07-10 17:40:39 -04007691 tls13Variant: ver.tls13Variant,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007692 flags: []string{
7693 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7694 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7695 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007696 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007697 },
7698 shouldFail: shouldSignFail,
7699 expectedError: signError,
7700 expectedPeerSignatureAlgorithm: alg.id,
7701 })
7702 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007703
7704 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007705 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007706 config: Config{
7707 MaxVersion: ver.version,
7708 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007709 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007710 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007711 alg.id,
7712 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007713 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007714 SkipECDSACurveCheck: shouldVerifyFail,
7715 IgnoreSignatureVersionChecks: shouldVerifyFail,
7716 // Some signature algorithms may not be advertised.
7717 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007718 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007719 },
David Benjamina5022392017-07-10 17:40:39 -04007720 tls13Variant: ver.tls13Variant,
David Benjamin1fb125c2016-07-08 18:52:12 -07007721 flags: []string{
7722 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7723 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007724 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007725 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007726 // Resume the session to assert the peer signature
7727 // algorithm is reported on both handshakes.
7728 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007729 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007730 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007731 })
David Benjamin5208fd42016-07-13 21:43:25 -04007732
David Benjamin3ef76972016-10-17 17:59:54 -04007733 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007734 testCases = append(testCases, testCase{
7735 testType: serverTest,
7736 name: "ClientAuth-InvalidSignature" + suffix,
7737 config: Config{
7738 MaxVersion: ver.version,
7739 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7740 SignSignatureAlgorithms: []signatureAlgorithm{
7741 alg.id,
7742 },
7743 Bugs: ProtocolBugs{
7744 InvalidSignature: true,
7745 },
7746 },
David Benjamina5022392017-07-10 17:40:39 -04007747 tls13Variant: ver.tls13Variant,
David Benjamin5208fd42016-07-13 21:43:25 -04007748 flags: []string{
7749 "-require-any-client-certificate",
7750 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007751 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007752 },
7753 shouldFail: true,
7754 expectedError: ":BAD_SIGNATURE:",
7755 })
7756
7757 testCases = append(testCases, testCase{
7758 name: "ServerAuth-InvalidSignature" + suffix,
7759 config: Config{
7760 MaxVersion: ver.version,
7761 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7762 CipherSuites: signingCiphers,
7763 SignSignatureAlgorithms: []signatureAlgorithm{
7764 alg.id,
7765 },
7766 Bugs: ProtocolBugs{
7767 InvalidSignature: true,
7768 },
7769 },
David Benjamina5022392017-07-10 17:40:39 -04007770 tls13Variant: ver.tls13Variant,
David Benjamin69522112017-03-28 15:38:29 -05007771 flags: []string{
7772 "-enable-all-curves",
7773 "-enable-ed25519",
7774 },
David Benjamin5208fd42016-07-13 21:43:25 -04007775 shouldFail: true,
7776 expectedError: ":BAD_SIGNATURE:",
7777 })
7778 }
David Benjaminca3d5452016-07-14 12:51:01 -04007779
David Benjamin3ef76972016-10-17 17:59:54 -04007780 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007781 testCases = append(testCases, testCase{
7782 name: "ClientAuth-Sign-Negotiate" + suffix,
7783 config: Config{
7784 MaxVersion: ver.version,
7785 ClientAuth: RequireAnyClientCert,
7786 VerifySignatureAlgorithms: allAlgorithms,
7787 },
David Benjamina5022392017-07-10 17:40:39 -04007788 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007789 flags: []string{
7790 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7791 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7792 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007793 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007794 "-signing-prefs", strconv.Itoa(int(alg.id)),
7795 },
7796 expectedPeerSignatureAlgorithm: alg.id,
7797 })
7798
7799 testCases = append(testCases, testCase{
7800 testType: serverTest,
7801 name: "ServerAuth-Sign-Negotiate" + suffix,
7802 config: Config{
7803 MaxVersion: ver.version,
7804 CipherSuites: signingCiphers,
7805 VerifySignatureAlgorithms: allAlgorithms,
7806 },
David Benjamina5022392017-07-10 17:40:39 -04007807 tls13Variant: ver.tls13Variant,
David Benjaminca3d5452016-07-14 12:51:01 -04007808 flags: []string{
7809 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7810 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7811 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007812 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007813 "-signing-prefs", strconv.Itoa(int(alg.id)),
7814 },
7815 expectedPeerSignatureAlgorithm: alg.id,
7816 })
7817 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007818 }
David Benjamin000800a2014-11-14 01:43:59 -05007819 }
7820
Nick Harper60edffd2016-06-21 15:19:24 -07007821 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007822 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007823 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007824 config: Config{
7825 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007826 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007827 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007828 signatureECDSAWithP521AndSHA512,
7829 signatureRSAPKCS1WithSHA384,
7830 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007831 },
7832 },
7833 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007834 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7835 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007836 },
Nick Harper60edffd2016-06-21 15:19:24 -07007837 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007838 })
7839
7840 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007841 name: "ClientAuth-SignatureType-TLS13",
7842 config: Config{
7843 ClientAuth: RequireAnyClientCert,
7844 MaxVersion: VersionTLS13,
7845 VerifySignatureAlgorithms: []signatureAlgorithm{
7846 signatureECDSAWithP521AndSHA512,
7847 signatureRSAPKCS1WithSHA384,
7848 signatureRSAPSSWithSHA384,
7849 signatureECDSAWithSHA1,
7850 },
7851 },
7852 flags: []string{
7853 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7854 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7855 },
7856 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7857 })
7858
7859 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007860 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007861 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007862 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007863 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007864 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007865 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007866 signatureECDSAWithP521AndSHA512,
7867 signatureRSAPKCS1WithSHA384,
7868 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007869 },
7870 },
Nick Harper60edffd2016-06-21 15:19:24 -07007871 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007872 })
7873
Steven Valdez143e8b32016-07-11 13:19:03 -04007874 testCases = append(testCases, testCase{
7875 testType: serverTest,
7876 name: "ServerAuth-SignatureType-TLS13",
7877 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007878 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007879 VerifySignatureAlgorithms: []signatureAlgorithm{
7880 signatureECDSAWithP521AndSHA512,
7881 signatureRSAPKCS1WithSHA384,
7882 signatureRSAPSSWithSHA384,
7883 signatureECDSAWithSHA1,
7884 },
7885 },
7886 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7887 })
7888
David Benjamina95e9f32016-07-08 16:28:04 -07007889 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007890 testCases = append(testCases, testCase{
7891 testType: serverTest,
7892 name: "Verify-ClientAuth-SignatureType",
7893 config: Config{
7894 MaxVersion: VersionTLS12,
7895 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007896 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007897 signatureRSAPKCS1WithSHA256,
7898 },
7899 Bugs: ProtocolBugs{
7900 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7901 },
7902 },
7903 flags: []string{
7904 "-require-any-client-certificate",
7905 },
7906 shouldFail: true,
7907 expectedError: ":WRONG_SIGNATURE_TYPE:",
7908 })
7909
7910 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007911 testType: serverTest,
7912 name: "Verify-ClientAuth-SignatureType-TLS13",
7913 config: Config{
7914 MaxVersion: VersionTLS13,
7915 Certificates: []Certificate{rsaCertificate},
7916 SignSignatureAlgorithms: []signatureAlgorithm{
7917 signatureRSAPSSWithSHA256,
7918 },
7919 Bugs: ProtocolBugs{
7920 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7921 },
7922 },
7923 flags: []string{
7924 "-require-any-client-certificate",
7925 },
7926 shouldFail: true,
7927 expectedError: ":WRONG_SIGNATURE_TYPE:",
7928 })
7929
7930 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007931 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007932 config: Config{
7933 MaxVersion: VersionTLS12,
7934 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007935 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007936 signatureRSAPKCS1WithSHA256,
7937 },
7938 Bugs: ProtocolBugs{
7939 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7940 },
7941 },
7942 shouldFail: true,
7943 expectedError: ":WRONG_SIGNATURE_TYPE:",
7944 })
7945
Steven Valdez143e8b32016-07-11 13:19:03 -04007946 testCases = append(testCases, testCase{
7947 name: "Verify-ServerAuth-SignatureType-TLS13",
7948 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007949 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007950 SignSignatureAlgorithms: []signatureAlgorithm{
7951 signatureRSAPSSWithSHA256,
7952 },
7953 Bugs: ProtocolBugs{
7954 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7955 },
7956 },
7957 shouldFail: true,
7958 expectedError: ":WRONG_SIGNATURE_TYPE:",
7959 })
7960
David Benjamin51dd7d62016-07-08 16:07:01 -07007961 // Test that, if the list is missing, the peer falls back to SHA-1 in
7962 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007963 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007964 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007966 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007967 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007968 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007969 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007970 },
7971 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007972 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007973 },
7974 },
7975 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007976 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7977 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007978 },
7979 })
7980
7981 testCases = append(testCases, testCase{
7982 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007983 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007984 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007985 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007986 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007987 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007988 },
7989 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007990 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007991 },
7992 },
David Benjaminee32bea2016-08-17 13:36:44 -04007993 flags: []string{
7994 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7995 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7996 },
7997 })
7998
7999 testCases = append(testCases, testCase{
8000 name: "ClientAuth-SHA1-Fallback-ECDSA",
8001 config: Config{
8002 MaxVersion: VersionTLS12,
8003 ClientAuth: RequireAnyClientCert,
8004 VerifySignatureAlgorithms: []signatureAlgorithm{
8005 signatureECDSAWithSHA1,
8006 },
8007 Bugs: ProtocolBugs{
8008 NoSignatureAlgorithms: true,
8009 },
8010 },
8011 flags: []string{
8012 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8013 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8014 },
8015 })
8016
8017 testCases = append(testCases, testCase{
8018 testType: serverTest,
8019 name: "ServerAuth-SHA1-Fallback-ECDSA",
8020 config: Config{
8021 MaxVersion: VersionTLS12,
8022 VerifySignatureAlgorithms: []signatureAlgorithm{
8023 signatureECDSAWithSHA1,
8024 },
8025 Bugs: ProtocolBugs{
8026 NoSignatureAlgorithms: true,
8027 },
8028 },
8029 flags: []string{
8030 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8031 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8032 },
David Benjamin000800a2014-11-14 01:43:59 -05008033 })
David Benjamin72dc7832015-03-16 17:49:43 -04008034
David Benjamin51dd7d62016-07-08 16:07:01 -07008035 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008036 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008037 config: Config{
8038 MaxVersion: VersionTLS13,
8039 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008040 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008041 signatureRSAPKCS1WithSHA1,
8042 },
8043 Bugs: ProtocolBugs{
8044 NoSignatureAlgorithms: true,
8045 },
8046 },
8047 flags: []string{
8048 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8049 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8050 },
David Benjamin48901652016-08-01 12:12:47 -04008051 shouldFail: true,
8052 // An empty CertificateRequest signature algorithm list is a
8053 // syntax error in TLS 1.3.
8054 expectedError: ":DECODE_ERROR:",
8055 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07008056 })
8057
8058 testCases = append(testCases, testCase{
8059 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008060 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07008061 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008062 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008063 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07008064 signatureRSAPKCS1WithSHA1,
8065 },
8066 Bugs: ProtocolBugs{
8067 NoSignatureAlgorithms: true,
8068 },
8069 },
8070 shouldFail: true,
8071 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8072 })
8073
David Benjaminb62d2872016-07-18 14:55:02 +02008074 // Test that hash preferences are enforced. BoringSSL does not implement
8075 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04008076 testCases = append(testCases, testCase{
8077 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04008078 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008079 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008080 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008081 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008082 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008083 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008084 },
8085 Bugs: ProtocolBugs{
8086 IgnorePeerSignatureAlgorithmPreferences: true,
8087 },
8088 },
8089 flags: []string{"-require-any-client-certificate"},
8090 shouldFail: true,
8091 expectedError: ":WRONG_SIGNATURE_TYPE:",
8092 })
8093
8094 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04008095 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04008096 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008097 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04008098 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07008099 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008100 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04008101 },
8102 Bugs: ProtocolBugs{
8103 IgnorePeerSignatureAlgorithmPreferences: true,
8104 },
8105 },
8106 shouldFail: true,
8107 expectedError: ":WRONG_SIGNATURE_TYPE:",
8108 })
David Benjaminb62d2872016-07-18 14:55:02 +02008109 testCases = append(testCases, testCase{
8110 testType: serverTest,
8111 name: "ClientAuth-Enforced-TLS13",
8112 config: Config{
8113 MaxVersion: VersionTLS13,
8114 Certificates: []Certificate{rsaCertificate},
8115 SignSignatureAlgorithms: []signatureAlgorithm{
8116 signatureRSAPKCS1WithMD5,
8117 },
8118 Bugs: ProtocolBugs{
8119 IgnorePeerSignatureAlgorithmPreferences: true,
8120 IgnoreSignatureVersionChecks: true,
8121 },
8122 },
8123 flags: []string{"-require-any-client-certificate"},
8124 shouldFail: true,
8125 expectedError: ":WRONG_SIGNATURE_TYPE:",
8126 })
8127
8128 testCases = append(testCases, testCase{
8129 name: "ServerAuth-Enforced-TLS13",
8130 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008131 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02008132 SignSignatureAlgorithms: []signatureAlgorithm{
8133 signatureRSAPKCS1WithMD5,
8134 },
8135 Bugs: ProtocolBugs{
8136 IgnorePeerSignatureAlgorithmPreferences: true,
8137 IgnoreSignatureVersionChecks: true,
8138 },
8139 },
8140 shouldFail: true,
8141 expectedError: ":WRONG_SIGNATURE_TYPE:",
8142 })
Steven Valdez0d62f262015-09-04 12:41:04 -04008143
8144 // Test that the agreed upon digest respects the client preferences and
8145 // the server digests.
8146 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04008147 name: "NoCommonAlgorithms-Digests",
8148 config: Config{
8149 MaxVersion: VersionTLS12,
8150 ClientAuth: RequireAnyClientCert,
8151 VerifySignatureAlgorithms: []signatureAlgorithm{
8152 signatureRSAPKCS1WithSHA512,
8153 signatureRSAPKCS1WithSHA1,
8154 },
8155 },
8156 flags: []string{
8157 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8158 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8159 "-digest-prefs", "SHA256",
8160 },
8161 shouldFail: true,
8162 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8163 })
8164 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07008165 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04008166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008167 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008168 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008169 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008170 signatureRSAPKCS1WithSHA512,
8171 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008172 },
8173 },
8174 flags: []string{
8175 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8176 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008177 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04008178 },
David Benjaminca3d5452016-07-14 12:51:01 -04008179 shouldFail: true,
8180 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8181 })
8182 testCases = append(testCases, testCase{
8183 name: "NoCommonAlgorithms-TLS13",
8184 config: Config{
8185 MaxVersion: VersionTLS13,
8186 ClientAuth: RequireAnyClientCert,
8187 VerifySignatureAlgorithms: []signatureAlgorithm{
8188 signatureRSAPSSWithSHA512,
8189 signatureRSAPSSWithSHA384,
8190 },
8191 },
8192 flags: []string{
8193 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8194 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8195 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
8196 },
David Benjaminea9a0d52016-07-08 15:52:59 -07008197 shouldFail: true,
8198 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04008199 })
8200 testCases = append(testCases, testCase{
8201 name: "Agree-Digest-SHA256",
8202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008203 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008204 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008205 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008206 signatureRSAPKCS1WithSHA1,
8207 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008208 },
8209 },
8210 flags: []string{
8211 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8212 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008213 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008214 },
Nick Harper60edffd2016-06-21 15:19:24 -07008215 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008216 })
8217 testCases = append(testCases, testCase{
8218 name: "Agree-Digest-SHA1",
8219 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008220 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008221 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008222 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008223 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008224 },
8225 },
8226 flags: []string{
8227 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8228 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04008229 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04008230 },
Nick Harper60edffd2016-06-21 15:19:24 -07008231 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008232 })
8233 testCases = append(testCases, testCase{
8234 name: "Agree-Digest-Default",
8235 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008236 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04008237 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07008238 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07008239 signatureRSAPKCS1WithSHA256,
8240 signatureECDSAWithP256AndSHA256,
8241 signatureRSAPKCS1WithSHA1,
8242 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04008243 },
8244 },
8245 flags: []string{
8246 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8247 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8248 },
Nick Harper60edffd2016-06-21 15:19:24 -07008249 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04008250 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008251
David Benjaminca3d5452016-07-14 12:51:01 -04008252 // Test that the signing preference list may include extra algorithms
8253 // without negotiation problems.
8254 testCases = append(testCases, testCase{
8255 testType: serverTest,
8256 name: "FilterExtraAlgorithms",
8257 config: Config{
8258 MaxVersion: VersionTLS12,
8259 VerifySignatureAlgorithms: []signatureAlgorithm{
8260 signatureRSAPKCS1WithSHA256,
8261 },
8262 },
8263 flags: []string{
8264 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8265 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8266 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
8267 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
8268 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
8269 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
8270 },
8271 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
8272 })
8273
David Benjamin4c3ddf72016-06-29 18:13:53 -04008274 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
8275 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04008276 testCases = append(testCases, testCase{
8277 name: "CheckLeafCurve",
8278 config: Config{
8279 MaxVersion: VersionTLS12,
8280 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07008281 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04008282 },
8283 flags: []string{"-p384-only"},
8284 shouldFail: true,
8285 expectedError: ":BAD_ECC_CERT:",
8286 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07008287
8288 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
8289 testCases = append(testCases, testCase{
8290 name: "CheckLeafCurve-TLS13",
8291 config: Config{
8292 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07008293 Certificates: []Certificate{ecdsaP256Certificate},
8294 },
8295 flags: []string{"-p384-only"},
8296 })
David Benjamin1fb125c2016-07-08 18:52:12 -07008297
8298 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
8299 testCases = append(testCases, testCase{
8300 name: "ECDSACurveMismatch-Verify-TLS12",
8301 config: Config{
8302 MaxVersion: VersionTLS12,
8303 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
8304 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008305 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008306 signatureECDSAWithP384AndSHA384,
8307 },
8308 },
8309 })
8310
8311 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
8312 testCases = append(testCases, testCase{
8313 name: "ECDSACurveMismatch-Verify-TLS13",
8314 config: Config{
8315 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07008316 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07008317 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008318 signatureECDSAWithP384AndSHA384,
8319 },
8320 Bugs: ProtocolBugs{
8321 SkipECDSACurveCheck: true,
8322 },
8323 },
8324 shouldFail: true,
8325 expectedError: ":WRONG_SIGNATURE_TYPE:",
8326 })
8327
8328 // Signature algorithm selection in TLS 1.3 should take the curve into
8329 // account.
8330 testCases = append(testCases, testCase{
8331 testType: serverTest,
8332 name: "ECDSACurveMismatch-Sign-TLS13",
8333 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008334 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07008335 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07008336 signatureECDSAWithP384AndSHA384,
8337 signatureECDSAWithP256AndSHA256,
8338 },
8339 },
8340 flags: []string{
8341 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
8342 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
8343 },
8344 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
8345 })
David Benjamin7944a9f2016-07-12 22:27:01 -04008346
8347 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
8348 // server does not attempt to sign in that case.
8349 testCases = append(testCases, testCase{
8350 testType: serverTest,
8351 name: "RSA-PSS-Large",
8352 config: Config{
8353 MaxVersion: VersionTLS13,
8354 VerifySignatureAlgorithms: []signatureAlgorithm{
8355 signatureRSAPSSWithSHA512,
8356 },
8357 },
8358 flags: []string{
8359 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
8360 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
8361 },
8362 shouldFail: true,
8363 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8364 })
David Benjamin57e929f2016-08-30 00:30:38 -04008365
8366 // Test that RSA-PSS is enabled by default for TLS 1.2.
8367 testCases = append(testCases, testCase{
8368 testType: clientTest,
8369 name: "RSA-PSS-Default-Verify",
8370 config: Config{
8371 MaxVersion: VersionTLS12,
8372 SignSignatureAlgorithms: []signatureAlgorithm{
8373 signatureRSAPSSWithSHA256,
8374 },
8375 },
8376 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8377 })
8378
8379 testCases = append(testCases, testCase{
8380 testType: serverTest,
8381 name: "RSA-PSS-Default-Sign",
8382 config: Config{
8383 MaxVersion: VersionTLS12,
8384 VerifySignatureAlgorithms: []signatureAlgorithm{
8385 signatureRSAPSSWithSHA256,
8386 },
8387 },
8388 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8389 })
David Benjamin69522112017-03-28 15:38:29 -05008390
8391 // TLS 1.1 and below has no way to advertise support for or negotiate
8392 // Ed25519's signature algorithm.
8393 testCases = append(testCases, testCase{
8394 testType: clientTest,
8395 name: "NoEd25519-TLS11-ServerAuth-Verify",
8396 config: Config{
8397 MaxVersion: VersionTLS11,
8398 Certificates: []Certificate{ed25519Certificate},
8399 Bugs: ProtocolBugs{
8400 // Sign with Ed25519 even though it is TLS 1.1.
8401 UseLegacySigningAlgorithm: signatureEd25519,
8402 },
8403 },
8404 flags: []string{"-enable-ed25519"},
8405 shouldFail: true,
8406 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8407 })
8408 testCases = append(testCases, testCase{
8409 testType: serverTest,
8410 name: "NoEd25519-TLS11-ServerAuth-Sign",
8411 config: Config{
8412 MaxVersion: VersionTLS11,
8413 },
8414 flags: []string{
8415 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8416 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8417 },
8418 shouldFail: true,
8419 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8420 })
8421 testCases = append(testCases, testCase{
8422 testType: serverTest,
8423 name: "NoEd25519-TLS11-ClientAuth-Verify",
8424 config: Config{
8425 MaxVersion: VersionTLS11,
8426 Certificates: []Certificate{ed25519Certificate},
8427 Bugs: ProtocolBugs{
8428 // Sign with Ed25519 even though it is TLS 1.1.
8429 UseLegacySigningAlgorithm: signatureEd25519,
8430 },
8431 },
8432 flags: []string{
8433 "-enable-ed25519",
8434 "-require-any-client-certificate",
8435 },
8436 shouldFail: true,
8437 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8438 })
8439 testCases = append(testCases, testCase{
8440 testType: clientTest,
8441 name: "NoEd25519-TLS11-ClientAuth-Sign",
8442 config: Config{
8443 MaxVersion: VersionTLS11,
8444 ClientAuth: RequireAnyClientCert,
8445 },
8446 flags: []string{
8447 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8448 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8449 },
8450 shouldFail: true,
8451 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8452 })
8453
8454 // Test Ed25519 is not advertised by default.
8455 testCases = append(testCases, testCase{
8456 testType: clientTest,
8457 name: "Ed25519DefaultDisable-NoAdvertise",
8458 config: Config{
8459 Certificates: []Certificate{ed25519Certificate},
8460 },
8461 shouldFail: true,
8462 expectedLocalError: "tls: no common signature algorithms",
8463 })
8464
8465 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8466 // preferences.
8467 testCases = append(testCases, testCase{
8468 testType: clientTest,
8469 name: "Ed25519DefaultDisable-NoAccept",
8470 config: Config{
8471 Certificates: []Certificate{ed25519Certificate},
8472 Bugs: ProtocolBugs{
8473 IgnorePeerSignatureAlgorithmPreferences: true,
8474 },
8475 },
8476 shouldFail: true,
8477 expectedLocalError: "remote error: illegal parameter",
8478 expectedError: ":WRONG_SIGNATURE_TYPE:",
8479 })
David Benjamin71c21b42017-04-14 17:05:40 -04008480
8481 // Test that configuring verify preferences changes what the client
8482 // advertises.
8483 testCases = append(testCases, testCase{
8484 name: "VerifyPreferences-Advertised",
8485 config: Config{
8486 Certificates: []Certificate{rsaCertificate},
8487 SignSignatureAlgorithms: []signatureAlgorithm{
8488 signatureRSAPSSWithSHA256,
8489 signatureRSAPSSWithSHA384,
8490 signatureRSAPSSWithSHA512,
8491 },
8492 },
8493 flags: []string{
8494 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8495 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8496 },
8497 })
8498
8499 // Test that the client advertises a set which the runner can find
8500 // nothing in common with.
8501 testCases = append(testCases, testCase{
8502 name: "VerifyPreferences-NoCommonAlgorithms",
8503 config: Config{
8504 Certificates: []Certificate{rsaCertificate},
8505 SignSignatureAlgorithms: []signatureAlgorithm{
8506 signatureRSAPSSWithSHA256,
8507 signatureRSAPSSWithSHA512,
8508 },
8509 },
8510 flags: []string{
8511 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8512 },
8513 shouldFail: true,
8514 expectedLocalError: "tls: no common signature algorithms",
8515 })
8516
8517 // Test that the client enforces its preferences when configured.
8518 testCases = append(testCases, testCase{
8519 name: "VerifyPreferences-Enforced",
8520 config: Config{
8521 Certificates: []Certificate{rsaCertificate},
8522 SignSignatureAlgorithms: []signatureAlgorithm{
8523 signatureRSAPSSWithSHA256,
8524 signatureRSAPSSWithSHA512,
8525 },
8526 Bugs: ProtocolBugs{
8527 IgnorePeerSignatureAlgorithmPreferences: true,
8528 },
8529 },
8530 flags: []string{
8531 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8532 },
8533 shouldFail: true,
8534 expectedLocalError: "remote error: illegal parameter",
8535 expectedError: ":WRONG_SIGNATURE_TYPE:",
8536 })
8537
8538 // Test that explicitly configuring Ed25519 is as good as changing the
8539 // boolean toggle.
8540 testCases = append(testCases, testCase{
8541 name: "VerifyPreferences-Ed25519",
8542 config: Config{
8543 Certificates: []Certificate{ed25519Certificate},
8544 },
8545 flags: []string{
8546 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8547 },
8548 })
David Benjamin000800a2014-11-14 01:43:59 -05008549}
8550
David Benjamin83f90402015-01-27 01:09:43 -05008551// timeouts is the retransmit schedule for BoringSSL. It doubles and
8552// caps at 60 seconds. On the 13th timeout, it gives up.
8553var timeouts = []time.Duration{
8554 1 * time.Second,
8555 2 * time.Second,
8556 4 * time.Second,
8557 8 * time.Second,
8558 16 * time.Second,
8559 32 * time.Second,
8560 60 * time.Second,
8561 60 * time.Second,
8562 60 * time.Second,
8563 60 * time.Second,
8564 60 * time.Second,
8565 60 * time.Second,
8566 60 * time.Second,
8567}
8568
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008569// shortTimeouts is an alternate set of timeouts which would occur if the
8570// initial timeout duration was set to 250ms.
8571var shortTimeouts = []time.Duration{
8572 250 * time.Millisecond,
8573 500 * time.Millisecond,
8574 1 * time.Second,
8575 2 * time.Second,
8576 4 * time.Second,
8577 8 * time.Second,
8578 16 * time.Second,
8579 32 * time.Second,
8580 60 * time.Second,
8581 60 * time.Second,
8582 60 * time.Second,
8583 60 * time.Second,
8584 60 * time.Second,
8585}
8586
David Benjamin83f90402015-01-27 01:09:43 -05008587func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008588 // These tests work by coordinating some behavior on both the shim and
8589 // the runner.
8590 //
8591 // TimeoutSchedule configures the runner to send a series of timeout
8592 // opcodes to the shim (see packetAdaptor) immediately before reading
8593 // each peer handshake flight N. The timeout opcode both simulates a
8594 // timeout in the shim and acts as a synchronization point to help the
8595 // runner bracket each handshake flight.
8596 //
8597 // We assume the shim does not read from the channel eagerly. It must
8598 // first wait until it has sent flight N and is ready to receive
8599 // handshake flight N+1. At this point, it will process the timeout
8600 // opcode. It must then immediately respond with a timeout ACK and act
8601 // as if the shim was idle for the specified amount of time.
8602 //
8603 // The runner then drops all packets received before the ACK and
8604 // continues waiting for flight N. This ordering results in one attempt
8605 // at sending flight N to be dropped. For the test to complete, the
8606 // shim must send flight N again, testing that the shim implements DTLS
8607 // retransmit on a timeout.
8608
Steven Valdez143e8b32016-07-11 13:19:03 -04008609 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008610 // likely be more epochs to cross and the final message's retransmit may
8611 // be more complex.
8612
David Benjamin11c82892017-02-23 20:40:31 -05008613 // Test that this is indeed the timeout schedule. Stress all
8614 // four patterns of handshake.
8615 for i := 1; i < len(timeouts); i++ {
8616 number := strconv.Itoa(i)
8617 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008618 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008619 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008620 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008621 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008622 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008623 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008624 },
8625 },
8626 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008627 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008628 })
David Benjamin11c82892017-02-23 20:40:31 -05008629 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008630 protocol: dtls,
8631 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008632 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008633 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008634 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008635 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008636 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008637 },
8638 },
8639 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008640 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008641 })
8642 }
David Benjamin11c82892017-02-23 20:40:31 -05008643
8644 // Test that exceeding the timeout schedule hits a read
8645 // timeout.
8646 testCases = append(testCases, testCase{
8647 protocol: dtls,
8648 name: "DTLS-Retransmit-Timeout",
8649 config: Config{
8650 MaxVersion: VersionTLS12,
8651 Bugs: ProtocolBugs{
8652 TimeoutSchedule: timeouts,
8653 },
8654 },
8655 resumeSession: true,
8656 flags: []string{"-async"},
8657 shouldFail: true,
8658 expectedError: ":READ_TIMEOUT_EXPIRED:",
8659 })
8660
8661 // Test that timeout handling has a fudge factor, due to API
8662 // problems.
8663 testCases = append(testCases, testCase{
8664 protocol: dtls,
8665 name: "DTLS-Retransmit-Fudge",
8666 config: Config{
8667 MaxVersion: VersionTLS12,
8668 Bugs: ProtocolBugs{
8669 TimeoutSchedule: []time.Duration{
8670 timeouts[0] - 10*time.Millisecond,
8671 },
8672 },
8673 },
8674 resumeSession: true,
8675 flags: []string{"-async"},
8676 })
8677
8678 // Test that the final Finished retransmitting isn't
8679 // duplicated if the peer badly fragments everything.
8680 testCases = append(testCases, testCase{
8681 testType: serverTest,
8682 protocol: dtls,
8683 name: "DTLS-Retransmit-Fragmented",
8684 config: Config{
8685 MaxVersion: VersionTLS12,
8686 Bugs: ProtocolBugs{
8687 TimeoutSchedule: []time.Duration{timeouts[0]},
8688 MaxHandshakeRecordLength: 2,
8689 },
8690 },
8691 flags: []string{"-async"},
8692 })
8693
8694 // Test the timeout schedule when a shorter initial timeout duration is set.
8695 testCases = append(testCases, testCase{
8696 protocol: dtls,
8697 name: "DTLS-Retransmit-Short-Client",
8698 config: Config{
8699 MaxVersion: VersionTLS12,
8700 Bugs: ProtocolBugs{
8701 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8702 },
8703 },
8704 resumeSession: true,
8705 flags: []string{
8706 "-async",
8707 "-initial-timeout-duration-ms", "250",
8708 },
8709 })
8710 testCases = append(testCases, testCase{
8711 protocol: dtls,
8712 testType: serverTest,
8713 name: "DTLS-Retransmit-Short-Server",
8714 config: Config{
8715 MaxVersion: VersionTLS12,
8716 Bugs: ProtocolBugs{
8717 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8718 },
8719 },
8720 resumeSession: true,
8721 flags: []string{
8722 "-async",
8723 "-initial-timeout-duration-ms", "250",
8724 },
8725 })
David Benjamin302b8182017-08-22 14:47:22 -07008726
8727 // If the shim sends the last Finished (server full or client resume
8728 // handshakes), it must retransmit that Finished when it sees a
8729 // post-handshake penultimate Finished from the runner. The above tests
8730 // cover this. Conversely, if the shim sends the penultimate Finished
8731 // (client full or server resume), test that it does not retransmit.
8732 testCases = append(testCases, testCase{
8733 protocol: dtls,
8734 testType: clientTest,
8735 name: "DTLS-StrayRetransmitFinished-ClientFull",
8736 config: Config{
8737 MaxVersion: VersionTLS12,
8738 Bugs: ProtocolBugs{
8739 RetransmitFinished: true,
8740 },
8741 },
8742 })
8743 testCases = append(testCases, testCase{
8744 protocol: dtls,
8745 testType: serverTest,
8746 name: "DTLS-StrayRetransmitFinished-ServerResume",
8747 config: Config{
8748 MaxVersion: VersionTLS12,
8749 },
8750 resumeConfig: &Config{
8751 MaxVersion: VersionTLS12,
8752 Bugs: ProtocolBugs{
8753 RetransmitFinished: true,
8754 },
8755 },
8756 resumeSession: true,
8757 })
David Benjamin83f90402015-01-27 01:09:43 -05008758}
8759
David Benjaminc565ebb2015-04-03 04:06:36 -04008760func addExportKeyingMaterialTests() {
8761 for _, vers := range tlsVersions {
8762 if vers.version == VersionSSL30 {
8763 continue
8764 }
8765 testCases = append(testCases, testCase{
8766 name: "ExportKeyingMaterial-" + vers.name,
8767 config: Config{
8768 MaxVersion: vers.version,
8769 },
David Benjamina5022392017-07-10 17:40:39 -04008770 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008771 exportKeyingMaterial: 1024,
8772 exportLabel: "label",
8773 exportContext: "context",
8774 useExportContext: true,
8775 })
8776 testCases = append(testCases, testCase{
8777 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8778 config: Config{
8779 MaxVersion: vers.version,
8780 },
David Benjamina5022392017-07-10 17:40:39 -04008781 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008782 exportKeyingMaterial: 1024,
8783 })
8784 testCases = append(testCases, testCase{
8785 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8786 config: Config{
8787 MaxVersion: vers.version,
8788 },
David Benjamina5022392017-07-10 17:40:39 -04008789 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008790 exportKeyingMaterial: 1024,
8791 useExportContext: true,
8792 })
8793 testCases = append(testCases, testCase{
8794 name: "ExportKeyingMaterial-Small-" + vers.name,
8795 config: Config{
8796 MaxVersion: vers.version,
8797 },
David Benjamina5022392017-07-10 17:40:39 -04008798 tls13Variant: vers.tls13Variant,
David Benjaminc565ebb2015-04-03 04:06:36 -04008799 exportKeyingMaterial: 1,
8800 exportLabel: "label",
8801 exportContext: "context",
8802 useExportContext: true,
8803 })
8804 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008805
David Benjaminc565ebb2015-04-03 04:06:36 -04008806 testCases = append(testCases, testCase{
8807 name: "ExportKeyingMaterial-SSL3",
8808 config: Config{
8809 MaxVersion: VersionSSL30,
8810 },
8811 exportKeyingMaterial: 1024,
8812 exportLabel: "label",
8813 exportContext: "context",
8814 useExportContext: true,
8815 shouldFail: true,
8816 expectedError: "failed to export keying material",
8817 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008818
8819 // Exporters work during a False Start.
8820 testCases = append(testCases, testCase{
8821 name: "ExportKeyingMaterial-FalseStart",
8822 config: Config{
8823 MaxVersion: VersionTLS12,
8824 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8825 NextProtos: []string{"foo"},
8826 Bugs: ProtocolBugs{
8827 ExpectFalseStart: true,
8828 },
8829 },
8830 flags: []string{
8831 "-false-start",
8832 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008833 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008834 },
8835 shimWritesFirst: true,
8836 exportKeyingMaterial: 1024,
8837 exportLabel: "label",
8838 exportContext: "context",
8839 useExportContext: true,
8840 })
8841
8842 // Exporters do not work in the middle of a renegotiation. Test this by
8843 // triggering the exporter after every SSL_read call and configuring the
8844 // shim to run asynchronously.
8845 testCases = append(testCases, testCase{
8846 name: "ExportKeyingMaterial-Renegotiate",
8847 config: Config{
8848 MaxVersion: VersionTLS12,
8849 },
8850 renegotiate: 1,
8851 flags: []string{
8852 "-async",
8853 "-use-exporter-between-reads",
8854 "-renegotiate-freely",
8855 "-expect-total-renegotiations", "1",
8856 },
8857 shouldFail: true,
8858 expectedError: "failed to export keying material",
8859 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008860}
8861
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008862func addTLSUniqueTests() {
8863 for _, isClient := range []bool{false, true} {
8864 for _, isResumption := range []bool{false, true} {
8865 for _, hasEMS := range []bool{false, true} {
8866 var suffix string
8867 if isResumption {
8868 suffix = "Resume-"
8869 } else {
8870 suffix = "Full-"
8871 }
8872
8873 if hasEMS {
8874 suffix += "EMS-"
8875 } else {
8876 suffix += "NoEMS-"
8877 }
8878
8879 if isClient {
8880 suffix += "Client"
8881 } else {
8882 suffix += "Server"
8883 }
8884
8885 test := testCase{
8886 name: "TLSUnique-" + suffix,
8887 testTLSUnique: true,
8888 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008889 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008890 Bugs: ProtocolBugs{
8891 NoExtendedMasterSecret: !hasEMS,
8892 },
8893 },
8894 }
8895
8896 if isResumption {
8897 test.resumeSession = true
8898 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008899 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008900 Bugs: ProtocolBugs{
8901 NoExtendedMasterSecret: !hasEMS,
8902 },
8903 }
8904 }
8905
8906 if isResumption && !hasEMS {
8907 test.shouldFail = true
8908 test.expectedError = "failed to get tls-unique"
8909 }
8910
8911 testCases = append(testCases, test)
8912 }
8913 }
8914 }
8915}
8916
Adam Langley09505632015-07-30 18:10:13 -07008917func addCustomExtensionTests() {
8918 expectedContents := "custom extension"
8919 emptyString := ""
8920
8921 for _, isClient := range []bool{false, true} {
8922 suffix := "Server"
8923 flag := "-enable-server-custom-extension"
8924 testType := serverTest
8925 if isClient {
8926 suffix = "Client"
8927 flag = "-enable-client-custom-extension"
8928 testType = clientTest
8929 }
8930
8931 testCases = append(testCases, testCase{
8932 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008933 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008935 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008936 Bugs: ProtocolBugs{
8937 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008938 ExpectedCustomExtension: &expectedContents,
8939 },
8940 },
8941 flags: []string{flag},
8942 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008943 testCases = append(testCases, testCase{
8944 testType: testType,
8945 name: "CustomExtensions-" + suffix + "-TLS13",
8946 config: Config{
8947 MaxVersion: VersionTLS13,
8948 Bugs: ProtocolBugs{
8949 CustomExtension: expectedContents,
8950 ExpectedCustomExtension: &expectedContents,
8951 },
8952 },
8953 flags: []string{flag},
8954 })
Adam Langley09505632015-07-30 18:10:13 -07008955
8956 // If the parse callback fails, the handshake should also fail.
8957 testCases = append(testCases, testCase{
8958 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008959 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008960 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008961 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008962 Bugs: ProtocolBugs{
8963 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008964 ExpectedCustomExtension: &expectedContents,
8965 },
8966 },
David Benjamin399e7c92015-07-30 23:01:27 -04008967 flags: []string{flag},
8968 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008969 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8970 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008971 testCases = append(testCases, testCase{
8972 testType: testType,
8973 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8974 config: Config{
8975 MaxVersion: VersionTLS13,
8976 Bugs: ProtocolBugs{
8977 CustomExtension: expectedContents + "foo",
8978 ExpectedCustomExtension: &expectedContents,
8979 },
8980 },
8981 flags: []string{flag},
8982 shouldFail: true,
8983 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8984 })
Adam Langley09505632015-07-30 18:10:13 -07008985
8986 // If the add callback fails, the handshake should also fail.
8987 testCases = append(testCases, testCase{
8988 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008989 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008990 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008991 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008992 Bugs: ProtocolBugs{
8993 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008994 ExpectedCustomExtension: &expectedContents,
8995 },
8996 },
David Benjamin399e7c92015-07-30 23:01:27 -04008997 flags: []string{flag, "-custom-extension-fail-add"},
8998 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008999 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9000 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009001 testCases = append(testCases, testCase{
9002 testType: testType,
9003 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
9004 config: Config{
9005 MaxVersion: VersionTLS13,
9006 Bugs: ProtocolBugs{
9007 CustomExtension: expectedContents,
9008 ExpectedCustomExtension: &expectedContents,
9009 },
9010 },
9011 flags: []string{flag, "-custom-extension-fail-add"},
9012 shouldFail: true,
9013 expectedError: ":CUSTOM_EXTENSION_ERROR:",
9014 })
Adam Langley09505632015-07-30 18:10:13 -07009015
9016 // If the add callback returns zero, no extension should be
9017 // added.
9018 skipCustomExtension := expectedContents
9019 if isClient {
9020 // For the case where the client skips sending the
9021 // custom extension, the server must not “echo” it.
9022 skipCustomExtension = ""
9023 }
9024 testCases = append(testCases, testCase{
9025 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04009026 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07009027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009028 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009029 Bugs: ProtocolBugs{
9030 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07009031 ExpectedCustomExtension: &emptyString,
9032 },
9033 },
9034 flags: []string{flag, "-custom-extension-skip"},
9035 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009036 testCases = append(testCases, testCase{
9037 testType: testType,
9038 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
9039 config: Config{
9040 MaxVersion: VersionTLS13,
9041 Bugs: ProtocolBugs{
9042 CustomExtension: skipCustomExtension,
9043 ExpectedCustomExtension: &emptyString,
9044 },
9045 },
9046 flags: []string{flag, "-custom-extension-skip"},
9047 })
Adam Langley09505632015-07-30 18:10:13 -07009048 }
9049
Steven Valdezf4ecc842017-08-10 14:02:56 -04009050 // If the client sends both early data and custom extension, the handshake
9051 // should succeed as long as both the extensions aren't returned by the
9052 // server.
9053 testCases = append(testCases, testCase{
9054 testType: clientTest,
9055 name: "CustomExtensions-Client-EarlyData-None",
9056 config: Config{
9057 MaxVersion: VersionTLS13,
9058 MaxEarlyDataSize: 16384,
9059 Bugs: ProtocolBugs{
9060 ExpectedCustomExtension: &expectedContents,
9061 AlwaysRejectEarlyData: true,
9062 },
9063 },
9064 resumeSession: true,
9065 flags: []string{
9066 "-enable-client-custom-extension",
9067 "-enable-early-data",
9068 "-expect-early-data-info",
9069 "-expect-reject-early-data",
9070 },
9071 })
9072
9073 testCases = append(testCases, testCase{
9074 testType: clientTest,
9075 name: "CustomExtensions-Client-EarlyData-EarlyDataAccepted",
9076 config: Config{
9077 MaxVersion: VersionTLS13,
9078 MaxEarlyDataSize: 16384,
9079 Bugs: ProtocolBugs{
9080 ExpectedCustomExtension: &expectedContents,
9081 },
9082 },
9083 resumeSession: true,
9084 flags: []string{
9085 "-enable-client-custom-extension",
9086 "-enable-early-data",
9087 "-expect-early-data-info",
9088 "-expect-accept-early-data",
9089 },
9090 })
9091
9092 testCases = append(testCases, testCase{
9093 testType: clientTest,
9094 name: "CustomExtensions-Client-EarlyData-CustomExtensionAccepted",
9095 config: Config{
9096 MaxVersion: VersionTLS13,
9097 MaxEarlyDataSize: 16384,
9098 Bugs: ProtocolBugs{
9099 AlwaysRejectEarlyData: true,
9100 CustomExtension: expectedContents,
9101 ExpectedCustomExtension: &expectedContents,
9102 },
9103 },
9104 resumeSession: true,
9105 flags: []string{
9106 "-enable-client-custom-extension",
9107 "-enable-early-data",
9108 "-expect-early-data-info",
9109 "-expect-reject-early-data",
9110 },
9111 })
9112
9113 testCases = append(testCases, testCase{
9114 testType: clientTest,
9115 name: "CustomExtensions-Client-EarlyDataAndCustomExtensions",
9116 config: Config{
9117 MaxVersion: VersionTLS13,
9118 MaxEarlyDataSize: 16384,
9119 Bugs: ProtocolBugs{
9120 CustomExtension: expectedContents,
9121 ExpectedCustomExtension: &expectedContents,
9122 },
9123 },
9124 resumeConfig: &Config{
9125 MaxVersion: VersionTLS13,
9126 MaxEarlyDataSize: 16384,
9127 Bugs: ProtocolBugs{
9128 CustomExtension: expectedContents,
9129 ExpectedCustomExtension: &expectedContents,
9130 SendEarlyDataExtension: true,
9131 },
9132 },
9133 resumeSession: true,
9134 shouldFail: true,
9135 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
9136 flags: []string{
9137 "-enable-client-custom-extension",
9138 "-enable-early-data",
9139 "-expect-early-data-info",
9140 },
9141 })
9142
9143 // If the server receives both early data and custom extension, only the
9144 // custom extension should be accepted.
9145 testCases = append(testCases, testCase{
9146 testType: serverTest,
9147 name: "CustomExtensions-Server-EarlyDataAccepted",
9148 config: Config{
9149 MaxVersion: VersionTLS13,
9150 MaxEarlyDataSize: 16384,
9151 Bugs: ProtocolBugs{
9152 CustomExtension: expectedContents,
9153 ExpectedCustomExtension: &expectedContents,
9154 ExpectEarlyDataAccepted: false,
9155 },
9156 },
9157 resumeSession: true,
9158 flags: []string{
9159 "-enable-server-custom-extension",
9160 "-enable-early-data",
9161 "-expect-early-data-info",
9162 },
9163 })
9164
Adam Langley09505632015-07-30 18:10:13 -07009165 // The custom extension add callback should not be called if the client
9166 // doesn't send the extension.
9167 testCases = append(testCases, testCase{
9168 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04009169 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07009170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009171 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04009172 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07009173 ExpectedCustomExtension: &emptyString,
9174 },
9175 },
9176 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9177 })
Adam Langley2deb9842015-08-07 11:15:37 -07009178
Steven Valdez143e8b32016-07-11 13:19:03 -04009179 testCases = append(testCases, testCase{
9180 testType: serverTest,
9181 name: "CustomExtensions-NotCalled-Server-TLS13",
9182 config: Config{
9183 MaxVersion: VersionTLS13,
9184 Bugs: ProtocolBugs{
9185 ExpectedCustomExtension: &emptyString,
9186 },
9187 },
9188 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
9189 })
9190
Adam Langley2deb9842015-08-07 11:15:37 -07009191 // Test an unknown extension from the server.
9192 testCases = append(testCases, testCase{
9193 testType: clientTest,
9194 name: "UnknownExtension-Client",
9195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009196 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07009197 Bugs: ProtocolBugs{
9198 CustomExtension: expectedContents,
9199 },
9200 },
David Benjamin0c40a962016-08-01 12:05:50 -04009201 shouldFail: true,
9202 expectedError: ":UNEXPECTED_EXTENSION:",
9203 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07009204 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009205 testCases = append(testCases, testCase{
9206 testType: clientTest,
9207 name: "UnknownExtension-Client-TLS13",
9208 config: Config{
9209 MaxVersion: VersionTLS13,
9210 Bugs: ProtocolBugs{
9211 CustomExtension: expectedContents,
9212 },
9213 },
David Benjamin0c40a962016-08-01 12:05:50 -04009214 shouldFail: true,
9215 expectedError: ":UNEXPECTED_EXTENSION:",
9216 expectedLocalError: "remote error: unsupported extension",
9217 })
David Benjamin490469f2016-10-05 22:44:38 -04009218 testCases = append(testCases, testCase{
9219 testType: clientTest,
9220 name: "UnknownUnencryptedExtension-Client-TLS13",
9221 config: Config{
9222 MaxVersion: VersionTLS13,
9223 Bugs: ProtocolBugs{
9224 CustomUnencryptedExtension: expectedContents,
9225 },
9226 },
9227 shouldFail: true,
9228 expectedError: ":UNEXPECTED_EXTENSION:",
9229 // The shim must send an alert, but alerts at this point do not
9230 // get successfully decrypted by the runner.
9231 expectedLocalError: "local error: bad record MAC",
9232 })
9233 testCases = append(testCases, testCase{
9234 testType: clientTest,
9235 name: "UnexpectedUnencryptedExtension-Client-TLS13",
9236 config: Config{
9237 MaxVersion: VersionTLS13,
9238 Bugs: ProtocolBugs{
9239 SendUnencryptedALPN: "foo",
9240 },
9241 },
9242 flags: []string{
9243 "-advertise-alpn", "\x03foo\x03bar",
9244 },
9245 shouldFail: true,
9246 expectedError: ":UNEXPECTED_EXTENSION:",
9247 // The shim must send an alert, but alerts at this point do not
9248 // get successfully decrypted by the runner.
9249 expectedLocalError: "local error: bad record MAC",
9250 })
David Benjamin0c40a962016-08-01 12:05:50 -04009251
9252 // Test a known but unoffered extension from the server.
9253 testCases = append(testCases, testCase{
9254 testType: clientTest,
9255 name: "UnofferedExtension-Client",
9256 config: Config{
9257 MaxVersion: VersionTLS12,
9258 Bugs: ProtocolBugs{
9259 SendALPN: "alpn",
9260 },
9261 },
9262 shouldFail: true,
9263 expectedError: ":UNEXPECTED_EXTENSION:",
9264 expectedLocalError: "remote error: unsupported extension",
9265 })
9266 testCases = append(testCases, testCase{
9267 testType: clientTest,
9268 name: "UnofferedExtension-Client-TLS13",
9269 config: Config{
9270 MaxVersion: VersionTLS13,
9271 Bugs: ProtocolBugs{
9272 SendALPN: "alpn",
9273 },
9274 },
9275 shouldFail: true,
9276 expectedError: ":UNEXPECTED_EXTENSION:",
9277 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04009278 })
Adam Langley09505632015-07-30 18:10:13 -07009279}
9280
David Benjaminb36a3952015-12-01 18:53:13 -05009281func addRSAClientKeyExchangeTests() {
9282 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
9283 testCases = append(testCases, testCase{
9284 testType: serverTest,
9285 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
9286 config: Config{
9287 // Ensure the ClientHello version and final
9288 // version are different, to detect if the
9289 // server uses the wrong one.
9290 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07009291 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05009292 Bugs: ProtocolBugs{
9293 BadRSAClientKeyExchange: bad,
9294 },
9295 },
9296 shouldFail: true,
9297 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9298 })
9299 }
David Benjamine63d9d72016-09-19 18:27:34 -04009300
9301 // The server must compare whatever was in ClientHello.version for the
9302 // RSA premaster.
9303 testCases = append(testCases, testCase{
9304 testType: serverTest,
9305 name: "SendClientVersion-RSA",
9306 config: Config{
9307 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
9308 Bugs: ProtocolBugs{
9309 SendClientVersion: 0x1234,
9310 },
9311 },
9312 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9313 })
David Benjaminb36a3952015-12-01 18:53:13 -05009314}
9315
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009316var testCurves = []struct {
9317 name string
9318 id CurveID
9319}{
Adam Langley764ab982017-03-10 18:01:30 -08009320 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009321 {"P-256", CurveP256},
9322 {"P-384", CurveP384},
9323 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05009324 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009325}
9326
Steven Valdez5440fe02016-07-18 12:40:30 -04009327const bogusCurve = 0x1234
9328
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009329func addCurveTests() {
9330 for _, curve := range testCurves {
9331 testCases = append(testCases, testCase{
9332 name: "CurveTest-Client-" + curve.name,
9333 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009334 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009335 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9336 CurvePreferences: []CurveID{curve.id},
9337 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009338 flags: []string{
9339 "-enable-all-curves",
9340 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9341 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009342 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009343 })
9344 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009345 name: "CurveTest-Client-" + curve.name + "-TLS13",
9346 config: Config{
9347 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009348 CurvePreferences: []CurveID{curve.id},
9349 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009350 flags: []string{
9351 "-enable-all-curves",
9352 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9353 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009354 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009355 })
9356 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009357 testType: serverTest,
9358 name: "CurveTest-Server-" + curve.name,
9359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009360 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009361 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9362 CurvePreferences: []CurveID{curve.id},
9363 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009364 flags: []string{
9365 "-enable-all-curves",
9366 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9367 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009368 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009369 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009370 testCases = append(testCases, testCase{
9371 testType: serverTest,
9372 name: "CurveTest-Server-" + curve.name + "-TLS13",
9373 config: Config{
9374 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009375 CurvePreferences: []CurveID{curve.id},
9376 },
David Benjamin5c4e8572016-08-19 17:44:53 -04009377 flags: []string{
9378 "-enable-all-curves",
9379 "-expect-curve-id", strconv.Itoa(int(curve.id)),
9380 },
Steven Valdez5440fe02016-07-18 12:40:30 -04009381 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04009382 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009383 }
David Benjamin241ae832016-01-15 03:04:54 -05009384
9385 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05009386 testCases = append(testCases, testCase{
9387 testType: serverTest,
9388 name: "UnknownCurve",
9389 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009390 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05009391 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9392 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9393 },
9394 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009395
Steven Valdez803c77a2016-09-06 14:13:43 -04009396 // The server must be tolerant to bogus curves.
9397 testCases = append(testCases, testCase{
9398 testType: serverTest,
9399 name: "UnknownCurve-TLS13",
9400 config: Config{
9401 MaxVersion: VersionTLS13,
9402 CurvePreferences: []CurveID{bogusCurve, CurveP256},
9403 },
9404 })
9405
David Benjamin4c3ddf72016-06-29 18:13:53 -04009406 // The server must not consider ECDHE ciphers when there are no
9407 // supported curves.
9408 testCases = append(testCases, testCase{
9409 testType: serverTest,
9410 name: "NoSupportedCurves",
9411 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009412 MaxVersion: VersionTLS12,
9413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9414 Bugs: ProtocolBugs{
9415 NoSupportedCurves: true,
9416 },
9417 },
9418 shouldFail: true,
9419 expectedError: ":NO_SHARED_CIPHER:",
9420 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009421 testCases = append(testCases, testCase{
9422 testType: serverTest,
9423 name: "NoSupportedCurves-TLS13",
9424 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009425 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009426 Bugs: ProtocolBugs{
9427 NoSupportedCurves: true,
9428 },
9429 },
9430 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04009431 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009432 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009433
9434 // The server must fall back to another cipher when there are no
9435 // supported curves.
9436 testCases = append(testCases, testCase{
9437 testType: serverTest,
9438 name: "NoCommonCurves",
9439 config: Config{
9440 MaxVersion: VersionTLS12,
9441 CipherSuites: []uint16{
9442 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009443 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009444 },
9445 CurvePreferences: []CurveID{CurveP224},
9446 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07009447 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04009448 })
9449
9450 // The client must reject bogus curves and disabled curves.
9451 testCases = append(testCases, testCase{
9452 name: "BadECDHECurve",
9453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009454 MaxVersion: VersionTLS12,
9455 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9456 Bugs: ProtocolBugs{
9457 SendCurve: bogusCurve,
9458 },
9459 },
9460 shouldFail: true,
9461 expectedError: ":WRONG_CURVE:",
9462 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009463 testCases = append(testCases, testCase{
9464 name: "BadECDHECurve-TLS13",
9465 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009466 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009467 Bugs: ProtocolBugs{
9468 SendCurve: bogusCurve,
9469 },
9470 },
9471 shouldFail: true,
9472 expectedError: ":WRONG_CURVE:",
9473 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04009474
9475 testCases = append(testCases, testCase{
9476 name: "UnsupportedCurve",
9477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009478 MaxVersion: VersionTLS12,
9479 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9480 CurvePreferences: []CurveID{CurveP256},
9481 Bugs: ProtocolBugs{
9482 IgnorePeerCurvePreferences: true,
9483 },
9484 },
9485 flags: []string{"-p384-only"},
9486 shouldFail: true,
9487 expectedError: ":WRONG_CURVE:",
9488 })
9489
David Benjamin4f921572016-07-17 14:20:10 +02009490 testCases = append(testCases, testCase{
9491 // TODO(davidben): Add a TLS 1.3 version where
9492 // HelloRetryRequest requests an unsupported curve.
9493 name: "UnsupportedCurve-ServerHello-TLS13",
9494 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04009495 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02009496 CurvePreferences: []CurveID{CurveP384},
9497 Bugs: ProtocolBugs{
9498 SendCurve: CurveP256,
9499 },
9500 },
9501 flags: []string{"-p384-only"},
9502 shouldFail: true,
9503 expectedError: ":WRONG_CURVE:",
9504 })
9505
David Benjamin4c3ddf72016-06-29 18:13:53 -04009506 // Test invalid curve points.
9507 testCases = append(testCases, testCase{
9508 name: "InvalidECDHPoint-Client",
9509 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009510 MaxVersion: VersionTLS12,
9511 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9512 CurvePreferences: []CurveID{CurveP256},
9513 Bugs: ProtocolBugs{
9514 InvalidECDHPoint: true,
9515 },
9516 },
9517 shouldFail: true,
9518 expectedError: ":INVALID_ENCODING:",
9519 })
9520 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009521 name: "InvalidECDHPoint-Client-TLS13",
9522 config: Config{
9523 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009524 CurvePreferences: []CurveID{CurveP256},
9525 Bugs: ProtocolBugs{
9526 InvalidECDHPoint: true,
9527 },
9528 },
9529 shouldFail: true,
9530 expectedError: ":INVALID_ENCODING:",
9531 })
9532 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009533 testType: serverTest,
9534 name: "InvalidECDHPoint-Server",
9535 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04009536 MaxVersion: VersionTLS12,
9537 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9538 CurvePreferences: []CurveID{CurveP256},
9539 Bugs: ProtocolBugs{
9540 InvalidECDHPoint: true,
9541 },
9542 },
9543 shouldFail: true,
9544 expectedError: ":INVALID_ENCODING:",
9545 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009546 testCases = append(testCases, testCase{
9547 testType: serverTest,
9548 name: "InvalidECDHPoint-Server-TLS13",
9549 config: Config{
9550 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04009551 CurvePreferences: []CurveID{CurveP256},
9552 Bugs: ProtocolBugs{
9553 InvalidECDHPoint: true,
9554 },
9555 },
9556 shouldFail: true,
9557 expectedError: ":INVALID_ENCODING:",
9558 })
David Benjamin8a55ce42016-12-11 03:03:42 -05009559
9560 // The previous curve ID should be reported on TLS 1.2 resumption.
9561 testCases = append(testCases, testCase{
9562 name: "CurveID-Resume-Client",
9563 config: Config{
9564 MaxVersion: VersionTLS12,
9565 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9566 CurvePreferences: []CurveID{CurveX25519},
9567 },
9568 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9569 resumeSession: true,
9570 })
9571 testCases = append(testCases, testCase{
9572 testType: serverTest,
9573 name: "CurveID-Resume-Server",
9574 config: Config{
9575 MaxVersion: VersionTLS12,
9576 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9577 CurvePreferences: []CurveID{CurveX25519},
9578 },
9579 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9580 resumeSession: true,
9581 })
9582
9583 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9584 // one should be reported.
9585 testCases = append(testCases, testCase{
9586 name: "CurveID-Resume-Client-TLS13",
9587 config: Config{
9588 MaxVersion: VersionTLS13,
9589 CurvePreferences: []CurveID{CurveX25519},
9590 },
9591 resumeConfig: &Config{
9592 MaxVersion: VersionTLS13,
9593 CurvePreferences: []CurveID{CurveP256},
9594 },
9595 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009596 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9597 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009598 },
9599 resumeSession: true,
9600 })
9601 testCases = append(testCases, testCase{
9602 testType: serverTest,
9603 name: "CurveID-Resume-Server-TLS13",
9604 config: Config{
9605 MaxVersion: VersionTLS13,
9606 CurvePreferences: []CurveID{CurveX25519},
9607 },
9608 resumeConfig: &Config{
9609 MaxVersion: VersionTLS13,
9610 CurvePreferences: []CurveID{CurveP256},
9611 },
9612 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009613 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9614 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009615 },
9616 resumeSession: true,
9617 })
David Benjamina81967b2016-12-22 09:16:57 -05009618
9619 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9620 testCases = append(testCases, testCase{
9621 name: "PointFormat-ServerHello-TLS12",
9622 config: Config{
9623 MaxVersion: VersionTLS12,
9624 Bugs: ProtocolBugs{
9625 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9626 },
9627 },
9628 })
9629 testCases = append(testCases, testCase{
9630 name: "PointFormat-EncryptedExtensions-TLS13",
9631 config: Config{
9632 MaxVersion: VersionTLS13,
9633 Bugs: ProtocolBugs{
9634 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9635 },
9636 },
9637 shouldFail: true,
9638 expectedError: ":ERROR_PARSING_EXTENSION:",
9639 })
9640
9641 // Test that we tolerate unknown point formats, as long as
9642 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9643 // check they are still functional.
9644 testCases = append(testCases, testCase{
9645 name: "PointFormat-Client-Tolerance",
9646 config: Config{
9647 MaxVersion: VersionTLS12,
9648 Bugs: ProtocolBugs{
9649 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9650 },
9651 },
9652 })
9653 testCases = append(testCases, testCase{
9654 testType: serverTest,
9655 name: "PointFormat-Server-Tolerance",
9656 config: Config{
9657 MaxVersion: VersionTLS12,
9658 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9659 Bugs: ProtocolBugs{
9660 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9661 },
9662 },
9663 })
9664
9665 // Test TLS 1.2 does not require the point format extension to be
9666 // present.
9667 testCases = append(testCases, testCase{
9668 name: "PointFormat-Client-Missing",
9669 config: Config{
9670 MaxVersion: VersionTLS12,
9671 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9672 Bugs: ProtocolBugs{
9673 SendSupportedPointFormats: []byte{},
9674 },
9675 },
9676 })
9677 testCases = append(testCases, testCase{
9678 testType: serverTest,
9679 name: "PointFormat-Server-Missing",
9680 config: Config{
9681 MaxVersion: VersionTLS12,
9682 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9683 Bugs: ProtocolBugs{
9684 SendSupportedPointFormats: []byte{},
9685 },
9686 },
9687 })
9688
9689 // If the point format extension is present, uncompressed points must be
9690 // offered. BoringSSL requires this whether or not ECDHE is used.
9691 testCases = append(testCases, testCase{
9692 name: "PointFormat-Client-MissingUncompressed",
9693 config: Config{
9694 MaxVersion: VersionTLS12,
9695 Bugs: ProtocolBugs{
9696 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9697 },
9698 },
9699 shouldFail: true,
9700 expectedError: ":ERROR_PARSING_EXTENSION:",
9701 })
9702 testCases = append(testCases, testCase{
9703 testType: serverTest,
9704 name: "PointFormat-Server-MissingUncompressed",
9705 config: Config{
9706 MaxVersion: VersionTLS12,
9707 Bugs: ProtocolBugs{
9708 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9709 },
9710 },
9711 shouldFail: true,
9712 expectedError: ":ERROR_PARSING_EXTENSION:",
9713 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009714}
9715
David Benjaminc9ae27c2016-06-24 22:56:37 -04009716func addTLS13RecordTests() {
9717 testCases = append(testCases, testCase{
9718 name: "TLS13-RecordPadding",
9719 config: Config{
9720 MaxVersion: VersionTLS13,
9721 MinVersion: VersionTLS13,
9722 Bugs: ProtocolBugs{
9723 RecordPadding: 10,
9724 },
9725 },
9726 })
9727
9728 testCases = append(testCases, testCase{
9729 name: "TLS13-EmptyRecords",
9730 config: Config{
9731 MaxVersion: VersionTLS13,
9732 MinVersion: VersionTLS13,
9733 Bugs: ProtocolBugs{
9734 OmitRecordContents: true,
9735 },
9736 },
9737 shouldFail: true,
9738 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9739 })
9740
9741 testCases = append(testCases, testCase{
9742 name: "TLS13-OnlyPadding",
9743 config: Config{
9744 MaxVersion: VersionTLS13,
9745 MinVersion: VersionTLS13,
9746 Bugs: ProtocolBugs{
9747 OmitRecordContents: true,
9748 RecordPadding: 10,
9749 },
9750 },
9751 shouldFail: true,
9752 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9753 })
9754
9755 testCases = append(testCases, testCase{
9756 name: "TLS13-WrongOuterRecord",
9757 config: Config{
9758 MaxVersion: VersionTLS13,
9759 MinVersion: VersionTLS13,
9760 Bugs: ProtocolBugs{
9761 OuterRecordType: recordTypeHandshake,
9762 },
9763 },
9764 shouldFail: true,
9765 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9766 })
9767}
9768
Steven Valdez5b986082016-09-01 12:29:49 -04009769func addSessionTicketTests() {
9770 testCases = append(testCases, testCase{
9771 // In TLS 1.2 and below, empty NewSessionTicket messages
9772 // mean the server changed its mind on sending a ticket.
9773 name: "SendEmptySessionTicket",
9774 config: Config{
9775 MaxVersion: VersionTLS12,
9776 Bugs: ProtocolBugs{
9777 SendEmptySessionTicket: true,
9778 },
9779 },
9780 flags: []string{"-expect-no-session"},
9781 })
9782
9783 // Test that the server ignores unknown PSK modes.
9784 testCases = append(testCases, testCase{
9785 testType: serverTest,
9786 name: "TLS13-SendUnknownModeSessionTicket-Server",
9787 config: Config{
9788 MaxVersion: VersionTLS13,
9789 Bugs: ProtocolBugs{
9790 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009791 },
9792 },
9793 resumeSession: true,
9794 expectedResumeVersion: VersionTLS13,
9795 })
9796
Steven Valdeza833c352016-11-01 13:39:36 -04009797 // Test that the server does not send session tickets with no matching key exchange mode.
9798 testCases = append(testCases, testCase{
9799 testType: serverTest,
9800 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9801 config: Config{
9802 MaxVersion: VersionTLS13,
9803 Bugs: ProtocolBugs{
9804 SendPSKKeyExchangeModes: []byte{0x1a},
9805 ExpectNoNewSessionTicket: true,
9806 },
9807 },
9808 })
9809
9810 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009811 testCases = append(testCases, testCase{
9812 testType: serverTest,
9813 name: "TLS13-SendBadKEModeSessionTicket-Server",
9814 config: Config{
9815 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009816 },
9817 resumeConfig: &Config{
9818 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009819 Bugs: ProtocolBugs{
9820 SendPSKKeyExchangeModes: []byte{0x1a},
9821 },
9822 },
9823 resumeSession: true,
9824 expectResumeRejected: true,
9825 })
9826
Steven Valdeza833c352016-11-01 13:39:36 -04009827 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009828 testCases = append(testCases, testCase{
9829 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009830 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009831 config: Config{
9832 MaxVersion: VersionTLS13,
9833 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009834 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009835 },
9836 },
Steven Valdeza833c352016-11-01 13:39:36 -04009837 resumeSession: true,
9838 flags: []string{
9839 "-resumption-delay", "10",
9840 },
Steven Valdez5b986082016-09-01 12:29:49 -04009841 })
9842
Steven Valdeza833c352016-11-01 13:39:36 -04009843 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009844 testCases = append(testCases, testCase{
9845 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009846 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009847 config: Config{
9848 MaxVersion: VersionTLS13,
9849 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009850 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009851 },
9852 },
Steven Valdeza833c352016-11-01 13:39:36 -04009853 resumeSession: true,
9854 shouldFail: true,
9855 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009856 })
9857
David Benjamin35ac5b72017-03-03 15:05:56 -05009858 // Test that the server's ticket age skew reporting works.
9859 testCases = append(testCases, testCase{
9860 testType: serverTest,
9861 name: "TLS13-TicketAgeSkew-Forward",
9862 config: Config{
9863 MaxVersion: VersionTLS13,
9864 Bugs: ProtocolBugs{
9865 SendTicketAge: 15 * time.Second,
9866 },
9867 },
David Benjamin065d7332017-03-26 10:51:43 -05009868 resumeSession: true,
9869 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009870 flags: []string{
9871 "-resumption-delay", "10",
9872 "-expect-ticket-age-skew", "5",
9873 },
9874 })
9875 testCases = append(testCases, testCase{
9876 testType: serverTest,
9877 name: "TLS13-TicketAgeSkew-Backward",
9878 config: Config{
9879 MaxVersion: VersionTLS13,
9880 Bugs: ProtocolBugs{
9881 SendTicketAge: 5 * time.Second,
9882 },
9883 },
David Benjamin065d7332017-03-26 10:51:43 -05009884 resumeSession: true,
9885 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009886 flags: []string{
9887 "-resumption-delay", "10",
9888 "-expect-ticket-age-skew", "-5",
9889 },
9890 })
9891
Steven Valdez08b65f42016-12-07 15:29:45 -05009892 testCases = append(testCases, testCase{
9893 testType: clientTest,
9894 name: "TLS13-SendTicketEarlyDataInfo",
9895 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009896 MaxVersion: VersionTLS13,
9897 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009898 },
9899 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009900 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009901 "-expect-early-data-info",
9902 },
9903 })
9904
David Benjamin9b160662017-01-25 19:53:43 -05009905 // Test that 0-RTT tickets are ignored in clients unless opted in.
9906 testCases = append(testCases, testCase{
9907 testType: clientTest,
9908 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9909 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009910 MaxVersion: VersionTLS13,
9911 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009912 },
9913 })
9914
Steven Valdez08b65f42016-12-07 15:29:45 -05009915 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009916 testType: clientTest,
9917 name: "TLS13-DuplicateTicketEarlyDataInfo",
9918 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009919 MaxVersion: VersionTLS13,
9920 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009921 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009922 DuplicateTicketEarlyDataInfo: true,
9923 },
9924 },
9925 shouldFail: true,
9926 expectedError: ":DUPLICATE_EXTENSION:",
9927 expectedLocalError: "remote error: illegal parameter",
9928 })
9929
9930 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009931 testType: serverTest,
9932 name: "TLS13-ExpectTicketEarlyDataInfo",
9933 config: Config{
9934 MaxVersion: VersionTLS13,
9935 Bugs: ProtocolBugs{
9936 ExpectTicketEarlyDataInfo: true,
9937 },
9938 },
9939 flags: []string{
9940 "-enable-early-data",
9941 },
9942 })
David Benjamin17b30832017-01-28 14:00:32 -05009943
9944 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9945 // is honored.
9946 testCases = append(testCases, testCase{
9947 testType: clientTest,
9948 name: "TLS13-HonorServerSessionTicketLifetime",
9949 config: Config{
9950 MaxVersion: VersionTLS13,
9951 Bugs: ProtocolBugs{
9952 SendTicketLifetime: 20 * time.Second,
9953 },
9954 },
9955 flags: []string{
9956 "-resumption-delay", "19",
9957 },
9958 resumeSession: true,
9959 })
9960 testCases = append(testCases, testCase{
9961 testType: clientTest,
9962 name: "TLS13-HonorServerSessionTicketLifetime-2",
9963 config: Config{
9964 MaxVersion: VersionTLS13,
9965 Bugs: ProtocolBugs{
9966 SendTicketLifetime: 20 * time.Second,
9967 // The client should not offer the expired session.
9968 ExpectNoTLS13PSK: true,
9969 },
9970 },
9971 flags: []string{
9972 "-resumption-delay", "21",
9973 },
David Benjamin023d4192017-02-06 13:49:07 -05009974 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009975 expectResumeRejected: true,
9976 })
Steven Valdez5b986082016-09-01 12:29:49 -04009977}
9978
David Benjamin82261be2016-07-07 14:32:50 -07009979func addChangeCipherSpecTests() {
9980 // Test missing ChangeCipherSpecs.
9981 testCases = append(testCases, testCase{
9982 name: "SkipChangeCipherSpec-Client",
9983 config: Config{
9984 MaxVersion: VersionTLS12,
9985 Bugs: ProtocolBugs{
9986 SkipChangeCipherSpec: true,
9987 },
9988 },
9989 shouldFail: true,
9990 expectedError: ":UNEXPECTED_RECORD:",
9991 })
9992 testCases = append(testCases, testCase{
9993 testType: serverTest,
9994 name: "SkipChangeCipherSpec-Server",
9995 config: Config{
9996 MaxVersion: VersionTLS12,
9997 Bugs: ProtocolBugs{
9998 SkipChangeCipherSpec: true,
9999 },
10000 },
10001 shouldFail: true,
10002 expectedError: ":UNEXPECTED_RECORD:",
10003 })
10004 testCases = append(testCases, testCase{
10005 testType: serverTest,
10006 name: "SkipChangeCipherSpec-Server-NPN",
10007 config: Config{
10008 MaxVersion: VersionTLS12,
10009 NextProtos: []string{"bar"},
10010 Bugs: ProtocolBugs{
10011 SkipChangeCipherSpec: true,
10012 },
10013 },
10014 flags: []string{
10015 "-advertise-npn", "\x03foo\x03bar\x03baz",
10016 },
10017 shouldFail: true,
10018 expectedError: ":UNEXPECTED_RECORD:",
10019 })
10020
10021 // Test synchronization between the handshake and ChangeCipherSpec.
10022 // Partial post-CCS handshake messages before ChangeCipherSpec should be
10023 // rejected. Test both with and without handshake packing to handle both
10024 // when the partial post-CCS message is in its own record and when it is
10025 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -070010026 for _, packed := range []bool{false, true} {
10027 var suffix string
10028 if packed {
10029 suffix = "-Packed"
10030 }
10031
10032 testCases = append(testCases, testCase{
10033 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
10034 config: Config{
10035 MaxVersion: VersionTLS12,
10036 Bugs: ProtocolBugs{
10037 FragmentAcrossChangeCipherSpec: true,
10038 PackHandshakeFlight: packed,
10039 },
10040 },
10041 shouldFail: true,
10042 expectedError: ":UNEXPECTED_RECORD:",
10043 })
10044 testCases = append(testCases, testCase{
10045 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
10046 config: Config{
10047 MaxVersion: VersionTLS12,
10048 },
10049 resumeSession: true,
10050 resumeConfig: &Config{
10051 MaxVersion: VersionTLS12,
10052 Bugs: ProtocolBugs{
10053 FragmentAcrossChangeCipherSpec: true,
10054 PackHandshakeFlight: packed,
10055 },
10056 },
10057 shouldFail: true,
10058 expectedError: ":UNEXPECTED_RECORD:",
10059 })
10060 testCases = append(testCases, testCase{
10061 testType: serverTest,
10062 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
10063 config: Config{
10064 MaxVersion: VersionTLS12,
10065 Bugs: ProtocolBugs{
10066 FragmentAcrossChangeCipherSpec: true,
10067 PackHandshakeFlight: packed,
10068 },
10069 },
10070 shouldFail: true,
10071 expectedError: ":UNEXPECTED_RECORD:",
10072 })
10073 testCases = append(testCases, testCase{
10074 testType: serverTest,
10075 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
10076 config: Config{
10077 MaxVersion: VersionTLS12,
10078 },
10079 resumeSession: true,
10080 resumeConfig: &Config{
10081 MaxVersion: VersionTLS12,
10082 Bugs: ProtocolBugs{
10083 FragmentAcrossChangeCipherSpec: true,
10084 PackHandshakeFlight: packed,
10085 },
10086 },
10087 shouldFail: true,
10088 expectedError: ":UNEXPECTED_RECORD:",
10089 })
10090 testCases = append(testCases, testCase{
10091 testType: serverTest,
10092 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
10093 config: Config{
10094 MaxVersion: VersionTLS12,
10095 NextProtos: []string{"bar"},
10096 Bugs: ProtocolBugs{
10097 FragmentAcrossChangeCipherSpec: true,
10098 PackHandshakeFlight: packed,
10099 },
10100 },
10101 flags: []string{
10102 "-advertise-npn", "\x03foo\x03bar\x03baz",
10103 },
10104 shouldFail: true,
10105 expectedError: ":UNEXPECTED_RECORD:",
10106 })
10107 }
10108
David Benjamin61672812016-07-14 23:10:43 -040010109 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
10110 // messages in the handshake queue. Do this by testing the server
10111 // reading the client Finished, reversing the flight so Finished comes
10112 // first.
10113 testCases = append(testCases, testCase{
10114 protocol: dtls,
10115 testType: serverTest,
10116 name: "SendUnencryptedFinished-DTLS",
10117 config: Config{
10118 MaxVersion: VersionTLS12,
10119 Bugs: ProtocolBugs{
10120 SendUnencryptedFinished: true,
10121 ReverseHandshakeFragments: true,
10122 },
10123 },
10124 shouldFail: true,
10125 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10126 })
10127
Steven Valdez143e8b32016-07-11 13:19:03 -040010128 // Test synchronization between encryption changes and the handshake in
10129 // TLS 1.3, where ChangeCipherSpec is implicit.
10130 testCases = append(testCases, testCase{
10131 name: "PartialEncryptedExtensionsWithServerHello",
10132 config: Config{
10133 MaxVersion: VersionTLS13,
10134 Bugs: ProtocolBugs{
10135 PartialEncryptedExtensionsWithServerHello: true,
10136 },
10137 },
10138 shouldFail: true,
10139 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10140 })
10141 testCases = append(testCases, testCase{
10142 testType: serverTest,
10143 name: "PartialClientFinishedWithClientHello",
10144 config: Config{
10145 MaxVersion: VersionTLS13,
10146 Bugs: ProtocolBugs{
10147 PartialClientFinishedWithClientHello: true,
10148 },
10149 },
10150 shouldFail: true,
10151 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
10152 })
10153
David Benjamin82261be2016-07-07 14:32:50 -070010154 // Test that early ChangeCipherSpecs are handled correctly.
10155 testCases = append(testCases, testCase{
10156 testType: serverTest,
10157 name: "EarlyChangeCipherSpec-server-1",
10158 config: Config{
10159 MaxVersion: VersionTLS12,
10160 Bugs: ProtocolBugs{
10161 EarlyChangeCipherSpec: 1,
10162 },
10163 },
10164 shouldFail: true,
10165 expectedError: ":UNEXPECTED_RECORD:",
10166 })
10167 testCases = append(testCases, testCase{
10168 testType: serverTest,
10169 name: "EarlyChangeCipherSpec-server-2",
10170 config: Config{
10171 MaxVersion: VersionTLS12,
10172 Bugs: ProtocolBugs{
10173 EarlyChangeCipherSpec: 2,
10174 },
10175 },
10176 shouldFail: true,
10177 expectedError: ":UNEXPECTED_RECORD:",
10178 })
10179 testCases = append(testCases, testCase{
10180 protocol: dtls,
10181 name: "StrayChangeCipherSpec",
10182 config: Config{
10183 // TODO(davidben): Once DTLS 1.3 exists, test
10184 // that stray ChangeCipherSpec messages are
10185 // rejected.
10186 MaxVersion: VersionTLS12,
10187 Bugs: ProtocolBugs{
10188 StrayChangeCipherSpec: true,
10189 },
10190 },
10191 })
10192
David Benjaminb0c761e2017-06-25 22:42:55 -040010193 // Test that reordered ChangeCipherSpecs are tolerated.
10194 testCases = append(testCases, testCase{
10195 protocol: dtls,
10196 name: "ReorderChangeCipherSpec-DTLS-Client",
10197 config: Config{
10198 MaxVersion: VersionTLS12,
10199 Bugs: ProtocolBugs{
10200 ReorderChangeCipherSpec: true,
10201 },
10202 },
10203 resumeSession: true,
10204 })
10205 testCases = append(testCases, testCase{
10206 testType: serverTest,
10207 protocol: dtls,
10208 name: "ReorderChangeCipherSpec-DTLS-Server",
10209 config: Config{
10210 MaxVersion: VersionTLS12,
10211 Bugs: ProtocolBugs{
10212 ReorderChangeCipherSpec: true,
10213 },
10214 },
10215 resumeSession: true,
10216 })
10217
David Benjamin82261be2016-07-07 14:32:50 -070010218 // Test that the contents of ChangeCipherSpec are checked.
10219 testCases = append(testCases, testCase{
10220 name: "BadChangeCipherSpec-1",
10221 config: Config{
10222 MaxVersion: VersionTLS12,
10223 Bugs: ProtocolBugs{
10224 BadChangeCipherSpec: []byte{2},
10225 },
10226 },
10227 shouldFail: true,
10228 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10229 })
10230 testCases = append(testCases, testCase{
10231 name: "BadChangeCipherSpec-2",
10232 config: Config{
10233 MaxVersion: VersionTLS12,
10234 Bugs: ProtocolBugs{
10235 BadChangeCipherSpec: []byte{1, 1},
10236 },
10237 },
10238 shouldFail: true,
10239 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10240 })
10241 testCases = append(testCases, testCase{
10242 protocol: dtls,
10243 name: "BadChangeCipherSpec-DTLS-1",
10244 config: Config{
10245 MaxVersion: VersionTLS12,
10246 Bugs: ProtocolBugs{
10247 BadChangeCipherSpec: []byte{2},
10248 },
10249 },
10250 shouldFail: true,
10251 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10252 })
10253 testCases = append(testCases, testCase{
10254 protocol: dtls,
10255 name: "BadChangeCipherSpec-DTLS-2",
10256 config: Config{
10257 MaxVersion: VersionTLS12,
10258 Bugs: ProtocolBugs{
10259 BadChangeCipherSpec: []byte{1, 1},
10260 },
10261 },
10262 shouldFail: true,
10263 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
10264 })
10265}
10266
David Benjamincd2c8062016-09-09 11:28:16 -040010267type perMessageTest struct {
10268 messageType uint8
10269 test testCase
10270}
10271
10272// makePerMessageTests returns a series of test templates which cover each
10273// message in the TLS handshake. These may be used with bugs like
10274// WrongMessageType to fully test a per-message bug.
10275func makePerMessageTests() []perMessageTest {
10276 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -040010277 for _, protocol := range []protocol{tls, dtls} {
10278 var suffix string
10279 if protocol == dtls {
10280 suffix = "-DTLS"
10281 }
10282
David Benjamincd2c8062016-09-09 11:28:16 -040010283 ret = append(ret, perMessageTest{
10284 messageType: typeClientHello,
10285 test: testCase{
10286 protocol: protocol,
10287 testType: serverTest,
10288 name: "ClientHello" + suffix,
10289 config: Config{
10290 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010291 },
10292 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010293 })
10294
10295 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010296 ret = append(ret, perMessageTest{
10297 messageType: typeHelloVerifyRequest,
10298 test: testCase{
10299 protocol: protocol,
10300 name: "HelloVerifyRequest" + suffix,
10301 config: Config{
10302 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010303 },
10304 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010305 })
10306 }
10307
David Benjamincd2c8062016-09-09 11:28:16 -040010308 ret = append(ret, perMessageTest{
10309 messageType: typeServerHello,
10310 test: testCase{
10311 protocol: protocol,
10312 name: "ServerHello" + suffix,
10313 config: Config{
10314 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010315 },
10316 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010317 })
10318
David Benjamincd2c8062016-09-09 11:28:16 -040010319 ret = append(ret, perMessageTest{
10320 messageType: typeCertificate,
10321 test: testCase{
10322 protocol: protocol,
10323 name: "ServerCertificate" + suffix,
10324 config: Config{
10325 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010326 },
10327 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010328 })
10329
David Benjamincd2c8062016-09-09 11:28:16 -040010330 ret = append(ret, perMessageTest{
10331 messageType: typeCertificateStatus,
10332 test: testCase{
10333 protocol: protocol,
10334 name: "CertificateStatus" + suffix,
10335 config: Config{
10336 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010337 },
David Benjamincd2c8062016-09-09 11:28:16 -040010338 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010339 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010340 })
10341
David Benjamincd2c8062016-09-09 11:28:16 -040010342 ret = append(ret, perMessageTest{
10343 messageType: typeServerKeyExchange,
10344 test: testCase{
10345 protocol: protocol,
10346 name: "ServerKeyExchange" + suffix,
10347 config: Config{
10348 MaxVersion: VersionTLS12,
10349 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010350 },
10351 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010352 })
10353
David Benjamincd2c8062016-09-09 11:28:16 -040010354 ret = append(ret, perMessageTest{
10355 messageType: typeCertificateRequest,
10356 test: testCase{
10357 protocol: protocol,
10358 name: "CertificateRequest" + suffix,
10359 config: Config{
10360 MaxVersion: VersionTLS12,
10361 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010362 },
10363 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010364 })
10365
David Benjamincd2c8062016-09-09 11:28:16 -040010366 ret = append(ret, perMessageTest{
10367 messageType: typeServerHelloDone,
10368 test: testCase{
10369 protocol: protocol,
10370 name: "ServerHelloDone" + suffix,
10371 config: Config{
10372 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010373 },
10374 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010375 })
10376
David Benjamincd2c8062016-09-09 11:28:16 -040010377 ret = append(ret, perMessageTest{
10378 messageType: typeCertificate,
10379 test: testCase{
10380 testType: serverTest,
10381 protocol: protocol,
10382 name: "ClientCertificate" + suffix,
10383 config: Config{
10384 Certificates: []Certificate{rsaCertificate},
10385 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010386 },
David Benjamincd2c8062016-09-09 11:28:16 -040010387 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010388 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010389 })
10390
David Benjamincd2c8062016-09-09 11:28:16 -040010391 ret = append(ret, perMessageTest{
10392 messageType: typeCertificateVerify,
10393 test: testCase{
10394 testType: serverTest,
10395 protocol: protocol,
10396 name: "CertificateVerify" + suffix,
10397 config: Config{
10398 Certificates: []Certificate{rsaCertificate},
10399 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010400 },
David Benjamincd2c8062016-09-09 11:28:16 -040010401 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010402 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010403 })
10404
David Benjamincd2c8062016-09-09 11:28:16 -040010405 ret = append(ret, perMessageTest{
10406 messageType: typeClientKeyExchange,
10407 test: testCase{
10408 testType: serverTest,
10409 protocol: protocol,
10410 name: "ClientKeyExchange" + suffix,
10411 config: Config{
10412 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010413 },
10414 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010415 })
10416
10417 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -040010418 ret = append(ret, perMessageTest{
10419 messageType: typeNextProtocol,
10420 test: testCase{
10421 testType: serverTest,
10422 protocol: protocol,
10423 name: "NextProtocol" + suffix,
10424 config: Config{
10425 MaxVersion: VersionTLS12,
10426 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010427 },
David Benjamincd2c8062016-09-09 11:28:16 -040010428 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -040010429 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010430 })
10431
David Benjamincd2c8062016-09-09 11:28:16 -040010432 ret = append(ret, perMessageTest{
10433 messageType: typeChannelID,
10434 test: testCase{
10435 testType: serverTest,
10436 protocol: protocol,
10437 name: "ChannelID" + suffix,
10438 config: Config{
10439 MaxVersion: VersionTLS12,
10440 ChannelID: channelIDKey,
10441 },
10442 flags: []string{
10443 "-expect-channel-id",
10444 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -040010445 },
10446 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010447 })
10448 }
10449
David Benjamincd2c8062016-09-09 11:28:16 -040010450 ret = append(ret, perMessageTest{
10451 messageType: typeFinished,
10452 test: testCase{
10453 testType: serverTest,
10454 protocol: protocol,
10455 name: "ClientFinished" + suffix,
10456 config: Config{
10457 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010458 },
10459 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010460 })
10461
David Benjamincd2c8062016-09-09 11:28:16 -040010462 ret = append(ret, perMessageTest{
10463 messageType: typeNewSessionTicket,
10464 test: testCase{
10465 protocol: protocol,
10466 name: "NewSessionTicket" + suffix,
10467 config: Config{
10468 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010469 },
10470 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010471 })
10472
David Benjamincd2c8062016-09-09 11:28:16 -040010473 ret = append(ret, perMessageTest{
10474 messageType: typeFinished,
10475 test: testCase{
10476 protocol: protocol,
10477 name: "ServerFinished" + suffix,
10478 config: Config{
10479 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -040010480 },
10481 },
David Benjamin0b8d5da2016-07-15 00:39:56 -040010482 })
10483
10484 }
David Benjamincd2c8062016-09-09 11:28:16 -040010485
10486 ret = append(ret, perMessageTest{
10487 messageType: typeClientHello,
10488 test: testCase{
10489 testType: serverTest,
10490 name: "TLS13-ClientHello",
10491 config: Config{
10492 MaxVersion: VersionTLS13,
10493 },
10494 },
10495 })
10496
10497 ret = append(ret, perMessageTest{
10498 messageType: typeServerHello,
10499 test: testCase{
10500 name: "TLS13-ServerHello",
10501 config: Config{
10502 MaxVersion: VersionTLS13,
10503 },
10504 },
10505 })
10506
10507 ret = append(ret, perMessageTest{
10508 messageType: typeEncryptedExtensions,
10509 test: testCase{
10510 name: "TLS13-EncryptedExtensions",
10511 config: Config{
10512 MaxVersion: VersionTLS13,
10513 },
10514 },
10515 })
10516
10517 ret = append(ret, perMessageTest{
10518 messageType: typeCertificateRequest,
10519 test: testCase{
10520 name: "TLS13-CertificateRequest",
10521 config: Config{
10522 MaxVersion: VersionTLS13,
10523 ClientAuth: RequireAnyClientCert,
10524 },
10525 },
10526 })
10527
10528 ret = append(ret, perMessageTest{
10529 messageType: typeCertificate,
10530 test: testCase{
10531 name: "TLS13-ServerCertificate",
10532 config: Config{
10533 MaxVersion: VersionTLS13,
10534 },
10535 },
10536 })
10537
10538 ret = append(ret, perMessageTest{
10539 messageType: typeCertificateVerify,
10540 test: testCase{
10541 name: "TLS13-ServerCertificateVerify",
10542 config: Config{
10543 MaxVersion: VersionTLS13,
10544 },
10545 },
10546 })
10547
10548 ret = append(ret, perMessageTest{
10549 messageType: typeFinished,
10550 test: testCase{
10551 name: "TLS13-ServerFinished",
10552 config: Config{
10553 MaxVersion: VersionTLS13,
10554 },
10555 },
10556 })
10557
10558 ret = append(ret, perMessageTest{
10559 messageType: typeCertificate,
10560 test: testCase{
10561 testType: serverTest,
10562 name: "TLS13-ClientCertificate",
10563 config: Config{
10564 Certificates: []Certificate{rsaCertificate},
10565 MaxVersion: VersionTLS13,
10566 },
10567 flags: []string{"-require-any-client-certificate"},
10568 },
10569 })
10570
10571 ret = append(ret, perMessageTest{
10572 messageType: typeCertificateVerify,
10573 test: testCase{
10574 testType: serverTest,
10575 name: "TLS13-ClientCertificateVerify",
10576 config: Config{
10577 Certificates: []Certificate{rsaCertificate},
10578 MaxVersion: VersionTLS13,
10579 },
10580 flags: []string{"-require-any-client-certificate"},
10581 },
10582 })
10583
10584 ret = append(ret, perMessageTest{
10585 messageType: typeFinished,
10586 test: testCase{
10587 testType: serverTest,
10588 name: "TLS13-ClientFinished",
10589 config: Config{
10590 MaxVersion: VersionTLS13,
10591 },
10592 },
10593 })
10594
10595 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010596}
10597
David Benjamincd2c8062016-09-09 11:28:16 -040010598func addWrongMessageTypeTests() {
10599 for _, t := range makePerMessageTests() {
10600 t.test.name = "WrongMessageType-" + t.test.name
10601 t.test.config.Bugs.SendWrongMessageType = t.messageType
10602 t.test.shouldFail = true
10603 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10604 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010605
David Benjamincd2c8062016-09-09 11:28:16 -040010606 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10607 // In TLS 1.3, a bad ServerHello means the client sends
10608 // an unencrypted alert while the server expects
10609 // encryption, so the alert is not readable by runner.
10610 t.test.expectedLocalError = "local error: bad record MAC"
10611 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010612
David Benjamincd2c8062016-09-09 11:28:16 -040010613 testCases = append(testCases, t.test)
10614 }
David Benjaminebacdee2017-04-08 11:00:45 -040010615
10616 // The processing order for TLS 1.3 version negotiation is such that one
10617 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10618 // TLS 1.2. Test that we do not do this.
10619 testCases = append(testCases, testCase{
10620 name: "SendServerHelloAsHelloRetryRequest",
10621 config: Config{
10622 MaxVersion: VersionTLS12,
10623 Bugs: ProtocolBugs{
10624 SendServerHelloAsHelloRetryRequest: true,
10625 },
10626 },
10627 shouldFail: true,
10628 expectedError: ":UNEXPECTED_MESSAGE:",
10629 expectedLocalError: "remote error: unexpected message",
10630 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010631}
10632
David Benjamin639846e2016-09-09 11:41:18 -040010633func addTrailingMessageDataTests() {
10634 for _, t := range makePerMessageTests() {
10635 t.test.name = "TrailingMessageData-" + t.test.name
10636 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10637 t.test.shouldFail = true
10638 t.test.expectedError = ":DECODE_ERROR:"
10639 t.test.expectedLocalError = "remote error: error decoding message"
10640
10641 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10642 // In TLS 1.3, a bad ServerHello means the client sends
10643 // an unencrypted alert while the server expects
10644 // encryption, so the alert is not readable by runner.
10645 t.test.expectedLocalError = "local error: bad record MAC"
10646 }
10647
10648 if t.messageType == typeFinished {
10649 // Bad Finished messages read as the verify data having
10650 // the wrong length.
10651 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10652 t.test.expectedLocalError = "remote error: error decrypting message"
10653 }
10654
10655 testCases = append(testCases, t.test)
10656 }
10657}
10658
Steven Valdez143e8b32016-07-11 13:19:03 -040010659func addTLS13HandshakeTests() {
10660 testCases = append(testCases, testCase{
10661 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010662 name: "NegotiatePSKResumption-TLS13",
10663 config: Config{
10664 MaxVersion: VersionTLS13,
10665 Bugs: ProtocolBugs{
10666 NegotiatePSKResumption: true,
10667 },
10668 },
10669 resumeSession: true,
10670 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010671 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010672 })
10673
10674 testCases = append(testCases, testCase{
10675 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010676 name: "MissingKeyShare-Client",
10677 config: Config{
10678 MaxVersion: VersionTLS13,
10679 Bugs: ProtocolBugs{
10680 MissingKeyShare: true,
10681 },
10682 },
10683 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010684 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010685 })
10686
10687 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010688 testType: serverTest,
10689 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010690 config: Config{
10691 MaxVersion: VersionTLS13,
10692 Bugs: ProtocolBugs{
10693 MissingKeyShare: true,
10694 },
10695 },
10696 shouldFail: true,
10697 expectedError: ":MISSING_KEY_SHARE:",
10698 })
10699
10700 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010701 testType: serverTest,
10702 name: "DuplicateKeyShares",
10703 config: Config{
10704 MaxVersion: VersionTLS13,
10705 Bugs: ProtocolBugs{
10706 DuplicateKeyShares: true,
10707 },
10708 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010709 shouldFail: true,
10710 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010711 })
10712
Steven Valdezc7d4d212017-09-11 13:53:08 -040010713 for _, version := range allVersions(tls) {
10714 if version.version != VersionTLS13 {
10715 continue
10716 }
10717 name := version.name
10718 variant := version.tls13Variant
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010719
Steven Valdezc7d4d212017-09-11 13:53:08 -040010720 testCases = append(testCases, testCase{
10721 testType: serverTest,
10722 name: "SkipEarlyData-" + name,
10723 config: Config{
10724 MaxVersion: VersionTLS13,
10725 Bugs: ProtocolBugs{
10726 SendFakeEarlyDataLength: 4,
10727 },
Steven Valdez520e1222017-06-13 12:45:25 -040010728 },
Steven Valdezc7d4d212017-09-11 13:53:08 -040010729 tls13Variant: variant,
10730 })
Steven Valdez520e1222017-06-13 12:45:25 -040010731
Steven Valdezc7d4d212017-09-11 13:53:08 -040010732 // Test that enabling a TLS 1.3 variant does not interfere with
10733 // TLS 1.2 session ID resumption.
10734 testCases = append(testCases, testCase{
10735 testType: clientTest,
10736 name: "ResumeTLS12SessionID-" + name,
10737 config: Config{
10738 MaxVersion: VersionTLS12,
10739 SessionTicketsDisabled: true,
Steven Valdezdbe01582017-07-14 10:39:28 -040010740 },
Steven Valdezc7d4d212017-09-11 13:53:08 -040010741 tls13Variant: variant,
10742 resumeSession: true,
10743 })
10744
10745 // Test that the server correctly echoes back session IDs of
10746 // various lengths.
10747 testCases = append(testCases, testCase{
10748 testType: serverTest,
10749 name: "EmptySessionID-" + name,
10750 config: Config{
10751 MaxVersion: VersionTLS13,
10752 Bugs: ProtocolBugs{
10753 SendClientHelloSessionID: []byte{},
10754 },
10755 },
10756 tls13Variant: variant,
10757 })
10758
10759 testCases = append(testCases, testCase{
10760 testType: serverTest,
10761 name: "ShortSessionID-" + name,
10762 config: Config{
10763 MaxVersion: VersionTLS13,
10764 Bugs: ProtocolBugs{
10765 SendClientHelloSessionID: make([]byte, 16),
10766 },
10767 },
10768 tls13Variant: variant,
10769 })
10770
10771 testCases = append(testCases, testCase{
10772 testType: serverTest,
10773 name: "FullSessionID-" + name,
10774 config: Config{
10775 MaxVersion: VersionTLS13,
10776 Bugs: ProtocolBugs{
10777 SendClientHelloSessionID: make([]byte, 32),
10778 },
10779 },
10780 tls13Variant: variant,
10781 })
10782
10783 hasSessionID := false
10784 hasEmptySessionID := false
10785 if variant == TLS13NoSessionIDExperiment {
10786 hasEmptySessionID = true
10787 } else if variant != TLS13Default && variant != TLS13RecordTypeExperiment {
10788 hasSessionID = true
10789 }
10790
10791 // Test that the client sends a fake session ID in the correct experiments.
10792 testCases = append(testCases, testCase{
10793 testType: clientTest,
10794 name: "TLS13SessionID-" + name,
10795 config: Config{
10796 MaxVersion: VersionTLS13,
10797 Bugs: ProtocolBugs{
10798 ExpectClientHelloSessionID: hasSessionID,
10799 ExpectEmptyClientHelloSessionID: hasEmptySessionID,
10800 },
10801 },
10802 tls13Variant: variant,
10803 })
10804
10805 testCases = append(testCases, testCase{
10806 testType: clientTest,
10807 name: "EarlyData-Client-" + name,
10808 config: Config{
10809 MaxVersion: VersionTLS13,
10810 MinVersion: VersionTLS13,
10811 MaxEarlyDataSize: 16384,
10812 },
10813 resumeConfig: &Config{
10814 MaxVersion: VersionTLS13,
10815 MinVersion: VersionTLS13,
10816 MaxEarlyDataSize: 16384,
10817 Bugs: ProtocolBugs{
10818 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
10819 },
10820 },
10821 tls13Variant: variant,
10822 resumeSession: true,
10823 flags: []string{
10824 "-enable-early-data",
10825 "-expect-early-data-info",
10826 "-expect-accept-early-data",
10827 "-on-resume-shim-writes-first",
10828 },
10829 })
10830
10831 testCases = append(testCases, testCase{
10832 testType: clientTest,
10833 name: "EarlyData-Reject-Client-" + name,
10834 config: Config{
10835 MaxVersion: VersionTLS13,
10836 MaxEarlyDataSize: 16384,
10837 },
10838 resumeConfig: &Config{
10839 MaxVersion: VersionTLS13,
10840 MaxEarlyDataSize: 16384,
10841 Bugs: ProtocolBugs{
10842 AlwaysRejectEarlyData: true,
10843 },
10844 },
10845 tls13Variant: variant,
10846 resumeSession: true,
10847 flags: []string{
10848 "-enable-early-data",
10849 "-expect-early-data-info",
10850 "-expect-reject-early-data",
10851 "-on-resume-shim-writes-first",
10852 },
10853 })
10854
10855 testCases = append(testCases, testCase{
10856 testType: serverTest,
10857 name: "EarlyData-Server-" + name,
10858 config: Config{
10859 MaxVersion: VersionTLS13,
10860 MinVersion: VersionTLS13,
10861 Bugs: ProtocolBugs{
10862 SendEarlyData: [][]byte{{1, 2, 3, 4}},
10863 ExpectEarlyDataAccepted: true,
10864 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
10865 },
10866 },
10867 tls13Variant: variant,
10868 messageCount: 2,
10869 resumeSession: true,
10870 flags: []string{
10871 "-enable-early-data",
10872 "-expect-accept-early-data",
10873 },
10874 })
10875
10876 }
Steven Valdezdbe01582017-07-14 10:39:28 -040010877
10878 testCases = append(testCases, testCase{
10879 testType: serverTest,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010880 name: "SkipEarlyData-OmitEarlyDataExtension",
10881 config: Config{
10882 MaxVersion: VersionTLS13,
10883 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010884 SendFakeEarlyDataLength: 4,
10885 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010886 },
10887 },
10888 shouldFail: true,
10889 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10890 })
10891
10892 testCases = append(testCases, testCase{
10893 testType: serverTest,
10894 name: "SkipEarlyData-TooMuchData",
10895 config: Config{
10896 MaxVersion: VersionTLS13,
10897 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010898 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010899 },
10900 },
10901 shouldFail: true,
10902 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10903 })
10904
10905 testCases = append(testCases, testCase{
10906 testType: serverTest,
10907 name: "SkipEarlyData-Interleaved",
10908 config: Config{
10909 MaxVersion: VersionTLS13,
10910 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010911 SendFakeEarlyDataLength: 4,
10912 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010913 },
10914 },
10915 shouldFail: true,
10916 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10917 })
10918
10919 testCases = append(testCases, testCase{
10920 testType: serverTest,
10921 name: "SkipEarlyData-EarlyDataInTLS12",
10922 config: Config{
10923 MaxVersion: VersionTLS13,
10924 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010925 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010926 },
10927 },
10928 shouldFail: true,
10929 expectedError: ":UNEXPECTED_RECORD:",
10930 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10931 })
10932
10933 testCases = append(testCases, testCase{
10934 testType: serverTest,
10935 name: "SkipEarlyData-HRR",
10936 config: Config{
10937 MaxVersion: VersionTLS13,
10938 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010939 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010940 },
10941 DefaultCurves: []CurveID{},
10942 },
10943 })
10944
10945 testCases = append(testCases, testCase{
10946 testType: serverTest,
10947 name: "SkipEarlyData-HRR-Interleaved",
10948 config: Config{
10949 MaxVersion: VersionTLS13,
10950 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010951 SendFakeEarlyDataLength: 4,
10952 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010953 },
10954 DefaultCurves: []CurveID{},
10955 },
10956 shouldFail: true,
10957 expectedError: ":UNEXPECTED_RECORD:",
10958 })
10959
10960 testCases = append(testCases, testCase{
10961 testType: serverTest,
10962 name: "SkipEarlyData-HRR-TooMuchData",
10963 config: Config{
10964 MaxVersion: VersionTLS13,
10965 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010966 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010967 },
10968 DefaultCurves: []CurveID{},
10969 },
10970 shouldFail: true,
10971 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10972 })
10973
10974 // Test that skipping early data looking for cleartext correctly
10975 // processes an alert record.
10976 testCases = append(testCases, testCase{
10977 testType: serverTest,
10978 name: "SkipEarlyData-HRR-FatalAlert",
10979 config: Config{
10980 MaxVersion: VersionTLS13,
10981 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010982 SendEarlyAlert: true,
10983 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010984 },
10985 DefaultCurves: []CurveID{},
10986 },
10987 shouldFail: true,
10988 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10989 })
10990
10991 testCases = append(testCases, testCase{
10992 testType: serverTest,
10993 name: "SkipEarlyData-SecondClientHelloEarlyData",
10994 config: Config{
10995 MaxVersion: VersionTLS13,
10996 Bugs: ProtocolBugs{
10997 SendEarlyDataOnSecondClientHello: true,
10998 },
10999 DefaultCurves: []CurveID{},
11000 },
11001 shouldFail: true,
11002 expectedLocalError: "remote error: bad record MAC",
11003 })
11004
11005 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040011006 testType: clientTest,
11007 name: "EmptyEncryptedExtensions",
11008 config: Config{
11009 MaxVersion: VersionTLS13,
11010 Bugs: ProtocolBugs{
11011 EmptyEncryptedExtensions: true,
11012 },
11013 },
11014 shouldFail: true,
11015 expectedLocalError: "remote error: error decoding message",
11016 })
11017
11018 testCases = append(testCases, testCase{
11019 testType: clientTest,
11020 name: "EncryptedExtensionsWithKeyShare",
11021 config: Config{
11022 MaxVersion: VersionTLS13,
11023 Bugs: ProtocolBugs{
11024 EncryptedExtensionsWithKeyShare: true,
11025 },
11026 },
11027 shouldFail: true,
11028 expectedLocalError: "remote error: unsupported extension",
11029 })
Steven Valdez5440fe02016-07-18 12:40:30 -040011030
11031 testCases = append(testCases, testCase{
11032 testType: serverTest,
11033 name: "SendHelloRetryRequest",
11034 config: Config{
11035 MaxVersion: VersionTLS13,
11036 // Require a HelloRetryRequest for every curve.
11037 DefaultCurves: []CurveID{},
11038 },
11039 expectedCurveID: CurveX25519,
11040 })
11041
11042 testCases = append(testCases, testCase{
11043 testType: serverTest,
11044 name: "SendHelloRetryRequest-2",
11045 config: Config{
11046 MaxVersion: VersionTLS13,
11047 DefaultCurves: []CurveID{CurveP384},
11048 },
11049 // Although the ClientHello did not predict our preferred curve,
11050 // we always select it whether it is predicted or not.
11051 expectedCurveID: CurveX25519,
11052 })
11053
11054 testCases = append(testCases, testCase{
11055 name: "UnknownCurve-HelloRetryRequest",
11056 config: Config{
11057 MaxVersion: VersionTLS13,
11058 // P-384 requires HelloRetryRequest in BoringSSL.
11059 CurvePreferences: []CurveID{CurveP384},
11060 Bugs: ProtocolBugs{
11061 SendHelloRetryRequestCurve: bogusCurve,
11062 },
11063 },
11064 shouldFail: true,
11065 expectedError: ":WRONG_CURVE:",
11066 })
11067
11068 testCases = append(testCases, testCase{
11069 name: "DisabledCurve-HelloRetryRequest",
11070 config: Config{
11071 MaxVersion: VersionTLS13,
11072 CurvePreferences: []CurveID{CurveP256},
11073 Bugs: ProtocolBugs{
11074 IgnorePeerCurvePreferences: true,
11075 },
11076 },
11077 flags: []string{"-p384-only"},
11078 shouldFail: true,
11079 expectedError: ":WRONG_CURVE:",
11080 })
11081
11082 testCases = append(testCases, testCase{
11083 name: "UnnecessaryHelloRetryRequest",
11084 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040011085 MaxVersion: VersionTLS13,
11086 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040011087 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040011088 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040011089 },
11090 },
11091 shouldFail: true,
11092 expectedError: ":WRONG_CURVE:",
11093 })
11094
11095 testCases = append(testCases, testCase{
11096 name: "SecondHelloRetryRequest",
11097 config: Config{
11098 MaxVersion: VersionTLS13,
11099 // P-384 requires HelloRetryRequest in BoringSSL.
11100 CurvePreferences: []CurveID{CurveP384},
11101 Bugs: ProtocolBugs{
11102 SecondHelloRetryRequest: true,
11103 },
11104 },
11105 shouldFail: true,
11106 expectedError: ":UNEXPECTED_MESSAGE:",
11107 })
11108
11109 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040011110 name: "HelloRetryRequest-Empty",
11111 config: Config{
11112 MaxVersion: VersionTLS13,
11113 Bugs: ProtocolBugs{
11114 AlwaysSendHelloRetryRequest: true,
11115 },
11116 },
11117 shouldFail: true,
11118 expectedError: ":DECODE_ERROR:",
11119 })
11120
11121 testCases = append(testCases, testCase{
11122 name: "HelloRetryRequest-DuplicateCurve",
11123 config: Config{
11124 MaxVersion: VersionTLS13,
11125 // P-384 requires a HelloRetryRequest against BoringSSL's default
11126 // configuration. Assert this ExpectMissingKeyShare.
11127 CurvePreferences: []CurveID{CurveP384},
11128 Bugs: ProtocolBugs{
11129 ExpectMissingKeyShare: true,
11130 DuplicateHelloRetryRequestExtensions: true,
11131 },
11132 },
11133 shouldFail: true,
11134 expectedError: ":DUPLICATE_EXTENSION:",
11135 expectedLocalError: "remote error: illegal parameter",
11136 })
11137
11138 testCases = append(testCases, testCase{
11139 name: "HelloRetryRequest-Cookie",
11140 config: Config{
11141 MaxVersion: VersionTLS13,
11142 Bugs: ProtocolBugs{
11143 SendHelloRetryRequestCookie: []byte("cookie"),
11144 },
11145 },
11146 })
11147
11148 testCases = append(testCases, testCase{
11149 name: "HelloRetryRequest-DuplicateCookie",
11150 config: Config{
11151 MaxVersion: VersionTLS13,
11152 Bugs: ProtocolBugs{
11153 SendHelloRetryRequestCookie: []byte("cookie"),
11154 DuplicateHelloRetryRequestExtensions: true,
11155 },
11156 },
11157 shouldFail: true,
11158 expectedError: ":DUPLICATE_EXTENSION:",
11159 expectedLocalError: "remote error: illegal parameter",
11160 })
11161
11162 testCases = append(testCases, testCase{
11163 name: "HelloRetryRequest-EmptyCookie",
11164 config: Config{
11165 MaxVersion: VersionTLS13,
11166 Bugs: ProtocolBugs{
11167 SendHelloRetryRequestCookie: []byte{},
11168 },
11169 },
11170 shouldFail: true,
11171 expectedError: ":DECODE_ERROR:",
11172 })
11173
11174 testCases = append(testCases, testCase{
11175 name: "HelloRetryRequest-Cookie-Curve",
11176 config: Config{
11177 MaxVersion: VersionTLS13,
11178 // P-384 requires HelloRetryRequest in BoringSSL.
11179 CurvePreferences: []CurveID{CurveP384},
11180 Bugs: ProtocolBugs{
11181 SendHelloRetryRequestCookie: []byte("cookie"),
11182 ExpectMissingKeyShare: true,
11183 },
11184 },
11185 })
11186
11187 testCases = append(testCases, testCase{
11188 name: "HelloRetryRequest-Unknown",
11189 config: Config{
11190 MaxVersion: VersionTLS13,
11191 Bugs: ProtocolBugs{
11192 CustomHelloRetryRequestExtension: "extension",
11193 },
11194 },
11195 shouldFail: true,
11196 expectedError: ":UNEXPECTED_EXTENSION:",
11197 expectedLocalError: "remote error: unsupported extension",
11198 })
11199
11200 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040011201 testType: serverTest,
11202 name: "SecondClientHelloMissingKeyShare",
11203 config: Config{
11204 MaxVersion: VersionTLS13,
11205 DefaultCurves: []CurveID{},
11206 Bugs: ProtocolBugs{
11207 SecondClientHelloMissingKeyShare: true,
11208 },
11209 },
11210 shouldFail: true,
11211 expectedError: ":MISSING_KEY_SHARE:",
11212 })
11213
11214 testCases = append(testCases, testCase{
11215 testType: serverTest,
11216 name: "SecondClientHelloWrongCurve",
11217 config: Config{
11218 MaxVersion: VersionTLS13,
11219 DefaultCurves: []CurveID{},
11220 Bugs: ProtocolBugs{
11221 MisinterpretHelloRetryRequestCurve: CurveP521,
11222 },
11223 },
11224 shouldFail: true,
11225 expectedError: ":WRONG_CURVE:",
11226 })
11227
11228 testCases = append(testCases, testCase{
11229 name: "HelloRetryRequestVersionMismatch",
11230 config: Config{
11231 MaxVersion: VersionTLS13,
11232 // P-384 requires HelloRetryRequest in BoringSSL.
11233 CurvePreferences: []CurveID{CurveP384},
11234 Bugs: ProtocolBugs{
11235 SendServerHelloVersion: 0x0305,
11236 },
11237 },
11238 shouldFail: true,
11239 expectedError: ":WRONG_VERSION_NUMBER:",
11240 })
11241
11242 testCases = append(testCases, testCase{
11243 name: "HelloRetryRequestCurveMismatch",
11244 config: Config{
11245 MaxVersion: VersionTLS13,
11246 // P-384 requires HelloRetryRequest in BoringSSL.
11247 CurvePreferences: []CurveID{CurveP384},
11248 Bugs: ProtocolBugs{
11249 // Send P-384 (correct) in the HelloRetryRequest.
11250 SendHelloRetryRequestCurve: CurveP384,
11251 // But send P-256 in the ServerHello.
11252 SendCurve: CurveP256,
11253 },
11254 },
11255 shouldFail: true,
11256 expectedError: ":WRONG_CURVE:",
11257 })
11258
11259 // Test the server selecting a curve that requires a HelloRetryRequest
11260 // without sending it.
11261 testCases = append(testCases, testCase{
11262 name: "SkipHelloRetryRequest",
11263 config: Config{
11264 MaxVersion: VersionTLS13,
11265 // P-384 requires HelloRetryRequest in BoringSSL.
11266 CurvePreferences: []CurveID{CurveP384},
11267 Bugs: ProtocolBugs{
11268 SkipHelloRetryRequest: true,
11269 },
11270 },
11271 shouldFail: true,
11272 expectedError: ":WRONG_CURVE:",
11273 })
David Benjamin8a8349b2016-08-18 02:32:23 -040011274
11275 testCases = append(testCases, testCase{
11276 name: "TLS13-RequestContextInHandshake",
11277 config: Config{
11278 MaxVersion: VersionTLS13,
11279 MinVersion: VersionTLS13,
11280 ClientAuth: RequireAnyClientCert,
11281 Bugs: ProtocolBugs{
11282 SendRequestContext: []byte("request context"),
11283 },
11284 },
11285 flags: []string{
11286 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11287 "-key-file", path.Join(*resourceDir, rsaKeyFile),
11288 },
11289 shouldFail: true,
11290 expectedError: ":DECODE_ERROR:",
11291 })
David Benjamin7e1f9842016-09-20 19:24:40 -040011292
11293 testCases = append(testCases, testCase{
11294 testType: serverTest,
11295 name: "TLS13-TrailingKeyShareData",
11296 config: Config{
11297 MaxVersion: VersionTLS13,
11298 Bugs: ProtocolBugs{
11299 TrailingKeyShareData: true,
11300 },
11301 },
11302 shouldFail: true,
11303 expectedError: ":DECODE_ERROR:",
11304 })
David Benjamin7f78df42016-10-05 22:33:19 -040011305
11306 testCases = append(testCases, testCase{
11307 name: "TLS13-AlwaysSelectPSKIdentity",
11308 config: Config{
11309 MaxVersion: VersionTLS13,
11310 Bugs: ProtocolBugs{
11311 AlwaysSelectPSKIdentity: true,
11312 },
11313 },
11314 shouldFail: true,
11315 expectedError: ":UNEXPECTED_EXTENSION:",
11316 })
11317
11318 testCases = append(testCases, testCase{
11319 name: "TLS13-InvalidPSKIdentity",
11320 config: Config{
11321 MaxVersion: VersionTLS13,
11322 Bugs: ProtocolBugs{
11323 SelectPSKIdentityOnResume: 1,
11324 },
11325 },
11326 resumeSession: true,
11327 shouldFail: true,
11328 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
11329 })
David Benjamin1286bee2016-10-07 15:25:06 -040011330
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011331 testCases = append(testCases, testCase{
11332 testType: serverTest,
11333 name: "TLS13-ExtraPSKIdentity",
11334 config: Config{
11335 MaxVersion: VersionTLS13,
11336 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050011337 ExtraPSKIdentity: true,
11338 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040011339 },
11340 },
11341 resumeSession: true,
11342 })
11343
David Benjamin1286bee2016-10-07 15:25:06 -040011344 // Test that unknown NewSessionTicket extensions are tolerated.
11345 testCases = append(testCases, testCase{
11346 name: "TLS13-CustomTicketExtension",
11347 config: Config{
11348 MaxVersion: VersionTLS13,
11349 Bugs: ProtocolBugs{
11350 CustomTicketExtension: "1234",
11351 },
11352 },
11353 })
Steven Valdezdbe01582017-07-14 10:39:28 -040011354 testCases = append(testCases, testCase{
11355 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011356 name: "TLS13-EarlyData-RejectTicket-Client",
11357 config: Config{
11358 MaxVersion: VersionTLS13,
11359 MaxEarlyDataSize: 16384,
11360 Certificates: []Certificate{rsaCertificate},
11361 },
11362 resumeConfig: &Config{
11363 MaxVersion: VersionTLS13,
11364 MaxEarlyDataSize: 16384,
11365 Certificates: []Certificate{ecdsaP256Certificate},
11366 SessionTicketsDisabled: true,
11367 },
11368 resumeSession: true,
11369 expectResumeRejected: true,
11370 flags: []string{
11371 "-enable-early-data",
11372 "-expect-early-data-info",
11373 "-expect-reject-early-data",
11374 "-on-resume-shim-writes-first",
11375 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11376 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
11377 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
11378 // Session tickets are disabled, so the runner will not send a ticket.
11379 "-on-retry-expect-no-session",
11380 },
11381 })
11382
11383 testCases = append(testCases, testCase{
11384 testType: clientTest,
11385 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011386 config: Config{
11387 MaxVersion: VersionTLS13,
11388 MaxEarlyDataSize: 16384,
11389 },
11390 resumeConfig: &Config{
11391 MaxVersion: VersionTLS13,
11392 MaxEarlyDataSize: 16384,
11393 Bugs: ProtocolBugs{
11394 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11395 },
11396 },
11397 resumeSession: true,
11398 flags: []string{
11399 "-enable-early-data",
11400 "-expect-early-data-info",
11401 "-expect-reject-early-data",
11402 },
11403 })
11404
11405 // The client must check the server does not send the early_data
11406 // extension while rejecting the session.
11407 testCases = append(testCases, testCase{
11408 testType: clientTest,
11409 name: "TLS13-EarlyDataWithoutResume-Client",
11410 config: Config{
11411 MaxVersion: VersionTLS13,
11412 MaxEarlyDataSize: 16384,
11413 },
11414 resumeConfig: &Config{
11415 MaxVersion: VersionTLS13,
11416 SessionTicketsDisabled: true,
11417 Bugs: ProtocolBugs{
11418 SendEarlyDataExtension: true,
11419 },
11420 },
11421 resumeSession: true,
11422 flags: []string{
11423 "-enable-early-data",
11424 "-expect-early-data-info",
11425 },
11426 shouldFail: true,
11427 expectedError: ":UNEXPECTED_EXTENSION:",
11428 })
11429
11430 // The client must fail with a dedicated error code if the server
11431 // responds with TLS 1.2 when offering 0-RTT.
11432 testCases = append(testCases, testCase{
11433 testType: clientTest,
11434 name: "TLS13-EarlyDataVersionDowngrade-Client",
11435 config: Config{
11436 MaxVersion: VersionTLS13,
11437 MaxEarlyDataSize: 16384,
11438 },
11439 resumeConfig: &Config{
11440 MaxVersion: VersionTLS12,
11441 },
11442 resumeSession: true,
11443 flags: []string{
11444 "-enable-early-data",
11445 "-expect-early-data-info",
11446 },
11447 shouldFail: true,
11448 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
11449 })
11450
11451 // Test that the client rejects an (unsolicited) early_data extension if
11452 // the server sent an HRR.
11453 testCases = append(testCases, testCase{
11454 testType: clientTest,
11455 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
11456 config: Config{
11457 MaxVersion: VersionTLS13,
11458 MaxEarlyDataSize: 16384,
11459 },
11460 resumeConfig: &Config{
11461 MaxVersion: VersionTLS13,
11462 MaxEarlyDataSize: 16384,
11463 Bugs: ProtocolBugs{
11464 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
11465 SendEarlyDataExtension: true,
11466 },
11467 },
11468 resumeSession: true,
11469 flags: []string{
11470 "-enable-early-data",
11471 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050011472 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011473 },
11474 shouldFail: true,
11475 expectedError: ":UNEXPECTED_EXTENSION:",
11476 })
11477
11478 fooString := "foo"
11479 barString := "bar"
11480
11481 // Test that the client reports the correct ALPN after a 0-RTT reject
11482 // that changed it.
11483 testCases = append(testCases, testCase{
11484 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011485 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011486 config: Config{
11487 MaxVersion: VersionTLS13,
11488 MaxEarlyDataSize: 16384,
11489 Bugs: ProtocolBugs{
11490 ALPNProtocol: &fooString,
11491 },
11492 },
11493 resumeConfig: &Config{
11494 MaxVersion: VersionTLS13,
11495 MaxEarlyDataSize: 16384,
11496 Bugs: ProtocolBugs{
11497 ALPNProtocol: &barString,
11498 },
11499 },
11500 resumeSession: true,
11501 flags: []string{
11502 "-advertise-alpn", "\x03foo\x03bar",
11503 "-enable-early-data",
11504 "-expect-early-data-info",
11505 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011506 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011507 "-on-resume-expect-alpn", "foo",
11508 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011509 },
11510 })
11511
11512 // Test that the client reports the correct ALPN after a 0-RTT reject if
11513 // ALPN was omitted from the first connection.
11514 testCases = append(testCases, testCase{
11515 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011516 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011517 config: Config{
11518 MaxVersion: VersionTLS13,
11519 MaxEarlyDataSize: 16384,
11520 },
11521 resumeConfig: &Config{
11522 MaxVersion: VersionTLS13,
11523 MaxEarlyDataSize: 16384,
11524 NextProtos: []string{"foo"},
11525 },
11526 resumeSession: true,
11527 flags: []string{
11528 "-advertise-alpn", "\x03foo\x03bar",
11529 "-enable-early-data",
11530 "-expect-early-data-info",
11531 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011532 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050011533 "-on-resume-expect-alpn", "",
11534 "-on-retry-expect-alpn", "foo",
11535 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011536 },
11537 })
11538
11539 // Test that the client reports the correct ALPN after a 0-RTT reject if
11540 // ALPN was omitted from the second connection.
11541 testCases = append(testCases, testCase{
11542 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011543 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011544 config: Config{
11545 MaxVersion: VersionTLS13,
11546 MaxEarlyDataSize: 16384,
11547 NextProtos: []string{"foo"},
11548 },
11549 resumeConfig: &Config{
11550 MaxVersion: VersionTLS13,
11551 MaxEarlyDataSize: 16384,
11552 },
11553 resumeSession: true,
11554 flags: []string{
11555 "-advertise-alpn", "\x03foo\x03bar",
11556 "-enable-early-data",
11557 "-expect-early-data-info",
11558 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011559 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011560 "-on-resume-expect-alpn", "foo",
11561 "-on-retry-expect-alpn", "",
11562 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050011563 },
11564 })
11565
11566 // Test that the client enforces ALPN match on 0-RTT accept.
11567 testCases = append(testCases, testCase{
11568 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050011569 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050011570 config: Config{
11571 MaxVersion: VersionTLS13,
11572 MaxEarlyDataSize: 16384,
11573 Bugs: ProtocolBugs{
11574 ALPNProtocol: &fooString,
11575 },
11576 },
11577 resumeConfig: &Config{
11578 MaxVersion: VersionTLS13,
11579 MaxEarlyDataSize: 16384,
11580 Bugs: ProtocolBugs{
11581 AlwaysAcceptEarlyData: true,
11582 ALPNProtocol: &barString,
11583 },
11584 },
11585 resumeSession: true,
11586 flags: []string{
11587 "-advertise-alpn", "\x03foo\x03bar",
11588 "-enable-early-data",
11589 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040011590 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050011591 "-on-resume-expect-alpn", "foo",
11592 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011593 },
11594 shouldFail: true,
11595 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
11596 })
11597
11598 // Test that the server correctly rejects 0-RTT when the previous
11599 // session did not allow early data on resumption.
11600 testCases = append(testCases, testCase{
11601 testType: serverTest,
11602 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
11603 config: Config{
11604 MaxVersion: VersionTLS13,
11605 },
11606 resumeConfig: &Config{
11607 MaxVersion: VersionTLS13,
11608 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011609 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011610 ExpectEarlyDataAccepted: false,
11611 },
11612 },
11613 resumeSession: true,
11614 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040011615 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050011616 "-expect-reject-early-data",
11617 },
11618 })
11619
11620 // Test that we reject early data where ALPN is omitted from the first
11621 // connection.
11622 testCases = append(testCases, testCase{
11623 testType: serverTest,
11624 name: "TLS13-EarlyData-ALPNOmitted1-Server",
11625 config: Config{
11626 MaxVersion: VersionTLS13,
11627 NextProtos: []string{},
11628 },
11629 resumeConfig: &Config{
11630 MaxVersion: VersionTLS13,
11631 NextProtos: []string{"foo"},
11632 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011633 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011634 ExpectEarlyDataAccepted: false,
11635 },
11636 },
11637 resumeSession: true,
11638 flags: []string{
11639 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011640 "-on-initial-select-alpn", "",
11641 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050011642 },
11643 })
11644
11645 // Test that we reject early data where ALPN is omitted from the second
11646 // connection.
11647 testCases = append(testCases, testCase{
11648 testType: serverTest,
11649 name: "TLS13-EarlyData-ALPNOmitted2-Server",
11650 config: Config{
11651 MaxVersion: VersionTLS13,
11652 NextProtos: []string{"foo"},
11653 },
11654 resumeConfig: &Config{
11655 MaxVersion: VersionTLS13,
11656 NextProtos: []string{},
11657 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011658 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011659 ExpectEarlyDataAccepted: false,
11660 },
11661 },
11662 resumeSession: true,
11663 flags: []string{
11664 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011665 "-on-initial-select-alpn", "foo",
11666 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050011667 },
11668 })
11669
11670 // Test that we reject early data with mismatched ALPN.
11671 testCases = append(testCases, testCase{
11672 testType: serverTest,
11673 name: "TLS13-EarlyData-ALPNMismatch-Server",
11674 config: Config{
11675 MaxVersion: VersionTLS13,
11676 NextProtos: []string{"foo"},
11677 },
11678 resumeConfig: &Config{
11679 MaxVersion: VersionTLS13,
11680 NextProtos: []string{"bar"},
11681 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011682 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050011683 ExpectEarlyDataAccepted: false,
11684 },
11685 },
11686 resumeSession: true,
11687 flags: []string{
11688 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040011689 "-on-initial-select-alpn", "foo",
11690 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050011691 },
11692 })
11693
David Benjamin6bb507b2017-03-29 16:35:57 -050011694 // Test that the client offering 0-RTT and Channel ID forbids the server
11695 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050011696 testCases = append(testCases, testCase{
11697 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011698 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050011699 config: Config{
11700 MaxVersion: VersionTLS13,
11701 MaxEarlyDataSize: 16384,
11702 RequestChannelID: true,
11703 },
11704 resumeSession: true,
11705 expectChannelID: true,
11706 shouldFail: true,
Steven Valdezf4ecc842017-08-10 14:02:56 -040011707 expectedError: ":UNEXPECTED_EXTENSION_ON_EARLY_DATA:",
Steven Valdez2a070722017-03-25 20:54:16 -050011708 flags: []string{
11709 "-enable-early-data",
11710 "-expect-early-data-info",
11711 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11712 },
11713 })
11714
David Benjamin6bb507b2017-03-29 16:35:57 -050011715 // Test that the client offering Channel ID and 0-RTT allows the server
11716 // to decline 0-RTT.
11717 testCases = append(testCases, testCase{
11718 testType: clientTest,
11719 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
11720 config: Config{
11721 MaxVersion: VersionTLS13,
11722 MaxEarlyDataSize: 16384,
11723 RequestChannelID: true,
11724 Bugs: ProtocolBugs{
11725 AlwaysRejectEarlyData: true,
11726 },
11727 },
11728 resumeSession: true,
11729 expectChannelID: true,
11730 flags: []string{
11731 "-enable-early-data",
11732 "-expect-early-data-info",
11733 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11734 "-expect-reject-early-data",
11735 },
11736 })
11737
11738 // Test that the client offering Channel ID and 0-RTT allows the server
11739 // to decline Channel ID.
11740 testCases = append(testCases, testCase{
11741 testType: clientTest,
11742 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11743 config: Config{
11744 MaxVersion: VersionTLS13,
11745 MaxEarlyDataSize: 16384,
11746 },
11747 resumeSession: true,
11748 flags: []string{
11749 "-enable-early-data",
11750 "-expect-early-data-info",
11751 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11752 "-expect-accept-early-data",
11753 },
11754 })
11755
11756 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11757 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011758 testCases = append(testCases, testCase{
11759 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011760 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011761 config: Config{
11762 MaxVersion: VersionTLS13,
11763 ChannelID: channelIDKey,
11764 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011765 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011766 ExpectEarlyDataAccepted: false,
11767 },
11768 },
11769 resumeSession: true,
11770 expectChannelID: true,
11771 flags: []string{
11772 "-enable-early-data",
11773 "-expect-reject-early-data",
11774 "-expect-channel-id",
11775 base64.StdEncoding.EncodeToString(channelIDBytes),
11776 },
11777 })
11778
David Benjamin6bb507b2017-03-29 16:35:57 -050011779 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11780 // if not offered Channel ID.
11781 testCases = append(testCases, testCase{
11782 testType: serverTest,
11783 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11784 config: Config{
11785 MaxVersion: VersionTLS13,
11786 Bugs: ProtocolBugs{
11787 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11788 ExpectEarlyDataAccepted: true,
11789 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11790 },
11791 },
11792 resumeSession: true,
11793 expectChannelID: false,
11794 flags: []string{
11795 "-enable-early-data",
11796 "-expect-accept-early-data",
11797 "-enable-channel-id",
11798 },
11799 })
11800
David Benjamin32c89272017-03-26 13:54:21 -050011801 // Test that the server rejects 0-RTT streams without end_of_early_data.
11802 // The subsequent records should fail to decrypt.
11803 testCases = append(testCases, testCase{
11804 testType: serverTest,
11805 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11806 config: Config{
11807 MaxVersion: VersionTLS13,
11808 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011809 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011810 ExpectEarlyDataAccepted: true,
11811 SkipEndOfEarlyData: true,
11812 },
11813 },
11814 resumeSession: true,
11815 flags: []string{"-enable-early-data"},
11816 shouldFail: true,
11817 expectedLocalError: "remote error: bad record MAC",
11818 expectedError: ":BAD_DECRYPT:",
11819 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011820
11821 testCases = append(testCases, testCase{
11822 testType: serverTest,
11823 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11824 config: Config{
11825 MaxVersion: VersionTLS13,
11826 },
11827 resumeConfig: &Config{
11828 MaxVersion: VersionTLS13,
11829 Bugs: ProtocolBugs{
11830 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11831 SendStrayEarlyHandshake: true,
David Benjamin4a37de02017-08-08 20:15:40 -040011832 ExpectEarlyDataAccepted: true,
11833 },
Steven Valdez681eb6a2016-12-19 13:19:29 -050011834 },
11835 resumeSession: true,
11836 shouldFail: true,
11837 expectedError: ":UNEXPECTED_RECORD:",
11838 expectedLocalError: "remote error: unexpected message",
11839 flags: []string{
11840 "-enable-early-data",
11841 },
11842 })
David Benjamind9cbb532017-07-07 13:17:19 -040011843
11844 // Test that the client reports TLS 1.3 as the version while sending
11845 // early data.
11846 testCases = append(testCases, testCase{
11847 testType: clientTest,
11848 name: "TLS13-EarlyData-Client-VersionAPI",
11849 config: Config{
11850 MaxVersion: VersionTLS13,
11851 MaxEarlyDataSize: 16384,
11852 },
11853 resumeSession: true,
11854 flags: []string{
11855 "-enable-early-data",
11856 "-expect-early-data-info",
11857 "-expect-accept-early-data",
11858 "-expect-version", strconv.Itoa(VersionTLS13),
11859 },
11860 })
David Benjamin4a37de02017-08-08 20:15:40 -040011861
11862 // Test that client and server both notice handshake errors after data
11863 // has started flowing.
11864 testCases = append(testCases, testCase{
11865 testType: clientTest,
11866 name: "TLS13-EarlyData-Client-BadFinished",
11867 config: Config{
11868 MaxVersion: VersionTLS13,
11869 MaxEarlyDataSize: 16384,
11870 },
11871 resumeConfig: &Config{
11872 MaxVersion: VersionTLS13,
11873 MaxEarlyDataSize: 16384,
11874 Bugs: ProtocolBugs{
11875 BadFinished: true,
11876 },
11877 },
11878 resumeSession: true,
11879 flags: []string{
11880 "-enable-early-data",
11881 "-expect-early-data-info",
11882 "-expect-accept-early-data",
11883 },
11884 shouldFail: true,
11885 expectedError: ":DIGEST_CHECK_FAILED:",
11886 expectedLocalError: "remote error: error decrypting message",
11887 })
11888 testCases = append(testCases, testCase{
11889 testType: serverTest,
11890 name: "TLS13-EarlyData-Server-BadFinished",
11891 config: Config{
11892 MaxVersion: VersionTLS13,
11893 MaxEarlyDataSize: 16384,
11894 },
11895 resumeConfig: &Config{
11896 MaxVersion: VersionTLS13,
11897 MaxEarlyDataSize: 16384,
11898 Bugs: ProtocolBugs{
11899 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11900 ExpectEarlyDataAccepted: true,
11901 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11902 BadFinished: true,
11903 },
11904 },
11905 resumeSession: true,
11906 flags: []string{
11907 "-enable-early-data",
11908 "-expect-accept-early-data",
11909 },
11910 shouldFail: true,
11911 expectedError: ":DIGEST_CHECK_FAILED:",
11912 expectedLocalError: "remote error: error decrypting message",
11913 })
Dimitar Vlahovskibd708452017-08-10 18:01:06 +020011914 testCases = append(testCases, testCase{
11915 testType: serverTest,
11916 name: "TLS13-ServerSkipCertificateVerify",
11917 config: Config{
11918 MinVersion: VersionTLS13,
11919 MaxVersion: VersionTLS13,
11920 Certificates: []Certificate{rsaChainCertificate},
11921 Bugs: ProtocolBugs{
11922 SkipCertificateVerify: true,
11923 },
11924 },
11925 expectPeerCertificate: &rsaChainCertificate,
11926 flags: []string{
11927 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11928 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11929 "-require-any-client-certificate",
11930 },
11931 shouldFail: true,
11932 expectedError: ":UNEXPECTED_MESSAGE:",
11933 expectedLocalError: "remote error: unexpected message",
11934 })
11935 testCases = append(testCases, testCase{
11936 testType: clientTest,
11937 name: "TLS13-ClientSkipCertificateVerify",
11938 config: Config{
11939 MinVersion: VersionTLS13,
11940 MaxVersion: VersionTLS13,
11941 Certificates: []Certificate{rsaChainCertificate},
11942 Bugs: ProtocolBugs{
11943 SkipCertificateVerify: true,
11944 },
11945 },
11946 expectPeerCertificate: &rsaChainCertificate,
11947 flags: []string{
11948 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11949 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11950 },
11951 shouldFail: true,
11952 expectedError: ":UNEXPECTED_MESSAGE:",
11953 expectedLocalError: "remote error: unexpected message",
11954 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011955}
11956
David Benjaminabbbee12016-10-31 19:20:42 -040011957func addTLS13CipherPreferenceTests() {
11958 // Test that client preference is honored if the shim has AES hardware
11959 // and ChaCha20-Poly1305 is preferred otherwise.
11960 testCases = append(testCases, testCase{
11961 testType: serverTest,
11962 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11963 config: Config{
11964 MaxVersion: VersionTLS13,
11965 CipherSuites: []uint16{
11966 TLS_CHACHA20_POLY1305_SHA256,
11967 TLS_AES_128_GCM_SHA256,
11968 },
11969 },
11970 flags: []string{
11971 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11972 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11973 },
11974 })
11975
11976 testCases = append(testCases, testCase{
11977 testType: serverTest,
11978 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11979 config: Config{
11980 MaxVersion: VersionTLS13,
11981 CipherSuites: []uint16{
11982 TLS_AES_128_GCM_SHA256,
11983 TLS_CHACHA20_POLY1305_SHA256,
11984 },
11985 },
11986 flags: []string{
11987 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11988 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11989 },
11990 })
11991
11992 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11993 // whether it has AES hardware.
11994 testCases = append(testCases, testCase{
11995 name: "TLS13-CipherPreference-Client",
11996 config: Config{
11997 MaxVersion: VersionTLS13,
11998 // Use the client cipher order. (This is the default but
11999 // is listed to be explicit.)
12000 PreferServerCipherSuites: false,
12001 },
12002 flags: []string{
12003 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
12004 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
12005 },
12006 })
12007}
12008
David Benjaminf3fbade2016-09-19 13:08:16 -040012009func addPeekTests() {
12010 // Test SSL_peek works, including on empty records.
12011 testCases = append(testCases, testCase{
12012 name: "Peek-Basic",
12013 sendEmptyRecords: 1,
12014 flags: []string{"-peek-then-read"},
12015 })
12016
12017 // Test SSL_peek can drive the initial handshake.
12018 testCases = append(testCases, testCase{
12019 name: "Peek-ImplicitHandshake",
12020 flags: []string{
12021 "-peek-then-read",
12022 "-implicit-handshake",
12023 },
12024 })
12025
12026 // Test SSL_peek can discover and drive a renegotiation.
12027 testCases = append(testCases, testCase{
12028 name: "Peek-Renegotiate",
12029 config: Config{
12030 MaxVersion: VersionTLS12,
12031 },
12032 renegotiate: 1,
12033 flags: []string{
12034 "-peek-then-read",
12035 "-renegotiate-freely",
12036 "-expect-total-renegotiations", "1",
12037 },
12038 })
12039
12040 // Test SSL_peek can discover a close_notify.
12041 testCases = append(testCases, testCase{
12042 name: "Peek-Shutdown",
12043 config: Config{
12044 Bugs: ProtocolBugs{
12045 ExpectCloseNotify: true,
12046 },
12047 },
12048 flags: []string{
12049 "-peek-then-read",
12050 "-check-close-notify",
12051 },
12052 })
12053
12054 // Test SSL_peek can discover an alert.
12055 testCases = append(testCases, testCase{
12056 name: "Peek-Alert",
12057 config: Config{
12058 Bugs: ProtocolBugs{
12059 SendSpuriousAlert: alertRecordOverflow,
12060 },
12061 },
12062 flags: []string{"-peek-then-read"},
12063 shouldFail: true,
12064 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
12065 })
12066
12067 // Test SSL_peek can handle KeyUpdate.
12068 testCases = append(testCases, testCase{
12069 name: "Peek-KeyUpdate",
12070 config: Config{
12071 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040012072 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040012073 sendKeyUpdates: 1,
12074 keyUpdateRequest: keyUpdateNotRequested,
12075 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040012076 })
12077}
12078
David Benjamine6f22212016-11-08 14:28:24 -050012079func addRecordVersionTests() {
12080 for _, ver := range tlsVersions {
12081 // Test that the record version is enforced.
12082 testCases = append(testCases, testCase{
12083 name: "CheckRecordVersion-" + ver.name,
12084 config: Config{
12085 MinVersion: ver.version,
12086 MaxVersion: ver.version,
12087 Bugs: ProtocolBugs{
12088 SendRecordVersion: 0x03ff,
12089 },
12090 },
David Benjamina5022392017-07-10 17:40:39 -040012091 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012092 shouldFail: true,
12093 expectedError: ":WRONG_VERSION_NUMBER:",
12094 })
12095
12096 // Test that the ClientHello may use any record version, for
12097 // compatibility reasons.
12098 testCases = append(testCases, testCase{
12099 testType: serverTest,
12100 name: "LooseInitialRecordVersion-" + ver.name,
12101 config: Config{
12102 MinVersion: ver.version,
12103 MaxVersion: ver.version,
12104 Bugs: ProtocolBugs{
12105 SendInitialRecordVersion: 0x03ff,
12106 },
12107 },
David Benjamina5022392017-07-10 17:40:39 -040012108 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012109 })
12110
12111 // Test that garbage ClientHello record versions are rejected.
12112 testCases = append(testCases, testCase{
12113 testType: serverTest,
12114 name: "GarbageInitialRecordVersion-" + ver.name,
12115 config: Config{
12116 MinVersion: ver.version,
12117 MaxVersion: ver.version,
12118 Bugs: ProtocolBugs{
12119 SendInitialRecordVersion: 0xffff,
12120 },
12121 },
David Benjamina5022392017-07-10 17:40:39 -040012122 tls13Variant: ver.tls13Variant,
David Benjamine6f22212016-11-08 14:28:24 -050012123 shouldFail: true,
12124 expectedError: ":WRONG_VERSION_NUMBER:",
12125 })
12126 }
12127}
12128
David Benjamin2c516452016-11-15 10:16:54 +090012129func addCertificateTests() {
David Benjamin2c516452016-11-15 10:16:54 +090012130 for _, ver := range tlsVersions {
David Benjamin3969fdf2017-08-29 15:50:58 -040012131 // Test that a certificate chain with intermediate may be sent
12132 // and received as both client and server.
David Benjamin2c516452016-11-15 10:16:54 +090012133 testCases = append(testCases, testCase{
12134 testType: clientTest,
12135 name: "SendReceiveIntermediate-Client-" + ver.name,
12136 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012137 MinVersion: ver.version,
12138 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012139 Certificates: []Certificate{rsaChainCertificate},
12140 ClientAuth: RequireAnyClientCert,
12141 },
David Benjamina5022392017-07-10 17:40:39 -040012142 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012143 expectPeerCertificate: &rsaChainCertificate,
12144 flags: []string{
12145 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12146 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12147 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12148 },
12149 })
12150
12151 testCases = append(testCases, testCase{
12152 testType: serverTest,
12153 name: "SendReceiveIntermediate-Server-" + ver.name,
12154 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080012155 MinVersion: ver.version,
12156 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090012157 Certificates: []Certificate{rsaChainCertificate},
12158 },
David Benjamina5022392017-07-10 17:40:39 -040012159 tls13Variant: ver.tls13Variant,
David Benjamin2c516452016-11-15 10:16:54 +090012160 expectPeerCertificate: &rsaChainCertificate,
12161 flags: []string{
12162 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12163 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
12164 "-require-any-client-certificate",
12165 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
12166 },
12167 })
David Benjamin3969fdf2017-08-29 15:50:58 -040012168
12169 // Test that garbage leaf certificates are properly rejected.
12170 testCases = append(testCases, testCase{
12171 testType: clientTest,
12172 name: "GarbageCertificate-Client-" + ver.name,
12173 config: Config{
12174 MinVersion: ver.version,
12175 MaxVersion: ver.version,
12176 Certificates: []Certificate{garbageCertificate},
12177 },
12178 tls13Variant: ver.tls13Variant,
12179 shouldFail: true,
12180 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12181 expectedLocalError: "remote error: error decoding message",
12182 })
12183
12184 testCases = append(testCases, testCase{
12185 testType: serverTest,
12186 name: "GarbageCertificate-Server-" + ver.name,
12187 config: Config{
12188 MinVersion: ver.version,
12189 MaxVersion: ver.version,
12190 Certificates: []Certificate{garbageCertificate},
12191 },
12192 tls13Variant: ver.tls13Variant,
12193 flags: []string{"-require-any-client-certificate"},
12194 shouldFail: true,
12195 expectedError: ":CANNOT_PARSE_LEAF_CERT:",
12196 expectedLocalError: "remote error: error decoding message",
12197 })
David Benjamin2c516452016-11-15 10:16:54 +090012198 }
12199}
12200
David Benjaminbbaf3672016-11-17 10:53:09 +090012201func addRetainOnlySHA256ClientCertTests() {
12202 for _, ver := range tlsVersions {
12203 // Test that enabling
12204 // SSL_CTX_set_retain_only_sha256_of_client_certs without
12205 // actually requesting a client certificate is a no-op.
12206 testCases = append(testCases, testCase{
12207 testType: serverTest,
12208 name: "RetainOnlySHA256-NoCert-" + ver.name,
12209 config: Config{
12210 MinVersion: ver.version,
12211 MaxVersion: ver.version,
12212 },
David Benjamina5022392017-07-10 17:40:39 -040012213 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012214 flags: []string{
David Benjaminf2165072017-08-23 23:01:37 -070012215 "-on-initial-retain-only-sha256-client-cert",
12216 "-on-resume-retain-only-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012217 },
12218 resumeSession: true,
12219 })
12220
12221 // Test that when retaining only a SHA-256 certificate is
12222 // enabled, the hash appears as expected.
12223 testCases = append(testCases, testCase{
12224 testType: serverTest,
12225 name: "RetainOnlySHA256-Cert-" + ver.name,
12226 config: Config{
12227 MinVersion: ver.version,
12228 MaxVersion: ver.version,
12229 Certificates: []Certificate{rsaCertificate},
12230 },
David Benjamina5022392017-07-10 17:40:39 -040012231 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012232 flags: []string{
12233 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012234 "-on-initial-retain-only-sha256-client-cert",
12235 "-on-resume-retain-only-sha256-client-cert",
12236 "-on-initial-expect-sha256-client-cert",
12237 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012238 },
12239 resumeSession: true,
12240 })
12241
12242 // Test that when the config changes from on to off, a
12243 // resumption is rejected because the server now wants the full
12244 // certificate chain.
12245 testCases = append(testCases, testCase{
12246 testType: serverTest,
12247 name: "RetainOnlySHA256-OnOff-" + ver.name,
12248 config: Config{
12249 MinVersion: ver.version,
12250 MaxVersion: ver.version,
12251 Certificates: []Certificate{rsaCertificate},
12252 },
David Benjamina5022392017-07-10 17:40:39 -040012253 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012254 flags: []string{
12255 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012256 "-on-initial-retain-only-sha256-client-cert",
12257 "-on-initial-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012258 },
12259 resumeSession: true,
12260 expectResumeRejected: true,
12261 })
12262
12263 // Test that when the config changes from off to on, a
12264 // resumption is rejected because the server now wants just the
12265 // hash.
12266 testCases = append(testCases, testCase{
12267 testType: serverTest,
12268 name: "RetainOnlySHA256-OffOn-" + ver.name,
12269 config: Config{
12270 MinVersion: ver.version,
12271 MaxVersion: ver.version,
12272 Certificates: []Certificate{rsaCertificate},
12273 },
David Benjamina5022392017-07-10 17:40:39 -040012274 tls13Variant: ver.tls13Variant,
David Benjaminbbaf3672016-11-17 10:53:09 +090012275 flags: []string{
12276 "-verify-peer",
David Benjaminf2165072017-08-23 23:01:37 -070012277 "-on-resume-retain-only-sha256-client-cert",
12278 "-on-resume-expect-sha256-client-cert",
David Benjaminbbaf3672016-11-17 10:53:09 +090012279 },
12280 resumeSession: true,
12281 expectResumeRejected: true,
12282 })
12283 }
12284}
12285
Adam Langleya4b91982016-12-12 12:05:53 -080012286func addECDSAKeyUsageTests() {
12287 p256 := elliptic.P256()
12288 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
12289 if err != nil {
12290 panic(err)
12291 }
12292
12293 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
12294 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
12295 if err != nil {
12296 panic(err)
12297 }
12298
12299 template := x509.Certificate{
12300 SerialNumber: serialNumber,
12301 Subject: pkix.Name{
12302 Organization: []string{"Acme Co"},
12303 },
12304 NotBefore: time.Now(),
12305 NotAfter: time.Now(),
12306
12307 // An ECC certificate with only the keyAgreement key usgae may
12308 // be used with ECDH, but not ECDSA.
12309 KeyUsage: x509.KeyUsageKeyAgreement,
12310 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
12311 BasicConstraintsValid: true,
12312 }
12313
12314 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
12315 if err != nil {
12316 panic(err)
12317 }
12318
12319 cert := Certificate{
12320 Certificate: [][]byte{derBytes},
12321 PrivateKey: priv,
12322 }
12323
12324 for _, ver := range tlsVersions {
12325 if ver.version < VersionTLS12 {
12326 continue
12327 }
12328
12329 testCases = append(testCases, testCase{
12330 testType: clientTest,
12331 name: "ECDSAKeyUsage-" + ver.name,
12332 config: Config{
12333 MinVersion: ver.version,
12334 MaxVersion: ver.version,
12335 Certificates: []Certificate{cert},
12336 },
David Benjamina5022392017-07-10 17:40:39 -040012337 tls13Variant: ver.tls13Variant,
Adam Langleya4b91982016-12-12 12:05:53 -080012338 shouldFail: true,
12339 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
12340 })
12341 }
12342}
12343
David Benjamin8c26d752017-03-26 15:13:51 -050012344func addExtraHandshakeTests() {
12345 // An extra SSL_do_handshake is normally a no-op. These tests use -async
12346 // to ensure there is no transport I/O.
12347 testCases = append(testCases, testCase{
12348 testType: clientTest,
12349 name: "ExtraHandshake-Client-TLS12",
12350 config: Config{
12351 MinVersion: VersionTLS12,
12352 MaxVersion: VersionTLS12,
12353 },
12354 flags: []string{
12355 "-async",
12356 "-no-op-extra-handshake",
12357 },
12358 })
12359 testCases = append(testCases, testCase{
12360 testType: serverTest,
12361 name: "ExtraHandshake-Server-TLS12",
12362 config: Config{
12363 MinVersion: VersionTLS12,
12364 MaxVersion: VersionTLS12,
12365 },
12366 flags: []string{
12367 "-async",
12368 "-no-op-extra-handshake",
12369 },
12370 })
12371 testCases = append(testCases, testCase{
12372 testType: clientTest,
12373 name: "ExtraHandshake-Client-TLS13",
12374 config: Config{
12375 MinVersion: VersionTLS13,
12376 MaxVersion: VersionTLS13,
12377 },
12378 flags: []string{
12379 "-async",
12380 "-no-op-extra-handshake",
12381 },
12382 })
12383 testCases = append(testCases, testCase{
12384 testType: serverTest,
12385 name: "ExtraHandshake-Server-TLS13",
12386 config: Config{
12387 MinVersion: VersionTLS13,
12388 MaxVersion: VersionTLS13,
12389 },
12390 flags: []string{
12391 "-async",
12392 "-no-op-extra-handshake",
12393 },
12394 })
12395
12396 // An extra SSL_do_handshake is a no-op in server 0-RTT.
12397 testCases = append(testCases, testCase{
12398 testType: serverTest,
12399 name: "ExtraHandshake-Server-EarlyData-TLS13",
12400 config: Config{
12401 MaxVersion: VersionTLS13,
12402 MinVersion: VersionTLS13,
12403 Bugs: ProtocolBugs{
12404 SendEarlyData: [][]byte{{1, 2, 3, 4}},
12405 ExpectEarlyDataAccepted: true,
12406 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
12407 },
12408 },
12409 messageCount: 2,
12410 resumeSession: true,
12411 flags: []string{
12412 "-async",
12413 "-enable-early-data",
12414 "-expect-accept-early-data",
12415 "-no-op-extra-handshake",
12416 },
12417 })
12418
12419 // An extra SSL_do_handshake drives the handshake to completion in False
12420 // Start. We test this by handshaking twice and asserting the False
12421 // Start does not appear to happen. See AlertBeforeFalseStartTest for
12422 // how the test works.
12423 testCases = append(testCases, testCase{
12424 testType: clientTest,
12425 name: "ExtraHandshake-FalseStart",
12426 config: Config{
12427 MaxVersion: VersionTLS12,
12428 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
12429 NextProtos: []string{"foo"},
12430 Bugs: ProtocolBugs{
12431 ExpectFalseStart: true,
12432 AlertBeforeFalseStartTest: alertAccessDenied,
12433 },
12434 },
12435 flags: []string{
12436 "-handshake-twice",
12437 "-false-start",
12438 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040012439 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050012440 },
12441 shimWritesFirst: true,
12442 shouldFail: true,
12443 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
12444 expectedLocalError: "tls: peer did not false start: EOF",
12445 })
12446}
12447
David Benjaminb853f312017-07-14 18:40:34 -040012448// Test that omitted and empty extensions blocks are tolerated.
12449func addOmitExtensionsTests() {
David Benjamin0a471912017-08-31 00:19:57 -040012450 // Check the ExpectOmitExtensions setting works.
12451 testCases = append(testCases, testCase{
12452 testType: serverTest,
12453 name: "ExpectOmitExtensions",
12454 config: Config{
12455 MinVersion: VersionTLS12,
12456 MaxVersion: VersionTLS12,
12457 Bugs: ProtocolBugs{
12458 ExpectOmitExtensions: true,
12459 },
12460 },
12461 shouldFail: true,
12462 expectedLocalError: "tls: ServerHello did not omit extensions",
12463 })
12464
David Benjaminb853f312017-07-14 18:40:34 -040012465 for _, ver := range tlsVersions {
12466 if ver.version > VersionTLS12 {
12467 continue
12468 }
12469
12470 testCases = append(testCases, testCase{
12471 testType: serverTest,
12472 name: "OmitExtensions-ClientHello-" + ver.name,
12473 config: Config{
12474 MinVersion: ver.version,
12475 MaxVersion: ver.version,
12476 SessionTicketsDisabled: true,
12477 Bugs: ProtocolBugs{
12478 OmitExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012479 // With no client extensions, the ServerHello must not have
12480 // extensions. It should then omit the extensions field.
12481 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012482 },
12483 },
12484 })
12485
12486 testCases = append(testCases, testCase{
12487 testType: serverTest,
12488 name: "EmptyExtensions-ClientHello-" + ver.name,
12489 config: Config{
12490 MinVersion: ver.version,
12491 MaxVersion: ver.version,
12492 SessionTicketsDisabled: true,
12493 Bugs: ProtocolBugs{
12494 EmptyExtensions: true,
David Benjamin0a471912017-08-31 00:19:57 -040012495 // With no client extensions, the ServerHello must not have
12496 // extensions. It should then omit the extensions field.
12497 ExpectOmitExtensions: true,
David Benjaminb853f312017-07-14 18:40:34 -040012498 },
12499 },
12500 })
12501
12502 testCases = append(testCases, testCase{
12503 testType: clientTest,
12504 name: "OmitExtensions-ServerHello-" + ver.name,
12505 config: Config{
12506 MinVersion: ver.version,
12507 MaxVersion: ver.version,
12508 SessionTicketsDisabled: true,
12509 Bugs: ProtocolBugs{
12510 OmitExtensions: true,
12511 // Disable all ServerHello extensions so
12512 // OmitExtensions works.
12513 NoExtendedMasterSecret: true,
12514 NoRenegotiationInfo: true,
12515 },
12516 },
12517 })
12518
12519 testCases = append(testCases, testCase{
12520 testType: clientTest,
12521 name: "EmptyExtensions-ServerHello-" + ver.name,
12522 config: Config{
12523 MinVersion: ver.version,
12524 MaxVersion: ver.version,
12525 SessionTicketsDisabled: true,
12526 Bugs: ProtocolBugs{
12527 EmptyExtensions: true,
12528 // Disable all ServerHello extensions so
12529 // EmptyExtensions works.
12530 NoExtendedMasterSecret: true,
12531 NoRenegotiationInfo: true,
12532 },
12533 },
12534 })
12535 }
12536}
12537
Adam Langley7c803a62015-06-15 15:35:05 -070012538func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070012539 defer wg.Done()
12540
12541 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080012542 var err error
12543
David Benjaminba28dfc2016-11-15 17:47:21 +090012544 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080012545 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
12546 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070012547 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080012548 if err != nil {
12549 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
12550 }
12551 break
12552 }
12553 }
David Benjaminba28dfc2016-11-15 17:47:21 +090012554 } else if *repeatUntilFailure {
12555 for err == nil {
12556 statusChan <- statusMsg{test: test, started: true}
12557 err = runTest(test, shimPath, -1)
12558 }
12559 } else {
12560 statusChan <- statusMsg{test: test, started: true}
12561 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080012562 }
Adam Langley95c29f32014-06-20 12:00:00 -070012563 statusChan <- statusMsg{test: test, err: err}
12564 }
12565}
12566
12567type statusMsg struct {
12568 test *testCase
12569 started bool
12570 err error
12571}
12572
David Benjamin5f237bc2015-02-11 17:14:15 -050012573func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020012574 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070012575
David Benjamin5f237bc2015-02-11 17:14:15 -050012576 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070012577 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050012578 if !*pipe {
12579 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050012580 var erase string
12581 for i := 0; i < lineLen; i++ {
12582 erase += "\b \b"
12583 }
12584 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050012585 }
12586
Adam Langley95c29f32014-06-20 12:00:00 -070012587 if msg.started {
12588 started++
12589 } else {
12590 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050012591
12592 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020012593 if msg.err == errUnimplemented {
12594 if *pipe {
12595 // Print each test instead of a status line.
12596 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
12597 }
12598 unimplemented++
12599 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
12600 } else {
12601 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
12602 failed++
12603 testOutput.addResult(msg.test.name, "FAIL")
12604 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012605 } else {
12606 if *pipe {
12607 // Print each test instead of a status line.
12608 fmt.Printf("PASSED (%s)\n", msg.test.name)
12609 }
12610 testOutput.addResult(msg.test.name, "PASS")
12611 }
Adam Langley95c29f32014-06-20 12:00:00 -070012612 }
12613
David Benjamin5f237bc2015-02-11 17:14:15 -050012614 if !*pipe {
12615 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020012616 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050012617 lineLen = len(line)
12618 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070012619 }
Adam Langley95c29f32014-06-20 12:00:00 -070012620 }
David Benjamin5f237bc2015-02-11 17:14:15 -050012621
12622 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070012623}
12624
12625func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070012626 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070012627 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070012628 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070012629
Adam Langley7c803a62015-06-15 15:35:05 -070012630 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012631 addCipherSuiteTests()
12632 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070012633 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070012634 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040012635 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080012636 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040012637 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050012638 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040012639 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040012640 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070012641 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070012642 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050012643 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070012644 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050012645 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040012646 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070012647 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070012648 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050012649 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050012650 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040012651 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040012652 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070012653 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070012654 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040012655 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040012656 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040012657 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040012658 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040012659 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050012660 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090012661 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090012662 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080012663 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050012664 addExtraHandshakeTests()
David Benjaminb853f312017-07-14 18:40:34 -040012665 addOmitExtensionsTests()
Adam Langley95c29f32014-06-20 12:00:00 -070012666
12667 var wg sync.WaitGroup
12668
Adam Langley7c803a62015-06-15 15:35:05 -070012669 statusChan := make(chan statusMsg, *numWorkers)
12670 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050012671 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070012672
EKRf71d7ed2016-08-06 13:25:12 -070012673 if len(*shimConfigFile) != 0 {
12674 encoded, err := ioutil.ReadFile(*shimConfigFile)
12675 if err != nil {
12676 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
12677 os.Exit(1)
12678 }
12679
12680 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
12681 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
12682 os.Exit(1)
12683 }
12684 }
12685
David Benjamin025b3d32014-07-01 19:53:04 -040012686 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070012687
Adam Langley7c803a62015-06-15 15:35:05 -070012688 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070012689 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070012690 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070012691 }
12692
David Benjamin270f0a72016-03-17 14:41:36 -040012693 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040012694 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040012695 matched := true
12696 if len(*testToRun) != 0 {
12697 var err error
12698 matched, err = filepath.Match(*testToRun, testCases[i].name)
12699 if err != nil {
12700 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
12701 os.Exit(1)
12702 }
12703 }
12704
EKRf71d7ed2016-08-06 13:25:12 -070012705 if !*includeDisabled {
12706 for pattern := range shimConfig.DisabledTests {
12707 isDisabled, err := filepath.Match(pattern, testCases[i].name)
12708 if err != nil {
12709 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
12710 os.Exit(1)
12711 }
12712
12713 if isDisabled {
12714 matched = false
12715 break
12716 }
12717 }
12718 }
12719
David Benjamin17e12922016-07-28 18:04:43 -040012720 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040012721 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040012722 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090012723
12724 // Only run one test if repeating until failure.
12725 if *repeatUntilFailure {
12726 break
12727 }
Adam Langley95c29f32014-06-20 12:00:00 -070012728 }
12729 }
David Benjamin17e12922016-07-28 18:04:43 -040012730
David Benjamin270f0a72016-03-17 14:41:36 -040012731 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070012732 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040012733 os.Exit(1)
12734 }
Adam Langley95c29f32014-06-20 12:00:00 -070012735
12736 close(testChan)
12737 wg.Wait()
12738 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050012739 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070012740
12741 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050012742
12743 if *jsonOutput != "" {
12744 if err := testOutput.writeTo(*jsonOutput); err != nil {
12745 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
12746 }
12747 }
David Benjamin2ab7a862015-04-04 17:02:18 -040012748
EKR842ae6c2016-07-27 09:22:05 +020012749 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
12750 os.Exit(1)
12751 }
12752
12753 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040012754 os.Exit(1)
12755 }
Adam Langley95c29f32014-06-20 12:00:00 -070012756}